malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MAX = 1010;   string a[MAX];   int n, m;   bool visit[MAX][MAX];   bool v[1000010];   int b[MAX][MAX];   int val[1000010];   void dfs(int x, int y, int cnt) {     if (x < 0 || y < 0 || x >= n || y >= m) {       return;     }     if (visit[x][y]) {       return;     }     if (a[x][y] ==  * ) {       return;     }     visit[x][y] = true;     val[cnt]++;     b[x][y] = cnt;     dfs(x + 1, y, cnt);     dfs(x, y + 1, cnt);     dfs(x - 1, y, cnt);     dfs(x, y - 1, cnt);   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     memset(visit, false, sizeof(visit));     memset(b, -1, sizeof(visit));     memset(val, 0, sizeof(val));     int cnt = 1;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (!visit[i][j] && a[i][j] ==  . ) {           dfs(i, j, cnt);           cnt++;         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] ==  * ) {           int temp = 1, t[5] = {0};           if (b[i - 1][j] != -1 && i - 1 >= 0) {             t[0] = b[i - 1][j];           }           if (b[i][j - 1] != -1 && j - 1 >= 0) {             t[1] = b[i][j - 1];           }           if (b[i + 1][j] != -1 && i + 1 < n) {             t[2] = b[i + 1][j];           }           if (b[i][j + 1] != -1 && j + 1 < m) {             t[3] = b[i][j + 1];           }           sort(t, t + 4);           for (int k = 0; k < 4; k++) {             if (t[k] != t[k + 1]) {               temp += val[t[k]];             }           }           a[i][j] =  0  + (temp) % 10;         }       }     }     for (int i = 0; i < n; i++) {       cout << a[i] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, cnt, a[220000];   long long sum;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int l = 1; l <= n; l++) {       sum = a[l + 1];       for (int r = l + 2; r <= n; r++) {         if (a[l] < a[r]) {           sum += a[r];           if (sum > (1 << ((int)log2(a[l]) + 1))) break;           continue;         }         if ((a[l] ^ a[r]) == sum) cnt++;         sum += a[r];         if (sum > (1 << ((int)log2(a[l]) + 1))) break;       }     }     reverse(a + 1, a + n + 1);     for (int l = 1; l <= n; l++) {       sum = a[l + 1];       for (int r = l + 2; r <= n; r++) {         if (a[l] <= a[r]) {           sum += a[r];           if (sum > (1 << ((int)log2(a[l]) + 1))) break;           continue;         }         if ((a[l] ^ a[r]) == sum) cnt++;         sum += a[r];         if (sum > (1 << ((int)log2(a[l]) + 1))) break;       }     }     printf( %d , cnt);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int k = 1;     int r = 0;     int index1, index2;     cin >> n;     vector<pair<pair<int, int>, pair<int, int>>> s(n);     vector<int> t(3);     for (int i = 0; i < n; i++) {       scanf( %i%i%i , &t[0], &t[1], &t[2]);       sort(t.begin(), t.end());       s[i].first.first = t[2];       s[i].first.second = t[1];       s[i].second.first = t[0];       s[i].second.second = i;       if (t[0] > r) {         index1 = i;         r = t[0];       }     }     sort(s.begin(), s.end());     for (int i = 0; i < s.size() - 1; i++) {       if (s[i].first.first == s[i + 1].first.first &&           s[i].first.second == s[i + 1].first.second) {         int temp = min(s[i].second.first + s[i + 1].second.first,                        min(s[i].first.first, s[i].first.second));         if (temp > r) {           r = temp;           index1 = s[i].second.second;           index2 = s[i + 1].second.second;           k = 2;         }       }     }     cout << k << endl;     if (k == 1) {       cout << index1 + 1 << endl;     } else       cout << index1 + 1 <<     << index2 + 1 << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize(3)   using namespace std;   const long long N = 210;   inline long long read() {     long long s = 0, w = 1;     register char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();     return s * w;   }   long long n, K, vis[N], g[N];   struct Node {     long long l, r;   } a[N];   inline bool Check(long long x, long long y) {     Node p = a[x], q = a[y];     if (p.l > q.l) swap(p, q);     return (q.l < p.r && p.r < q.r);   }   signed main() {     for (register long long T = read(); T; T--) {       memset(vis, 0, sizeof(vis));       n = read(), K = read();       for (register long long i = 1; i <= K; i++) {         a[i].l = read(), a[i].r = read();         if (a[i].l > a[i].r) swap(a[i].l, a[i].r);         vis[a[i].l] = vis[a[i].r] = 1;       }       long long m = 0;       for (register long long i = 1; i <= n * 2; i++) {         if (!vis[i]) g[++m] = i;       }       long long sz = n - K;       for (register long long i = 1; i <= sz; i++) {         a[++K] = (Node){g[i], g[i + sz]};       }       long long ans = 0;       for (register long long i = 1; i <= n; i++) {         for (register long long j = i + 1; j <= n; j++) {           if (Check(i, j)) ans++;         }       }       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[5010], b[5010], n, dp[5010];   int main() {     cin >> n;     for (long long i = 1ll; i <= n; i++) scanf( %I64d , &a[i]), b[i] = a[i];     sort(b + 1ll, b + n + 1ll);     dp[0ll] = (long long)1000000000000000007;     for (long long i = 1ll; i <= n; i++) {       for (long long j = 1ll; j <= n; j++) {         dp[j] = min(dp[j - 1ll], dp[j] + abs(b[j] - a[i]));       }     }     cout << dp[n] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 1123;   const int INF = 0x3f3f3f3f;   const long long MOD = 1000000007;   const double EPS = 1e-9;   const double PI = acos(-1);   inline int cmp(double x, double y = 0, double tol = EPS) {     return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;   }   struct point {     double x, y;     point(double a, double b) : x(a), y(b) {}     point() : x(0.0), y(0.0) {}     point operator+(point q) { return point(x + q.x, y + q.y); }     point operator-(point q) { return point(x - q.x, y - q.y); }     point operator*(double t) { return point(x * t, y * t); }     point operator/(double t) { return point(x / t, y / t); }     double operator*(point q) { return x * q.x + y * q.y; }     double operator^(point q) { return x * q.y - y * q.x; }     double polar() { return ((y > -EPS) ? atan2(y, x) : 2 * PI + atan2(y, x)); }     double mod() { return sqrt(x * x + y * y); }     double mod2() { return (x * x + y * y); }     point rotate(double t) {       return point(x * cos(t) - y * sin(t), x * sin(t) + y * cos(t));     }     int cmp(point q) const {       if (int t = ::cmp(x, q.x)) return t;       return ::cmp(y, q.y);     }     bool operator==(point q) const { return cmp(q) == 0; }     bool operator!=(point q) const { return cmp(q) != 0; }     bool operator<(point q) const { return cmp(q) < 0; }   };   int n, tam;   point P[MAX];   point Q[MAX * MAX];   inline int ccw(point p, point q, point r) { return cmp((q - r) ^ (p - r)); }   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     cin.sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 0; i < n; i++) cin >> P[i].x >> P[i].y;     if (P[0].x == P[1].x) {       tam = 0;       if (P[1].y > P[0].y) {         for (int i = P[0].y; i <= P[1].y; i++) Q[tam++] = point(P[0].x, i);       } else {         for (int i = P[0].y; i >= P[1].y; i--) Q[tam++] = point(P[0].x, i);       }     } else if (P[0].y == P[1].y) {       tam = 0;       if (P[1].x > P[0].x) {         for (int i = P[0].x; i <= P[1].x; i++) Q[tam++] = point(i, P[0].y);       } else {         for (int i = P[0].x; i >= P[1].x; i--) Q[tam++] = point(i, P[0].y);       }     } else {       tam = 0;       int g = gcd((int)(abs(P[0].y - P[1].y)), (int)(abs(P[0].x - P[1].x)));       int p = (P[0].y - P[1].y) / g;       int q = (P[0].x - P[1].x) / g;       for (int i = P[0].x; q ? (i <= P[1].x) : (i >= P[1].x); i += q)         Q[tam++] = point(i, P[0].y + ((i - P[0].x) * p) / q);     }     int st = 0, ed = tam - 1;     fprintf(stderr,  %d %d n , st, ed);     for (int i = 1; i < n; i++) {       while (st <= ed && ccw(P[i], P[(i + 1) % n], Q[st]) < 0) st++;       while (ed >= st && ccw(P[i], P[(i + 1) % n], Q[ed]) < 0) ed--;     }     cout << max(ed - st + 1, 0) <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int arr[100005];   int lfl[100005];   int rfl[100005];   int main() {     int n;     cin >> n;     int i, j;     for (i = 1; i <= n; i++) {       cin >> arr[i];     }     for (i = 1; i <= n; i++) {       lfl[i] = min(lfl[i - 1] + 1, arr[i]);     }     long long ans = INT_MIN;     for (i = n; i >= 1; i--) {       rfl[i] = min(rfl[i + 1] + 1, arr[i]);       ans = (long long)max(ans, (long long)min(lfl[i], rfl[i]));     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B>   ostream &operator<<(ostream &os, const pair<A, B> &p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename T_container, typename T = typename enable_if<                                       !is_same<T_container, string>::value,                                       typename T_container::value_type>::type>   ostream &operator<<(ostream &os, const T_container &v) {     os <<  [ ;     string sep;     for (const T &x : v) os << sep << x, sep =  ,  ;     return os <<  ] ;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << H;     debug_out(T...);   }   void run_case() {     int N;     cin >> N;     vector<int> A(N);     for (int &a : A) cin >> a;     int MX = *max_element(A.begin(), A.end()) / 3 + 100;     int best = MX;     for (int ones = 0; ones <= 2; ++ones)       for (int twos = 0; twos <= 2; ++twos) {         int threes = 0;         for (int a : A) {           int least = MX;           for (int one = 0; one <= ones; ++one)             for (int two = 0; two <= twos; ++two) {               int want = a - two * 2 - one;               if (want % 3 != 0 || want < 0) continue;               least = min(least, want / 3);             }           threes = max(threes, least);         }         best = min(best, ones + twos + threes);       }     cout << best <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int tests;     cin >> tests;     while (tests--) run_case();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, s = 0;     cin >> n;     int arr[n];     for (int i = 0; i < n; i++) {       cin >> arr[i];       s += arr[i];     }     int count = 0, k = 0;     for (int i = 0; i < n - 1; i++) {       k += arr[i];       if (k == (s - k)) count++;     }     cout << count;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     vector<int> lucky;     for (int i = 1; i <= 9; i++) {       for (int j = 0; j < (1 << i); j++) {         int num = 0;         for (int k = 0; k < i; k++) {           if (j & (1 << k))             num = num * 10 + 7;           else             num = num * 10 + 4;         }         lucky.push_back(num);       }     }     sort(lucky.begin(), lucky.end());     int n;     cin >> n;     for (int i = 0; i < lucky.size(); i++) {       if (lucky[i] == n) {         cout << i + 1;         break;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, x, y;     cin >> n >> x >> y;     long long chis = y - n + 1;     if (n - 1 + chis * chis >= x && chis > 0) {       for (long long i = 0; i < n - 1; i++) cout <<  1  <<   n ;       cout << chis;     } else       cout <<  -1 ;     return 0;   }
#include <bits/stdc++.h>   class arr {     bool* marked;     int* nummarked;     int markednumber;       public:     arr() {       marked = new bool[1000000];       for (int i = 0; i < 1000000; i++) {         marked[i] = false;       }       nummarked = new int[1000];       for (int i = 0; i < 1000; i++) {         nummarked[i] = 0;       }       markednumber = 0;     }     void mark(int i) {       marked[i] = true;       nummarked[i / 1000]++;       markednumber++;     }     int position(int i) {       int pr = 0;       for (int j = 0; j < (i / 1000); j++) {         pr += 1000;         pr -= nummarked[j];       }       for (int j = (i / 1000 * 1000); j < i; j++) {         if (!marked[j]) {           pr++;         }       }       return pr;     }     int number(int i) {       int sh = 0;       int tek = 0;       while ((i - sh - (1000 - nummarked[tek / 1000])) >= 0) {         sh += (1000 - nummarked[tek / 1000]);         tek += 1000;       }       while (i > sh) {         if (!marked[tek]) {           sh++;         }         tek++;       }       while (marked[tek]) tek++;       return tek;     }   };   const int max = 200000;   int main() {     int n;     scanf( %d , &n);     int* p1 = new int[n];     int* p2 = new int[n];     for (int i = 0; i < n; i++) scanf( %d , (p1 + i));     for (int i = 0; i < n; i++) scanf( %d , (p2 + i));     int* i1 = new int[max];     {       arr ist;       for (int i = 0; i < (n - 1); i++) {         i1[i] = ist.position(p1[i]);         ist.mark(p1[i]);       }     }     int* i2 = new int[max];     {       arr ist2;       for (int i = 0; i < (n - 1); i++) {         i2[i] = ist2.position(p2[i]);         ist2.mark(p2[i]);       }     }     int* is = new int[max];     for (int i = 0; i < (n - 1); i++) {       is[i] = i1[i] + i2[i];     }     for (int j = (n - 2); j > 0; j--) {       while (is[j] > (n - 1 - j)) {         is[j] -= (n - j);         is[j - 1]++;       }     }     while (is[0] > (n - 1)) {       is[0] -= n;     }     int* ps = new int[n];     for (int i = 0; i < n; i++) {       ps[i] = 0;     }     arr ists;     for (int i = 0; i < (n - 1); i++) {       ps[i] = ists.number(is[i]);       ists.mark(ps[i]);     }     ps[n - 1] = ists.number(0);     for (int i = 0; i < n; i++) {       printf( %d  , ps[i]);     }     return 0;   }
#include <bits/stdc++.h>   int main(void) {     int n, w;     int el[(4 * 100 * 1000)], be[(4 * 100 * 1000)];     int k[(4 * 100 * 1000)];     int i, j, z;     scanf( %d %d , &n, &w);     if (w == 1) {       printf( %d n , n);       return 0;     }     n--;     for (i = 0; i <= n; i++) {       if (i == 0) {         scanf( %d , &z);       } else {         scanf( %d , &j);         be[i - 1] = j - z;         z = j;       }     }     w--;     for (i = 0; i <= w; i++) {       if (i == 0) {         scanf( %d , &z);       } else {         scanf( %d , &j);         el[i - 1] = j - z;         z = j;       }     }     i = 0;     j = -1;     k[0] = -1;     while (i < w) {       while (j >= 0 && el[i] != el[j]) j = k[j];       i++;       j++;       k[i] = j;     }     i = 0;     j = 0;     z = 0;     while (i < n) {       while (j >= 0 && be[i] != el[j]) j = k[j];       i++;       j++;       if (j == w) {         z++;         j = k[j];       }     }     printf( %d n , z);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   ifstream fin( AAtest.in.txt );   long long n, p, t[4][ T ], su;   string s;   int main() {     ios::sync_with_stdio(0);     cin >> n;     for (int(i) = (0); ((i)) < ((n)); ((i))++) {       cin >> s;       p = s.size();       p--;       t[p][s[p]]++;       su++;     }     for (int(i) = (0); ((i)) < ((n)); ((i))++) {       cin >> s;       p = s.size();       p--;       su -= abs(t[p][s[p]]);       t[p][s[p]]--;       su += abs(t[p][s[p]]);     }     cout << su / 2;   }
#include <bits/stdc++.h>   using namespace std;   void solve(void) {     int N;     long int s = 0;     cin >> N;     for (int i = 2; i <= N; i++) s += i - 1;     cout << s * 6 * 2 + 1 << endl;   }   int main(int argc, char const *argv[]) {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   vector<string> v;   set<string> st;   map<string, int> mp;   int main() {     char t[11];     int c;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       memset(t,   0 , sizeof(t));       scanf( %s , t);       if (st.count(t) == 0) {         st.insert(t);         v.push_back(t);         mp[t] = 1;       } else         mp[t]++;     }     int cur = mp[v[0]];     string res = v[0];     for (int i = 1; i < v.size(); i++)       if (mp[v[i]] > cur) res = v[1];     printf( %s , res.c_str());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k;   long long cnt, sum, mx, ans = 0;   bool flag, gov[1010], vis[1010];   vector<int> vec, edges[1010];   void dfs(int u) {     vis[u] = 1;     for (int v : edges[u])       if (!vis[v]) dfs(v);     ++cnt;     flag |= gov[u];   }   int main() {     int u, v, i;     cin >> n >> m >> k;     for (i = 0; i < k; ++i) {       scanf( %d , &u);       gov[u] = 1;     }     for (i = 0; i < m; ++i) {       scanf( %d %d , &u, &v);       edges[u].push_back(v);       edges[v].push_back(u);     }     for (i = 1; i <= n; ++i) {       if (vis[i]) continue;       cnt = flag = 0;       dfs(i);       ans += cnt * (cnt - 1) / 2;       if (flag)         mx = max(mx, cnt);       else         vec.push_back(cnt);     }     for (int v : vec) {       ans += mx * v;       mx += v;     }     cout << ans - m << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 4e18;   const long long MAX = 2e5 + 5;   const long long MOD = 1e9 + 7;   int n, m;   void exgcd(int a, int b, long long &c, long long &d) {     if (a == 0) {       c = 0;       d = 1;       return;     }     exgcd(b % a, a, d, c);     c -= b / a * d;   }   long long gcd(int a, int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   int g[MAX];   bool arv[MAX], avb[MAX];   int sz[MAX];   pair<int, int> ma[MAX];   vector<int> v;   vector<int> son[MAX];   void build() {     for (int i = 0; i < m; i++) {       g[i] = gcd(i, m);       sz[g[i]]++;       son[g[i]].push_back(i);     }     g[m] = m;     int x = m;     for (int i = 2; i <= sqrt(x); i++) {       if (x % i == 0) v.push_back(i);       while (x % i == 0) x /= i;     }     if (x > 1) v.push_back(x);   }   void read() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     build();     for (int i = 0; i < n; i++) {       int x;       cin >> x;       avb[x] = 1;       if (!x) avb[m] = 1;       sz[gcd(x, m)]--;     }   }   void dfs(long long x) {     if (arv[x]) return;     for (int i : v) {       if (i * x > m) break;       if (g[i * x] == i * x) {         dfs(i * x);         ma[x] = max(ma[x], {ma[i * x].first, i * x});       }     }     ma[x].first += sz[x];     ;     arv[x] = 1;   }   vector<int> ans;   void output() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout << ((long long)(ans).size()) <<   n ;     for (int i : ans) cout << i <<    ;     cout <<   n ;     ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     read();     for (int i = 1; i <= m; i++)       if (g[i] == i && !arv[i]) dfs(i);     long long now = 1, pre = 1;     long long cod;     while (now <= m) {       ;       for (long long i : son[now]) {         if (!avb[i]) {           long long r, y;           long long gc = gcd(pre, m);           exgcd(pre / gc, m / gc, r, y);           if (r < 0) r += m;           ans.push_back(i / gc * r % m);           pre = i;         }       }       if (ma[now].second) {         now = ma[now].second;       } else         break;     }     output();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1010000;   long long binpow(long long a, long long b, long long c) {     long long res = 1;     while (b) {       if (b & 1) res = (res * a) % c;       a = (a * a) % c;       b >>= 1;     }     return res;   }   int gcd(int a, int b) {     if (!b) return a;     return gcd(b, a % b);   }   int phi;   int lp[N], pr[N], k = 0;   int cnt[N];   int n, m, mod, x;   long long go[N];   vector<pair<int, int> > fact(int x) {     vector<pair<int, int> > res;     while (x > 1) {       if (res.size() > 0 && res[(int)res.size() - 1].first == lp[x])         res[(int)res.size() - 1].second++;       else         res.push_back(make_pair(lp[x], 1));       x /= lp[x];     }     return res;   }   long long f[N], inv[N];   long long C(int n, int m) {     if (n < m) return 0;     long long res = f[n];     res = (res * inv[m]) % phi;     res = (res * inv[n - m]) % phi;     return res;   }   long long ans[N];   int main() {     lp[0] = lp[1] = 1;     for (int i = 2; i <= 1000123; ++i) {       if (!lp[i]) {         lp[i] = i;         pr[++k] = i;       }       for (int j = 1; j <= k && pr[j] <= lp[i]; ++j) {         if ((long long)pr[j] * i > 1000123) break;         lp[pr[j] * i] = pr[j];       }     }     cin >> n >> m >> x >> mod;     for (int i = 1; i < mod; ++i) {       if (binpow(x, i, mod) == 1) {         phi = i;         break;       }     }     f[0] = inv[0] = 1;     for (int i = 1; i <= 1000123; ++i) {       f[i] = (f[i - 1] * i) % phi;       inv[i] = binpow(f[i], phi - 2, phi);     }     go[0] = 1;     for (int i = 1; i <= n; ++i) {       go[i] = (go[i - 1] + C(m, i)) % phi;     }     for (int i = 1; i <= n; ++i) {       ans[i] = binpow(x, go[i - 1], mod);     }     for (int i = n; i > 0; --i) printf( %lld  , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, len = 0, max = 0, flag = 1;     cin >> n;     string alpha =  abcdefghijklmnopqrstuvwxyz ;     vector<string> vs(n);     for (int i = 0; i < n; i++) cin >> vs[i];     for (auto i : alpha) {       for (auto j : alpha) {         len = 0;         for (auto k : vs) {           flag = 1;           for (auto l : k) {             if (l != i && l != j) {               flag = 0;               break;             }           }           if (flag) len += k.size();         }         if (len > max) max = len;       }     }     cout << max;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int arr[105];       for (int i = 0; i < n; i++) {         cin >> arr[i];       }       int visited[105] = {0};       for (int i = 0; i < n; i++) {         visited[arr[i]]++;       }       int flag1 = -1;       int flag2 = -1;       for (int i = 0; i < 105; i++) {         if (visited[i] == 1 and flag1 == -1) {           flag1 = i;         }         if (visited[i] == 0 and flag1 == -1) {           flag1 = i;           flag2 = i;           break;         } else if (visited[i] == 0 and flag1 != -1) {           flag2 = i;           break;         }       }       cout << flag1 + flag2 << endl;     }   }