solution
stringlengths
10
983k
difficulty
int64
0
25
language
stringclasses
2 values
#include <bits/stdc++.h> using namespace std; int TAB[500000 + 5]; int ask[500000 + 5][4]; int small[800][800]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int q; cin >> q; for (int i = 1; i <= q; i++) cin >> ask[i][0] >> ask[i][1] >> ask[i][2]; for (int i = 1; i <= q; i++) { if (ask[i][0] == 1) { TAB[ask[i][1]] += ask[i][2]; for (int j = 1; j <= 700; j++) small[j][ask[i][1] % j] += ask[i][2]; } else { if (ask[i][1] >= 700) { int tmp = 0; for (int j = ask[i][2]; j <= 500000; j += ask[i][1]) tmp += TAB[j]; cout << tmp << '\n'; } else cout << small[ask[i][1]][ask[i][2]] << '\n'; } } }
12
CPP
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; int a[t], c = 0; for (int i = 0; i < t; i++) { cin >> a[i]; c = c + a[i]; } if (c >= 1) { cout << "HARD"; } else cout << "EASY"; }
7
CPP
n, k = map(int, input().split()) vt = [[] for i in range(n + 1)] vb = [[] for i in range(n + 1)] queue = [] visit = [0 for i in range(n + 1)] s = set([i for i in range(1, n + 1)]) for i in range(k): a, b = map(int, input().split()) vt[a].append(b) vt[b].append(a) visit[1] = 1 queue = [1] if vt[n].count(1): for i in range(n): vb[i] = list(s - set(vt[i])) h = 0 t = 1 while h != t: v = queue[h] h += 1 for u in vb[v]: if not visit[u]: visit[u] = visit[v] + 1 queue.append(u) t += 1 print(visit[n] - 1) else: h = 0 t = 1 while h != t: v = queue[h] h += 1 for u in vt[v]: if not visit[u]: visit[u] = visit[v] + 1 queue.append(u) t += 1 print(visit[n] - 1)
9
PYTHON3
#include <bits/stdc++.h> using namespace std; const int maxn = 202; const int maxs = 1000004; int data[maxn * maxn], n, m, q; int iscir[maxn * maxn], cir[maxn * maxn][10], N[maxn * maxn]; int X[10], Y[10]; void readin() { scanf("%d%d%d", &n, &m, &q); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { char c = '\n'; while (c == '\n') scanf("%c", &c); data[i * m + j] = c - '0'; } for (int i = 0; i < 10; i++) scanf("%d%d", &X[i], &Y[i]); } int vis[maxn * maxn]; int next(int u) { int x = u / m, y = u % m; x += X[data[u]]; y += Y[data[u]]; int v; if (x >= n || y >= m || x < 0 || y < 0) v = u; else v = x * m + y; return v; } void find_cir(int u) { vis[u] = -1; int v = N[u]; if (vis[v] != 1) { if (vis[v] == -1) iscir[v] = 1; else find_cir(v); } vis[u] = 1; } void get_cir(int i, int u) { cir[i][data[u]] = 1; vis[u] = 1; int v = N[u]; if (vis[v]) return; get_cir(i, v); } char s[maxs]; bool is[maxs][10]; bool ishead[maxn * maxn]; void head_dfs(int u) { vis[u] = 1; if (vis[N[u]]) return; head_dfs(N[u]); } void get_head() { memset(vis, 0, sizeof(vis)); for (int i = 0; i < n * m; i++) vis[N[i]] = 1; for (int i = 0; i < n * m; i++) if (!vis[i]) ishead[i] = true; memset(vis, 0, sizeof(vis)); for (int i = 0; i < n * m; i++) if (ishead[i]) head_dfs(i); for (int i = 0; i < n * m; i++) if (iscir[i] && !vis[i]) ishead[i] = true; } bool judge() { int len = strlen(s); for (int i = len - 1; i >= 0; i--) { memset(is[i], false, sizeof(is[i])); if (i != len - 1) for (int j = 0; j < 10; j++) is[i][j] = is[i + 1][j]; is[i][s[i] - '0'] = true; } for (int i = 0; i < n * m; i++) if (ishead[i]) { int u = i, cur = 0; while (!iscir[u]) { while (s[cur] - '0' != data[u]) { u = N[u]; if (iscir[u]) break; } if (!iscir[u]) { u = N[u]; cur++; if (cur == len) return true; } } int flag = 1; for (int j = 0; j < 10; j++) if (is[cur][j] && !cir[u][j]) flag = 0; if (flag) return true; } return false; } void solve() { memset(iscir, 0, sizeof(iscir)); memset(vis, 0, sizeof(vis)); for (int i = 0; i < n * m; i++) { N[i] = next(i); for (int j = 0; j < 10; j++) cir[i][j] = 0; } for (int i = 0; i < n * m; i++) if (vis[i] != 1) find_cir(i); memset(vis, 0, sizeof(vis)); for (int i = 0; i < n * m; i++) if (iscir[i]) get_cir(i, i); get_head(); for (int i = 0; i < q; i++) { scanf("%s", s); if (judge()) printf("YES\n"); else printf("NO\n"); } } int main() { readin(); solve(); return 0; }
11
CPP
#!/usr/bin/env python # -*- coding: utf-8 -*- # # Card.py # # Copyright 2020 Md Sidratul Muntaher Tibrow <[email protected]> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. # # def main(args): input() n = list(input()) a = n.count('n') b = n.count('z') x = [] for i in range(a): x.append(1) for i in range(b): x.append(0) print(*x) if __name__ == '__main__': import sys sys.exit(main(sys.argv))
7
PYTHON3
#include<stdio.h> #include<algorithm> int main() { int a[5],x,y,i,*p; for(;;) { for(i=0;i<5;++i) { if(scanf("%d%d",&x,&y),!x&&!y)return 0; a[i]=x+y; } p=std::max_element(a,a+5); printf("%c %d\n","ABCDE"[p-a],*p); } }
0
CPP
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 1, M = 1e9 + 7; mt19937 rng(std::chrono::system_clock::now().time_since_epoch().count()); int n, dp[N], a; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a); dp[i + 1] = (2 * dp[i] + 2LL - dp[a - 1] + M) % M; } cout << dp[n] << endl; }
8
CPP
for _ in range(int(input())) : n = int(input()) k = int((n + 3) / 4) for __ in range(n - k) : print(9,end="") for __ in range(k) : print(8,end="") print()
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for(int i = 0; i < n; ++i) cin >> a[i]; set<int> st; for(int i = 0; i < n; ++i) { int tmp = a[i]; for(int j = 2; j * j <= tmp; ++j) { while(tmp % j == 0) { st.insert(j); st.insert(tmp / j); tmp /= j; } } st.insert(tmp); } int64_t ans = 0; for(int k : st) { if(k < 2) continue; int64_t tmp = 0; for(int i = 0; i < n; ++i) { if(a[i] % k == 0) tmp += a[i]; } ans = max(ans, tmp); } cout << ans << '\n'; return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; char arr[1000][1000]; long long yo[1000][1000]; long long query(long long row1, long long col1, long long row2, long long col2) { return yo[row2][col2] - yo[row2][col1 - 1] - yo[row1 - 1][col2] + yo[row1 - 1][col1 - 1]; } int main() { long long n, m, k; cin >> n >> m >> k; for (long long i = 1; i <= n; i++) for (long long j = 1; j <= m; j++) cin >> arr[i][j]; for (long long i = 1; i <= n; i++) { for (long long j = 1; j <= m; j++) { yo[i][j] = yo[i][j - 1] + yo[i - 1][j] - yo[i - 1][j - 1]; if (arr[i][j] == '1' && arr[i - 1][j] == '1' && arr[i + 1][j] == '1' && arr[i][j - 1] == '1' && arr[i][j + 1] == '1') yo[i][j]++; } } long long tot = 0; for (long long i = 2; i <= n - 1; i++) { for (long long j = i; j <= n - 1; j++) { long long hi1 = 2, hi2 = 1; while (hi2 <= m - 1) { while (hi2 < m - 1 && query(i, hi1, j, hi2) < k) hi2++; if (query(i, hi1, j, hi2) < k) break; while (query(i, hi1, j, hi2) >= k) { tot += m - hi2; hi1++; } } } } cout << tot; return 0; }
12
CPP
n = int(input()) if n%2!=0: print(-1) else: i=0 k=2 z=1 for i in range(n//2): print(i+k,i+z,end=" ") k+=1 z+=1
7
PYTHON3
n,m=map(int,input().split()) l=[] for i in range(n): l+=input().split() for i in range(m): a,b=input().split() c=list(b) c.remove(c[-1]) c="".join(c) print(a+" "+b+" #"+l[l.index(c)-1])
8
PYTHON3
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007ll int main(){ string S; cin >> S; int l=S.size(); long long dp[l+1][4]; for(int i=0;i<l+1;i++)for(int j=0;j<4;j++)dp[i][j]=0ll; dp[0][0]=1; for(int i=0;i<l;i++){ for(int j=0;j<4;j++){ dp[i+1][j]=dp[i][j]; if(S[i]=='?'){ dp[i+1][j]*=3; if(dp[i+1][j]>=MOD)dp[i+1][j]%=MOD; } if(j>0 && (S[i]=='A'+j-1 || S[i]=='?')){ dp[i+1][j]+=dp[i][j-1]; if(dp[i+1][j]>=MOD)dp[i+1][j]-=MOD; } } } cout << dp[l][3] << endl; return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define all(x) (x).begin(),(x).end() #define pb push_back #define fi first #define se second #define dbg(x) cout<<#x" = "<<((x))<<endl template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;} template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;} /* 基本要素 */ typedef complex<double> Point; typedef pair<Point, Point> Line; typedef vector<Point> VP; const double PI = acos(-1); const double EPS = 1e-8; // 許容誤差^2 const double INF = 1e9; #define X real() #define Y imag() // #define LE(n,m) ((n) < (m) + EPS) #define LE(n,m) ((n) - (m) < EPS) // #define GE(n,m) ((n) + EPS > (m)) #define GE(n,m) (EPS > (m) - (n)) #define EQ(n,m) (abs((n)-(m)) < EPS) // 頂点の順序(sortやmax_elementに必要) namespace std { bool operator<(const Point a, const Point b) { return a.X != b.X ? a.X < b.X : a.Y < b.Y; } } // 内積 dot(a,b) = |a||b|cosθ double dot(Point a, Point b) { return a.X*b.X + a.Y*b.Y; } // 外積 cross(a,b) = |a||b|sinθ double cross(Point a, Point b) { return a.X*b.Y - a.Y*b.X; } // 点の進行方向 // !!! 誤差に注意 !!! (掛け算したものとかなり小さいものを比べているので) int ccw(Point a, Point b, Point c) { b -= a; c -= a; if (cross(b,c) > EPS) return +1; // counter clockwise if (cross(b,c) < -EPS) return -1; // clockwise if (dot(b,c) < -EPS) return +2; // c--a--b on line if (norm(b) < norm(c)) return -2; // a--b--c on line or a==b return 0; // a--c--b on line or a==c or b==c } // 線分と線分 bool isecSS(Point a1, Point a2, Point b1, Point b2) { return ccw(a1, a2, b1)*ccw(a1, a2, b2) <= 0 && ccw(b1, b2, a1)*ccw(b1, b2, a2) <= 0; } // 線分と点 bool isecSP(Point a1, Point a2, Point b) { return !ccw(a1, a2, b); } // 点pの直線aへの射影点を返す Point proj(Point a1, Point a2, Point p) { return a1 + dot(a2-a1, p-a1)/norm(a2-a1) * (a2-a1); } double distSP(Point a1, Point a2, Point p) { Point r = proj(a1, a2, p); if (isecSP(a1, a2, r)) return abs(r-p); //= !ccw(a1, a2, r) return min(abs(a1-p), abs(a2-p)); } double distSS(Point a1, Point a2, Point b1, Point b2) { if (isecSS(a1, a2, b1, b2)) return 0; return min(min(distSP(a1, a2, b1), distSP(a1, a2, b2)), min(distSP(b1, b2, a1), distSP(b1, b2, a2))); } // 凸包 // 入力1個 -> 空 // 2個以上の全て同じ点 -> 同じもの2つ VP convexHull(VP ps) { // 元の点集合がソートされていいならVP&に int n = ps.size(), k = 0; sort(ps.begin(), ps.end()); VP ch(2*n); for (int i = 0; i < n; ch[k++] = ps[i++]) // lower-hull while (k >= 2 && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k; // 余計な点も含むなら == -1 とする for (int i = n-2, t = k+1; i >= 0; ch[k++] = ps[i--]) // upper-hull while (k >= t && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k; ch.resize(k-1); return ch; } // 凸多角形の内部判定 O(n) // 点が領域内部なら1、境界上なら2、外部なら0を返す int inConvex(Point p, const VP& ps) { int n = ps.size(); int dir = ccw(ps[0], ps[1], p); rep (i, n) { int ccwc = ccw(ps[i], ps[(i + 1) % n], p); if (!ccwc) return 2; // 線分上に存在 if (ccwc != dir) return 0; } return 1; } Point READ_P(){ int x,y; cin >>x >>y; return Point(x,y); } double ang2rad(double x){ return PI*x/180; } double distHH(VP ps, VP qs){ int n = ps.size(), m = qs.size(); double ret = INF; rep(i,n)rep(j,m){ ret = min(ret, distSS(ps[i],ps[(i+1)%n],qs[j],qs[(j+1)%m])); } return ret; } double distPH(Point p, VP ps){ if(inConvex(p,ps)) return 0; int n = ps.size(); double ret = INF; rep(i,n){ ret = min(ret, distSP(ps[i],ps[(i+1)%n],p)); } return ret; } int main(){ int n; while(cin >>n,n){ vector<VP> building(n); vector<double> h(n); rep(i,n){ int V; cin >>V >>h[i]; rep(j,V) building[i].pb(READ_P()); } double theta,phi; cin >>theta >>phi; theta = ang2rad(theta); phi = ang2rad(phi); Point start = READ_P(), goal = READ_P(); int S = n, T = n+1; // make convex hull rep(i,n){ VP shadow; for(Point p:building[i]){ double L = h[i]/tan(phi); shadow.pb(p + polar(L, theta+PI)); } for(Point p:shadow) building[i].pb(p); building[i] = convexHull(building[i]); } // Floyd-Warshall vector<vector<double>> d(n+2, vector<double>(n+2)); rep(i,n)rep(j,i){ d[i][j] = d[j][i] = distHH(building[i], building[j]); } rep(i,n){ d[S][i] = d[i][S] = distPH(start, building[i]); d[T][i] = d[i][T] = distPH(goal, building[i]); } d[S][T] = d[T][S] = abs(start-goal); rep(k,n+2)rep(i,n+2)rep(j,n+2) d[i][j] = min(d[i][j], d[i][k]+d[k][j]); printf("%.10f\n", d[S][T]); } return 0; }
0
CPP
n = list(map(int,input().split())) a = n[0] b = n[1] c = 240 - b time = 0 count = 0 for i in range(1,a+1): time += 5*i if time <= c: count += 1 else: break print(count)
7
PYTHON3
def checkprime(n): if n==1: return False elif n==2 or n==3: return True else: for i in range(2,int(n**0.5)+1): if n%i==0: return False return True n=int(input()) if n==1: print("3") elif n%2!=0: print("1") else: for i in range(1,1001): if not checkprime(1+i*n): print(i) break
7
PYTHON3
n, m = map(int, input().split()) a = list(map(int, input().split())) print("Yes" if len([i for i in a if i/sum(a) >= 1/(4 * m)]) >= m else "No")
0
PYTHON3
#include <cstdio> #include <cstring> #include <string> #include <cmath> #include <cassert> #include <iostream> #include <algorithm> #include <stack> #include <queue> #include <vector> #include <set> #include <map> #include <bitset> #include <unordered_set> using namespace std; #define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define rep(i,n) repl(i,0,n) #define mp(a,b) make_pair(a,b) #define pb(a) push_back(a) #define all(x) (x).begin(),(x).end() #define dbg(x) cout<<#x"="<<x<<endl #define fi first #define se second #define INF 2147483600 char c1[4010], c2[4010]; int main(){ scanf("%s %s", c1, c2); string s1(c1), s2(c2); if(s1.size() > s2.size()) swap(s1,s2); for(int l = s1.size(); l>0; l--){ set<vector<int> > st; vector<int> rui(26,0); rep(i,l-1) rui[s1[i]-'a']++; rep(i, s1.size()-l+1){ rui[s1[i+l-1]-'a']++; vector<int> vec(rui); st.insert(vec); rui[s1[i]-'a']--; } rui = vector<int>(26,0); rep(i,l-1) rui[s2[i]-'a']++; rep(i, s2.size()-l+1){ rui[s2[i+l-1]-'a']++; if(st.find(rui)!=st.end()){ cout<<l<<endl; return 0; } rui[s2[i]-'a']--; } } cout<<0<<endl; return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; inline int D() { int m; cin >> m; return m; } inline long long lD() { long long m; cin >> m; return m; } inline double dD() { double m; cin >> m; return m; } void fast() { ios_base ::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { fast(); int a = D(), b = D(), x = D(); string ans = ""; char d; if (a > b) { ans += '0'; a--; d = '0'; } else { ans += '1'; b--; d = '1'; } x--; while (x--) { if (d == '0') d = '1'; else d = '0'; ans += d; if (d == '1') b--; else a--; } if (d == '1') { while (b--) ans += "1"; while (a--) ans += "0"; } else { while (a--) ans += "0"; while (b--) ans += "1"; } cout << ans; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 140003; int N, n, deg[maxn], b[5], sz[maxn], depth; vector<int> g[maxn]; void ensure(bool cond) { if (!cond) { printf("0\n"); exit(0); } } void add(int u, int v) { ensure(u >= 1 && u <= n + 1 && v >= 1 && v <= n + 1); g[u].push_back(v); g[v].push_back(u); } void del(int u, int v) { ensure(u >= 1 && u <= n + 1 && v >= 1 && v <= n + 1); g[u].erase(find(g[u].begin(), g[u].end(), v)); g[v].erase(find(g[v].begin(), g[v].end(), u)); } int dfs1(int u, int last, int rt) { if (u == rt) return -1; int mx = 0, mxi = 0; sz[u] = 1; for (int v : g[u]) { if (v == last) continue; if (dfs1(v, u, rt) == -1) { if (last) return -1; else { sz[v] = -1; continue; } } sz[u] += sz[v]; if (sz[v] > mx) mx = sz[v], mxi = v; } return mxi; } int dfs(int u, int last) { sz[u] = 1; for (int v : g[u]) { if (v == last) continue; int tmp = dfs(v, u); if (tmp) { sz[u] = -1; return tmp; } sz[u] += sz[v]; } return sz[u] == (n >> 1) ? u : 0; } bool DFS(int u, int last, int dep) { if (g[u].size() == 1 && last) { if (!depth) depth = dep; else if (depth != dep) return 0; return 1; } if (!((last == 0 && g[u].size() == 2) || (last && g[u].size() == 3))) return 0; for (int v : g[u]) { if (v == last) continue; if (!DFS(v, u, dep + 1)) return 0; } return 1; } bool check(int u) { depth = 0; return DFS(u, 0, 1); } int main() { scanf("%d", &N); n = (1 << N) - 2; for (int i = 1; i < n; i++) { int u, v; scanf("%d%d", &u, &v); add(u, v); deg[u]++, deg[v]++; } if (n == 2) { printf("2\n1 2"); return 0; } for (int i = 1; i <= n; i++) b[deg[i]]++; if (b[2] == 2 && b[4] == 0) { int u1 = 0, u2 = 0; for (u1 = 1; u1 <= n && deg[u1] != 2; u1++) ; for (u2 = u1 + 1; u2 <= n && deg[u2] != 2; u2++) ; bool flag = 0; for (int v : g[u1]) if (deg[v] == 1) { flag = 1; break; } if (flag) swap(u1, u2); add(u2, n + 1); ensure(check(u1)); printf("1\n%d", u2); } else if (b[2] == 1 && b[4] == 1) { int u1 = 0, u2 = 0, v1 = 0, v2 = 0; for (u1 = 1; u1 <= n && deg[u1] != 2; u1++) ; for (u2 = 1; u2 <= n && deg[u2] != 4; u2++) ; int v3 = dfs1(u2, 0, u1); for (int v : g[u2]) if (sz[v] != -1 && v != v3) v1 == 0 ? (v1 = v) : (v2 = v); del(u2, v1); del(u2, v2); add(u2, n + 1); add(n + 1, v1); add(n + 1, v2); ensure(check(u1)); printf("1\n%d", u2); } else if (b[2] == 0 && b[4] == 0) { int u1 = 0, u2 = 0, v1 = 0, v2 = 0; for (v1 = 1; v1 <= n && deg[v1] != 1; v1++) ; u1 = dfs(v1, 0); for (int v : g[u1]) if (sz[v] == -1) { u2 = v; break; } v1 = 0; for (int v : g[u1]) if (v != u2) v1 == 0 ? (v1 = v) : (v2 = v); del(u1, v1); del(u1, v2); add(u1, n + 1); add(n + 1, v1); add(n + 1, v2); ensure(check(u1)); printf("2\n%d %d", min(u1, u2), max(u1, u2)); } else ensure(0); return 0; }
12
CPP
#!/usr/bin/env python #-*-coding:utf-8 -*- n=int(input()) i=j=n>>1 a=1 b=2 for _ in range(n): for y in range(n): if min(i,j)<=y<=max(i,j): c=a a+=2 else: c=b b+=2 print(c,end=' 'if n-1>y else'\n') i-=1 j+=1 if 0>i:i,j=n-2,1
9
PYTHON3
n, m = input().split() n = int(n) m = int(m) prime = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47] k = 0 for i in range(len(prime)-1): if prime[i] == n and prime[i+1] == m : k = 1 break if k == 1: print("YES") else: print("NO")
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int a, b; pair<int, int> res[1010]; int main() { int n, t1, t2, k; cin >> n >> t1 >> t2 >> k; for (int i = 0; i < n; i++) { cin >> a >> b; res[i].first = min(-(a * t1) * (100 - k) - 100 * (b * t2), -(b * t1) * (100 - k) - 100 * (a * t2)); res[i].second = i; } sort(res, res + n); for (int i = 0; i < n; i++) { cout << res[i].second + 1 << " "; cout << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << -1.0 * res[i].first / 100 << endl; } return 0; }
8
CPP
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int INF = 1e9; const ll LINF = 1e18; template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; } template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; } template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; } template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; } /* <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2296> 問題文============================================================ ================================================================= 解説============================================================= ================================================================ */ ll solve(){ ll res = 0; ll N,M,W,T; cin >> N >> M >> W >> T; vector<string> S(M); vector<ll> V(M),P(M),L(N),X(N),Y(N); vector<vector<ll>> R(N),Q(N); for(int i = 0; i < M;i++) cin >> S[i] >> V[i] >> P[i]; map<string,int> S2idx; for(int i = 0; i < M;i++) S2idx[S[i]] = i; for(int i = 0; i < N;i++){ cin >> L[i] >> X[i] >> Y[i]; R[i].resize(L[i]); Q[i].resize(L[i]); for(int j = 0; j < L[i]; j++){ string str; cin >> str >> Q[i][j]; R[i][j] = S2idx[str]; Q[i][j] = P[R[i][j]] - Q[i][j]; } } // 巡る町を決めたとき、最短でその町をめぐる時間を求める // O(2^N*N*N) vector<vector<ll>> traveling(1<<N,vector<ll>(N,LINF)); vector<ll> traveling_time(1<<N,LINF); for(int i = 0; i < N;i++) traveling[1<<i][i] = abs(X[i]) + abs(Y[i]); for(int i = 0; i < (1<<N);i++){ for(int j = 0; j < N;j++){ if(traveling[i][j] == LINF) continue; for(int k = 0; k < N;k++){ if((i>>k)&1) continue; traveling[i|(1<<k)][k] = min(traveling[i|(1<<k)][k],traveling[i][j]+abs(X[j]-X[k])+abs(Y[j]-Y[k])); } } } for(int i = 0; i < (1<<N);i++){ for(int j = 0; j < N;j++){ traveling_time[i] = min(traveling_time[i],traveling[i][j]+abs(X[j])+abs(Y[j])); } } // cout << traveling_time << endl; // cout << Q << endl; // 巡る町が決まっているときの重さ制限Wでの最大の利益を求める // O(2^N*MW) vector<ll> benefit(1<<N); vector<ll> benefit_dp(W+1,0); for(int i = 0; i < (1<<N);i++){ vector<ll> items(M,-LINF); for(int j = 0; j < N;j++){ if(!((i>>j)&1)) continue; for(int k = 0; k < L[j]; k++){ items[R[j][k]] = max(items[R[j][k]],Q[j][k]); } } fill(benefit_dp.begin(),benefit_dp.end(),0); for(int j = 0; j < M;j++){ for(ll k = V[j]; k <= W;k++){ benefit_dp[k] = max(benefit_dp[k],benefit_dp[k-V[j]]+items[j]); } } benefit[i] = benefit_dp[W]; } // 巡る町が決まっているとき時間制限Tでの最大の利益を求める // O(2^N*T) vector<ll> maxbenefit(T+1,0); for(int i = 0; i < (1<<N);i++){ for(ll t = traveling_time[i]; t <= T; t++){ maxbenefit[t] = max(maxbenefit[t],maxbenefit[t-traveling_time[i]]+benefit[i]); } } res = maxbenefit[T]; return res; } int main(void) { cin.tie(0); ios_base::sync_with_stdio(false); cout << solve() << endl; return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:255000000") bool firstout = 1; template <class T> T &minn(T &a, T b) { if (b < a) a = b; return a; } template <class T> T &maxx(T &a, T b) { if (a < b) a = b; return a; } int &madd(int &a, int b) { a += b; if (a >= 1000000009) a -= 1000000009; return a; } int &msub(int &a, int b) { a -= b; if (a < 0) a += 1000000009; return a; } int &mmult(int &a, int b) { return a = (long long)a * b % 1000000009; } int mdiv(long long a, long long b, long long m) { a = (a % m + m) % m; b = (b % m + m) % m; if (a % b == 0) return a / b; return (a + m * mdiv(-a, m, b)) / b; } int n, m, q; int A[101234]; int B[101234]; long long D[101234]; int main() { int i, j, k; char c; int a, d; int ts; for (ts = 1; scanf("%" "d", &(n)) > 0; ++ts) { scanf( "%" "d", &(q)); for (i = (0); i < (n); ++i) { scanf( "%" "d", &(A[i])); } for (i = (0); i < (n); ++i) { scanf( "%" "d", &(B[i])); --B[i]; } for (; q--;) { long long a, b; scanf( "%" "I64d", &(a)); scanf( "%" "I64d", &(b)); for (i = (0); i < (101234); ++i) D[i] = -(long long)1012345678 * 1012345678; long long mx = 0, mxx = 0; int c = 0; for (i = (0); i < (n); ++i) { long long x; j = B[i]; if (c == j) { x = (long long)b * A[i] + mxx; maxx(x, (long long)a * A[i] + D[j]); maxx(mx, x); } else { x = (long long)b * A[i] + mx; maxx(x, (long long)a * A[i] + D[j]); if (x > mx) { mxx = mx; mx = x; c = B[i]; } else maxx(mxx, x); } maxx(D[j], x); } long long res = mx; printf((firstout) ? "%" "I64d" : " %" "I64d", (res)), firstout = 0; printf("\n"), firstout = 1; } } return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { return !b ? a : gcd(b, a % b); } template <typename T> T lcm(T a, T b) { return a * (b / gcd(a, b)); } template <typename T> T sqr(T a) { return a * a; } template <typename T> T cube(T a) { return a * a * a; } template <typename T> inline void smin(T &a, T b) { a = a < b ? a : b; } template <typename T> inline void smax(T &a, T b) { a = a > b ? a : b; } int in() { int n; scanf("%d", &n); return n; } long long Lin() { long long n; scanf("%lld", &n); return n; } double Din() { double n; scanf("%lf", &n); return n; } const long long inf = (long long)1e17; const long long mod = (long long)1e9 + 7; const int N = 1e6 + 5; vector<int> g[N]; int x[N], vis[N]; int dfs(int u) { vis[u] = 1; int ans = 1; for (auto v : g[u]) { if (!vis[v]) ans += dfs(v); } return ans; } int solve() { int n = in(), m = in(), loop = 0; for (int i = 1; i <= m; i++) { int u = in(), v = in(); x[u] = 1, x[v] = 1; if (u == v) loop++; else { g[u].push_back(v); g[v].push_back(u); } } bool ok = true; int comp = 0; for (int i = 1; i <= n; i++) { if (x[i]) comp++; if (ok && x[i]) ok = false, comp -= dfs(i); } if (comp) return printf("0\n"); long long ans = 0; for (int i = 1; i <= n; i++) { long long d = (long long)g[i].size(); ans += (d * (d - 1)) / 2; } ans += ((long long)loop * (loop - 1)) / 2; ans += (long long)loop * ((long long)m - (long long)loop); cout << ans << '\n'; return 0; } int main() { int test = 1, tc = 0; while (test--) { solve(); } return 0; }
10
CPP
n=int(input()) a=list(map(int,input().split())) a.sort(reverse=1) ans=0 temp=0 for i in a: if i%2==0: ans+=i elif temp!=0: ans+=i+temp temp=0 else: temp=i print(ans)
7
PYTHON3
#include <iostream> using namespace std; int main() { int n; cin >> n; int dp[n+1]; dp[1] = 4; int ans = 0; if(n%2==0){ int x = (n/2) + 1; ans = x*x; } else { int x = ((n-1)/2) + 1; ans = ((x+1) *x)*2; } cout << ans << '\n'; }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, x, y, z; while (cin >> n) { map<pair<int, int>, set<pair<int, int> > > box; int ans = 1, i1, i2, mxa = 0, x, y, z; vector<int> t(3); for (int i = 0; i < n; i++) { cin >> t[0] >> t[1] >> t[2]; sort(t.begin(), t.end()); x = t[0]; y = t[1]; z = t[2]; box[make_pair(x, y)].insert(make_pair(z, i + 1)); box[make_pair(x, z)].insert(make_pair(y, i + 1)); box[make_pair(y, z)].insert(make_pair(x, i + 1)); if (x > mxa) { mxa = x; i1 = i + 1; } } for (map<pair<int, int>, set<pair<int, int> > >::iterator it = box.begin(); it != box.end(); it++) { if (it->second.size() > 1) { set<pair<int, int> >::iterator it1 = it->second.begin(), it2; it2 = it1; it2++; int top = min(it->first.first, it->first.second); while (it2 != it->second.end()) { int sum = it2->first + it1->first; int mmin = min(top, sum); if (mmin > mxa) { mxa = mmin; i1 = it2->second; i2 = it1->second; ans = 2; } it1++; it2++; if (sum > top) { break; } } } } if (ans == 2) { cout << ans << endl << i1 << " " << i2 << endl; } else { cout << ans << endl << i1 << endl; } } }
10
CPP
def pair(x) : return (x * (x - 1)) // 2 n, k = list(map(int, input().split())) a, b = n // k, n % k res = a + 1; mini = pair(res) * b + pair(a) * (k - b) maxi = pair(n - k + 1) print(mini, maxi, sep =" ")
8
PYTHON3
n=int(input()) s=input() c1=0 c2=0 for i in range(n): if s[i]=='z': c1=c1+1 elif s[i]=='n': c2=c2+1 print('1 '*c2 + '0 '*c1)
7
PYTHON3
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) print(*sorted(a, key=lambda x: x % 2))
7
PYTHON3
a = [int(i) for i in input().split()] a.sort() if a[0] == a[1] and a[1] == a[2] and a[2] == a[3] and a[4] == a[5] and a[5] == a[6] and a[6] == a[7] and a[8] == a[9] and a[9] == a[10] and a[10] == a[11]: print("yes") else: print("no")
0
PYTHON3
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n, k, w, s[15][N]; char str[N]; bool judge(int x, int y) { if ((y - x + k + 1) % k == 0 && str[y - 1] == '0') return true; if ((y - x + k + 1) % k != 0 && str[y - 1] == '1') return true; return false; } void init() { memset(s, 0, sizeof(s)); scanf("%d%d%d%s", &n, &k, &w, str); int len = strlen(str); for (int i = 0; i < k; i++) { for (int j = i + 1; j <= len; j++) { s[i][j] = s[i][j - 1]; if (judge(i, j)) s[i][j]++; } } } int handle(int x) { if (k == 1) { if (str[x - 1] == '0') return 1; } else { if (str[x - 1] == '1') return 1; } return 0; } void solve() { int x, y; for (int i = 0; i < w; i++) { scanf("%d%d", &x, &y); int t = x % k; printf("%d\n", s[t][y] - s[t][x] + handle(x)); } } int main() { init(); solve(); return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int k1, k2, k3; cin >> k1 >> k2 >> k3; if (k1 == 1 || k2 == 1 || k3 == 1) { cout << "YES"; return 0; } if ((k1 == 2) + (k2 == 2) + (k3 == 2) >= 2) { cout << "YES"; return 0; } if (k1 == 3 && k2 == 3 && k3 == 3) { cout << "YES"; return 0; } if ((k1 == 4) + (k2 == 4) + (k3 == 4) == 2 && (k1 == 2) + (k2 == 2) + (k3 == 2) == 1) { cout << "YES"; return 0; } cout << "NO"; return 0; }
9
CPP
inp = lambda : [*map(int, input().split())] ax, ay = inp() bx, by = inp() cx, cy = inp() print(3) print(ax + bx - cx, ay + by - cy) print(bx + cx - ax, by + cy - ay) print(ax + cx - bx, ay + cy - by)
8
PYTHON3
#!/usr/bin/env python3 import sys, math, itertools, collections, bisect input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') inf = float('inf') ;mod = 10**9+7 mans = inf ;ans = 0 ;count = 0 ;pro = 1 n = int(input()) A = list(map(int,input().split())) A.append(1) ans = [] i = j = 0 while i < n: i += 1 while i < n+1 and A[i] != 1: i += 1 ans.append(A[i-1]) print(len(ans)) print(*ans)
7
PYTHON3
import math import re n = int(input()) arr = list(map(int, input().split())) arr = sorted(arr) print(arr[math.ceil(n/2) - 1]) # arr = list(map(int, input().split())) # m = int(input()) # spis = list(map(int, input().split())) # # arr1 = sorted(arr, reverse=True) # a = [n - arr1.index(arr[el - 1]) for el in spis] # print(' '.join(map(str, a)))
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int flag[1000]; int a[1000]; int main() { int n, k; cin >> n >> k; for (int i = 0; i < k; i++) { cin >> a[i]; flag[a[i]] = true; } for (int i = 0; i < k; i++) { cout << a[i] << ' '; int count = 1; for (int j = 1; count < n; j++) if (!flag[j]) { flag[j] = true; cout << j << ' '; count++; } cout << endl; } return 0; }
7
CPP
#include <iostream> using namespace std; int a; int main() { cin>>a; cout<<a+a*a+a*a*a; return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; template <class T> void debug(T a, T b) { ; } template <class T> void chmin(T& a, const T& b) { if (a > b) a = b; } template <class T> void chmax(T& a, const T& b) { if (a < b) a = b; } namespace std { template <class S, class T> ostream& operator<<(ostream& out, const pair<S, T>& a) { out << '(' << a.first << ',' << a.second << ')'; return out; } } // namespace std long long int readL() { long long int res; scanf("%I64d", &res); return res; } void printL(long long int res) { printf("%I64d", res); } const int INF = 5e8; int n; int w[200005]; static const int MAX_N = 200005; vector<pair<int, int> > g[MAX_N]; int cut[MAX_N], size[MAX_N], whole; int root, rcost; int getsize(int v, int p) { size[v] = 1; for (int i = 0; i < (g[v].size()); ++i) { int to = g[v][i].first; if (to != p && cut[to] == 0) size[v] += getsize(to, v); } return size[v]; } void getbestroot(int v, int p) { int maxi = 0; for (int i = 0; i < (g[v].size()); ++i) { int to = g[v][i].first; if (to != p && cut[to] == 0) { getbestroot(to, v); maxi = max(maxi, size[to]); } } int rest = whole - size[v]; maxi = max(maxi, rest); if (maxi < rcost) { rcost = maxi; root = v; } } vector<int> cand; int cnt; int ways[MAX_N]; double dfs2(int v, int p, int d) { double res = w[v] * sqrt((double)d); for (auto e : g[v]) { if (e.first == p) continue; res += dfs2(e.first, v, d + e.second); } return res; } void dfs(int v) { getsize(v, -1); if (size[v] == 1) { cand.push_back(v); return; } whole = size[v]; rcost = INF; getbestroot(v, -1); v = root; cand.push_back(root); cut[v] = 1; double mx = -1; int nxt = -1; for (int i = 0; i < (g[v].size()); ++i) { pair<int, int>& e = g[v][i]; if (cut[e.first] == 0) { double a = dfs2(e.first, v, e.second); if (mx < a) { mx = a; nxt = e.first; } } } if (~nxt) dfs(nxt); cut[v] = 0; } double calc(int v, int p, int d) { double res = w[v] * sqrt((double)d) * d; for (auto e : g[v]) { if (e.first == p) continue; res += calc(e.first, v, d + e.second); } return res; } int main() { cin >> n; for (int i = 0; i < (n); ++i) scanf("%d", &w[i]); for (int i = 0; i < (n - 1); ++i) { int a, b, l; scanf("%d%d%d", &a, &b, &l); --a; --b; g[a].push_back(make_pair(b, l)); g[b].push_back(make_pair(a, l)); } dfs(0); double res = 1e100; int R; for (auto v : cand) { double t = calc(v, -1, 0); if (res > t) { res = t; R = v; } } printf("%d %.10f\n", R + 1, res); return 0; }
9
CPP
from __future__ import division, print_function import os,sys 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 from bisect import bisect_left as lower_bound, bisect_right as upper_bound def so(): return int(input()) def st(): return input() def mj(): return map(int,input().strip().split(" ")) def msj(): return map(str,input().strip().split(" ")) def le(): return list(map(int,input().split())) def lebe():return list(map(int, input())) def dmain(): sys.setrecursionlimit(1000000) threading.stack_size(1024000) thread = threading.Thread(target=main) thread.start() def joro(L): return(''.join(map(str, L))) def decimalToBinary(n): return bin(n).replace("0b","") def isprime(n): for i in range(2,int(n**0.5)+1): if n%i==0: return False return True def read(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') def tr(n): return n*(n+1)//2 def main(): for i in range(so()): m=so() L=le() a=0 b=0 for i in range(m*2): if(L[i]%2!=0): b+=1 else: a+=1 if(a!=b): print("No") else: print("Yes") # region fastio # template taken from https://github.com/cheran-senthil/PyRival/blob/master/templates/template.py 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") def print(*args, **kwargs): """Prints the values to a stream, or to sys.stdout by default.""" sep, file = kwargs.pop("sep", " "), 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", "\n")) if kwargs.pop("flush", False): file.flush() if sys.version_info[0] < 3: sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout) else: sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # endregion if __name__ == "__main__": #read() main() #dmain() # Comment Read()
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int n; int dp[80][80][80][2]; char s[80]; int sv[80], sk[80], so[80]; int pv[80], pk[80], po[80]; int nv, nk, no; int main() { scanf("%d%s", &n, s); for (int i = 0, ThxDem = n; i < ThxDem; ++i) { sv[i + 1] = sv[i]; sk[i + 1] = sk[i]; so[i + 1] = so[i]; if (s[i] == 'V') pv[nv++] = i, sv[i + 1]++; else if (s[i] == 'K') pk[nk++] = i, sk[i + 1]++; else po[no++] = i, so[i + 1]++; } for (int v = 0, ThxDem = nv + 1; v < ThxDem; ++v) for (int k = 0, ThxDem = nk + 1; k < ThxDem; ++k) for (int o = 0, ThxDem = no + 1; o < ThxDem; ++o) for (int i = 0, ThxDem = 2; i < ThxDem; ++i) dp[v][k][o][i] = 1 << 20; dp[0][0][0][0] = 0; for (int v = 0, ThxDem = nv + 1; v < ThxDem; ++v) for (int k = 0, ThxDem = nk + 1; k < ThxDem; ++k) for (int o = 0, ThxDem = no + 1; o < ThxDem; ++o) for (int i = 0, ThxDem = 2; i < ThxDem; ++i) { int z = dp[v][k][o][i]; if (v < nv) { int r = z; int p = pv[v]; r += max(sk[p] - k, 0) + max(so[p] - o, 0); dp[v + 1][k][o][1] = min(dp[v + 1][k][o][1], r); } if (k < nk && !i) { int r = z; int p = pk[k]; r += max(sv[p] - v, 0) + max(so[p] - o, 0); dp[v][k + 1][o][0] = min(dp[v][k + 1][o][0], r); } if (o < no) { int r = z; int p = po[o]; r += max(sk[p] - k, 0) + max(sv[p] - v, 0); dp[v][k][o + 1][0] = min(dp[v][k][o + 1][0], r); } } printf("%d\n", min(dp[nv][nk][no][0], dp[nv][nk][no][1])); return 0; }
10
CPP
pos_1, pos_2=0, 0 for i in range(1, 6): string = input() if '1' in string: pos = string.find('1') + 1 pos_1 = i pos_2 = pos//2 + 1 moves = abs(3-pos_1) + abs(3-pos_2) print (moves)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > ans[2]; char a[100][100]; inline void domove(int x, int y, int it) { if (a[x][y] == 'U') { a[x][y] = 'L'; a[x][y + 1] = 'R'; a[x + 1][y] = 'L'; a[x + 1][y + 1] = 'R'; } else if (a[x][y] == 'L') { a[x][y] = 'U'; a[x][y + 1] = 'U'; a[x + 1][y] = 'D'; a[x + 1][y + 1] = 'D'; } ans[it].push_back(make_pair(x + 1, y + 1)); } inline void REC(int x, int y, int it) { if (a[x + 1][y] == 'U') { if (a[x + 1][y + 1] == 'L') REC(x + 1, y + 1, it); domove(x + 1, y, it); } domove(x, y, it); } inline void REC2(int x, int y, int it) { if (a[x][y + 1] == 'L') { if (a[x + 1][y + 1] == 'U') REC2(x + 1, y + 1, it); domove(x, y + 1, it); } domove(x, y, it); } inline int readInt() { register int d = 0; register char c = getchar(); while (c == ' ' || c == '\n') c = getchar(); register int sgn = 1; if (c == '-') { sgn = -1; c = getchar(); } while (!(c == ' ' || c == '\n' || c == EOF)) { d = d * 10 + c - '0'; c = getchar(); } return d * sgn; } void out(int x) { register stringstream ss; ss << x; register string d; ss >> d; for (int i = 0; i < d.size(); i++) putchar(d[i]); } int main() { register int n = readInt(); register int m = readInt(); for (int it = 0; it < 2; ++it) { for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { register char c = getchar(); while (c == ' ' || c == '\n') c = getchar(); a[i][j] = c; } } for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if ((a[i][j] == 'L' && n % 2 == 0)) REC(i, j, it); else if ((a[i][j] == 'U' && m % 2 == 0 && n % 2 == 1)) REC2(i, j, it); } } } reverse(ans[1].begin(), ans[1].end()); out(ans[0].size() + ans[1].size()); putchar('\n'); for (int j = 0; j < 2; ++j) for (int i = 0; i < ans[j].size(); ++i) { out(ans[j][i].first); putchar(' '); out(ans[j][i].second); putchar('\n'); } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; map<pair<int, int>, int> vst; pair<int, int> a[70010], ans[70010]; long long sum[70010]; int used[70010], nn, nxt[70010]; bool solve(int st, int s) { if (s == 0) return true; if (sum[st] < s) return false; if (vst.count(pair<int, int>(st, s))) return false; vst[pair<int, int>(st, s)] = 1; if (a[st].first <= s) { used[st] = 1; if (solve(st + 1, s - a[st].first)) return true; used[st] = 0; } return solve(st + 1, s); } int main() { int n, s; cin >> n >> s; for (int i = 0; i < n; i++) { scanf("%d", &a[i].first); a[i].second = i; } sort(a, a + n); reverse(a, a + n); for (int i = n - 1; i >= 0; i--) sum[i] = sum[i + 1] + a[i].first; s -= a[0].first; used[0] = 1; if (s < 0) return puts("-1"); if (!solve(1, s)) return puts("-1"); used[0] = 0; int pos = -1; for (int i = n - 1; i >= 0; i--) if (!used[i]) nxt[i] = pos, pos = i; for (int i = 0; i < n; i++) { if (used[i] || nxt[i] == -1) { ans[a[i].second] = pair<int, int>(a[i].first, -1); } else ans[a[i].second] = pair<int, int>(a[i].first - a[nxt[i]].first, a[nxt[i]].second); } for (int i = 0; i < n; i++) { if (ans[i].second >= 0) printf("%d 1 %d\n", ans[i].first, ans[i].second + 1); else printf("%d %d\n", ans[i].first, ans[i].second + 1); } return 0; }
10
CPP
n = int(input()) l = [] st = set() l = map(int, input().split()) a = list(l) x = 0 y = 0 a.append(-1) for i in range(n): x = x + 1 if a[i] == 0: y = y + 1 if (a[i] +a[i + 1])==1: st.add(x) st.add(y) x=0 y=0 st.add(x) st.add(y) st.discard(0) if len(st) == 1: print("YES") else: print("NO")
9
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long LLINF = 0x3f3f3f3f3f3f3f3f; class Item { public: long long val, cnt, sum; Item() { val = cnt = sum = 0LL; }; }; int n = 0, k = 0, tot = 0; long long a[200005] = {}; Item s[200005] = {}; Item pre[200005] = {}; Item suf[200005] = {}; void init() { cin >> n >> k; for (int i = 1; i <= n; ++i) { cin >> a[i]; } sort(a + 1, a + n + 1); long long last = 0, cnt = 0; for (int i = 1; i <= n; ++i) { if (a[i] != last) { if (last) { ++tot; s[tot].val = last; s[tot].cnt = cnt; s[tot].sum = last * cnt; } last = a[i]; cnt = 1; } else { ++cnt; } } ++tot; s[tot].val = last; s[tot].cnt = cnt; s[tot].sum = last * cnt; for (int i = 1; i <= tot; ++i) { pre[i].cnt = pre[i - 1].cnt + s[i].cnt; pre[i].sum = pre[i - 1].sum + s[i].sum; } for (int i = tot; i >= 1; --i) { suf[i].cnt = suf[i + 1].cnt + s[i].cnt; suf[i].sum = suf[i + 1].sum + s[i].sum; } } inline long long costL(int i) { return (s[i].val - 1) * (pre[i - 1].cnt) - pre[i - 1].sum; } inline long long costR(int i) { return suf[i + 1].sum - (s[i].val + 1) * (suf[i + 1].cnt); } long long solve() { long long ans = LLINF; for (int i = 1; i <= tot; ++i) { if (s[i].cnt >= k) { ans = 0LL; break; } else { long long cnt = k - s[i].cnt; { long long cntL = min(cnt, pre[i - 1].cnt); long long cntR = max(cnt - cntL, 0LL); long long tmp = costL(i); if (cntR > 0) { tmp += costR(i); } ans = min(ans, tmp + cnt); } { long long cntR = min(cnt, suf[i + 1].cnt); long long cntL = max(cnt - cntR, 0LL); long long tmp = costR(i); if (cntL > 0) { tmp += costL(i); } ans = min(ans, tmp + cnt); } } } return ans; } int main() { cin.sync_with_stdio(false); cout.sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); init(); printf("%lld\n", solve()); return 0; }
12
CPP
#include <bits/stdc++.h> using namespace std; const long long UNDEF = -1; const long long INF = 1e18; template <typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; } template <typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; } static char stdinBuffer[1024]; static char *stdinDataEnd = stdinBuffer + sizeof(stdinBuffer); static const char *stdinPos = stdinDataEnd; void readAhead(size_t amount) { size_t remaining = stdinDataEnd - stdinPos; if (remaining < amount) { memmove(stdinBuffer, stdinPos, remaining); size_t sz = fread(stdinBuffer + remaining, 1, sizeof(stdinBuffer) - remaining, stdin); stdinPos = stdinBuffer; stdinDataEnd = stdinBuffer + remaining + sz; if (stdinDataEnd != stdinBuffer + sizeof(stdinBuffer)) *stdinDataEnd = 0; } } int readInt() { readAhead(16); int x = 0; bool neg = false; while (*stdinPos == ' ' || *stdinPos == '\n') ++stdinPos; if (*stdinPos == '-') { ++stdinPos; neg = true; } while (*stdinPos >= '0' && *stdinPos <= '9') { x *= 10; x += *stdinPos - '0'; ++stdinPos; } return neg ? -x : x; } char readCh() { readAhead(16); while (*stdinPos == ' ' || *stdinPos == '\n') ++stdinPos; char ans = *stdinPos; ++stdinPos; return ans; } inline int rri() { char c; while (c = getchar(), c <= ' ') ; bool sign = c == '-'; if (sign) { c = getchar(); } int res = c - '0'; while (c = getchar(), c >= '0' && c <= '9') { res = res * 10 + (c - '0'); } return sign ? -res : res; } inline long long rrl() { char c; while (c = getchar(), c <= ' ') ; bool sign = c == '-'; if (sign) { c = getchar(); } long long res = c - '0'; while (c = getchar(), c >= '0' && c <= '9') { res = res * 10 + (c - '0'); } return sign ? -res : res; } inline char rrc() { char c; while (c = getchar(), c <= ' ') ; return c; } inline int rrs(char *target) { char c; while (c = getchar(), c <= ' ') ; int idx = -1; target[++idx] = c; while (1) { c = getchar(); if (c <= ' ') { target[++idx] = '\0'; return idx; } target[++idx] = c; } } vector<vector<int> > matrixUnit(long long n) { vector<vector<int> > res(n, vector<int>(n)); for (long long i = 0; i < n; i++) res[i][i] = 1; return res; } vector<vector<int> > matrixMul(const vector<vector<int> > &a, const vector<vector<int> > &b) { long long n = a.size(); long long m = a[0].size(); long long k = b[0].size(); vector<vector<int> > res(n, vector<int>(k)); for (long long i = 0; i < n; i++) for (long long j = 0; j < k; j++) for (long long p = 0; p < m; p++) res[i][j] = (res[i][j] + (long long)a[i][p] * b[p][j]) % 1000000007LL; return res; } void matrixMult(vector<vector<int> > &res, const vector<vector<int> > &a, const vector<vector<int> > &b) { long long n = a.size(); long long m = a[0].size(); long long k = b[0].size(); for (long long i = 0; i < n; i++) for (long long j = 0; j < k; j++) { long long ans = 0; for (long long p = 0; p < m; p++) ans = (ans + (long long)a[i][p] * b[p][j]) % 1000000007LL; res[i][j] = ans; } } const int mn = 2004; bitset<mn> g[mn]; bool bf(int n) { vector<vector<int> > inp; inp.resize(n); for (int x = 0; x < n; x++) { inp[x].resize(n); for (int y = 0; y < n; y++) inp[x][y] = g[x][y]; } vector<vector<int> > a = inp; for (int k = 0; k < 500; k++) { bool ok = 1; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { if (a[i][j] == 0) { ok = 0; break; } } if (ok) return 1; a = matrixMul(a, inp); } return 0; } bitset<mn> h[mn]; bitset<mn> seen; bool solve2(int n) { queue<int> q; for (int x = 0; x < n; x++) { if (h[0][x]) q.push(x); } seen = h[0]; while (!q.empty()) { int x = q.front(); q.pop(); for (int y = 0; y < n; y++) { if ((!seen[y]) && h[x][y]) { q.push(y); seen[y] = true; } } } assert(seen.count() <= n); return (int)seen.count() == n; } bool solve(int n) { int spec = -1; for (int k = 0; k < n; k++) if (g[k][k]) spec = k; assert(spec != -1); for (int x = 0; x < n; x++) for (int y = 0; y < n; y++) { int sx = (x == spec || x == 0) ? x ^ spec : x; int sy = (y == spec || y == 0) ? y ^ spec : y; h[sx][sy] = g[x][y]; } assert(h[0][0]); if (!solve2(n)) return 0; for (int x = 0; x < n; x++) for (int y = 0; y < n; y++) { g[x][y] = h[y][x]; } for (int x = 0; x < n; x++) h[x] = g[x]; if (!solve2(n)) return 0; return 1; } void test() { srand(time(0) + clock() + rand()); for (int j = 0; j < 1000; j++) { int n = (rand() % 6) + 1; for (int x = 0; x < n; x++) { h[x].reset(); g[x].reset(); for (int y = 0; y < n; y++) g[x][y] = rand() & 1; } int k = rand() % n; g[k][k] = 1; bool b = bf(n); bool s = solve(n); if (b != s) { for (int x = 0; x < n; x++) { for (int y = 0; y < n; y++) printf("%d", (int)g[x][y]); printf("\n"); } printf("b:%d s:%d\n", b, s); } } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n = rri(); for (int x = 0; x < n; x++) for (int y = 0; y < n; y++) { int t = rri(); t = (t > 0) ? 1 : 0; g[x][y] = t; } bool final = solve(n); if (final) printf("YES\n"); else printf("NO\n"); }
9
CPP
#include <bits/stdc++.h> using namespace std; long long a, b; int dfs(long long a, long long b) { if (a > b) swap(a, b); if (a == 0) return 0; if (dfs(b % a, a)) { b -= b % a; b /= a; if (a % 2) return b % 2 ? 0 : 1; else return (b % (a + 1)) % 2 ? 0 : 1; } else return 1; } void main2() { scanf("%lld %lld", &a, &b); if (dfs(a, b)) printf("First\n"); else printf("Second\n"); } int TC; int main() { scanf("%d", &TC); while (TC--) main2(); }
9
CPP
i=int(input()) dis={'Tetrahedron':4,'Cube':6,'Octahedron':8,'Dodecahedron':12,'Icosahedron':20} sum1=0 for i in range(i): sum1=sum1+dis[input()] print(sum1)
7
PYTHON3
class Pair: def __init__(self, s, i): b = s.split(" ") self.left = int(b[0]) self.right = int(b[1]) self.num = i self.group = 0 t = int(input()) for j in range(0, t): n = int(input()) arr = [] for i in range(0, n): arr.append(Pair(input(), i)) arr1 = arr.copy() arr.sort(key=lambda c: c.right) minSuf = [None] * n for i, e in reversed(list(enumerate(arr))): arr[i].group = 2 if i < n - 1: minSuf[i] = min(e.left, minSuf[i + 1]) else: minSuf[i] = e.left if i > 0 and arr[i - 1].right < minSuf[i]: for k in range(0, i): arr[k].group = 1 break if arr[0].group == 2: print(-1, end=" ") else: for p in arr1: print(p.group, end=' ') print()
9
PYTHON3
def main(): from re import sub s = sub(r"[{},\s]", '', input()) counts = {} for c in s: counts[c] = True print(len(counts)) if __name__ == '__main__': main()
7
PYTHON3
#include <bits/stdc++.h> using namespace std; struct P { int x, y; } p[10]; int main() { int r, c, n, k; cin >> r >> c >> n >> k; for (int i = 0; i < n; ++i) { cin >> p[i].x >> p[i].y; --p[i].x; --p[i].y; } int result = 0; for (int x = 0; x < r; ++x) { for (int y = 0; y < c; ++y) { for (int w = 1; w <= r - x; ++w) { for (int h = 1; h <= c - y; ++h) { int t = 0; for (int i = 0; i < n; ++i) { if (p[i].x >= x && p[i].x < x + w && p[i].y >= y && p[i].y < y + h) { ++t; } } if (t >= k) { ++result; } } } } } cout << result << endl; return 0; }
7
CPP
#include<cstdio> #include<algorithm> #define maxn 100005 using namespace std; int n,ma[maxn]; struct node { int v; node *nxt; } edge[maxn*2],*head[maxn],*ncnt; void addedge(int u,int v) { ncnt++; ncnt->v=v,ncnt->nxt=head[u]; head[u]=ncnt; } void dfs(int u,int fa) { for(node *p=head[u];p;p=p->nxt) { int v=p->v; if(v==fa) continue; dfs(v,u); if(!ma[v]) { if(ma[u]) { printf("First\n"); exit(0); } ma[u]=v,ma[v]=u; } } } int main() { ncnt=&edge[0]; scanf("%d",&n); for(int i=1;i<n;i++) { int u,v; scanf("%d%d",&u,&v); addedge(u,v); addedge(v,u); } dfs(1,0); printf("%s\n",ma[1]?"Second":"First"); }
0
CPP
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(0); cin.tie(NULL); long long int n; cin >> n; char a[n][n], r[n], c[n]; memset(r, 0, sizeof(r)); memset(c, 0, sizeof(c)); for (auto i = 0; i != n; i++) for (auto j = 0; j != n; j++) { cin >> a[i][j]; if (a[i][j] == '.') { r[i] = 1; c[j] = 1; } } for (auto i = 0; i != n; i++) for (auto j = 0; j != n; j++) if (a[i][j] == 'E' && !r[i] && !c[j]) { cout << -1 << "\n"; return 0; } vector<pair<long long int, long long int>> row, col; for (auto i = 0; i != n; i++) { for (auto j = 0; j != n; j++) { if (a[i][j] == '.') { row.push_back(make_pair((i + 1), (j + 1))); break; } } for (auto j = 0; j != n; j++) { if (a[j][i] == '.') { col.push_back(make_pair((j + 1), (i + 1))); break; } } } if ((long long int)(row).size() == n) for (auto i = 0; i != n; i++) cout << row[i].first << " " << row[i].second << "\n"; else for (auto i = 0; i != n; i++) cout << col[i].first << " " << col[i].second << "\n"; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); ; long long int n, ans = 0; cin >> n; long long int arr[n]; for (long long int i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n); for (long long int j = n - 2; j >= 0; j--) { if (ans >= arr[j]) break; if (arr[j] == arr[j + 1]) continue; for (long long int i = 2 * arr[j]; i <= arr[n - 1] + arr[j]; i += arr[j]) { long long int ind = lower_bound(arr, arr + n, i) - arr; ans = max(ans, arr[ind - 1] % arr[j]); } } cout << ans; }
8
CPP
#include<bits/stdc++.h> using namespace std; long long n,ans; string s; map <string,long long> mp; int main() { cin>>n; for(int i=1;i<=n;i++){ cin>>s,sort(s.begin(),s.end()); ans+=mp[s]; mp[s]++; } cout<<ans; return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; const int inf = 2147483647; int minx, miny, maxx, maxy; struct point { int x, y; bool operator<(const point &a) const { return x == a.x ? y < a.y : x < a.x; } } a[9]; int main() { minx = miny = inf; maxx = maxy = -inf; for (int i = 0; i < 4; i++) { cin >> a[i].x >> a[i].y; maxx = max(maxx, a[i].x), minx = min(minx, a[i].x); maxy = max(maxy, a[i].y), miny = min(miny, a[i].y); } for (int i = 4; i < 8; ++i) cin >> a[i].x >> a[i].y; sort(a + 4, a + 8); for (int i = minx; i <= maxx; i++) { for (int j = miny; j <= maxy; j++) if (((a[4].x + a[4].y <= i + j) && (i + j <= a[6].x + a[6].y)) && ((a[4].y - a[4].x >= j - i) && (a[5].y - a[5].x <= j - i))) { cout << "YES" << endl; return 0; } } cout << "NO" << endl; return 0; }
9
CPP
#include<iostream> #include<algorithm> using namespace std; static const int MAX = 1000; static const int VMAX = 10000; int n, A[MAX], s; int B[MAX], T[VMAX + 1]; //s:与えられた数列の中での最小値 //A:与えられた数列 //B:ソート済みの数列 //T:与えられた数列の中の数字がソート済みの数列のなかで来る位置(イテレータ) int solve(){ int ans = 0; bool V[MAX]; //V:各数字がどのループに属するか判明したかどうか for (int i = 0; i < n; i++){ B[i] = A[i]; V[i] = false; } sort(B, B+n); for (int i = 0; i < n; i++) T[B[i]] = i; for (int i = 0; i < n; i++){ if (V[i]) continue; int cur = i; //検討する数字がソート後に来る位置 int S = 0; //各ループの要素の数字の和 int m = VMAX; //各ループの最小値 int an = 0; //各ループの要素数 while (1) { V[cur] = true; an++; int v = A[cur]; m = min(m, v); S += v; cur = T[v]; if (V[cur]) break; } ans += min(S + (an - 2) * m, m + S + (an + 1) * s); } return ans; } int main(){ cin >> n; s = VMAX; for (int i = 0; i < n; i++){ cin >> A[i]; s = min(s, A[i]); } int ans = solve(); cout << ans << endl; return 0; }
0
CPP
a = input() k = len(a) a = list(a) j = 1 m = 0 for i in range(1,k): if a[i-1]==a[i]: j+=1 else: m = max(j,m) j = 1 m = max(j,m) if m>=7: print('YES') else: print('NO')
7
PYTHON3
a = input() b = list(map(int, a.split())) c = b[0] d = b[1] e = b[2] mincount = 0 maxcount = 0 mincount += c-d for i in range(d): mincount += 2**i for i in range(e): maxcount += 2**i maxcount += (c-e) * 2**(e-1) print(str(mincount) + " " + str(maxcount))
8
PYTHON3
s = input() d1 = s.find("A") d2 = s.rfind("Z") print(d2-d1+1)
0
PYTHON3
a=input() b=input() import re c=len(re.findall(r'(?=BB)',b)) d=len(re.findall(r'(?=GG)',b)) e=len(re.findall(r'(?=RR)',b)) print(c+d+e)
7
PYTHON3
class Watermelon: def solve(self, num): if num > 2 and num % 2 == 0: return "YES"; else: return "NO"; if __name__ == "__main__": w = int(input()) wm = Watermelon() print(wm.solve(w))
7
PYTHON3
#include <bits/stdc++.h> using namespace std; template <typename T> void chkmax(T& x, T y) { if (x < y) x = y; } template <typename T> void chkmin(T& x, T y) { if (x > y) x = y; } inline int read() { int x = 0; char c = getchar(); bool f = 0; while (c < 48) f |= c == '-', c = getchar(); while (c > 47) x = x * 10 + (c ^ 48), c = getchar(); return f ? -x : x; } const int maxn = 2e5 + 10; int n, m, q; vector<int> E[maxn]; int sz[maxn], dfn[maxn], dep[maxn], fa[maxn][18], up[maxn][18]; struct bus { int u, v; } R[maxn]; void cmp(int& x, int y) { if (y && (!x || dep[x] > dep[y])) x = y; } void dfs(int u) { static int now; dfn[u] = ++now, dep[u] = dep[fa[u][0]] + 1, sz[u] = 1; for (int i = (1), iend = (17); i <= iend; ++i) fa[u][i] = fa[fa[u][i - 1]][i - 1]; for (int v : E[u]) dfs(v), sz[u] += sz[v]; } int qlca(int u, int v) { if (dep[u] < dep[v]) swap(u, v); for (int i = (17), iend = (0); i >= iend; --i) if (dep[u] - (1 << i) >= dep[v]) u = fa[u][i]; if (u == v) return u; for (int i = (17), iend = (0); i >= iend; --i) if (fa[u][i] != fa[v][i]) u = fa[u][i], v = fa[v][i]; return fa[u][0]; } int qkth(int u, int k) { for (int i = (17), iend = (0); i >= iend; --i) if (k >> i & 1) u = fa[u][i]; return u; } int run(int& u, int anc) { int res = 0; for (int i = (17), iend = (0); i >= iend; --i) { int x = up[u][i]; if (x && dep[x] > dep[anc]) u = x, res += 1 << i; } if (!up[u][0] || dep[up[u][0]] > dep[anc]) return -1e9; return res; } vector<int> fsn[maxn]; int tot, rt[maxn], su[maxn * 40], ls[maxn * 40], rs[maxn * 40]; void ins(int& k, int rt, int l, int r, int x) { su[k = ++tot] = su[rt] + 1, ls[k] = ls[rt], rs[k] = rs[rt]; if (l == r) return; int mid = (l + r) / 2; x <= mid ? ins(ls[k], ls[rt], l, mid, x) : ins(rs[k], rs[rt], mid + 1, r, x); } int query(int k, int l, int r, int ql, int qr) { if (ql <= l && r <= qr) return su[k]; int mid = (l + r) / 2, res = 0; if (ql <= mid) res = query(ls[k], l, mid, ql, qr); if (qr > mid) res += query(rs[k], mid + 1, r, ql, qr); return res; } int yysy(int x, int y) { return query(rt[x], 1, n, 1, y); } bool check(int x1, int x2, int y1, int y2) { int res = yysy(x2, y2); if (x1 > 1) res -= yysy(x1 - 1, y2); if (y1 > 1) res -= yysy(x2, y1 - 1); if (x1 > 1 && y1 > 1) res += yysy(x1 - 1, y1 - 1); return res > 0; } void solve() { cin >> n; for (int i = (2), iend = (n); i <= iend; ++i) E[fa[i][0] = read()].push_back(i); dfs(1); cin >> m; for (int i = (1), iend = (m); i <= iend; ++i) { int u = read(), v = read(), anc = qlca(u, v); R[i] = {u, v}, cmp(up[u][0], anc), cmp(up[v][0], anc); fsn[dfn[u]].push_back(dfn[v]), fsn[dfn[v]].push_back(dfn[u]); } for (int i = (n), iend = (2); i >= iend; --i) cmp(up[fa[i][0]][0], up[i][0]); for (int i = (1), iend = (n); i <= iend; ++i) { cmp(up[i][0], i); for (int j = (1), jend = (17); j <= jend; ++j) up[i][j] = up[up[i][j - 1]][j - 1]; } for (int i = (1), iend = (n); i <= iend; ++i) { rt[i] = rt[i - 1]; for (int x : fsn[i]) ins(rt[i], rt[i], 1, n, x); } cin >> q; while (q--) { int u = read(), v = read(), anc = qlca(u, v); if (dep[u] < dep[v]) swap(u, v); int res = run(u, anc); int l = 0, r = dep[v] - dep[anc], nxt = anc; while (l <= r) { int mid = (l + r) >> 1; int ff = qkth(v, mid); check(dfn[u], dfn[u] + sz[u] - 1, dfn[ff], dfn[ff] + sz[ff] - 1) ? nxt = ff, r = mid - 1 : l = mid + 1; } res += run(v, nxt); printf("%d\n", res < 0 ? -1 : res + 1 + (nxt != v)); } } signed main() { solve(); return 0; }
11
CPP
#include <iostream> #include <algorithm> using namespace std; int main(){ int N; cin >> N; int x, y, b, p; int moneya; int moneyb; for (int i = 0; i < N; i++){ cin >> x >> y >> b >> p; moneya = x*b + y * p; if (b >= 5 && p >= 2){ moneya *= 0.8; } if (b <= 5){ b = 5; } if (p <= 2){ p = 2; } moneyb = x*b + y*p; moneyb *= 0.8; cout << min(moneya, moneyb) << endl; } return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; #define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define rep(i,n) repl(i,0,n) #define mp(a,b) make_pair((a),(b)) #define pb(a) push_back((a)) #define all(x) (x).begin(),(x).end() #define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x)) #define fi first #define se second #define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__) void _dbg(string){cout<<endl;} template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);} template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;} template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;} #define INF 1120000000 bool solve(int n, int m){ vector<string> vec(n); rep(i,n) cin>>vec[i]; const int dx[] = {0,1,0,-1}; const int dy[] = {-1,0,1,0}; const int tx[] = {n-1, n-1, 0, 0}; const int ty[] = {0, m-1, m-1, 0}; int dir=0; int x=0, y=0; rep(i,4){ auto ok = [&](int p, int q){ return p>=0 && q>=0 && p<n && q<m && (vec[p][q]=='.' || vec[p][q]==i); }; int step = 0; while(x!=tx[i] || y!=ty[i]){ int nd = 0; while(nd<4 && !ok(x+dx[(dir+nd)%4], y+dy[(dir+nd)%4])) nd++; if(nd==4) return false; x += dx[(dir+nd)%4]; y += dy[(dir+nd)%4]; dir = (dir+nd+3)%4; vec[x][y] = i; if(step++ > n*m) return false; } } return true; } int main(){ int n,m; while(cin>>n>>m, n|m){ if(solve(n,m)) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 7; long long c[maxn], r[maxn], ll[maxn], rr[maxn]; long long a[1005][1005]; int n, m, k, p; int main() { scanf("%d%d%d%d", &n, &m, &k, &p); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { scanf("%I64d", &a[i][j]); ll[i] += a[i][j]; rr[j] += a[i][j]; } } priority_queue<long long> Q; for (int i = 1; i <= n; i++) Q.push(ll[i]); for (int i = 1; i <= k; i++) { int now = Q.top(); Q.pop(); c[i] = c[i - 1] + now; now -= m * p; Q.push(now); } while (!Q.empty()) Q.pop(); for (int i = 1; i <= m; i++) Q.push(rr[i]); for (int i = 1; i <= k; i++) { int now = Q.top(); Q.pop(); r[i] = r[i - 1] + now; now -= n * p; Q.push(now); } long long ans = -1LL << 60; for (int i = 0; i <= k; i++) ans = max(ans, c[i] + r[k - i] - 1ll * i * (k - i) * p); cout << ans << endl; }
8
CPP
for _ in range(int(input())): n,m=list(map(int,input().split())) a=list(map(int,input().split())) p=list(map(int,input().split())) if sorted(a)==a: print("YES") else: flag=1 for i in range(len(a)): for j in range(len(a)-1-i): if a[j]>a[j+1]: if j+1 in p: a[j],a[j+1]=a[j+1],a[j] else: flag=0 print("NO") break if flag==0: break if flag: print("YES")
8
PYTHON3
def solve(array): nums = [0]*8001 counted = [False]*8001 tmp = 0 limit = 0 length = len(array) for i in range(length): nums[array[i]] += 1 if limit < array[i]: limit = array[i] for i in range(length-1): candidate = array[i] + array[i+1] j = i+1 while (j < length) and (candidate <= limit): if not counted[candidate]: tmp += nums[candidate] counted[candidate] = True j += 1 if j < length: candidate += array[j] return tmp t = int(input()) for i in range(t): n = int(input()) inp_str = input() arr = [int(j) for j in inp_str.split(' ')] ans = solve(arr) print(str(ans))
11
PYTHON3
n = int(input()) s = input().lower() c = 0 alp = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] if len(s) < 26: print('NO') else: for i in alp: if s.count(i) == 0: break else: c += 1 if c == 26: print('YES') else: print('NO')
7
PYTHON3
#include <bits/stdc++.h> #pragma 03 using namespace std; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); const long long INF = 1e9 + 1; long long tree_size = 0; long long st[6000005], st_l[6000005], st_r[6000005]; long long roots[300005]; pair<pair<long long, long long>, long long> segments[300005]; long long build(long long l, long long r) { long long t_id = tree_size; tree_size++; if (l != r) { long long mid = (l + r) / 2; st[t_id] = INF; st_l[t_id] = build(l, mid); st_r[t_id] = build(mid + 1, r); } else { st[t_id] = INF; st_l[t_id] = st_r[t_id] = -1; } return t_id; } long long update(long long prv_root, long long l, long long r, long long id, long long val) { long long t_id = tree_size; tree_size++; if (l == r) { st[t_id] = min(st[prv_root], val); st_l[t_id] = st_r[t_id] = -1; return t_id; } long long mid = (l + r) / 2; if (id <= mid) { st_l[t_id] = update(st_l[prv_root], l, mid, id, val); st_r[t_id] = st_r[prv_root]; st[t_id] = max(st[st_l[t_id]], st[st_r[t_id]]); } else { st_l[t_id] = st_l[prv_root]; st_r[t_id] = update(st_r[prv_root], mid + 1, r, id, val); st[t_id] = max(st[st_l[t_id]], st[st_r[t_id]]); } return t_id; } long long query(long long root, long long l, long long r, long long x, long long y) { if ((y < l) || (r < x)) return 0; if ((x <= l) && (r <= y)) return st[root]; long long mid = (l + r) / 2; return max(query(st_l[root], l, mid, x, y), query(st_r[root], mid + 1, r, x, y)); } bool comp_seg(pair<pair<long long, long long>, long long> a, pair<pair<long long, long long>, long long> b) { return a.first.first < b.first.first; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, m, k; cin >> n >> m >> k; for (long long i = 1; i <= k; i++) { cin >> segments[i].first.first >> segments[i].first.second >> segments[i].second; segments[i].second--; } sort(segments + 1, segments + k + 1, comp_seg); roots[0] = build(0, n - 1); for (long long i = k; i >= 1; i--) roots[k + 1 - i] = update(roots[k - i], 0, n - 1, segments[i].second, segments[i].first.second); segments[k + 1] = make_pair(make_pair(INF, INF), INF); for (long long i = 1; i <= m; i++) { long long a, b, x, y; cin >> a >> b >> x >> y; a--; b--; long long id = upper_bound(segments + 1, segments + k + 2, make_pair(make_pair(x, -INF), -INF)) - segments; long long max_ = query(roots[k + 1 - id], 0, n - 1, a, b); if (max_ <= y) cout << "yes\n"; else cout << "no\n"; cout.flush(); } }
12
CPP
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k; int n, diff = 2000; int index1, index2; scanf("%d", &n); int h[n]; for (i = 0; i < n; i++) { scanf("%d", &h[i]); } for (i = 0; i < n - 1; i++) { if (abs(h[i + 1] - h[i]) < diff) { diff = abs(h[i + 1] - h[i]); index1 = i; index2 = i + 1; } } if (abs(h[0] - h[n - 1]) < diff) { diff = abs(h[0] - h[n - 1]); index1 = 0; index2 = n - 1; } printf("%d %d", index1 + 1, index2 + 1); }
7
CPP
n = int(input()) arr = [int(num) for num in input().split( )] arr.sort() a = 0 for i in range(0, n, 2): a += arr[i + 1] - arr[i] print(a)
8
PYTHON3
def solve(): inputs = list(map(int, input().split())) nums = inputs[0] times = inputs[1] for _ in range(times): if nums % 10 == 0: nums /= 10 else: nums -= 1 print(int(nums)) solve()
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long mod2 = 998244353; const long double pi = 3.1415926535; const long long MAX = -100000000000; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, x = 0, k = 0, f = 0, y = 0, e, m; long long a, b; cin >> n; long long arr[n]; for (long long i = 0; i < n; i++) cin >> arr[i]; long long chest = 0, biceps = 0, back = 0; for (long long i = 0; i < n; i++) { if (i % 3 == 0) chest += arr[i]; else if (i % 3 == 1) biceps += arr[i]; else back += arr[i]; } long long mx = max(chest, biceps); mx = max(mx, back); if (mx == chest) cout << "chest"; else if (mx == biceps) cout << "biceps"; else cout << "back"; return 0; }
7
CPP
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; template <typename T1, typename T2> inline void chkMin(T1 &x, T2 y) { if (x > y) x = y; } template <typename T1, typename T2> inline void chkMax(T1 &x, T2 y) { if (x < y) x = y; } const int MAXN = 2e5 + 10, INF = 1e9; long long a[MAXN], c[MAXN]; bool used[MAXN]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> c[i]; } for (int i = 0; i < n; i++) { cin >> a[i]; a[i]--; } long long ans = 0; for (int i = 0; i < n; i++) { if (used[i]) continue; vector<int> path; int u = i; while (!used[u]) { used[u] = true; path.push_back(u); u = a[u]; } long long add = c[u]; while (!path.empty() && path.back() != u) { chkMin(add, c[path.back()]); path.pop_back(); } if (!path.empty()) ans += add; } cout << ans; }
10
CPP
#include <bits/stdc++.h> using namespace std; long long n, m, a[751], dp[751]; signed main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); cin >> n >> m; for (long long i = 1; i <= n; i++) cin >> a[i]; vector<bool> in(n + 1, 1); for (long long i = 1; i < n; i++) { long long maxminval = -1000000000000, maxminind = -1; for (long long j = 1; j <= n; j++) { if (!in[j]) continue; long long minval = 1000000000000; long long sum = 0; for (long long k = 1; k <= n; k++) { if ((!in[k]) or k == j) continue; sum += a[k]; if (minval > sum) { minval = sum; } } if (maxminval < minval) { maxminval = minval; maxminind = j; } } in[maxminind] = 0; dp[i] = maxminval; } for (long long i = 1, sum = 0; i <= n; i++) { sum += a[i]; dp[0] = min(dp[0], sum); } while (m--) { long long b; cin >> b; long long ans = n; for (long long i = 0; i < n; i++) { if (dp[i] + b >= 0) { ans = i; break; } } cout << ans << '\n'; } }
12
CPP
#include <bits/stdc++.h> using namespace std; string s, ans; int v[200], pos[200], num[200]; int main() { int i, j = 0, last = 0; cin >> s; for (i = 0; i < (int)s.length(); i++) v[s[i]] = 1; for (i = 'z'; i >= 'a'; i--) if (v[i]) { for (j = last; j < (int)s.length(); j++) if (s[j] == i) { pos[i] = j; last = j; num[i]++; } for (j = 0; j < num[i]; j++) ans.push_back(i); } cout << ans; }
7
CPP
n = int(input()) s = input() j = 1 result = [0] for i in range(n): while (j < n-1) and (s[i:j] in s[:i]+"0"+s[j:]): j += 1 result.append(j-i-1) print(max(result))
0
PYTHON3
#pragma GCC target ("avx2") #pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #include<bits/stdc++.h> using namespace std; // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // int rnd(int x, int y) {return (rng() % (y-x +1)) + x;}; #define ll long long #define pb push_back #define eb emplace_back #define mp make_pair #define lb lower_bound #define ub upper_bound #define ins insert #define ull unsigned long long #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define ff first #define ss second #define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); #define nl "\n" #define sz(a) (int)(a).size() #define all(a) (a).begin(),(a).end() #define fl(a,x) memset(a,x,sizeof(a)); #define pt(a,x) cout << get<x>(a) << " " ; #define mt make_tuple #define vec vector #define mxe max_element #define mne max_element #define present(c, x) (c.find(x) != c.end()) #define printall(a) for(auto i : a) cout << i << " " ; cout << nl ; #define int long long typedef vector<int> vii; typedef vector<ll> vll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector<pii> vpi; typedef vector<pll> vpl; typedef vector<vii> vvi; typedef vector<vll> vvl; #define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); } void err(istream_iterator<string> it) {} template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cout << *it << " = " << a << endl; err(++it, args...); } const int mod = (int) 1e9 + 7 ; const int MOD = (int) 998244353 ; const ll INF = (ll) 1e18; inline int add(int a, int b) {return (a + b >= mod ? a + b - mod : a + b);} inline int mul(int a, int b) {return (ll) a * b % mod ; } void solve() { int n; cin >> n ; string s; cin >> s; int ans = 0 ; int id = 0 , cnt = 0 ; int x = count(all(s), '*') ; rep(i,0,n) { cnt += (s[i] == '*') ; if(cnt == (x+1)/2) { id = i ; break ; } } cnt = 0 ; for(int i = id + 1 ; i < n ; ++i) { if(s[i] != '*') continue ; ans += i - id - 1 - cnt ; ++cnt ; } cnt = 0 ; for(int i = id - 1 ; i >= 0 ; --i) { if(s[i] != '*') continue ; ans += id - i - 1 - cnt ; ++cnt ; } cout << ans << nl ; } int32_t main() { fast; int t; cin >> t ; rep(i,0,t) solve() ; // cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; return 0; }
11
CPP
#include <bits/stdc++.h> using namespace std; int main() { long n; while (cin >> n) { long mn = 1002, x, res = 0, cnt = 0; for (__typeof(2 * n - 1) i = 0; i < (2 * n - 1); i++) { cin >> x; res += abs(x); mn = min(mn, abs(x)); if (x < 0) cnt++; } if (cnt >= n) cnt -= n; if (n % 2 == 1 || cnt % 2 == 0) cout << res << endl; else cout << res - 2 * mn << endl; } return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 5; struct number { int x, y, z; inline bool friend operator<(const number &a, const number &b) { return a.y > b.y; } }; number a[N]; inline int read() { int sum = 0, ff = 1; char ch = getchar(); while (!isdigit(ch)) ch = getchar(); while (isdigit(ch)) sum = sum * 10 + (ch ^ 48), ch = getchar(); return sum * ff; } int n, m, ans, gs, tmp[N], tr[N << 2]; inline int max(int i, int j) { if (i > j) return i; return j; } inline void build(int k, int l, int r) { tr[k] = 0; if (l == r) return; int mid = (l + r) / 2; build(k << 1, l, mid); build(k << 1 | 1, mid + 1, r); } inline void modify(int k, int l, int r, int pos, int val) { if (l == r) { tr[k] = max(tr[k], val); return; } int mid = (l + r) / 2; if (pos <= mid) modify(k << 1, l, mid, pos, val); else modify(k << 1 | 1, mid + 1, r, pos, val); tr[k] = max(tr[k << 1], tr[k << 1 | 1]); } inline int query(int k, int l, int r, int ll, int rr) { if (ll <= l && r <= rr) return tr[k]; int mid = (l + r) / 2; int ret = 0; if (ll <= mid) ret = max(ret, query(k << 1, l, mid, ll, rr)); if (mid < rr) ret = max(ret, query(k << 1 | 1, mid + 1, r, ll, rr)); return ret; } int main() { n = read(); for (int i = 1; i <= n; i++) a[i].x = read(), tmp[i] = a[i].x; for (int i = 1; i <= n; i++) a[i].y = read(); for (int i = 1; i <= n; i++) a[i].z = read(); sort(tmp + 1, tmp + n + 1); gs = unique(tmp + 1, tmp + n + 1) - tmp - 1; build(1, 1, gs); for (int i = 1; i <= n; i++) a[i].x = lower_bound(tmp + 1, tmp + gs + 1, a[i].x) - tmp; sort(a + 1, a + n + 1); int i, j; for (i = 1; i <= n; i = j) { for (j = i; j <= n && (a[j].y == a[i].y); j++) { int mc; mc = query(1, 1, gs, a[j].x + 1, gs); if (mc > a[j].z) ans++; } for (; i <= j - 1; i++) modify(1, 1, gs, a[i].x, a[i].z); } printf("%d\n", ans); return 0; }
10
CPP
N = int(input()) print(' {}'.format(' '.join([str(c) for c in range(1, N + 1) if c % 3 == 0 or '3' in str(c)])))
0
PYTHON3
#include <bits/stdc++.h> using namespace std; long long n; int sum(long long n) { long long s = 0; while (n > 0) { s += n % 10; n /= 10; } return s; } long long ff(long long x) { long long tmp = x * x + sum(x) * x - n; return tmp; } int main() { cin >> n; for (long long i = 1; i <= 90; i++) { long long tmp = (i * i + 4 * n); long long x1 = (-i + sqrt(tmp)) / 2; long long x2 = (-i - sqrt(tmp)) / 2; if (x1 >= 0 && sum(x1) == i && ff(x1) == 0) { cout << x1 << endl; return 0; } if (x2 >= 0 && sum(x2) == i && ff(x2) == 0) { cout << x2 << endl; return 0; } } cout << -1; return 0; }
8
CPP
import os import sys from io import BytesIO, IOBase def main(): pass # region fastio 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") ''' t = int(input()) for pp in range(t): n,k = map(int, input().split()) lis = list(map(int, input().split())) lis.sort(reverse=True) mini = lis[-1] sumz = sum(lis) if sumz <= k: print(0) elif len(lis) == 1: print(sumz-k) elif sumz == k+1: print(1) else: ans = float("inf") cur = 0 for i in range(n-1): curans = 0 cur += lis[i] sus = cur - (i+1)*mini if sumz-sus-k>0: curans += max(0, (sumz-sus-k-1)//(i+2)+1) curans += i+1 ans = min(ans, curans) print(ans)
9
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { string s,sf,sb,tp; cin>>s; int q,t,f;bool rev=false; cin>>q;char c; deque <char> dq(s.begin(),s.end()); while(q--) { cin>>t; if(t==1)rev=!rev; else { cin>>f>>c; if((f==1&&!rev)||(f==2&&rev)) { dq.push_front(c); } else { dq.push_back(c); } } } if(rev) for(auto it=dq.rbegin();it!=dq.rend();it++)cout<<*it; else for(auto it=dq.begin();it!=dq.end();it++)cout<<*it; }
0
CPP
for t in range(int(input())): n = int(input()) *a, = map(int, input().split()) dp = [[0]*3 for _ in range(n+2)] for i in range(n): # 反転を開始していない dp[i+1][0] = dp[i][0] + (a[i] if i % 2 == 0 else 0) # 反転開始したが、終了していない if i+1 < n: dp[i+2][1] = max(dp[i][0], dp[i][1]) + (a[i+1] if i % 2 == 0 else a[i]) # 反転終了している dp[i+1][2] = max(dp[i][1], dp[i][2])+(a[i] if i % 2 == 0 else 0) print(max(dp[n]))
10
PYTHON3
import math t = int(input()) for i in range(t): a, b = list(map(int, input().split())) count = 0 diff = abs(a - b) print(math.ceil(diff / 10))
7
PYTHON3
t=int(input()) for _ in range(t): n=int(input()) arr=list(map(int,input().split())) even,odd=0,0 a,b,p,q=0,0,0,0 for i in range(n): if i%2==0 and arr[i]%2!=0: even+=1 elif i%2!=0 and arr[i]%2==0: odd+=1 if even==odd: print(odd) else: print(-1)
8
PYTHON3
K,X =map(int,input().split()) ans = "Yes" if 500*K >= X else "No" print(ans)
0
PYTHON3
#include<cstdio> #include<vector> #include<algorithm> #include<map> using namespace std; typedef pair<int,int>pii; int main(){ int n; while(scanf("%d",&n),n){ vector<pii>V; for(int i=0;i<n;i++){ int p,sum=0; scanf("%d",&p); for(int i=0;i<4;i++){ int m,s; scanf("%d%d",&m,&s); sum+=m*60+s; } V.push_back(pii(sum,p)); } sort(V.begin(),V.end()); printf("%d\n",V[0].second); printf("%d\n",V[1].second); printf("%d\n",V[n-2].second); } return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; int a[n + 1]; for (int i = 1; i <= n; i++) { cin >> a[i]; } int count = 0; int max = a[1]; for (int i = 1; i <= n; i++) { if (a[i] > max) { max = a[i]; } if (i == max) { count++; continue; } } cout << count << endl; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int n; vector<int> v[100005]; double dfs(int node, int parent, int depth) { int i, j, k; double p, q; p = 1 / (double)depth; for (i = 0; i < v[node].size(); i++) { j = v[node][i]; if (j == parent) continue; p += dfs(j, node, depth + 1); } return p; } int main() { int i, j, k; scanf("%d", &n); for (i = 1; i < n; i++) { scanf("%d %d", &j, &k); v[j].push_back(k); v[k].push_back(j); } printf("%.8lf\n", dfs(1, 0, 1)); return 0; }
9
CPP
for _ in range(int(input())): a, b, x, y, n = map(int, input().split()) # aim to find maximum difference of a and b if a > b: a, b, x, y = b, a, y, x if (a - x) >= n: print((a - n) * b) elif n >= (a - x + b - y): print(x * y) elif (a - x + b - y) > n: if x <= y or (b-a) >= n: print(x * (b - n + a - x)) else: if (b-y) >= n: print(min((b-n)*a, x * (b - n + a - x))) else: print(min(y*(a-n+b-y), x * (b - n + a - x)))
8
PYTHON3
input() s = '0' + input() + '0' print('No' if '000' in s or '11' in s else "Yes")
7
PYTHON3
s = input().split('WUB') i = 0 while i < len(s): if s[i] == '': s.remove(s[i]) i -= 1 i += 1 print(' '.join(i for i in s))
7
PYTHON3
x, y, z, t1, t2, t3 = tuple(map(int, input().split())) if (abs(z - x) * t2 + abs(x - y) * t2 + 3 * t3) <= (t1 * abs(x - y)): print("YES") else: print('NO')
7
PYTHON3
t = int(input()) for qweqerq in range(t): n = int(input()) a = list(map(int,input().split())) s = sum(a) k = a.count(0) if s != 0 and k == 0: print(0) else: if s + k != 0: print(k) else: print(k + 1)
7
PYTHON3