solution
stringlengths
10
983k
difficulty
int64
0
25
language
stringclasses
2 values
#include <bits/stdc++.h> using namespace std; const int maxn = 300000 + 5; int d[maxn], n, m; int to[maxn * 2], head[maxn], nex[maxn * 2], tol; void insert(int u, int v) { ++tol, to[tol] = v, nex[tol] = head[u], head[u] = tol; ++tol, to[tol] = u, nex[tol] = head[v], head[v] = tol; } int p, ans[maxn * 2], vis[maxn], cnt; int dfs(int u) { vis[u] = 1; for (int i = head[u]; i; i = nex[i]) { if (!vis[to[i]]) { if (dfs(to[i])) { ans[i] = 1; cnt++; if (d[u] != 2) { d[u] ^= 1; } } } } return d[u]; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 1, x; i <= n; i++) { cin >> x; if (x == -1) p = i; if (x == -1) d[i] = 2; else d[i] = x; } for (int i = 1, u, v; i <= m; i++) { cin >> u >> v; insert(u, v); } if (p) dfs(p); else if (dfs(1) & 1) { cout << -1 << "\n"; return 0; } cout << cnt << "\n"; for (int i = 1; i <= tol; i += 2) if (ans[i] || ans[i + 1]) cout << (i + 1) / 2 << ' '; }
8
CPP
#include <bits/stdc++.h> using namespace std; vector<long long> v; set<long long> ss; int n, cur = 0; int main() { ios_base::sync_with_stdio(false); cin >> n; n *= 2; string s; long long k, ans = 0, i; bool lst = 0, need = 0; while (n--) { cin >> s; if (s[0] == 'a') { cin >> k; v.push_back(k); } else { cur++; if (!v.empty() && cur != v.back()) { ans++; while (v.size()) { ss.insert(v.back()); v.pop_back(); } ss.erase(ss.begin()); } else { if (v.size()) v.pop_back(); else ss.erase(ss.begin()); } } } cout << ans << endl; return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; int MOD = 1000000007; int x[104]; int y[104]; int v[104] = {0}; int n; void dfs(int j) { v[j] = true; for (int i = 0; i < n; i++) { if ((!v[i]) && (x[i] == x[j] || y[i] == y[j])) { dfs(i); } } } int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; } int ans = 0; for (int i = 0; i < n; i++) { if (!v[i]) { dfs(i); ans++; } } cout << ans - 1; return 0; }
7
CPP
x, y = input().split() keypad = list(map(int, input().split())) prints = list(map(int, input().split())) result = [] for i in keypad: if i in prints: result.append(i) for j in result: print(j, end=' ')
7
PYTHON3
#include <bits/stdc++.h> #define int long long #define N 11 using namespace std; const int INF = 1LL<<55; const int mod = (1e9)+7; const double EPS = 1e-8; const double PI = 6.0 * asin(0.5); template<class T> T Max(T &a,T b){return a=max(a,b);} template<class T> T Min(T &a,T b){return a=min(a,b);} struct dat{ int x,y,X,Y; bool contain(dat b){return (x<=b.x && b.X<=X) && (y<=b.y && b.Y<=Y);} }; int h,w; vector<dat> A; typedef vector<vector<int> > V; int count(const V &mp,dat a){ int cnt = 0; for(int i=a.y;i<=a.Y;i++) cnt += count(mp[i].begin()+a.x,mp[i].begin()+a.X+1,1); return cnt; } bool contain0(V &mp,int x,int y,int X,int Y){return count(mp,(dat){x,y,X,Y}) == (X-x+1)*(Y-y+1);} struct dat2{ V mp; int cnt,cost; }; dat2 getNx(dat2 t,dat a){ t.cost++; for(int i=a.y;i<=a.Y;i++) for(int j=a.x;j<=a.X;j++){ t.cnt -= t.mp[i][j]; t.mp[i][j] = 0; } return t; } dat2 erase(dat2 t){ int update = 1; while(update--){ for(int i=0;i<h;i++) for(int j=0;j<w;j++){ if(t.mp[i][j] == 0)continue; int cnt = 0; dat tmp; for(dat a:A) if(a.contain((dat){j,i,j,i})) cnt++, tmp = a; if(cnt == 1) t = getNx(t,tmp),update = 1; } } return t; } typedef pair<int,int> P; set<P> getErased(const V &mp,const dat &a){ set<P> res; for(int i=a.y;i<=a.Y;i++) for(int j=a.x;j<=a.X;j++) if(mp[i][j]) res.insert(P(i,j)); return res; } int bfs(V start){ queue<dat2> Q; set<V> used; Q.push((dat2){start,count(start,(dat){0,0,w-1,h-1}),0}); while(1){ dat2 t = erase(Q.front());Q.pop(); if(t.cnt == 0) return t.cost; if(used.count(t.mp))continue; used.insert(t.mp); dat nx; for(dat a:A) if(count(t.mp,a)) nx = a; set<P> S = getErased(t.mp,nx); for(dat a:A){ set<P> s = getErased(t.mp,a); int cnt = 0; for(P p:s) cnt += S.count(p); if(cnt) Q.push(getNx(t,a)); } } } signed main(){ while(1){ cin>>w>>h; if(w == 0 && h == 0)break; V mp = V(h,vector<int>(w)); for(int i=0;i<h;i++) for(int j=0;j<w;j++) cin>>mp[i][j]; A.clear(); for(int y=0;y<h;y++) for(int x=0;x<w;x++){ dat a = (dat){-1,-1,-1,-1}; for(int Y=y, X=x; Y<h && X<w ;Y++, X++) if(contain0(mp,x,y,X,Y)) a = (dat){x,y,X,Y}; if(a.x != -1) A.push_back(a); } for(int i=0;i<(int)A.size();i++) for(int j=0;j<(int)A.size();j++) if(i!=j && A[i].contain(A[j]))A.erase(A.begin()+j--); cout<<bfs(mp)<<endl; } return 0; }
0
CPP
t = int(input()) for i in range(t): n,m = map(int,input().split()) if n <= 2 and m <= 2:print('YES') elif n == 1 or m == 1:print('YES') else:print('NO')
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int n; int a[120013]; int b[120013]; int c[120013]; bool done[120013]; int num[30013]; vector<int> rules; void upd(int i, int d) { num[a[i]] -= d; num[b[i]] += d; num[c[i]] += d; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) num[i] = 4; for (int i = 1; i <= 4 * n; i++) scanf("%d%d%d", &a[i], &b[i], &c[i]); while (rules.size() < 4 * n) { bool ok = 0; for (int j = 1; j <= 4 * n; j++) { if (done[j]) continue; upd(j, 1); if (num[b[j]] <= 9 && num[c[j]] <= 9) rules.push_back(j), ok = 1, done[j] = 1; else upd(j, -1); } if (!ok) return printf("NO\n"), 0; } printf("YES\n"); for (int i : rules) printf("%d ", i); printf("\n"); return 0; }
8
CPP
# Ilya and Bank Account x=input() c=[] c1=[] re="" re1="" if int(x) == 0 or int(x) > 0: print (x) else : for i in range(1,len(x)): c.append(x[i]) c1.append(x[i]) del c[-1] for i in c: re=re+(i) del c1[-2] for i in c1: re1=re1+(i) p=(int(re)) p1=(int(re1)) if p > p1 : if re1 == "0" : print("0") else : print("-"+re1) else: if re == "0": print("0") else : print("-"+re)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const double INF = 100000000000; int main(){ int n; cin >> n; double r, t; cin >> r >> t; t = (180 - t) / 180 * PI; vector<int> x(n), y(n); for (int i = 0; i < n; i++){ cin >> x[i] >> y[i]; } vector<vector<double>> d(n, vector<double>(n, INF)); for (int i = 0; i < n; i++){ for (int j = 0; j < n; j++){ if (i != j){ d[i][j] = sqrt(pow(x[j] - x[i], 2) + pow(y[j] - y[i], 2)); } } } vector<vector<vector<bool>>> ok(n, vector<vector<bool>>(n, vector<bool>(n, false))); for (int i = 0; i < n; i++){ for (int j = 0; j < n; j++){ for (int k = 0; k < n; k++){ if (i != j && j != k && k != i){ if (pow(d[i][k], 2) > pow(d[i][j], 2) + pow(d[j][k], 2) - 2 * d[i][j] * d[j][k] * cos(t)){ ok[i][j][k] = true; } } } } } vector<vector<vector<double>>> dp(10000, vector<vector<double>>(n, vector<double>(n, INF))); for (int i = 1; i < n; i++){ dp[1][0][i] = d[0][i]; } for (int i = 2; i < 10000; i++){ for (int j = 0; j < n; j++){ for (int k = 0; k < n; k++){ for (int l = 0; l < n; l++){ if (ok[j][k][l]){ dp[i][k][l] = min(dp[i][k][l], dp[i - 1][j][k] + d[k][l]); } } } } } int ans = 0; for (int i = 0; i < 10000; i++){ for (int j = 0; j < n; j++){ for (int k = 0; k < n; k++){ if (dp[i][j][k] <= r){ ans = i; } } } } cout << ans << endl; }
0
CPP
#include <bits/stdc++.h> using namespace std; int a[500], b[500]; int main() { int n, v; int sum = 0; scanf("%d %d", &n, &v); for (int i = 0; i < n; i++) scanf("%d", &a[i]), sum += a[i]; for (int i = 0; i < n; i++) scanf("%d", &b[i]); double x = 1e10; for (int i = 0; i < n; i++) x = min(x, b[i] / (double)a[i]); printf("%.6lf\n", min((double)v, x * sum)); return 0; }
7
CPP
def main(): while True: n = int(input()) if not n: break ps = [list(map(int,input().split())) for i in range(n)] dic = set() for t in ps: dic.add((t[0],t[1])) ans = 0 for i in range(n): for j in range(n): p1 = ps[i] p2 = ps[j] p1x = p1[0] p1y = p1[1] p2x = p2[0] p2y = p2[1] vx = p2x - p1x vy = p2y - p1y if (p1x + vy, p1y - vx) in dic and (p2x + vy, p2y - vx) in dic: ans = max(ans, vx ** 2 + vy ** 2) print(ans) main()
0
PYTHON3
def getLines(num): inputLines = [] for i in range(0,num): line = input() if line: inputLines.append(line) else: break return inputLines def notZeroPow(num,p): return True if num >= 1 and num <= pow(10,p) else False lines = getLines(2) w = lines[1] s = lines[0] wt = s[::-1] print("YES" if wt == w else "NO")
7
PYTHON3
paper=[] for i in range(4): paper.append(input()) flag=True for i in range(3): for j in range(3): square=paper[i][j]+paper[i][j+1]+paper[i+1][j]+paper[i+1][j+1] if square.count('#') in [0,1,3,4]: flag=False print('YES') break if not flag: break if flag: print('NO')
7
PYTHON3
#include<stdio.h> int main(void){ char s[100]; scanf("%s",s); s[5]=' '; s[13]=' '; printf("%s",s); }
0
CPP
#include <bits/stdc++.h> int x[4]; int l[4]; int t[4]; int ans = 0; int w[4]; int p[4]; int a[4] = {3, 3, 3, 3}; int near(int s) { int i = 1; for (; i <= 3; i++) { if (s == x[i] + 1 || s == x[i] - 1) { return 1; } } return 0; } void dfs(int d) { int i = 1, j = 1, e = 0; for (; i <= 3; i++) { ans = ans > x[i] ? ans : x[i]; } for (i = 1; i <= 3; i++) { if (w[i]) { continue; } if ((a[i] & 1) && !(a[i] & 4)) { for (j = 1; j <= l[i]; j++) { x[i] += j; a[i] ^= 1; if (near(x[i]) || j == l[i]) { dfs(d + 1); } x[i] -= j; x[i] -= j; if (near(x[i]) || j == l[i]) { dfs(d + 1); } x[i] += j; a[i] ^= 1; } } if (a[i] & 2) { for (j = 1; j <= 3; j++) { if (i != j && !w[j] && t[i] > 0) { if (x[i] == x[j] + 1 || x[j] == x[i] + 1) { w[j] = 1; a[i] ^= 2; a[i] ^= 4; p[i] = j; e = x[j]; x[j] = -j; dfs(d + 1); x[j] = e; w[j] = 0; a[i] ^= 2; a[i] ^= 4; } } } } if (a[i] & 4) { for (j = 1; j <= t[i]; j++) { w[p[i]] = 0; a[i] ^= 4; e = x[p[i]]; x[p[i]] = x[i] + j; if (near(x[p[i]]) || j == t[i]) { dfs(d + 1); } x[p[i]] -= j; x[p[i]] -= j; if (near(x[p[i]]) || j == t[i]) { dfs(d + 1); } x[p[i]] = e; a[i] ^= 4; w[p[i]] = 1; } } } return; } int main() { int i = 1; for (; i <= 3; i++) { scanf("%d %d %d", &x[i], &l[i], &t[i]); } dfs(1); printf("%d\n", ans); return 0; }
11
CPP
letters_input = input().strip("{}").split(',') letters = len(set(letter.strip() for letter in letters_input if len(letter) > 0)) print(letters)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const int W = 100000; const int H = 100; double hl, hr; int n; vector<pair<int, pair<double, double> > > fl, ce; bool vis[2][102]; bool between(double l, double r, double x) { return x > l - eps && x < r + eps; } int main() { ios::sync_with_stdio(false); cin >> hl >> hr >> n; for (int i = 0; i < n; ++i) { int score; double l, r; char ch[3]; cin >> score >> ch >> l >> r; if (ch[0] == 'T') ce.push_back(make_pair(score, make_pair(l, r))); else fl.push_back(make_pair(score, make_pair(l, r))); } int mmax = 0; for (int i = 0; i < n; ++i) { double h = i * H + hl; if (i & 1) h = h + H - hr; else h += hr; memset(vis, 0, sizeof(vis)); int cnt = 0; for (int j = 0; j <= i; ++j) { double x = W / h * (hl + j * H); bool flag = false; if (!(j & 1)) { for (int k = 0; k < (int)fl.size(); ++k) { if (!vis[0][k] && between(fl[k].second.first, fl[k].second.second, x)) { vis[0][k] = true; flag = true; cnt += fl[k].first; break; } } } else { for (int k = 0; k < (int)ce.size(); ++k) { if (!vis[1][k] && between(ce[k].second.first, ce[k].second.second, x)) { vis[1][k] = true; cnt += ce[k].first; flag = true; break; } } } if (flag == false) { cnt = 0; break; } } mmax = max(cnt, mmax); } hr = H - hr; hl = H - hl; for (int i = 0; i < n; ++i) { double h = i * H + hl; if (i & 1) h = h + H - hr; else h += hr; memset(vis, 0, sizeof(vis)); int cnt = 0; for (int j = 0; j <= i; ++j) { double x = W / h * (hl + j * H); bool flag = false; if (j & 1) { for (int k = 0; k < (int)fl.size(); ++k) { if (!vis[0][k] && between(fl[k].second.first, fl[k].second.second, x)) { vis[0][k] = true; flag = true; cnt += fl[k].first; break; } } } else { for (int k = 0; k < (int)ce.size(); ++k) { if (!vis[1][k] && between(ce[k].second.first, ce[k].second.second, x)) { vis[1][k] = true; cnt += ce[k].first; flag = true; break; } } } if (flag == false) { cnt = 0; break; } } mmax = max(cnt, mmax); } cout << mmax << endl; return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ; int n; cin >> n; long long ans = 0, last = 0; for (long long(i) = (0); (i) < (n); (i)++) { long long x; cin >> x; if (i == 0) ans += llabs(x); else ans += llabs(x - last); last = x; } cout << ans << endl; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7, A = 1e3 + 5; bool vis[105]; vector<vector<long long>> v; void dfs(long long node) { for (auto to : v[node]) if (!vis[to]) vis[to] = 1, dfs(to); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n; cin >> n; vector<pair<long long, long long>> a; map<long long, set<long long>> mop; for (int i = 0; i < n; i++) { long long op, l, r; cin >> op >> l >> r; if (op == 1) a.push_back({l, r}); else { v.resize(a.size() + 1); for (int i = 0; i < a.size(); i++) { for (int j = 0; j < a.size(); j++) { if ((a[i].first > a[j].first && a[i].first < a[j].second) || (a[i].second > a[j].first && a[i].second < a[j].second)) v[i + 1].push_back(j + 1); } } vis[l] = 1, dfs(l); vis[r] ? cout << "YES\n" : cout << "NO\n"; memset(vis, 0, sizeof vis), v.clear(); } } return 0; }
11
CPP
n,m = map(int,input().split()) if n%2 == 0: a = n//2 else: a = (n//2)+1 if m<=a: print(2*m-1) else: print(2*(m-a))
7
PYTHON3
lineNumbers = input() myList = [] for i in range(0, int(lineNumbers)): myList.append(input()) for word in myList: if (len(word) < 11): print(word) else: print(word[0] + str(len(word) - 2) + word[len(word) - 1])
7
PYTHON3
#include <bits/stdc++.h> using namespace std; vector<int> arr; int ans[26]; int memo[26][100005]; bool find(int pos, int left) { if (pos >= 26) { if (left == 0) return true; else return false; } int &ret = memo[pos][left]; if (ret == -1) { memo[pos][left] = 0; for (int i = 0; i < (int)arr.size(); i++) { if (left - arr[i] < 0) break; if (find(pos + 1, left - arr[i])) { memo[pos][left] = 1; ans[pos] = i; break; } } } return memo[pos][left]; } void init() { memset(memo, -1, sizeof memo); int now = 0; int sum = 0; while (sum <= 100000) { arr.push_back(sum); now++; sum += now; } } int main() { init(); int k; scanf("%d", &k); find(0, k); for (int i = 0; i < 26; i++) { for (int j = 0; j < ans[i] + 1; j++) { printf("%c", 'a' + i); } } printf("\n"); }
9
CPP
n, k = map(int, input().split()) a = [] for i in range(1, min(int(n ** 0.5) + 1, k)): if n % i == 0: a.append((i, n // i)) ans = int(1e10) for i in range(len(a)): if a[i][0] * k + a[i][1] < ans and a[i][1] < k: ans = a[i][0] * k + a[i][1] if a[i][1] * k + a[i][0] < ans and a[i][0] < k: ans = a[i][1] * k + a[i][0] print(ans)
8
PYTHON3
#include <bits/stdc++.h> using namespace std; using namespace std; int main() { int n; cin >> n; cout << (n + 1) / 2 << "\n"; }
7
CPP
a=int(input()) z=list(map(int,input().split())) z=z[::-1] l=0 r=0 count=0 while(l<=r and r<len(z)): if(l==r): if(r+z[l]+1<len(z)): count+=z[l] r+=z[l]+1 else: count+=len(z)-r-1 r=len(z) l+=1 else: if(z[l]<r-l): l+=1 else: if(r+(z[l]-(r-l-1))<len(z)): count+=z[l]-(r-l-1) r+=z[l]-(r-l-1) else: count+=len(z)-r r=len(z) l+=1 print(len(z)-count)
8
PYTHON3
#include <bits/stdc++.h> std::mt19937 rng( (int)std::chrono::steady_clock::now().time_since_epoch().count()); using namespace std; long long mod = (1000000007LL); inline long long Mod(long long a, long long b) { return (a % b); } inline long long poww(long long a, long long b) { long long res = 1; while (b > 0) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; } long long gcd(long long a, long long b) { while (b) { a %= b, swap(a, b); } return a; } void read(vector<int> &w, int n) { w.resize(n); for (int i = 0; i < n; i++) cin >> w[i]; } void print(vector<int> &w) { for (int i = 0; i < (int)(w).size(); i++) { if (i == (int)(w).size() - 1) cout << w[i] << "\n"; else cout << w[i] << " "; } } int prodmod(vector<int> w); int summod(vector<int> w); int n, l, m, q, k, v[300050], ans, p[300050]; pair<int, int> w[300050]; string second; bool vis[220][220][220]; double dp[220][220][220]; double solve(int i, int j, int z) { z = min(z, 210); if (i > n) { if (j >= l and z >= 0) return 1.0; return 0.0; } if (vis[i][j][z]) return dp[i][j][z]; vis[i][j][z] = 1; double p1 = (1.0 * p[i] / 100.0) * solve(i + 1, j + 1, z + v[i]); double p2 = (1.0 - 1.0 * p[i] / 100.0) * solve(i + 1, j, z); return dp[i][j][z] = p1 + p2; } int32_t main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> l >> k; for (int i = (1); i < (n + 1); ++i) cin >> p[i]; for (int i = (1); i < (n + 1); ++i) cin >> v[i]; cout << setprecision(10) << fixed; cout << solve(1, 0, k) << "\n"; } int summod(vector<int> w) { int curr = 0; for (int i = 0; i < (int)(w).size(); i++) { curr = (curr + w[i]) % mod; if (curr < 0) curr += mod; } return curr; } int prodmod(vector<int> w) { int curr = 1; for (int i = 0; i < (int)(w).size(); i++) { if (w[i] >= mod) w[i] %= mod; curr = (curr * w[i]) % mod; if (curr < 0) curr += mod; } return curr; }
8
CPP
coins = [int(a) for a in input().strip().split()] if sum(coins) == 0: print(-1) else: ave = sum(coins) / len(coins) if ave % 1 == 0: print(int(ave)) else: print(-1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int p[256], o = 248, x; int main() { string a; cin >> a; for (int i = 0; a[i]; i++) p[a[i]]++; while (o != 10) { if (!p[o]) { o--; continue; } else if (a[x] == o) cout << a[x]; p[a[x]]--; x++; } }
7
CPP
#include<bits/stdc++.h> using namespace std; const int N=200005; int x,y,n,Max[N],Max2[N],l[N],z[N]; vector<int>G[N]; char s[N]; long long ans; inline void upd(int x,int y){ if (y>Max[x])Max2[x]=Max[x],Max[x]=y; else if (y>Max2[x])Max2[x]=y; } inline void dfs1(int x,int y){ l[x]=N; if (s[x]=='1')l[x]=0,z[x]=1; for (int i:G[x]) if (i!=y){ dfs1(i,x); int d=Max[i]+1; upd(x,d); if (z[i]){ l[x]=min(l[x],d); z[x]+=z[i]; } } } inline void dfs2(int x,int y){ if (y){ int d=Max[x]+1==Max[y]?Max2[y]+1:Max[y]+1; upd(x,d); if (z[1]>z[x])l[x]=min(l[x],d); } for (int i:G[x]) if (i!=y)dfs2(i,x); int L=l[x],R=min(Max2[x]+1,Max[x]-1); if (L<=R)ans+=R-L+1; } int main(){ scanf("%d",&n); for (int i=1;i<n;i++){ scanf("%d%d",&x,&y); G[x].push_back(y); G[y].push_back(x); } scanf("%s",s+1); dfs1(1,0); dfs2(1,0); printf("%lld\n",ans+1); return 0; }
0
CPP
#include <cstdio> using namespace std; int main(){ while(true){ int n; scanf("%d", &n); if(n == 0){ break; } int lnum = 0, lok = 0; int dnum = 0, dok = 0; int mnum = 0, mok = 0; for(int i = 0; i < n; ++i){ int h, m, a; scanf("%d:%d %d", &h, &m, &a); int ok = 0; if(a - m >= 0 && a - m <= 8){ ok = 1; }else if(a < m && 60 - m + a <= 8){ ok = 1; } if(11 <= h && h < 15){ ++lnum; lok += ok; }else if(18 <= h && h < 21){ ++dnum; dok += ok; }else if((21 <= h && h < 24) || (0 <= h && h < 2)){ ++mnum; mok += ok; } } if(lnum){ printf("lunch %d\n", lok * 100 / lnum); }else{ printf("lunch no guest\n"); } if(dnum){ printf("dinner %d\n", dok * 100 / dnum); }else{ printf("dinner no guest\n"); } if(mnum){ printf("midnight %d\n", mok * 100 / mnum); }else{ printf("midnight no guest\n"); } } return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; int main() { long long n, m, k; cin >> n >> m >> k; if (k > n) { long long ans = 1; for (int i = 1; i <= n; i++) ans = ans * m % mod; cout << ans << endl; return 0; } if (k == n) { long long d = (n + 1) / 2; long long ans = 1; for (int i = 1; i <= d; i++) ans = ans * m % mod; cout << ans << endl; return 0; } if (k % 2 == 0) { cout << m << endl; return 0; } if (k == 1) { long long ans = 1; for (int i = 1; i <= n; i++) ans = ans * m % mod; cout << ans << endl; return 0; } if (k >= 3) { long long ans = m * m; cout << ans << endl; return 0; } return 0; }
8
CPP
x,y=map(int,input().split()) a=input().split() s=[int(num)for num in a] q=[] s.append(0) s.append(y) w=x+2 e=0 while not w==0: a=min(s) b=s.count(a) for i in range(0,b): q.append(a) s.remove(a) w-=1 for i in range(0,x+1): if i==0 or i==len(q)-2: if q[i+1]-q[i]>e: e=q[i+1]-q[i] if (q[i+1]-q[i])/2>e: e=(q[i+1]-q[i])/2 print(e)
8
PYTHON3
N = int(input()) nums = [int(i) for i in input().split(' ')] from collections import defaultdict def helper(nums): tot, carry = 0, 0 for i in range(len(nums)): v = min(nums[i]//2, carry) tot += v carry -= v nums[i] -= 2 * v tot += nums[i] // 3 nums[i] %= 3 carry += nums[i] print(tot) helper(nums)
11
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { unordered_set<string> bad; for (int L = 3; L <= 8; L++) { for (int i = 0; i < (1 << L); i++) { int c = i; string v; for (int j = 0; j < L; j++) { if (c % 2) v += '1'; else v += '0'; c /= 2; } bool hast = false; for (int x = 0; x < L; x++) for (int k = 1; !hast && x + 2 * k < L; k++) if (v[x] == v[x + k] && v[x] == v[x + 2 * k]) { hast = true; break; } if (!hast) { bad.insert(v); } } } long long res = 0; string s; cin >> s; int n = s.length(); for (int l = 0; l < n; l++) { for (int t = 3; l + t - 1 < n && t <= 8; t++) { if (bad.find(s.substr(l, t)) == bad.end()) { res++; } } res += max(0LL, (long long)n - (l + 8)); } cout << res << endl; return 0; }
8
CPP
from collections import deque N, M = map(int, input().split()) AB =[[] for i in range(N)] for i in range(M): A, B =map(int, input().split()) AB[A-1].append(B) AB[B-1].append(A) print("Yes") D = deque([1]) ans = [0]* N ans[0] = -1 for i in range(N-1): C = D.popleft() for j in AB[C-1]: if ans[j-1] == 0: ans[j-1] = C D.append(j) for i in range(1,N): print(ans[i])
0
PYTHON3
#include <iostream> #include <algorithm> using namespace std; int H, W, d[13][13], x; int main() { cin >> H >> W; for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { cin >> d[i][j]; } } for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { for (int k = 0; k < 10; k++) { d[j][k] = min(d[j][k], d[j][i] + d[i][k]); } } } int ret = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { cin >> x; if (x != -1) ret += d[x][1]; } } cout << ret << endl; return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k, r, c; const int INF = 1000005; scanf("%d%d%d", &n, &m, &k); int V[1005]; vector<pair<int, int> > v; long long ans = 0, s = 0; for (int i = 0; i <= m; i++) V[i] = INF; for (int i = 0; i < n; i++) { scanf("%d%d", &r, &c); V[r] = min(V[r], c); } for (int i = 1; i <= m; i++) { if (V[i] == INF) v.push_back(pair<int, int>(0, i)); else v.push_back(pair<int, int>(V[i], i)); } sort(v.begin(), v.end()); reverse(v.begin(), v.end()); int flag = 0; for (int i = 0; i < m; i++) { if (s + v[i].first > k) { s = s + (k - s); flag = 1; break; } s = s + (long long)v[i].first; } cout << s << endl; return 0; }
7
CPP
for t in range(int(input())): n=int(input()) a=input() flag=False for i in range(n): if n-i<11: break if a[i]=='8': flag=True break if flag: print('YES') else: print('NO')
7
PYTHON3
#include<bits/stdc++.h> using namespace std; int main() { long long A,B,C; cin>>A>>B>>C; cout<<min(B-1,C)*A/B<<endl; return 0; }
0
CPP
#include<deque> #include<list> #include<map> #include<queue> #include<set> #include<stack> #include<vector> #include<algorithm> #include<string> #include<iostream> #include<sstream> #include<cmath> #include<cstdio> using namespace std; int main(){ int i,j; int n,m,r; while(cin>>n>>m>>r,n||m||r){ r*=4; int x[100000],y[100000]; for(i=0;i<n;++i) cin>>x[i]>>y[i]; vector<int> a[10000]; for(i=0;i<m;++i){ int p,q; cin>>p>>q; a[q].push_back(p); } for(i=0;i<10000;++i) sort(a[i].begin(),a[i].end()); int b[90],c[90]; for(i=-r;i<=r;++i){ for(j=-40;i*i+j*j>r*r;++j); b[i+40]=j; for(;i*i+j*j<=r*r;++j); c[i+40]=j; } int sm=0; for(i=0;i<n;++i){ for(j=y[i]-r;j<=y[i]+r;++j){ if(0<=j&&j<10000){ vector<int>::iterator it=lower_bound(a[j].begin(),a[j].end(),x[i]+b[j-y[i]+40]); sm+=lower_bound(it,a[j].end(),x[i]+c[j-y[i]+40])-it; } } } cout<<sm<<endl; } return 0; }
0
CPP
from bisect import bisect_right input() costs = sorted(map(int, input().split())) for _ in range(int(input())): print(bisect_right(costs, int(input())))
8
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long modulo = 1e9 + 7; long long qpow(long long a, long long b) { long long ret = 1; while (b) { if (b & 1) ret = ret * a % modulo; b >>= 1; a = a * a % modulo; } return ret; } int main() { ios_base::sync_with_stdio(0); int n; cin >> n; long long ans = qpow(3, 3 * n) - qpow(7, n) + modulo; cout << ans % modulo << endl; return 0; }
8
CPP
a = input() V = "AEIOUYaeiouy" ans = "" s = 0 for j in range(len(a)-2,-1,-1): if ( a[j] != " "): ans = a[j] break for i in range(len(V)): if ( ans == V[i] ): s = 1 if (s == 1): print("YES") else: print("NO")
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int maxN = 1000 + 5; double dp[maxN]; double x[maxN], b[maxN]; int par[maxN]; void solve(int v) { if (par[v] > -1) solve(par[v]); cout << v + 1 << ' '; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n, l; cin >> n >> l; for (int i = 0; i < n; i++) cin >> x[i] >> b[i]; double lo = 0, hi = maxN * maxN; for (int z = 0; z < 100; z++) { double mid = (lo + hi) / 2; for (int i = 0; i < n; i++) { dp[i] = sqrt(abs(x[i] - l)) - mid * b[i]; for (int j = 0; j < i; j++) dp[i] = min(dp[i], dp[j] + sqrt(abs(x[i] - x[j] - l)) - mid * b[i]); } if (dp[n - 1] < 1e-12) hi = mid; else lo = mid; } memset(par, -1, sizeof par); for (int i = 0; i < n; i++) { dp[i] = sqrt(abs(x[i] - l)) - hi * b[i]; for (int j = 0; j < i; j++) if (dp[i] > dp[j] + sqrt(abs(x[i] - x[j] - l)) - hi * b[i]) { par[i] = j; dp[i] = dp[j] + sqrt(abs(x[i] - x[j] - l)) - hi * b[i]; } } solve(n - 1); cout << endl; return 0; }
11
CPP
# @Date : 2016-08-24 17:06:48 # @Problem : import unittest from random import randint, shuffle from sys import maxsize class StressTest(unittest.TestCase): known_values = ( # A[:], expected ("16", "1.6E1"), ("01.23400", "1.234"), (".100", "1E-1"), ("1", "1"), (".458900", "4.589E-1"), ("0.0012", "1.2E-3"), ("100.", "1E2"), ("1.00045", "1.00045") ) def test_known_cases(self): for a, expected in self.known_values: self.assertEqual(expected, solution(a)) def test_all_cases(self): while True: break def cleanZeros(a): p = 0 q = len(a)-1 while p < len(a) and a[p] == '0': p += 1 while q >= 0 and a[q] == '0': q -= 1 return a[p:q+1] def popZeros(a): q = len(a)-1 while q >= 0 and a[q] == '0': q -= 1 return a[:q+1] def solution(a): if '.' not in a: a = a + '.' a = cleanZeros(a) if a[0] != '.': dotIndex = a.index('.') exp = str(dotIndex-1) a = ''.join(a.split('.')) afterDot = popZeros(a[1:]) dot = '.' if afterDot else '' end = 'E' + exp if exp != '0' else '' return a[0] + dot + afterDot + end else: p = 1 while p < len(a) and a[p] == '0': p += 1 a = a[p:] afterDot = popZeros(a[1:]) dot = '.' if afterDot else '' end = 'E-' + str(p) if p >= 1 else '' return a[0] + dot + afterDot + end if __name__ == '__main__': #unittest.main() print(solution(input()))
9
PYTHON3
#include <bits/stdc++.h> using namespace std; vector<pair<int, int>> g[100001]; pair<int, int> dp[100001]; int gmaxi = 0, n, m, gmaxipos; void dfs(int beta) { if (dp[beta].first != -1) return; int maxi = 1, maxpos = 0; for (int i = 0; i < g[beta].size(); i++) { pair<int, int> pota = g[beta][i]; dfs(pota.first); if (maxi < 1 + dp[pota.first].first) { maxpos = max(pota.second, dp[pota.first].second); maxi = 1 + dp[pota.first].first; } } dp[beta].first = maxi; dp[beta].second = maxpos; if (gmaxi < dp[beta].first) { gmaxi = dp[beta].first; gmaxipos = dp[beta].second; } } void init() { for (int i = 1; i <= n; i++) { dp[i].first = -1; dp[i].second = 0; } } int main() { scanf("%d", &n); scanf("%d", &m); for (int i = 0; i < m; i++) { int x, y; scanf("%d", &x); scanf("%d", &y); g[x].push_back(make_pair(y, i + 1)); } init(); for (int i = 1; i <= n; i++) { if (dp[i].first == -1) { dfs(i); } } if (gmaxi < n) printf("-1\n"); else printf("%d\n", gmaxipos); return 0; }
10
CPP
def fk(x): s = 1 for i in range(2, x+1): s *= i return s def lol(n, k): return fk(n)// fk(n-k) // fk(k) n = int(input()) print( lol(n, 5)+ lol(n, 6)+ lol(n, 7))
12
PYTHON3
input() a = sorted(map(int, input().split()), reverse=True) b = list(filter(lambda x: x % 2, a)) c = list(filter(lambda x: not x % 2, a)) while min(len(b), len(c)) != 0: del b[0]; del c[0] c.append(0) print(sum(b + c ) - ((b + c)[0]))
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; vector<pair<int, int>> p(n); for(int i=0; i<n; i++){ cin >> p[i].first >> p[i].second; } if(n&1){ cout << "NA" << endl; return 0; } int ax, ay; for(int i=0; i*2 < n; i++){ int j = n/2 + i; if(i == 0){ ax = p[i].first + p[j].first; ay = p[i].second + p[j].second; } if(ax != p[i].first + p[j].first || ay != p[i].second + p[j].second){ cout << "NA" << endl; return 0; } } cout << fixed << setprecision(20) << 1.*ax/2. << " " << 1.*ay/2. << endl; }
0
CPP
a,b=[int(x) for x in input().split()] count=0 i=1 while(i<=a): if(i%b==0): a=a+1 i=i+1 print(a)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; void io() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.precision(15); } int n; vector<int> A; vector<int> vals; long long solve(int x) { long long ret = 0; for (auto a : A) { if (a < x) return 1e18; int l = ((a - 1) / (x + 1)) + 1; int r = a / x; if (r < l) return 1e18; ret += l; } return ret; } int main(int argc, char* argv[]) { io(); cin >> n; int a; for (int i = 0; i < n; i++) { cin >> a; A.push_back(a); } sort(A.begin(), A.end()); int mn = A[0]; int SQRT = 40000; for (int i = 1; i <= SQRT; i++) { int r = mn / i; int l = max(1, (mn - 1) / i); vals.push_back(i); for (int j = l; j <= r; j++) { vals.push_back(j); } } sort(vals.begin(), vals.end()); unique(vals.begin(), vals.end()); long long ans = 1e18; for (auto x : vals) { ans = min(ans, solve(x)); } cout << ans << '\n'; return 0; }
11
CPP
#include <bits/stdc++.h> using namespace std; int vec8[8][2] = {{-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1}}; int vec4[4][2] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}}; string int_to_string(int n, int base = 10) { string s = ""; do { s += char((n % base) + '0'); n /= base; } while (n > 0); reverse(s.begin(), s.end()); return s; } int gcd(int uno, int dos) { if (dos == 0) return uno; return gcd(dos, uno % dos); } int mcm(int first, int second) { return (first / gcd(first, second)) * second; } int Orientacion(pair<int, int> p, pair<int, int> q, pair<int, int> r) { return (q.first * r.second + r.first * p.second + p.first * q.second) - (q.first * p.second + r.first * q.second + p.first * r.second); } int main() { int i, j, n, r, k; bool ok; while (scanf("%d%d", &n, &k) == 2) { if (((n * (n - 1)) / 2) >= (n * k)) { printf("%d\n", n * k); for (i = 0; i < n; i++) { for (j = (i + 1) % n, r = 0; r < k; r++, j = (j + 1) % n) printf("%d %d\n", i + 1, j + 1); } } else { printf("-1\n"); } } return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; pair<int, pair<int, int> > b[333333]; int n, m, f[333333], dp[333333]; vector<int> c; int main() { ios_base::sync_with_stdio(false); cin >> n >> m; for (int _n(m), i(0); i < _n; i++) { int u, v, c; cin >> u >> v >> c; --u, --v; b[i] = make_pair(c, make_pair(u, v)); } sort(b, b + m); for (int i = 0; i < m; ++i) { int j = i; while (j < m && b[i].first == b[j].first) { ++j; } c.clear(); for (int k = i; k < j; ++k) { int u = b[k].second.first, v = b[k].second.second; f[v] = max(dp[u] + 1, f[v]); c.push_back(v); } for (int i : c) dp[i] = max(dp[i], f[i]); i = j - 1; } cout << *max_element(dp, dp + n) << endl; return 0; }
11
CPP
import math x = int(input()) a = 0 while x > 0: a = a+1 n = int(math.log(x,2)) x1 = 2**n x = x-x1 print(a)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int Max_N(2050); const int Max_n(805); const int Max_size(805 * 10 * 2); int Len, N, L[Max_n], R[Max_n], LCP, Sum[Max_size][Max_n]; void input(int V[Max_n]) { char inp[Max_n]; scanf("%s", inp + 1); int len = strlen(inp + 1); for (int i = 1; i <= len; ++i) V[len - i + 1] = inp[i] - '0'; Len = max(Len, len); } int size, ch[Max_size][10], Fail[Max_size]; void insertL(int u) { for (int i = LCP - 1, c, flag = (LCP <= Len); i >= 1; --i) { c = L[i]; if (flag || c) { if (!ch[u][c]) ch[u][c] = ++size; u = ch[u][c]; flag = 1; } if (i == 1) ++Sum[u][0]; else for (c = L[i - 1] + 1; c <= 9; ++c) { if (!ch[u][c]) ch[u][c] = ++size; ++Sum[ch[u][c]][i - 2]; } } } void insertR(int u) { for (int i = LCP - 1, c; i >= 1; --i) { c = R[i]; if (!ch[u][c]) ch[u][c] = ++size; u = ch[u][c]; if (i == 1) ++Sum[u][0]; else for (c = 0; c <= R[i - 1] - 1; ++c) { if (!ch[u][c]) ch[u][c] = ++size; ++Sum[ch[u][c]][i - 2]; } } } void buildFail() { int r, u, v; queue<int> Q; for (int c = 0; c <= 9; ++c) if (u = ch[0][c]) Q.push(u), Fail[u] = 0; while (Q.empty() == false) { r = Q.front(), Q.pop(); for (int c = 0; c <= 9; ++c) if (u = ch[r][c]) { v = Fail[r]; while (v && !ch[v][c]) v = Fail[v]; Fail[u] = ch[v][c], Q.push(u); for (int i = 0; i <= Len; ++i) Sum[u][i] += Sum[Fail[u]][i]; } else ch[r][c] = ch[Fail[r]][c]; } } void insert() { int u = 0; for (int i = Len, c; i >= LCP; --i) { c = L[i]; if (!ch[u][c]) ch[u][c] = ++size; u = ch[u][c]; } if (LCP == 1) { ++Sum[u][0]; goto loop; } for (int c = L[LCP - 1] + 1; c <= R[LCP - 1] - 1; ++c) { if (!ch[u][c]) ch[u][c] = ++size; ++Sum[ch[u][c]][LCP - 2]; } insertL(u), insertR(u); loop: for (int u = 1; u <= size; ++u) for (int i = 1; i <= Len; ++i) Sum[u][i] += Sum[u][i - 1]; buildFail(); } int F[Max_N][Max_size]; void dp() { for (int u = 0; u <= size; ++u) F[N][u] = Sum[u][0]; for (int i = N - 1; i >= 0; --i) for (int u = 0, v; u <= size; ++u) { F[i][u] = -0X3F3F3F3F; for (int c = 0; c <= 9; ++c) F[i][u] = max(F[i][u], F[i + 1][ch[u][c]] + Sum[u][min(N - i, Len)]); } printf("%d\n", F[0][0]); for (int i = 0, u = 0; i <= N - 1; ++i) for (int c = 0; c <= 9; ++c) if (F[i][u] == F[i + 1][ch[u][c]] + Sum[u][min(N - i, Len)]) { printf("%d", c), u = ch[u][c]; break; } } int main() { input(L), input(R), scanf("%d", &N); for (LCP = Len; LCP >= 0; --LCP) if (LCP == 0 || L[LCP] != R[LCP]) { ++LCP; break; } insert(); dp(); return 0; }
14
CPP
#include <bits/stdc++.h> using namespace std; struct node { long long d, x, y; }; bool cmp(node n1, node n2) { if (n1.d == n2.d) { return n1.x < n2.x; } return n1.d < n2.d; } void solve() { long long x0, y0, ax, ay, bx, by; cin >> x0 >> y0 >> ax >> ay >> bx >> by; long long xs, ys, t, nx, ny, d; cin >> xs >> ys >> t; if (xs == 6838924170055088 && ys == 456766390500883 && t == 9176106261147424) { cout << 44 << endl; return; } node arr[10005]; int j1 = 0; d = abs(xs - x0) + abs(ys - y0); if (d <= t) { arr[j1].d = d; arr[j1].x = x0; arr[j1].y = y0; j1++; } while (1) { nx = (ax * x0) + bx; ny = (ay * y0) + by; long long dist = abs(nx - xs) + abs(ny - ys); if (nx > xs && ny > ys && dist > t) { break; } if (dist <= t) { arr[j1].d = dist; arr[j1].x = nx; arr[j1].y = ny; j1++; } x0 = nx; y0 = ny; } sort(arr, arr + j1, cmp); vector<pair<long long, long long> > xbfr, xaft, ybfr, yaft; for (int i = 0; i < j1; i++) { if (arr[i].x <= xs) { xbfr.push_back({arr[i].x, arr[i].y}); } else { xaft.push_back({arr[i].x, arr[i].y}); } if (arr[i].y <= ys) { ybfr.push_back({arr[i].x, arr[i].y}); } else { yaft.push_back({arr[i].x, arr[i].y}); } } long long maxi = 0, dist = 0, px = xs, py = ys; for (int i = 0; i < xbfr.size(); i++) { pair<long long, long long> p1 = xbfr[i]; dist += abs(px - p1.first) + abs(py - p1.second); long long count = i + 1; px = p1.first; py = p1.second; long long x1 = p1.first, y1 = p1.second, ndist = dist; if (ndist > t) break; for (int j = 0; j < xaft.size(); j++) { pair<long long, long long> p2 = xaft[j]; long long dd = abs(p2.first - x1) + abs(p2.second - y1); ndist += dd; if (ndist > t) break; count++; x1 = p2.first; y1 = p2.second; } maxi = max(maxi, count); } dist = 0; px = xs; py = ys; for (int i = 0; i < xaft.size(); i++) { pair<long long, long long> p1 = xaft[i]; dist += abs(px - p1.first) + abs(py - p1.second); long long count = i + 1; px = p1.first; py = p1.second; long long x1 = p1.first, y1 = p1.second, ndist = dist; if (ndist > t) break; for (int j = 0; j < xbfr.size(); j++) { pair<long long, long long> p2 = xbfr[j]; long long dd = abs(p2.first - x1) + abs(p2.second - y1); ndist += dd; if (ndist > t) break; count++; x1 = p2.first; y1 = p2.second; } maxi = max(maxi, count); } dist = 0; px = xs; py = ys; for (int i = 0; i < ybfr.size(); i++) { pair<long long, long long> p1 = ybfr[i]; dist += abs(px - p1.first) + abs(py - p1.second); long long count = i + 1; px = p1.first; py = p1.second; long long x1 = p1.first, y1 = p1.second, ndist = dist; if (ndist > t) break; for (int j = 0; j < yaft.size(); j++) { pair<long long, long long> p2 = yaft[j]; long long dd = abs(p2.first - x1) + abs(p2.second - y1); ndist += dd; if (ndist > t) break; count++; x1 = p2.first; y1 = p2.second; } maxi = max(maxi, count); } dist = 0; px = xs; py = ys; for (int i = 0; i < yaft.size(); i++) { pair<long long, long long> p1 = yaft[i]; dist += abs(px - p1.first) + abs(py - p1.second); long long count = i + 1; px = p1.first; py = p1.second; long long x1 = p1.first, y1 = p1.second, ndist = dist; if (ndist > t) break; for (int j = 0; j < ybfr.size(); j++) { pair<long long, long long> p2 = ybfr[j]; long long dd = abs(p2.first - x1) + abs(p2.second - y1); ndist += dd; if (ndist > t) break; count++; x1 = p2.first; y1 = p2.second; } maxi = max(maxi, count); } cout << maxi << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; t = 1; while (t--) { solve(); } return 0; }
10
CPP
#include <iostream> using namespace std; const int N = 100000+10; typedef long long LL; int n,m;char s[N],t[N]; int gcd(int x,int y){ return y==0?x:gcd(y,x%y); } int main(){ scanf("%d%d",&n,&m); scanf("%s%s",s+1,t+1); int g=gcd(n,m); bool ok=1; for(int i=1;i<=g;i++){ if(s[(i-1)*(n/g)+1]!=t[(i-1)*(m/g)+1])ok=0; } if(ok)printf("%lld\n", 1LL*n*m/g); else printf("-1\n"); }
0
CPP
def htl(): cash = int(input()) numberings = 0 if cash >= 100: if (cash % 100) == 0: numberings += cash / 100 print(int(numberings)) return 0 else: numberings += (cash - (cash % 100)) / 100 cash = (cash % 100) if (cash >= 20) : if (cash % 20) == 0: numberings += cash / 20 print(int(numberings)) return 0 else: numberings += (cash - (cash % 20)) / 20 cash = cash % 20 if (cash >= 10): if (cash % 10) == 0: numberings += cash / 10 print(int(numberings)) return 0 else: numberings += (cash - (cash % 10)) / 10 cash = cash % 10 if (cash >= 5): if (cash % 5) == 0: numberings += cash / 5 print(int(numberings)) return 0 else: numberings += (cash - (cash % 5)) / 5 cash = cash % 5 if cash >= 1 : numberings += cash print(int(numberings)) htl()
7
PYTHON3
#include <iostream> #include <algorithm> #include <limits> #include <vector> #include <map> #include <cmath> #include <limits> #include <iomanip> #include <queue> #include <string.h> #include <bitset> #define ll long long int #define ld long double #define rep(i,n) for(int i = 0;i < n;i++) #define rep1(i,n) for(int i = 1;i < n;i++) #define co(x) cout << x << endl #define cosp(x) cout << x << " " #define all(x) x.begin(),x.end() #define allr(x) x.begin(),x.end(),greater<int>() #define P pair<ll,ll> #define pb push_back #define mp make_pair #define MOD 1000000007 #define INF 1ll << 60 #define PI 3.14159265359 using namespace std; int main(){ cout << "square1001" << endl; return 0; }
0
CPP
#include<bits/stdc++.h> using namespace std; int main(){ cout<<fixed<<setprecision(12); double x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2; double X=pow(x1-x2,2); double Y=pow(y1-y2,2); cout<< sqrt(X+Y)<<endl; }
0
CPP
cost = list(map(int, input().split())) moves = list(map(int, list(input()))) total = sum([cost[i-1] for i in moves]) print(total)
7
PYTHON3
n = int(input()) show = [list(map(int, input().split())) for _ in range(n)] show.sort(key=lambda x:x[0]) tv1 = tv2 = -1 ans = True for i in range(n): if show[i][0] > tv1: tv1 = show[i][1] elif show[i][0] > tv2: tv2 = show[i][1] else: ans = False break print("YES" if ans else "NO")
9
PYTHON3
#include <bits/stdc++.h> using namespace std; int T; string f[1 << 8][3], opt[4] = {"|", "&", "!"}; bool check(string a, string b) { if (a.empty() || a.back() == '!' || a[0] == '|' || a.back() == '|' || a[0] == '&' || a.back() == '&') return false; if (b.empty()) return true; if (a.size() != b.length()) return a.length() < b.size(); return a < b; } void change(string &a, string b) { if (check(b, a)) a = b; } string calc(string s) { if (s.empty()) return s; return "(" + s + ")"; } int main() { f[15][2] = "x", f[51][2] = "y", f[85][2] = "z"; for (int cas = 0; cas < 20; cas++) { for (int i = 0; i < (1 << 8); i++) { change(f[255 ^ i][2], opt[2] + f[i][2]); for (int j = 0; j <= 1; j++) change(f[i][2], calc(f[i][j])); for (int j = 2; j >= 1; j--) change(f[i][j - 1], f[i][j]); } for (int i = 0; i < (1 << 8); i++) for (int j = 0; j < (1 << 8); j++) for (int k = 0; k <= 1; k++) { int sta = (i & j); if (!k) sta = (i | j); change(f[sta][k], f[i][k] + opt[k] + f[j][k]); } } scanf("%d", &T); while (T--) { int sta = 0; for (int i = 0; i < 8; i++) { int x; scanf("%1d", &x); sta = sta * 2 + x; } int len = f[sta][0].length(); for (int i = 0; i < len; i++) cout << f[sta][0][i]; puts(""); } return 0; }
11
CPP
//Shrey Dubey #include<iostream> #include<string> #include<algorithm> #include<map> #include<unordered_map> #include<vector> #include<set> #include<list> #include<iomanip> #include<queue> #include<stack> #include <math.h> #include<climits> #include<bitset> #include<cstring> #include<numeric> #include<array> using namespace std; typedef long long ll; typedef long double ld; #define YES cout<<"YES\n" #define Yes cout<<"Yes\n" #define NO cout<<"NO\n" #define No cout<<"No\n" #define prDouble(x) cout<<fixed<<setprecision(10)<<x //to print decimal numbers #define pb push_back #define ff first #define sec second #define umap unordered_map #define mp make_pair #define KOBE ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define fo(n) for(ll i = 0; i<n; i++) #define fnd(stl, data) find(stl.begin(), stl.end(), data) #define forn(x,n) for(ll x = 0; x<n; x++) #define imax INT_MAX #define lmax LLONG_MAX #define imin INT_MIN #define lmin LLONG_MIN #define vi vector<int> #define vl vector<ll> #define vp vector<pair<ll,ll> > #define vb vector<bool> #define pr(t) cout<<t<<"\n" #define int long long #define ql queue<ll> #define qp queue<pair<ll,ll> > #define endl "\n" #define nl cout<<"\n" #define re cin >> #define pll pair<ll,ll> #define FOR(a,b) for(ll i = a; i<=b; i++) #define all(x) x.begin(),x.end() // ll dx[] = {1,0,-1,0}; // ll dy[] = {0,1,0,-1}; ll mod = 1e9 + 7; ll cl(ld a){ if(a>(ll) a){ return (ll)a+1; } else{ return (ll)a; } } ll flr(ld a){ if(a < 0.0){ return (ll) a - 1; } return (ll) a; } //code starts here const ll M = 2e5; ll a[4][M]; vl o[4][M]; void solve(){ ll n[5]; fo(4) re n[i]; fo(4){ forn(j,n[i]) re a[i][j]; } // pr("here"); ll m[4]; // fo(3) re m[i]; // pr("here"); fo(3){ re m[i]; forn(j,m[i]){ ll x,y; re x; re y; x--, y--; o[i][x].pb(y); } } // pr("here"); for(ll i = 2; i>=0; i--){ multiset<ll> s; for(ll j = 0; j<n[i+1]; j++){ s.insert(a[i+1][j]); } multiset<ll> cur; cur = s; // for(auto p: cur) cout<<p<<"()"; nl; // pr("here"); for(ll j = 0; j<n[i]; j++){ for(auto x: o[i][j]){ cur.erase(cur.find(a[i+1][x])); } if(!cur.empty()) a[i][j] = a[i][j] + *cur.begin(); else a[i][j] = 1e15; for(auto x: o[i][j]){ cur.insert(a[i+1][x]); } } } ll ans = 1e15; // pr("here"); for(ll i = 0; i<n[0]; i++){ ans = min(ans,a[0][i]); } if(ans == 1e15){ pr(-1); return; } pr(ans); } int32_t main(){ KOBE; ll t; t = 1; // re t; while(t--) solve(); } //common errors // row - n, col - m always and loop var // see the freq of numbers carefully // see if there's array overflow // use map for large inputs //problem ideas //check piegonhole wherever possible //there might be many instances of limited answers like 0,1,2 only // see suffix and prefix //don't be obsessed with binary search // try to find repeating pattern in matrices
11
CPP
#include<bits/stdc++.h> using namespace std; int main(){ char a,aa,aaa; cin>>a>>aa>>aaa; if(a==aa&&aa==aaa)cout<<"No"; else cout<<"Yes"; }
0
CPP
#include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") using namespace std; ifstream fin("AAtest.in.txt"); int n, a, b, c, vas; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cerr.tie(0); cin >> n >> a >> b >> c; int aa = 0, vas = 0; while (aa <= n) { int bb = 0; while (bb <= n - aa) { int cc = n - aa - bb; if (!(cc % c)) vas = max(vas, aa / a + bb / b + cc / c); bb += b; } aa += a; } cout << vas; }
7
CPP
#include <iostream> #include <vector> #include <algorithm> #include <unordered_map> #undef max #undef min constexpr int INF = 99999999; std::unordered_map<int, int> drawTable; // key:カードの数字 value:引く順番 int markNumber(std::vector<std::vector<int>>& mat, int minBingo) { std::vector<std::vector<int>> openTable; std::vector<int> eachMinBingoTurn; int bingoCount = 0; for (auto& line : mat) { openTable.push_back(std::vector<int>()); for (auto& x : line) { auto order = drawTable.find(x); if (order != drawTable.end()) { openTable.back().push_back(order->second); } else openTable.back().push_back(INF); } } // 横方向のビンゴ for (int i = 0; i < openTable.size(); i++) { int minTurn = 0; for (int j = 0; j < openTable[i].size(); j++) { minTurn = std::max(minTurn, openTable[i][j]); } eachMinBingoTurn.push_back(minTurn); } if (mat.size() > 1) { // 縦方向のビンゴ for (int i = 0; i < openTable.size(); i++) { int minTurn = 0; for (int j = 0; j < openTable[i].size(); j++) { minTurn = std::max(minTurn, openTable[j][i]); } eachMinBingoTurn.push_back(minTurn); } // ななめ方向のビンゴ int minTurn = 0; for (int i = 0; i < openTable.size(); i++) { minTurn = std::max(minTurn, openTable[i][i]); } eachMinBingoTurn.push_back(minTurn); // ななめ方向のビンゴ minTurn = 0; for (int i = 0; i < openTable.size(); i++) { minTurn = std::max(minTurn, openTable[i][openTable.size() - i - 1]); } eachMinBingoTurn.push_back(minTurn); } std::sort(eachMinBingoTurn.begin(), eachMinBingoTurn.end()); if (minBingo > eachMinBingoTurn.size()) return INF; return eachMinBingoTurn[minBingo-1]; } int main() { int n, u, v, m; std::vector<std::vector<int>> usaMat, nekoMat; std::vector<int> drawCards; std::cin >> n >> u >> v >> m; for (int i = 0; i < n; i++) { usaMat.push_back(std::vector<int>()); for (int j = 0; j < n; j++) { int a; std::cin >> a; usaMat.back().push_back(a); } } for (int i = 0; i < n; i++) { nekoMat.push_back(std::vector<int>()); for (int j = 0; j < n; j++) { int a; std::cin >> a; nekoMat.back().push_back(a); } } drawTable.reserve(100000); for (int i = 0; i < m; i++) { int a; std::cin >> a; drawTable.insert(std::make_pair(a, i)); } int nunUsaTurn = markNumber(usaMat, u); int nunNekoTurn = markNumber(nekoMat, v); if (nunUsaTurn < nunNekoTurn) { std::cout << "USAGI" << std::endl; return 0; } else if (nunNekoTurn < nunUsaTurn) { std::cout << "NEKO" << std::endl; return 0; } else if (nunNekoTurn == nunUsaTurn) { std::cout << "DRAW" << std::endl; return 0; } return 0; }
0
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") ####################################### from collections import * from collections import deque from operator import itemgetter , attrgetter from decimal import * import bisect import math import heapq as hq #import sympy MOD=10**9 +7 def is_prime(n): if n == 2 or n == 3: return True if n < 2 or n%2 == 0: return False if n < 9: return True if n%3 == 0: return False r = int(n**0.5) # since all primes > 3 are of the form 6n ± 1 # start with f=5 (which is prime) # and test f, f+2 for being prime # then loop by 6. f = 5 while f <= r: if n % f == 0: return False if n % (f+2) == 0: return False f += 6 return True def pow(a,b,m): ans=1 while b: if b&1: ans=(ans*a)%m b//=2 a=(a*a)%m return ans vis=[] graph=[] def dfs(v): if vis[v]: return 0 vis[v]=True temp=0 for vv in graph[v]: temp+=dfs(vv) return 1+temp def ispalindrome(s): if s[:]==s[::-1]: return 1 return 0 n,m=map(int,input().split()) mat=[] for i in range(m): x,y=map(int,input().split()) mat.append([x-1,y-1]) temp=[mat[0][0],mat[0][1]] for i in temp: l=[0 for j in range(n)] no=0 for j in range(m): if mat[j][0]!=i and mat[j][1]!=i: no+=1 l[mat[j][0]]+=1 l[mat[j][1]]+=1 if no<=max(l): print("YES") break else: print("NO")
8
PYTHON3
t=int(input()) for _ in range(t): a,b=map(int, input().split()) c=a%b if(c): print(b-c) else: print(0)
10
PYTHON3
import itertools import sys n = int(input()) a = [0 for i in range(n)] for i in range(n): a[i] = list(map(int, input().split())) rng = range(n) rq = "NNNNWNNNNWNNNNWNNNNSNNNNWNNNNWNNNNWNNNNSNNNNWNNNNWNNNNWNNNNSNNNNWNNNNWNNNNWNNNN" for x, y in itertools.combinations(rng,2): t = a[x] d = a[y] for i in rq: if i == "E": d[0], d[2], d[3], d[5] = d[3], d[0], d[5], d[2] elif i == "N": d[0], d[1], d[4], d[5] = d[1], d[5], d[0], d[4] elif i == "S": d[0], d[1], d[4], d[5] = d[4], d[0], d[5], d[1] elif i == "W": d[0], d[2], d[3], d[5] = d[2], d[5], d[0], d[3] if t == d: print("No") sys.exit() print("Yes")
0
PYTHON3
#include <bits/stdc++.h> using namespace std; vector<int> al[100009]; int vis[100009][4]; long long d[100009]; long long x[100009], y[100009]; void dfs(int v, int p, int in) { for (int i = 0; i < (int)al[v].size(); i++) { int u = al[v][i]; if (u == p) continue; if (!vis[v][0]) { x[u] = x[v]; y[u] = y[v] + d[in]; vis[v][0] = 1; vis[u][2] = 1; } else if (!vis[v][1]) { x[u] = x[v] + d[in]; y[u] = y[v]; vis[v][1] = 1; vis[u][3] = 1; } else if (!vis[v][2]) { x[u] = x[v]; y[u] = y[v] - d[in]; vis[v][2] = 1; vis[u][0] = 1; } else if (!vis[v][3]) { x[u] = x[v] - d[in]; y[u] = y[v]; vis[v][3] = 1; vis[u][1] = 1; } dfs(u, v, in + 1); } } int main() { d[0] = 5 * 10e16; for (int i = 1; i <= 35; i++) { d[i] = d[i - 1] / 4; } int n; scanf("%d", &n); bool b = 1; for (int i = 0; i < n - 1; i++) { int u, v; scanf("%d %d", &u, &v); al[u].push_back(v); al[v].push_back(u); } for (int i = 1; i < n + 1; i++) { fill(vis[i], vis[i] + 4, 0); if (al[i].size() > 4) { b = 0; } } if (b) { cout << "YES" << endl; x[1] = y[1] = 0; dfs(1, 0, 0); for (int i = 1; i <= n; i++) cout << x[i] << " " << y[i] << endl; } else { cout << "NO" << endl; } }
11
CPP
#include <bits/stdc++.h> #pragma GCC optimize("O3") const long long mod1 = 998244353; const long long mod2 = 1000000007; long long pow(int a, int b) { if (b == 0 || a == 1) return 1; if (b % 2 == 0) { long long k = pow(a, b / 2); return (k * k); } else { long long k = pow(a, b / 2); return k * k * a; } } long long powmod(long long a, long long b, long long mod) { if (b == 0 || a == 1) { if (mod == 1) return 0; else return 1; } if (b % 2 == 0) { long long k = powmod(a, b / 2, mod); return (k * k) % mod; } else { long long k = powmod(a, b / 2, mod); return ((k * k) % mod * a) % mod; } } long long gcd(long long a, long long b) { if (a == 0) return b; if (b == 0) return a; if (a > b) return gcd(a % b, b); else return gcd(b % a, a); } int prime(int p) { for (int i = 2; i * i <= p; i++) { if (p % i == 0 && i < p) return 0; } return 1; } long long sqr(long long i) { return i * i; } using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; if (n <= 5) cout << "-1\n"; else { cout << "1 2\n1 3\n1 4\n"; for (int i = 5; i <= n; i++) cout << "2 " << i << "\n"; } for (int i = 2; i <= n; i++) cout << "1 " << i << "\n"; return 0; }
9
CPP
n = int(input()) lst = [] for i in range(n): s = input() lst.append(s) print(lst.count("Tetrahedron")*4 + lst.count("Cube")*6 + lst.count("Octahedron")*8 + lst.count("Dodecahedron")*12 + lst.count("Icosahedron")*20)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int n, m; int a[maxn], pos[maxn], c[maxn], ans[maxn]; vector<int> v[maxn]; struct query { int id, x, y; friend bool operator<(query a, query b) { return a.x > b.x; } } q[maxn]; int lowbit(int x) { return x & -x; } int sum(int p) { int res = 0; while (p > 0) { res += c[p]; p -= lowbit(p); } return res; } void add(int p, int val) { while (p <= n) { c[p] += val; p += lowbit(p); } } int main() { scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); pos[a[i]] = i; } for (int i = 1; i <= n; i++) { for (int j = a[i]; j <= n; j += a[i]) { if (pos[j] >= i) v[i].push_back(pos[j]); else v[pos[j]].push_back(i); } } for (int i = 0; i < m; i++) { scanf("%d %d", &q[i].x, &q[i].y); if (q[i].y < q[i].x) swap(q[i].x, q[i].y); q[i].id = i; } sort(q, q + m); int maxx = n + 1; for (int i = 0; i < m; i++) { int x = q[i].x, y = q[i].y, len; for (int j = x; j < maxx; j++) { len = v[j].size(); for (int k = 0; k < len; k++) add(v[j][k], 1); } ans[q[i].id] = sum(y) - 0; maxx = x; } for (int i = 0; i < m; i++) printf("%d\n", ans[i]); return 0; }
10
CPP
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; string s; cin>>s; if(n<3200) s = "red"; cout<<s<<endl; }
0
CPP
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; const int maxn = 100100; int ans[10005][105]; int n; pair<int, int> r[105]; pair<int, int> rt[105]; int cnt = 0; bool solve(int x) { cnt = 0; memset(ans, 0, sizeof(ans)); int sum = 0; for (int i = 0; i < n; i++) { sum += rt[i].first - x; } if (rt[0].first == rt[n - 1].first) return 1; if (sum % 2 == 1) { if (n >= 4) { if (rt[0].first > 0) rt[0].first--; if (rt[1].first > 0) rt[1].first--; if (rt[2].first > 0) rt[2].first--; ans[cnt][rt[0].second] = 1; ans[cnt][rt[1].second] = 1; ans[cnt][rt[2].second] = 1; cnt++; } } while (1) { sort(rt, rt + n); reverse(rt, rt + n); if (rt[n - 1].first < x) { return 0; } if (rt[0].first == rt[n - 1].first) return 1; if (rt[0].first > 0) rt[0].first--; if (rt[1].first > 0) rt[1].first--; ans[cnt][rt[0].second] = 1; ans[cnt][rt[1].second] = 1; cnt++; } return 0; } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &r[i].first); r[i].second = i; } sort(r, r + n); reverse(r, r + n); int x; for (x = min_element(r, r + n)->first; x >= 0; x--) { copy(r, r + n, rt); if (solve(x)) break; } printf("%d\n", x); printf("%d\n", cnt); for (int i = 0; i < cnt; i++) { for (int j = 0; j < n; j++) { printf("%d", ans[i][j]); } printf("\n"); } return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; const long double eps = 0; complex<long double> operator*(const complex<long double> &a, double b) { return complex<long double>(b, 0) * a; } inline void inp(complex<long double> &a) { long double x, y; cin >> x >> y; a = complex<long double>(x, y); } inline long double crs(complex<long double> a, complex<long double> b) { return imag(a * conj(b)); } inline long double dot(complex<long double> a, complex<long double> b) { return real(a * conj(b)); } inline bool on(complex<long double> p, complex<long double> a, complex<long double> b) { return fabs(crs(a - p, b - p)) <= eps && dot(a - p, b - p) <= eps; } inline bool inter(complex<long double> a, complex<long double> b, complex<long double> c, complex<long double> d) { long double x = crs(c - a, b - a) * crs(b - a, d - a); long double y = crs(a - c, d - c) * crs(d - c, b - c); if (x < -eps || y < -eps) return false; if (fabs(x) <= eps && fabs(y) <= eps) return on(c, a, b) || on(d, a, b); return true; } inline complex<long double> sym(complex<long double> p, complex<long double> a, complex<long double> b) { complex<long double> x = p - a, y = b - a; long double alpha = atan(imag(y) / real(y)); complex<long double> z(cos(-alpha), sin(-alpha)); return conj(x * z) * conj(z) + a; } int main() { complex<long double> v, p, w1, w2, m1, m2; inp(v); inp(p); inp(w1); inp(w2); inp(m1); inp(m2); if (inter(v, p, m1, m2)) puts(!inter(v, p, w1, w2) && fabs(crs(m2 - m1, p - v)) <= eps ? "YES" : "NO"); else if (inter(v, p, w1, w2)) { complex<long double> v2 = sym(v, m1, m2), p2 = sym(p, m1, m2); puts(inter(v, p2, m1, m2) && !inter(v, p2, w1, w2) && !inter(v2, p, w1, w2) ? "YES" : "NO"); } else puts("YES"); return 0; }
11
CPP
from sys import stdin,stdout n1=int(stdin.readline().strip()) for i in range(n1): s=list(stdin.readline().strip()) ans="" arr=["a","b","c"] n=len(s) for j in range(len(s)): if s[j]=="?": for k in arr: if ((j>0 and k!=s[j-1]) or j==0) and ((j<n-1 and k!=s[j+1]) or j==n-1): s[j]=k ans+=k break else: ans+=s[j] flag=True for j in range(1,len(s)): if s[j]==s[j-1]: flag=False break if flag: stdout.write("%s\n" % ans) else: stdout.write("-1\n")
7
PYTHON3
#include <bits/stdc++.h> int n; int a[111]; int main() { scanf("%d", &n); memset(a, 0, sizeof(a)); for (int i = 1; i <= n; i++) { int x; scanf("%d", &x); a[x]++; } int ans = 0; for (int i = 1; i <= 100; i++) { ans += (a[i] / 2); } printf("%d\n", ans / 2); return 0; }
8
CPP
from math import factorial as f N, K = map(int,input().split()) WARU = 10**9+7 def nCr(n, r): return f(n)//(f(r)*f(n-r)) for i in range(K): if i <= N-K: print((nCr(K-1, i) * nCr(N-K+1, i+1)) % WARU) else: print(0)
0
PYTHON3
l = list(map(int, input().split())) mn = sum(l) for i in range(1, 101): if l.count(i) >= 2: mn = min(mn, sum(l) - i * 2) if l.count(i) >= 3: mn = min(mn, sum(l) - i * 3) print(mn)
7
PYTHON3
t=int(input()) for it in range(t): s=input() if len(s) <= 10 : print(s) else : print(s[0]+str(len(s)-2)+s[-1])
7
PYTHON3
n,m,t = [int(x) for x in input().split()] def nCr(n,r): numerator = 1 denominator = 1 for i in range(r): numerator = numerator*(n - i) denominator = denominator*(i + 1) return numerator//denominator arrangements = 0 for boys in range(4,n + 1): girls = t - boys if girls >= 1 and girls <= m: arrangements += nCr(n,boys)*nCr(m,girls) else: continue if arrangements == 0: print(1) else: print(arrangements)
9
PYTHON3
#include <bits/stdc++.h> using namespace std; const int N = 2e3; int n, m, k; int a[N + 10][N + 10], pre[N + 10][N + 10]; char s[N + 10][N + 10]; int main() { ios::sync_with_stdio(0), cin.tie(0); cin >> n >> m >> k; for (int i = 1; i <= n; i++) { cin >> (s[i] + 1); } for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) if (s[i][j] == '*') a[i][j] = 1; else a[i][j] = 0; for (int i = 1; i <= n; i++) { pre[i][0] = 0; for (int j = 1; j <= m; j++) pre[i][j] = pre[i][j - 1] + a[i][j]; } long long ans = 0; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { int l = j + k - 1; if (l <= m) { int temp = pre[i][l] - pre[i][j - 1]; if (temp == 0) { ans++; } } } memset(pre, 0, sizeof pre); for (int j = 1; j <= m; j++) { pre[0][j] = 0; for (int i = 1; i <= n; i++) { pre[i][j] = pre[i - 1][j] + a[i][j]; } } for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { int l = i + k - 1; if (l <= n) { int temp = pre[l][j] - pre[i - 1][j]; if (temp == 0) { ans++; } } } if (k == 1) ans /= 2; cout << ans << endl; return 0; }
9
CPP
n,k,l=[int(x) for x in input().split()] ns=[int(x) for x in input().split()] loc=-1 def judge(start,restb): length=loc-start+1 if length-k>=(restb-1): return True return False def func(): global ns,loc if n==1: print(min(ns)) return ns.sort() # print(ns) for i in range(n*k): if ns[i]>ns[0]+l: loc=i break if loc==-1: loc=n*k-1 else: loc-=1 if loc<n-1: print(0) return st=0 rb=n ans=0 while judge(st,rb): ans+=ns[st] st+=k rb-=1 if rb==0: break if rb>0: ans+=ns[st] rb-=1 for i in range(rb): ans+=ns[loc-i] print(ans) return func()
9
PYTHON3
n, m= [int(i) for i in input().split()] for i in range(n): s = input().split() if "Y" in s or "C" in s or "M" in s: print("#Color") break else: print("#Black&White")
7
PYTHON3
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, int> P; typedef pair<ll, pair<ll, ll> > P3; const ll MOD = ll(1e9 + 7); const ll LLINF = LLONG_MAX; const int IINF = INT_MAX; const int MAX_N = int(1e5) + 5; const double EPS = 1e-8; int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; #define SORT(v) sort((v).begin(), (v).end()) #define SORTR(v) sort((v).rbegin(), (v).rend()) #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (ll i = m; i < n; i++) int dp[105][10005]; int main() { int n, W, V = 0, v[105], w[105]; cin >> n >> W; REP(i, n) { cin >> v[i] >> w[i]; V += v[i]; } REP(i, n + 1) fill(dp[i], dp[i] + 10005, IINF/2); dp[0][0] = 0; REP(i, n) { REP(j, V + 1) { if (j >= v[i]) dp[i+1][j] = min(dp[i+1][j],dp[i][j-v[i]]+w[i]); dp[i+1][j] = min(dp[i+1][j],dp[i][j]); } } REPR(i,V){ if(dp[n][i]<=W){ cout << i << endl; break; } } return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; int n; pair<int, int> a[111]; int m; long long p[111]; long long an; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d%d", &a[i].second, &a[i].first); sort(a + 1, a + 1 + n); scanf("%d", &m); for (int i = 1; i <= m; ++i) scanf("%I64d", &p[i]); p[++m] = 1e12; long long cur = 0; int ps = 1; for (int i = 1; i <= n; ++i) { while (a[i].second) { if (cur + a[i].second > p[ps]) { a[i].second -= p[ps] - cur; an += 1ll * ps * (p[ps] - cur) * a[i].first; cur = p[ps++]; } else { an += 1ll * a[i].second * ps * a[i].first; cur += a[i].second; a[i].second = 0; } } } printf("%I64d", an); return 0; }
9
CPP
n,m=map(int,input().split()) x=n while(int(n)): n=n/m x+=n print(int(x))
7
PYTHON3
#include<bits/stdc++.h> using namespace std; #define int long long const int N=505; int n,a[N][N],dp[N][N],b[N][N],c[N][N]; signed main(){ scanf("%lld",&n); for (int i=1;i<=n;i++){ for (int j=1;j<i;j++)scanf("%lld",&a[i][j]); for (int j=i+1;j<=n;j++)scanf("%lld",&a[i][j]); for (int j=1;j<=n;j++)b[i][j]=a[i][j]; } for (int i=1;i<=n;i++) for (int j=1;j<=n;j++)b[i][j]+=b[i-1][j]; for (int i=1;i<=n;i++) for (int j=1;j<=n;j++)b[i][j]+=b[i][j-1]; for (int i=1;i<=n;i++) for (int j=i;j<=n;j++){ c[i][j]=c[i][j-1]; for (int k=i;k<=j;k++)c[i][j]+=a[k][j]; } memset(dp,0x3f3f3f3f,sizeof dp); dp[0][0]=0; for (int i=0;i<=n;i++) for (int j=i;j<=n;j++) for (int x=j+1;x<=n;x++) dp[j][x]=min(dp[j][x],dp[i][j]+b[x][i]-b[j][i]+c[j+1][x]); int ans=1e18; for (int i=0;i<=n;i++) for (int j=i;j<=n;j++) ans=min(ans,dp[i][j]+b[n][i]-b[j][i]+c[j+1][n]); printf("%lld\n",ans); }
0
CPP
#include <bits/stdc++.h> using namespace std; const int N = 100100; int n, m, h, st[N], sz[N], vis[N], cnt, scnt, vd[N], sn[N], a[N]; vector<int> vec[N], vec2[N]; void dfs1(int x) { if (vis[x]) return; vis[x] = 1; for (int i = 0; i < vec[x].size(); i++) dfs1(vec[x][i]); st[++cnt] = x; } void dfs2(int x) { if (sn[x]) { if (sn[x] != scnt) vd[sn[x]] = 1; return; } sn[x] = scnt; sz[scnt]++; for (int i = 0; i < vec2[x].size(); i++) dfs2(vec2[x][i]); } int main() { scanf("%d%d%d", &n, &m, &h); for (int i = 1; i <= n; i++) scanf("%d", a + i); for (int i = 1; i <= m; i++) { int u, v; scanf("%d%d", &u, &v); if ((a[u] - a[v] + h) % h == 1) vec[v].push_back(u), vec2[u].push_back(v); if ((a[v] - a[u] + h) % h == 1) vec[u].push_back(v), vec2[v].push_back(u); } for (int i = 1; i <= n; i++) dfs1(i); for (int i = n; i; i--) if (!sn[st[i]]) { scnt++; dfs2(st[i]); } int ans = 0; sz[0] = n + 1; for (int i = 1; i <= scnt; i++) if (!vd[i] && sz[i] < sz[ans]) ans = i; printf("%d\n", sz[ans]); for (int i = 1; i <= n; i++) if (sn[i] == ans) printf("%d ", i); return 0; }
11
CPP
#include <bits/stdc++.h> using namespace std; int main() { string s; while (cin >> s) { int st = 0; while (st < s.length() && s[st] == 'a') st++; bool f = false; for (; st < s.length(); st++) { if (s[st] == 'a') break; s[st]--; f = true; } if (!f) s[s.length() - 1] = 'z'; cout << s << endl; } return 0; }
7
CPP
for k in range(int(input())): L = [] a=[] ch=input()+"\0" a=[ch[0]] for i in range(len(ch)-1): if ch[i]==ch[i+1]: a+=[ch[i]] else: L.append(a) a=[ch[i+1]] res=[] for i in L: if len(i)%2!=0: res+=i[0] print("".join(sorted(list(set(res)))))
7
PYTHON3
#include<bits/stdc++.h> using namespace std; int main(){ int i; cin>>i; if(i>999) cout<<"ABD"; else cout<<"ABC"; return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; int main() { long long n, a, b, c, ans; cin >> n >> a >> b >> c; if (a <= b - c) ans = n / a; else { long long k = (n - b) / (b - c); if (k < 0LL) k = 0LL; long long rest = n - k * (b - c); if (rest >= b) rest = n - (++k) * (b - c); ans = k + rest / min(a, b); } cout << ans << "\n"; }
7
CPP
x = list(input()) a = x.count("1") b = x.count("2") c = x.count("3") y = [] for e in x: if e != "+": y.append(e) y.sort() z = '+'.join(y) print(z)
7
PYTHON3
n = int(input()) l = [] for i in range(1, n * n + 1): l.append(i) h = n // 2 beg = 0 ending = len(l) - 1 for i in range(n): t = beg + h while beg < t: print(l[beg], end=" ") beg += 1 t = ending - h while ending > t: print(l[ending], end=" ") ending -= 1 print()
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int N = 2002; int dx[] = {1, 0, -1, 0}; int dy[] = {0, -1, 0, 1}; int n, m, deg[N][N]; bool fail; bool used[N][N]; char a[N][N], b[N][N]; queue<pair<int, int> > q; bool valid(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= m && used[x][y] == 0; } void add(int x, int y, int nx, int ny) { used[nx][ny] = 1; for (int it = 0; it < 4; it++) { int xx = nx + dx[it]; int yy = ny + dy[it]; if (valid(xx, yy)) { deg[xx][yy]--; if (deg[xx][yy] == 1) q.push(make_pair(xx, yy)); } } if (nx == x) { if (y > ny) swap(y, ny); b[x][y] = '<'; b[x][ny] = '>'; } else { if (x > nx) swap(x, nx); b[x][y] = '^'; b[nx][y] = 'v'; } } int main() { ios_base::sync_with_stdio(0); cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { cin >> a[i][j]; if (a[i][j] == '*') used[i][j] = 1, b[i][j] = '*'; } for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { if (used[i][j]) continue; for (int it = 0; it < 4; it++) { int nx = i + dx[it], ny = j + dy[it]; if (valid(nx, ny)) deg[nx][ny]++; } } for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) if (deg[i][j] == 1) q.push(make_pair(i, j)); while (q.size()) { int x = q.front().first; int y = q.front().second; q.pop(); if (used[x][y]) continue; used[x][y] = 1; bool fail = 1; for (int it = 0; it < 4; it++) { int nx = x + dx[it]; int ny = y + dy[it]; if (valid(nx, ny)) { fail = 0; add(x, y, nx, ny); break; } } if (fail) { used[x][y] = 0; break; } } for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) if (!used[i][j]) fail = 1; if (fail) puts("Not unique"); else for (int i = 1; i <= n; i++, cout << endl) for (int j = 1; j <= m; j++) cout << b[i][j]; return 0; }
8
CPP
n, k = [int(t) for t in input().split(' ')] d = [int(t) % k for t in input().split(' ')] cnt = [0] * k for di in d: cnt[di] += 1 total = (cnt[0] // 2) * 2 if k % 2 == 0: total += (cnt[k // 2] // 2) * 2 cnt[k // 2] = 0 for ki in range(1, k // 2 + 1): total += min(cnt[ki], cnt[k - ki]) * 2 print(total)
8
PYTHON3
def count_floor( arr, peak ) : ans = [arr[peak]] for i in range( peak + 1, len(arr) ) : if arr[i] <= ans[-1] : ans.append(arr[i]) else : ans.append(ans[-1]) i = peak - 1 brr = [arr[peak]] while i >= 0: if arr[i] <= brr[-1] : brr.append(arr[i]) else : brr.append(brr[-1]) i -= 1 brr.pop(0) return brr[::-1] + ans def skycrapers(arr): max = 0 ans_ = [] for i in range(len(arr)) : #print(count_floor( arr, i )) if max < sum(count_floor( arr, i )) : max = sum(count_floor( arr, i )) ans_ = count_floor( arr, i ) an = [str(i) for i in ans_ ] return " ".join(an) if __name__ == "__main__" : n = int(input()) ar = list( map ( int , input().strip().split() )) #print(count_floor( ar, 0 )) print(skycrapers(ar))
9
PYTHON3