solution
stringlengths
10
983k
difficulty
int64
0
25
language
stringclasses
2 values
#Stones on the Table n = int(input()) lin = [x for x in input()] counter = 0 for i in range(0,n-1): if lin[i] == lin[i+1]: counter += 1 print(counter)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, h, alturaPersona, anchuraTotal; cin >> n >> h; anchuraTotal = 0; while (n--) { cin >> alturaPersona; anchuraTotal += ((alturaPersona > h) ? 2 : 1); } cout << anchuraTotal << endl; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; long long n, sum; int a[maxn], ans[maxn]; int main() { scanf("%I64d%I64d", &n, &sum); long long tot = 0; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); tot += a[i]; } for (int i = 1; i <= n; i++) { if (a[i] > sum - n + 1) ans[i] += a[i] - (sum - n + 1); if (sum - 1 > tot - a[i]) ans[i] += sum - 1 - (tot - a[i]); } for (int i = 1; i <= n; i++) printf("%d%c", ans[i], i == n ? '\n' : ' '); return 0; }
9
CPP
input = int(input('')) if input > 2 and input % 2 == 0: print('YES') else: print('NO')
7
PYTHON3
class CodeforcesTask1047ASolution: def __init__(self): self.result = '' self.n = 0 def read_input(self): self.n = int(input()) def process_task(self): if not self.n % 3: a = 1 b = 1 c = self.n - 2 else: a = 1 b = 2 c = self.n - 3 self.result = f"{a} {b} {c}" def get_result(self): return self.result if __name__ == "__main__": Solution = CodeforcesTask1047ASolution() Solution.read_input() Solution.process_task() print(Solution.get_result())
7
PYTHON3
#include <bits/stdc++.h> using namespace std; using ll = long long; struct point { ll x, y; point(ll x = 0, ll y = 0) : x(x), y(y) {} point &operator+=(const point &o) { x += o.x; y += o.y; return *this; } point &operator-=(const point &o) { x -= o.x; y -= o.y; return *this; } point operator+(const point &o) const { return point(*this) += o; } point operator-(const point &o) const { return point(*this) -= o; } bool operator<(const point &o) const { return x != o.x ? x < o.x : y < o.y; } }; using poly = vector<point>; ll dot(const point &a, const point &b) { return a.x * b.x + a.y * b.y; } ll cross(const point &a, const point &b) { return a.x * b.y - a.y * b.x; } ll orient(const point &a, const point &b, const point &c) { return cross(b - a, c - b); } poly minkowski(const poly &a, const poly &b) { if (a.empty() || b.empty()) return a.size() ? a : b; poly sum(1, a[0] + b[0]); int i = 0, j = 0, m = a.size(), n = b.size(); while (i < m && j < n) { point p = (i == m - 1 ? a[0] : a[i + 1]) - a[i]; point q = (j == n - 1 ? b[0] : b[j + 1]) - b[j]; if (cross(p, q) >= 0) { sum.push_back(sum.back() + p); i++; } else { sum.push_back(sum.back() + q); j++; } } while (i + 1 < m) { sum.push_back(sum.back() + a[i + 1] - a[i]); i++; } while (j + 1 < n) { sum.push_back(sum.back() + b[j + 1] - b[j]); j++; } return sum; } void normalize(poly &a) { poly b; int m = a.size(), n = 0; while (m > 2 && !orient(a[0], a[m - 1], a[m - 2])) { a.pop_back(); m--; } for (int i = 0; i < m; i++) { while (n > 1 && !orient(b[n - 2], b[n - 1], a[i])) { b.pop_back(); n--; } b.push_back(a[i]); n++; } a = b; } int main() { cin.tie(0)->sync_with_stdio(0); poly sum; for (int id = 0; id < 3; id++) { int n; cin >> n; poly a(n); for (auto &p : a) cin >> p.x >> p.y; rotate(a.begin(), min_element(a.begin(), a.end()), a.end()); sum = minkowski(sum, a); } normalize(sum); int q; cin >> q; while (q--) { point p; cin >> p.x >> p.y; p.x *= 3; p.y *= 3; if (orient(sum[0], p, sum[1]) > 0 || orient(sum[0], p, sum.back()) < 0) { cout << "NO\n"; continue; } int lo = 1, hi = sum.size() - 1; while (lo + 1 < hi) { int mi = (lo + hi) / 2; if (orient(sum[0], p, sum[mi]) < 0) lo = mi; else hi = mi; } if (orient(sum[lo], p, sum[hi]) <= 0) cout << "YES\n"; else cout << "NO\n"; } }
11
CPP
#include <bits/stdc++.h> using namespace std; const int M = 1024; int save[M]; int main(void) { int n, ans = 0; cin >> n; for (int i = 1; i <= n; i++) cin >> save[i]; int vecs = save[n] + 1; int r = n, l = 1, ready = 0; for (int vec = 1; vec < vecs; vec++) { if (save[l] <= ready) l++, r--; else if (ready + vecs - vec == save[r]) ready++, ans += vecs - vec; } printf("%d\n", ans); r = n, l = 1, ready = 0; for (int vec = 1; vec < vecs; vec++) { if (save[l] <= ready) l++, r--; else if (ready + vecs - vec == save[r]) { for (int j = vec + 1; j <= vecs; j++) printf("%d %d\n", vec, j); ready++; ans += vecs - vec; } } return 0; }
10
CPP
import math def findv(lcm,l,r,b): p = max(min(r,b),l) s = r-p+1 x1 = p//lcm x2 = r//lcm x1s = p%lcm if x1*lcm+b > p: s -= b-x1s x1 += 1 if x2*lcm+b <= r: s -= b*(x2-x1+1) else: s -= b*(x2-x1)+r%lcm+1 return s cases = int(input()) for t in range(cases): a,b,q = list(map(int,input().split())) a,b = min(a,b),max(a,b) lcm = (a*b)//math.gcd(a,b) out = [] for i in range(q): l,r = list(map(int,input().split())) if b>r: out.append(0) else: out.append(findv(lcm, l, r, b)) print(*out)
9
PYTHON3
#include <iostream> #include <string> int main(){ std::string s; std::cin >> s; unsigned int posA = s.find("A"); unsigned int posZ = s.rfind("Z"); std::cout << posZ-posA+1 << std::endl; return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; int n; int p[3000]; double solve() { int res = 0; for (int i = n - 1; i >= 0; i--) { pair<int, int> mx = make_pair(-1, -1); for (int j = 0; j <= i; j++) { mx = std::max(mx, make_pair(p[j], j)); } res += i - mx.second; for (int j = mx.second; j < i; j++) { p[j] = p[j + 1]; } p[n - 1] = mx.first; } double dp[3]; dp[0] = 0; dp[1] = 1; for (int i = 2; i <= res; i++) { dp[i % 3] = 4 + dp[(i + 1) % 3]; } return dp[res % 3]; } inline void init() {} int main() { ios::sync_with_stdio(0); init(); bool prev = false; while (cin >> n) { if (prev) { cout << endl; } prev = true; for (int i = 0; i < n; i++) { cin >> p[i]; } cout.precision(10); cout.setf(ios::fixed, ios::fixed); cout << solve() << endl; } return 0; }
8
CPP
if __name__ == '__main__': t = int(input()) for i in range(t): b = input() l = len(b) s = '' i = 0 while(i<l): if i % 2 == 0: s+=b[i] i+=2 s+=b[l-1] print(s)
7
PYTHON3
""" https://codeforces.com/problemset/problem/158/A """ def solution(n, k, scores): ptr1 = 0 for i in range(n): if scores[i] > 0 and scores[i] >= scores[k-1]: ptr1 += 1 return ptr1 def read_inp(): line_1 = input().strip().split() n = int(line_1[0]) k = int(line_1[-1]) scores = list(map(lambda x: int(x), input().strip().split())) print(solution(n, k, scores)) read_inp()
7
PYTHON3
#include <bits/stdc++.h> using namespace std; inline long long pw(long long a, long long b) { return (b) ? (pw((a) * (a), (b) >> 1) * ((b)&1 ? (a) : 1)) : 1; } const int MAXN = 1e6 + 5; const long long INF = 1e10; const int MOD = 1e9 + 7; long long dp[MAXN]; int x, y, u, r; map<pair<int, int>, bool> mp; void pos(char ch, int r, int u) {} int main() { int cur = 1; cin >> x >> y >> r >> u; r--; u--; string s; cin >> s; dp[0] = 1; mp[make_pair(r, u)] = true; for (int i = 0; i < s.size(); i++) { char ch = s[i]; if (ch == 'L' && u > 0) u--; else if (ch == 'R' && u < y - 1) u++; else if (ch == 'U' && r > 0) r--; else if (ch == 'D' && r < x - 1) r++; if (i != s.size() - 1) { if (!mp[make_pair(r, u)]) dp[i + 1] = 1; else dp[i + 1] = 0; } if (i == s.size() - 1) { dp[i + 1] = x * y - cur; } if (!mp[make_pair(r, u)]) { cur++; mp[make_pair(r, u)] = true; } } for (int i = 0; i < s.size() + 1; i++) cout << dp[i] << " "; }
8
CPP
x=(input()) count=0 c=0 for i in range(len(x)): if x[i].isupper(): count=count+1 else: c=c+1 #print(count,c) if (count <= c): print(x.lower()) else: print(x.upper())
7
PYTHON3
#include <bits/stdc++.h> using namespace std; double EPS = 1e-9; int INF = 1000000005; long long INFF = 1000000000000000005LL; inline string IntToString(long long a) { ostringstream str1; str1 << a; string geek = str1.str(); return geek; } inline long long StringToInt(string a) { stringstream geek(a); long long x = 0; geek >> x; return x; } inline long long gcd(long long a, long long b) { if (b == 0) { return a; } return gcd(b, a % b); } inline long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } inline long long power(long long x, long long y) { long long temp; if (y == 0) return 1; temp = pow(x, y / 2); if (y % 2 == 0) return temp * temp; else return x * temp * temp; } inline long long sumDigits(long long n) { return n == 0 ? 0 : n % 10 + sumDigits(n / 10); } inline bool isprime(long long n) { vector<bool> prime(n + 1, true); for (long long p = 2; p * p <= n; p++) { if (prime[p] == true) { for (long long i = p * p; i <= n; i += p) prime[i] = false; } } if (n == 1) return false; else if (prime[n]) return true; else return false; } inline bool ispalinDigit(string num) { string t = num; reverse(t.begin(), t.end()); if (t == num) return true; return false; } inline void primeFactors(long long n) { while (n % 2 == 0) { printf("%d ", 2); n = n / 2; } for (long long i = 3; i <= sqrt(n); i = i + 2) { while (n % i == 0) { printf("%lld ", i); n = n / i; } } if (n > 2) printf("%lld ", n); } inline long long fact(long long n) { if (n <= 1) return 1; return n * fact(n - 1); } inline long long ncr(long long n, long long r) { long long p = 1, k = 1; if (n - r < r) r = n - r; if (r != 0) { while (r) { p *= n; k *= r; long long m = gcd(p, k); p /= m; k /= m; n--; r--; } } else p = 1; return p; } inline long long npr(long long n, long long r) { return fact(n) / fact(n - r); } inline void printA(long long arr[], long long n) { for (long long i = 0; i < n; i++) cout << arr[i] << " "; cout << endl; } inline void printV(vector<long long> v) { for (long long i = 0; i < v.size(); i++) cout << v[i] << " "; cout << endl; } void checktimer() { clock_t start, end; start = clock(); end = clock(); double time_taken = double(end - start) / double(CLOCKS_PER_SEC); cout << "Execution time: " << time_taken << " secs"; } void solve() { string s; cin >> s; long long f = s[s.length() - 1] - '0'; (f % 2 == 0) ? cout << "0" << endl : cout << "1" << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t = 1; while (t--) { solve(); } return 0; }
10
CPP
a=input().lower() b=input().lower() x=sorted(a) y=sorted(b) k = 0 for i in range(len(a)): if a[i] < b[i]: k = -1 break if a[i] > b[i]: k = 1 break print(k)
7
PYTHON3
# cook your dish here t=int(input()) count=0 while t: t-=1 lst=list(map(int,input().split())) if sum(lst)>=2: count+=1 print(count)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int maxn = 110; const int INF = 0x3f3f3f3f; int n, f[maxn][maxn][2], ans; pair<int, int> a[maxn]; inline int Get(int x, int y) { if (y == 0) return a[x].first - 1; return a[x].first - 1 + a[x].second; } int main() { scanf("%d", &n); for (int i = (1), _end_ = (n); i <= _end_; ++i) scanf("%d%d", &a[i].first, &a[i].second); sort(a + 1, a + n + 1); a[0].first = -INF; for (int i = (0), _end_ = (n - 1); i <= _end_; ++i) for (int j = (0), _end_ = (i); j <= _end_; ++j) for (int p = (0), _end_ = (1); p <= _end_; ++p) { if (f[i][j][p] == INF) continue; int r = Get(j, p), Max = -INF, first = 0; for (int k = (i + 1), _end_ = (n); k <= _end_; ++k) for (int o = (0), _end_ = (1); o <= _end_; ++o) { if (Get(k, o) > Max) { Max = Get(k, o); first = k; } f[k][first][first == k ? o : 1] = max(f[k][first][first == k ? o : 1], f[i][j][p] + Max - max(r, o == 0 ? a[k].first - a[k].second - 1 : a[k].first - 1)); if (Get(k, 1) > Max) { Max = Get(k, 1); first = k; } } } for (int i = (1), _end_ = (n); i <= _end_; ++i) for (int j = (1), _end_ = (n); j <= _end_; ++j) for (int p = (0), _end_ = (1); p <= _end_; ++p) ans = max(ans, f[i][j][p]); printf("%d\n", ans); return 0; }
11
CPP
N = input() if N[0] == '1' and all(n == '0' for n in N[1:]): print(10) else: print(sum(int(n) for n in N))
0
PYTHON3
#include <bits/stdc++.h> using namespace std; int n; int arr[100005]; int len = 1; int maxn = 1; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = 1; i < n; i++) { if (arr[i] > arr[i - 1]) { len++; } else maxn = max(maxn, len), len = 1; } cout << max(maxn, len); }
7
CPP
s = list(input()) k = int(input()) for i in range(len(s)): if ord("z")<ord(s[i])+k and s[i]!="a": k =k-(ord("z")-ord(s[i])+1) s[i]="a" if i==len(s)-1 and 0<k: k=k%26 s[i]=chr(ord(s[i])+k) print("".join(s))
0
PYTHON3
#include <bits/stdc++.h> using namespace std; //#define cerr if (false) cerr #define db(x) cerr << #x << "=" << x << endl #define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl #define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl #define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl #define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl template <typename A, typename B> ostream& operator<<(ostream& os, const pair<A, B>& x) { return os << "(" << x.first << "," << x.second << ")"; } typedef long long ll; typedef long double ld; const int MOD = 1000000007; struct Mint { int val; Mint() { val = 0; } Mint(const ll& x) { val = (-MOD <= x && x < MOD) ? x : x % MOD; if (val < 0) val += MOD; } template <typename U> explicit operator U() const { return (U)val; } friend bool operator==(const Mint& a, const Mint& b) { return a.val == b.val; } friend bool operator!=(const Mint& a, const Mint& b) { return !(a == b); } friend bool operator<(const Mint& a, const Mint& b) { return a.val < b.val; } Mint& operator+=(const Mint& m) { if ((val += m.val) >= MOD) val -= MOD; return *this; } Mint& operator-=(const Mint& m) { if ((val -= m.val) < 0) val += MOD; return *this; } Mint& operator*=(const Mint& m) { val = (ll)val * m.val % MOD; return *this; } friend Mint modex(Mint a, ll p) { assert(p >= 0); Mint ans = 1; for (; p; p >>= 1, a *= a) if (p & 1) ans *= a; return ans; } Mint& operator/=(const Mint& m) { return *this *= modex(m, MOD - 2); } Mint& operator++() { return *this += 1; } Mint& operator--() { return *this -= 1; } Mint operator++(int) { Mint result(*this); *this += 1; return result; } Mint operator--(int) { Mint result(*this); *this -= 1; return result; } Mint operator-() const { return Mint(-val); } friend Mint operator+(Mint a, const Mint& b) { return a += b; } friend Mint operator-(Mint a, const Mint& b) { return a -= b; } friend Mint operator*(Mint a, const Mint& b) { return a *= b; } friend Mint operator/(Mint a, const Mint& b) { return a /= b; } friend ostream& operator<<(ostream& os, const Mint& x) { return os << x.val; } }; Mint dp[5005][5005]; const int MAXN = 10000005; Mint fac[MAXN], invfac[MAXN]; Mint binom(ll a, ll b) { if (b < 0) return 0; if (b > a) return 0; return fac[a] * invfac[b] * invfac[a - b]; } int main() { fac[0] = 1; for (int i = 1; i < MAXN; ++i) fac[i] = fac[i - 1] * i; invfac[MAXN - 1] = 1 / fac[MAXN - 1]; for (int i = MAXN - 2; i >= 0; --i) invfac[i] = invfac[i + 1] * (i + 1); int n, A; scanf("%d%d", &n, &A); int B = n - A; Mint ans = 0; dp[0][0] = 1; for (int ones = 0; ones <= A; ++ones) { Mint sum = 0; for (int i = 1; i <= A; ++i) { if (i >= 2) sum += dp[i - 2][ones] * fac[A - i + 1]; dp[i][ones] = sum * invfac[A - i]; if (ones) dp[i][ones] += dp[i - 1][ones - 1]; if (i >= 2) { ans += dp[i - 1][ones] * binom(i - 2 + B - ones, i - 2) * fac[A - i] * fac[B]; } } ans += dp[A][ones] * binom(A - 1 + B - ones, A - 1) * fac[B]; } printf("%d\n", ans.val); }
0
CPP
#include <bits/stdc++.h> using namespace std; int __gcd(int a, int b) { return (b == 0 ? a : __gcd(b, a % b)); } const int inf = 2e9; const int maxn = 5e4 + 100; int rk[maxn][6]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); int _; cin >> _; while (_--) { int n; cin >> n; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= 5; ++j) cin >> rk[i][j]; } int now = 1; for (int i = 2; i <= n; ++i) { int score_now = 0, score_i = 0; for (int j = 1; j <= 5; ++j) { if (rk[i][j] < rk[now][j]) score_i++; else score_now++; } if (score_i > score_now) now = i; } for (int i = 1; i <= n; ++i) { if (i == now) continue; int score = 0; for (int j = 1; j <= 5; ++j) { if (rk[now][j] < rk[i][j]) ++score; } if (score < 3) { now = -1; break; } } cout << now << "\n"; } }
8
CPP
import os import sys from io import BytesIO, IOBase 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") ##############################################3 t=int(input()) from collections import defaultdict for i in range(t): n,m=map(int,input().split()) l=[] d=defaultdict(int) for j in range(n): l.append(int(input(),2)) x=pow(2,m-1)-1 ln=0 for j in l: if ln%2!=0: if j>=x: x-=1 while d[x]==1: x-=1 d[j]=1 else: d[j]=1 else: if j<=x: x+=1 while d[x]==1: x+=1 d[j]=1 else: d[j]=1 ln=ln^1 ans=bin(x).lstrip('0b') ans='0'*(m-len(ans))+ans print(ans)
14
PYTHON3
a=int(input()) if int(a)==2: print("NO") else: if int(a)%2==0: print("YES") else: print("NO")
7
PYTHON3
a,b,n = map(int,input().split()) x = min(b-1,n) print((((a * x)//b)) )
0
PYTHON3
for _ in range(int(input())): a, b = map(int, input().split()) s = input() gaps = [] cnt = 0 i, j = 0, 0 while i < len(s): while j < len(s) and s[i] == s[j]: j += 1 if s[i] == '1': cnt += 1 elif i > 0 and j < len(s): gaps.append(j - i) i = j ans = cnt * a for i in range(len(gaps)): if b * gaps[i] < a: ans += b * gaps[i] - a print(ans)
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int dr[] = {1, -1, 0, 0, 1, -1, -1, 1}; int dc[] = {0, 0, 1, -1, 1, -1, 1, -1}; int main() { int noTest; cin >> noTest; while (noTest--) { int size, end; string word; cin >> size; cin >> word; end = size - 1; bool valid = true; for (int i = 0; i < (size / 2); i++) { if (word[i] != word[end]) { if (word[i] > 'a' && word[i] < 'z') if (((word[i] - 1 == word[end] - 1) || (word[i] - 1 == word[end] + 1)) || ((word[i] + 1 == word[end] - 1) || (word[i] + 1 == word[end] + 1))) { end--; continue; } else { valid = false; break; } else if (word[i] == 'a') if (((word[i] + 1 == word[end] - 1) || (word[i] + 1 == word[end] + 1))) { end--; continue; } else { valid = false; break; } else if (((word[i] - 1 == word[end] - 1) || (word[i] - 1 == word[end] + 1))) { end--; continue; } else { valid = false; break; } } end--; } puts(valid ? "YES" : "NO"); } }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n, k, t, a, b, sum = 0, cnt = 0; vector<int> A, B, C; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> t >> a >> b; if (a != b) { if (a == 1) { A.push_back(t); } else { B.push_back(t); } } else { if (a == 1) { C.push_back(t); } } } sort(A.begin(), A.end()); sort(B.begin(), B.end()); sort(C.begin(), C.end()); if (A.size() + C.size() < k) { cout << -1; return 0; } else if (B.size() + C.size() < k) { cout << -1; return 0; } else { int i = 0, j = 0, l = 0; while (i < A.size() && j < B.size() && l < C.size() && cnt < k) { if (A[i] + B[j] < C[l]) { sum += A[i] + B[j]; i++; j++; cnt++; } else { sum += C[l]; l++; cnt++; } } if (cnt < k) { if (l == C.size()) { l = cnt; while (l < k) { sum += A[i]; i++; l++; } l = cnt; while (l < k) { sum += B[j]; j++; l++; } } else { i = cnt; while (i < k) { sum += C[l]; l++; i++; } } } } cout << sum; return 0; }
11
CPP
s = input() print(s.replace('WUB',' ').lstrip())
7
PYTHON3
#include <bits/stdc++.h> using namespace std; vector<string> a; vector<int> ans; void rev(char &c) { if (c == '0') { c = '1'; } else { c = '0'; } } void changeSquare(int i, int j) { vector<pair<int, int>> p1; vector<pair<int, int>> p0; for (int k = i; k <= i + 1; k++) { for (int d = j; d <= j + 1; d++) { if (a[k][d] == '1') { p1.push_back(make_pair(k, d)); } else { p0.push_back(make_pair(k, d)); } } } if (p1.size() == 1) { ans.push_back(p1[0].first); ans.push_back(p1[0].second); ans.push_back(p0[0].first); ans.push_back(p0[0].second); ans.push_back(p0[1].first); ans.push_back(p0[1].second); ans.push_back(p1[0].first); ans.push_back(p1[0].second); ans.push_back(p0[0].first); ans.push_back(p0[0].second); ans.push_back(p0[2].first); ans.push_back(p0[2].second); ans.push_back(p1[0].first); ans.push_back(p1[0].second); ans.push_back(p0[1].first); ans.push_back(p0[1].second); ans.push_back(p0[2].first); ans.push_back(p0[2].second); rev(a[p1[0].first][p1[0].second]); rev(a[p0[0].first][p0[0].second]); rev(a[p0[1].first][p0[1].second]); rev(a[p1[0].first][p1[0].second]); rev(a[p0[0].first][p0[0].second]); rev(a[p0[2].first][p0[2].second]); rev(a[p1[0].first][p1[0].second]); rev(a[p0[1].first][p0[1].second]); rev(a[p0[2].first][p0[2].second]); } else if (p1.size() == 2) { ans.push_back(p1[0].first); ans.push_back(p1[0].second); ans.push_back(p0[1].first); ans.push_back(p0[1].second); ans.push_back(p0[0].first); ans.push_back(p0[0].second); ans.push_back(p1[1].first); ans.push_back(p1[1].second); ans.push_back(p0[1].first); ans.push_back(p0[1].second); ans.push_back(p0[0].first); ans.push_back(p0[0].second); rev(a[p1[0].first][p1[0].second]); rev(a[p0[0].first][p0[0].second]); rev(a[p0[1].first][p0[1].second]); rev(a[p1[1].first][p1[1].second]); rev(a[p0[0].first][p0[0].second]); rev(a[p0[1].first][p0[1].second]); } else if (p1.size() == 3) { ans.push_back(p1[0].first); ans.push_back(p1[0].second); ans.push_back(p1[1].first); ans.push_back(p1[1].second); ans.push_back(p1[2].first); ans.push_back(p1[2].second); rev(a[p1[0].first][p1[0].second]); rev(a[p1[1].first][p1[1].second]); rev(a[p1[2].first][p1[2].second]); } else if (p1.size() == 4) { ans.push_back(p1[0].first); ans.push_back(p1[0].second); ans.push_back(p1[1].first); ans.push_back(p1[1].second); ans.push_back(p1[2].first); ans.push_back(p1[2].second); ans.push_back(p1[0].first); ans.push_back(p1[0].second); ans.push_back(p1[1].first); ans.push_back(p1[1].second); ans.push_back(p1[3].first); ans.push_back(p1[3].second); ans.push_back(p1[0].first); ans.push_back(p1[0].second); ans.push_back(p1[2].first); ans.push_back(p1[2].second); ans.push_back(p1[3].first); ans.push_back(p1[3].second); ans.push_back(p1[1].first); ans.push_back(p1[1].second); ans.push_back(p1[2].first); ans.push_back(p1[2].second); ans.push_back(p1[3].first); ans.push_back(p1[3].second); rev(a[p1[0].first][p1[0].second]); rev(a[p1[1].first][p1[1].second]); rev(a[p1[2].first][p1[2].second]); rev(a[p1[0].first][p1[0].second]); rev(a[p1[1].first][p1[1].second]); rev(a[p1[3].first][p1[3].second]); rev(a[p1[0].first][p1[0].second]); rev(a[p1[2].first][p1[2].second]); rev(a[p1[3].first][p1[3].second]); rev(a[p1[1].first][p1[1].second]); rev(a[p1[2].first][p1[2].second]); rev(a[p1[3].first][p1[3].second]); } } int main() { int t; cin >> t; while (t--) { a.clear(); ans.clear(); int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { string s; cin >> s; a.push_back(s); } for (int i = 0; i < n - 1; i++) { for (int j = 0; j < m - 1; j++) { changeSquare(i, j); } } cout << ans.size() / 6 << "\n"; for (int i = 0; i < ans.size(); i++) { cout << ans[i] + 1 << " "; if ((i + 1) % 6 == 0) { cout << "\n"; } } } return 0; }
7
CPP
import math t = int(input()) cnt = 0 for cnt in range(t): a , b = map(int, input().split()) c = max(a,b) d = min(a,b) ans = 0 if(c>=2*d): print(d) else: x = math.ceil((2*d-c)/3) d -= x*2 ans = x+d print(ans)
7
PYTHON3
T = int(input()) for _ in range(T): x = input(); y = input() last1y = 0 for i in range(len(y)-1,-1,-1): if(y[i]=='1'): break last1y+=1 last1x = last1y for j in range(len(x)-1-last1y,-1,-1): if(x[j]=='1'): break last1x+=1 print(last1x-last1y)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; pair<int, int> mn[500500 << 2]; int up[500500 << 2]; void push_up(int u) { mn[u] = min(mn[(u << 1)], mn[((u << 1) | 1)]); } void build(int u, int L, int R) { mn[u] = pair<int, int>(0, L); up[u] = 0; if (L + 1 == R) return; build((u << 1), L, (L + R >> 1)); build(((u << 1) | 1), (L + R >> 1), R); } void push_down(int u) { if (up[u]) { up[(u << 1)] += up[u]; mn[(u << 1)].first += up[u]; up[((u << 1) | 1)] += up[u]; mn[((u << 1) | 1)].first += up[u]; up[u] = 0; } } void update(int u, int L, int R, int l, int r, int first) { if (r <= L || R <= l) return; if (l <= L && R <= r) { up[u] += first; mn[u].first += first; return; } push_down(u); update((u << 1), L, (L + R >> 1), l, r, first); update(((u << 1) | 1), (L + R >> 1), R, l, r, first); push_up(u); } vector<pair<int, int> > vec[500500]; int p[500500]; int main() { int T, n; for (cin >> T; T--;) { scanf("%d", &n); build(1, 1, n + 1); for (int i = 1; i <= n; i++) vec[i].clear(); for (int i = 1; i <= n; i++) { int p; scanf("%d", &p); if (p == -1) continue; if (p > i + 1) { vec[i].push_back(pair<int, int>(i + 1, p)); update(1, 1, n + 1, i + 1, p, 1); } if (p <= n) { vec[p].push_back(pair<int, int>(i, i + 1)); update(1, 1, n + 1, i, i + 1, 1); } } int nn = 0; while (nn < n && mn[1].first == 0) { int u = mn[1].second; update(1, 1, n + 1, u, u + 1, 500500); p[u] = n - nn; for (pair<int, int> r : vec[u]) update(1, 1, n + 1, r.first, r.second, -1); nn++; } if (nn < n) puts("-1"); else { for (int i = 1; i <= n; i++) printf("%d ", p[i]); puts(""); } } return 0; }
9
CPP
i = 0 z = 0 x = list(map(int, input().split())) y = list(map(int, input().split())) while i < x[0]: if y[i] <= x[1]: z += 1 else: z += 2 i += 1 print(z)
7
PYTHON3
#include <bits/stdc++.h> int n, l[5000], m; bool b; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < m; i++) scanf("%d", &l[i]); std::sort(l, l + m); for (int i = 0; i < m - 2; i++) if (l[i] == l[i + 1] - 1 && l[i + 2] - 2 == l[i]) b = 1; if (b || l[0] == 1 || l[m - 1] == n) printf("NO\n"); else printf("YES\n"); scanf("\n"); }
8
CPP
N, I = map(int,input().split()) if N%2==0: print((I-1)+I if I<=N//2 else I-(N-I)) else: print(I+(I-1) if I<=(N//2)+1 else I-(N-I)-1)
7
PYTHON3
t = int(input()) for _ in range(t): n, k = list(map(int, input().split())) c = k // (n - 1) last = k % (n-1) if not last: result =n * c + last - 1 else: result = n*c + last print(result)
9
PYTHON3
from math import * from collections import * n = int(input()) l = [] for i in range(n): s = input() l.append(s[0]) l = Counter(l) ans = 0 for i in l.values(): x = i//2 y = i-x ans += x*(x-1)//2 + y*(y-1)//2 print(ans)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const long long inf = 0x3f3f3f3f3f3f3f3fll; const int maxn = 205; const int maxv = 5e4 + 5; int pre[maxn], n, m, G, S; struct edge { int u, v, cx, cy; } e[maxv], g[maxn]; bool cmp(edge a, edge b) { return a.cx == b.cx ? a.cy < b.cy : a.cx < b.cx; } int find(int c) { return pre[c] == c ? c : pre[c] = find(pre[c]); } int main(void) { scanf("%d%d%d%d", &n, &m, &G, &S); for (int i = 1; i <= m; ++i) scanf("%d%d%d%d", &e[i].u, &e[i].v, &e[i].cx, &e[i].cy); sort(e + 1, e + m + 1, cmp); int top = 0; long long ans = inf; for (int i = 1; i <= m; ++i) { for (int j = 1; j <= n; ++j) pre[j] = j; g[++top] = e[i]; for (int j = top; j >= 2; --j) if (g[j].cy < g[j - 1].cy) swap(g[j], g[j - 1]); int cnt = 0; for (int j = 1; j <= top; ++j) { int fx = find(g[j].u), fy = find(g[j].v); if (fx != fy) { g[++cnt] = g[j]; pre[fx] = fy; if (cnt == n - 1) break; } } if (cnt == n - 1) ans = min(ans, (long long)e[i].cx * G + (long long)g[cnt].cy * S); top = cnt; } if (ans == inf) printf("-1\n"); else printf("%lld\n", ans); }
7
CPP
for _ in range(int(input())): a=[int(i) for i in input().split()] if(a.count(max(a))<2): print("NO") else : print("YES") if(a[0]==max(a) and a[1]==max(a)): A=max(a);B=min(a);C=min(a) elif(a[0]==max(a) and a[2]==max(a)): B=max(a);A=min(a);C=min(a) else: C=max(a);A=min(a);B=min(a) print(A,B,C)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int maxint = -1u >> 1; int n, ans; int a[25], b[25], f[2][1 << 23]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } f[0][1] = 1; bool flag; int cur, last, len, tmp, v; ans = maxint; if (n == 1) ans = 1; for (int i = 1; i < n; i++) { cur = i % 2, last = (i + 1) % 2; for (int sta = 1; sta < (1 << i); sta++) f[cur][sta] = 0; for (int sta = 1; sta < (1 << i); sta++) { if (f[last][sta] == 0) continue; len = 0; for (int j = 0; j < i; j++) if ((1 << j) & sta) { b[len++] = j; } flag = false; for (int j = 0; j < len; j++) for (int k = 0; k < len; k++) if (a[b[j]] + a[b[k]] == a[i]) { flag = true; break; } if (flag) { tmp = sta | (1 << i); if (f[last][sta] + 1 < f[cur][tmp] || f[cur][tmp] == 0) { f[cur][tmp] = f[last][sta] + 1; if (i == n - 1) ans = min(ans, f[cur][tmp]); } for (int j = 0; j < len; j++) { v = tmp ^ (1 << b[j]); if (f[last][sta] < f[cur][v] || f[cur][v] == 0) { f[cur][v] = f[last][sta]; if (i == n - 1) ans = min(ans, f[cur][v]); } } } } } if (ans == maxint) ans = -1; cout << ans << endl; return 0; }
10
CPP
n=int(input()) c=0 for i in input().split(): c+=int(i) print("YES" if c%2==0 else "NO")
0
PYTHON3
#include <bits/stdc++.h> int a[105][105]; int main(void) { int n, m, mm, i, j, k, x, t; scanf("%d", &n); for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) a[i][j] = (j - 1) * n + i; } for (j = 1; j < n; j++) { x = j; while (x--) { t = a[1][j]; for (i = 1; i <= n; i++) { if (i + 1 <= n) a[i][j] = a[i + 1][j]; else a[i][j] = t; } } } for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { printf("%d ", a[i][j]); } printf("\n"); } return 0; }
7
CPP
n,x,y = map(int,input().split()) c = input() k = list((c)) count = 0 for i in range(n-x,n): # print(k[i],end = ' ') if i < n-y-1: if k[i] != '0': count+=1 else: if i == n-y-1: if k[i] != '1': count+=1 else: if k[i] != '0': count+=1 print(count)
7
PYTHON3
s=input() l=len(s) mod = 10**9+7 dp=[[0]*13 for _ in range(l+1)] dp[0][0]=1 #初期値設定 for i in range(l): if s[i]!="?": for k in range(13): dp[i+1][(k*10+int(s[i]))%13]+=dp[i][k]%mod else: for j in range(10): for k in range(13): dp[i+1][(k*10+j)%13]+=dp[i][k]%mod print(dp[-1][5]%mod)
0
PYTHON3
#include <bits/stdc++.h> const int MAXN = 300 + 10; int n; int pre[MAXN][MAXN]; int send[MAXN]; int main() { scanf("%d", &n); for (int i = 1; i <= n + 1; ++i) { pre[i % (n + 1)][0] = n << 1; for (int t, j = 0; j < n; ++j) { scanf("%d", &t); pre[i % (n + 1)][t] = j; } } int a1 = 0, a2 = 0; for (int i = 1; i <= n; ++i) send[i] = 0; for (int i = 1; i <= n; ++i) { if (pre[0][a1] > pre[0][i]) { a2 = a1; a1 = i; } else if (pre[0][a2] > pre[0][i]) a2 = i; for (int t, j = 1; j <= n; ++j) { if (a1 == j) t = a2; else t = a1; if (pre[j][send[j]] > pre[j][t]) send[j] = t; } } printf("%d", send[1]); for (int i = 2; i <= n; ++i) printf(" %d", send[i]); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 20; int dp[maxn][2][2]; char a[20][105]; char b[20][105]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { for (int j = 0; j < m + 2; j++) { cin >> b[i][j]; a[n - i - 1][j] = b[i][j]; } } memset(dp, 0x3f3f3f3f, sizeof(dp)); dp[0][0][1] = m + 1; dp[0][1][1] = 0x3f3f3f3f; dp[0][1][0] = 0x3f3f3f3f; dp[0][0][0] = 0; for (int j = 0; j < m + 2; j++) { if (a[0][j] == '1') dp[0][0][0] = 2 * j; } for (int i = 1; i < n - 1; i++) { int dis1, dis2; dis1 = 1; for (int j = 0; j < m + 2; j++) { if (a[i][j] == '1') dis1 = 2 * j + 1; } dp[i][0][0] = min(dp[i - 1][1][0], dp[i - 1][0][0]) + dis1; dp[i][1][0] = min(dp[i - 1][1][1], dp[i - 1][0][1]) + m + 2; dis2 = 1; for (int j = m + 1; j >= 0; j--) { if (a[i][j] == '1') dis2 = 2 * (m + 1 - j) + 1; } dp[i][1][1] = min(dp[i - 1][1][1], dp[i - 1][0][1]) + dis2; dp[i][0][1] = min(dp[i - 1][1][0], dp[i - 1][0][0]) + m + 2; } int mmax = 0x3f3f3f3f; int cnt = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m + 2; j++) { if (a[i][j] == '1') { cnt = i; break; } } } int d1, d2; d1 = d2 = 1; for (int j = 0; j < m + 2; j++) { if (a[cnt][j] == '1') d1 = j + 1; } for (int j = m + 1; j >= 0; j--) { if (a[cnt][j] == '1') d2 = m + 2 - j; } if (cnt >= 1) mmax = min(min(min(min(dp[cnt - 1][0][0] + d1, dp[cnt - 1][1][0] + d1), dp[cnt - 1][1][1] + d2), dp[cnt - 1][0][1] + d2), mmax); else { mmax = min(d1 - 1, mmax); } cout << mmax << endl; return 0; }
8
CPP
input() L = [0]*100001 for val in map(int,input().split()): L[val] += val a = 0 b = 0 for elem in L: a, b = max(a, elem+b), a print(a)
9
PYTHON3
#include <bits/stdc++.h> using namespace std; const int BUCKET_SIZE = 317; const int N = 100500; int powers[N]; int nextHole[N]; int jumps[N]; int lastUpdated[BUCKET_SIZE]; pair<int, int> output[N]; int n; void update(int index) { int bucket = index / BUCKET_SIZE; index = lastUpdated[bucket]; if (index == -1) return; lastUpdated[bucket] = -1; int bucketLow = bucket * BUCKET_SIZE; int bucketHigh = std::min(n - 1, bucketLow + BUCKET_SIZE); for (; index >= bucketLow; index--) { int next = index + powers[index]; if (next >= bucketHigh) { jumps[index] = 1; nextHole[index] = next; } else { jumps[index] = 1 + jumps[next]; nextHole[index] = nextHole[next]; } } } pair<int, int> search(int index) { int jumpCount = 0; update(index); while (nextHole[index] < n) { jumpCount += jumps[index]; index = nextHole[index]; update(index); } while (powers[index] + index < n) { index = powers[index] + index; jumpCount++; } return make_pair(index + 1, jumpCount + 1); } int main() { std::ios::sync_with_stdio(false); int m; cin >> n >> m; for (int i = 0; i < n; i++) { int x; cin >> x; powers[i] = x; } for (int i = 0; i < BUCKET_SIZE; i++) lastUpdated[i] = (i + 1) * BUCKET_SIZE - 1; int outCount = 0; for (int i = 0; i < m; i++) { int type, index; cin >> type >> index; index--; if (type == 0) { int power; cin >> power; powers[index] = power; int bucket = index / BUCKET_SIZE; lastUpdated[bucket] = std::max(lastUpdated[bucket], index); } else { output[outCount++] = search(index); } } for (int i = 0; i < outCount; i++) { auto out = output[i]; cout << out.first << ' ' << out.second << '\n'; } }
11
CPP
n = int(input()) answer = 1 set_p = set() prev_s, now_sum = input(), 1 for i in range(n-1): s = input() if s == prev_s: now_sum += 1 if now_sum > answer: answer = now_sum else: now_sum = 1 prev_s = s print(answer)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf("%d", &t); while (t--) { int n; scanf("%d", &n); if (n == 1) printf("-1\n"); else { printf("2"); for (int i = 1; i < n; i++) printf("3"); printf("\n"); } } return 0; }
7
CPP
#include<bits/stdc++.h> using namespace std; int l,w,q; int main() { cin>>l>>w>>q; cout<<max(q+w-l,0); return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; int main() { string s; int n; int k = 0; int kk = 0; int kkk = 0; int count = 0; while (getline(cin, s)) { if (s[0] == '+') count++; else if (s[0] == '-') count--; else { for (int i = 0; i < s.length(); i++) { if (s[i] == ':') k++; if (k > 0 && s[i] != ':') kk++; } } kkk = kkk + kk * count; kk = 0; k = 0; } cout << kkk << endl; return 0; }
7
CPP
n = int(input()) b = list(map(int, input().split())) print(min(b),max(b),sum(b))
0
PYTHON3
from collections import deque as dq n = int(input()) l = list(map(int,input().split())) l.sort() l = dq(l) r = [] while l: r.append(l.pop()) if len(l)>0: r.append(l.popleft()) if n%2==0: print((n//2)-1) print(*r) else: print(n//2) print(*r)
10
PYTHON3
def read(): return [int(v) for v in input().split()] def min_stolen(a): n = len(a) ans = 0 for i in range(1, n): ans += a[i] - a[i-1] - 1 return ans def main(): read() a = sorted(read()) print(min_stolen(a)) if __name__ == '__main__': main()
7
PYTHON3
#include <bits/stdc++.h> using namespace std; void Shivam() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int n, m, k, x, y, a, b, d[2010][2010], v[2010][2010]; bool solve(int x, int y, int k) { int l = max(1, x - k), r = min(x + k, n), t; for (int i = l; i < r + 1; i++) { t = k - abs(i - x); if (y - t > 0 && !v[i][y - t]) return a = i, b = y - t, 1; if (y + t <= m && !v[i][y + t]) return a = i, b = y + t, 1; } return 0; } int main() { cin >> n >> m >> k; for (int t = 0; t < k; t++) { cin >> x >> y; for (int i = -2; i < 3; i++) for (int j = -2; j < 3; j++) { if (x + i < 1 || x + i > n || y + j < 1 || y + j > m) continue; d[x][y] = max(d[x][y], d[x + i][y + j] - abs(i) - abs(j)); } while (!solve(x, y, d[x][y])) d[x][y]++; cout << a << " " << b << "\n"; v[a][b] = 1; } }
7
CPP
import sys from sys import stdin tt = int(stdin.readline()) for loop in range(tt): n,m = map(int,stdin.readline().split()) xtmp = list(map(int,stdin.readline().split())) stmp = list(stdin.readline().split()) xs = [(xtmp[i],stmp[i],i) for i in range(n)] xs.sort() x = [xs[i][0] for i in range(n)] s = [xs[i][1] for i in range(n)] ind = [xs[i][2] for i in range(n)] ans = [-1] * n ostk = [] estk = [] for i in range(n): if x[i] % 2 == 1: if s[i] == "R": estk.append( (x[i],s[i],ind[i]) ) else: if len(estk) > 0 and estk[-1][1] == "R": lx,ls,li = estk[-1] ; del estk[-1] rx,rs,ri = x[i],s[i],ind[i] ans[li] = ans[ri] = abs(rx-lx)//2 else: estk.append((x[i],s[i],ind[i])) else: if s[i] == "R": ostk.append( (x[i],s[i],ind[i]) ) else: if len(ostk) > 0 and ostk[-1][1] == "R": lx,ls,li = ostk[-1] ; del ostk[-1] rx,rs,ri = x[i],s[i],ind[i] ans[li] = ans[ri] = abs(rx-lx)//2 else: ostk.append((x[i],s[i],ind[i])) OL = [] OR = [] for i in ostk: if i[1] == "L": OL.append(i) else: OR.append(i) OL.reverse() while len(OL) >= 2: lx,ls,li = OL[-1] del OL[-1] rx,rs,ri = OL[-1] del OL[-1] ans[li] = ans[ri] = (lx+rx)//2 while len(OR) >= 2: lx,ls,li = OR[-1] del OR[-1] rx,rs,ri = OR[-1] del OR[-1] ans[li] = ans[ri] = ((m-lx)+(m-rx))//2 EL = [] ER = [] for i in estk: if i[1] == "L": EL.append(i) else: ER.append(i) EL.reverse() while len(EL) >= 2: lx,ls,li = EL[-1] del EL[-1] rx,rs,ri = EL[-1] del EL[-1] ans[li] = ans[ri] = (lx+rx)//2 while len(ER) >= 2: lx,ls,li = ER[-1] del ER[-1] rx,rs,ri = ER[-1] del ER[-1] ans[li] = ans[ri] = ((m-lx)+(m-rx))//2 #print (OL,EL,OR,ER,ans) if True: if len(OL) > 0 and len(OR) > 0: lx,ls,li = OL[0] rx,rs,ri = OR[0] ans[li] = ans[ri] = (lx + m + (m-rx))//2 if len(EL) > 0 and len(ER) > 0: lx,ls,li = EL[0] rx,rs,ri = ER[0] ans[li] = ans[ri] = (lx + m + (m-rx))//2 print (*ans)
9
PYTHON3
n = int(input()) a = [int(i) for i in input().split()] a.sort() print(min(a[-1] - a[1], a[-2] - a[0]))
8
PYTHON3
#include <bits/stdc++.h> #define r(i,n) for(int i=0;i<n;i++) using namespace std; int dp[111][111],n,L[111],R[111]; int dfs(int l,int r){ if(dp[l][r]>-1)return dp[l][r]; int res=1e9; for(int i=l;i<r;i++){ res=min(res,dfs(l,i)+dfs(i+1,r)+L[l]*R[i]*R[r]); } return dp[l][r]=res; } int main(){ memset(dp,-1,sizeof(dp)); r(i,111)dp[i][i]=0; cin>>n; r(i,n)cin>>L[i]>>R[i]; cout<<dfs(0,n-1)<<endl; }
0
CPP
from collections import* I=input print(sum(x*max(c.values())for c,x in zip(map(Counter,zip(*(I()for _ in[0]*int(I().split()[0])))),map(int,I().split()))))
7
PYTHON3
#include<bits/stdc++.h> using namespace std; int N,M; struct data{ int total,id; data(int a,int b):total(a),id(b){} }; bool comp(const data &a,const data &b){ return a.total!=b.total?a.total>b.total:a.id<b.id; } void solve(){ int cnt[100]={0}; for(int i=0;i<N;i++){ for(int j=0;j<M;j++){ int t;cin>>t; cnt[j]+=t; } } vector<data>V; for(int i=0;i<M;i++)V.push_back(data(cnt[i],i)); sort(V.begin(),V.end(),comp); for(int i=0;i<M;i++){ cout<<V[i].id+1<<(i!=M-1?" ":"\n"); } } int main(){ while(cin>>N>>M)solve(); }
0
CPP
t = int(input()) for _ in range(t): s = str(input()) l = [] u = [] d = [] for i, c in enumerate(s): if c.islower(): l.append(i) elif c.isupper(): u.append(i) else: d.append(i) s = list(s) if l and u and d: pass elif not l and u and d: if len(u) > len(d): s[u[0]] = 'a' else: s[d[0]] = 'a' elif l and not u and d: if len(l) > len(d): s[l[0]] = 'A' else: s[d[0]] = 'A' elif l and u and not d: if len(l) > len(u): s[l[0]] = '1' else: s[u[0]] = '1' elif l and not u and not d: s[l[0]] = 'A' s[l[1]] = '1' elif not l and u and not d: s[u[0]] = 'a' s[u[1]] = '1' elif not l and not u and d: s[d[0]] = 'a' s[d[1]] = 'A' print(''.join(s))
7
PYTHON3
#include <bits/stdc++.h> using namespace std; char s[1000010]; int n, p[1000010]; int main() { scanf("%s", s), n = strlen(s); for (int i = 0; i < n; i++) if (s[i] == '1') p[n - 1 - i] = 1; for (int i = 0, j; i < n + 2;) if (!p[i]) i++; else { j = i; while (p[j]) j++; if (j - i >= 2) { p[i] = -1; for (int k = i + 1; k < j; k++) p[k] = 0; p[j] = 1; } i = j; } int S = 0; for (int i = 0; i < n + 2; i++) if (p[i] != 0) S++; printf("%d\n", S); for (int i = 0; i < n + 2; i++) if (p[i] != 0) if (p[i] > 0) printf("+2^%d\n", i); else printf("-2^%d\n", i); return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 8; int v[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, i; cin >> n; for (i = 1; i <= n; i++) { cin >> v[i]; } for (i = 1; i <= n / 2; i++) { if (i & 1) { swap(v[i], v[n - i + 1]); } } cout << v[1]; for (i = 2; i <= n; i++) cout << " " << v[i]; cout << endl; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { long long t, i, j, k; scanf("%lld", &t); while (t--) { scanf("%lld", &k); long long m = 1, sum = 0; for (i = 3, j = 8; i <= k; i += 2, j += 8) { sum += j * m; m++; } printf("%lld\n", sum); } return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; int ans[2]; int compteur = 0; int absolu(int x) { if (x < 0) return -x; else return x; } char ask(int x, int y) { string s; compteur++; printf("1 %d %d\n", x, y); fflush(stdout); cin >> s; return s[0]; } int main() { int n, k; ans[0] = 2; ans[1] = 3; scanf("%d %d", &n, &k); int first, second; int a = 1; int b = n; int c; char s; while (a < b) { if ((b - a + 1) % 2 == 0) { c = a + (b - a + 1) / 2 - 1; } else { c = a + (b - a) / 2; } s = ask(c, c + 1); if (s == 'T') b = c; else a = c + 1; } first = a; if (first > 1) { a = 1; b = first - 1; while (a < b) { if ((b - a + 1) % 2 == 0) { c = a + (b - a + 1) / 2 - 1; } else { c = a + (b - a) / 2; } s = ask(c, c + 1); if (s == 'T') b = c; else a = c + 1; } second = a; s = ask(second, first); if (s == 'T') { printf("%d %d %d\n", 2, first, second); fflush(stdout); return 0; } } a = first + 1; b = n; while (a < b) { if ((b - a + 1) % 2 == 0) { c = a + (b - a + 1) / 2 - 1; } else { c = a + (b - a) / 2; } s = ask(c, c + 1); if (s == 'T') b = c; else a = c + 1; } second = a; printf("%d %d %d\n", 2, first, second); fflush(stdout); cerr << compteur << endl; return 0; }
8
CPP
first = input() n,k = [(int)(x) for x in first.split()] n = (int)(n) k = (int)(k) second = input() nums = [(int)(x) for x in second.split()] players = [nums[0],nums[1]] nums.pop(0) nums.pop(0) if(n==2): print(max(players)) else: while(1): winner = max(players) if(len(nums) <= k-1 and max(nums) < winner): print(winner) break elif(max(nums[:(k-1)]) < winner): print(winner) break else: nums.append(min(players)) players.remove(min(players)) players.append(nums[0]) nums.pop(0)
8
PYTHON3
#include <bits/stdc++.h> using namespace std; #define SZ(x) (int)(x.size()) #define REP(i, n) for(int i=0;i<(n);++i) #define FOR(i, a, b) for(int i=(a);i<(b);++i) #define RREP(i, n) for(int i=(int)(n)-1;i>=0;--i) #define RFOR(i, a, b) for(int i=(int)(b)-1;i>=(a);--i) #define ALL(a) a.begin(),a.end() #define DUMP(x) cerr<<#x<<" = "<<(x)<<endl #define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using P = pair<int, int>; const double eps = 1e-8; const ll MOD = 1000000007; const int INF = INT_MAX / 2; const ll LINF = LLONG_MAX / 2; template <typename T1, typename T2> bool chmax(T1 &a, const T2 &b) { if (a < b) { a = b; return true; } return false; } template <typename T1, typename T2> bool chmin(T1 &a, const T2 &b) { if (a > b) { a = b; return true; } return false; } template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "["; REP(i, SZ(v)) { if (i) os << ", "; os << v[i]; } return os << "]"; } template<typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp) { os << "{"; int a = 0; for (auto &tp : mp) { if (a) os << ", "; a = 1; os << tp; } return os << "}"; } template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << p.first << ":" << p.second; return os; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); int N, H, W; cin >> N >> H >> W; int ans = 0; for (int i = 0; i < N; i += 2) { int x, y; cin >> x >> y; ans += min(x + y, 2 * W - (x + y)); } cout << ans * H << endl; return 0; }
0
CPP
n = int(input()) l = [0] for _ in range(0, n): a = int(input()) l2 = [] for x in l: l2.append(x + a) l2.append(x - a) l = l2 print(("NO", "YES")[any([x % 360 == 0 for x in l])])
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int cnt = 0, pos1 = 0; void solve(int n, int m) { if (m == 0) { if (n == pos1) cnt++; return; } solve(n + 1, m - 1); solve(n - 1, m - 1); } int main() { string s1, s2; double a; int mark = 0, pos2 = 0; cin >> s1 >> s2; for (int i = 0; i < s2.size(); i++) { if (s2[i] == '+') pos2++; else if (s2[i] == '-') pos2--; else mark++; } for (int i = 0; i < s1.size(); i++) { if (s1[i] == '+') pos1++; else pos1--; } if (pos1 == pos2 && mark == 0) cout << "1"; else { if (abs(pos1 - pos2) <= mark) { solve(pos2, mark); a = (cnt / (double)pow(2, mark)); printf("%.15lf", a); } else cout << "0"; } return 0; }
8
CPP
import os import sys from io import BytesIO, IOBase from collections import Counter, deque,defaultdict from heapq import heappush, heappop nmbr = lambda: int(input()) lst = lambda: list(map(int, input().split())) def main(): for _ in range(nmbr()): n = nmbr() # n,k=lst() s = input() sz = n // 2 if '0' not in s: print(1, sz, 2, sz + 1) continue for i in range(n): if s[i] == '0': if ((i + 1) - (sz + 1)) >= 0: ans1 = [i - sz + 1, i + 1] ans2 = [i - sz + 1, i] break elif (i + sz + 1) <= n: ans2 = [i + 1, i + sz + 1] ans1 = [i + 1 + 1, i + sz + 1] break print(*ans1, *ans2) # l1,r1=ans1[0]-1, ans1[1]-1 # l2,r2=ans2[0]-1, ans2[1]-1 # if int(s[l1:r1+1])%int(s[l2:r2+1])!=0: # print(s) # sys.stdout.write(str(ans)+'\n') # sys.stdout.flush() 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__": for t in range(1):main()#int(input())):
9
PYTHON3
from collections import Counter def convert(arr): arr = arr.split(" ") for i in range(len(arr)): arr[i] = int(arr[i]) return arr t = int(input()) s = input() n_num = convert(s) n = len(n_num) data = Counter(n_num) get_mode = dict(data) mode = [k for k, v in get_mode.items() if v == max(list(data.values()))] ans = t - get_mode[mode[0]] print(ans)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf("%d", &t); while (t--) { int n; scanf("%d", &n); pair<int, int> a[n]; for (int i = 0; i < n; i++) { scanf("%d%d", &a[i].first, &a[i].second); } sort(a, a + n); priority_queue<int, vector<int>, greater<int> > pq; int taken = 0; long long ans = 0; for (int i = n - 1; i >= 0; i--) { pq.push(a[i].second); if (i == 0 || a[i].first != a[i - 1].first) { int num = max(0, (a[i].first - i) - taken); taken += num; while (num-- && pq.size()) { ans += pq.top(); pq.pop(); } } } printf("%lld\n", ans); } }
11
CPP
#include <bits/stdc++.h> using namespace std; int main() { string a; cin >> a; string b[10] = {"23", "10", "30", "11", "13", "12", "31", "33", "32", "21"}; string c; for (int i = 0; i < a.size(); i++) { c += b[a[i] - '0']; } string d = c; reverse(c.begin(), c.end()); if (c == d) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
10
CPP
import sys from math import * def minp(): return sys.stdin.readline().strip() def mint(): return int(minp()) def mints(): return map(int, minp().split()) n = mint() a = list(mints()) d = dict() p = dict() dp = [0]*n pd = [0]*n r = (0,0) for i in range(n): x = a[i] v = d.get(x-1, 0) + 1 r = max(r, (v, i)) dp[i] = v pd[i] = p.get(x-1, -1) d[x] = dp[i] p[x] = i print(r[0]) res = [] x = r[1] while len(res) < r[0]: res.append(x+1) x = pd[x] print(*res[::-1])
12
PYTHON3
import math for _ in range(int(input())): a,b,c=map(int,input().split()) if a!=b and b!=c and c!=a: print("NO") else: if a==b and b==c and c==a: print("YES") print(a,b,c) else: if a==b: if c>a: print("NO") else: print("YES") print(a,c,c) elif b==c: if a>b: print("NO") else: print("YES") print(a,a,b) else: if b>a: print("NO") else: print("YES") print(b,a,b)
7
PYTHON3
import sys sys.setrecursionlimit(10 ** 9) def solve(pick, idx): if pick == 0: return 0 if idx >= n: return -float('inf') if (pick, idx) in dp: return dp[pick, idx] if n-idx+2 < pick*2: return -float('inf') total = max(A[idx] + solve(pick-1, idx+2), solve(pick, idx+1)) dp[(pick, idx)] = total return total n = int(input()) A = list(map(int, input().split())) dp = {} pick = n//2 print(solve(pick, 0))
0
PYTHON3
#include <bits/stdc++.h> using namespace std; bool sim(string a, string b) { bool was = 0; if (a.length() != b.length()) { return 1; } for (long long i = 0; i < a.length(); i++) { if (a[i] >= 'A' && a[i] <= 'Z') { a[i] = a[i] - 'A' + 'a'; } if (a[i] == '0') { a[i] = 'o'; } if (a[i] == '1' || a[i] == 'i') { a[i] = 'l'; } if (b[i] >= 'A' && b[i] <= 'Z') { b[i] = b[i] - 'A' + 'a'; } if (b[i] == '0') { b[i] = 'o'; } if (b[i] == '1' || b[i] == 'i') { b[i] = 'l'; } } for (long long i = 0; i < a.length(); i++) { if (a[i] != b[i]) { return 1; } } return 0; } void solve() { string s; cin >> s; long long n; cin >> n; bool can = 1; for (long long i = 0; i < n; i++) { string s1; cin >> s1; can &= sim(s1, s); } if (can) { cout << "Yes"; } else { cout << "No"; } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t = 1; while (t--) { solve(); } return 0; }
7
CPP
#include<bits/stdc++.h> using namespace std; typedef pair<int, int> P; const int M = 1000000007; int main() { while (1) { int n; cin >> n; if (!n) return 0; vector<int> w(n); for (int i = 0; i < n; ++i) { cin >> w[i]; } vector<vector<int>> dp(n, vector<int>(n + 1, 0)); for (int i = 2; i <= n; ++i) { for (int j = 0; i + j <= n; ++j) { if (dp[j + 1][i - 2] == i - 2 && abs(w[j] - w[i + j - 1]) < 2) { dp[j][i] = i; continue; } for (int k = 1; k < i; ++k) { dp[j][i] = max(dp[j][i], dp[j][k] + dp[j + k][i - k]); } } } cout << dp[0][n] << "\n"; } }
0
CPP
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; int n, m; int a[N], num[N]; int rpos[N]; vector<int> pos[N]; void fail() { puts("no"); exit(0); } void DFS_init(int l, int r) { int cnt = 0, len = 0; for (int i = l + 1; i <= r - 1; i++) { int x = a[i]; if (x) { if (rpos[x] > r) fail(); int lst = 0; for (int p : pos[x]) { if (lst) DFS_init(lst, p); lst = p; } i = rpos[x]; ++cnt; } ++len; } ++len; if (l == 1 && !a[1]) len += 2; if (len / 2 < cnt || len % 2) fail(); int c = len / 2 - cnt; if (l == 1 && !a[1] && !c) { int _cnt = 0, _len = 0; for (int i = l + 1; i <= r - 1; i++) { int x = a[i]; ++_len; if (x) { i = rpos[x]; if (_len % 2 == 0 && _cnt * 2 == _len) { a[1] = x; break; } ++_cnt; } } } if (l == 1 && !a[1]) --l, ++r; for (int i = l + 1; i <= r - 1; i++) { if (!c) break; int x = a[i]; if (!x) a[i] = num[m--], --c; else i = rpos[x]; } a[2 * n - 1] = a[1]; } int nxt[N], pre[N]; void DFS_work(int l, int r) { assert(a[l] == a[r]); vector<int> vec; for (int i = l + 1; i <= r - 1; i++) { int x = a[i]; if (x) { int lst = 0; for (int p : pos[x]) { if (lst) DFS_work(lst, p); lst = p; } i = rpos[x]; } vec.push_back(i); } pre[l] = nxt[r] = 0; int lst = l; for (int x : vec) pre[x] = lst, nxt[lst] = x, lst = x; nxt[lst] = r, pre[r] = lst; for (int o = nxt[l]; o < r; o = nxt[o]) while (a[pre[o]] && a[o] && !a[nxt[o]]) { a[nxt[o]] = a[pre[o]]; int v = nxt[nxt[o]]; nxt[pre[o]] = v, pre[v] = pre[o]; o = pre[o]; } for (int o = pre[r]; o > l; o = pre[o]) while (!a[pre[o]] && a[o] && a[nxt[o]]) { a[pre[o]] = a[nxt[o]]; int v = pre[pre[o]]; pre[nxt[o]] = v, nxt[v] = nxt[o]; o = nxt[o]; } } int main() { scanf("%d", &n); for (int i = 1; i <= 2 * n - 1; i++) scanf("%d", &a[i]); if (n == 1) a[1] = 1; if (a[1] && a[2 * n - 1] && a[1] != a[2 * n - 1]) fail(); a[1] = a[2 * n - 1] = max(a[1], a[2 * n - 1]); for (int i = 1; i <= 2 * n - 1; i++) if (a[i]) { pos[a[i]].push_back(i); rpos[a[i]] = i; } for (int i = 1; i <= n; i++) if (!rpos[i]) num[++m] = i; if (!a[1]) DFS_init(1, 2 * n - 1); else { int x = a[1], lst = 0; for (int p : pos[x]) { if (lst) DFS_init(lst, p); lst = p; } } if (m) fail(); for (int i = 1; i <= n; i++) pos[i].clear(); for (int i = 1; i <= 2 * n - 1; i++) if (a[i]) { pos[a[i]].push_back(i); rpos[a[i]] = i; } int x = a[1], lst = 0; for (int p : pos[x]) { if (lst) DFS_work(lst, p); lst = p; } puts("yes"); for (int i = 1; i <= 2 * n - 1; i++) printf("%d%c", a[i], i == 2 * n - 1 ? '\n' : ' '); return 0; }
11
CPP
from heapq import heappush, heappop import sys input = sys.stdin.readline N, K = map(int, input().split()) P = list(map(int, input().split())) mn = [N] * (N-K) mx = [-1] * (N-K) min_heap = [] max_heap = [] for i in range(K): heappush(min_heap, P[i]) heappush(max_heap, -P[i]) used = set() for i in range(N-K): heappush(min_heap, P[i+K]) heappush(max_heap, -P[i+K]) while min_heap[0] in used: heappop(min_heap) while -max_heap[0] in used: heappop(max_heap) mn[i] = min_heap[0] mx[i] = -max_heap[0] used.add(P[i]) ans = 1 for i in range(N-K): if P[i] != mn[i] or P[i+K] != mx[i]: ans += 1 inc = 1 cnt = 0 for i in range(1, N): if P[i-1] < P[i]: inc += 1 else: inc = 1 if inc == K: cnt += 1 ans -= max(0, cnt-1) print(ans)
0
PYTHON3
#include <bits/stdc++.h> using namespace std; void tolower(string &str) { for (int i = 0; i < str.size(); ++i) { str[i] = tolower(str[i]); } } int main(void) { int n; string forbidden[100]; cin >> n; for (int i = 0; i < n; ++i) { cin >> forbidden[i]; tolower(forbidden[i]); } string team_name; cin >> team_name; char lucky; cin >> lucky; lucky = tolower(lucky); const int len = team_name.size(); string low_team = team_name; tolower(low_team); bool invalid[100]; for (int i = 0; i < len; ++i) invalid[i] = false; for (int i = 0; i < n; ++i) { const int m = forbidden[i].size(); for (int j = 0;; ++j) { j = low_team.find(forbidden[i], j); if (j == string::npos) break; for (int k = 0; k < m; ++k) { invalid[k + j] = true; } } } for (int i = 0; i < len; ++i) { if (!invalid[i]) continue; char &t = team_name[i]; char s = (low_team[i] != lucky) ? lucky : (lucky == 'a') ? 'b' : 'a'; t = isupper(t) ? toupper(s) : s; } cout << team_name << "\n"; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string a, b, c; cin >> a >> b >> c; int ans = 0; for (int i = 0; i < n; ++i) { set<char> s; s.insert(a[i]); s.insert(b[i]); s.insert(c[i]); ans += s.size() - 1; } cout << ans << '\n'; }
0
CPP
n,x,y=map(int,input().split()) a=[int(i) for i in input()] a.reverse() c=0 for i in range(x): if i==y: if a[y]!=1: c+=1 else: if a[i]!=0: c+=1 print(c)
7
PYTHON3
n=int(input()) s=[] z=0 for i in range(0,n): c=input() if z==0: if c[0]=="O" and c[1]=="O": z=1; d="++|"+c[3]+c[4] s.append(d) elif c[3]=="O" and c[4]=="O": z=2; d=c[0]+c[1]+"|++" s.append(d) else: s.append(c) else: s.append(c) if z==1 or z==2: print("YES") for i in range(0,n): print(s[i]) else: print("NO")
7
PYTHON3
[participants, pens, notebooks] = list(map(int, input().strip().split())) if participants <= pens and participants <= notebooks: print("Yes") else: print("No")
7
PYTHON3
n = int(input()) array = [int(s) for s in input().split()] array = sorted(array) curr = 1 counter = 0 for i in range(len(array)): if array[i] >= curr: counter += 1 curr += 1 print(counter)
8
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long N = 30; long long deg[N + 2], id; long long df[N + 2]; vector<long long> adj[N + 2]; pair<long long, long long> ans[N + 2]; void dfs(long long node, long long par, long long r, long long c, long long ck) { ans[node] = {r, c}; long long f = 0; for (auto xx : adj[node]) { if (xx == par) continue; if (f == 0 && ck != 2) dfs(xx, node, r + df[++id], c, 0); else if (f == 1 && ck != 3) dfs(xx, node, r, c + df[++id], 1); else if (f == 2 && ck != 0) dfs(xx, node, r - df[++id], c, 2); else dfs(xx, node, r, c - df[++id], 3); f++; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n; cin >> n; for (long long i = 1; i < n; i++) { long long u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); deg[u]++, deg[v]++; } long long rt = 1; for (long long i = 1; i <= n; i++) { if (deg[i] == 4) rt = i; if (deg[i] > 4) cout << "NO" << endl, exit(0); } df[1] = 1; for (long long i = 2; i <= n; i++) { df[i] = df[i - 1] * 31LL; if (df[i] > 1e16) df[i] = 1; } sort(df + 1, df + 31); reverse(df + 1, df + 31); dfs(rt, -1, 0, 0, 5); cout << "YES" << endl; for (long long i = 1; i <= n; i++) cout << ans[i].first << " " << ans[i].second << endl; return 0; }
11
CPP
#include <bits/stdc++.h> using namespace std; int main() { string s; int n, m; cin >> s; n = (s[0] - 48 + 1) * pow(10, s.size() - 1); m = 0; for (int i = 0; i < s.size(); i++) { m = m * 10 + s[i] - 48; } cout << n - m; }
7
CPP
#include <bits/stdc++.h> using namespace std; long long ind = 1, n, k, ans, a[200001]; pair<int, pair<int, int>> p[200000]; int main() { cin >> k; for (int i = 1; i <= k; i++) { cin >> n; ans = 0; for (int j = 1; j <= n; j++) { cin >> a[j]; ans += a[j]; } for (int j = 1; j <= n; j++) { p[ind].first = ans - a[j]; p[ind].second.first = i; p[ind].second.second = j; ind++; a[j] = 0; } } ind--; sort(p + 1, p + ind + 1); for (int i = 1; i <= ind; i++) { if (p[i].first == p[i + 1].first && p[i].second.first != p[i + 1].second.first) { cout << "YES" << endl; cout << p[i].second.first << " " << p[i].second.second << endl; cout << p[i + 1].second.first << " " << p[i + 1].second.second << endl; return 0; } } cout << "NO"; }
9
CPP
__author__ = "runekri3" a = int(input()) b = int(input()) c = int(input()) vals = [] vals.append(a + b + c) vals.append(a * b + c) vals.append(a + b * c) vals.append(a * b * c) # vals.append((a + b) + c) # vals.append((a * b) + c) vals.append((a + b) * c) # vals.append((a * b) * c) # vals.append(a + (b + c)) vals.append(a * (b + c)) # vals.append(a + (b * c)) # vals.append(a * (b * c)) print(max(vals))
7
PYTHON3
for i in range(5): ar=list(map(int,input().split())) for j in range(5): if ar[j]==1: row=j col=i break print((abs(2-row)+abs(2-col)))
7
PYTHON3
#include <bits/stdc++.h> using namespace std; static const int INF = 500000000; template <class T> void debug(T a, T b) { for (; a != b; ++a) cerr << *a << ' '; cerr << endl; } int belong[100005], cnt, id[100005]; vector<int> g[100005]; vector<int> group[100005]; int n, m; vector<int> stk; int vis[100005]; void dfs(int v, int p) { vis[v] = 1; stk.push_back(v); for (int i = 0; i < g[v].size(); ++i) { int to = g[v][i]; if (to == p) continue; if (vis[to]) { if (belong[to] != -1) continue; int j = stk.size() - 1; while (j >= 0 && stk[j] != to) { belong[stk[j]] = cnt; --j; } belong[to] = cnt; ++cnt; continue; } dfs(to, v); } stk.pop_back(); } int rec(int v, int p) { int be = belong[v], res = (group[be].size() > 1); int exist = 0; for (int i = 0; i < group[be].size(); ++i) { int v2 = group[be][i]; int ecnt = 0; for (int j = 0; j < g[v2].size(); ++j) { int to = g[v2][j]; if (belong[to] == be) continue; int tmp; if (to == p) tmp = 1; else tmp = rec(to, v2); res += tmp; ++ecnt; } res -= ecnt / 2; if (ecnt) ++exist; } if (exist >= 2) --res; return res; } int main() { scanf("%d%d", &n, &m); for (int i = 0; i < m; ++i) { int a, b; scanf("%d%d", &a, &b); --a; --b; g[a].push_back(b); g[b].push_back(a); } memset(belong, -1, sizeof(belong)); dfs(0, -1); for (int i = 0; i < n; ++i) if (belong[i] == -1) belong[i] = cnt++; for (int i = 0; i < n; ++i) group[belong[i]].push_back(i); printf("%d %d\n", rec(0, -1), m); return 0; }
10
CPP
#include<bits/stdc++.h> using namespace std; #define ll long long int #define trace(x) cerr<<#x<<": "<<x<<endl; void dbg(){cerr<<"\n";} template<typename T, typename... Types> void dbg(T var1, Types... var2){cerr<<var1<<" ";dbg(var2...);} int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll tc,n,x,c0,c1,j; bool flag; cin>>tc; while(tc--){ flag=true; cin>>n; vector<pair<ll,ll>>a(n),b(n); for(int i=0;i<n;i++){ cin>>a[i].first; a[i].second=i%2; } b=a; sort(b.begin(),b.end()); for(int i=0;i<n;i++){ b[i].second=i%2; } sort(a.begin(),a.end()); sort(b.begin(),b.end()); if(a==b){ cout<<"YES\n"; } else{ cout<<"NO\n"; } } return 0; }
9
CPP
s=input() m=input() s+=s if m in s: print("Yes") else: print("No")
0
PYTHON3
#include <bits/stdc++.h> using namespace std; const double epsilon = 1e-7; void solve() { int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; ++i) cin >> v[i]; int res = -1; int mx = *max_element(v.begin(), v.end()); for (int i = 0; i < n; ++i) { if (v[i] != mx) continue; if (i and v[i - 1] != mx) { res = i + 1; break; } if (i < n - 1 and v[i + 1] != mx) { res = i + 1; break; } } cout << res << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { solve(); } return 0; }
9
CPP
sum = 0 for i in range(int(input())): j = input() sum += '++' in j sum -= '--' in j print(sum)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int t, n; int d[305]; int vis[1000005]; int main() { scanf("%d", &t); while (t--) { memset(vis, 0, sizeof(vis)); scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &d[i]); vis[d[i]] = 1; } sort(d, d + n); long long ans = 1ll * d[0] * d[n - 1]; int flag = 1; for (int i = 1; i <= n / 2; i++) { if (ans != (1ll * d[i] * d[n - i - 1])) { flag = 0; break; } } if (flag) { for (long long i = 2; i * i <= ans; i++) { if (ans % i == 0) { if (vis[i] == 0) { flag = 0; break; } } } } if (flag) printf("%lld\n", ans); else printf("-1\n"); } return 0; }
10
CPP