solution
stringlengths
10
983k
difficulty
int64
0
25
language
stringclasses
2 values
cost, money, n_banana = map(int, input().split()) total_cost = int(n_banana * (2*cost + (n_banana-1)*cost) / 2) if total_cost > money: print(total_cost-money) else: print(0)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int maxN = 15e2; int n; const long long int mod = 998244353; int a[maxN][maxN]; struct Edge { int u, v, cost; bool operator<(const Edge &other) const { return cost < other.cost; } }; vector<Edge> edges; int parent[maxN], setEdges[maxN]; vector<long long int> memo[maxN]; int root(int u) { return parent[u] < 0 ? u : parent[u] = root(parent[u]); } int setSize(int u) { return -parent[root(u)]; } bool isClique(int u) { return setEdges[root(u)] == (setSize(u) * (setSize(u) - 1)) >> 1; } void merge(int u, int v) { if ((u = root(u)) == (v = root(v))) { setEdges[u]++; if (isClique(u)) memo[u][1] = 1; return; } if (parent[u] > parent[v]) swap(u, v); parent[u] += parent[v]; setEdges[u] += setEdges[v] + 1; parent[v] = u; vector<long long int> aux(memo[u].size() + memo[v].size() - 1); aux[1] = isClique(u); for (int i = 1; i < memo[u].size(); i++) for (int j = 1; j < memo[v].size(); j++) aux[i + j] = (aux[i + j] + memo[u][i] * memo[v][j] % mod) % mod; memo[u] = aux; } int main() { int tt = 0; while (scanf("%d", &n) != EOF) { if (tt++) printf("\n"); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) scanf("%d", &a[i][j]); edges.clear(); for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) edges.push_back(Edge{i, j, a[i][j]}); sort(edges.begin(), edges.end()); if (0) for (Edge &e : edges) printf("%d %d | %d\n", e.u + 1, e.v + 1, e.cost); memset(parent, -1, sizeof(parent)); memset(setEdges, 0, sizeof(setEdges)); for (int i = 0; i < n; i++) { memo[i].resize(2); memo[i][1] = 1; } for (Edge &e : edges) { merge(e.u, e.v); } vector<long long int> &ans = memo[root(0)]; for (int i = 1; i < ans.size(); i++) printf("%lld%c", ans[i], "\n "[i < ans.size() - 1]); } return 0; }
13
CPP
''' @Author: nuoyanli @Date: 2020-07-29 11:59:21 @LastEditTime: 2020-07-29 12:00:59 @Author's blog: https://blog.nuoyanli.com/ @Description: Don't forget the rich and the poor! ''' ans = 0 mmp = {"Tetrahedron": 4, "Cube": 6, "Octahedron": 8, "Dodecahedron": 12, "Icosahedron": 20} T = int(input()) for _ in range(T): s = input() ans += mmp[s] print(ans)
7
PYTHON3
#include <iostream> #include <vector> #include <cstring> #include <algorithm> #include <queue> #include <functional> using namespace std; const int INF = 1e9 + 10; struct Edge { int to, dist, constraint; Edge() = default; Edge(int t, int d, int c): to(t), dist(d), constraint(c) { } }; struct Node { double cost; int cur, prev, v; Node() = default; Node(double c, int cur, int prev, int v): cost(c), cur(cur), prev(prev), v(v) { } inline bool operator<(const Node& node) const { return cost < node.cost; } inline bool operator>(const Node& node) const { return cost > node.cost; } }; int main() { while (true) { int n, m; cin >> n >> m; if (n + m == 0) { break; } int s, g; cin >> s >> g; vector<Edge> G[31]; for (int i = 0; i < m; i++) { int x, y, d, c; cin >> x >> y >> d >> c; G[x].push_back(Edge(y, d, c)); G[y].push_back(Edge(x, d, c)); } double min_cost[31][31][31]; for (int i = 0; i < 31; i++) { for (int j = 0; j < 31; j++) { for (int k = 0; k < 31; k++) { min_cost[i][j][k] = INF; } } } priority_queue<Node, vector<Node>, greater<Node>> que; min_cost[s][0][1] = 0; que.push(Node(0, s, -1, 0)); while (!que.empty()) { Node node = que.top(); que.pop(); for (const auto& e : G[node.cur]) { if (node.prev == e.to) { continue; } const int dv[3] = { -1, 0, 1 }; for (int i = 0; i < 3; i++) { int nv = node.v + dv[i]; if (nv > 0 && nv <= e.constraint) { double temp = e.dist / (double)nv; if (min_cost[e.to][node.cur][nv] > node.cost + temp) { min_cost[e.to][node.cur][nv] = node.cost + temp; que.push(Node(node.cost + temp, e.to, node.cur, nv)); } } } } } double ans = INF; for (int i = 1; i <= n; i++) { ans = min(ans, min_cost[g][i][1]); } if (ans >= INF) { cout << "unreachable" << endl; } else { printf("%.15f\n", ans); } } return 0; }
0
CPP
def main(): n = int(input()) mnrn, mxln = 1000000000, 0 for i in range(n): l, r = [int(x) for x in input().split()] mnrn = min(mnrn, r) mxln = max(mxln, l) m = int(input()) mnrm, mxlm = 1000000000, 0 for i in range(m): l, r = [int(x) for x in input().split()] mnrm = min(mnrm, r) mxlm = max(mxlm, l) d1 = mxlm - mnrn if mxlm > mnrn else 0 d2 = mxln - mnrm if mxln > mnrm else 0 ans = max(d1, d2) print(ans) if __name__=="__main__": main()
8
PYTHON3
q = input() s = input() s1 = "qwertyuiop" s2 = "asdfghjkl;" s3 = "zxcvbnm,./" for c in s: if c in s1: if q == 'L': print(s1[s1.find(c)+1], end = '') else: print(s1[s1.find(c)-1],end = '') if c in s2: if q == 'L': print(s2[s2.find(c)+1],end = '') else: print(s2[s2.find(c)-1],end = '') if c in s3: if q == 'L': print(s3[s3.find(c)+1],end = '') else: print(s3[s3.find(c)-1],end = '')
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int MAXN = 10 + 1e6, maxn = 1e5; int n, p, k; int a[MAXN]; void Inout() { freopen( "ABC" ".inp", "r", stdin); freopen( "ABC" ".out", "w", stdout); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> a[i]; sort(a + 1, a + n + 1); int l = 0, r = a[n] - a[1]; while (l < r) { int mid = (l + r) / 2; int b[MAXN], dem[MAXN]; b[0] = 1; dem[0] = 1; for (int i = 1; i <= n; ++i) { int x = lower_bound(a + 1, a + n + 1, max(0, a[i] - mid)) - a; --x; if (i - k < x || i - k < 0) b[i] = 0; else { int first = dem[i - k]; first -= (x > 0 ? dem[x - 1] : 0); if (first) b[i] = 1; else b[i] = 0; } dem[i] = dem[i - 1] + b[i]; } if (b[n] == 1) r = mid; else l = mid + 1; } cout << l; return 0; }
15
CPP
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 100005; vector<int> go[N]; vector<ll> ft[N]; void prec_add(int x, int y) { for (; x < N; x += x & -x) { go[x].push_back(y); } } void init() { for (int i = 1; i < N; i++) { sort(go[i].begin(), go[i].end()); go[i].resize(unique(go[i].begin(), go[i].end()) - go[i].begin()); ft[i].assign(go[i].size() + 1, 0); } } void add(int x, int y, int val) { for (; x < N; x += x & -x) { int id = int(upper_bound(go[x].begin(), go[x].end(), y) - go[x].begin()); for (; id < (int)ft[x].size(); id += id & -id) ft[x][id] += val; } } ll sum(int x, int y) { ll ans = 0; for (; x > 0; x -= x & -x) { int id = int(upper_bound(go[x].begin(), go[x].end(), y) - go[x].begin()); for (; id > 0; id -= id & -id) ans += ft[x][id]; } return ans; } int n, m; int a[N], ta[N]; int t[N], l[N], r[N]; set<int> occ[N]; vector<tuple<int, int, int>> upd(int pos, int val) { vector<tuple<int, int, int>> ans; if (a[pos] == val) return ans; { auto it = occ[a[pos]].find(pos); bool to_add = true; if (it != occ[a[pos]].begin()) { ans.emplace_back(*prev(it), *it, -1); } else to_add = false; if (next(it) != occ[a[pos]].end()) { ans.emplace_back(*it, *next(it), -1); } else to_add = false; if (to_add) { ans.emplace_back(*prev(it), *next(it), 1); } occ[a[pos]].erase(it); } { a[pos] = val; occ[a[pos]].insert(pos); auto it = occ[a[pos]].find(pos); bool to_add = true; if (it != occ[a[pos]].begin()) { ans.emplace_back(*prev(it), *it, 1); } else to_add = false; if (next(it) != occ[a[pos]].end()) { ans.emplace_back(*it, *next(it), 1); } else to_add = false; if (to_add) { ans.emplace_back(*prev(it), *next(it), -1); } } return ans; } int main() { scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d", a + i); if (!occ[a[i]].empty()) { prec_add(*occ[a[i]].rbegin(), i); } occ[a[i]].insert(i); ta[i] = a[i]; } for (int i = 0; i < m; i++) { scanf("%d %d %d", t + i, l + i, r + i); if (t[i] == 1) { for (auto [x, y, val] : upd(l[i], r[i])) { prec_add(x, y); } } } init(); for (int i = 1; i <= n; i++) occ[i].clear(); for (int i = 1; i <= n; i++) { a[i] = ta[i]; if (!occ[a[i]].empty()) { int lef = *occ[a[i]].rbegin(); add(lef, i, i - lef); } occ[a[i]].insert(i); } for (int i = 0; i < m; i++) { if (t[i] == 1) { for (auto [x, y, val] : upd(l[i], r[i])) { add(x, y, val * (y - x)); } } else { ll ans = sum(r[i], r[i]); ans -= sum(l[i] - 1, r[i]); ans -= sum(r[i], l[i] - 1); ans += sum(l[i] - 1, l[i] - 1); printf("%lld\n", ans); } } }
9
CPP
#include <bits/stdc++.h> using namespace std; void solve() { int n, r, g, b; cin >> n; for (int i = 0; i < n; i++) { cin >> r >> g >> b; int maxi = max(r, max(g, b)); int res = (r + g + b) - maxi; if (maxi - 1 > res) cout << "No" << endl; else cout << "Yes" << endl; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); return 0; }
7
CPP
l=int(input()) s=input() ans=0 while s: a=len(s) s=s.lstrip(s[0]) ans += a-len(s)-1 print(ans)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } inline void write(long long x) { if (x < 0) putchar('-'), x = -x; if (x >= 10) write(x / 10); putchar(x % 10 + '0'); } inline void writeln(long long x) { write(x); puts(""); } const long long N = 1010; vector<long long> g[N]; long long f[N], h[N], n, T; int main() { n = read(); T = read(); for (long long i = 1; i <= n; ++i) { long long sgr = read(); g[T - sgr].push_back(read()); } f[0] = 0; for (long long tim = T - 1; tim >= 0; --tim) { memcpy(h, f, sizeof f); for (long long i = 0; i <= n; ++i) f[i] = max(h[i * 2], h[i * 2 - 1]); for (long long i = 0; i < g[tim].size(); i++) for (long long j = n; j >= 1; --j) f[j] = max(f[j], f[j - 1] + g[tim][i]); } writeln(f[1]); }
12
CPP
t = int(input()) while t != 0: t = t - 1 n = int(input()) s = input() sf1 = 0 sf2 = 0 sf3 = 0 for i in s: if i == '>': sf1 = sf1 + 1 elif i == '<': sf2 = sf2 + 1 else: sf3 = sf3 + 1 #print(sf1) #print(sf2) #print(sf3) if sf1 == n or sf2 == n or sf3 == n or sf1 + sf3 == n or sf2 + sf3 == n: print(n) continue elif sf3 == 0: print("0") else: cnt = 0 ans = 0 for i in s: if i == '-': if cnt == 0: cnt = cnt + 2 else: cnt = cnt + 1 else: ans = ans + cnt cnt = 0 ans = ans + cnt if s[0] == '-' and s[n - 1] == '-': ans = ans - 1 print(ans)
8
PYTHON3
def prefix(s): p = [0] * len(s) for i in range(1, len(s)): k = p[i - 1] while k > 0 and s[k] != s[i]: k = p[k - 1] if s[k] == s[i]: k += 1 p[i] = k return p string = input() prefix_values = prefix(string) n = len(string) if prefix_values[n - 1] == 0: print('Just a legend') exit() last_pr = prefix_values[n - 1] for i in range(n - 1): if prefix_values[i] == last_pr: print(string[:prefix_values[i]]) exit() next_pos_value = prefix_values[last_pr - 1] if next_pos_value == 0: print('Just a legend') exit() for i in range(n): a = prefix_values[i] if prefix_values[i] == next_pos_value and i != last_pr: print(string[:prefix_values[i]]) exit() # print('Just a legend')
10
PYTHON3
#include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <complex> #include <string> #include <sstream> #include <algorithm> #include <vector> #include <queue> #include <stack> #include <functional> #include <iostream> #include <map> #include <set> using namespace std; typedef pair<int,int> P; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; #define pu push #define pb push_back #define mp make_pair #define eps 1e-9 #define INF 2000000000 #define sz(x) ((int)(x).size()) #define fi first #define sec second #define SORT(x) sort((x).begin(),(x).end()) #define all(x) (x).begin(),(x).end() #define EQ(a,b) (abs((a)-(b))<EPS) bool c[300010]; int N,Q,maxc=-1,ans=0; int s[300010]; int main() { cin >> N >> Q; for(int i=0;i<N;i++) { int a; cin >> a; maxc=max(maxc,a); c[a]=true; } for(int i=0;i<=maxc;i++) { if(c[i])s[i+1]=i; else s[i+1]=s[i]; } for(int i=0;i<Q;i++) { int q; cin >> q; ans=0; for(int d=maxc;maxc;) { int p=d%q; ans=max(ans,p); if(d-p<=0)break; d=s[d-p]; } cout << ans << endl; } return 0; }
0
CPP
for _ in range(int(input())): n,m=map(int,input().split()) l=[] s=0 for i in range(n): l.append(list(map(int,input().split()))) for i in range(n): for j in range(m): a=list(sorted([l[i][j],l[n-i-1][j],l[i][m-1-j],l[n-1-i][m-1-j]])) s+=a[3]+a[2]-a[1]-a[0] print(s//4)
8
PYTHON3
n = int(input()) b = [i for i in map(int, input().split())] vis = [0 for i in range(600010)] for i in range(n): vis[b[i]-i] = vis[b[i]-i] + b[i] print(max(vis))
7
PYTHON3
#include <bits/stdc++.h> using namespace std; long long fastpow(long long a, long long b, long long p) { long long res = 1; while (b != 0) { if (b % 2 == 1) { res = (res * a) % p; } a = (a * a) % p; b = b / 2; } return res; } int main() { long long ans = 1; long long p = 1000000007; int n; cin >> n; for (int i = 1; i < n; i++) ans = (ans * (((2 * n - i) * fastpow(i, p - 2, p)) % p)) % p; cout << (2 * ans - n) % p; return 0; }
9
CPP
t=int(input()) for _ in range(t): n,x=[int(i) for i in input().split()] if n==1 or n==2: print(1) else: count=(n-2)//x rem=(n-2)%x if(rem>0): count+=1 print(count+1)
7
PYTHON3
a = [i for i in input()] b = [i for i in input()] full = sorted([i for i in input()]) print('YES' if sorted(a + b) == full else 'NO')
7
PYTHON3
#include <bits/stdc++.h> using namespace std; vector<vector<int>> g; vector<int> vis, d; void dfs(int v, int c) { d[v] = c; vis[v] = true; for (int u : g[v]) { if (!vis[u]) dfs(u, c + 1); } } void solve() { int n, m; cin >> n >> m; g.resize(n + 1, vector<int>()); vis.resize(n + 1, false); d.resize(n + 1, -1); while (m--) { int a, b; cin >> a >> b; g[a].push_back(b); g[b].push_back(a); } dfs(1, 0); int u = max_element(d.begin(), d.end()) - d.begin(); vis.clear(); vis.resize(n + 1, false); dfs(u, 0); cout << (*max_element(d.begin(), d.end())) << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); int T = 1; while (T--) { solve(); } }
9
CPP
#include <iostream> using namespace std; int main() { int t,i,f[1000]={0},b[100000]; string a; cin>>t; for(i=0;i<t;i++){ cin>>a; b[i]=a[0]; f[b[i]]++; } cout<<"AC x "<<f['A']<<endl; cout<<"WA x "<<f['W']<<endl; cout<<"TLE x "<<f['T']<<endl; cout<<"RE x "<<f['R']<<endl; }
0
CPP
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; const long long M = 1e6 + 5; const long long mod = 1e9 + 7; const long long m1 = 1e9 + 7; const long long m2 = 1e9 + 9; const long long p1 = 402653189; const long long p2 = 1610612741; const long long LN = 61; long long powermodm(long long x, long long n, long long M) { long long result = 1; while (n > 0) { if (n % 2 == 1) result = (result * x) % M; x = (x * x) % M; n = n / 2; } return result; } long long power(long long _a, long long _b) { long long _r = 1; while (_b) { if (_b % 2 == 1) _r = (_r * _a); _b /= 2; _a = (_a * _a); } return _r; } long long gcd(long long a, long long b) { if (a == 0) return b; return gcd(b % a, a); } long long lcm(long long a, long long b) { return (max(a, b) / gcd(a, b)) * min(a, b); } long long dx[4] = {-1, 1, 0, 0}; long long dy[4] = {0, 0, 1, -1}; const long long MAX = sqrt(1e9); const long long INFL = 1e18; vector<long long> pri, max_vals; bool p[N]; void pre() { for (long long i = 2; i < N; i++) p[i] = true; for (long long i = 2; i <= MAX; i++) { if (p[i]) { pri.push_back(i); for (long long j = i * i; j <= MAX; j += i) p[j] = false; } } for (auto it : pri) { long long curr = it; while (curr * it <= 1e9) curr *= it; max_vals.push_back(curr); } } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; pre(); long long i, j; long long t; cin >> t; while (t--) { long long curr = 1, ans = 1, que = 0; for (i = 0; i < pri.size(); i++) { long long right = pri.size(), mul = 1; for (j = i; j < pri.size(); j++) { if (mul > (INFL / pri[j])) { right = j; break; } mul *= pri[j]; } if (que == 22) break; que++; cout << "? " << mul << "\n"; cout.flush(); long long val; cin >> val; for (j = i; j < right; j++) { if (val % pri[j] == 0) { if (que >= 22) break; que++; cout << "? " << max_vals[j] << "\n"; cout.flush(); long long val1; cin >> val1; curr *= val1; long long cnt = 0; while (val1) { cnt++; val1 /= pri[j]; } ans *= cnt; } } i = right - 1; } cout << "! " << max(ans + 7, 2 * ans) << "\n"; cout.flush(); } return 0; }
12
CPP
import sys input=sys.stdin.readline n=int(input()) s=list(input().rstrip()) t=list(input().rstrip()) if s.count("1")!=t.count("1"): print(-1) exit() s11=0 s10=0 s01=0 s00=0 for i in range(n): if s[i]!=t[i]: if s[i]=="1": if s00: s00-=1 s01+=1 elif s10: s10-=1 s11+=1 else: s11+=1 else: if s11: s11-=1 s10+=1 elif s01: s01-=1 s00+=1 else: s00+=1 print(s01+s10)
11
PYTHON3
tc,budget=map(int,input().split()) ans=[] count=0 for i in range(tc): l=[int (x) for x in input().split()] for x in range(1,len(l)): if l[x]<budget: count+=1 ans.append(i+1) break print(count) print(*ans)
7
PYTHON3
t=int(input()) for i in range(t): n,k=map(int,input().split()) arr=list(map(int,input().split())) if k%2!=0: d=max(arr) for i in range(n): arr[i]=d-arr[i] for i in arr: print(i,end=" ") print("") else: i=2 while i!=0: d=max(arr) for j in range(n): arr[j]=d-arr[j] i-=1 for k in arr: print(k,end=" ") print(" ")
8
PYTHON3
for _ in range(int(input())): a,b,x,y=map(int,input().split()) print(max((x*y,(a-x-1)*b,(b-y-1)*a,a*y,b*x)))
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int n, ans, sum, a[110], b[110], to[110]; bool used[10][10]; char S[10]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%s", S); if (S[0] == 'R') a[i] = 1; else if (S[0] == 'G') a[i] = 2; else if (S[0] == 'B') a[i] = 3; else if (S[0] == 'Y') a[i] = 4; else a[i] = 0; b[i] = S[1] - '0' - 1; } ans = 10000; for (int i = 0; i < 32; i++) for (int j = 0; j < 32; j++) { for (int p = 1; p <= n; p++) { int x, y; if ((1 << a[p]) & i) x = a[p]; else x = 5; if ((1 << b[p]) & j) y = b[p]; else y = 5; to[p] = x * 6 + y; } bool ok = true; for (int p = 1; p <= n; p++) for (int q = 1; q < p; q++) if (to[p] == to[q] && (a[p] != a[q] || b[p] != b[q])) ok = false; if (ok) { int tot = 0; for (int p = 0; p < 5; p++) if ((1 << p) & i) tot++; for (int p = 0; p < 5; p++) if ((1 << p) & j) tot++; ans = min(ans, tot); } } printf("%d\n", ans); }
9
CPP
#include <bits/stdc++.h> using namespace std; int main() { long long int x, y, k; vector<pair<long long int, long long int> > loc; cin >> k; for (long long int i = 0; i < k; i++) { if (i % 2 == 0) { loc.push_back(make_pair(i, 0)); } else { loc.push_back(make_pair(i, 0)); loc.push_back(make_pair(i, 3)); } } for (long long int i = 0; i < k; i++) cout << loc[i].first << " " << loc[i].second << endl; return 0; }
9
CPP
vova=[int(i) for i in input().split(" ")] modcrab=[int(j) for j in input().split(" ")] h1=vova[0] a1=vova[1] c1=vova[2] h2=modcrab[0] a2=modcrab[1] strat=[] moves=0 h="HEAL" s="STRIKE" while h2>0: if h2-a1>0 and h1-a2<=0: h1+=c1 strat.append(h) else: h2-=a1 strat.append(s) moves+=1 h1-=a2 print(moves) for i in strat: print(i)
8
PYTHON3
#include <bits/stdc++.h> using namespace std; template <typename _T> inline void _DBG(const char *s, _T x) { cerr << s << " = " << x << "\n"; } template <typename _T, typename... args> void _DBG(const char *s, _T x, args... a) { while (*s != ',') cerr << *s++; cerr << " = " << x << ','; _DBG(s + 1, a...); } const int N = 1e6 + 7; int n; long long T[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> T[i]; vector<pair<long long, long long> > st = {{T[n], 1}}; for (int i = n - 1; i >= 1; i--) { long long x = T[i]; long long sm = x, cnt = 1; while (!st.empty() && sm * (cnt + st.back().second) >= (sm + st.back().first) * cnt) { sm += st.back().first; cnt += st.back().second; st.pop_back(); } st.push_back({sm, cnt}); } reverse((st).begin(), (st).end()); for (auto p : st) { for (int i = 0; i < p.second; i++) cout << fixed << setprecision(10) << (long double)p.first / (long double)p.second << "\n"; } return 0; }
9
CPP
#include <iostream> #include <cstdlib> #include <algorithm> #include <cstdio> #include <cmath> #include <cstring> #define rep(i,j,k) for(int i=(j);i<(k);i++) using namespace std; int data[3][100005]; int rdata[100005],flag[100005]; int _abs(int a) { return a>0?a:-a; } int dfs(int a) { flag[a]=1; int nex=rdata[a]; if(flag[nex])return 1; else return 1+dfs(nex); } int main() { int n; scanf("%d",&n); rep(j,0,3)rep(i,1,n+1)scanf("%d",&data[j][i]); rep(i,1,n+1) { if(data[1][i]%3!=2) { puts("No"); return 0; } rdata[i]=(data[1][i]+1)/3; } rep(i,1,n+1)if((data[0][i]+2)/3!=rdata[i]||(data[2][i]+2)/3!=rdata[i]) { puts("No"); return 0; } rep(i,1,n+1)if(rdata[i]%2!=i%2) { puts("No"); return 0; } long long cnt[2]={0,0},nxd[2]={0,0}; rep(i,1,n+1)if(data[0][i]%3==0)cnt[i%2]++; rep(i,1,n+1)if(!flag[rdata[i]])nxd[i%2]+=(dfs(rdata[i])%2)^1; if(cnt[0]%2==nxd[1]%2&&cnt[1]%2==nxd[0]%2)puts("Yes"); else puts("No"); return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; int TotalCount[3]; int calculation(int a, int b, int c) { int totalMoney = 0; totalMoney += (a / 5 * 5 * 0.8 + a % 5) * 380; totalMoney += (b / 4 * 4 * 0.85 + b % 4) * 550; totalMoney += (c / 3 * 3 * 0.88 + c % 3) * 850; return totalMoney; } int main() { int g, minMoney; while (cin >> g, g) { memset(TotalCount, 0, sizeof(TotalCount)); TotalCount[0] = g / 200; TotalCount[1] = g / 300; TotalCount[2] = g / 500; minMoney = INT_MAX; for (int a = 0; a <= TotalCount[0]; a++) { for (int b = 0; b <= TotalCount[1]; b++) { for (int c = 0; c <= TotalCount[2]; c++) { if (a * 200 + b * 300 + c * 500 == g) { minMoney = min(minMoney, calculation(a, b, c)); } } } } cout << minMoney << endl; } return 0; }
0
CPP
a,b=map(int,input().split()) l=[] for i in range(a): m=[j for j in input()] l.append(m) p=[] for i in range(b): m=l[0][i] for j in range(1,a): if m<l[j][i]: m=l[j][i] p.append(m) n=[] for i in range(a): n.append(0) for i in range(b): for j in range(a): if l[j][i]==p[i]: n[j]=1 print(n.count(1))
7
PYTHON3
a=input() x=a.count('x') y=len(a)-x print(('yx'[x>y])*abs(x-y))
8
PYTHON3
#include <bits/stdc++.h> using namespace std; long long n, k, a, b, z, answer = -2000000001; int main() { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a >> b; if (b > k) { z = a - (b - k); } else { z = a; } answer = max(answer, z); } cout << answer; }
7
CPP
n=int(input()) a=[int(i) for i in input().split()] a.sort(reverse=True) suma=sum(a) add=0 num=n for i in range (n): add+=a[i] if 2*add>suma: num=i+1 break print (num)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; long long t, n, x, cnt, Max, Min, ans, now; string s; bool flag; signed main() { cin >> t; while (t) { --t; cin >> n >> x; cin >> s; cnt = 0; ans = 0; for (long long i = 0; i < n; ++i) { if (s[i] == '0') { ++cnt; } else { --cnt; } } flag = false; now = 0; for (long long i = 0; i < n; ++i) { if (cnt == 0) { if (now == x) { flag = true; break; } } else { if ((x - now) % cnt == 0 && (x - now) * cnt >= 0) { ++ans; } } if (s[i] == '0') { ++now; } else { --now; } } if (flag) { ans = -1; } cout << ans << endl; } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 1000; string a[maxn], b[maxn]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i <= n; ++i) cin >> b[i]; int ans = 0; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { if (a[i] == b[j]) { a[i] = b[j] = ""; break; } } } for (int i = 1; i <= n; ++i) { if (a[i] == "") continue; int tm = 1000, p = 0; for (int j = 1; j <= n; ++j) { if (a[i].size() == b[j].size()) { int cnt = 0; for (int k = 0; k < a[i].size(); ++k) if (a[i][k] != b[j][k]) cnt++; if (tm > cnt) tm = cnt, p = j; } } ans += tm; b[p] = ""; } cout << ans << endl; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; vector<int> a, b; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int i, n, t; cin >> n; for (i = 0; i < n; i++) { cin >> t; if (t != 0) a.push_back(t); } for (i = 0; i < n - 1; i++) if (a[i] != 0) a.push_back(a[i]); for (i = 0; i < n; i++) { cin >> t; if (t != 0) b.push_back(t); } for (i = 0; i < a.size(); i++) { if (a[i] == b[0]) { bool u = true; for (int j = i; j < i + n - 1; j++) if (a[j] != b[j - i]) u = false; if (u == false) cout << "NO"; else cout << "YES"; return 0; } } return 0; }
8
CPP
#include <bits/stdc++.h> const long double pi = 2 * acos(0.0); using namespace std; string s1 = "RGB", s2 = "GBR", s3 = "BRG"; long long fun(string s1, string s2) { long long ans = 0; for (long long i = 0; i < (long long)s1.size(); ++i) if (s1[i] != s2[i % 3]) ++ans; return ans; } int32_t main() { ios_base::sync_with_stdio(0); long long q; cin >> q; while (q--) { long long n, k, ans; string s; cin >> n >> k >> s; ans = n; for (long long i = 0; i <= n - k; ++i) { string temp = s.substr(i, k); ans = min(ans, min(fun(temp, s1), min(fun(temp, s2), fun(temp, s3)))); } cout << ans << endl; } return 0; }
10
CPP
# -*- coding: utf-8 -*- """ Created on Sat Mar 23 01:11:54 2019 @author: albasha """ s = input() s1 = s.lower() s = input() s2 = s.lower() if(s1 > s2): print(1) elif(s2>s1): print(-1) else: print(0)
7
PYTHON3
n=int(input()) d=[int(x) for x in input().split()] c=d.count(1) if c>0: print('HARD') else: print('EASY')
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int i, j, b, n, a[2001], mx; int main() { cin >> n >> b; for (i = 1; i <= n; i++) cin >> a[i]; mx = b; for (i = 1; i <= n - 1; i++) for (j = i + 1; j <= n; j++) if (mx < (b / a[i]) * a[j] + b % a[i]) mx = (b / a[i]) * a[j] + b % a[i]; cout << mx; }
8
CPP
#include <bits/stdc++.h> using namespace std; bool isPrime(long long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, k; cin >> n >> k; long long int a[n + 1], b[n + 1]; char ans[n + 1]; set<long long int> st; for (long long int i = 1; i <= n; i++) { cin >> a[i]; b[a[i]] = i; st.insert(i); } char w = '1'; for (long long int i = n; i > 0; i--) { long long int idx = b[i]; if (st.count(idx)) { auto e = st.end(); e--; auto it = st.find(idx); auto itf = it, itb = it; if (it == st.begin()) { itf++; } else if (it == e) { itb--; } else { itf++; itb--; } vector<long long int> v; v.push_back(*it); long long int z = k; while (z--) { if (itf == st.end()) break; v.push_back(*itf); itf++; } z = k; while (z--) { v.push_back(*itb); if (itb == st.begin()) break; itb--; } for (auto g : v) { ans[g] = w; st.erase(g); } if (w == '1') { w = '2'; } else { w = '1'; } } } for (long long int i = 1; i <= n; i++) { cout << ans[i]; } }
11
CPP
#include <bits/stdc++.h> using namespace std; const long double PI = acos(-1.0l); const long long MOD = 1e9 + 7; bool debug = 0; const int N = 1; long long n, m, r, k; long long w, h; long long currn, currm; long double ans = 0, falta = 0; long long qualmenor(long long ii, long long val) { long long lo = 1, hi = currm; while (lo < hi) { long long mid = (lo + hi) / 2; if (ii * mid < val) { lo = mid + 1; } else hi = mid; } if (ii * lo >= val) return lo; return 0; } long long qnt(long long val) { long long ans = 0; for (int i = 1; i <= currn; i++) { long long j = qualmenor(i, val); if (j == 0) continue; long long nn; if (i == currn) { nn = h * (2 * (currm - j) + w); } else { nn = 4 * (currm - j); nn += 2 * w; } ans += nn; } return ans; } int main() { cin >> n >> m >> r >> k; if (m > n) swap(n, m); long long div = (n - r + 1) * (m - r + 1); if (r == 1) { ans = (long double)k / div; printf("%.10lf\n", (double)ans); return 0; } currn = 0, currm; ans = 0; if (n >= 2 * r + 1) { h = n - 2 * r + 2; currn = r; } else if (n == 2 * r) { currn = r; h = 2; } else { currn = n - r + 1; h = n - 2 * (n - r); } if (m >= 2 * r + 1) { w = m - 2 * r + 2; currm = r; } else if (m == 2 * r) { currm = r; w = 2; } else { currm = m - r + 1; w = m - 2 * (m - r); } long long lo = 1, hi = currn * currm + 1; while (lo < hi) { long long mid = (lo + hi) / 2; if (qnt(mid) >= k) { lo = mid + 1; } else { hi = mid; } } lo--; long long falta = k; if (debug) cout << "lo" << " = " << (lo) << endl; map<long double, long long> mapa; for (int i = 1; i <= currn; i++) { for (int j = currm; j >= 0; j--) { long long ii = i; if (ii * j <= lo) break; long long nn = 4; if (ii == currn and j == currm) nn = w * h; else if (ii == currn) nn = 2 * h; else if (j == currm) nn = 2 * w; for (int k = 0; k < nn; k++) { ans += (long double)ii * j / div; mapa[(long double)ii * j / div]++; falta--; } } } for (int i = 0; i < falta; i++) { mapa[(long double)lo / div]++; ans += (long double)lo / div; } for (auto it : mapa) { if (debug) cout << "it" << ".fi=" << (it).first << " " << "it" << ".se=" << (it).second << endl; } printf("%.10lf\n", (double)ans); if (debug) cout << "h" << " = " << (h) << endl; if (debug) cout << "w" << " = " << (w) << endl; if (debug) cout << "h * w" << " = " << (h * w) << endl; if (debug) cout << "(h + 2) * (w)" << " = " << ((h + 2) * (w)) << endl; return 0; }
10
CPP
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Fri Sep 4 21:29:10 2020 @author: suneelvarma """ """ array restoration: 5 2 1 49 n x y 5 20 50 6 20 50 5 3 8 9 13 22 1 49 20 40 30 50 10 26 32 20 38 44 50 8 23 18 13 3 1 10 13 4 19 22 25 16 7 """ def Search(n, low, high): arr = [] limit = (10**9)+1 for piv in range(low+1,high+1): d1,d2 = piv-low, high-piv if d2%d1 == 0 and (high-low)//d1 <= n-1: break piv -= low for num in range(low,high+1,piv): if not n: break arr.append(num) n -= 1 for num in range(low-piv, 0, -piv): if not n: break arr.append(num) n -= 1 for num in range(high+piv, limit, piv): if not n: break arr.append(num) n -= 1 return arr if __name__ == "__main__": t = int(input()) for _ in range(t): n,x,y = tuple(map(int,input().split())) print(*Search(n,x,y))
9
PYTHON3
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (n); ++i) template<class Abel> struct UnionFind { vector<int> par; vector<int> size; vector<int> rank; vector<Abel> diff_weight; UnionFind(int n) { init(n); } void init(int n) { par.resize(n); size.assign(n,1); rank.resize(n); diff_weight.resize(n); for (int i = 0; i < n; ++i) par[i] = i; } int root(int x) { if (par[x] == x) { return x; } else { int r = root(par[x]); size[x] = size[r]; diff_weight[x] += diff_weight[par[x]]; return par[x] = r; } } int scale(int x) { return size[root(x)]; } Abel weight(int x) { root(x); return diff_weight[x]; } Abel diff(int x, int y) { return weight(y) - weight(x); } bool is_same(int x, int y) { return root(x) == root(y); } bool merge(int x, int y, Abel w = 0) { w += weight(x); w -= weight(y); x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) { swap(x,y); w = -w; } if (rank[x] == rank[y]) ++rank[x]; size[x] += size[y]; par[y] = x; diff_weight[y] = w; return true; } }; int main(){ int n,q; cin >> n >> q; UnionFind<int> uf(n); rep(i,q){ int x,y,z,t; cin >> t; if(t){ cin >> x >> y; if(uf.is_same(x,y)) cout << uf.diff(x,y) << endl; else cout << "?\n"; }else{ cin >> x >> y >> z; uf.merge(x,y,z); } } }
0
CPP
n = int(input()) s = list(map(int, list(input()))) cnt = len(s) - sum(s) if len(s) == 1: print(s[0]) else: print("1" + "0"*cnt)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; int n, m, cnt, tot; int a[N], vis[N]; unsigned int Ans[N], b[N]; set<int> s[N]; struct node { int opt, l, r, w; } que[N * 7], q[N * 7]; inline void modify(int p, int v) { for (; p <= n; p += p & -p) b[p] += v; } inline int query(int p, int r = 0) { for (; p; p ^= p & -p) r += b[p]; return r; } void solve(int l, int r) { int flag = 0; for (int i = l; i <= r; ++i) if (que[i].opt == 2) flag = 1; if (!flag || l == r) return; const int mid = l + r >> 1; solve(l, mid); solve(mid + 1, r); tot = 0; for (int i = l; i <= mid; ++i) if (que[i].opt == 1) q[++tot] = que[i]; for (int i = mid + 1; i <= r; ++i) if (que[i].opt == 2) q[++tot] = que[i]; sort(q + 1, q + tot + 1, [](const node &a, const node &b) { return a.r == b.r ? a.opt < b.opt : a.r < b.r; }); for (int i = 1; i <= tot; ++i) if (q[i].opt == 1) modify(q[i].l, q[i].w); else Ans[q[i].w] += query(n) - query(q[i].l - 1); for (int i = 1; i <= tot; ++i) if (q[i].opt == 1) modify(q[i].l, -q[i].w); } inline int read(register int x = 0, register char ch = getchar(), register int f = 0) { for (; !isdigit(ch); ch = getchar()) f = ch == '-'; for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48); return f ? -x : x; } int main() { n = read(); m = read(); for (int i = 1; i <= n; ++i) a[i] = read(), s[a[i]].insert(i); for (int i = 1; i <= n; ++i) if (s[i].size() > 1) for (auto it = s[i].begin(); next(it) != s[i].end(); ++it) que[++cnt] = (node){1, *it, *next(it), *next(it) - *it}; for (int i = 1, opt, l, r; i <= m; ++i) { opt = read(); l = read(); r = read(); if (opt == 1) { auto it = s[a[l]].find(l); if (it != s[a[l]].begin()) que[++cnt] = (node){1, *prev(it), *it, -*it + *prev(it)}; if (next(it) != s[a[l]].end()) que[++cnt] = (node){1, *it, *next(it), -*next(it) + *it}; if (it != s[a[l]].begin() && next(it) != s[a[l]].end()) que[++cnt] = (node){1, *prev(it), *next(it), *next(it) - *prev(it)}; s[a[l]].erase(it); a[l] = r; it = s[a[l]].insert(l).first; if (it != s[a[l]].begin()) que[++cnt] = (node){1, *prev(it), *it, *it - *prev(it)}; if (next(it) != s[a[l]].end()) que[++cnt] = (node){1, *it, *next(it), *next(it) - *it}; if (it != s[a[l]].begin() && next(it) != s[a[l]].end()) que[++cnt] = (node){1, *prev(it), *next(it), -*next(it) + *prev(it)}; } else que[++cnt] = (node){2, l, r, i}; } solve(1, cnt); for (int i = 1; i <= cnt; ++i) if (que[i].opt == 2) printf("%u\n", Ans[que[i].w]); return 0; }
9
CPP
n=int(input()) b=int(input()) c=0 for i in range(1,n): a=int(input()) if a!=b: c+=1 b=a print(c+1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n, m; while (cin >> n >> m) { int l = 0, r = n + 1, s; char ch[10]; for (int i = 0; i < m; ++i) { scanf("%*s%*s%s%*s%d", ch, &s); if (ch[0] == 'r') l = max(s, l); else r = min(s, r); } if (l + 1 >= r) cout << -1 << endl; else cout << r - l - 1 << endl; } return 0; }
7
CPP
try: N=int(input()) s=input() l=[] l1=dict() for i in range(len(s)-1): l.append(s[i:i+2]) s=set(l) for i in s: l1[i]=l.count(i) ans=max(l1,key=l1.get) print(ans) except EOFError: pass
8
PYTHON3
#include <stdio.h> #include <string.h> #include <ctype.h> #include <queue> #include <utility> using namespace std; char space[60][11]; const int dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1}; int w, h; double hps(int on[60][10],int x,int y){ int flag[60][10], i, j, cnt; double xsum, M; queue<int> xq,yq; memset(flag,0,sizeof(flag)); xq.push(x); yq.push(y); while(xq.size()){ x = xq.front(); y = yq.front(); xq.pop(); yq.pop(); flag[y][x] = 1; for(i = 0;i < 4;i++){ if(x + dx[i] >= 0 && x + dx[i] < w && y + dy[i] >= 0 && y + dy[i] < h && !flag[y + dy[i]][x + dx[i]] && (space[y][x] == space[y + dy[i]][x + dx[i]] || (dy[i] == 1 && on[y + dy[i]][x]))){ xq.push(x + dx[i]); yq.push(y + dy[i]); } } } cnt = xsum = 0; for(i = 0;i < h;i++){ for(j = 0;j < w;j++){ if(flag[i][j]){ cnt++; xsum += j + 0.5; } } } M = (double)xsum / cnt; return M; } int main(void){ int i, j, k, xl, xr; int flag[60][10]; int past[60][10]; queue<double> M; queue<int> l, r, qx, qy; scanf("%d%d%*c",&w,&h); memset(flag,0,sizeof(flag)); memset(past,0,sizeof(past)); while(w != 0 || h != 0){ for(i = h - 1;i >= 0;i--){ for(j = 0;j < w;j++) space[i][j] = getchar(); getchar(); } for(i = 0;i < h;i++) for(j = 0;j < w;j++) if((i == 0 && isdigit(space[i][j])) || (i != 0 && isdigit(space[i][j]) && isdigit(space[i - 1][j]) && space[i][j] != space[i - 1][j])) flag[i][j] = 1; for(i = 0;i < h;i++){ for(j = 0;j < w;j++){ if(flag[i][j]){ M.push(hps(flag,j,i)); int x, y; qx.push(j); qy.push(i); xr = -1; xl = 11; char tmp = space[i][j]; while(qx.size()){ x = qx.front(); y = qy.front(); qx.pop(); qy.pop(); if(flag[y][x] && xr < x) xr = x; if(flag[y][x] && xl > x) xl = x; space[y][x] = '.'; flag[y][x] = 0; for(k = 0;k < 4;k++){ if(x + dx[k] >= 0 && x + dx[k] < w && y + dy[k] >= 0 && y + dy[k] < h && tmp == space[y + dy[k]][x + dx[k]]){ qx.push(x + dx[k]); qy.push(y + dy[k]); } } } r.push(xr + 1); l.push(xl); } } } while(M.size()){ if(l.front() < M.front() && M.front() < r.front()){ M.pop(); r.pop(); l.pop(); continue; }else break; } if(!M.size()) printf("STABLE\n"); else printf("UNSTABLE\n"); while(M.size()){ M.pop(); r.pop(); l.pop(); } scanf("%d%d%*c",&w,&h); } return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; using ll = long long; template <typename T> bool chmax(T& x, T y) { return x < y ? (x = y, true) : false; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m, k; cin >> n >> m >> k; enum Type { leave, enter }; vector<tuple<int, Type, int>> events; for (int i = 0; i < n; ++i) { int l, r; cin >> l >> r; events.emplace_back(l, enter, i); events.emplace_back(r + 1, leave, i); } sort(begin(events), end(events)); vector<int> o(1 << k); for (int mask = 1; mask < (1 << k); ++mask) { int lsb = mask & -mask; o[mask] = 1 ^ o[mask ^ lsb]; } vector<int> dp(1 << k, -m), I(k, -1); int last = 0; dp[0] = 0; for (auto [x, t, i] : events) { if (last != x) { for (int mask = 0; mask < (1 << k); ++mask) { dp[mask] += (x - last) * o[mask]; } last = x; } if (t == enter) { int j = 0; while (I[j] != -1) ++j; I[j] = i; for (int mask = 0; mask < (1 << k); ++mask) { if (~mask >> j & 1) { chmax(dp[mask | 1 << j], dp[mask]); } } } else { int j = 0; while (I[j] != i) ++j; I[j] = -1; for (int mask = 0; mask < (1 << k); ++mask) { if (mask >> j & 1) { chmax(dp[mask ^ (1 << j)], dp[mask]); dp[mask] = -m; } } } } int ans = *max_element(begin(dp), end(dp)); cout << ans << endl; exit(0); }
10
CPP
s=input() x=s[0] print(x.capitalize()+s[1:])
7
PYTHON3
n, m = list(map(int, input().split())) flag = 0 for i in range(n): if i % 2 == 0: print(m * '#') else: if flag == 0: print((m - 1) * '.' + '#') flag = 1 else: print('#' + (m - 1) * '.') flag = 0
7
PYTHON3
x,k=map(int,input().split()) #x=60 #k=5 if x==1: print(1) import sys sys.exit() import math L=int(math.sqrt(x)) mod=10**9+7 FACT=dict() for i in range(2,L+2): while x%i==0: FACT[i]=FACT.get(i,0)+1 x=x//i if x!=1: FACT[x]=FACT.get(x,0)+1 def prod(A,B,k,l,m):#A:k*l,B:l*m C=[[None for i in range(m)] for j in range(k)] for i in range(k): for j in range(m): ANS=0 for pl in range(l): ANS=(ANS+A[i][pl]*B[pl][j])%mod C[i][j]=ANS return C def plus(A,B,k,l):#a,B:k*l C=[[None for i in range(l)] for j in range(k)] for i in range(k): for j in range(l): C[i][j]=(A[i][j]+B[i][j])%mod return C #XX=[[1,1],[1,1],[1,1]] #YY=[[2,2,2],[2,3,4]] #print(prod(XX,YY,3,2,3)) MAT_index=max(FACT.values())+1 MAT=[[0 for i in range(MAT_index)] for j in range(MAT_index)] for m in range(MAT_index): for l in range(m+1): x=pow(m+1,mod-2,mod) MAT[m][l]=x #print(MAT) #MAT_ini=MAT #for i in range(k-1): # MAT=prod(MAT,MAT_ini,MAT_index,MAT_index,MAT_index) #ここをダブリング MAT_dob=[None]*14 MAT_dob[0]=MAT for i in range(1,14): MAT_dob[i]=prod(MAT_dob[i-1],MAT_dob[i-1],MAT_index,MAT_index,MAT_index) MAT=[[0 for i in range(MAT_index)] for j in range(MAT_index)] for i in range(MAT_index): MAT[i][i]=1 for i in range(14): if k & 1<<i !=0: #print(i,MAT,MAT_dob[i]) MAT=prod(MAT,MAT_dob[i],MAT_index,MAT_index,MAT_index) #print(MAT) #print(MAT) ANS=1 for fa in FACT: x=FACT[fa] ANS_fa=0 for i in range(x+1): ANS_fa=(ANS_fa+pow(fa,i,mod)*MAT[x][i])%mod ANS=ANS*ANS_fa%mod print(ANS)
10
PYTHON3
t = int(input()) for _ in range(t): n=int(input()) lis=list(map(int,input().split())) ai=lis[0] b=lis[1] c=ai+b fg=0 d=0 for i in range(2,n): if(c<=lis[i]): fg=1 d=i+1 break if fg==0: print(-1) else: print(1,2,d)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; vector<int> v(100001); int c[100001]; int a[100001]; void solve() { map<string, int> mp; int n; cin >> n; int ok[4] = {0}; vector<string> s = {"A", "B", "C", "AB", "AC", "BC", "ABC"}; for (int i = 0; i < n; i++) { int x; string a; cin >> x >> a; sort(a.begin(), a.end()); for (auto j : a) ok[j - 'A'] = 1; for (int j = 0; j < s.size(); j++) { int ch = 0; for (int k = 0; k < a.length(); k++) { for (int r = 0; r < s[j].length(); r++) { if (a[k] == s[j][r]) ch++; } } if (ch == s[j].length()) { if (mp.find(s[j]) != mp.end()) { mp[s[j]] = min(mp[s[j]], x); } else { mp[s[j]] = x; } } } } for (int i = 0; i < 3; i++) { if (ok[i] == 0) { cout << "-1\n"; return; } } int ans = INT_MAX; vector<vector<string>> v = { {"A", "BC"}, {"A", "B", "C"}, {"AB", "C"}, {"AC", "B"}, {"ABC"}}; for (int i = 0; i < v.size(); i++) { int cur = 0, ch = 0; for (int j = 0; j < v[i].size(); j++) { if (mp.find(v[i][j]) == mp.end()) { ch = 1; break; } cur += mp[v[i][j]]; } if (ch == 1) continue; ans = min(ans, cur); } cout << ans << "\n"; } int main() { int t = 1; while (t--) { solve(); } }
8
CPP
n=int(input()) l=list(map(int,input().split())) ans=1 c=1 for i in range(1,n): if(l[i]>l[i-1]): c+=1 else: c=1 if(c>ans): ans=c if(c>ans): ans=c print(ans)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; struct vec { int to; int fro; }; int fa[200010], son[200010][26], mx[200010]; int rt, lst, tot; int n, m; char s[200010]; vec mp[200010]; int tai[200010], cnt; int P[200010]; int ans[200010]; vector<int> qs[200010]; int av[200010]; int len[200010]; int Rt[200010], Son[4000010][2]; int TOT; inline void be(int x, int y) { mp[++cnt].to = y; mp[cnt].fro = tai[x]; tai[x] = cnt; } int merge(int x, int y) { if (!x || !y) { return x + y; } Son[x][0] = merge(Son[x][0], Son[y][0]); Son[x][1] = merge(Son[x][1], Son[y][1]); return x; } void change(int &x, int y, int z, int p) { if (!x) { x = ++TOT; } if (y == z) { return; } int mid = y + z >> 1; if (p <= mid) { change(Son[x][0], y, mid, p); } else { change(Son[x][1], mid + 1, z, p); } } void ins(int x) { int np = ++tot, p = lst; mx[np] = mx[p] + 1; while (p && !son[p][x]) { son[p][x] = np; p = fa[p]; } if (!p) { fa[np] = rt; } else { int q = son[p][x]; if (mx[q] == mx[p] + 1) { fa[np] = q; } else { int nq = ++tot; mx[nq] = mx[p] + 1; memcpy(son[nq], son[q], sizeof(son[q])); fa[nq] = fa[q]; fa[np] = fa[q] = nq; while (p && son[p][x] == q) { son[p][x] = nq; p = fa[p]; } } } lst = np; } int L; int t[200010]; void DFS(int x, int y, int z) { if (y == z) { t[++L] = y; return; } int mid = y + z >> 1; if (Son[x][0]) { DFS(Son[x][0], y, mid); } if (Son[x][1]) { DFS(Son[x][1], mid + 1, z); } } void dfs(int x) { int i, y; for (i = tai[x]; i; i = mp[i].fro) { y = mp[i].to; dfs(y); } for (i = tai[x]; i; i = mp[i].fro) { y = mp[i].to; Rt[x] = merge(Rt[x], Rt[y]); } L = 0; if (qs[x].size()) { L = 0; DFS(Rt[x], 1, n); for (i = 0; i < qs[x].size(); i++) { int wzh = 1; int ti = qs[x][i]; int tav = av[qs[x][i]]; if (L < tav) { ans[ti] = -1; } else { ans[ti] = 1000000000; for (int j = tav; j <= L; j++) { ans[ti] = min(ans[ti], t[j] - t[j - tav + 1] + len[ti]); } } } } } int main() { int i, x; lst = rt = tot = 1; scanf("%s", s + 1); n = strlen(s + 1); int p = rt; for (i = 1; i <= n; i++) { ins(s[i] - 'a'); p = son[p][s[i] - 'a']; P[i] = p; change(Rt[p], 1, n, i); } for (i = 2; i <= tot; i++) { be(fa[i], i); } scanf("%d", &m); for (i = 1; i <= m; i++) { scanf("%d%s", &av[i], s + 1); int p = rt; for (int j = 1; s[j]; j++) { p = son[p][s[j] - 'a']; } len[i] = strlen(s + 1); if (!p) { ans[i] = -1; } else { qs[p].push_back(i); } } dfs(1); for (i = 1; i <= m; i++) { printf("%d\n", ans[i]); } return 0; }
10
CPP
t = int(input()) a = [0] * 3 *10**5 for _ in range(t): n = int(input()) if n%4: print("NO") continue print('Yes') for i in range(2,n+1,2): print(i) for i in range(1,n-1,2): print(i) print(n - 1 + int(n/2))
8
PYTHON3
M = {'A':'T', 'T': 'A', 'C':'G', 'G':'C'} print(M[input()])
0
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int x, y; cin >> x >> y; bool ceil = false; while (true) { if (!ceil) { if (x > 1 && y > 1) { x -= 2; y -= 2; ceil = !ceil; } else if (x == 1 && y >= 12) { x--; y -= 12; ceil = !ceil; } else if (y >= 22) { y -= 22; ceil = !ceil; } else break; } else { if (y >= 22) { y -= 22; ceil = !ceil; } else if (x > 0 && y >= 12) { x--; y -= 12; ceil = !ceil; } else if (x > 1 && y > 1) { x -= 2; y -= 2; ceil = !ceil; } else break; } } if (ceil) { cout << "Ciel"; } else cout << "Hanako"; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { int a,b; cin>>a>>b; if(a==b)cout<<2*a<<endl; else cout<<max(a,b)+max(a,b)-1<<endl; }
0
CPP
#include <bits/stdc++.h> using namespace std; string t = "abacaba"; long long substr(string str) { bool flag = false; long long c = 0; string sub_str = "abacaba"; for (long long i = 0; i < str.length(); i++) { if (str.substr(i, sub_str.length()) == sub_str) { c++; flag = true; } } return c; } bool check(string s, long long index) { for (long long i = 0; i < 7; i++) { if (s[index + i] == '?') s[index + i] = t[i]; else if (s[index + i] != t[i]) return false; } long long cnt = 0; long long n = s.size(); for (long long i = 0; i < n; i++) if (s[i] == '?') s[i] = 'd'; long long ocur = substr(s); if (ocur == 1) { cout << "YES" << endl; cout << s << endl; return true; } return false; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) { long long n; cin >> n; string s; cin >> s; bool ok = false; for (long long i = 0; i < n - 6; i++) { if (check(s, i)) { ok = true; break; } } if (ok) continue; cout << "NO" << endl; } }
7
CPP
#include <bits/stdc++.h> using namespace std; long long n, k; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> k; cout << k / n + (k % n != 0); return 0; }
7
CPP
""" https://codeforces.com/problemset/problem/1136/A """ n = int(input()) chapters = [] for n in range(n): chapters.append([int(x) for x in input().split(" ")]) page = int(input()) i = 0 while i <= n: if chapters[i][1] >= page: break i += 1 print(str(n-i+1))
7
PYTHON3
t = ["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"] n = int(input()) p = input() for i in t: if n == len(i) and all(i[j] == p[j] for j in range(n) if p[j] != '.'): print(i) break
7
PYTHON3
num = int(input()) def getSum(num) : return sum([int(i) for i in str(num)]) def f(num) : if num[-1] != '0' : return int(num) return f(num[:-1]) reachable = [num] while True : num = f(str(num + 1)) if num not in reachable : reachable.append(num) else : break print(len(reachable))
7
PYTHON3
sx,sy,tx,ty=map(int,input().split()) print("R"*(tx-sx)+"U"*(ty-sy)+"L"*(tx-sx)+"D"*(ty-sy)+"L"+"U"*(ty-sy+1)+"R"*(tx-sx+1)+"D"+"R"+"D"*(ty-sy+1)+"L"*(tx-sx+1)+"U")
0
PYTHON3
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (int)(n); ++i) const int INF = 1e9; class bipartite_matching { public: int n; vector<vector<int>> g; vector<int> match; bipartite_matching(int n_) : n(n_), g(n_), match(n_), used(n_) {} void add_edge(int u, int v) { g[u].push_back(v); g[v].push_back(u); } int maximum_matching(void) { int res = 0; fill(begin(match), end(match), -1); for(int v = 0; v < n; ++v){ if (match[v] < 0) { fill(begin(used), end(used), false); if (dfs(v)) res++; } } return res; } private: vector<int> used; bool dfs(int v) { used[v] = true; for (int u: g[v]) { int w = match[u]; if (w < 0 || (!used[w] && dfs(w))) { match[v] = u; match[u] = v; return true; } } return false; } }; int N,M,L; int mat[110][110]; pair<int,int> node[1010]; int main(){ while(cin >> N >> M >> L && N){ rep(i,N)rep(j,N) mat[i][j] = (i == j ? 0 : INF); rep(i,M){ int u,v,d; cin >> u >> v >> d; mat[u][v] = mat[v][u] = d; } rep(k,N)rep(i,N)rep(j,N) mat[i][j] = min(mat[i][j], mat[i][k]+mat[k][j]); rep(i,L) cin >> node[i].second >> node[i].first; sort(node, node+L); bipartite_matching bm(L*2); rep(i,L)rep(j,i){ int dt = node[i].first - node[j].first; int dist = mat[node[i].second][node[j].second]; if(dt >= dist){ bm.add_edge(j, i+L); } } int f = bm.maximum_matching(); cout << L-f << endl; } }
0
CPP
#include<bits/stdc++.h> using namespace std; #define int long long typedef pair<int,int>pint; typedef vector<int>vint; typedef vector<pint>vpint; #define pb push_back #define mp make_pair #define fi first #define se second #define all(v) (v).begin(),(v).end() #define rep(i,n) for(int i=0;i<(n);i++) #define reps(i,f,n) for(int i=(f);i<(n);i++) #define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++) template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;} template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;} signed main(){ int W;cin>>W; string s; for(int i=3;W;i*=3){ int tmp=W%3; if(tmp==0)s+="0"; else if(tmp==1)s+="+"; else{ s+="-"; W+=3; } W/=3; } reverse(all(s)); cout<<s<<endl; }
0
CPP
import math import sys import re n , m = map(int , input().rstrip().split()) l1 = [] for x in range(n): s = input() l1.append(s) l2 = list(map(int , input().rstrip().split())) total = 0 for i in range(m): a = 0 b = 0 c = 0 d = 0 e = 0 for j in l1: if j[i] == 'A': a = a + 1 elif j[i] == 'B': b = b + 1 elif j[i] == 'C': c = c + 1 elif j[i] == 'D': d = d + 1 elif j[i] == 'E': e = e + 1 mx = max(a , b , c , d , e) total = total + mx*l2[i] print(total)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template <typename T> void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } const int N = 3e5 + 5; const long long M = 1e9 + 7; long long power(long long x, long long y) { x %= M; long long ans = 1; while (y) { if (y & 1) ans = (ans * x) % M; y >>= 1LL; x = (x * x) % M; } return ans; } long long ad(long long a, long long b) { return ((a % M + b % M) % M); } long long sub(long long a, long long b) { return ((a % M - b % M + M) % M); } long long mul(long long a, long long b) { return (((a % M) * (b % M)) % M); } long long divi(long long a, long long b) { return (mul(a, power(b, M - 2)) % M); } int main() { ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long a, b, n, x; cin >> a >> b >> n >> x; long long sum = 0; if (a == 1) { sum = n; } long long ans = mul(b, (a == 1 ? sum : divi(sub(power(a, n), 1), sub(a, 1)))); ans = ad(ans, mul(x, power(a, n))); cout << ans; return 0; }
10
CPP
from collections import Counter for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) temp = Counter(arr) f = 0 for i in arr: if temp[i] > 1: f = 1 break if f == 1: print('YES') else: print('NO')
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int ans = 0, ansarr[20000][3]; void print(int key, int i, int flg, int n) { if (key) { int r, c; if (flg) { if (i < n) { r = 1; c = i + 1; } else { r = 4; c = 2 * n - i; } ansarr[ans][0] = key; ansarr[ans][1] = r; ansarr[ans][2] = c; } else { if (i < n) { r = 2; c = i + 1; } else { r = 3; c = 2 * n - i; } ansarr[ans][0] = key; ansarr[ans][1] = r; ansarr[ans][2] = c; } ans++; } } int main() { int n, k, cnt = 0, temp, zeroIdx, i; cin >> n >> k; int a[2 * n], b[2 * n]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; } for (int i = 0; i < n; i++) { cin >> temp; b[2 * n - i - 1] = temp; } for (int i = 0; i < n; i++) { cin >> temp; a[2 * n - i - 1] = temp; } for (int i = 0; i < 2 * n; i++) { if (b[i] == 0) { cnt++; zeroIdx = i; break; } else if (b[i] == a[i]) { cnt++; zeroIdx = i; print(b[i], i, 1, n); b[i] = 0; break; } } if (cnt == 0) { cout << -1; } else { for (int z = 0; z < 2 * n; z++) { for (int j = zeroIdx + 1; j <= zeroIdx + 2 * n; j++) { i = j % (2 * n); if (j == zeroIdx + 2 * n) { b[(i - 1 + 2 * n) % (2 * n)] = 0; zeroIdx = (zeroIdx - 1 + 2 * n) % (2 * n); break; } if (b[i] == a[i]) { print(b[i], i, 1, n); b[i] = 0; swap(b[i], b[(i - 1 + 2 * n) % (2 * n)]); } else { print(b[i], (i - 1 + 2 * n) % (2 * n), 0, n); swap(b[i], b[(i - 1 + 2 * n) % (2 * n)]); } } } cout << ans << endl; for (int i = 0; i < ans; i++) { cout << ansarr[i][0] << " " << ansarr[i][1] << " " << ansarr[i][2] << endl; } } }
9
CPP
n = int(input()) ar = list(map(int, input().split())) i = 0 j = n-1 sereja = 0 dima = 0 turn = True while i<=j: if ar[i]>ar[j]: mx = ar[i] i += 1 else: mx = ar[j] j -= 1 if turn: sereja += mx else: dima += mx turn = not turn print(sereja,dima)
7
PYTHON3
#include <iostream> #include <cstring> #include <vector> using namespace std; typedef long long i64; const int MAXN = 1e5 + 10; i64 answer; i64 totCnt; i64 N, M; i64 check[MAXN]; i64 cnt[3]; bool flag; vector<pair<i64, i64> > Adj[MAXN]; inline void addEdge(i64 u, i64 v, i64 w) { Adj[u].emplace_back(v, w); } void DFS(int cur) { cnt[check[cur]] ++; for(auto x : Adj[cur]) { totCnt += (x.second == 1); if(check[x.first] != -1) { if((check[cur] + x.second) % 3 != check[x.first]) flag = true; } else { check[x.first] = (check[cur] + x.second) % 3; DFS(x.first); } } } int main() { ios::sync_with_stdio(false), cin.tie(nullptr); cin >> N >> M; for (int i = 1; i <= M; i++) { i64 u, v; cin >> u >> v; addEdge(u, v, 1); addEdge(v, u, 2); } memset(check, -1, sizeof check); for(int i = 1; i <= N; i++) { if(check[i] != -1) continue; check[i] = 0, totCnt = 0; cnt[0] = cnt[1] = cnt[2] = 0; flag = false; DFS(i); if(flag) answer += (cnt[0] + cnt[1] + cnt[2]) * (cnt[0] + cnt[1] + cnt[2]); else if(!cnt[0] || !cnt[1] || !cnt[2]) answer += totCnt; else answer += cnt[0] * cnt[1] + cnt[1] * cnt[2] + cnt[2] * cnt[0]; } cout << answer << endl ; return 0; }
0
CPP
x=int(input()) for i in range(x): t=int(input()) r=list(map(int,input().strip().split())) totalsum=sum(r) for i in range(t-1): y=r.pop() r[0]=r[0]^y finalxor=r[0] print('2') print(str(finalxor)+' '+str(finalxor+totalsum))
9
PYTHON3
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:64000000") using namespace std; const int MAXK = -1; const int MAXN = 1 << MAXK; const int MOD = 0; struct MySet { multiset<int> st; long long sum; MySet() { sum = 0; } void add(int x) { sum += x; st.insert(x); } void del(int x) { auto it = st.find(x); assert(it != st.end()); st.erase(it); sum -= x; } bool empty() { return st.empty(); } int mx() { assert(!st.empty()); return *st.rbegin(); } int mn() { assert(!st.empty()); return *st.begin(); } int size() { return st.size(); } long long getSum() { return sum; } }; struct MyHeap { MySet st1, st2; MyHeap() { st1 = MySet(); st2 = MySet(); } void add(int x) { if (st1.empty() || st1.mx() <= x) { st2.add(x); } else { st1.add(x); } } long long get(int k) { while (st1.size() > k) { int x = st1.mx(); st1.del(x); st2.add(x); } while (st1.size() < k) { int x = st2.mn(); st2.del(x); st1.add(x); } return st1.getSum(); } int size() { return st1.size() + st2.size(); } }; const long long INF = 1e18; int main() { int n, m, k; while (scanf("%d%d%d", &n, &m, &k) == 3) { vector<int> c(n); for (int i = 0; i < n; i++) scanf("%d", &c[i]); vector<int> mask(n); for (int i = 0; i < 2; i++) { int w; scanf("%d", &w); for (int j = 0; j < w; j++) { int x; scanf("%d", &x); x--; mask[x] |= 1 << i; } } vector<vector<int> > a(4); for (int i = 0; i < n; i++) a[mask[i]].push_back(c[i]); for (int i = 0; i < 4; i++) { sort(a[i].begin(), a[i].end()); } vector<vector<long long> > s(4); for (int i = 0; i < 4; i++) { s[i].resize(a[i].size() + 1); for (int j = 0; j < (int)a[i].size(); j++) { s[i][j + 1] = s[i][j] + a[i][j]; } } MyHeap h = MyHeap(); for (int i = 0; i < (int)a[0].size(); i++) h.add(a[0][i]); for (int i = 1; i <= 2; i++) { for (int j = k; j < (int)a[i].size(); j++) { h.add(a[i][j]); } } long long ans = INF; for (int common = 0; common <= min((int)a[3].size(), m); common++) { int t = max(k - common, 0); if (t <= (int)a[1].size() && t <= (int)a[2].size()) { long long cur = s[3][common]; cur += s[1][t]; cur += s[2][t]; if (common + t + t <= m && h.size() >= m - common - t - t) { ans = min(ans, cur + h.get(m - common - t - t)); } } if (t > 0) { if (t <= (int)a[1].size()) h.add(a[1][t - 1]); if (t <= (int)a[2].size()) h.add(a[2][t - 1]); } } if (ans == INF) ans = -1; cout << ans << endl; } return 0; }
11
CPP
#include<cstdio> #include<iostream> #include<vector> #include<string> #include<algorithm> #include<complex> #include<set> #include<map> #include<queue> using namespace std; #define reps(i,f,n) for(int i=f;i<int(n);i++) #define rep(i,n) reps(i,0,n) const int W = 31; const int H = 61; class P{ public: int a,b,c,d; int val; P(int a,int b,int c,int d,int val):a(a),b(b),c(c),d(d),val(val){} bool operator<(const P& tmp)const{ return val>tmp.val; } }; int h,w; char masu[H][W]; void initQue(priority_queue<P>& que){ rep(i,h)rep(j,w){ if(masu[i][j]=='S')que.push(P(i,j,i,j,0)); } } int getCost(int y,int x){ if(y<0 || x<0 || y>=h || x>=w)return -1; if(masu[y][x]=='X')return -1; if(masu[y][x]=='T')return 0; if(masu[y][x]=='S')return 0; return masu[y][x]-'0'; } void addQue(priority_queue<P> &que, P& u){ int dy[]={-2,-1,-1,0,0,0,1,1,2}; int dx[]={1,1,2,1,2,3,1,2,1}; rep(p,9){ int ny = u.a + dy[p]; int nx = u.b + dx[p]; int ncost = getCost(ny,nx); if(ncost != -1) que.push(P(u.a,u.b, ny,nx, u.val+ncost)); } rep(p,9){ int ty = u.c + dy[p]; int tx = u.d - dx[p]; int tcost = getCost(ty,tx); if(tcost != -1) que.push(P(ty,tx, u.c,u.d, u.val+tcost)); } } bool isGoal(P& u){ return masu[u.a][u.b]=='T' || masu[u.c][u.d]=='T'; } int visit[H][W][H][W]; int solve(){ rep(i,h)rep(j,w)cin>>masu[i][j]; priority_queue<P> que; initQue(que); int ans = -1; rep(i,h)rep(j,w)rep(k,h)rep(p,w)visit[i][j][k][p]=0; while(1){ if(que.empty())break; P u = que.top(); que.pop(); if(visit[u.a][u.b][u.c][u.d]==1)continue; visit[u.a][u.b][u.c][u.d]=1; //printf("(%d %d) (%d %d) %d\n",u.a,u.b,u.c,u.d,u.val); if(isGoal(u)){ ans = u.val; break; } addQue(que, u); } return ans; } int main(){ while(1){ cin>>w>>h; if(h==0 && w==0)break; printf("%d\n",solve()); } }
0
CPP
#include <bits/stdc++.h> using namespace std; inline void pisz(int n) { printf("%d\n", n); } int stat[1003]; int main() { int(n); scanf("%d", &(n)); ; stat[0] = 0; for (int(i) = 1; (i) <= (n); ++(i)) scanf("%d", stat + i); double lb = 10; double ub = 1e9; for (int(i) = 1; (i) <= (n); ++(i)) { double new_lb = 10.0 * stat[i] / i; double new_ub = 10.0 * (stat[i] + 1) / i; if (lb < new_lb) lb = new_lb; if (ub > new_ub) ub = new_ub; } double fuel1 = lb * (n + 1) - 10.0 * stat[n]; double fuel2 = ub * (n + 1) - 10.0 * stat[n]; int stop = stat[n]; while (1) { ++stop; fuel1 -= 10; fuel2 -= 10; if ((fuel1 < 10) && (fuel2 <= 10)) { printf("unique\n%d", stop); break; } else if ((fuel1 < 10) || (fuel2 <= 10)) { printf("not unique"); break; } } }
9
CPP
n = int(input()) s = [int(x) for x in input().split()] a = 0 for i in s: a += i print(a/n)
8
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 5, inf = 1e16; void ok() { cout << "YES" << '\n'; exit(0); } void no() { cout << "NO" << '\n'; exit(0); } inline long long nxt() { long long x; cin >> x; return x; } vector<long long> t(4 * N); vector<long long> a(N); int build(int v, int tl, int tr) { if (tl == tr) { t[v] = a[tl]; return 1; } else { int tm = (tl + tr) / 2; int t1 = build(v * 2, tl, tm); int t2 = build(v * 2 + 1, tm + 1, tr); if (t1 || t2) { t[v] = t[v * 2] | t[v * 2 + 1]; return 0; } else { t[v] = t[v * 2] ^ t[v * 2 + 1]; return 1; } } } int update(int v, int tl, int tr, int pos, int new_val) { if (tl == tr) { t[v] = new_val; return 1; } else { int tm = (tl + tr) / 2; int temp; if (pos <= tm) { temp = update(v * 2, tl, tm, pos, new_val); } else { temp = update(v * 2 + 1, tm + 1, tr, pos, new_val); } if (temp) { t[v] = t[v * 2] | t[v * 2 + 1]; return 0; } else { t[v] = t[v * 2] ^ t[v * 2 + 1]; return 1; } } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); long long n = (1 << nxt()); long long m = nxt(); for (int i = 0; i < n; i++) { a[i] = nxt(); } build(1, 0, n - 1); for (int i = 0; i < m; i++) { long long p = nxt(); long long b = nxt(); update(1, 1, n, p, b); cout << t[1] << '\n'; } }
10
CPP
#include <bits/stdc++.h> using namespace std; int answer, users, n, m, t, i, FreeID, hours, minutes, seconds; bool completed; pair<int, pair<int, int> > events[300000]; int id[300000]; int c[300000]; void work() { scanf("%d%d%d", &n, &m, &t); for (i = (1); i <= (n); i++) { char u; scanf("%d%c%d%c%d", &hours, &u, &minutes, &u, &seconds); seconds += 3600 * hours + 60 * minutes; events[2 * (i - 1) + 1] = make_pair(seconds, make_pair(i, 1)); events[2 * i] = make_pair(seconds + t, make_pair(i, 2)); } sort(events + 1, events + 2 * n + 1); for (i = (1); i <= (2 * n); i++) { if (events[i].second.second == 1) { if (users == m) { id[events[i].second.first] = FreeID; c[id[events[i].second.first]]++; } else { answer++; FreeID = answer; id[events[i].second.first] = answer; c[id[events[i].second.first]]++; users++; } if (users == m) { completed = true; } } else { c[id[events[i].second.first]]--; if (c[id[events[i].second.first]] == 0) { users--; } } } if (completed) { printf("%d\n", answer); for (i = (1); i <= (n); i++) { printf("%d\n", id[i]); } } else { cout << "No solution" << endl; } } int main() { work(); return 0; }
10
CPP
n = int(input()) s = input() k = s.count('z') for i in range((n-k*4)//3): print('1',end = ' ') for i in range(k): print('0',end = ' ')
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int N = 5e6 + 5; const int inf = 1791791791; const int mod = 1e9 + 7; int main() { int n; scanf("%d", &n); int count = 0; for (int i = 1; i <= n; i++) { for (int j = i; j <= n; j++) { int k = i ^ j; if (k < j || k > n) continue; if (i + j > k && i + k > j && k + j > i) { count++; } } } printf("%d\n", count); return 0; }
8
CPP
from collections import deque N = int(input()) T = [[] for i in range(N)] for i in range(N-1): a,b = map(lambda x:int(x)-1,input().split()) T[a].append(b) T[b].append(a) P = list(map(int,input().split())) P.sort(reverse=True) A = [-1]*N v = -1 for i in range(N): if len(T[i])==1: v = i break Q = deque([v]) p_index = 0 while Q: v = Q.pop() A[v] = P[p_index] p_index+=1 for c in T[v]: if A[c]==-1: Q.append(c) print(sum(P[1:])) print(*A)
0
PYTHON3
#include <iostream> using namespace std; int main() { int n,a,b; cin>>n>>a>>b; int c = 0; for (int i=0;i<n;i++) { int x;cin >> x; if (a<=x&&x<b) c++; } cout << n-c << endl; return 0; }
0
CPP
#include<bits/stdc++.h> using namespace std; int n,a[27],ans; int main(){ scanf("%d",&n); for(int i=1;i<=n;i++)scanf("%d",&a[i]); for(int i=2;i<n;i++){ if((a[i]>=a[i+1]&&a[i]<a[i-1])||(a[i]>=a[i-1]&&a[i]<a[i+1]))ans++; } printf("%d\n",ans); return 0; }
0
CPP
a=input() a4=a.count('4') a7=a.count('7') su=a7+a4 su=set(list(str(su))) if (len(su)==1 and ('4' in su or '7' in su)) or (len(su)==2 and ('4' in su and '7' in su)): print('YES') else: print('NO')
7
PYTHON3
#include <bits/stdc++.h> using namespace std; inline int read() { int k = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { k = k * 10 + ch - '0'; ch = getchar(); } return k * f; } struct ppap { int x, y; } a[5], b[5], as[5], d[30]; int cnt = 0, ans; inline void gz(int x, int y) { if (a[x].x != a[y].x && a[x].y != a[y].y) { d[++cnt] = (ppap){a[x].x, a[y].y}; d[++cnt] = (ppap){a[y].x, a[x].y}; } } int p[30]; inline void heng() { for (int i = 1; i <= 4; i++) p[i] = a[i].y; sort(p + 1, p + 5); if (p[1] != p[2] || p[3] != p[4]) return; int D = p[3] - p[2], x1 = 0, y1 = 0, x2 = 0, y2 = 0; for (int i = 1; i <= 4; i++) { if (a[i].y == p[1]) { if (x1) x2 = a[i].x; else x1 = a[i].x; } else { if (y1) y2 = a[i].x; else y1 = a[i].x; } } int X1 = min(min(x1, x2), max(x1, x2) - D), X2 = max(min(x1, x2), max(x1, x2) - D); int Y1 = min(min(y1, y2), max(y1, y2) - D), Y2 = max(min(y1, y2), max(y1, y2) - D); int X = min(X1, Y1), Y = max(X2, Y2); d[++cnt] = (ppap){(X + Y) / 2, p[1]}; } inline void shu() { for (int i = 1; i <= 4; i++) p[i] = a[i].x; sort(p + 1, p + 5); if (p[1] != p[2] || p[3] != p[4]) return; int D = p[3] - p[2], x1 = 0, y1 = 0, x2 = 0, y2 = 0; for (int i = 1; i <= 4; i++) { if (a[i].x == p[1]) { if (x1) x2 = a[i].y; else x1 = a[i].y; } else { if (y1) y2 = a[i].y; else y1 = a[i].y; } } int X1 = min(min(x1, x2), max(x1, x2) - D), X2 = max(min(x1, x2), max(x1, x2) - D); int Y1 = min(min(y1, y2), max(y1, y2) - D), Y2 = max(min(y1, y2), max(y1, y2) - D); int X = min(X1, Y1), Y = max(X2, Y2); d[++cnt] = (ppap){p[1], (X + Y) / 2}; } bool vis[30]; inline void dfs(int x, int maxx) { if (maxx > ans) return; if (x == 5) { for (int i = 1; i <= 4; i++) as[i] = b[p[i]]; ans = maxx; return; } for (int i = 1; i <= 4; i++) if (a[i].x == b[x].x || a[i].y == b[x].y) { if (vis[i]) continue; p[i] = x; vis[i] = 1; dfs(x + 1, max(maxx, max(abs(a[i].x - b[x].x), abs(a[i].y - b[x].y)))); vis[i] = 0; } } inline void work(int x) { for (int i = 1; i <= cnt; i++) { b[1] = (ppap){d[i].x, d[i].y}; b[2] = (ppap){d[i].x + x, d[i].y}; b[3] = (ppap){d[i].x, d[i].y + x}; b[4] = (ppap){d[i].x + x, d[i].y + x}; dfs(1, 0); b[1] = (ppap){d[i].x, d[i].y}; b[2] = (ppap){d[i].x - x, d[i].y}; b[3] = (ppap){d[i].x, d[i].y + x}; b[4] = (ppap){d[i].x - x, d[i].y + x}; dfs(1, 0); b[1] = (ppap){d[i].x, d[i].y}; b[2] = (ppap){d[i].x + x, d[i].y}; b[3] = (ppap){d[i].x, d[i].y - x}; b[4] = (ppap){d[i].x + x, d[i].y - x}; dfs(1, 0); b[1] = (ppap){d[i].x, d[i].y}; b[2] = (ppap){d[i].x - x, d[i].y}; b[3] = (ppap){d[i].x, d[i].y - x}; b[4] = (ppap){d[i].x - x, d[i].y - x}; dfs(1, 0); } } int main() { int T = read(); while (T--) { cnt = 0; ans = 1e9; for (int i = 1; i <= 4; i++) a[i].x = read(), a[i].y = read(), d[++cnt] = a[i]; heng(); shu(); for (int i = 1; i <= 4; i++) for (int j = i + 1; j <= 4; j++) gz(i, j); for (int i = 1; i <= 4; i++) for (int j = i + 1; j <= 4; j++) work(abs(a[i].x - a[j].x)), work(a[i].y - a[j].y); if (ans == 1e9) { puts("-1"); continue; } printf("%d\n", ans); for (int i = 1; i <= 4; i++) printf("%d %d\n", as[i].x, as[i].y); } return 0; }
10
CPP
t = int(input()) for g in range(t): matrix = [[int(j) for j in list(input())] for i in range(9)] ind = 0 for i in range(0, 9, 3): matrix[i][ind] = matrix[i + 1][ind] ind += 1 ind = 3 for i in range(1, 9, 3): matrix[i][ind] = matrix[i + 1][ind] ind += 1 ind = 6 for i in range(2, 9, 3): matrix[i][ind] = matrix[i - 1][ind] ind += 1 [print("".join([str(j) for j in i])) for i in matrix]
10
PYTHON3
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int a[N], bl[N]; struct Query { int l, r, id; } q[N]; int l = 1, r = 0, cnt[N * 10]; long long now = 0; long long Ans[N]; void add(int x) { now -= 1ll * cnt[a[x]] * cnt[a[x]] * a[x]; cnt[a[x]]++; now += 1ll * cnt[a[x]] * cnt[a[x]] * a[x]; } void del(int x) { now -= 1ll * cnt[a[x]] * cnt[a[x]] * a[x]; cnt[a[x]]--; now += 1ll * cnt[a[x]] * cnt[a[x]] * a[x]; } bool cmp(Query a, Query b) { return (bl[a.l] ^ bl[b.l]) ? bl[a.l] < bl[b.l] : ((bl[a.l] & 1) ? a.r < b.r : a.r > b.r); } int main() { int n, t; scanf("%d%d", &n, &t); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); int unt = sqrt(n); for (int i = 1; i <= n; i++) bl[i] = (i - 1) / unt + 1; for (int i = 1; i <= t; i++) { scanf("%d%d", &q[i].l, &q[i].r); q[i].id = i; } sort(q + 1, q + t + 1, cmp); for (int i = 1; i <= t; i++) { while (l < q[i].l) del(l++); while (l > q[i].l) add(--l); while (r < q[i].r) add(++r); while (r > q[i].r) del(r--); Ans[q[i].id] = now; } for (int i = 1; i <= t; i++) printf("%lld\n", Ans[i]); return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 250 + 10, mod = 998244353; int p[N][2], q[N], g[N], f[N][N], G[N], c[N << 1][N << 1], ans[N], d[N][2]; bool vis[N][2]; int cnt[5], fac[N]; void dfs(int x, int d, int st) { vis[x][d] = true; if (p[x][d]) { if (!vis[p[x][d]][d ^ 1]) dfs(p[x][d], d ^ 1, st); else cnt[4]++; } else cnt[(st << 1) | d]++; } int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &q[i]), p[q[i]][0] = i; if (q[i]) d[i][1]++; } for (int i = 1; i <= n; i++) scanf("%d", &p[i][1]), d[p[i][1]][0]++; for (int i = 1; i <= n; i++) for (int d0 = 0; d0 <= 1; d0++) if (!vis[i][d0] && !d[i][d0]) dfs(i, d0, d0); for (int i = 1; i <= n; i++) for (int d0 = 0; d0 <= 1; d0++) if (!vis[i][d0]) dfs(i, d0, d0); int l = cnt[0]; assert(cnt[0] == cnt[3]); fac[0] = 1; for (int i = 1; i <= n; i++) fac[i] = 1LL * fac[i - 1] * i % mod; int m = n << 1; for (int i = 0; i <= m; i++) { c[i][0] = c[i][i] = 1; for (int j = 1; j <= i - 1; j++) c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod; } for (int i = 0; i <= n; i++) g[i] = 1LL * fac[l] * fac[i] % mod * (l == 0 ? (i == 0 ? 1 : 0) : c[i + l - 1][l - 1]) % mod; f[0][0] = 1; for (int i = 1; i <= n; i++) for (int j = 1; j <= i; j++) f[i][j] = (f[i - 1][j - 1] + f[i - 1][j] * 1LL * (i - 1)) % mod; int l2 = cnt[2], l1 = cnt[1]; for (int t = 0; t <= n; t++) { G[t] = 0; for (int k = 0; k <= l2; k++) G[t] = (G[t] + g[k] * 1LL * f[l2 - k][t] % mod * c[l2][k]) % mod; } for (int i = 0; i <= n; i++) for (int t = 0; t <= i; t++) ans[i] = (ans[i] + 1LL * f[l1 + l][i - t] * G[t] % mod) % mod; for (int i = n; i >= 1; i--) if (i >= cnt[4]) ans[i] = ans[i - cnt[4]]; else ans[i] = 0; for (int i = 1; i <= n; i++) printf("%d ", ans[n - i + 1]); printf("\n"); return 0; }
11
CPP
#include <bits/stdc++.h> using namespace std; using ll = long long; using Pii = pair<int, int>; using Vi = vector<int>; void run(); int main() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(18); run(); return 0; } int uplg(int n) { return 32 - __builtin_clz(n); } int uplg(ll n) { return 64 - __builtin_clzll(n); } struct Banned { int begin, end, height, cost; bool operator<(const Banned& r) const { return height < r.height; } }; int dp[51][51][51]; vector<Banned> bans; int solve(int begin, int end, int height) { int& ret = dp[begin][end][height]; if (ret >= 0) return ret; ret = 0; for (int i = (begin); i < (end); i++) { int cost = 0, j = 0; for (int h = (0); h < (height + 1); h++) { while (j < int((bans).size())) { auto& b = bans[j]; if (b.height >= h) break; if (b.begin >= begin && b.end <= end && b.begin <= i && b.end >= i + 1) { cost += b.cost; } j++; } ret = max(ret, solve(begin, i, h) + solve(i + 1, end, h) - cost + h * h); } } return ret; } void run() { int n, h, m; cin >> n >> h >> m; bans.resize(m); for (auto& b : (bans)) { cin >> b.begin >> b.end >> b.height >> b.cost; b.begin--; } sort((bans).begin(), (bans).end()); for (int i = (0); i < (n + 1); i++) for (int j = (0); j < (n + 1); j++) for (int k = (0); k < (h + 1); k++) dp[i][j][k] = -1; cout << solve(0, n, h) << endl; }
13
CPP
n = int(input()) x = 0 while n != 0: proposal = str(input()) if proposal[1] == '+': x += 1 else: x -= 1 n -= 1 print(x)
7
PYTHON3
n=int(input()) s=input() if s.count('SF')>s.count('FS') : print("YES") else: print("NO");
7
PYTHON3
for t in range(int(input())): x = int(input()) if x > 30: print('YES') if x == 36: print(5,6,10,15) elif x == 40: print(6,9,10,15) elif x == 44: print(6,10,13,15) else: print(6,10,14,x-30) else: print('NO')
7
PYTHON3