solution
stringlengths
11
983k
difficulty
int64
0
21
language
stringclasses
2 values
#include <bits/stdc++.h> using namespace std; bool comp(int x, int y) { return x > y; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int t = 1; cin >> t; long long m, n, k; while (t--) { cin >> n; int arr[101] = {0}; for (long long i = 0; i < n; i++) { int input; cin >> input; arr[input] += 1; } if (arr[0] == 0) { cout << 0 << '\n'; } else { int n1 = -1, n2 = -1; int flag = 0; for (long long i = 0; i < 101; i++) { if (flag == 0) { if (arr[i] == 0) { n1 = n2 = i; break; } else if (arr[i] == 1) { n1 = i; flag = 1; } } else { if (arr[i] == 0) { n2 = i; break; } } } if (n2 == -1) n2 = 101; cout << n1 + n2 << '\n'; } } }
7
CPP
for _ in range(int(input())): n = int(input()) a = list(map(int,input().split())) mp = [0]*101 for i in range(n): mp[a[i]] += 1 ans = 0 k = 2 # mx = max(a) # print(mp) for i in range(101): if k <= 0: break if mp[i] == 1 and k == 2: ans += i k-=1 elif k == 1 and mp[i] == 0 : ans += i k -= 1 elif mp[i] == 0 and k == 2: ans += (i*2) k -= 2 print(ans)
7
PYTHON3
import sys def get_ints(): return map(int, sys.stdin.readline().strip().split()) def get_array(): return list(map(int, sys.stdin.readline().strip().split())) def input(): return sys.stdin.readline().strip() for _ in range(int(input())): n=int(input()) arr = get_array() dic = {} m=max(arr) # print(m) for i in range(0,m+2): # print(i) dic[i]=0 for i in arr: dic[i]+=1 ans=0 flag=0 for i in dic.keys(): if(flag==1 and dic[i]==0): ans+=i # print('ans',ans) # print('f') break # print('key',i,dic[i]) if(dic[i]==0 and flag!=1): ans=i+i # print('s') break elif(dic[i]==1 and flag!=1): flag=1 ans+=i # print('t') # print('ans',ans) print(ans)
7
PYTHON3
T=lambda: range(int(input())) A=lambda : list(map(int,input().split())) for _ in T() : n=int(input()) a=A() a.sort() p=[0]*101 for i in a : p[i]+=1 i=0 acn=0 bcn=0 st=True while True : if not(p[i]) : acn=i if st : bcn=i break elif p[i]>1 : acn+=1 if st : bcn+=1 elif p[i]>0 : acn+=1 st=False i+=1 print(acn+bcn)
7
PYTHON3
for ii in range(int(input())): n=int(input()) a = (list(map(int , input().split()))) m=max(a) x=0 for i in range(m+2): if i not in a: x+=i break else: a.remove(i) x1=0 for i in range(m+2): if i not in a: x1+=i break print(x+x1)
7
PYTHON3
t = int(input()) for _ in range(t): n = int(input()) s = list(map(int, input().split())) s.sort() a = [s[0]] b = [] if min(s) != 0: print(0) else: for i in range(1, n): if s[i] - a[-1] == 1: a.append(s[i]) else: b.append(s[i]) ans1 = max(a) + 1 if len(b) == 0: ans2 = 0 else: if min(b) != 0: ans2 = 0 elif len(b) == 1: ans2 = 1 else: ans2 = 1 for k in range(len(b) - 1): if b[k+1] - b[k] != 1 and b[k+1] - b[k] != 0: break ans2 = b[k+1] + 1 ans = ans1 + ans2 print(ans)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; template <class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; } long long POW(long long a, long long p, long long M) { if (!p) return 1LL; long long T = POW(a, p / 2, M); T = T * T % M; if (p & 1) T = T * (a % M) % M; return T; } long long SQRT(long long a) { long long b = (long long)sqrtl(((double)a) + 0.5); while (b * b < a) ++b; while (b * b > a) --b; return (b * b == a) ? b : -1; } const long long MOD = 1e9 + 7; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.precision(10); cout << fixed; int t; cin >> t; while (t--) { int n; cin >> n; int cnt[101]; memset(cnt, 0, sizeof(cnt)); for (int i = 0; i < n; i++) { int a; cin >> a; cnt[a]++; } int ans = 0; int a, b; a = b = 101; for (int i = 0; i <= 100; i++) { if (cnt[i] >= 2) continue; else if (cnt[i] == 1) { if (b == 101) b = i; } else { if (b == 101) b = i; a = i; break; } } ans = a + b; cout << ans << endl; } cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n"; return 0; }
7
CPP
for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) a=[] b=[] f1=-1 l.sort() f2=-1 for i in l: if(len(a)==0): a.append(i) elif i in a: if(i not in b): b.append(i) elif i not in a: a.append(i) a.sort() b.sort() for i in range(len(a)): if(a[i]!=i): f1=i break for i in range(len(b)): if(b[i]!=i): f2=i break if(f1==-1): f1=len(a) if f2==-1: f2=len(b) print(abs(f2+f1))
7
PYTHON3
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) T = int(input()) for _ in range(T): N = int(input()) Xs = list(mapint()) Xs.sort() x1 = 0 for i in range(100): if i in Xs: x1 += 1 Xs.remove(i) else: break x2 = 0 for i in range(100): if i in Xs: x2 += 1 Xs.remove(i) else: break print(x1+x2)
7
PYTHON3
cases=int(input("")) list1=[] list2=[] output=[] mex=0 flag=0 for case in range(cases): size=int(input("")) x=input("").split() if size == 1: if int(x[0]) == 0: output.append(1) continue else: output.append(0) continue if size ==2 and x[0]=='0' and x[1]=='0': output.append(2) continue for c in range(size): list1.append(int(x[c])) list1.sort() for c in range(size-1): if list1[c] == list1[c+1]: list2.append(list1[c]) #for c in range (0,size): # falg=0 # for i in range (c+1,size-1): # if list1[c] == list1[i]: # flag=1 # if flag == 1: # list2.append(list1[c]) list2=set(list2) list1=set(list1) list2=list(list2) list1=list(list1) list1.sort() list2.sort() #print(list1) #print(list2) for c in range(105): if list1[c] != c : mex+=c break if c == len(list1)-1: mex+=list1[len(list1)-1]+1 break for z in range(105): if len(list2) == 0 : break if list2[z] != z : mex+=z break if z == len(list2)-1: mex+=list2[len(list2)-1]+1 break output.append(mex) mex=0 list1=[] list2=[] flag=0 print(*output,sep="\n")
7
PYTHON3
totLoop = int(input()) for x in range (totLoop): z = int(input()) y = list(map(int, input().split())) y.sort() dict = {} for i in y: if str(i) in dict: dict[str(i)] += 1 else: dict[str(i)] = 1 listValue = list(dict.keys()) mexA = 0 mexB = 0 checkVal = 0 oneElementFlag = 0 for p in listValue : if p != str(checkVal) : break else: checkVal += 1 if dict[p] > 1: mexA += 1 if oneElementFlag != 1: mexB += 1 else: oneElementFlag = 1 mexA += 1 print(mexA + mexB)
7
PYTHON3
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) if n == 1: if arr[0] != 0: print("0") else: print("1") continue arr.sort() if arr[0] != 0: print("0") continue set1 = [0] set2 = [] el1 = 1 el2 = 0 for i in range(1, n): if arr[i] == set1[-1]: set2.append(arr[i]) if arr[i] == el2: el2 += 1 else: set1.append(arr[i]) if arr[i] == el1: el1 += 1 print(el1 + el2)
7
PYTHON3
for _ in range(int(input())): n=int(input()) arr=list(map(int,input().split())) kls= [0]*101 for i in arr: kls[i]+=1 s1=0 s2=0 for i in range(101): if kls[i]: s1+=1 else: break for i in range(101): if kls[i]>=2: s2+=1 else: break print(s1+s2)
7
PYTHON3
from collections import defaultdict from collections import Counter import math def solve(n,A): m = max(A) ans = 0 freq = Counter(A) fa = [0]*(110) for i,v in freq.items(): fa[i] = v k = 2 while k!= 0: i = 0 while fa[i] != 0: fa[i]-=1 i+=1 ans += (i) k -=1 return ans t = int(input()) while t: res = [] n = int(input()) in_ = map(int,input().split(" ")) for x in in_: res.append(int(x)) print(solve(n,res)) t-=1
7
PYTHON3
def ans(n, arr): d = dict() for i in range(n): d[arr[i]] = d.get(arr[i], 0) + 1 # we created a dictionary of occurence of elements # make a variable which will decide if we will append to B or not flag = 0 a, b = 0, 0 for i in range(n): x = d.get(i, 0) if x >= 2: a += 1 if flag == 0: b += 1 elif x == 1: a += 1 flag = 1 elif x == 0: break return a + b t = int(input()) L = [] for i in range(t): n = int(input()) arr = [int(x) for x in input().split()] L.append(ans(n, arr)) for l in L: print(l)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; using db = double; using ll = long long; using ull = unsigned long long; using pII = pair<int, int>; using pLL = pair<ll, ll>; int main() { int T; cin >> T; while (T--) { ll n, c = 0; cin >> n; ll a[n]; map<ll, ll> m, m1; for (int i = 1; i <= n; i++) { cin >> a[i]; m[a[i]] = -1; m1[a[i]]++; } ll Rekhe_De = 0; ll Rekhe_de = 0; for (int i = 0; i <= 101; i++) { if (m[i] == 0 && c == 0) { Rekhe_De = i; ++c; break; } else if (m1[i] > 0) m1[i]--; } for (int i = 0; i <= 101; ++i) { if (m1[i] == 0) { Rekhe_de = i; break; } } cout << Rekhe_De + Rekhe_de << endl; } }
7
CPP
import bisect from collections import Counter,defaultdict,deque from sys import stdin, stdout input = stdin.readline I =lambda:int(input()) M =lambda:map(int,input().split()) LI=lambda:list(map(int,input().split())) for _ in range(I()): n=I() arr=LI() arr.sort() c=0 if arr[0]!=0: print(0) else: dic=Counter(arr) brr=[] crr=[] for i in dic.keys(): if dic[i]>=2: brr+=[i] crr+=[i] elif dic[i]==1: brr+=[i] flag=1 for i in range(len(crr)): if i!=crr[i]: c+=i;flag=0;break if i==len(crr)-1 and flag: c+=(i+1) flag=1 for j in range(len(brr)): if j!=brr[j]: c+=j;flag=0;break if j==len(brr)-1 and flag: c+=(j+1) print(c)
7
PYTHON3
for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) freq = [0] * 101 for i in l: freq[i] += 1 #print(freq) ans = 0 for i in range(len(freq)): if freq[i] >= 2: continue else: if freq[i] == 0 : ans += i break for i in range(len(freq)): if freq[i] <= 1: ans += i break print(ans)
7
PYTHON3
num_cases = int(input()) for i in range(num_cases): case_len = input() case_str = input() integers = list(map(int, case_str.split(' '))) max_integer = max(integers) # print('max', max_integer) max_sum = 0 max_sum_count = 0 for j in range(max_integer + 2): j_count = integers.count(j) if j_count == 0: if max_sum_count == 0: max_sum += j max_sum_count += 1 # print('+ +', j, max_sum_count) max_sum += j max_sum_count += 1 # print('++', j, max_sum_count) if j_count == 1 and max_sum_count == 0: max_sum += j max_sum_count += 1 # print('+', j, max_sum_count) if max_sum_count > 1: break print(max_sum)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; while (T--) { int n; cin >> n; int a[n], b[101] = {0}; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { b[a[i]]++; } int x = 0, y = 0; for (int i = 0; i < 101; i++) { if (b[i] == 1 || b[i] == 0) { x = i; break; } } for (int i = 0; i < 101; i++) { if (b[i] == 0) { y = i; break; } } cout << x + y << endl; } return 0; }
7
CPP
from collections import deque from math import * t = int(input()) for _ in range(t): n = int(input()) arr = sorted([int(p) for p in input().split()]) count = {} for i in range(len(arr)): try: count[arr[i]] += 1 except KeyError: count[arr[i]] = 1 a1 = [] a2 = [] for i in count: a1.append(i) count[i] -= 1 for i in count: if count[i] > 0: a2.append(i) c1 = 0 c2 = 0 for i in range(len(a1)): if a1[i] != i: c1 = i break if i == len(a1) - 1: c1 = i+1 for i in range(len(a2)): if a2[i] != i: c2 = i break if i == len(a2) - 1: c2 = i+1 print(c1+c2)
7
PYTHON3
def findMax(l): l = sorted(set(l)) for i in range(len(l) + 1): if i >= len(l): return i if i != l[i]: return i for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) d = {} for i in l: if i in d: d[i] += 1 else: d[i] = 1 a = [] b = [] for i in range(0, 101): if i in d: a.append(i) d[i] -= 1 if d[i] != 0: b.append(i) # print(a,b) print(findMax(a) + findMax(b))
7
PYTHON3
for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) l.sort() freq=101*[0] for i in l: freq[i]+=1 ans=0 c=0 for i in range(101): if freq[i]<2: ans+=i break add=0 import bisect for i in range(102): j=bisect.bisect_left(l,i) if j==len(l) or l[bisect.bisect_left(l,i)]!=i: add=i break print(ans+add)
7
PYTHON3
from collections import Counter for _ in range(int(input())): n = int(input()) l = list(map(int,input().split())) cc = Counter(l) x,y=0,0 for i in range(101): if cc[i]>=2: continue else: x=i y=i break d=i for i in range(d,101): if cc[i]>=1: continue else: x=i break print(x+y)
7
PYTHON3
n=int(input()) for i in range(n): l=int(input()) a=[int(x) for x in input().split()] b=-1 c=-1 for j in range(101): if a.count(j)<2: b=j break for j in range(101): if a.count(j)<1: c=j break print(b+c)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; istream& inp = cin; template <typename T> vector<T> readV(int64_t size) { vector<T> result; for (int64_t i = 0; i < size; ++i) { T x; inp >> x; result.push_back(x); } return result; } template <typename T> T divup(T a, T b) { if ((a % b) == 0) return a / b; return 1 + a / b; } template <typename T> pair<T, T> gcdl(T a, T b) { if (0 == b) return {1, 0}; if (a < b) { auto p = gcdl(b, a); return {p.second, p.first}; } auto p = gcdl(a % b, b); return {p.first, p.second - p.first * (a / b)}; } int64_t constexpr M = 1000000007; static_assert(M <= (1 << 30)); class modint { int64_t v; public: modint(int64_t x) : v(x % M) {} int64_t get() const { return v; } modint operator+(modint b) { return modint(v + b.v); } modint operator*(modint b) { return modint(v * b.v); } modint operator-(modint b) { return modint(v + M - b.v); } modint operator/(modint b) { auto p = gcdl(b.get(), M); assert(1 == int64_t(p.first) * b.get() + int64_t(p.second) * M); int64_t x = p.first + int64_t(M) * M; return *this * modint(x); } }; int32_t main() { int64_t ntests; assert(inp); inp >> ntests; for (int64_t test = 0; test < ntests; ++test) { int64_t n; inp >> n; const auto a = readV<int64_t>(n); vector<int64_t> count(102, 0); for (int64_t x : a) ++count.at(x); int64_t mex1 = 0; while (mex1 < count.size() && count.at(mex1) >= 2) ++mex1; int64_t mex2 = 0; while (mex2 < count.size() && count.at(mex2) >= 1) ++mex2; cout << mex1 + mex2 << endl; } return 0; }
7
CPP
from math import * from bisect import * from collections import * from random import * from decimal import * import sys input=sys.stdin.readline def inp(): return int(input()) def st(): return input().rstrip('\n') def lis(): return list(map(int,input().split())) def ma(): return map(int,input().split()) t=inp() while(t): t-=1 n=inp() a=lis() co=[0]*(102) for i in a: co[i]+=1 a=[] b=[] a.sort() po=0 fl=0 s=0 for i in range(101): if(co[i]>=2): continue if(co[i]==0): if(fl==0): s+=2*i else: s+=i break elif(fl==0 and co[i]==1): fl=1 s+=i elif(fl==1 and co[i]==0): s+=i break print(s)
7
PYTHON3
t = int(input()) for i in range(t): n = int(input()) a = list(map(int, input().split())) a.sort() for j in range(101): if j not in a: mex_a = j break if j in a: a.remove(j) for j in range(101): if j not in a: mex_b = j break print(mex_a + mex_b)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n, t, temp, t1, t2, count; cin >> t; while (t--) { cin >> n; count = 0; map<int, int> a, b, c; for (int i = 0; i < n; ++i) { cin >> temp; a[temp]++; } auto it = a.begin(); while (it != a.end()) { count = it->second; if (count >= 2) { b[it->first]++; c[it->first]++; } else b[it->first]++; it++; } temp = 0; it = b.begin(); while (it != b.end()) { if (it->first == temp && it->second != 0) { for (int i = temp + 1;; ++i) { if (b[i] == 0) { temp = i; break; } } } it++; } t1 = temp; temp = 0; it = c.begin(); while (it != c.end()) { if (it->first == temp && it->second != 0) { for (int i = temp + 1;; ++i) { if (c[i] == 0) { temp = i; break; } } } it++; } t2 = temp; cout << t1 + t2 << endl; } return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; const int N = 100005; void solve() { long long int n; cin >> n; long long int a[n]; long long int fre[200]; memset(fre, 0, sizeof(fre)); for (long long int i = 0; i < n; i++) { cin >> a[i]; fre[a[i]]++; } long long int last = -1; for (long long int i = 0; i < 105; i++) { if (fre[i] == 0) { last = i; break; } } long long int last1 = -1; for (long long int i = 0; i < last; i++) { fre[i]--; } for (long long int i = 0; i < 105; i++) { if (fre[i] == 0) { last1 = i; break; } } cout << last1 + last << "\n"; } int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); srand(time(NULL)); ; int t = 1; cin >> t; for (int i = 1; i <= t; i++) { solve(); } }
7
CPP
#include <bits/stdc++.h> struct MI { private: char bb[4096]; FILE* f; char *bs, *be; char e; bool o, l; public: MI() : f(stdin) {} MI(FILE* f) : f(f), bs(0), be(0) {} MI(const char* s) : f(fmemopen(const_cast<char*>(s), strlen(s), "r")) {} inline operator bool() { return !l; } inline char get() { if (o) { o = 0; return e; } if (bs == be) be = (bs = bb) + fread(bb, 1, sizeof(bb), f); if (bs == be) { l = 1; return -1; }; return *bs++; } inline void unget(char c) { o = 1; e = c; } template <typename T> inline T read() { T r; *this > r; return r; } template <typename T> inline MI& operator>(T&); }; template <typename T> struct Q { const static bool U = T(-1) >= T(0); inline void operator()(MI& t, T& r) const { r = 0; char c; bool y = 0; if (U) for (;;) { c = t.get(); if (c == -1) goto E; if (isdigit(c)) break; } else for (;;) { c = t.get(); if (c == -1) goto E; if (c == '-') { c = t.get(); if (isdigit(c)) { y = 1; break; }; } else if (isdigit(c)) break; ; }; for (;;) { if (c == -1) goto E; if (isdigit(c)) r = r * 10 + (c ^ 48); else break; c = t.get(); } t.unget(c); E:; if (y) r = -r; } }; template <> struct Q<char> { inline void operator()(MI& t, char& r) { int c; for (;;) { c = t.get(); if (c == -1) { r = -1; return; }; if (!isspace(c)) { r = c; return; }; } } }; template <typename T> inline MI& MI::operator>(T& t) { Q<T>()(*this, t); return *this; } template <typename T> std::ostream& operator<(std::ostream& out, const T& t) { return out << t; } using std::cout; MI cin; const int nmax = 101; int n; int occ[nmax]; inline void work() { cin > n; memset(occ, 0, sizeof(occ)); for (int i = 1; i <= n; ++i) ++occ[(cin.read<int>())]; int l = 0; while (occ[l]) --occ[l++]; int r = 0; while (occ[r]) --occ[r++]; cout < (l + r) < ('\n'); } int main() { int T = (cin.read<int>()); while (T--) work(); return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int t, n; int main() { ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); cin >> t; while (t--) { int cnt[2], a[110]; bool b = false; fill(a, a + 101, 0); cin >> n; for (int i = 0; i < n; i++) { int inp; cin >> inp, a[inp]++; } for (int i = 0; i <= 100; i++) { if (a[i] == 1) cnt[b] = i, b = true; else if (!a[i] && !b) { cnt[0] = cnt[1] = i; break; } else if (b && a[i] <= 1) { cnt[b] = i; break; } } cout << cnt[0] + cnt[1] << '\n'; } return 0; }
7
CPP
t = int(input()) while t: n = int(input()) arr = list(map(int, input().split())) freq = [0 for i in range(101)] for i in arr: freq[i] += 1 b = c = -1 for i in range(101): if freq[i] > 0: freq[i] -= 1 else: b = i break for i in range(101): if freq[i] > 0: freq[i] -= 1 else: c = i break print(b+c) t -= 1
7
PYTHON3
from collections import defaultdict t = int(input()) for _ in range(t): n = int(input()) l = list(map(int,input().split())) hash = defaultdict(int) for i in l: hash[i]+=1 mexa = 0 mexb = 0 flag = 0 for i in range(n+1): if i in hash: if hash[i] == 1: mexa+=1 flag = 1 else: mexa+=1 if flag!=1: mexb+=1 else: break print(mexa+mexb)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; for (int testcases = 0; testcases < T; testcases++) { int n; cin >> n; vector<int> arr(n); vector<int> cnt(101); for (int i = 0; i < n; i++) { cin >> arr[i]; cnt[arr[i]]++; } int cnt1 = 0; bool both = true; int cnt2 = 0; for (int i = 0; i < 101; i++) { if (both && cnt[i] > 1) cnt1++; if (both && cnt[i] <= 1) { both = false; } if (!both && cnt[i] > 0) cnt2++; if (!both && cnt[i] == 0) break; } cout << cnt1 * 2 + cnt2 << endl; } }
7
CPP
#include <bits/stdc++.h> using namespace std; void process() { int n; cin >> n; vector<int> a(n); for (int &i : a) cin >> i; int ans = 0; sort(a.begin(), a.end()); int x = -1, y = -1; for (int i : a) { if (i == x + 1) { x++; } else { if (i == y + 1) { y++; } } } ans = x + y + 2; cout << ans << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { process(); } return 0; }
7
CPP
t = int(input()) for _ in range(t): n = int(input()) a=[] b=[] l = list(map(int,input().split())) l.sort() c1=0 c2=0 for i in l: if i not in a: a.append(i) elif i not in b: b.append(i) for i in range(len(a)): if c1==a[i]: c1+=1 else: break for i in range(len(b)): if c2 == b[i]: c2 += 1 else: break print(c1+c2)
7
PYTHON3
# 1406A.py from collections import defaultdict for _ in range(int(input())): n = int(input()) a = list(map(int,input().split())) a.sort() count = dict() count = defaultdict(lambda : 0,count) for i in range(n): count[a[i]]+=1 p = 0 while count[p]!=0: p+=1 # print(p) i = 0 while count[i]>1: i+=1 p+=i print(p)
7
PYTHON3
from collections import Counter t = int(input()) for _ in range(t): n = int(input()) a = Counter(map(int, input().split())) ans = 0 for i in range(101): if i in a and a[i]>0: a[i] -= 1 continue ans += i break for i in range(101): if i in a and a[i]>0: a[i] -= 1 continue ans += i break print(ans)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> v; for (int i = 0; i < n; i++) { int x; cin >> x; v.push_back(x); } sort(v.begin(), v.end()); int l = 0, r = 0; for (int i = 0; i < n; i++) { if (v[i] == l) l++; else if (v[i] == r) r++; } cout << l + r << endl; } return 0; }
7
CPP
import math import sys input = sys.stdin.readline if __name__ == '__main__': for _ in range(int(input())): n = int(input()) a = list(map(int, input().rstrip().split())) m1, m2 = -1, -1 for i in range(101): if m1!=-1 and m2 != -1: break c = a.count(i) if c == 0: if m1 == -1: m1 = m2 = i else: m2 = i if c == 1: if m1 == -1: m1 = i print(m1+m2)
7
PYTHON3
t = int(input()) while t != 0: n = int(input()) a = list(map(int, input().split()))[:n] b = [i for i in range(n)] net = [0] * 101 for i in range(n): net[a[i]] += 1 for i in range(101): if net[i] == 0: x = i break else: net[i] -= 1 for i in range(101): if net[i] == 0: y = i break else: net[i] -= 1 print(x + y) t -= 1
7
PYTHON3
t=int(input()) for q in range(0,t): n=int(input()) a=[int(i) for i in input().split()] b=[0]*(101) for i in range(0,n): b[a[i]]+=1 count=0 for i in range(0,101): if b[i]==0: count=i break for i in range(0,101): if b[i]<=1: count+=i break print(count)
7
PYTHON3
t=int(input()) for _ in range(t): a=[0]*101 b=[0]*101 n=int(input()) ls=list(map(int,input().split())) for i in ls: if(a[i]==1): b[i]=1 else: a[i]=1 # print(a) # print(b) ans=0 ind=0 flaga=0 flagb=0 while(ind<101 and (flaga!=1 or flagb!=1)): if(a[ind]==0 and flaga!=1): flaga+=1 ans+=ind if(b[ind]==0 and flagb!=1): flagb+=1 ans+=ind ind+=1 # print(flaga,flagb,ind) print(ans)
7
PYTHON3
t=int(input()) for _ in range(t): n=int(input()) l=list(map(int, input().split())) def mex(l): i=0 a=[] while i<n+1: if i in l: a.append(i) l.remove(i) i+=1 else: return i r1=mex(l) r2=mex(l) print(r1+r2)
7
PYTHON3
for _ in range(int(input())): n,lst,a,b = int(input()),sorted(list(map(int,input().split()))),0,0 for i in lst: if a == i:a+=1 elif b == i:b+=1 print(a+b)
7
PYTHON3
for _ in range(int(input())): N=int(input()) array=[int(x) for x in input().split()] checklist=[0 for i in range(200)] total=0 for i in array: checklist[i]+=1 for i in range(2): j=0 while checklist[j]: checklist[j]-=1 j+=1 total+=j print(total)
7
PYTHON3
import random def gcd(a, b): if a == 0: return b return gcd(b % a, a) def lcm(a, b): return (a * b) / gcd(a, b) for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) a.sort() curr=0 d={} ans=[] for i in a: if i not in d: d[i]=1 else: d[i]+=1 while(len(ans)<2): if curr in d: if d[curr]==1 and len(ans)==0: ans.append(curr) else: ans.append(curr) ans.append(curr) curr+=1 print(ans[0]+ans[1])
7
PYTHON3
n = int(input()) def mex(li): now = 0 if not li: return 0 while True: if now not in li: break now += 1 return now for _ in range(n): m = int(input()) li = list(map(int,input().split())) li.sort() a = [] b = [] for i in li: if i in a: b.append(i) else: a.append(i) print(mex(a)+mex(b))
7
PYTHON3
import sys import math from collections import defaultdict,Counter # input=sys.stdin.readline # def print(x): # sys.stdout.write(str(x)+"\n") # sys.stdout=open("CP1/output.txt",'w') # sys.stdin=open("CP1/input.txt",'r') # mod=pow(10,9)+7 t=int(input()) for i in range(t): n=int(input()) a=list(map(int,input().split())) c=Counter(a) ans=0 for j in range(101): if c.get(j,0)==0: ans+=2*j break elif c.get(j,0)==1: ans+=j for k in range(j+1,101): if c.get(k,0)==0: ans+=k break break print(ans)
7
PYTHON3
t=int(input()) for i in range(t): n=int(input()) arr=list(map(int,input().split())) lst1=[] lst2=[] for j in arr: if j in lst1: lst2.append(j) else: lst1.append(j) a=0 while a in lst1: a=a+1 if a==max(lst1)+1: break mex1=a b=0 while b in lst2: b=b+1 if b==max(lst2)+1: break mex2=b print(mex1+mex2)
7
PYTHON3
for _ in range(int(input())): a=[0]*105 input() for i in map(int,input().split()): a[i]+=1 ans=0 #print(a) for i in range(101): if a[i]<2: ans+=i break for i in range(101): if a[i]<1: ans+=i break print(ans)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { unordered_map<int, int> m; int n; cin >> n; for (int i = 0; i < n; i++) { int a; cin >> a; m[a]++; } int ans = 0; int i = 0; while (true) { if (m[i] >= 2) { ans += 2; } else if (m[i] == 1) { ans++; i++; while (m[i] > 0) { ans++; i++; } break; } else { break; } i++; } cout << ans << "\n"; } return 0; }
7
CPP
t = int(input()) for _ in range(t): n = int(input()) v = [0] * 110 for u in map(int,input().split()): v[u]+=1 mx = 0 for i in range(0,110): if v[i]<2: mx = i break if v[mx]==0: mx=2 * mx else: for i in range(mx+1,110): if v[i]<1: mx+=i break print(mx)
7
PYTHON3
import sys sys.setrecursionlimit(10**5) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def SI(): return sys.stdin.readline()[:-1] from collections import Counter for _ in range(II()): n=II() aa=LI() ac=Counter(aa) x=y=-1 for a in range(101): if x==-1 and ac[a]<2:x=a if y==-1 and ac[a]<1:y=a print(x+y)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; void solve() { int n, a; cin >> n; vector<int> cnt(102); for (int i = 0; i < n; i++) { cin >> a; cnt[a]++; } int ans = 0, x = 0, i = 0; while (i < 101 && cnt[i] >= 2) i++; if (cnt[i] == 0) { cout << 2 * i << endl; return; } ans = i; i++; while (i < 101 && cnt[i] >= 1) i++; ans += i; cout << ans << endl; } int main() { int T; cin >> T; while (T--) { solve(); } return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int MOD = 1e9 + 7; const int MX = 2e5 + 5; const ll INF = 1e18; const ld PI = acos((ld)-1); int main() { int t; cin >> t; while (t--) { vector<int> cnt(101); int n; cin >> n; for (int i = 0; i < n; i++) { int x; cin >> x; cnt[x]++; } int queda = 2; int sol = 0; for (int i = 0; i < 102 && queda > 0; i++) { if (cnt[i] == 0) { if (queda == 2) { queda -= 2; sol += (i * 2); } else { queda--; sol += i; } } else if (cnt[i] == 1 && queda == 2) { queda--; sol += i; } } cout << sol << '\n'; } }
7
CPP
import sys input = sys.stdin.readline ins = lambda: input().rstrip() ini = lambda: int(input().rstrip()) inm = lambda: map(int, input().rstrip().split()) inl = lambda: list(map(int, input().split())) out = lambda x, s='\n': print(s.join(map(str, x))) t = ini() for _ in range(t): n = ini() a = inl() first = second = -1 for i in range(101): if a.count(i) > 1: continue if a.count(i) == 1 and first == -1: first = i continue if a.count(i) == 0: first = i if first == -1 else first second = i break print(first+second)
7
PYTHON3
# cook your dish here t=int(input()) for _ in range(t): n=int(input()) a=sorted(list(map(int,input().split()))) list1=[] list2=[] for items in a : if items not in list1: list1.append(items) elif items not in list2: list2.append(items) x=-1 for i in range(0,len(list1)): x+=1 if list1[i]!=x: break if i==len(list1)-1: if x==list1[i]: x+=1 y=-1 if len(list2)==0: y=0 else: for i in range(0,len(list2)): y+=1 if list2[i]!=y: break if i==len(list2)-1: if y==list2[i]: y+=1 print(x+y)
7
PYTHON3
T = int(input()) from collections import Counter for _ in range(T): n = int(input()) a = list(map(int,input().split())) b = Counter(a) al,be = -1,-1 for i in range(102): if b[i] >= 2: continue elif b[i] == 1: if al == -1: al = i elif b[i] == 0: if al == -1: al,be = i,i print(al+be) break else: be = i print(al+be) break
7
PYTHON3
def mex(l): for i in range(101): if i not in l: return i for _ in range(int(input())): n = int(input()) x = list(map(int, input().split())) l1 = [] l2 = [] x.sort() for each in x: if each in l1: l2.append(each) else: l1.append(each) print(mex(l1) + mex(l2))
7
PYTHON3
for s in[*open(0)][2::2]: a=[0]*101 for x in s.split():a[int(x)]+=1 i=a.index(0);a[i]=1;print(i+a.index(1))
7
PYTHON3
res=[] for x in range(int(input())): a=int(input()) l=list(map(int,input().split())) m=set(l) ans1=[];ans2=[];fi=[];sec=[] for y in m: e=l.count(y) if e>1: sec.append(y) fi.append(y) else: fi.append(y) for t in range(len(sec)+1): if t not in sec: ans1.append(t) break if t==len(sec): ans1.append(t) break if len(sec)==0: d=0 ans1.append(d) for t in range(len(fi)+1): if t not in fi: ans2.append(t) break if t==len(fi): ans1.append(t) break if len(fi)==0: d=0 ans2.append(d) final=sum(ans1)+sum(ans2) res.append(final) for B in res: print(B)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int a[n]; int freq[101] = {0}; for (int i = 0; i < n; i++) { cin >> a[i]; freq[a[i]] += 1; } int ans = 0; int i; int f = 0; for (i = 0; i <= 100; i++) { if (freq[i] == 0) { ans = 2 * i; f = 1; break; } if (freq[i] == 1) { ans += i; break; } } if (i == 101) { cout << "202" << endl; continue; } if (f == 1) { cout << ans << endl; continue; } while (freq[i] >= 1 && i <= 100) { i += 1; } ans += i; cout << ans << endl; } }
7
CPP
t = int(input()) for _ in range(t): N = int(input()) a = list(map(int, input().split())) nums = [0] * 101 for i in range(N): nums[a[i]] += 1 now = 0 while nums[now] >= 2: now += 1 now2 = 0 while nums[now2] >= 1: now2 += 1 print(now+now2)
7
PYTHON3
t=int(input()) for _ in range(t): n=int(input()) l1=list(map(int,input().split())) l2=list(set(l1)) l3=[] l2.sort() x,y=min(l2),max(l2) ans=0 if x==0: f,c=0,0 for i in range(x,y+1): if i not in l2: c=i f=1 break if f==0: ans+=y+1 else: ans+=c if len(l1)!=len(l2): for i in l2: if l1.count(i)>1: l3.append(i) x,y=min(l3),max(l3) if x==0: f,c=0,0 for i in range(x,y+1): if i not in l3: c=i f=1 break if f==0: ans+=y+1 else: ans+=c print(ans)
7
PYTHON3
# @oj: codeforces # @id: hitwanyang # @email: [email protected] # @date: 2020-09-12 21:45 # @url:https://codeforc.es/contest/1406/problem/A import sys,os from io import BytesIO, IOBase import collections,itertools,bisect,heapq,math,string from decimal import * # region fastio BUFSIZE = 8192 BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # ------------------------------ ## 注意嵌套括号!!!!!! ## 先有思路,再写代码,别着急!!! ## 先有朴素解法,不要有思维定式,试着换思路解决 def main(): t=int(input()) for i in range(t): n=int(input()) a=list(map(int,input().split())) cnt=[0]*101 for x in a: cnt[x]+=1 ans=0 for j in range(len(cnt)): if cnt[j]==0: ans+=j break cnt[j]-=1 for j in range(len(cnt)): if cnt[j]==0: ans+=j break cnt[j]-=1 print (ans) if __name__ == "__main__": main()
7
PYTHON3
for _ in range(int(input())): n = int(input()) l = sorted(list(map(int, input().split()))) a = [0] b = [-1] bool = False if l[0] != 0: print(0) else: for num in range(n): if abs(l[num] - a[-1]) <= 1: if l.count(l[num]) < 2: a.append(l[num]) bool = True else: if bool == False: a.append(l[num]) b.append(l[num]) else: a.append(l[num]) else: break print(max(a)+1+max(b)+1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int a[105]; int t; cin >> t; while (t--) { memset(a, 0, sizeof(a)); int n; int b[105]; cin >> n; for (int i = 0; i < n; i++) { cin >> b[i]; a[b[i]]++; } int ans = 0; int len = 2; for (int i = 0; i < 102; i++) { if (len == 0) break; if (a[i] >= 2) continue; if (a[i] == 1) { if (len == 2) ans += i, len--; else if (len == 1) continue; } else if (a[i] == 0) { if (len == 2) ans += 2 * i, len -= 2; else if (len == 1) ans += i, len--; } } cout << ans << endl; } return 0; }
7
CPP
#include <bits/stdc++.h> int main() { int t; scanf("%d", &t); while (t--) { int arr[100], freq[101] = {0}, sum = 0, n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &arr[i]); } for (int x = 0; x < n; x++) { freq[arr[x]]++; } for (int j = 0; j < 101; j++) { if (freq[j] != 0) freq[j]--; else { sum = j; break; } } for (int j = 0; j < 101; j++) { if (freq[j] != 0) freq[j]--; else { sum = sum + j; break; } } printf("%d\n", sum); } }
7
CPP
for _ in range(int(input())): n = int(input()) l = list(map(int,input().split())) f = [] for i in range(101): f.append(0) for i in l: f[i]+=1 f1 = -1 f2 = 0 #print(f) for i in range(101): if f[i]==0: if f1==-1: f1 = i f2 = i break if f[i]==1: if f1==-1: f1=i print(f2+f1)
7
PYTHON3
test=int(input()) for i in range(0,test): n=int(input()) s=[int(i) for i in input().split(' ')] c=[] for i in range(0,102): c.append(0) for e in s: c[e]+=1 oi=-1 zi=-1 for i in range(0,102): if c[i]==1: oi=i break for i in range(0,102): if c[i]==0: zi=i break if oi==-1: print(2*zi) elif zi<oi: print(2*zi) else: print(zi+oi)
7
PYTHON3
t=int(input()) for _ in range(t): n=int(input()) l=list(map(int,input().split())) a,b=None,None d={} for i in range(101): d[i]=0 for i in l: d[i]=d[i]+1 for i in range(101): if d[i]<2: if d[i]==1: if a==None: a=i if d[i]==0: if a==None: a,b=i,i else: b=i if a!=None and b!=None: break print(a+b)
7
PYTHON3
for i in range(int(input())): n=int(input()) x=list(map(int,input().split())) x.sort() lst=list() lst1=list() c3=0 c2=0 for i in range(n): if x[i] in lst and x[i] in lst1: continue if x[i] not in lst: lst.append(x[i]) else: lst1.append(x[i]) for i in range(len(lst)): if i!=lst[i]: c=i c2=1 break if c2!=1: if len(lst)==0: c=0 else: c=lst[-1]+1 for i in range(len(lst1)): if i!=lst1[i]: c1=i c3=1 break if c3!=1: if len(lst1)==0: c1=0 else: c1=lst1[-1]+1 print(c+c1)
7
PYTHON3
def ans(A): d={} for i in A:d[i]=d.get(i,0)+1 ans=0 for i in range(105): if i not in d: ans+=i break else: d[i]-=1 if d[i]==0:del d[i] for i in range(105): if i not in d: ans+=i break else: d[i]-=1 if d[i]==0:del d[i] return ans T=int(input()) for i in range(T): n=int(input()) arr=list(map(int,input().strip().split(" "))) print(ans(arr))
7
PYTHON3
t = int(input()) for i in range(t): freq = [0 for i in range(101)] n = int(input()) a = list(map(int, input().split())) for num in a: freq[num] += 1 mexa = -1 for i, count in enumerate(freq): if count == 1 and mexa == -1: mexa = i elif count == 0: if mexa == -1: mexa = i mexb = i else: mexb = i break print(mexa + mexb)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; template <class L, class R> ostream& operator<<(ostream& os, pair<L, R> P) { return os << "(" << P.first << "," << P.second << ")"; } template <class T> ostream& operator<<(ostream& os, vector<T> V) { os << "[ "; for (auto v : V) os << v << " "; return os << "]"; } template <class T> ostream& operator<<(ostream& os, set<T> second) { os << "{ "; for (auto s : second) os << s << " "; return os << "}"; } template <class L, class R> ostream& operator<<(ostream& os, map<L, R> M) { os << "{ "; for (auto m : M) os << "(" << m.first << " : " << m.second << ") "; return os << "}"; } template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " |"; __f(comma + 1, args...); } void solve() { map<int, int> cnt; int n; cin >> n; for (int i = 0; i < n; ++i) { int x; cin >> x; cnt[x]++; } int a = -1; for (int i = 0; i <= 101; ++i) { if (cnt[i] == 0) { cout << i + (a == -1 ? i : a) << '\n'; return; } else if (cnt[i] == 1 and a == -1) { a = i; } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T = 1, tc = 1; cin >> T; while (T--) { solve(); } return 0; }
7
CPP
for _ in range(int(input())): n=int(input()) a=[int(i) for i in input().split()] a=sorted(a) ans=0 if a.count(0)<2 and n%2==1: for i in range(101): if i not in a: ans=i break else: if a.count(0)>=2: a1=[0] a2=[] for i in range(1,n): if a[i] not in a1 and a[i]-1 in a1: a1.append(a[i]) else : a2.append(a[i]) for i in range(101): if i not in a1: ans+=i break for i in range(101): if i not in a2: ans+=i break for i in range(101): if i not in a: ans=max(ans,i) break else: for i in range(101): if i not in a: ans+=i break print(ans)
7
PYTHON3
from bisect import bisect_left as bl from bisect import bisect_right as br from heapq import heappush,heappop,heapify import math from collections import * from functools import reduce,cmp_to_key import sys input = sys.stdin.readline from itertools import accumulate from functools import lru_cache M = mod = 998244353 def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))) def inv_mod(n):return pow(n, mod - 2, mod) def li():return [int(i) for i in input().rstrip('\n').split()] def st():return input().rstrip('\n') def val():return int(input().rstrip('\n')) def li2():return [i for i in input().rstrip('\n')] def li3():return [int(i) for i in input().rstrip('\n')] for _ in range(val()): n = val() l = sorted(li()) a1 = set() a2 = set() for i in l: if i in a1: a2.add(i) else:a1.add(i) ans = 0 for i in range(200): if i not in a1: ans += i break for i in range(200): if i not in a2: ans += i break print(ans)
7
PYTHON3
T=int(input()) while T: n = int(input()) a = [int(x) for x in input().split()] a.sort() b=[] c=[] if a[0]!=0: print("0") else: b = list(set(a)) b.sort() f=x=y=0 for i in range(len(b)): if i not in b: x=i f=1 break if f==0: x = b[-1]+1 for i in b: a.remove(i) f=0 for i in range(len(a)): if i not in a: y=i f=1 break if f==0: if(len(a)>0): y = a[-1]+1 print(x+y) T-=1
7
PYTHON3
#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; } }
7
CPP
#Codeforces Round #670 #Problem A import sys, collections # #BEGIN TEMPLATE # def input(): return sys.stdin.readline()[:-1] def getInt(): return int(input()) def getIntIter(): return map(int, input().split()) def getIntList(): return list(getIntIter()) def flush(): sys.stdout.flush() # #END TEMPLATE # for _ in range(getInt()): n = getInt() nums = getIntList() c = collections.Counter(nums) out = 0 curr = 0 m = 2 while curr in c.keys(): out += min(c[curr],m) m = min(m,c[curr]) curr += 1 print(out)
7
PYTHON3
for t in range(int(input())): n=int(input()) arr=list(map(int,input().split())) arr.sort() m=arr[-1] l=[0]*(m+1) for i in set(arr): l[i]=arr.count(i) x=[] y=[] for i in range(len(l)): for j in range(l[i]//2): x.append(i) y.append(i) if l[i]%2!=0: x.append(i) ans1,ans2=-1,-1 x=list(set(x)) y=list(set(y)) for i in range(len(x)): if x[i]!=i: ans1=i break if ans1==-1: if len(x)>=1: ans1=x[-1]+1 else: ans1=0 for i in range(len(y)): if y[i]!=i: ans2=i break if ans2==-1: if len(y)>=1: ans2=y[-1]+1 else: ans2=0 print(ans1+ans2)
7
PYTHON3
Q=int(input()) for i in range(Q): N=int(input()) L=list(map(int,input().split())) A=[0 for i in range(100+2)] B=[0 for i in range(100+2)] for n in range(N): if A[L[n]]==0: A[L[n]]=1 else: B[L[n]]=1 a=0 b=0 for i in range(len(A)): if A[101-i]==0: a=101-i if B[101-i]==0: b=101-i print(a+b) #print(A[:10])
7
PYTHON3
T=int(input()) for _ in range(T): N=int(input()) A=list(map(int,input().split())) dic={} mex=max(A) for i in A: if i in dic: dic[i]+=1 else: dic[i]=1 count=ans=0 #print(dic) flag=1 for i in range(mex+2): if i in dic: if dic[i]==1 and flag==1: ans+=i flag=0 #print(i,"a") count+=1 if count==2: break else: ans+=i flag=0 count+=1 break if count==1: ans*=2 print(ans)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; void solve() { int n, a[105]; memset((a), (0), sizeof(a)); cin >> n; for (int i = 0; i < n; i++) { int b; cin >> b; b[a]++; } int i; for (i = 0; i < 101; i++) { a[i]--; if (a[i] < 0) break; } int j; for (j = 0; j < 101; j++) { if (a[j] < 1) break; } cout << (i + j) << "\n"; } int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) solve(); }
7
CPP
def solve(): n = int(input().strip()) a = list(map(int, input().strip().split())) count = {i: 0 for i in range(102)} for i in a: count[i] += 1 mexA = None mexB = None for i in range(101): if count[i] == 1: if mexA==None: mexA = i elif count[i] == 0: if mexA==None: mexA = i if mexB==None: mexB = i break print(mexA + mexB) t = int(input().strip()) for _ in range(t): solve()
7
PYTHON3
# cook your dish here # code # ___________________________________ # | | # | | # | _, _ _ ,_ | # | .-'` / \'-'/ \ `'-. | # | / | | | | \ | # | ; \_ _/ \_ _/ ; | # | | `` `` | | # | | | | # | ; .-. .-. .-. .-. ; | # | \ ( '.' \ / '.' ) / | # | '-.; V ;.-' | # | ` ` | # | | # |___________________________________| # | | # | Author : Ramzz | # | Created On : 21-07-2020 | # |___________________________________| # # _ __ __ _ _ __ ___ ________ # | '__/ _` | '_ ` _ \|_ /_ / # | | | (_| | | | | | |/ / / / # |_| \__,_|_| |_| |_/___/___| # import math import collections from sys import stdin,stdout,setrecursionlimit from bisect import bisect_left as bsl from bisect import bisect_right as bsr import heapq as hq setrecursionlimit(2**20) t = 1 t = int(stdin.readline()) for _ in range(t): n = int(stdin.readline()) #s = stdin.readline().strip('\n') a = list(map(int, stdin.readline().rstrip().split())) d = {} for i in a: if(i not in d): d[i] = 0 d[i]+=1 ans1 = 0 for i in range(0,102): if(i not in d): ans1 = i break #print(d) for j in range(0,ans1): if(j in d): d[j]-=1 if(d[j]==0): del d[j] #print(d) ans2 = 0 for i in range(0,102): if(i not in d): ans2 = i break print(ans1+ans2)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; bool flag = 0, flag1 = 0, flag2 = 0, flag3 = 0, flag4 = 0, flag5 = 0; int main() { long long int t; cin >> t; while (t--) { long long int n, k, ans = 0; cin >> n; multiset<long long int> a; for (long long int i = 0; i < n; i++) { cin >> k; a.insert(k); } for (long long int i = 0; i < n + 1; i++) { if (a.count(i) == 0) { ans += i; break; } else a.erase(a.find(i)); } for (long long int i = 0; i < n + 1; i++) { if (a.count(i) == 0) { ans += i; break; } } cout << ans << "\n"; } return 0; }
7
CPP
from collections import Counter for _ in range(int(input())): input() arr = map(int, input().split()) c = Counter(arr) one = two = 0 while 1: if c[two] >= 2: two += 1 else: break one = two while 1: if c[one] >= 1: one += 1 else: break print(two + one)
7
PYTHON3
# import sys # input=sys.stdin.readline # print=sys.stdout.writeline def check(arr,l): for i in range(l): if arr[i]!=i: return i else: return i+1 def solve(l): d={0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0, 9: 0, 10: 0, 11: 0, 12: 0, 13: 0, 14: 0, 15: 0, 16: 0, 17: 0, 18: 0, 19: 0, 20: 0, 21: 0, 22: 0, 23: 0, 24: 0, 25: 0, 26: 0, 27: 0, 28: 0, 29: 0, 30: 0, 31: 0, 32: 0, 33: 0, 34: 0, 35: 0, 36: 0, 37: 0, 38: 0, 39: 0, 40: 0, 41: 0, 42: 0, 43: 0, 44: 0, 45: 0, 46: 0, 47: 0, 48: 0, 49: 0, 50: 0, 51: 0, 52: 0, 53: 0, 54: 0, 55: 0, 56: 0, 57: 0, 58: 0, 59: 0, 60: 0, 61: 0, 62: 0, 63: 0, 64: 0, 65: 0, 66: 0, 67: 0, 68: 0, 69: 0, 70: 0, 71: 0, 72: 0, 73: 0, 74: 0, 75: 0, 76: 0, 77: 0, 78: 0, 79: 0, 80: 0, 81: 0, 82: 0, 83: 0, 84: 0, 85: 0, 86: 0, 87: 0, 88: 0, 89: 0, 90: 0, 91: 0, 92: 0, 93: 0, 94: 0, 95: 0, 96: 0, 97: 0, 98: 0, 99: 0, 100: 0} m=0 for i in l: d[i]+=1 if i>m: m=i l=[] r=[] ll=0 lr=0 for i in range(m+1): if d[i]>=2: r.append(i) lr+=1 ll+=1 l.append(i) elif d[i]==1: ll+=1 l.append(i) if lr>0: return check(l,ll)+check(r,lr) else: return check(l,ll) for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) print(solve(l))
7
PYTHON3
def answer(n, ary): sum = 0 inc = 2 #print('n=', n, 'ary=', ary) for i in range(n+1): if ary.count(i) >= 2: sum += inc elif ary.count(i) == 1: inc = 1 sum += inc else: #count(i) == 0 return sum def main(): t = int(input()) n = [0] * t ary = [0] * t for j in range(t): n[j] = int(input()) ary[j] = [int(i) for i in input().split()] for j in range(t): print(answer(n[j], ary[j])) main()
7
PYTHON3
numeroTestes = int(input()) for i in range (numeroTestes): # descarta tamanho, em python não precisamos int(input()) aux = 0 vector = [] countVector = [ 0 ] * 101 for i in input().split(): countVector[int(i)]+=1 for i in range (101): if countVector[i] != 0: countVector[i] -= 1 else: aux += i break for i in range (101): if countVector[i] != 0: countVector[i] -= 1 else: aux += i break print(aux)
7
PYTHON3
for _ in ' '*int(input()): v, i, n, a = 0, 0, int(input()), sorted([int(x) for x in input().split()]) for row in set(a): if a.count(row) >= 2 and row == v: v += 1; i += 1 elif row == i: i += 1 print(v+i)
7
PYTHON3
if __name__ == "__main__": for _ in range(int(input())): n = int(input()) num = list(map(int, input().split())) num.sort() a = [0] * 101 b = [0] * 101 for i in range(len(num)): if a[num[i]] == 0: a[num[i]] = 1 else: b[num[i]] = 1 answer = 0 for i in range(101): if a[i] == 1: continue else: answer += i break for i in range(101): if b[i] == 1: continue else: answer += i break print(answer)
7
PYTHON3
from collections import * for _ in range(int(input())): N=int(input()) A=list(map(int,input().split())) dic=defaultdict(int) for i in A: dic[i]+=1 ans=0 check1=-1 flag=0 for i in range(0,101): if(dic[i]==0): ans+=i break else: dic[i]-=1 flag=0 for i in range(0,101): if(dic[i]==0): ans+=i break else: dic[i]-=1 print(ans)
7
PYTHON3
#Code by Sounak, IIESTS #------------------------------warmup---------------------------- import os import sys import math from io import BytesIO, IOBase from fractions import Fraction import collections from itertools import permutations from collections import defaultdict import threading BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") #-------------------game starts now----------------------------------------------------- for _ in range (int(input())): n=int(input()) a=list(map(int,input().split())) mx=max(a)+1 mn=0 ch=1 d=dict() for i in a: if i in d: d[i]+=1 else: d[i]=1 for i in range (max(a)+1): if i not in d: mx=i break if ch==1 and d[i]>1: mn=i+1 if d[i]==1: ch=0 #print(mx,mn) print(mx+mn)
7
PYTHON3
# for _ in range(int(input())): # = map(int, input().split()) # = int(input()) # = input() for _ in range(int(input())): input() a = list(map(int, input().split())) a.sort() m1 = 0 m2 = 0 pairs = True while len(a) > 0: if a[0] == m1: m1+=1 a.pop(0) elif a[0] == m2: m2+=1 a.pop(0) elif a[0] < m1 or a[0] < m2: a.pop(0) continue else: break print(m1+m2)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; template <class T> using PQ = priority_queue<T>; template <class T> using PQ_inv = priority_queue<T, vector<T>, greater<T>>; const double pai = 3.1415926535897; const long long mod = 1000000007; const long long INF = 1000000021; const long long LINF = 2000000000000000000; const long long MAX = 510000; const long long MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (long long i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } long long COM(long long n, long long k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } long long PER(long long n, long long k) { if (n < 0 || k < 0) return 0; if (n < k) return fac[n]; return fac[n] * finv[n - k] % mod; } long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } long long modpow(long long a, long long n) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } struct edge { long long to, cost; }; edge m_e(long long xx, long long yy) { edge ed; ed.to = xx; ed.cost = yy; return ed; } long long b_s(vector<long long>& vec, long long xx) { return lower_bound(vec.begin(), vec.end(), xx) - vec.begin(); } template <class T> void vecout(vector<T>& vec) { for (T t : vec) cout << t << " "; cout << "\n"; } template <class T> void vecout(vector<vector<T>>& vec) { for (vector<T> tvec : vec) { for (T t : tvec) cout << t << " "; cout << "\n"; } } template <class T> void vecin(vector<T>& vec) { for (long long i = 0; i < (long long)vec.size(); i++) cin >> vec[i]; } bool chmax(long long& xx, long long yy) { if (xx < yy) { xx = yy; return true; } return false; } bool chmin(long long& xx, long long yy) { if (xx > yy) { xx = yy; return true; } return false; } double dist(long long x, long long y) { return sqrt(x * x + y * y); } double dist(long long xx1, long long xx2, long long yy1, long long yy2) { return sqrt(abs(xx1 - xx2) * abs(xx1 - xx2) + abs(yy1 - yy2) * abs(yy1 - yy2)); } long long mypow(long long nn, long long kk) { long long xx = 1; for (long long i = 0; i < (long long)(kk); i++) { xx *= nn; } return xx; } long long gcd(long long xx, long long yy) { long long p = xx; long long q = yy; if (q > p) swap(p, q); while (p % q != 0) { p %= q; swap(p, q); } return q; } long long lcm(long long xx, long long yy) { return xx * yy / gcd(xx, yy); } bool prime(long long xx) { if (xx <= 1) { return 0; } for (long long i = 2; i * i <= xx; i++) { if (xx % i == 0) { return 0; } } return 1; } signed main() { long long t, n, a; cin >> t; for (long long i = 0; i < (long long)(t); i++) { long long ans = 0, d = 2; cin >> n; map<long long, long long> ma; for (long long i = 0; i < (long long)(n); i++) { cin >> a; if (!ma.count(a)) { ma[a] = 1; } else { ma[a]++; } } long long j = 0; while (1) { if (!ma.count(j)) { break; } if (ma[j] == 1) { d = 1; } ans += d; j++; } cout << ans << "\n"; } }
7
CPP
def mex(arr): tmp = [0] * 101 for i in arr: tmp[i] = 1 for i in range(102): if tmp[i] == 0: return i for _ in range(int(input())): n = int(input()) lis = list(map(int,input().split())) A, B = [], [] for i in lis: if i not in A: A.append(i) else: B.append(i) print(mex(A) + mex(B))
7
PYTHON3