malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MAX = 100010;   string nick[MAX];   int ara[MAX], ord[MAX], b[MAX];   int save[MAX];   bool cmp(int a, int b) {     if (ara[a] == ara[b]) return nick[a] < nick[b];     return ara[a] > ara[b];   }   deque<int> D;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n;     if (n == 0) {       cout << 0 <<     << 0 << endl;       return 0;     }     for (int i = 1; i <= n; i++) {       cin >> nick[i] >> ara[i];       save[i] = ara[i];     }     cin >> m;     for (int i = 1; i <= m; i++) cin >> b[i], D.push_back(b[i]);     sort(D.begin(), D.end());     string s;     cin >> s;     int id = -1;     for (int i = 1; i <= n; i++) {       if (s == nick[i]) {         if (id == -1)           id = i;         else           assert(false);       }     }     for (int i = 1; i <= n; i++) ord[i] = i;     sort(ord + 1, ord + n + 1, cmp);     int ans1, ans2;     if (m == 0) {       for (int i = 1; i <= n; i++)         if (ord[i] == id) {           ans2 = ans1 = i;           break;         }       cout << ans1 <<     << ans2 << endl;       return 0;     }     int cur;     for (int i = 1; i <= n; i++)       if (ord[i] == id) cur = i;     if (n == m) {       ara[id] += D.front();       D.pop_front();     }     int parbo = n - cur;     int bad = D.size() - parbo;     for (int i = cur - 1; i >= 1 and bad > 0; i--, bad--) {       ara[ord[i]] += D.front();       D.pop_front();     }     int need;     for (int i = cur + 1; i <= n; i++) {       need = (ara[id] + 1) - ara[ord[i]];       int paic = 0;       while (D.size() > 0) {         if (D.front() >= need) {           paic = D.front();           D.pop_front();           break;         } else           D.pop_front();       }       ara[ord[i]] += paic;     }     sort(ord + 1, ord + n + 1, cmp);     for (int i = 1; i <= n; i++)       if (ord[i] == id) ans2 = i;     for (int i = 1; i <= n; i++) ara[i] = save[i];     D.clear();     for (int i = 1; i <= m; i++) D.push_back(b[i]);     sort(D.begin(), D.end());     ara[id] += D.back();     D.pop_back();     sort(ord + 1, ord + n + 1, cmp);     for (int i = n; i >= 1 and D.size() > 0; i--) {       if (ord[i] == id) continue;       ara[ord[i]] += D.back();       D.pop_back();     }     sort(ord + 1, ord + n + 1, cmp);     for (int i = 1; i <= n; i++)       if (ord[i] == id) ans1 = i;     cout << ans1 <<     << ans2 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 100;   vector<int> a[N];   int d[N];   void work(int l, int r) {     d[l]++;     d[r + 1]--;   }   int main() {     cin.tie(0);     cin.sync_with_stdio(false);     memset(d, 0, sizeof(d));     int n, c, m, tp, i, j, x, y;     cin >> n >> c;     int sum = 0, flag = 1;     for (i = 1; i <= n; i++) {       cin >> m;       a[i].push_back(m);       for (j = 1; j <= a[i][0]; j++) {         cin >> m;         a[i].push_back(m);       }     }     for (i = 1; i < n; i++) {       tp = min(a[i][0], a[i + 1][0]);       for (j = 1; j <= tp; j++) {         x = a[i][j];         y = a[i + 1][j];         if (x != y) break;       }       if (j > tp && a[i][0] > a[i + 1][0]) {         cout << -1 << endl;         return 0;       }       if (y > x) {         work(0, c - y);         work(c + 1 - x, c - 1);       } else if (x > y) {         work(c + 1 - x, c - y);       } else         work(0, c - 1);     }     for (int i = 0; i < c; i++) {       sum += d[i];       if (sum == n - 1) {         cout << i << endl;         flag = 0;         break;       }     }     if (flag) cout << -1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2005, M = N * N;   bool vis[N];   char s[N][2][25];   int n, m, dfn[N], low[N], tt, S[N], col[N];   int hd[N], V[M], nx[M], fs[N], q[N], id[N], in[N];   vector<int> e[N];   void add(int u, int v) {     nx[++tt] = hd[u];     V[hd[u] = tt] = v;   }   void tarjan(int x) {     dfn[x] = low[x] = ++tt;     S[++S[0]] = x;     vis[x] = 1;     for (int i = hd[x]; i; i = nx[i]) {       if (!dfn[V[i]])         tarjan(V[i]), low[x] = min(low[x], low[V[i]]);       else if (vis[V[i]])         low[x] = min(low[x], dfn[V[i]]);     }     if (dfn[x] == low[x]) {       col[x] = ++col[0];       while (S[S[0]] != x) vis[S[S[0]]] = 0, col[S[S[0]--]] = col[0];       S[0]--;       vis[x] = 0;     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %s%s , s[i][0], s[i][1]);     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++) {         bool J = 1;         for (int k = 0; k < 3; k++) J &= (s[i][0][k] == s[j][0][k]);         if (J) add(i, i + n), add(j, j + n);         J = (s[i][1][0] == s[j][1][0]);         for (int k = 0; k < 2; k++) J &= (s[i][0][k] == s[j][0][k]);         if (J) add(i + n, j), add(j + n, i);         J = (s[i][0][2] == s[j][1][0]);         for (int k = 0; k < 2; k++) J &= (s[i][0][k] == s[j][0][k]);         if (J) add(i, j), add(j + n, i + n);         J = (s[i][1][0] == s[j][0][2]);         for (int k = 0; k < 2; k++) J &= (s[i][0][k] == s[j][0][k]);         if (J) add(j, i), add(i + n, j + n);       }     tt = 0;     for (int i = 1; i <= n + n; i++)       if (!dfn[i]) tarjan(i);     for (int i = 1; i <= n; i++)       if (col[i] == col[i + n]) {         puts( NO );         return 0;       }     puts( YES );     for (int i = 1; i <= n + n; i++)       for (int j = hd[i]; j; j = nx[j])         if (col[V[j]] != col[i]) e[col[i]].push_back(col[V[j]]), in[col[V[j]]]++;     int l = 1, r = 0;     for (int i = 1; i <= col[0]; i++)       if (!in[i]) q[id[i] = ++r] = i;     while (l <= r) {       int x = q[l++], z = e[x].size();       for (int v, i = 0; i < z; i++)         if (!(--in[v = e[x][i]])) q[id[v] = ++r] = v;     }     for (int i = 1; i <= n; i++) {       if (id[col[i]] < id[col[i + n]]) s[i][0][2] = s[i][1][0];       for (int k = 0; k < 3; k++) putchar(s[i][0][k]);       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char c;     int ans = 0;     for (int i = 0; i < 8; i++) {       for (int j = 0; j < 8; j++) {         cin >> c;         if (c ==  . ) continue;         if (c ==  Q ) ans += 9;         if (c ==  q ) ans -= 9;         if (c ==  R ) ans += 5;         if (c ==  r ) ans -= 5;         if (c ==  B ) ans += 3;         if (c ==  b ) ans -= 3;         if (c ==  N ) ans += 3;         if (c ==  n ) ans -= 3;         if (c ==  P ) ans += 1;         if (c ==  p ) ans -= 1;       }     }     if (ans == 0) {       cout <<  Draw  << endl;     } else if (ans > 0) {       cout <<  White  << endl;     } else {       cout <<  Black  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long base = 31;   int xx[4] = {0, 0, 1, -1};   int yy[4] = {-1, 1, 0, 0};   string step =  URDL ;   long long Pow(long long a, long long b) {     long long res = 1;     if (b <= 0) return 1;     while (b > 0) {       if (b % 2) {         res = (res % mod * a % mod);         res %= mod;       }       a = (a % mod * a % mod) % mod;       b /= 2;     }     return res % mod;   }   const int maxn = 1e6 + 1;   long long a[maxn], b[maxn];   string s;   void solve() {     cin >> s;     int n = s.size();     for (int i = 0; i < n; i++) {       a[i + 1] = a[i];       b[i + 1] = b[i];       if (s[i] ==  a )         a[i + 1]++;       else         b[i]++;     }     long long res = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  b ) {         res = (res % mod + (Pow(2, a[i + 1]) - 1)) % mod;       }     }     cout << res;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   long long int n, k;   long long int a[100010], max;   long long int print[100010], pc;   int main(void) {     long long int i, j, f, l, mid;     long long int sum, baki = 2147483647;     scanf( %I64d %I64d , &n, &k);     for (i = 1; i <= n; i++) {       scanf( %I64d , &a[i]);       if (max < a[i]) max = a[i];     }     if (k == 0) {       for (i = 1; i <= n; i++) {         printf( %I64d  , i);       }       return false;     }     f = 1, l = max;     for (;;) {       mid = (f + l) / 2;       sum = 0;       for (i = 1; i <= n; i++) {         if (a[i] >= mid)           sum += mid;         else           sum += a[i];       }       if (sum >= k) {         if (baki > mid) baki = mid;         l = mid - 1;       } else {         f = mid + 1;       }       if (f > l) break;     }     if (baki == 2147483647) {       printf( -1 n );       return false;     }     for (i = 1; i <= n; i++) {       if (baki > a[i])         k -= a[i];       else         k -= baki - 1;     }     for (i = 1; i <= n; i++) {       if (baki <= a[i]) k--;       if (k == 0) break;     }     if (k > 0) {       printf( -1 n );       return false;     }     for (j = i + 1; j <= n; j++) {       if (baki <= a[j]) {         print[++pc] = j;       }     }     for (j = 1; j <= i; j++) {       if (baki < a[j]) {         print[++pc] = j;       }     }     for (i = 1; i <= pc; i++) {       printf( %I64d  , print[i]);     }     return false;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void pr(const string& name, T t) {     cerr << name <<  :   << t << endl;   }   template <typename T, typename... Types>   void pr(const string& names, T t, Types... rest) {     auto comma_pos = names.find( , );     cerr << names.substr(0, comma_pos) <<  :   << t <<  ,  ;     auto next_name_pos = names.find_first_not_of(   t n , comma_pos + 1);     pr(string(names, next_name_pos), rest...);   }   template <class T, class U>   ostream& operator<<(ostream& o, const pair<T, U>& v) {     return o <<  (  << v.first <<  ,   << v.second <<  ) ;   }   template <class T>   ostream& operator<<(ostream& o, const vector<T>& v) {     o <<  { ;     for (int i = 0; i < (int)((int)((v).size())); ++i)       o << (i ?  ,   :   ) << v[i];     return o <<  } ;   }   const int dx[] = {0, 1, 0, -1};   const int dy[] = {-1, 0, 1, 0};   const int MAX_N = 2e5 + 10;   vector<int> G[MAX_N];   vector<int> rG[MAX_N];   int cmp[MAX_N];   bool vis[MAX_N];   int V;   vector<int> vs;   void dfs(int v) {     vis[v] = true;     for (auto e : G[v])       if (!vis[e]) dfs(e);     vs.push_back(v);   }   void rdfs(int v, int k) {     vis[v] = true;     cmp[v] = k;     for (auto e : rG[v])       if (!vis[e]) rdfs(e, k);   }   int scc() {     vs.clear();     memset(vis, 0, sizeof(vis));     for (int i = 0; i < (int)(V); ++i)       if (!vis[i]) dfs(i);     memset(vis, 0, sizeof(vis));     int k = 0;     reverse((vs).begin(), (vs).end());     for (auto e : vs)       if (!vis[e]) rdfs(e, k++);     return k;   }   int un[MAX_N];   int find(int x) {     if (un[x] == x) return x;     return un[x] = find(un[x]);   }   void unit(int a, int b) { un[find(a)] = find(b); }   int main(int argc, char* argv[]) {     ios::sync_with_stdio(0);     cin.tie(0);     memset(un, -1, sizeof(un));     int n, m;     cin >> n >> m;     for (int i = 0; i < (int)(n); ++i) un[i] = i;     for (int i = 0; i < (int)(m); ++i) {       int a, b;       cin >> a >> b;       --a, --b;       G[a].push_back(b);       rG[b].push_back(a);       unit(a, b);     }     V = n;     scc();     map<int, set<int> > app;     for (int i = 0; i < (int)(n); ++i) app[find(i)].insert(i);     int ans = 0;     for (auto& e : app) {       if ((int)((e.second).size()) == 1) continue;       set<int> cnum;       for (auto v : e.second) cnum.insert(cmp[v]);       if ((int)((cnum).size()) != (int)((e.second).size()))         ans += (int)((e.second).size());       else         ans += (int)((e.second).size()) - 1;     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     vector<int> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < 10; i++) {     }     set<int> s(a.begin(), a.end());     if (s.size() < k) {       cout <<  NO  << endl;     } else {       cout <<  YES  << endl;       int cnt = 0;       for (auto item : s) {         if (cnt == k) {           break;         }         for (int i = 0; i < n; i++) {           if (a[i] == item) {             cout << i + 1 <<    ;             cnt++;             break;           }         }       }       for (int i = 0; i < 10; i++) {       }       cout << endl;     }     for (int i = 0; i < 10; i++) {     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> G[100005];   vector<int> rG[100005];   int f[100005];   int n, m;   bool canUsing[100005];   bool canAss[100005];   void dfs0(int u) {     canUsing[u] = 1;     if (f[u] == 1) return;     for (int i = 0; i < rG[u].size(); i++) {       int v = rG[u][i];       if (canUsing[v]) continue;       dfs0(v);     }   }   void dfs1(int u) {     canAss[u] = 1;     for (int i = 0; i < G[u].size(); i++) {       int v = G[u][i];       if (canAss[v]) continue;       dfs1(v);     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &f[i]);     for (int i = 1; i <= m; i++) {       int u, v;       scanf( %d%d , &u, &v);       G[u].push_back(v);       rG[v].push_back(u);     }     for (int i = 1; i <= n; i++) {       if (f[i] == 2 && canUsing[i] == 0) dfs0(i);       if (f[i] == 1 && canAss[i] == 0) dfs1(i);     }     for (int i = 1; i <= n; i++) {       int t = canAss[i] & canUsing[i];       printf( %d n , t);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool letras[26];   int main() {     list<char> kbd;     list<char>::iterator i;     int t, j;     bool foundKbd;     string s;     for (cin >> t; t > 0; t--) {       foundKbd = true;       cin >> s;       for (j = 0; j < s.size() && foundKbd; j++) {         if (kbd.size() == 0) {           kbd.push_back(s.at(j));           letras[s.at(j) -  a ] = true;         } else if (letras[s.at(j) -  a ] == false) {           for (i = kbd.begin(); i != kbd.end() && *i != s.at(j - 1); i++)             ;           if (i == kbd.begin()) {             kbd.push_front(s.at(j));             letras[s.at(j) -  a ] = true;           } else if (i == --kbd.end()) {             kbd.push_back(s.at(j));             letras[s.at(j) -  a ] = true;           } else             foundKbd = false;         } else {           for (i = kbd.begin(); i != kbd.end() && *i != s.at(j - 1); i++)             ;           if (*(++i) == s.at(j))             --i;           else if (*(--(--i)) != s.at(j))             foundKbd = false;         }       }       if (foundKbd) {         cout <<  YES  << endl;         for (j = 0; j < 26; j++)           if (letras[j] == false) kbd.push_back( a  + j);         for (i = kbd.begin(); i != kbd.end(); i++) cout << *i;         cout << endl;       } else         cout <<  NO  << endl;       kbd.clear();       for (j = 0; j < 26; j++) letras[j] = false;     }   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     for (; !isdigit(ch); ch = getchar()) {       if (ch ==  - ) f = -1;     }     for (; isdigit(ch); ch = getchar()) {       x = x * 10 + ch - 48;     }     return x * f;   }   const int mxN = 1e5;   const int P = 998244353;   struct Element {     long long x, v, p;   } a[mxN + 3];   struct Event {     int u, x, y;     long long t1, t2;     bool operator<(const Event &arg) const { return t1 * arg.t2 < t2 * arg.t1; }   } ev[mxN * 2 + 3];   int f[mxN + 3][2][2];   int n, m;   long long quickpow(long long x, long long y) {     long long cur = x, ret = 1ll;     for (int i = 0; y; i++) {       if (y & (1ll << i)) {         y -= (1ll << i);         ret = ret * cur % P;       }       cur = cur * cur % P;     }     return ret;   }   long long mulinv(long long x) { return quickpow(x, P - 2); }   struct SgTNode {     long long x[2][2];   } sgt[mxN * 4 + 3];   void pushup(int u, int mid) {     for (int i = 0; i < 2; i++)       for (int j = 0; j < 2; j++) sgt[u].x[i][j] = 0ll;     for (int i = 0; i < 2; i++)       for (int j = 0; j < 2; j++)         if (!f[mid][i][j]) {           for (int ii = 0; ii < 2; ii++)             for (int jj = 0; jj < 2; jj++) {               sgt[u].x[ii][jj] += sgt[u << 1].x[ii][i] * sgt[u << 1 | 1].x[j][jj];             }         }     for (int i = 0; i < 2; i++)       for (int j = 0; j < 2; j++) {         sgt[u].x[i][j] %= P;       }   }   void build(int u, int le, int ri) {     if (le == ri) {       sgt[u].x[0][0] = P + 1 - a[le].p, sgt[u].x[1][1] = a[le].p;       return;     }     int mid = (le + ri) >> 1;     build(u << 1, le, mid);     build(u << 1 | 1, mid + 1, ri);     pushup(u, mid);   }   void update(int u, int le, int ri, int pos) {     if (le == ri) {       return;     }     int mid = (le + ri) >> 1;     if (pos <= mid) {       update(u << 1, le, mid, pos);     } else {       update(u << 1 | 1, mid + 1, ri, pos);     }     pushup(u, mid);   }   long long query() {     return (sgt[1].x[0][0] + sgt[1].x[0][1] + sgt[1].x[1][0] + sgt[1].x[1][1]) %            P;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %I64d%I64d%I64d , &a[i].x, &a[i].v, &a[i].p);       a[i].p = a[i].p * mulinv(100) % P;     }     for (int i = 1; i < n; i++) {       ev[++m].u = i, ev[m].x = 1, ev[m].y = 0, ev[m].t1 = a[i + 1].x - a[i].x,       ev[m].t2 = a[i].v + a[i + 1].v;       if (a[i].v < a[i + 1].v) {         ev[++m].u = i, ev[m].x = 0, ev[m].y = 0, ev[m].t1 = a[i + 1].x - a[i].x,         ev[m].t2 = a[i + 1].v - a[i].v;       } else if (a[i].v > a[i + 1].v) {         ev[++m].u = i, ev[m].x = 1, ev[m].y = 1, ev[m].t1 = a[i + 1].x - a[i].x,         ev[m].t2 = a[i].v - a[i + 1].v;       }     }     sort(ev + 1, ev + m + 1);     long long ans = 0ll, prob = 1ll;     build(1, 1, n);     for (int i = 1; i <= m; i++) {       f[ev[i].u][ev[i].x][ev[i].y] = 1;       update(1, 1, n, ev[i].u);       long long tmp = query(), tim = ev[i].t1 * mulinv(ev[i].t2) % P;       ans = (ans + (prob - tmp + P) * tim) % P;       prob = tmp;     }     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T gi() {     T x = 0;     bool f = 0;     char c = getchar();     while (c !=  -  && (c <  0  || c >  9 )) c = getchar();     if (c ==  - ) f = 1, c = getchar();     while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar();     return f ? -x : x;   }   const int N = 2e5 + 10;   struct node {     int to, nxt, w;   } g[N << 1];   int lst[N], gl, w[N];   void add(int z, int y, int x) {     g[++gl] = (node){y, lst[x], z};     lst[x] = gl;     g[++gl] = (node){x, lst[y], z};     lst[y] = gl;   }   int ans1;   double ans2;   int siz[N], mx, rt, sum;   bool vis[N];   void getroot(int u, int ff) {     siz[u] = 1;     int s = 0;     for (int i = lst[u]; i; i = g[i].nxt) {       int v = g[i].to;       if (v == ff || vis[v]) continue;       getroot(v, u);       siz[u] += siz[v];       s = max(s, siz[v]);     }     s = max(s, sum - siz[u]);     if (s < mx) mx = s, rt = u;   }   double sd[N], sumd, ans;   void dfs(int u, int ff, int tp, int dep) {     ans += pow(dep, 1.5) * w[u];     sumd += 1.5 * sqrt(dep) * w[u];     sd[tp] += 1.5 * sqrt(dep) * w[u];     for (int i = lst[u]; i; i = g[i].nxt) {       int v = g[i].to;       if (v == ff) continue;       dfs(v, u, tp, dep + g[i].w);     }   }   void solve(int u) {     vis[u] = 1;     ans = sumd = 0;     for (int i = lst[u]; i; i = g[i].nxt)       sd[g[i].to] = 0, dfs(g[i].to, u, g[i].to, g[i].w);     if (ans2 > ans) ans1 = u, ans2 = ans;     for (int i = lst[u]; i; i = g[i].nxt) {       int v = g[i].to;       if (vis[v]) continue;       if (sumd - sd[v] > sd[v]) continue;       mx = sum = siz[v];       getroot(v, u);       solve(rt);     }   }   int main() {     int n = gi<int>();     for (int i = 1; i <= n; i++) w[i] = gi<int>();     for (int i = 1; i < n; i++) add(gi<int>(), gi<int>(), gi<int>());     ans2 = 1e20;     mx = sum = n;     getroot(1, 0);     solve(rt);     printf( %d %.10lf n , ans1, ans2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, i;     double sum = 0, num, av, av1;     cin >> n >> k;     int a[n];     for (i = 0; i < n; i++) {       cin >> a[i];       sum = sum + a[i];     }     av1 = sum / n;     if (av1 >= (k - .5)) {       cout << 0 << endl;       return 0;     } else {       for (i = 1;; i++) {         sum = sum + k;         num = n + i;         av = sum / num;         if (av >= (k - 0.5)) {           cout << i << endl;           return 0;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     bool check = false;     int left, right;     cin >> left >> right;     for (int i = left; i <= right; i++) {       int num = i;       bool ch[10] = {false};       while (num > 0) {         if (ch[num % 10]) break;         ch[num % 10] = true;         num /= 10;       }       if (num == 0) {         cout << i;         check = true;         break;       }     }     if (!check) cout <<  -1 ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char *name, Arg1 &&arg1) {     cerr << name <<   :   << arg1 << endl;   }   template <typename Arg1, typename... Args>   void __f(const char *names, Arg1 &&arg1, Args &&...args) {     const char *comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   using ll = long long;   using P = pair<int, int>;   using vi = vector<int>;   const char nl =   n ;   const int inf = 2e9;   const ll INF = (ll)2e18;   const ll mod = 1e9 + 7;   const int N = 2e6 + 15;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n, x;     cin >> n;     vi a(n), pos(n + 1);     vi bucket(n, 0);     for (int i = 0; i < n; ++i) cin >> a[i];     for (int i = 0; i < n; ++i) {       cin >> x;       pos[x] = i;     }     for (int i = 0; i < n; ++i) {       if (pos[a[i]] <= i) {         bucket[i - pos[a[i]]]++;       } else {         bucket[i + n - pos[a[i]]]++;       }     }     int ans = 0;     for (int i = 0; i < n; ++i) {       ans = max(ans, bucket[i]);     }     cout << ans << nl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int A[n], ans = 0, maxi = -1;     for (int i = 0; i < n; i++) {       cin >> A[i];       if (A[i] == 1)         ans++;       else {         maxi = max(ans, maxi);         ans = 0;       }     }     for (int i = 0; i < n; i++) {       if (A[i] == 1)         ans++;       else {         maxi = max(ans, maxi);         ans = 0;       }     }     cout << maxi;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   using minpq = priority_queue<T, vector<T>, greater<T>>;   long long pl, pr, vl, vr;   int k;   long long inter(long long a, long long b, long long c, long long d) {     return max(0LL, min(b, d) - max(a, c) + 1);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> pl >> pr >> vl >> vr >> k;     long double ans = 0;     vector<long long> lucky;     for (int len = (0); len < (11); len++) {       for (int x = (0); x < ((1 << len)); x++) {         long long y = 0;         for (int i = (0); i < (len); i++) {           if ((x >> i) & 1) {             y = y * 10 + 4;           } else {             y = y * 10 + 7;           }         }         lucky.push_back(y);       }     }     sort((lucky).begin(), (lucky).end());     int n = ((int)(lucky).size());     for (int i = (1); i < (n - k); i++) {       int j = i + k;       ans += 1.0 * inter(pl, pr, lucky[i - 1] + 1, lucky[i]) *              inter(vl, vr, lucky[j - 1], lucky[j] - 1);       ans += 1.0 * inter(vl, vr, lucky[i - 1] + 1, lucky[i]) *              inter(pl, pr, lucky[j - 1], lucky[j] - 1);       if (k == 1 && pl <= lucky[i] && lucky[i] <= pr && vl <= lucky[i] &&           lucky[i] <= vr)         ans--;     }     ans /= 1.0 * (pr - pl + 1) * (vr - vl + 1);     cout << fixed << setprecision(11) << ans <<   n ;   }