solution
stringlengths 11
983k
| difficulty
int64 0
21
| language
stringclasses 2
values |
---|---|---|
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
int a[N];
int main() {
int i, j, k, m, n, t;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (i = 0; i <= 105; i++) a[i] = 0;
for (i = 1; i <= n; i++) scanf("%d", &k), a[k]++;
i = 0;
while (a[i] >= 2) i++;
int ans = 0;
ans = i;
while (a[i] >= 1) i++;
ans += i;
printf("%d\n", ans);
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
int a[maxn], b[maxn], w[maxn];
int main() {
int t;
cin >> t;
while (t--) {
memset(a, 0, sizeof(a));
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
a[x]++;
}
int ans = 0;
for (int i = 0; i <= n; i++) {
if (a[i])
a[i]--;
else {
ans += i;
break;
}
}
for (int i = 0; i <= n; i++) {
if (a[i])
a[i]--;
else {
ans += i;
break;
}
}
cout << ans << endl;
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 110;
const int mod = 1e9 + 7;
int a[N];
int main() {
int t;
cin >> t;
while (t--) {
memset(a, 0, sizeof(a));
;
int n;
cin >> n;
for (int i = 0, x; i < n; i++) {
cin >> x;
a[x]++;
}
int j = 0, k = 0;
while (a[j] != 0) j++;
while (a[k] > 1) k++;
cout << j + k << endl;
}
return 0;
}
| 7 | CPP |
for i in range(int(input())):
m=int(input())
a=list(map(int,input().split(' ')))
a.sort()
if a.count(0)==0:
print(0)
elif a.count(0)==1:
for j in range(len(a)+1):
if a.count(j)==0:
print(j)
break
else:
sum=0
for k in range(len(a)):
if a.count(k)>=2:
continue
elif a.count(k)==1 and sum==0:
sum+=k
continue
elif a.count(k)==0 and sum!=0:
sum+=k
break
elif a.count(k)==0 and sum==0:
sum+=k*2
break
else:
continue
print(sum)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
int n = 7, m, k, dots = 0, cou = 0, yes = 0, r;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int i, lim, p, mn = INT_MAX, mx = INT_MIN, j, t, sum = 0, sal = 0,
ii, jj, cnt = 0, x, y, ans = 0;
cin >> t;
while (t--) {
cin >> n;
vector<int> v(n), val(102);
for (i = 0; i < n; i++) {
cin >> v[i];
val[v[i]]++;
}
int ans1 = -1, ans2 = -1;
for (i = 0; i < 101; i++) {
if (val[i] >= 2) continue;
if (val[i] == 1) {
if (ans1 == -1) ans1 = i;
} else {
if (ans1 == -1) {
ans1 = i;
ans2 = i;
break;
} else {
ans2 = i;
break;
}
}
}
cout << ans1 + ans2 << "\n";
}
}
| 7 | CPP |
for _ in range(int(input())):
n = int(input())
lst = list(map(int, input().split()))
lst.sort()
temp = set(lst)
ans = 0
for i in range(101):
if i not in lst:
ans += i
break
done = False
for j in range(i):
if lst.count(j)<2:
ans += j
done = True
break
if not done:
ans += i
print(ans) | 7 | PYTHON3 |
from sys import stdin, stdout
from collections import defaultdict, deque, Counter, OrderedDict
def Integer(): return int(stdin.readline().strip())
def MapInteger(): return map(int, stdin.readline().strip().split())
def MapList(): return list(map(int, stdin.readline().split()))
for _ in range(int(input())):
k=int(input())
array=list(MapInteger())
countnum=Counter(array)
first=True
second=True
a,b=0,0
for i in range(max(array)+1):
if countnum[i]>=2:
if first:
a+=1
if second:
b+=1
if countnum[i]==1:
if first:
a+=1
if second:
second=False
if countnum[i]==0:
if first:
first=False
if second:
second=False
print(a+b) | 7 | PYTHON3 |
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
cnt1 = [0] * 110
cnt2 = [0] * 110
for i in range(n):
if cnt1[a[i]] == 0:
cnt1[a[i]] += 1
else:
cnt2[a[i]] += 1
ans1, ans2 = 0, 0
for i in range(110):
if cnt1[i] == 0:
ans1 = i
break
for i in range(110):
if cnt2[i] == 0:
ans2 = i
break
print(ans1 + ans2) | 7 | PYTHON3 |
import sys
input = sys.stdin.readline
from collections import Counter
t=int(input())
for tests in range(t):
n=int(input())
C=Counter(map(int,input().split()))
X=0
Y=0
TWO=1
for i in range(200):
if TWO==1:
if C[i]>=2:
X+=1
Y+=1
elif C[i]==1:
X+=1
TWO=0
else:
break
else:
if C[i]>=1:
X+=1
else:
break
print(X+Y)
| 7 | PYTHON3 |
import sys
from collections import Counter
input = sys.stdin.readline
def solve(n, a):
c = Counter(a)
subseta = set()
subsetb = set()
for i in range(102):
if c[i] >= 2:
subseta.add(i)
subsetb.add(i)
elif c[i] == 1:
subseta.add(i)
mexa = mexb = 0
for i in range(102):
if i not in subseta:
mexa = i
break
for i in range(102):
if i not in subsetb:
mexb = i
break
return mexa + mexb
# assert solve(4, list(map(int, '0 2 1 5 0 1'.split()))) == 5
# assert solve(3, list(map(int, '0 1 2'.split()))) == 3
# assert solve(4, list(map(int, '0 2 0 1'.split()))) == 4
# assert solve(6, list(map(int, '1 2 3 4 5 6'.split()))) == 0
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
v = solve(n, a)
print(v)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t, x, n;
cin >> t;
while (t--) {
cin >> n;
vector<int> v(109, 0);
while (n--) {
cin >> x;
v[x] += 1;
}
int sum = 0;
for (int i = 0; i < v.size(); i++) {
if (v[i] == 0) {
sum += i;
break;
}
}
for (int i = 0; i < v.size(); i++) {
if (v[i] <= 1) {
sum += i;
break;
}
}
cout << sum << "\n";
}
return 0;
}
| 7 | CPP |
def don(arr):
try:
a = []
b = []
mex = []
for value in arr:
if value not in a:
a.append(value)
else:
b.append(value)
if a!= []:
max_a = max(a)
for i in range(max_a+2):
if i not in a:
mex.append(i)
break
if b!= []:
max_b = max(b)
for j in range(max_b+2):
if j not in b:
mex.append(j)
break
sum = 0
for values in mex:
sum = sum + values
return sum
except:
return 0
t = int(input())
solution = []
for _ in range(t):
n = int(input())
arr = list(map(int,input().split()))
arr.sort()
x = don(arr)
solution.append(x)
for values in solution:
print(values,end= '\n')
| 7 | PYTHON3 |
t=int(input())
while(t):
n=int(input())
a=list(map(int,input().split()))
m1=m2=0
m11=m22=True
# b=set(a)
for x in range(0,n+2):
# print(x,a.count(x))
if(a.count(x)==0 and m11):
m1=x
m11=False
if(a.count(x)==0 and m22):
m2=x
m22=False
if(a.count(x)==1 and m11):
m1=x
m11=False
continue
# if(a.count(x)==1 and m22):
# m2=x
# m22=False
print(m1+m2)
t-=1 | 7 | PYTHON3 |
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
ch=[0 for i in range(101)]
for el in a:
ch[el]+=1
i=0
while ch[i]>=2:
i+=1
x=i
while ch[i]>=1:
i+=1
print(x+i) | 7 | PYTHON3 |
from collections import Counter
t = int(input())
while t:
t -= 1
n = int(input())
a = list(map(int, input().split()))
a1, a2 = None, None
freq = Counter(a)
for i in range(0, 101):
if freq.get(i, 0) == 0:
if a1 == None and a2 == None:
print(2*i)
else:
print(a1 + i)
break
elif freq.get(i) == 1:
if a1 == None:
a1 = i
| 7 | PYTHON3 |
t = int(input())
for i in range(t):
n = int(input())
a = list(map(int,input().split()))
a.sort()
ans = 0
sum = 0
for i in a:
if ans == i:
ans+=1
elif sum == i:
sum += 1
print(ans+sum)
| 7 | PYTHON3 |
for _ in " "*int(input()):
z=int(input())
a=sorted(map(int,input().split()))
c,d=[],[]
for i in range(z):
if a[i] in c:d.append(a[i])
else:c.append(a[i])
i=0
while i in c:i+=1
j=0
while j in d:j+=1
print(i+j) | 7 | PYTHON3 |
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
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")
# ------------------- fast io --------------------
from math import gcd, ceil
def pre(s):
n = len(s)
pi = [0] * n
for i in range(1, n):
j = pi[i - 1]
while j and s[i] != s[j]:
j = pi[j - 1]
if s[i] == s[j]:
j += 1
pi[i] = j
return pi
def prod(a):
ans = 1
for each in a:
ans = (ans * each)
return ans
def lcm(a, b): return a * b // gcd(a, b)
def binary(x, length=16):
y = bin(x)[2:]
return y if len(y) >= length else "0" * (length - len(y)) + y
for _ in range(int(input()) if True else 1):
n = int(input())
#n, k = map(int, input().split())
#a, b = map(int, input().split())
#c, d = map(int, input().split())
a = list(map(int, input().split()))
#b = list(map(int, input().split()))
#s = input()
di = {}
for i in a:
di[i] = 1 if i not in di else di[i] + 1
mex = 0
two = 0
twopos = True
for i in range(n):
if i in di:
mex += 1
if twopos and di[i] >= 2:
two += 2
else:
two += 1
twopos = False
else:break
if mex == n:
print(mex)
continue
print(max(mex, two))
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int smallest_positive(vector<long long int> &v) {
long long int i = 0;
if (v.size() == 0) return 0;
if (v[0] != 0) return 0;
for (i = 1; i < v.size(); i++) {
if (v[i] != (v[i - 1] + 1) && v[i] != v[i - 1]) {
return v[i - 1] + 1;
};
}
return v[v.size() - 1] + 1;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
vector<long long int> a(n);
vector<long long int> a1;
vector<long long int> a2;
for (long long int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a.begin(), a.end());
a1.push_back(a[0]);
for (long long int i = 1; i < n; i++) {
if (a[i] != a[i - 1])
a1.push_back(a[i]);
else
a2.push_back(a[i]);
}
cout << smallest_positive(a1) + smallest_positive(a2) << endl;
}
return 0;
}
| 7 | CPP |
for _ in range(int(input())):
N = int(input())
array = list(map(int, input().split()))
dic = {}
for i in array:
if i not in dic.keys():
dic[i] = 1
else:
dic[i] += 1
set_1 = []
set_2 = []
ans = 0
for i in range(101):
if dic.get(i, -1) > 0:
dic[i] -= 1
else:
ans += i
break
for i in range(101):
if dic.get(i, -1) > 0:
dic[i] -= 1
else:
ans += i
break
print(ans)
| 7 | PYTHON3 |
from sys import *
input = stdin.readline
t=int(input())
for case in range(t):
n=int(input())
arr = [*map(int,input().split())]
arr.sort()
mex_a,mex_b=0,0
for i in range(n):
if arr[i]==mex_a:
mex_a+=1
arr[i]=-1
elif arr[i]>mex_a:
break
for i in range(n):
if arr[i]==-1:
continue
if arr[i]==mex_b:
mex_b+=1
arr[i]=-1
elif arr[i]>mex_b:
break
print(mex_a+mex_b)
| 7 | PYTHON3 |
number_of_entries=int(input())
len_of_array=[]
array=[]
for i in range(number_of_entries):
ithlen=int(input())
itharray=list(map(int,input().split()))
len_of_array.append(ithlen)
array.append(itharray)
def calculate_mex(len_of_array,array):
array.sort()
mex=0
for i in range(len_of_array):
if array[i]==mex:
mex+=1
return mex
def maximum_sum_of_mex_of_subsets(len_of_array,array):
array.sort()
sub_array1=[]
sub_array2=[]
for i in range(len_of_array-1):
if array[i]==array[i+1]:
array[i]=-1
sub_array1.append(array[i+1])
for i in range(len_of_array):
if array[i]!=-1:
sub_array2.append(array[i])
mex1=calculate_mex(len(sub_array1),sub_array1)
mex2=calculate_mex(len(sub_array2),sub_array2)
return mex1+mex2
for i in range(number_of_entries):
ans=maximum_sum_of_mex_of_subsets(len_of_array[i],array[i])
print(ans)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
int arr[101];
for (int i = 0; i < 101; i++) {
arr[i] = 0;
}
int temp;
for (long long int i = 0; i < n; i++) {
cin >> temp;
arr[temp]++;
}
int ans = 0;
for (int i = 0; i < 101; i++) {
if (arr[i] >= 1) {
arr[i]--;
} else {
ans += i;
break;
}
}
for (int i = 0; i < 101; i++) {
if (arr[i] >= 1) {
arr[i]--;
} else {
ans += i;
break;
}
}
cout << ans << endl;
}
int main() {
long long int t;
cin >> t;
while (t--) {
solve();
}
}
| 7 | CPP |
from collections import Counter
def mex(A):
A = [-1] + A
for i in range(1, len(A)):
if A[i] - A[i - 1] > 1:
return A[i - 1] + 1
return A[-1] + 1
for _ in range(int(input())):
n = input()
arr = [*map(int, input().split())]
c = Counter(arr)
A, B = [], []
for i in sorted(c.keys()):
if c[i] > 1:
A.append(i)
B.append(i)
else:
A.append(i)
print(mex(A) + mex(B)) | 7 | PYTHON3 |
from collections import Counter
T = int(input())
for t in range(T):
n = int(input())
S = list(map(int, input().split()))
Sd = Counter()
for i in S:
Sd[i] += 1
mA = 0
while Sd[mA]:
Sd[mA] -= 1
mA += 1
mB = 0
while Sd[mB]:
Sd[mB] -= 1
mB += 1
print(mA + mB)
| 7 | PYTHON3 |
def read(datatype=int):
return datatype(input())
def readl(datatype=int):
return list(map(datatype, input().split()))
def printl(data):
string = ''
for d in data:
string += str(d) + ' '
print(string)
def mex(arr):
freq = [False for _ in range(101)]
for a in arr:
freq[a] = True
for i in range(101):
if not freq[i]:
return i
return 101
def testcase():
# --------------------- start testcase ---------------------
n = read()
arr = readl()
freq = [0 for _ in range(101)]
for a in arr:
freq[a] += 1
a = []
b = []
for i in range(101):
while freq[i] > 1:
a.append(i)
b.append(i)
freq[i] -= 2
if freq[i] == 1:
a.append(i)
print(
mex(a) + mex(b)
)
# --------------------- end testcase -----------------------
return
t = read()
for _ in range(t):
testcase() | 7 | PYTHON3 |
for _ in range(int(input())):
n = int(input())
a = sorted(list(map(int,input().split())))
l = [0,0]
for i in a:
if i==l[0]:
l[0]+=1
elif i==l[1]:
l[1]+=1
print(sum(l)) | 7 | PYTHON3 |
n=int(input())
for i in range(n):
m=int(input())
a=[int(i) for i in input().split()]
l=[]
l1=[]
d=set(a)
first=0
second=0
for j in d:
if(a.count(j)==1):
l.append(j)
else:
l.append(j)
l1.append(j)
for j in range(0,101):
if(j not in l):
first=j
break
for j in range(0,101):
if(j not in l1):
second=j
break
print(first+second) | 7 | PYTHON3 |
from collections import defaultdict as dc
def solv():
x = int(input())
s = list(map(int, input().split()))
s.sort()
a = dc(lambda: 0)
b = dc(lambda: 0)
for n in s:
if a[n] == 0:
a[n] = 1
else:
b[n] = 1
p = 0
while a[p]:
p += 1
q = 0
while b[q]:
q += 1
print(p+q)
for n in range(int(input())):
solv()
| 7 | PYTHON3 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <class c>
struct rge {
c b, e;
};
template <class c>
rge<c> range(c i, c j) {
return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
template <class c>
debug& operator<<(const c&) {
return *this;
}
};
const long long MOD = 1e9 + 7;
const long long N = 1e7 + 1;
const long long INF = 1e18 + 10;
void solve() {
long long n;
cin >> n;
vector<long long> v(n);
multiset<long long> ms;
for (long long i = 0; i < n; i++) {
cin >> v[i];
ms.insert(v[i]);
}
long long first = -1;
for (long long i = 0; i <= 101; i++) {
if (ms.count(i) == 0) {
debug() << " ["
<< "first"
": "
<< (first) << "] ";
if (first != -1) {
cout << first + i << endl;
} else
cout << i + i << endl;
return;
} else if (ms.count(i) == 1 && first == -1) {
first = i;
}
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long t;
cin >> t;
while (t--) solve();
return 0;
}
| 7 | CPP |
from collections import Counter
for _ in range(int(input())):
n=int(input())
arr=Counter(map(int,input().split()))
a=[]
b=[]
for i in arr:
a.append(i)
if arr[i]>=2:
b.append(i)
last=a[-1]+10
a.append(last)
a.sort()
if len(b)!=0:
last=b[-1]+10
b.append(last)
b.sort()
mex=[]
if len(a)!=0:
for i in range(len(a)+1):
if i!=a[i]:
mex.append(i)
break
if len(b)!=0:
for i in range(len(b)+1):
if i!=b[i]:
mex.append(i)
break
print(sum(mex)) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int arr[n];
map<int, int> m;
int mx = 0, mn = 101, sum = 0;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
m[x] += 1;
}
for (int i = 0; i <= 100; i++) {
if (m[i] == 0) {
sum += i;
break;
} else if (m[i] > 0) {
m[i] -= 1;
}
}
for (int i = 0; i <= 100; i++) {
if (m[i] == 0) {
sum += i;
break;
}
}
cout << sum << endl;
}
}
| 7 | CPP |
from collections import *
for u in range(int(input())):
n=int(input())
l=list(map(int,input().split()))
d=[0]*101
for i in l:
d[i]+=1
x=-1
for i in range(101):
if(d[i]==0):
x=i
break
r=0
i=0
while(i<101 and d[i]>1):
i+=1
if(i<101 and d[i]==0):
r=2*i
print(max(x,r))
continue
r+=i
i+=1
while(i<101 and d[i]>0):
i+=1
r+=i
print(max(r,x))
| 7 | PYTHON3 |
for __ in range(int(input())):
n = int(input())
ar = list(map(int, input().split()))
kek = [0] * 200
for elem in ar:
kek[elem] += 1
a, b = 0, 0
flag = True
for i in range(200):
if flag and kek[i] >= 2:
a += 1
b += 1
else:
flag = False
if kek[i] >= 1:
a += 1
else:
break
print(a + b) | 7 | PYTHON3 |
#### IMPORTANT LIBRARY ####
############################
### DO NOT USE import random --> 250ms to load the library
############################
### In case of extra libraries: https://github.com/cheran-senthil/PyRival
######################
####### IMPORT #######
######################
from functools import cmp_to_key
from collections import deque, Counter
from heapq import heappush, heappop
from math import log, ceil
######################
#### STANDARD I/O ####
######################
import sys
import os
from io import BytesIO, IOBase
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")
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def print(*args, **kwargs):
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
def inp():
return sys.stdin.readline().rstrip("\r\n") # for fast input
def ii():
return int(inp())
def si():
return str(inp())
def li(lag = 0):
l = list(map(int, inp().split()))
if lag != 0:
for i in range(len(l)):
l[i] += lag
return l
def mi(lag = 0):
matrix = list()
for i in range(n):
matrix.append(li(lag))
return matrix
def lsi(): #string list
return list(map(str, inp().split()))
def print_list(lista, space = " "):
print(space.join(map(str, lista)))
######################
### BISECT METHODS ###
######################
def bisect_left(a, x):
"""i tale che a[i] >= x e a[i-1] < x"""
left = 0
right = len(a)
while left < right:
mid = (left+right)//2
if a[mid] < x:
left = mid+1
else:
right = mid
return left
def bisect_right(a, x):
"""i tale che a[i] > x e a[i-1] <= x"""
left = 0
right = len(a)
while left < right:
mid = (left+right)//2
if a[mid] > x:
right = mid
else:
left = mid+1
return left
def bisect_elements(a, x):
"""elementi pari a x nell'árray sortato"""
return bisect_right(a, x) - bisect_left(a, x)
######################
### MOD OPERATION ####
######################
MOD = 10**9 + 7
maxN = 5
FACT = [0] * maxN
INV_FACT = [0] * maxN
def add(x, y):
return (x+y) % MOD
def multiply(x, y):
return (x*y) % MOD
def power(x, y):
if y == 0:
return 1
elif y % 2:
return multiply(x, power(x, y-1))
else:
a = power(x, y//2)
return multiply(a, a)
def inverse(x):
return power(x, MOD-2)
def divide(x, y):
return multiply(x, inverse(y))
def allFactorials():
FACT[0] = 1
for i in range(1, maxN):
FACT[i] = multiply(i, FACT[i-1])
def inverseFactorials():
n = len(INV_FACT)
INV_FACT[n-1] = inverse(FACT[n-1])
for i in range(n-2, -1, -1):
INV_FACT[i] = multiply(INV_FACT[i+1], i+1)
def coeffBinom(n, k):
if n < k:
return 0
return multiply(FACT[n], multiply(INV_FACT[k], INV_FACT[n-k]))
######################
#### GRAPH ALGOS #####
######################
# ZERO BASED GRAPH
def create_graph(n, m, undirected = 1, unweighted = 1):
graph = [[] for i in range(n)]
if unweighted:
for i in range(m):
[x, y] = li(lag = -1)
graph[x].append(y)
if undirected:
graph[y].append(x)
else:
for i in range(m):
[x, y, w] = li(lag = -1)
w += 1
graph[x].append([y,w])
if undirected:
graph[y].append([x,w])
return graph
def create_tree(n, unweighted = 1):
children = [[] for i in range(n)]
if unweighted:
for i in range(n-1):
[x, y] = li(lag = -1)
children[x].append(y)
children[y].append(x)
else:
for i in range(n-1):
[x, y, w] = li(lag = -1)
w += 1
children[x].append([y, w])
children[y].append([x, w])
return children
def dist(tree, n, A, B = -1):
s = [[A, 0]]
massimo, massimo_nodo = 0, 0
distanza = -1
v = [-1] * n
while s:
el, dis = s.pop()
if dis > massimo:
massimo = dis
massimo_nodo = el
if el == B:
distanza = dis
for child in tree[el]:
if v[child] == -1:
v[child] = 1
s.append([child, dis+1])
return massimo, massimo_nodo, distanza
def diameter(tree):
_, foglia, _ = dist(tree, n, 0)
diam, _, _ = dist(tree, n, foglia)
return diam
def dfs(graph, n, A):
v = [-1] * n
s = [[A, 0]]
v[A] = 0
while s:
el, dis = s.pop()
for child in graph[el]:
if v[child] == -1:
v[child] = dis + 1
s.append([child, dis + 1])
return v #visited: -1 if not visited, otherwise v[B] is the distance in terms of edges
def bfs(graph, n, A):
v = [-1] * n
s = deque()
s.append([A, 0])
v[A] = 0
while s:
el, dis = s.popleft()
for child in graph[el]:
if v[child] == -1:
v[child] = dis + 1
s.append([child, dis + 1])
return v #visited: -1 if not visited, otherwise v[B] is the distance in terms of edges
#FROM A GIVEN ROOT, RECOVER THE STRUCTURE
def parents_children_root_unrooted_tree(tree, n, root = 0):
q = deque()
visited = [0] * n
parent = [-1] * n
children = [[] for i in range(n)]
q.append(root)
while q:
all_done = 1
visited[q[0]] = 1
for child in tree[q[0]]:
if not visited[child]:
all_done = 0
q.appendleft(child)
if all_done:
for child in tree[q[0]]:
if parent[child] == -1:
parent[q[0]] = child
children[child].append(q[0])
q.popleft()
return parent, children
# CALCULATING LONGEST PATH FOR ALL THE NODES
def all_longest_path_passing_from_node(parent, children, n):
q = deque()
visited = [len(children[i]) for i in range(n)]
downwards = [[0,0] for i in range(n)]
upward = [1] * n
longest_path = [1] * n
for i in range(n):
if not visited[i]:
q.append(i)
downwards[i] = [1,0]
while q:
node = q.popleft()
if parent[node] != -1:
visited[parent[node]] -= 1
if not visited[parent[node]]:
q.append(parent[node])
else:
root = node
for child in children[node]:
downwards[node] = sorted([downwards[node][0], downwards[node][1], downwards[child][0] + 1], reverse = True)[0:2]
s = [node]
while s:
node = s.pop()
if parent[node] != -1:
if downwards[parent[node]][0] == downwards[node][0] + 1:
upward[node] = 1 + max(upward[parent[node]], downwards[parent[node]][1])
else:
upward[node] = 1 + max(upward[parent[node]], downwards[parent[node]][0])
longest_path[node] = downwards[node][0] + downwards[node][1] + upward[node] - min([downwards[node][0], downwards[node][1], upward[node]]) - 1
for child in children[node]:
s.append(child)
return longest_path
### TBD SUCCESSOR GRAPH 7.5
### TBD TREE QUERIES 10.2 da 2 a 4
### TBD ADVANCED TREE 10.3
### TBD GRAPHS AND MATRICES 11.3.3 e 11.4.3 e 11.5.3 (ON GAMES)
######################
## END OF LIBRARIES ##
######################
for test in range(ii()):
n = ii()
a = li()
a = sorted(a)
occ = [0 for i in range(n+1)]
for i in range(n):
if a[i] >= 0 and a[i] <= n:
occ[a[i]] += 1
messo = 0
s = 0
i = 0
while i <= n and messo < 2:
if occ[i] == 0:
s += (2-messo)*i
messo = 2
elif occ[i] == 1 and messo == 0:
s += i
messo += 1
i += 1
print(s) | 7 | PYTHON3 |
class Node():
def __init__(self,val):
self.val=val
self.children=None
self.centroid=None
self.edges=[]
class Graph():
def __init__(self):
self.root=None
def add_edge(self,a,b):
if(self.root==None):
self.root=a
a.edges.append(b)
b.edges.append(a)
def dfs_children(g,root,visited):
visited.add(root.val)
c=0
for i in root.edges:
if(i.val not in visited):
visited.add(i.val)
c+=1+dfs_children(g,i,visited)
root.children=c
return root.children
def dfs_centroids(g,root,visited,n,ce):
visited.add(root.val)
c=-1
t=0
for i in root.edges:
if(i.val not in visited):
visited.add(i.val)
c=max(c,i.children+1)
dfs_centroids(g,i,visited,n,ce)
t+=i.children+1
c=max(c,n-t-1)
root.centroid=c
if(c in ce):
ce[c].append(root)
else:
ce[c]=[root]
return root.centroid
def get_leaf(root,li,visited,noti):
if(root.val==noti.val):
return False
visited.add(root.val)
flag=True
for i in root.edges:
if(i.val not in visited and i.val!=noti.val):
visited.add(i.val)
li[0]=root
li[1]=i
flag=flag & get_leaf(root,li,visited,noti)
return flag
def process():
n=int(input())
li=list(map(int,input().split()))
counts={}
for i in li:
if(i in counts):
counts[i]+=1
else:
counts[i]=1
ans=-1
for i in range(0,101):
if(i in counts):
if(counts[i]>=2):
pass
elif(counts[i]==1 and ans==-1):
ans=0
ans+=i
else:
if(ans>=0):
ans+=i
break
else:
ans=2*i
break
print(ans)
# g=Graph()
# nodes={}
# for i in range(n-1):
# if(a not in nodes):
# nodes[a]=Node(a)
# if(b not in nodes):
# nodes[b]=Node(b)
# g.add_edge(nodes[a],nodes[b])
# visited=set()
# dfs_children(g,g.root,visited)
# visited=set()
# ce={}
# dfs_centroids(g,g.root,visited,n,ce)
# centroid=min(list(ce.keys()))
# if(len(ce[centroid])==1):
# print(g.root.val,g.root.edges[0].val)
# print(g.root.val, g.root.edges[0].val)
# pass
# else:
# li=[-1,ce[centroid][0]]
# # print(li[1].val)
# for i in ce[centroid][0].edges:
# visited={i.val,ce[centroid][0].val}
# li[0]=ce[centroid][0]
# li[1]=i
# if(get_leaf(i,li,visited,ce[centroid][1])):
# break
#
# print(li[0].val,li[1].val)
# print(li[1].val,ce[centroid][1].val)
# a,b=list(map(int,input().split()))
tests=int(input())
for i in range(tests):
process() | 7 | PYTHON3 |
for _ in range(int(input())):
n = int(input())
al = list(map(int, input().split()))
al.sort()
cntl = []
prev = al[0]
cnt = 1
for a in al[1:]:
if prev == a: cnt+=1
else:
cntl.append((prev,cnt))
cnt = 1
prev = a
cntl.append((prev,cnt))
one_end = False
ans1 = -1
ans2 = -1
# print(cntl)
for i, (a,cnt) in enumerate(cntl):
if a == i:
if cnt >= 2:
# i += 1
pass
else:
if not one_end:
ans1 = i
one_end = True
# i += 1
else:
pass
else:
if ans1 == -1: ans1 = i
ans2 = i
break
else:
if ans1 == -1: ans1 = max(al)+1
if ans2 == -1: ans2 = max(al)+1
print(ans1+ans2)
# for i, (a,cnt) in enumerate(cntl):
# if a == i:
# if cnt >= 2:
# # i += 1
# pass
# else:
# if not one_skip:
# ans1 = i
# one_skip = True
# # i += 1
# else:
# ans2 = i
# break
# else:
# if ans1 == -1: ans1 = i
# ans2 = i
# break
# else:
# if ans1 == -1: ans1 = max(al)+1
# if ans2 == -1: ans2 = max(al)+1
# print(ans1+ans2)
# print(ans1,ans2)
| 7 | PYTHON3 |
# It's never too late to start!
from bisect import bisect_left
import os
import sys
from io import BytesIO, IOBase
from collections import Counter, defaultdict
from collections import deque
from functools import cmp_to_key
import math
import heapq
def sin():
return input()
def ain():
return list(map(int, sin().split()))
def sain():
return input().split()
def iin():
return int(sin())
MAX = float('inf')
MIN = float('-inf')
MOD = 1000000007
def sieve(n):
prime = [True for i in range(n+1)]
p = 2
while (p * p <= n):
if (prime[p] == True):
for i in range(p * p, n+1, p):
prime[i] = False
p += 1
s = set()
for p in range(2, n+1):
if prime[p]:
s.add(p)
return s
def readTree(n, m):
adj = [deque([]) for _ in range(n+1)]
for _ in range(m):
u,v = ain()
adj[u].append(v)
adj[v].append(u)
return adj
# Stay hungry, stay foolish!
def main():
for _ in range(iin()):
n = iin()
l = ain()
a = [0]*101
for i in l:
a[i] += 1
m1 = 101
for i in range(101):
if a[i] == 0:
m1 = i
break
else:
a[i] -= 1
m2 = 101
for i in range(101):
if a[i] == 0:
m2 = i
break
else:
a[i] -= 1
print(m1+m2)
# Fast IO Template starts
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")
if os.getcwd() == 'D:\\code':
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# Fast IO Template ends
if __name__ == "__main__":
main()
# Never Give Up - John Cena | 7 | PYTHON3 |
t = int(input())
for i in range(t):
n = int(input())
k = list(map(int, input().split()))
m1, m2 = 0, 0
for i in range(101):
if k.count(i) < 2:
m1 = i
break
for i in range(m1, 101):
if k.count(i) < 1:
m2 = i
break
print(m1+m2)
| 7 | PYTHON3 |
t=int(input())
for q in range(t):
n=int(input())
ch=input()
L=[int(i)for i in ch.split()]
M=[0]*102
for i in range(n):
M[L[i]]+=1
for i in range(102):
if M[i]==0:
x=i
break
M[i]-=1
for i in range(102):
if M[i]==0:
y=i
break
M[i]-=1
print(x+y)
| 7 | PYTHON3 |
import sys
import heapq, functools, collections
import math, random
from collections import Counter, defaultdict
# available on Google, not available on Codeforces
# import numpy as np
# import scipy
def solve(lst): # fix inputs here
console("----- solving ------")
c = Counter(lst)
cur = 0
while True:
if c[cur] < 2:
a = cur
break
cur += 1
while True:
if c[cur] < 1:
b = cur
break
cur += 1
# return a string (i.e. not a list or matrix)
return a + b
def console(*args): # the judge will not read these print statement
print('\033[36m', *args, '\033[0m', file=sys.stderr)
return
# fast read all
# sys.stdin.readlines()
for case_num in range(int(input())):
# read line as a string
# strr = input()
# read line as an integer
k = int(input())
# read one line and parse each word as a string
# lst = input().split()
# read one line and parse each word as an integer
lst = list(map(int,input().split()))
# read matrix and parse as integers (after reading read nrows)
# lst = list(map(int,input().split()))
# nrows = lst[0] # index containing information, please change
# grid = []
# for _ in range(nrows):
# grid.append(list(map(int,input().split())))
res = solve(lst) # please change
# Google - case number required
# print("Case #{}: {}".format(case_num+1, res))
# Codeforces - no case number required
print(res)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int A[n];
for (int i = 0; i < n; i++) cin >> A[i];
sort(A, A + n);
vector<int> h(A[n - 1] + 2, 0);
for (int i : A) {
h[i]++;
};
int ans = 0, c = 0, zero = -1, one = -1;
for (int i = 0; i < h.size(); i++) {
if (h[i] == 1) {
one = i;
break;
};
};
for (int i = 0; i < h.size(); i++) {
if (h[i] == 0) {
zero = i;
break;
};
};
if (one == -1 || one > zero) {
ans += 2 * zero;
} else {
ans += (one + zero);
};
cout << ans << endl;
};
return 0;
}
| 7 | CPP |
def mex(l):
l.sort()
if len(l)==0:
return(0)
elif l[0]!=0:
return(0)
else:
base=0
for m in range(1,len(l)):
if l[m]-base>=2:
break
else:
base=l[m]
base+=1
return(base)
t=int(input())
for i in range(t):
n=int(input())
l=list(map(int,input().split()))
l.sort()
d={}
for item in l:
d[item]=d.get(item,0)+1
a=list(set(l))
b=[]
for itm in a:
d[itm]=d.get(itm)-1
for it in l:
if d[it]>0:
b.append(it)
print(mex(a)+mex(b))
| 7 | PYTHON3 |
def mex(hash_map):
for i in range(0,1000):
if(i not in hash_map):
return i
return None
t=int(input())
while t>0:
t-=1
n=int(input())
a=list(map(int,input().strip().split()))
a.sort()
used={}
used2={}
for i in a:
if i in used:
used2[i]=1
else:
used[i]=1
print(mex(used)+mex(used2))
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int vis[110];
int a[110];
int main() {
int t;
int n;
cin >> t;
while (t--) {
scanf("%d", &n);
memset(vis, 0, sizeof(vis));
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
vis[a[i]]++;
}
int flag = 0, ans = 0;
for (int i = 0; i <= 100 && flag != 2; i++) {
if (flag == 0) {
if (vis[i] == 0)
ans += i * 2, flag = 2;
else if (vis[i] == 1)
ans += i, flag = 1;
} else if (flag == 1) {
if (vis[i] == 0) ans += i, flag = 2;
}
}
printf("%d\n", ans);
}
return 0;
}
| 7 | CPP |
# from bisect import bisect_left
TC = int(input())
for tc in range(TC):
N = int(input())
A = list(map(int, input().split()))
cnt = [0 for _ in range(101)]
# print(N, A)
for a in A:
cnt[a] += 1
m1 = -1
m2 = -1
for i, c in enumerate(cnt):
if m1 == -1:
if c < 2:
m1 = i
if c == 0:
m2 = i
break
print(m1 + m2)
# print(cnt[:10])
| 7 | PYTHON3 |
# -*- coding: utf-8 -*-
for _ in range(int(input())):
n = int(input())
a = list(map(int,input().split()))
mexA, mexB = 0,0
k = max(a)
for i in range(k+2):
if i not in a: mexA = i; break
if i in a: del a[a.index(i)]
for j in range(k+2):
if j not in a: mexB = j; break
if j in a: del a[a.index(j)]
print(mexA+mexB)
| 7 | PYTHON3 |
for _ in range(int(input())):
n=int(input())
c=[0]*(101)
for i in map(int,input().split()):
c[i]+=1
s=0
z=1;v=1
for i in range(101):
if z and c[i]==0:
s+=i
z=0
if v and c[i]<=1:
s+=i
v=0
if not z and not v:
break
print(s) | 7 | PYTHON3 |
t= int(input())
for _ in range(t):
n = int(input())
arr = list(map(int,input().strip().split()))[:n]
my_hash = [0]*200
for i in arr:
my_hash[i] += 1
#print(my_hash[:10])
a_mex = None
b_mex = None
for i in range(len(my_hash)):
if my_hash[i] == 0:
if a_mex is None:
a_mex = i
if b_mex is None:
b_mex = i
break
elif my_hash[i] == 1:
if a_mex is None:
a_mex = i
print(a_mex+b_mex)
| 7 | PYTHON3 |
n = int(input())
for _ in range(n):
mex = []
s = int(input())
myset = list(map(int, input().split()))
#print(myset)
for i in range(101):
if myset.count(i) == 0 and len(mex) == 0:
mex.append(i + i)
break
if myset.count(i) < (2 - len(mex)):
mex.append(i)
#print("c mex:", mex)
if len(mex) == 2:
break
print(sum(mex))
| 7 | PYTHON3 |
cases = int(input())
for i in range(cases):
n = int(input())
l2 = input().split(' ')
arr = []
sol = 0
for a in l2:
arr.append(int(a))
ss = []
n1 = n2 = 0
for b in range(0, 101):
if b in arr:
ss.append(b)
arr.remove(b)
else:
n1 = b
break
for c in range(0,101):
if c not in arr:
n2 = c
break
print(n1+n2)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int mex(set<int> s) {
if (s.size() == 0) return 0;
for (int i = 0;; i++)
if (s.find(i) == s.end()) return i;
return -1;
}
void solve() {
int n, x;
scanf("%d", &n);
vector<int> v(n);
set<int> a, b;
for (int i = 0; i < n; i++) {
scanf("%d", &x);
if (a.find(x) != a.end())
b.insert(x);
else
a.insert(x);
}
printf("%d\n", mex(a) + mex(b));
}
int main() {
int t;
scanf("%d", &t);
while (t--) solve();
return 0;
}
| 7 | CPP |
from collections import Counter
T = int(input())
for i in range(T):
N = int(input())
A = list(map(int,input().split()))
C = Counter(A)
flag1 = False
for i in range(102):
if not i in C:
if flag1:
b = i
else:
a = i
b = i
break
else:
if C[i]==1:
if not flag1:
a = i
flag1 = True
print(a+b) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int t, n, a[N];
int main() {
cin >> t;
while (t--) {
cin >> n;
memset(a, 0, sizeof a);
for (int i = 0; i < n; i++) {
int x;
cin >> x;
a[x]++;
}
int b[101], c[101], a1 = 0, a2 = 0;
memset(b, 0, sizeof b);
memset(c, 0, sizeof c);
for (int i = 0; i < 101; i++) {
if (a[i] >= 2)
b[i] = c[i] = 1;
else if (a[i] == 1)
b[i] = 1, c[i] = 0;
else
b[i] = c[i] = 0;
}
int s1, s2;
for (int i = 0; i < 101; i++) {
if (!b[i]) {
s1 = i;
break;
}
}
for (int i = 0; i < 101; i++) {
if (!c[i]) {
s2 = i;
break;
}
}
cout << s1 + s2 << endl;
}
return 0;
}
| 7 | CPP |
for _ in range(int(input())):
n=int(input())
arr=list(map(int,input().split()))
p={}
ans=0
for i in range(101):
p[i]=arr.count(i)
for k in p:
if p[k]==0:
ans+=k
break
for k in p:
if p[k]<2:
ans+=k
break
print(ans) | 7 | PYTHON3 |
from collections import Counter
y122=int(input())
for _ in range(y122):
a=input()
a=Counter(map(int,input().strip().split()))
b=0
c=0
d=2
for i in range(101):
try:
qw=a[i]
except:
a[i]=0
if a[i]<2:
if d==2:
if a[i]==1:
b=i
d-=1
else:
b=i
c=i
break
else:
if a[i]<1:
c=i
break
print(b+c)
| 7 | PYTHON3 |
import os
import sys
from io import BytesIO, IOBase
def solution(arr, n):
arr.sort()
s1, s2 = [], []
i = 0
while i < n:
s1.append(arr[i])
while i < n - 1 and arr[i] == arr[i + 1]:
s2.append(arr[i + 1])
i += 1
i += 1
res, x = 0, 0
while True:
if x not in s1:
res += x
break
x += 1
x = 0
while True and s2:
if x not in s2:
res += x
break
x += 1
write(res)
def main():
for _ in range(r_int()):
n = r_int()
arr = r_array()
solution(arr, n)
# fast-io region
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)
def input():
return sys.stdin.readline().rstrip("\r\n")
def write(*args, end='\n'):
for x in args[:-1]:
sys.stdout.write(str(x) + ' ')
sys.stdout.write(str(args[-1]))
sys.stdout.write(end)
def r_array():
return [int(x) for x in input().split()]
def r_int():
return int(input())
if __name__ == "__main__":
main()
| 7 | PYTHON3 |
from sys import stdin
input = stdin.readline
for _ in range(int(input())):
n = int(input())
a = [int(x) for x in input().split()]
res = 0
b = [0] * 101
for x in a:
b[x] += 1
for x in range(102):
if b[x] == 0:
res = x
break
else:
b[x] -= 1
for x in range(102):
if b[x] == 0:
res += x
break
print(res) | 7 | PYTHON3 |
MAXA = 100
def solve(n, a):
cnt = [0] * (MAXA + 1)
for v in a:
cnt[v] += 1
both = 0
while both < len(cnt) and cnt[both] > 1:
both += 1
single = both
while single < len(cnt) and cnt[single] > 0:
single += 1
return both + single
tests = int(input())
for test in range(tests):
n = int(input())
a = list(map(int, input().split()))
print(solve(n, a))
| 7 | PYTHON3 |
# -*- coding: utf-8 -*-
"""
Created on Sat Sep 12 19:34:24 2020
@author: Nihkv
"""
def mex(l):
if l==[]:
return 0
l.append(0)
for i in range(len(l)):
if i==l[i]:
pass
else:
return i
t=int(input())
for i in range(t):
n,a=int(input()),list(map(int,input().split()))
if n==0:
print(0)
elif n==1:
if a[0]==0:
print(1)
else:
print(0)
else:
i=0
a.sort()
la,lb=[],[]
while(i<(n-1)):
if a[i]==a[i+1]:
if a[i] not in la:
la.append(a[i])
if a[i+1] not in lb:
lb.append(a[1+i])
i+=2
else:
if a[i] not in la:
la.append(a[i])
i+=1
la.append(a[-1])
print(mex(la)+mex(lb))
| 7 | PYTHON3 |
for _ in range(int(input())):
n = int(input())
x = sorted(list(map(int, input().split())))
a, b = [], []
ans = 0
for i in x:
if i not in a:
a.append(i)
else:
b.append(i)
if a:
for i in range(max(a) + 2):
if i not in a:
ans += i
break
if b:
for i in range(max(b) + 2):
if i not in b:
ans += i
break
print(ans) | 7 | PYTHON3 |
from collections import Counter
t = int(input())
for i in range(t):
a = input()
nums = list(map(int, input().split()))
nums = Counter(nums)
cur = 0
while nums[cur]:
cur += 1
ans = cur
cur = 0
while nums[cur] > 1:
cur += 1
ans += cur
print(ans)
| 7 | PYTHON3 |
n=int(input())
for i in range(n):
a=[0]*102
m=int(input())
for j in input().split():
a[int(j)]+=1
s=0
ll=0
ink=0
f=True
while a[ll]!=0:
if a[ll]==1 and f==True:
ink=ll
f=False
ll+=1
if f==True:
s=ll+ll
else:
s=ink+ll
print(s)
| 7 | PYTHON3 |
from sys import stdin
def inp():
return stdin.buffer.readline().rstrip().decode('utf8')
def itg():
return int(stdin.buffer.readline())
def mpint():
return map(int, stdin.buffer.readline().split())
# ############################## import
# ############################## main
from collections import Counter
for __ in range(itg()):
n = itg()
c = Counter(mpint())
ans = v = 0
for k in range(101):
if v is None:
if c[k]:
ans += 1
else:
break
else:
if c[k] >= 2:
ans += 1
v += 1
elif c[k] == 1:
ans += 1 + v
v = None
else:
ans += v
break
print(ans)
# Please check!
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[n + 5];
int b[105] = {0};
for (int i = 0; i < n; i++) {
cin >> a[i];
b[a[i]]++;
}
int ans = 0;
bool f = false;
for (int i = 0; i < 105; i++) {
if (!f && b[i] == 0) {
ans += i + i;
break;
}
if (!f && b[i] == 1) {
f = true;
ans += i;
}
if (f && b[i] == 0) {
ans += i;
break;
}
}
cout << ans << "\n";
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
solve();
return 0;
}
| 7 | CPP |
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
# from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
# import numpy as np
starttime = time.time()
# import numpy as np
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]
try:
# sys.setrecursionlimit(int(pow(10,6)))
sys.stdin = open("input.txt", "r")
# sys.stdout = open("../output.txt", "w")
except:
pass
for _ in range(L()[0]):
n=L()[0]
A=L()
cnt=[0 for i in range(101)]
for ele in A:
cnt[ele]+=1
a=-1
b=-1
for i in range(101):
if cnt[i]==0:
b=i
if a==-1:
a=i
break
if cnt[i]<=1 and a==-1:
a=i
print(a+b)
endtime = time.time()
# print(f"Runtime of the program is {endtime - starttime}")
| 7 | PYTHON3 |
import sys
t=int(input().strip())
for a0 in range(t):
n=int(input())
l1=[int(i) for i in input().split()]
l=[]
r=[]
for i in l1:
if(i in l and i in r):
continue
elif(i in l):
r.append(i)
else:
l.append(i)
r.sort()
l.sort()
a=0
b=0
countl=0
countr=0
if(len(l)==0):
a=0
else:
for i in range(len(l)):
if(l[i]!=i):
a=i
break
else:
countl+=1
if(countl==len(l)):
a=len(l)
if(len(r)==0):
b=0
else:
for i in range(len(r)):
if(r[i]!=i):
b=i
break
else:
countr+=1
if(countr==len(r)):
b=len(r)
print(a+b)
| 7 | PYTHON3 |
def mex(a):
if(not a):
return 0
for i in range(max(a)+2):
if(i not in a):
return i
def main():
for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
s1,s2=set(),set()
a=sorted(a)
for i in range(n):
if(a[i] not in s1):
s1.add(a[i])
else:
s2.add(a[i])
print(mex(s1)+mex(s2))
main() | 7 | PYTHON3 |
z,zz=input,lambda:list(map(int,z().split()))
zzz=lambda:[int(i) for i in stdin.readline().split()]
szz,graph,mod,szzz=lambda:sorted(zz()),{},10**9+7,lambda:sorted(zzz())
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac
from itertools import permutations as permu
def lcd(xnum1,xnum2):return (xnum1*xnum2//gcd(xnum1,xnum2))
def prime(x):
p=ceil(x**.5)+1
for i in range(2,p):
if (x%i==0 and x!=2) or x==0:return 0
return 1
def dfs(u,visit,graph):
visit[u]=True
for i in graph[u]:
if not visit[i]:
dfs(i,visit,graph)
###########################---Test-Case---#################################
"""
"""
###########################---START-CODING---##############################
num=1
num=int(z())
for _ in range( num ):
n=int(z())
arr=zzz()
cnt=[0]*(103)
for i in arr:
cnt[i]+=1
ans=0
for i in range(102):
if cnt[i]>=1:
continue
else:
ans=i
break
for i in range(102):
if cnt[i]>=2:
continue
else:
ans+=i
break
print(ans)
| 7 | PYTHON3 |
from collections import Counter
t = int(input())
for _ in range(t):
n = int(input())
arr = list(map(int, input().split()))
d = Counter(arr)
for ele in d:
if d[ele] > 2:
d[ele] = 2
maximum1 = 0
maximum2 = 0
n = len(arr)
for i in range(0, len(arr)):
if i in d:
if d[i] == 2:
maximum1 += 1
maximum2 += 1
else:
maximum1 += 1
break
else:
break
if i in d:
i += 1
while i in d:
maximum1 += 1
i += 1
print(maximum1 + maximum2) | 7 | PYTHON3 |
import sys
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
a = list(map(int,input().split()))
a.sort()
ans = 0
flag = False
for i in range(n):
if i in a:
a.remove(i)
else:
ans+=i
flag = True
break
if not flag: ans+=n
flag = False
for i in range(n):
if i in a:
a.remove(i)
else:
ans+=i
flag = True
break
if not flag: ans += n
print(ans)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int a;
cin >> a;
int arr[105] = {0};
for (int i = 0; i < a; i++) {
int x;
cin >> x;
arr[x]++;
}
int b = -1;
int c = -1;
for (int i = 0; i <= 105; i++) {
if (arr[i] > 0) {
arr[i]--;
} else {
b = i;
break;
}
}
for (int i = 0; i <= 105; i++) {
if (arr[i] > 0) {
arr[i]--;
} else {
c = i;
break;
}
}
cout << b + c << endl;
}
}
| 7 | CPP |
for t in range(int(input())):
occ=[0]*120
n=int(input())
a=[int(x) for x in input().split()]
for x in a:
occ[x]+=1
fl=1
ok=0
m1=-1
for i in range(len(occ)):
if(occ[i]==0):
m1=i
break
else:
occ[i]-=1
m2=-1
for i in range(len(occ)):
if(occ[i]==0):
m2=i
break
else:
occ[i]-=1
print(m1+m2) | 7 | PYTHON3 |
for _ in range(int(input())):
n = int(input())
arr = [int(num) for num in input().split(' ')]
arr.sort()
a = [arr[0]]
b = []
for i in range(1,n):
if arr[i] == arr[i-1] + 1 :
a.append(arr[i])
else:
b.append(arr[i])
ans = 0
for i in range(a[-1] + 2):
if a.count(i) == 0:
ans = ans + i
break
if len(b)>0:
for i in range(b[-1] + 2):
if b.count(i) == 0:
ans = ans + i
break
print(ans)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int a[110];
int b[110];
int main() {
int t;
cin >> t;
while (t--) {
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
b[a[i]]++;
}
int ans = 0;
for (int i = 0; i < 110; i++) {
if (b[i] == 0) {
ans += i;
break;
}
b[i]--;
}
for (int i = 0; i < 110; i++) {
if (b[i] == 0) {
ans += i;
break;
}
}
cout << ans << endl;
}
return 0;
}
| 7 | CPP |
t=int(input())
for _ in range(t):
n=int(input())
arr=list(map(int,input().split()))
i=0
a=0
b=0
while True:
if i not in arr:
a=i
break
else:
arr.remove(i)
i+=1
i=0
while True:
if i not in arr:
b=i
break
else:
arr.remove(i)
i+=1
print(a+b)
| 7 | PYTHON3 |
t = int(input())
for _ in range(t):
n = int(input())
tab = list(map(int, input().split()))
arr = [0]*101
for i in tab:
arr[i] += 1
sol = 0
it = 0
while arr[it] >= 2:
it += 1
sol += it
#print(sol)
while(arr[it]>=1):
it += 1
sol += it
print(sol)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
long long a[maxn];
int vis[110];
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--) {
memset(vis, 0, sizeof(vis));
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
vis[a[i]]++;
}
int a = -1, b = -1;
for (int i = 0; i <= 100; i++) {
if (!vis[i]) {
a = i;
break;
} else
vis[i]--;
}
for (int i = 0; i <= 100; i++) {
if (!vis[i]) {
b = i;
break;
}
}
cout << a + b << '\n';
}
}
| 7 | CPP |
from sys import stdin
input = stdin.buffer.readline
for _ in range(int(input())):
n = int(input())
*a, = map(int, input().split())
d = {}
for i in a:
d[i] = d.get(i, 0) + 1
ans = cnt = 0
#print(d)
for i in range(n + 1):
if d.get(i, 0) < 2:
ans = i
#print(i)
break
for i in range(ans, n + 1):
if i not in d:
ans += i
#print(i)
break
#print(d)
print(ans)
| 7 | PYTHON3 |
t = int(input())
for _ in range(t):
n = int(input())
li = list(map(int, input().split()))
li.sort()
a, b = 0, 0
c = 0
for e in li:
if a == e:
a += 1
continue
if b == e:
b += 1
print(a+b) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int t;
int n, x, v[105], nr1, nr2;
int main() {
cin >> t;
++t;
while (--t) {
cin >> n;
for (int i = 0; i <= 100; ++i) v[i] = 0;
for (int i = 1; i <= n; ++i) {
cin >> x;
v[x]++;
}
nr1 = nr2 = -1;
for (int i = 0; i <= 100 && nr2 == -1; ++i) {
if (v[i] == 1 && nr1 == -1) nr1 = i;
if (v[i] == 0) {
nr2 = i;
if (nr1 == -1) nr1 = i;
}
}
cout << nr1 + nr2 << '\n';
}
return 0;
}
| 7 | CPP |
import sys
import math
def II():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
def MI():
return map(int, sys.stdin.readline().split())
def SI():
return sys.stdin.readline().strip()
t = II()
for q in range(t):
n = II()
a = LI()
d = [0]*101
for i in range(n):
d[a[i]]+=1
ans = 0
boo = False
for i in range(101):
if boo == False and d[i]<2:
ans+=i
boo = True
if boo == True and d[i]<1:
ans+=i
break
print(ans) | 7 | PYTHON3 |
for _ in range(int(input())):
n=int(input())
l=[int(x) for x in input().split()]
l.sort()
l1=[]
l2=[]
l1.append(l[0])
for i in range(1,n):
if l[i] not in l1:
l1.append(l[i])
elif l[i] not in l2:
l2.append(l[i])
else:
l1.append(l[i])
ans1=0
ans2=0
for k in range(101):
if k not in l1:
ans1+=k
break
for j in range(101):
if j not in l2:
ans2+=j
break
print(ans1+ans2) | 7 | PYTHON3 |
from collections import Counter
for _ in range(int(input())):
n=int(input())
arr=Counter(map(int,input().split()))
i=0
while arr[i]>0:
arr[i]-=1
i+=1
out=i
i=0
while arr[i]>0:
arr[i]-=1
i+=1
out+=i
print(out)
| 7 | PYTHON3 |
import collections
def solve():
n = int(input())
l = list(map(int, input().split()))
c = collections.Counter(l)
cur = 0
cur2 = 0
l.sort()
s = set(l)
for e in s:
if e != cur:
break
else:
cur += 1
for e in s:
if e == cur2 and c[e] > 1:
cur2 += 1
else:
break
return cur + cur2
for __ in range(int(input())):
print(solve())
| 7 | PYTHON3 |
for _ in range(int(input())):
n = int(input())
a = list(map(int,input().split()))
a.sort()
d = dict()
#print(d)
lst,lst1 = [],[]
for i in a:
d[i] = d.get(i,0)+1
for i,j in d.items():
if d[i]%2==0:
lst+=[i]*(d[i]//2)
lst1+=[i]*(d[i]//2)
else:
lst+=[i]*(d[i]//2+1)
lst1+=[i]*(d[i]//2)
#print(lst,lst1)
lst = list(set(lst))
lst1 = list(set(lst1))
p,q = 0,0
if lst!=[]:
for i in range(max(lst)+2):
if i not in lst:
p = i
break
if lst1!=[]:
for j in range(max(lst1)+2):
if j not in lst1:
q = j
break
#print(p,q,lst,lst1)
print(p+q)
| 7 | PYTHON3 |
# for #!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
# region fastio
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")
# endregion
from math import log2, ceil
from heapq import heappush, heappop, heapify
from copy import deepcopy
from collections import deque, Counter as CC
from bisect import bisect_left as bl
def main():
# Enter your code here. Read input from STDIN. Print output to STDOUT
for t in range(int(input())):
n = int(input())
l = [int(j) for j in input().split()]
m1 = -1
m2 = -1
x = CC(l)
ct = 0
for i in range(101):
if(m1!=-1 and m2!=-1):
break
if x[ct]==0:
if(m1==-1):
m1 = ct
if(m2==-1):
m2 = ct
break
elif x[ct]==1:
if m1!=-1 or m2!=-1:
pass
elif m1==-1:
m1 = ct
elif m2==-1:
m2 = ct
# print(m1, m2, ct)
ct+=1
print(m1+m2)
if __name__ == "__main__":
main() | 7 | PYTHON3 |
USE_FILE = False
FILE = None
if USE_FILE:
FILE = open("input.txt")
def rline():
return (FILE.readline() if USE_FILE else input()).split()
def readint():
return int(rline()[0])
def sum2(l, r):
return ((l + r) // 2) * (((r - l) // 2) + 1)
def solve():
n = readint()
line = rline()
all = [int(x) for x in line]
cnt = {}
for x in all:
if x not in cnt:
cnt[x] = 1
else:
cnt[x] += 1
res = 0
remain = 2
for i in range(103):
if i not in cnt:
if remain == 2:
return i * 2
else:
return res + i
if cnt[i] < remain:
res = i
remain -= 1
return res
if __name__ == '__main__':
t = int(rline()[0])
for z in range(t):
res = solve()
print(res)
| 7 | PYTHON3 |
import sys
from math import sqrt, gcd, ceil, log, floor
from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
input = sys.stdin.readline
read = lambda: list(map(int, input().strip().split()))
# MOD = 10**9 + 7
def main():
ans_ = []
for _ in range(int(input())):
n = int(input());arr = Counter(read())
ans = 0
for i in range(101):
if arr[i] < 2:ans += i;break
for i in range(101):
if arr[i] == 0:ans += i;break
ans_.append(ans)
print(("\n").join(map(str, ans_)))
if __name__ == "__main__":
main()
| 7 | PYTHON3 |
t=int(input())
for z in range(t):
n=int(input())
arr=input()
arr=arr.split()
a=[]
for i in range(n):
a.append(int(arr[i]))
s=[0]*101
for i in range(n):
s[a[i]] += 1
ans=0
for i in range(101):
if s[i] > 1:
continue
ans+=i
break
for i in range(101):
if s[i]>0:
continue
ans+=i
break
print(ans) | 7 | PYTHON3 |
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
cnt = [0 for i in range(101)]
for x in a:
cnt[x] += 1
ans = -1
for i in range(102):
if cnt[i] == 1 and ans == -1:
ans = i
if not cnt[i]:
ans = ans + i if ans != -1 else 2*i
break
print(ans)
| 7 | PYTHON3 |
n = int(input())
for i in range(n):
x = int(input())
s = list(map(int,input().split()))[:x]
s.sort()
a =[]
b =[]
j =2
#print(s)
while(j<len(s)+1):
if s[j-2]==s[j-1]:
a.append(s[j-2])
b.append(s[j-1])
j +=2
else:
a.append(s[j-2])
j+=1
a.append(s[len(s)-1])
mexA = 0
mexB = 0
# print(a)
# print(b)
if len(a) > 0:
# print(max(a)+1)
for k in range(max(a)+2):
if k not in a:
# print(k)
mexA = k
break
if len(b)>0:
for k in range(max(b)+2):
if k not in b:
mexB = k
break
# print(mexA, mexB)
print(mexA+mexB)
| 7 | PYTHON3 |
lst = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]
x = int(input())
for i in range(x):
sub1 = []; sub2 = []; check1 = []; check2 = []; u = 0; v = 0
n = int(input())
lst1 = [int(x) for x in input().split()]
copy = lst1.copy()
for j in lst1:
sub1.append(j)
copy.pop(0)
for k in copy:
if j==k:
sub2.append(k)
for l in lst:
if l not in sub1:
u = l
break
for m in lst:
if m not in sub2:
v = m
break
print(u+v) | 7 | PYTHON3 |
# cook your dish here
for _ in range(int(input())):
n=int(input())
l=list(map(int,input().split()))
a=[0 for i in range(max(l)+1)]
for i in l:
a[i]+=1
m,n=0,0
check=0
k=max(l)
for i in range(k+1):
if a[i]==0:
m,n=i,i
check=1
break
elif a[i]==1:
m=i
check=2
break
if check==1:
print(m+n)
elif check==2:
for j in range(i+1,k+1):
if a[j]==0:
n=j
check=0
break
if check==0:
print(m+n)
else:
print(m+k+1)
else:
print(2*k+2) | 7 | PYTHON3 |
t=int(input())
while t:
n=int(input())
a=list(map(int, input().split()))
a1=-1
b1=-1
d1={}
for i in a:
if i in d1.keys():
d1[i]+=1
else:
d1[i]=1
p=list(d1.keys())
p.sort()
for i in range(0,p[-1]+1):
if i not in d1.keys():
if a1==-1:
a1=i
b1=i
break
else:
if d1[i]==1 and a1==-1:
a1=i
else:
b1=p[-1]+1
if a1==-1:
a1=b1
print (a1+b1)
# p=0
# i=0
# count=0
# ans=0
# check=0
# first=-1
# second=-1
# while i<n:
# if a[i]==p:
# count=count+1
# i=i+1
# else:
# if count==0 and first==-1:
# first=p
# if count==1 and second==-1:
# second=p
# count=0
# p=p+1
# if count==1 and second==-1:
# second=p
# if first==-1:
# first=a[-1]+1
# if second==-1:
# second=a[-1]+1
# if first<second:
# print (first)
# else:
# print (first+second)
t=t-1 | 7 | PYTHON3 |
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split(" ")))
a.sort()
x,y = 0,0
for i in range(n):
if i in a:
a.remove(i)
if i==n-1:
x = i+1
else:
x = i
break
m = len(a)
for j in range(m):
if j in a:
a.remove(j)
if j==m-1:
y = j+1
else:
y = j
break
print(x+y) | 7 | PYTHON3 |
# -*- coding: utf-8 -*-
"""
Created on Sun Aug 12 10:16:00 2020
670-2: A. Subset Mex
@author: jonathan-chen10
"""
def main():
trials = input()
for i in range(int(trials)):
input()
nums = [int(n) for n in input().split()]
l_open = 2
mex_sum = 0
for j in range(max(nums)+2):
if nums.count(j) < l_open:
mex_sum += j * (l_open-nums.count(j))
l_open = nums.count(j)
if l_open == 0:
break
print(mex_sum)
if __name__ == '__main__':
main()
| 7 | PYTHON3 |
t = int(input())
for ex in range(t):
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
num = 0
while a.count(num) >= 2:
num += 1
m1 = num
while a.count(num) >= 1:
num+= 1
m2 = num
print(m1 + m2) | 7 | PYTHON3 |
for test in range(int(input())):
n = int(input())
l = [int(x) for x in input().split(" ")]
freq = [0 for i in range(0,101)]
for i in l:
freq[i] += 1
ans = 0
for i in range(101):
if freq[i]==0:
ans = 2*i
break
elif freq[i]==1:
ans += i
for j in range(i+1,101):
if freq[j] in [0]:
ans += j
break
break
print(ans) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int T, n;
int a[N], cnt[N];
int main() {
scanf("%d", &T);
while (T--) {
memset(cnt, 0, sizeof(cnt));
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]), cnt[a[i]]++;
int ans = 0;
int anscnt = 0;
for (int i = 0; i <= n; i++) {
if (cnt[i] == 0 && anscnt == 0)
ans += i * 2, anscnt = 2;
else if (cnt[i] == 1 && anscnt == 0) {
anscnt++;
ans += i;
} else if (cnt[i] == 0 && anscnt == 1) {
anscnt++;
ans += i;
}
if (anscnt == 2) break;
}
printf("%d\n", ans);
}
}
| 7 | CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.