solution
stringlengths
10
983k
difficulty
int64
0
25
language
stringclasses
2 values
import math data=input().split() n=int(data[0]) m=int(data[1]) a=int(data[2]) k=math.ceil(n/a) l=math.ceil(m/a) print(k*l)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int MaxN = 100010; int solve(int n, int m) { int x[] = {n, m}; int s = n + m; --x[0]; int a = 0, p = 0; for (int i = 2; i <= s; ++i) { if (i & 1) { if (x[p]) { --x[p]; ++a; } else { p ^= 1; --x[p]; --a; } } else { if (x[p ^ 1]) { p ^= 1; --x[p]; --a; } else { --x[p]; ++a; } } } return a; } int main() { int n, m; cin >> n >> m; int x = max(solve(n, m), solve(m, n)); int a = (n + m - 1 + x) / 2; int b = n + m - 1 - a; cout << a << " " << b << endl; return 0; }
8
CPP
k=int(input()) l=list(map(int,input().split())) l.sort(reverse=True) i=0 s=0 flag=0 if(k==0): print(0) flag=1 while i<12 and flag==0: s+=l[i] if(s>=k): print(i+1) flag=1 break i+=1 if flag==0: print(-1)
7
PYTHON3
n=int(input()) c=list(map(int,input().split())) t=list(map(int,input().split())) cdiffs=[c[i+1]-c[i] for i in range(n-1)] tdiffs=[t[i+1]-t[i] for i in range(n-1)] if sorted(cdiffs)==sorted(tdiffs) and t[0]==c[0]: print("Yes") else: print("No")
11
PYTHON3
#include <bits/stdc++.h> using namespace std; int cost[200000 + 5], jump[200000 + 5], mark[200000 + 5]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, i, j, k, temp, ticks = 0, ans = 0; cin >> n; for (i = 1; i <= n; ++i) cin >> cost[i]; for (i = 1; i <= n; ++i) cin >> jump[i]; for (i = 1; i <= n; ++i) { if (mark[i]) continue; ++ticks; j = i; mark[j] = ticks; while (true) { k = j; j = jump[j]; if (mark[j]) { if (mark[j] != ticks) break; temp = cost[j]; while (j != k) { j = jump[j]; temp = min(temp, cost[j]); } ans += temp; break; } else mark[j] = ticks; } } cout << ans; return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; long long powmod(long long a, long long b) { long long tmp = 1; a %= (1000000007); for (; b; b >>= 1) { if (b & 1) tmp = tmp * a % (1000000007); a = a * a % (1000000007); } return tmp; } long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } template <class T> inline void R(T &xx) { xx = 0; char ch = getchar(); bool F = 0; while ((ch < '0' || ch > '9') && ch != '-') ch = getchar(); if (ch == '-') F = 1, ch = getchar(); while (ch >= '0' && ch <= '9') xx = xx + xx + (xx << 3) + ch - 48, ch = getchar(); if (F) xx = -xx; } template <class T> inline void add(int &x, T y) { for (x += y; x >= (1000000007); x -= (1000000007)) ; } char a[2][200011]; int n, q; struct nod { int a[2][2]; nod() { a[0][0] = a[0][1] = a[1][0] = a[1][1] = (1 << 29); } } seg[200011 << 3]; inline nod merge(nod a, nod b) { nod c; for (int i = 0; i < (int)2; i++) for (int j = 0; j < (int)2; j++) { for (int k = 0; k < (int)2; k++) c.a[i][j] = min(c.a[i][j], a.a[i][k] + b.a[k][j] + 1); } return c; } void build(int cur, int l, int r) { if (l == r) { for (int i = 0; i < (int)2; i++) for (int j = 0; j < (int)2; j++) if (a[i][l] == '.' && a[j][l] == '.') seg[cur].a[i][j] = abs(i - j); return; } int mid = l + r >> 1; build((cur << 1), l, mid); build((cur << 1 | 1), mid + 1, r); seg[cur] = merge(seg[(cur << 1)], seg[(cur << 1 | 1)]); } nod que(int cur, int l, int r, int L, int R) { if (l >= L && r <= R) return seg[cur]; int mid = l + r >> 1; if (R <= mid) return que((cur << 1), l, mid, L, R); if (L > mid) return que((cur << 1 | 1), mid + 1, r, L, R); return merge(que((cur << 1), l, mid, L, mid), que((cur << 1 | 1), mid + 1, r, mid + 1, R)); } int main() { R(n); R(q); scanf("%s%s", a[0] + 1, a[1] + 1); build(1, 1, n); for (int x, y, x1, y1, x2, y2; q--;) { R(x); R(y); if (x > n) x1 = 1, y1 = x - n; else x1 = 0, y1 = x; if (y > n) x2 = 1, y2 = y - n; else x2 = 0, y2 = y; if (y1 > y2) swap(x1, x2), swap(y1, y2); nod ans = que(1, 1, n, y1, y2); printf("%d\n", (ans.a[x1][x2] > (n << 1)) ? -1 : ans.a[x1][x2]); } return 0; }
11
CPP
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:128000000") using namespace std; mt19937 ggen; int n; long long A, cf, cm, m; pair<long long, int> a[100010]; long long aval[100010]; long long ps[100010]; long long rps[100010]; long long mps[100010]; void solve() { cin >> n >> A >> cf >> cm >> m; for (int i = 1; i <= n; i++) { cin >> a[i].first; a[i].second = i; } sort(a + 1, a + n + 1); for (int i = 1; i <= n; i++) { ps[i] = ps[i - 1] + a[i].first; } mps[0] = mps[1] = 0; for (int i = 2; i <= n; i++) { mps[i] = mps[i - 1] + (long long)(i - 1) * (long long)(a[i].first - a[i - 1].first); } for (int i = n; i >= 1; i--) rps[n - i + 1] = rps[n - i] + a[i].first; long long ansv = -1, anspref, anspval, anssuff; for (int i = 0; i <= n; i++) { long long needA = (long long)(i)*A - rps[i]; if (needA > m) break; long long ost = m - needA; int l = 0, r = n - i, mid, res = -1; while (l <= r) { mid = (l + r) >> 1; if (mps[mid] <= ost) { res = mid; l = mid + 1; } else r = mid - 1; } if (res == -1) continue; ost -= mps[res]; long long tans = cf * (long long)(i); long long minl; if (res == 0) minl = A; else minl = a[res].first + min(ost / (long long)(res), A - a[res].first); tans += minl * cm; if (ansv == -1 || tans > ansv) { anspref = res; anssuff = i; anspval = minl; ansv = tans; } } for (int i = 1; i <= n; i++) { if (n - i < anssuff) { aval[a[i].second] = A; } else if (i <= anspref) { aval[a[i].second] = anspval; } else aval[a[i].second] = a[i].first; } cout << ansv << endl; for (int i = 1; i <= n; i++) cout << aval[i] << " "; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); srand(88); ggen = mt19937(88); solve(); return 0; }
8
CPP
from math import gcd K=int(input()) S=0 for a in range(1,K+1): for b in range(1,K+1): for c in range(1,K+1): S+=gcd(a,gcd(b,c)) print(S)
0
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int a[n], b[n]; for (int i = 0; i < n; i++) { cin >> a[i]; b[i] = a[i]; } string s; cin >> s; int cnt = 0; vector<int> big, small, old1, old0; for (int i = 0; i < s.size(); i++) { cnt += (s[i] == '1'); (s[i] == '1' ? old1 : old0).push_back(a[i]); } sort(a, a + n); for (int i = n - 1; i >= 0; i--, cnt--) { if (cnt > 0) big.push_back(a[i]); else small.push_back(a[i]); } sort(old1.begin(), old1.end()); sort(old0.begin(), old0.end()); sort(big.begin(), big.end()); sort(small.begin(), small.end()); map<int, int> mp; for (int i = 0; i < old0.size(); i++) { mp[old0[i]] = small[i]; } for (int i = 0; i < old1.size(); i++) { mp[old1[i]] = big[i]; } for (int i = 0; i < n; i++) { if (s[i] == '0') { cout << mp[b[i]]; } else { cout << mp[b[i]]; } cout << " "; } cout << '\n'; } }
8
CPP
n = input() m = input() q ="" for i in range(len(n)): if n[i]!=m[i]: q+="1" else: q+="0" print(q)
7
PYTHON3
n = int(input()) s = [x for x in input()] v = ['a', 'e', 'i', 'o', 'u','y'] ans = '' i = 0 while i<(len(s)): if(s[i] not in v): ans+=s[i] else: ans+=s[i] while(i<len(s) and s[i] in v): i+=1 i-=1 i+=1 print(ans)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int MAXN = 100 * 1000 + 1000; int arr[MAXN]; int mrk[MAXN]; int n; int32_t main() { int cur = 0, max_so = 0; cin >> n; for (int i = 0; i < 2 * n; i++) { int num; cin >> num; if (!mrk[num]) { mrk[num] = 1; cur++; } else { mrk[num] = 0; cur--; } max_so = max(max_so, cur); } cout << max_so << endl; }
7
CPP
#include <bits/stdc++.h> const char EMPTY = '.'; static void setComponent(int rows, int cols, const std::vector<std::string>& input, int row, int col, std::deque<std::pair<int, int>>& toVisit, std::vector<std::vector<int>>& components, std::unordered_map<int, int>& componentsSize) { toVisit.clear(); toVisit.push_back(std::make_pair(row, col)); int curComponent = componentsSize.size(); while (!toVisit.empty()) { const std::pair<int, int>& cur = toVisit.front(); toVisit.pop_front(); if (cur.first >= 0 && cur.first < rows && cur.second >= 0 && cur.second < cols && components[cur.first][cur.second] == -1 && input[cur.first][cur.second] == EMPTY) { components[cur.first][cur.second] = curComponent; ++componentsSize[curComponent]; toVisit.push_back(std::make_pair(cur.first - 1, cur.second)); toVisit.push_back(std::make_pair(cur.first + 1, cur.second)); toVisit.push_back(std::make_pair(cur.first, cur.second - 1)); toVisit.push_back(std::make_pair(cur.first, cur.second + 1)); } } } int main() { int rows, cols; std::cin >> rows >> cols; std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); std::vector<std::string> input(rows, std::string(cols, ' ')); std::vector<std::string> output(rows, std::string(cols, ' ')); std::vector<std::vector<int>> components(rows, std::vector<int>(cols, -1)); std::unordered_map<int, int> componentsSize; for (int row = 0; row < rows; ++row) { scanf("%s", &input[row][0]); } std::deque<std::pair<int, int>> toVisit; std::unordered_set<int> uniqueComponents; for (int startRow = 0; startRow < rows; ++startRow) { for (int startCol = 0; startCol < cols; ++startCol) { if (input[startRow][startCol] != EMPTY) { setComponent(rows, cols, input, startRow - 1, startCol, toVisit, components, componentsSize); setComponent(rows, cols, input, startRow + 1, startCol, toVisit, components, componentsSize); setComponent(rows, cols, input, startRow, startCol - 1, toVisit, components, componentsSize); setComponent(rows, cols, input, startRow, startCol + 1, toVisit, components, componentsSize); uniqueComponents.clear(); if (startRow > 0) uniqueComponents.insert(components[startRow - 1][startCol]); if (startRow < rows - 1) uniqueComponents.insert(components[startRow + 1][startCol]); if (startCol > 0) uniqueComponents.insert(components[startRow][startCol - 1]); if (startCol < cols - 1) uniqueComponents.insert(components[startRow][startCol + 1]); int total = 1; for (int component : uniqueComponents) { total += componentsSize[component]; } output[startRow][startCol] = char('0') + total % 10; } else { output[startRow][startCol] = '.'; } } printf("%s\n", output[startRow].c_str()); } }
9
CPP
M,D=map(int,input().split()) ans = 0 for m in range(1,M+1): for d in range(22,D+1): d1 = d%10 d10 = d//10 if d1 >=2 and d10 >=2 and m == d1*d10: ans += 1 print(ans)
0
PYTHON3
n = int(input()) ai = input().replace(" ","") num = ai.count("1") print(num + ai.replace("101","11011").count("101"))
7
PYTHON3
import sys def main(): s = input() n = len(s) lim = 243 ar = [int(c) for c in s] dp = [0] * (n + lim + 3) for i in range(n - 1, -1, -1): x = 0 k = 1 if ar[i] == 0 else lim for j in range(k): if (i + j) == n: break x = ((x * 10) + ar[i + j]) % 3 dp[i] = max(dp[i], dp[i + j + 1] + (x == 0)) print(dp[0]) if __name__ == '__main__': main()
10
PYTHON3
#include <bits/stdc++.h> using namespace std; template <class A, class B> ostream& operator<<(ostream& o, pair<A, B>& p) { return o << "(" << p.first << ", " << p.second << ")"; } template <class T> ostream& operator<<(ostream& o, const vector<T>& v) { o << "{"; for (typeof((v).begin()) it = (v).begin(); it != (v).end(); it++) o << *it << ", "; return o << "}"; } struct debugger { ostream& out; bool first; void start() { first = true; } debugger(ostream& out) : out(out) { start(); } void nl() { out << endl; start(); } template <class T> debugger& operator,(T& v) { if (first) first = false; else out << ", "; out << v; return *this; } template <class T> debugger& operator,(pair<T*, int> arr) { out << "{"; for (typeof((arr.second) - 1) i = (0); i <= ((arr.second) - 1); i++) { out << arr.first[i] << ", "; } out << "}"; return *this; } } dbg(cerr); int n; string str1, str2; int _11, _10, _01, _00, c1, c2; int main() { cin >> n; cin >> str1 >> str2; for (typeof((n * 2) - 1) i = (0); i <= ((n * 2) - 1); i++) { if (str1[i] == '1' && str2[i] == '1') _11++; else if (str1[i] == '1' && str2[i] == '0') _10++; else if (str1[i] == '0' && str2[i] == '1') _01++; else if (str1[i] == '0' && str2[i] == '0') _00++; } for (typeof((n * 2) - 1) i = (0); i <= ((n * 2) - 1); i++) { if (i % 2 == 0) { if (_11) _11--, c1++; else if (_10) _10--, c1++; else if (_01) _01--; else _00--; } else { if (_11) _11--, c2++; else if (_01) _01--, c2++; else if (_10) _10--; else _00--; } } if (c1 == c2) cout << "Draw" << endl; else if (c1 > c2) cout << "First" << endl; else cout << "Second" << endl; return 0; }
7
CPP
#include<bits/stdc++.h> using namespace std; int main() {long long n;cin>>n; cout<<(n/2)+(n%2); return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; int main() { set<long long> s; long long n, k; cin >> n >> k; for (int i = 1; i <= k; i++) { if (s.find(n % i) != s.end()) break; s.insert(n % i); } if (s.size() == k) cout << "YES"; else cout << "NO"; }
9
CPP
t=int(input()) for i in range(t): n=int(input()) a=input() b="" for j in range(0,len(a),2): b+=a[j] print(b)
7
PYTHON3
N,A,B=map(int,input().split()) x=min([N*A,B]) print(x)
0
PYTHON3
# https://codeforces.com/contest/1358/problem/D import sys import os import heapq import math try: path = "./file/input.txt" if os.path.exists(path): sys.stdin = open(path, 'r') # sys.stdout = open(r"./file/output.txt", 'w') except: pass t = 1 def printd(value): # print(value) pass def case(): arr = list(map(int, input().split(" "))) n, x = arr[0], arr[1] arr = list(map(int, input().split(" "))) arr = arr * 2 result = [0] * len(arr) total = [0] * len(arr) left = 0 right = 0 sum = arr[0] result[0] = arr[0] total[0] += int((1 + arr[0]) * arr[0] / 2) while right < n * 2: right += 1 if right >= n * 2: break total[right] = total[right - 1] sum += arr[right] result[right] = sum total[right] += int((1 + arr[right]) * arr[right] / 2) while left < right and sum - arr[left] > x: sum -= arr[left] total[right] -= int((1 + arr[left]) * arr[left] / 2) result[right] = sum left += 1 answer = 0 for index in range(n * 2): if result[index] >= x: diff = result[index] - x value = total[index] - int((1 + diff) * diff / 2) answer = max(answer, value) print(answer) for _ in range(t): case()
10
PYTHON3
#include <bits/stdc++.h> using namespace std; const int NUM_ROW = 15; const int NUM_COL = 15; int mod(int a) { if (a < 0) { return -a; } return a; } int cmp(const void *a, const void *b) { return -(*(int *)a - *(int *)b); } void FV(int grid[NUM_ROW][NUM_COL], int length) { for (int k = 0; k < length; k++) { for (int i = 0; i < length; i++) { for (int j = 0; j < length; j++) { if (grid[k][j] != 0 && grid[i][k] != 0) grid[i][j] = min(grid[i][j], grid[i][k] + grid[k][j]); } } } } void printGrid(int grid[NUM_ROW][NUM_COL], int row_length, int col_length) { for (int i = 0; i < row_length; i++) { for (int j = 0; j < col_length; j++) { cout << grid[i][j] << " "; } cout << endl; } } void printArr(int *arr, int length) { for (int i = 0; i < length; i++) { cout << arr[i] << " "; } cout << endl; } void copyGrid(int grid1[NUM_ROW][NUM_COL], int grid[NUM_ROW][NUM_COL], int row_length, int col_length) { for (int i = 0; i < row_length; i++) { for (int j = 0; j < col_length; j++) { grid1[i][j] = grid[i][j]; } } } int main() { int n, k; cin >> n >> k; int tot = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { tot++; } } if (tot <= k) { cout << "no solution"; return 0; } for (int i = 0; i < n; i++) { int x = i; int y = n - i - 1; cout << x << " " << y * n << endl; } }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; unsigned long long int a; unsigned long long int temp; unsigned long long int temp2; unsigned long long int count = 0; for (int i = 0; i < n; i++) { cin >> a; if (a == 1) { cout << "NO\n"; } else { temp = (unsigned long long int)sqrt(a); if (a == (temp * temp)) { temp2 = (unsigned long long int)sqrt(temp); if ((temp % 2 == 0) && (temp2 >= 2)) { count++; cout << "NO\n"; } else { for (unsigned long long int j = 3; j <= temp2; j = j + 2) { if (temp % j == 0) { count++; cout << "NO\n"; break; } } } if (count == 0) { cout << "YES\n"; } count = 0; } else cout << "NO\n"; } } return 0; }
8
CPP
import math as m n=int(input()) arr=[] c=1 for i in range(n): t=int(input()) if t/2==m.ceil(t/2): arr.append(t//2) elif c%2!=0: arr.append(m.ceil(t/2)) c+=1 else: arr.append(m.floor(t/2)) c+=1 for i in arr: print(i)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long MAXN = 2e5 + 5; pair<long long, long long> a[MAXN]; long long s; long long n; bool check(long long x) { long long sum = 0, cnt = 0; vector<long long> nums; for (long long i = 0; i < n; i++) { if (a[i].first >= x) { sum += a[i].first; cnt++; } else { if (a[i].second < x) { sum += a[i].first; } else { nums.push_back(a[i].first); } } } long long left = max((long long)0, (n + 1) / 2 - cnt); if (left > nums.size()) return 0; for (long long i = 0; i < nums.size() - left; i++) { sum += nums[i]; } for (long long i = nums.size() - left; i < nums.size(); i++) { sum += x; } return (sum <= s); } int main() { long long q; cin >> q; while (q--) { cin >> n >> s; for (long long i = 0; i < n; i++) { cin >> a[i].first >> a[i].second; } sort(a, a + n); long long l = 1, r = 1e9 + 100; while (l + 1 < r) { long long m = (l + r) >> 1; if (check(m)) { l = m; } else { r = m; } } cout << l << "\n"; } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; const int MAXM = 60; int sum[MAXN << 2][MAXM]; void push_up(int rt) { for (int i = 0; i < MAXM; ++i) sum[rt][i] = sum[rt << 1][i] + sum[rt << 1 | 1][(i + sum[rt << 1][i]) % MAXM]; } void build(int l, int r, int rt) { if (l == r) { int val; scanf("%d", &val); for (int i = 0; i < MAXM; ++i) sum[rt][i] = 1 + (i % val == 0); return; } int m = l + r >> 1; build(l, m, rt << 1); build(m + 1, r, rt << 1 | 1); push_up(rt); } void update(int p, int val, int l, int r, int rt) { if (l == r) { for (int i = 0; i < MAXM; ++i) sum[rt][i] = 1 + (i % val == 0); return; } int m = l + r >> 1; if (p <= m) update(p, val, l, m, rt << 1); else update(p, val, m + 1, r, rt << 1 | 1); push_up(rt); } void query(int L, int R, int l, int r, int rt, int &ret) { if (L <= l && r <= R) { ret += sum[rt][ret % MAXM]; return; } int m = l + r >> 1; if (L <= m) query(L, R, l, m, rt << 1, ret); if (m < R) query(L, R, m + 1, r, rt << 1 | 1, ret); } int main() { int n, q, x, y, ans; char c; scanf("%d", &n); build(1, n, 1); scanf("%d", &q); while (q--) { scanf(" %c%d%d", &c, &x, &y); switch (c) { case 'A': ans = 0; query(x, y - 1, 1, n, 1, ans); printf("%d\n", ans); break; case 'C': update(x, y, 1, n, 1); break; } } }
10
CPP
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int tc = 1; cin >> tc; while (tc--) { long long int m, d, w; cin >> m >> d >> w; w = w / gcd(max(w, d - 1), min(w, d - 1)); m = min(d, m), d = min(d, m); long long int n = (m - 1) / w, ans = (n) * ((m - 1) % w + 1) + w * n * (n - 1) / 2; cout << ans << "\n"; } return 0; }
11
CPP
n=int(input()) a=list(input()) l=[0,0,0,0,0] for i in a: if i=='A': l[0]+=1 elif i=='C': l[1]+=1 elif i=='G': l[2]+=1 elif i=='T': l[3]+=1 else: l[4]+=1 max1=max(l[:-1]) req=0 for i in l[:-1]: req=req+(max1-i) if ((req!=l[-1] and l[-1]!=n) and ((l[-1]-req)%4!=0 or l[-1]<req)) or (l[-1]==n and n%4!=0): print("===") elif l[-1]==n: print('ACGT'*(l[-1]//4)) else: i=1 j=0 while i<=(max1-l[0]): if a[j]=='?': a[j]='A' i=i+1 j=j+1 i=1 while i<=(max1-l[1]): if a[j]=='?': a[j]='C' i=i+1 j=j+1 i=1 while i<=(max1-l[2]): if a[j]=='?': a[j]='G' i=i+1 j=j+1 i=1 while i<=(max1-l[3]): if a[j]=='?': a[j]='T' i=i+1 j=j+1 if l[-1]-req>0: i=0 while i<(l[-1]-req)//4: if a[j]=='?': a[j]='A' i=i+1 j=j+1 i=0 while i<(l[-1]-req)//4: if a[j]=='?': a[j]='C' i=i+1 j=j+1 i=0 while i<(l[-1]-req)//4: if a[j]=='?': a[j]='G' i=i+1 j=j+1 i=0 while i<(l[-1]-req)//4: if a[j]=='?': a[j]='T' i=i+1 j=j+1 for i in a: print(i,end='')
8
PYTHON3
n=[] x=str(input()) d=x.replace('WUB',' ') c=d.replace(' ',' ') for v in c: n.append(v) if n[0]==' ': n.remove(n[0]) for m in n: print(m,end='')
7
PYTHON3
l,r=map(int,input().split()) mini=2019 L=l R=r+1 if r-l<2019*2 else l+2019+1 for i in range(L,R): for j in range(i+1,R): mini=min(mini,i*j%2019) print(mini)
0
PYTHON3
n = int(input()) array = list(map(int, input().split())) i = 0 j = len(array)-1 soma = 0 soma1 = array[i] soma2 = array[j] while i < j: if soma1 < soma2: i += 1 soma1 += array[i] elif soma1 > soma2: j -= 1 soma2 += array[j] else: if soma1 > soma: soma = soma1 i += 1 j -= 1 soma1 += array[i] soma2 += array[j] print(soma)
9
PYTHON3
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll inf = 1e9 + 7; const double PI = 3.141592653589793; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n, sumq = 0, mini = 0; cin >> n; ll q[n - 1]; for (ll i = 0; i < (ll)(n - 1); ++i) { cin >> q[i]; sumq += q[i]; mini = min(mini, sumq); } ll dp[n]; set<ll> st; bool f = true; for (ll i = 0; i < (ll)(n); ++i) { (i == 0) ? dp[i] = 1 - mini : dp[i] = dp[i - 1] + q[i - 1]; if (st.count(dp[i]) != 0 || dp[i] < 0 || dp[i] > n) f = false; st.insert(dp[i]); } if (!f) cout << "-1\n"; else { for (ll i = 0; i < (ll)(n); ++i) { cout << dp[i]; cout << (i == n - 1 ? '\n' : ' '); } } return 0; }
9
CPP
#include<bits/stdc++.h> using namespace std; int main(){ int N,M; cin>>N>>M; int ans=pow(2,M)*(100*N+1800*M); cout<<ans<<endl; }
0
CPP
x1, y1 = map(int, input().split()) x2, y2 = map(int, input().split()) n = int(input()) num_sign_diff = 0 for road in range(n): a, b, c = map(int, input().split()) pos1 = (a * x1 + b * y1 + c) > 0 pos2 = (a * x2 + b * y2 + c) > 0 if pos1 + pos2 == 1: #exactly one of them is on positive side of line num_sign_diff += 1 print(num_sign_diff)
7
PYTHON3
l = list(map(int,input().split())) coins = 0 login_times = 0 while True: coins += l[0] login_times += 1 if login_times%7==0: coins += l[1] if coins>=l[2]: print(login_times) break
0
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { long long n, s, sum1 = 0, sum2 = 0, c = 0, f; vector<long long> v; cin >> n; for (size_t i = 0; i < n; i++) { cin >> s; v.push_back(s); if (v[i] % 2 != 0) { if (c % 2 == 0) { v[i] = ceil(v[i] / 2.0); c++; } else { if (v[i] != 0) v[i] = floor(v[i] / 2.0); c++; } } else v[i] /= 2; sum1 += v[i]; } for (long long x : v) cout << x << endl; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const long long mod = 1e9 + 7; long long dp[25][25]; int a[30]; int dfs(int pos, int sta, bool lead, bool limit) { if (pos == -1) return 1; if (!limit && !lead && dp[pos][sta] != -1) return dp[pos][sta]; int up = limit ? a[pos] : 9; long long ans = 0; for (int i = 0; i <= up; i++) { if (lead && i == 0) ans += dfs(pos - 1, sta, lead, limit && i == a[pos]); else if (sta + (i != 0) <= 3) ans += dfs(pos - 1, sta + (i > 0 ? 1 : 0), lead && i == 0, limit && i == a[pos]); } if (!limit && !lead) dp[pos][sta] = ans; return ans; } long long solve(long long x) { int pos = 0; while (x) { a[pos++] = x % 10; x /= 10; } return dfs(pos - 1, 0, true, true); } int main() { memset(dp, -1, sizeof dp); int ww; scanf("%d", &ww); long long a, b; while (ww--) { scanf("%lld%lld", &a, &b); printf("%lld\n", solve(b) - solve(a - 1)); } return 0; }
9
CPP
def optimal(num): int_num = int(num) if int_num >= 0: return num elif int_num >= -10: return 0 else: if num[-2] > num[-1]: res = num[0:-2] + num[-1] else: res = num[0:-1] if res == '-0': return 0 return res def main(): n = input() print(optimal(n)) main()
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int constexpr nax = 3e5 + 5; using ll = int64_t; const int INF = 1e9; template <typename T> struct fenwick { T bit[nax]; fenwick() { memset(bit, 0, sizeof(bit)); } void update(int x, T val) { for (; x < nax; x += x & -x) bit[x] += val; } T get(int x) { int res = 0; for (; x > 0; x -= x & -x) res += bit[x]; return res; } T get(int l, int r) { return get(r) - get(l - 1); } }; struct segtree { static constexpr int Mx = 4 * nax; ll sg[Mx] = {}, tag[Mx] = {}; inline void pull(int v) { sg[v] = min(sg[v * 2], sg[v * 2 + 1]); } segtree() { fill(sg, sg + Mx, INF); fill(tag, tag + Mx, 0); } inline void push(int v) { if (v * 2 + 1 < Mx && tag[v]) { sg[v * 2] += tag[v]; sg[v * 2 + 1] += tag[v]; tag[v * 2] += tag[v]; tag[v * 2 + 1] += tag[v]; } tag[v] = 0; } inline void update(int v, int x, int y, int l, int r, ll val) { push(v); if (l > r) return; if (l == x && r == y) { sg[v] += val; tag[v] += val; return push(v); } int mid = x + y >> 1; update(v * 2, x, mid, l, min(r, mid), val); update(v * 2 + 1, mid + 1, y, max(l, mid + 1), r, val); pull(v); } int find_first_neg(int v, int x, int y) { push(v); if (x == y) { assert(sg[v] <= 0); return x; } else { int mid = x + y >> 1; if (sg[v * 2] <= 0) return find_first_neg(v * 2, x, mid); else return find_first_neg(v * 2 + 1, mid + 1, y); } } }; segtree sg; fenwick<int> sum; int n, nq; int ans[nax]; int b[nax]; vector<pair<int, int>> q[nax]; int main() { cin.tie(0)->sync_with_stdio(false); cin >> n >> nq; for (int i = 1; i <= n; ++i) { cin >> b[i]; b[i] = i < b[i] ? INF : i - b[i]; } for (int i = 1; i <= nq; ++i) { int x, y; cin >> x >> y; q[x + 1].emplace_back(n - y, i); } for (int i = n; i >= 1; --i) { sg.update(1, 1, n, i, i, (ll)b[i] - INF); while (sg.sg[1] <= 0) { int v = sg.find_first_neg(1, 1, n); sum.update(v, 1); sg.update(1, 1, n, v, v, INF); sg.update(1, 1, n, v, n, -1); } for (const auto &[r, id] : q[i]) ans[id] = sum.get(i, r); } for (int i = 1; i <= nq; ++i) { cout << ans[i] << '\n'; } }
9
CPP
# -*- coding: utf-8 -*- """ Created on Wed Aug 12 18:22:02 2020 @author: The Wonder Land """ """ A. Watermelon time limit per test: 1 second memory limit per test: 64 megabytes input: standard input output: standard output One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed w kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight. Input The first (and the only) input line contains integer number w (1 ≤ w ≤ 100) — the weight of the watermelon bought by the boys. Output Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. Examples input 8 output YES """ val = int(input()) if(val > 2 and val%2 == 0): print("YES") else: print("NO")
7
PYTHON3
#include <bits/stdc++.h> int main() { long long int a, b, s; scanf("%lld%lld%lld", &a, &b, &s); if (s >= abs(a) + abs(b)) { if ((s - (abs(a) + abs(b))) % 2 == 0) { printf("Yes\n"); } else { printf("No\n"); } } else { printf("No\n"); } return 0; }
7
CPP
#from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] # from math import gcd # from itertools import combinations,permutations,accumulate, product # (string,3) 3回 # #from collections import deque # from collections import deque,defaultdict,Counter # import decimal # import re # import math # import bisect # import heapq # # # # pythonで無理なときは、pypyでやると正解するかも!! # # # my_round_int = lambda x:np.round((x*2 + 1)//2) # 四捨五入g # # インデックス系 # int min_y = max(0, i - 2), max_y = min(h - 1, i + 2); # int min_x = max(0, j - 2), max_x = min(w - 1, j + 2); # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 #mod = 9982443453 #mod = 998244353 INF = float('inf') from sys import stdin readline = stdin.readline def readInts(): return list(map(int,readline().split())) def readTuples(): return tuple(map(int,readline().split())) def I(): return int(readline()) n,m = readInts() A = readInts() Q = readInts() import itertools A = [0] + list(itertools.accumulate(A)) # print(A) import bisect for i in range(m): v = Q[i] idx = bisect.bisect_left(A,v) print(idx,v-A[idx-1])
9
PYTHON3
#include <bits/stdc++.h> using namespace std; long long int A[1005], B[1005]; long long int V[1005]; int main() { int n, k1, k2; scanf("%d%d%d", &(n), &(k1), &(k2)); for (int i = 1; i <= n; i++) scanf("%lld", &(A[i])); for (int i = 1; i <= n; i++) scanf("%lld", &(B[i])); for (int i = 1; i <= n; i++) { long long int a = A[i]; long long int b = B[i]; V[i] = abs(a - b); } int k = k1 + k2; while (k1 > 0 || k2 > 0) { long long int mx = -100000000000014; int index; for (int i = 1; i <= n; i++) { long long int x = V[i]; if (x >= mx) { mx = x; index = i; } } if (A[index] >= B[index]) { if (k1 > 0) { A[index] -= 1; k1 -= 1; } else { B[index] += 1; k2 -= 1; } } else if (A[index] < B[index]) { if (k2 > 0) { B[index] -= 1; k2 -= 1; } else { A[index] += 1; k1 -= 1; } } V[index] = abs(A[index] - B[index]); } long long int sum = 0; for (int i = 1; i <= n; i++) { sum += (V[i] * V[i]); } printf("%lld\n", sum); }
8
CPP
#include <bits/stdc++.h> using namespace std; char arr[1000][1000]; int main() { int n; cin >> n; int ans = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if (i % 2 == 0 && j % 2 == 0) arr[i][j] = 'C'; else if (i % 2 == 0 && j % 2 != 0) arr[i][j] = '.'; else if (i % 2 != 0 && j % 2 != 0) arr[i][j] = 'C'; else arr[i][j] = '.'; } } for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if (arr[i][j] == 'C') ans++; } } cout << ans << endl; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) cout << arr[i][j]; cout << endl; } }
7
CPP
# Legends Always Come Up with Solution # Author: Manvir Singh import os import sys from io import BytesIO, IOBase def solve(): n = int(input()) a = [list(map(int,input().split())) for _ in range(n)] for i in range(5): for j in range(i + 1, 5): x,y,f=0,0,1 for k in range(n): if not (a[k][i]|a[k][j]): f=0 break x+=a[k][i] y+=a[k][j] if f and x>=(n//2) and y>=(n//2): return "YES" return "NO" def main(): for _ in range(int(input())): print(solve()) # FASTIO 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()
8
PYTHON3
def fonct(): n=int(input()) s=set() nb=0; for i in map(int,input().split()): s.add(i); t=len(s) l=list() if(t<=1): print("NO"); else: for i in s: l.append(i); l.sort() print (l[1]) fonct()
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long maxN = 1e18; const long long minN = -1e18; const int INF = 2e9; const long long MOD = 1e9 + 7; const long long MOD1 = 998244353; const int baseHash = 331; const int bigNumLength = 5000; const long double PI = acos(-1); const long long limit = 3e5 + 5; const long long limit1 = 1e6 + 5; const long long limit2 = 1e3 + 5; pair<int, int> dir[] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; pair<int, int> NON = {-1, -1}; struct Team { long long p, w; }; int n; vector<Team> strong, weak; Team our; struct CMP { bool operator()(const Team &a, const Team &b) { return (a.w - a.p) > (b.w - b.p); } }; bool cmp1(Team a, Team b) { return (a.w - a.p) < (b.w - b.p); } bool cmp2(Team a, Team b) { return a.p > b.p; } bool check(int place) { Team cur = our; for (int i = (0); i < (strong.size() - place + 1); ++i) { cur.p -= strong[i].w - strong[i].p + 1; if (cur.p < 0) return false; } priority_queue<Team, vector<Team>, CMP> heap; int j = 0; for (int i = (strong.size() - place + 1); i < (strong.size()); ++i) heap.push(strong[i]); while (j < weak.size() && weak[j].p > cur.p) heap.push(weak[j++]); while (heap.size() > place - 1) { while (heap.size() > place - 1) { Team tmp = heap.top(); heap.pop(); cur.p -= tmp.w - tmp.p + 1; if (cur.p < 0) return false; } while (j < weak.size() && weak[j].p > cur.p) heap.push(weak[j++]); } return (cur.p >= 0); } void solveProblem() { sort((strong).begin(), (strong).end(), cmp1); sort((weak).begin(), (weak).end(), cmp2); int l = 1, r = strong.size(); int ans = strong.size() + 1; while (l <= r) { int mid = (l + r) >> 1; if (check(mid)) { ans = mid; r = mid - 1; } else l = mid + 1; } cout << ans << '\n'; } void fastInput() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } void readInput() { cin >> n; cin >> our.p >> our.w; for (int i = (1); i <= (n - 1); ++i) { Team t; cin >> t.p >> t.w; if (t.p > our.p) strong.push_back(t); else weak.push_back(t); } } int main() { fastInput(); readInput(); solveProblem(); }
10
CPP
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int ans{}; for (int i{1}; N >= i; i *= 100) { ans += min(i*10-1, N) - (i - 1); } cout << ans << endl; return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; int main() { int x, o = 0, l = 0; string str; cin >> str; for (x = 0; x < str.length(); x++) { if (str[x] == 'o') o++; else l++; } if (l == 0 || o == 0) cout << "YES" << endl; else { if (l % o) cout << "NO" << endl; else cout << "YES" << endl; } return 0; }
7
CPP
ip = str(input()).split(' ') m = int(ip[0]) n = int(ip[1]) num_of_dominos_placed = 0 def print_board(): global board for row in board: print(''.join(row)) def place_domino(row, col): global board, num_of_dominos_placed, m, n if board[row][col] == '*': if col + 1 < n and board[row][col + 1] == '*': board[row][col] = '-' board[row][col + 1] = '-' num_of_dominos_placed += 1 elif row + 1 < m and board[row + 1][col] == '*': board[row][col] = '|' board[row + 1][col] = '|' num_of_dominos_placed += 1 board = [] for row in range(m): board.append(['*' for col in range(n)]) # print_board() for row in range(m): for col in range(n): place_domino(row, col) # print_board() print(num_of_dominos_placed)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int a, b, n, p; cin >> a >> b >> n; p = a ^ b; if (n % 3 == 0) cout << a << endl; else if ((n - 1) % 3 == 0) cout << b << endl; else cout << p << endl; } return 0; }
7
CPP
arr=input() arr=arr.lower() new="" ch=['a','e','i','o','u','y'] for i in range(len(arr)): if arr[i] not in ch: new+='.' new+=arr[i] print(new)
7
PYTHON3
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse2") using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { std::cerr << name << " : " << arg1 << '\n'; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); std::cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } long long max(long long a, long long b) { return (a > b) ? a : b; } long long min(long long a, long long b) { return (a < b) ? a : b; } void amax(long long& a, long long b) { a = max(a, b) % 1000000007; } void amin(long long& a, long long b) { a = min(a, b) % 1000000007; } void inc(long long& a, long long b) { a = (a + b) % 1000000007; } void dec(long long& a, long long b) { a = (a - b + 1000000007) % 1000000007; } const long long MAXN = 2e6 + 10; const long long M2 = 1e9 + 9; vector<long long> h(MAXN, 0), h2(MAXN, 0), PI(MAXN, 0), PI2(MAXN, 0); long long power(long long x, unsigned long long y, unsigned long long m) { if (y == 0) return 1; long long p = power(x, y / 2, m) % m; p = (p * p) % m; return (y % 2 == 0) ? p : (x * p) % m; } void hashed(string s) { long long n = s.size(); long long p = 31, cur = 1, val = 0; long long p2 = 31, cur2 = 1, val2 = 0; for (long long i = 0; i < n; i++) { val += (cur * (s[i] - 'a' + 1)); val %= 1000000007; h[i] = val; PI[i] = power(cur, 1000000007 - 2, 1000000007); cur *= p; cur %= 1000000007; val2 += (cur2 * (s[i] - 'a' + 1)); val2 %= M2; h2[i] = val2; PI2[i] = power(cur2, M2 - 2, M2); cur2 *= p2; cur2 %= M2; } } pair<long long, long long> hashed2(string s) { long long n = s.size(); long long p = 31, cur = 1, val = 0; long long p2 = 31, cur2 = 1, val2 = 0; for (long long i = 0; i < n; i++) { val += (cur * (s[i] - 'a' + 1)); val %= 1000000007; cur *= p; cur %= 1000000007; val2 += (cur2 * (s[i] - 'a' + 1)); val2 %= M2; cur2 *= p2; cur2 %= M2; } return {val, val2}; } long long solve() { long long n, k; string s; cin >> n >> k >> s; s = s + s; map<pair<long long, long long>, long long> keys; long long q; cin >> q; for (long long i = 0; i < q; i++) { string t; cin >> t; keys[hashed2(t)] = i + 1; } map<pair<long long, long long>, long long> m; vector<long long> ans(n + 1, -1); long long flag = 1, st = 1e9; hashed(s); for (long long j = 0; j < k; j++) { long long val = h[j + k - 1] + 1000000007; if (j) val -= h[j - 1]; val %= 1000000007; val *= PI[j]; val %= 1000000007; long long val2 = h2[j + k - 1] + M2; if (j) val2 -= h2[j - 1]; val2 %= M2; val2 *= PI2[j]; val2 %= M2; if (keys[{val, val2}]) { st = j; map<long long, long long> m; flag = 1; for (long long l = 0; l < n; l++) { long long i = l * k + st; long long right = i + k - 1; long long val = h[right] + 1000000007; if (i) val -= h[i - 1]; val %= 1000000007; val *= PI[i]; val %= 1000000007; long long val2 = h2[right] + M2; if (i) val2 -= h2[i - 1]; val2 %= M2; val2 *= PI2[i]; val2 %= M2; if (m[keys[{val, val2}]] || keys[{val, val2}] == 0) { flag = 0; break; } m[keys[{val, val2}]] = l + 1; } if (flag) { cout << "YES" << '\n'; for (auto i : m) ans[i.second] = i.first; for (long long i = 1; i < n + 1; i++) cout << ans[i] << " "; return 0; } } } cout << "NO"; return 0; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long t = 1; while (t--) { solve(); } }
11
CPP
#include <bits/stdc++.h> using namespace std; const int N = 510000; int n, k; char s1[N], s2[N]; int main() { scanf("%d%d", &n, &k); scanf("%s%s", s1 + 1, s2 + 1); long long ans = 0, now = 0, last = 0; for (int i = 1; i <= n; i++) { now = (now << 1) + s2[i] - s1[i]; long long tmp = min((long long)k, now + 1) - last; ans += tmp * (n - i + 1); last += tmp; if (last == k) break; } cout << ans << endl; return 0; }
11
CPP
#include <bits/stdc++.h> int main(void) { int n, a[1000000], i = 0, b = 0, j; char s[1000000]; scanf("%s", s); n = strlen(s); j = n - 1; for (b = 0; b < n; b++) { if (s[b] == 'r') { a[i] = b + 1; i++; } else if (s[b] == 'l') { a[j] = b + 1; j--; } } for (i = 0; i < n; i++) printf("%d\n", a[i]); return 0; }
7
CPP
n = int(input()) d = list(map(int,input().split()))[:n] dp = [[int(101) for i in range(100)] for j in range(3)] dp[0][0] = 1 if d[0]==1 or d[0]==3: dp[1][0] = 0 if d[0]==2 or d[0]==3: dp[2][0] = 0 for i in range(1,n): dp[0][i] = 1+min(dp[0][i-1],dp[1][i-1],dp[2][i-1]) if d[i]==1 or d[i]==3: dp[1][i] = min(dp[0][i-1],dp[2][i-1]) if d[i]==2 or d[i]==3: dp[2][i] = min(dp[0][i-1],dp[1][i-1]) print(min(dp[0][n-1],dp[1][n-1],dp[2][n-1]))
7
PYTHON3
if __name__ == '__main__': n = int(input()) if n in (1, 2): print(1) elif n == 3: print(0) elif n % 4 == 0 or (n-3) % 4 == 0: print(0) else: print(1)
7
PYTHON3
import math as mt import sys,string,bisect input=sys.stdin.readline import random from collections import deque,defaultdict L=lambda : list(map(int,input().split())) Ls=lambda : list(input().split()) M=lambda : map(int,input().split()) I=lambda :int(input()) n,s=M() a=L() def check(k,s): l=a[::] for i in range(len(l)): l[i]+=(k*(i+1)) l.sort() w=sum(l[:k:]) if(w<=s): return (True,w) else: return (False,0) le=0 r=n d=0 t=0 while(le<=r): mid=(le+r)//2 p,q=check(mid,s) if(p): le=mid+1 d=mid t=q else: r=mid-1 print(d,t)
9
PYTHON3
n, m, q= map(int,input().split()) s,t = input(), input() ans = "" for i in range(n-m+1): if s[i:i+m] == t: ans += "1" else:ans += "0" for i in range(0,q): l, r = map(int,input().split()) if r-l+1 >= m: print(ans[l-1 : r-m+1].count("1")) else:print("0")
8
PYTHON3
nm = list(map(int, input().split())) n, m = nm[0], nm[1] pol = set() vrag = set() for i in range(0, n): pol.add(input()) for i in range(0, m): vrag.add(input()) vrf = 0 while len(pol) > 0 and len(vrag) > 0: vrf = 0 pol_flag = 0 for w in pol: if w in vrag: pol.remove(w) vrag.remove(w) pol_flag = 1 break if pol_flag == 0: pol.pop() if len(vrag) == 0: break vrag_flag = 0 for w in vrag: if w in pol: pol.remove(w) vrag.remove(w) vrag_flag = 1 vrf = 1 break if vrag_flag == 0: vrag.pop() vrf = 1 if len(pol) == 0 and vrf == 1: print('NO') else: print('YES')
8
PYTHON3
a = input().lstrip("0") b = input().lstrip("0") if a == "": a = "0" if b == "": b = "0" if len(a) > len(b): print(">") elif len(a) < len(b): print("<") else: equal = True for i in range(0,len(a)): if int(a[i]) > int(b[i]): equal = False print(">") break elif int(a[i]) < int(b[i]): equal = False print("<") break if equal: print("=")
7
PYTHON3
import sys def input(): return sys.stdin.readline().strip() def ints(): return map(int, input().split()) def solve(): input() k, n, m = ints() a = list(ints()) b = list(ints()) i = j = 0 res = [] while i < len(a) or j < len(b): if i < len(a) and a[i] == 0: res.append(a[i]) k += 1 i += 1 elif j < len(b) and b[j] == 0: res.append(b[j]) k += 1 j += 1 elif i < len(a) and a[i] <= k: res.append(a[i]) i += 1 elif j < len(b) and b[j] <= k: res.append(b[j]) j += 1 else: return [-1] return res T = int(input()) for _ in range(T): print(*solve())
9
PYTHON3
#include <bits/stdc++.h> using namespace std; int T, n; int num; int main() { ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); cin >> T; while (T--) { cin >> n; deque<int> deq; for (int i = 0; i < n; ++i) { cin >> num; deq.push_back(num); } int prev = -1, cnt = 0, a = 0, b = 0; for (int i = 0; i < n; ++i) { if (deq.empty()) break; int cur = 0; if (i % 2 == 0) { do { cur += deq.front(); deq.pop_front(); } while (prev >= cur && !deq.empty()); a += cur; } else { do { cur += deq.back(); deq.pop_back(); } while (prev >= cur && !deq.empty()); b += cur; } prev = max(prev, cur); cnt++; } cout << cnt << " " << a << " " << b << '\n'; } return 0; }
10
CPP
#include <iostream> #include <string> #include <algorithm> #include <vector> using namespace std; int main() { int n, cnt = 0, p[1000][1000]; bool check[1000]; cin >> n; for (int i = 0; i < n; i++){ for(int j = 0; j < 3; j++){ cin >> p[i][j]; } sort(p[i], p[i] + 3); } for(int i = 0; i < n - 1; i++){ for(int j = i + 1; j < n; j++){ for(int k = 0; k < 3; k++){ if(p[i][k] != p[j][k]){ break; } if(k == 2){ check[j] = true; } } } } for(int i = 0; i < n; i++){ if(check[i]){ cnt++; } } cout << cnt << endl; return 0; }
0
CPP
#include<bits/stdc++.h> using namespace std; struct RMQ{ static const int MAX_N = 1 << 17; int n,dat[2*MAX_N-1]; RMQ(){} RMQ(int n_){init(n_);} void init(int n_){ n=1; while(n<n_) n*=2; for(int i=0;i<2*n-1;i++) dat[i]=INT_MAX; } void update(int k,int a){ k+=n-1; dat[k]=a; while(k>0){ k=(k-1)/2; dat[k]=min(dat[k*2+1],dat[k*2+2]); } } int query(int a,int b,int k,int l,int r){ if(r<=a||b<=l) return INT_MAX; if(a<=l&&r<=b) return dat[k]; else{ int vl=query(a,b,k*2+1,l,(l+r)/2); int vr=query(a,b,k*2+2,(l+r)/2,r); return min(vl,vr); } } int query(int a,int b){ return query(a,b,0,0,n); } }; int main(){ int n,q; cin>>n>>q; RMQ rmq(n); for(int i=0;i<q;i++){ int c,x,y; cin>>c>>x>>y; if(c) cout<<rmq.query(x,y+1)<<endl; else rmq.update(x,y); } return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; void solve() {} long long findNumberOfDigits(long n, long long base) { if (n == 0) return 1; long long dig = (long long)(floor(log(n) / log(base)) + 1); return dig; } void no() { cout << 0 << '\n'; exit(0); } long long pows[50]; signed main() { ios::sync_with_stdio(0); cin.sync_with_stdio(0); cin.tie(0); pows[0] = 1; for (long long i = 1; i <= 20; i++) { pows[i] = pows[i - 1] * 7; } long long n, m; cin >> n >> m; vector<long long> p = {0, 1, 2, 3, 4, 5, 6}; long long dn = findNumberOfDigits(n - 1, 7), dm = findNumberOfDigits(m - 1, 7); if ((dn + dm) > 7) no(); set<pair<vector<long long>, vector<long long>>> ans; do { long long nsum = 0, msum = 0; vector<long long> vn, vm; for (long long i = 0; i < dn; i++) { nsum += pows[i] * p[i]; vn.emplace_back(p[i]); } for (long long i = 0; i < dm; i++) { msum += pows[i] * p[i + dn]; vm.emplace_back(p[i + dn]); } if (nsum < n and msum < m) { ans.emplace(pair<vector<long long>, vector<long long>>(vn, vm)); } } while (next_permutation(p.begin(), p.end())); for (auto x : ans) { for (long long y : x.first) { if (false) cerr << y << " "; } if (false) cerr << '\n'; for (long long y : x.second) { if (false) cerr << y << " "; } if (false) cerr << '\n'; if (false) cerr << "~~~~" << '\n'; } cout << (long long)ans.size() << '\n'; }
7
CPP
for _ in range(int(input())): n=int(input()) d={} for i in range(n): a=input() for j in a: try: d[j]+=1 except: d[j]=1 k=0 for i in d.keys(): if d[i]%n==0: pass else: k=1 break if k==0: print("YES") else: print("NO")
7
PYTHON3
import collections, heapq, bisect, math def gcd(a, b): if b == 0: return a return gcd(b, a%b) def solve(s, n): count = 0 out = [] for i in range(0,len(s),2): if s[i:i+2] == 'aa': out.append('ab') count += 1 elif s[i:i+2] == 'bb': out.append('ab') count += 1 else: out.append(s[i:i+2]) print(count) print(''.join(out)) q = 1#input() tests = [] for test in range(1): n = input() s = input() #tests.append([int(p) for p in input().split(' ')]) solve(s, n) #print(solve(n,b))
7
PYTHON3
#include <bits/stdc++.h> using namespace std; constexpr long long INF = 1999999999999999997; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; char a[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> a[i][j]; } } int f = 0; for (int i = 0; i < n - 1; i++) { for (int j = 0; j < n - 1; j++) { if (a[i][j] == '1') { if (a[i + 1][j] == '0' && a[i][j + 1] == '0') f = 1; } } } if (f) cout << "NO" << endl; else cout << "YES" << endl; } }
11
CPP
#include<iostream> #include<cstdio> #include<vector> #include<algorithm> #include<map> #include<deque> #include<cstring> #include<climits> #include<cassert> #include<cctype> #define REP(i,s,n) for(int i=s;i<n;++i) #define rep(i,n) REP(i,0,n) using namespace std; int dx[] = {0,1}; int dy[] = {1,0}; struct Data { int x,y; char v; bool operator < ( const Data &data ) const { if( x != data.x ) return x < data.x; if( y != data.y ) return y < data.y; return v < data.v; } }; bool used[60][60]; void makeGraph(vector<string> &C,vector<vector<int>> &G,vector<char> &ws) { int H = C.size(), W = C[0].size(); map<Data,int> mp; int _cnt = 0; rep(i,H) rep(j,W) if( ( i == 0 && j == 0 ) || ( i == H-1 && j == W-1 ) || isalpha(C[i][j]) ) { mp[(Data){j,i,C[i][j]}] = _cnt++; } int V = mp.size(); G.resize(V); rep(i,V) G[i].clear(); ws.resize(V); rep(i,H) rep(j,W) if( ( i == 0 && j == 0 ) || ( i == H-1 && j == W-1 ) || isalpha(C[i][j]) ) { int sp = mp[(Data){j,i,C[i][j]}]; ws[sp] = C[i][j]; memset(used,false,sizeof used); deque<int> deq; deq.push_back(j+i*W); while( !deq.empty() ) { int cur = deq.front(); deq.pop_front(); int x = cur % W, y = cur / W; rep(k,2) { int nx = x + dx[k], ny = y + dy[k]; if( !( 0 <= nx && nx < W && 0 <= ny && ny < H ) ) continue; if( used[ny][nx] ) continue; if( C[ny][nx] == '#' ) continue; used[ny][nx] = true; if( isalpha(C[ny][nx]) || ( nx == W-1 && ny == H-1 ) ) G[sp].push_back(mp[(Data){nx,ny,C[ny][nx]}]); deq.push_back(nx+ny*W); } } } } bool visit(const vector<vector<int>>& G,int v,vector<int>& order,vector<int>& color){ color[v] = 1; rep(i,(int)G[v].size()) { int e = G[v][i]; if(color[e] == 2)continue; if(color[e] == 1)return false; if(!visit(G,e,order,color))return false; } order.push_back(v); color[v] = 2; return true; } bool topologicalSort(const vector<vector<int>>& G,vector<int>& order){ int SizeG = G.size(); vector<int> color(SizeG); for(int u=0;u<SizeG;u++) if(!color[u] && !visit(G,u,order,color)) return false; reverse(order.begin(),order.end()); return true; } bool canPut(char a,char A) { if( !islower(a) || !isupper(A) ) return false; return toupper(a) == A; } #define MAX_V 600 bool hasEdge[MAX_V][MAX_V]; int dp[MAX_V][MAX_V]; void compute(vector<string> &C) { if( C.size() == 1 && C[0].size() == 1 ) { puts("0"); return; } // DAG??? vector<vector<int>> G; vector<char> ws; makeGraph(C,G,ws); { bool fin = true; rep(i,(int)G[0].size()) if( G[0][i] == (int)G.size()-1 ) { fin = false; break; } if( fin ) { puts("-1"); return; } } // topological sort vector<int> order; assert( topologicalSort(G,order) ); // DP int V = G.size(); memset(hasEdge,false,sizeof hasEdge); rep(i,V) rep(j,(int)G[i].size()) hasEdge[i][G[i][j]] = true; assert( V < MAX_V ); memset(dp,0,sizeof dp); REP(len,2,V+1) { rep(i,V) { int j = i + len - 1; if( j >= V ) break; int sp = order[i]; int ep = order[j]; if( !hasEdge[sp][ep] ) continue; bool put = false; if( canPut(ws[sp],ws[ep]) ) { put = true; dp[sp][ep] = max(dp[sp][ep],1); } rep(k,(int)G[sp].size()) { int nex = G[sp][k]; rep(l,(int)G[nex].size()) { int nnex = G[nex][l]; if( !( nnex == ep || hasEdge[nnex][ep] ) ) continue; dp[sp][ep] = max(dp[sp][ep], max(dp[nex][nnex],dp[sp][nex]+dp[nnex][ep])); if( put && nnex != ep ) { dp[sp][ep] = max(dp[sp][ep], dp[nex][nnex]+1); } } } } } cout << dp[0][V-1] << endl; } int main() { int H,W; while( cin >> H >> W, H|W ) { vector<string> C(H); rep(i,H) cin >> C[i]; compute(C); } return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; int n; cin >> n >> a >> b >> c; if (n == 1) { cout << "0" << endl; } else if (n == 2) { cout << min(a, b) << endl; } else { if (c >= a || c >= b) { printf("%d\n", (n - 1) * min(a, b)); } else if (a >= c && b >= c) { printf("%d\n", min(a, b) + (n - 2) * c); } } return 0; }
7
CPP
a=int(input()) b=int(input()) c=int(input()) d=int(input()) e=int(input()) f=e-a*(c-1)-b*(d-1) if f<0: f=0 if c>d: g=d h=b j=c else: g=c h=a j=d if e<g*h: i=int(e/g) else: i=h+int((e-h*g)/j) print(f) print(i)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; long long mod_plus(long long a, long long b) { return (a + b) % 1000000007; } long long mod_mul(long long a, long long b) { return (a * b) % 1000000007; } long long m[10], g[10]; long long go(char *second, int now) { if (now < 0) return 0; return mod_plus(m[second[now] - '0'], mod_mul(g[second[now] - '0'], go(second, now - 1))); } void process(int dig, char *second) { int len = strlen(second); m[dig] = go(second, len - 1); long long temp = 1; for (len = 0; second[len]; len++) temp = mod_mul(temp, g[second[len] - '0']); g[dig] = temp; return; } char str[100005], tt[100005]; vector<string> all; int main() { scanf("%s", str); int n, i; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%s", tt); string now = tt; all.push_back(now); } for (i = 0; i < 10; i++) { m[i] = i; g[i] = 10; } for (i = n - 1; i >= 0; i--) { strcpy(tt, all[i].c_str()); process(tt[0] - '0', tt + 3); } cout << go(str, strlen(str) - 1) << endl; return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == '9' || s[i] == 'H' || s[i] == 'Q') { cout << "YES"; return 0; } } cout << "NO"; }
7
CPP
def maximize_items_count(p, f, cnt_s, cnt_w, s, w): if s > w or (s == w and cnt_s < cnt_w): cnt_s, cnt_w = cnt_w, cnt_s s, w = w, s max_sum = 0 max_cnt_s = min(cnt_s, p // s + f // s) p_cnt_s = 0 while p_cnt_s <= max_cnt_s: p_cnt_w = (p - s * p_cnt_s) // w f_cnt_w = (f - s * (max_cnt_s - p_cnt_s)) // w if p_cnt_w >= 0 and f_cnt_w >= 0: max_sum = max(max_sum, max_cnt_s + min(cnt_w, p_cnt_w + f_cnt_w)) p_cnt_s += 1 return max_sum t = int(input()) for i in range(t): p, f = list(map(int, input().split())) cnt_s, cnt_w = list(map(int, input().split())) s, w = list(map(int, input().split())) print(maximize_items_count(p, f, cnt_s, cnt_w, s, w))
8
PYTHON3
// -----Joy Baba Lokenath, Joy Maa Lokenath ,Joy Guru Lokenath, Joy Shiva Lokenath, Joy Brahma Lokenath----- // #include<bits/stdc++.h> #include<stdio.h> using namespace std; #define ll long long int #define vv vector #define desc greater<int> #define pll pair<ll,ll> #define pii pair<int,int> #define pb push_back #define ff first #define ss second #define gcd(a,b) __gcd(a,b) #define setbits(x) __builtin_popcount(x) #define inf 1e18 #define len(x) x.length() #define all(v) v.begin(), v.end() #define fl(i, a, b) for(int i = a; i < b; i++) #define rfl(i, a, b) for(int i = a; i > b; i--) #define fastaf ios::sync_with_stdio(false), cin.tie(0) , cout.tie(0) #define cases() int t; cin >> t; while (t--) #define mod 4294967296 /****************************** FUNCTIONS ****************************************/ //Modular exponentiation // ll power(ll x, ll y, ll p){ // ll res = 1; // x = x % p; // while (y > 0){ // if (y & 1) // res = (res*x) % p; // y = y>>1; // x = (x*x) % p; // } // return res; // } // //For M=prime no // ll modInverse(ll A,ll M) // { // return power(A,M-2,M); // } // int phi(int n) // { // float result = n; // for (int p = 2; p * p <= n; ++p) { // if (n % p == 0) { // while (n % p == 0) // n /= p; // result *= (1.0 - (1.0 / (float)p)); // } // } // if (n > 1) // result *= (1.0 - (1.0 / (float)n)); // return (int)result; // } void openFiles() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } // void swap(int* a, int* b) // { // int t = *a; // *a = *b; // *b = t; // } // //Prime Factorisation // int prime_factor[100000]; // vector<pair<int, int> > prime_factors[100000]; // void GeneratePrimeFactors(int N) // { // for(int i = 2; i < N; i++) { // if(prime_factor[i] != 0) continue; // prime_factor[i] = i; // for(int j = 2*i; j < N; j += i) { // prime_factor[j] = i; // } // } // for(int i = 2; i < N; i++) { // int x = i; // map<int, int> M; // while(x != 1) { // M[prime_factor[x]]++; // x /= prime_factor[x]; // } // for(auto v : M) { // prime_factors[i].push_back(v); // } // } // } // bool prime[10000007]; // vector<int> ans; // void Seive(int N) // { // memset(prime,true,sizeof(prime)); // for(int i=2;i<=N;i++) // { // if(prime[i]) // { // ans.pb(i); // for(int j=2*i;j<=N;j+=i) // { // prime[j]=false; // } // } // } // } // Matrix Exponentiation // void multiply(ll a[2][2],ll b[2][2]) // { // ll mul[2][2]; // for(int i=0;i<2;i++) // { // for(int j=0;j<2;j++) // { // mul[i][j]=0; // for(int k=0;k<2;k++) // { // mul[i][j]=(mul[i][j] +(a[i][k]%mod * b[k][j]%mod))%mod; // } // } // } // for(int i=0;i<2;i++) // { // for(int j=0;j<2;j++) // { // a[i][j]=mul[i][j]%mod; // } // } // } // void power(ll M[2][2],ll n) // { // if(n==0 || n==1) // return; // ll M1[2][2]={{1,1},{1,0}}; // power(M,n/2); // multiply(M,M); // if(n%2!=0) // multiply(M,M1); // } // ll fib(ll n) // { // ll M[2][2]={{1,1},{1,0}}; // if(n==0) // return 0; // power(M,n-1); // return M[0][0]%mod; // } // ll fact[10000]; // void factorial(int n){ // fact[1]=1; // fact[0]=1; // for(int i=2;i<=n;i++){ // fact[i]=(fact[i-1]*i)%M; // } // } // ll comb(int n,int r){ // if(r>n) // return 0; // return (fact[n] * modInverse(fact[r], M) % M // * modInverse(fact[n - r], M) % M) // % M; // } // ------------------------------ My Template end ------------------------------- // int main() { fastaf; //openFiles(); cases(){ ll n,k; cin>>n>>k; for(int i=0;i<n;i++){ if(i%3==0){ cout<<"a"; } else if(i%3==1){ cout<<"b"; } else{ cout<<"c"; } } cout<<endl; } return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; long long mult(long long a, long long b, long long p = 1000000007) { return ((a % p) * (b % p)) % p; } long long add(long long a, long long b, long long p = 1000000007) { return (a % p + b % p) % p; } long long fpow(long long n, long long k, long long p = 1000000007) { long long r = 1; for (; k; k >>= 1) { if (k & 1) r = r * n % p; n = n * n % p; } return r; } long long inv(long long a, long long p = 1000000007) { return fpow(a, p - 2, p); } long long a[300005]; long long ev[300005]; long long odd[300005]; long long sum[300005]; int main() { ios::sync_with_stdio(0); long long n; cin >> n; for (long long i = 0; i < n; i++) { long long p; cin >> p; a[i] = __builtin_popcountll(p); } for (long long i = n - 1; i >= 0; i--) { sum[i] = sum[i + 1] + a[i]; odd[i] += odd[i + 1]; ev[i] += ev[i + 1]; if (sum[i] & 1) { odd[i - 1]++; } else { ev[i - 1]++; } } long long ans = 0; for (long long i = n - 2; i >= 0; i--) { if (sum[i] & 1) { ans += odd[i]; } else { ans += ev[i]; ans++; } long long sm = 0; long long maxx = 0; for (long long j = i; j < min((long long)100 + i, n); j++) { sm += a[j]; maxx = max(maxx, a[j]); if (sm % 2 == 0 && 2 * maxx > sm) { ans--; } } } cout << ans << "\n"; }
8
CPP
#include<iostream> using namespace std; int main() { int r,g,b,n,i,j; long long dem=0; cin >> r >> g >> b >> n; for (i=0; i<=n/r; i++) for (j=0; j<=(n-i*r)/g; j++) if ((n-i*r-j*g)%b==0) dem++; cout << dem; return 0; }
0
CPP
n=int(input()) space=0 for i in range(n): p,q=map(int,input().split()) if q-p >= 2: space= space+1 print(space)
7
PYTHON3
#include <bits/stdc++.h> #pragma GCC target("avx") #pragma GCC optimize(3) #pragma GCC optimize("Ofast") using namespace std; template <class code> inline code read(const code &a) { code x = 0; short w = 0; char ch = 0; while (!isdigit(ch)) { w |= ch == '-'; ch = getchar(); } while (isdigit(ch)) { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar(); } return w ? -x : x; } void print(int x) { if (x < 0) putchar('-'), x = -x; if (x >= 10) print(x / 10); putchar(x % 10 + 48); } int a[505][505], q[105]; int main() { int k = read(k), u = 0, w = 1, k1 = k; while (k != 0) { q[++u] = k % 2; k /= 2; w *= 2; } a[1][1] = k1 + w; a[2][2] = k1 + w; a[3][3] = k1 + w; a[1][2] = w; a[1][3] = w; a[1][4] = w; a[2][3] = w; a[2][4] = w; a[2][1] = k1; a[3][1] = k1; a[3][2] = k1; a[3][4] = k1; printf("3 4\n"); for (int i = 1; i <= 3; i++) { for (int j = 1; j <= 4; j++) printf("%d ", a[i][j]); puts(""); } return 0; }
10
CPP
n=int(input()) a=[int(x) for x in input().split()] pref=[0] for item in a: if item<0: pref.append(pref[-1]+1) else: pref.append(pref[-1]) non=0 on=0 arr=0 for item in pref: if item%2==0: arr+=non on+=1 else: arr+=on non+=1 print(arr,n*(n+1)//2-arr)
8
PYTHON3
import io,os from collections import deque dev=0 if dev: def read(): return input().strip() else: input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def read(): return input().decode() t = int(read()) def solve(): n,m = map(int,read().split()) initial = list(map(int, read().split())) desired = list(map(int, read().split())) painters = list(map(int, read().split())) set_desired = set(desired) dict_colors=dict() dict_painters = dict() res = deque() for i,(ini,des) in enumerate(zip(initial,desired)): if(ini!=des): try: dict_colors[des][0]+=1 dict_colors[des][1].append(i) except: dict_colors[des] = [1,deque([i])] for painter in painters: dict_painters[painter] = dict_painters.get(painter,0)+1 for key in dict_colors.keys(): if dict_colors[key][0]>dict_painters.get(key,0): return False trash = -1 if painters[-1] in set_desired: if dict_colors.get(painters[-1],0): trash = dict_colors[painters[-1]][1][0] dict_colors[painters[-1]][1].popleft() dict_colors[painters[-1]][0]-=1 if dict_colors[painters[-1]][0]==0: dict_colors.pop(painters[-1]) else: trash = desired.index(painters[-1]) else: return False for painter in painters: if dict_colors.get(painter,0): res.append(dict_colors[painter][1][0]) dict_colors[painter][1].popleft() dict_colors[painter][0]-=1 if dict_colors[painter][0]==0: dict_colors.pop(painter) else: res.append(trash) return res while t: s = solve() if s: print("YES") print("".join([str(x+1)+" " for x in s])) else: print("NO") t-=1
9
PYTHON3
def solve(l): n = int(input()) #print(l[:n]) if n == 2: print(2) else: #print(l[:n+1]) sum1, sum2 = l[n], 0 for i in range(1, n//2): sum1 += l[i] i = n // 2 while i < n: sum2 += l[i] i += 1 print(abs(sum1 - sum2)) try: l = [] for i in range(0, 31): l.append(2**i) for _ in range(int(input())): solve(l) except: pass
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; struct SegmentTree { int data[maxn << 2], lz[maxn << 2]; int L[maxn << 2], R[maxn << 2]; void build(int l, int r, int k) { L[k] = l; R[k] = r; lz[k] = 0; if (l == r) { return; } int mid = (l + r) >> 1; build(l, mid, k << 1); build(mid + 1, r, k << 1 | 1); } void lzadd(int k, int x) { if (x == 3) lz[k] ^= 3; else lz[k] = x; } void pushdown(int k) { if (lz[k] == 0) return; lzadd(k << 1, lz[k]); lzadd(k << 1 | 1, lz[k]); lz[k] = 0; } void add(int l, int r, int k, int x) { if (L[k] >= l && R[k] <= r) { lzadd(k, x); return; } pushdown(k); int mid = (L[k] + R[k]) >> 1; if (mid >= l) add(l, r, k << 1, x); if (mid < r) add(l, r, k << 1 | 1, x); } long long query(int l, int r, int k) { if (L[k] >= l && R[k] <= r) return lz[k]; pushdown(k); long long ans = 0; int mid = (L[k] + R[k]) >> 1; if (mid >= l) ans = ans + query(l, r, k << 1); if (mid < r) ans = ans + query(l, r, k << 1 | 1); return ans; } } tree; int a[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, q; int up = maxn - 5; cin >> n >> q; for (int i = (1); i <= (int)(n); i++) cin >> a[i]; tree.build(0, up, 1); while (q--) { char c; int x; cin >> c >> x; if (c == '>') { if (x >= 0) { tree.add(x + 1, up, 1, 2); } else { tree.add(-x, up, 1, 2); tree.add(0, -x - 1, 1, 3); } } else { if (x <= 0) { tree.add(-x + 1, up, 1, 1); } else { tree.add(x, up, 1, 1); tree.add(0, x - 1, 1, 3); } } } for (int i = (1); i <= (int)(n); i++) { int ty = tree.query(abs(a[i]), abs(a[i]), 1); if (ty == 0) cout << a[i] << ' '; else if (ty == 1) cout << abs(a[i]) << ' '; else if (ty == 2) cout << -abs(a[i]) << ' '; else cout << -a[i] << ' '; } cout << '\n'; return 0; }
11
CPP
import sys t = int(sys.stdin.readline()) while t: s = sys.stdin.readline() stack = [] count = 0 for e in s: if e=='1': if stack and stack[-1]=='0': stack.pop() count+=1 else: stack.append(e) elif e=='0': if stack and stack[-1]=='1': stack.pop() count+=1 else: stack.append(e) if count%2==0: print("NET") else: print("DA") t-=1
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n, x, k, ans = 0; cin >> n >> k; if (n < 3) { cout << 0; return 0; } for (int i = 0; i < n; ++i) { cin >> x; if (5 - x >= k) ans++; } cout << ans / 3; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; template <ostream& out = cout, class... T> void prints(T&&...) {} template <ostream& out = cout, class... T> void printe(T&&...) {} template <ostream& out = cout, class... T> void printw(T&&...) {} template <ostream& out = cout, class... T> void printew(T&&...) {} template <ostream& out = cout, class... T> void printb(T&&...) {} template <ostream& out = cout, class... T> void printd(T&&...) {} template <ostream& out = cout, class... T> void printde(T&&...){}; template <class T> istream& operator>>(istream& in, vector<T>& v) { for (auto& e : v) { in >> e; } return in; } template <char d = ' ', class T> ostream& operator<<(ostream& out, vector<T>& v) { for (auto& e : v) { out << e << d; } return out; } ifstream fin("input.txt"); ofstream fout("output.txt"); const vector<int> dx{-1, 1, 0, 0}; const vector<int> dy{0, 0, 1, -1}; long long gcd(long long a, long long b) { return a == 0 ? b : gcd(b % a, a); } long long powq(long long x, long long y) { long long q = 1; for (long long i = 1; i <= y; i++) { q *= x; } return q; } int main() { int n, m; cin >> n >> m; vector<int> a(m); cin >> a; vector<int> b(n, 0); for (long long i = 0; i < m; i++) { b[a[i] - 1]++; } int gg = 1e9; for (long long i = 0; i < n; i++) { if (b[i] == 0) { cout << 0 << '\n'; return 0; }; gg = min(gg, b[i]); } cout << gg; return 0; }
7
CPP
#define _USE_MATH_DEFINES #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <cmath> #include <algorithm> #include <vector> #include <queue> #include <map> using namespace std; //typedef pair<long long int, long long int> P; long long int INF = 1e18; long long int MOD = 1e9 + 7; int a[110000]; int main(){ int N; cin >> N; for(int i = 0; i < N; i++){ cin >> a[i]; } map<long long int, long long int> m; int cnt = 0; vector<int> v; for(int i = 0; i < N; i++){ m[a[i]]++; if(m[a[i]] == 0){ cnt++; }else if(m[a[i]] == 1){ cnt--; } m[a[N - i - 1]]--; if(m[a[N - i - 1]] == 0){ cnt++; }else if(m[a[N - i - 1]] == -1){ cnt--; } if(cnt == 0){ v.push_back(i + 1); } } for(int i = 0; i < v.size() - 1; i++){ cout << v[i] << " "; } cout << v[v.size() - 1] << endl; return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; long long bigmod(long long a, long long b, long long M) { if (b == 0) return 1 % M; long long x = bigmod(a, b / 2, M); x = (x * x) % M; if (b % 2 == 1) x = (x * a) % M; return x; } int main() { long long n, m; cin >> n >> m; if (n == 0) cout << "0" << endl; else { n %= 1000000007; long long p = n * bigmod(2, m + 1, 1000000007) - bigmod(2, m, 1000000007) + 1; p %= 1000000007; if (p < 0) { p += 1000000007; } cout << p << endl; } }
9
CPP
""" Author: Sagar Pandey """ # ---------------------------------------------------Import Libraries--------------------------------------------------- import sys import time import os from math import sqrt, log, log2, ceil, log10, gcd, floor, pow, sin, cos, tan, pi, inf, factorial from copy import copy, deepcopy from sys import exit, stdin, stdout from collections import Counter, defaultdict, deque from itertools import permutations import heapq from bisect import bisect_left as bl # If the element is already present in the list, # the left most position where element has to be inserted is returned. from bisect import bisect_right as br from bisect import bisect # If the element is already present in the list, # the right most position where element has to be inserted is r # ---------------------------------------------------Global Variables--------------------------------------------------- # sys.setrecursionlimit(100000000) mod = 1000000007 # ---------------------------------------------------Helper Functions--------------------------------------------------- iinp = lambda: int(sys.stdin.readline()) inp = lambda: sys.stdin.readline().strip() strl = lambda: list(inp().strip().split(" ")) intl = lambda: list(map(int, inp().split(" "))) mint = lambda: map(int, inp().split()) flol = lambda: list(map(float, inp().split(" "))) flush = lambda: stdout.flush() def permute(nums): def fun(arr, nums, cur, v): if len(cur) == len(nums): arr.append(cur.copy()) i = 0 while i < len(nums): if v[i]: i += 1 continue else: cur.append(nums[i]) v[i] = 1 fun(arr, nums, cur, v) cur.pop() v[i] = 0 i += 1 # while i<len(nums) and nums[i]==nums[i-1]:i+=1 # Uncomment for unique permutations return arr res = [] nums.sort() v = [0] * len(nums) return fun(res, nums, [], v) def subsets(res, index, arr, cur): res.append(cur.copy()) for i in range(index, len(arr)): cur.append(arr[i]) subsets(res, i + 1, arr, cur) cur.pop() return res def sieve(N): root = int(sqrt(N)) primes = [1] * (N + 1) primes[0], primes[1] = 0, 0 for i in range(2, root + 1): if primes[i]: for j in range(i * i, N + 1, i): primes[j] = 0 return primes def bs(arr, l, r, x): if x < arr[0] or x > arr[len(arr) - 1]: return -1 while l <= r: mid = l + (r - l) // 2 if arr[mid] == x: return mid elif arr[mid] < x: l = mid + 1 else: r = mid - 1 return -1 def isPrime(n): if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False p = int(sqrt(n)) for i in range(5, p + 1, 6): if n % i == 0 or n % (i + 2) == 0: return False return True # -------------------------------------------------------Functions------------------------------------------------------ def solve(): n,k=mint() arr=[] for i in range(n): arr.append(intl()) arr.sort(key=lambda x:(-x[0],x[1])) d={} i=0 rank=1 # print(arr) while i<n: j=i while j<n and arr[i]==arr[j]: j+=1 d[rank]=j-i t=rank while rank<t+j-i: d[rank]=j-i rank+=1 i=j # print(d) if k not in d.keys(): print(d[k-1]) else: print(d[k]) # -------------------------------------------------------Main Code------------------------------------------------------ start_time = time.time() # for _ in range(iinp()): s=sieve(10**6) solve() # print("--- %s seconds ---" % (time.time() - start_time))
7
PYTHON3
I = lambda: [int(i) for i in input().split()] n,t = I() a = [] a = I() c=0 while c<(t-1): c = c+a[c] if(c>=t): print("NO") else: print("YES")
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n, c = 0, i, ans = 0; scanf("%d", &n); int a[n]; for (i = 0; i < n; i++) { scanf("%d", &a[i]); } for (i = 0; i < n; i++) { if (i == 0) { if (a[1] == 2) { c++; } } else if (i == n - 1 && a[n - 2] == 999) { c++; } else if (a[i] == a[i - 1] + 1 && a[i] == a[i + 1] - 1 && i != n - 1) { c++; } else { ans = max(ans, c); c = 0; } } ans = max(ans, c); cout << ans; }
7
CPP
n,m=map(int,input().split()) b=list(map(int,input().split())) g=list(map(int,input().split())) if(min(g)<max(b)): print(-1) exit(0) from collections import * from heapq import * ans=[] al=defaultdict(int) for i in range(len(g)): heappush(ans,-g[i]) al[g[i]]+=1 total=sum(b)*len(g) b.sort(reverse=True) cnt=0 index=0 while(len(ans)): while(len(ans) and al[abs(ans[0])]==0): heappop(ans) if(len(ans)==0): break; if(cnt==len(g)-1): if(al[b[index]]>0): al[b[index]]-=1 cnt=0 index+=1 continue; total-=b[index] total+=abs(ans[0]) al[abs(ans[0])]-=1 heappop(ans) cnt+=1 print(total)
9
PYTHON3
#include <bits/stdc++.h> using namespace std; long long int dp[4011][4011]; long long int b[2000000]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n; cin >> n; long long int a[n]; set<long long int> st; for (int i = 0; i < n; i++) { cin >> a[i]; st.insert(a[i]); } long long int k = 0; for (auto u : st) { b[u] = k; k++; } for (int i = 0; i < n; i++) { a[i] = b[a[i]]; } for (int i = 0; i < n; i++) { long long int f = 0; for (int j = i - 1; j >= 0; j--) { if (a[i] == a[j]) { if (f == 1) continue; f = 1; dp[a[i]][a[j]]++; } else { dp[a[i]][a[j]] = max(dp[a[i]][a[j]], 1 + dp[a[j]][a[i]]); } } } long long int ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) ans = max(ans, dp[i][j]); } cout << ans + 1; }
7
CPP
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; void solve() { int n; string s; cin >> n >> s; vector<int> last[2]; vector<int> ans(n); int now = 0; for (int i = 0; i < n; i++) { int cur = s[i] - '0'; if (last[cur ^ 1].empty()) { ans[i] = ++now; } else { ans[i] = last[cur ^ 1].back(); last[cur ^ 1].pop_back(); } last[cur].emplace_back(ans[i]); } cout << now << '\n'; for (int i = 0; i < n; i++) { cout << ans[i] << ' '; } cout << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int TC = 1; cin >> TC; for (int i = 1; i <= TC; i++) { solve(); } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; long long l[100005], le[100005]; vector<int> Div[100005]; long long tedad[100005], contain[100005]; long long t(long long a, int b) { if (b == 0) return 1; long long ans = t(a, b / 2); ans = (ans * ans) % 1000000007; if (b % 2 == 1) ans = (ans * a) % 1000000007; return ans; } int main() { int n; cin >> n; int a; int Max = 0; for (int i = 0; i < n; i++) { cin >> a; Max = max(Max, a); tedad[a]++; } contain[100000] = tedad[100000]; for (int i = 99999; i >= 1; i--) contain[i] = contain[i + 1] + tedad[i]; for (int i = 1; i <= 100000; i++) { le[i] = l[i] = 1; for (int j = 1; i * j <= 100000; j++) Div[i * j].push_back(i); } long long ans = 0; for (int i = 2; i <= Max; i++) { for (int j = 0; j < Div[i].size(); j++) { if (j < Div[i].size() - 1) { le[i] *= t(j + 1, contain[Div[i][j]] - contain[Div[i][j + 1]]); le[i] %= 1000000007; if (j + 1 == Div[i].size() - 1) l[i] *= t(j + 1, contain[Div[i][j]]); else l[i] *= t(j + 1, contain[Div[i][j]] - contain[Div[i][j + 1]]); l[i] %= 1000000007; } else { le[i] *= t(j + 1, contain[Div[i][j]]); le[i] %= 1000000007; } } ans = (ans + le[i] - l[i]); while (ans < 0) ans += 1000000007; ans %= 1000000007; } cout << ans + 1 << endl; return 0; }
11
CPP
#include<iostream> #include<algorithm> #define int long long using namespace std; int n, a[1010], q, b, e, k; signed main() { cin >> n; for (int i = 0; i < n; i++)cin >> a[i]; cin >> q; for (int i = 0; i < q; i++) { cin >> k >> b >> e; int ans = a[b]; for (int j = b + 1; j < e; j++)if (!k)ans = min(ans, a[j]); else ans = max(ans, a[j]); cout << ans << endl; } }
0
CPP
#include <bits/stdc++.h> using namespace std; using ll = long long; const int maxn=1e5+5; const int N = 1e3+5; int n,d,a[maxn]; double lg[N],nw[11],go[11]; pair<int,int>to[maxn][11]; double dp[maxn][11]; int main(){ ios::sync_with_stdio(false); cin.tie(0); for(int i = 1;i <= 1000;i++) lg[i] = log10(i); cin >> n >> d; for(int i = 0;i <= n;i++) for(int j = 0;j < 10;j++) dp[i][j] = -1; for(int i = 1;i <= n;i++){ int x; cin >> x; a[i] = x; for(int j = 0;j < 10;j++) nw[j] = go[j] = -1; nw[x % 10] = lg[x]; for(int j = 0;j < 10;j++){ if(dp[i-1][j] == -1) continue; int now = (j * x) % 10; if(dp[i-1][j] + lg[x] > nw[now]){ nw[now] = dp[i-1][j] + lg[x]; go[now] = j; } } for(int j = 0;j < 10;j++){ dp[i][j] = dp[i-1][j]; to[i][j] = {0,j}; if(nw[j] > dp[i][j]){ dp[i][j] = nw[j]; to[i][j] = {1,go[j]}; } } } // cout<<dp[n][d]<<'\n'; if(dp[n][d] == -1) return cout<<-1,0; vector<int>ans; for(int i = n;i >= 1;i--){ if(d == -1) break; if(to[i][d].first == 1) ans.push_back(a[i]); d = to[i][d].second; } cout<<(int)ans.size()<<'\n'; for(auto i : ans) cout<<i<<' '; }
10
CPP
""" Author : co_devil Chirag Garg Institute : JIIT """ from __future__ import division, print_function from sys import stdin, stdout import itertools, os, sys, threading from collections import deque, Counter, OrderedDict, defaultdict import heapq from math import ceil, floor, log, sqrt, factorial, pow, pi, gcd # from bisect import bisect_left,bisect_right # from decimal import *,threading from fractions import Fraction """from io import BytesIO, IOBase if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip else: from builtins import str as __str__ str = lambda x=b'': x if type(x) is bytes else __str__(x).encode() BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._buffer = BytesIO() self._fd = file.fileno() 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): return self._buffer.read() if self._buffer.tell() else os.read(self._fd, os.fstat(self._fd).st_size) def readline(self): while self.newlines == 0: b, ptr = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)), self._buffer.tell() self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr) self.newlines += b.count(b'\n') + (not b) 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) sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout) input = lambda: sys.stdin.readline().rstrip(b'\r\n') def print(*args, **kwargs): sep, file = kwargs.pop('sep', b' '), kwargs.pop('file', sys.stdout) at_start = True for x in args: if not at_start: file.write(sep) file.write(str(x)) at_start = False file.write(kwargs.pop('end', b'\n')) if kwargs.pop('flush', False): file.flush() """ def ii(): return int(input()) def si(): return str(input()) def mi(): return map(int, input().split()) def li(): return list(mi()) def fii(): return int(stdin.readline()) def fsi(): return str(stdin.readline()) def fmi(): return map(int, stdin.readline().split()) def fli(): return list(fmi()) abc = 'abcdefghijklmnopqrstuvwxyz' abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25} mod = 1000000007 dx, dy = [-1, 1, 0, 0], [0, 0, 1, -1] def getKey(item): return item[0] def sort2(l): return sorted(l, key=getKey) def d2(n, m, num): return [[num for x in range(m)] for y in range(n)] def isPowerOfTwo(x): return (x and (not (x & (x - 1)))) def decimalToBinary(n): return bin(n).replace("0b", "") def ntl(n): return [int(i) for i in str(n)] def powerMod(x, y, p): res = 1 x %= p while y > 0: if y & 1: res = (res * x) % p y = y >> 1 x = (x * x) % p return res def gcd(x, y): while y: x, y = y, x % y return x # For getting input from input.txt file # sys.stdin = open('input.txt', 'r') # Printing the Output to output.txt file # sys.stdout = open('output.txt', 'w') graph = defaultdict(list) visited = [0] * 1000000 col = [-1] * 1000000 def dfs(v, c): if visited[v]: if col[v] != c: print('-1') exit() return col[v] = c visited[v] = 1 for i in graph[v]: dfs(i, c ^ 1) def bfs(d, v): q = [] q.append(v) visited[v] = 1 while len(q) != 0: x = q[0] q.pop(0) for i in d[x]: if visited[i] != 1: visited[i] = 1 q.append(i) print(x) def make_graph(e): d = defaultdict(list) for i in range(e): x, y = mi() d[x].append(y) d[y].append(x) return d def gr2(n): d = defaultdict(list) for i in range(n): x, y = mi() d[x].append(y) return d def connected_components(graph): seen = set() def dfs(v): vs = set([v]) component = [] while vs: v = vs.pop() seen.add(v) vs |= set(graph[v]) - seen component.append(v) return component ans = [] for v in graph: if v not in seen: d = dfs(v) ans.append(d) return ans def primeFactors(n): s = set() while n % 2 == 0: s.add(2) n = n // 2 for i in range(3, int(sqrt(n)) + 1, 2): while n % i == 0: s.add(i) n = n // i if n > 2: s.add(n) return s def find_all(a_str, sub): start = 0 while True: start = a_str.find(sub, start) if start == -1: return yield start start += len(sub) def Prime(x): if x<2: return False for i in range(2,int(sqrt(x))+1): if x%i==0: return False return True if __name__ == '__main__': n=ii() l=li() k = int(1e6 + 2) sieve = [True] * k sieve[1] = sieve[0] = False for i in range(2, k): if sieve[i] == True: for j in range(i * i, k, i): sieve[j] = False for i in l: if int(i ** 0.5) == i ** 0.5 and sieve[int(i ** 0.5)] == True: print('YES') else: print('NO')
8
PYTHON3