malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int N = 5e5 + 5;   int n, m;   ll c[N];   vector<int> adj[N];   map<vector<int>, ll> mp;   ll custom_gcd(ll a, ll b) {     ll c;     while (b > 0) {       c = a % b;       a = b;       b = c;     }     return a;   }   void solve() {     mp.clear();     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       cin >> c[i];       adj[i].clear();     }     for (int i = 1, u, v; i <= m; ++i) {       cin >> u >> v;       adj[v].emplace_back(u);     }     for (int i = 1; i <= n; ++i) {       sort(adj[i].begin(), adj[i].end());       if (!adj[i].empty()) mp[adj[i]] += c[i];     }     ll ans = 0;     for (auto &p : mp) {       ans = custom_gcd(ans, p.second);     }     cout << ans <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000 + 1;   char a[N][N];   int f[N * 2], head[1000001], vis[2 * N], d[N * 2], d1[N * 2], bj[N * 2];   int ask(int x) { return x == f[x] ? x : f[x] = ask(f[x]); }   struct node {     int next, to;   } e[N * N];   int tot;   void add(int x, int y) {     e[++tot].to = y;     e[tot].next = head[x];     head[x] = tot;   }   int cnt;   int solve() {     queue<int> q;     for (int i = 1; i <= cnt; i++) {       if (d[i] == 0) q.push(i);     }     while (!q.empty()) {       int p = q.front();       q.pop();       for (int i = head[p]; i; i = e[i].next) {         int u = e[i].to;         d[u]--;         if (d[u] == 0) q.push(u);       }     }     for (int i = 1; i <= cnt; i++)       if (d[i]) return 1;     return 0;   }   void dfs(int u, int w) {     bj[u] = w;     for (int i = head[u]; i; i = e[i].next) {       int v = e[i].to;       if (bj[v] < w + 1) dfs(v, w + 1);     }   }   void solve1() {     queue<int> q;     for (int i = 1; i <= cnt; i++)       if (!d1[i]) q.push(i), bj[i] = 1;     while (!q.empty()) {       int p = q.front();       q.pop();       for (int i = head[p]; i; i = e[i].next) {         int u = e[i].to;         d1[u]--;         bj[u] = max(bj[u], bj[p] + 1);         if (!d1[u]) q.push(u);       }     }   }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int n, m;     cin >> n >> m;     for (int i = 1; i <= n + m; i++) f[i] = i;     for (int i = 1; i <= n; i++) {       cin >> a[i] + 1;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         int f1 = ask(i), f2 = ask(n + j);         if (a[i][j] !=  = ) {           if (f1 == f2) {             cout <<  No n ;             return 0;           }         } else {           f[f1] = f2;         }       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         int f1 = ask(i), f2 = ask(n + j);         if (!vis[f1]) vis[f1] = ++cnt;         if (!vis[f2]) vis[f2] = ++cnt;         if (a[i][j] !=  = ) {           if (f1 == f2) {             cout <<  No n ;             return 0;           }           if (a[i][j] ==  < )             add(vis[f1], vis[f2]), d[vis[f2]]++, d1[vis[f2]]++;           else             add(vis[f2], vis[f1]), d[vis[f1]]++, d1[vis[f1]]++;         }       }     }     if (solve()) {       cout <<  No n ;       return 0;     }     solve1();     cout <<  Yes n ;     for (int i = 1; i <= n + m; i++) {       cout << bj[vis[ask(i)]] <<    ;       if (i == n) cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;       typedef long double ld;   const long long inf = 1100000000000000000;   #define maxn 1000005   #define mod 1000000007 //998244353   #define int long long   #define PB push_back   #define eb emplace_back   #define all(c) (c).begin(),(c).end()   #define pii pair <int,int>   #define vi vector<int>   #define F first   #define S second   #define rep(i,a,b)  for(int i=a;i<b;i++)   #define rep1(i,a,b) for(int i=a;i<=b;i++)   #define repd(i,a,b) for(int i=a;i>=b;--i)   #define sz(x) (int)((x).size())     #define mem(a,x) memset(a,x,sizeof(a))   const long double PI=3.141592653589793238462643383279502884197169399375105820974944;      void solve(){    int n, m; cin>>n>>m;    int z = 720720; //lcm{1..16}    int a[n][m];    rep(i, 0, n)      rep(j, 0, m)       cin>>a[i][j];    rep(i, 0, n){     rep(j, 0, m){      int k = z-pow(a[i][j], 4);      if((i+j)%2)       cout<<z<<   ;      else       cout<<k<<   ;     }cout<<  n ;    }   }      signed main(){       ios_base::sync_with_stdio(false), cin.tie(nullptr);        int T=1;// cin>>T;        while(T--){           solve();cout<<  n ;       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   long n, ps[1000], tp, q, ar[1000], ans, x, y, a, b;   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> ar[i];       ps[ar[i]] = i;     }     cin >> q;     for (; q; --q) {       cin >> tp;       if (tp == 2) {         cin >> a >> b;         swap(ar[a], ar[b]);         ps[ar[a]] = a;         ps[ar[b]] = b;       } else {         cin >> x >> y;         ans = 1;         while (x < y) {           if (ps[x + 1] < ps[x]) ++ans;           ++x;         }         cout << ans << endl;       }     }     cin.get();     cin.get();     return 0;   }
#include <bits/stdc++.h>   void solve() {     int n;     std::cin >> n;     int a = 0;     std::string s;     std::cin >> s;     bool flag = false;     int x, y;     x = y = 0;     if (s[0] ==  U ) {       ++y;     } else {       ++x;     }     if (x > y) flag = true;     for (size_t i = 1; i < s.size(); ++i) {       if (s[i] ==  U ) {         ++y;       } else {         ++x;       }       if (x > y && !flag) {         flag = true;         ++a;       } else if (x < y && flag) {         flag = false;         ++a;       }     }     std::cout << a;   }   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(nullptr);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long d = 0, n, i;     cin >> n;     int a[n];     for (i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     for (i = 0; i < n; i++) {       if (a[i] > d) d++;     }     cout << d << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   int pos[N];   int main() {     ios::sync_with_stdio(false);     int n, a;     while (cin >> n) {       for (int i = 1; i <= n; ++i) {         cin >> a;         pos[a] = i;       }       int last = 0;       for (int i = 1; i <= n; ++i) {         cin >> a;         cout << max(pos[a] - last, 0) <<    ;         last = max(last, pos[a]);       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     vector<long long> a(n + 1, 0);     long long s1 = 0, s2 = 0, s3 = 0;     for (int i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       a[i] += a[i - 1];     }     if (a[n] % 3) {       cout <<  0 n ;       return;     }     vector<int> a0, a1;     for (int i = 1; i < n; i++) {       if (a[i] == a[n] / 3) a0.push_back(i);       if (a[i] == 2 * a[n] / 3) a1.push_back(i);     }     long long ret = 0;     while (a0.size() && a1.size()) {       while (a0.size() && a0.back() >= a1.back()) {         a0.pop_back();       }       if (!a0.size()) break;       ret += a0.size();       a1.pop_back();     }     cout << ret << endl;   }   int main() {     solve();     return 0;   }
#include <iostream>   #include <vector>   #include <set>   #include <unordered_set>   #include <map>   #include <unordered_map>   #include <algorithm>   #include <numeric>   #include <queue>   #include <iomanip>   #include <numeric>   #include <cmath>   using namespace std;      int main() {    int t;    cin >> t;    for (int tt = 0; tt < t; tt++) {     int n, m;     cin >> n >> m;     vector<int> va(n, 0), vb(n, 0);     unordered_map<int, vector<int>> tofix;     unordered_map<int, int> fixed;     for (int i = 0; i < n; i++) {      cin >> va[i];     }     for (int i = 0; i < n; i++) {      cin >> vb[i];      if (va[i] == vb[i]) {       fixed[va[i]] = i;      } else {       tofix[vb[i]].push_back(i);      }     }     vector<int> res(m, 0);     vector<pair<int, int>> redundant;     for (int i = 0; i < m; i++) {      int x;      cin >> x;      if (tofix.count(x) > 0 and tofix[x].size() > 0) {       res[i] = tofix[x].back();       fixed[x] = tofix[x].back();       tofix[x].pop_back();       if (tofix[x].size() == 0) {        tofix.erase(x);       }          if (redundant.size() > 0) {        for (auto p : redundant) {         res[p.first] = fixed[x];        }        redundant.clear();       }      } else {       if (fixed.count(x) > 0) {        if (redundant.size() > 0) {         for (auto p : redundant) {          res[p.first] = fixed[x];         }         redundant.clear();         res[i] = fixed[x];        } else {         res[i] = fixed[x];        }       } else {        redundant.emplace_back(i, x);       }      }     }     if (redundant.empty() and tofix.size() == 0) {      cout <<  YES  << endl;      for (auto r : res) {       cout << r + 1 <<    ;      }      cout << endl;     } else {      cout <<  NO  << endl;     }    }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2.5 * 1e5 + 5;   int n, m, k;   int d[N];   struct Edge {     int num;     int next;   } edge[4 * N];   int tot, last[N];   vector<int> q;   vector<int> ans[N];   vector<int> path;   int anss;   bool flag;   void Add(int i, int j) {     tot++;     edge[tot].num = j;     edge[tot].next = last[i];     last[i] = tot;   }   void dfs(int i, int deep) {     if (flag) return;     d[i] = deep;     q.push_back(i);     if (deep > n / k) {       flag = 1;       for (int j = q.size() - 1; j >= 0; j--) path.push_back(q[j]);       return;     }     bool flag = 0;     for (int k = last[i]; k != 0; k = edge[k].next) {       int v = edge[k].num;       if (d[v] == 0) {         dfs(v, deep + 1);         flag = 1;       }     }     if (flag == 0) {       anss++;       int sign1 = 0, sign2 = 0;       bool sign = 0;       for (int k = last[i]; k != 0; k = edge[k].next) {         int v = edge[k].num;         if (d[v] + 1 == d[i]) continue;         if ((d[i] - d[v]) % 3 == 2) {           if (sign1 == 0)             sign1 = v;           else             sign2 = v;         } else {           for (int k = q.size() - 1; k >= 0; k--) {             ans[anss].push_back(q[k]);             if (q[k] == v) break;           }           sign = 1;           break;         }       }       if (sign == 0) {         bool en = 0;         ans[anss].push_back(i);         for (int k = q.size() - 1; k >= 0; k--) {           if ((q[k] == sign1 || q[k] == sign2) && en == 0) {             en = 1;             ans[anss].push_back(q[k]);             continue;           }           if (en) ans[anss].push_back(q[k]);           if ((q[k] == sign1 || q[k] == sign2) && en == 1) {             en = 0;             break;           }         }       }     }     q.pop_back();   }   int main() {     std::ios::sync_with_stdio(0);     cin >> n >> m >> k;     for (int i = 1; i <= m; i++) {       int u, v;       cin >> u >> v;       Add(u, v);       Add(v, u);     }     dfs(1, 1);     if (flag) {       cout <<  PATH n  << path.size() << endl;       for (int j = path.size() - 1; j >= 0; j--) cout << path[j] <<    ;     } else {       cout <<  CYCLES n ;       for (int i = 1; i <= k; i++) {         cout << ans[i].size() << endl;         ;         for (int j = 0; j <= ans[i].size() - 1; j++) cout << ans[i][j] <<    ;         cout << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int test_case;     cin >> test_case;     while (test_case--) {       int a, b, x, y;       vector<int> akash;       cin >> a >> b >> x >> y;       int temp1 = 0, temp2 = 0, temp3 = 0, temp4 = 0;       temp1 = ((b - y) - 1) * a;       temp2 = ((a - x) - 1) * b;       temp3 = (y - 0) * a;       temp4 = (x - 0) * b;       akash.push_back(temp1);       akash.push_back(temp2);       akash.push_back(temp3);       akash.push_back(temp4);       int max = akash[0];       for (int i = 1; i < 4; i++) {         if (max < akash[i]) {           max = akash[i];         }       }       cout << max << endl;       akash.clear();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[20000];   int main() {     ios_base::sync_with_stdio(NULL);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       if (x == 1) {         cout <<  HARD ;         return 0;       }     }     cout <<  EASY ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, a[105];       cin >> n;       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = n - 1; i >= 0; i--) cout << a[i] <<    ;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   const int N = 1000000;   int n;   char str[N + 10];   int cdog = 0, fdog = 0, ldog = 0, cbone = 0, fbone = 0, lbone = 0;   int cntd[N + 10], cntb[N + 10];   int nxtd[N + 10], nxtb[N + 10];   int lstd[N + 10], lstb[N + 10];   int tp1[N + 10], tp2[N + 10][2];   bool dp[N + 10];   bool chk(int x) {     memset(dp, 0, sizeof(dp));     dp[0] = true;     for (int i = n; i >= 0; --i) {       if (str[i] !=  P ) continue;       int nd = lstd[std::min(i + x, n)];       if (nd > i)         tp1[i] = tp1[nd];       else         tp1[i] = i + x;     }     for (int i = n; i >= 0; --i) {       if (str[i] !=  P ) continue;       int nd = lstd[std::min(i + x, n)], bd = nxtd[i + 1];       if (!bd)         tp2[i][0] = n + 1, tp2[i][1] = 0;       else if (nd == bd)         tp2[i][0] = bd - x, tp2[i][1] = i + x;       else         tp2[i][0] = bd - x, tp2[i][1] = tp1[nd];     }     for (int i = 0; i < n; ++i) {       if (!dp[i]) continue;       int nd = nxtd[i + 1];       int nb = nxtb[i + 1];       if (nd == 0 || nb == 0) break;       if (nb < nd) {         if (nb >= nd - x) {           dp[nd] = true;         }         if (nb >= tp2[nd][0]) {           dp[std::min(tp2[nd][1], n)] = true;         }       } else {         dp[std::min(tp1[nd], n)] = true;       }     }     int lst = 0;     for (int i = n; i >= 0; --i)       if (dp[i]) {         lst = i;         break;       }     return lst >= lbone;   }   int main() {     scanf( %d , &n);     scanf( %s , str + 1);     for (int i = 1; i <= n; ++i)       if (str[i] ==  P ) {         ++cdog;         if (fdog == 0) fdog = i;         ldog = i;         cntd[i] = cntd[i - 1] + 1;         cntb[i] = cntb[i - 1];       } else if (str[i] ==  * ) {         ++cbone;         if (fbone == 0) fbone = i;         lbone = i;         cntd[i] = cntd[i - 1];         cntb[i] = cntb[i - 1] + 1;       } else {         cntd[i] = cntd[i - 1];         cntb[i] = cntb[i - 1];       }     if (cdog == 1) {       if (cntb[ldog] > cbone - cntb[ldog]) {         printf( %d %d n , cntb[ldog], ldog - fbone);       } else {         printf( %d %d n , cbone - cntb[ldog], lbone - ldog);       }       return 0;     }     printf( %d  , cbone);     for (int i = n; i >= 0; --i) {       if (str[i] ==  P )         nxtd[i] = i;       else         nxtd[i] = nxtd[i + 1];       if (str[i] ==  * )         nxtb[i] = i;       else         nxtb[i] = nxtb[i + 1];     }     for (int i = 1; i <= n; ++i) {       if (str[i] ==  P )         lstd[i] = i;       else         lstd[i] = lstd[i - 1];       if (str[i] ==  * )         lstb[i] = i;       else         lstb[i] = lstb[i - 1];     }     int l = 1, r = n, ans = 0;     while (l <= r) {       int mid = (l + r) >> 1;       if (chk(mid)) {         ans = mid, r = mid - 1;       } else {         l = mid + 1;       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[17][17];   int main() {     int n, m, k, need;     scanf( %d%d%d%d , &n, &m, &k, &need);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         int x, y;         scanf( %d%d , &x, &y);         a[x][y] = 1;       }     }     int ans = 0;     for (int x1 = 1; x1 <= n; x1++) {       for (int y1 = 1; y1 <= m; y1++) {         for (int x2 = x1; x2 <= n; x2++) {           for (int y2 = 1; y2 <= m; y2++) {             int tot = 0;             for (int x = x1; x <= x2; x++) {               for (int y = y1; y <= y2; y++) {                 tot += a[x][y];               }             }             if (tot >= need) ans++;           }         }       }     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int M = 2e5 + 5;   vector<int> G[M];   int n, A[M], num, ok, res, ans[2][M], C;   bool mark[M];   void ma(int a, int b) {     if (a == b || mark[a] && mark[b]) return;     printf( %d %d n , a, b);     ans[0][C] = a;     ans[1][C] = b;     C++;     mark[a] = mark[b] = 1;     ma(A[a], A[b]);   }   int main() {     scanf( %d , &n);     res = -1;     for (int i = 1; i <= n; i++) scanf( %d , A + i);     for (int i = 1; i <= n; i++) {       int nw = A[i], has = 0;       while (!mark[nw]) {         has = 1;         mark[nw] = 1;         G[num].push_back(nw);         nw = A[nw];       }       if (G[num].size() == 1) ok = A[i];       if (G[num].size() == 2) res = num;       if (has) num++;     }     memset(mark, 0, sizeof(mark));     if (ok) {       puts( YES );       for (int i = 1; i <= n; i++)         if (i != ok) printf( %d %d n , ok, i);     } else if (~res) {       for (int i = 0; i < num; i++)         if (G[i].size() & 1) {           puts( NO );           return 0;         }       puts( YES );       printf( %d %d n , G[res][0], A[G[res][0]]);       for (int i = 0; i < num; i++)         if (res != i) ma(G[res][0], G[i][0]);     } else       puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int INF = 1e9 + 10;   const int N = 1e2 + 5;   int mark[N];   int ans;   int main() {     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       mark[x] = i + 1;     }     for (int i = 0; i < N; i++) {       if (mark[i] != 0) ans++;     }     if (ans >= k) {       cout <<  YES  <<   n ;       int cnt = 0;       for (int i = 0; i < N; i++) {         if (cnt < k and mark[i] != 0) {           cout << mark[i] <<    ;           cnt++;         }       }     } else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, len;     char s[105];     cin >> s;     len = strlen(s);     for (i = 0; i < len; i++) {       for (j = 0; j < len - i - 2; j += 2) {         if (s[j] > s[j + 2]) {           swap(s[j], s[j + 2]);         }       }     }     printf( %s , s);     return 0;   }
#include <bits/stdc++.h>   int c[100];   int main() {     int n, s, max = 0, i, j;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &s);       c[s] += 1;       if (s > max) max = s;     }     for (i = 0; i <= max; i++)       for (j = 0; j < c[i]; j++) printf( %d  , i);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, k, m, d, i = 0, b = 1, ans = 0;   int main(void) {     cin >> n >> k >> m >> d;     for (i = 1; i <= d && b <= n; i++, b += k) {       ans = max(ans, min(m, n / b) * i);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     long long x;     bool s;     node(long long a, bool b) { x = a, s = b; }   };   bool operator<(node a, node b) { return a.x > b.x; }   priority_queue<node> pq;   int main() {     int n;     long long temp;     cin >> n;     long long ans = 0;     for (int i = 1; i <= n; i++) {       cin >> temp;       if (pq.empty() || pq.top().x > temp) {         pq.push(node(temp, 0));       } else {         long long now = pq.top().x;         bool se = pq.top().s;         pq.pop();         if (se) pq.push(node(now, 0));         ans += temp - now, pq.push(node(temp, 1));       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     long long ar[n + 1];     for (long long i = 1; i <= n; i++) {       cin >> ar[i];     }     for (long long i = 1; i <= n; i++) {       long long f = ar[i];       long long t = ar[f];       if (ar[t] == i) {         return cout <<  YES , 0;       }     }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int MOD = 1e9 + 7, MAX = 1e6 + 5;   const long long INF = 1e18 + 5;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, q;       cin >> n >> q;       vector<int> A(n + 2);       for (int in = 1; in < 1 + n; in++) cin >> A[in];       A[0] = -n - 1;       A[n + 1] = -n - 1;       long long ans = 0;       set<int> Pos;       set<int> Neg;       for (int i = 1; i <= n; i++) {         if (A[i] > A[i - 1] && A[i] > A[i + 1]) {           ans += A[i];           Pos.insert(A[i]);         }         if (A[i] < A[i - 1] && A[i] < A[i + 1]) {           ans -= A[i];           Neg.insert(A[i]);         }       }       cout << ans <<   n ;       while (q--) {         int u, v;         cin >> u >> v;         swap(A[u], A[v]);         long long diff = 0;         for (int i = u - 1; i <= u + 1; i++) {           if (i <= 0) continue;           if (i > n) continue;           if (A[i] > A[i - 1] && A[i] > A[i + 1]) {             if (Neg.count(A[i])) {               Neg.erase(A[i]);               Pos.insert(A[i]);               diff += 2 * A[i];             } else if (!Pos.count(A[i])) {               Pos.insert(A[i]);               diff += A[i];             }           } else if (A[i] < A[i - 1] && A[i] < A[i + 1]) {             if (Pos.count(A[i])) {               Pos.erase(A[i]);               Neg.insert(A[i]);               diff -= 2 * A[i];             } else if (!Neg.count(A[i])) {               Neg.insert(A[i]);               diff -= A[i];             }           } else {             if (Pos.count(A[i])) {               Pos.erase(A[i]);               diff -= A[i];             } else if (Neg.count(A[i])) {               Neg.erase(A[i]);               diff += A[i];             }           }         }         for (int i = v - 1; i <= v + 1; i++) {           if (i <= u + 1) continue;           if (i <= 0) continue;           if (i > n) continue;           if (A[i] > A[i - 1] && A[i] > A[i + 1]) {             if (Neg.count(A[i])) {               Neg.erase(A[i]);               Pos.insert(A[i]);               diff += 2 * A[i];             } else if (!Pos.count(A[i])) {               Pos.insert(A[i]);               diff += A[i];             }           } else if (A[i] < A[i - 1] && A[i] < A[i + 1]) {             if (Pos.count(A[i])) {               Pos.erase(A[i]);               Neg.insert(A[i]);               diff -= 2 * A[i];             } else if (!Neg.count(A[i])) {               Neg.insert(A[i]);               diff -= A[i];             }           } else {             if (Pos.count(A[i])) {               Pos.erase(A[i]);               diff -= A[i];             } else if (Neg.count(A[i])) {               Neg.erase(A[i]);               diff += A[i];             }           }         }         ans += diff;         cout << ans <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     int a[10] = {0};     int n;     string d;     cin >> n;     cin >> d;     for (int i = 0; i < d.size(); i++) {       if (d[i] ==  L ) {         for (int j = 0; j < 10; j++) {           if (a[j] == 0) {             a[j] = 1;             break;           }         }       } else if (d[i] ==  R ) {         for (int j = 9; j >= 0; j--) {           if (a[j] == 0) {             a[j] = 1;             break;           }         }       } else {         a[d[i] -  0 ] = 0;       }     }     for (int i = 0; i < 10; i++) printf( %d , a[i]);   }