solution
stringlengths
10
983k
difficulty
int64
0
25
language
stringclasses
2 values
x=int(input("")) if x%2==0 and x!=2: if x>0 and x<=100: print("YES") else: print("NO")
7
PYTHON3
#include "bits/stdc++.h" using namespace std; #ifdef _DEBUG #include "dump.hpp" #else #define dump(...) #endif //#define int long long #define rep(i,a,b) for(int i=(a);i<(b);i++) #define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--) #define all(c) begin(c),end(c) const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f; const int MOD = (int)(1e9) + 7; template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } struct MinimumCostFlow { using Flow = int; using Cost = int; struct Edge { int to, rev; Flow cap; Cost cost; Edge() {} Edge(int to, int rev, Flow cap, Cost cost) :to(to), rev(rev), cap(cap), cost(cost) {} }; int n; vector<vector<Edge>> g; vector<int> dist; vector<int> prevv, preve; MinimumCostFlow(int n) :n(n), g(n), dist(n), prevv(n), preve(n) {} void addEdge(int from, int to, Flow cap, Cost cost) { g[from].emplace_back(to, (int)g[to].size(), cap, cost); g[to].emplace_back(from, (int)g[from].size() - 1, 0, -cost); } // s??????t????????????f???????°??????¨??? // ??????????????´?????? -1 Cost minimumCostFlow(int s, int t, Flow f) { Cost total = 0; while (f > 0) { // Bellman-Ford fill(dist.begin(), dist.end(), INF); dist[s] = 0; bool update = true; while (update) { update = false; for (int v = 0; v < n; v++) { if (dist[v] == INF)continue; for (int i = 0; i < g[v].size(); i++) { Edge &e = g[v][i]; if (e.cap > 0 && dist[e.to] > dist[v] + e.cost) { dist[e.to] = dist[v] + e.cost; prevv[e.to] = v; preve[e.to] = i; update = true; } } } } // ????????\??????????????? if (dist[t] == INF) return -1; // ?????????????????£?????????????????? int d = f; for (int v = t; v != s; v = prevv[v]) d = min(d, g[prevv[v]][preve[v]].cap); f -= d; total += d*dist[t]; for (int v = t; v != s; v = prevv[v]) { Edge &e = g[prevv[v]][preve[v]]; e.cap -= d; g[v][e.rev].cap += d; } } return total; } }; signed main() { cin.tie(0); ios::sync_with_stdio(false); int V, E, F; cin >> V >> E >> F; MinimumCostFlow mcf(V); rep(i, 0, E) { int u, v, c, d; cin >> u >> v >> c >> d; mcf.addEdge(u, v, c, d); } cout << mcf.minimumCostFlow(0, V - 1, F) << endl; return 0; }
0
CPP
# -*- coding: utf-8 -*- """ Created on Sun Apr 12 19:41:01 2020 @author: KSHITIZ ARORA """ import sys msg = sys.stdin.read() l = list(map(int, msg.split())) for i in l[1:]: print (i)
7
PYTHON3
n=int(input()) c=0 for i in range(n): p,q=[int (i) for i in input().split()] if (q-p)>=2: c+=1 print(c)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; void solve() { char arr[8][8]; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { cin >> arr[i][j]; } } for (int i = 0; i < 8; i++) { for (int j = 0; j < 7; j++) { if (arr[i][j] == arr[i][j + 1]) { cout << "NO\n"; return; } } } cout << "YES\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long T; T = 1; for (int t = 0; t < T; t++) { solve(); } return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f, MAXN = 500000 + 10; int a[MAXN], cnt[MAXN]; int main() { int n, mx = 0, p = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); mx = max(mx, a[i]); cnt[a[i]]++; } for (int i = 1; i <= mx; i++) { while (cnt[i]) { cnt[i]--; a[p++] = i; } } int ans = n, sum = 0, st = (n - 1) / 2 + 1; p = n - 1; for (int i = (n - 1) / 2; i >= 0; i--) { int tmp = a[i] << 1; while (p >= st && a[p] >= tmp) p--, sum++; if (sum >= 1) ans--, sum--; } printf("%d\n", ans); return 0; }
7
CPP
name = ["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","Aa","Ba","Ca","Da","Ea","Fa","Ga","Ha","Ia","Ja","Ka","La","Ma","Na","Oa","Pa","Qa","Ra","Sa","Ta","Ua","Va","Wa","Xa","Ya","Za"] n,k = map(int,input().split()) a=list(map(str,input().split())) l = [name[i] for i in range(k-1)] ans = [name[i] for i in range(k-1)] j=k-1 o=k-1 for i in range(n-k+1): x=l.pop(0) l.append(name[o]) o+=1 if a[i]=="YES": ans.append(name[j]) j+=1 else: ans.append(ans[len(ans)-k+1]) print(*ans)
8
PYTHON3
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <cstdio> #define rep(i,n) for(int i=0;i<n;i++) #define fs first #define sc second using namespace std; typedef pair<double,double> P; int n; double x[50000],r[50000]; vector<P> seg; double eps=1e-9; bool check(double m){ seg.clear(); rep(i,n){ if(r[i]<m) continue; seg.push_back(P(x[i]-sqrt(r[i]*r[i]-m*m),x[i]+sqrt(r[i]*r[i]-m*m))); } sort(seg.begin(),seg.end()); if(seg.size()==0) return false; double mx=0,nowl=seg[0].fs,nowr=seg[0].sc; rep(i,seg.size()){ if(nowr+eps<seg[i].fs){ mx=max(mx,nowr-nowl); nowl=seg[i].fs,nowr=seg[i].sc; }else{ nowr=max(nowr,seg[i].sc); } } mx=max(mx,nowr-nowl); if(mx>m*2) return true; return false; } int main(){ while(true){ cin>>n; if(n==0) break; rep(i,n) cin>>x[i]>>r[i]; double ub=100000,lb=0; while(ub-lb>0.00000001){ double m=(ub+lb)/2; if(check(m)) lb=m; else ub=m; } printf("%.12f\n",ub*2); } }
0
CPP
//15 #include<iostream> #include<algorithm> #include<vector> using namespace std; int main(){ for(int n[2];cin>>n[0]>>n[1],n[0]|n[1];){ int hw[2][1501]={{}}; for(int i=0;i<2;i++){ for(int j=1;j<=n[i];j++){ cin>>hw[i][j]; hw[i][j]+=hw[i][j-1]; } } vector<int> v; for(int i=0;i<=n[0];i++){ for(int j=i+1;j<=n[0];j++){ v.push_back(hw[0][j]-hw[0][i]); } } sort(v.begin(),v.end()); int ans=0; for(int i=0;i<=n[1];i++){ for(int j=i+1;j<=n[1];j++){ ans+=upper_bound(v.begin(),v.end(),hw[1][j]-hw[1][i])-lower_bound(v.begin(),v.end(),hw[1][j]-hw[1][i]); } } cout<<ans<<endl; } return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long n, k1, k2, a[100005], b[100005]; priority_queue<long long, vector<long long>, less<long long> > p; int main() { cin >> n >> k1 >> k2; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) { cin >> b[i]; long long x = a[i] - b[i]; if (x < 0) x = -x; p.push(x); } for (int i = 1; i <= k1 + k2; i++) { long long x = p.top() - 1; p.pop(); if (x < 0) x = -x; p.push(x); } long long ans = 0; while (!p.empty()) { long long x = p.top(); p.pop(); ans += x * x; } cout << ans << endl; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:36777216") template <class T> inline void RD(T &x) { char c; for (c = getchar(); c < '0'; c = getchar()) ; x = c - '0'; for (c = getchar(); c >= '0'; c = getchar()) x = x * 10 + c - '0'; } template <class T> inline void OT(const T &x) { cout << x << endl; } template <class T> inline T &_RD(T &x) { RD(x); return x; } inline int RD() { int x; RD(x); return x; } inline long long RD_LL() { int x; RD(x); return x; } inline double RD_DB() { double x; RD(x); return x; } template <class T0, class T1> inline void RD(T0 &x0, T1 &x1) { RD(x0), RD(x1); } template <class T0, class T1, class T2> inline void RD(T0 &x0, T1 &x1, T2 &x2) { RD(x0), RD(x1), RD(x2); } template <class T0, class T1, class T2, class T3> inline void RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3) { RD(x0), RD(x1), RD(x2), RD(x3); } template <class T0, class T1, class T2, class T3, class T4> inline void RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4) { RD(x0), RD(x1), RD(x2), RD(x3), RD(x4); } template <class T0, class T1, class T2, class T3, class T4, class T5> inline void RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5) { RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5); } template <class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5, T6 &x6) { RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5), RD(x6); } template <class T0, class T1> inline void OT(T0 &x0, T1 &x1) { OT(x0), OT(x1); } template <class T0, class T1, class T2> inline void OT(T0 &x0, T1 &x1, T2 &x2) { OT(x0), OT(x1), OT(x2); } template <class T0, class T1, class T2, class T3> inline void OT(T0 &x0, T1 &x1, T2 &x2, T3 &x3) { OT(x0), OT(x1), OT(x2), OT(x3); } template <class T0, class T1, class T2, class T3, class T4> inline void OT(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4) { OT(x0), OT(x1), OT(x2), OT(x3), OT(x4); } template <class T0, class T1, class T2, class T3, class T4, class T5> inline void OT(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5) { OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5); } template <class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void OT(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5, T6 &x6) { OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5), OT(x6); } template <class T> inline void RST(T &A) { memset(A, 0, sizeof(A)); } template <class T0, class T1> inline void RST(T0 &A0, T1 &A1) { RST(A0), RST(A1); } template <class T0, class T1, class T2> inline void RST(T0 &A0, T1 &A1, T2 &A2) { RST(A0), RST(A1), RST(A2); } template <class T0, class T1, class T2, class T3> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3) { RST(A0), RST(A1), RST(A2), RST(A3); } template <class T0, class T1, class T2, class T3, class T4> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4) { RST(A0), RST(A1), RST(A2), RST(A3), RST(A4); } template <class T0, class T1, class T2, class T3, class T4, class T5> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5) { RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5); } template <class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6) { RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5), RST(A6); } template <class T> inline void CLR(T &A) { A.clear(); } template <class T0, class T1> inline void CLR(T0 &A0, T1 &A1) { CLR(A0), CLR(A1); } template <class T0, class T1, class T2> inline void CLR(T0 &A0, T1 &A1, T2 &A2) { CLR(A0), CLR(A1), CLR(A2); } template <class T0, class T1, class T2, class T3> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3) { CLR(A0), CLR(A1), CLR(A2), CLR(A3); } template <class T0, class T1, class T2, class T3, class T4> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4) { CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4); } template <class T0, class T1, class T2, class T3, class T4, class T5> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5) { CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5); } template <class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6) { CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5), CLR(A6); } template <class T> inline void CLR(T &A, int n) { for (int i = 0; i < int(n); ++i) CLR(A[i]); } template <class T> inline void FLC(T &A, int x) { memset(A, x, sizeof(A)); } template <class T0, class T1> inline void FLC(T0 &A0, T1 &A1, int x) { FLC(A0, x), FLC(A1, x); } template <class T0, class T1, class T2> inline void FLC(T0 &A0, T1 &A1, T2 &A2) { FLC(A0), FLC(A1), FLC(A2); } template <class T0, class T1, class T2, class T3> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3) { FLC(A0), FLC(A1), FLC(A2), FLC(A3); } template <class T0, class T1, class T2, class T3, class T4> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4) { FLC(A0), FLC(A1), FLC(A2), FLC(A3), FLC(A4); } template <class T0, class T1, class T2, class T3, class T4, class T5> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5) { FLC(A0), FLC(A1), FLC(A2), FLC(A3), FLC(A4), FLC(A5); } template <class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6) { FLC(A0), FLC(A1), FLC(A2), FLC(A3), FLC(A4), FLC(A5), FLC(A6); } template <class T> inline void checkMin(T &a, T b) { if (b < a) a = b; } template <class T> inline void checkMax(T &a, T b) { if (b > a) a = b; } template <class T> inline T sqr(T x) { return x * x; } template <class T> inline T min(T a, T b, T c) { return min(min(a, b), c); } template <class T> inline T max(T a, T b, T c) { return max(max(a, b), c); } const int MOD = 1000000007; const int INF = 0x7fffffff; const double EPS = 1e-6; const double OO = 1e15; const int N = 20000 + 5; bool A[3], B[3], _B[3], B_[3]; int x[3], m[3], l[3], u[3]; int res; void dfs() { int _i, i_; for (int i = 0; i < int(3); ++i) if (!_B[i]) { if (i == 0) _i = 1, i_ = 2; else if (i == 1) _i = 0, i_ = 2; else _i = 0, i_ = 1; if (B[i] && !B_[i]) { if (u[i] == i_) swap(_i, i_); B_[i] = true, _B[_i] = false; if (B[_i] && !B_[_i]) { checkMax(res, x[i] + l[i] + l[_i] + (A[i_] ? 0 : m[i_])); } else { int x_i = x[_i]; for (int j = int(-l[i]); j <= int(l[i]); ++j) if (j != 0) { int xx = x[i] + j; if (x[i_] != xx && (abs(x[i_] - xx) == 1 || j == 1 || j == l[i])) { checkMax(res, xx); x[_i] = xx, dfs(); x[_i] = x_i; } } } _B[_i] = true, B_[i] = false; } else { if (!B[i]) { if (!_B[_i] && x[_i] == x[i] + -1) { x[_i] = x[i], B[i] = _B[_i] = true, u[i] = _i, dfs(), x[_i] = x[i] + -1; B[i] = _B[_i] = false; }; if (!_B[_i] && x[_i] == x[i] + 1) { x[_i] = x[i], B[i] = _B[_i] = true, u[i] = _i, dfs(), x[_i] = x[i] + 1; B[i] = _B[_i] = false; }; if (!_B[i_] && x[i_] == x[i] + -1) { x[i_] = x[i], B[i] = _B[i_] = true, u[i] = i_, dfs(), x[i_] = x[i] + -1; B[i] = _B[i_] = false; }; if (!_B[i_] && x[i_] == x[i] + 1) { x[i_] = x[i], B[i] = _B[i_] = true, u[i] = i_, dfs(), x[i_] = x[i] + 1; B[i] = _B[i_] = false; }; } if (!A[i]) { A[i] = true; int xi = x[i]; for (int j = int(-m[i]); j <= int(m[i]); ++j) if (j != 0) { int xx = xi + j; if (x[_i] != xx && x[i_] != xx) { checkMax(res, xx); x[i] = xx, dfs(), x[i] = xi; } } A[i] = false; } } } } int main() { for (int i = 0; i < int(3); ++i) RD(x[i], m[i], l[i]); res = max(x[0], x[1], x[2]); dfs(); OT(res); }
11
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n; int s; int odd = 0, even = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> s; if (s % 2 == 0) even++; else odd++; } if (odd % 2 == 0) cout << even; else cout << odd; return 0; }
7
CPP
#include<iostream> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; const int N = 1e5+5; ll minnx[N]; int n; struct node { ll l,r; }a[N],s[N]; bool cmp(node a,node b){ return a.l>b.l; } int main(){ cin>>n; ll maxx=0,minn=1e17,maxlen=0; for(int i=1;i<=n;i++){ cin>>a[i].l>>a[i].r; maxx=max(maxx,a[i].l); minn=min(minn,a[i].r); maxlen=max(maxlen,a[i].r-a[i].l+1); } ll ans1=maxlen+max(minn-maxx+1,0ll); for(int i=1;i<=n;i++){ s[i].l=max(minn-a[i].l+1,0ll); s[i].r=max(a[i].r-maxx+1,0ll); } sort(s+1,s+n+1,cmp); minnx[n+1]=1e18; for(int i=n;i>=1;i--) minnx[i]=min(minnx[i+1],s[i].r); ll ans2=0; for(int i=1;i<=n-1;i++){ // cout<<s[i].l<<" "<<s[i].r<<endl; ans2=max(ans2,s[i].l+minnx[i+1]); // cout<<ans2<<endl; } // cout<<ans1<<" "<<ans2<<endl; cout<<max(ans1,ans2)<<endl; return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; int main() { string s; int i; bool upper = false, lower = false, digit = false; cin >> s; for (i = 0; i < s.size(); i++) { if (isupper(s[i])) upper = true; else if (islower(s[i])) lower = true; else if (isdigit(s[i])) digit = true; } if (upper && lower && digit && s.size() >= 5) cout << "Correct" << "\n"; else cout << "Too weak" << "\n"; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e3 + 10; const int INF = 1e9 + 10; int n, m; char a[MAXN][MAXN]; int group[MAXN][MAXN]; int group_cnt = 1; set<int> g[MAXN * MAXN]; set<int> deprecated_colors[MAXN * MAXN]; int color[MAXN * MAXN]; void init() { for (int i = 0; i <= n + 1; ++i) { group[i][0] = group[i][m + 1] = -1; } for (int j = 0; j <= m + 1; ++j) { group[0][j] = group[n + 1][j] = -1; } } int di[] = {-1, 1, 0, 0}; int dj[] = {0, 0, -1, 1}; void add_group(int i, int j) { group[i][j] = group_cnt; int free_i = -1, free_j = -1; int neighbor = -1; for (int z = 0; z < 4; ++z) { int ii = i + di[z]; int jj = j + dj[z]; if (group[ii][jj] == 0) { free_i = ii; free_j = jj; } else if (group[ii][jj] > 0) { neighbor = group[ii][jj]; } } if (free_i == -1) { if (neighbor == -1) { cout << -1; exit(0); } else { group[i][j] = neighbor; } } else { group[free_i][free_j] = group_cnt++; } } int group_size(int i, int j, int pi, int pj) { int res = 0; for (int z = 0; z < 4; ++z) { int ii = i + di[z]; int jj = j + dj[z]; if ((ii != pi || jj != pj) && group[ii][jj] == group[i][j]) { res += group_size(ii, jj, i, j); } } return res; } bool used[MAXN][MAXN]; void dfs_neighbors(int i, int j) { used[i][j] = 1; for (int z = 0; z < 4; ++z) { int ii = i + di[z]; int jj = j + dj[z]; if (group[ii][jj] != -1) { if (group[ii][jj] != group[i][j]) { g[group[i][j]].emplace(group[ii][jj]); g[group[ii][jj]].emplace(group[i][j]); } if (!used[ii][jj]) { dfs_neighbors(ii, jj); } } } } void set_color(int v) { for (int col = 1; col <= 10; ++col) { if (!deprecated_colors[v].count(col)) { color[v] = col; break; } } for (int child : g[v]) { if (color[child] == 0) { deprecated_colors[child].insert(color[v]); } } for (int child : g[v]) { if (color[child] == 0) { set_color(child); } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { cin >> a[i][j]; if (a[i][j] == '#') { group[i][j] = -1; } } } init(); for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { if (group[i][j] == 0) { add_group(i, j); } } } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { if (!used[i][j] && group[i][j] > 0) { dfs_neighbors(i, j); } } } for (int i = 1; i < group_cnt; ++i) { if (!color[i]) { set_color(i); } } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { cout << (a[i][j] == '#' ? '#' : char('0' + color[group[i][j]] - 1)); } cout << "\n"; } }
8
CPP
#include <bits/stdc++.h> using namespace std; void solve(istream &in, ostream &out) { int n, k; in >> n >> k; if (n / k < 3) { out << -1 << endl; return; } for (int i = 1; i <= k; ++i) out << i << ' '; for (int i = 1; i <= k; ++i) out << i << ' ' << i << ' '; for (int i = 0; i < n - k * 3; ++i) out << 1 << ' '; out << endl; } int main() { solve(cin, cout); return 0; }
9
CPP
def game_func(lis, a): if list_pi[0] != 1: print("First") elif a%2 != 0 and len(list(set(list_pi))) == 1 and list(set(list_pi))[0] == 1: print("First") elif a%2 == 0 and len(list(set(list_pi))) == 1 and list(set(list_pi))[0] == 1: print("Second") else: if list_pi[1] != 1: print("Second") else: try : del(list_pi[0]) del(list_pi[0]) except IndexError: print("First") else: return game_func(list_pi, len(list_pi)) if __name__ == '__main__': t = int(input()) for h in range(t): num_pi = int(input()) list_pi = list(map(int, input().split())) game_func(list_pi, num_pi)
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int n, a; int main() { cin >> n >> a; if (a % 2 == 1) cout << a / 2 + 1 << endl; else cout << (n - a) / 2 + 1 << endl; return 0; }
7
CPP
for _ in range(int(input())): input() nums = [int(x) for x in input().split()] new_ar = list(zip(nums,[i for i in range(len(nums))])) new_ar.sort() maxx = new_ar[0][1] minn = new_ar[0][1] s="1" for j in range(1,len(new_ar)): if(new_ar[j][1]>maxx): maxx = new_ar[j][1] if(new_ar[j][1]<minn): minn = new_ar[j][1] if(maxx-minn<j+1): s+="1" else: s+="0" print(s)
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) { long long n; cin >> n; vector<long long> a(n + 1); for (long long i = 1; i <= n; i++) cin >> a[i]; vector<long long> ans_left; vector<long long> ans_right; long long mx = 0; set<long long> s; for (long long i = 1; i <= n; i++) { mx = max(mx, a[i]); s.insert(a[i]); if (mx == s.size() && i == mx) ans_left.push_back(i); } mx = 0; s.clear(); for (long long i = n; i >= 1; i--) { mx = max(mx, a[i]); s.insert(a[i]); if (mx == s.size() && (n - i + 1) == mx) ans_right.push_back(n - i + 1); } long long ans = 0; vector<long long> k; for (auto i : ans_left) { if (binary_search(ans_right.begin(), ans_right.end(), n - i)) { ans++; k.push_back(i); } } cout << ans << "\n"; for (auto i : k) cout << i << " " << n - i << "\n"; } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int NN, sl; char s[100100]; int mark[11]; int ans; int main(void) { scanf("%s", s); NN = strlen(s); sl = 10; for (int i = (0); i <= (10); ++i) mark[i] = 0; if (s[0] == '?' || ('A' <= s[0] && s[0] <= 'J')) { ans = 9; if (s[0] != '?') { mark[s[0] - 'A'] = 1; sl = sl - 1; } } else ans = 1; int cnt = 0; for (int i = (1); i <= (NN - 1); ++i) { if (!('0' <= s[i] && s[i] <= '9')) { if (s[i] == '?') { cnt = cnt + 1; } else { if (mark[s[i] - 'A'] == 0) { mark[s[i] - 'A'] = 1; ans = ans * sl; sl = sl - 1; } } } } printf("%d", ans); for (int i = (1); i <= (cnt); ++i) printf("0"); printf("\n"); return 0; }
7
CPP
a = input() b = "hello" if a.islower() and len(a) >= 1 and len(a) <= 100: k = 0 for i in a: if k >= 5: break elif i == b[k]: k+=1 if k >= 5: print("YES") else: print("NO")
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int coun = 1, n = 0; string s; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == s[i + 1]) { coun++; } else { if (coun % 2 == 0) n++; coun = 1; } } cout << n << "\n"; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; double l1, l2, l3, h1, h2, h3, s1, s2, s3, t, v1, v2, v3, r; const double Pi = acos(-1.0); int main() { cin >> l1 >> l2 >> l3; s2 = l2 * l2; h2 = sqrt(l2 * l2 / 2); v2 = s2 * h2 / 3; s1 = l1 * l1 * sqrt(3) / 4; h1 = sqrt(l1 * l1 * 2 / 3); v1 = s1 * h1 / 3; s3 = 5 * l3 * l3 / 4 * 1 / tan(Pi / 5); r = sqrt(sqrt(5) + 5) / sqrt(10) * l3; h3 = sqrt(l3 * l3 - r * r); v3 = s3 * h3 / 3; printf("%.9f", v1 + v2 + v3); return 0; }
24
CPP
#include <bits/stdc++.h> clock_t START, END; void __stTIME(); void __enTIME(); void __IOPUT(); using namespace std; int main(void) { __stTIME(); __IOPUT(); string s; cin >> s; int len = s.length(); bool ok = false; for (int i = 0; i <= len - 3; i++) { bool A, B, C; A = B = C = false; for (int j = i; j < i + 3; j++) { if (s[j] == 'A') A = true; if (s[j] == 'B') B = true; if (s[j] == 'C') C = true; } if (A && B && C) { ok = true; break; } } if (ok) puts("Yes"); else puts("No"); __enTIME(); return 0; } void __stTIME() {} void __enTIME() {} void __IOPUT() {}
7
CPP
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int MAX_N = 200100; int d[MAX_N]; int p[MAX_N]; vector<int> A[MAX_N]; void dfs1(int nod) { d[nod] = 1; for (auto it : A[nod]) { dfs1(it); d[nod] = (1LL * d[nod] * (d[it] + 1)) % MOD; } } void dfs2(int nod, int dad) { p[nod] = (1LL * d[nod] * (dad + 1)) % MOD; vector<int> v1, v2; v1.push_back(1); for (auto it : A[nod]) { v1.push_back(d[it] + 1); } v1.push_back(1); v2 = v1; reverse(v2.begin(), v2.end()); for (int i = 1; i < (int)v1.size(); i++) { v1[i] = (1LL * v1[i] * v1[i - 1]) % MOD; } for (int i = 1; i < (int)v2.size(); i++) { v2[i] = (1LL * v2[i] * v2[i - 1]) % MOD; } reverse(v2.begin(), v2.end()); for (int i = 1; i <= (int)A[nod].size(); i++) { dfs2(A[nod][i - 1], ((1LL * (dad + 1) * v1[i - 1]) % MOD * v2[i + 1]) % MOD); } } int main() { int n; cin >> n; for (int i = 2; i <= n; i++) { int a; cin >> a; A[a].push_back(i); } dfs1(1); dfs2(1, 0); for (int i = 1; i <= n; i++) { cout << p[i] << ' '; } }
10
CPP
Bear=list(map(int,input().split())) n=0 while(1): if(Bear[0]<=Bear[1]): n=n+1 Bear[0]*=3 Bear[1]*=2 else: print(n) exit()
7
PYTHON3
#include<iostream> #include<cstdio> using namespace std; int n,m; char a[55][55]; int dx[9]={0,1,1,1,0,0,-1,-1,-1}; int dy[9]={0,1,0,-1,1,-1,1,0,-1}; int main() { cin>>n>>m; for(int i=1; i<=n; i++) { for(int j=1; j<=m; j++) { cin>>a[i][j]; } } for(int i=1; i<=n; i++) { for(int j=1; j<=m; j++) { if(a[i][j]=='#'){ cout<<'#';continue; } int sum=0; for(int k=1; k<=8; k++) if(a[i+dx[k]][j+dy[k]]=='#') sum++; cout<<sum; } cout<<endl; } return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; using ll = long long int; class graph { public: graph(int n) : gr(n), grb(n) {} void addarrow(int a, int b) { gr[a].push_back(b); grb[b].push_back(a); } pair<vector<vector<int> >, graph> strongconnect() { int n = gr.size(); vector<int> s; vector<int> visited(n, 0); int iec = 0; while (iec < n) { while (iec < n && (visited[iec] == -1)) ++iec; if (iec < n) browsetempssortie(gr, visited, iec, s, 0, -1); } vector<vector<int> > res; int k = 0; while (!s.empty()) { int i = s.back(); s.pop_back(); if (visited[i] == -1) { res.push_back(vector<int>()); browsetempssortie(grb, visited, i, res.back(), -1, k); ++k; } } graph resg(k); for (int i = 0; i < k; ++i) { vector<bool> p(k, true); p[i] = false; for (auto j : res[i]) for (auto m : gr[j]) { int q = visited[m]; if (p[q]) { resg.addarrow(i, q); p[q] = false; } } } return pair<vector<vector<int> >, graph>(res, resg); } vector<vector<int> > strongconnectsources() { return strongconnectss(true); } vector<vector<int> > strongconnectsinks() { return strongconnectss(false); } bool issink(int i) { return gr[i].size() == 0; } bool issource(int i) { return grb[i].size() == 0; } vector<int> sinks() { return havecond(bind(&graph::issink, *this, std::placeholders::_1)); } vector<int> sources() { return havecond(bind(&graph::issource, *this, std::placeholders::_1)); } template <class T> void print(T& o) { int n = gr.size(); for (int i = 0; i < n; ++i) { o << i << " ->"; for (auto j : gr[i]) o << " " << j; o << "\n"; } } vector<vector<int> > gr, grb; template <class T> void browsetempssortie( const vector<vector<int> >& g, vector<T>& visited, int i, vector<int>& s, const T valnonvisited = false, const T valvisited = true, const function<bool(int)> cond = [](int) { return true; }) { visited[i] = valvisited; for (auto j : g[i]) if (visited[j] == valnonvisited) browsetempssortie(g, visited, j, s, valnonvisited, valvisited, cond); if (cond(i)) s.push_back(i); } template <class T> void browsebump(const vector<vector<int> >& g, vector<T>& visited, int i, int jmax, vector<int>& bumpback, const T valnonvisited = false, const T valvisited = true) { visited[i] = valvisited; for (auto j : g[i]) { if (visited[j] == valnonvisited) browsebump(g, visited, j, jmax, bumpback, valnonvisited, valvisited); else if (j < jmax) bumpback.push_back(j); } } vector<int> havecond(const function<bool(int)> cond) { int n = gr.size(); vector<int> s; vector<bool> visited(n, false); int iec = 0; while (iec < n) { while (iec < n && visited[iec]) ++iec; if (iec < n) browsetempssortie(gr, visited, iec, s, false, true, cond); } return s; } vector<int> mingen(const vector<vector<int> >& g) { int n = gr.size(); vector<int> visited(n, -1); vector<int> compo, last; int iec = 0; int k = 0; while (iec < n) { while (iec < n && (visited[iec] != -1)) ++iec; if (iec < n) { vector<int> l; browsebump(g, visited, iec, iec, l, -1, k); last.push_back(iec); compo.push_back(k); for (auto i : l) compo[visited[i]] = k; ++k; } } vector<int> res; for (int i = 0; i < k; ++i) if (compo[i] == i) res.push_back(last[i]); return res; } vector<vector<int> > strongconnectss(const bool source) { vector<vector<int> > res; vector<bool> visited(gr.size(), false); for (auto i : mingen((source) ? gr : grb)) { res.push_back(vector<int>()); browsetempssortie((source) ? grb : gr, visited, i, res.back()); } return res; } }; int main() { int n, m, h; cin >> n >> m >> h; vector<int> u(n); for (int i = 0; i < n; ++i) cin >> u[i]; graph gr(n); for (int i = 0; i < m; ++i) { int c1, c2; cin >> c1 >> c2; --c1; --c2; if (u[c1] == u[c2] + 1 || u[c1] == u[c2] + 1 - h) gr.addarrow(c2, c1); if (u[c2] == u[c1] + 1 || u[c2] == u[c1] + 1 - h) gr.addarrow(c1, c2); } auto res = gr.strongconnectsinks(); int rep = n + 1; int best; for (int i = 0; i < res.size(); ++i) { int u = res[i].size(); if (u < rep) { rep = u; best = i; } } cout << rep << "\n"; for (int i = 0; i < rep; ++i) { if (i > 0) cout << " "; cout << res[best][i] + 1; } cout << "\n"; return 0; }
11
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; if (n % 4 != 0) { cout << "===\n"; return 0; } int k = n / 4; int a[4] = {0, 0, 0, 0}; char c[4] = {'A', 'C', 'G', 'T'}; for (int i = 0; i < n; i++) { if (s[i] == 'A') a[0]++; if (s[i] == 'C') a[1]++; if (s[i] == 'G') a[2]++; if (s[i] == 'T') a[3]++; } for (int i = 0; i < 4; i++) { if (a[i] > k) { cout << "===\n"; return 0; } a[i] = k - a[i]; } for (int i = 0; i < n; i++) { if (s[i] == '?') { int j; for (j = 0; a[j] == 0 && j < 4; j++) ; s[i] = c[j]; a[j]--; } } cout << s << "\n"; }
8
CPP
#include<bits/stdc++.h> using namespace std; int n,m; char a[100][100]; queue< pair<int,int> >q; int d[4]={0,1,-1,0},c[4]={1,0,0,-1}; int dd[100][100]; void step(){ while(!q.empty()){ int xx1=q.front().first; int xx2=q.front().second; q.pop(); for(int i=0;i<=3;i++){ int x1=xx1+d[i]; int x2=xx2+c[i]; if((a[x1][x2]=='.')&&(dd[x1][x2]==0)){ dd[x1][x2]=dd[xx1][xx2]+1; q.push(make_pair(x1,x2)); } } } } int main(){ cin>>n>>m; int count =0; dd[1][1]=0; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cin>>a[i][j]; if(a[i][j]=='#'){ count++; } } } q.push(make_pair(1,1)); step(); if(dd[n][m]==0) cout<<-1; else cout<<n*m-count-dd[n][m]-1; }
0
CPP
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target( \ "avx,avx2,fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; const int N = 200000; pair<long double, long double> mas[N]; long long last = 0; void add(long double k, long double b) { while (last > 1) { long double x1 = (mas[last - 1].second - mas[last - 2].second) / (mas[last - 2].first - mas[last - 1].first); long double x2 = (mas[last - 1].second - b) / (k - mas[last - 1].first); if (x1 < x2) { break; } else { last--; } } mas[last] = {k, b}; last++; } long double get(long double x) { long long L = 0, R = last; while (R - L > 1) { long long mm = (R + L) / 2; long double x1 = ((mas[mm - 1].second - mas[mm].second)) / (mas[mm].first - mas[mm - 1].first); if (x1 <= x) { L = mm; } else { R = mm; } } return mas[L].first * x + mas[L].second; } long long MOD = 1e9 + 7; long long INF = 1e18; const int K = 51; long double dp[K][N]; long double sm[N]; long double rs[N]; long double eps = 1e-5; signed main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout << fixed << setprecision(20); long long n, k; cin >> n >> k; long long smm = 0; vector<long long> t(n); for (int i = 0; i < n; i++) { cin >> t[i]; } for (int i = 0; i < n; i++) { if (i) dp[1][i] = dp[1][i - 1] + smm * 1.0 / (long double)t[i]; smm += t[i]; sm[i] = t[i]; if (i) sm[i] += sm[i - 1]; rs[i] = 1.0 / (long double)t[i]; if (i) rs[i] += rs[i - 1]; } for (int j = 2; j <= k; j++) { for (int i = 0; i < n; i++) { add(-sm[i], dp[j - 1][i] - dp[1][i] + rs[i] * sm[i]); } for (int i = 1; i < n; i++) { dp[j][i] = get(rs[i]) + dp[1][i]; } last = 0; for (int i = 0; i < N; i++) { mas[i] = {0, 0}; } } cout << n + dp[k][n - 1]; }
9
CPP
#include <bits/stdc++.h> using namespace std; inline long long rd() { long long x = 0; bool neg = false; char c = getchar(); while (c != '-' && (c < '0' || c > '9')) c = getchar(); if (c == '-') neg = true, c = getchar(); while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); if (neg) x = -x; return x; } inline void write(long long x) { if (x < 0) { putchar('-'); x = -x; } if (x > 9) write(x / 10); putchar(x % 10 + '0'); } const int N = 2e6, oo = 1e9; int n; string s; void input() { cin >> s; n = s.length(); } int dp[10], d[10]; void make_xy(int first, int second) { for (int _x = 10, i = 0; i < _x; ++i) dp[i] = oo; dp[first] = 1; dp[second] = 1; while (true) { int ok = 0; for (int _x = 10, i = 0; i < _x; ++i) if (dp[i] != oo) for (int _x = 10, j = 0; j < _x; ++j) if (dp[j] != oo) { int k = (i + j) % 10; if (dp[k] > dp[i] + dp[j]) { ok = 1; dp[k] = dp[i] + dp[j]; } } if (!ok) break; } } void solve() { if (s[0] - '0' != 0) ++d[s[0] - '0']; for (int _x = n - 1, i = 0; i < _x; ++i) { int z = s[i + 1] - s[i]; while (z < 0) z += 10; ++d[z]; } for (int _b = 9, i = 0; i <= _b; ++i) { for (int _b = 9, j = 0; j <= _b; ++j) { make_xy(i, j); int res = 0; for (int _x = 10, k = 0; k < _x; ++k) if (d[k]) { if (dp[k] != oo) res += dp[k] * d[k]; else { res = -1; break; } } if (res == -1) cout << -1 << ' '; else cout << res - s.length() + 1 << ' '; } cout << '\n'; } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); input(); solve(); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; map<int, int> m; int cnt = 1; for (int i = 0; i < n; i++) { int x; cin >> x; m[x] = i; } int mn = INF, mn_ind; for (auto i : m) { if (i.second < mn) { mn = i.second; mn_ind = i.first; } } cout << mn_ind; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long t; cin >> t; while (t--) { long long n; cin >> n; long long ans = -1; long long p2 = 0, p3 = 0; while (n % 2 == 0) { n /= 2; p2++; } while (n % 3 == 0) { n /= 3; p3++; } if (n == 1 && p2 <= p3) { ans = 2 * p3 - p2; } cout << ans << "\n"; } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; long long int BIT[16][N], suffix[N]; void upd(int x, int lv, long long int plus) { while (x < N) { BIT[lv][x] += plus; x += x & (-x); } } long long int query(int x, int lv) { long long int ans = 0LL; while (x > 0) { ans += BIT[lv][x]; x -= x & (-x); } return ans; } long long int n, k, v[N], cnt[16][N]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); memset(BIT, 0LL, sizeof(BIT)); cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> v[i]; for (int i = 1; i <= n; ++i) cnt[0][i] = 1LL; for (int i = n; i >= 1; --i) { int x = v[i]; for (int j = 1; j <= k; ++j) { cnt[j][x] = query(n, j) - query(x, j); upd(x, j, cnt[j - 1][x]); } } long long int ans = 0LL; ans = 0LL; for (int i = 1; i <= n; ++i) ans += cnt[k][i]; if (k == 0LL) ans = n; cout << ans << "\n"; }
9
CPP
#include <bits/stdc++.h> using namespace std; int main() { long double a, b; cin >> a >> b; cout << (long long)(a * b) << endl; }
0
CPP
#include <bits/stdc++.h> using namespace std; int n, m, ds, lt; char s[200005]; int main() { cin >> (s + 1); n = strlen(s + 1); cin >> m; for (int i = 1; i <= n; ++i) { s[i] -= '0'; ds = (ds * 10 + s[i]) % m; } lt = 1; for (int i = 2; i <= n; ++i) lt = (lt * 10) % m; int res = ds; for (int i = 1; i < n; ++i) { res = ((res - s[i] * lt) % m + m) % m; res = (res * 10 + s[i]) % m; if (s[i + 1] != 0) ds = min(ds, res); } cout << ds; }
11
CPP
wejscie=input() z='' z=z+wejscie[0].capitalize() for i in range(1,len(wejscie)): z=z+wejscie[i] print(z)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { string s, s1; cin >> s; s1 = s; reverse(s.begin(), s.end()); s = s1 + s; cout << s << endl; }
7
CPP
#include <bits/stdc++.h> using namespace std; struct Pt { int X, Y, c, id; bool operator<(const Pt &p) const { if (X == p.X) return Y == p.Y; return X < p.X; } Pt(int _x = 0, int _y = 0, int _c = 0, int _id = 0) { X = _x; Y = _y; c = _c; id = _id; } }; int n; Pt p[20202], nsp; bool ptcmp(Pt p1, Pt p2) { long long x1, x2, y1, y2; x1 = p1.X - nsp.X; x2 = p2.X - nsp.X; y1 = p1.Y - nsp.Y; y2 = p2.Y - nsp.Y; return 1LL * x1 * y2 < 1LL * y1 * x2; } int ans[20202]; void meteor(int nl, int nr) { if (nl == nr) return; int t = min_element(p + nl, p + nr) - p; swap(p[nl], p[t]); nsp = p[nl]; sort(p + nl + 1, p + nr, ptcmp); int df = 0, nc = p[nl].c; for (int i = nl + 1; i < nr; i++) { if (p[i].c != nc and df == 0) { int a = p[nl].id + 1; int b = p[i].id + 1; ans[min(a, b)] = max(a, b) - n; meteor(nl + 1, i); meteor(i + 1, nr); return; } else df += p[i].c; } } int main() { cin >> n; for (int i = 0; i < n + n; i++) { int x, y; cin >> x >> y; p[i] = Pt(x, y, (i < n ? 1 : -1), i); } meteor(0, n << 1); for (int i = 0; i < n; i++) printf("%d\n", ans[i + 1]); }
11
CPP
/* #include<bits/stdc++.h> */ #include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #ifndef ONLINE_JUDGE #include "prettyprint.h" #endif using namespace std; #define int long long #define deb(...) cerr << "[" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__) void DBG() { cerr << "]\n"; } template <typename T, typename... Args> void DBG(T first, Args... args) { cerr << first; if (sizeof...(args)) cerr << ", "; DBG(args...); } void solve() { int n; cin >> n; n*=2; vector<int> a(n); for(int i=0;i<n;i++){ cin >> a[i]; } sort(a.begin(), a.end()); vector<int> ans(n); int j = 0; for(int i=0;i<n;i+=2){ ans[i] = a[j++]; } for(int i=1;i<n;i+=2){ ans[i] = a[j++]; } for(int i=0;i<n;i++){ cout << ans[i] << " " ; } cout << "\n"; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); int t = 1; cin >> t; for (int tt = 1; tt <= t; tt++) { solve(); } }
7
CPP
#include<cstdio> #include<iostream> using namespace std; int main(){ while(1){ int n,taro=0,hana=0,nowcard,card[201]={0},next=1; scanf("%d",&n); if(n==0) break; for(int i=0;i<n;i++){ scanf("%d",&nowcard); card[nowcard]=1; } /* for(int i=1;i<n*2+1;i++) printf("%d",card[i]); */ for(int i=1;;i++){ if(i==n*2+1){ i=1; if(next==1) next=0; else next=1; } if(next==1&&card[i]==1) next=0,card[i]=2,taro++; else if(next==0&&card[i]==0) next=1,card[i]=2,hana++; if(taro==n||hana==n){ printf("%d\n%d\n",n-hana,n-taro); break; } } } return 0; }
0
CPP
#include<bits/stdc++.h> using namespace std; using ll = long long; int main(){ ll n,m; cin>>n>>m; ll res = 1e18; for(int i=1;i<n;i++){ ll h1 = i*m; ll h2 = max(((n-i)/2)*m,(n-i)*(m/2)); ll h3 = (n-i)*m-h2; //cout<<"h3:"<<h3<<endl; vector<ll> v = {h1,h2,h3}; sort(v.begin(),v.end()); res = min(res,v[2]-v[0]); } swap(n,m); for(int i=1;i<n;i++){ ll h1 = i*m; ll h2 = max(((n-i)/2)*m,(n-i)*(m/2)); ll h3 = (n-i)*m-h2; vector<ll> v = {h1,h2,h3}; sort(v.begin(),v.end()); res = min(res,v[2]-v[0]); } cout<<res; }
0
CPP
#include <bits/stdc++.h> using namespace std; int n; int a[1001115]; long long s[1001115]; long long ans = 0x7f7f7f7f7f7f7f7f; void chk(long long p) { long long ret = 0; for (int i = 1; i <= n; i++) { auto x = (s[i] % p); ret += min(x, p - x); } ans = min(ret, ans); } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) s[i] = s[i - 1] + a[i]; long long x = s[n]; for (int i = 2; (long long)i * i <= x; i++) { if (x % i == 0) { while (x % i == 0) x /= i; chk(i); } } if (x > 1) chk(x); cout << (ans == 0x7f7f7f7f7f7f7f7f ? -1 : ans) << endl; }
11
CPP
x=input() numbers=list(map(int,x.split("+"))) ones=0 twos=0 threes=0 for x in numbers : if x==1 : ones+=1 elif x==2 : twos+=1 elif x==3 : threes+=1 finalString="" for x in range(0,(ones)): finalString+="1+" for x in range(0,(twos)): finalString+="2+" for x in range(0,(threes)): finalString+="3+" sObject=slice(0,-1) print(finalString[sObject])
7
PYTHON3
n=int(input()) arr=[int(x) for x in input().split()] a=[0]*n a[0]=1 for i in range(1,n): if(arr[i]>=arr[i-1]): a[i]=a[i-1]+1 else: a[i]=1 print(max(a))
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 7; const int MAXK = 1e5 + 3; const int Candy = 1e7; const int mod = 998244353; const long long inf = 1ll << 55; const double pi = 3.1415926535897932384626433; const long double eps = 1e-12; long long fast_pow(int a, int b) { long long res = a, ret = 1; while (b > 0) { if (b % 2) ret = (ret * res) % mod; res = (res * res) % mod; b /= 2; } return ret; } unsigned long long fact(unsigned long long n) { if (n == 1 || n == 0) return 1; return ((n % mod) * (fact(n - 1) % mod) % mod); } map<char, int> ma; string s, t; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> s >> t; ma['a'] = 1; ma['e'] = 1; ma['o'] = 1; ma['i'] = 1; ma['u'] = 1; if (((int)(s).size()) == ((int)(t).size())) { for (long long i = 0; i < ((int)(s).size()); ++i) { if (ma[s[i]] != ma[t[i]]) { cout << "NO"; return 0; } } cout << "YES"; } else cout << "NO"; return (!false && !true) || ((long long)((long long)(1713 + 2377 + 1464) * (long long)(1713 + 2377 + 1464) * (long long)(1713 + 2377 + 1464)) != (long long)(171323771464)); }
7
CPP
import sys from heapq import* input = sys.stdin.readline def main(): N,M,S = map(int,input().split()) edges = [[]for _ in range(N)] d = {} A = 0 for _ in range(M): u,v,a,b = map(int,input().split()) u -= 1 v -= 1 A = max(A,a) edges[u].append((v,a,b)) edges[v].append((u,a,b)) ex = [tuple(map(int,input().split()))for _ in range(N)] M = 2500 dist = [[2**60]*M for _ in range(N)] prev = [-1]*N if S >= M:S = M-1 dist[0][S] = 0 q = [(0,S,0)] while q: cost,sil,u = heappop(q) if dist[u][sil] < cost:continue if sil+ex[u][0] < M and cost+ex[u][1] < dist[u][sil+ex[u][0]]: dist[u][sil+ex[u][0]] = cost + ex[u][1] heappush(q,(dist[u][sil+ex[u][0]],sil+ex[u][0],u)) for v,a,b in edges[u]: if sil >= a and cost+b < dist[v][sil-a]: dist[v][sil-a] = cost+b heappush(q,(dist[v][sil-a],sil-a,v)) for t in range(1,N): print(min(dist[t])) if __name__ == "__main__": main()
0
PYTHON3
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; int m, i, j, n, d, last[200005]; pair<int, int> a[200005]; stack<pair<int, int> > c; int main() { scanf("%d%d%d", &d, &n, &m); for (i = 0; i < m; i++) scanf("%d%d", &a[i].first, &a[i].second); a[m++] = {0, 0}; a[m++] = {d, 0}; sort(a, a + m); for (i = 0; i < m; i++) last[i] = INF; for (i = 0; i < m; i++) { while (c.size() && c.top().first > a[i].second) { last[c.top().second] = i; c.pop(); } c.push({a[i].second, i}); } long long ans = 0; int p = 0; int now = n; for (i = 1; i < m; i++) { now -= a[i].first - a[i - 1].first; if (now < 0) return 0 * printf("-1\n"); if (last[i] != INF && a[last[i]].first - a[i].first <= n) { ans += 1LL * max(0, a[last[i]].first - a[i].first - now) * a[i].second; now = max(now, a[last[i]].first - a[i].first); } else if (a[i].first + n < d) { ans += 1LL * (n - now) * a[i].second; now = n; } else { ans += 1LL * max(0, d - a[i].first - now) * a[i].second; now = max(now, d - a[i].first); } } printf("%lld\n", ans); }
9
CPP
#467a tc=int(input()) count=0 for i in range(tc): a,b=list(map(int,input().split())) if b-a>=2: count=count+1 print(count)
7
PYTHON3
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math") #pragma GCC target("popcnt") #include <bits/stdc++.h> #define maxn 1000010 #define ll long long #define ull unsigned long long #define ld long double #define fi first #define se second #define pb push_back #define eb emplace_back #define pob pop_back #define pf push_front #define pof pop_front #define pii pair<int, int> #define pil pair<int, ll> #define pll pair<ll, ll> #define IL inline #define ss system using namespace std; int n, h, d; ll f[maxn], s[maxn], fac[maxn], sum = 0; const ll p = 1e9 + 7; template <class T> void read(T &x) { char ch = x = 0; bool fl = false; while (!isdigit(ch)) fl |= ch == '-', ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); x = fl ? -x : x; } int main() { cin >> n >> h >> d, fac[0] = 1; for (int i = 1; i <= n; i++) { fac[i] = fac[i - 1] * i % p; } f[0] = s[0] = fac[n]; for (int i = 1; i <= n; i++) { sum = (sum + fac[i]) % p; } for (int i = 1; i <= h; i++) { f[i] = (s[i - 1] - (i > d ? s[i - d - 1] : 0) + p) % p * (i == h ? 1 : sum) % p; s[i] = (s[i - 1] + f[i]) % p; } cout << f[h] << endl; return 0; }
0
CPP
n,t=map(int,input().split()) s=input() for i in range(t): s=s.replace("BG",'GB') print(s)
8
PYTHON3
#include<iostream> #include<cstring> #include<queue> #define MAX_N 110 #define INF (1<<30) bool A[MAX_N][MAX_N]; int rooter_num; using namespace std; int bfs(int,int); int main() { int n,startNode,goalNode,TTL; int r,k,t; int a; memset(A,false,sizeof(A)); cin>>rooter_num; /*------------input---------------*/ for(int i=0;i<rooter_num;i++) { cin>>r>>k; for(int j=0;j<k;j++) { cin>>t; A[r][t]=true; } } cin>>n; /*-------------search--------------*/ for(int i=0;i<n;i++) { cin>>startNode>>goalNode>>TTL; a=bfs(startNode,goalNode); //cout<<"TTL="<<TTL<<";"<<"a-1="<<a<<endl; /* TTLの減少値 = (それまでに通ったルータの数) - 1 直前のNodeでTTLが1以上ならばパケットが通るので goal地点でのTTLの減少値がTTLと同等,またはそれ以下ならば パケットが通る事になる。 */ if(a<=TTL)cout<<a<<endl; else cout<<"NA"<<endl; } return 0; } int bfs(int startNode,int goalNode) { queue<int>Q; int visited[rooter_num+1]; /* visitedは既に通過しているかの判定と経由したルータの数を保持する */ memset(visited,0,sizeof(visited)); /* memsetによって全てを0で初期化する */ int currentNode=startNode; Q.push(currentNode); visited[currentNode]=1; /*-------BFS--------*/ while(!Q.empty()) { currentNode=Q.front(); Q.pop(); for(int nextNode=1;nextNode<=rooter_num;nextNode++) { if(A[currentNode][nextNode]==0)continue; /* 接続されていない場合を切り取った */ if(nextNode==goalNode)return visited[currentNode]+1; /* goalNodeの接続を確認したので探索を打ち切る */ if(visited[nextNode]<=0) { visited[nextNode]=visited[currentNode]+1; Q.push(nextNode); } /* まだ訪れていない(かつ接続出来るNodeを)キューに追加する */ } } return INF; /* 接続出来ない場合無限大を返す */ }
0
CPP
for k in range(int(input())): a, b = map(int, input().split()) n = abs(a - b) print(n // 5 + (n % 5) // 2 + (n % 5) % 2)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; long long Set(long long N, long long pos) { if (pos < 0) return N; return N = N | (1ll << pos); } long long reset(long long N, long long pos) { return N = N & ~(1ll << pos); } bool check(long long N, long long pos) { if (pos < 0) return 0; return (bool)(N & (1ll << pos)); } void CI(long long &_x) { scanf("%d", &_x); } void CO(long long &_x) { cout << _x; } template <typename T> void getarray(T a[], long long n) { for (long long i = 0; i < n; i++) cin >> a[i]; } template <typename T> void prLLIarray(T a[], long long n) { for (long long i = 0; i < n - 1; i++) cout << a[i] << " "; cout << a[n - 1] << endl; } const double EPS = 1e-9; const long long INF = 0x7f7f7f7f; long long dr8[8] = {1, -1, 0, 0, 1, -1, -1, 1}; long long dc8[8] = {0, 0, -1, 1, 1, 1, -1, -1}; long long dr4[4] = {0, 0, 1, -1}; long long dc4[4] = {-1, 1, 0, 0}; long long kn8r[8] = {1, 2, 2, 1, -1, -2, -2, -1}; long long kn8c[8] = {2, 1, -1, -2, -2, -1, 1, 2}; vector<pair<int, int> > p; double dist(double x1, double y1, double x2, double y2) { double d; d = (x1 - x2) * (x1 - x2); d += (y1 - y2) * (y1 - y2); return sqrt(d); } double ar[100005]; int n; int ax, ay, bx, by, tx, ty; double dp[100005][2][2]; bool vis[100005][2][2]; double rec(int pos, int f, int s) { if (pos == n) { if (f == 1 || s == 1) return 0; return 1e18; } if (vis[pos][f][s]) return dp[pos][f][s]; double ans = 1e18; ans = min(ans, ar[pos] + rec(pos + 1, f, s)); if (f == 0) { double d = dist(ax, ay, p[pos].first, p[pos].second) + dist(p[pos].first, p[pos].second, tx, ty); ans = min(ans, d + rec(pos + 1, 1, s)); } if (s == 0) { double d = dist(bx, by, p[pos].first, p[pos].second) + dist(p[pos].first, p[pos].second, tx, ty); ans = min(ans, d + rec(pos + 1, f, 1)); } vis[pos][f][s] = 1; dp[pos][f][s] = ans; return ans; } int main() { memset(vis, 0, sizeof vis); scanf("%d %d %d %d %d %d", &ax, &ay, &bx, &by, &tx, &ty); scanf("%d", &n); double sum = 0; for (long long i = 0; i < n; i++) { int x, y; scanf("%d %d", &x, &y); p.push_back(make_pair(x, y)); ar[i] = 2.0 * dist(tx, ty, x, y); sum += ar[i]; } printf("%0.10lf\n", rec(0, 0, 0)); }
7
CPP
from bisect import bisect_right, bisect_left N = int(input()) As = sorted(list(map(int, input().split()))) Bs = sorted(list(map(int, input().split()))) Cs = sorted(list(map(int, input().split()))) ans = 0 for B in Bs: A_idx = bisect_left(As, B) C_idx = bisect_right(Cs, B) ans += A_idx * (N - C_idx) print(ans)
0
PYTHON3
import sys, os, io def rs(): return sys.stdin.readline().rstrip() def ri(): return int(sys.stdin.readline()) def ria(): return list(map(int, sys.stdin.readline().split())) def ws(s): sys.stdout.write(s + '\n') def wi(n): sys.stdout.write(str(n) + '\n') def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n') import math,datetime,functools,itertools from collections import deque,defaultdict,OrderedDict import collections def main(): starttime=datetime.datetime.now() if(os.path.exists('input.txt')): sys.stdin = open("input.txt","r") sys.stdout = open("output.txt","w") #Solving Area Starts--> for _ in range(ri()): n,r=ria() x=ria() x=sorted(list(set(x))) x=deque(x) c=0 while True: x.pop() c+=1 if len(x)==0: break z=x[-1] x[-1]-=c*r if x[-1]<=0: break print(c) #<--Solving Area Ends endtime=datetime.datetime.now() time=(endtime-starttime).total_seconds()*1000 if(os.path.exists('input.txt')): print("Time:",time,"ms") class FastReader(io.IOBase): newlines = 0 def __init__(self, fd, chunk_size=1024 * 8): self._fd = fd self._chunk_size = chunk_size self.buffer = io.BytesIO() def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size)) 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, size=-1): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size)) 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() class FastWriter(io.IOBase): def __init__(self, fd): self._fd = fd self.buffer = io.BytesIO() self.write = self.buffer.write def flush(self): os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class FastStdin(io.IOBase): def __init__(self, fd=0): self.buffer = FastReader(fd) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") class FastStdout(io.IOBase): def __init__(self, fd=1): self.buffer = FastWriter(fd) self.write = lambda s: self.buffer.write(s.encode("ascii")) self.flush = self.buffer.flush if __name__ == '__main__': sys.stdin = FastStdin() sys.stdout = FastStdout() main()
8
PYTHON3
from collections import Counter """ t = int(input()) for i in range(t): n = int(input()) nums = list(map(int, input().split())) nums.sort() evens = 0 odds = 0 for i in nums: if i%2==0: evens += 1 else: odds += 1 if evens%2==0 or odds%2==0: print("YES") else: pos = 0 while pos < len(nums)-1: #print(nums,pos) p1,p2 = nums[pos], nums[pos+1] if p2-p1==1: nums.pop(pos) nums.pop(pos) pos -= 1 if pos < 0: pos = 0 else: pos += 1 pos = 0 while pos < len(nums)-1: #print(nums,pos) p1,p2 = nums[pos], nums[pos+1] if p2%2==p1%2: nums.pop(pos) nums.pop(pos) pos -= 1 if pos < 0: pos = 0 else: pos += 1 if nums: print("NO") else: print("YES")""" """ from collections import defaultdict from itertools import product t = int(input()) for i in range(t): n,m = list(map(int, input().split())) store = [defaultdict(int) for i in range(m)] strings = [] for j in range(n): s = input() strings.append(s) for k in range(len(s)): store[k][s[k]] += 1 ans = [set() for i in range(m)] for mi in range(len(store)): m = store[mi] for i,j in m.items(): ans[mi].add(i) test = sorted(ans, key=lambda x: len(x)) #print(test) if len(test) > 1 and len(test[-2]) > 5: final = False else: final = False for answer in product(*ans): main = answer got =True for string in strings: count = 0 #print(string, main) for ind in range(len(main)): if string[ind]!=main[ind]: count += 1 if count > 1: got = False break if count > 1: got = False break if got: print("".join(answer)) final = True break if not final: print(-1)""" a,b = list(map(int, input().split())) def pfac(factors,n): if n==1: return factors if n%2==0: factors.append(2) return pfac(factors, n//2) for j in range(3, int(n**0.5)+1, 2): if n%j==0: factors.append(j) return pfac(factors, n//j) factors.append(n) return factors f2 = pfac([], a) f1= pfac([], b) flag = True for thing in f2: try: f1.remove(thing) except: flag = False break #print(f1, f2) counter = 0 for i in f1: if i not in [2,3]: flag = False #print(f1) #print(f2) if flag: if not f1 and not f2 and a!=b: print(-1) else: print(len(f1)) else: #print(f1, f2) print(-1)
7
PYTHON3
for _ in range(int(input())): n = int(input()) arr = [int(num) for num in input().split(' ')] arr.reverse() for item in arr: print(item,end=' ') print('')
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const double error = 1e-15; const double pi = 2 * acos(0); const int maxn = (int)1e5 + 10; const int mod = (int)1e9 + 7; int dx[] = {0, -1, 0, +1, -1, -1, +1, +1}; int dy[] = {-1, 0, +1, 0, -1, +1, +1, -1}; long long mod1(long long a, long long b) { if (b == 0) return 1; long long x = mod1(a, b / 2); x = (x * x) % mod; if (b % 2 == 1) x = (x * a) % mod; return x; } int main() { ios_base::sync_with_stdio(0); string st1, st2, st; long long i, j, m, n, t, x, ans, k; cin >> n; ans = (mod1(3, 3 * n) - mod1(7, n) + mod) % mod; cout << ans << endl; return 0; }
8
CPP
n = int(input()) dic = {} for _ in range(n): q, X = input().split() if q == "insert": dic[X] = 1 else: if X in dic.keys(): print("yes") else: print("no")
0
PYTHON3
#include <bits/stdc++.h> using namespace std; int a[1010]; int b[1010]; int c[1010]; int d[1010]; struct node { int l, r, m, id; } q[1010]; bool cmp(node x, node y) { if (x.l == y.l) return x.id < y.id; return x.l < y.l; } bool cmp1(node x, node y) { return x.id < y.id; } int main(void) { int i, j, k, n, m, t; scanf("%d", &t); while (t--) { memset(d, 0, sizeof(d)); scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d%d", &q[i].l, &q[i].r); q[i].id = i + 1; } sort(q, q + n, cmp); k = 0; for (i = 1; i <= 2000; i++) { for (j = 0; j < n; j++) { if (q[j].l <= i && q[j].r >= i && d[q[j].id] != 1) { q[j].m = i; d[q[j].id] = 1; break; } if (d[q[j].id] != 1) { if (q[j].r < i) { q[j].m = 0; d[q[j].id] = 1; } } } } sort(q, q + n, cmp1); for (i = 0; i < n - 1; i++) { printf("%d ", q[i].m); } printf("%d\n", q[n - 1].m); } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int N = 505; const int M = 1e9 + 7; bool a[N][N]; long long dp[N][N][2]; long long calc(int l, int r, bool t) { if (dp[l][r][t] >= 0) return dp[l][r][t]; if (r - l <= 1) return 1; long long ans = 0; if (t == 0) { for (int i = l + 1; i < r; i++) { if (a[i][r] == 0) continue; long long inc = calc(l, i, 0) * calc(i, r, 1); ans = (ans + inc) % M; } } else { for (int i = l + 1; i < r; i++) { if (a[l][i] == 0) continue; long long inc = calc(l, i, 1) * calc(i, r, 1); ans = (ans + inc) % M; } ans = (ans + calc(l, r, 0)) % M; } return dp[l][r][t] = ans; } int main() { ios::sync_with_stdio(0); int n; cin >> n; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> a[i][j]; for (int i = 0; i <= n; i++) a[i][n] = a[n][i] = a[i][0]; memset(dp, -1, sizeof dp); cout << calc(0, n, 0) % M << endl; }
12
CPP
import sys t=int(input().strip()) for a0 in range(t): n=int(input()) if(n==1 or n==2 or n==4): print(-1) elif(n%7==0): a=n//7 print(0,0,a) elif(n%7==1): a=n//7 print(1,1,a-1) elif(n%7==2): a=n//7 print(3,0,a-1) elif(n%7==3): a=n//7 print(1,0,a) elif(n%7==4): a=n//7 print(2,1,a-1) elif(n%7==5): a=n//7 print(0,1,a) elif(n%7==6): a=n//7 print(2,0,a)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; long long dp[20]; long long sum[20]; long long a[100]; long long POW(long long n, long long k) { if (k < 0) return 0; if (k == 0) return 1; long long res = POW(n, k / 2); res = (res * res) % 1000000007ll; if (k % 2 == 1) res = (res * n) % 1000000007ll; return res % 1000000007ll; } long long F(long long n) { if (n < 0) return 0; long long res = 1; for (long long i = 1; i <= n; i++) res = (res * i) % 1000000007ll; return res; } long long F(long long l, long long r) { if (l < 1) return 0; long long res = 1; for (long long i = l; i <= r; i++) res = (res * i) % 1000000007ll; return res; } long long Sum(long long l, long long r) { long long res = sum[r] - sum[l - 1]; if (res < 0) res = 0; return res; } long long dfs(long long n, long long sum) { if (sum > 10) return 0; if (n > 6) return Sum(sum + 1, 10); long long res = 0; for (int i = 0; i <= 10; i++) if (dp[i] > 0) { dp[i]--; res += (dp[i] + 1) * dfs(n + 1, sum + i); res = res % 1000000007ll; dp[i]++; } return res; } int main() { long long n; cin >> n; long long x = n; int m = 0; while (x) { a[m++] = x % 10; x /= 10; } dp[0] = 0; long long ans = 0; for (long long i = 0; i <= 10; i++) { long long cnt = 0; for (long long x = 0; x <= i; x++) { long long y = i - x; long long xx = x, yy = y; for (long long j = 10; j >= 0; j--) { if (xx < 0 || yy < 0) break; int mul = a[j]; if (a[j] > 4) mul--; if (a[j] > 7) mul--; if (j - (xx + yy) >= 0) { cnt += mul * POW(8, j - (xx + yy)) * (F(j) / F(xx) / F(yy) / F(j - (xx + yy))); cnt = cnt % 1000000007ll; } if (a[j] > 4) { xx--; mul = 1; if (xx >= 0) if (j - (xx + yy) >= 0) { cnt += mul * POW(8, j - (xx + yy)) * (F(j) / F(xx) / F(yy) / F(j - (xx + yy))); cnt = cnt % 1000000007ll; } xx++; } if (a[j] > 7) { yy--; mul = 1; if (yy >= 0) if (j - (xx + yy) >= 0) { cnt += mul * POW(8, j - (xx + yy)) * (F(j) / F(xx) / F(yy) / F(j - (xx + yy))); cnt = cnt % 1000000007ll; } yy++; } cnt = cnt % 1000000007ll; if (a[j] == 4) xx--; if (a[j] == 7) yy--; } xx = x; yy = y; for (long long j = 10; j >= 0; j--) { if (a[j] == 4) xx--; if (a[j] == 7) yy--; } if (xx == 0 && yy == 0) cnt++; } if (i == 0) cnt--; dp[i] = cnt; } sum[0] = dp[0]; for (int i = 1; i <= 10; i++) sum[i] = sum[i - 1] + dp[i]; ans = dfs(1, 0); cout << ans; return 0; }
10
CPP
n,p = map(int,input().split()) a = list(map(int,input().split())) c = [a[0]] for i in range(1,len(a)): c.append(c[-1]+a[i]) sums = [] for i in range(len(c)-1): sums.append(c[i]%p+(c[-1]-c[i])%p) print(max(sums))
9
PYTHON3
s = input() s2 = '1000000' p = 0 for i in s: if p >= len(s2): break if i == s2[p]: p+=1 if p >= len(s2): print('yes') else: print('no')
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int k; string str; cin >> str; string ara[10]; int flag = 0; for (int i = 0; i < 10; i++) cin >> ara[i]; int length = 0; string s1; for (int i = 0; i < 80; i++) { s1.push_back(str[i]); length++; if (length == 10) { for (int i = 0; i < 10; i++) { if (s1 == ara[i]) cout << i; } s1.clear(); length = 0; } } cout << endl; return 0; }
7
CPP
from sys import stdin def rl(): return [int(w) for w in stdin.readline().split()] k, = rl() for _ in range(k): n, = rl() p = rl() q = [0] * n for i, x in enumerate(p): q[x-1] = i l = r = q[0] m = [] for k, i in enumerate(q): if i < l: l = i elif i > r: r = i m.append('1' if r - l == k else '0') print(''.join(m))
8
PYTHON3
#include <bits/stdc++.h> using namespace std; const int maxn = 300000 + 5; struct Robot { int x, id; char dir; bool operator<(const Robot& rhs) const { return x < rhs.x; } }; int n, m; Robot a[maxn]; void solve() { sort(a, a+n); vector<int> ans(n, -1); stack<Robot> stk[2]; for (int i = 0; i < n; i++) { int p = a[i].x % 2; if (a[i].dir == 'L') { if (stk[p].empty()) stk[p].push(a[i]); else { Robot lastRobot = stk[p].top(); stk[p].pop(); if (lastRobot.dir == 'L') { ans[lastRobot.id] = ans[a[i].id] = (lastRobot.x + a[i].x) / 2; } else { ans[lastRobot.id] = ans[a[i].id] = (a[i].x - lastRobot.x) / 2; } } } else { stk[p].push(a[i]); } } for (int p = 0; p < 2; p++) { stack<Robot> &s = stk[p]; while (s.size() >= 2) { Robot firstRobot = s.top(); s.pop(); Robot secondRobot = s.top(); s.pop(); ans[firstRobot.id] = ans[secondRobot.id] = (2*m - firstRobot.x - (secondRobot.dir == 'L' ? -secondRobot.x : secondRobot.x)) / 2; } } for (int i = 0; i < n; i++) cout << ans[i] << " "; cout << "\n"; } int main() { int T; cin >> T; while (T--) { cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a[i].x; a[i].id = i; } for (int i = 0; i < n; i++) { cin >> a[i].dir; } solve(); } return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; int n, t, m; int a[10000]; bool used[10000]; int x[10000], y[10000]; int ans[10000]; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%d%d", &x[i], &y[i]); for (int j = 0; j < m; j++) scanf("%d", &a[j]); x[n] = x[0]; y[n] = y[0]; x[n + 1] = x[1]; y[n + 1] = y[1]; x[n + 2] = x[2]; y[n + 2] = y[2]; for (int cur = 0; cur < 2; cur++) { memset(used, false, sizeof(used)); bool haveans = true; for (int i = cur; i < cur + n; i += 2) { int l1 = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]); int l2 = abs(x[i + 2] - x[i + 1]) + abs(y[i + 2] - y[i + 1]); int len = l1 + l2; bool ok = false; int num; for (int j = 0; j < m; j++) if (!used[j] && a[j] == len) { ok = true; num = j; used[j] = true; break; } if (!ok) { haveans = false; break; } else { ans[i] = -1; ans[(i + 1) % n] = num + 1; ans[(i + 2) % n] = -1; } } if (haveans) { printf("YES\n"); for (int i = 0; i < n; i++) printf("%d ", ans[i]); printf("\n"); return 0; } } printf("NO\n"); return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j; cin >> n; bool flag = false; for (i = 4; i <= n / 2 + 1; i++) { for (j = 2; j <= sqrt(i) + 1; j++) if (i % j == 0) { flag = true; break; } if (!flag) continue; flag = false; int p = n - i; for (j = 2; j <= sqrt(p) + 1; j++) if (p % j == 0) { flag = true; break; } if (flag) { cout << i << ' ' << p << endl; break; } } return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; inline int read() { int f = 1, x = 0; char ch; do { ch = getchar(); if (ch == '-') f = -1LL; } while (ch < '0' || ch > '9'); do { x = x * 10 + ch - '0'; ch = getchar(); } while (ch >= '0' && ch <= '9'); return f * x; } inline long long readll() { long long f = 1, x = 0; char ch; do { ch = getchar(); if (ch == '-') f = -1LL; } while (ch < '0' || ch > '9'); do { x = x * 10 + ch - '0'; ch = getchar(); } while (ch >= '0' && ch <= '9'); return f * x; } template <class T> inline void chmax(T &a, T b) { if (a < b) a = b; } template <class T> inline void chmin(T &a, T b) { if (a > b) a = b; } inline void swap(int &a, int &b) { int c = a; a = b; b = c; } using namespace std; const int N = 2e3 + 10; const int P = 998244853; inline int inc(int a, int b) { a += b; if (a >= P) a -= P; return a; } int n, m, f[N][N], g[N][N]; int main() { n = read(); m = read(); f[0][0] = 1; for (int i = (0); i <= (n); ++i) { for (int j = (0); j <= (m); ++j) { if (i) f[i][j] = inc(f[i][j], f[i - 1][j]); if (j && (j < i)) f[i][j] = inc(f[i][j], f[i][j - 1]); } } g[0][0] = 1; for (int i = (0); i <= (n); ++i) { for (int j = (0); j <= (m); ++j) { if (j) g[i][j] = inc(g[i][j], g[i][j - 1]); if (i && (i <= j)) g[i][j] = inc(g[i][j], g[i - 1][j]); } } int ans = 0; for (int i = (0); i <= (n); ++i) { for (int j = (0); j <= (m); ++j) { ans = inc(ans, 1ll * f[i][j] * g[n - i][m - j] % P * max(i - j, 0) % P); } } printf("%d\n", ans); return 0; }
11
CPP
# @author import sys class DHarmoniousGraph: def solve(self): from collections import defaultdict class Node: def __init__(self, val): self.parent = self self.size = 1 self.val = val def union(x, y): xRoot, yRoot = find(x), find(y) if xRoot == yRoot: return if xRoot.size >= yRoot.size: yRoot.parent = xRoot xRoot.size += yRoot.size else: xRoot.parent = yRoot yRoot.size += xRoot.size def find(x): while x.parent != x: x = x.parent return x n, m = [int(_) for _ in input().split()] adj = defaultdict(list) nodes = [Node(i) for i in range(n)] parent = [-1] * n for i in range(m): u, v = [int(_) for _ in input().split()] u -= 1 v -= 1 adj[u].append(v) adj[v].append(u) union(nodes[u], nodes[v]) for i in range(n): parent[i] = find(nodes[i]).val cc = defaultdict(tuple) for g in parent: cc[g] = (float('inf'), -float('inf')) for i in range(n): g = parent[i] cc[g] = (min(cc[g][0], i), max(cc[g][1], i)) ccs = [[g, cc[g][0], cc[g][1]] for g in cc] ccs.sort(key=lambda x:x[1]) ans = 0 done = {g : 0 for g in cc} for g, cur, r in ccs: if done[g]: continue # print(g, cur, r, ans) while cur < r: cur_p = find(nodes[cur]) r_p = find(nodes[r]) # print(cur, r, cur_p.val, r_p.val) if cur_p != r_p: ans += 1 done[cur_p.val] = 1 new_r = max(r, cc[cur_p.val][1]) union(nodes[cur], nodes[r]) r = new_r cur += 1 print(ans) solver = DHarmoniousGraph() input = sys.stdin.readline solver.solve()
10
PYTHON3
""" Nombre: New Year Trasnportation id: 500A Fuente: codeforces.com Coder: Cgesu Coder """ n, t = map(int, input().split()) nis = list(map(int, input().split())) visitar = set() pos = 0 visitar.add(pos) while pos < len(nis): pos += nis[pos] visitar.add(pos) print("YES") if t-1 in visitar else print("NO")
7
PYTHON3
T = int(input()) def main(): a,b = tuple(map(int, input().split())) if a>=2*b or b>=2*a: result = min(a,b) return result if a==b: pairs = a//3 result = pairs*2 if a%3 == 2: result=result+1 return result else: return (a+b)//3 for _ in range(T): print(main())
7
PYTHON3
#include <bits/stdc++.h> using namespace std; using ld = long double; using ll = long long; const ll mod = 1000000007; #define fo(i,a,b) for(ll i=a;i<b;i++) #define T ll t; cin>>t; fo(i,0,t) #define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n"; /*vector<pair<ll, ll> > A; //sorting map in asc order by val //use A.begin() after the sort work as map bool cmp(pair<ll, ll>& a, //if using multiple time dont forget to use A.clear(); pair<ll, ll>& b) { return a.second < b.second; } void sort(map<ll, ll>& M) //sort(ma); { for (auto& it : M) { A.push_back(it); } sort(A.begin(), A.end(), cmp); } ll gcd(ll a,ll b){ //b>a if(a==0) return b; gcd(b%a,a); } ll isprime(ll n){ if(n==2) return 1; if(n<=1) return 0; for(ll i=2;i<=sqrt(n);i++){ if(n%i==0) return 0; } return 1; } ll fac(ll n){ if(n==0) return 1; if(n==1) return 1; ll i=n,fact=1; while(n/i!=n){ fact=fact*i; i--; } return fact%mod; }*/ string dectobin(ll n){ string str=bitset<32>(n).to_string(); //string length 32 //const auto loc=str.find('1');//index of first '1' starting from 0 //if(loc!=string::npos) // return str.substr(loc); return str; // return "0"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); T{ ll n,k; cin>>n>>k; ll x[n],y[n]; fo(i,0,n){ cin>>x[i]>>y[i]; } ll r=-1; ll c; fo(i,0,n){ fo(j,0,n){ if(i==j) continue; if((abs(x[i]-x[j])+abs(y[i]-y[j]))<=k){ //r=1; break; c=1; } else{ c=-1; break; } } if(c==1) break; } if(c==1) cout<<1; else cout<<r; cout<<'\n'; } printclock; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { long long x, y, m, t, res = 0; cin >> x >> y >> m; t = max(x, y); if (t >= m) res = 0; else if (x <= 0 && y <= 0) res = -1; else { long long xx = min(x, y); long long yy = max(x, y); if (xx < 0) { res += (-xx) / yy; xx += res * yy; x = xx; y = yy; } xx = min(x, y); yy = max(x, y); while (yy < m) { x = xx + yy; y = yy; res++; xx = min(x, y); yy = max(x, y); } } cout << res << endl; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; inline bool _R(int &x) { return scanf("%d", &x) == 1; } inline bool _R(long long &x) { return scanf("%lld", &x) == 1; } inline bool _R(double &x) { return scanf("%lf", &x) == 1; } inline bool _R(char &x) { return scanf(" %c", &x) == 1; } inline bool _R(char *x) { return scanf("%s", x) == 1; } template <typename T, typename U> inline bool _R(pair<T, U> &x) { return _R(x.first) && _R(x.second); } inline bool Read() { return 1; } template <typename T, typename... U> inline bool Read(T &head, U &...tail) { return _R(head) && Read(tail...); } inline void _W(const int &x) { printf("%d", x); } inline void _W(const long long &x) { printf("%lld", x); } inline void _W(const double &x) { printf("%.10f", x); } inline void _W(const char &x) { putchar(x); } inline void _W(const char *x) { printf("%s", x); } template <typename T, typename U> inline void _W(const pair<T, U> &x) { _W(x.first); putchar(' '); _W(x.second); } template <typename T> inline void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) { if (i != x.begin()) { putchar(' '); } } } inline void Write() {} template <typename T, typename... U> inline void Write(const T &head, const U &...tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); Write(tail...); } const int Move[][2] = {{0, 0}, {1, 0}, {0, 1}, {0, -1}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; void solve(); int32_t main() { solve(); 2333; } const int MOD = 1e9 + 7; inline long long sqr(long long a) { return a * a; } inline long long add(long long a, long long b) { a += b; return (a >= MOD) ? (a - MOD) : a; } inline long long sub(long long a, long long b) { a -= b; return (a < 0) ? (a + MOD) : a; } inline long long mul(long long a, long long b) { a *= b; if (a >= MOD) a = a - a / MOD * MOD; return a; } template <typename T> inline bool chkmin(T &a, T b) { return (a > b) ? (a = b, true) : false; } template <typename T> inline bool chkmax(T &a, T b) { return (a < b) ? (a = b, true) : false; } long long Pow(long long a, long long t) { long long b = 1; for (; t > 0; t >>= 1, a *= a) if (t & 1) b *= a; return b; } long long qpow(long long a, long long t) { long long b = 1; for (; t > 0; t >>= 1, a = mul(a, a)) if (t & 1) b = mul(b, a); return b; } const int maxn = 3e5 + 5; const int INF = 0x3f3f3f3f; struct node { int u; long long w; node(int a = 0, long long b = 0) : u(a), w(b) {} bool operator<(const node &b) const { return w > b.w; } }; struct edge { int v, next; long long w; edge(int a = 0, int b = 0, long long c = 0) : v(a), next(b), w(c) {} } G[maxn << 1]; int tot, head[maxn], pre[maxn]; long long dis[maxn]; bool vis[maxn]; vector<int> ans; int n, k; map<pair<int, int>, int> Map; void init() { tot = 0; Map.clear(), ans.clear(); memset(vis, 0, sizeof vis); memset(pre, -1, sizeof pre); memset(head, -1, sizeof head); memset(dis, 0x3f, sizeof dis); } void addedge(int u, int v, int w, int id) { if (u > v) swap(u, v); Map[{u, v}] = id; G[tot] = edge(v, head[u], w); head[u] = tot++; G[tot] = edge(u, head[v], w); head[v] = tot++; } void addans(int u, int v) { if (u > v) swap(u, v); ans.push_back(Map[{u, v}]); } void Dijkstra() { priority_queue<node> Q; Q.emplace(1, 0), dis[1] = 0; while (!Q.empty()) { int u = Q.top().u; Q.pop(); if (vis[u]) continue; else vis[u] = 1; if (pre[u] != -1) addans(pre[u], u); if ((int)ans.size() == k) return; for (int i = head[u]; i != -1; i = G[i].next) { edge &e = G[i]; if (!vis[e.v] && chkmin(dis[e.v], dis[u] + e.w)) { pre[e.v] = u; Q.emplace(e.v, dis[e.v]); } } } } void solve() { int m; while (Read(n, m, k)) { init(); for (int i = 1; i <= m; i++) { int u, v, w; Read(u, v, w); addedge(u, v, w, i); } Dijkstra(); Write((int)ans.size()); Write(ans); } }
10
CPP
input();d = [int(x) for x in input().split()];maxa = max(d) d.remove(maxa);print(abs(sum(d)-(maxa*len(d))))
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int Next[3][100005]; string str, ss[3]; void getnext(int x) { int now = -1, j = 0; Next[x][0] = now; int m = ss[x].length(); while (j < m) { if (now == -1 || ss[x][j] == ss[x][now]) { Next[x][++j] = ++now; } else now = Next[x][now]; } return; } int main() { cin >> str >> ss[1] >> ss[2]; getnext(1); getnext(2); bool f1 = 0, f2 = 0; int s, now, i; int k = str.length(); i = 1; s = 0, now = 0; int m = ss[1].length(); while (s < k) { if (now == -1 || str[s] == ss[i][now]) { now++; s++; } else now = Next[i][now]; if (now == m) { if (i == 1) { now = 0; i = 2; m = ss[2].length(); } else if (i == 2) { f1 = 1; break; } } } reverse(str.begin(), str.end()); s = 0, now = 0; i = 1; m = ss[1].length(); while (s < k) { if (now == -1 || str[s] == ss[i][now]) { now++; s++; } else now = Next[i][now]; if (now == m) { if (i == 1) { now = 0; i = 2; m = ss[2].length(); } else if (i == 2) { f2 = 1; break; } } } if (f1 == 1 && f2 == 1) cout << "both" << endl; else if (f1 == 1 && f2 == 0) cout << "forward" << endl; else if (f1 == 0 && f2 == 1) cout << "backward" << endl; else if (f1 == 0 && f2 == 0) cout << "fantasy" << endl; return 0; }
7
CPP
n=int(input()) s=str(input()) x,y=0,0 for i in range(n): if s[i]=='A': x+=1 else: y+=1 if x>y: print("Anton") elif y>x: print("Danik") else: print("Friendship")
7
PYTHON3
#include <bits/stdc++.h> using namespace std; long long n; long long biao[] = { 0, 1, 9, 245, 126565, 54326037, 321837880, 323252721, 754868154, 328083248, 838314395, 220816781, 893672292, 166441208, 251255697, 114256285, 118775501, 482714697, 11784725, 460862131, 550384565, 106742050, 425241115, 626692854, 674266678, 320014275, 345949512, 527320049, 897822749, 137190263, 491039182, 810384961, 482023334, 658099864, 886790989, 845381174, 371433224, 278969124, 420088324, 696766322, 388302635, 141033366, 46387851, 932125021, 278342766, 371131134, 922501918, 110778457, 506223573, 806353719, 391845991, 923507761, 780307355, 109951115, 830090230, 605558495, 344686604, 988110893, 944684429, 715019947, 799898820, 384672708, 907325090, 758952329, 550672104, 368337206, 394915145, 401744167, 923781939, 831857516, 407845661, 329267374, 927004007, 891609656, 897919613, 481297880, 737337940, 651873737, 287246681, 973133651, 679864988, 784719328, 820504764, 875613823, 806512665, 164851642, 500228957, 951814419, 447763649, 273141670, 979349615, 964027956, 809510400, 276634497, 116631976, 426739449, 175282420, 885948162, 62270880, 974395255, 675165056, 759589968, 837957573, 931897605, 152352780, 585420109, 1772087, 333401718, 898833639, 745874265, 786209423, 691982338, 498790927, 473374639, 274302623, 971280670, 241671319, 13070005, 302088807, 550276351, 436592588, 631667314, 548656698, 730626984, 146295220, 674398632, 400383348, 454138904, 786220712, 118620797, 233440672, 217349271, 274853536, 310607544, 105221205, 769566615, 853585061, 800665807, 695377419, 924327065, 388199705, 551624811, 721435546, 501720515, 308465454, 825369234, 396065729, 451899519, 295058424, 142088952, 473485086, 378771634, 734511215, 462404399, 959198328, 337668263, 794122911, 38911400, 951992982, 472696081, 373904752, 105884826, 630251717, 28980684, 845136347, 353665773, 691661192, 19922354, 231463797, 757917231, 242739918, 979036950, 713722080, 234689388, 2243164, 209872853, 240808787, 539523346, 425797848, 913772061, 224613100, 421742777, 222232478, 92712941, 215137570, 949901408, 274827432, 15162482, 593145989, 274574232, 239282092, 762720192, 804146934, 500629424, 565985054, 81127381, 671811155, 655565571, 890331075, 237994348, 743647404, 667160634, 713914299, 668506729, 741341289, 277636808, 762781382, 14272789, 902864131, 567443405, 149113383, 648844381, 825489976, 933016723, 192288078, 734493315, 240985733, 861817693, 762711459, 525904609, 532463481, 377133989, 620711079, 772561562, 980733194, 227599811, 162774370, 209512798, 787116594, 3509258, 748795368, 378035466, 612938915, 802091952, 857679599, 481748937, 493370392, 358420805, 48301629, 412001241, 463126722, 509578422, 967799131, 994766554, 687287243, 863623583, 771554899, 690911527, 855314994, 923686429, 246862514, 192479791, 133487041, 703444043, 295281758, 801816257, 920762934, 749306433, 973004841, 848644684, 560026478, 952127278, 616654635, 839390326, 975154012, 409583672, 635350249, 343228425, 335331602, 223826406, 952341037, 589677800, 249747234, 555694261, 137143500, 628190328, 461598392, 431912756, 29349807, 759199489, 783281228, 781971312, 915823407, 388508707, 718062705, 27424111, 309999451, 963383322, 831185229, 132910888, 347028136, 850484840, 223055285, 142335980, 144754000, 772005560, 81796039, 167696020, 79454283, 172772542, 201056991, 484957644, 716630285, 763194701, 211505841, 903448791, 926964672, 257752668, 482951716, 411539070, 620249847, 592476107, 170473128, 814662613, 898000271, 57354872, 361106091, 488697643, 889007954, 138725767, 684860983, 36248116, 304610143, 137633385, 413715776, 99010024, 779653665, 100387568, 286328069, 564731826, 621740468, 943513219, 506666491, 249987886, 553719884, 769853086, 337485319, 702455584, 809637762, 755400257, 892290368, 502180086, 364275817, 118162370, 873374339, 261271695, 970132574, 744105500, 434447173, 117975095, 383088393, 625447969, 180281249, 545367713, 133236931, 360175662, 148087453, 806871297, 498529036, 886076476, 65645000, 465138299, 967109895, 331362616, 472283705, 796894900, 199697765, 503759892, 472807906, 187586706, 941198065, 782234442, 57693411, 18678611, 82626204, 395317191, 570588915, 152519440, 449852456, 63696518, 763741345, 878748386, 494317541, 444782633, 93316211, 929164666, 529288371, 165769871, 730546850, 955877127, 994202767, 492009567, 275683011, 415902127, 95725776, 718047399, 786963365, 73091278, 986172399, 174591541, 913259286}; inline long long read() { long long f = 1, x = 0; char ch = getchar(); while (!isdigit(ch)) ch = getchar(), f = -1; while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar(); return x * f; } inline void write(long long x) { if (x >= 10) { write(x / 10); } putchar(x % 10 + 48); } signed main() { ios::sync_with_stdio(0); n = read(); write(biao[n]); return 0; }
10
CPP
for i in range(int(input())): numbers = [] size = int(input()) for _ in range(size): numbers.append(int(input())) change = size - len(set(numbers)) unique = [] uni_dig = 0 while len(numbers): num = numbers.pop() while num in unique or num in numbers: num = num // 10 * 10 + uni_dig uni_dig = (uni_dig + 1) % 10 unique.append(num) print(change) for num in reversed(unique): print("{0:-04}".format(num))
8
PYTHON3
import math q=int(input()) for i in range(q): n=int(input()) l=list(map(int,input().split())) ans=math.ceil(sum(l)/n) print(ans)
7
PYTHON3
# @oj: codeforces # @id: hitwanyang # @email: [email protected] # @date: 2020-10-15 10:09 # @url:https://codeforc.es/contest/999/problem/C import sys,os from io import BytesIO, IOBase import collections,itertools,bisect,heapq,math,string from decimal import * # region fastio BUFSIZE = 8192 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") # ------------------------------ ## 注意嵌套括号!!!!!! ## 先有思路,再写代码,别着急!!! ## 先有朴素解法,不要有思维定式,试着换思路解决 ## 精度 print("%.10f" % ans) ## sqrt:int(math.sqrt(n))+1 ## 字符串拼接不要用+操作,会超时 def main(): n,k=map(int,input().split()) s=str(input()) res=[[] for i in range(26)] v=[False]*n for i in range(n): temp=ord(s[i])-ord('a') res[temp].append(i) f=False for r in res: for x in r: if k==0: f=True break v[x]=True k=k-1 if f: break ans=[] for i in range(n): if not v[i]: ans.append(s[i]) # print (res) print ("".join(ans)) if __name__ == "__main__": main()
9
PYTHON3
teams = [input().split(" ") for i in range(int(input()))] times = 0 for i, team1 in enumerate(teams[:-1]): for team2 in teams[i+1:]: if team1[0] == team2[1]: times +=1 if team1[1] == team2[0]: times +=1 print(times)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { long long n, wait = 0, cnt = 0; cin >> n; long long a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (int i = 0; i < n; i++) { if (a[i] >= wait) { cnt++; wait += a[i]; } } cout << cnt << endl; }
10
CPP
#include <bits/stdc++.h> using namespace std; int a, b, cnt, c, ans; set<int> s; int main() { cin >> a >> b; for (int i = 1; i <= a; ++i) { cin >> c; while (c > 10) { if (c % 10 == 4) { cnt++; } if (c % 10 == 7) { cnt++; } c /= 10; } if (c % 10 == 4) { cnt++; } if (c % 10 == 7) { cnt++; } if (cnt <= b) { ans++; } cnt = 0; } cout << ans; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int cnt[30][30], n, sum[30], ok[30][5010]; char s[5010], a[5010][5010]; int main() { scanf("%s", s); n = strlen(s); for (int i = 0; i < n; i++) { int tmp = s[i] - 'a' + 1; sum[tmp]++; } for (int i = 0; i < n; i++) { for (int j = 1; j < n; j++) { int pos = (i + j) % n; a[i][j] = s[pos]; } } for (int i = 1; i < n; i++) { memset(cnt, 0, sizeof(cnt)); for (int j = 0; j < n; j++) { int tmp2 = a[j][i] - 'a' + 1; int tmp1 = s[j] - 'a' + 1; cnt[tmp1][tmp2]++; } for (int j = 0; j < n; j++) { int tmp2 = a[j][i] - 'a' + 1; int tmp1 = s[j] - 'a' + 1; if (cnt[tmp1][tmp2] > 1) a[j][i] = '.'; } } double ans = 0; for (int i = 0; i < n; i++) { for (int j = 1; j < n; j++) { if (a[i][j] != '.') { int tmp = s[i] - 'a' + 1; ok[tmp][j]++; } } } for (int i = 1; i <= 26; i++) { int mx = 0; for (int j = 1; j < n; j++) { mx = max(mx, ok[i][j]); } ans += mx; } ans = ans / (double)n; printf("%.15f", ans); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; char _; const long long maxN = 1000 * 1000 + 5; const long long mod = 1000 * 1000 * 1000 + 7; const long long base = 701; const long long SQ = 500; const long long maxL = 20; vector<long long> a[maxN]; vector<long long> ans[maxN]; vector<long long> v; vector<pair<long long, long long> > pos[maxN]; long long cntx[maxN], cnty[maxN]; bool cmp(const pair<long long, long long> &p, const pair<long long, long long> &q) { return (ans[p.first][p.second] > ans[q.first][q.second]); } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); long long n, m; cin >> n >> m; for (long long i = 0; i < n; i++) for (long long j = 0; j < m; j++) { long long x; cin >> x; v.push_back(x); a[i].push_back(x); ans[i].push_back(0); } sort(v.begin(), v.end()); v.resize(unique(v.begin(), v.end()) - v.begin()); for (long long i = 0; i < n; i++) for (long long j = 0; j < m; j++) { long long ps = lower_bound(v.begin(), v.end(), a[i][j]) - v.begin(); pos[ps].push_back(make_pair(i, j)); } for (long long i = 0; i < v.size(); i++) { for (long long j = 0; j < pos[i].size(); j++) { long long x = pos[i][j].first, y = pos[i][j].second; ans[x][y] = max(cntx[x], cnty[y]) + 1; } sort(pos[i].begin(), pos[i].end(), cmp); for (long long tof = 0; tof < 40; tof++) { for (long long j = 0; j < pos[i].size(); j++) { long long x = pos[i][j].first, y = pos[i][j].second; ans[x][y] = max(ans[x][y], max(cntx[x], cnty[y])); cntx[x] = max(cntx[x], ans[x][y]); cnty[y] = max(cnty[y], ans[x][y]); } } } for (long long i = 0; i < n; i++) { for (long long j = 0; j < m; j++) cout << ans[i][j] << ' '; cout << endl; } return 0; }
11
CPP
#!/usr/bin/env python # coding: utf-8 # In[4]: a,b=input().split() x=int(a)*int(b) if x%2==0: print(x//2) else: print((x-1)//2) # In[ ]: # In[ ]:
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 3; const int s1 = 214789; const int s2 = 224737; const int m1 = 999999937; const int m2 = 1000000007; int n, m; inline void Ex_gcd(int a, int b, long long &x, long long &y) { (!b) ? (x = y = 1) : (Ex_gcd(b, a % b, y, x), y -= x * (a / b)); return; } inline int rin() { int s = 0; bool bj = false; char c = getchar(); for (; (c > '9' || c < '0') && c != '-'; c = getchar()) ; if (c == '-') bj = true, c = getchar(); for (; c >= '0' && c <= '9'; c = getchar()) s = (s << 1) + (s << 3) + (c ^ '0'); if (bj) s = -s; return s; } inline int gc() { char c = getchar(); for (; c > 'z' || c < 'a'; c = getchar()) ; return c - 'a'; } vector<int> a[26]; vector<long long> b[26]; vector<long long> c[26]; long long sl_1[N]; long long sl_2[N]; long long sr_1[N]; long long sr_2[N]; int d[27]; int e[27]; int t_1, t_2; inline void find_right(int x, int R, int &right) { int l = 1, r = a[x].size() - 1; for (; l <= r;) { int mid = (l + r) >> 1; if (a[x][mid] <= R) right = mid, l = mid + 1; else r = mid - 1; } return; } inline void find_left(int x, int L, int &left) { int l = 1, r = a[x].size() - 1; for (; l <= r;) { int mid = (l + r) >> 1; if (a[x][mid] >= L) left = mid, r = mid - 1; else l = mid + 1; } return; } inline void add_d(int x, int L, int R, int i) { int left = 0x3f3f3f3f, right = -1; find_left(x, L, left); find_right(x, R, right); if (left > right) return; if (!i) d[++t_1] = (((b[x][right] - (b[x][left] * sl_1[right - left] % m1)) + (a[x][left] - L + 1) * sl_1[right - left] % m1) % m1 + m1) % m1; else d[++t_1] = (((c[x][right] - (c[x][left] * sl_2[right - left] % m2)) + (a[x][left] - L + 1) * sl_2[right - left] % m2) % m2 + m2) % m2; return; } inline void add_e(int x, int L, int R, int i) { int left = 0x3f3f3f3f, right = -1; find_left(x, L, left); find_right(x, R, right); if (left > right) return; if (!i) e[++t_2] = (((b[x][right] - (b[x][left] * sl_1[right - left] % m1)) + (a[x][left] - L + 1) * sl_1[right - left] % m1) % m1 + m1) % m1; else e[++t_2] = (((c[x][right] - (c[x][left] * sl_2[right - left] % m2)) + (a[x][left] - L + 1) * sl_2[right - left] % m2) % m2 + m2) % m2; return; } inline void work() { t_1 = t_2 = 0; int l, r, lens; l = rin(); r = rin(); lens = rin(); for (int i = 0; i < 26; i++) add_d(i, l, l + lens - 1, 0), add_e(i, r, r + lens - 1, 0); if (t_1 != t_2) { puts("NO"); return; } sort(d + 1, d + t_1 + 1); sort(e + 1, e + t_2 + 1); for (int i = 1; i <= t_1; i++) if (d[i] != e[i]) { puts("NO"); return; } t_1 = t_2 = 0; for (int i = 0; i < 26; i++) add_d(i, l, l + lens - 1, 1), add_e(i, r, r + lens - 1, 1); if (t_1 != t_2) { puts("NO"); return; } sort(d + 1, d + t_1 + 1); sort(e + 1, e + t_2 + 1); for (int i = 1; i <= t_1; i++) if (d[i] != e[i]) { puts("NO"); return; } puts("YES"); return; } int main() { int i, j; n = rin(); m = rin(); sl_1[0] = sl_2[0] = 1; sr_1[0] = sr_2[0] = 1; for (i = 0; i < 26; i++) a[i].push_back(0), b[i].push_back(0), c[i].push_back(0); for (i = 1; i <= n; i++) { j = gc(); b[j].push_back(((b[j].back() * s1 + i - a[j].back()) % m1 + m1) % m1); c[j].push_back(((c[j].back() * s2 + i - a[j].back()) % m2 + m2) % m2); a[j].push_back(i); sl_1[i] = sl_1[i - 1] * s1 % m1; sl_2[i] = sl_2[i - 1] * s2 % m2; } Ex_gcd(sl_1[n], m1, sr_1[n], sr_1[n + 1]); sr_1[n] = (sr_1[n] % m1 + m1) % m1; Ex_gcd(sl_2[n], m2, sr_2[n], sr_2[n + 1]); sr_2[n] = (sr_2[n] % m2 + m2) % m2; for (i = n - 1; i >= 1; i--) sr_1[i] = sr_1[i + 1] * s1 % m1, sr_2[i] = sr_2[i + 1] * s2 % m2; for (i = 1; i <= m; i++) work(); return 0; }
12
CPP
str_n = [int(x) for x in list(input())] max_counters = [0,0] temp_counters = [0,0] temp_elem = str_n[0] if temp_elem == 1: temp_counters[1] = temp_counters[1]+1 else: temp_counters[0] = temp_counters[0]+1 for elem in str_n[1:]: if elem == temp_elem: temp_counters[elem] +=1 else: if temp_counters[temp_elem] > max_counters[temp_elem]: max_counters[temp_elem] = temp_counters[temp_elem] temp_counters[temp_elem] = 1 temp_elem = elem if max(max_counters) >= 7: print('YES') break else: if elem == temp_elem: temp_counters[elem] +=1 if max(temp_counters) >= 7: print('YES') else: print('NO')
7
PYTHON3
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) #define REP(i,s,n) for(int i=s;i<n;i++) #define all(a) a.begin(),a.end() typedef long long ll; const ll inf = 1e9; int main(){ int n; cin >> n; vector<ll> a(n); rep(i,n)cin >> a[i]; int q; cin >> q; rep(i,q){ ll k; cin >> k; cout << binary_search(all(a), k) << endl; } return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e6 + 10; vector<int> g[MAX_N]; vector<int> a, b; map<vector<int>, int> mp; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int ia, ib; cin >> ia >> ib; g[ia].push_back(ib); g[ib].push_back(ia); a.push_back(ia); b.push_back(ib); } long long ans = 0; for (int i = 1; i <= n; i++) { sort(g[i].begin(), g[i].end()); ans += mp[g[i]]++; } mp.clear(); for (int i = 1; i <= n; i++) { g[i].push_back(i); sort(g[i].begin(), g[i].end()); ans += mp[g[i]]++; } cout << ans; return 0; }
9
CPP
a,b=map(int,input().split());print(a+(b//2))
0
PYTHON3
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; /*再帰関数による最大公約数*/ int gcd(int x,int y){ return y ? gcd(y, x%y) : x; } int main (){ int x,y; cin>>x>>y; int s=gcd(x,y); int ans=1+(x+y)-s; printf("%d\n",ans); return 0; }
0
CPP
n = int(input()) a = list(input().split()) m = int(input()) b = list(input().split()) # for i in range(max(len(a),len(b))): # if a[i] == b[i]: # if i+1 >= len(a) and len(b) > i+1 : # print('1') # break # elif i+1 >= len(b): # print('0') # break # pass # elif a[i] < b[i]: # print('1') # break # else: # print('0') # break print(+(a < b))
0
PYTHON3