solution
stringlengths
10
983k
difficulty
int64
0
25
language
stringclasses
2 values
#include <bits/stdc++.h> using namespace std; int n, m; int in[55]; int cnt; int pre[55]; pair<int, int> ans[55]; int find(int x) { return pre[x] = (x == pre[x] ? x : find(pre[x])); } bool merge(int a, int b) { int ra = find(a); int rb = find(b); if (ra != rb) pre[ra] = rb; else return false; return true; } int main() { while (cin >> n >> m) { memset(in, 0, sizeof(in)); bool flag = true; for (int i = 1; i <= n; i++) pre[i] = i; for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; if (u == v) flag = false; in[u]++; in[v]++; if (!merge(u, v) && m != n) flag = false; } if (n == 1) { puts(m == 0 ? "YES\n1\n1 1\n" : (m > 1 ? "NO" : "YES\n0")); continue; } int cnt = 0, tot = 0; for (int i = 1; i <= n; i++) { if (in[i] > 2) { flag = false; break; } cnt += 2 - in[i]; } if (!flag) puts("NO"); else { puts("YES"); cout << (cnt / 2) << endl; for (int i = 0; i < (cnt / 2); i++) { for (int j = 1; j <= n; j++) { if (in[j] >= 2) continue; for (int k = j + 1; k <= n; k++) { if (in[k] >= 2) continue; if (i + 1 < (cnt / 2) && !merge(j, k)) continue; printf("%d %d\n", j, k); in[j]++; in[k]++; j = n + 1; k = n + 1; } } } } } return 0; }
11
CPP
## necessary imports import sys import random from math import log2, log, ceil input = sys.stdin.readline # swap_array function def swaparr(arr, a,b): temp = arr[a]; arr[a] = arr[b]; arr[b] = temp ## gcd function def gcd(a,b): if a > 0: return gcd(b%a, a) return b ## prime factorization def primefs(n): ## if n == 1 if n == 1: return 1 ## calculating primes primes = {} while(n%2 == 0): primes[2] = primes.get(2, 0) + 1 n = n//2 for i in range(3, int(n**0.5)+2, 2): while(n%i == 0): primes[i] = primes.get(i, 0) + 1 n = n//i if n > 2: primes[n] = primes.get(n, 0) + 1 ## prime factoriazation of n is stored in dictionary ## primes and can be accesed. O(sqrt n) return primes ## DISJOINT SET UNINON FUNCTIONS def swap(a,b): temp = a a = b b = temp return a,b # find function def find(x, link): while(x != link[x]): x = link[x] return x # the union function which makes union(x,y) # of two nodes x and y def union(x, y, size, link): x = find(x, link) y = find(y, link) if size[x] < size[y]: x,y = swap(x,y) if x != y: size[x] += size[y] link[y] = x ## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES def sieve(n): prime = [True for i in range(n+1)] p = 2 while (p * p <= n): if (prime[p] == True): for i in range(p * p, n+1, p): prime[i] = False p += 1 return prime #### PRIME FACTORIZATION IN O(log n) using Sieve #### MAXN = int(1e6 + 5) def spf_sieve(): spf[1] = 1; for i in range(2, MAXN): spf[i] = i; for i in range(4, MAXN, 2): spf[i] = 2; for i in range(3, ceil(MAXN ** 0.5), 2): if spf[i] == i: for j in range(i*i, MAXN, i): if spf[j] == j: spf[j] = i; ## function for storing smallest prime factors (spf) in the array ################## un-comment below 2 lines when using factorization ################# # spf = [0 for i in range(MAXN)] # spf_sieve() def factoriazation(x): ret = {}; while x != 1: ret[spf[x]] = ret.get(spf[x], 0) + 1; x = x//spf[x] return ret ## this function is useful for multiple queries only, o/w use ## primefs function above. complexity O(log n) ## taking integer array input def int_array(): return list(map(int, input().split())) #defining a couple constants MOD = int(1e9)+7; CMOD = 998244353; ################# ---------------- TEMPLATE ENDS HERE ---------------- ################# n,m = int_array(); ans = 0; while(n*m != 0 and n+m >= 3): ans += 1; n -=1; m -=1; if n > m: n -=1; else: m -=1; print(ans)
9
PYTHON3
for j in range(int(input())): a,b = map(int,input().split()) if b>a: print(b-a) else: if a%2==0: if a%2 == 0 and b%2==0: print(0) else: print(1) else: if a%2!=0 and (b%2!=0): print(0) else: print(1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int n, l, all; int x[10]; int u[20]; vector<int> xx; void out(int x) { xx.push_back(x); } void gao(int j, int ip, int k = 0) { if (k == 4) { if (j == l) out(ip); return; } if (u[j] == 0) { gao(j + 1, ip << 8, k + 1); } else { for (int t = u[j]; t <= 255; t = t * 10 + u[++j]) gao(j + 1, ip << 8 | t, k + 1); } } void dfs(int L, int z) { if (L >= 2 && z == all) { l = L << 1; for (int i = 0; i < L; ++i) u[l - 1 - i] = u[i]; gao(0, 0); } if (L >= 3 && z == all) { l = (L << 1) - 1; for (int i = 0; i + 1 < L; ++i) u[l - 1 - i] = u[i]; gao(0, 0); } if (L <= 5) for (int i = 0; i < n; ++i) { u[L] = x[i]; dfs(L + 1, z | 1 << i); } } int main() { scanf("%d", &n); all = (1 << n) - 1; for (int i = 0; i < n; ++i) scanf("%d", x + i); dfs(0, 0); printf("%u\n", xx.size()); for (unsigned i = 0, t; i < xx.size(); ++i) { t = xx[i]; printf("%u.%u.%u.%u\n", t >> 24, t >> 16 & 255, t >> 8 & 255, t & 255); } return 0; }
9
CPP
import re, math, decimal, bisect def read(): return input().strip() def iread(): return int(input().strip()) def viread(): return [int(_) for _ in input().strip().split()] # code goes here for _ in range(iread()): l, r, d = viread() ans1 = r+1 if d != 1: ans1 += (d - (ans1 % d)) % d ans2 = d print(ans1 if ans2 >= l and ans2 <= r else ans2)
7
PYTHON3
for _ in range(int(input())): count=0 a=input() b=input() c=input() for i in range(len(a)): if a[i]==c[i] or b[i]==c[i]: count+=1 if count<len(a): print('NO') else: print('YES')
7
PYTHON3
import sys for _ in range(int(sys.stdin.readline())): n = int(sys.stdin.readline()) q, r = (n - 1) // 3, n % 3 i = 0 while q >= 1 << (i << 1): q -= 1 << (i << 1) i += 1 quad = [0] * i if r == 1: s = 0 while q > 0: quad[s] += q % 4 q >>= 2 s += 1 res = 1 << (len(quad) * 2) for j, x in enumerate(quad): res += {0: 0, 1: 1, 2: 2, 3: 3}[x] << (j * 2) print(res) continue if r == 2: s = 0 while q > 0: quad[s] += q % 4 q >>= 2 s += 1 res = 2 << (len(quad) * 2) for j, x in enumerate(quad): res += {0: 0, 1: 2, 2: 3, 3: 1}[x] << (j * 2) print(res) continue if r == 0: s = 0 while q > 0: quad[s] += q % 4 q >>= 2 s += 1 res = 3 << (len(quad) * 2) for j, x in enumerate(quad): res += {0: 0, 1: 3, 2: 1, 3: 2}[x] << (j * 2) print(res) continue
11
PYTHON3
word = input() vowels = ['a', 'A', 'o', 'O', 'y', 'Y','e', 'E', 'u', 'U', 'i', 'I'] res = '' for i in range(0, len(word)): if(word[i] in vowels): continue else: res = res + '.' res = res + word[i].lower() print(res)
7
PYTHON3
import math a,b=map(int,input().split()) n=(a*b)//2 print(math.ceil(n))
7
PYTHON3
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; int n, q, a[200009], b[200009], t[200009], r[200009]; int main() { scanf("%d %d", &n, &q); for (int i = 0; i < n; i++) scanf("%d", &a[i]); for (int i = 0; i < q; i++) scanf("%d %d", &t[i], &r[i]); vector<int> g; g.push_back(q - 1); for (int i = q - 2; i >= 0; i--) { if (r[i] > r[g.back()]) { if (t[i] == t[g.back()]) g.back() = i; else g.push_back(i); } } sort(a, a + r[g.back()]); for (int i = r[g.back()]; i < n; i++) b[i] = a[i]; int lc = 0, rc = r[g.back()]; for (int i = g.size() - 1; i >= 1; i--) { if (t[g[i]] == 1) { for (int j = r[g[i - 1]]; j < r[g[i]]; j++) b[j] = a[rc - (r[g[i]] - j)]; rc -= r[g[i]] - r[g[i - 1]]; } else { for (int j = r[g[i - 1]]; j < r[g[i]]; j++) b[j] = a[lc + (r[g[i]] - j) - 1]; lc += r[g[i]] - r[g[i - 1]]; } } for (int i = 0; i < r[g[0]]; i++) b[i] = a[i + lc]; if (t[g[0]] == 2) reverse(b, b + r[g[0]]); for (int i = 0; i < n; i++) printf("%d ", b[i]); return 0; }
9
CPP
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c* x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct debug { template <class c> debug& operator<<(const c&) { return *this; } }; const long long N = 1e5 + 5; long long n; vector<long long> a, t; long long v[N + 5], seg[4 * N]; bool temp[N]; map<long long, long long> mp; void update(long long st, long long en, long long ind, long long val, long long pos) { if (st == en) { seg[pos] = val; return; } long long mid = (st + en) / 2; if (st <= ind && ind <= mid) { update(st, mid, ind, val, 2 * pos + 1); } else { update(mid + 1, en, ind, val, 2 * pos + 2); } seg[pos] = max(seg[2 * pos + 1], seg[2 * pos + 2]); } long long query(long long st, long long en, long long qst, long long qen, long long pos) { if (en < qst || qen < st) return -1; if (qst <= st && en <= qen) return seg[pos]; long long mid = (st + en) / 2; return max(query(st, mid, qst, qen, 2 * pos + 1), query(mid + 1, en, qst, qen, 2 * pos + 2)); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; a.resize(n); for (long long i = 0; i < n; i++) { cin >> a[i]; } t = a; sort((t).begin(), (t).end()); long long cnt = 0; for (long long i = 0; i < n; i++) { if (!mp[t[i]]) { mp[t[i]] = ++cnt; } } for (long long i = 0; i < n; i++) { a[i] = mp[a[i]]; } debug() << " [" << "a" ": " << (a) << "] "; memset(seg, -1, sizeof seg); long long ind; vector<long long> ans(n); for (long long i = n - 1; i >= 0; i--) { ind = query(1, cnt, 1, a[i] - 1, 0); if (ind == -1) { ans[i] = -1; } else { ans[i] = ind - i - 1; } if (!temp[a[i]]) update(1, cnt, a[i], i, 0), temp[a[i]] = true; } for (long long i = 0; i < n; i++) { cout << ans[i] << " "; } cout << "\n"; return 0; }
8
CPP
a = int(input()) s = input() b = 0 for x in range(1, a): if s[x] == s[x - 1]: b += 1 print(b)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int n, f[100010]; int main() { scanf("%d", &n); for (int i = 2; i * i <= n + 1; i++) { if (f[i] == 0) for (int j = 2; i * j <= n + 1; j++) f[i * j] = 1; } if (n >= 3) printf("2\n"); else printf("1\n"); for (int i = 2; i <= n + 1; i++) if (f[i]) printf("2 "); else printf("1 "); return 0; }
8
CPP
n = int(input()) a = list(map(int, input().split())) res = 100000000 for i in range (n): tmp = 0 for j in range(n): x = a[i] - a[j] if x < 0: x = x * -1 ; if x % 2: tmp += 1 ; if res > tmp: res = tmp print(res)
7
PYTHON3
n=int(input()) l=[] for i in range(n): l.append(1) for i in range (1,n): for j in range(1,n): l[j]=l[j]+l[j-1] print(l[n-1])
7
PYTHON3
#include <bits/stdc++.h> using namespace std; pair<int, int> pos[200005]; long long int cost[200005], zan[200005]; int main() { int d, n, m; scanf("%d %d %d", &d, &n, &m); for (int i = 0; i < m; i++) { int x, p; scanf("%d %d", &x, &p); pos[i] = pair<int, int>(x, p); } pos[m++] = pair<int, int>(d, 0); sort(pos, pos + m); int s = 0, e = 0; long long int sum = n; long long int ret = 0; for (int i = 0; i < m; i++) { pair<int, int> p = pos[i]; while (s < e && sum < p.first) { long long int gt = n - (sum + zan[s]); long long int nd = p.first - sum; if (gt < nd) { ret += gt * cost[s]; sum += gt; s++; } else { ret += nd * cost[s]; sum += nd; } } if (sum < p.first) { puts("-1"); return 0; } while (s < e && cost[e - 1] >= p.second) e--; cost[e] = p.second, zan[e] = -p.first; e++; } printf("%lld\n", ret); return 0; }
9
CPP
import sys n = int(input()) a = {} for i in range(n): temp = int(input()) if temp not in a.keys(): a[temp] = 1 else: a[temp] += 1 if len(a.keys()) > 2 or len(a.keys()) < 2: print("NO") sys.exit() l = list(a.keys()) if a[l[0]] != a[l[1]]: print("NO") sys.exit() print("YES") print("{} {}".format(l[0], l[1]))
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int n; int arities[100001]; int legs[100001]; bool markers[100001]; list<int> graph[100001]; void parse() { int a, b; cin >> n; for (int it = 0; it < (100001); it++) { (arities)[it] = (0); }; for (int it = 0; it < (100001); it++) { (markers)[it] = (false); }; for (int it = 0; it < (100001); it++) { (legs)[it] = (0); }; for (int i = 1; i < n; i++) { cin >> a >> b; graph[a].push_back(b); graph[b].push_back(a); arities[a]++; arities[b]++; } } void traverse(int i) { if (markers[i]) return; if (arities[i] >= 3) { legs[i]++; return; } markers[i] = true; for (list<int>::iterator it = graph[i].begin(); it != graph[i].end(); ++it) { traverse(*it); } } void solve() { for (int i = 1; i <= n; i++) { if (arities[i] == 1) traverse(i); } for (int i = 1; i <= n; i++) { if (!markers[i]) { int r = 0; for (list<int>::iterator it = graph[i].begin(); it != graph[i].end(); ++it) { if (!markers[*it] && arities[*it] - min(legs[*it], 2) > 1) r++; } if (r > 2) { cout << "No"; return; } } } cout << "Yes"; } int main() { ios::sync_with_stdio(false); std::cout.precision(11); parse(); solve(); cout << endl; return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; string str; int k; void findbig(char ch, int index, int len) { int _min, pt, i; char g; if (len - index < k) _min = len - index; else _min = k; g = ch; pt = -1; for (i = 0; i < _min; i++) if (g < str[index + i]) { g = str[index + i]; pt = i; } if (pt == -1) return; for (i = pt + index; i >= index; i--) str[i] = str[i - 1]; str[index - 1] = g; k = k - pt - 1; } int main() { int i, len; cin >> str >> k; len = str.length(); for (i = 0; i < len; i++) { findbig(str[i], i + 1, len); } cout << str << endl; return 0; }
8
CPP
peso=int(input()) if(peso<=2 or peso%2!=0): print("NO") else: print("YES") # 1505941512583
7
PYTHON3
#include<iostream> #include<string> using namespace std; char field[12][12]; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; void dfs(int x, int y){ if(0 <= x && x < 12 && 0 <= y && y < 12 && field[x][y] == '1'){ field[x][y] = '0'; for(int i=0; i < 4; i++){ dfs(x + dx[i], y + dy[i]); } } } int main(){ while(cin >> field[0][0]){ int ans = 0; for(int i=0; i < 12; i++){ for(int j=0; j < 12; j++){ if(i == 0 && j == 0) continue; cin >> field[i][j]; } } for(int i=0; i < 12; i++){ for(int j=0; j < 12; j++){ if(field[i][j] == '1'){ dfs(i, j); ans++; } } } cout << ans << endl; } }
0
CPP
t=int(input()) for _ in range(t): n=int(input()) arr=list(map(int,input().split())) arr.sort() m=float("inf") for i in range(1,n): if abs(arr[i]-arr[i-1])<m: m=abs(arr[i]-arr[i-1]) if m==0: break print(m)
8
PYTHON3
# by the authority of GOD author: manhar singh sachdev # import os,sys from io import BytesIO, IOBase def main(): n = int(input()) a = list(map(int,input().split())) b = sorted(a) ans = 0 for x,y in zip(a,b): if x!=y: ans += 1 if ans <= 2: print('YES') else: print('NO') #Fast IO Region BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") if __name__ == '__main__': main()
7
PYTHON3
t = int(input()) for _ in range(t): a, b = map(int, input().split()) if a == b: print(0) elif a > b: print((a - b - 1) // 10 + 1) else: print((b - a - 1) // 10 + 1)
7
PYTHON3
#include <bits/stdc++.h> int compare(const void *a, const void *b) { int ia = *(int *)a; int ib = *(int *)b; return ia - ib; } int main() { int i, n, k, p, x, y, sum, cnt, max, bad; static int a[999]; scanf("%d%d%d%d%d", &n, &k, &p, &x, &y); for (i = 0; i < n; i++) scanf("%d", &a[i]); sum = 0; for (i = 0; i < n; i++) sum += a[i]; cnt = 0; max = 0; for (i = 0; i < k; i++) { if (a[i] < y) cnt++; if (max < a[i]) max = a[i]; } bad = 0; if (sum >= x || sum + (n - 1) / 2 - cnt + (n - k - (n - 1) / 2 + cnt) * y > x) bad = 1; if (k >= (n + 1) / 2) { qsort(a, k, sizeof(*a), compare); if (a[(n - 1) / 2] < y) bad = 1; } if (bad) printf("-1"); else { for (i = 0; i < (n - 1) / 2 - cnt && i < n - k; i++) printf("1 "); for (; i < n - k; i++) printf("%d ", y); } printf("\n"); return 0; }
8
CPP
#include<bits/stdc++.h> using namespace std; const int maxn=1e5+6; int vis[maxn],c[maxn],cnt,ans; int n,m; int main() { scanf("%d %d",&n,&m); for(int i=1;i<=m;++i) { int a;char s[4]; scanf("%d",&a); scanf("%s",s); if(s[0]=='A'&&vis[a]==0) cnt++,ans+=c[a],vis[a]=1; else c[a]++; } printf("%d %d",cnt,ans); }
0
CPP
n, m = list(map(int, input().split())) x = list(map(int, input().split())) y = list(map(int, input().split())) MOD = 10 ** 9 + 7 X = 0 Y = 0 for i in range(n - 1): t = x[i + 1] - x[i] X = (X + (i + 1) * (n - i - 1) * t) % MOD for i in range(m - 1): t = y[i + 1] - y[i] Y = (Y + (i + 1) * (m - i - 1) * t) % MOD print(X * Y % MOD)
0
PYTHON3
#include <bits/stdc++.h> using namespace std; void solve() { int n, x, inp; cin >> n >> x; int even = 0, odd = 0; for (long long int i = 0; i < n; i++) { cin >> inp; if (inp % 2 == 0) even++; else odd++; } if (odd == 0) { cout << "NO\n"; return; } else if (even >= (x - 1)) { cout << "YES\n"; return; } else if (x == n) { if (odd % 2 == 0) { cout << "NO\n"; return; } } else if (x % 2 == 0 && even == 0) { cout << "NO\n"; return; } cout << "YES\n"; return; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL); ; int t = 1; cin >> t; while (t--) { solve(); } return 0; }
7
CPP
t = int(input()) for _ in range(t): input() students = input() patients = students.split('A') if students[0] != 'A': patients = patients[1:] res = 0 for p in patients: res = max(res, len(p)) print(res)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; string s, t; cin >> s >> t; vector<int> f; int mn = 1001, x; for (int i = 0; i <= (m - n); i++) { vector<int> vi; for (int j = i, k = 0; k < n; j++, k++) { if (s[k] != t[j]) { vi.push_back(k + 1); } } x = vi.size(); if (mn > x) { f.erase(f.begin(), f.end()); for (int l = 0; l < x; l++) { f.push_back(vi[l]); } mn = x; } } x = f.size(); cout << x << endl; for (int i = 0; i < x; i++) cout << f[i] << " "; cout << endl; return 0; }
8
CPP
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:66777216") using namespace std; long long n, m, x, y, z; int a[105]; int main() { cin >> n; string s; cin >> s; for (int i = 1; i < n; i++) { for (int c = 0; c < n; c++) { int ans = 0; for (int k = c; k < n; k += i) { if (s[k] == '*') ans++; else break; } if (ans >= 5) { cout << "yes"; return 0; } } } cout << "no"; return 0; }
7
CPP
#coding: utf - 8 import math n,m,a = input().split() n = int (n) m = int (m) a = int (a) z = math.ceil (n/a) s = math.ceil (m/a) d= z*s print (d)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; const long double PI = acos(-1); constexpr long double EPS = 1e-15; constexpr int inf = 2e9; constexpr ll INF = 2e18; constexpr ll MOD = 1e9+7; constexpr ll MOD1 = 998244353; typedef pair<ll,ll> P; //#define all(v) (v).begin(), (v).end() #define rep(i,a,b) for (int i = (a); i < (b); i++) #define REP(i,n) rep(i,0,n) #define sz(s) (s).size() #define pb push_back #define fi first #define se second //#define mp make_pair int main(){ int n; cin >> n; int cnt[3] = {}; REP(i,n) { int tmp; cin >> tmp; cnt[tmp%3]++; } if (cnt[0] == n) { cout << 1 << endl; return 0; } int ans; if(cnt[1] < cnt[2] - 3){ ans = cnt[1] * 2 + 3; }else if(cnt[1] <= cnt[2] + 3){ ans = cnt[1] + cnt[2]; }else{ ans = cnt[2] * 2 + 3; } ans += cnt[0]; cout << ans << endl; return 0; }
0
CPP
import math circles = int(input()) radii = sorted(map(int,input().split()),reverse = True) if circles == 1: print ((radii[0]**2)*math.pi) else: red = (radii[-1]**2)*math.pi if circles%2 else 0 a = 1 if circles%2 else 0 for x in range(1,circles-a,2): red += math.pi*(radii[x-1]**2 - radii[x]**2) print (red)
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); int i; long long A[100010]; long long sum = 0; long long ma = -1; for (i = 0; i < n; i++) { cin >> A[i]; sum += A[i]; ma = max(A[i], ma); } long long t = ((sum + n - 2) / (n - 1)); long long r = t; r = max(r, ma); cout << r << endl; }
7
CPP
t = int(input()) for _ in range(t): arr = list(map(int,input().split())) arr.sort() two = set(arr) if len(two)<=2 and arr[1]==arr[2]: print("YES") print(f'{min(arr)} {min(arr)} {max(arr)}') else: print("NO")
7
PYTHON3
#include<iostream> #include<cmath> #include<cstdio> #include<vector> #include<algorithm> using namespace std; double EPS = 1e-7; double add(double a,double b){ if(abs(a+b)<EPS*(abs(a)+abs(b)))return 0; return a+b; } struct point{ double x,y; point() {} point(double x,double y):x(x),y(y){ } point operator + (point p){ return point(add(x,p.x),add(y,p.y)); } point operator - (point p){ return point(add(x,-p.x),add(y,-p.y)); } point operator * (double d){ return point(x*d,y*d); } point operator / (double d){ return point(x/d,y/d); } }; double dist(point a,point b){ return sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2)); } int main(void){ int n,x,y,v; vector<point>P; vector<double>V; while(cin >> n,n){ P.clear(); V.clear(); for(int i=0;i<n;i++){ cin >> x >> y >> v; P.push_back(point(x,y)); V.push_back(v); } double r=0.98; point now(0,0); for(double d=10;d>EPS;d*=r){ int mx=0; double mxd=0; for(int j=0;j<P.size();j++) if(dist(now,P[j])/V[j]>mxd) mx=j,mxd=dist(now,P[j])/V[j]; now=now+((P[mx]-now)/dist(P[mx],now)*d); } double ans=0; for(int i=0;i<P.size();i++){ ans=max(ans,dist(now,P[i])/V[i]); } printf("%.8f\n",ans); } return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; if (a == b) { cout << "infinity\n"; } else if (a < b) { cout << "0" << endl; } else { int ans = 0; int x = a - b; for (int i = 1; i * i <= x; i++) { if (x % i == 0 && i > b) { ans++; } if (x % i == 0 && x / i > b && x / i != i) { ans++; } } cout << ans << endl; } return 0; }
8
CPP
#include<bits/stdc++.h> using namespace std; int main(){ long long int n,a=2,b=1,c=3,d; cin>>n; for(int i=0;i<n;i++){ c=c+b; d=b; b=b+a; a=d; } cout<<a<<endl; }
0
CPP
#include <bits/stdc++.h> const int N = 4005, mu = 1e9 + 7; void reduce(int &x) { x += x >> 31 & mu; } int vis[N], to[N << 1], edge, Next[N << 1], last[N], n, m, cnt; int x, y, tot, a[N], tmp[2][N][N * 2], g[2][N * 2], ans, tt[N * 4]; int *dp[2], *id = tt; void add(int x, int y) { to[++edge] = y; Next[edge] = last[x]; last[x] = edge; } void dfs(int x) { cnt++; vis[x] = 1; for (int i = last[x]; i; i = Next[i]) if (!vis[to[i]]) dfs(to[i]); } void solve(int l, int r, int *f[2], int sum) { if (l == r) { int ret = 0; for (int i = 1, j = a[l] - 1; j > 0; i++, j--) reduce(ret += f[0][m + i - j] - mu); for (int i = 1, j = a[l] - 2; j > 0; i++, j--) reduce(ret += f[0][m + i - j] - mu); ret = ret * 2 % mu; reduce(ans += ret - mu); if (l == tot || (m & 1)) { reduce(ans += (long long)f[1][m + a[l] - (m & 1)] * (1 + (m & 1)) % mu - mu); reduce(ans += (long long)f[1][m - a[l] + (m & 1)] * (1 + (m & 1)) % mu - mu); } return; } int now = ++cnt; int mid = (l + r) >> 1; for (int i = 0; i <= 2 * m; i++) tmp[0][cnt][i] = f[0][i], tmp[1][cnt][i] = f[1][i]; int sum1 = sum; for (int i = mid + 1; i <= r; i++) { for (int j = m - sum1; j <= m + sum1; j++) { g[0][j] = f[0][j]; g[1][j] = f[1][j], f[1][j] = 0; } for (int j = m - sum1; j <= m + sum1; j++) for (int t = 0; t < 2; t++) { reduce(f[t][j + a[i]] += g[t][j] - mu); reduce(f[t][j - a[i]] += g[t][j] - mu); } sum1 += a[i]; } solve(l, mid, f, sum1); for (int i = 0; i <= 2 * m; i++) f[0][i] = tmp[0][now][i], f[1][i] = tmp[1][now][i]; sum1 = sum; for (int i = l; i <= mid; i++) { for (int j = m - sum1; j <= m + sum1; j++) { g[0][j] = f[0][j]; g[1][j] = f[1][j], f[1][j] = 0; } for (int j = m - sum1; j <= m + sum1; j++) for (int t = 0; t < 2; t++) { reduce(f[t][j + a[i]] += g[t][j] - mu); reduce(f[t][j - a[i]] += g[t][j] - mu); } sum1 += a[i]; } solve(mid + 1, r, f, sum1); } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= m; i++) { scanf("%d%d", &x, &y); add(x, y), add(y, x); } vis[1] = 1; for (int i = last[1]; i; i = Next[i]) { cnt = 1; int u = to[i]; if (vis[u]) continue; dfs(to[i]); a[++tot] = cnt; } dp[0] = id; dp[0][m] = 1; id += 2 * m; dp[1] = id; dp[1][m] = 1; cnt = 0; solve(1, tot, dp, 0); printf("%d\n", ans); }
8
CPP
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; template <class C> void mini(C &a4, C b4) { a4 = min(a4, b4); } template <class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); } template <class TH> void _dbg(const char *sdbg, TH h) { cerr << sdbg << '=' << h << endl; } template <class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) { while (*sdbg != ',') cerr << *sdbg++; cerr << '=' << h << ','; _dbg(sdbg + 1, a...); } template <class T> ostream &operator<<(ostream &os, vector<T> V) { os << "["; for (auto vv : V) os << vv << ","; return os << "]"; } template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) { return os << "(" << P.first << "," << P.second << ")"; } const long long MAX = 1001; long long n; long long gd[MAX]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(11); if (0) cout << fixed << setprecision(6); cin >> n; bool wynn = 1; for (long long i = (0); i <= ((long long)(n)-1); i++) { long long pom; cin >> pom; pom--; gd[pom] = i; if (pom != i) wynn = 0; } if (wynn) { cout << n << "\n"; string res(n, '.'); for (long long i = (0); i <= ((long long)(n)-1); i++) { cout << res << "\n"; } return 0; } cout << n - 1 << "\n"; long long wol = 0; for (long long _ = (0); _ <= ((long long)(n)-1); _++) { string res(n, '.'); if (gd[wol] != wol) { long long ak = -1; for (long long j = (0); j <= ((long long)(n)-1); j++) { if (gd[j] == wol) { ak = j; break; } } if (ak < wol) { res[ak] = '\\'; res[wol] = '\\'; if (gd[wol] == ak) { for (long long i = 0; i < ak; i++) { if (gd[i] != i) { res[i] = '\\'; swap(gd[i], gd[ak]); ak = i; break; } } } } else { res[ak] = '/'; res[wol] = '/'; for (long long i = n - 1; i > ak; i--) { if (gd[i] != i) { res[i] = '/'; swap(gd[i], gd[ak]); ak = i; break; } } } swap(gd[ak], gd[wol]); wol = ak; } else { for (long long j = (0); j <= ((long long)(n)-1); j++) { if (gd[j] < j && wol < gd[j]) { long long a = wol; long long b = gd[j]; long long c = j; res[a] = '/'; res[b] = '/'; res[c] = '/'; gd[a] = gd[b]; gd[b] = b; gd[c] = a; wol = c; break; } if (gd[j] > j && wol > gd[j]) { long long a = wol; long long b = gd[j]; long long c = j; res[a] = '\\'; res[b] = '\\'; res[c] = '\\'; gd[a] = gd[b]; gd[b] = b; gd[c] = a; wol = c; break; } } } cout << res << "\n"; } }
11
CPP
#include <bits/stdc++.h> using namespace std; char T[10][10]; int Ans = 0; int main() { for (int i = 0; i < 8; i++) { scanf("%s", T[i]); } for (int i = 0; i < 8; i++) { int CC = 0; for (int j = 0; j < 8; j++) { if (T[i][j] == 'B') { CC++; } } if (CC == 8) { Ans++; } } for (int i = 0; i < 8; i++) { int CC = 0; for (int j = 0; j < 8; j++) { if (T[j][i] == 'B') { CC++; } } if (CC == 8) { Ans++; } } if (Ans == 16) Ans = 8; printf("%d\n", Ans); }
7
CPP
#include <bits/stdc++.h> using namespace std; const int INF = 2e9 + 1; int main() { int n, k; cin >> n >> k; vector<int> times[4]; vector<int> sums[4]; for (int i = 0; i < n; ++i) { int t, a, b; cin >> t >> a >> b; times[a * 2 + b].push_back(t); } for (int i = 0; i < 4; ++i) { sort(times[i].begin(), times[i].end()); sums[i].push_back(0); for (auto it : times[i]) { sums[i].push_back(sums[i].back() + it); } } int ans = INF; for (int cnt = 0; cnt < min(k + 1, int(sums[3].size())); ++cnt) { if (k - cnt < int(sums[1].size()) && k - cnt < int(sums[2].size())) { ans = min(ans, sums[3][cnt] + sums[1][k - cnt] + sums[2][k - cnt]); } } if (ans == INF) ans = -1; cout << ans << endl; return 0; }
11
CPP
m,n = input().split(" ") width = int(m) height = int(n) isArea = width * height numOfDomino = isArea // 2 print(numOfDomino)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; template <char MIN_CHAR = 'a', int ALPHABET = 26> struct aho_corasick { struct node { int suff = -1, dict = -1, word_index = -1; int link[ALPHABET]; node() { fill(link, link + ALPHABET, -1); } int &operator[](char c) { return link[c - MIN_CHAR]; } }; int N, W; vector<node> nodes; vector<int> word_location; vector<int> word_indices_by_depth; vector<int> defer; aho_corasick(const vector<string> &words = {}) { if (!words.empty()) build(words); } vector<vector<int>> build_suffix_adj() const { vector<vector<int>> adj(N); for (int i = 1; i < N; i++) adj[nodes[i].suff].push_back(i); return adj; } int get_or_add_child(int current, char c) { if (nodes[current][c] >= 0) return nodes[current][c]; return nodes[current][c] = N++; } int add_word(const string &word, int word_index) { assert(!nodes.empty()); int current = 0; for (char c : word) current = get_or_add_child(current, c); if (nodes[current].word_index < 0) nodes[current].word_index = word_index; return current; } int get_suffix_link(int location, char c) const { if (location >= 0) location = nodes[location].link[c - MIN_CHAR]; return max(location, 0); } void build(const vector<string> &words) { nodes.resize(1e7 + 5); N = 0; nodes[N++] = node(); W = words.size(); word_location.resize(W); defer.resize(W); int max_depth = 0; for (int i = 0; i < W; i++) { word_location[i] = add_word(words[i], i); max_depth = max(max_depth, (int)words[i].size()); defer[i] = nodes[word_location[i]].word_index; } word_indices_by_depth.resize(words.size()); vector<int> depth_freq(max_depth + 1, 0); for (int i = 0; i < (int)words.size(); i++) depth_freq[words[i].size()]++; for (int i = max_depth - 1; i >= 0; i--) depth_freq[i] += depth_freq[i + 1]; for (int i = 0; i < (int)words.size(); i++) word_indices_by_depth[--depth_freq[words[i].size()]] = i; vector<int> q = {0}; for (int i = 0; i < (int)q.size(); i++) { int current = q[i]; for (char c = MIN_CHAR; c < MIN_CHAR + ALPHABET; c++) { int &index = nodes[current][c]; if (index >= 0) { int suffix_parent = get_suffix_link(nodes[current].suff, c); nodes[index].suff = suffix_parent; nodes[index].dict = nodes[suffix_parent].word_index >= 0 ? suffix_parent : nodes[suffix_parent].dict; q.push_back(index); } else { index = get_suffix_link(nodes[current].suff, c); } } } } vector<int> count_matches(const string &text) const { vector<int> matches(W, 0); int current = 0; for (char c : text) { current = get_suffix_link(current, c); int dict_node = nodes[current].word_index >= 0 ? current : nodes[current].dict; if (dict_node >= 0) matches[nodes[dict_node].word_index]++; } for (int word_index : word_indices_by_depth) { int location = word_location[word_index]; int dict_node = nodes[location].dict; if (dict_node >= 0) matches[nodes[dict_node].word_index] += matches[word_index]; } for (int i = 0; i < W; i++) matches[i] = matches[defer[i]]; return matches; } }; struct dinic_matching { static const int INF = 1e9 + 5; int N = -1, M = -1; vector<vector<int>> adj; vector<int> dist; vector<int> prev; vector<int> q; int q_start, q_end; vector<bool> matched; vector<int> edge_index; dinic_matching(int n = -1, int m = -1) { if (n >= 0 && m >= 0) init(n, m); } void init(int n, int m) { N = n; M = m; adj.assign(N, {}); dist.resize(N); q.resize(N); matched.resize(N); edge_index.resize(N); prev.resize(M); } void add_edge(int a, int b) { adj[a].push_back(b); } bool bfs() { fill(dist.begin(), dist.end(), INF); q_start = q_end = 0; for (int i = 0; i < N; i++) if (!matched[i]) bfs_check(i, 0); bool has_path = false; while (q_start < q_end) { int num = q[q_start++]; for (int next : adj[num]) if (prev[next] < 0) has_path = true; else bfs_check(prev[next], dist[num] + 1); } return has_path; } void bfs_check(int num, int potential_dist) { if (potential_dist < dist[num]) { dist[num] = potential_dist; q[q_end++] = num; } } bool dfs(int num) { while (edge_index[num] < (int)adj[num].size()) { int next = adj[num][edge_index[num]]; bool solved = false; if (prev[next] < 0 || (dist[num] + 1 == dist[prev[next]] && dfs(prev[next]))) { prev[next] = num; matched[num] = true; solved = true; } edge_index[num]++; if (solved) return true; } dist[num] = INF; return false; } int match() { assert(N >= 0 && M >= 0); for (int i = 0; i < N; i++) matched[i] = false; for (int j = 0; j < M; j++) prev[j] = -1; int matches = 0; while (bfs()) { for (int i = 0; i < N; i++) edge_index[i] = 0; for (int i = 0; i < N; i++) if (!matched[i] && dfs(i)) matches++; } return matches; } vector<bool> reachable_left, reachable_right; void reachable_dfs(int left) { reachable_left[left] = true; for (int right : adj[left]) if (prev[right] != left && !reachable_right[right]) { reachable_right[right] = true; int next_left = prev[right]; if (next_left >= 0 && !reachable_left[next_left]) reachable_dfs(next_left); } } vector<int> min_vertex_cover() { int size = match(); reachable_left.assign(N, false); reachable_right.assign(M, false); for (int i = 0; i < N; i++) if (!matched[i] && !reachable_left[i]) reachable_dfs(i); vector<int> cover; for (int i = 0; i < N; i++) if (!reachable_left[i]) cover.push_back(i); for (int i = 0; i < M; i++) if (reachable_right[i]) cover.push_back(N + i); assert((int)cover.size() == size); return cover; } vector<int> max_independent_set() { int cover_size = min_vertex_cover().size(); vector<int> independent_set; for (int i = 0; i < N; i++) if (reachable_left[i]) independent_set.push_back(i); for (int i = 0; i < M; i++) if (!reachable_right[i]) independent_set.push_back(N + i); assert((int)independent_set.size() == N + M - cover_size); return independent_set; } }; int N; vector<string> greetings; aho_corasick<'a', 2> AC; vector<vector<bool>> contains; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N; greetings.resize(N); for (string &greeting : greetings) cin >> greeting; AC.build(greetings); contains.assign(N, vector<bool>(N, false)); for (int i = 0; i < N; i++) { vector<int> matches = AC.count_matches(greetings[i]); for (int j = 0; j < N; j++) contains[i][j] = matches[j] > 0; } dinic_matching graph(N, N); for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) if (i != j && contains[i][j]) graph.add_edge(i, j); vector<int> vertex_cover = graph.min_vertex_cover(); vector<bool> in_cover(N, false); for (int v : vertex_cover) in_cover[v % N] = true; vector<int> independent_set; for (int i = 0; i < N; i++) if (!in_cover[i]) independent_set.push_back(i); cout << independent_set.size() << '\n'; for (int i = 0; i < (int)independent_set.size(); i++) cout << independent_set[i] + 1 << (i < (int)independent_set.size() - 1 ? ' ' : '\n'); }
11
CPP
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int i, j, n, first = -1; cin >> n; vector<int> v(n, 0); for (i = 0; i < n; i++) { cin >> v[i]; if (v[i] % 2 == 0) first = i; } int sum = v[0]; i = 1; while (i < n && sum % 2) { sum += v[i]; i++; } if (sum % 2) { if (first != -1) { cout << 1 << endl; cout << first + 1 << endl; } else cout << -1 << endl; } else { cout << i << endl; for (j = 1; j <= i; j++) cout << j << " "; cout << endl; } } }
7
CPP
#include<iostream> #include<algorithm> #include<cmath> #include<vector> #include<complex> #include<cassert> #include<iomanip> #define REP(i,s,n) for(int i=s;i<n;i++) #define rep(i,n) REP(i,0,n) #define EPS (1e-10) #define inf (1<<29) #define COUNTER_CLOCKWISE 1 #define CLOCKWISE -1 #define ONLINE_BACK 2 #define ONLINE_FRONT -2 #define ON_SEGMENT 0 #define equals(a,b) (fabs((a)-(b)) < EPS) using namespace std; class Point { public: double x,y; Point(double x = -inf,double y = -inf): x(x),y(y){} Point operator + (Point p ){return Point(x+p.x,y+p.y);} Point operator - (Point p){return Point(x-p.x,y-p.y);} Point operator * (double a){return Point(a*x,a*y);} Point operator / (double a){return Point(x/a,y/a);}//※イケメンに限る }; struct Segment { Point p1,p2; Segment(Point p1 = Point(),Point p2 = Point()):p1(p1),p2(p2){} }; typedef Point Vector; typedef Segment Line; typedef vector<Point> Polygon; double dot(Point a,Point b) { return a.x*b.x + a.y*b.y; } double cross(Point a,Point b) { return a.x*b.y - a.y*b.x; } double norm(Point a) { return a.x*a.x+a.y*a.y; } double abs(Point a) { return sqrt(norm(a)); } int ccw(Point p0,Point p1,Point p2) { Point a = p1-p0; Point b = p2-p0; if(cross(a,b) > EPS)return COUNTER_CLOCKWISE; if(cross(a,b) < -EPS)return CLOCKWISE; if(dot(a,b) < -EPS)return ONLINE_BACK; if(norm(a) < norm(b))return ONLINE_FRONT; return ON_SEGMENT; } double getDistanceLP(Line s,Point p) { return abs(cross(s.p2-s.p1,p-s.p1))/abs(s.p2-s.p1); } double getDistanceSP(Segment s,Point p) { if(dot(s.p2-s.p1,p-s.p1) < 0.0)return abs(p-s.p1); if(dot(s.p1-s.p2,p-s.p2) < 0.0)return abs(p-s.p2); return getDistanceLP(s,p); } struct Circle { Point p; double r; Circle(Point p=Point(),double r=inf):p(p),r(r){} }; bool isIntersect(Point p1,Point p2,Point p3,Point p4) { return (ccw(p1,p2,p3) * ccw(p1,p2,p4) <= 0 && ccw(p3,p4,p1) * ccw(p3,p4,p2) <= 0 ); } bool isIntersect(Segment s1,Segment s2) { return isIntersect(s1.p1,s1.p2,s2.p1,s2.p2); } //cross product of pq and pr double cross3p(Point p,Point q,Point r) { return (r.x-q.x) * (p.y -q.y) - (r.y - q.y) * (p.x - q.x); } //returns true if point r is on the same line as the line pq bool collinear(Point p,Point q,Point r) { return fabs(cross3p(p,q,r)) < EPS; } //returns true if point t is on the left side of line pq bool ccwtest(Point p,Point q,Point r) { return cross3p(p,q,r) > 0;//can be modified to accept collinear points } bool onSegment(Point p,Point q,Point r) { return collinear(p,q,r) && equals(sqrt(pow(p.x-r.x,2)+pow(p.y-r.y,2)) + sqrt(pow(r.x-q.x,2) + pow(r.y-q.y,2) ),sqrt(pow(p.x-q.x,2)+pow(p.y-q.y,2)) ) ; } bool isConvex(vector<Point> p) { int sz = (int)p.size(); if(sz < 3)return false;//boundary case, we treat a point or a line as not convex bool isLeft = ccwtest(p[0],p[1],p[2]); for(int i=1; i<(int)p.size();i++) if(ccwtest(p[i],p[(i+1)%sz],p[(i+2)%sz]) != isLeft) return false; return true; } double angle(Point a,Point b,Point c) { double ux = b.x - a.x, uy = b.y - a.y; double vx = c.x - a.x, vy = c.y - a.y; return acos((ux*vx + uy*vy)/sqrt((ux*ux + uy*uy) * (vx*vx + vy*vy))); } //多角形poly内(線分上も含む)に点pが存在するかどうは判定する bool inPolygon(Polygon poly,Point p) { if((int)poly.size() == 0)return false; //polyの最後の要素 = polyの最初の要素 であることが前提 //そうでない場合は rep(i,poly.size()) if(onSegment(poly[i],poly[(i+1)%poly.size()],p))return true; double sum = 0; for(int i=0; i < (int)poly.size() ;i++) { if(cross3p(p,poly[i],poly[(i+1)%poly.size()]) < 0) sum -= angle(p,poly[i],poly[(i+1)%poly.size()]); else sum += angle(p,poly[i],poly[(i+1)%poly.size()]); } return (fabs(sum - 2*M_PI) < EPS || fabs(sum + 2*M_PI) < EPS); } Point project(Segment s,Point p) { Vector base = s.p2 - s.p1; double t = dot(p-s.p1,base)/norm(base); return s.p1 + base*t; } double getDistance(Segment s1,Segment s2) { if(isIntersect(s1,s2))return 0; return min( min(getDistanceSP(s1,s2.p1), getDistanceSP(s1,s2.p2) ), min(getDistanceSP(s2,s1.p1), getDistanceSP(s2,s1.p2) )); } //------------------------------- bool intersectLL(Line l, Line m) { return abs(cross(l.p2-l.p1, m.p2-m.p1)) > EPS || // non-parallel abs(cross(l.p2-l.p1, m.p1-l.p1)) < EPS; // same line } bool intersectLS(Line l, Line s) { return cross(l.p2-l.p1, s.p1-l.p1)* // s[0] is left of l cross(l.p2-l.p1, s.p2-l.p1) < EPS; // s[1] is right of l } bool intersectLP(Line l,Point p) { return abs(cross(l.p2-p, l.p1-p)) < EPS; } bool intersectSS(Line s, Line t) { return ccw(s.p1,s.p2,t.p1)*ccw(s.p1,s.p2,t.p2) <= 0 && ccw(t.p1,t.p2,s.p1)*ccw(t.p1,t.p2,s.p2) <= 0; } bool intersectSP(Line s, Point p) { return abs(s.p1-p)+abs(s.p2-p)-abs(s.p2-s.p1) < EPS; // triangle inequality } Point projection(Line l,Point p) { double t = dot(p-l.p1, l.p1-l.p2) / norm(l.p1-l.p2); return l.p1 + (l.p1-l.p2)*t; } Point reflection(Line l,Point p) { return p + (projection(l, p) - p) * 2; } double distanceLP(Line l, Point p) { return abs(p - projection(l, p)); } double distanceLL(Line l, Line m) { return intersectLL(l, m) ? 0 : distanceLP(l, m.p1); } double distanceLS(Line l, Line s) { if (intersectLS(l, s)) return 0; return min(distanceLP(l, s.p1), distanceLP(l, s.p2)); } double distanceSP(Line s, Point p) { Point r = projection(s, p); if (intersectSP(s, r)) return abs(r - p); return min(abs(s.p1 - p), abs(s.p2 - p)); } double distanceSS(Line s, Line t) { if (intersectSS(s, t)) return 0; return min(min(distanceSP(s, t.p1), distanceSP(s, t.p2)), min(distanceSP(t, s.p1), distanceSP(t, s.p2))); } Point crosspoint(Line l, Line m) { double A = cross(l.p2 - l.p1, m.p2 - m.p1); double B = cross(l.p2 - l.p1, l.p2 - m.p1); if (abs(A) < EPS && abs(B) < EPS) return m.p1; // same line if (abs(A) < EPS) assert(false); // !!!PRECONDITION NOT SATISFIED!!! return m.p1 + (m.p2 - m.p1) * (B / A); } //------------------------------------------^^^ struct Obj { vector<Point> ps; double h; Obj(Point ps1=Point(),Point ps2=Point(),double h=-inf):h(h) { ps.clear(); ps.resize(4); ps[0].x = ps1.x,ps[0].y = ps1.y; ps[1].x = ps1.x,ps[1].y = ps2.y; ps[2].x = ps2.x,ps[2].y = ps2.y; ps[3].x = ps2.x,ps[3].y = ps1.y; } }; int N; Point s,e; int main() { while(cin >> N,N) { cin >> s.x >> s.y >> e.x >> e.y; Obj vec; Circle c(s); Segment seg(s,e); rep(i,N) { Point a,b; double h; cin >> a.x >> a.y >> b.x >> b.y >> h; if(c.r == 0)continue; vec = Obj(a,b,h); rep(j,4) { if(isIntersect(seg,Segment(vec.ps[j],vec.ps[(j+1)%4])) ) { c.r = 0; break; } } if(inPolygon(vec.ps,s) || inPolygon(vec.ps,e)) { c.r = 0; continue; } rep(j,4) { double w = distanceSS(seg,Segment(vec.ps[j],vec.ps[(j+1)%4])); //double w = getDistance(seg,Segment(vec.ps[j],vec.ps[(j+1)%4])); double dist = (h*h+w*w)/(2.0*h); if(!equals(w,h) && w < h)dist = w; c.r = min(c.r,dist); } } cout << setiosflags(ios::fixed) << setprecision(10) << c.r << endl; } return 0; }
0
CPP
i=input() if len(i)>1: l=[] for j in i: l.append(j) l=l[::2] o=[] for k in l: k=int(k) o.append(k) o.sort() s=[] for e in o: e=str(e) s.append(e) s.append('+') s.pop(len(s)-1) str1="" y=str1.join(s) print(y) else: print(int(i))
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int read() { char c = getchar(); int d = 0, f = 1; for (; c < '0' || c > '9'; c = getchar()) if (c == '-') f = -1; for (; c >= '0' && c <= '9'; d = d * 10 + c - 48, c = getchar()) ; return d * f; } char Read() { char c = getchar(); while (c < '0' || c > '9') c = getchar(); return c; } int getdigit(char c) { return (c < '0' || c > '9') ? -1e9 : (c - '0'); } const int inf = 1e9; const int N = 1000000; const int Up = 24; int T, tot, len[N + 1], pn, pr[N + 1], p[N + 1][10], w[10], mk[N + 1]; int TOT, pw[30001][31], t[31], op[30001]; bool cmp(int a, int b) { return a > b; } void dfs(int x, int s, int la, int S) { if (x > Up) { ++TOT; if (S <= N) op[TOT] = mk[S]; pw[TOT][0] = x - 1; for (int i = 1; i <= x - 1; ++i) pw[TOT][i] = t[i]; return; } for (int i = 0; i <= min(la, Up - s); ++i) { t[x] = i + 1; dfs(x + 1, s + i, i, S); S = (int)min(1LL * (N + 1), (long long)S * pr[x]); } } int cnt, head[80001]; struct edge { int to, next, s; } e[N * 4]; void addedge(int x, int y, int s) { e[++cnt] = (edge){y, head[x], s}; head[x] = cnt; } void Addedge(int x, int y, int s) { addedge(x, y, s); addedge(y, x, s); } int stot; map<long long, int> smp; void initedge() { stot = TOT; for (int i = 1; i <= TOT; ++i) { for (int j = 1; j <= Up; ++j) t[j] = pw[i][j]; long long S = 1; for (int j = 1; j <= Up; ++j) S = S * t[j]; int& Smp = smp[S]; if (!Smp) Smp = ++stot; S = Smp; addedge(i, S, 0); addedge(S, i + 40000, 0); for (int j = 1; j <= Up; ++j) if (j == Up || t[j] != t[j + 1]) if (t[j] > 1) { t[j]--; int L = 1, R = TOT; while (L < R) { int mid = (L + R) >> 1; bool flag = 0; for (int I = 1; I <= Up; ++I) { if (pw[mid][I] < t[I]) { flag = 1; break; } else if (pw[mid][I] > t[I]) break; } if (flag) L = mid + 1; else R = mid; } Addedge(i, L, 1); Addedge(i + 40000, L + 40000, 1); t[j]++; } } } int dis[300][80001], q[80001], ans[300][300]; void initdis() { for (int i = 1; i <= TOT; ++i) if (op[i]) { int* Dis = dis[op[i]]; for (int j = 1; j <= stot + 40000; ++j) Dis[j] = inf; Dis[i] = 0; int h1 = 1, t = 0; q[++t] = i; while (h1 <= t) { int h2 = t; for (int I = h1; I <= h2; ++I) for (int j = head[q[I]], y = e[j].to; j; j = e[j].next, y = e[j].to) if (e[j].s == 0) { if (Dis[y] < inf) continue; Dis[y] = Dis[q[I]]; q[++h2] = y; } t = h2; for (int I = h1; I <= h2; ++I) for (int j = head[q[I]], y = e[j].to; j; j = e[j].next, y = e[j].to) if (e[j].s == 1) { if (Dis[y] < inf) continue; Dis[y] = Dis[q[I]] + 1; q[++t] = y; } h1 = h2 + 1; } for (int j = 1; j <= TOT; ++j) if (op[j]) ans[op[i]][op[j]] = min(Dis[j + 40000], Dis[j]); } } int main() { for (int i = 2; i <= N; ++i) if (!len[i]) { for (int j = i; j <= N; j += i) p[j][++len[j]] = i; pr[++pn] = i; } for (int i = 1; i <= N; ++i) { memset(w, 0, sizeof w); int s = i; for (int j = 1; j <= 10; ++j) w[j] = 1; for (int j = 1; j <= len[i]; ++j) while (s % p[i][j] == 0) w[j]++, s /= p[i][j]; sort(w + 1, w + len[i] + 1, cmp); s = 1; for (int j = 1; j <= len[i]; ++j) for (int k = 1; k <= w[j] - 1; ++k) s = (long long)s * pr[j]; if (s == i) ++tot, mk[i] = tot; else mk[i] = mk[s]; } TOT = 0; dfs(1, 0, Up, 1); initedge(); initdis(); T = read(); while (T--) { int x = read(), y = read(); x = mk[x], y = mk[y]; printf("%d\n", ans[x][y]); } }
12
CPP
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <set> #include <map> using namespace std; int main() { int n; while(cin >> n && n) cout << n*(n-1)/2+n+1 << endl; }
0
CPP
#include <bits/stdc++.h> using namespace std; const int Maxn = 16; int dp[(1 << Maxn)][3 * Maxn]; int Tree[8]; int main() { int n, m; cin >> n >> m; if (n > m) { int a = n; n = m; m = a; } if (n == 1) { int tmp = m - m / 3; if (m % 3) tmp--; cout << tmp << endl; return 0; } for (int i = 0; i < (1 << Maxn); i++) for (int j = 0; j < 3 * Maxn; j++) dp[i][j] = 40; int Ans = n * m; for (int mask = 0; mask < (1 << n); mask++) { int cnt = 0; int arr[n + 1]; for (int i = 0; i < n; i++) arr[i] = 0; if (mask % 2) { cnt++; arr[0] = 2; arr[1] = 1; } for (int i = 1; i < n; i++) { if (mask & (1 << i)) cnt++, arr[i] = 2, arr[i - 1] = max(arr[i - 1], 1), arr[i + 1] = 1; } int MASK = 0; for (int i = n - 1; i + 1; --i) { MASK *= 3; MASK += arr[i]; } dp[MASK][0] = cnt; } Tree[0] = 1; for (int i = 1; i <= n; i++) Tree[i] = Tree[i - 1] * 3; for (int lev = 1; lev < m; ++lev) for (int mask1 = 0; mask1 < Tree[n]; mask1++) { for (int mask2 = 0; mask2 < Tree[n]; mask2++) { bool flag = 1; int cnt = 0; for (int i = 0; i < n; i++) { int f1 = 0, f2 = 0; f1 = (mask1 / Tree[i]) % 3; f2 = (mask2 / Tree[i]) % 3; if (f1 != 2 && !f2) flag = 0; if (f2 == 2 && !f1) flag = 0; } if (!flag) continue; for (int i = 1; i < n - 1; i++) { int f1 = (mask1 / Tree[i]) % 3; int f2 = (mask2 / Tree[i]) % 3; int f3 = (mask1 / Tree[i - 1]) % 3; int f4 = (mask1 / Tree[i + 1]) % 3; if (f1 == 1 && f2 != 2 && f3 != 2 && f4 != 2) flag = 0; } int f1 = (mask1 / Tree[0]) % 3; int f2 = (mask2 / Tree[0]) % 3; int f3 = (mask1 / Tree[1]) % 3; if (f1 == 1 && f2 != 2 && f3 != 2) flag = 0; int f4 = (mask1 / Tree[n - 1]) % 3; int f5 = (mask2 / Tree[n - 1]) % 3; int f6 = (mask1 / Tree[n - 2]) % 3; if (f4 == 1 && f5 != 2 && f6 != 2) flag = 0; if (!flag) continue; for (int i = 0; i < n; i++) { int f = (mask1 / Tree[i]) % 3; if (f == 2) cnt++; } dp[mask1][lev] = min(dp[mask1][lev], cnt + dp[mask2][lev - 1]); } } for (int i = 0; i < Tree[n]; i++) { int tmp = i; for (int j = 0; j < n; j++) { if (tmp % 3 == 0) { tmp = -1; break; } tmp /= 3; } if (tmp + 1) { Ans = min(Ans, dp[i][m - 1]); } } cout << n * m - Ans << endl; return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; int n, p, q, a[300]; int main() { cin >> n >> p; for (int i = 0; i < p; i++) cin >> a[i]; cin >> q; for (int i = p; i < p + q; i++) cin >> a[i]; sort(a, a + p + q); int l = 1; for (int i = 0; i < p + q; i++) { if (a[i] == l) { l++; } } if (l == n + 1) { cout << "I become the guy." << endl; } else { cout << "Oh, my keyboard!" << endl; } }
7
CPP
t=int(input()) while(t): t-=1 a,b,c=map(int,input().split()) if(a>=c): print("-1",end=" ") else: print("1",end=" ") if((c/b)>=a): print("-1") else: print(b)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int INF = 0x3fffffff; const int SINF = 0x7fffffff; const long long LINF = 0x3fffffffffffffff; const long long SLINF = 0x7fffffffffffffff; const int MAXN = 200007; const int MAXS = 2000007; int OK[3 * 3 * 3 * 3]; class ftT { public: void upd(int p, int x) { for (; p < MAXN; p += p & -p) data[p] += x; } int sum(int p) { int ans = 0; for (; p; p ^= p & -p) ans += data[p]; return ans; } private: int data[MAXN]; } ft; struct qT { int l, d, r, u; } que[MAXN]; struct oT { void setd(int _id, int _x, int _y) { id = _id, x = _x, y = _y; } int id, x, y, ans; } nq[MAXS]; int n, q; int nk; int cp[MAXN], p[MAXN]; int nt[3][3]; void init(); void input(); void work(); void presolve(); int main() { init(); input(); work(); } void init() { ios::sync_with_stdio(false); for (int a = 0; a < 3; ++a) { for (int b = 0; b < 3; ++b) { for (int c = 0; c < 3; ++c) { for (int d = 0; d < 3; ++d) { if (a * 3 + b < c * 3 + d) { if (((((a) < (c)) ? (a) : (c)) <= 1 && (((a) > (c)) ? (a) : (c)) >= 1) && ((((b) < (d)) ? (b) : (d)) <= 1 && (((b) > (d)) ? (b) : (d)) >= 1)) { OK[a * 27 + b * 9 + c * 3 + d] = 1; } } } } } } } void input() { scanf("%d%d", &n, &q); for (int i = 1; i <= n; ++i) scanf("%d", &cp[i]); for (int i = 1; i <= q; ++i) scanf("%d%d%d%d", &que[i].l, &que[i].d, &que[i].r, &que[i].u); } void work() { for (int i = 1; i <= n; ++i) p[cp[i]] = i; nk = 0; int nx, ny; for (int i = 1; i <= q; ++i) { for (int j = 0; j < 3; ++j) { nx = (j == 0) ? (que[i].d - 1) : (j == 1) ? (que[i].u) : n; for (int k = 0; k < 3; ++k) { ny = (k == 0) ? (que[i].l - 1) : (k == 1) ? (que[i].r) : n; nq[++nk].setd(nk, nx, ny); } } } presolve(); nk = 0; long long ans = 0; int na, nb, nc, nd; for (int i = 1; i <= q; ++i) { for (int j = 0; j < 3; ++j) { for (int k = 0; k < 3; ++k) { nt[j][k] = nq[++nk].ans; } } for (int a = 0; a < 3; ++a) { na = a * 27; for (int b = 0; b < 3; ++b) { nb = na + b * 9; for (int c = 0; c < 3; ++c) { nc = nb + c * 3; for (int d = 0; d < 3; ++d) { nd = nc + d; if (c <= a && d <= b && ((a ^ c) || (b ^ d))) { nt[a][b] -= nt[c][d]; } } } } } ans = 0; for (int a = 0; a < 3; ++a) { na = a * 27; for (int b = 0; b < 3; ++b) { nb = na + b * 9; for (int c = 0; c < 3; ++c) { nc = nb + c * 3; for (int d = 0; d < 3; ++d) { nd = nc + d; if (OK[nd]) { ans += static_cast<long long>(nt[a][b]) * nt[c][d]; } } } } } ans += static_cast<long long>(nt[1][1]) * (nt[1][1] - 1) >> 1; printf("%I64d\n", ans); } } void presolve() { sort(nq + 1, nq + 1 + nk, [](const oT &a, const oT &b) { return (a.x ^ b.x) ? (a.x < b.x) : (a.y < b.y); }); int iq = 1; for (; iq <= nk && nq[iq].x == 0; ++iq) ; for (int i = 1; i <= n; ++i) { ft.upd(p[i], 1); for (; iq <= nk && nq[iq].x == i; ++iq) { nq[iq].ans = ft.sum(nq[iq].y); } } sort(nq + 1, nq + 1 + nk, [](const oT &a, const oT &b) { return a.id < b.id; }); }
11
CPP
a, b = map(int, input().split()) ans=0 while(a>=b): ans=ans+b a=a-b+1 print(ans+a)
7
PYTHON3
import sys from functools import wraps def memoize(function): memo = {} @wraps(function) def wrapper(*args): if args in memo: return memo[args] else: res = function(*args) memo[args] = res return res return wrapper @memoize def count(canvas, pos, last): if pos == len(canvas): return 1 res = 0 for color in "CYM": if not (color == last or (canvas[pos] != '?' and color != canvas[pos])): res += count(canvas, pos + 1, color) return res def main(args): n = int(input()) canvas = input() print("Yes" if count(canvas, 0, 'X') >= 2 else "No") if __name__ == '__main__': sys.exit(main(sys.argv))
7
PYTHON3
t = int(input()) for s in range(t) : a,b,n = map(int,input().split()) step = 0 while True : if a > b : b += a step += 1 else : a += b step += 1 if a > n or b > n: print(step) break
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = s.size(); if(s[0] != '1' or s[n - 1] == '1') { cout << -1 << '\n'; return 0; } s = '0' + s; for(int i = 1; i < n; ++i) { if(s[i] != s[n - i]) { cout << -1 << '\n'; return 0; } } int par = 1; for(int i = 1; i < n; ++i) { if(s[i] == '1') { cout << par << " " << i + 1 << '\n'; par = i + 1; } else { cout << par << " " << i + 1 << '\n'; } } return 0; }
0
CPP
def fac1(n): fac = 1 i = 0 while i < n: i += 1 fac = fac * i return fac def gcd(x,y): while y: x, y = y, x % y return x def gcdfac(x,y): if x > y: return fac1(y) else: return fac1(x) x,y = map(int,input().split()) print(gcdfac(x,y))
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main(void){ int a,b; for (int i=0;i<7;i++) { cin>>a>>b; cout<<a-b<<endl; } }
0
CPP
#include <bits/stdc++.h> using namespace std; int arr[100005]; int arr2[100005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, cnt = 0; cin >> n; string str; cin >> str; for (auto i : str) { if (i == '(') { cout << ++cnt % 2; } else { cout << cnt-- % 2; } } cout << endl; }
10
CPP
#include <bits/stdc++.h> using namespace std; long long MOD = 1e9 + 7; bool debug = 1; const int N = 1e5 + 10; bool vis[N]; int g[N]; int dfs(int i) { vis[i] = 1; if (!vis[g[i]]) { return 1 + dfs(g[i]); } return 1; } int main() { int n, x; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &x); x--; g[i] = x; } vector<int> vc; for (int i = 0; i < n; i++) { if (!vis[i]) vc.push_back(dfs(i)); } long long tot = 0; sort(vc.begin(), vc.end(), greater<int>()); for (int i = 0; i < min((int)vc.size(), 2); i++) { tot += vc[i]; } tot = tot * tot; for (int i = 2; i <= vc.size() - 1; i++) { tot += 1ll * vc[i] * vc[i]; } cout << tot << endl; return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const double eps = 1e-10, pi = acos(-1); int n, k; double x[N], y[N]; long double dis[N]; int cnt, t, c[N]; struct node { long double p; int v; inline node(long double P = 0, int V = 0) : p(P), v(V) {} inline bool operator<(const node &a) const { return p < a.p; } } w[N * 10]; inline void push(long double d, long double u) { ++cnt, w[cnt] = node(d, 1); ++cnt, w[cnt] = node(u, -1); } inline bool check(long double r) { cnt = 0; for (int i = 1; i <= n; ++i) if (dis[i] <= 2 * r) { long double a = atan2((long double)y[i], (long double)x[i]), b = acos((long double)0.5 * dis[i] / r); long double up = a + b, dn = a - b; if (dn < -pi) push(dn + 2 * pi, pi), push(-pi, up); else if (up > pi) push(dn, pi), push(-pi, up - 2 * pi); else push(dn, up); } sort(w + 1, w + cnt + 1); int mx = 0, d = 0; for (int i = 1; i <= cnt; ++i) d += w[i].v, mx = max(mx, d); return mx >= k; } int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; ++i) scanf("%lf%lf", &x[i], &y[i]), dis[i] = sqrt(x[i] * x[i] + y[i] * y[i]); double l = 0, r = 200000; while (r - l > eps) { double mid = (l + r) / 2; if (check(mid)) r = mid; else l = mid; } printf("%.10lf", l); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { int W, H; cin >> H >> W; for (int i=0; i<H; i++){ string s; cin >> s; cout << s << endl; cout << s << endl; } }
0
CPP
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const int N = 1e6 + 5; int n, x[N], y[N], seg[4 * N]; void update(int node, int s, int e, int i, int val) { if (s == e) { seg[node] = val; return; } int mid = s + e >> 1; if (i <= mid) update(node << 1, s, mid, i, val); else update(node << 1 | 1, mid + 1, e, i, val); seg[node] = max(seg[node << 1], seg[node << 1 | 1]); } int query(int node, int s, int e, int l, int r) { if (l > e || s > r) return 0; if (l <= s && r >= e) return seg[node]; int mid = s + e >> 1; return max(query(node << 1, s, mid, l, r), query(node << 1 | 1, mid + 1, e, l, r)); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> x[i]; for (int i = 1; i <= n; i++) { int r; cin >> r; y[r] = i; } for (int i = 1; i <= n; i++) { int mx = query(1, 1, n, y[x[i]], n); update(1, 1, n, y[x[i]], mx + 1); } cout << seg[1]; return 0; }
10
CPP
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define ll long long #define MOD 998244353 #define fi first #define se second #define IT vector < int > :: iterator using namespace std; const int NR = 2e5 + 10 , oo = 2e9 ; void pres () { #ifndef ONLINE_JUDGE freopen("date.in", "r", stdin); // freopen("date.out", "w", stdout); #endif } int maxim , a [ 150 ][ 150 ] , n , b [ 150 ][ 150 ] ; int main() { int i , j ; // pres(); cin >> n ; if ( n <= 2 ) return cout << -1 , 0 ; for ( i = 2 ; i <= n ; ++ i ) { a [ 1 ][ i ] = i - 1 ; } for ( i = 2 ; i <= n ; ++ i ) { maxim = 1 ; for ( j = 1 ; j < i ; ++ j ) { a [ i ][ j ] = a [ j ][ i ] + 1 ; if ( a [ i ][ j ] == n ) a [ i ][ j ] = 1 ; maxim = a [ i ][ j ]; } maxim ++ ; for ( j = i + 1 ; j <= n ; ++ j ) { if ( maxim == n ) maxim = 1 ; a [ i ][ j ] = maxim ; maxim ++ ; } } for ( i = 1 ; i <= n ; ++ i ) for ( j = 1 ; j <= n ; ++ j ) { if ( i == j ) continue ; b [ i ][ a [ i ][ j ] ] = j ; } for ( i = 1 ; i <= n ; ++ i , cout << '\n' ) for ( j = 1 ; j < n ; ++ j ) cout << b [ i ][ j ] << ' ' ; return 0 ; }
0
CPP
#include <bits/stdc++.h> using namespace std; long long k, l, r, mid, tot, sz; string ans; long long calc() { long long ret = 0, i = 1, j = 9, k = 9; for (; j < mid; i++, k *= 10LL, j += k) { ret += i * (k * (k + 1LL) / 2LL) + i * k * (mid - j); } k = mid - j / 10LL, ret += i * (k * (k + 1LL) / 2); return ret; } void solve() { cin >> k; k--, l = 0, r = 2e9; while (l < r) { mid = (l + r + 1LL) / 2LL; if (calc() > k) { r = mid - 1LL; } else { l = mid; } } mid = l, k -= calc(), sz = 1, tot = 9; while (k >= tot * sz) { k -= tot * (sz++), tot *= 10LL; } ans = to_string(k / sz + tot / 9LL); cout << ans[k % sz] << '\n'; } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) solve(); return 0; }
11
CPP
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int f[404][404], g[404][404], h[404][404], w[404], v[404], a[404]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &v[i]); for (int i = 1; i <= n; i++) scanf("%d", &w[i]); for (int i = 1; i <= n; i++) { f[i][i] = v[1]; g[i][i] = h[i][i] = 0; } for (int l = 1; l <= n; l++) { for (int i = 1; i + l - 1 <= n; i++) { int j = i + l - 1; if (i == j) continue; f[i][j] = g[i][j] = h[i][j] = -1e8; for (int k = i + 1; k <= j; k++) { if (w[i] + 1 == w[k]) g[i][j] = max(g[i][j], f[i + 1][k - 1] + g[k][j]); if (w[i] - 1 == w[k]) h[i][j] = max(h[i][j], f[i + 1][k - 1] + h[k][j]); f[i][j] = max(f[i][j], f[i][k - 1] + f[k][j]); } for (int k = i; k <= j; k++) { long long len = 2LL * w[k] - w[i] - w[j] + 1; if (0 <= len && len <= n) f[i][j] = max(f[i][j], g[i][k] + h[k][j] + v[2 * w[k] - w[i] - w[j] + 1]); } } } a[0] = 0; for (int j = 1; j <= n; j++) { a[j] = a[j - 1]; for (int i = 1; i <= j; i++) a[j] = max(a[j], a[i - 1] + f[i][j]); } printf("%d\n", a[n]); return 0; }
11
CPP
test = int(input()) for _ in range(test): n = int(input()) if n%4==0: print("YES") else: print("NO")
7
PYTHON3
n = int(input()) c = 0 for i in range(n): s = input() if (s == "X++"or s =="++X"): c +=1 elif(s == "--X" or s == "X--"): c -=1 print(c)
7
PYTHON3
#include <iostream> #include <cstring> #include <algorithm> #include <cstdio> #include <queue> #include <vector> #include <set> #include <map> #define ll long long #define PII pair<int,int> using namespace std; ///////////////////////////// const int N=1e6+100; int main() { int T; cin>>T; while(T--) { ll n,m,x; cin>>n>>m>>x; ll l=x/n; if(x%n) l++; ll h; if(x%n==0) h=n; else h=x%n; ll ans=(h-1)*m+l; cout<<ans<<endl; } }
7
CPP
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) vector<int>v; int main() { int n; cin >> n; rep(i, n) { int a; cin >> a; v.push_back(a); } v.erase(unique(v.begin(), v.end()), v.end()); rep(i, v.size())cout << v[i] << (i == v.size() - 1 ? "\n" : " "); return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; pair<int, long long> ans; long long m; inline void get_ready() { cin >> m; } inline long long getmax(long long x) { if (x == 1) return 1; long long l = 1, r = 100007, maxx = 1; while (l <= r) { long long mid = (long long)(l + r) >> 1; if (mid * mid * mid <= x) maxx = mid, l = mid + 1; else r = mid - 1; } return maxx; } inline long long getpow(long long x) { return x * x * x; } inline void dfs(long long m, int num, long long now) { if (m == 0) { ans = max(ans, make_pair(num, now)); return; } long long x = getmax(m); dfs(m - getpow(x), num + 1, now + getpow(x)); if (x >= 1) dfs(getpow(x) - getpow(x - 1) - 1, num + 1, now + getpow(x - 1)); } inline void slove() { dfs(m, 0, 0); cout << ans.first << " " << ans.second << endl; } int main() { get_ready(); slove(); return 0; }
10
CPP
l,r=list(map(int,input().split())) if l==r: print(l) else: if abs(l - r) == 3: if l % 2 == 0: print(2) elif l == 3: print(3) else: print(2) else: print(2)
7
PYTHON3
# import sys # sys.stdin = open("test.in","r") # sys.stdout = open("test.out","w") for i in range(int(input())): n=int(input()) a=list(map(int,input().split())) a.sort() f=0 for i in range(n-1): if a[i+1]-a[i]==1: f=1 break if f==0: print('1') else: print('2')
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; int main() { long long int t; cin >> t; while (t--) { long long int ar[4]; set<long long int> s; long long int mx = -1; for (long long int i = 1; i <= 3; i++) { cin >> ar[i]; s.insert(ar[i]); mx = max(ar[i], mx); } if ((long long int)s.size() == 3) { cout << "NO" << "\n"; } else if ((long long int)s.size() == 2) { long long int f = 1; sort(ar + 1, ar + 4); for (long long int i = 2; i <= 3; i++) { if (ar[i] == ar[i - 1]) { if (ar[i] != mx) f = 0; } } if (f) { cout << "YES" << "\n"; for (long long int i : s) cout << i << ' '; cout << 1 << "\n"; } else { cout << "NO" << "\n"; } } else { cout << "YES" << "\n"; for (long long int i = 1; i <= 3; i++) { cout << ar[i] << ' '; } cout << "\n"; } } }
7
CPP
#include <bits/stdc++.h> using namespace std; struct Point { int x, y; Point operator-(Point b) { Point ret; ret.x = x - b.x; ret.y = y - b.y; return ret; } int operator^(Point a) { return x * a.y - y * a.x; } }; bool cmp(Point a, Point b) { return a.x == b.x ? a.y < b.y : a.x < b.x; } bool HASH[555][555]; char cmap[555][555]; int n; vector<Point> p, q, tmp; void convex_hull() { sort(p.begin(), p.end(), cmp); tmp.clear(); n = (int)p.size(); for (int i = 0; i < n; i++) { while ((int)q.size() > 1 && ((p[i] - q[(int)q.size() - 1]) ^ (q[(int)q.size() - 1] - q[(int)q.size() - 2])) <= 0) q.pop_back(); while ((int)tmp.size() > 1 && ((p[i] - tmp[(int)tmp.size() - 1]) ^ (tmp[(int)tmp.size() - 1] - tmp[(int)tmp.size() - 2])) >= 0) tmp.pop_back(); q.push_back(p[i]); tmp.push_back(p[i]); } for (int i = (int)tmp.size() - 2; i; i--) q.push_back(tmp[i]); return; } int main() { while (scanf("%d", &n) == 1 && n) { for (int i = 0; i < n; i++) scanf("%s", cmap[n - i] + 1); memset(HASH, 0, sizeof(HASH)); p.clear(); q.clear(); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) if (cmap[i][j] == '1') { Point tmp; if (cmap[i][j + 1] != '0' && cmap[i + 1][j] != '0' && cmap[i + 1][j + 1] != '0') { tmp.x = j; tmp.y = i; } else if (cmap[i][j - 1] != '0' && cmap[i + 1][j] != '0' && cmap[i + 1][j - 1] != '0') { tmp.x = j - 1; tmp.y = i; } else if (cmap[i - 1][j - 1] != '0' && cmap[i][j - 1] != '0' && cmap[i - 1][j] != '0') { tmp.x = j - 1; tmp.y = i - 1; } else { tmp.x = j; tmp.y = i - 1; } if (!HASH[tmp.x + 1][tmp.y + 1]) { HASH[tmp.x + 1][tmp.y + 1] = 1; p.push_back(tmp); } } convex_hull(); printf("%d\n", (int)q.size()); for (int i = 0; i < (int)q.size(); i++) printf("%d %d\n", q[i].x, q[i].y); } return 0; }
8
CPP
n = int(input()) a = [0] for i in range(n): m = int(input()) new = [] for j in a: new.extend([j + m, j - m]) a = new[:] print("yes" if any(c%360==0 for c in a) else "no")
8
PYTHON3
x, y, z = input().split() base, dollars, total=int(x), int(y),int(z) price=0 for b in range(1,total+1): price += b*base if dollars < price: print(abs(dollars - price)) else: print(0)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n < 3) cout << -1; else if (n == 3) cout << 210; else { int pow10 = 1; for (int i = 0, _i = (n - 1); i < _i; ++i) { pow10 *= 10; pow10 %= 210; } int r = (210 - pow10) % 210; cout << 1; for (int i = 0, _i = (n - 4); i < _i; ++i) cout << 0; cout << r / 100; r %= 100; cout << r / 10; r %= 10; cout << r; } }
8
CPP
from bisect import bisect_right as bisect n=int(input()) s=list(map(int,input().split())) q=int(input()) t=list(map(int,input().split())) s.sort() ans=0 for i in range(q): index=bisect(s,t[i]) if index>0: if t[i]==s[index-1]: ans+=1 print(ans)
0
PYTHON3
#include <bits/stdc++.h> using namespace std; long long n, m, ans; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; ans = n * m / 2; if (n > m) swap(n, m); if (n == 1) if (((m + 1) % 6) / 3 != 0) --ans; if (n == 2) { if (m == 2) ans -= 2; if (m == 3 || m == 7) ans -= 1; } cout << 2 * ans; return 0; }
10
CPP
count = 0 num = int(input()) scores = list(map(int,input().split())) worst = scores[0] best = scores[0] for i in range(1,num): if scores[i] > best: best = scores[i] count += 1 if scores[i] < worst: worst = scores[i] count += 1 print(count)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6 + 7; const int INF = 1e9; int s, k, n, m, x, y, p, q, a, b, c, d, caseno = 0; int ar[MAX], ans = 0; int MAIN() { scanf("%d", &n); for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) { scanf("%d", &a); if (i == j) ans ^= a; } scanf("%d", &m); while (m--) { scanf("%d", &a); ; if (a <= 2) { scanf("%d", &b); ans ^= 1; } else printf("%d", ans); } return 0; } int main() { ios_base::sync_with_stdio(false); int start = clock(); cout << fixed << setprecision(16); int ret = MAIN(); return ret; }
7
CPP
#include <bits/stdc++.h> using namespace std; long long int power(long long int x, long long int y, long long int p) { long long int temp; if (y <= 0) return 1; temp = power(x, y / 2, p); if (y % 2 == 0) { return (temp * temp) % p; } else { return (((x * temp) % p) * temp) % p; } } long long int power_not_p(long long int x, long long int y) { long long int temp; if (y <= 0) { return 1; } temp = power_not_p(x, y / 2); if (y % 2 == 0) { return temp * temp; } else { return x * temp * temp; } } long long int modInverse(long long int n, long long int p) { return power(n, p - 2, p); } long long int nCrModPFermat(long long int n, long long int r, long long int p) { if (r == 0) { return 1; } long long int fac[n + 1]; fac[0] = 1; for (long long int i = 1; i <= n; i++) { fac[i] = fac[i - 1] * i % p; } return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; } long long int gcd(long long int x, long long int y) { if (x == 0) { return y; } return gcd(y % x, x); } long long int lcm(long long int x, long long int y) { return (x * y) / gcd(x, y); } void print_array_int(int arr[], int n) { for (int i = 0; i < n; i++) { cout << arr[i] << " "; } cout << endl; return; } void print_array_lli(long long int arr[], long long int n) { for (long long int i = 0; i < n; i++) { cout << arr[i] << " "; } cout << endl; return; } void addEdge(vector<int> v[], int x, int y) { v[x].push_back(y); } void bfs(vector<int> v[], bool visited[], int dist[], int x) { queue<int> q; q.push(x); visited[x] = true; while (!q.empty()) { int f = q.front(); q.pop(); for (int i = 0; i < v[f].size(); i++) { if (!visited[v[f][i]]) { q.push(v[f][i]); visited[v[f][i]] = true; dist[v[f][i]] = dist[f] + 1; } } } } long long int nCk(long long int n, long long int k) { long long int res = 1; if (k > n - k) { k = n - k; } for (long long int i = 0; i < k; ++i) { res *= (n - i); res /= (i + 1); } return res; } bool compare(pair<int, bool> a, pair<int, bool> b) { if (a.second == b.second) { if (a.first < b.first) { return true; } return false; } return a.first < b.first; } int bs(pair<int, bool> arr[], int n, pair<int, bool> ele) { int high = n - 1; int low = 0; int mid; while (low <= high) { int mid = (low + high) / 2; if (arr[mid].first == ele.first && arr[mid].second == ele.second) { return mid; } else if (arr[mid].first < ele.first) { low = mid + 1; } else { high = mid - 1; } } return -1; } char beats(char c) { if (c == 'R') { return 'P'; } else if (c == 'S') { return 'R'; } return 'S'; } int solve() { int arr[4]; cin >> arr[0] >> arr[1] >> arr[2] >> arr[3]; int odd = 0, even = 0; bool flag = 0; for (int i = 0; i < 4; i++) { odd += arr[i] % 2 == 1 ? 1 : 0; even += arr[i] % 2 == 0 ? 1 : 0; } if ((odd == 1 && even == 3) || even == 4) flag = 1; if (arr[0] > 0 && arr[1] > 0 && arr[2] > 0) { arr[0]--; arr[1]--; arr[2]--; arr[3] += 3; } odd = 0; even = 0; for (int i = 0; i < 4; i++) { odd += arr[i] % 2 == 1 ? 1 : 0; even += arr[i] % 2 == 0 ? 1 : 0; } if ((odd == 1 && even == 3) || even == 4) flag = 1; if (flag) { cout << "Yes" << endl; } else { cout << "No" << endl; } } int main() { int n, m; cin >> n >> m; int a[n], b[m]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < m; i++) { cin >> b[i]; } int c[n]; for (int i = 0; i < n; i++) { c[i] = INT_MAX; } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { c[i] = min(c[i], (a[i] & b[j])); } } int minn = *max_element(c, c + n); for (int i = 0; i < n; i++) { c[i] = INT_MAX; for (int j = 0; j < m; j++) { c[i] = min(c[i], minn | (a[i] & b[j])); } minn = minn | c[i]; } cout << minn << endl; return 0; }
9
CPP
#include <iostream> #include <algorithm> #include <deque> #include <vector> using namespace std; int n; int cnt; deque<int> c; int a[12]; void Op(deque<int> s) { for (int i = 0; i < n; i++){ c.push_back(count(s.begin(), s.end(), a[i])); a[i] = c.back(); } cnt++; } int main() { while (cin >> n, n){ deque<int> s; int cn = 0; cnt = 0; for (int i = 0; i < n; i++){ cin >> a[i]; s.push_back(a[i]); } while (cn != n){ Op(s); cn = 0; for (int i = 0; i < n; i++){ if (s.front() == c.front()){ cn++; } s.pop_front(); s.push_back(c.front()); c.pop_front(); } } cout << cnt - 1 << "\n" << s[0]; for (int i = 1; i < n; i++){ cout << " " << s[i]; } cout << endl; } }
0
CPP
// Author -- xyr2005 #include<bits/stdc++.h> #define lowbit(x) ((x)&(-(x))) #define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__) #define SZ(x) ((int)x.size()) #define mkpr std::make_pair #define pb push_back typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef std::pair<int,int> pi; typedef std::pair<ll,ll> pl; using std::min; using std::max; const int inf=0x3f3f3f3f,Inf=0x7fffffff; const ll INF=0x3f3f3f3f3f3f3f3f; std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count()); template <typename _Tp>_Tp gcd(const _Tp &a,const _Tp &b){return (!b)?a:gcd(b,a%b);} template <typename _Tp>inline _Tp abs(const _Tp &a){return a>=0?a:-a;} template <typename _Tp>inline void chmax(_Tp &a,const _Tp &b){(a<b)&&(a=b);} template <typename _Tp>inline void chmin(_Tp &a,const _Tp &b){(b<a)&&(a=b);} template <typename _Tp>inline void read(_Tp &x) { char ch(getchar());bool f(false);while(!isdigit(ch)) f|=ch==45,ch=getchar(); x=ch&15,ch=getchar();while(isdigit(ch)) x=(((x<<2)+x)<<1)+(ch&15),ch=getchar(); f&&(x=-x); } template <typename _Tp,typename... Args>inline void read(_Tp &t,Args &...args){read(t);read(args...);} inline int read_str(char *s) { char ch(getchar());while(ch==' '||ch=='\r'||ch=='\n') ch=getchar(); char *tar=s;*tar++=ch,ch=getchar();while(ch!=' '&&ch!='\r'&&ch!='\n'&&ch!=EOF) *tar++=ch,ch=getchar(); return *tar=0,tar-s; } const int N=(1<<20)+5; char s[5005]; int L[N],R[N],cnt[N],t[27],id[27]; bool dp[N]; int main() { memset(id,255,sizeof(id)); int n,a,b;read(n,a,b); read_str(s+1); int m=0; for(int i=1;i<=n;++i) { int tmp=s[i]-'a'; if(id[tmp]==-1) t[m]=tmp,id[tmp]=m,L[1<<m]=i,R[1<<m]=i,++m; else R[1<<id[tmp]]=i; ++cnt[1<<id[tmp]]; } std::vector<int> ans; for(int i=0;i<m;++i) if(a*(R[1<<i]-L[1<<i]+1)<=cnt[1<<i]*b) dp[1<<i]=true,((1<<i)==(1<<m)-1)&&(ans.pb(i),0); L[0]=n+1,R[0]=0,dp[0]=true; for(int st=1;st<1<<m;++st) { L[st]=min(L[lowbit(st)],L[st^lowbit(st)]),R[st]=max(R[lowbit(st)],R[st^lowbit(st)]),cnt[st]=cnt[lowbit(st)]+cnt[st^lowbit(st)]; int cur=0; for(int i=0;i<m;++i)if((st>>i)&1) { cur|=1<<i; if(dp[cur]&&dp[st^cur]) dp[st]=true; } if(dp[st]) { for(int i=0;i<m;++i)if(!((st>>i)&1)) { int l=min(L[1<<i],L[st]),r=max(R[1<<i],R[st]); if(a*(r-l+1)<=(cnt[st]+cnt[1<<i])*b) { if((st|(1<<i))==(1<<m)-1) ans.pb(i); dp[st|(1<<i)]=true; } } } } std::sort(ans.begin(),ans.end(),[&](int a,int b)->bool{return t[a]<t[b];}),ans.erase(std::unique(ans.begin(),ans.end()),ans.end()); printf("%d ",SZ(ans)); for(auto it:ans) printf("%c ",t[it]+'a'); printf("\n"); return 0; }
13
CPP
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; #define REP(i,s,n) for(int i=(int)(s);i<(int)(n);++i) #define rep(i,n) REP(i, 0, n) typedef long long int i64; typedef pair<int, int> pint; bool check(int x) { for(int y = 2; y * y <= x; ++y) if(x % y == 0) { int sqy = sqrt((double)y) + 1.0e-13; for(int a = -sqy; a <= sqy; ++a) for(int b = -sqy; b <= sqy; ++b) if(a * a + b * b == y) return true; } return false; } int main() { cin.tie(0); ios::sync_with_stdio(false); int T; cin >> T; int m, n; rep(___, T) { cin >> m >> n; cout << (check(m * m + n * n) ? 'C' : 'P') << '\n'; } return 0; }
0
CPP
s = input() i = 1 a = [] if (len(s) == 2): print(0) exit(0) while i < len(s): a.append(int(ord(s[i]))) i = i + 3 a.sort() ans = 0 for i in range(len(a)): if i == 0 or a[i]!=a[i-1]: ans = ans + 1 print(ans)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int N = (int)1e3 + 1, MOD = (int)2e5 + 1; int c[N]; string s[N]; int accept() { int n, m; cin >> n >> m; for (int i = 0; i < 2230; i++) cout << 5; cout << "\n"; for (int i = 0; i < 2229; i++) cout << 4; cout << 5 << "\n"; return 0; } int main() { ios_base ::sync_with_stdio(0), cin.tie(0), cout.tie(0); int t = 1; while (t--) { accept(); } return 0; exit(0); }
8
CPP
N,M,V,P=map(int, input().split()) *A,=map(int, input().split()) A.sort() Ax = A[-P] #上位Pの中の最下位 def f(i): mine = A[i] + M #自分に全力で投票 if mine < Ax: return False #逆転不能 votes = M*V votes -= M #自分への票 votes -= min(P-1, V) * M #上位陣のx以外に全力で投票 votes -= sum([min(mine - A[j], M) for j in range(N-P+1) if i!=j]) #逆転されない程度に下位陣に投票 if votes > 0 : return False #再逆転される return True under = -1 r = N-P while r-under>1: m = (r+under)//2 if f(m): r=m else: under=m print(N-r)
0
PYTHON3
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 69; const long long INF = 1e18; struct item { long long d, fr, to, c; }; bool cmp(item a, item b) { return a.d < b.d; } item a[MAXN]; long long pr[MAXN], suf[MAXN]; long long go[MAXN]; long long n, m, k; int main() { cin >> n >> m >> k; for (long long i = 0; i < m; ++i) cin >> a[i].d >> a[i].fr >> a[i].to >> a[i].c; sort(a, a + m, cmp); for (long long i = 1; i <= n; ++i) go[i] = INF; long long ans = 0; long long cnt = 0; for (long long i = 0; i < m; ++i) { if (a[i].fr == 0) { if (i == 0) pr[i] = INF; else pr[i] = pr[i - 1]; continue; } long long fr = a[i].fr, to = a[i].to, d = a[i].d, c = a[i].c; if (go[fr] == INF) { ans += c; go[fr] = c; cnt++; } else if (c < go[fr]) { ans -= go[fr]; go[fr] = c; ans += go[fr]; } if (cnt == n) pr[i] = ans; else pr[i] = INF; } ans = 0; for (long long i = 1; i <= n; ++i) go[i] = INF; cnt = 0; for (long long i = m - 1; i >= 0; --i) { if (a[i].to == 0) { suf[i] = INF; if (i == m - 1) suf[i] = INF; else suf[i] = suf[i + 1]; continue; } long long fr = a[i].fr, to = a[i].to, d = a[i].d, c = a[i].c; if (go[to] == INF) { ans += c; go[to] = c; cnt++; } else if (c < go[to]) { ans -= go[to]; go[to] = c; ans += go[to]; } if (cnt == n) suf[i] = ans; else suf[i] = INF; } long long res = INF; for (long long i = 0; i < m; ++i) { long long out = a[i].d + k + 1; long long l = -1, r = m; while (l + 1 < r) { long long mi = (l + r) / 2; if (a[mi].d >= out) r = mi; else l = mi; } if (r == m) continue; if (pr[i] != INF && suf[r] != INF) res = min(res, pr[i] + suf[r]); } if (res == INF) cout << -1; else cout << res; return 0; }
10
CPP
n=int(input()) s=[] for i in range(n): s.append(input()) ans=10**9 for i in range(n): t=s[i] y=0 for j in range(n): x=s[j]+s[j] z=len(t) c=-1 for k in range(z): if x[k:k+z]==t: c=k break if c!=-1: y=y+c else: y=-1 break if y!=-1: ans=min(ans,y) if ans==10**(9): print(-1) else: print(ans)
8
PYTHON3
#include <bits/stdc++.h> int main() { const int N = 200007; std::vector<std::vector<long> > fa(N, std::vector<long>(2, 0)); long l(1), r(2); bool ambiguous(false); long h; scanf("%ld", &h); for (long p = 0; p <= h; p++) { long a; scanf("%ld", &a); if (p == 0) { continue; } if (r - l > 1 && a > 1) { ambiguous = true; } for (long q = 0; q < a; q++) { fa[r + q][0] = l; fa[r + q][1] = l + q % (r - l); } l = r; r += a; } if (ambiguous) { puts("ambiguous"); for (long p = 1; p < r; p++) { printf("%ld ", fa[p][0]); }; puts(""); for (long p = 1; p < r; p++) { printf("%ld ", fa[p][1]); }; puts(""); } else { puts("perfect"); } return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n; cin >> n; vector<int> a(2 * n); for (int i = 0; i < n; ++i) if (i % 2) { a[i] = 2 * n - i + 1; a[i + n] = a[i] - 1; } else { a[i] = 1 + i; a[i + n] = a[i] + 1; } if (n % 2) { cout << "YES\n"; for (int i = 0; i < 2 * n; ++i) cout << a[i] << " "; cout << "\n"; } else { cout << "NO\n"; } return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pi = pair<int, int>; using pll = pair<ll, ll>; constexpr int INF = 0x3f3f3f3f; constexpr ll LLINF = 0x3f3f3f3f3f3f3f3f; template <class RIt> void dbarr(RIt frs, RIt lst) { cerr << "arr: "; for (int i = 0; i < (int)(lst - frs); i++) cerr << frs[i] << " \n"[i == (int)(lst - frs) - 1]; } const int MM = 1e5 + 5; int n; int main() { cin.tie(0)->sync_with_stdio(0); cin >> n; unordered_map<int, int> masks; ll tot = 0; for (int i = 0; i < n; i++) { string s; cin >> s; int msk = 0; for (char c : s) msk ^= (1 << (c - 'a')); for (int j = 0; j < 26; j++) tot += masks[msk ^ (1 << j)]; tot += masks[msk]++; } cout << tot << "\n"; }
15
CPP
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long power(long long x, long long y) { long long ans = 1; x = x % mod; while (y > 0) { if (y & 1) ans = (ans * x) % mod; y = y >> 1; x = (x * x) % mod; } return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, ans; long long t; cin >> t; while (t--) { ans = 1; cin >> n; long long arr[n]; for (long long i = (long long)(0); i <= (long long)(n - 1); ++i) { cin >> arr[i]; } sort(arr, arr + n); for (long long i = (long long)(n - 1); i >= (long long)(0); --i) { if (arr[i] <= i + 1) { ans = i + 2; break; } } cout << ans << '\n'; } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; struct data { int h, m; } t[105]; int cmp(data a, data b) { if (a.h == b.h) return a.m < b.m; else return a.h < b.h; } int n, s; int flag; int ans1, ans2; int main() { scanf("%d%d", &n, &s); for (int i = 1; i <= n; ++i) scanf("%d%d", &t[i].h, &t[i].m); sort(t + 1, t + n + 1, cmp); if (!ans1) { int hh = 0, mm = 0; mm = s + 1; int add = mm / 60; mm %= 60; hh += add; if (hh < t[1].h || (hh == t[1].h && mm <= t[1].m)) { printf("0 0"); return 0; } } for (int i = 1; i < n; ++i) { int hh = t[i].h, mm = t[i].m; mm += 2 * s + 2; int add = mm / 60; mm %= 60; hh += add; if (hh < t[i + 1].h || (hh == t[i + 1].h && mm <= t[i + 1].m)) { flag = 1; hh = t[i].h; mm = t[i].m + s + 1; int add = mm / 60; mm %= 60; hh += add; ans1 = hh, ans2 = mm; break; } } if (!flag) { int hh, mm; hh = t[n].h; mm = t[n].m + s + 1; int add = mm / 60; mm %= 60; hh += add; ans1 = hh, ans2 = mm; } printf("%d %d", ans1, ans2); }
7
CPP
x=int(input()) for i in range(x): m=list(map(int,input().split()))[:4] m.sort() print(m[0]*m[2])
11
PYTHON3
from collections import Counter print('Yes' if sorted(list(Counter(input()).values())) == sorted(list(Counter(input()).values())) else 'No')
0
PYTHON3