malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     double n, m;     while (cin >> m >> n) {       double res = 0;       for (double i = 1; i <= m; i++) {         res += i * (pow(i / m, n) - pow((i - 1) / m, n));       }       cout << res << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void print(T &x) {     cout << x;   }   template <class T, class U>   void print(pair<T, U> &p) {     cout <<  ( ;     print(p.first);     cout <<  ,  ;     print(p.second);     cout <<  ) ;   }   template <class T>   void print(vector<T> &v) {     cout <<  { ;     if (((int)(v).size())) print(v[0]);     for (int i = 1; i < ((int)(v).size()); i++) cout <<  ,  , print(v[i]);     cout <<  } n ;   }   const int n = 5e5 + 5;   int N, M, K, T;   vector<long long> A;   int cnt(vector<long long> A, int b) {     if (((int)(A).size()) == 1) return 1;     if (((int)(A).size()) == 0) return 0;     vector<long long> B;     while (!A.empty() && A[((int)(A).size()) - 1] >= 1LL << b) {       long long v = A[((int)(A).size()) - 1];       A.pop_back();       B.push_back(v ^ (1LL << b));     }     int szA = ((int)(A).size());     int t1 = cnt(A, b - 1) + (((int)(B).size()) > 0 ? 1 : 0);     sort(B.begin(), B.end());     int t2 = cnt(B, b - 1) + (szA > 0 ? 1 : 0);     return max(t1, t2);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> N;     A.resize(N);     for (long long &a : A) cin >> a;     sort(A.begin(), A.end());     int c = cnt(A, 31);     cout << N - c << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 50;   const int inf = 0x3f3f3f3f;   int n, mod;   long long ans;   int head[maxn], nxt[maxn << 1], to[maxn << 1], cost[maxn << 1], edge_tot;   void add_edge(int u, int v, int c) {     nxt[++edge_tot] = head[u];     head[u] = edge_tot;     to[edge_tot] = v;     cost[edge_tot] = c;   }   void change(long long &x, int mod) { x = (x % mod + mod) % mod; }   void ext_gcd(long long a, long long b, long long &d, long long &x,                long long &y) {     if (!b) {       d = a;       x = 1;       y = 0;     } else {       ext_gcd(b, a % b, d, y, x);       y -= x * (a / b);     }   }   long long fac[maxn], inv[maxn];   void pre() {     fac[0] = 1;     for (int i = 1; i < maxn; i++) fac[i] = fac[i - 1] * 10 % mod;     for (int i = 0; i < maxn; i++) {       long long a = fac[i], b = mod;       long long d, x, y;       ext_gcd(a, b, d, x, y);       change(x, mod);       inv[i] = x;     }   }   int root;   bool vis[maxn];   int siz[maxn], mxson[maxn];   void ndc_init() { mxson[0] = inf; }   void get_root(int u, int f, int sum) {     siz[u] = 1;     mxson[u] = 0;     for (int i = head[u]; i; i = nxt[i]) {       int v = to[i];       if (vis[v] || v == f) continue;       get_root(v, u, sum);       siz[u] += siz[v];       if (mxson[u] < siz[v]) mxson[u] = siz[v];     }     if (mxson[u] < sum - siz[u]) mxson[u] = sum - siz[u];     if (mxson[u] < mxson[root]) root = u;   }   map<long long, int> mp;   void add1(int u, int f, register long long sum, int dep, int op) {     mp[sum] += op;     for (int i = head[u]; i; i = nxt[i]) {       int v = to[i];       if (vis[v] || v == f) continue;       add1(v, u, (sum + fac[dep] * cost[i] % mod) % mod, dep + 1, op);     }   }   void calc(int u, int f, register long long sum, int dep) {     if (!sum) ans++;     long long fd = -inv[dep] * sum;     change(fd, mod);     if (mp.count(fd)) ans += mp[fd];     for (int i = head[u]; i; i = nxt[i]) {       int v = to[i];       if (vis[v] || v == f) continue;       calc(v, u, (sum * 10 + cost[i]) % mod, dep + 1);     }   }   void solve(int u = 1, int sum = n) {     root = 0;     get_root(u, 0, sum);     vis[root] = 1;     for (int i = head[root]; i; i = nxt[i]) {       int v = to[i];       if (vis[v]) continue;       add1(v, root, cost[i] % mod, 1, 1);     }     if (mp.count(0)) ans += mp[0];     for (int i = head[root]; i; i = nxt[i]) {       int v = to[i];       if (vis[v]) continue;       add1(v, root, cost[i] % mod, 1, -1);       calc(v, root, cost[i] % mod, 1);       add1(v, root, cost[i] % mod, 1, 1);     }     mp.clear();     int root_sz = siz[root];     for (int i = head[root]; i; i = nxt[i]) {       int v = to[i];       if (vis[v]) continue;       solve(v, siz[v]);     }   }   int main() {     ans = 0;     scanf( %d%d , &n, &mod);     for (int i = 1; i < n; i++) {       int u, v, c;       scanf( %d%d%d , &u, &v, &c);       u++, v++;       add_edge(u, v, c);       add_edge(v, u, c);     }     pre();     ndc_init();     solve();     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long dp[41];   void prec() {     dp[0] = 0;     long long x = 1;     for (int i = int(1); i < int(41); i++) {       dp[i] = 2 * dp[i - 1] + x;       x = x << 1;     }   }   int main(int argc, const char* argv[]) {     long long n;     cin >> n;     prec();     n--;     long long ans = 0;     long long original = n;     while (n) {       long long r = n & (-n);       ans += dp[(int)log2(r)];       n -= r;     }     long long i = 1;     while (i <= original) {       ans += i & original;       i = i << 1;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[100001], i;     set<int> mysetp, mysetn, left, right;     set<int>::iterator l, r, p;     scanf( %d , &n);     scanf( %d , &a[1]);     mysetn.insert(-a[1]);     mysetp.insert(a[1]);     for (i = 2; i <= n; i++) {       scanf( %d , &a[i]);       l = mysetn.lower_bound(-a[i]);       r = mysetp.lower_bound(a[i]);       if (*l > 0 || -(*l) > a[i]) {         left.insert(*r);         printf( %d n , *r);       } else if (*r < a[i]) {         printf( %d n , -(*l));       } else if (-(*l) == *r) {         if (*r > a[i]) left.insert(*r);         printf( %d n , *r);       } else {         p = left.lower_bound(*r);         if (*p == *r) {           printf( %d n , -(*l));         } else {           left.insert(*r);           printf( %d n , *r);         }       }       mysetp.insert(a[i]);       mysetn.insert(-a[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using DB = double;   using LL = long long;   using PII = pair<int, int>;   void err() { puts(  ); }   template <template <typename...> class T, typename t, typename... Args>   void err(T<t> a, Args... args) {     for (auto x : a) cout << x <<    ;     err(args...);   }   template <typename T, typename... Args>   void err(T a, Args... args) {     cout << a <<    ;     err(args...);   }   const int N = 2e5 + 10;   char s[N], t[N];   void work() {     int n, m;     scanf( %d%d%s%s , &n, &m, s, t);     int id = -1;     for (int i = 0; i < n; i++)       if (s[i] ==  * ) id = i;     if (id == -1) {       printf( %s n , strcmp(s, t) == 0 ?  YES  :  NO );     } else {       bool flag = 0;       if (n - 1 <= m) {         flag = 1;         for (int i = 0; i < id; i++) {           if (s[i] != t[i]) flag = 0;         }         for (int i = n - 1, j = m - 1; i > id; i--, j--) {           if (s[i] != t[j]) flag = 0;         }       }       printf( %s n , flag ?  YES  :  NO );     }   }   int main() {     work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000010;   const long long inf = 1000000000000000000LL;   int a[N];   long long prefix_cost[N], cost[N], suffix_cost[N];   set<int> factors;   set<int>::iterator it;   void pf(int x) {     for (int j = x - 1; j <= x + 1; j++) {       int d = j;       for (int i = 2; i * i <= j; i++) {         if (d % i == 0) {           factors.insert(i);           while (d % i == 0) d /= i;         }       }       if (d != 1) factors.insert(d);     }   }   int main() {     int n, p, A, B;     scanf( %d %d %d , &n, &A, &B);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     if (n == 1) {       printf( 0 n );       return 0;     }     pf(a[1]);     pf(a[n]);     long long ans = inf;     for (it = factors.begin(); it != factors.end(); ++it) {       prefix_cost[0] = 0LL;       p = *it;       for (int i = 1; i <= n; i++) {         if (a[i] % p == 0)           cost[i] = 0LL;         else if ((a[i] + 1) % p == 0 || (a[i] - 1) % p == 0)           cost[i] = (long long)B;         else           cost[i] = inf;         prefix_cost[i] = prefix_cost[i - 1] + cost[i];         if (prefix_cost[i] > inf) prefix_cost[i] = inf;       }       prefix_cost[0] = inf;       suffix_cost[n + 1] = 0LL;       long long suffix_sum = 0LL;       for (int i = n; i > 0; i--) {         suffix_sum += cost[i];         if (suffix_sum > inf) suffix_sum = inf;         suffix_cost[i] = min(A + suffix_cost[i + 1], suffix_sum);       }       ans = min(ans, suffix_cost[1]);       for (int i = 2; i <= n; i++)         ans = min(ans, prefix_cost[i - 1] + suffix_cost[i]);     }     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   static const int MOD = 51123987;   static const int MAXN = 150 + 10;   char s[MAXN];   int p[MAXN][3];   int dp[MAXN][55][55][55];   int n, res;   int main() {     scanf( %d%s , &n, s + 1);     p[n + 1][0] = p[n + 1][1] = p[n + 1][2] = n + 1;     for (int i = n; i >= 1; i--) {       p[i][0] = p[i + 1][0];       p[i][1] = p[i + 1][1];       p[i][2] = p[i + 1][2];       if (s[i] ==  a ) p[i][0] = i;       if (s[i] ==  b ) p[i][1] = i;       if (s[i] ==  c ) p[i][2] = i;     }     int k = (n + 2) / 3;     dp[1][0][0][0] = 1;     for (int i = 1; i <= n; i++)       for (int a = 0; a <= k; a++)         for (int b = 0; b <= k; b++)           for (int c = 0; c <= k; c++) {             if (a + b + c == n && abs(a - b) < 2 && abs(a - c) < 2 &&                 abs(b - c) < 2) {               res = (res + dp[i][a][b][c]) % MOD;               continue;             }             dp[p[i][0]][a + 1][b][c] =                 (dp[p[i][0]][a + 1][b][c] + dp[i][a][b][c]) % MOD;             dp[p[i][1]][a][b + 1][c] =                 (dp[p[i][1]][a][b + 1][c] + dp[i][a][b][c]) % MOD;             dp[p[i][2]][a][b][c + 1] =                 (dp[p[i][2]][a][b][c + 1] + dp[i][a][b][c]) % MOD;           }     printf( %d n , res);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   template <class T>   T gcd(T a, T b) {     return ((b == 0) ? a : gcd(b, a % b));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, q;     cin >> n >> q;     vector<int> a(n);     set<int> st;     multiset<int> mlt;     for (int i = 0; i < (int)(n); i++) cin >> a[i], st.insert(a[i]);     sort(a.begin(), a.end());     for (int i = (int)(1); i < (int)(n); i++) mlt.insert(a[i] - a[i - 1]);     int r = a[n - 1], l = a[0];     for (int i = 0; i < (int)(q + 1); i++) {       if (mlt.size()) {         auto it = --mlt.end();         int mx = *it;         cout << r - l - mx <<   n ;       } else         cout << 0 <<   n ;       if (i == q) continue;       int t;       cin >> t;       if (t == 0) {         int x;         cin >> x;         if (*st.begin() == x) {           auto it = st.begin();           it++;           if (it != st.end()) {             auto it2 = mlt.find(*it - *st.begin());             if (it2 != mlt.end()) mlt.erase(it2);           }         } else {           auto it = st.lower_bound(x);           it--;           if (mlt.find(x - *it) != mlt.end()) mlt.erase(mlt.find(x - *it));           auto it1 = it;           it1++;           it1++;           if (it1 != st.end()) {             auto it2 = mlt.find(*it1 - x);             if (it2 != mlt.end()) mlt.erase(it2);             mlt.insert(*it1 - *it);           }         }         auto it = st.find(x);         if (it != st.end()) st.erase(it);       } else {         int x;         cin >> x;         if (st.size()) {           auto it = st.lower_bound(x);           if (it != st.end()) {             mlt.insert(*it - x);             if (it != st.begin()) {               auto it1 = it;               it1--;               mlt.insert(x - *it1);               auto it2 = mlt.find(*it - *it1);               if (it2 != mlt.end()) mlt.erase(it2);             }           } else {             if (it != st.begin()) {               it--;               mlt.insert(x - *it);             }           }         }         st.insert(x);       }       if (st.size()) {         l = *st.begin();         r = *(--st.end());       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long m;   int k;   vector<int> a;   long long memo[66][2][66];   long long dp(int id, int tight, int cnt) {     long long &res = memo[id][tight][cnt];     if (res == -1) {       res = 0;       if (id == a.size()) {         if (cnt == k) res = 1;       } else {         for (int i = 0; i < 2; i++) {           if (tight && i > a[id]) continue;           int new_tight = tight ? i == a[id] : false;           int new_cnt = cnt + (i == 1 ? 1 : 0);           res += dp(id + 1, new_tight, new_cnt);         }       }     }     return res;   }   long long solve(long long n) {     a.clear();     while (n) {       a.push_back(n % 2);       n /= 2;     }     a.push_back(0);     reverse(a.begin(), a.end());     memset(memo, -1, sizeof(memo));     return dp(0, 1, 0);   }   long long possible(long long n) { return solve(2 * n) - solve(n); }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cin >> m >> k;     long long lo = 1, hi = (long long)1e18 + 15;     long long ans = -1;     while (lo <= hi) {       long long mid = (lo + hi) / 2;       if (possible(mid) == m) {         ans = mid;         break;       }       if (possible(mid) < m) {         lo = mid + 1;       } else         hi = mid - 1;     }     assert(ans != -1);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool compare(int a, int b) { return a > b; }   int main() {     int n, a, index;     cin >> n;     vector<int> A;     int temp;     int count = 0;     for (int i = 0; i < n; i++) {       cin >> a;       A.push_back(a);     }     for (int i = 0; i < n; i++) {       if (A[i] == 1) {         count++;         index = i;         break;       }     }     for (int i = index + 1; i < n; i++) {       if (A[i] == 1 && A[i - 1] == 1)         count++;       else if (A[i] == 1 && A[i - 1] == 0)         count += 2;       else         continue;     }     cout << count;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     vector<long long> v, ans;     long long n;     cin >> n;     for (long long i = 0; i < n; i++) {       long long q;       cin >> q;       v.push_back(q);     }     sort(v.begin(), v.end());     bool cur = 0;     while (!v.empty()) {       if (!cur) {         cout << v.front();         v.erase(v.begin());       } else {         cout << v.back();         v.erase(v.begin() + v.size() - 1);       }       cout <<    ;       cur = 1 - cur;     }   }   signed main() {     long long t = 1;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   const long long INF64 = (long long)(1e18) + 10;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int q = 1, i, j, test, k;     for (test = 1; test < (q + 1); test++) {       long long n, ans = 0, x = 0;       cin >> n;       vector<long long> v(n);       for (i = 0; i < (n); i++) cin >> v[i];       map<long long, long long> prefodd, prefeven;       prefodd[0]++;       for (i = 0; i < (n); i++) {         x = x ^ v[i];         if (i & 1)           ans += prefodd[x], prefodd[x]++;         else           ans += prefeven[x], prefeven[x]++;       }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   bool isBeautiful(int n) {     bool flag[10];     for (int i = 0; i < 10; i++) flag[i] = false;     while (n > 0) {       int digit = n % 10;       if (flag[digit]) return false;       flag[digit] = true;       n = n / 10;     }     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     if (isBeautiful(n)) n++;     while (!isBeautiful(n)) {       n++;     }     cout << n;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long INF = (1e15) + 1;   int n, dp[100004], par[100004];   long long d, arr[100004];   struct Node {     Node *leftNode, *rightNode;     long long leftBound, rightBound;     pair<int, int> mx;     Node() {       leftNode = rightNode = NULL;       leftBound = rightBound = 0LL;       mx = {0, 0};     }   };   void update(Node *par, long long pos, int dpMax, int ind) {     if (par->leftBound == pos && par->rightBound == pos) {       if ((par->mx).first < dpMax) {         par->mx = {dpMax, ind};       }       return;     }     long long mid = (par->leftBound + par->rightBound) >> 1;     if (pos <= mid) {       if (par->leftNode == NULL) par->leftNode = new Node();       par->leftNode->leftBound = par->leftBound;       par->leftNode->rightBound = mid;       update(par->leftNode, pos, dpMax, ind);       if ((par->leftNode->mx).first > (par->mx).first) {         par->mx = par->leftNode->mx;       }     } else {       if (par->rightNode == NULL) par->rightNode = new Node();       par->rightNode->leftBound = mid + 1;       par->rightNode->rightBound = par->rightBound;       update(par->rightNode, pos, dpMax, ind);       if ((par->rightNode->mx).first > (par->mx).first) {         par->mx = par->rightNode->mx;       }     }   }   pair<int, int> query(Node *par, long long l, long long r) {     if (par == NULL || par->leftBound > r || par->rightBound < l) {       return {0, 0};     }     if (par->leftBound >= l && par->rightBound <= r) {       return par->mx;     }     long long mid = (par->leftBound + par->rightBound) >> 1;     pair<int, int> p1 = query(par->leftNode, l, r);     pair<int, int> p2 = query(par->rightNode, l, r);     if (p1.first > p2.first)       return p1;     else       return p2;   }   int main() {     scanf( %d%lld , &n, &d);     for (int i = 1; i <= n; i++) scanf( %lld , &arr[i]);     Node *root = new Node();     root->leftBound = 0LL;     root->rightBound = INF;     int ans = 0, curInd = 0;     for (int i = 1; i <= n; i++) {       long long l = max(0LL, arr[i] - d);       long long r = min(INF, arr[i] + d);       pair<int, int> p1 = query(root, 1LL, l);       pair<int, int> p2 = query(root, r, INF);       pair<int, int> p = p1;       if (p.first < p2.first) p = p2;       dp[i] = p.first + 1;       par[i] = p.second;       update(root, arr[i], dp[i], i);       if (dp[i] > ans) {         ans = dp[i];         curInd = i;       }     }     printf( %d n , ans);     vector<int> inds;     while (curInd != 0) {       inds.push_back(curInd);       curInd = par[curInd];     }     reverse(inds.begin(), inds.end());     for (int i = 0; i <= inds.size() - 1; i++) {       printf( %d  , inds[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void Read(T &x) {     x = 0;     char c;     while (!isdigit(c = getchar()))       ;     do {       x = x * 10 + c -  0 ;     } while (isdigit(c = getchar()));   }   long long read() {     long long tmp;     cin >> tmp;     return tmp;   }   void giuncute() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   void OF() {     freopen(          f           .inp ,          r , stdin);     freopen(          f           .out ,          w , stdout);   }   const long long MOD = 1e9 + 7, mxn = 5e3 + 2;   long long n, a[mxn] = {0}, numNode[mxn] = {0}, p[mxn];   int down[mxn][mxn] = {{0}}, up[mxn][2] = {{0}};   long long Pow(long long u, long long v) {     if (!v) return 1;     long long tmp = Pow(u, v >> 1);     (tmp *= tmp) %= MOD;     if (v & 1) return (tmp * u) % MOD;     return tmp;   }   int main() {     giuncute();     cin >> n;     numNode[1] = 1;     for (long long i = 1; i <= n - 1; ++i) {       cin >> a[i];       numNode[i + 1] = (numNode[i] * a[i]) % MOD;       p[i] = Pow(a[i], MOD - 2);     }     for (long long i = 1; i <= n; ++i) down[i][1] = a[i], up[i][1] = 1;     up[1][1] = 0;     for (long long i = n - 1; i >= 1; --i)       for (long long j = 2; j <= n - i; ++j)         down[i][j] = (a[i] * down[i + 1][j - 1]) % MOD;     long long p2 = Pow(2, MOD - 2);     for (long long j = 1; j <= n * 2 - 2; ++j) {       long long cnt_up = 0, cnt_down = 0;       if (j != 1)         for (long long i = 2; i <= n; ++i) {           if (j > n + i - 2) continue;           (up[i][j & 1] += up[i - 1][~j & 1]) %= MOD;           if (j <= n && down[i - 1][j - 1])             (up[i][j & 1] +=              (down[i - 1][j - 1] * (((a[i - 1] - 1) * p[i - 1]) % MOD)) % MOD) %=                 MOD;         }       for (long long i = 1; i <= n; ++i) {         up[i][~j & 1] = 0;         if (j > n + i - 2) continue;         (cnt_up += (numNode[i] * up[i][j & 1]) % MOD) %= MOD;         if (j < n) (cnt_down += (numNode[i] * down[i][j]) % MOD) %= MOD;       }       cout << (((cnt_up + cnt_down) % MOD) * p2) % MOD <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B>   ostream& operator<<(ostream& out, const pair<A, B>& p) {     out <<  (  << p.first <<  ,  << p.second <<  )  ;     return out;   }   template <typename A, typename B>   void printP(const pair<A, B>& p, const char* str = NULL) {     if (!(1 && !1)) return;     if (str != NULL) cout << str <<  : ;     cout <<  (  << p.first <<  ,  << p.second <<  )  ;   }   template <typename T>   void printV(const vector<T>& v, const char* str = NULL) {     if (!(1 && !1)) return;     if (str != NULL) cout << str <<  :  ;     for (int i = 0; i < (v.size()); ++i) cout << v[i] <<    ;     cout << endl;   }   template <typename T>   void printC(T& container, const char* str = NULL) {     if (!(1 && !1)) return;     if (str != NULL) cout << str <<  : ;     for (__typeof((container).begin()) it = ((container).begin());          it != (container).end(); ++it) {       cout << (*it) <<    ;     }     cout << endl;   }   const int INF = 1000010111;   const int S_N = 152;   const int MOD = 1000000007;   int main() {     int n;     cin >> n;     vector<int> t1, t2;     for (int i = 0; i < n; i++) {       int thick, width;       cin >> thick >> width;       ((thick == 1) ? t1 : t2).push_back(width);     }     sort(t1.begin(), t1.end(), greater<int>());     sort(t2.begin(), t2.end(), greater<int>());     int mini = INF;     for (int c1 = 0; c1 <= t1.size(); c1++) {       for (int c2 = 0; c2 <= t2.size(); c2++) {         int tSum = 1 * c1 + 2 * c2;         int wSum = 0;         for (int i = c1; i < t1.size(); i++) wSum += t1[i];         for (int i = c2; i < t2.size(); i++) wSum += t2[i];         if (tSum >= wSum) mini = min(mini, tSum);       }     }     cout << mini << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 500010;   int n, a;   multiset<int> st;   int main() {     cin >> n;     st.insert(0);     for (int i = 1; i <= n; ++i) {       scanf( %d , &a);       if (st.find(a) != st.end()) {         st.erase(st.find(a));         st.insert(i);       } else {         st.insert(i);       }     }     cout << st.size() << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long arr[200005];   long long n;   map<long long, long long> ans;   bool debug = false;   long long rec(long long node) {     if (debug) cout <<  entering   << node << endl;     if (node == 1) return 1000000000000;     if (node <= 0 || node > n) return 0;     if (ans.count(node) && ans[node] == -1000000000000)       return ans[node] = 1000000000000;     if (ans.count(node)) {       if (debug) cout <<  already computed for   << node << endl;       return ans[node];     }     ans[node] = -1000000000000;     long long val = 0;     long long n1 = node + arr[node];     val += arr[node];     if (n1 <= 0 || n1 > n) return ans[node] = val;     long long n2 = n1 - arr[n1];     val += arr[n1];     return ans[node] = val + rec(n2);   }   int main() {     scanf( %lld , &n);     for (__typeof(n - 1) i = 0; i < n - 1; i++) scanf( %lld , &arr[i + 2]);     long long k;     for (__typeof(n) i = 2; i <= n; i++) {       long long val = i - 1;       long long nex = i - arr[i];       val += arr[i];       k = rec(nex) + val;       if (k >= 1000000000000)         cout << -1 << endl;       else         cout << k << endl;     }     return 0;   }