malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, s, h, m, qh, qm, qhm, d;     cin >> n >> s;     qh = 0, qm = 0;     qhm = 0;     for (int i = 0; i < n; i++) {       cin >> h >> m;       d = h * 60 + m;       if (i == 0 && d >= s + 1) {         cout << 0 <<     << 0;         return 0;       }       if (d - qhm >= 2 * s + 2) {         qhm += s + 1;         cout << qhm / 60 <<     << qhm % 60;         return 0;       }       qhm = d;     }     qhm += s + 1;     cout << qhm / 60 <<     << qhm % 60;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); }   long long power(long long a, long long n) {     long long p = 1;     while (n > 0) {       if (n % 2) {         p = p * a;       }       n >>= 1;       a *= a;     }     return p;   }   const int maxN = 3000;   int dist[maxN + 10][maxN + 10], n, m, a, b, s[2], t[2], l[2], ans;   vector<int> e[maxN + 10];   void bfs(int u) {     memset(dist[u], -1, sizeof(dist[u]));     dist[u][u] = 0;     queue<int> q;     q.push(u);     while (!q.empty()) {       int x = q.front();       q.pop();       for (int i = 0; i < e[x].size(); i++) {         int y = e[x][i];         if (dist[u][y] == -1) {           dist[u][y] = dist[u][x] + 1;           q.push(y);         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> a >> b;       a--;       b--;       e[a].push_back(b);       e[b].push_back(a);     }     for (int i = 0; i < 2; i++) {       cin >> s[i] >> t[i] >> l[i];       s[i]--;       t[i]--;     }     for (int i = 0; i < n; i++) {       bfs(i);     }     if (dist[s[0]][t[0]] > l[0] || dist[s[1]][t[1]] > l[1]) return cout << -1, 0;     ans = dist[s[0]][t[0]] + dist[s[1]][t[1]];     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         int d1 = dist[s[0]][i] + dist[i][j] + dist[j][t[0]];         int d2 = dist[s[1]][i] + dist[i][j] + dist[j][t[1]];         if (d1 <= l[0] && d2 <= l[1]) {           ans = min(ans, d1 + d2 - dist[i][j]);         }         d2 = dist[t[1]][i] + dist[i][j] + dist[j][s[1]];         if (d1 <= l[0] && d2 <= l[1]) {           ans = min(ans, d1 + d2 - dist[i][j]);         }         d1 = dist[t[0]][i] + dist[i][j] + dist[j][s[0]];         if (d1 <= l[0] && d2 <= l[1]) {           ans = min(ans, d1 + d2 - dist[i][j]);         }         d2 = dist[s[1]][i] + dist[i][j] + dist[j][t[1]];         if (d1 <= l[0] && d2 <= l[1]) {           ans = min(ans, d1 + d2 - dist[i][j]);         }       }     }     cout << m - ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int maxn = 2e3 + 1;   const int maxm = 2e3 + 1;   char a[maxn], b[maxn];   int num[maxn];   int m, d;   long long dp[maxn][maxm];   int len;   int judge(const char* s, int lena) {     int mod = 0;     for (int i = 1; i <= lena; i++) {       mod = (mod * 10 + s[i]) % m;       if ((i & 1) == 0 && s[i] != d) {         return 0;       }       if ((i & 1) && s[i] == d) return 0;     }     return (mod == 0);   }   int val[maxn];   long long dfs(int pos, int mod, bool limit) {     if (pos == len + 1) {       return mod == 0;     }     if (!limit && dp[pos][mod] != -1) return dp[pos][mod];     int up = (limit ? num[pos] : 9);     long long res = 0;     for (int i = 0; i <= up; i++) {       int tmod = (mod * 10 + i) % m;       if ((pos & 1) && (i == d)) continue;       if (!(pos & 1) && (i != d)) continue;       res = (res + dfs(pos + 1, tmod, limit && i == up)) % MOD;     }     if (!limit) dp[pos][mod] = res;     return res;   }   long long solve(const char* s, int lena) {     for (int i = 1; i <= lena; i++) num[i] = s[i];     len = lena;     memset(dp, -1, sizeof(dp));     return dfs(1, 0, true) % MOD;   }   int main() {     cin >> m >> d;     cin >> (a + 1);     cin >> (b + 1);     int lena = strlen(a + 1), lenb = strlen(b + 1);     for (int i = 1; i <= lena; i++) a[i] -=  0 ;     for (int i = 1; i <= lenb; i++) b[i] -=  0 ;     cout << ((solve(b, lenb) - solve(a, lena) + judge(a, lena)) % MOD + MOD) % MOD          << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = LLONG_MAX;   struct minimum_cost_bipartite_matching {     int nl, nr;     long long mc = 0;     vector<int> ml, mr, ly;     minimum_cost_bipartite_matching(int nl, int nr, vector<vector<long long>> &c)         : nl(nl), nr(nr), ml(nl, -1), mr(nr, -1), ly(nr) {       vector<long long> s(nl), t(nr);       for (int i = 0; i < nl; i++) {         int x = i, y = -1;         vector<bool> u(nr);         vector<long long> md(nr, inf);         while (x != -1) {           long long ny = -1, d = inf;           for (int j = 0; j < nr; j++)             if (!u[j]) {               long long v = c[x][j] - s[x] - t[j];               if (v < md[j]) md[j] = v, ly[j] = y;               if (md[j] < d) d = md[j], ny = j;             }           s[i] += d;           mc += d;           for (int j = 0; j < nr; j++)             if (u[j])               s[mr[j]] += d, t[j] -= d;             else               md[j] -= d;           y = ny;           u[y] = true;           x = mr[y];         }         while (y != -1) {           mr[y] = ly[y] != -1 ? mr[ly[y]] : i;           ml[mr[y]] = y;           y = ly[y];         }       }     }   };   int charToInt(char c) { return c >=  a  && c <=  z  ? c -  a  : c -  A  + 26; }   char intToChar(int c) { return c < 26 ?  a  + c :  A  + c - 26; }   int main() {     int n, k;     cin >> n >> k;     string s[2];     cin >> s[0] >> s[1];     vector<vector<long long>> c(k, vector<long long>(k));     for (int i = 0; i < n; i++) c[charToInt(s[0][i])][charToInt(s[1][i])]--;     minimum_cost_bipartite_matching mcbm(k, k, c);     cout << -mcbm.mc <<   n ;     for (int i = 0; i < k; i++) cout << intToChar(mcbm.ml[i]);     cout <<   n ;   }
#include <bits/stdc++.h>   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( O8 )   #pragma GCC optimization( unroll-loops )   using namespace std;   const long long int N = 4e6 + 20, mod = 1e9 + 7, inf = 1e9, dlt = 12250,                       maxm = 2e6;   int poww(long long a, int k) {     if (!k) return 1;     if (k == 1) return a;     long long r = poww(a, k / 2);     return (((r * r) % mod) * poww(a, k & 1)) % mod;   }   int trie[N][3], cnt;   long long a[N / 10];   void build(string s) {     int p = 0;     string t =   ;     for (char ch : s) {       int u = ch -  0 ;       t += ch;       if (!trie[p][u]) {         cnt++;         trie[p][u] = cnt;       }       p = trie[p][u];     }   }   long long que(long long x) {     int p = 0, h = 0;     long long y = 0;     for (int i = 0; i < 40; i++) {       if (!trie[p][0] && !trie[p][1]) return y;       bool f = (!(x & (1ll << (39 - i))));       if (!trie[p][0] || (trie[p][1] && f)) {         if (f) y += (1ll << (39 - i));         p = trie[p][1];         continue;       }       if (!f) y += (1ll << (39 - i));       p = trie[p][0];     }     return y;   }   int main() {     ios ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     long long x = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       x ^= a[i];     }     long long ans = x;     string st =   ;     for (int i = 0; i < 40; i++) st +=  0 ;     build(st);     long long y = 0;     for (int i = 0; i < n; i++) {       x ^= a[i];       y ^= a[i];       string s =   ;       for (int j = 0; j < 40; j++) {         if (y & (1ll << j))           s =  1  + s;         else           s =  0  + s;       }       build(s);       ans = max(que(x), ans);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::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...);   }   int main() {     long long a, b;     scanf( %lld , &a);     scanf( %lld , &b);     while (a > 0 && b > 0 && (a >= 2 * b || b >= 2 * a))       if (a >= 2 * b)         a %= 2 * b;       else         b %= 2 * a;     printf( %lld %lld n , a, b);   }
#include <bits/stdc++.h>   using namespace std;   void boost() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   const long long mod = 1000000007;   int tablica[2];   long long potega(long long base, long long pot) {     if (pot == 0) return 1;     if (pot == 1) return base;     if (pot % 2 == 0) {       long long res = potega(base, pot / 2);       return ((res * res) % mod);     } else       return ((potega(base, pot - 1) * base) % mod);   }   int bs(int pocz, int kon, int szu) {     int sr;     while (pocz < kon) {       sr = (pocz + kon) / 2;       if (tablica[sr] >= szu)         kon = sr;       else         pocz = sr + 1;     }     return pocz;   }   int n, k, a[1007], ile;   void reset_arrays() { ile = 0; }   void solve() {     reset_arrays();     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     sort(a, a + n);     for (int i = 1; i < n; i++) {       int pom = (k - a[i]) / a[0];       ile += pom;     }     printf( %d n , ile);   }   int main() {     int t = 1;     scanf( %d , &t);     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m;     scanf( %lld%lld , &n, &m);     long long t = m / 2;     if (t >= n) {       printf( 0 n );     } else {       if (m % 2 == 1) {         printf( %lld n , min(t, n - (t + 1) + 1));       } else {         printf( %lld n , min(t - 1, n - (t + 1) + 1));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long M = 3e4 + 1;   long long n, m, d;   const long long K = 3e4 + 5;   const long long huge = 1e15;   long long dp[K][500];   long long a[K], ps[K];   long long solve(long long i, long long j) {     if (i >= M) return 0;     long long jj = j - (d - 250);     if (dp[i][jj] != -1) return dp[i][jj];     long long ans = 0;     if (j != 1)       ans = a[i] + max(solve(i + j, j),                        max(solve(i + j + 1, j + 1), solve(i + j - 1, j - 1)));     else       ans = a[i] + max(solve(i + j, j), solve(i + j + 1, j + 1));     return dp[i][jj] = ans;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     ;     cin >> n;     cin >> d;     while (n--) {       cin >> m;       a[m]++;     }     memset(dp, -1, sizeof dp);     cout << a[0] + solve(d, d);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int n = s.length();     for (int i = 1; i < n - 1; i++)       if (s[i] == s[i - 1] && s[i] == s[i + 1]) {         if (s[i] ==  a )           s[i] =  b ;         else           s[i] =  a ;       }     for (int i = 1; i < n; i++)       if (s[i] == s[i - 1]) {         if (s[i] ==  a ) {           if (i != n - 1 && s[i + 1] !=  b )             s[i] =  b ;           else             s[i] =  c ;         } else if (s[i + 1] !=  a )           s[i] =  a ;         else if (s[i] !=  b )           s[i] =  b ;         else           s[i] =  c ;       }     cout << s;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int main() {     cin >> n >> m;     if (n == 1) {       cout << 1;       exit(0);     }     cout << fixed << setprecision(12)          << 1.0 / n + (1.0 * (n - 1)) / n * (1.0 * (m - 1)) / (m * n - 1);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<pair<int, int> > p;     int a[n + 1], b[n + 1];     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) cin >> b[i];     for (int i = 1; i <= n; i++) {       if (a[i] != b[i]) {         for (int j = i + 1; j <= n; j++) {           if (a[i] == b[j]) {             for (int k = j; k > i; k--) {               p.push_back(make_pair(k - 1, k));               swap(b[k], b[k - 1]);             }             break;           }         }       }     }     cout << p.size() << endl;     for (int i = 0; i < p.size(); i++)       cout << p[i].first <<     << p[i].second << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a[1002], b[1002], n, m;     while (cin >> n >> m) {       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 0; i < n; i++) cin >> b[i];       double be = m;       bool flag = 0;       for (int i = n - 1; i >= 0; i--) {         be = be * b[(i + 1) % n] / (b[(i + 1) % n] - 1);         if (be > 1000000000) {           flag = 1;           break;         }         be = be * a[i] / (a[i] - 1);       }       if (flag)         cout << -1 << endl;       else         cout << fixed << setprecision(10) << be - m << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int power(long long int a, long long int b) {     a %= 1000000007;     long long int res = 1;     while (b > 0) {       if (b & 1) res = res * a % 1000000007;       a = a * a % 1000000007;       b >>= 1;     }     return res;   }   long long int modinv(long long int p) { return power(p, 1000000007 - 2); }   vector<long long int> arr[200000];   long long int dp[100005][2] = {0};   void dfs(long long int s, long long int p, long long int a[]) {     if (a[s] == 0) {       long long int su = 1;       dp[s][1] = 0;       for (auto it : arr[s]) {         if (it != p) {           dfs(it, s, a);           su *= (dp[it][0] + dp[it][1]);           su %= 1000000007;         }       }       dp[s][0] = su % 1000000007;       for (auto it : arr[s]) {         if (it != p) {           if (dp[it][0] + dp[it][1] > 0) {             dp[s][1] += (dp[it][1] *                          ((su * modinv(dp[it][0] + dp[it][1])) % 1000000007)) %                         1000000007;             dp[s][1] %= 1000000007;           }         }       }     } else {       dp[s][0] = 0;       dp[s][1] = 1;       for (auto it : arr[s]) {         if (it != p) {           dfs(it, s, a);           dp[s][1] *= (dp[it][0] + dp[it][1]) % 1000000007;           dp[s][1] %= 1000000007;         }       }     }   }   int main() {     long long int n;     cin >> n;     long long int q;     for (long long int x = 1; x < n; x++) {       cin >> q;       arr[q].push_back(x);       arr[x].push_back(q);     }     long long int a[n];     for (int x = 0; x < n; x++) {       cin >> a[x];     }     dfs(0, -1, a);     cout << dp[0][1] % 1000000007 <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const double one = 1.0;   const double PI = 3.14159265;   const long long maxn = 2e3 + 10;   const long long maxx = 1e6 + 10;   const long double eps = 1e-14;   const long long max_len = 1e6 + 1;   const long long mod1 = 1000000007;   const long long mod2 = 998244353;   long long dp[maxn][maxn];   void solve() {     long long n, k;     cin >> n >> k;     vector<long long> vl(n + 2);     for (long long i = 1; i < long long(n + 1); i++) cin >> vl[i];     for (long long i = 0; i < long long(n + 1); i++) {       for (long long j = 0; j < long long(n + 1); j++) dp[i][j] = 0;     }     for (long long i = 1; i < long long(n + 1); i++) {       for (long long j = 0; j < long long(i + 1); j++) {         dp[i][j] = max(dp[i][j], dp[i - 1][j] + (i - j == vl[i]));         if (j > 0) dp[i][j] = max(dp[i - 1][j - 1], dp[i][j]);       }     }     long long ans = 1000000000000000000;     for (long long j = 0; j < long long(n + 1); j++) {       if (dp[n][j] >= k) ans = min(ans, j);     }     if (ans >= 1000000000000000000) ans = -1;     cout << ans << endl;     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cerr.tie(0);     long long t;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   int a, b, k;   int main() {     scanf( %d%d%d , &b, &a, &k);     if (b + k < a) {       printf( %.12f n , 0.0f);       return 0;     }     double ans = 1;     for (int i = 0; i <= k; i++) {       ans *= (a - i);       ans /= (b + 1 + i);     }     ans = 1 - ans;     printf( %.12f n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int SZ = (int)3e7 + 10;   int cnt[SZ];   int n[3], t[3], sum[3];   int main() {     int k;     cin >> k;     for (int i = 0; i < 3; i++) cin >> n[i];     for (int i = 0; i < 3; i++) cin >> t[i];     for (int i = 0; i < 3; i++) sum[i] = 0;     for (int tme = 0;; tme++) {       int mn = k;       for (int s = 0; s < 3; s++) {         mn = min(mn, n[s] - sum[s]);       }       cnt[tme] = mn;       k -= mn;       if (k == 0) {         printf( %d , tme + t[0] + t[1] + t[2]);         return 0;       }       for (int s = 0; s < 3; s++) {         sum[s] += mn;         if (tme - t[s] + 1 >= 0) sum[s] -= cnt[tme - t[s] + 1];       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, k;   long double ans, eps = 1e-10, l, v1, v2;   bool solve(long double mid) {     int x = (n + k - 1) / k;     long double tl = mid, pos = l;     while (x--) {       if (tl < 0) return 0;       long double trav = (v2 * v1 * tl - v2 * pos) / (v1 - v2);       if (trav > pos) return 0;       long double oldTime = tl;       tl -= trav / v2 + (trav - v1 * trav / v2) / (v1 + v2);       pos -= v1 * (oldTime - tl);     }     return 1;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> l >> v1 >> v2 >> k;     double long hi = 1e10, lo = 0;     while (hi - lo >= eps) {       long double mid = (hi + lo) / 2;       if (solve(mid)) {         ans = mid;         hi = mid - eps;       } else         lo = mid + eps;     }     cout << setprecision(12) << ans;     solve(ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3010;   const int MOD = 1000000007;   int n, m;   long long f[MAXN][MAXN], ans1, ans2, ans3, ans4;   char a[MAXN][MAXN];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %s , a[i] + 1);     if (a[1][2] ==  . ) f[1][2] = 1;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         if (i == 1 && j == 2) continue;         if (a[i][j] ==  . ) f[i][j] = (f[i - 1][j] + f[i][j - 1]) % MOD;       }     ans1 = f[n - 1][m];     memset(f, 0, sizeof(f));     if (a[2][1] ==  . ) f[2][1] = 1;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         if (i == 2 && j == 1) continue;         if (a[i][j] ==  . ) f[i][j] = (f[i - 1][j] + f[i][j - 1]) % MOD;       }     ans2 = f[n][m - 1];     memset(f, 0, sizeof(f));     if (a[1][2] ==  . ) f[1][2] = 1;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         if (i == 1 && j == 2) continue;         if (a[i][j] ==  . ) f[i][j] = (f[i - 1][j] + f[i][j - 1]) % MOD;       }     ans3 = f[n][m - 1];     memset(f, 0, sizeof(f));     if (a[2][1] ==  . ) f[2][1] = 1;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         if (i == 2 && j == 1) continue;         if (a[i][j] ==  . ) f[i][j] = (f[i - 1][j] + f[i][j - 1]) % MOD;       }     ans4 = f[n - 1][m];     memset(f, 0, sizeof(f));     printf( %I64d n , ((ans1 * ans2) % MOD - (ans3 * ans4) % MOD + MOD) % MOD);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[212345], s1[212345], s2[212345], pos1[212345], pos2[212345], n;   vector<pair<int, int> > res;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) {       s1[i] = s1[i - 1] + (a[i] == 1);       s2[i] = s2[i - 1] + (a[i] == 2);     }     for (int i = n; i >= 1; i--) {       pos1[s1[i]] = i;       pos2[s2[i]] = i;     }     for (int i = 1; i <= n; i++) pos1[s1[n] + i] = pos2[s2[n] + i] = n + 1;     for (int t = 1; t <= n; t++) {       int curPos = 0;       int win1 = 0;       int win2 = 0;       while (curPos < n) {         curPos = min(pos1[s1[curPos] + t], pos2[s2[curPos] + t]);         if (curPos <= n) {           if (a[curPos] == 1)             win1++;           else             win2++;         }       }       if (curPos == n && win1 != win2 && ((win1 > win2) == (a[curPos] == 1)))         res.push_back(make_pair(max(win1, win2), t));     }     sort(res.begin(), res.end());     cout << (int)res.size() << endl;     for (int i = 0; i < (int)res.size(); i++)       cout << res[i].first <<     << res[i].second << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   namespace FGF {   const int N = 1e5 + 5, mo = 1e9 + 7, inv2 = (mo + 1) / 2;   int a[N], b[N], pre[N], lst[N], nxt[N], sum[N << 2][4], ta[N << 2][2], n, st[N],       tp, mi[N], mx[N], ans, cnt[N];   void pushtag(int ro, int l, int r, int x, int o) {     sum[ro][3] = 1ll * x * sum[ro][o ^ 1] % mo;     sum[ro][o] = 1ll * (r - l + 1) * x % mo;     ta[ro][o] = x;     if (!o) sum[ro][2] = 1ll * (r + l) * (r - l + 1) % mo * inv2 % mo * x % mo;   }   void pushdown(int ro, int l, int r) {     for (int i = 0; i <= 1; i++)       if (ta[ro][i])         pushtag(ro << 1, l, ((l + r) >> 1), ta[ro][i], i),             pushtag(ro << 1 | 1, ((l + r) >> 1) + 1, r, ta[ro][i], i),             ta[ro][i] = 0;   }   void pushup(int ro) {     for (int i = 0; i < 4; i++)       sum[ro][i] = (sum[ro << 1][i] + sum[ro << 1 | 1][i]) % mo;   }   void updat(int ro, int l, int r, int L, int R, int x, int o) {     if (L <= l && r <= R) return pushtag(ro, l, r, x, o);     pushdown(ro, l, r);     if (L <= ((l + r) >> 1)) updat(ro << 1, l, ((l + r) >> 1), L, R, x, o);     if (R > ((l + r) >> 1)) updat(ro << 1 | 1, ((l + r) >> 1) + 1, r, L, R, x, o);     pushup(ro);   }   int query(int ro, int l, int r, int L, int R, int o) {     if (L <= l && r <= R) return sum[ro][o];     pushdown(ro, l, r);     return ((L <= ((l + r) >> 1) ? query(ro << 1, l, ((l + r) >> 1), L, R, o)                                  : 0) +             (R > ((l + r) >> 1)                  ? query(ro << 1 | 1, ((l + r) >> 1) + 1, r, L, R, o)                  : 0)) %            mo;   }   void work() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), b[i] = a[i];     sort(b + 1, b + n + 1);     for (int i = 1; i <= n; i++) a[i] = lower_bound(b + 1, b + n + 1, a[i]) - b;     for (int i = 1; i <= n; i++) pre[i] = lst[a[i]] + 1, lst[a[i]] = i;     for (int i = n; i; i--) lst[i] = n + 1;     for (int i = n; i; i--) nxt[i] = lst[a[i]] - 1, lst[a[i]] = i;     for (int i = n; i; i--) {       while (tp && pre[i] > pre[st[tp]]) tp--;       mx[i] = tp ? st[tp] - 1 : n, st[++tp] = i;     }     tp = 0;     for (int i = n; i; i--) {       while (tp && nxt[i] < nxt[st[tp]]) tp--;       mi[i] = tp ? st[tp] - 1 : n, st[++tp] = i;     }     for (int i = n, j = n; i; i--) {       updat(1, 1, n, i, mx[i], pre[i], 0), updat(1, 1, n, i, mi[i], nxt[i], 1);       cnt[a[i]]++;       while (cnt[a[i]] > 1) cnt[a[j]]--, j--;       ans = (ans + 1ll * i * query(1, 1, n, i, j, 1) % mo +              query(1, 1, n, i, j, 2) -              1ll * i * (i + j) % mo * (j - i + 1) % mo * inv2 % mo -              query(1, 1, n, i, j, 3)) %             mo;     }     printf( %d n , (ans + mo) % mo);   }   }  // namespace FGF   int main() {     FGF::work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const double PI = 3.14159265;   const double E = 2.718281828459;   const double EPS = 1e-8;   const int M = 2e5 + 5;   long long n, A;   long long a[M];   int main() {     while (~scanf( %I64d %I64d , &n, &A)) {       long long sumb = 0;       for (int i = 0; i < n; i++) {         scanf( %I64d , a + i);         sumb += a[i];       }       long long minb = n - 1;       bool first = true;       for (int i = 0; i < n; i++) {         long long cnt = 0;         long long x = A - minb;         if (a[i] > x) cnt += a[i] - x;         long long y = A - (sumb - a[i]);         if (y > 0) cnt += y - 1;         if (first) {           printf( %I64d , cnt);           first = false;         } else           printf(  %I64d , cnt);       }       printf(  n );     }   }