malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long p = 1234567, q = 123456, r = 1234, n;     cin >> n;     long long x = n;     for (int a = 0; a <= n; a += 1234567)       for (int b = 0; b <= n - a; b += 123456) {         if ((n - a - b) % 1234 == 0) {           cout <<  YES ;           return 0;         }       }     cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m;     cin >> n >> m;     if (n > m) swap(n, m);     if (n == 2) {       if (m % 4 == 0)         cout << m;       else if (m % 4 == 1)         cout << m + 1;       else         cout << (m / 4) * 4 + 4;     } else if ((m < 2) || (n < 2) || ((m == 2) && (n == 2)))       cout << n * m << endl;     else       cout << (n * m + 1) / 2;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ask(string s) {     cout <<  ?   << s << endl;     fflush(stdout);     int x;     cin >> x;     return x;   }   int main() {     int n;     scanf( %d , &n);     string s(n,  0 );     int c = ask(s);     s[0] =  1 ;     int a0;     int d = ask(s);     int pos1 = -1, pos0 = -1;     int zo = 0;     if (d < c) {       pos1 = 0;       zo = 1;     } else {       pos0 = 0;     }     if (zo == 1) {       a0 = ask(string(n,  1 ));     } else {       a0 = c;     }     int le(0), ri(n - 2);     while (le != ri) {       string s;       int mid((le + ri + 1) / 2);       for (int i(0); i <= mid; i++) s.push_back( 1  ^ zo);       for (int i(mid + 1); i < n; i++) s.push_back( 0  ^ zo);       if (ask(s) == a0 + mid + 1) {         le = mid;       } else {         ri = mid - 1;       }     }     if (pos1 == -1)       pos1 = le + 1;     else       pos0 = le + 1;     printf( ! %d %d n , 1 + pos0, 1 + pos1);     fflush(stdout);   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   long long dp[100005][2];   string a, b;   int main() {     int K;     while (cin >> a >> b) {       cin >> K;       memset(dp, 0, sizeof(dp));       if (a == b)         dp[0][1] = 1;       else         dp[0][0] = 1;       int cnt = 0, l = a.length();       a = a + a;       for (int i = 0; i < l; i++)         if (a.compare(i, l, b) == 0) cnt++;       for (int i = 1; i <= K; i++) {         dp[i][1] = (dp[i - 1][1] * (cnt - 1) + dp[i - 1][0] * cnt) % mod;         dp[i][0] =             (dp[i - 1][1] * (l - cnt) + dp[i - 1][0] * (l - cnt - 1)) % mod;       }       cout << dp[K][1] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> g[100010];   int us[100010], w[3][100010], z1, z2, dooc;   void dfs(int v, int in = 1) {     us[v] = in;     for (int i = 0; i < g[v].size(); i++)       if (us[g[v][i]] == 0) {         dfs(g[v][i], (in == 1 ? 2 : 1));       } else if (us[g[v][i]] == in) {         dooc = -1;       }   }   int main() {     int n, m, u, v, i;     cin >> n >> m;     while (m--) {       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     for (i = 1; i <= n; i++)       if (!us[i]) dfs(i);     if (dooc == -1) {       cout << -1;       return 0;     }     for (i = 1; i <= n; i++) {       if (us[i] == 1) w[1][++z1] = i;       if (us[i] == 2) w[2][++z2] = i;     }     cout << z1 <<   n ;     for (i = 1; i <= z1; i++) cout << w[1][i] <<    ;     cout <<   n  << z2 <<   n ;     for (i = 1; i <= z2; i++) cout << w[2][i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int r = 0, u = 0;     string s;     cin >> s;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  L )         r--;       else if (s[i] ==  R )         r++;       else if (s[i] ==  U )         u++;       else if (s[i] ==  D )         u--;     }     r *= r < 0 ? -1 : 1;     u *= u < 0 ? -1 : 1;     if ((r + u) % 2 == 0)       cout << (r + u) / 2;     else       cout << -1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1005, MAXM = 3e4 + 5;   int N, M, s, t;   int cost[MAXM], low[MAXN], disc[MAXN];   bool vis[MAXN];   vector<int> edges, bridge, ANS;   vector<pair<int, int> > adj[MAXN];   void read() {     scanf( %d %d , &N, &M);     scanf( %d %d , &s, &t);     for (int i = 1; i <= M; i++) {       int u, v, c;       scanf( %d %d %d , &u, &v, &c);       adj[u].push_back(make_pair(v, i));       adj[v].push_back(make_pair(u, i));       cost[i] = c;     }   }   bool dfs(int pos) {     if (pos == t) return true;     vis[pos] = true;     for (pair<int, int> next : adj[pos]) {       if (!vis[next.first] && dfs(next.first)) {         edges.push_back(next.second);         return true;       }     }     return false;   }   bool canReach(int pos, int posID, int forbidEdge) {     static int time = 0;     vis[pos] = true;     low[pos] = disc[pos] = ++time;     bool res = false;     if (pos == t) res = true;     for (pair<int, int> next : adj[pos]) {       if (next.second == forbidEdge || next.second == posID) continue;       if (vis[next.first])         low[pos] = min(low[pos], disc[next.first]);       else {         bool flag = canReach(next.first, next.second, forbidEdge);         if (flag) res = true;         low[pos] = min(low[pos], low[next.first]);         if (low[next.first] > disc[pos] && flag) bridge.push_back(next.second);       }     }     return res;   }   void solve() {     memset(vis, false, sizeof(vis));     if (!dfs(s)) {       printf( 0 n0 n );       return;     }     int res = INT_MAX;     for (int forbidEdge : edges) {       bridge.clear();       memset(vis, false, sizeof(vis));       if (!canReach(s, -1, forbidEdge)) {         if (cost[forbidEdge] < res) {           res = cost[forbidEdge];           ANS = {forbidEdge};         }       }       for (int edge : bridge) {         if (cost[forbidEdge] + cost[edge] < res) {           res = cost[forbidEdge] + cost[edge];           ANS = {forbidEdge, edge};         }       }     }     if (res == INT_MAX) {       printf( -1 n );       return;     }     printf( %d n%d n , res, ANS.size());     for (int i = 0; i < ANS.size(); i++) {       printf( %d%c , ANS[i], i == ANS.size() - 1 ?   n  :    );     }   }   int main() {     read();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long M;   const int N_MAX = 2;   template <class T>   void mul(int n, const T A[N_MAX][N_MAX], const T x[N_MAX], T y[N_MAX]) {     static T z[N_MAX];     for (int i = 0; i < (n); i++) {       z[i] = 0;       for (int j = 0; j < (n); j++) z[i] = (z[i] + A[i][j] * x[j]) % M;     }     for (int i = 0; i < (n); i++) y[i] = z[i];   }   template <class T>   void mul(int n, const T A[N_MAX][N_MAX], const T B[N_MAX][N_MAX],            T C[N_MAX][N_MAX]) {     static T tmp[N_MAX][N_MAX];     for (int i = 0; i < (n); i++)       for (int j = 0; j < (n); j++) {         tmp[i][j] = 0;         for (int k = 0; k < (n); k++)           tmp[i][j] = (tmp[i][j] + A[i][k] * B[k][j]) % M;       }     for (int i = 0; i < (n); i++)       for (int j = 0; j < (n); j++) C[i][j] = tmp[i][j];   }   template <class T>   void pow(int n, const T A[N_MAX][N_MAX], long long m, T B[N_MAX][N_MAX]) {     static T tmp[N_MAX][N_MAX];     for (int i = 0; i < (n); i++)       for (int j = 0; j < (n); j++) {         tmp[i][j] = A[i][j];         B[i][j] = (i == j ? 1 : 0);       }     for (int t = 0; m > 0; t++) {       if (m & (1LL << t)) {         mul(n, B, tmp, B);         m -= 1LL << t;       }       mul(n, tmp, tmp, tmp);     }   }   long long fib(long long n) {     long long A[2][2] = {{1, 1}, {1, 0}}, x[2] = {1, 0};     pow(2, A, n - 1, A);     mul(2, A, x, x);     return x[0];   }   int main() {     long long l, r, k;     cin >> M >> l >> r >> k;     vector<long long> cand;     for (long long i = 1; i * i <= r; i++) {       cand.push_back(i);       for (int j = -1; j <= 1; j++) {         cand.push_back(l / i + j);         cand.push_back(r / i + j);       }     }     long long idx = 1;     for (int i = 0; i < (cand.size()); i++) {       long long a = cand[i];       if (a > 0 && r / a - (l - 1) / a >= k) idx = max(idx, a);     }     cout << fib(idx) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   map<long long, long long> mp;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long n, m;     cin >> n;     vector<long long> v(n);     for (int i = 0; i < n; ++i) {       cin >> v[i];       if (mp.find(v[i]) == mp.end())         mp[v[i]] = 1;       else         mp[v[i]]++;     }     cin >> m;     vector<long long> a(m), b(m);     for (int i = 0; i < m; ++i) cin >> a[i];     for (int i = 0; i < m; ++i) cin >> b[i];     vector<pair<long long, pair<long long, long long> > > vp;     for (int i = 0; i < m; ++i) {       vp.push_back({mp[a[i]], {mp[b[i]], i}});     }     sort(vp.begin(), vp.end());     int ans = vp.size() - 1;     while (ans > 0 && vp[ans].first == vp[ans - 1].first &&            vp[ans].second.first == vp[ans - 1].second.first)       ans--;     cout << vp[ans].second.second + 1 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e6 + 5;   const int mod = 1e9 + 7;   int n, k;   long long a[maxn];   template <class T>   inline void read(T &res) {     res = 0;     T f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       res = res * 10 + c -  0 ;       c = getchar();     }     res *= f;   }   long long cal(int n) { return a[n]; }   int nn = 4, mm = 12;   long long call(int i) {     if (i % 3) return (a[i - 1] + 2 * a[i - 2]) % mod;     return (a[i - 1] + 2 * a[i - 2] + 4) % mod;   }   void init() {     a[3] = a[4] = nn;     a[5] = mm;     for (int i = 6; i <= maxn; ++i) {       a[i] = call(i);     }   }   int main() {     int qwq;     init();     read(qwq);     while (qwq--) {       read(n);       long long ans = cal(n);       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Problem {     long long as, at, bs, bt;     double pr;   } a[2000];   const long long P = (long long)1e6;   int n, m;   long long fail[1001];   long long f[1001][1600];   double g[1001][1600];   bool cmp(Problem u, Problem v) {     return u.bt * u.pr * (1 - v.pr) < v.bt * v.pr * (1 - u.pr);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++)       scanf( %I64d%I64d%I64d%I64d%lf , &a[i].as, &a[i].bs, &a[i].at, &a[i].bt,             &a[i].pr);     sort(a + 1, a + n + 1, cmp);     for (int i = 1; i <= n; i++) fail[i] = (long long)(a[i].pr * P + 0.5);     for (int i = 0; i <= n; i++)       for (int j = 0; j <= m; j++) f[i][j] = -1;     f[0][0] = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j <= m; j++)         if (f[i][j] != -1) {           int t = i + 1;           if (f[i + 1][j] < f[i][j] ||               (f[i + 1][j] == f[i][j] && g[i + 1][j] > g[i][j])) {             f[i + 1][j] = f[i][j];             g[i + 1][j] = g[i][j];           }           if (j + a[t].at <= m) {             long long t1 = f[i][j] + a[t].as * P;             double p1 = g[i][j] + a[t].at;             int j1 = j + a[t].at;             if (f[i + 1][j1] < t1 || (f[i + 1][j1] == t1 && g[i + 1][j1] > p1)) {               f[i + 1][j1] = t1;               g[i + 1][j1] = p1;             }           }           if (j + a[t].at + a[t].bt <= m) {             long long t1 = f[i][j] + a[t].as * P + a[t].bs * (P - fail[t]);             double p1 =                 g[i][j] * a[t].pr + a[t].at + (j + a[t].bt) * (1 - a[t].pr);             int j1 = j + a[t].at + a[t].bt;             if (f[i + 1][j1] < t1 || (f[i + 1][j1] == t1 && g[i + 1][j1] > p1)) {               f[i + 1][j1] = t1;               g[i + 1][j1] = p1;             }           }         }     long long ans1 = -1;     double ans2 = 0;     for (int i = 0; i <= m; i++)       if (ans1 < f[n][i] || (ans1 == f[n][i] && g[n][i] < ans2))         ans1 = f[n][i], ans2 = g[n][i];     printf( %.9lf %.9lf n , (double)ans1 / (double)P, ans2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 300;   const double eps = 1e-9;   int px[MAXN], py[MAXN];   int ans[1000100];   int n, m;   int main() {     while (scanf( %d%d , &n, &m) != EOF) {       for (int i = 0; i < m; ++i) scanf( %d%d , px + i, py + i);       memset(ans, 0, sizeof(ans));       for (int i = 0; i < m; ++i)         for (int j = 0; j < m; ++j) {           double dx = px[j] - px[i];           double dy = py[j] - py[i];           if (abs(dy) < eps) continue;           double axi;           if (abs(dx) < eps)             axi = px[i];           else             axi = (-py[i] * dx) / dy + px[i];           if (abs(axi - (int)axi) > eps || (int)axi > n || (int)axi < 1) continue;           int cnt = 0;           for (int k = 0; k < m; ++k) {             if (k == i || k == j) continue;             if (dy * (px[k] - px[i]) == (py[k] - py[i]) * dx) ++cnt;           }           ans[(int)axi] = max(ans[(int)axi], cnt + 2);         }       int sum(0);       for (int i = 1; i <= n; ++i) {         sum += max(1, ans[i]);       }       printf( %d n , sum);     }     return 0;   }
#include <bits/stdc++.h>   template <typename tp>   inline tp max(tp x, tp y) {     return x > y ? x : y;   }   template <typename tp>   inline tp min(tp x, tp y) {     return x < y ? x : y;   }   template <typename tp>   inline bool chkmax(tp& x, tp y) {     return (x >= y) ? false : (x = y, true);   }   template <typename tp>   inline bool chkmin(tp& x, tp y) {     return (x <= y) ? false : (x = y, true);   }   static const int len = 1 << 20 | 1;   char buffer[len], *Ser, *Ter;   inline char Getchar() {     if (Ser == Ter) Ter = (Ser = buffer) + fread(buffer, 1, len, stdin);     return (Ser == Ter) ? (char)EOF : (*Ser++);   }   template <typename tp>   inline tp scanf(tp& in) {     in = 0;     char ch = getchar();     tp f = 1;     for (; ch >  9  || ch <  0 ; ch = getchar())       if (ch ==  - ) f = -1;     for (; ch >=  0  && ch <=  9 ; ch = getchar()) in = in * 10 + ch -  0 ;     return in *= f;   }   static const int max1 = 1e5 + 11;   static const int max2 = 2e5 + 11;   int n;   int k;   int q;   long long ans;   int ti[max1];   int ai[max1];   long long sum[max1];   long long tot[max1];   int dt;   long long dir[max2];   int cnt1[max2];   int cnt2[max2];   long long output[max1];   class query {    public:     int l;     int r;     int bel;     int id;     bool operator<(const query& t) const {       if (bel ^ t.bel) return bel < t.bel;       if (r ^ t.r) return r < t.r;       return l < t.l;     }   } qi[max1];   int main() {     scanf(n);     scanf(k);     for (int i = (1), ir = (n); i <= (ir); ++i) scanf(ti[i]);     for (int i = (1), ir = (n); i <= (ir); ++i)       ai[i] = scanf(ai[i]) * ((ti[i] == 1) ? 1 : -1);     int N = sqrt(n);     scanf(q);     for (int i = (1), ir = (q); i <= (ir); ++i)       scanf(qi[i].l), scanf(qi[i].r), qi[i].id = i, qi[i].bel = qi[i].l / N;     std ::sort(1 + qi, 1 + q + qi);     for (int i = (1), ir = (n); i <= (ir); ++i)       dir[++dt] = sum[i] = sum[i - 1] + ai[i],       dir[++dt] = tot[i] = sum[i - 1] + k;     std ::sort(1 + dir, 1 + dt + dir);     dt = std ::unique(1 + dir, 1 + dt + dir) - dir - 1;     for (int i = (1), ir = (n); i <= (ir); ++i)       sum[i] = std ::lower_bound(1 + dir, 1 + dt + dir, sum[i]) - dir,       tot[i] = std ::lower_bound(1 + dir, 1 + dt + dir, tot[i]) - dir;     int l = 1, r = 0;     for (int i = (1), ir = (q); i <= (ir); ++i) {       int L = qi[i].l, R = qi[i].r;       while (r < R) ++r, ++cnt1[sum[r]], ++cnt2[tot[r]], ans += cnt2[sum[r]];       while (r > R) ans -= cnt2[sum[r]], --cnt1[sum[r]], --cnt2[tot[r]], --r;       while (l < L) ans -= cnt1[tot[l]], --cnt1[sum[l]], --cnt2[tot[l]], ++l;       while (l > L) --l, ++cnt1[sum[l]], ++cnt2[tot[l]], ans += cnt1[tot[l]];       output[qi[i].id] = ans;     }     for (int i = (1), ir = (q); i <= (ir); ++i) printf( %lld n , output[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, p, t[100100], tree[100100];   queue<int> q;   set<int> waiting;   long long curT, ans[100100];   int get(int x) {     for (int i = x; i; i -= i & -i)       if (tree[i]) return 1;     return 0;   }   void add(int x, int v) {     for (int i = x; i <= 100000; i += i & -i) tree[i] += v;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     vector<pair<int, int>> a;     cin >> n >> p;     for (int i = 0; i < n; i++) {       cin >> t[i];       a.push_back({t[i], i});     }     sort(a.begin(), a.end());     int i = 0;     while (1)       if (!q.empty()) {         int x = q.front();         q.pop();         curT += p;         ans[x] = curT;         while (i < n && a[i].first < curT) {           int y = a[i++].second;           if (get(y))             waiting.insert(y);           else {             q.push(y);             add(y + 1, 1);           }         }         add(x + 1, -1);         while (i < n && a[i].first == curT) waiting.insert(a[i++].second);         if (waiting.empty()) continue;         int y = *waiting.begin();         if (get(y)) {           auto it = waiting.lower_bound(x);           if (it == waiting.end()) continue;           y = *it;           if (get(y)) continue;         }         q.push(y);         add(y + 1, 1);         waiting.erase(y);       } else {         if (i == n) break;         int x = a[i++].second;         q.push(x);         curT = t[x];         add(x + 1, 1);       }     for (int i = 0; i < n; i++) cout << ans[i] <<    n [i == n - 1];   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, i, j, ans, tmp, t, curr, x, r, sm, k, l;   long long arr[1000005], res[1000005], par1[1000005], par2[1000005];   string s;   vector<long long> vec[1000005];   void dfs(long long idx, long long par, long long col) {     if (col != arr[idx]) {       ans++;       col = arr[idx];     }     for (long long i = 0; i < vec[idx].size(); i++) {       if (vec[idx][i] == par) continue;       dfs(vec[idx][i], idx, col);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     for (i = 2; i <= n; i++) {       cin >> x;       vec[x].push_back(i);     }     for (i = 1; i <= n; i++) cin >> arr[i];     dfs(1, -1, 0);     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k, x, y, z, last[500039][2], a[500039], s[500039], ans;   long long q[500039];   inline void swap(int &x, int &y) { x ^= y ^= x ^= y; }   inline void check(int x, int y) {     if (y - x < 2 || !x) return;     if (q[y - 1] - q[x] == (a[y] ^ a[x])) ans++;   }   inline void find(int flag) {     register int i, j;     memset(last, 0, sizeof(last));     for (i = 1; i <= n; i++) {       last[s[i]][1] = last[s[i]][0];       last[s[i]][0] = i;       for (j = s[i] + 1; j <= 29; j++) check(last[j][0], i), check(last[j][1], i);       if (!flag) check(last[s[i]][1], i);     }   }   int main() {     register int i, j;     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &a[i]), q[i] = q[i - 1] + a[i];     for (i = 1; i <= n; i++) {       for (j = 29; j >= 0; j--)         if (a[i] & (1 << j)) {           s[i] = j;           break;         }     }     find(0);     for (i = 1; i <= n / 2; i++)       swap(a[i], a[n - i + 1]), swap(s[i], s[n - i + 1]);     for (i = 1; i <= n; i++) q[i] = q[i - 1] + a[i];     find(1);     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   string employees;   queue<int> d, r;   int main() {     int n;     cin >> n >> employees;     for (int i = 0; i < n; i++) {       if (employees[i] ==  D )         d.push(i);       else         r.push(i);     }     while (!d.empty() && !r.empty()) {       int idx_d = d.front(), idx_r = r.front();       d.pop(), r.pop();       if (idx_d < idx_r)         d.push(idx_d + n);       else         r.push(idx_r + n);     }     if (d.empty())       cout <<  R ;     else       cout <<  D ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     cin >> n;     if (n == 1 || n == 4 || n == 6 || n == 8 || n == 9 || n == 10 || n == 13 ||         n == 15) {       cout <<  1 ;       return 0;     }     cout <<  0 ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000050;   const int inf = 0x3f3f3f3f;   const int mod = 1e9 + 7;   int a[maxn], b[maxn], mi, ans1, ans2, ans3, ans, l, r;   vector<int> v;   char s[maxn];   void pa(int s, int e) {     ans2 = 0;     for (int i = s; i < e; i++)       if (a[i] == mi + 1) ans2++;     if (ans2 > ans) {       ans = ans2;       l = s, r = e;     }     ans3 = 0;     int x = s + 1;     for (int i = s + 1; i < e; i++) {       if (a[i] == mi + 1) {         if (ans3 + ans1 > ans) {           ans = ans1 + ans3;           l = x, r = i;         }         x = i + 1;         ans3 = 0;       }       if (a[i] == mi + 2) ans3++;     }   }   int main() {     int n, m, i, j, k, t;     scanf( %d , &n);     scanf( %s , s + 1);     for (i = 1; i <= n; i++)       a[i] = s[i] ==  (  ? a[i - 1] + 1 : a[i - 1] - 1, mi = min(mi, a[i]);     if (a[n] != 0) printf( 0 n1 1 n ), exit(0);     for (i = n + 1; i <= 2 * n; i++) a[i] = a[i - n];     for (i = 1; i <= n; i++)       if (a[i] == mi) v.push_back(i);     ans = ans1 = v.size();     l = r = 1;     v.push_back(v[0] + n);     for (i = 0; i < v.size() - 1; i++) pa(v[i] + 1, v[i + 1]);     printf( %d n%d %d n , ans, l > n ? l - n : l, r > n ? r - n : r);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int arr[104];   int main() {     int n, avg, mn, flag;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     avg = 0;     avg = arr[1] - arr[0];     flag = 0;     for (int i = 1; i < n; i++) {       int diff = (arr[i] - arr[i - 1]);       if (diff != avg) {         flag = 1;         break;       }     }     if (flag == 1) {       cout << arr[n - 1] << endl;     } else {       cout << arr[n - 1] + avg << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Edge {     int64_t v, f, c;     Edge(int64_t v, int64_t f, int64_t c) : v(v), f(f), c(c) {}     int64_t get_capacity() { return c - f; }   };   const int64_t INF = (int64_t)(1e9) + 666;   const int64_t N = 10000;   const int64_t S = N - 2;   const int64_t T = N - 1;   vector<Edge> edges;   vector<int64_t> g[N];   int64_t dist[N];   int64_t ptr[N];   void add_edge(int64_t v, int64_t u, int64_t c) {     g[v].emplace_back(edges.size());     edges.emplace_back(u, 0, c);     g[u].emplace_back(edges.size());     edges.emplace_back(v, 0, 0);   }   bool bfs() {     fill(dist, dist + N, INF);     dist[S] = 0;     queue<int64_t> q;     q.push(S);     while (!q.empty()) {       int64_t v = q.front();       q.pop();       for (int64_t id : g[v]) {         if (edges[id].get_capacity() < 1) {           continue;         }         if (dist[edges[id].v] > dist[v] + 1) {           dist[edges[id].v] = dist[v] + 1;           q.push(edges[id].v);         }       }     }     return dist[T] != INF;   }   int64_t dfs(int64_t v, int64_t min_c) {     if (v == T) {       return min_c;     }     while (ptr[v] < g[v].size()) {       int64_t id = g[v][ptr[v]];       ++ptr[v];       if (edges[id].get_capacity() < 1) {         continue;       }       if (dist[edges[id].v] != dist[v] + 1) {         continue;       }       int64_t x = dfs(edges[id].v, min(min_c, edges[id].get_capacity()));       if (x) {         --ptr[v];         edges[id].f += x;         edges[id ^ 1].f -= x;         return x;       }     }     return 0;   }   int main() {     int64_t n, h, m;     cin >> n >> h >> m;     int64_t sum = 0;     for (int64_t i = 0; i < n; ++i) {       for (int64_t j = 0; j < h; ++j) {         sum += 2 * (j + 1) - 1;         add_edge(S, i * h + j, 2 * (j + 1) - 1);       }     }     for (int64_t q = 0; q < m; ++q) {       int64_t left, right, x, c;       cin >> left >> right >> x >> c;       add_edge(q + N / 2, T, c);       for (int64_t i = left - 1; i < right; ++i) {         for (int64_t j = x; j < h; ++j) {           add_edge(i * h + j, q + N / 2, INF);         }       }     }     while (bfs()) {       fill(ptr, ptr + N, 0);       while (dfs(S, INF)) {       }     }     for (int64_t id : g[S]) {       sum -= edges[id].f;     }     cout << sum << endl;     return 0;   }