malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   struct BIT {     int bit[200005];     void init() { memset(bit, 0, sizeof(bit)); }     void add(int k, int x) {       k++;       while (k < 200005) {         bit[k] += x;         k += k & -k;       }     }     int get(int k) {       k++;       int ret = 0;       while (k > 0) {         ret += bit[k];         k -= k & -k;       }       return ret;     }     int get(int s, int t) { return get(t) - get(s - 1); }   };   BIT bit[3];   set<int> st[3];   set<int>::iterator it;   int A[200005];   char str[200005];   int n;   int ctoi(char c) {     if (c ==  R ) return 0;     if (c ==  P ) return 1;     if (c ==  S ) return 2;     return -1;   }   int get(int l, int r, int c) {     l = max(l, 0);     r = min(r, n - 1);     if (l > r) return 0;     return bit[c].get(l, r);   }   void rm(int v) {     st[A[v]].erase(v);     bit[A[v]].add(v, -1);   }   void ins(int v) {     st[A[v]].insert(v);     bit[A[v]].add(v, 1);   }   int query() {     int ret = 0;     for (int i = 0; i < 3; i++) {       int x = i, y = i + 1, z = i - 1;       if (z < 0) z += 3;       if (y >= 3) y -= 3;       int my = n, mz = n;       it = st[y].begin();       if (it != st[y].end()) my = *it;       it = st[z].begin();       if (it != st[z].end()) mz = *it;       int My = -1, Mz = -1;       it = st[y].end();       if (it != st[y].begin()) {         it--;         My = *it;       }       it = st[z].end();       if (it != st[z].begin()) {         it--;         Mz = *it;       }       ret += st[x].size();       if (my < mz) {         if (Mz < My) {           if (mz < Mz) {             ret -= get(my, mz, x);             ret -= get(Mz, My, x);           } else {             ret -= get(min(my, Mz), max(mz, My), x);           }         } else {           ret -= get(my, mz, x);         }       } else if (Mz < My) {         ret -= get(Mz, My, x);       }     }     return ret;   }   int main() {     int Q;     scanf( %d %d , &n, &Q);     scanf( %s , &str);     for (int i = 0; i < 3; i++) bit[i].init();     for (int i = 0; i < n; i++) {       A[i] = ctoi(str[i]);       ins(i);     }     printf( %d n , query());     while (Q--) {       int t;       scanf( %d %s , &t, &str);       t--;       rm(t);       A[t] = ctoi(str[0]);       ins(t);       printf( %d n , query());     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e3 + 5;   struct edge {     int to, w, next;   } G[maxn * maxn];   struct node {     int x1, y1, x2, y2, id;   } nd[maxn];   long long bit[maxn][maxn], ans[maxn];   int n, m, k, q, head[maxn], tot;   vector<int> vec[maxn];   char s[10];   void init(int n) {     memset(head, -1, sizeof(head));     memset(bit, 0, sizeof(bit));     for (int i = 1; i <= n; ++i) vec[i].clear();     tot = 0;   }   void addedge(int u, int v, int w) {     G[tot].to = v;     G[tot].w = w;     G[tot].next = head[u];     head[u] = tot++;   }   void update(int x, int y, int v) {     while (x <= n) {       for (int i = y; i <= m; i += i & -i) {         bit[x][i] += v;       }       x += x & -x;     }   }   long long query(int x, int y) {     long long ret = 0;     while (x) {       for (int i = y; i; i -= i & -i) {         ret += bit[x][i];       }       x -= x & -x;     }     return ret;   }   int myhash(int x, int y) { return x * (m + 1) + y; }   int main() {     scanf( %d%d%d , &n, &m, &k);     init(n);     for (int i = 1; i <= k; ++i) {       int l;       scanf( %d , &l);       for (int j = 0; j < l; ++j) {         int x, y, w;         scanf( %d%d%d , &x, &y, &w);         addedge(i, myhash(x, y), w);       }     }     scanf( %d , &q);     int cnt = 0;     for (int i = 0; i < q; ++i) {       scanf( %s , s);       if (*s ==  S ) {         int o;         scanf( %d , &o);         vec[o].push_back(i);       } else {         scanf( %d%d%d%d , &nd[cnt].x1, &nd[cnt].y1, &nd[cnt].x2, &nd[cnt].y2);         nd[cnt].id = i;         ans[cnt++] = 0;       }     }     for (int i = 1; i <= k; ++i) {       int on = 1;       for (int j = head[i]; ~j; j = G[j].next) {         edge e = G[j];         int x = e.to / (m + 1), y = e.to % (m + 1);         update(x, y, e.w);       }       for (int j = 0, l = 0; j < cnt; ++j) {         while (l < vec[i].size() && vec[i][l] < nd[j].id) {           on ^= 1;           ++l;         }         if (on)           ans[j] += query(nd[j].x2, nd[j].y2) - query(nd[j].x1 - 1, nd[j].y2) -                     query(nd[j].x2, nd[j].y1 - 1) +                     query(nd[j].x1 - 1, nd[j].y1 - 1);       }       for (int j = head[i]; ~j; j = G[j].next) {         edge e = G[j];         int x = e.to / (m + 1), y = e.to % (m + 1);         update(x, y, -e.w);       }     }     for (int i = 0; i < cnt; ++i) printf( %I64d n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void boost() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   int main(void) {     boost();     long long n;     cin >> n;     vector<long long> v(n);     for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));          i += 1 - 2 * ((0) > (n)))       cin >> v[i];     map<long long, long long> mp1;     for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));          i += 1 - 2 * ((0) > (n))) {       mp1[v[i]] = i;     }     long long a[n + 1];     for (__typeof(n + 1) i = (0) - ((0) > (n + 1));          i != (n + 1) - ((0) > (n + 1)); i += 1 - 2 * ((0) > (n + 1)))       a[i] = 0;     long long t1;     for (long long i = n; i >= 1; i--) {       t1 = mp1[i];       while (1) {         t1 = t1 - i;         if (t1 < 0) break;         if (v[t1] > i && a[v[t1]] == 0) {           a[i] = 1;         }       }       t1 = mp1[i];       while (1) {         t1 = t1 + i;         if (t1 >= n) break;         if (v[t1] > i && a[v[t1]] == 0) {           a[i] = 1;         }       }     }     for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));          i += 1 - 2 * ((0) > (n))) {       if (a[v[i]] == 0)         cout <<  B ;       else         cout <<  A ;     }   }
#include <bits/stdc++.h>   using namespace std;   char s[200005], c;   int a[200005];   int ans[26];   int main() {     int n, k;     int maxn = 0;     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> s[i];     for (int i = 0; i < n; i++) {       if (s[i] == s[i - 1])         a[i] = a[i - 1] + 1;       else         a[i] = 1;     }     for (int i = 0; i < n; i++) {       if (a[i] != 0 && a[i] % k == 0) ans[(int)s[i] -  a ]++;     }     for (int i = 0; i <= 25; i++) maxn = max(maxn, ans[i]);     printf( %d , maxn);     return 0;   }
#include <bits/stdc++.h>   typedef struct {     int u, v, w;   } Edge;   int n;   int e;   Edge edges[100 * 99];   int d[100];   void bf(int s) {     int i, j;     for (i = 0; i < n; ++i) d[i] = 1000000000;     d[s] = 0;     for (i = 0; i < n - 1; ++i)       for (j = 0; j < e; ++j)         if (d[edges[j].u] + edges[j].w < d[edges[j].v])           d[edges[j].v] = d[edges[j].u] + edges[j].w;   }   int abs(int v) { return v < 0 ? -v : v; }   int a[100];   int cord[100][2];   int main() {     int c;     scanf( %d %d , &n, &c);     for (int i = 1; i <= n - 2; ++i) {       scanf( %d , &a[i]);     }     for (int i = 0; i < n; ++i) {       scanf( %d %d , &cord[i][0], &cord[i][1]);     }     int ei = 0;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         if (i == j) continue;         Edge ed;         ed.u = i;         ed.v = j;         ed.w = abs(cord[i][0] - cord[j][0]) + abs(cord[i][1] - cord[j][1]);         ed.w *= c;         ed.w -= a[j];         edges[ei++] = ed;       }     }     e = n * (n - 1);     bf(0);     printf( %d n , d[n - 1]);     return 0;   }
#include <bits/stdc++.h>   const int inf = INT_MAX;   const int MAX = 1e5 + 8;   const long long MOD = 1e9 + 7;   const int TOT_PRIMES = 1e6 + 9;   const int MAX_A = 71;   const int LN = 20;   using namespace std;   bool prime[MAX];   void precompute() {     memset(prime, false, sizeof(prime));     for (int i = 2; i < MAX; i++) {       if (!prime[i]) {         for (int j = 2 * i; j < MAX; j += i) prime[j] = true;       }     }   }   int a[60][60], b[60][60];   int main() {     int n;     vector<long long> dif;     cin >> n;     long long ans = 0;     for (int i = 0; i < n; i++) {       long long x, y;       cin >> x >> y;       dif.push_back(x - y);       ans = ans + (n * y - x);     }     sort(dif.begin(), dif.end());     for (int i = n - 1; i >= 0; i--) {       ans = ans + (dif[n - i - 1] * (i + 1));     }     cout << ans;   }
#include <bits/stdc++.h>   char str[100010], out[100010], visited[100010];   int n, m, len, ar[100010], counter[256], tree[100010];   void update(int p, int v) {     p++;     while (p <= n) {       tree[p] += v;       p += (p & (-p));     }   }   int query(int p) {     int res = 0;     while (p) {       res += tree[p];       p ^= (p & (-p));     }     return res;   }   int range_query(int l, int r) {     l++, r++;     if (l > r) return 0;     return (query(r) - query(--l));   }   int main() {     int i, j, k, l, c, res, flag;     while (scanf( %d , &m) != EOF) {       scanf( %s , str);       n = strlen(str);       memset(counter, 0, sizeof(counter));       memset(tree, 0, sizeof(tree));       for (i = 0; i < n; i++) counter[str[i]]++;       for (c =  a ; c <=  z ; c++) {         for (i = 0; i < n; i++) {           if (str[i] == c) update(i, 1);         }         flag = 1;         for (i = 0; (i + m) <= n; i++) {           if (range_query(i, i + m - 1) == 0) {             flag = 0;             break;           }         }         if (flag) break;       }       for (i = 0, len = 0; i < n; i++) {         if (str[i] == c) {           update(i, -1);           ar[len++] = i;         }       }       res = 0;       memset(visited, 0, sizeof(visited));       for (i = 0, j = 0; (i + m) <= n; i++) {         if (range_query(i, i + m - 1) == 0) {           k = -1;           while (j < len) {             if ((ar[j] + m - 1) < i)               j++;             else {               if (ar[j] > (i + m - 1)) break;               k = j++;             }           }           assert(k != -1);           visited[k] = 1;           update(ar[k], 1);         }       }       for (i = 0; i < 100010; i++) res += visited[i];       len = 0;       for (i =  a ; i < c; i++) {         for (j = 0; j < counter[i]; j++) {           out[len++] = i;         }       }       for (i = 0; i < res; i++) out[len++] = c;       out[len] = 0;       puts(out);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> g[201010];   int tin[201010], tout[201010];   int n, a[201010], m, timer;   int is[201010], lvl[201010];   void dfs(int v) {     tin[v] = ++timer;     for (auto to : g[v])       if (!tin[to]) {         lvl[to] = lvl[v] ^ 1;         dfs(to);       }     tout[v] = timer;   }   int t[2][801010];   void upd(int l, int r, int x, bool tp, int v = 1, int tl = 1, int tr = n) {     if (tl > r || tr < l) return;     if (tl >= l && tr <= r) {       t[tp][v] += x;       t[tp ^ 1][v] -= x;       return;     }     int tm = (tl + tr) / 2;     upd(l, r, x, tp, v * 2, tl, tm);     upd(l, r, x, tp, v * 2 + 1, tm + 1, tr);   }   int get(int x, bool tp, int v = 1, int tl = 1, int tr = n) {     if (tl == tr) return t[tp][v];     int tm = (tl + tr) / 2;     if (x <= tm)       return t[tp][v] + get(x, tp, v * 2, tl, tm);     else       return t[tp][v] + get(x, tp, v * 2 + 1, tm + 1, tr);   }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1, u, v; i < n; i++) {       cin >> u >> v;       g[v].push_back(u);       g[u].push_back(v);     }     dfs(1);     for (int i = 1, x, val, tt; i <= m; i++) {       cin >> tt >> x;       if (tt == 2) {         cout << a[x] + get(tin[x], lvl[x]) <<   n ;         continue;       }       cin >> val;       upd(tin[x], tout[x], val, lvl[x]);     }   }
#include <bits/stdc++.h>   int d[1005], vis[1005];   int main() {     int flag = 0;     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &d[i]);       vis[d[i]]++;     }     int ans = 0;     for (int i = 1; i <= 100; i++) {       if (vis[i] == 1) {         ans++;       }       if (vis[i] >= 3) {         flag = 1;       }     }     if (!(ans & 1)) {       puts( YES );       int g = 0;       for (int i = 0; i < n; i++) {         if (vis[d[i]] == 1 && g) {           putchar( A );         } else {           putchar( B );         }         if (vis[d[i]] == 1) {           g ^= 1;         }       }       puts(  );       return 0;     }     if (flag == 0) {       puts( NO );       return 0;     }     puts( YES );     int cnt = 0, f = 0;     for (int i = 0; i < n; i++) {       if (cnt < (ans >> 1) && vis[d[i]] == 1) {         putchar( B );         cnt++;       } else if (vis[d[i]] >= 3 && f == 0) {         putchar( B );         f = 1;       } else {         putchar( A );       }     }     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int len = 6020;   int SIZE;   const int inf = (int)1e9;   int n;   vector<int> in;   vector<vector<int>> g;   int flow[len][len], cost[len][len], pot[len];   int get_p(int u, int v) { return cost[u][v] + pot[u] - pot[v]; }   int add_path(int from, int to) {     vector<int> dist(SIZE, (int)1e9), prv(SIZE);     vector<bool> check(SIZE, false);     dist[from] = 0;     check[from] = true;     priority_queue<pair<int, int>> q;     q.push(make_pair(0, from));     while (!q.empty()) {       auto tmp = q.top();       tmp.first *= -1;       q.pop();       if (dist[tmp.second] != tmp.first) {         continue;       }       check[tmp.second] = true;       for (auto i : g[tmp.second]) {         if (flow[tmp.second][i] > 0 &&             dist[i] > dist[tmp.second] + get_p(tmp.second, i)) {           dist[i] = dist[tmp.second] + get_p(tmp.second, i);           prv[i] = tmp.second;           q.push(make_pair(-dist[i], i));         }       }     }     for (int i = 0; i < SIZE; i++) {       pot[i] += dist[i];     }     if (!check[to]) {       return inf;     }     int ptr = to, cap = inf, sum = 0;     while (ptr != from) {       cap = min(cap, flow[prv[ptr]][ptr]);       ptr = prv[ptr];     }     ptr = to;     while (ptr != from) {       flow[prv[ptr]][ptr] -= cap;       flow[ptr][prv[ptr]] += cap;       sum += cost[prv[ptr]][ptr];       ptr = prv[ptr];     }     return sum;   }   int solve(int from, int to) {     int sum = 0, tmp;     while ((tmp = add_path(from, to)) != inf) {       sum -= tmp;     }     return sum;   }   void add(int from, int to, int in_flow, int in_cost) {     g[from].push_back(to);     g[to].push_back(from);     flow[from][to] = in_flow;     cost[from][to] = in_cost;     cost[to][from] = -in_cost;   }   vector<int> super_cnt[100001];   vector<int> cnt[7];   int main() {     cin >> n;     SIZE = 2 * n + 3;     in.resize(SIZE);     for (int i = 0; i < n; i++) {       cin >> in[i];     }     g.resize(SIZE, vector<int>());     add(0, 1, 4, 0);     for (int i = 0; i < n; i++) {       add(2 * i + 3, 2 * i + 4, 1, -1);       add(1, 2 * i + 3, 1, 0);       add(2 * i + 4, 2, 1, 0);       for (int j : cnt[in[i] % 7]) {         add(2 * j + 4, 2 * i + 3, 1, 0);       }       for (int j : super_cnt[in[i] - 1]) {         add(2 * j + 4, 2 * i + 3, 1, 0);       }       for (int j : super_cnt[in[i] + 1]) {         add(2 * j + 4, 2 * i + 3, 1, 0);       }       cnt[in[i] % 7].push_back(i);       super_cnt[in[i]].push_back(i);     }     for (int i = 0; i < SIZE; i++) {       for (int j = 0; j < i; j++) {         if (flow[j][i] && pot[j] + cost[j][i] < pot[i]) {           pot[i] = pot[j] + cost[j][i];         }       }     }     cout << solve(0, 2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t[111];   int main() {     int n, k, m;     cin >> n >> k >> m;     int sum = 0;     for (int i = 0; i < k; i++) {       cin >> t[i];       sum += t[i];     }     sort(t, t + k);     int ans = 0;     for (int i = 0; i <= n; i++) {       int time = m - sum * i;       if (time < 0) break;       int cnt = (k + 1) * i;       for (int j = 0; j < k; j++) {         for (int q = 0; q < (n - i); q++) {           if (time - t[j] >= 0) {             cnt++;             time -= t[j];           }         }       }       ans = max(ans, cnt);     }     cout << ans << endl;   }
#include  bits/stdc++.h       using namespace std;      const int MAXN = 3e5+10;   int cores[MAXN];   int pos[51];   int n, m;      int solve(int cor){       int ans = pos[cor];       for(int i = 1; i <= 50; i++){           if(pos[i] < pos[cor] && pos[i]) pos[i]++;       }       pos[cor] = 1;       return ans;   }      int main(){          cin>>n>>m;          for(int i = 0; i < n; i++){           cin>>cores[i];           if(!pos[cores[i]]) pos[cores[i]] = i+1;       }          for(int i = 0; i < m; i++){           int query;           cin>>query;           cout<<solve(query)<<  n ;       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s1, s2;   int k, ans;   double eps = 0.01;   bool ok(int l) {     if (s1.compare(0, l, s2, 0, l) != 0) {       return false;     }     for (int i = 0; i < s1.size(); i += l) {       if (s1.compare(0, l, s1, i, l) != 0) {         return false;       }     }     for (int i = 0; i < s2.size(); i += l) {       if (s2.compare(0, l, s2, i, l) != 0) {         return false;       }     }     return true;   }   int main() {     cin >> s1 >> s2;     k = min(s1.size(), s2.size());     for (int i = 1; i <= sqrt(k + eps); i++) {       if (s1.size() % i == 0 && s2.size() % i == 0 && ok(i)) {         ans++;       }       if (s1.size() % (k / i) == 0 && s2.size() % (k / i) == 0 && i != k / i &&           ok(k / i)) {         ans++;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 15;   int dis[maxn][maxn];   char str[2000100];   void cal(int p, int q) {     memset(dis, 0x3f3f3f3f, sizeof dis);     for (int i = 0; i <= 9; i++) {       dis[i][(i + p) % 10] = min(dis[i][(i + p) % 10], 1);       dis[i][(i + q) % 10] = min(dis[i][(i + q) % 10], 1);     }     for (int k = 0; k <= 9; k++)       for (int i = 0; i <= 9; i++)         for (int j = 0; j <= 9; j++) {           dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);         }   }   int main() {     cal(0, 1);     scanf( %s , str);     int len = strlen(str);     int ans[15][15];     memset(ans, -1, sizeof ans);     for (int i = 0; i < 10; i++)       for (int j = i; j < 10; j++) {         cal(i, j);         int sm = 0;         for (int k = 1; k < len; k++) {           int ti = str[k - 1] -  0 , tj = str[k] -  0 ;           if (dis[ti][tj] == 0x3f3f3f3f || dis[ti][tj] == 0) {             sm = -1;             break;           } else             sm += dis[ti][tj] - 1;         }         ans[i][j] = ans[j][i] = sm;       }     for (int i = 0; i < 10; i++)       for (int j = 0; j < 10; j++) {         printf(j == 9 ?  %d n  :  %d  , ans[i][j]);       }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool isprime(long long int n) {     if (n < 2) return false;     for (long long int i = 2; i <= sqrt(n); i++)       if (n % i == 0) return false;     return true;   }   long long gcd(long long int a, long long int b) {     if (a == 0 || b == 0)       return a + b;     else       return gcd(b, a % b);   }   const int mx = 100000;   long long int b[mx], w[mx], dp[10][mx];   char c[1100][1100];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long int n, m, x, y;     cin >> n >> m >> x >> y;     for (long long int i = 1; i <= n; i++)       for (long long int j = 1; j <= m; j++) cin >> c[i][j];     for (long long int i = 1; i <= m; i++) {       long long int wt = 0, bl = 0;       for (long long int j = 1; j <= n; j++) {         if (c[j][i] ==  . )           wt++;         else           bl++;       }       w[i] = w[i - 1] + wt;       b[i] = b[i - 1] + bl;     }     for (long long int i = 1; i <= m; i++) {       dp[1][i] = 100000000;       dp[0][i] = 100000000;       for (long long int a = x; a <= y; a++) {         if (i - a >= 0) {           dp[1][i] = min(dp[0][i - a] + w[i] - w[i - a], dp[1][i]);           dp[0][i] = min(dp[1][i - a] + b[i] - b[i - a], dp[0][i]);         }       }     }     cout << min(dp[0][m], dp[1][m]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int L[36000], R[36000];   int D[36000], U[36000];   int C[36000];   int S[185], H[185], mark[36000], OK[185], tans[36000];   int ak, size;   void Link(int r, int c) {     S[c]++;     C[size] = c;     U[size] = U[c];     D[U[c]] = size;     D[size] = c;     U[c] = size;     if (H[r] == -1)       H[r] = L[size] = R[size] = size;     else {       L[size] = L[H[r]];       R[L[H[r]]] = size;       R[size] = H[r];       L[H[r]] = size;     }     mark[size] = r;     size++;   }   void remove(int c) {     int i;     for (i = D[c]; i != c; i = D[i]) L[R[i]] = L[i], R[L[i]] = R[i];   }   void resume(int c) {     int i;     for (i = U[c]; i != c; i = U[i]) L[R[i]] = R[L[i]] = i;   }   int h() {     int i, j, k, count = 0;     bool visit[185];     memset(visit, 0, sizeof(visit));     for (i = R[0]; i; i = R[i]) {       if (visit[i]) continue;       count++;       visit[i] = 1;       for (j = D[i]; j != i; j = D[j]) {         for (k = R[j]; k != j; k = R[k]) visit[C[k]] = 1;       }     }     return count;   }   void Dance(int k) {     int i, j, c, Min, ans;     ans = h();     if (k + ans >= ak) return;     if (!R[0]) {       if (k < ak) {         ak = k;         for (int i = 0; i < k; i++) {           tans[i] = mark[OK[i]];         }       }       return;     }     for (Min = 185, i = R[0]; i; i = R[i])       if (S[i] < Min) Min = S[i], c = i;     for (i = D[c]; i != c; i = D[i]) {       OK[k] = i;       remove(i);       for (j = R[i]; j != i; j = R[j]) remove(j);       Dance(k + 1);       for (j = L[i]; j != i; j = L[j]) resume(j);       resume(i);     }     return;   }   int xx[5] = {0, 0, 0, 1, -1};   int yy[5] = {0, 1, -1, 0, 0};   int mat[400][400];   int main() {     int tn, tm;     while (scanf( %d%d , &tn, &tm) == 2) {       memset(mat, 0, sizeof(mat));       for (int i = 1; i <= tn; i++) {         for (int j = 1; j <= tm; j++) {           for (int k = 0; k < 5; k++) {             int x = i + xx[k], y = j + yy[k];             if (x >= 1 && x <= tn && y >= 1 && y <= tm) {               mat[(i - 1) * tm + j][(x - 1) * tm + y] = 1;             }           }         }       }       n = tn * tm, m = tn * tm;       for (int i = 0; i <= m; i++) {         S[i] = 0;         U[i] = D[i] = i;         L[i + 1] = i;         R[i] = i + 1;       }       R[m] = 0;       memset(H, -1, sizeof(H));       memset(mark, 0, sizeof(mark));       memset(tans, 0, sizeof(tans));       size = m + 1;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) {           if (mat[i][j]) Link(i, j);         }       }       ak = 185;       Dance(0);       printf( %d n , n - ak);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     unsigned long num_bottles = 0;     cin >> num_bottles;     map<unsigned long, pair<unsigned long, unsigned long> > links;     map<unsigned long, unsigned long> counts;     for (unsigned long n = 0; n < num_bottles; n++) {       unsigned long a = 0, b = 0;       cin >> a >> b;       counts[a]++;       links[a];       if (a == b) {         links[b].second++;       } else {         links[b].first++;       }     }     unsigned long unopened = 0;     for (map<unsigned long, pair<unsigned long, unsigned long> >::iterator              links_it = links.begin();          links_it != links.end(); ++links_it) {       unsigned long bottle = links_it->first;       unsigned long from_outside = links_it->second.first;       unsigned long from_within = links_it->second.second;       if (from_outside > 0) continue;       if (from_within > 1) continue;       if (from_within == 1) {         unopened++;         continue;       }       unopened += counts[bottle];     }     cout << unopened;     return 0;   }