malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 300005;   template <typename T>   inline void read(T &AKNOI) {     T x = 0, flag = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) flag = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     AKNOI = flag * x;   }   namespace ModCalculator {   const int MOD = 1e9 + 7;   inline void Inc(int &x, int y) {     x += y;     if (x >= MOD) x -= MOD;   }   inline void Dec(int &x, int y) {     x -= y;     if (x < 0) x += MOD;   }   inline int Add(int x, int y) {     Inc(x, y);     return x;   }   inline int Sub(int x, int y) {     Dec(x, y);     return x;   }   inline int Mul(int x, int y) { return 1LL * x * y % MOD; }   inline int Ksm(int x, int k) {     int ret = 1;     for (; k; k >>= 1) {       if (k & 1) ret = Mul(ret, x);       x = Mul(x, x);     }     return ret;   }   inline int Inv(int x) { return Ksm(x, MOD - 2); }   }  // namespace ModCalculator   using namespace ModCalculator;   int n, fac[MAXN], finv[MAXN], sum[MAXN];   vector<int> a[MAXN];   inline int C(int x, int y) { return Mul(fac[x], Mul(finv[y], finv[x - y])); }   void init() {     read(n);     for (int i = 1; i <= n; ++i) {       int x;       read(x);       for (int j = 2; j * j <= x; ++j) {         if (x % j) continue;         int cnt = 0;         while (x % j == 0) {           ++cnt;           x /= j;         }         a[j].push_back(cnt);       }       if (x > 1) {         a[x].push_back(1);       }     }     fac[0] = 1;     for (int i = 1; i <= n; ++i) {       fac[i] = Mul(fac[i - 1], i);     }     finv[n] = Inv(fac[n]);     for (int i = n; i >= 1; --i) {       finv[i - 1] = Mul(finv[i], i);     }     sum[0] = 1;     for (int i = 1; i < n; ++i) {       sum[i] = Add(sum[i - 1], C(n - 1, i));     }   }   void solve() {     int ans = 0;     for (int i = 2; i < MAXN; ++i) {       if (!a[i].size()) continue;       sort(a[i].begin(), a[i].end());       int r = n - a[i].size();       for (auto x : a[i]) {         ++r;         int coef = (r > 1 ? sum[r - 2] : 0);         Dec(coef, Sub(sum[n - 1], sum[r - 1]));         Inc(ans, Mul(x, coef));       }     }     printf( %d n , ans);   }   int main() {     init();     solve();     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int N = 1e3 + 5, OO = 0x3f3f3f3f, MOD = 1000000007, M = 200000 + 5;   const double EPS = 0.000000001;   int n, x, y;   char str[N];   int main() {     scanf( %d %s , &n, str);     for (int i = 0; i < n; ++i) {       x += str[i] ==  R  ? 1 : str[i] ==  L  ? -1 : 0;       y += str[i] ==  U  ? 1 : str[i] ==  D  ? -1 : 0;     }     x = abs(x);     y = abs(y);     printf( %d n , n - x - y);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, ans, val[3001000];   priority_queue<int> q;   int main() {     scanf( %lld , &n);     for (int i = 1; i <= n; i++) scanf( %lld , &val[i]);     for (int i = 1; i <= n; i++) {       q.push(-val[i]);       q.push(-val[i]);       ans += val[i] + q.top();       q.pop();     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5;   int p[N + 10], a[N + 10], pos[N + 10];   struct seg {     int l, r, min;   } t[N * 4 + 10];   int nxt[N + 10][20];   int get(int x, int n) {     int ans = x, cnt = 0;     while (n) {       if (n & 1) ans = nxt[ans][cnt];       if (ans >= 0x7f7f7f7f) break;       n >>= 1;       cnt++;     }     return ans;   }   int n;   void build(int p, int l, int r) {     t[p].l = l;     t[p].r = r;     if (l == r) {       t[p].min = get(l, n - 1);       return;     }     int mid = (l + r) / 2;     build(p * 2, l, mid);     build(p * 2 + 1, mid + 1, r);     t[p].min = min(t[p * 2].min, t[p * 2 + 1].min);   }   int query(int p, int l, int r) {     if (l <= t[p].l && t[p].r <= r) return t[p].min;     int mid = (t[p].l + t[p].r) / 2, ans = 0x7f7f7f7f;     if (l <= mid) ans = min(ans, query(p * 2, l, r));     if (r > mid) ans = min(ans, query(p * 2 + 1, l, r));     return ans;   }   int ans[N + 10];   int main() {     int m, q;     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= n; i++) {       scanf( %d , &p[i]);       pos[p[i]] = i;     }     for (int i = 1; i <= m; i++) {       scanf( %d , &a[i]);       a[i] = pos[a[i]];     }     memset(pos, 0x7f, sizeof(pos));     for (int i = m; i; i--) {       nxt[i][0] = pos[a[i] == n ? 1 : a[i] + 1];       pos[a[i]] = i;     }     int logn = (int)(log(n) / log(2)) + 1;     for (int s = 1; s <= logn; s++) {       for (int i = 1; i <= m; i++) {         if (i + (1 << s) - 1 > m) {           nxt[i][s] = 0x7f7f7f7f;           continue;         }         if (nxt[i][s - 1] > m) {           nxt[i][s] = 0x7f7f7f7f;           continue;         }         nxt[i][s] = nxt[nxt[i][s - 1]][s - 1];       }     }     build(1, 1, m);     for (int i = 1; i <= q; i++) {       int l, r;       scanf( %d%d , &l, &r);       int tmp = query(1, l, r);       ans[i] = (tmp <= r);     }     for (int i = 1; i <= q; i++) putchar(48 ^ ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long T, n;     cin >> T;     while (T--) {       cin >> n;       double x = (3.141592653589793238) / (2 * n);       cout << fixed << setprecision(10) << cos(x) / sin(x) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void out(int a) { printf( %d n , a); }   inline void out(int a, int b) { printf( %d %d n , a, b); }   inline void outf(double a) { printf( %3.lf n , a); }   inline void outf(double a, double b) { printf( %3.lf %3.lf n , a, b); }   inline void base() {     ios_base::sync_with_stdio(false);     cin.tie(0);   }   bool cek(long long a, long long b) {     long long tmp = 0;     long long ctr = 1;     while (a) {       if (a % 10 == 7 || a % 10 == 4) {         tmp = tmp + ctr * (a % 10);         ctr *= 10;       }       a /= 10;     }     return tmp == b;   }   int main() {     base();     long long a, b;     cin >> a >> b;     a++;     while (!cek(a, b)) {       a++;     }     cout << a << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string a, b, c, s;   const long long mod = 1000000007;   long long res[310000], sum;   int N, ar[310000], srt[310000], dad[310000];   int where[310000], lcp[310000], F[310000], S[310000], T[310000];   pair<int, int> as[310000];   vector<pair<int, int> > q;   int comp(const int &a, const int &b) { return as[a] < as[b]; }   int find(int x) {     if (dad[x] == x) return x;     return dad[x] = find(dad[x]);   }   int main() {     cin >> a >> b >> c;     N = a.size() + b.size() + c.size() + 2;     s =     + a +  #  + b +  0  + c;     for (int i = 1; i <= N; i++) ar[i] = s[i];     for (int z = 0; (1 << z) <= N; z++) {       for (int i = 1; i <= N; i++)         as[i] = pair<int, int>(ar[i],                                ((i + (1 << z)) <= N) ? (ar[i + (1 << z)]) : (-1)),         srt[i] = i;       sort(srt + 1, srt + 1 + N, comp);       pair<int, int> prev = pair<int, int>(-1, -1);       for (int i = 1, cnt = 0; i <= N; i++) {         if (as[srt[i]] != prev) {           prev = as[srt[i]];           ++cnt;         }         ar[srt[i]] = cnt;       }     }     for (int i = 1; i <= N; i++) where[ar[i]] = i;     for (int i = 1, ss = 0; i <= N; i++) {       if (ar[i] == N) continue;       int x = where[ar[i] + 1];       while (s[i + ss] == s[x + ss] && i + ss <= N && x + ss <= N) ss++;       lcp[ar[i]] = ss;       q.push_back(pair<int, int>(ss, ar[i]));       if (ss) ss--;     }     for (int i = 1; i <= N; i++) {       dad[i] = i;       if (where[i] <= a.size())         F[i] = 1;       else if (where[i] <= a.size() + b.size() + 1)         S[i] = 1;       else         T[i] = 1;     }     sort(q.begin(), q.end());     reverse(q.begin(), q.end());     int M = min(a.size(), min(b.size(), c.size()));     for (int i = M, j = 0; i; i--) {       while (j < (int)q.size() && q[j].first >= i) {         int x = q[j].second, y = q[j].second + 1;         long long pl = -1LL * F[find(x)] * S[find(x)] * T[find(x)];         pl -= 1LL * F[find(y)] * S[find(y)] * T[find(y)];         F[find(x)] += F[find(y)];         S[find(x)] += S[find(y)];         T[find(x)] += T[find(y)];         dad[find(y)] = find(x);         pl += 1LL * F[find(x)] * S[find(x)] * T[find(x)];         sum = (sum + pl) % mod;         j++;       }       res[i] = sum;     }     for (int i = 1; i <= M; i++) printf( %d  , res[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1 << 20;   long long sum;   int k, p, n, a[N + 1], i, b[N + 1], left_tree[N + 1], right_tree[N + 1];   vector<long long> leftv, rightv;   void update(int index, int value, int tree[]) {     while (index < N + 1) {       tree[index] += value;       index += (index & -index);     }   }   int read(int index, int tree[]) {     int sum = 0;     while (index > 0) {       sum += tree[index];       index -= (index & -index);     }     return sum;   }   int main() {     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i];       b[i] = a[i];     }     sort(b, b + n);     for (i = 0; i < n; i++) {       a[i] = upper_bound(b, b + n, a[i]) - b;     }     for (i = 0; i < n; i++) {       update(a[i], 1, left_tree);       leftv.push_back(read(N, left_tree) - read(a[i], left_tree));     }     for (i = n - 1; i >= 0; i--) {       rightv.push_back(read(a[i], right_tree));       update(a[i], 1, right_tree);     }     reverse(rightv.begin(), rightv.end());     for (i = 0; i < n; i++) {       sum += rightv[i] * leftv[i];     }     cout << sum;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[100001], b[100001];   long long int k, SS;   int compare(const void* a, const void* b) { return (*(int*)a - *(int*)b); }   int main() {     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> a[i];       b[i] = a[i];       SS = SS + a[i];     }     if (SS < k) {       cout << -1;       return 0;     }     if (SS == k) {       return 0;     }     qsort(b, n, sizeof(int), compare);     int s = 0;     long long int K = k;     for (int i = 0; i < n; i++)       if (b[i] > s) {         if (K >= (long long int)(n - i) * (b[i] - s)) {           K = K - (long long int)(n - i) * (b[i] - s);           s = b[i];         } else {           break;         }       }     int conlai = n;     for (int i = 0; i < n; i++) {       if (a[i] <= s) {         a[i] = -1;         conlai--;       } else         a[i] = a[i] - s;     }     for (int i = 0; i < n; i++)       if (a[i] != -1) {         a[i] = a[i] - K / conlai;         if (a[i] == 0) a[i] == -1;       }     K = K % conlai;     if (K > 0)       for (int i = 0; i < n; i++) {         if (a[i] >= 1) {           K--;           if (a[i] == 1) a[i] = -1;           if (K == 0) {             for (int j = i + 1; j < n; j++)               if (a[j] != -1) cout << j + 1 <<    ;             for (int j = 0; j <= i; j++)               if (a[j] != -1) cout << j + 1 <<    ;           }         }       }     else       for (int i = 0; i < n; i++)         if (a[i] != -1) cout << i + 1 <<    ;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void pv(T a, T b) {     for (T i = a; i != b; ++i) cout << *i <<    ;     cout << endl;   }   int main() {     int N;     scanf( %d , &N);     int cnt[3] = {};     for (int i = 0; i < (int)(N); ++i) {       int a;       scanf( %d , &a);       ++cnt[a - 1];     }     cout << (N - *max_element(cnt, cnt + 3)) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a, b, c, k, k1, ans;   int main() {     cin >> a >> b >> c;     if (b > c) swap(b, c);     if (b <= a / 2 && c > a / 2) {       cout <<  Final!  << endl;       return 0;     }     while (c != b) {       b++;       c++;       b /= 2;       c /= 2;       ans++;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   using vc = vector<T>;   template <class T>   using vvc = vc<vc<T>>;   template <class T>   void mkuni(vector<T>& v) {     sort(v.begin(), v.end());     v.erase(unique(v.begin(), v.end()), v.end());   }   long long rand_int(long long l, long long r) {     static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());     return uniform_int_distribution<long long>(l, r)(gen);   }   template <class T>   void print(T x, int suc = 1) {     cout << x;     if (suc == 1)       cout <<   n ;     else       cout <<    ;   }   template <class T>   void print(const vector<T>& v, int suc = 1) {     for (int i = 0; i < v.size(); i++)       print(v[i], i == (int)(v.size()) - 1 ? suc : 2);   }   const int maxn = 1e6 + 7;   int ed[maxn];   int p[maxn];   struct Edge {     int u, v;   } edge[maxn];   struct Q {     int tp, x;   };   int fa[maxn];   int Find(int x) { return x == fa[x] ? x : fa[x] = Find(fa[x]); }   int tot;   vector<int> G[maxn];   void Union(int x, int y) {     x = Find(x), y = Find(y);     if (x == y) return;     tot++;     fa[x] = tot;     fa[y] = tot;     G[tot].push_back(x);     G[tot].push_back(y);   }   int ti[maxn], ot[maxn];   int T;   void dfs(int u, int fa = -1) {     ti[u] = ++T;     for (auto v : G[u])       if (v != fa) dfs(v, u);     ot[u] = T;   }   pair<int, int> mx[maxn << 2];   void modify(int p, int v, int L = 1, int R = tot, int o = 1) {     if (L == R) {       mx[o] = make_pair(v, p);       return;     }     int mid = L + R >> 1;     if (p <= mid)       modify(p, v, L, mid, o << 1);     else       modify(p, v, mid + 1, R, o << 1 | 1);     mx[o] = max(mx[o << 1], mx[o << 1 | 1]);   }   pair<int, int> ask(int l, int r, int L = 1, int R = tot, int o = 1) {     if (l <= L && r >= R) return mx[o];     pair<int, int> ret = {0, 0};     int mid = L + R >> 1;     if (l <= mid) ret = max(ret, ask(l, r, L, mid, o << 1));     if (r > mid) ret = max(ret, ask(l, r, mid + 1, R, o << 1 | 1));     return ret;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n, m, q;     cin >> n >> m >> q;     for (int i = 1; i <= n + m + q; i++) fa[i] = i;     tot = n;     for (int i = 1; i <= n; i++) cin >> p[i];     for (int i = 1; i <= m; i++) cin >> edge[i].u >> edge[i].v, ed[i] = q;     vc<Q> query(q);     for (int i = 0; i < q; i++) {       int tp, x;       cin >> tp >> x;       if (tp == 2) ed[x] = i;       query[i] = {tp, x};     }     for (int i = 1; i <= m; i++)       if (ed[i] == q) Union(edge[i].u, edge[i].v);     for (int i = q - 1; i >= 0; i--) {       int x = query[i].x;       if (query[i].tp == 2)         Union(edge[x].u, edge[x].v);       else {         query[i].x = Find(query[i].x);         ;       }     }     for (int i = 1; i <= tot; i++)       if (Find(i) == i) dfs(i);     for (int i = 1; i <= n; i++) modify(ti[i], p[i]);     for (int i = 0; i < q; i++) {       if (query[i].tp == 1) {         int x = query[i].x;         auto tar = ask(ti[x], ot[x]);         print(tar.first);         modify(tar.second, 0);       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   const long long mod = 1e9 + 7;   int prime[500], judge[500], lcm[500][40], cnt, tol;   int tree[100][maxn << 2], root[maxn], ls[maxn << 6], rs[maxn << 6],       sum[maxn << 6], last[maxn << 1];   int a[maxn], ba = 1 << (int)ceil(log2(1e5 + 1));   inline void sieve() {     int sq = sqrt(maxn << 1);     for (int i = 2; i <= sq; i++) {       if (!judge[i]) prime[judge[i] = ++cnt] = i;       for (int j = 1, v; j <= judge[i] && (v = i * prime[j]) <= sq; j++)         judge[v] = j;     }   }   inline void build(int n, int no) {     int x, v = prime[no];     for (int i = 1; i <= n; i++) {       x = 0;       while (!(a[i] % v)) {         a[i] /= v;         x++;       }       tree[no][ba + i - 1] = x;     }     for (int i = ba - 1; i >= 1; i--)       tree[no][i] = max(tree[no][i << 1], tree[no][i << 1 | 1]);   }   inline int query(int l, int r, int no) {     l = l + ba - 1;     r = r + ba - 1;     int ans = 0;     while (l <= r) {       if (l & 1) ans = max(ans, tree[no][l++]);       if (~r & 1) ans = max(ans, tree[no][r--]);       l >>= 1;       r >>= 1;     }     return ans;   }   inline int powmod(long long a, int b) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % mod;       a = a * a % mod;       b >>= 1;     }     return ans;   }   inline int buildrt(int l, int r) {     int rt = ++tol;     if (l == r) return rt;     int mid = l + r >> 1;     ls[rt] = buildrt(l, mid);     rs[rt] = buildrt(mid + 1, r);     return rt;   }   inline int updatert(int k, int l, int r, int rt, long long v) {     int now = ++tol;     ls[now] = ls[rt], rs[now] = rs[rt], sum[now] = max(sum[rt], 1) * v % mod;     if (l == r) return now;     int mid = l + r >> 1;     if (k <= mid)       ls[now] = updatert(k, l, mid, ls[now], v);     else       rs[now] = updatert(k, mid + 1, r, rs[now], v);     return now;   }   inline long long queryrt(int rt, int l, int r, int L, int R) {     if (R < l || r < L) return 1;     if (L <= l && r <= R) return max(1, sum[rt]);     int mid = l + r >> 1;     return queryrt(ls[rt], l, mid, L, R) * queryrt(rs[rt], mid + 1, r, L, R) %            mod;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     sieve();     int n, ans = 0, l, r, q;     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= cnt; i++) build(n, i);     root[0] = buildrt(1, n);     for (int i = 1; i <= n; i++) {       root[i] = root[i - 1];       if (a[i] == 1) continue;       if (last[a[i]])         root[i] = updatert(last[a[i]], 1, n, root[i], powmod(a[i], mod - 2));       root[i] = updatert(i, 1, n, root[i], a[i]);       last[a[i]] = i;     }     cin >> q;     while (q--) {       cin >> l >> r;       l = (ans + l) % n + 1;       r = (ans + r) % n + 1;       if (l > r) swap(l, r);       ans = 1;       for (int i = 1; i <= cnt; i++)         ans = (long long)ans * powmod(prime[i], query(l, r, i)) % mod;       cout << (ans = ans * queryrt(root[r], 1, n, l, r) % mod) <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   vector<int> p;   vector<int> t;   int main() {     int n, c, a, ans1 = 0, ans2 = 0, t1 = 0, t2 = 0;     cin >> n >> c;     for (int i = 0; i < n * 2; i++) {       cin >> a;       if (i < n) {         p.push_back(a);       } else {         t.push_back(a);       }     }     for (int i = 0; i < p.size(); i++) {       t1 += t[i];       ans1 += max(0, p[i] - c * t1);     }     for (int i = n - 1; i >= 0; i--) {       t2 += t[i];       ans2 += max(0, p[i] - c * t2);     }     if (ans1 > ans2)       cout <<  Limak ;     else if (ans2 > ans1)       cout <<  Radewoosh ;     else       cout <<  Tie ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int const N = 3e5 + 5;   int const NN = 20;   int const MAX = 1e9 + 1;   int n, a[N];   struct ITMAX {     pair<int, int> tree[4 * N];     pair<int, int> get_interval(pair<int, int> p, pair<int, int> q) {       return make_pair(min(p.first, q.first), max(p.second, q.second));     }     void build(int node, int l, int r, pair<int, int> val[]) {       if (l == r) {         tree[node] = val[l];         return;       }       int mid = (l + r) / 2;       build(node * 2, l, mid, val);       build(node * 2 + 1, mid + 1, r, val);       tree[node] = get_interval(tree[node * 2], tree[node * 2 + 1]);     }     pair<int, int> get_max(int node, int l, int r, int d, int c) {       if (l > c || r < d) {         return make_pair(MAX, -MAX);       }       if (d <= l && r <= c) {         return tree[node];       }       int mid = (l + r) / 2;       return get_interval(get_max(node * 2, l, mid, d, c),                           get_max(node * 2 + 1, mid + 1, r, d, c));     }   };   ITMAX tree[NN];   pair<int, int> dp[NN][N];   void solve_nxt() {     for (int i = 1; i <= n; i++) {       dp[0][i] = make_pair(max(i - a[i], 1), min(i + a[i], n));     }     tree[0].build(1, 1, n, dp[0]);     for (int j = 1; j < NN; j++) {       for (int i = 1; i <= n; i++) {         dp[j][i] =             tree[j - 1].get_max(1, 1, n, dp[j - 1][i].first, dp[j - 1][i].second);       }       tree[j].build(1, 1, n, dp[j]);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       a[i + n] = a[i];       a[i + n + n] = a[i];     }     if (n == 1) {       cout << 0 << endl;       return 0;     }     n *= 3;     solve_nxt();     int sq = n / 3;     for (int i = sq + 1; i <= sq + sq; i++) {       int l = i;       int r = i;       int ans = 0;       for (int j = NN - 1; j >= 0; j--) {         pair<int, int> interval = tree[j].get_max(1, 1, n, l, r);         int newL = interval.first;         int newR = interval.second;         if (newR - newL + 1 < sq) {           l = newL;           r = newR;           ans += (1 << j);         }       }       cout << ans + 1 <<    ;     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   int main() {     ios::sync_with_stdio(false);     long long n;     cin >> n;     string s;     cin >> s;     if (s[0] == s[n - 1]) {       char a = s[0];       char b = s[n - 1];       long long x = 0, y = 0;       for (int i = 0; s[i] == a; i++) {         x++;       }       for (int i = n - 1; s[i] == b; i--) {         y++;       }       cout << ((x + 1) * (y + 1)) % mod;     } else {       char a = s[0];       char b = s[n - 1];       long long x = 0, y = 0;       for (int i = 0; s[i] == a; i++) {         x++;       }       for (int i = n - 1; s[i] == b; i--) {         y++;       }       cout << (x + y + 1) % mod;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int pow(long long int a, long long int b) {     long long int ans = 1;     while (b) {       if (b & 1) ans *= a;       a *= a;       b >>= 1;     }     return ans;   }   long long int powmod(long long int a, long long int b) {     long long int ans = 1;     while (b) {       if (b & 1) ans = (ans * a) % 10000000007;       a = (a * a) % 10000000007;       b >>= 1;     }     return ans;   }   bool ispal(string &a) {     for (int i = 0; i < a.size() / 2; i++)       if (a[i] != a[a.size() - i - 1]) return false;     return true;   }   unsigned long long int sum(unsigned long long int n) {     unsigned long long int x = 0;     while (n) {       x += n % 10;       n /= 10;     }     return x;   }   int main() {     {       ios_base::sync_with_stdio(false);       cin.tie(NULL);       cout.tie(NULL);     };     unsigned long long int n, m;     cin >> n >> m;     unsigned long long int ans = 0, p = 1;     for (int i = 0; i < m; i++) {       unsigned long long int x;       cin >> x;       ans += (p > x) ? n - p + x : x - p;       p = x;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 7;   struct node {     int x, d;   };   vector<int> adj[100005];   vector<int> good[105];   int vis[100005];   int a[100005];   int d[100005][105];   void bfs(int s) {     queue<node> q;     for (int i = 0; i < good[s].size(); i++) {       int v = good[s][i];       node tmp;       tmp.x = v;       tmp.d = 0;       q.push(tmp);     }     while (!q.empty()) {       node t = q.front();       q.pop();       d[t.x][s] = min(d[t.x][s], t.d);       for (int i = 0; i < adj[t.x].size(); i++) {         int v = adj[t.x][i];         if (vis[v] == 0) {           vis[v] = 1;           node tmp;           tmp.x = v;           tmp.d = t.d + 1;           q.push(tmp);         }       }     }   }   int main() {     int n, m, k, s, u, v;     scanf( %d%d%d%d , &n, &m, &k, &s);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       good[a[i]].push_back(i);     }     for (int i = 0; i < m; i++) {       scanf( %d%d , &u, &v);       adj[u].push_back(v);       adj[v].push_back(u);     }     fill(d[0], d[0] + 105 * 100005, inf);     for (int i = 1; i <= k; i++) {       memset(vis, 0, sizeof(vis));       bfs(i);     }     for (int i = 1; i <= n; i++) {       sort(d[i] + 1, d[i] + 1 + k);       long long sum = 0;       for (int j = 1; j <= s; j++) sum += d[i][j];       printf( %lld  , sum);     }     return 0;   }