solution
stringlengths 11
983k
| difficulty
int64 0
21
| language
stringclasses 2
values |
---|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int n, i;
long long int t;
cin >> t;
while (t--) {
cin >> n;
long long int a[n], x = -1, y = -1;
for (i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
for (i = 0; i < n; i++) {
if (a[i] - 1 == x)
x = a[i];
else {
if (a[i] - 1 == y) y = a[i];
}
}
cout << x + y + 2 << "\n";
}
return 0;
}
| 7 | CPP |
cases = int(input())
for _ in range(cases):
n = int(input())
ds = list(map(int, input().split()))
index = 102
cn = [0] * index
for v in ds:
cn[v] += 1
a, b = 0, 0
for i in range(index):
if cn[i] == 0:
b = i
break
else:
cn[i] -= 1
for i in range(index):
if cn[i] == 0:
a = i
break
print(a + b) | 7 | PYTHON3 |
from sys import stdin
from collections import Counter
N = int(stdin.readline())
for case in range(N):
length = int(stdin.readline())
array = [int(i) for i in stdin.readline().split()]
mexa = 0
mexb = 0
count = Counter(array)
for i in range(101):
if count[i] > 0:
count[i] -= 1
continue
else:
mexa = i
break
for i in range(101):
if count[i] == 0:
mexb = i
break
print(mexa + mexb)
| 7 | PYTHON3 |
for s in[*open(0)][2::2]:
a=[0]*102+[1]
for x in s.split():a[int(x)]+=1
i=a.index(0);print(i+min(i,a.index(1))) | 7 | PYTHON3 |
def mex(l):
l = sorted(l)
A = []
B = []
for var in l:
if A:
if var == A[-1]:
B.append(var)
else:
A.append(var)
else:
A.append(var)
return A, B
def min_mex(x):
if not x:
return 0
for i in range(0, max(x)):
if i not in x:
return i
return max(x) + 1
t = int(input())
for i in range(t):
n = int(input())
li = [int(s) for s in input().split()]
a, b = mex(li)
print(min_mex(a) + min_mex(b))
| 7 | PYTHON3 |
T = int(input().rstrip())
def get_mex(d):
c = 0
while True:
if c not in d or d[c] == 0:
return c
d[c] -= 1
c += 1
def solve(arr):
nd = {}
for i in arr:
if i in nd:
nd[i] += 1
else:
nd[i] = 1
mex1 = get_mex(nd)
mex2 = get_mex(nd)
return mex1 + mex2
for test in range(T):
n = int(input().rstrip())
arr = [int(x) for x in input().rstrip().split()]
ret = solve(arr)
print(ret)
| 7 | PYTHON3 |
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
# import time,random,resource
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)
def IF(c, t, f): return t if c else f
def YES(c): return IF(c, "YES", "NO")
def Yes(c): return IF(c, "Yes", "No")
def main():
t = I()
rr = []
for _ in range(t):
n = I()
a = LI()
c = collections.Counter(a)
d = e = 0
for i in range(n+1):
if c[i] < 2:
d = i
break
for i in range(n+1):
if c[i] < 1:
e = i
break
rr.append(d + e)
return JA(rr, "\n")
print(main())
| 7 | PYTHON3 |
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)
| 7 | PYTHON3 |
t = int(input())
while(t):
n = int(input())
li = list(map(int,input().split()))
a,b = [],[]
small_a, small_b =0,0
for i in li:
if i not in a:
a.append(i)
else:
b.append(i)
for i in range(0,101):
if i not in a:
small_a = i
break
for i in range(0,101):
if i not in b:
small_b = i
break
print(small_a + small_b)
t-=1 | 7 | PYTHON3 |
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
from collections import Counter
def find_mex(a):
Mex = 0
while Mex in a:
Mex += 1
return Mex
def main():
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
b = sorted(list(set(a)))
c = Counter(a)
p = []
q = []
for key, val in c.items():
if val > 1:
p.append(key)
q.append(key)
else:
p.append(key)
ans = find_mex(set(p)) + find_mex(set(q))
print(ans)
# 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
if __name__ == "__main__":
main()
| 7 | PYTHON3 |
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import copy
import decimal
class Scanner():
@staticmethod
def int():
return int(sys.stdin.readline().rstrip())
@staticmethod
def string():
return sys.stdin.readline().rstrip()
@staticmethod
def map_int():
return [int(x) for x in Scanner.string().split()]
@staticmethod
def string_list(n):
return [Scanner.string() for i in range(n)]
@staticmethod
def int_list_list(n):
return [Scanner.map_int() for i in range(n)]
@staticmethod
def int_cols_list(n):
return [Scanner.int() for i in range(n)]
def solve():
n = Scanner.int()
a = Scanner.map_int()
a.sort()
A = []
B = []
for i in range(0, n):
if len(A) == 0:
A.append(a[i])
elif A[-1] == a[i]:
B.append(a[i])
else:
A.append(a[i])
def mex(a):
a.sort()
s = set()
for i in a:
s.add(i)
for i in range(0, 101):
if not i in s:
return i
return 100
print(mex(A) + mex(B))
def main():
# sys.setrecursionlimit(1000000)
# sys.stdin = open("sample.txt")
T = Scanner.int()
for _ in range(T):
solve()
if __name__ == "__main__":
main()
| 7 | PYTHON3 |
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 9 14:53:08 2020
@author: mohit
"""
def DD(W):
if(len(W)==0):
return 0
else:
for p in range(len(W)):
if(p in W):
pass
else:
return p
return p+1
t=int(input())
for i in range(t):
N=int(input())
A=list(map(int,input().split()))
B=sorted(A)
C=[]
D=[]
Z=0
for j in range(len(B)):
if(B[j] in C):
pass
else:
C.append(B[j])
A.remove(B[j])
m=DD(C)
n=DD(A)
print(m+n)
| 7 | PYTHON3 |
# 1
import itertools
import math
import sys
from collections import defaultdict
def stdinWrapper():
data = '''4
6
0 2 1 5 0 1
3
0 1 2
4
0 2 0 1
6
1 2 3 4 5 6
'''
for line in data.split('\n'):
yield line
if '--debug' not in sys.argv:
def stdinWrapper():
while True:
yield input()
inputs = stdinWrapper()
def inputWrapper():
return next(inputs)
def getType(_type):
return _type(inputWrapper())
def getArray(_type):
return [_type(x) for x in inputWrapper().split()]
''' Solution '''
def solve(a):
a = sorted(a)
left = []
right = []
for x in a:
if not left or left[-1] != x:
left.append(x)
elif not right or right[-1] != x:
right.append(x)
def mex(arr):
if not arr:
return 0
for i in range(max(arr)):
if i not in arr:
return i
return max(arr)+1
return mex(left) + mex(right)
t = getType(int)
for _ in range(t):
n = getType(int)
a = getArray(int)
res = solve(a)
print(res)
| 7 | PYTHON3 |
from collections import defaultdict
if __name__=="__main__":
t=int(input())
for i in range(t):
n=int(input())
l=list(map(int,input().split()))
count=defaultdict(int)
for i in range(len(l)):
count[l[i]]+=1
l=set(l)
mex=0
total=0
for i in range(max(l)+2):
if count[i]==0 and total==0:
mex=2*i
break
elif count[i]==1 and total==0:
mex+=i
total+=1
elif count[i]==0 and total==1:
mex+=i
total+=1
if total==2:
break
print(mex)
| 7 | PYTHON3 |
def Input():
Str= input('')
List = Str.split(' ')
for i in range(len(List)):
List[i] = int(List[i])
return List
def Twice(List,n):
Count = 0
for i in range(len(List)):
if List[i] == n:
Count += 1
if Count == 2:
break
return Count
def Mex(List):
N = 0
Done = False
while Done == False:
x = Twice(List,N)
if x == 0 or x == 1:
Done = True
else:
N += 1
M = N
if x != 0:
Done = False
N += 1
while Done == False:
x = Twice(List,N)
if x == 0:
Done = True
else:
N += 1
return M+N
trials = int(input(''))
for i in range(trials):
input('')
List = Input()
print(Mex(List))
| 7 | PYTHON3 |
# Author : devil9614 - Sujan Mukherjee
from __future__ import division, print_function
import os,sys
import math
import collections
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
class my_dictionary(dict):
def __init__(self):
self = dict()
def add(self,key,value):
self[key] = value
def ii(): return int(input())
def si(): return input()
def mi(): return map(int,input().strip().split(" "))
def msi(): return map(str,input().strip().split(" "))
def li(): return list(mi())
def sli(): return list(msi())
def dmain():
sys.setrecursionlimit(100000000)
threading.stack_size(40960000)
thread = threading.Thread(target=main)
thread.start()
#from collections import deque, Counter, OrderedDict,defaultdict
#from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace
#from math import log,sqrt,factorial
#from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
#from decimal import *,threading
#from itertools import permutations
#Copy 2D list m = [x[:] for x in mark] .. Avoid Using Deepcopy
abc='abcdefghijklmnopqrstuvwxyz'
abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod=1000000007
#mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]
def getKey(item): return item[1]
def sort2(l):return sorted(l, key=getKey,reverse=True)
def d2(n,m,num):return [[num for x in range(m)] for y in range(n)]
def isPowerOfTwo (x): return (x and (not(x & (x - 1))) )
def decimalToBinary(n): return bin(n).replace("0b","")
def ntl(n):return [int(i) for i in str(n)]
def factorial(n): return 1 if (n==1 or n==0) else n * factorial(n - 1)
def ncr(n,r): return factorial(n)//(factorial(r)*factorial(n-r))
def binary_search(arr, low, high, x):
if high >= low:
mid = (high + low) // 2
if arr[mid] == x:
return mid
elif arr[mid] > x:
return binary_search(arr, low, mid - 1, x)
else:
return binary_search(arr, mid + 1, high, x)
else:
return -1
def ceil(x,y):
if x%y==0:
return x//y
else:
return x//y+1
def powerMod(x,y,p):
res = 1
x %= p
while y > 0:
if y&1:
res = (res*x)%p
y = y>>1
x = (x*x)%p
return res
def gcd(x, y):
while y:
x, y = y, x % y
return x
def nCr(n, r):
return (fact(n) / (fact(r)
* fact(n - r)))
# Returns factorial of n
def fact(n):
res = 1
for i in range(2, n+1):
res = res * i
return res
def isPrime(n) : # Check Prime Number or not
if (n <= 1) : return False
if (n <= 3) : return True
if (n % 2 == 0 or n % 3 == 0) : return False
i = 5
while(i * i <= n) :
if (n % i == 0 or n % (i + 2) == 0) :
return False
i = i + 6
return True
def read():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
def padded_bin_with_complement(x):
if x < 0:
return bin((2**16) - abs(x))[2:].zfill(16)
else:
return bin(x)[2:].zfill(16)
def binaryToDecimal(binary):
binary1 = binary
decimal, i, n = 0, 0, 0
while(binary != 0):
dec = binary % 10
decimal = decimal + dec * pow(2, i)
binary = binary//10
i += 1
print(decimal)
def CountFrequency(my_list):
freq = {}
for item in my_list:
if (item in freq):
freq[item] += 1
else:
freq[item] = 1
return freq
def pos(a):
b = [0]*len(a)
c = sorted(a)
for i in range(len(a)):
for j in range(len(a)):
if c[j] == a[i]:
b[i] = j
break
return b
def smallestDivisor(n):
# if divisible by 2
if (n % 2 == 0):
return 2
# iterate from 3 to sqrt(n)
i = 3
while(i * i <= n):
if (n % i == 0):
return i
i += 2
return n
def commonn(a,b,n):
c = []
for i in range(n):
if a[i] == b[i]:
c.append("-1")
else:
c.append(b[i])
return c
def find_lcm(num1, num2):
if(num1>num2):
num = num1
den = num2
else:
num = num2
den = num1
rem = num % den
while(rem != 0):
num = den
den = rem
rem = num % den
gcd = den
lcm = int(int(num1 * num2)/int(gcd))
return lcm
def sumdigit(n):
n = str(n)
k = 0
for i in range(len(n)):
k+=int(n[i])
return k
def main():
for _ in range(ii()):
n = ii()
a = li()
b = [0]*105
res = 0
for i in range(n):
b[a[i]]+=1
count = 0
f1 = f2 = 1
first = 0
sec = 0
# print(b[0:n])
for i in range(len(b)):
if b[i] > 1:
if f1:
first+=1
if f2:
sec+=1
elif b[i] ==1:
first+=1
f2=0
else:
break
# print(first,sec)
print(sec+first)
# print(b[0:n])
# print(res)
# region fastio
# template taken from https://github.com/cheran-senthil/PyRival/blob/master/templates/template.py
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")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
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()
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)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
#read()
main() | 7 | PYTHON3 |
t = int(input())
for _ in range(t):
n = int(input())
lol=[int(n) for n in input().split()]
l1 = []
l2 = []
ans = 0
for i in lol:
if i not in l1:
l1.append(i)
else:
l2.append(i)
if(len(l1) > 0 and len(l2) > 0):
for i in range(0, max(l1) + 2):
if i not in l1:
ans += i
f = 1
break
for j in range(0, max(l2) + 2):
if j not in l2:
ans += j
f = 1
break
if(len(l1)==0):
for j in range(0, max(l2) + 2):
if j not in l2:
ans += j
f = 1
break
if(len(l2)==0):
for i in range(0, max(l1) + 2):
if i not in l1:
ans += i
f = 1
break
print(ans)
# print(l1)
# print(l2) | 7 | PYTHON3 |
def segregate(arr, size):
j = 0
for i in range(size):
if (arr[i] <= 0):
arr[i], arr[j] = arr[j], arr[i]
j += 1
return j
def findMissingPositive(arr, size):
for i in range(size):
if (abs(arr[i]) - 1 < size and arr[abs(arr[i]) - 1] > 0):
arr[abs(arr[i]) - 1] = -arr[abs(arr[i]) - 1]
for i in range(size):
if (arr[i] > 0):
return i + 1
return size + 1
def findMissing(arr, size):
shift = segregate(arr, size)
if 0 not in arr:
return 0
if arr == []:
return 0
return findMissingPositive(arr[shift:], size - shift)
t = int(input())
for p in range(t):
n = int(input())
a = list(map(int, input().split()))
A = set()
B = set()
a.sort()
for i in range(n):
if a[i] not in A:
A.add(a[i])
else:
B.add(a[i])
A = list(A)
B = list(B)
print(findMissing(A, len(A)) + findMissing(B, len(B)))
| 7 | PYTHON3 |
from collections import Counter
def solver(arr):
if len(arr) == 0:
return 0
set_arr = list(set(arr))
set_arr.sort()
if set_arr[0] != 0:
return 0
val = 0
seq = []
for idx, item in enumerate(set_arr):
if idx == item:
val += 1
seq.append(idx)
else:
break
counted = dict(Counter(arr))
for i in seq:
val += min(counted[i] - 1, 1)
if counted[i] - 1 == 0:
break
return val
N = int(input())
for _ in range(N):
n = int(input())
arr = list(map(lambda x: int(x), input().split(" ")))
print(solver(arr)) | 7 | PYTHON3 |
for _ in range(int(input())):
n=int(input())
l=list(map(int,input().split()))
a,b=0,0
for i in range(101):
if i not in l:
a=i
break
for i in range(101):
if l.count(i)<=1:
b=i
break
print(a+b)
| 7 | PYTHON3 |
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
n = int(input())
a = [int(_) for _ in input().split()]
num = [0] * 101
for i in a:
num[i] += 1
ans = 0
mode = True
for i in range(101):
if num[i] >= 2:
if mode:
ans += 2
else:
ans += 1
continue
elif num[i] == 1:
mode = False
ans += 1
else:
break
print(ans) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (t--) {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
vector<long long> a(n);
long long x = 0, y = 0;
for (long long i = 0; i < n; ++i) cin >> a[i];
sort(a.begin(), a.end());
for (long long i = 0; i < n; ++i) {
if (a[i] == x) {
++x;
continue;
} else if (a[i] == y)
++y;
}
cout << x + y << '\n';
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout.tie(nullptr);
;
ll t;
cin >> t;
while (t--) {
int n;
cin >> n;
vi a(n);
map<int, int> m;
for (long long i = 0; i < n; i += 1) {
cin >> a[i];
m[a[i]]++;
}
int amex = 0, bmex = 0;
if ((m.begin())->first != 0) {
cout << 0 << endl;
continue;
}
for (auto i : m) {
if ((i.first) - amex == 0) {
amex = i.first + 1;
i.second--;
} else
break;
if ((i.second) && (i.first) - bmex == 0) {
bmex = i.first + 1;
}
}
cout << amex + bmex << endl;
}
return 0;
}
| 7 | CPP |
def mex(arr):
if len(arr)==0:
return 0
for i in range(max(arr)+2):
if i not in arr:
res=i
return res
for i in range(int(input())):
n=int(input())
arr=list(map(int,input().split()))
arr.sort()
a=[]
b=[]
i=0
while i<len(arr)-1:
if arr[i+1]==arr[i]:
a.append(arr[i])
b.append(arr[i+1])
i+=2
else:
a.append(arr[i])
i+=1
a.append(arr[len(arr)-1])
print(mex(a)+mex(b))
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long double PI = 3.14159265358979323846;
const long long M = 1e9 + 7;
const long long inf = 1e18;
const long long ms = 2e5 + 5;
static int fastline = []() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
return 0;
}();
;
unsigned long long ans;
void solve() {
long long n;
cin >> n;
vector<long long> v1, v2;
map<long long, long long> mp;
for (int i = 0; i < n; i++) {
long long a;
cin >> a;
mp[a]++;
}
for (auto &it : mp) {
if (it.second) {
v1.push_back(it.first);
it.second--;
}
if (it.second) {
v2.push_back(it.first);
it.second--;
}
}
long long a1 = v1.size(), a2 = v2.size();
for (int i = 0; i < v1.size(); i++) {
if (i != v1[i]) {
a1 = i;
break;
}
}
for (int i = 0; i < v2.size(); i++) {
if (i != v2[i]) {
a2 = i;
break;
}
}
cout << a1 + a2 << endl;
}
int main() {
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
| 7 | CPP |
for _ in range(int(input())):
n, a = int(input()), sorted([int(x) for x in input().split()])
v = 0
i = 0
for row in set(a):
if row == i:
if a.count(row) >= 2 and row == v: v += 1; i += 1
else: i += 1
print(v+i) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int n, k = 0, t;
int main() {
cin >> t;
while (t--) {
cin >> n;
vector<int> cnt(101, 0);
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (x <= 100) ++cnt[x];
}
int min1 = 0, min2 = 0;
for (int i = 0; i < 101; i++) {
if (i > min1)
break;
else if (cnt[i] > 1) {
min1++;
if (i <= min2) min2++;
} else if (cnt[i] == 1)
min1++;
}
cout << min1 + min2 << endl;
}
}
| 7 | CPP |
for i in range(int(input())):
n = int(input())
l = list(map(int,input().split()))
m = 0
a = []
b = []
for i in l:
if i not in a:
a.append(i)
else:
b.append(i)
if len(a) > 0:
for i in range(max(a)+2):
if i not in a:
x = i
break
else:
x = 0
if len(b) > 0:
for i in range(max(b)+2):
if i not in b:
y = i
break
else:
y = 0
print(x+y) | 7 | PYTHON3 |
# @uthor : Kaleab Asfaw
from sys import stdin, stdout
# Fast IO
# from math import gcd
def input():
a = stdin.readline()
if a[-1] == "\n": a = a[:-1]
return a
def print(*argv, end="\n", sep=" "):
n = len(argv)
for i in range(n):
if i == n-1: stdout.write(str(argv[i]))
else: stdout.write(str(argv[i]) + sep)
stdout.write(end)
# Others
mod = 10**9+7
def lcm(x, y): return (x * y) / (gcd(x, y))
def fact(x, mod=mod):
ans = 1
for i in range(1, x+1): ans = (ans * i) % mod
return ans
def arr2D(n, m, default=0):
lst = []
for i in range(n): temp = [default] * m; lst.append(temp)
return lst
def sortDictV(x): return {k: v for k, v in sorted(x.items(), key = lambda item : item[1])}
def solve(n, lst):
cnt = [0]*101
for i in lst:
if cnt[i] == -1: cnt[i] = 1
else: cnt[i] += 1
check = False
a, b = -1, -1
for i in range(101):
if not check:
if cnt[i] == 1:
a = i
check = True
elif cnt[i] == 0:
return i*2
else:
if cnt[i] == 0:
b = i
break
if b == -1: return 0
else: return a + b
for _ in range(int(input())): # Multicase
n = int(input())
lst = list(map(int, input().split()))
print(solve(n, lst)) | 7 | PYTHON3 |
def subsetMax(arr,n):
countDict = {}
setA = set()
setB = set()
setC = set([i for i in range(101)])
for i in range(n):
if(arr[i] not in setA):
setA.add(arr[i])
elif(arr[i] not in setB):
setB.add(arr[i])
remA = min(setC-setC.intersection(setA))
remB = min(setC-setC.intersection(setB))
return remA+remB
if __name__ == '__main__':
testCases = input()
for i in range(int(testCases)):
n = int(input())
arr = list(map(int,input().split()))
ans = subsetMax(arr,n)
print(ans)
| 7 | PYTHON3 |
def inp():
return int(input())
for _ in range(inp()):
n = inp()
arr = list(map(int, input().split(' ')))
if 0 not in arr:
print(0)
else:
a = []
b = []
ans = []
for i in arr:
if i not in a:
a.append(i)
else:
b.append(i)
for j in range(n):
if j not in a:
ans.append(j)
break
if len(ans) == 0:
ans.append(max(a) + 1)
if len(b) > 0:
for j in range(n):
if j not in b:
ans.append(j)
break
else:
ans.append(0)
print(sum(ans)) | 7 | PYTHON3 |
def fun(n,arr):
arr.sort()
a=arr
b=[]
i=0
while True:
if i in a:
ind = arr.index(i)
b.append(arr.pop(ind))
i+=1
else:
mex_b = i
break
j=0
while True:
if j in a:
j+=1
else:
mex_a = j
break
print(mex_a+mex_b)
t=int(input())
n = []
num = []
for i in range(t):
n.append(int(input()))
tem = list(int(ele) for ele in input().strip().split(" "))
num.append(tem)
for i in range(t):
fun(n[i],num[i])
| 7 | PYTHON3 |
def solve():
# put code here
n=int(input())
cntr=[0]*200
arr=[int(v) for v in input().split()]
for v in arr:
cntr[v]+=1
ans=0
st=0
for i in range(len(cntr)):
if cntr[i]>=2:
ans=i+1
else:
st=i
break
while st<len(cntr) and cntr[st]:
st+=1
ans+=st
print(ans)
t = int(input())
for _ in range(t):
solve()
| 7 | PYTHON3 |
N = int(input())
for _ in range(N):
_ = int(input())
A = sorted(list(map(int, input().split())))
seta = set()
setb = set()
for a in A:
if a in seta:
setb.add(a)
else:
seta.add(a)
numa, numb = -1,-1
for i in range(101):
if (i not in seta) and numa == -1:
numa = i
if (i not in setb) and numb == -1:
numb = i
print(numa + numb)
| 7 | PYTHON3 |
def subset_mex(arr):
s = list(set(arr))
s.sort()
a = []
b = []
min = 0
for i in s:
if arr.count(i)>=2:
a.append(i)
b.append(i)
else:
a.append(i)
if a:
for i in range(max(a)):
if i not in a:
min+=i
break
else:
min+=max(a)+1
if b:
for i in range(max(b)):
if i not in b:
min+=i
break
else:
min+=max(b)+1
return min
t = int(input())
for _ in range(t):
n = int(input())
arr = list(map(int,input().split()))
print(subset_mex(arr)) | 7 | PYTHON3 |
for _ in range(int(input())):
n = int(input())
a = [int(x) for x in input().split()]
A = []
B = []
ans = 0
count = 0
for i in a:
if i not in A:
A.append(i)
else:
B.append(i)
for i in range(n + 1):
if i not in A:
ans += i
break
for i in range(n + 1):
if i not in B:
ans += i
break
print(ans)
| 7 | PYTHON3 |
t = int(input())
while t > 0:
n = int(input())
counts = [0]*101
elems = list(map(int, input().split()))
for elem in elems:
counts[elem] += 1
i = 0
sum = 0
flag = 0
while i <= 100:
if counts[i] == 0:
print(sum)
break
if counts[i] == 1:
sum+=1
flag = 1
elif counts[i] >= 2 and i != 0:
if flag == 0:
sum+=2
else:
sum+=1
elif counts[i] >= 2:
sum += 2
i+=1
t -= 1
| 7 | PYTHON3 |
t = int(input())
for i in range(t):
counts = [0 for i in range(101)]
input()
numbers = [int(i) for i in input().split(' ')]
for n in numbers:
counts[n] +=1
x = 0
while counts[x] >= 2:
x += 1
ans = x
while counts[x] >= 1:
x += 1
ans += x
print(ans)
| 7 | PYTHON3 |
import math
for _ in range(int(input())):
n = int(input())
l= sorted(list(map(int,input().split())))
a = 0
b = 0
for i in l:
if a== i:
a += 1
elif b == i:
b +=1
print(a+b)
| 7 | PYTHON3 |
t = int(input())
def mex(setter):
a = set(range(0, 101))
return min(a - setter)
for i in range(t):
n = int(input())
a = list(map(int,input().split()))
A = set(a)
B = set()
for elem in a:
if a.count(elem) > 1:
B.add(elem)
minimum = mex(A)+mex(B)
print(minimum)
| 7 | PYTHON3 |
import collections
m = int(input())
while(m):
z=0
l=0
n=int(input())
x=collections.Counter(map(int,input().split()))
for i in range (101):
if(x[i]==0 and z>0):
print(l+i)
break
if(x[i]==0):
print(i*2)
break
elif(x[i]==1):
if(z==0):
l=i
z+=1
m-=1
| 7 | PYTHON3 |
t=int(input())
for i in range(t):
n=int(input())
lst = list(map(int, input().strip().split(' ')))
lst.sort()
#mylist = list( dict.fromkeys(lst) )
if lst[0]!=0:
print(0)
elif n==1 and lst[0]==0:
print(1)
elif n>1 and lst[1]!=0:
lst = list( dict.fromkeys(lst) )
for j in range(len(lst)):
if lst[j]==j:
if j==len(lst)-1:
print(len(lst))
else:
print(j)
break
else:
lst1=[0]
lst2=[0]
for j in range(2,n):
if lst[j]==lst1[-1]+1:
lst1.append(lst[j])
elif lst[j]==lst2[-1]+1:
lst2.append(lst[j])
elif lst[j]==lst1[-1] or lst[j]==lst2[-1]:
continue
else:
break
print(lst1[-1]+lst2[-1]+2)
| 7 | PYTHON3 |
t= int(input())
for _ in range(t):
n=int(input())
l=list(map(int,input().split()))
dic=[0]*(100+1)
for i in range(len(l)):
dic[l[i]]+=1
a=b=0
for i in range(len(dic)):
if dic[i]==0:
a=i
break
for i in range(len(dic)):
if dic[i]<=1:
b=i
break
print(a+b) | 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 --------------------
def findmex(arr):
cur=0
for s in range(len(arr)):
if arr[s]==cur:
cur+=1
return cur
for j in range(int(input())):
n=int(input());vals=list(map(int,input().split()));enc=set([])
m1=[];m2=[]
for s in range(n):
if not(vals[s] in enc):
m1.append(vals[s]);enc.add(vals[s])
else:
m2.append(vals[s])
m1.sort();m2.sort()
print(findmex(m1)+findmex(m2)) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> a(n);
for (auto& cur : a) cin >> cur;
sort(a.begin(), a.end());
int mex1 = 0;
for (auto& cur : a) {
if (cur == mex1) {
cur = -1;
mex1++;
}
}
int mex2 = 0;
for (auto& cur : a) {
if (cur == mex2) {
cur = -1;
mex2++;
}
}
cout << mex1 + mex2 << endl;
}
int main() {
int t;
cin >> t;
while (t--) {
solve();
}
}
| 7 | CPP |
for _ in range(0,int(input())):
n =int(input())
a =list(map(int,input().split()))
a.sort()
m,n=0,0
for i in a:
if i==m:
m+=1
elif i==n:
n+=1
print(m+n)
| 7 | PYTHON3 |
import sys
#from collections import deque
#from functools import *
#from fractions import Fraction as f
from copy import *
from bisect import *
#from heapq import *
#from math import *
#from itertools import permutations ,product
def eprint(*args):
print(*args, file=sys.stderr)
zz=1
#sys.setrecursionlimit(10**6)
if zz:
input=sys.stdin.readline
else:
sys.stdin=open('input.txt', 'r')
sys.stdout=open('all.txt','w')
di=[[-1,0],[1,0],[0,1],[0,-1]]
def inc(d,c,x=1):
d[c]=d[c]+x if c in d else x
def bo(i):
return ord(i)-ord('A')
def li():
return [int(xx) for xx in input().split()]
def fli():
return [float(x) for x in input().split()]
def comp(a,b):
if(a>b):
return 2
return 2 if a==b else 0
def gi():
return [xx for xx in input().split()]
def fi():
return int(input())
def pro(a):
return reduce(lambda a,b:a*b,a)
def swap(a,i,j):
a[i],a[j]=a[j],a[i]
def si():
return list(input().rstrip())
def mi():
return map(int,input().split())
def gh():
sys.stdout.flush()
def isvalid(i,j):
return 0<=i<n and 0<=j<m and a[i][j]!="."
def bo(i):
return ord(i)-ord('a')
def graph(n,m):
for i in range(m):
x,y=mi()
a[x].append(y)
a[y].append(x)
t=fi()
while t>0:
t-=1
n=fi()
a=li()
d=[0]*(100+2)
ans=0
for i in range(n):
d[a[i]]+=1
for i in range(n+2):
if d[i]==1:
ans+=i
for j in range(i+1,n+2):
if d[j]==0:
ans+=j
break
break
elif d[i]==0:
ans+=2*i
break
print(ans) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
long long int a[n];
long long int b[105] = {0};
for (long long int i = 0; i < n; i++) {
cin >> a[i];
b[a[i]]++;
}
long long int mexa[105] = {0};
long long int mexb[105] = {0};
for (long long int i = 0; i <= 100; i++) {
if (b[i] > 0) {
if (b[i] > 1) {
mexa[i] = b[i] / 2;
mexb[i] = b[i] - mexa[i];
} else
mexa[i] = 1;
}
}
long long int ans = 0;
for (long long int i = 0; i <= 100; i++) {
if (mexa[i] == 0) {
ans = ans + i;
break;
}
}
for (long long int i = 0; i <= 100; i++) {
if (mexb[i] == 0) {
ans = ans + i;
break;
}
}
cout << ans << endl;
}
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(106):
if freq[i] > 0:
freq[i] -= 1
else:
c = i
break
print(b+c)
t -= 1
| 7 | PYTHON3 |
from sys import stdin, exit, setrecursionlimit
from collections import deque
input = stdin.readline
lmi = lambda: list(map(int, input().split()))
mi = lambda: map(int, input().split())
si = lambda: input().strip('\n')
ssi = lambda: input().strip('\n').split()
mod = 10**9+7
for _ in range(int(input())):
n = int(input())
a = lmi()
tot = 0
for i in range(n+1):
if a.count(i) < 2:
tot += i
break
for i in range(n+1):
if a.count(i) < 1:
tot += i
break
print(tot) | 7 | PYTHON3 |
cases = int(input())
for _ in range(cases):
count = 0
a = []
n = int(input())
b = list(map(int,input().split()))
b.sort()
s = set(b)
s = list(s)
s.sort()
#print(a,b,s)
a.append(s[0])
b.remove(s[0])
for x in range(len(s)-1):
if s[x] == s[x+1] - 1:
a.append(s[x+1])
b.remove(s[x+1])
else:
break
#print(a,b,s)
for x in range(101):
if x not in a:
count += x
break
#print(count)
for x in range(101):
if x not in b:
count += x
break
print(count) | 7 | PYTHON3 |
def answer(n,A):
arr=[0]*(102)
for i in range(n):
arr[A[i]]+=1
s1=set()
s2=set()
ans=0
for i in range(102):
if arr[i]==0:
ans=i
break
flag=1
for i in range(102):
if arr[i]==1:
s1.add(i)
flag=0
elif arr[i]>1:
s1.add(i)
if flag:
s2.add(i)
else:
break
if s2 and s1:
ans=max(ans,max(s2)+1+max(s1)+1)
if s1:
ans=max(ans,max(s1)+1)
return ans
t=int(input())
for i in range(t):
n=int(input())
l=list(map(int,input().split()))
print(answer(n,l)) | 7 | PYTHON3 |
t = int(input())
while t > 0:
n = int(input())
x = [int(i) for i in input().split()]
x.sort()
if 0 not in x:
print(0)
else:
a = []
b = []
res = 0
m = 0
a.append(x[0])
for i in range(1, n):
if a[m] + 1 == x[i]:
a.append(x[i])
m += 1
elif a[m] == x[i]:
if x[i] not in b:
b.append(x[i])
else:
if x[i] not in b:
b.append(x[i])
break
res = a[m] + 1
z = 0
for i in range(len(b)):
if b[i] == z:
z += 1
else:
break
res += z
print(res)
t -= 1
| 7 | PYTHON3 |
import sys,bisect
input = sys.stdin.buffer.readline
T = int(input())
for testcase in range(T):
n = int(input())
a = list(map(int,input().split()))
a.sort()
flag = [True]*n
res = -1
for j in range(101):
k = bisect.bisect_left(a,j)
if k < n and a[k] == j:
flag[k] = False
res = j
else:
break
c = []
for i in range(n):
if flag[i]:
c.append(a[i])
ans = -1
c = list(set(c))
for e in c:
if e == ans+1:
ans = e
else:
break
print(ans+res+2)
| 7 | PYTHON3 |
for i in range(int(input())):
n = int(input())
arr = list(map(int, input().strip().split()))
i = 0
arr.sort()
while True:
if i in arr:
arr.remove(i)
i += 1
else:
break
a = i
i = 0
while True:
if i in arr:
arr.remove(i)
i += 1
else:
break
b = i
print(a+b)
| 7 | PYTHON3 |
for _ in range(int(input())):
ans=0
n=int(input())
a=list(map(int,input().split()))
a.sort()
d=list(set(a))
#print(d)
f=0
for i in range(len(d)):
if(i==d[i]):
#print(i)
for j in range(len(a)):
if(a[j]==i):
a.pop(j)
break
continue
else:
f=1
ans+=i
break
if(f==0):
ans+=i+1
#print(a)
d=list(set(a))
f=0
for i in range(len(d)):
if(i==d[i]):
continue
else:
f=1
ans+=i
break
if(f==0 and len(d)!=0):
ans+=i+1
print(ans)
| 7 | PYTHON3 |
for _ in range(int(input())):
n=int(input())
frequency = [0]*101
for item in list(map(int,input().split())):
frequency[item]+=1
ans=0
for i in range(101):
if (frequency[i]==0):
ans+=i
break
frequency[i]-=1
for i in range(101):
if frequency[i]==0:
ans+=i
break
print(ans) | 7 | PYTHON3 |
for _ in range(int(input())):
n=int(input())
l=list(map(int,input().split()))
a=[0]*102
for i in l:
a[i]+=1
ma1=-1
ma2=-1
for i in range(101):
if a[i]>=2:
if ma2==i-1:
ma2=i
ma1=i
else:
ma1=i
elif a[i]==1:
ma1=i
else:
break
print(ma1+ma2+2)
| 7 | PYTHON3 |
for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
a.sort()
b=[0]*105
for i in range(n):
b[a[i]]+=1
# print(b)
c=0
for i in range(len(b)):
if b[i]>0:
b[i]-=1
else:
c+=i
break
for i in range(len(b)):
if b[i]>0:
b[i]-=1
else:
c+=i
break
print(c) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n;
cin >> t;
while (t--) {
cin >> n;
int p = -1, q = -1, a, d = 0;
vector<int> h(101, 0);
for (int i = 0; i < n; i++) {
cin >> a;
h[a]++;
}
for (int i = 0; i <= n; i++) {
if (h[i] == 0) {
cout << p + q + 2 << endl;
break;
} else if (h[i] == 1) {
p++;
d = 1;
} else {
p++;
if (d == 0) q++;
}
}
}
}
| 7 | CPP |
import sys
from collections import Counter
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10**19
MOD = 10**9 + 7
for _ in range(INT()):
N = INT()
A = LIST()
C = Counter(A)
has2 = True
ans = 0
for i in range(101):
if C[i] >= 2 and has2:
ans += 2
elif C[i] >= 1:
has2 = False
ans += 1
else:
break
print(ans)
| 7 | PYTHON3 |
import sys
import string
import math
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache
from fractions import Fraction
def mi(s):
return map(int, s.strip().split())
def lmi(s):
return list(mi(s))
def tmi(s):
return tuple(mi(s))
def mf(f, s):
return map(f, s)
def lmf(f, s):
return list(mf(f, s))
def js(lst):
return " ".join(str(d) for d in lst)
def jsns(lst):
return "".join(str(d) for d in lst)
def line():
return sys.stdin.readline().strip()
def linesp():
return line().split()
def iline():
return int(line())
def mat(n):
matr = []
for _ in range(n):
matr.append(linesp())
return matr
def matns(n):
mat = []
for _ in range(n):
mat.append([c for c in line()])
return mat
def mati(n):
mat = []
for _ in range(n):
mat.append(lmi(line()))
return mat
def pmat(mat):
for row in mat:
print(js(row))
def solve():
line()
arr = lmi(line())
counts = Counter(arr)
i = 0
j = 0
while True:
noj = True
noi = True
if counts[i] >= 1:
counts[i] -= 1
i += 1
noi = False
if counts[j] >= 1:
counts[j] -= 1
j += 1
noj = False
if noi and noj:
break
print(i + j)
def main():
t = iline()
for _ in range(t):
solve()
main()
| 7 | PYTHON3 |
from collections import defaultdict
t = int(input())
for i in range(t):
n = int(input())
A = list(map(int, input().split()))
ct = defaultdict(int)
for x in A:
ct[x] = ct[x] + 1
ans = 0
for i in range(101):
if ct[i] == 0:
ans += i
break
ct[i] -= 1
for i in range(101):
if ct[i] == 0:
ans += i
break
print(ans)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
sort(a.begin(), a.end());
int j = 0;
int ans = 0;
int cnt = 0;
for (int i = 0; i < n; ++i) {
int k = 0;
while (i < n && a[i] == j) {
++i;
++k;
}
if (cnt == 0) {
if (k == 0) {
ans += 2 * j;
cnt += 2;
} else if (k == 1) {
ans += j;
++cnt;
}
} else if (cnt == 1) {
if (k == 0) {
ans += j;
++cnt;
}
}
if (cnt == 2) {
break;
}
++j;
--i;
}
if (cnt == 2) {
cout << ans << endl;
} else if (cnt == 1) {
cout << ans + j << endl;
} else {
cout << j * 2 << endl;
}
}
int main() {
int n = 1;
cin >> n;
for (unsigned long long i = 0; i < n; ++i) {
solve();
}
return 0;
}
| 7 | CPP |
t = int(input())
while t>0:
t-=1
n = int(input())
C = list(map(int,input().split(' ')))
m = max(C)
A = []
for i in range(m+1):
if i in C:
A.append(i)
C.remove(i)
A.sort()
C.sort()
ans = 0
for i in range(max(A)+1):
if i not in A:
ans+=i
break
else:
ans+=max(A)+1
if len(C)!=0:
for i in range(max(C)+1):
if i not in C:
ans+=i
break
else:
ans+=max(C)+1
print(ans) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string token;
int t;
cin >> token;
t = stoi(token);
for (int i = 0; i < t; i++) {
vector<int> v;
int n;
cin >> token;
n = stoi(token);
for (int j = 0; j < n; j++) {
cin >> token;
v.push_back(stoi(token));
}
sort(v.begin(), v.end());
int c = 0;
int a;
for (int j = 0; j < v.size();) {
if (v[j] == c) {
v.erase(v.begin() + j);
c++;
} else if (v[j] < c) {
j++;
} else {
break;
}
}
a = c;
int b;
c = 0;
for (int j = 0; j < v.size();) {
if (v[j] == c) {
v.erase(v.begin() + j);
c++;
} else if (v[j] < c) {
j++;
} else {
break;
}
}
b = c;
cout << a + b << '\n';
}
return 0;
}
| 7 | CPP |
t = int(input())
for _ in range(t):
n = int(input())
l1 = sorted([int(x) for x in input().split()])
i=0
ans=0
while i<2:
j=0
while j in l1:
l1.remove(j)
j+=1
ans+=j
i+=1
print(ans) | 7 | PYTHON3 |
t=int(input())
while (t>0):
n=int(input())
arr=[int(i) for i in input().split()]
a=[]
b=[]
for i in arr:
if (i not in a):a.append(i)
else:b.append(i)
i=0
j=0
while (i in a):
i+=1
while (j in b):
j+=1
print(i+j)
t-=1 | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long double PI = 3.14159265359;
long long inf = 1000000000000000007;
long long mod = 1000000007;
long long mod1 = 998244353;
const bool multi = 1;
long long ile[107];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long tt;
if (multi)
cin >> tt;
else
tt = 1;
while (tt--) {
for (long long i = 0; i <= 100; i++) ile[i] = 0;
long long n, x;
cin >> n;
for (long long i = 0; i < n; i++) {
cin >> x;
ile[x]++;
}
long long a, b, it = 0;
while (ile[it] >= 1) it++;
a = it, it = 0;
while (ile[it] >= 2) it++;
b = it;
cout << a + b << '\n';
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for (int i = 0; i < t; i++) {
int n;
cin >> n;
vector<int> arr(101, 0);
for (int j = 0; j < n; j++) {
int temp;
cin >> temp;
arr[temp]++;
}
int count1 = 0, count2 = 0, flag = 0;
for (int j = 0; j < n; j++) {
if (arr[j] == 0) {
cout << count1 + count2 << endl;
break;
}
if (arr[j] > 0) {
if (arr[j] >= 2 && flag == 0) {
count1 = j + 1;
count2 = j + 1;
}
if (arr[j] == 1 || flag == 1) {
count1 = j + 1;
flag = 1;
}
}
if (j == n - 1) {
cout << count1 + count2 << endl;
break;
}
}
}
}
| 7 | CPP |
import sys
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
a = list(map(int,input().split()))
data = [0]*101
for i in range(n):
data[a[i]]+=1
M = -1
m = -1
for i in range(101):
if data[i]<=1:
m = i
break
for i in range(101):
if data[i]==0:
M = i
break
print(m+M)
| 7 | PYTHON3 |
k = int(input())
for _ in range(k):
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
check = 0
b_check = 0
stack = 0
a, b = 0, 0
for e in arr:
if e == check:
stack += 1
if stack >= 3:
continue
elif e != check:
check += 1
stack = 1
if e == a and e != b:
b_check = 1
elif e != a and e != b:
break
if check == a and stack == 1:
a += 1
elif check == b and stack == 2 and b_check == 0:
b += 1
print(a+b) | 7 | PYTHON3 |
# cook your dish here
from sys import stdin,stdout
from collections import Counter
from itertools import permutations
import bisect
import math
I=lambda: map(int,stdin.readline().split())
I1=lambda: stdin.readline()
#(a/b)%m =((a%m)*pow(b,m-2)%m)%m
for _ in range(int(I1())):
n=int(I1())
a=list(I())
m=max(a)
d={i:0 for i in range(101)}
for x in a:
d[x]+=1
ans=0
#print(d)
for x in range(101):
if(d[x]==0):
ans+=x
break
d[x]-=1
#print(d)
for x in range(101):
if(d[x]==0):
ans+=x
break
d[x]-=1
#print(d)
print(ans)
| 7 | PYTHON3 |
"""
pppppppppppppppppppp
ppppp ppppppppppppppppppp
ppppppp ppppppppppppppppppppp
pppppppp pppppppppppppppppppppp
pppppppppppppppppppppppppppppppp
pppppppppppppppppppppppp
ppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppp
pppppppppppppppppppppppppppppppppppppppppppppppp ppppppppppppppppppppp
ppppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppp
ppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppp
pppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppppp
ppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppppppp
pppppppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppp
pppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppp
ppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppppp
pppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppppppp
ppppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppppp
pppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppp
ppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppp
pppppppppppppppppppppppp
pppppppppppppppppppppppppppppppp
pppppppppppppppppppppp pppppppp
ppppppppppppppppppppp ppppppp
ppppppppppppppppppp ppppp
pppppppppppppppppppp
"""
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
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
from decimal import Decimal
# sys.setrecursionlimit(pow(10, 6))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(var, end="\n"): sys.stdout.write(str(var)+end)
def outa(*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)]
for _ in range(int(data())):
n = int(data())
c = C(l())
answer = 0
for i in range(101):
if not c[i]:
answer = i
break
c[i] -= 1
for i in range(101):
if not c[i]:
answer += i
break
out(answer)
| 7 | PYTHON3 |
inputed = []
count = int(input())
linesPer = 2
for i in range(count*linesPer):
inputed.append(input())
for i in range(count):
try:
inputed[1] = inputed[1].split(" ")
inputed[1] = [int(x) for x in inputed[1]]
countArr = [0 for x in inputed[1]]
maxA = 0
maxB = 0
for x in inputed[1]:
if x < len(countArr):
countArr[x] += 1
#print(countArr)
for i in range(len(countArr)):
if countArr[i] > 0:
maxA += 1
countArr[i] -= 1
else:
break
for i in range(len(countArr)):
if countArr[i] > 0:
maxB += 1
else:
break
print(maxA + maxB)
except:
print(0)
#print("maxA",maxA,"maxB",maxB)
for i in range(linesPer):
del inputed[0]
| 7 | PYTHON3 |
if __name__ == '__main__':
t = int(input())
for _ in range(t):
n = int(input())
a = [int(x) for x in input().split()]
counter = [0 for _ in range(102)]
for i in a:
counter[i] += 1
mex_a = mex_b = 0
flag1 = flag2 = True
for i in range(len(counter)):
if counter[i] == 0:
mex_a = i if flag1 else mex_a
mex_b = i
break
elif counter[i] == 1:
if not flag1:
mex_b = i
break
else:
flag1 = False
mex_a = i
res1 = mex_a + mex_b
mex_a = mex_b = 0
flag1 = flag2 = True
for i in range(len(counter)):
if counter[i] == 0:
mex_a = i if flag1 else mex_a
mex_b = i
break
elif counter[i] == 1:
if flag1:
flag1 = False
mex_a = i
res2 = mex_a + mex_b
print(max(res1, res2))
| 7 | PYTHON3 |
for _ in range(int(input())):
n = int(input())
data = list(map(int, input().split()))
cnt = [0] * 101
for x in data:
cnt[x] += 1
first = 0
while True:
if cnt[first] >= 1:
cnt[first] -= 1
else:
break
first += 1
second = 0
while True:
if cnt[second] >= 1:
cnt[second] -= 1
else:
break
second += 1
print(first + second) | 7 | PYTHON3 |
for _ in range(int(input())):
n = int(input())
s = list(map(int,input().split()))
a,b = set(),set()
for i in s:
if i in a:
b.add(i)
else:
a.add(i)
mexa = 0
for i in range(n+1):
if i not in a:
mexa = i
break
mexb = 0
for i in range(n+1):
if i not in b:
mexb = i
break
print(mexa+mexb)
| 7 | PYTHON3 |
import os
import sys
from io import BytesIO, IOBase
def gcd(a,b):
# a>b
if(b==0):
return a
else:
return gcd(b,a%b)
def prime(n) :
if (n <= 1) :
return False
if (n <= 3) :
return True
# This is checked so that we can skip
# middle five numbers in below loop
if (n % 2 == 0 or n % 3 == 0) :
return False
i = 5
while(i * i <= n) :
if (n % i == 0 or n % (i + 2) == 0) :
return False
i = i + 6
return True
def divisors(n) :
# Note that this loop runs till square root
i = 1
div = []
while i <= math.sqrt(n):
if (n % i == 0) :
# If divisors are equal, print only one
if (n / i == i) :
div.append(i)
else :
# Otherwise print both
div.append(i)
div.append(n//i)
i = i + 1
return div
def solve() :
for _ in range(int(input())) :
n = int(input())
arr = list(map(int,input().split()))
cnt = [0]*101
for i in arr :
cnt[i] += 1
ans = 0
flag1 = 1
flag2 = 1
for i in range(len(cnt)) :
if cnt[i]==0 and flag1==1:
ans = ans + i
flag1 = 0
if cnt[i]<=1 and flag2==1 :
ans = ans + i
flag2 = 0
if flag1==0 and flag2==0 :
break
print(ans)
def main():
solve()
pass
# 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
if __name__ == "__main__":
main()
| 7 | PYTHON3 |
for i in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
a = 0
br = 0
g=True
for j in range(0, max(arr) + 1):
if arr.count(j) >= 2 and g==True:
a = j + 1
br = j + 1
elif arr.count(j)>= 1 and abs(j - a) == 0 :
g=False
a = j + 1
else:
break
print(br + a)
| 7 | PYTHON3 |
for i in range(int(input())):
n = int(input())
a = list(map(int,input().split()))
ar = []
for i in a:
if a.count(i) > 1:
ar.append(i)
ai = dict.fromkeys(ar)
l = dict.fromkeys(a)
ai = sorted(ai)
l = sorted(l)
c = 0
b = 0
if 0 in ai:
for i in range(len(ai)):
if i == ai[i]:
c+=1
else:
break
elif len(ai) == 0:
c = 0
else:
c = 0
if 0 in l:
for i in range(len(l)):
if i == l[i]:
b += 1
else:
break
elif len(l) == 0:
b = 0
else:
b = 0
print(c+b) | 7 | PYTHON3 |
from collections import defaultdict,Counter
from math import ceil,floor,log2
#n,k = map(int,input().split())
#a = sorted(list(map(int,input().split())))
#a = list(map(int,input().split()))
alph = "abcdefghijklmnopqrstuvwxyz"
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int,input().split()))
c = Counter(a)
el = sorted(list(set(a)))
total = 0
added = False
prev = -1
count = 0
for x in el:
if x-2>=prev:
break
else:
count+=1
if c[x]==1 and not added:
total+=count-1
added = True
prev = x
#print (count,c[x],x,total)
if added:
total+=count
else:
total+=count*2
print (total)
#break
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 5;
const int MAX = 1e5 + 5;
const int MOD = 1e9 + 7;
const long long INF = 1e14;
int test, n, x, y;
int f[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> test;
while (test--) {
cin >> n;
for (int i = 0; i <= n; ++i) {
f[i] = 0;
}
for (int i = 1; i <= n; ++i) {
cin >> x;
if (x <= n) {
++f[x];
}
}
x = -1;
y = -1;
for (int i = 0; i <= n; ++i) {
if (f[i] == 0) {
if (x == -1) {
x = i;
}
if (y == -1) {
y = i;
}
break;
}
if (f[i] == 1) {
if (i == 0 || x == i) {
x = i + 1;
if (y == -1) {
y = 0;
}
} else {
if (i == 0 || y == i) {
++y;
} else {
break;
}
}
} else {
if (i == 0 || x == i) {
x = i + 1;
}
if (i == 0 || y == i) {
y = i + 1;
}
if (x != i + 1 && y != i + 1) {
break;
}
}
}
cout << x + y << "\n";
}
}
| 7 | CPP |
t = int(input())
for _ in range(t):
u = input()
nums = list(map(int,input().split()))
A = [0 for _ in range(101)]
B = [0 for _ in range(101)]
for i in nums:
if(A[i] == 0):
A[i] = 1
else:
B[i] = 1
A_stop = 1000
B_stop = 1000
for i in range(101):
if (A_stop == 1000) and A[i] == 0:
A_stop = i
if (B_stop == 1000) and B[i] == 0:
B_stop = i
A_stop = min(A_stop,100)
B_stop = min(B_stop,100)
print(A_stop + B_stop) | 7 | PYTHON3 |
import collections
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,input().split()))
t = inp()
for _ in range(t):
n = inp()
l = inlt()
a, b = set(), set()
for num in l:
if num not in a:
a.add(num)
else:
b.add(num)
res = 0
afound = bfound = False
for i in range(0, 101):
if not afound and i not in a:
res += i
afound = True
if not bfound and i not in b:
res += i
bfound = True
if afound and bfound:
print(res)
break
| 7 | PYTHON3 |
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
l = [0 for i in range(105)]
for i in a:
l[i]+=1
s = 0
mn = 2
for i in range(105):
if l[i]==0:
break
if l[i]>=mn:
s+=mn
elif l[i]<mn:
mn = l[i]
s+=mn
print(s)
| 7 | PYTHON3 |
# import sys
# input = lambda: sys.stdin.readline().rstrip()
import sys
import math
input = sys.stdin.readline
from collections import deque
from queue import LifoQueue
def binary_search(a, n):
L = 0
R = len(a)-1
while L<=R:
mid = L+(R-L)//2
if a[mid]==n:
return mid
elif a[mid]<n:
L = mid+1
else:
R = mid-1
return -1
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
a.sort()
c = [a[0]]
I = [0]
for i in range(n):
if c[-1]!=a[i] and a[i]==c[-1]+1:
c.append(a[i])
I.append(i)
k = 0
for i in I:
a.pop(i-k)
k+=1
a = list(set(a))
a.sort()
# a.append(10**4)
ans = 0
for i in range(len(a)):
if i!=a[i]:
if i-1>=0:
ans+=a[i-1]+1
else:
ans+=0
break
elif i==len(a)-1:
ans+=a[i]+1
for i in range(len(c)):
if i!=c[i]:
if i-1>=0:
ans+=c[i-1]+1
else:
ans+=0
break
elif i==len(c)-1:
ans+=c[i]+1
# print(a,c)
print(ans) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e2;
int t, n;
int freq[N + 2];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
clock_t ck;
ck = clock();
cin >> t;
while (t--) {
cin >> n;
memset(freq, 0, sizeof(freq));
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
freq[x]++;
}
int a, b;
a = b = 0;
for (int i = 0; i <= N && freq[i] > 0; i++) {
a = i + 1;
}
for (int i = 0; i <= N && freq[i] > 1; i++) {
b = i + 1;
}
cout << a + b << '\n';
}
ck = clock() - ck;
cerr << "It took " << 1.0 * ck / CLOCKS_PER_SEC << " sec\n";
return 0;
}
| 7 | CPP |
testcases = int(input())
for _ in range(testcases):
cnt = [0 for i in range(0,101)]
n = int(input())
l = list(map(int,input().split()))
for i in l :
cnt[i]+=1
a_mex,i = 0,0
while(True):
if(cnt[i] == 0):
a_mex = i
break
else:
cnt[i]-=1
i+=1
b_mex,i = 0 , 0
while(True):
if(cnt[i] == 0):
b_mex = i
break
i+=1
print(a_mex + b_mex) | 7 | PYTHON3 |
from sys import stdin, stdout
def mex(ar):
n = len(ar)
have = [False] * (n + 1)
for item in ar:
if item <= n:
have[item] = True
return have.index(False)
t = int(stdin.readline())
for case in range(t):
n = int(stdin.readline())
xx = list(map(int, stdin.readline().split()))
count = [0] * 101
for item in xx:
count[item] += 1
mex_a = mex(xx)
b = []
for i in range(101):
if count[i] >= 2:
b.append(i)
stdout.write("{}\n".format(mex_a + mex(b)))
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
struct point {
int x, y, ind;
char ch;
};
long long mod = 1e9 + 7;
long long powmod(long long a, long long b) {
long long res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
}
return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long fact[13];
void factorial() {
fact[0] = 1;
for (long long i = 1; i < 12; i++) fact[i] = (fact[i - 1] * i);
}
bool cmp(point A, point B) {
if (A.x != B.x) return A.x < B.x;
return A.y < B.y;
}
vector<long long> sie;
long long spf[1000007 + 7];
void sieve() {
for (long long i = 2; i < 1000007; i++) {
if (spf[i] == 0) {
spf[i] = i;
sie.push_back(i);
}
for (long long j = 0; j < ((long long)(sie).size()) &&
i * sie[j] <= 1000007 && sie[j] <= spf[i];
j++)
spf[i * sie[j]] = sie[j];
}
}
const long long mx = 2e5 + 9;
long long n, a, b, _, ans, c, _1, _2, m, an, k, need, shuru, _3, _c, _a, _b,
way, _0, mex, q, d, temp;
double DF, AF;
string st, good, orginal[2];
long long ar[mx], co[mx];
long long sol(long long x, long long y) { return _1; }
void f() {
for (long long i = 0; i < 103; i++) co[i] = 0;
cin >> n;
for (long long i = 0; i < n; i++) {
cin >> _;
co[_]++;
}
ans = 0;
_ = 0;
for (long long i = 0; i < 102; i++) {
if (co[i] >= 2) continue;
if (co[i] && _ == 0) {
_ = 1;
ans = i;
} else if (co[i] == 0 && _ == 1) {
_ = 2;
ans += i;
} else if (co[i] == 0 && _ == 0) {
_ = 2;
ans = i + i;
}
if (_ == 2) break;
}
cout << ans << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cout << setprecision(12);
long long _t;
cin >> _t;
for (long long w = 0; w < _t; w++) f();
return 0;
}
| 7 | CPP |
for i in range(int(input())):
n=int(input())
a=list(map(int,input().split()))[:n]
a=sorted(a)
b,c=[],[]
for i in range(n):
if a[i] not in b:
b.append(a[i])
else:
c.append(a[i])
x,y=0,0
while x in b:
x=x+1
while y in c:
y=y+1
print(x+y)
| 7 | PYTHON3 |
def solve(a):
x, y = -1, -1
for i in range(101):
if a.count(i) == 0:
return 2*i if x == -1 else x + i
elif a.count(i) == 1:
if x == -1:
x=i
return 101 + x if x != -1 else 101 + 102
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split(" ")))
a.sort()
print(solve(a))
| 7 | PYTHON3 |
from __future__ import division, print_function
# import threading
# threading.stack_size(2**27)
# import sys
# sys.setrecursionlimit(10**7)
# sys.stdin = open('inpy.txt', 'r')
# sys.stdout = open('outpy.txt', 'w')
from sys import stdin, stdout
import bisect #c++ upperbound
import math
import heapq
i_m=9223372036854775807
def inin():
return int(input())
def stin():
return input()
def spin():
return map(int,stin().split())
def lin(): #takes array as input
return list(map(int,stin().split()))
def matrix(n):
#matrix input
return [list(map(int,input().split()))for i in range(n)]
################################################
def count2Dmatrix(i,list):
return sum(c.count(i) for c in list)
def modinv(n,p):
return pow(n,p-2,p)
def GCD(x, y):
x=abs(x)
y=abs(y)
if(min(x,y)==0):
return max(x,y)
while(y):
x, y = y, x % y
return x
def Divisors(n) :
l = []
for i in range(1, int(math.sqrt(n) + 1)) :
if (n % i == 0) :
if (n // i == i) :
l.append(i)
else :
l.append(i)
l.append(n//i)
return l
prime=[]
def SieveOfEratosthenes(n):
global prime
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
f=[]
for p in range(2, n):
if prime[p]:
f.append(p)
return f
q=[]
def dfs(n,d,v,c):
global q
v[n]=1
x=d[n]
q.append(n)
j=c
for i in x:
if i not in v:
f=dfs(i,d,v,c+1)
j=max(j,f)
# print(f)
return j
# d = {}
"""*******************************************************"""
for _ in range(inin()):
n = inin()
a = lin()
a.sort()
x, y = 0, 0
for i in a:
if x == i:
x += 1
elif y == i:
y += 1
print(x + y) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[102], x, i, j;
for (i = 0; i <= 100; i++) {
a[i] = 0;
}
while (n--) {
cin >> x;
a[x]++;
}
for (i = 0; a[i] > 1; i++)
;
for (j = i; a[j] > 0; j++)
;
cout << (j + i);
cout << '\n';
}
return 0;
}
| 7 | CPP |
for _ in range(int(input())):
n=int(input())
lis=list(map(int,input().split()))
lis.sort()
a=[-1]
b=[-1]
for i in lis:
if a[-1]!=i:
a.append(i)
elif b[-1]!=i:
b.append(i)
i1=-1
for j in a:
if j!=i1:
break
else:
i1+=1
k1=-1
for j in b:
if j!=k1:
break
else:
k1+=1
print(i1+k1)
| 7 | PYTHON3 |
t=int(input())
while t:
n=int(input())
arr=list(map(int,input().split()))
occr=[0]*101
for e in arr:
occr[e]+=1
ans=0
minb=102
for i in range(0,101):
if occr[i]==0:
mina=i
break
for i in range(0,101):
if occr[i]==1:
minb=i
break
if mina<minb or minb==102:
minb=mina
ans=mina+minb
print(ans)
t-=1 | 7 | PYTHON3 |
t = int(input())
i = 0
while i < t:
n = int(input())
a = list(map(int, input().split()))
A = [0] * 101
Am = -1
Bm = -1
for j in a:
A[j] += 1
index = 0
while True:
while A[index] >= 2:
Am = index
Bm = index
index += 1
while A[index] >= 1:
Am = index
index += 1
print(Am + Bm + 2)
break
i += 1
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
long long t;
cin >> t;
for (long long i = 0; i < t; i++) {
int n;
cin >> n;
int a[n];
for (int j = 0; j < n; j++) {
cin >> a[j];
}
int occur[102];
for (int j = 0; j <= 101; j++) {
occur[j] = 0;
}
for (int j = 0; j < n; j++) {
occur[a[j]]++;
}
int ans = 0;
int one = 0;
for (int j = 0; j <= 101; j++) {
if (occur[j] >= 2) {
} else if (occur[j] == 1) {
if (one == 1) {
continue;
}
ans += j;
one = 1;
} else {
if (one == 1) {
ans += j;
} else {
ans += 2 * j;
}
break;
}
}
cout << ans << endl;
}
return 0;
}
| 7 | CPP |
for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
d = dict()
for i in range(n):
if arr[i] in d:
d[arr[i]] += 1
else:
d[arr[i]] = 1
mexa = 0
mexb = 0
flag = True
for i in range(max(arr)+1):
if i in d:
if d[i] > 1:
mexa = i+1
if flag:
mexb = i+1
else:
mexa = i+1
flag = False
else:
break
print(mexa+mexb)
| 7 | PYTHON3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.