text stringlengths 198 433k | conversation_id int64 0 109k |
|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bob is about to take a hot bath.
There are two taps to fill the bath: a hot water tap and a cold water tap. The cold water's temperature is t1, and the hot water's temperature is t2. The cold water tap can transmit any integer number of water units per second from 0 to x1, inclusive. Similarly, the hot water tap can transmit from 0 to x2 water units per second.
If y1 water units per second flow through the first tap and y2 water units per second flow through the second tap, then the resulting bath water temperature will be:
<image>
Bob wants to open both taps so that the bath water temperature was not less than t0. However, the temperature should be as close as possible to this value. If there are several optimal variants, Bob chooses the one that lets fill the bath in the quickest way possible.
Determine how much each tap should be opened so that Bob was pleased with the result in the end.
Input
You are given five integers t1, t2, x1, x2 and t0 (1 ≤ t1 ≤ t0 ≤ t2 ≤ 106, 1 ≤ x1, x2 ≤ 106).
Output
Print two space-separated integers y1 and y2 (0 ≤ y1 ≤ x1, 0 ≤ y2 ≤ x2).
Examples
Input
10 70 100 100 25
Output
99 33
Input
300 500 1000 1000 300
Output
1000 0
Input
143 456 110 117 273
Output
76 54
Note
In the second sample the hot water tap shouldn't be opened, but the cold water tap should be opened at full capacity in order to fill the bath in the quickest way possible.
Submitted Solution:
```
from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce,cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 998244353
def factors(n):return sorted(list(set(reduce(list.__add__,([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))))
# def inv_mod(n):return pow(n, mod - 2, mod)
def li():return [int(i) for i in input().rstrip('\n').split()]
def st():return input().rstrip('\n')
def val():return int(input().rstrip('\n'))
def li2():return [i for i in input().rstrip('\n').split(' ')]
def li3():return [int(i) for i in input().rstrip('\n')]
def compare(a,b):
if a[-1]<b[-1]:return -1
elif a[-1]>b[-1]:return 1
else:
if sum(a[:-1]) > sum(b[:-1]):return -1
return 1
def give(a,b):
temp = (a*t1 + b*t2)/(a + b)
if temp < t:
return [a,b,1000]
return [a,b,abs(t - temp)]
t1, t2, x1, x2, t = li()
bestans = []
if t == t1 and t1 == t2:
print(x1,x2)
elif t == t1:
print(x1,0)
elif t == t2:
print(0,x2)
else:
currans = []
currcheck = float('inf')
r = (t2 - t)/(t - t1)
bestans.append(give(x1,x2))
bestans.append(give(0,x2))
bestans.append(give(x1,0))
for i in bestans:
if currcheck > i[-1]:
currcheck = i[-1]
currans = i[:-1]
if currcheck == i[-1] and sum(currans) < sum(i[:-1]):
currans = i[:-1]
for i in range(1,x2 + 1):
curry1 = i*r
a = curry1
b = i
if 0 <= int(curry1) <= x1:
c,d,e = give(int(a),b)
if e < currcheck:
currcheck = e
currans = [c,d]
if e == currcheck and sum(currans) < c + d:
currans = [c,d]
if 0 <= math.ceil(curry1) <= x1:
c,d,e = give(math.ceil(a),b)
if e < currcheck:
currcheck = e
currans = [c,d]
if e == currcheck and sum(currans) < c + d:
currans = [c,d]
# for i,(a,b,c) in enumerate(bestans):
# if ((a*t1 + b*t2)/(a + b)) < t:
# bestans[i][-1] = 1000
# continue
# bestans[i][-1] = abs(t - ((a*t1 + b*t2)/(a + b)))
# bestans.sort(key=cmp_to_key(compare))
# print(bestans)
print(*currans)
```
No
| 6,700 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bob is about to take a hot bath.
There are two taps to fill the bath: a hot water tap and a cold water tap. The cold water's temperature is t1, and the hot water's temperature is t2. The cold water tap can transmit any integer number of water units per second from 0 to x1, inclusive. Similarly, the hot water tap can transmit from 0 to x2 water units per second.
If y1 water units per second flow through the first tap and y2 water units per second flow through the second tap, then the resulting bath water temperature will be:
<image>
Bob wants to open both taps so that the bath water temperature was not less than t0. However, the temperature should be as close as possible to this value. If there are several optimal variants, Bob chooses the one that lets fill the bath in the quickest way possible.
Determine how much each tap should be opened so that Bob was pleased with the result in the end.
Input
You are given five integers t1, t2, x1, x2 and t0 (1 ≤ t1 ≤ t0 ≤ t2 ≤ 106, 1 ≤ x1, x2 ≤ 106).
Output
Print two space-separated integers y1 and y2 (0 ≤ y1 ≤ x1, 0 ≤ y2 ≤ x2).
Examples
Input
10 70 100 100 25
Output
99 33
Input
300 500 1000 1000 300
Output
1000 0
Input
143 456 110 117 273
Output
76 54
Note
In the second sample the hot water tap shouldn't be opened, but the cold water tap should be opened at full capacity in order to fill the bath in the quickest way possible.
Submitted Solution:
```
a=input()[:2]
if (a=="10"):print("99 33")
else:print("0 1000")
```
No
| 6,701 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bob is about to take a hot bath.
There are two taps to fill the bath: a hot water tap and a cold water tap. The cold water's temperature is t1, and the hot water's temperature is t2. The cold water tap can transmit any integer number of water units per second from 0 to x1, inclusive. Similarly, the hot water tap can transmit from 0 to x2 water units per second.
If y1 water units per second flow through the first tap and y2 water units per second flow through the second tap, then the resulting bath water temperature will be:
<image>
Bob wants to open both taps so that the bath water temperature was not less than t0. However, the temperature should be as close as possible to this value. If there are several optimal variants, Bob chooses the one that lets fill the bath in the quickest way possible.
Determine how much each tap should be opened so that Bob was pleased with the result in the end.
Input
You are given five integers t1, t2, x1, x2 and t0 (1 ≤ t1 ≤ t0 ≤ t2 ≤ 106, 1 ≤ x1, x2 ≤ 106).
Output
Print two space-separated integers y1 and y2 (0 ≤ y1 ≤ x1, 0 ≤ y2 ≤ x2).
Examples
Input
10 70 100 100 25
Output
99 33
Input
300 500 1000 1000 300
Output
1000 0
Input
143 456 110 117 273
Output
76 54
Note
In the second sample the hot water tap shouldn't be opened, but the cold water tap should be opened at full capacity in order to fill the bath in the quickest way possible.
Submitted Solution:
```
def R(): return map(int, input().split())
def I(): return int(input())
def S(): return str(input())
def L(): return list(R())
from collections import Counter
import math
import sys
t1,t2,x1,x2,t0=R()
mint=10*100
y1min=-1
y2min=-1
for y1 in range(x1+1):
y2=min(math.ceil(y1*(t0-t1)/(t2-t0)),x2)
if y1+y2==0: continue
if mint>(y1*t1+y2*t2)/(y1+y2):
mint=(y1*t1+y2*t2)/(y1+y2)
#print(mint)
y1min=y1
y2min=y2
if y1min==0:
k=x2//y2min
elif y2min==0:
k=x1//y1min
else:
k=min(x1//y1min,x2//y2min)
print(k*y1min,k*y2min)
```
No
| 6,702 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bob is about to take a hot bath.
There are two taps to fill the bath: a hot water tap and a cold water tap. The cold water's temperature is t1, and the hot water's temperature is t2. The cold water tap can transmit any integer number of water units per second from 0 to x1, inclusive. Similarly, the hot water tap can transmit from 0 to x2 water units per second.
If y1 water units per second flow through the first tap and y2 water units per second flow through the second tap, then the resulting bath water temperature will be:
<image>
Bob wants to open both taps so that the bath water temperature was not less than t0. However, the temperature should be as close as possible to this value. If there are several optimal variants, Bob chooses the one that lets fill the bath in the quickest way possible.
Determine how much each tap should be opened so that Bob was pleased with the result in the end.
Input
You are given five integers t1, t2, x1, x2 and t0 (1 ≤ t1 ≤ t0 ≤ t2 ≤ 106, 1 ≤ x1, x2 ≤ 106).
Output
Print two space-separated integers y1 and y2 (0 ≤ y1 ≤ x1, 0 ≤ y2 ≤ x2).
Examples
Input
10 70 100 100 25
Output
99 33
Input
300 500 1000 1000 300
Output
1000 0
Input
143 456 110 117 273
Output
76 54
Note
In the second sample the hot water tap shouldn't be opened, but the cold water tap should be opened at full capacity in order to fill the bath in the quickest way possible.
Submitted Solution:
```
from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce,cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 998244353
def factors(n):return sorted(list(set(reduce(list.__add__,([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))))
# def inv_mod(n):return pow(n, mod - 2, mod)
def li():return [int(i) for i in input().rstrip('\n').split()]
def st():return input().rstrip('\n')
def val():return int(input().rstrip('\n'))
def li2():return [i for i in input().rstrip('\n').split(' ')]
def li3():return [int(i) for i in input().rstrip('\n')]
def compare(a,b):
if a[-1]<b[-1]:return -1
elif a[-1]>b[-1]:return 1
else:
if sum(a[:-1]) > sum(b[:-1]):return -1
return 1
t1, t2, x1, x2, t = li()
bestans = []
if t == t1 and t1 == t2:
print(x1,x2)
elif t == t1:
print(x1,0)
elif t == t2:
print(0,x2)
else:
r = (t2 - t)/(t - t1)
# bestans.append([0,0,0])
bestans.append([0,x2,0])
bestans.append([x1,0,0])
for i in range(1,x2 + 1):
curry1 = i*r
if 0 <= int(curry1) <= x1:
bestans.append([int(curry1),i,curry1 - int(curry1)])
if 0 <= math.ceil(curry1) <= x1:
bestans.append([math.ceil(curry1),i,math.ceil(curry1) - curry1])
for i,(a,b,c) in enumerate(bestans):
if ((a*t1 + b*t2)/(a + b)) < t:
bestans[i][-1] = 1000
continue
bestans[i][-1] = abs(t - ((a*t1 + b*t2)/(a + b)))
bestans.sort(key=cmp_to_key(compare))
# print(bestans)
print(*bestans[0][:-1])
```
No
| 6,703 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number n to Bob and said:
—Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroes.
—No problem! — said Bob and immediately gave her an answer.
Alice said a random number, so she doesn't know whether Bob's answer is correct. Help her to find this out, because impatient brother is waiting for the verdict.
Input
The first line contains one integer n (0 ≤ n ≤ 109) without leading zeroes. The second lines contains one integer m (0 ≤ m ≤ 109) — Bob's answer, possibly with leading zeroes.
Output
Print OK if Bob's answer is correct and WRONG_ANSWER otherwise.
Examples
Input
3310
1033
Output
OK
Input
4
5
Output
WRONG_ANSWER
Tags: implementation, sortings
Correct Solution:
```
n=str(input())
a=str(input())
lt=[]
if int(n)==0:
if n==a:
print("OK")
else:
print("WRONG_ANSWER")
else:
if a[0]=="0":
print("WRONG_ANSWER")
elif int(n)>0:
b=n.count("0")
for i in range(len(n)):
if int(n[i])>0:
lt.append(n[i])
lt.sort()
d=lt[0]
if b>0:
for i in range(b):
d=str(d)+"0"
for i in range(len(lt)-1):
d=str(d)+str(lt[i+1])
if b==0:
for i in range(len(lt)-1):
d=str(d)+str(lt[i+1])
if int(d)==int(a):
print("OK")
else:
print("WRONG_ANSWER")
```
| 6,704 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number n to Bob and said:
—Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroes.
—No problem! — said Bob and immediately gave her an answer.
Alice said a random number, so she doesn't know whether Bob's answer is correct. Help her to find this out, because impatient brother is waiting for the verdict.
Input
The first line contains one integer n (0 ≤ n ≤ 109) without leading zeroes. The second lines contains one integer m (0 ≤ m ≤ 109) — Bob's answer, possibly with leading zeroes.
Output
Print OK if Bob's answer is correct and WRONG_ANSWER otherwise.
Examples
Input
3310
1033
Output
OK
Input
4
5
Output
WRONG_ANSWER
Tags: implementation, sortings
Correct Solution:
```
s=input()
z=input()
a=[0]*10
for c in s:
a[int(c)]+=1
ans=""
for i in range(1,10):
if a[i]>0:
a[i]-=1
ans=str(i)
break
for i in range(0,10):
for j in range(a[i]):
ans+=str(i)
if ans==z:
print("OK")
else:
print("WRONG_ANSWER")
```
| 6,705 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number n to Bob and said:
—Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroes.
—No problem! — said Bob and immediately gave her an answer.
Alice said a random number, so she doesn't know whether Bob's answer is correct. Help her to find this out, because impatient brother is waiting for the verdict.
Input
The first line contains one integer n (0 ≤ n ≤ 109) without leading zeroes. The second lines contains one integer m (0 ≤ m ≤ 109) — Bob's answer, possibly with leading zeroes.
Output
Print OK if Bob's answer is correct and WRONG_ANSWER otherwise.
Examples
Input
3310
1033
Output
OK
Input
4
5
Output
WRONG_ANSWER
Tags: implementation, sortings
Correct Solution:
```
l=list(input())
m=list(input())
l.sort()
e=0
if(l[0]=='0'):
for i in range(1,len(l)):
if(l[i]!='0'):
l[0]=l[i]
l[i]='0'
e=1
break
if(e==1):
break
if(l==m ):
print('OK')
else:
print('WRONG_ANSWER')
```
| 6,706 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number n to Bob and said:
—Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroes.
—No problem! — said Bob and immediately gave her an answer.
Alice said a random number, so she doesn't know whether Bob's answer is correct. Help her to find this out, because impatient brother is waiting for the verdict.
Input
The first line contains one integer n (0 ≤ n ≤ 109) without leading zeroes. The second lines contains one integer m (0 ≤ m ≤ 109) — Bob's answer, possibly with leading zeroes.
Output
Print OK if Bob's answer is correct and WRONG_ANSWER otherwise.
Examples
Input
3310
1033
Output
OK
Input
4
5
Output
WRONG_ANSWER
Tags: implementation, sortings
Correct Solution:
```
n=list(input())
dic={}
for i in range(0,10):
dic[i]=0
for i in range(0,len(n)):
dic[int(n[i])]+=1
ans=[]
for i in range(1,10):
if dic[i]!=0:
ans.append(i)
dic[i]-=1
break
for i in range(0,10):
while dic[i]!=0:
ans.append(i)
dic[i]-=1
n=list(input())
cpans=[]
for i in range(0,len(n)):
cpans.append(int(n[i]))
if cpans==ans:
print("OK")
else:
print("WRONG_ANSWER")
```
| 6,707 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number n to Bob and said:
—Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroes.
—No problem! — said Bob and immediately gave her an answer.
Alice said a random number, so she doesn't know whether Bob's answer is correct. Help her to find this out, because impatient brother is waiting for the verdict.
Input
The first line contains one integer n (0 ≤ n ≤ 109) without leading zeroes. The second lines contains one integer m (0 ≤ m ≤ 109) — Bob's answer, possibly with leading zeroes.
Output
Print OK if Bob's answer is correct and WRONG_ANSWER otherwise.
Examples
Input
3310
1033
Output
OK
Input
4
5
Output
WRONG_ANSWER
Tags: implementation, sortings
Correct Solution:
```
c=[0]*10
for x in input():
c[ord(x)-ord('0')]+=1
t=[]
t.append(c[1]*'1')
t.append(c[0]*'0')
for i in range(2,10):
if c[i]==0:
continue
t.append(c[i]*chr(ord('0')+i))
s=input()
if (len(s)==1 and s[0]=='0') or (s[0]!='0' and s==''.join(t)):
print('OK')
else:
print('WRONG_ANSWER')
```
| 6,708 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number n to Bob and said:
—Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroes.
—No problem! — said Bob and immediately gave her an answer.
Alice said a random number, so she doesn't know whether Bob's answer is correct. Help her to find this out, because impatient brother is waiting for the verdict.
Input
The first line contains one integer n (0 ≤ n ≤ 109) without leading zeroes. The second lines contains one integer m (0 ≤ m ≤ 109) — Bob's answer, possibly with leading zeroes.
Output
Print OK if Bob's answer is correct and WRONG_ANSWER otherwise.
Examples
Input
3310
1033
Output
OK
Input
4
5
Output
WRONG_ANSWER
Tags: implementation, sortings
Correct Solution:
```
n = list(input())
t = input()
n = sorted(n)
if(n[0]=='0'):
for i in range(len(n)):
if(n[i]!='0'):
n[0],n[i] = n[i],n[0]
break
if(str(''.join(n))==t):
print('OK')
else:
print('WRONG_ANSWER')
else:
if(str(''.join(n))==t):
print('OK')
else:
print('WRONG_ANSWER')
```
| 6,709 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number n to Bob and said:
—Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroes.
—No problem! — said Bob and immediately gave her an answer.
Alice said a random number, so she doesn't know whether Bob's answer is correct. Help her to find this out, because impatient brother is waiting for the verdict.
Input
The first line contains one integer n (0 ≤ n ≤ 109) without leading zeroes. The second lines contains one integer m (0 ≤ m ≤ 109) — Bob's answer, possibly with leading zeroes.
Output
Print OK if Bob's answer is correct and WRONG_ANSWER otherwise.
Examples
Input
3310
1033
Output
OK
Input
4
5
Output
WRONG_ANSWER
Tags: implementation, sortings
Correct Solution:
```
n = int(input())
m = input()
v = []
zeros = 0
for c in str(n):
if c != '0':
v.append(c)
else:
zeros += 1
v.sort()
res = (v[0] if len(v) > 0 else "") + ('0' * zeros)
for i in range(1, len(v)):
res += v[i]
ans = "WRONG_ANSWER"
if m == res:
ans = "OK"
print(ans)
```
| 6,710 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number n to Bob and said:
—Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroes.
—No problem! — said Bob and immediately gave her an answer.
Alice said a random number, so she doesn't know whether Bob's answer is correct. Help her to find this out, because impatient brother is waiting for the verdict.
Input
The first line contains one integer n (0 ≤ n ≤ 109) without leading zeroes. The second lines contains one integer m (0 ≤ m ≤ 109) — Bob's answer, possibly with leading zeroes.
Output
Print OK if Bob's answer is correct and WRONG_ANSWER otherwise.
Examples
Input
3310
1033
Output
OK
Input
4
5
Output
WRONG_ANSWER
Tags: implementation, sortings
Correct Solution:
```
l=list(map(int,list(input())))
l.sort()
t=input()
def f(l,t):
if len(l)==1 and l[0]==0:
if t=="0":
return "OK"
return "WRONG_ANSWER"
c=l.count(0)
s=""
w=0
for i in range(len(l)):
if l[i]!=0 and w==0:
# print(s)
s+=str(l[i])+"0"*c
w+=1
# print(s)
elif l[i]!=0:
s+=str(l[i])
# print(s)
if t==s:
return "OK"
return "WRONG_ANSWER"
print(f(l,t))
```
| 6,711 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number n to Bob and said:
—Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroes.
—No problem! — said Bob and immediately gave her an answer.
Alice said a random number, so she doesn't know whether Bob's answer is correct. Help her to find this out, because impatient brother is waiting for the verdict.
Input
The first line contains one integer n (0 ≤ n ≤ 109) without leading zeroes. The second lines contains one integer m (0 ≤ m ≤ 109) — Bob's answer, possibly with leading zeroes.
Output
Print OK if Bob's answer is correct and WRONG_ANSWER otherwise.
Examples
Input
3310
1033
Output
OK
Input
4
5
Output
WRONG_ANSWER
Submitted Solution:
```
first =list(input())# получаем список с строковыми элементами ['3', '3', '1', '0']
second = input()
first_reverse = sorted(first[::-1]) # переворачивам
#print(first_reverse)
if first_reverse[0] == "0": # если первый элемент 0, то перебираем дальше список, пока не найдем отличный от 0 элемент
for i in first_reverse:
if i != "0":
y = first_reverse.index(i)# получаем индекс первого отличного от нуля элемента
first_reverse[0],first_reverse[y] = first_reverse[y],first_reverse[0]# меняем местами значения, без помози буферной пер
break
result = ''.join(first_reverse)# соединяем элементы воедино
#print(result)
if result == second:#сравниваем и выводим
print("OK")
else: print("WRONG_ANSWER")
```
Yes
| 6,712 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number n to Bob and said:
—Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroes.
—No problem! — said Bob and immediately gave her an answer.
Alice said a random number, so she doesn't know whether Bob's answer is correct. Help her to find this out, because impatient brother is waiting for the verdict.
Input
The first line contains one integer n (0 ≤ n ≤ 109) without leading zeroes. The second lines contains one integer m (0 ≤ m ≤ 109) — Bob's answer, possibly with leading zeroes.
Output
Print OK if Bob's answer is correct and WRONG_ANSWER otherwise.
Examples
Input
3310
1033
Output
OK
Input
4
5
Output
WRONG_ANSWER
Submitted Solution:
```
import sys
import math
n = sys.stdin.readline()
m = sys.stdin.readline()
l = len(n) - 1
k = [0] * 10
res = 0
for i in range(l):
k[int(n[i])] += 1
z = []
for i in range(1, 10):
if(k[i] != 0):
z.append(str(i))
k[i] -= 1
break
z.extend("0" * k[0])
for i in range(1, 10):
if(k[i] != 0):
z.extend(str(i) * k[i])
ml = len(m) - 1
zers = 0
for i in range(ml):
if(m[i] != '0'):
zers = i
break
if(zers != 0):
print("WRONG_ANSWER")
exit()
if(int(n) == 0 and ml != 1):
print("WRONG_ANSWER")
exit()
if(int("".join(z)) == int(m)):
print("OK")
else:
print("WRONG_ANSWER")
```
Yes
| 6,713 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number n to Bob and said:
—Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroes.
—No problem! — said Bob and immediately gave her an answer.
Alice said a random number, so she doesn't know whether Bob's answer is correct. Help her to find this out, because impatient brother is waiting for the verdict.
Input
The first line contains one integer n (0 ≤ n ≤ 109) without leading zeroes. The second lines contains one integer m (0 ≤ m ≤ 109) — Bob's answer, possibly with leading zeroes.
Output
Print OK if Bob's answer is correct and WRONG_ANSWER otherwise.
Examples
Input
3310
1033
Output
OK
Input
4
5
Output
WRONG_ANSWER
Submitted Solution:
```
def main():
s = input()
if s != "0":
l = sorted(c for c in s if c != '0')
l[0] += '0' * s.count('0')
s = ''.join(l)
print(("OK", "WRONG_ANSWER")[s != input()])
if __name__ == '__main__':
main()
```
Yes
| 6,714 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number n to Bob and said:
—Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroes.
—No problem! — said Bob and immediately gave her an answer.
Alice said a random number, so she doesn't know whether Bob's answer is correct. Help her to find this out, because impatient brother is waiting for the verdict.
Input
The first line contains one integer n (0 ≤ n ≤ 109) without leading zeroes. The second lines contains one integer m (0 ≤ m ≤ 109) — Bob's answer, possibly with leading zeroes.
Output
Print OK if Bob's answer is correct and WRONG_ANSWER otherwise.
Examples
Input
3310
1033
Output
OK
Input
4
5
Output
WRONG_ANSWER
Submitted Solution:
```
n = input()
m = input()
from sys import exit
if n=='0':
if m=='0':
print('OK')
else:
print('WRONG_ANSWER')
exit()
mas = []
for i,x in enumerate(n):
mas.append(int(x))
mas.sort()
q = mas.count(0)
rez = str(mas[q])
for i in range(q):
rez+='0'
for i in range(q+1,len(n)):
rez+=str(mas[i])
if m==rez:
print('OK')
else:
print('WRONG_ANSWER')
```
Yes
| 6,715 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number n to Bob and said:
—Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroes.
—No problem! — said Bob and immediately gave her an answer.
Alice said a random number, so she doesn't know whether Bob's answer is correct. Help her to find this out, because impatient brother is waiting for the verdict.
Input
The first line contains one integer n (0 ≤ n ≤ 109) without leading zeroes. The second lines contains one integer m (0 ≤ m ≤ 109) — Bob's answer, possibly with leading zeroes.
Output
Print OK if Bob's answer is correct and WRONG_ANSWER otherwise.
Examples
Input
3310
1033
Output
OK
Input
4
5
Output
WRONG_ANSWER
Submitted Solution:
```
n=input()
m=input()
l=list(n)
l.sort()
x=l.count('0')
d=[]
for i in l:
if(i!='0'):
d.append(i)
d.sort()
if(d==[]):
if(int(n)==int(m)):
print("OK")
else:
print("WRONG_ANSWER")
else:
s=d[0]+'0'*x+''.join(d[1:])
if(int(s)==int(m)):
print("OK")
else:
print("WRONG ANSWER")
```
No
| 6,716 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number n to Bob and said:
—Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroes.
—No problem! — said Bob and immediately gave her an answer.
Alice said a random number, so she doesn't know whether Bob's answer is correct. Help her to find this out, because impatient brother is waiting for the verdict.
Input
The first line contains one integer n (0 ≤ n ≤ 109) without leading zeroes. The second lines contains one integer m (0 ≤ m ≤ 109) — Bob's answer, possibly with leading zeroes.
Output
Print OK if Bob's answer is correct and WRONG_ANSWER otherwise.
Examples
Input
3310
1033
Output
OK
Input
4
5
Output
WRONG_ANSWER
Submitted Solution:
```
a=int(input())
b=input()
if(b[0]=='0'):
print('WRONG_ANSWER')
else:
a=list(str(a))
a.sort()
i=0
while(i<len(a)):
if(a[i]!='0'):
break
i+=1
s1=''
for j in a[i+1:]:
s1+=j
s=a[i]+'0'*i+s1
#print(s)
if(s==str(b)):
print('OK')
else:
print('WRONG_ANSWER')
```
No
| 6,717 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number n to Bob and said:
—Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroes.
—No problem! — said Bob and immediately gave her an answer.
Alice said a random number, so she doesn't know whether Bob's answer is correct. Help her to find this out, because impatient brother is waiting for the verdict.
Input
The first line contains one integer n (0 ≤ n ≤ 109) without leading zeroes. The second lines contains one integer m (0 ≤ m ≤ 109) — Bob's answer, possibly with leading zeroes.
Output
Print OK if Bob's answer is correct and WRONG_ANSWER otherwise.
Examples
Input
3310
1033
Output
OK
Input
4
5
Output
WRONG_ANSWER
Submitted Solution:
```
n=int(input())
m=int(input())
if m==n:
print("WRONG_ANSWER")
else:
aN=sorted([int(i) for i in str(n)])
aM=[int(i) for i in str(m)]
if aN[0]!=0:
print("OK" if aN==aM else "WRONG_ANSWER")
else:
i=1
while aN[0]==0:
aN[0],aN[i]=aN[i],aN[0]
i+=1
print("OK" if aN==aM else "WRONG_ANSWER")
```
No
| 6,718 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number n to Bob and said:
—Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroes.
—No problem! — said Bob and immediately gave her an answer.
Alice said a random number, so she doesn't know whether Bob's answer is correct. Help her to find this out, because impatient brother is waiting for the verdict.
Input
The first line contains one integer n (0 ≤ n ≤ 109) without leading zeroes. The second lines contains one integer m (0 ≤ m ≤ 109) — Bob's answer, possibly with leading zeroes.
Output
Print OK if Bob's answer is correct and WRONG_ANSWER otherwise.
Examples
Input
3310
1033
Output
OK
Input
4
5
Output
WRONG_ANSWER
Submitted Solution:
```
n,s = list(input()), int(input());
n.sort();
if len(n)>1:
for x in n:
if x!='0':
ans=x;
break;
n.remove(ans);
n.insert(0, ans);
n=''.join(n);
print(['WRONG_ANSWER','OK'][int(n)==s>0]);
```
No
| 6,719 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Catherine received an array of integers as a gift for March 8. Eventually she grew bored with it, and she started calculated various useless characteristics for it. She succeeded to do it for each one she came up with. But when she came up with another one — xor of all pairwise sums of elements in the array, she realized that she couldn't compute it for a very large array, thus she asked for your help. Can you do it? Formally, you need to compute
$$$ (a_1 + a_2) ⊕ (a_1 + a_3) ⊕ … ⊕ (a_1 + a_n) \\\ ⊕ (a_2 + a_3) ⊕ … ⊕ (a_2 + a_n) \\\ … \\\ ⊕ (a_{n-1} + a_n) \\\ $$$
Here x ⊕ y is a bitwise XOR operation (i.e. x ^ y in many modern programming languages). You can read about it in Wikipedia: <https://en.wikipedia.org/wiki/Exclusive_or#Bitwise_operation>.
Input
The first line contains a single integer n (2 ≤ n ≤ 400 000) — the number of integers in the array.
The second line contains integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^7).
Output
Print a single integer — xor of all pairwise sums of integers in the given array.
Examples
Input
2
1 2
Output
3
Input
3
1 2 3
Output
2
Note
In the first sample case there is only one sum 1 + 2 = 3.
In the second sample case there are three sums: 1 + 2 = 3, 1 + 3 = 4, 2 + 3 = 5. In binary they are represented as 011_2 ⊕ 100_2 ⊕ 101_2 = 010_2, thus the answer is 2.
⊕ is the bitwise xor operation. To define x ⊕ y, consider binary representations of integers x and y. We put the i-th bit of the result to be 1 when exactly one of the i-th bits of x and y is 1. Otherwise, the i-th bit of the result is put to be 0. For example, 0101_2 ⊕ 0011_2 = 0110_2.
Tags: binary search, bitmasks, constructive algorithms, data structures, math, sortings
Correct Solution:
```
import io
import os
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
DEBUG = False
def solveBrute(N, A):
ans = 0
for i in range(N):
for j in range(i + 1, N):
ans ^= A[i] + A[j]
return ans
def solve(N, A):
B = max(A).bit_length()
ans = 0
for k in range(B + 1):
# Count number of pairs with kth bit on (0 indexed)
# For example if k==2, want pairs where lower 3 bits are between 100 and 111 inclusive
# If we mask A to the lower 3 bits, we can find all pairs that sum to either 100 to 111 or overflowed to 1100 to 1111
MOD = 1 << (k + 1)
MASK = MOD - 1
# Sort by x & MASK incrementally
left = []
right = []
for x in A:
if (x >> k) & 1:
right.append(x)
else:
left.append(x)
A = left + right
arr = [x & MASK for x in A]
if DEBUG:
assert arr == sorted(arr)
numPairs = 0
tLo = 1 << k
tHi = (1 << (k + 1)) - 1
for targetLo, targetHi in [(tLo, tHi), (MOD + tLo, MOD + tHi)]:
# Want to binary search for y such that targetLo <= x + y <= targetHi
# But this TLE so walk the lo/hi pointers instead
lo = N
hi = N
for i, x in enumerate(arr):
lo = max(lo, i + 1)
hi = max(hi, lo)
while lo - 1 >= i + 1 and arr[lo - 1] >= targetLo - x:
lo -= 1
while hi - 1 >= lo and arr[hi - 1] > targetHi - x:
hi -= 1
numPairs += hi - lo
if DEBUG:
# Check
assert lo == bisect_left(arr, targetLo - x, i + 1)
assert hi == bisect_right(arr, targetHi - x, lo)
for j, y in enumerate(arr):
cond = i < j and targetLo <= x + y <= targetHi
if lo <= j < hi:
assert cond
else:
assert not cond
ans += (numPairs % 2) << k
return ans
if DEBUG:
import random
random.seed(0)
for i in range(100):
A = [random.randint(1, 1000) for i in range(100)]
N = len(A)
ans1 = solveBrute(N, A)
ans2 = solve(N, A)
print(A, bin(ans1), bin(ans2))
assert ans1 == ans2
else:
if False:
# Timing
import random
random.seed(0)
A = [random.randint(1, 10 ** 7) for i in range(400000)]
N = len(A)
print(solve(N, A))
if __name__ == "__main__":
(N,) = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = solve(N, A)
print(ans)
```
| 6,720 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Catherine received an array of integers as a gift for March 8. Eventually she grew bored with it, and she started calculated various useless characteristics for it. She succeeded to do it for each one she came up with. But when she came up with another one — xor of all pairwise sums of elements in the array, she realized that she couldn't compute it for a very large array, thus she asked for your help. Can you do it? Formally, you need to compute
$$$ (a_1 + a_2) ⊕ (a_1 + a_3) ⊕ … ⊕ (a_1 + a_n) \\\ ⊕ (a_2 + a_3) ⊕ … ⊕ (a_2 + a_n) \\\ … \\\ ⊕ (a_{n-1} + a_n) \\\ $$$
Here x ⊕ y is a bitwise XOR operation (i.e. x ^ y in many modern programming languages). You can read about it in Wikipedia: <https://en.wikipedia.org/wiki/Exclusive_or#Bitwise_operation>.
Input
The first line contains a single integer n (2 ≤ n ≤ 400 000) — the number of integers in the array.
The second line contains integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^7).
Output
Print a single integer — xor of all pairwise sums of integers in the given array.
Examples
Input
2
1 2
Output
3
Input
3
1 2 3
Output
2
Note
In the first sample case there is only one sum 1 + 2 = 3.
In the second sample case there are three sums: 1 + 2 = 3, 1 + 3 = 4, 2 + 3 = 5. In binary they are represented as 011_2 ⊕ 100_2 ⊕ 101_2 = 010_2, thus the answer is 2.
⊕ is the bitwise xor operation. To define x ⊕ y, consider binary representations of integers x and y. We put the i-th bit of the result to be 1 when exactly one of the i-th bits of x and y is 1. Otherwise, the i-th bit of the result is put to be 0. For example, 0101_2 ⊕ 0011_2 = 0110_2.
Tags: binary search, bitmasks, constructive algorithms, data structures, math, sortings
Correct Solution:
```
import io
import os
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
DEBUG = False
def solveBrute(N, A):
ans = 0
for i in range(N):
for j in range(i + 1, N):
ans ^= A[i] + A[j]
return ans
def solve(N, A):
B = max(A).bit_length()
ans = 0
for k in range(B + 1):
# Count number of pairs with kth bit on (0 indexed)
# For example if k==2, want pairs where lower 3 bits are between 100 and 111 inclusive
# If we mask A to the lower 3 bits, we can find all pairs that sum to either 100 to 111 or overflowed to 1100 to 1111
MOD = 1 << (k + 1)
MASK = MOD - 1
# Sort by x & MASK incrementally
i = 0
right = []
for x in A:
if (x >> k) & 1:
right.append(x)
else:
A[i] = x
i += 1
assert N - i == len(right)
A[i:] = right
arr = [x & MASK for x in A]
if DEBUG:
assert arr == sorted(arr)
numPairs = 0
tlo = 1 << k
thi = (1 << (k + 1)) - 1
for targetLo, targetHi in [(tlo, thi), (MOD + tlo, MOD + thi)]:
# Want to binary search for y such that targetLo <= x + y <= targetHi
# But this TLE so walk the lo/hi pointers instead
lo = N
hi = N
for i, x in enumerate(arr):
lo = max(lo, i + 1)
hi = max(hi, lo)
while lo - 1 >= i + 1 and arr[lo - 1] >= targetLo - x:
lo -= 1
while hi - 1 >= lo and arr[hi - 1] >= targetHi - x + 1:
hi -= 1
numPairs += hi - lo
if DEBUG:
assert lo == bisect_left(arr, targetLo - x, i + 1)
assert hi == bisect_right(arr, targetHi - x, lo)
# Check
for j, y in enumerate(arr):
cond = i < j and targetLo <= x + y <= targetHi
if lo <= j < hi:
assert cond
else:
assert not cond
ans += (numPairs % 2) << k
return ans
if DEBUG:
import random
random.seed(0)
for i in range(100):
A = [random.randint(1, 1000) for i in range(100)]
N = len(A)
ans1 = solveBrute(N, A)
ans2 = solve(N, A)
print(A, bin(ans1), bin(ans2))
assert ans1 == ans2
else:
if False:
# Timing
import random
random.seed(0)
A = [random.randint(1, 10 ** 7) for i in range(400000)]
N = len(A)
print(solve(N, A))
if __name__ == "__main__":
(N,) = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = solve(N, A)
print(ans)
```
| 6,721 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Catherine received an array of integers as a gift for March 8. Eventually she grew bored with it, and she started calculated various useless characteristics for it. She succeeded to do it for each one she came up with. But when she came up with another one — xor of all pairwise sums of elements in the array, she realized that she couldn't compute it for a very large array, thus she asked for your help. Can you do it? Formally, you need to compute
$$$ (a_1 + a_2) ⊕ (a_1 + a_3) ⊕ … ⊕ (a_1 + a_n) \\\ ⊕ (a_2 + a_3) ⊕ … ⊕ (a_2 + a_n) \\\ … \\\ ⊕ (a_{n-1} + a_n) \\\ $$$
Here x ⊕ y is a bitwise XOR operation (i.e. x ^ y in many modern programming languages). You can read about it in Wikipedia: <https://en.wikipedia.org/wiki/Exclusive_or#Bitwise_operation>.
Input
The first line contains a single integer n (2 ≤ n ≤ 400 000) — the number of integers in the array.
The second line contains integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^7).
Output
Print a single integer — xor of all pairwise sums of integers in the given array.
Examples
Input
2
1 2
Output
3
Input
3
1 2 3
Output
2
Note
In the first sample case there is only one sum 1 + 2 = 3.
In the second sample case there are three sums: 1 + 2 = 3, 1 + 3 = 4, 2 + 3 = 5. In binary they are represented as 011_2 ⊕ 100_2 ⊕ 101_2 = 010_2, thus the answer is 2.
⊕ is the bitwise xor operation. To define x ⊕ y, consider binary representations of integers x and y. We put the i-th bit of the result to be 1 when exactly one of the i-th bits of x and y is 1. Otherwise, the i-th bit of the result is put to be 0. For example, 0101_2 ⊕ 0011_2 = 0110_2.
Tags: binary search, bitmasks, constructive algorithms, data structures, math, sortings
Correct Solution:
```
import math
input_list = lambda: list(map(int, input().split()))
def main():
n = int(input())
a = input_list()
temp = []
ans = 0
for bit in range(26):
temp.clear()
value1 = 2**bit
value2 = 2**(bit + 1) - 1
value3 = 2**(bit + 1) + 2**bit
value4 = 2**(bit + 2) - 1
for i in range(n):
temp.append(a[i]%(2**(bit+1)))
f1, l1, f2, l2 = [n-1, n-1, n-1, n-1]
temp.sort()
noOfOnes = 0
for i in range(n):
while f1>=0 and temp[f1]+temp[i]>=value1:
f1 = f1 - 1
while l1>=0 and temp[l1] + temp[i]>value2:
l1 = l1 - 1
while f2>=0 and temp[f2] + temp[i]>=value3 :
f2 = f2 - 1
while l2>=0 and temp[l2] + temp[i]>value4:
l2 = l2 - 1
noOfOnes = noOfOnes + max(0, l1 - max(i,f1))
noOfOnes = noOfOnes + max(0, l2 - max(i, f2))
if noOfOnes%2==1:
ans = ans + 2**bit
print(ans)
main()
```
| 6,722 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Catherine received an array of integers as a gift for March 8. Eventually she grew bored with it, and she started calculated various useless characteristics for it. She succeeded to do it for each one she came up with. But when she came up with another one — xor of all pairwise sums of elements in the array, she realized that she couldn't compute it for a very large array, thus she asked for your help. Can you do it? Formally, you need to compute
$$$ (a_1 + a_2) ⊕ (a_1 + a_3) ⊕ … ⊕ (a_1 + a_n) \\\ ⊕ (a_2 + a_3) ⊕ … ⊕ (a_2 + a_n) \\\ … \\\ ⊕ (a_{n-1} + a_n) \\\ $$$
Here x ⊕ y is a bitwise XOR operation (i.e. x ^ y in many modern programming languages). You can read about it in Wikipedia: <https://en.wikipedia.org/wiki/Exclusive_or#Bitwise_operation>.
Input
The first line contains a single integer n (2 ≤ n ≤ 400 000) — the number of integers in the array.
The second line contains integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^7).
Output
Print a single integer — xor of all pairwise sums of integers in the given array.
Examples
Input
2
1 2
Output
3
Input
3
1 2 3
Output
2
Note
In the first sample case there is only one sum 1 + 2 = 3.
In the second sample case there are three sums: 1 + 2 = 3, 1 + 3 = 4, 2 + 3 = 5. In binary they are represented as 011_2 ⊕ 100_2 ⊕ 101_2 = 010_2, thus the answer is 2.
⊕ is the bitwise xor operation. To define x ⊕ y, consider binary representations of integers x and y. We put the i-th bit of the result to be 1 when exactly one of the i-th bits of x and y is 1. Otherwise, the i-th bit of the result is put to be 0. For example, 0101_2 ⊕ 0011_2 = 0110_2.
Tags: binary search, bitmasks, constructive algorithms, data structures, math, sortings
Correct Solution:
```
import math
import sys
input = sys.stdin.readline
input_list = lambda: list(map(int, input().split()))
def main():
n = int(input())
a = input_list()
temp = []
ans = 0
for bit in range(26):
temp.clear()
value1 = 2**bit
value2 = 2**(bit + 1) - 1
value3 = 2**(bit + 1) + 2**bit
value4 = 2**(bit + 2) - 1
for i in range(n):
temp.append(a[i]%(2**(bit+1)))
f1, l1, f2, l2 = [n-1, n-1, n-1, n-1]
temp.sort()
noOfOnes = 0
for i in range(n):
while f1>=0 and temp[f1]+temp[i]>=value1:
f1 = f1 - 1
while l1>=0 and temp[l1] + temp[i]>value2:
l1 = l1 - 1
while f2>=0 and temp[f2] + temp[i]>=value3 :
f2 = f2 - 1
while l2>=0 and temp[l2] + temp[i]>value4:
l2 = l2 - 1
noOfOnes = noOfOnes + max(0, l1 - max(i,f1))
noOfOnes = noOfOnes + max(0, l2 - max(i, f2))
if noOfOnes%2==1:
ans = ans + 2**bit
print(ans)
main()
```
| 6,723 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Catherine received an array of integers as a gift for March 8. Eventually she grew bored with it, and she started calculated various useless characteristics for it. She succeeded to do it for each one she came up with. But when she came up with another one — xor of all pairwise sums of elements in the array, she realized that she couldn't compute it for a very large array, thus she asked for your help. Can you do it? Formally, you need to compute
$$$ (a_1 + a_2) ⊕ (a_1 + a_3) ⊕ … ⊕ (a_1 + a_n) \\\ ⊕ (a_2 + a_3) ⊕ … ⊕ (a_2 + a_n) \\\ … \\\ ⊕ (a_{n-1} + a_n) \\\ $$$
Here x ⊕ y is a bitwise XOR operation (i.e. x ^ y in many modern programming languages). You can read about it in Wikipedia: <https://en.wikipedia.org/wiki/Exclusive_or#Bitwise_operation>.
Input
The first line contains a single integer n (2 ≤ n ≤ 400 000) — the number of integers in the array.
The second line contains integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^7).
Output
Print a single integer — xor of all pairwise sums of integers in the given array.
Examples
Input
2
1 2
Output
3
Input
3
1 2 3
Output
2
Note
In the first sample case there is only one sum 1 + 2 = 3.
In the second sample case there are three sums: 1 + 2 = 3, 1 + 3 = 4, 2 + 3 = 5. In binary they are represented as 011_2 ⊕ 100_2 ⊕ 101_2 = 010_2, thus the answer is 2.
⊕ is the bitwise xor operation. To define x ⊕ y, consider binary representations of integers x and y. We put the i-th bit of the result to be 1 when exactly one of the i-th bits of x and y is 1. Otherwise, the i-th bit of the result is put to be 0. For example, 0101_2 ⊕ 0011_2 = 0110_2.
Tags: binary search, bitmasks, constructive algorithms, data structures, math, sortings
Correct Solution:
```
import sys
from array import array # noqa: F401
from typing import List, Tuple, TypeVar, Generic, Sequence, Union # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
def main():
n = int(input())
a = sorted(map(int, input().split()))
ans = 0
for d in range(25, -1, -1):
bit = 1 << d
cnt = 0
j = k = l = n - 1
for i, x in enumerate(a):
j, k, l = max(j, i), max(k, i), max(l, i)
while i < j and a[j] >= bit - x:
j -= 1
while j < k and a[k] >= 2 * bit - x:
k -= 1
while k < l and a[l] >= 3 * bit - x:
l -= 1
cnt += k - j + n - 1 - l
if cnt & 1:
ans += bit
for i in range(n):
a[i] &= ~bit
a.sort()
print(ans)
if __name__ == '__main__':
main()
```
| 6,724 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Catherine received an array of integers as a gift for March 8. Eventually she grew bored with it, and she started calculated various useless characteristics for it. She succeeded to do it for each one she came up with. But when she came up with another one — xor of all pairwise sums of elements in the array, she realized that she couldn't compute it for a very large array, thus she asked for your help. Can you do it? Formally, you need to compute
$$$ (a_1 + a_2) ⊕ (a_1 + a_3) ⊕ … ⊕ (a_1 + a_n) \\\ ⊕ (a_2 + a_3) ⊕ … ⊕ (a_2 + a_n) \\\ … \\\ ⊕ (a_{n-1} + a_n) \\\ $$$
Here x ⊕ y is a bitwise XOR operation (i.e. x ^ y in many modern programming languages). You can read about it in Wikipedia: <https://en.wikipedia.org/wiki/Exclusive_or#Bitwise_operation>.
Input
The first line contains a single integer n (2 ≤ n ≤ 400 000) — the number of integers in the array.
The second line contains integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^7).
Output
Print a single integer — xor of all pairwise sums of integers in the given array.
Examples
Input
2
1 2
Output
3
Input
3
1 2 3
Output
2
Note
In the first sample case there is only one sum 1 + 2 = 3.
In the second sample case there are three sums: 1 + 2 = 3, 1 + 3 = 4, 2 + 3 = 5. In binary they are represented as 011_2 ⊕ 100_2 ⊕ 101_2 = 010_2, thus the answer is 2.
⊕ is the bitwise xor operation. To define x ⊕ y, consider binary representations of integers x and y. We put the i-th bit of the result to be 1 when exactly one of the i-th bits of x and y is 1. Otherwise, the i-th bit of the result is put to be 0. For example, 0101_2 ⊕ 0011_2 = 0110_2.
Tags: binary search, bitmasks, constructive algorithms, data structures, math, sortings
Correct Solution:
```
from bisect import bisect_left, bisect_right
def go():
n = int(input())
a = list(map(int, input().split()))
b = max(a).bit_length()
res = 0
vals = a
for i in range(b + 1):
# print("")
b2 = 2 << i
b1 = 1 << i
a0 = [aa for aa in a if aa & b1==0]
a1 = [aa for aa in a if aa & b1]
a = a0 + a1
vals = [aa % b2 for aa in a]
cnt = 0
# vals = sorted(aa % b2 for aa in a)
x1, x2, y1 = n - 1, n - 1, n - 1
for j, v in enumerate(vals):
while x1 > -1 and vals[x1] >= b1 - v:
x1 -= 1
while y1 > -1 and vals[y1] > b2 - v - 1:
y1 -= 1
# x, y = bisect_left(vals,b1-v), bisect_right(vals,b2-v-1)
x, y = x1 + 1, y1 + 1
# print('+++', x, y, bisect_left(vals, b1 - v), bisect_right(vals, b2 - v - 1))
cnt += y - x
if x <= j < y:
cnt -= 1
while x2 > -1 and vals[x2] >= b2 + b1 - v:
x2 -= 1
# x, y = bisect_left(vals,b2+b1-v), len(vals)
x, y = x2 + 1, n
# print('---', x, y, bisect_left(vals, b2 + b1 - v), len(vals))
cnt += y - x
if x <= j < y:
cnt -= 1
res += b1 * (cnt // 2 % 2)
return res
print(go())
```
| 6,725 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Catherine received an array of integers as a gift for March 8. Eventually she grew bored with it, and she started calculated various useless characteristics for it. She succeeded to do it for each one she came up with. But when she came up with another one — xor of all pairwise sums of elements in the array, she realized that she couldn't compute it for a very large array, thus she asked for your help. Can you do it? Formally, you need to compute
$$$ (a_1 + a_2) ⊕ (a_1 + a_3) ⊕ … ⊕ (a_1 + a_n) \\\ ⊕ (a_2 + a_3) ⊕ … ⊕ (a_2 + a_n) \\\ … \\\ ⊕ (a_{n-1} + a_n) \\\ $$$
Here x ⊕ y is a bitwise XOR operation (i.e. x ^ y in many modern programming languages). You can read about it in Wikipedia: <https://en.wikipedia.org/wiki/Exclusive_or#Bitwise_operation>.
Input
The first line contains a single integer n (2 ≤ n ≤ 400 000) — the number of integers in the array.
The second line contains integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^7).
Output
Print a single integer — xor of all pairwise sums of integers in the given array.
Examples
Input
2
1 2
Output
3
Input
3
1 2 3
Output
2
Note
In the first sample case there is only one sum 1 + 2 = 3.
In the second sample case there are three sums: 1 + 2 = 3, 1 + 3 = 4, 2 + 3 = 5. In binary they are represented as 011_2 ⊕ 100_2 ⊕ 101_2 = 010_2, thus the answer is 2.
⊕ is the bitwise xor operation. To define x ⊕ y, consider binary representations of integers x and y. We put the i-th bit of the result to be 1 when exactly one of the i-th bits of x and y is 1. Otherwise, the i-th bit of the result is put to be 0. For example, 0101_2 ⊕ 0011_2 = 0110_2.
Submitted Solution:
```
import sys
from array import array # noqa: F401
from typing import List, Tuple, TypeVar, Generic, Sequence, Union # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
def main():
n = int(input())
a = sorted(map(int, input().split()))
ans = 0
for d in range(23, -1, -1):
bit = 1 << d
cnt = 0
j = k = l = n - 1
for i, x in enumerate(a):
j, k, l = max(j, i), max(k, i), max(l, i)
while i < j and a[j] >= bit - x:
j -= 1
while j < k and a[k] >= 2 * bit - x:
k -= 1
while k < l and a[l] >= 3 * bit - x:
l -= 1
cnt += k - j + n - 1 - l
if cnt & 1:
ans += bit
for i in range(n):
a[i] &= ~bit
a.sort()
print(ans)
if __name__ == '__main__':
main()
```
No
| 6,726 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Catherine received an array of integers as a gift for March 8. Eventually she grew bored with it, and she started calculated various useless characteristics for it. She succeeded to do it for each one she came up with. But when she came up with another one — xor of all pairwise sums of elements in the array, she realized that she couldn't compute it for a very large array, thus she asked for your help. Can you do it? Formally, you need to compute
$$$ (a_1 + a_2) ⊕ (a_1 + a_3) ⊕ … ⊕ (a_1 + a_n) \\\ ⊕ (a_2 + a_3) ⊕ … ⊕ (a_2 + a_n) \\\ … \\\ ⊕ (a_{n-1} + a_n) \\\ $$$
Here x ⊕ y is a bitwise XOR operation (i.e. x ^ y in many modern programming languages). You can read about it in Wikipedia: <https://en.wikipedia.org/wiki/Exclusive_or#Bitwise_operation>.
Input
The first line contains a single integer n (2 ≤ n ≤ 400 000) — the number of integers in the array.
The second line contains integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^7).
Output
Print a single integer — xor of all pairwise sums of integers in the given array.
Examples
Input
2
1 2
Output
3
Input
3
1 2 3
Output
2
Note
In the first sample case there is only one sum 1 + 2 = 3.
In the second sample case there are three sums: 1 + 2 = 3, 1 + 3 = 4, 2 + 3 = 5. In binary they are represented as 011_2 ⊕ 100_2 ⊕ 101_2 = 010_2, thus the answer is 2.
⊕ is the bitwise xor operation. To define x ⊕ y, consider binary representations of integers x and y. We put the i-th bit of the result to be 1 when exactly one of the i-th bits of x and y is 1. Otherwise, the i-th bit of the result is put to be 0. For example, 0101_2 ⊕ 0011_2 = 0110_2.
Submitted Solution:
```
def go():
n = int(input())
a = list(map(int, input().split()))
b = max(a).bit_length()
res = 0
for i in range(b+1):
b2 = 2 << i
b1 = 1 << i
cnt = 0
vals = sorted(list(aa % b2 for aa in a))
x, y = n - 1, n - 1
for j, v in enumerate(vals):
while x >= 0 and vals[x] >= b1 - v:
x -= 1
while y >= 0 and vals[y] > b2 - 1 - v:
y -= 1
# print(x, y)
if y <= j:
break
cnt += y - max(x, 0, j)
# cnt += sum(1 for vv in vals[j + 1:] if b1 - v <= vv <= b2 - 1 - v)
res += b1 * (cnt % 2)
return res
print(go())
```
No
| 6,727 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Catherine received an array of integers as a gift for March 8. Eventually she grew bored with it, and she started calculated various useless characteristics for it. She succeeded to do it for each one she came up with. But when she came up with another one — xor of all pairwise sums of elements in the array, she realized that she couldn't compute it for a very large array, thus she asked for your help. Can you do it? Formally, you need to compute
$$$ (a_1 + a_2) ⊕ (a_1 + a_3) ⊕ … ⊕ (a_1 + a_n) \\\ ⊕ (a_2 + a_3) ⊕ … ⊕ (a_2 + a_n) \\\ … \\\ ⊕ (a_{n-1} + a_n) \\\ $$$
Here x ⊕ y is a bitwise XOR operation (i.e. x ^ y in many modern programming languages). You can read about it in Wikipedia: <https://en.wikipedia.org/wiki/Exclusive_or#Bitwise_operation>.
Input
The first line contains a single integer n (2 ≤ n ≤ 400 000) — the number of integers in the array.
The second line contains integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^7).
Output
Print a single integer — xor of all pairwise sums of integers in the given array.
Examples
Input
2
1 2
Output
3
Input
3
1 2 3
Output
2
Note
In the first sample case there is only one sum 1 + 2 = 3.
In the second sample case there are three sums: 1 + 2 = 3, 1 + 3 = 4, 2 + 3 = 5. In binary they are represented as 011_2 ⊕ 100_2 ⊕ 101_2 = 010_2, thus the answer is 2.
⊕ is the bitwise xor operation. To define x ⊕ y, consider binary representations of integers x and y. We put the i-th bit of the result to be 1 when exactly one of the i-th bits of x and y is 1. Otherwise, the i-th bit of the result is put to be 0. For example, 0101_2 ⊕ 0011_2 = 0110_2.
Submitted Solution:
```
def go():
n = int(input())
a = list(map(int, input().split()))
b = max(a).bit_length()
res = 0
for i in range(b):
b2 = 2 << i
b1 = 1 << i
cnt = 0
vals = sorted(list(aa % b2 for aa in a))
x, y = n - 1, n - 1
for j, v in enumerate(vals):
while x >= 0 and vals[x] >= b1 - v:
x -= 1
while y >= 0 and vals[y] > b2 - 1 - v:
y -= 1
# print(x, y)
if y<=j:
break
cnt += y-max(x, 0, j)
# cnt += sum(1 for vv in vals[j + 1:] if b1 - v <= vv <= b2 - 1 - v)
res += b1 * (cnt % 2)
return res
print(go())
```
No
| 6,728 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Catherine received an array of integers as a gift for March 8. Eventually she grew bored with it, and she started calculated various useless characteristics for it. She succeeded to do it for each one she came up with. But when she came up with another one — xor of all pairwise sums of elements in the array, she realized that she couldn't compute it for a very large array, thus she asked for your help. Can you do it? Formally, you need to compute
$$$ (a_1 + a_2) ⊕ (a_1 + a_3) ⊕ … ⊕ (a_1 + a_n) \\\ ⊕ (a_2 + a_3) ⊕ … ⊕ (a_2 + a_n) \\\ … \\\ ⊕ (a_{n-1} + a_n) \\\ $$$
Here x ⊕ y is a bitwise XOR operation (i.e. x ^ y in many modern programming languages). You can read about it in Wikipedia: <https://en.wikipedia.org/wiki/Exclusive_or#Bitwise_operation>.
Input
The first line contains a single integer n (2 ≤ n ≤ 400 000) — the number of integers in the array.
The second line contains integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^7).
Output
Print a single integer — xor of all pairwise sums of integers in the given array.
Examples
Input
2
1 2
Output
3
Input
3
1 2 3
Output
2
Note
In the first sample case there is only one sum 1 + 2 = 3.
In the second sample case there are three sums: 1 + 2 = 3, 1 + 3 = 4, 2 + 3 = 5. In binary they are represented as 011_2 ⊕ 100_2 ⊕ 101_2 = 010_2, thus the answer is 2.
⊕ is the bitwise xor operation. To define x ⊕ y, consider binary representations of integers x and y. We put the i-th bit of the result to be 1 when exactly one of the i-th bits of x and y is 1. Otherwise, the i-th bit of the result is put to be 0. For example, 0101_2 ⊕ 0011_2 = 0110_2.
Submitted Solution:
```
import math
input_list = lambda: list(map(int, input().split()))
def main():
n = int(input())
a = input_list()
temp = []
ans = 0
for bit in range(26):
temp.clear()
noOfOnes = 0
value1 = 2**bit
value2 = 2**(bit + 1) - 1
value3 = 2**(bit + 1) + 2**bit
value4 = 2**(bit + 2) - 1
for i in range(n):
temp.append(a[i]%(2**(bit+1)))
f1, l1, f2, l2 = [1, n-1, 1, n-1]
temp.sort()
for i in range(n):
while f1<=n-1 and temp[f1]+temp[i]<value1:
f1 = f1 + 1
while l1>=0 and temp[l1] + temp[i]>value2:
l1 = l1 - 1
while f2<=n-1 and temp[f2] + temp[i]<value3 :
f2 = f2 + 1
while l2>=0 and temp[l2] + temp[i]>value4:
l2 = l2 - 1
noOfOnes = noOfOnes + max(0, l1 - max(i+1,f1) + 1)
noOfOnes = noOfOnes + max(0, l2 - max(i+1, f2) + 1)
if noOfOnes%2==1:
ans = ans + 2**bit
print(ans)
main()
```
No
| 6,729 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers a and b, and q queries. The i-th query consists of two numbers l_i and r_i, and the answer to it is the number of integers x such that l_i ≤ x ≤ r_i, and ((x mod a) mod b) ≠ ((x mod b) mod a). Calculate the answer for each query.
Recall that y mod z is the remainder of the division of y by z. For example, 5 mod 3 = 2, 7 mod 8 = 7, 9 mod 4 = 1, 9 mod 9 = 0.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then the test cases follow.
The first line of each test case contains three integers a, b and q (1 ≤ a, b ≤ 200; 1 ≤ q ≤ 500).
Then q lines follow, each containing two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 10^{18}) for the corresponding query.
Output
For each test case, print q integers — the answers to the queries of this test case in the order they appear.
Example
Input
2
4 6 5
1 1
1 3
1 5
1 7
1 9
7 10 2
7 8
100 200
Output
0 0 0 2 4
0 91
Tags: math, number theory
Correct Solution:
```
from fractions import gcd
get=lambda x,lcm,b:x-b*(x//lcm)-min(b,x%lcm+1)
for _ in range(int(input())):
a,b,q=map(int,input().split())
lcm=a*b//gcd(a,b)
for i in range(q):
l,r=map(int,input().split())
print(get(r,lcm,max(a,b))-get(l-1,lcm,max(a,b)))
```
| 6,730 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers a and b, and q queries. The i-th query consists of two numbers l_i and r_i, and the answer to it is the number of integers x such that l_i ≤ x ≤ r_i, and ((x mod a) mod b) ≠ ((x mod b) mod a). Calculate the answer for each query.
Recall that y mod z is the remainder of the division of y by z. For example, 5 mod 3 = 2, 7 mod 8 = 7, 9 mod 4 = 1, 9 mod 9 = 0.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then the test cases follow.
The first line of each test case contains three integers a, b and q (1 ≤ a, b ≤ 200; 1 ≤ q ≤ 500).
Then q lines follow, each containing two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 10^{18}) for the corresponding query.
Output
For each test case, print q integers — the answers to the queries of this test case in the order they appear.
Example
Input
2
4 6 5
1 1
1 3
1 5
1 7
1 9
7 10 2
7 8
100 200
Output
0 0 0 2 4
0 91
Tags: math, number theory
Correct Solution:
```
import sys,math
input = sys.stdin.buffer.readline
def f(x,b,g,lcm):
seq,rest = divmod(x,lcm)
return seq*(lcm-b) + max(0,rest-b+1)
T = int(input())
for testcase in range(T):
a,b,q = map(int,input().split())
if a > b:
a,b = b,a
g = math.gcd(a,b)
lcm = a*b//g
res = []
for i in range(q):
ll,rr = map(int,input().split())
res.append(f(rr,b,g,lcm)-f(ll-1,b,g,lcm))
print(*res)
```
| 6,731 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers a and b, and q queries. The i-th query consists of two numbers l_i and r_i, and the answer to it is the number of integers x such that l_i ≤ x ≤ r_i, and ((x mod a) mod b) ≠ ((x mod b) mod a). Calculate the answer for each query.
Recall that y mod z is the remainder of the division of y by z. For example, 5 mod 3 = 2, 7 mod 8 = 7, 9 mod 4 = 1, 9 mod 9 = 0.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then the test cases follow.
The first line of each test case contains three integers a, b and q (1 ≤ a, b ≤ 200; 1 ≤ q ≤ 500).
Then q lines follow, each containing two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 10^{18}) for the corresponding query.
Output
For each test case, print q integers — the answers to the queries of this test case in the order they appear.
Example
Input
2
4 6 5
1 1
1 3
1 5
1 7
1 9
7 10 2
7 8
100 200
Output
0 0 0 2 4
0 91
Tags: math, number theory
Correct Solution:
```
import sys
from math import gcd
input=sys.stdin.readline
t=int(input())
for ii in range(t):
a,b,q=map(int,input().split())
c=a*b//gcd(a,b)
f=0
d=[0]
for i in range(c):
if (i%a)%b!=(i%b)%a:
f+=1
d.append(f)
ans=[]
for i in range(q):
l,r=map(int,input().split())
nl=l-l%c
nr=r+(c-r%c)-1
p=(nr-nl+1)//c
ff=0
tmp=p*f
tmp-=(d[(l%c)]+d[-1]-d[r%c+1])
ans.append(tmp)
print(*ans)
```
| 6,732 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers a and b, and q queries. The i-th query consists of two numbers l_i and r_i, and the answer to it is the number of integers x such that l_i ≤ x ≤ r_i, and ((x mod a) mod b) ≠ ((x mod b) mod a). Calculate the answer for each query.
Recall that y mod z is the remainder of the division of y by z. For example, 5 mod 3 = 2, 7 mod 8 = 7, 9 mod 4 = 1, 9 mod 9 = 0.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then the test cases follow.
The first line of each test case contains three integers a, b and q (1 ≤ a, b ≤ 200; 1 ≤ q ≤ 500).
Then q lines follow, each containing two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 10^{18}) for the corresponding query.
Output
For each test case, print q integers — the answers to the queries of this test case in the order they appear.
Example
Input
2
4 6 5
1 1
1 3
1 5
1 7
1 9
7 10 2
7 8
100 200
Output
0 0 0 2 4
0 91
Tags: math, number theory
Correct Solution:
```
from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush,heappop
import math
from collections import *
from functools import reduce,cmp_to_key
# import io, os
# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
import sys
input = sys.stdin.readline
M = mod = 10**9 + 7
def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))
def inv_mod(n):return pow(n, mod - 2, mod)
def li():return [int(i) for i in input().split()]
def st():return input()
def val():return int(input().rstrip('\n'))
def li2():return [i for i in input().rstrip('\n')]
def li3():return [int(i) for i in input().rstrip('\n')]
def giveab(a,b):
l = []
for i in range(1,a * b + 1,1):
l.append(1 if ((i%a)%b) != ((i%b)%a) else 0)
return l[:]
def giveforanum(r,s,l):
temp = r//(a * b)
up = temp*s
r %= (a * b)
return up + l[r]
for _ in range(val()):
a,b,q = li()
l1 = giveab(a,b)
pref = [0]
for i in l1:pref.append(pref[-1] + i)
s = sum(l1)
for i in range(q):
l,r = li()
print(giveforanum(r,s,pref) - giveforanum(l-1,s,pref))
```
| 6,733 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers a and b, and q queries. The i-th query consists of two numbers l_i and r_i, and the answer to it is the number of integers x such that l_i ≤ x ≤ r_i, and ((x mod a) mod b) ≠ ((x mod b) mod a). Calculate the answer for each query.
Recall that y mod z is the remainder of the division of y by z. For example, 5 mod 3 = 2, 7 mod 8 = 7, 9 mod 4 = 1, 9 mod 9 = 0.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then the test cases follow.
The first line of each test case contains three integers a, b and q (1 ≤ a, b ≤ 200; 1 ≤ q ≤ 500).
Then q lines follow, each containing two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 10^{18}) for the corresponding query.
Output
For each test case, print q integers — the answers to the queries of this test case in the order they appear.
Example
Input
2
4 6 5
1 1
1 3
1 5
1 7
1 9
7 10 2
7 8
100 200
Output
0 0 0 2 4
0 91
Tags: math, number theory
Correct Solution:
```
import sys
#
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
#
# range=xrange
from math import gcd
def go():
# n = int(input())
a,b,q = map(int, input().split())
# a, b = map(int, input().split())
g=a*b//gcd(a,b)
m=max(a,b)
def until(v):
result = ((v+1)//g)*m + min((v+1)%g,m)
result = v+1-result
# print ('-',v,result)
return result
res = []
for _ in range(q):
l, r = map(int, input().split())
res.append(until(r)-until(l-1))
return ' '.join(map(str,res))
# x,s = map(int,input().split())
t = int(input())
# t = 1
ans = []
for _ in range(t):
# print(go())
ans.append(str(go()))
#
print('\n'.join(ans))
```
| 6,734 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers a and b, and q queries. The i-th query consists of two numbers l_i and r_i, and the answer to it is the number of integers x such that l_i ≤ x ≤ r_i, and ((x mod a) mod b) ≠ ((x mod b) mod a). Calculate the answer for each query.
Recall that y mod z is the remainder of the division of y by z. For example, 5 mod 3 = 2, 7 mod 8 = 7, 9 mod 4 = 1, 9 mod 9 = 0.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then the test cases follow.
The first line of each test case contains three integers a, b and q (1 ≤ a, b ≤ 200; 1 ≤ q ≤ 500).
Then q lines follow, each containing two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 10^{18}) for the corresponding query.
Output
For each test case, print q integers — the answers to the queries of this test case in the order they appear.
Example
Input
2
4 6 5
1 1
1 3
1 5
1 7
1 9
7 10 2
7 8
100 200
Output
0 0 0 2 4
0 91
Tags: math, number theory
Correct Solution:
```
import math
def check(arr, a, b):
d = []
ll = a*b//math.gcd(a, b)
for i in range(1, ll+1):
if i%a%b != i%b%a:
d.append(1)
else:
d.append(0)
for i in range(1, len(d)):
if d[i] == 1:
d[i] = d[i-1] + 1
else:
d[i] = d[i-1]
result = []
last = d[-1]
for l, r in arr:
p = 1
q = 1
kk = last*((r//ll) - (l-1)//ll)
l -= 1
r = r % ll
if r == 0:
p = 0
else:
r -= 1
l = l % ll
if l == 0:
q = 0
else:
l -= 1
result.append(p*d[r] - q*d[l] + kk)
return result
t = int(input())
while t:
a, b, q = list(map(int, input().split()))
arr = []
for i in range(q):
arr.append(list(map(int, input().split())))
result = check(arr, a, b)
for i in result:
print(i, end=" " )
print()
t-= 1
```
| 6,735 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers a and b, and q queries. The i-th query consists of two numbers l_i and r_i, and the answer to it is the number of integers x such that l_i ≤ x ≤ r_i, and ((x mod a) mod b) ≠ ((x mod b) mod a). Calculate the answer for each query.
Recall that y mod z is the remainder of the division of y by z. For example, 5 mod 3 = 2, 7 mod 8 = 7, 9 mod 4 = 1, 9 mod 9 = 0.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then the test cases follow.
The first line of each test case contains three integers a, b and q (1 ≤ a, b ≤ 200; 1 ≤ q ≤ 500).
Then q lines follow, each containing two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 10^{18}) for the corresponding query.
Output
For each test case, print q integers — the answers to the queries of this test case in the order they appear.
Example
Input
2
4 6 5
1 1
1 3
1 5
1 7
1 9
7 10 2
7 8
100 200
Output
0 0 0 2 4
0 91
Tags: math, number theory
Correct Solution:
```
'''
Auther: ghoshashis545 Ashis Ghosh
College: jalpaiguri Govt Enggineerin College
Date:26/04/2020
'''
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())
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 powmod(a,b):
a%=mod
if(a==0):
return 0
res=1
while(b>0):
if(b&1):
res=(res*a)%mod
a=(a*a)%mod
b>>=1
return res
def func(x,y,c):
c1=x//y
ans=(c1*c)
x%=y
x+=1
if(x<c):
ans+=(x-c)
# print(ans)
return ans
def main():
for _ in range(ii()):
a,b,q=mi()
if(b>a):
a,b=b,a
x=a
y=(a*b)//gcd(a,b)
for i in range(q):
l,r=mi()
l-=1
if(a==b or r<a):
print('0',end=" ")
continue
if(r>=y):
ans=r-func(r,y,x)-a+1
else:
ans=(r-a+1)
if(l>=y):
ans1=l-func(l,y,x)-a+1
else:
if(l<a):
ans1=0
else:
ans1=(l-a+1)
# print(ans,ans1)
print(ans-ans1,end=" ")
print()
if __name__ == "__main__":
main()
```
| 6,736 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers a and b, and q queries. The i-th query consists of two numbers l_i and r_i, and the answer to it is the number of integers x such that l_i ≤ x ≤ r_i, and ((x mod a) mod b) ≠ ((x mod b) mod a). Calculate the answer for each query.
Recall that y mod z is the remainder of the division of y by z. For example, 5 mod 3 = 2, 7 mod 8 = 7, 9 mod 4 = 1, 9 mod 9 = 0.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then the test cases follow.
The first line of each test case contains three integers a, b and q (1 ≤ a, b ≤ 200; 1 ≤ q ≤ 500).
Then q lines follow, each containing two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 10^{18}) for the corresponding query.
Output
For each test case, print q integers — the answers to the queries of this test case in the order they appear.
Example
Input
2
4 6 5
1 1
1 3
1 5
1 7
1 9
7 10 2
7 8
100 200
Output
0 0 0 2 4
0 91
Tags: math, number theory
Correct Solution:
```
from math import gcd
finaans=[]
for t in range(int(input())):
a,b,q=[int(x) for x in input().split()]
l=(a*b)//gcd(a,b)
ans=[]
for k in range(q):
q1,q2=[int(x) for x in input().split()]
p=(q1-1)//l
q=q2//l
s1=q2-(q*max(a,b)+min(max(a,b),(q2%l)+1))
s2=q1-1-(p*max(a,b)+min(max(a,b),((q1-1)%l)+1))
ans.append(s1-s2)
finaans.append(ans)
for it in finaans:
print(*it)
```
| 6,737 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers a and b, and q queries. The i-th query consists of two numbers l_i and r_i, and the answer to it is the number of integers x such that l_i ≤ x ≤ r_i, and ((x mod a) mod b) ≠ ((x mod b) mod a). Calculate the answer for each query.
Recall that y mod z is the remainder of the division of y by z. For example, 5 mod 3 = 2, 7 mod 8 = 7, 9 mod 4 = 1, 9 mod 9 = 0.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then the test cases follow.
The first line of each test case contains three integers a, b and q (1 ≤ a, b ≤ 200; 1 ≤ q ≤ 500).
Then q lines follow, each containing two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 10^{18}) for the corresponding query.
Output
For each test case, print q integers — the answers to the queries of this test case in the order they appear.
Example
Input
2
4 6 5
1 1
1 3
1 5
1 7
1 9
7 10 2
7 8
100 200
Output
0 0 0 2 4
0 91
Submitted Solution:
```
def gcd(a,b):
if b==0:
return a
else:
return gcd(b,a%b)
def lcm(a,b):
return a*(b//gcd(a,b))
for _ in range(int(input())):
a,b,s=list(map(int,input().split()))
p=lcm(a,b)
q=max(a,b)
lis=[]
for _ in range(s):
l,r=map(int,input().split())
a1=l//p
a2=r//p
b1=l%p
b2=r%p
ans=0
if a1==a2:
if b1<q:
if b2<q:
ans+=b2-b1+1
else:
ans+=q-b1
else:
ans+=(a2-a1-1)*q
if b1<q:
ans+=q-b1
if b2>=q:
ans+=q
if b2<q:
ans+=b2+1
lis.append(r-l+1-ans)
print(*lis)
```
Yes
| 6,738 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers a and b, and q queries. The i-th query consists of two numbers l_i and r_i, and the answer to it is the number of integers x such that l_i ≤ x ≤ r_i, and ((x mod a) mod b) ≠ ((x mod b) mod a). Calculate the answer for each query.
Recall that y mod z is the remainder of the division of y by z. For example, 5 mod 3 = 2, 7 mod 8 = 7, 9 mod 4 = 1, 9 mod 9 = 0.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then the test cases follow.
The first line of each test case contains three integers a, b and q (1 ≤ a, b ≤ 200; 1 ≤ q ≤ 500).
Then q lines follow, each containing two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 10^{18}) for the corresponding query.
Output
For each test case, print q integers — the answers to the queries of this test case in the order they appear.
Example
Input
2
4 6 5
1 1
1 3
1 5
1 7
1 9
7 10 2
7 8
100 200
Output
0 0 0 2 4
0 91
Submitted Solution:
```
import math
def not_equal(a, b, i):
if i <= b-1:
return 0
# Get the lcm of a and b
l = a*b // math.gcd(a, b)
# The numbers up to the minimum always satisfy the condition
out = i - b + 1
# Subtract the terms k*l + c, k \in N, c < b
n_seqs = (i - b) // l
out -= n_seqs * b
# Add the terms that you may have missed when the modulus is close
mod = i % l
if mod < b:
out -= (mod+1)
return out
def naive_not_equal(a, b, val):
count = 0
for i in range(val+1):
if (i % a) % b != (i % b) % a:
count += 1
return count
t = int(input())
for _ in range(t):
a, b, q = map(int, input().split())
# Put a and b in order (a < b)
if a > b:
a, b = b, a
out = []
for _ in range(q):
l, r = map(int, input().split())
lhs = not_equal(a, b, l-1)
rhs = not_equal(a, b, r)
ans = rhs - lhs
out.append(str(ans))
print(' '.join(out))
```
Yes
| 6,739 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers a and b, and q queries. The i-th query consists of two numbers l_i and r_i, and the answer to it is the number of integers x such that l_i ≤ x ≤ r_i, and ((x mod a) mod b) ≠ ((x mod b) mod a). Calculate the answer for each query.
Recall that y mod z is the remainder of the division of y by z. For example, 5 mod 3 = 2, 7 mod 8 = 7, 9 mod 4 = 1, 9 mod 9 = 0.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then the test cases follow.
The first line of each test case contains three integers a, b and q (1 ≤ a, b ≤ 200; 1 ≤ q ≤ 500).
Then q lines follow, each containing two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 10^{18}) for the corresponding query.
Output
For each test case, print q integers — the answers to the queries of this test case in the order they appear.
Example
Input
2
4 6 5
1 1
1 3
1 5
1 7
1 9
7 10 2
7 8
100 200
Output
0 0 0 2 4
0 91
Submitted Solution:
```
import math
import os,io
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
def findv(lcm,l,r,b):
p = max(min(r,b),l)
s = r-p+1
x1 = p//lcm
x2 = r//lcm
if x1*lcm+b > p:
s -= b-p%lcm
x1 += 1
if x2*lcm+b <= r:
s -= b*(x2-x1+1)
else:
s -= b*(x2-x1)+ r%lcm + 1
return s
cases = int(input())
for t in range(cases):
a,b,q = list(map(int,input().split()))
a,b = min(a,b),max(a,b)
lcm = (a*b)//math.gcd(a,b)
out = []
for i in range(q):
l,r = list(map(int,input().split()))
if b>r:
out.append(0)
else:
out.append(findv(lcm, l, r, b))
print(*out)
```
Yes
| 6,740 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers a and b, and q queries. The i-th query consists of two numbers l_i and r_i, and the answer to it is the number of integers x such that l_i ≤ x ≤ r_i, and ((x mod a) mod b) ≠ ((x mod b) mod a). Calculate the answer for each query.
Recall that y mod z is the remainder of the division of y by z. For example, 5 mod 3 = 2, 7 mod 8 = 7, 9 mod 4 = 1, 9 mod 9 = 0.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then the test cases follow.
The first line of each test case contains three integers a, b and q (1 ≤ a, b ≤ 200; 1 ≤ q ≤ 500).
Then q lines follow, each containing two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 10^{18}) for the corresponding query.
Output
For each test case, print q integers — the answers to the queries of this test case in the order they appear.
Example
Input
2
4 6 5
1 1
1 3
1 5
1 7
1 9
7 10 2
7 8
100 200
Output
0 0 0 2 4
0 91
Submitted Solution:
```
for _ in range(int(input())):
a,b,q = map(int,input().split())
p = [0]*(a*b)
for j in range(1,a*b):
p[j] = p[j-1]
if (((j % a) % b) != ((j % b) % a)):
p[j] = p[j] + 1
m = []
for k in range(q):
l,r = map(int,input().split())
x = r//len(p)
y = (l-1)//len(p)
m.append(p[r % (len(p))] - p[(l - 1) % (len(p))] + (x - y) * p[-1])
print(*m)
```
Yes
| 6,741 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers a and b, and q queries. The i-th query consists of two numbers l_i and r_i, and the answer to it is the number of integers x such that l_i ≤ x ≤ r_i, and ((x mod a) mod b) ≠ ((x mod b) mod a). Calculate the answer for each query.
Recall that y mod z is the remainder of the division of y by z. For example, 5 mod 3 = 2, 7 mod 8 = 7, 9 mod 4 = 1, 9 mod 9 = 0.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then the test cases follow.
The first line of each test case contains three integers a, b and q (1 ≤ a, b ≤ 200; 1 ≤ q ≤ 500).
Then q lines follow, each containing two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 10^{18}) for the corresponding query.
Output
For each test case, print q integers — the answers to the queries of this test case in the order they appear.
Example
Input
2
4 6 5
1 1
1 3
1 5
1 7
1 9
7 10 2
7 8
100 200
Output
0 0 0 2 4
0 91
Submitted Solution:
```
def gcd(a,b):
# Everything divides 0
if (a == 0):
return b
if (b == 0):
return a
# base case
if (a == b):
return a
# a is greater
if (a > b):
return gcd(a-b, b)
return gcd(a, b-a)
T=int(input())
for _ in range(T):
a,b,q=input().split()
a=int(a)
b=int(b)
q=int(q)
answer=[]
lcm_ab=int((a*b)/gcd(a,b))
for _1 in range(q):
x,y=input().split()
x=int(x)
y=int(y)
if x>b:
temp=y-x+1
else:
temp=y-b+1
if temp>0:
count=temp
else:
count=0
count1=0
temp1=int(x/lcm_ab)
if x-temp1*lcm_ab<b and temp1>0:
count1+=temp1*lcm_ab+b-x
temp2=int(y/lcm_ab)
if y-temp2*lcm_ab<b and temp2>0:
count1+=y-temp2*lcm_ab
count1+=b*(temp2-temp1)
answer.append(count-count1)
print(*answer)
```
No
| 6,742 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers a and b, and q queries. The i-th query consists of two numbers l_i and r_i, and the answer to it is the number of integers x such that l_i ≤ x ≤ r_i, and ((x mod a) mod b) ≠ ((x mod b) mod a). Calculate the answer for each query.
Recall that y mod z is the remainder of the division of y by z. For example, 5 mod 3 = 2, 7 mod 8 = 7, 9 mod 4 = 1, 9 mod 9 = 0.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then the test cases follow.
The first line of each test case contains three integers a, b and q (1 ≤ a, b ≤ 200; 1 ≤ q ≤ 500).
Then q lines follow, each containing two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 10^{18}) for the corresponding query.
Output
For each test case, print q integers — the answers to the queries of this test case in the order they appear.
Example
Input
2
4 6 5
1 1
1 3
1 5
1 7
1 9
7 10 2
7 8
100 200
Output
0 0 0 2 4
0 91
Submitted Solution:
```
def readInts():
return list(map(int, input().split()))
def readInt():
return int(input())
def g(a, b, r):
times = (r + 1) // (a * b)
rem = (r + 1) % (a * b)
res = 0
for x in range(a * b):
if x > r:
break
if (x % a) % b != (x % b) % a:
res += times
if rem > 0:
res += 1
rem -= 1
return res
def f(a, b, l, r):
if a == b:
return 0
# a < b
res1 = g(a, b, r)
res2 = g(a, b, l - 1)
return res1 - res2
def solve(a, b, q):
ans = []
for _ in range(q):
l, r = readInts()
ans.append(f(min(a, b), max(a, b), l, r))
for x in ans:
print(x, end=" ")
print()
def main():
t = readInt()
for i in range(t):
a, b, q = readInts()
solve(a, b, q)
main()
```
No
| 6,743 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers a and b, and q queries. The i-th query consists of two numbers l_i and r_i, and the answer to it is the number of integers x such that l_i ≤ x ≤ r_i, and ((x mod a) mod b) ≠ ((x mod b) mod a). Calculate the answer for each query.
Recall that y mod z is the remainder of the division of y by z. For example, 5 mod 3 = 2, 7 mod 8 = 7, 9 mod 4 = 1, 9 mod 9 = 0.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then the test cases follow.
The first line of each test case contains three integers a, b and q (1 ≤ a, b ≤ 200; 1 ≤ q ≤ 500).
Then q lines follow, each containing two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 10^{18}) for the corresponding query.
Output
For each test case, print q integers — the answers to the queries of this test case in the order they appear.
Example
Input
2
4 6 5
1 1
1 3
1 5
1 7
1 9
7 10 2
7 8
100 200
Output
0 0 0 2 4
0 91
Submitted Solution:
```
import math
a = 0
b = 0
p = 0
def get(x):
k = int(x / p)
return int(x-(k*max(a, b)-1+min(max(a, b), (x-k*p+1))))
for _ in range(int(input())):
a, b, q = map(int, input().split())
p = math.gcd(a, b)
p = a * b / p
for k in range(q):
l, r = map(int, input().split())
print(get(r) - get(l-1), end=' ')
print(" ")
```
No
| 6,744 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers a and b, and q queries. The i-th query consists of two numbers l_i and r_i, and the answer to it is the number of integers x such that l_i ≤ x ≤ r_i, and ((x mod a) mod b) ≠ ((x mod b) mod a). Calculate the answer for each query.
Recall that y mod z is the remainder of the division of y by z. For example, 5 mod 3 = 2, 7 mod 8 = 7, 9 mod 4 = 1, 9 mod 9 = 0.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then the test cases follow.
The first line of each test case contains three integers a, b and q (1 ≤ a, b ≤ 200; 1 ≤ q ≤ 500).
Then q lines follow, each containing two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 10^{18}) for the corresponding query.
Output
For each test case, print q integers — the answers to the queries of this test case in the order they appear.
Example
Input
2
4 6 5
1 1
1 3
1 5
1 7
1 9
7 10 2
7 8
100 200
Output
0 0 0 2 4
0 91
Submitted Solution:
```
# Contest No.: Edu 86
# Problem No.: C
# Solver: JEMINI
# Date: 20200426
import sys
def gcd(a: int, b: int) -> int:
if a < b:
a, b = b, a
if b == 0:
return a
else:
return gcd(b, a % b)
def main():
t = int(input())
for _ in range(t):
a, b, q = map(int, sys.stdin.readline().split())
flag = None
modVal = None
if a == 1 or b == 1 or a == b:
flag = 0
elif max(a, b) % min(a, b) == 0:
flag = 1
modVal = min(a, b)
else:
flag = 2
modVal = a * b // gcd(a, b)
checkList = [False] * modVal
loopSum = 0
for i in range(modVal):
if ((i % a) % b) != ((i % b) % a):
checkList[i] = True
loopSum += 1
for i in range(q):
x, y = map(int, sys.stdin.readline().split())
if flag == 0:
print(0, end = " ")
elif flag == 1:
ans = y - x + 1
tempL = x + (modVal - x % modVal) % modVal
tempR = y + (modVal - y % modVal)
ans -= tempR // modVal - tempL // modVal
print(ans, end = " ")
else:
ans = sum(checkList[x % modVal:y % modVal + 1]) + (y // modVal - x // modVal) * loopSum
print(ans, end = " ")
print("")
return
if __name__ == "__main__":
main()
```
No
| 6,745 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Given an array a of length n, find another array, b, of length n such that:
* for each i (1 ≤ i ≤ n) MEX(\\{b_1, b_2, …, b_i\})=a_i.
The MEX of a set of integers is the smallest non-negative integer that doesn't belong to this set.
If such array doesn't exist, determine this.
Input
The first line contains an integer n (1 ≤ n ≤ 10^5) — the length of the array a.
The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ i) — the elements of the array a. It's guaranteed that a_i ≤ a_{i+1} for 1≤ i < n.
Output
If there's no such array, print a single line containing -1.
Otherwise, print a single line containing n integers b_1, b_2, …, b_n (0 ≤ b_i ≤ 10^6)
If there are multiple answers, print any.
Examples
Input
3
1 2 3
Output
0 1 2
Input
4
0 0 0 2
Output
1 3 4 0
Input
3
1 1 3
Output
0 2 1
Note
In the second test case, other answers like [1,1,1,0], for example, are valid.
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
import sys
N = int(input())
a = [int(x) for x in input().split(' ')]
b = [0 for _ in range(N)]
st = []
for i, x in enumerate(a):
dif = a[i] - a[i-1] if i != 0 else a[i]
if dif:
if len(st) + 1 < dif:
print(-1)
sys.exit(0)
else:
b[i] = a[i-1] if i != 0 else 0
for j in range(dif-1):
b[st.pop()] = a[i-1] + j + 1
else:
st.append(i)
for x in st:
b[x] = a[-1] + 1
print(' '.join(map(str, b)))
```
| 6,746 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Given an array a of length n, find another array, b, of length n such that:
* for each i (1 ≤ i ≤ n) MEX(\\{b_1, b_2, …, b_i\})=a_i.
The MEX of a set of integers is the smallest non-negative integer that doesn't belong to this set.
If such array doesn't exist, determine this.
Input
The first line contains an integer n (1 ≤ n ≤ 10^5) — the length of the array a.
The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ i) — the elements of the array a. It's guaranteed that a_i ≤ a_{i+1} for 1≤ i < n.
Output
If there's no such array, print a single line containing -1.
Otherwise, print a single line containing n integers b_1, b_2, …, b_n (0 ≤ b_i ≤ 10^6)
If there are multiple answers, print any.
Examples
Input
3
1 2 3
Output
0 1 2
Input
4
0 0 0 2
Output
1 3 4 0
Input
3
1 1 3
Output
0 2 1
Note
In the second test case, other answers like [1,1,1,0], for example, are valid.
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
# avoiding using queue
def main():
test = 1
for _ in range(test):
n = int(input())
ara = [int(num) for num in input().split()]
mark = [True for _ in range(n + 1)]
for num in ara:
mark[num] = False
take_from = []
for index in range(n + 1):
if mark[index]:
take_from.append(index)
ans = []
ans.append(take_from[0])
take_at = 1
take_size = len(take_from)
for index in range(1, n):
if ara[index] != ara[index - 1]:
ans.append(ara[index - 1])
elif take_at < take_size:
ans.append(take_from[take_at])
take_at += 1
else:
ans.append(n + 1)
ans = ' '.join(map(str, ans))
print(ans)
if __name__ == "__main__":
main()
```
| 6,747 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Given an array a of length n, find another array, b, of length n such that:
* for each i (1 ≤ i ≤ n) MEX(\\{b_1, b_2, …, b_i\})=a_i.
The MEX of a set of integers is the smallest non-negative integer that doesn't belong to this set.
If such array doesn't exist, determine this.
Input
The first line contains an integer n (1 ≤ n ≤ 10^5) — the length of the array a.
The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ i) — the elements of the array a. It's guaranteed that a_i ≤ a_{i+1} for 1≤ i < n.
Output
If there's no such array, print a single line containing -1.
Otherwise, print a single line containing n integers b_1, b_2, …, b_n (0 ≤ b_i ≤ 10^6)
If there are multiple answers, print any.
Examples
Input
3
1 2 3
Output
0 1 2
Input
4
0 0 0 2
Output
1 3 4 0
Input
3
1 1 3
Output
0 2 1
Note
In the second test case, other answers like [1,1,1,0], for example, are valid.
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
""" Python 3 compatibility tools. """
from __future__ import division, print_function
import itertools
import sys
import os
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
input = raw_input
range = xrange
filter = itertools.ifilter
map = itertools.imap
zip = itertools.izip
def is_it_local():
script_dir = str(os.getcwd()).split('/')
username = "dipta007"
return username in script_dir
def READ(fileName):
if is_it_local():
sys.stdin = open(f'./{fileName}', 'r')
# 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")
if not is_it_local():
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
def input1(type=int):
return type(input())
def input2(type=int):
[a, b] = list(map(type, input().split()))
return a, b
def input3(type=int):
[a, b, c] = list(map(type, input().split()))
return a, b, c
def input_array(type=int):
return list(map(type, input().split()))
def input_string():
s = input()
return list(s)
if is_it_local():
def debug(*args):
st = ""
for arg in args:
st += f"{arg} "
print(st)
else:
def debug(*args):
pass
##############################################################
import heapq
def main():
n = input1()
ar = input_array()
mp = {}
flg = 1
last = 0
for i in range(n-1, -1, -1):
if ar[i] not in mp:
mp[ar[i]] = 0
mp[ar[i]] += 1
last = max(last, ar[i])
if ar[i] > i + 1:
flg = 0
if flg == 0:
print(-1)
exit()
ll = []
heapq.heapify(ll)
for i in range(0, last):
if mp.get(i, 0) == 0:
heapq.heappush(ll, i)
res = []
for v in ar:
now = -1
if len(ll) > 0:
now = heapq.heappop(ll)
# heapq.remove(now)
else:
now = last + 1
res.append(now)
mp[v] -= 1
if mp[v] == 0:
heapq.heappush(ll, v)
print(" ".join(str(x) for x in res))
pass
if __name__ == '__main__':
# READ('in.txt')
main()
```
| 6,748 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Given an array a of length n, find another array, b, of length n such that:
* for each i (1 ≤ i ≤ n) MEX(\\{b_1, b_2, …, b_i\})=a_i.
The MEX of a set of integers is the smallest non-negative integer that doesn't belong to this set.
If such array doesn't exist, determine this.
Input
The first line contains an integer n (1 ≤ n ≤ 10^5) — the length of the array a.
The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ i) — the elements of the array a. It's guaranteed that a_i ≤ a_{i+1} for 1≤ i < n.
Output
If there's no such array, print a single line containing -1.
Otherwise, print a single line containing n integers b_1, b_2, …, b_n (0 ≤ b_i ≤ 10^6)
If there are multiple answers, print any.
Examples
Input
3
1 2 3
Output
0 1 2
Input
4
0 0 0 2
Output
1 3 4 0
Input
3
1 1 3
Output
0 2 1
Note
In the second test case, other answers like [1,1,1,0], for example, are valid.
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
n=int(input())
a=list(map(int,input().split()))
l=[]
r=[]
s1=set(a)
s2=set([int(x) for x in range(n+2)])
s3=s2.difference(s1)
r=list(s3)
r.sort()
l.append(r[0])
r.remove(r[0])
for i in range(1,n):
if a[i-1]!=a[i]:
l.append(a[i-1])
else:
l.append(r[0])
r.remove(r[0])
print(*l)
```
| 6,749 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Given an array a of length n, find another array, b, of length n such that:
* for each i (1 ≤ i ≤ n) MEX(\\{b_1, b_2, …, b_i\})=a_i.
The MEX of a set of integers is the smallest non-negative integer that doesn't belong to this set.
If such array doesn't exist, determine this.
Input
The first line contains an integer n (1 ≤ n ≤ 10^5) — the length of the array a.
The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ i) — the elements of the array a. It's guaranteed that a_i ≤ a_{i+1} for 1≤ i < n.
Output
If there's no such array, print a single line containing -1.
Otherwise, print a single line containing n integers b_1, b_2, …, b_n (0 ≤ b_i ≤ 10^6)
If there are multiple answers, print any.
Examples
Input
3
1 2 3
Output
0 1 2
Input
4
0 0 0 2
Output
1 3 4 0
Input
3
1 1 3
Output
0 2 1
Note
In the second test case, other answers like [1,1,1,0], for example, are valid.
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
n=int(input())
l=list(map(int,input().split()))
d={}
l1=[0]*(10**5+1)
cnt=0
l3=[]
for i in l:
if i not in d:
d[i]=0
for i in range(len(l1)):
if i in d:
continue
else:
l1[i]=1
l2=[]
for i in range(len(l1)):
if l1[i]!=0:
l2.append(i)
else:
l3.append(i)
j,z=0,0
l4=[]
for i in range(len(l)):
if l[i]>l3[j]:
l4.append(l3[j])
j+=1
else:
l4.append(l2[z])
z+=1
print(*l4)
```
| 6,750 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Given an array a of length n, find another array, b, of length n such that:
* for each i (1 ≤ i ≤ n) MEX(\\{b_1, b_2, …, b_i\})=a_i.
The MEX of a set of integers is the smallest non-negative integer that doesn't belong to this set.
If such array doesn't exist, determine this.
Input
The first line contains an integer n (1 ≤ n ≤ 10^5) — the length of the array a.
The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ i) — the elements of the array a. It's guaranteed that a_i ≤ a_{i+1} for 1≤ i < n.
Output
If there's no such array, print a single line containing -1.
Otherwise, print a single line containing n integers b_1, b_2, …, b_n (0 ≤ b_i ≤ 10^6)
If there are multiple answers, print any.
Examples
Input
3
1 2 3
Output
0 1 2
Input
4
0 0 0 2
Output
1 3 4 0
Input
3
1 1 3
Output
0 2 1
Note
In the second test case, other answers like [1,1,1,0], for example, are valid.
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
import sys
n = int(input())
mas = list(map(int, input().split()))
s = set(mas)
now = 1
p = 0
for i in range(n):
if mas[i] != p:
print(p, end = ' ')
p = mas[i]
if now == mas[i]:
now += 1
else:
while now in s:
now += 1
print(now, end = ' ')
now += 1
print()
```
| 6,751 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Given an array a of length n, find another array, b, of length n such that:
* for each i (1 ≤ i ≤ n) MEX(\\{b_1, b_2, …, b_i\})=a_i.
The MEX of a set of integers is the smallest non-negative integer that doesn't belong to this set.
If such array doesn't exist, determine this.
Input
The first line contains an integer n (1 ≤ n ≤ 10^5) — the length of the array a.
The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ i) — the elements of the array a. It's guaranteed that a_i ≤ a_{i+1} for 1≤ i < n.
Output
If there's no such array, print a single line containing -1.
Otherwise, print a single line containing n integers b_1, b_2, …, b_n (0 ≤ b_i ≤ 10^6)
If there are multiple answers, print any.
Examples
Input
3
1 2 3
Output
0 1 2
Input
4
0 0 0 2
Output
1 3 4 0
Input
3
1 1 3
Output
0 2 1
Note
In the second test case, other answers like [1,1,1,0], for example, are valid.
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
import sys
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()
n = II()
a = LI()
if a[0] not in [0,1] or a!=sorted(a):
print(-1)
else:
boo = True
for i in range(n):
if a[i]>i+1:
boo = False
break
if boo == False:
print(-1)
else:
b = [-1]*n
arr = list(range(n))
if a[-1] <n:
arr = list(range(n+1))
arr.pop(a[-1])
d = {}
for i in arr:
d[i] = 0
for i in range(n-1,0,-1):
if a[i]>a[i-1]:
b[i] = a[i-1]
d[a[i-1]] = 1
temp = 0
for i in range(n):
if b[i] == -1:
while(d[arr[temp]] == 1):
temp+=1
b[i] = arr[temp]
temp+=1
print(*b)
```
| 6,752 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Given an array a of length n, find another array, b, of length n such that:
* for each i (1 ≤ i ≤ n) MEX(\\{b_1, b_2, …, b_i\})=a_i.
The MEX of a set of integers is the smallest non-negative integer that doesn't belong to this set.
If such array doesn't exist, determine this.
Input
The first line contains an integer n (1 ≤ n ≤ 10^5) — the length of the array a.
The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ i) — the elements of the array a. It's guaranteed that a_i ≤ a_{i+1} for 1≤ i < n.
Output
If there's no such array, print a single line containing -1.
Otherwise, print a single line containing n integers b_1, b_2, …, b_n (0 ≤ b_i ≤ 10^6)
If there are multiple answers, print any.
Examples
Input
3
1 2 3
Output
0 1 2
Input
4
0 0 0 2
Output
1 3 4 0
Input
3
1 1 3
Output
0 2 1
Note
In the second test case, other answers like [1,1,1,0], for example, are valid.
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
n = int(input())
a = [int(i) for i in input().split(' ')]
b = [0] * n
count = 0
idxs = []
if a[0] == 0:
idxs.append(0)
else:
b[0] = 0
ok = True
for i in range(1, n):
if a[i] == a[i - 1]:
idxs.append(i)
else:
b[i] = a[i - 1]
k = 1
while k < a[i] - a[i - 1]:
if len(idxs) == 0:
ok = False
print(-1)
break
b[idxs.pop()] = a[i - 1] + k
k += 1
if not ok:
break
max_v = a[-1] * 2 if a[-1] != 0 else 1
while len(idxs):
b[idxs.pop()] = max_v
s = ''
for i in b:
s += f'{i} '
print(s)
```
| 6,753 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given an array a of length n, find another array, b, of length n such that:
* for each i (1 ≤ i ≤ n) MEX(\\{b_1, b_2, …, b_i\})=a_i.
The MEX of a set of integers is the smallest non-negative integer that doesn't belong to this set.
If such array doesn't exist, determine this.
Input
The first line contains an integer n (1 ≤ n ≤ 10^5) — the length of the array a.
The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ i) — the elements of the array a. It's guaranteed that a_i ≤ a_{i+1} for 1≤ i < n.
Output
If there's no such array, print a single line containing -1.
Otherwise, print a single line containing n integers b_1, b_2, …, b_n (0 ≤ b_i ≤ 10^6)
If there are multiple answers, print any.
Examples
Input
3
1 2 3
Output
0 1 2
Input
4
0 0 0 2
Output
1 3 4 0
Input
3
1 1 3
Output
0 2 1
Note
In the second test case, other answers like [1,1,1,0], for example, are valid.
Submitted Solution:
```
# kartikay26
"""
https://codeforces.com/contest/1364/problem/C
Idea:
- whenever MEX increases it means that number was added
- when MEX increases by more than 1 it means the numbers
in between were previously added
- create "slots" for numbers we do not know, then fill later
with n+1 or the numbers that we find later which should
have come before
"""
def main():
n = int(input())
mex = [int(x) for x in input().split()]
arr = [n+1] * n
prev_mex = 0
slots = []
for i in range(n):
if mex[i] > prev_mex:
arr[i] = prev_mex
nums_to_add = range(prev_mex+1,mex[i])
for num in nums_to_add:
if len(slots) == 0:
print(-1)
return
slot = slots.pop()
arr[slot] = num
else:
slots.append(i)
prev_mex = mex[i]
# print(arr)
print(" ".join(str(x) for x in arr))
if __name__ == "__main__":
main()
```
Yes
| 6,754 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given an array a of length n, find another array, b, of length n such that:
* for each i (1 ≤ i ≤ n) MEX(\\{b_1, b_2, …, b_i\})=a_i.
The MEX of a set of integers is the smallest non-negative integer that doesn't belong to this set.
If such array doesn't exist, determine this.
Input
The first line contains an integer n (1 ≤ n ≤ 10^5) — the length of the array a.
The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ i) — the elements of the array a. It's guaranteed that a_i ≤ a_{i+1} for 1≤ i < n.
Output
If there's no such array, print a single line containing -1.
Otherwise, print a single line containing n integers b_1, b_2, …, b_n (0 ≤ b_i ≤ 10^6)
If there are multiple answers, print any.
Examples
Input
3
1 2 3
Output
0 1 2
Input
4
0 0 0 2
Output
1 3 4 0
Input
3
1 1 3
Output
0 2 1
Note
In the second test case, other answers like [1,1,1,0], for example, are valid.
Submitted Solution:
```
from collections import deque
n = int(input())
INF=float('inf')
rr = lambda: input()
rri = lambda: int(input())
rrm = lambda: list(map(int, input().split()))
def solve(N, A):
free = deque()
ans = [-1] * N
low = 0
for i, x in enumerate(A):
free.append([i, x])
while low < x:
if not free: return
j, y = free.pop()
if low != y: #success
ans[j] = low
low += 1
else: return
while free:
ans[free.pop()[0]] = 10**6
return ans
arr= rrm()
ans = solve(n,arr)
if ans is None:
print -1
else:
print(" ".join(map(str, ans)))
# from awice
```
Yes
| 6,755 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given an array a of length n, find another array, b, of length n such that:
* for each i (1 ≤ i ≤ n) MEX(\\{b_1, b_2, …, b_i\})=a_i.
The MEX of a set of integers is the smallest non-negative integer that doesn't belong to this set.
If such array doesn't exist, determine this.
Input
The first line contains an integer n (1 ≤ n ≤ 10^5) — the length of the array a.
The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ i) — the elements of the array a. It's guaranteed that a_i ≤ a_{i+1} for 1≤ i < n.
Output
If there's no such array, print a single line containing -1.
Otherwise, print a single line containing n integers b_1, b_2, …, b_n (0 ≤ b_i ≤ 10^6)
If there are multiple answers, print any.
Examples
Input
3
1 2 3
Output
0 1 2
Input
4
0 0 0 2
Output
1 3 4 0
Input
3
1 1 3
Output
0 2 1
Note
In the second test case, other answers like [1,1,1,0], for example, are valid.
Submitted Solution:
```
from collections import deque
N = int(input())
List = [int(x) for x in input().split()]
for i in range(N):
if(List[i]>i+1):
print(-1)
exit()
Nahi = list(set(list(range(N+1))).difference(set(List)))
Nahi.sort()
Ans = [Nahi[0]]
Added = deque()
Added.append(List[0])
index = 1
for i in range(1,N):
if(List[i]==List[i-1]):
if(Added[-1]!=List[i]):
Added.append(List[i])
Ans.append(Nahi[index])
index+=1
else:
Ans.append(Added[0])
Added.popleft()
Added.append(List[i])
print(*Ans)
```
Yes
| 6,756 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given an array a of length n, find another array, b, of length n such that:
* for each i (1 ≤ i ≤ n) MEX(\\{b_1, b_2, …, b_i\})=a_i.
The MEX of a set of integers is the smallest non-negative integer that doesn't belong to this set.
If such array doesn't exist, determine this.
Input
The first line contains an integer n (1 ≤ n ≤ 10^5) — the length of the array a.
The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ i) — the elements of the array a. It's guaranteed that a_i ≤ a_{i+1} for 1≤ i < n.
Output
If there's no such array, print a single line containing -1.
Otherwise, print a single line containing n integers b_1, b_2, …, b_n (0 ≤ b_i ≤ 10^6)
If there are multiple answers, print any.
Examples
Input
3
1 2 3
Output
0 1 2
Input
4
0 0 0 2
Output
1 3 4 0
Input
3
1 1 3
Output
0 2 1
Note
In the second test case, other answers like [1,1,1,0], for example, are valid.
Submitted Solution:
```
import sys
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return map(int, minp().split())
def check(a, b):
n = len(a)
bb = [False]*(n+1)
c = [0]*n
j = 0
z = 0
for i in a:
if i <= n:
bb[i] = True
while bb[j]:
j += 1
if b[z] != j:
return False
z += 1
return True
def solve():
n = mint()
a = list(mints())
b = [None]*n
c = [False]*(n+1)
for i in range(1,n):
if a[i] != a[i-1]:
b[i] = a[i-1]
if a[i-1] <= n:
c[a[i-1]] = True
if a[-1] <= n:
c[a[-1]] = True
if a[0] != 0:
b[0] = 0
c[0] = True
#print(b)
#print(c)
j = 0
for i in range(n):
if b[i] is None:
while c[j]:
j += 1
b[i] = j
c[j] = True
#print(b)
#print(check(b,a))
if check(b,a):
print(' '.join(map(str,b)))
else:
print(-1)
#for i in range(mint()):
solve()
```
Yes
| 6,757 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given an array a of length n, find another array, b, of length n such that:
* for each i (1 ≤ i ≤ n) MEX(\\{b_1, b_2, …, b_i\})=a_i.
The MEX of a set of integers is the smallest non-negative integer that doesn't belong to this set.
If such array doesn't exist, determine this.
Input
The first line contains an integer n (1 ≤ n ≤ 10^5) — the length of the array a.
The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ i) — the elements of the array a. It's guaranteed that a_i ≤ a_{i+1} for 1≤ i < n.
Output
If there's no such array, print a single line containing -1.
Otherwise, print a single line containing n integers b_1, b_2, …, b_n (0 ≤ b_i ≤ 10^6)
If there are multiple answers, print any.
Examples
Input
3
1 2 3
Output
0 1 2
Input
4
0 0 0 2
Output
1 3 4 0
Input
3
1 1 3
Output
0 2 1
Note
In the second test case, other answers like [1,1,1,0], for example, are valid.
Submitted Solution:
```
n=int(input())
s=input().split()
flag=0
for j in range(n):
s[j]=int(s[j])
if s[j]>j+1:
flag=1
if flag==1:
print(-1)
else:
if s[0]==1:
for j in range (n-1):
if s[j+1]-s[j]>1:
flag=1
break
if flag==1:
print(-1)
else:
for j in range (n):
print(s[j]-1,end="")
else:
for j in range (n):
if s[j]>=3:
rr=j
else:
rr=0
if rr:
for j in range (rr,n-1):
if s[j+1]-s[j]>1:
flag=1
break
for j in range (n):
if s[j]==1:
flag=1
if flag==1:
print(-1)
else:
for j in range (n):
if s[j]==0:
print("1 ",end="")
elif s[j]==2:
print("0 ",end="")
else:
print(s[j]-1,end="")
```
No
| 6,758 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given an array a of length n, find another array, b, of length n such that:
* for each i (1 ≤ i ≤ n) MEX(\\{b_1, b_2, …, b_i\})=a_i.
The MEX of a set of integers is the smallest non-negative integer that doesn't belong to this set.
If such array doesn't exist, determine this.
Input
The first line contains an integer n (1 ≤ n ≤ 10^5) — the length of the array a.
The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ i) — the elements of the array a. It's guaranteed that a_i ≤ a_{i+1} for 1≤ i < n.
Output
If there's no such array, print a single line containing -1.
Otherwise, print a single line containing n integers b_1, b_2, …, b_n (0 ≤ b_i ≤ 10^6)
If there are multiple answers, print any.
Examples
Input
3
1 2 3
Output
0 1 2
Input
4
0 0 0 2
Output
1 3 4 0
Input
3
1 1 3
Output
0 2 1
Note
In the second test case, other answers like [1,1,1,0], for example, are valid.
Submitted Solution:
```
################om namh shivay##################37
###############(BHOLE KI FAUJ KREGI MAUJ)############37
from sys import stdin,stdout
import math,queue,heapq
fastinput=stdin.readline
fastout=stdout.write
t=1
while t:
t-=1
n=int(fastinput())
#n,m=map(int,fastinput().split())
#a=[0]+list(map(int,fastinput().split()))
b=list(map(int,fastinput().split()))
#matrix=[list(map(int,fastinput().split())) for _ in range(n)]
dubplicate=[]
ans=[]
j=1
if b[0]==0:
ans.append(1)
elif b[0]==1:
ans.append(0)
else:
print(-1)
exit()
flag=False
for i in range(1,n):
if b[i]==b[i-1]:
ans.append(ans[-1])
dubplicate.append(i)
else:
if (b[i]-b[i-1]-2)<=len(dubplicate):
ans.append(b[i-1])
x=b[i]-b[i-1]-1
j=1
while dubplicate and x>=j:
ans[dubplicate.pop()]=b[i-1]+j
j+=1
else:
flag=True
break
if flag:
print(-1)
else:
print(*ans)
```
No
| 6,759 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given an array a of length n, find another array, b, of length n such that:
* for each i (1 ≤ i ≤ n) MEX(\\{b_1, b_2, …, b_i\})=a_i.
The MEX of a set of integers is the smallest non-negative integer that doesn't belong to this set.
If such array doesn't exist, determine this.
Input
The first line contains an integer n (1 ≤ n ≤ 10^5) — the length of the array a.
The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ i) — the elements of the array a. It's guaranteed that a_i ≤ a_{i+1} for 1≤ i < n.
Output
If there's no such array, print a single line containing -1.
Otherwise, print a single line containing n integers b_1, b_2, …, b_n (0 ≤ b_i ≤ 10^6)
If there are multiple answers, print any.
Examples
Input
3
1 2 3
Output
0 1 2
Input
4
0 0 0 2
Output
1 3 4 0
Input
3
1 1 3
Output
0 2 1
Note
In the second test case, other answers like [1,1,1,0], for example, are valid.
Submitted Solution:
```
n = int(input())
l = list(map(int,input().split()))
for i in range(n):
print(l[i]+1,end=' ')
```
No
| 6,760 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given an array a of length n, find another array, b, of length n such that:
* for each i (1 ≤ i ≤ n) MEX(\\{b_1, b_2, …, b_i\})=a_i.
The MEX of a set of integers is the smallest non-negative integer that doesn't belong to this set.
If such array doesn't exist, determine this.
Input
The first line contains an integer n (1 ≤ n ≤ 10^5) — the length of the array a.
The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ i) — the elements of the array a. It's guaranteed that a_i ≤ a_{i+1} for 1≤ i < n.
Output
If there's no such array, print a single line containing -1.
Otherwise, print a single line containing n integers b_1, b_2, …, b_n (0 ≤ b_i ≤ 10^6)
If there are multiple answers, print any.
Examples
Input
3
1 2 3
Output
0 1 2
Input
4
0 0 0 2
Output
1 3 4 0
Input
3
1 1 3
Output
0 2 1
Note
In the second test case, other answers like [1,1,1,0], for example, are valid.
Submitted Solution:
```
def get_not_elements(a:list):
elements = set(a)
max_element = a[-1] +2
not_elements = []
for i in range(0,max_element):
if not i in elements:
not_elements.append(i)
not_elements.reverse()
return not_elements
#Ahora pensar esta funcion...
def is_valid(a : list):
if 0 in a and 1 in a:
return False
for i in range(len(a)):
if a[i]-1 > i:
return False
return True
def generate_array(a : list):
stack_ = get_not_elements(a)
b = [-1 for i in range(len(a))]
val = a[0]
for i in range(1,len(a)):
if a[i] != val:
b[i] = val
val = a[i]
if len(stack_)>0:
val = stack_.pop()
else:
val = a[0]
for i in range(len(a)):
if b[i] == -1:
b[i] = val
if len(stack_)>0:
val = stack_.pop()
return b
if __name__ == "__main__":
size =int(input())
array = [int(i) for i in input().split()]
if not is_valid(array):
print(-1)
else:
b = generate_array(array)
b = " ".join([str(i) for i in b])
print(b)
```
No
| 6,761 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Koa the Koala and her best friend want to play a game.
The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts.
Let's describe a move in the game:
* During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player.
More formally: if the current score of the player is x and the chosen element is y, his new score will be x ⊕ y. Here ⊕ denotes [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
Note that after a move element y is removed from a.
* The game ends when the array is empty.
At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.
If both players play optimally find out whether Koa will win, lose or draw the game.
Input
Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows.
The first line of each test case contains the integer n (1 ≤ n ≤ 10^5) — the length of a.
The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — elements of a.
It is guaranteed that the sum of n over all test cases does not exceed 10^5.
Output
For each test case print:
* WIN if Koa will win the game.
* LOSE if Koa will lose the game.
* DRAW if the game ends in a draw.
Examples
Input
3
3
1 2 2
3
2 2 3
5
0 0 0 2 2
Output
WIN
LOSE
DRAW
Input
4
5
4 1 5 1 3
4
1 0 1 6
1
0
2
5 4
Output
WIN
WIN
DRAW
WIN
Note
In testcase 1 of the first sample we have:
a = [1, 2, 2]. Here Koa chooses 1, other player has to choose 2, Koa chooses another 2. Score for Koa is 1 ⊕ 2 = 3 and score for other player is 2 so Koa wins.
Tags: bitmasks, constructive algorithms, dp, games, greedy, math
Correct Solution:
```
from collections import defaultdict
import sys, math
f = None
try:
f = open('q1.input', 'r')
except IOError:
f = sys.stdin
if 'xrange' in dir(__builtins__):
range = xrange
def print_case_iterable(case_num, iterable):
print("Case #{}: {}".format(case_num," ".join(map(str,iterable))))
def print_case_number(case_num, iterable):
print("Case #{}: {}".format(case_num,iterable))
def print_iterable(A):
print (' '.join(A))
def read_int():
return int(f.readline().strip())
def read_int_array():
return [int(x) for x in f.readline().strip().split(" ")]
def rns():
a = [x for x in f.readline().split(" ")]
return int(a[0]), a[1].strip()
def read_string():
return list(f.readline().strip())
def ri():
return int(f.readline().strip())
def ria():
return [int(x) for x in f.readline().strip().split(" ")]
def rns():
a = [x for x in f.readline().split(" ")]
return int(a[0]), a[1].strip()
def rs():
return list(f.readline().strip())
def bi(x):
return bin(x)[2:]
from collections import deque
import math
NUMBER = 10**9 + 7
def egcd(a, b):
if a == 0:
return (b, 0, 1)
else:
g, y, x = egcd(b % a, a)
return (g, x - (b // a) * y, y)
from collections import deque, defaultdict
import heapq
from types import GeneratorType
def shift(a,i,num):
for _ in range(num):
a[i],a[i+1],a[i+2] = a[i+2],a[i],a[i+1]
from heapq import heapify, heappush, heappop
from string import ascii_lowercase as al
def solution(a,n):
draw = True
for i in range(50,-1,-1):
cnt = 0
for x in a:
if (1<<i) & x:
cnt+=1
if cnt % 2:
draw = False
break
if draw:
return 'DRAW'
if (cnt - 1) % 4 == 0:
return 'WIN'
win = ((cnt+1)//2) % 2
win = win^((n - cnt )% 2)
return 'WIN' if win else 'LOSE'
def main():
for i in range(int(input())):
n = int(input())
a = list(map(int,input().split()))
x = solution(a,n)
if 'xrange' not in dir(__builtins__):
print(x) # print("Case #"+str(i+1)+':',x)
else:
print >>output,"Case #"+str(i+1)+':',str(x)
if 'xrange' in dir(__builtins__):
print(output.getvalue())
output.close()
if 'xrange' in dir(__builtins__):
import cStringIO
output = cStringIO.StringIO()
if __name__ == '__main__':
main()
```
| 6,762 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Koa the Koala and her best friend want to play a game.
The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts.
Let's describe a move in the game:
* During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player.
More formally: if the current score of the player is x and the chosen element is y, his new score will be x ⊕ y. Here ⊕ denotes [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
Note that after a move element y is removed from a.
* The game ends when the array is empty.
At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.
If both players play optimally find out whether Koa will win, lose or draw the game.
Input
Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows.
The first line of each test case contains the integer n (1 ≤ n ≤ 10^5) — the length of a.
The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — elements of a.
It is guaranteed that the sum of n over all test cases does not exceed 10^5.
Output
For each test case print:
* WIN if Koa will win the game.
* LOSE if Koa will lose the game.
* DRAW if the game ends in a draw.
Examples
Input
3
3
1 2 2
3
2 2 3
5
0 0 0 2 2
Output
WIN
LOSE
DRAW
Input
4
5
4 1 5 1 3
4
1 0 1 6
1
0
2
5 4
Output
WIN
WIN
DRAW
WIN
Note
In testcase 1 of the first sample we have:
a = [1, 2, 2]. Here Koa chooses 1, other player has to choose 2, Koa chooses another 2. Score for Koa is 1 ⊕ 2 = 3 and score for other player is 2 so Koa wins.
Tags: bitmasks, constructive algorithms, dp, games, greedy, math
Correct Solution:
```
from sys import stdin, stdout
fullans = ''
for _ in range(int(stdin.readline())):
n = int(stdin.readline())
ls = list(map(int, stdin.readline().split()))
bit = 32
check = True
while bit >= 0 and check:
x = 0
for i in ls:
if i & (1 << bit):
x += 1
y = n - x
if not x & 1:
bit -= 1
else:
check = False
if x % 4 == 1:
fullans += 'WIN\n'
else:
if y % 2 == 0:
fullans += 'LOSE\n'
else:
fullans += 'WIN\n'
if check:
fullans += 'DRAW\n'
stdout.write(fullans)
```
| 6,763 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Koa the Koala and her best friend want to play a game.
The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts.
Let's describe a move in the game:
* During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player.
More formally: if the current score of the player is x and the chosen element is y, his new score will be x ⊕ y. Here ⊕ denotes [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
Note that after a move element y is removed from a.
* The game ends when the array is empty.
At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.
If both players play optimally find out whether Koa will win, lose or draw the game.
Input
Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows.
The first line of each test case contains the integer n (1 ≤ n ≤ 10^5) — the length of a.
The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — elements of a.
It is guaranteed that the sum of n over all test cases does not exceed 10^5.
Output
For each test case print:
* WIN if Koa will win the game.
* LOSE if Koa will lose the game.
* DRAW if the game ends in a draw.
Examples
Input
3
3
1 2 2
3
2 2 3
5
0 0 0 2 2
Output
WIN
LOSE
DRAW
Input
4
5
4 1 5 1 3
4
1 0 1 6
1
0
2
5 4
Output
WIN
WIN
DRAW
WIN
Note
In testcase 1 of the first sample we have:
a = [1, 2, 2]. Here Koa chooses 1, other player has to choose 2, Koa chooses another 2. Score for Koa is 1 ⊕ 2 = 3 and score for other player is 2 so Koa wins.
Tags: bitmasks, constructive algorithms, dp, games, greedy, math
Correct Solution:
```
import sys
import math
from collections import defaultdict
import heapq
def getnum(num):
cnt=0
ans=0
while((1<<cnt)<=num):
ans=cnt
cnt+=1
if num==0:
return 0
return ans+1
t=int(sys.stdin.readline())
for _ in range(t):
n=int(sys.stdin.readline())
arr=list(map(int,sys.stdin.readline().split()))
mp=[[] for x in range(31)]
last=[]
for i in range(n):
x=getnum(arr[i])
mp[x].append(arr[i])
last.append(x)
last.sort()
rem=n
z=True
for i in range(30,0,-1):
if len(mp[i])!=0:
y=len(mp[i])
rem=n-y
if y==1:
z=False
print('WIN')
break
if y%2!=0:
if rem%2==0:
first=(y+1)//2
second=y//2
if first%2!=0:
print('WIN')
else:
print('LOSE')
z=False
break
if rem%2!=0:
print('WIN')
z=False
break
else:
for j in range(y):
mp[i][j]%=(1<<(i-1))
x=getnum(mp[i][j])
mp[x].append(mp[i][j])
else:
continue
if z:
print('DRAW')
```
| 6,764 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Koa the Koala and her best friend want to play a game.
The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts.
Let's describe a move in the game:
* During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player.
More formally: if the current score of the player is x and the chosen element is y, his new score will be x ⊕ y. Here ⊕ denotes [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
Note that after a move element y is removed from a.
* The game ends when the array is empty.
At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.
If both players play optimally find out whether Koa will win, lose or draw the game.
Input
Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows.
The first line of each test case contains the integer n (1 ≤ n ≤ 10^5) — the length of a.
The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — elements of a.
It is guaranteed that the sum of n over all test cases does not exceed 10^5.
Output
For each test case print:
* WIN if Koa will win the game.
* LOSE if Koa will lose the game.
* DRAW if the game ends in a draw.
Examples
Input
3
3
1 2 2
3
2 2 3
5
0 0 0 2 2
Output
WIN
LOSE
DRAW
Input
4
5
4 1 5 1 3
4
1 0 1 6
1
0
2
5 4
Output
WIN
WIN
DRAW
WIN
Note
In testcase 1 of the first sample we have:
a = [1, 2, 2]. Here Koa chooses 1, other player has to choose 2, Koa chooses another 2. Score for Koa is 1 ⊕ 2 = 3 and score for other player is 2 so Koa wins.
Tags: bitmasks, constructive algorithms, dp, games, greedy, math
Correct Solution:
```
from __future__ import division, print_function
import os,sys
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
from bisect import bisect_left as lower_bound, bisect_right as upper_bound
def so(): return int(input())
def st(): return input()
def mj(): return map(int,input().strip().split(" "))
def msj(): return map(str,input().strip().split(" "))
def le(): return list(map(int,input().split()))
def lebe():return list(map(int, input()))
def dmain():
sys.setrecursionlimit(1000000)
threading.stack_size(1024000)
thread = threading.Thread(target=main)
thread.start()
def joro(L):
return(''.join(map(str, L)))
def decimalToBinary(n): return bin(n).replace("0b","")
def isprime(n):
for i in range(2,int(n**0.5)+1):
if n%i==0:
return False
return True
def read():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
def tr(n):
return n*(n+1)//2
def iu():
m=so()
L=le()
i=30
while(i>=0):
c=0
for j in range(m):
c=c+((L[j]//(2**i))&1)
if(c%4==1):
print("WIN")
return
elif(m%2!=0 and c%2!=0):
print("LOSE")
return
elif(1==c%2):
print("WIN")
return
i=i-1
print("DRAW")
return
def main():
for i in range(so()):
iu()
# 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()
#dmain()
# Comment Read()
```
| 6,765 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Koa the Koala and her best friend want to play a game.
The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts.
Let's describe a move in the game:
* During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player.
More formally: if the current score of the player is x and the chosen element is y, his new score will be x ⊕ y. Here ⊕ denotes [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
Note that after a move element y is removed from a.
* The game ends when the array is empty.
At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.
If both players play optimally find out whether Koa will win, lose or draw the game.
Input
Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows.
The first line of each test case contains the integer n (1 ≤ n ≤ 10^5) — the length of a.
The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — elements of a.
It is guaranteed that the sum of n over all test cases does not exceed 10^5.
Output
For each test case print:
* WIN if Koa will win the game.
* LOSE if Koa will lose the game.
* DRAW if the game ends in a draw.
Examples
Input
3
3
1 2 2
3
2 2 3
5
0 0 0 2 2
Output
WIN
LOSE
DRAW
Input
4
5
4 1 5 1 3
4
1 0 1 6
1
0
2
5 4
Output
WIN
WIN
DRAW
WIN
Note
In testcase 1 of the first sample we have:
a = [1, 2, 2]. Here Koa chooses 1, other player has to choose 2, Koa chooses another 2. Score for Koa is 1 ⊕ 2 = 3 and score for other player is 2 so Koa wins.
Tags: bitmasks, constructive algorithms, dp, games, greedy, math
Correct Solution:
```
'''
Auther: ghoshashis545 Ashis Ghosh
College: jalpaiguri Govt Enggineering College
'''
from os import path
import sys
from heapq import heappush,heappop,heapify
from functools import cmp_to_key as ctk
from collections import deque,defaultdict as dd
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input().rstrip()
def mi():return map(int,input().split())
def li():return list(mi())
abc='abcdefghijklmnopqrstuvwxyz'
mod=1000000007
# mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]
def bo(i):
return ord(i)-ord('a')
file=1
def solve():
for _ in range(ii()):
n=ii()
a=li()
x=0
for i in a:
x^=i
if(x==0):
print("DRAW")
continue
for i in range(30,-1,-1):
if x>>i&1:
one=0
zero=0
for j in a:
if j>>i&1:
one+=1
else:
zero+=1
# if ith bit of even number element are not set
# then her best friend forced Koa to chose (x*2 + 2)[x=one//4] no of elements
# whose ith bit is set then Koa score ith bit will not set but her best
# friend select (x*2 + 1) no of elements so her bestfriend score ith bit
# will set. So,koa will lose.
if(zero%2==0 and one%4==3):
print('LOSE')
else:
print('WIN')
break
if __name__ =="__main__":
if(file):
if path.exists('input.txt'):
sys.stdin=open('input.txt', 'r')
sys.stdout=open('output.txt','w')
else:
input=sys.stdin.readline
solve()
```
| 6,766 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Koa the Koala and her best friend want to play a game.
The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts.
Let's describe a move in the game:
* During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player.
More formally: if the current score of the player is x and the chosen element is y, his new score will be x ⊕ y. Here ⊕ denotes [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
Note that after a move element y is removed from a.
* The game ends when the array is empty.
At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.
If both players play optimally find out whether Koa will win, lose or draw the game.
Input
Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows.
The first line of each test case contains the integer n (1 ≤ n ≤ 10^5) — the length of a.
The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — elements of a.
It is guaranteed that the sum of n over all test cases does not exceed 10^5.
Output
For each test case print:
* WIN if Koa will win the game.
* LOSE if Koa will lose the game.
* DRAW if the game ends in a draw.
Examples
Input
3
3
1 2 2
3
2 2 3
5
0 0 0 2 2
Output
WIN
LOSE
DRAW
Input
4
5
4 1 5 1 3
4
1 0 1 6
1
0
2
5 4
Output
WIN
WIN
DRAW
WIN
Note
In testcase 1 of the first sample we have:
a = [1, 2, 2]. Here Koa chooses 1, other player has to choose 2, Koa chooses another 2. Score for Koa is 1 ⊕ 2 = 3 and score for other player is 2 so Koa wins.
Tags: bitmasks, constructive algorithms, dp, games, greedy, math
Correct Solution:
```
import sys
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
ones = [0]*40
for i in range(40):
for ai in a:
ones[i] += (ai>>i)&1
for i in range(39, -1, -1):
if ones[i]%2==0:
continue
else:
if ones[i]%4==3 and (n-ones[i])%2==0:
print('LOSE')
else:
print('WIN')
break
else:
print('DRAW')
```
| 6,767 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Koa the Koala and her best friend want to play a game.
The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts.
Let's describe a move in the game:
* During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player.
More formally: if the current score of the player is x and the chosen element is y, his new score will be x ⊕ y. Here ⊕ denotes [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
Note that after a move element y is removed from a.
* The game ends when the array is empty.
At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.
If both players play optimally find out whether Koa will win, lose or draw the game.
Input
Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows.
The first line of each test case contains the integer n (1 ≤ n ≤ 10^5) — the length of a.
The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — elements of a.
It is guaranteed that the sum of n over all test cases does not exceed 10^5.
Output
For each test case print:
* WIN if Koa will win the game.
* LOSE if Koa will lose the game.
* DRAW if the game ends in a draw.
Examples
Input
3
3
1 2 2
3
2 2 3
5
0 0 0 2 2
Output
WIN
LOSE
DRAW
Input
4
5
4 1 5 1 3
4
1 0 1 6
1
0
2
5 4
Output
WIN
WIN
DRAW
WIN
Note
In testcase 1 of the first sample we have:
a = [1, 2, 2]. Here Koa chooses 1, other player has to choose 2, Koa chooses another 2. Score for Koa is 1 ⊕ 2 = 3 and score for other player is 2 so Koa wins.
Tags: bitmasks, constructive algorithms, dp, games, greedy, math
Correct Solution:
```
for _ in range(int(input())):
n=int(input())
a=[int(o) for o in input().split()]
ones=[0]*35
zeros= [0]*35
for i in a:
ba=bin(i)[2:][::-1]
j=-1
for k in ba:
if k=='1':
ones[j]+=1
else:
zeros[j]+=1
j-=1
res="DRAW"
# print(ones)
for i in range(35):
if ones[i]%2!=0:
if ones[i]%4==3 and (n-ones[i])%2==0:
res="LOSE"
else:
res="WIN"
break
print(res)
```
| 6,768 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Koa the Koala and her best friend want to play a game.
The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts.
Let's describe a move in the game:
* During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player.
More formally: if the current score of the player is x and the chosen element is y, his new score will be x ⊕ y. Here ⊕ denotes [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
Note that after a move element y is removed from a.
* The game ends when the array is empty.
At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.
If both players play optimally find out whether Koa will win, lose or draw the game.
Input
Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows.
The first line of each test case contains the integer n (1 ≤ n ≤ 10^5) — the length of a.
The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — elements of a.
It is guaranteed that the sum of n over all test cases does not exceed 10^5.
Output
For each test case print:
* WIN if Koa will win the game.
* LOSE if Koa will lose the game.
* DRAW if the game ends in a draw.
Examples
Input
3
3
1 2 2
3
2 2 3
5
0 0 0 2 2
Output
WIN
LOSE
DRAW
Input
4
5
4 1 5 1 3
4
1 0 1 6
1
0
2
5 4
Output
WIN
WIN
DRAW
WIN
Note
In testcase 1 of the first sample we have:
a = [1, 2, 2]. Here Koa chooses 1, other player has to choose 2, Koa chooses another 2. Score for Koa is 1 ⊕ 2 = 3 and score for other player is 2 so Koa wins.
Tags: bitmasks, constructive algorithms, dp, games, greedy, math
Correct Solution:
```
def solve():
n = int(input())
lst = list(map(int,input().split()))
k = 1
while k < 10**9:
k *= 2
num = 0
while k and num % 2 == 0:
num = 0
for i in lst:
if i % (k * 2) // k == 1:
num += 1
k //= 2
if k == 0 and num % 2 == 0:
print("DRAW")
return 0
if (num % 4 == 1) or (n % 2 == 0):
print("WIN")
else:
print("LOSE")
for i in range(int(input())):
solve()
```
| 6,769 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Koa the Koala and her best friend want to play a game.
The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts.
Let's describe a move in the game:
* During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player.
More formally: if the current score of the player is x and the chosen element is y, his new score will be x ⊕ y. Here ⊕ denotes [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
Note that after a move element y is removed from a.
* The game ends when the array is empty.
At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.
If both players play optimally find out whether Koa will win, lose or draw the game.
Input
Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows.
The first line of each test case contains the integer n (1 ≤ n ≤ 10^5) — the length of a.
The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — elements of a.
It is guaranteed that the sum of n over all test cases does not exceed 10^5.
Output
For each test case print:
* WIN if Koa will win the game.
* LOSE if Koa will lose the game.
* DRAW if the game ends in a draw.
Examples
Input
3
3
1 2 2
3
2 2 3
5
0 0 0 2 2
Output
WIN
LOSE
DRAW
Input
4
5
4 1 5 1 3
4
1 0 1 6
1
0
2
5 4
Output
WIN
WIN
DRAW
WIN
Note
In testcase 1 of the first sample we have:
a = [1, 2, 2]. Here Koa chooses 1, other player has to choose 2, Koa chooses another 2. Score for Koa is 1 ⊕ 2 = 3 and score for other player is 2 so Koa wins.
Submitted Solution:
```
d = {1:'WIN', 0:'LOSE', -1:'DRAW'}
t=int(input())
for _ in range(t):
n = int(input())
a = [int(x) for x in input().split()]
f = [0] * 30
for x in a:
for b in range(30):
if (x >> b) & 1:
f[b] += 1
ans = -1
for b in reversed(range(30)):
if f[b] % 2 == 1:
ans = 0 if f[b] % 4 == 3 and (n - f[b]) % 2 == 0 else 1
break
print(d[ans])
```
Yes
| 6,770 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Koa the Koala and her best friend want to play a game.
The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts.
Let's describe a move in the game:
* During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player.
More formally: if the current score of the player is x and the chosen element is y, his new score will be x ⊕ y. Here ⊕ denotes [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
Note that after a move element y is removed from a.
* The game ends when the array is empty.
At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.
If both players play optimally find out whether Koa will win, lose or draw the game.
Input
Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows.
The first line of each test case contains the integer n (1 ≤ n ≤ 10^5) — the length of a.
The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — elements of a.
It is guaranteed that the sum of n over all test cases does not exceed 10^5.
Output
For each test case print:
* WIN if Koa will win the game.
* LOSE if Koa will lose the game.
* DRAW if the game ends in a draw.
Examples
Input
3
3
1 2 2
3
2 2 3
5
0 0 0 2 2
Output
WIN
LOSE
DRAW
Input
4
5
4 1 5 1 3
4
1 0 1 6
1
0
2
5 4
Output
WIN
WIN
DRAW
WIN
Note
In testcase 1 of the first sample we have:
a = [1, 2, 2]. Here Koa chooses 1, other player has to choose 2, Koa chooses another 2. Score for Koa is 1 ⊕ 2 = 3 and score for other player is 2 so Koa wins.
Submitted Solution:
```
import sys,os,io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
for _ in range (int(input())):
n = int(input())
a = [int(i) for i in input().split()]
cnt = [0]*35
for i in a:
bi = bin(i)[2:][::-1]
for j in range (len(bi)):
if bi[j]=='1':
cnt[j]+=1
ans = "DRAW"
for i in range (34,-1,-1):
if cnt[i]%4==1 or (cnt[i]%4==3 and not n%2):
ans = "WIN"
break
if cnt[i]%4==3:
ans = "LOSE"
break
print(ans)
```
Yes
| 6,771 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Koa the Koala and her best friend want to play a game.
The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts.
Let's describe a move in the game:
* During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player.
More formally: if the current score of the player is x and the chosen element is y, his new score will be x ⊕ y. Here ⊕ denotes [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
Note that after a move element y is removed from a.
* The game ends when the array is empty.
At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.
If both players play optimally find out whether Koa will win, lose or draw the game.
Input
Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows.
The first line of each test case contains the integer n (1 ≤ n ≤ 10^5) — the length of a.
The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — elements of a.
It is guaranteed that the sum of n over all test cases does not exceed 10^5.
Output
For each test case print:
* WIN if Koa will win the game.
* LOSE if Koa will lose the game.
* DRAW if the game ends in a draw.
Examples
Input
3
3
1 2 2
3
2 2 3
5
0 0 0 2 2
Output
WIN
LOSE
DRAW
Input
4
5
4 1 5 1 3
4
1 0 1 6
1
0
2
5 4
Output
WIN
WIN
DRAW
WIN
Note
In testcase 1 of the first sample we have:
a = [1, 2, 2]. Here Koa chooses 1, other player has to choose 2, Koa chooses another 2. Score for Koa is 1 ⊕ 2 = 3 and score for other player is 2 so Koa wins.
Submitted Solution:
```
from bisect import *
from collections import *
from math import gcd,ceil,sqrt,floor,inf
from heapq import *
from itertools import *
from operator import add,mul,sub,xor,truediv,floordiv
from functools import *
#------------------------------------------------------------------------
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")
#------------------------------------------------------------------------
def RL(): return map(int, sys.stdin.readline().rstrip().split())
def RLL(): return list(map(int, sys.stdin.readline().rstrip().split()))
def N(): return int(input())
#------------------------------------------------------------------------
from types import GeneratorType
def bootstrap(f, stack=[]):
def wrappedfunc(*args, **kwargs):
if stack:
return f(*args, **kwargs)
else:
to = f(*args, **kwargs)
while True:
if type(to) is GeneratorType:
stack.append(to)
to = next(to)
else:
stack.pop()
if not stack:
break
to = stack[-1].send(to)
return to
return wrappedfunc
farr=[1]
ifa=[]
def fact(x,mod=0):
if mod:
while x>=len(farr):
farr.append(farr[-1]*len(farr)%mod)
else:
while x>=len(farr):
farr.append(farr[-1]*len(farr))
return farr[x]
def ifact(x,mod):
global ifa
ifa.append(pow(farr[-1],mod-2,mod))
for i in range(x,0,-1):
ifa.append(ifa[-1]*i%mod)
ifa=ifa[::-1]
def per(i,j,mod=0):
if i<j: return 0
if not mod:
return fact(i)//fact(i-j)
return farr[i]*ifa[i-j]%mod
def com(i,j,mod=0):
if i<j: return 0
if not mod:
return per(i,j)//fact(j)
return per(i,j,mod)*ifa[j]%mod
def catalan(n):
return com(2*n,n)//(n+1)
def linc(f,t,l,r):
while l<r:
mid=(l+r)//2
if t>f(mid):
l=mid+1
else:
r=mid
return l
def rinc(f,t,l,r):
while l<r:
mid=(l+r+1)//2
if t<f(mid):
r=mid-1
else:
l=mid
return l
def ldec(f,t,l,r):
while l<r:
mid=(l+r)//2
if t<f(mid):
l=mid+1
else:
r=mid
return l
def rdec(f,t,l,r):
while l<r:
mid=(l+r+1)//2
if t>f(mid):
r=mid-1
else:
l=mid
return l
def isprime(n):
for i in range(2,int(n**0.5)+1):
if n%i==0:
return False
return True
def binfun(x):
c=0
for w in arr:
c+=ceil(w/x)
return c
def lowbit(n):
return n&-n
def inverse(a,m):
a%=m
if a<=1: return a
return ((1-inverse(m,a)*m)//a)%m
class BIT:
def __init__(self,arr):
self.arr=arr
self.n=len(arr)-1
def update(self,x,v):
while x<=self.n:
self.arr[x]+=v
x+=x&-x
def query(self,x):
ans=0
while x:
ans+=self.arr[x]
x&=x-1
return ans
'''
class SMT:
def __init__(self,arr):
self.n=len(arr)-1
self.arr=[0]*(self.n<<2)
self.lazy=[0]*(self.n<<2)
def Build(l,r,rt):
if l==r:
self.arr[rt]=arr[l]
return
m=(l+r)>>1
Build(l,m,rt<<1)
Build(m+1,r,rt<<1|1)
self.pushup(rt)
Build(1,self.n,1)
def pushup(self,rt):
self.arr[rt]=self.arr[rt<<1]+self.arr[rt<<1|1]
def pushdown(self,rt,ln,rn):#lr,rn表区间数字数
if self.lazy[rt]:
self.lazy[rt<<1]+=self.lazy[rt]
self.lazy[rt<<1|1]=self.lazy[rt]
self.arr[rt<<1]+=self.lazy[rt]*ln
self.arr[rt<<1|1]+=self.lazy[rt]*rn
self.lazy[rt]=0
def update(self,L,R,c,l=1,r=None,rt=1):#L,R表示操作区间
if r==None: r=self.n
if L<=l and r<=R:
self.arr[rt]+=c*(r-l+1)
self.lazy[rt]+=c
return
m=(l+r)>>1
self.pushdown(rt,m-l+1,r-m)
if L<=m: self.update(L,R,c,l,m,rt<<1)
if R>m: self.update(L,R,c,m+1,r,rt<<1|1)
self.pushup(rt)
def query(self,L,R,l=1,r=None,rt=1):
if r==None: r=self.n
#print(L,R,l,r,rt)
if L<=l and R>=r:
return self.arr[rt]
m=(l+r)>>1
self.pushdown(rt,m-l+1,r-m)
ans=0
if L<=m: ans+=self.query(L,R,l,m,rt<<1)
if R>m: ans+=self.query(L,R,m+1,r,rt<<1|1)
return ans
'''
class DSU:#容量+路径压缩
def __init__(self,n):
self.c=[-1]*n
def same(self,x,y):
return self.find(x)==self.find(y)
def find(self,x):
if self.c[x]<0:
return x
self.c[x]=self.find(self.c[x])
return self.c[x]
def union(self,u,v):
u,v=self.find(u),self.find(v)
if u==v:
return False
if self.c[u]<self.c[v]:
u,v=v,u
self.c[u]+=self.c[v]
self.c[v]=u
return True
def size(self,x): return -self.c[self.find(x)]
class UFS:#秩+路径
def __init__(self,n):
self.parent=[i for i in range(n)]
self.ranks=[0]*n
def find(self,x):
if x!=self.parent[x]:
self.parent[x]=self.find(self.parent[x])
return self.parent[x]
def union(self,u,v):
pu,pv=self.find(u),self.find(v)
if pu==pv:
return False
if self.ranks[pu]>=self.ranks[pv]:
self.parent[pv]=pu
if self.ranks[pv]==self.ranks[pu]:
self.ranks[pu]+=1
else:
self.parent[pu]=pv
def Prime(n):
c=0
prime=[]
flag=[0]*(n+1)
for i in range(2,n+1):
if not flag[i]:
prime.append(i)
c+=1
for j in range(c):
if i*prime[j]>n: break
flag[i*prime[j]]=prime[j]
if i%prime[j]==0: break
return prime
def dij(s,graph):
d={}
d[s]=0
heap=[(0,s)]
seen=set()
while heap:
dis,u=heappop(heap)
if u in seen:
continue
for v in graph[u]:
if v not in d or d[v]>d[u]+graph[u][v]:
d[v]=d[u]+graph[u][v]
heappush(heap,(d[v],v))
return d
def GP(it): return [(ch,len(list(g))) for ch,g in groupby(it)]
class DLN:
def __init__(self,val):
self.val=val
self.pre=None
self.next=None
t=N()
for i in range(t):
n=N()
a=RLL()
res=0
for x in a:
res^=x
if res==0:
ans='DRAW'
else:
k=0
while res:
res>>=1
k+=1
k-=1
c=0
for x in a:
if x&(1<<k):
c+=1
c//=2
#print(c)
if c&1:
if n&1:
ans='LOSE'
else:
ans="WIN"
else:
ans="WIN"
print(ans)
'''
sys.setrecursionlimit(200000)
import threading
threading.stack_size(10**8)
t=threading.Thread(target=main)
t.start()
t.join()
'''
```
Yes
| 6,772 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Koa the Koala and her best friend want to play a game.
The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts.
Let's describe a move in the game:
* During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player.
More formally: if the current score of the player is x and the chosen element is y, his new score will be x ⊕ y. Here ⊕ denotes [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
Note that after a move element y is removed from a.
* The game ends when the array is empty.
At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.
If both players play optimally find out whether Koa will win, lose or draw the game.
Input
Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows.
The first line of each test case contains the integer n (1 ≤ n ≤ 10^5) — the length of a.
The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — elements of a.
It is guaranteed that the sum of n over all test cases does not exceed 10^5.
Output
For each test case print:
* WIN if Koa will win the game.
* LOSE if Koa will lose the game.
* DRAW if the game ends in a draw.
Examples
Input
3
3
1 2 2
3
2 2 3
5
0 0 0 2 2
Output
WIN
LOSE
DRAW
Input
4
5
4 1 5 1 3
4
1 0 1 6
1
0
2
5 4
Output
WIN
WIN
DRAW
WIN
Note
In testcase 1 of the first sample we have:
a = [1, 2, 2]. Here Koa chooses 1, other player has to choose 2, Koa chooses another 2. Score for Koa is 1 ⊕ 2 = 3 and score for other player is 2 so Koa wins.
Submitted Solution:
```
d = { 1: 'WIN', 0: 'LOSE', -1: 'DRAW' }
t = int(input())
for _ in range(t):
n = int(input())
a = map(int, input().split())
f = [0] * 30
for x in a:
for b in range(30):
if x >> b & 1:
f[b] += 1
ans = -1
for x in reversed(range(30)):
if f[x] % 2 == 1:
ans = 0 if f[x] % 4 == 3 and (n - f[x]) % 2 == 0 else 1
break
print(d[ans])
```
Yes
| 6,773 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Koa the Koala and her best friend want to play a game.
The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts.
Let's describe a move in the game:
* During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player.
More formally: if the current score of the player is x and the chosen element is y, his new score will be x ⊕ y. Here ⊕ denotes [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
Note that after a move element y is removed from a.
* The game ends when the array is empty.
At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.
If both players play optimally find out whether Koa will win, lose or draw the game.
Input
Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows.
The first line of each test case contains the integer n (1 ≤ n ≤ 10^5) — the length of a.
The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — elements of a.
It is guaranteed that the sum of n over all test cases does not exceed 10^5.
Output
For each test case print:
* WIN if Koa will win the game.
* LOSE if Koa will lose the game.
* DRAW if the game ends in a draw.
Examples
Input
3
3
1 2 2
3
2 2 3
5
0 0 0 2 2
Output
WIN
LOSE
DRAW
Input
4
5
4 1 5 1 3
4
1 0 1 6
1
0
2
5 4
Output
WIN
WIN
DRAW
WIN
Note
In testcase 1 of the first sample we have:
a = [1, 2, 2]. Here Koa chooses 1, other player has to choose 2, Koa chooses another 2. Score for Koa is 1 ⊕ 2 = 3 and score for other player is 2 so Koa wins.
Submitted Solution:
```
def run(n, a):
for i in range(30, -1, -1):
count = 0
for j in range(n):
count += (a[j] >> i) & 1
if count == 1:
return 'WIN'
elif count % 2 == 1 and n % 2 == 1:
return 'LOSE'
elif count % 2 == 0:
return 'WIN'
return 'DRAW'
def main():
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
ans = run(n, a)
print(ans)
if __name__ == '__main__':
main()
```
No
| 6,774 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Koa the Koala and her best friend want to play a game.
The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts.
Let's describe a move in the game:
* During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player.
More formally: if the current score of the player is x and the chosen element is y, his new score will be x ⊕ y. Here ⊕ denotes [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
Note that after a move element y is removed from a.
* The game ends when the array is empty.
At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.
If both players play optimally find out whether Koa will win, lose or draw the game.
Input
Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows.
The first line of each test case contains the integer n (1 ≤ n ≤ 10^5) — the length of a.
The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — elements of a.
It is guaranteed that the sum of n over all test cases does not exceed 10^5.
Output
For each test case print:
* WIN if Koa will win the game.
* LOSE if Koa will lose the game.
* DRAW if the game ends in a draw.
Examples
Input
3
3
1 2 2
3
2 2 3
5
0 0 0 2 2
Output
WIN
LOSE
DRAW
Input
4
5
4 1 5 1 3
4
1 0 1 6
1
0
2
5 4
Output
WIN
WIN
DRAW
WIN
Note
In testcase 1 of the first sample we have:
a = [1, 2, 2]. Here Koa chooses 1, other player has to choose 2, Koa chooses another 2. Score for Koa is 1 ⊕ 2 = 3 and score for other player is 2 so Koa wins.
Submitted Solution:
```
n=int(input())
l=list(map(int,input().split()))
for i in range(30,-1,-1):
cnt=0
for j in l:
if j&(1<<i):
cnt+=1
if cnt%4==1 or (n-cnt)&1:
print("WIN")
quit()
elif cnt%4==3:
print("LOSE")
quit()
print("DRAW")
```
No
| 6,775 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Koa the Koala and her best friend want to play a game.
The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts.
Let's describe a move in the game:
* During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player.
More formally: if the current score of the player is x and the chosen element is y, his new score will be x ⊕ y. Here ⊕ denotes [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
Note that after a move element y is removed from a.
* The game ends when the array is empty.
At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.
If both players play optimally find out whether Koa will win, lose or draw the game.
Input
Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows.
The first line of each test case contains the integer n (1 ≤ n ≤ 10^5) — the length of a.
The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — elements of a.
It is guaranteed that the sum of n over all test cases does not exceed 10^5.
Output
For each test case print:
* WIN if Koa will win the game.
* LOSE if Koa will lose the game.
* DRAW if the game ends in a draw.
Examples
Input
3
3
1 2 2
3
2 2 3
5
0 0 0 2 2
Output
WIN
LOSE
DRAW
Input
4
5
4 1 5 1 3
4
1 0 1 6
1
0
2
5 4
Output
WIN
WIN
DRAW
WIN
Note
In testcase 1 of the first sample we have:
a = [1, 2, 2]. Here Koa chooses 1, other player has to choose 2, Koa chooses another 2. Score for Koa is 1 ⊕ 2 = 3 and score for other player is 2 so Koa wins.
Submitted Solution:
```
for _ in range(int(input())):
n=input()
a=[int(o) for o in input().split()]
ones=[0]*31
zeros= [0]*31
for i in a:
ba=bin(i)[2:][::-1]
j=-1
for k in ba:
if k=='1':
ones[j]+=1
else:
zeros[j]+=1
j-=1
res="DEAW"
for i in range(31):
if ones[i]%2!=0:
if ones[i]%4==3 and zeros[i]%2==0:
res="LOSE"
else:
res="WIN"
break
print(res)
```
No
| 6,776 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Koa the Koala and her best friend want to play a game.
The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts.
Let's describe a move in the game:
* During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player.
More formally: if the current score of the player is x and the chosen element is y, his new score will be x ⊕ y. Here ⊕ denotes [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
Note that after a move element y is removed from a.
* The game ends when the array is empty.
At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw.
If both players play optimally find out whether Koa will win, lose or draw the game.
Input
Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows.
The first line of each test case contains the integer n (1 ≤ n ≤ 10^5) — the length of a.
The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — elements of a.
It is guaranteed that the sum of n over all test cases does not exceed 10^5.
Output
For each test case print:
* WIN if Koa will win the game.
* LOSE if Koa will lose the game.
* DRAW if the game ends in a draw.
Examples
Input
3
3
1 2 2
3
2 2 3
5
0 0 0 2 2
Output
WIN
LOSE
DRAW
Input
4
5
4 1 5 1 3
4
1 0 1 6
1
0
2
5 4
Output
WIN
WIN
DRAW
WIN
Note
In testcase 1 of the first sample we have:
a = [1, 2, 2]. Here Koa chooses 1, other player has to choose 2, Koa chooses another 2. Score for Koa is 1 ⊕ 2 = 3 and score for other player is 2 so Koa wins.
Submitted Solution:
```
def run(n, a):
for i in range(30, -1, -1):
count = 0
for j in range(n):
count += (a[j] >> i) & 1
if count == 1:
return 'WIN'
elif count % 2 == 1 and n % 2 == 1:
return 'LOSE'
elif count % 2 == 1:
return 'WIN'
return 'DRAW'
def main():
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
ans = run(n, a)
print(ans)
if __name__ == '__main__':
main()
```
No
| 6,777 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Given a set of integers (it can contain equal elements).
You have to split it into two subsets A and B (both of them can contain equal elements or be empty). You have to maximize the value of mex(A)+mex(B).
Here mex of a set denotes the smallest non-negative integer that doesn't exist in the set. For example:
* mex(\{1,4,0,2,2,1\})=3
* mex(\{3,3,2,1,3,0,0\})=4
* mex(∅)=0 (mex for empty set)
The set is splitted into two subsets A and B if for any integer number x the number of occurrences of x into this set is equal to the sum of the number of occurrences of x into A and the number of occurrences of x into B.
Input
The input consists of multiple test cases. The first line contains an integer t (1≤ t≤ 100) — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer n (1≤ n≤ 100) — the size of the set.
The second line of each testcase contains n integers a_1,a_2,... a_n (0≤ a_i≤ 100) — the numbers in the set.
Output
For each test case, print the maximum value of mex(A)+mex(B).
Example
Input
4
6
0 2 1 5 0 1
3
0 1 2
4
0 2 0 1
6
1 2 3 4 5 6
Output
5
3
4
0
Note
In the first test case, A=\left\{0,1,2\right\},B=\left\{0,1,5\right\} is a possible choice.
In the second test case, A=\left\{0,1,2\right\},B=∅ is a possible choice.
In the third test case, A=\left\{0,1,2\right\},B=\left\{0\right\} is a possible choice.
In the fourth test case, A=\left\{1,3,5\right\},B=\left\{2,4,6\right\} is a possible choice.
Tags: greedy, implementation, math
Correct Solution:
```
for _ in range(int(input())):
n=int(input())
arr=list(map(int,input().split()))
mex1=0
for i in range(102):
for j in range(n):
if arr[j]==mex1:
mex1+=1
arr[j]=-1
break
mex2=0
for i in range(102):
for j in range(n):
if arr[j]==mex2:
mex2+=1
arr[j]=-1
break
print(str(mex1+mex2))
```
| 6,778 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Given a set of integers (it can contain equal elements).
You have to split it into two subsets A and B (both of them can contain equal elements or be empty). You have to maximize the value of mex(A)+mex(B).
Here mex of a set denotes the smallest non-negative integer that doesn't exist in the set. For example:
* mex(\{1,4,0,2,2,1\})=3
* mex(\{3,3,2,1,3,0,0\})=4
* mex(∅)=0 (mex for empty set)
The set is splitted into two subsets A and B if for any integer number x the number of occurrences of x into this set is equal to the sum of the number of occurrences of x into A and the number of occurrences of x into B.
Input
The input consists of multiple test cases. The first line contains an integer t (1≤ t≤ 100) — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer n (1≤ n≤ 100) — the size of the set.
The second line of each testcase contains n integers a_1,a_2,... a_n (0≤ a_i≤ 100) — the numbers in the set.
Output
For each test case, print the maximum value of mex(A)+mex(B).
Example
Input
4
6
0 2 1 5 0 1
3
0 1 2
4
0 2 0 1
6
1 2 3 4 5 6
Output
5
3
4
0
Note
In the first test case, A=\left\{0,1,2\right\},B=\left\{0,1,5\right\} is a possible choice.
In the second test case, A=\left\{0,1,2\right\},B=∅ is a possible choice.
In the third test case, A=\left\{0,1,2\right\},B=\left\{0\right\} is a possible choice.
In the fourth test case, A=\left\{1,3,5\right\},B=\left\{2,4,6\right\} is a possible choice.
Tags: greedy, implementation, math
Correct Solution:
```
for i in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
a.sort()
if a.count(0) ==0:
print(0)
elif a.count(0) ==1:
for i in range(len(a)+2):
if i not in a:
print(i)
break
else:
for i in range(1,len(a)+2):
if a.count(i) <2:
if a.count(i) ==1:
b =i
while b+1 in a:
b+=1
print(b+i+1)
break
elif a.count(i) ==0:
print(int(2*i))
break
elif 1>0:
print(i+i+1)
break
```
| 6,779 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Given a set of integers (it can contain equal elements).
You have to split it into two subsets A and B (both of them can contain equal elements or be empty). You have to maximize the value of mex(A)+mex(B).
Here mex of a set denotes the smallest non-negative integer that doesn't exist in the set. For example:
* mex(\{1,4,0,2,2,1\})=3
* mex(\{3,3,2,1,3,0,0\})=4
* mex(∅)=0 (mex for empty set)
The set is splitted into two subsets A and B if for any integer number x the number of occurrences of x into this set is equal to the sum of the number of occurrences of x into A and the number of occurrences of x into B.
Input
The input consists of multiple test cases. The first line contains an integer t (1≤ t≤ 100) — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer n (1≤ n≤ 100) — the size of the set.
The second line of each testcase contains n integers a_1,a_2,... a_n (0≤ a_i≤ 100) — the numbers in the set.
Output
For each test case, print the maximum value of mex(A)+mex(B).
Example
Input
4
6
0 2 1 5 0 1
3
0 1 2
4
0 2 0 1
6
1 2 3 4 5 6
Output
5
3
4
0
Note
In the first test case, A=\left\{0,1,2\right\},B=\left\{0,1,5\right\} is a possible choice.
In the second test case, A=\left\{0,1,2\right\},B=∅ is a possible choice.
In the third test case, A=\left\{0,1,2\right\},B=\left\{0\right\} is a possible choice.
In the fourth test case, A=\left\{1,3,5\right\},B=\left\{2,4,6\right\} is a possible choice.
Tags: greedy, implementation, math
Correct Solution:
```
# ------------------- 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))
```
| 6,780 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Given a set of integers (it can contain equal elements).
You have to split it into two subsets A and B (both of them can contain equal elements or be empty). You have to maximize the value of mex(A)+mex(B).
Here mex of a set denotes the smallest non-negative integer that doesn't exist in the set. For example:
* mex(\{1,4,0,2,2,1\})=3
* mex(\{3,3,2,1,3,0,0\})=4
* mex(∅)=0 (mex for empty set)
The set is splitted into two subsets A and B if for any integer number x the number of occurrences of x into this set is equal to the sum of the number of occurrences of x into A and the number of occurrences of x into B.
Input
The input consists of multiple test cases. The first line contains an integer t (1≤ t≤ 100) — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer n (1≤ n≤ 100) — the size of the set.
The second line of each testcase contains n integers a_1,a_2,... a_n (0≤ a_i≤ 100) — the numbers in the set.
Output
For each test case, print the maximum value of mex(A)+mex(B).
Example
Input
4
6
0 2 1 5 0 1
3
0 1 2
4
0 2 0 1
6
1 2 3 4 5 6
Output
5
3
4
0
Note
In the first test case, A=\left\{0,1,2\right\},B=\left\{0,1,5\right\} is a possible choice.
In the second test case, A=\left\{0,1,2\right\},B=∅ is a possible choice.
In the third test case, A=\left\{0,1,2\right\},B=\left\{0\right\} is a possible choice.
In the fourth test case, A=\left\{1,3,5\right\},B=\left\{2,4,6\right\} is a possible choice.
Tags: greedy, implementation, math
Correct Solution:
```
# map(int, input().split())
rw = int(input())
for wewq in range(rw):
n = int(input())
a = list(map(int, input().split()))
b = 0
c = 0
for i in range(max(a) + 1):
f = a.count(i)
if f == 0:
break
elif f == 1:
b += 1
elif f >= 2 and b == c:
b += 1
c += 1
elif f >= 2 and b != c:
b += 1
print(b + c)
```
| 6,781 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Given a set of integers (it can contain equal elements).
You have to split it into two subsets A and B (both of them can contain equal elements or be empty). You have to maximize the value of mex(A)+mex(B).
Here mex of a set denotes the smallest non-negative integer that doesn't exist in the set. For example:
* mex(\{1,4,0,2,2,1\})=3
* mex(\{3,3,2,1,3,0,0\})=4
* mex(∅)=0 (mex for empty set)
The set is splitted into two subsets A and B if for any integer number x the number of occurrences of x into this set is equal to the sum of the number of occurrences of x into A and the number of occurrences of x into B.
Input
The input consists of multiple test cases. The first line contains an integer t (1≤ t≤ 100) — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer n (1≤ n≤ 100) — the size of the set.
The second line of each testcase contains n integers a_1,a_2,... a_n (0≤ a_i≤ 100) — the numbers in the set.
Output
For each test case, print the maximum value of mex(A)+mex(B).
Example
Input
4
6
0 2 1 5 0 1
3
0 1 2
4
0 2 0 1
6
1 2 3 4 5 6
Output
5
3
4
0
Note
In the first test case, A=\left\{0,1,2\right\},B=\left\{0,1,5\right\} is a possible choice.
In the second test case, A=\left\{0,1,2\right\},B=∅ is a possible choice.
In the third test case, A=\left\{0,1,2\right\},B=\left\{0\right\} is a possible choice.
In the fourth test case, A=\left\{1,3,5\right\},B=\left\{2,4,6\right\} is a possible choice.
Tags: greedy, implementation, math
Correct Solution:
```
def mex(arr):
if len(arr) == 0: return 0
arr.sort()
if arr[0] > 0: return 0
for i in range(len(arr) - 1):
if arr[i+1] - arr[i] > 1: return arr[i] + 1
return arr[-1] + 1
if __name__ == '__main__':
num_test_cases = int(input())
for i in range(num_test_cases):
size = int(input())
occ = {}
my_set = []
tmp = input().strip().split(" ")
for n in tmp:
m = int(n)
my_set.append(m)
occ[m] = occ.get(m, 0) + 1
keys_sorted = sorted(occ)
my_set = []
for key in keys_sorted:
if occ[key] >= 2:
my_set += [key, key]
else:
my_set += [key]
if my_set[0] != 0:
print(0)
continue
if len(my_set) > 1 and my_set[1] == 0:
# my_set contains two zeros at least
i = 1
end = len(keys_sorted)
while True and i < end:
if keys_sorted[i] != i or occ[keys_sorted[i]] < 2:
break
i += 1
if i == end:
result = (keys_sorted[i-1]+1) * 2
else:
if occ[keys_sorted[i]] >= 2:
result = i * 2
elif keys_sorted[i] == i:
i += 1
result = i
while True and i < end:
if keys_sorted[i] != i:
break
i += 1
result += keys_sorted[i-1]
else:
result = i * 2
print(result)
else: print(mex(my_set))
```
| 6,782 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Given a set of integers (it can contain equal elements).
You have to split it into two subsets A and B (both of them can contain equal elements or be empty). You have to maximize the value of mex(A)+mex(B).
Here mex of a set denotes the smallest non-negative integer that doesn't exist in the set. For example:
* mex(\{1,4,0,2,2,1\})=3
* mex(\{3,3,2,1,3,0,0\})=4
* mex(∅)=0 (mex for empty set)
The set is splitted into two subsets A and B if for any integer number x the number of occurrences of x into this set is equal to the sum of the number of occurrences of x into A and the number of occurrences of x into B.
Input
The input consists of multiple test cases. The first line contains an integer t (1≤ t≤ 100) — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer n (1≤ n≤ 100) — the size of the set.
The second line of each testcase contains n integers a_1,a_2,... a_n (0≤ a_i≤ 100) — the numbers in the set.
Output
For each test case, print the maximum value of mex(A)+mex(B).
Example
Input
4
6
0 2 1 5 0 1
3
0 1 2
4
0 2 0 1
6
1 2 3 4 5 6
Output
5
3
4
0
Note
In the first test case, A=\left\{0,1,2\right\},B=\left\{0,1,5\right\} is a possible choice.
In the second test case, A=\left\{0,1,2\right\},B=∅ is a possible choice.
In the third test case, A=\left\{0,1,2\right\},B=\left\{0\right\} is a possible choice.
In the fourth test case, A=\left\{1,3,5\right\},B=\left\{2,4,6\right\} is a possible choice.
Tags: greedy, implementation, math
Correct Solution:
```
import os
from io import BytesIO, IOBase
import sys
def main():
from collections import Counter
for t in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
b = Counter(a)
c = []
d = []
for i in range(max(a) + 1):
if b[i] >= 2:
c.append(i)
d.append(i)
else:
if b[i] == 1:
c.append(i)
ans = 0
flag = 0
for i in range(len(c)):
if i != c[i]:
ans += i
flag = 1
break
if flag == 0:
ans = c[-1] + 1
flag = 0
for i in range(len(d)):
if i != d[i]:
ans += i
flag = 1
break
if flag == 0:
if d != []:
ans += d[-1] + 1
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")
if __name__ == "__main__":
main()
```
| 6,783 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Given a set of integers (it can contain equal elements).
You have to split it into two subsets A and B (both of them can contain equal elements or be empty). You have to maximize the value of mex(A)+mex(B).
Here mex of a set denotes the smallest non-negative integer that doesn't exist in the set. For example:
* mex(\{1,4,0,2,2,1\})=3
* mex(\{3,3,2,1,3,0,0\})=4
* mex(∅)=0 (mex for empty set)
The set is splitted into two subsets A and B if for any integer number x the number of occurrences of x into this set is equal to the sum of the number of occurrences of x into A and the number of occurrences of x into B.
Input
The input consists of multiple test cases. The first line contains an integer t (1≤ t≤ 100) — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer n (1≤ n≤ 100) — the size of the set.
The second line of each testcase contains n integers a_1,a_2,... a_n (0≤ a_i≤ 100) — the numbers in the set.
Output
For each test case, print the maximum value of mex(A)+mex(B).
Example
Input
4
6
0 2 1 5 0 1
3
0 1 2
4
0 2 0 1
6
1 2 3 4 5 6
Output
5
3
4
0
Note
In the first test case, A=\left\{0,1,2\right\},B=\left\{0,1,5\right\} is a possible choice.
In the second test case, A=\left\{0,1,2\right\},B=∅ is a possible choice.
In the third test case, A=\left\{0,1,2\right\},B=\left\{0\right\} is a possible choice.
In the fourth test case, A=\left\{1,3,5\right\},B=\left\{2,4,6\right\} is a possible choice.
Tags: greedy, implementation, math
Correct Solution:
```
import sys
import math
from math import *
from collections import Counter,defaultdict,deque
lip = lambda : list(map(int, input().split()))
ip = lambda : int(input())
sip = lambda : input().split()
def main():
n = ip()
arr = lip()
set1 = set()
set2 = set()
d1 = defaultdict(lambda:False)
d2 = defaultdict(lambda:False)
for i in arr:
if i in set1:
set2.add(i)
d2[i] = True
else:
d1[i] = True
set1.add(i)
A = 0
for i in range(len(set1)+2):
if not d1[i]:
A = i
break
B = 0
for i in range(len(set2)+2):
if not d2[i]:
B = i
break
print(A+B)
for i in range(ip()):
main()
```
| 6,784 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Given a set of integers (it can contain equal elements).
You have to split it into two subsets A and B (both of them can contain equal elements or be empty). You have to maximize the value of mex(A)+mex(B).
Here mex of a set denotes the smallest non-negative integer that doesn't exist in the set. For example:
* mex(\{1,4,0,2,2,1\})=3
* mex(\{3,3,2,1,3,0,0\})=4
* mex(∅)=0 (mex for empty set)
The set is splitted into two subsets A and B if for any integer number x the number of occurrences of x into this set is equal to the sum of the number of occurrences of x into A and the number of occurrences of x into B.
Input
The input consists of multiple test cases. The first line contains an integer t (1≤ t≤ 100) — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer n (1≤ n≤ 100) — the size of the set.
The second line of each testcase contains n integers a_1,a_2,... a_n (0≤ a_i≤ 100) — the numbers in the set.
Output
For each test case, print the maximum value of mex(A)+mex(B).
Example
Input
4
6
0 2 1 5 0 1
3
0 1 2
4
0 2 0 1
6
1 2 3 4 5 6
Output
5
3
4
0
Note
In the first test case, A=\left\{0,1,2\right\},B=\left\{0,1,5\right\} is a possible choice.
In the second test case, A=\left\{0,1,2\right\},B=∅ is a possible choice.
In the third test case, A=\left\{0,1,2\right\},B=\left\{0\right\} is a possible choice.
In the fourth test case, A=\left\{1,3,5\right\},B=\left\{2,4,6\right\} is a possible choice.
Tags: greedy, implementation, math
Correct Solution:
```
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().rstrip().split())
inl = lambda: list(map(int, input().split()))
out = lambda x, s='\n': print(s.join(map(str, x)))
t = ini()
for _ in range(t):
n = ini()
a = inl()
first = second = -1
for i in range(101):
if a.count(i) > 1:
continue
if a.count(i) == 1 and first == -1:
first = i
continue
if a.count(i) == 0:
first = i if first == -1 else first
second = i
break
print(first+second)
```
| 6,785 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given a set of integers (it can contain equal elements).
You have to split it into two subsets A and B (both of them can contain equal elements or be empty). You have to maximize the value of mex(A)+mex(B).
Here mex of a set denotes the smallest non-negative integer that doesn't exist in the set. For example:
* mex(\{1,4,0,2,2,1\})=3
* mex(\{3,3,2,1,3,0,0\})=4
* mex(∅)=0 (mex for empty set)
The set is splitted into two subsets A and B if for any integer number x the number of occurrences of x into this set is equal to the sum of the number of occurrences of x into A and the number of occurrences of x into B.
Input
The input consists of multiple test cases. The first line contains an integer t (1≤ t≤ 100) — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer n (1≤ n≤ 100) — the size of the set.
The second line of each testcase contains n integers a_1,a_2,... a_n (0≤ a_i≤ 100) — the numbers in the set.
Output
For each test case, print the maximum value of mex(A)+mex(B).
Example
Input
4
6
0 2 1 5 0 1
3
0 1 2
4
0 2 0 1
6
1 2 3 4 5 6
Output
5
3
4
0
Note
In the first test case, A=\left\{0,1,2\right\},B=\left\{0,1,5\right\} is a possible choice.
In the second test case, A=\left\{0,1,2\right\},B=∅ is a possible choice.
In the third test case, A=\left\{0,1,2\right\},B=\left\{0\right\} is a possible choice.
In the fourth test case, A=\left\{1,3,5\right\},B=\left\{2,4,6\right\} is a possible choice.
Submitted Solution:
```
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))
```
Yes
| 6,786 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given a set of integers (it can contain equal elements).
You have to split it into two subsets A and B (both of them can contain equal elements or be empty). You have to maximize the value of mex(A)+mex(B).
Here mex of a set denotes the smallest non-negative integer that doesn't exist in the set. For example:
* mex(\{1,4,0,2,2,1\})=3
* mex(\{3,3,2,1,3,0,0\})=4
* mex(∅)=0 (mex for empty set)
The set is splitted into two subsets A and B if for any integer number x the number of occurrences of x into this set is equal to the sum of the number of occurrences of x into A and the number of occurrences of x into B.
Input
The input consists of multiple test cases. The first line contains an integer t (1≤ t≤ 100) — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer n (1≤ n≤ 100) — the size of the set.
The second line of each testcase contains n integers a_1,a_2,... a_n (0≤ a_i≤ 100) — the numbers in the set.
Output
For each test case, print the maximum value of mex(A)+mex(B).
Example
Input
4
6
0 2 1 5 0 1
3
0 1 2
4
0 2 0 1
6
1 2 3 4 5 6
Output
5
3
4
0
Note
In the first test case, A=\left\{0,1,2\right\},B=\left\{0,1,5\right\} is a possible choice.
In the second test case, A=\left\{0,1,2\right\},B=∅ is a possible choice.
In the third test case, A=\left\{0,1,2\right\},B=\left\{0\right\} is a possible choice.
In the fourth test case, A=\left\{1,3,5\right\},B=\left\{2,4,6\right\} is a possible choice.
Submitted Solution:
```
from sys import stdin
for _ in range(int(stdin.readline())):
n = int(stdin.readline())
a = sorted(map(int, stdin.readline().split()))
mex_a, mex_b = 0, 0
for i in a:
if i == mex_a:
mex_a += 1
elif i == mex_b:
mex_b += 1
print(mex_a + mex_b)
```
Yes
| 6,787 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given a set of integers (it can contain equal elements).
You have to split it into two subsets A and B (both of them can contain equal elements or be empty). You have to maximize the value of mex(A)+mex(B).
Here mex of a set denotes the smallest non-negative integer that doesn't exist in the set. For example:
* mex(\{1,4,0,2,2,1\})=3
* mex(\{3,3,2,1,3,0,0\})=4
* mex(∅)=0 (mex for empty set)
The set is splitted into two subsets A and B if for any integer number x the number of occurrences of x into this set is equal to the sum of the number of occurrences of x into A and the number of occurrences of x into B.
Input
The input consists of multiple test cases. The first line contains an integer t (1≤ t≤ 100) — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer n (1≤ n≤ 100) — the size of the set.
The second line of each testcase contains n integers a_1,a_2,... a_n (0≤ a_i≤ 100) — the numbers in the set.
Output
For each test case, print the maximum value of mex(A)+mex(B).
Example
Input
4
6
0 2 1 5 0 1
3
0 1 2
4
0 2 0 1
6
1 2 3 4 5 6
Output
5
3
4
0
Note
In the first test case, A=\left\{0,1,2\right\},B=\left\{0,1,5\right\} is a possible choice.
In the second test case, A=\left\{0,1,2\right\},B=∅ is a possible choice.
In the third test case, A=\left\{0,1,2\right\},B=\left\{0\right\} is a possible choice.
In the fourth test case, A=\left\{1,3,5\right\},B=\left\{2,4,6\right\} is a possible choice.
Submitted Solution:
```
t=int(input())
for _ in range(t):
n=int(input())
l=list(map(int,input().split()))
s=list(set(l))
f=0
res=0
for i in range(0,101):
cnt=l.count(i)
if cnt==0 and f==0:
res=2*i
break
elif cnt<=1:
if f==0:
res+=i
f=1
elif f==1 and cnt==0:
res+=i
break
print(res)
```
Yes
| 6,788 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given a set of integers (it can contain equal elements).
You have to split it into two subsets A and B (both of them can contain equal elements or be empty). You have to maximize the value of mex(A)+mex(B).
Here mex of a set denotes the smallest non-negative integer that doesn't exist in the set. For example:
* mex(\{1,4,0,2,2,1\})=3
* mex(\{3,3,2,1,3,0,0\})=4
* mex(∅)=0 (mex for empty set)
The set is splitted into two subsets A and B if for any integer number x the number of occurrences of x into this set is equal to the sum of the number of occurrences of x into A and the number of occurrences of x into B.
Input
The input consists of multiple test cases. The first line contains an integer t (1≤ t≤ 100) — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer n (1≤ n≤ 100) — the size of the set.
The second line of each testcase contains n integers a_1,a_2,... a_n (0≤ a_i≤ 100) — the numbers in the set.
Output
For each test case, print the maximum value of mex(A)+mex(B).
Example
Input
4
6
0 2 1 5 0 1
3
0 1 2
4
0 2 0 1
6
1 2 3 4 5 6
Output
5
3
4
0
Note
In the first test case, A=\left\{0,1,2\right\},B=\left\{0,1,5\right\} is a possible choice.
In the second test case, A=\left\{0,1,2\right\},B=∅ is a possible choice.
In the third test case, A=\left\{0,1,2\right\},B=\left\{0\right\} is a possible choice.
In the fourth test case, A=\left\{1,3,5\right\},B=\left\{2,4,6\right\} is a possible choice.
Submitted Solution:
```
from collections import Counter
for _ in range(int(input())):
n=int(input())
arr = list(map(int, input().split()))
arr=sorted(arr)
c=Counter(arr)
ls=[]
a=[]
for i in c:
if c[i]==1:
ls.append(i)
else:
ls.append(i)
a.append(i)
ans=0
f=0
f1=0
for i in range(101):
if f==0 and i not in ls:
ans+=i
f=1
if f1==0 and i not in a:
ans+=i
f1=1
if f==1 and f1==1:
break
print(ans)
```
Yes
| 6,789 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given a set of integers (it can contain equal elements).
You have to split it into two subsets A and B (both of them can contain equal elements or be empty). You have to maximize the value of mex(A)+mex(B).
Here mex of a set denotes the smallest non-negative integer that doesn't exist in the set. For example:
* mex(\{1,4,0,2,2,1\})=3
* mex(\{3,3,2,1,3,0,0\})=4
* mex(∅)=0 (mex for empty set)
The set is splitted into two subsets A and B if for any integer number x the number of occurrences of x into this set is equal to the sum of the number of occurrences of x into A and the number of occurrences of x into B.
Input
The input consists of multiple test cases. The first line contains an integer t (1≤ t≤ 100) — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer n (1≤ n≤ 100) — the size of the set.
The second line of each testcase contains n integers a_1,a_2,... a_n (0≤ a_i≤ 100) — the numbers in the set.
Output
For each test case, print the maximum value of mex(A)+mex(B).
Example
Input
4
6
0 2 1 5 0 1
3
0 1 2
4
0 2 0 1
6
1 2 3 4 5 6
Output
5
3
4
0
Note
In the first test case, A=\left\{0,1,2\right\},B=\left\{0,1,5\right\} is a possible choice.
In the second test case, A=\left\{0,1,2\right\},B=∅ is a possible choice.
In the third test case, A=\left\{0,1,2\right\},B=\left\{0\right\} is a possible choice.
In the fourth test case, A=\left\{1,3,5\right\},B=\left\{2,4,6\right\} is a possible choice.
Submitted Solution:
```
cases=int(input())
for _ in range(cases):
n=int(input())
c=list(map(int,input().split()))
l=sorted(c)
x=[]
y=[]
visx=[]
visy=[]
for i in range(len(l)):
if l[i] not in visx:
x.append(l[i])
visx.append(l[i])
else:
y.append(l[i])
visy.append(l[i])
index=0
flag=0
tot=0
for i in range(len(x)):
if x[i]==index:
index+=1
else:
flag=1
break
tot+=index
index=0
flag=0
for i in range(len(y)):
if y[i]==index:
index+=1
else:
flag=1
break
tot+=index
print(tot)
```
No
| 6,790 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given a set of integers (it can contain equal elements).
You have to split it into two subsets A and B (both of them can contain equal elements or be empty). You have to maximize the value of mex(A)+mex(B).
Here mex of a set denotes the smallest non-negative integer that doesn't exist in the set. For example:
* mex(\{1,4,0,2,2,1\})=3
* mex(\{3,3,2,1,3,0,0\})=4
* mex(∅)=0 (mex for empty set)
The set is splitted into two subsets A and B if for any integer number x the number of occurrences of x into this set is equal to the sum of the number of occurrences of x into A and the number of occurrences of x into B.
Input
The input consists of multiple test cases. The first line contains an integer t (1≤ t≤ 100) — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer n (1≤ n≤ 100) — the size of the set.
The second line of each testcase contains n integers a_1,a_2,... a_n (0≤ a_i≤ 100) — the numbers in the set.
Output
For each test case, print the maximum value of mex(A)+mex(B).
Example
Input
4
6
0 2 1 5 0 1
3
0 1 2
4
0 2 0 1
6
1 2 3 4 5 6
Output
5
3
4
0
Note
In the first test case, A=\left\{0,1,2\right\},B=\left\{0,1,5\right\} is a possible choice.
In the second test case, A=\left\{0,1,2\right\},B=∅ is a possible choice.
In the third test case, A=\left\{0,1,2\right\},B=\left\{0\right\} is a possible choice.
In the fourth test case, A=\left\{1,3,5\right\},B=\left\{2,4,6\right\} is a possible choice.
Submitted Solution:
```
t=int(input())
for _ in range(t):
n=int(input())
l1=list(map(int,input().split()))
l2=list(set(l1))
l3=[]
l2.sort()
x,y=min(l2),max(l2)
ans=0
if x==0:
f,c=0,0
ans=0
for i in range(x,y+1):
if i not in l2:
c=i
f=1
break
if f==0:
ans+=y+1
else:
ans+=c
if len(l1)!=len(l2):
for i in l2:
if l1.count(i)>1:
l3.append(i)
x,y=min(l3),max(l3)
f,c=0,0
for i in range(x,y+1):
if i not in l3:
c=i
f=1
break
if f==0:
ans+=y+1
else:
ans+=c
print(ans)
```
No
| 6,791 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given a set of integers (it can contain equal elements).
You have to split it into two subsets A and B (both of them can contain equal elements or be empty). You have to maximize the value of mex(A)+mex(B).
Here mex of a set denotes the smallest non-negative integer that doesn't exist in the set. For example:
* mex(\{1,4,0,2,2,1\})=3
* mex(\{3,3,2,1,3,0,0\})=4
* mex(∅)=0 (mex for empty set)
The set is splitted into two subsets A and B if for any integer number x the number of occurrences of x into this set is equal to the sum of the number of occurrences of x into A and the number of occurrences of x into B.
Input
The input consists of multiple test cases. The first line contains an integer t (1≤ t≤ 100) — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer n (1≤ n≤ 100) — the size of the set.
The second line of each testcase contains n integers a_1,a_2,... a_n (0≤ a_i≤ 100) — the numbers in the set.
Output
For each test case, print the maximum value of mex(A)+mex(B).
Example
Input
4
6
0 2 1 5 0 1
3
0 1 2
4
0 2 0 1
6
1 2 3 4 5 6
Output
5
3
4
0
Note
In the first test case, A=\left\{0,1,2\right\},B=\left\{0,1,5\right\} is a possible choice.
In the second test case, A=\left\{0,1,2\right\},B=∅ is a possible choice.
In the third test case, A=\left\{0,1,2\right\},B=\left\{0\right\} is a possible choice.
In the fourth test case, A=\left\{1,3,5\right\},B=\left\{2,4,6\right\} is a possible choice.
Submitted Solution:
```
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
l = [0 for i in range(101)]
for i in a:
l[i]+=1
s = 0
mn = l[0]
for i in range(101):
if mn == 0 or l[i]==0:
break
if l[i]>=mn:
s+=mn
elif l[i]<mn:
mn = l[i]
s+=mn
print(s)
```
No
| 6,792 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given a set of integers (it can contain equal elements).
You have to split it into two subsets A and B (both of them can contain equal elements or be empty). You have to maximize the value of mex(A)+mex(B).
Here mex of a set denotes the smallest non-negative integer that doesn't exist in the set. For example:
* mex(\{1,4,0,2,2,1\})=3
* mex(\{3,3,2,1,3,0,0\})=4
* mex(∅)=0 (mex for empty set)
The set is splitted into two subsets A and B if for any integer number x the number of occurrences of x into this set is equal to the sum of the number of occurrences of x into A and the number of occurrences of x into B.
Input
The input consists of multiple test cases. The first line contains an integer t (1≤ t≤ 100) — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer n (1≤ n≤ 100) — the size of the set.
The second line of each testcase contains n integers a_1,a_2,... a_n (0≤ a_i≤ 100) — the numbers in the set.
Output
For each test case, print the maximum value of mex(A)+mex(B).
Example
Input
4
6
0 2 1 5 0 1
3
0 1 2
4
0 2 0 1
6
1 2 3 4 5 6
Output
5
3
4
0
Note
In the first test case, A=\left\{0,1,2\right\},B=\left\{0,1,5\right\} is a possible choice.
In the second test case, A=\left\{0,1,2\right\},B=∅ is a possible choice.
In the third test case, A=\left\{0,1,2\right\},B=\left\{0\right\} is a possible choice.
In the fourth test case, A=\left\{1,3,5\right\},B=\left\{2,4,6\right\} is a possible choice.
Submitted Solution:
```
for t in range(int(input())):
n=int(input())
a=list(sorted(map(int,input().split())))
ans=0
j=0
m=True
d={}
for i in a:
if i not in d:
d[i]=1
else:
d[i]+=1
d=dict(sorted(d.items(),key=lambda x:x[0]))
for i in range(n+1):
if i not in d:
break
elif d[i]==1 and m:
m=False
j=i
print(i+j)
```
No
| 6,793 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You like playing chess tournaments online.
In your last tournament you played n games. For the sake of this problem, each chess game is either won or lost (no draws). When you lose a game you get 0 points. When you win you get 1 or 2 points: if you have won also the previous game you get 2 points, otherwise you get 1 point. If you win the very first game of the tournament you get 1 point (since there is not a "previous game").
The outcomes of the n games are represented by a string s of length n: the i-th character of s is W if you have won the i-th game, while it is L if you have lost the i-th game.
After the tournament, you notice a bug on the website that allows you to change the outcome of at most k of your games (meaning that at most k times you can change some symbol L to W, or W to L). Since your only goal is to improve your chess rating, you decide to cheat and use the bug.
Compute the maximum score you can get by cheating in the optimal way.
Input
Each test contains multiple test cases. The first line contains an integer t (1≤ t ≤ 20,000) — the number of test cases. The description of the test cases follows.
The first line of each testcase contains two integers n, k (1≤ n≤ 100,000, 0≤ k≤ n) – the number of games played and the number of outcomes that you can change.
The second line contains a string s of length n containing only the characters W and L. If you have won the i-th game then s_i= W, if you have lost the i-th game then s_i= L.
It is guaranteed that the sum of n over all testcases does not exceed 200,000.
Output
For each testcase, print a single integer – the maximum score you can get by cheating in the optimal way.
Example
Input
8
5 2
WLWLL
6 5
LLLWWL
7 1
LWLWLWL
15 5
WWWLLLWWWLLLWWW
40 7
LLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL
1 0
L
1 1
L
6 1
WLLWLW
Output
7
11
6
26
46
0
1
6
Note
Explanation of the first testcase. Before changing any outcome, the score is 2. Indeed, you won the first game, so you got 1 point, and you won also the third, so you got another 1 point (and not 2 because you lost the second game).
An optimal way to cheat is to change the outcomes of the second and fourth game. Doing so, you end up winning the first four games (the string of the outcomes becomes WWWWL). Hence, the new score is 7=1+2+2+2: 1 point for the first game and 2 points for the second, third and fourth game.
Explanation of the second testcase. Before changing any outcome, the score is 3. Indeed, you won the fourth game, so you got 1 point, and you won also the fifth game, so you got 2 more points (since you won also the previous game).
An optimal way to cheat is to change the outcomes of the first, second, third and sixth game. Doing so, you end up winning all games (the string of the outcomes becomes WWWWWW). Hence, the new score is 11 = 1+2+2+2+2+2: 1 point for the first game and 2 points for all the other games.
Tags: greedy, implementation, sortings
Correct Solution:
```
for t in range(int(input())):
n,k=map(int,input().split())
s=input()
if k>=n:
print(n*2-1)
continue
l=0
inter=[]
count=0
out=0
for i in s:
if i=='L':
l+=1
count+=1
else:
if count!=0:
inter.append(count)
out+=1
else:
out+=2
count=0
if s[0]=='W':
out-=1
elif inter:
inter.pop(0)
if l<=k:
print(n*2-1)
elif l==n and k!=0:
print(k*2-1)
else:
r=n-l
inter.sort()
for i in inter:
if k>=i:
out+=i*2+1
k-=i
else:
out+=k*2
k=0
break
out+=k*2
print(out)
```
| 6,794 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You like playing chess tournaments online.
In your last tournament you played n games. For the sake of this problem, each chess game is either won or lost (no draws). When you lose a game you get 0 points. When you win you get 1 or 2 points: if you have won also the previous game you get 2 points, otherwise you get 1 point. If you win the very first game of the tournament you get 1 point (since there is not a "previous game").
The outcomes of the n games are represented by a string s of length n: the i-th character of s is W if you have won the i-th game, while it is L if you have lost the i-th game.
After the tournament, you notice a bug on the website that allows you to change the outcome of at most k of your games (meaning that at most k times you can change some symbol L to W, or W to L). Since your only goal is to improve your chess rating, you decide to cheat and use the bug.
Compute the maximum score you can get by cheating in the optimal way.
Input
Each test contains multiple test cases. The first line contains an integer t (1≤ t ≤ 20,000) — the number of test cases. The description of the test cases follows.
The first line of each testcase contains two integers n, k (1≤ n≤ 100,000, 0≤ k≤ n) – the number of games played and the number of outcomes that you can change.
The second line contains a string s of length n containing only the characters W and L. If you have won the i-th game then s_i= W, if you have lost the i-th game then s_i= L.
It is guaranteed that the sum of n over all testcases does not exceed 200,000.
Output
For each testcase, print a single integer – the maximum score you can get by cheating in the optimal way.
Example
Input
8
5 2
WLWLL
6 5
LLLWWL
7 1
LWLWLWL
15 5
WWWLLLWWWLLLWWW
40 7
LLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL
1 0
L
1 1
L
6 1
WLLWLW
Output
7
11
6
26
46
0
1
6
Note
Explanation of the first testcase. Before changing any outcome, the score is 2. Indeed, you won the first game, so you got 1 point, and you won also the third, so you got another 1 point (and not 2 because you lost the second game).
An optimal way to cheat is to change the outcomes of the second and fourth game. Doing so, you end up winning the first four games (the string of the outcomes becomes WWWWL). Hence, the new score is 7=1+2+2+2: 1 point for the first game and 2 points for the second, third and fourth game.
Explanation of the second testcase. Before changing any outcome, the score is 3. Indeed, you won the fourth game, so you got 1 point, and you won also the fifth game, so you got 2 more points (since you won also the previous game).
An optimal way to cheat is to change the outcomes of the first, second, third and sixth game. Doing so, you end up winning all games (the string of the outcomes becomes WWWWWW). Hence, the new score is 11 = 1+2+2+2+2+2: 1 point for the first game and 2 points for all the other games.
Tags: greedy, implementation, sortings
Correct Solution:
```
for _ in " "*int(input()):
n,k=map(int,input().split())
s=list(input())
if "W" not in s:
print(max((min(k,n)*2)-1,0))
elif k >= s.count("L"):
print((n*2)-1)
else:
cnt,sm,ind=list(),s.count("W"),s.index("W")
for i in range(ind+1,n):
if s[i] == "W":
cnt.append(i-ind-1)
ind=i
cnt.sort()
for i in cnt:
if k >= i:
sm+=(2*i)+1
k-=i
else:
break;
if k>0:
sm+=(2*k)
print(sm)
```
| 6,795 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You like playing chess tournaments online.
In your last tournament you played n games. For the sake of this problem, each chess game is either won or lost (no draws). When you lose a game you get 0 points. When you win you get 1 or 2 points: if you have won also the previous game you get 2 points, otherwise you get 1 point. If you win the very first game of the tournament you get 1 point (since there is not a "previous game").
The outcomes of the n games are represented by a string s of length n: the i-th character of s is W if you have won the i-th game, while it is L if you have lost the i-th game.
After the tournament, you notice a bug on the website that allows you to change the outcome of at most k of your games (meaning that at most k times you can change some symbol L to W, or W to L). Since your only goal is to improve your chess rating, you decide to cheat and use the bug.
Compute the maximum score you can get by cheating in the optimal way.
Input
Each test contains multiple test cases. The first line contains an integer t (1≤ t ≤ 20,000) — the number of test cases. The description of the test cases follows.
The first line of each testcase contains two integers n, k (1≤ n≤ 100,000, 0≤ k≤ n) – the number of games played and the number of outcomes that you can change.
The second line contains a string s of length n containing only the characters W and L. If you have won the i-th game then s_i= W, if you have lost the i-th game then s_i= L.
It is guaranteed that the sum of n over all testcases does not exceed 200,000.
Output
For each testcase, print a single integer – the maximum score you can get by cheating in the optimal way.
Example
Input
8
5 2
WLWLL
6 5
LLLWWL
7 1
LWLWLWL
15 5
WWWLLLWWWLLLWWW
40 7
LLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL
1 0
L
1 1
L
6 1
WLLWLW
Output
7
11
6
26
46
0
1
6
Note
Explanation of the first testcase. Before changing any outcome, the score is 2. Indeed, you won the first game, so you got 1 point, and you won also the third, so you got another 1 point (and not 2 because you lost the second game).
An optimal way to cheat is to change the outcomes of the second and fourth game. Doing so, you end up winning the first four games (the string of the outcomes becomes WWWWL). Hence, the new score is 7=1+2+2+2: 1 point for the first game and 2 points for the second, third and fourth game.
Explanation of the second testcase. Before changing any outcome, the score is 3. Indeed, you won the fourth game, so you got 1 point, and you won also the fifth game, so you got 2 more points (since you won also the previous game).
An optimal way to cheat is to change the outcomes of the first, second, third and sixth game. Doing so, you end up winning all games (the string of the outcomes becomes WWWWWW). Hence, the new score is 11 = 1+2+2+2+2+2: 1 point for the first game and 2 points for all the other games.
Tags: greedy, implementation, sortings
Correct Solution:
```
for _ in range(int(input())):
n, k = map(int, input().split())
x = 1
X = []
ans = 0
y = 0
for s in input():
if s == 'W':
y = 1
if x:
X += [x]
ans += 1
x = 0
else:
ans += 2
else:
x += 1
if y == 0:
print(max(min(k, n) * 2 - 1, 0))
continue
if x:
X += [x + 10 ** 8]
X[0] += 99999999
X.sort()
X.reverse()
while k > 0 and X:
x = X.pop()
if x >= 10 ** 7:
x -= 10 ** 8
ans += 2 * min(x, k)
k -= min(x, k)
elif x > k:
ans += 2 * k
break
else:
ans += 2 * x + 1
k -= x
print(ans)
```
| 6,796 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You like playing chess tournaments online.
In your last tournament you played n games. For the sake of this problem, each chess game is either won or lost (no draws). When you lose a game you get 0 points. When you win you get 1 or 2 points: if you have won also the previous game you get 2 points, otherwise you get 1 point. If you win the very first game of the tournament you get 1 point (since there is not a "previous game").
The outcomes of the n games are represented by a string s of length n: the i-th character of s is W if you have won the i-th game, while it is L if you have lost the i-th game.
After the tournament, you notice a bug on the website that allows you to change the outcome of at most k of your games (meaning that at most k times you can change some symbol L to W, or W to L). Since your only goal is to improve your chess rating, you decide to cheat and use the bug.
Compute the maximum score you can get by cheating in the optimal way.
Input
Each test contains multiple test cases. The first line contains an integer t (1≤ t ≤ 20,000) — the number of test cases. The description of the test cases follows.
The first line of each testcase contains two integers n, k (1≤ n≤ 100,000, 0≤ k≤ n) – the number of games played and the number of outcomes that you can change.
The second line contains a string s of length n containing only the characters W and L. If you have won the i-th game then s_i= W, if you have lost the i-th game then s_i= L.
It is guaranteed that the sum of n over all testcases does not exceed 200,000.
Output
For each testcase, print a single integer – the maximum score you can get by cheating in the optimal way.
Example
Input
8
5 2
WLWLL
6 5
LLLWWL
7 1
LWLWLWL
15 5
WWWLLLWWWLLLWWW
40 7
LLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL
1 0
L
1 1
L
6 1
WLLWLW
Output
7
11
6
26
46
0
1
6
Note
Explanation of the first testcase. Before changing any outcome, the score is 2. Indeed, you won the first game, so you got 1 point, and you won also the third, so you got another 1 point (and not 2 because you lost the second game).
An optimal way to cheat is to change the outcomes of the second and fourth game. Doing so, you end up winning the first four games (the string of the outcomes becomes WWWWL). Hence, the new score is 7=1+2+2+2: 1 point for the first game and 2 points for the second, third and fourth game.
Explanation of the second testcase. Before changing any outcome, the score is 3. Indeed, you won the fourth game, so you got 1 point, and you won also the fifth game, so you got 2 more points (since you won also the previous game).
An optimal way to cheat is to change the outcomes of the first, second, third and sixth game. Doing so, you end up winning all games (the string of the outcomes becomes WWWWWW). Hence, the new score is 11 = 1+2+2+2+2+2: 1 point for the first game and 2 points for all the other games.
Tags: greedy, implementation, sortings
Correct Solution:
```
nums = int(input().strip())
for _ in range(nums):
n,k = map(int,input().strip().split())
s = input().strip()
lw,rw = s.find("W"),s.rfind("W")
res = cur_num = 0
if lw==rw:
if lw==-1:
res = 2*k-1
else:
res = 2*k+1
res = min(2*len(s)-1,res)
else:
part = []
for i in range(lw,rw+1):
if s[i]=="W":
if i>lw and s[i-1]=="L":
part.append(cur_num)
cur_num = 0
if i>lw and s[i-1]=="W":
res+=2
else:
res+=1
else:
cur_num+=1
if k>=(sum(part)+lw+len(s)-rw-1):
res = 2*len(s)-1
else:
part.sort()
for i in range(len(part)):
if k>=part[i]:
res+=2*part[i]+1
k-=part[i]
else:
break
res+=2*k
print(max(res,0))
```
| 6,797 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You like playing chess tournaments online.
In your last tournament you played n games. For the sake of this problem, each chess game is either won or lost (no draws). When you lose a game you get 0 points. When you win you get 1 or 2 points: if you have won also the previous game you get 2 points, otherwise you get 1 point. If you win the very first game of the tournament you get 1 point (since there is not a "previous game").
The outcomes of the n games are represented by a string s of length n: the i-th character of s is W if you have won the i-th game, while it is L if you have lost the i-th game.
After the tournament, you notice a bug on the website that allows you to change the outcome of at most k of your games (meaning that at most k times you can change some symbol L to W, or W to L). Since your only goal is to improve your chess rating, you decide to cheat and use the bug.
Compute the maximum score you can get by cheating in the optimal way.
Input
Each test contains multiple test cases. The first line contains an integer t (1≤ t ≤ 20,000) — the number of test cases. The description of the test cases follows.
The first line of each testcase contains two integers n, k (1≤ n≤ 100,000, 0≤ k≤ n) – the number of games played and the number of outcomes that you can change.
The second line contains a string s of length n containing only the characters W and L. If you have won the i-th game then s_i= W, if you have lost the i-th game then s_i= L.
It is guaranteed that the sum of n over all testcases does not exceed 200,000.
Output
For each testcase, print a single integer – the maximum score you can get by cheating in the optimal way.
Example
Input
8
5 2
WLWLL
6 5
LLLWWL
7 1
LWLWLWL
15 5
WWWLLLWWWLLLWWW
40 7
LLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL
1 0
L
1 1
L
6 1
WLLWLW
Output
7
11
6
26
46
0
1
6
Note
Explanation of the first testcase. Before changing any outcome, the score is 2. Indeed, you won the first game, so you got 1 point, and you won also the third, so you got another 1 point (and not 2 because you lost the second game).
An optimal way to cheat is to change the outcomes of the second and fourth game. Doing so, you end up winning the first four games (the string of the outcomes becomes WWWWL). Hence, the new score is 7=1+2+2+2: 1 point for the first game and 2 points for the second, third and fourth game.
Explanation of the second testcase. Before changing any outcome, the score is 3. Indeed, you won the fourth game, so you got 1 point, and you won also the fifth game, so you got 2 more points (since you won also the previous game).
An optimal way to cheat is to change the outcomes of the first, second, third and sixth game. Doing so, you end up winning all games (the string of the outcomes becomes WWWWWW). Hence, the new score is 11 = 1+2+2+2+2+2: 1 point for the first game and 2 points for all the other games.
Tags: greedy, implementation, sortings
Correct Solution:
```
for _ in range(int(input())):
n,k=map(int,input().split())
s=input()
s=list(s)
cw=0
w=[]
idx=-1
cl=0
fw=-1
lw=-1
ans = 0
for i in range(n):
if(s[i]=='W'):
if(i>0 and s[i-1]=='W'):
ans+=2
else:
ans+=1
if(fw==-1):
fw=i
lw=i
cw+=1
if(idx!=-1):
if(i-idx-1):
w.append(i-idx-1)
idx=i
else:
cl+=1
w.sort()
for i in w:
if(k==0):
break
if(i<=k):
k-=i
ans+=2*(i-1)+3
else:
ans+=2*(k)
k -= k
if(k>0):
if(k>=cl):
ans=1+(n-1)*2
else:
if(cw==0):
if(k>=n):
ans = 1 + (n - 1) * 2
k=0
else:
ans=1+(k-1)*2
k=0
else:
for i in range(lw+1,n):
if(k==0):
break
ans+=2
k-=1
if(k>0):
for i in range(fw-1,-1,-1):
if(k==0):
break
ans+=2
k-=1
print(ans)
```
| 6,798 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You like playing chess tournaments online.
In your last tournament you played n games. For the sake of this problem, each chess game is either won or lost (no draws). When you lose a game you get 0 points. When you win you get 1 or 2 points: if you have won also the previous game you get 2 points, otherwise you get 1 point. If you win the very first game of the tournament you get 1 point (since there is not a "previous game").
The outcomes of the n games are represented by a string s of length n: the i-th character of s is W if you have won the i-th game, while it is L if you have lost the i-th game.
After the tournament, you notice a bug on the website that allows you to change the outcome of at most k of your games (meaning that at most k times you can change some symbol L to W, or W to L). Since your only goal is to improve your chess rating, you decide to cheat and use the bug.
Compute the maximum score you can get by cheating in the optimal way.
Input
Each test contains multiple test cases. The first line contains an integer t (1≤ t ≤ 20,000) — the number of test cases. The description of the test cases follows.
The first line of each testcase contains two integers n, k (1≤ n≤ 100,000, 0≤ k≤ n) – the number of games played and the number of outcomes that you can change.
The second line contains a string s of length n containing only the characters W and L. If you have won the i-th game then s_i= W, if you have lost the i-th game then s_i= L.
It is guaranteed that the sum of n over all testcases does not exceed 200,000.
Output
For each testcase, print a single integer – the maximum score you can get by cheating in the optimal way.
Example
Input
8
5 2
WLWLL
6 5
LLLWWL
7 1
LWLWLWL
15 5
WWWLLLWWWLLLWWW
40 7
LLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL
1 0
L
1 1
L
6 1
WLLWLW
Output
7
11
6
26
46
0
1
6
Note
Explanation of the first testcase. Before changing any outcome, the score is 2. Indeed, you won the first game, so you got 1 point, and you won also the third, so you got another 1 point (and not 2 because you lost the second game).
An optimal way to cheat is to change the outcomes of the second and fourth game. Doing so, you end up winning the first four games (the string of the outcomes becomes WWWWL). Hence, the new score is 7=1+2+2+2: 1 point for the first game and 2 points for the second, third and fourth game.
Explanation of the second testcase. Before changing any outcome, the score is 3. Indeed, you won the fourth game, so you got 1 point, and you won also the fifth game, so you got 2 more points (since you won also the previous game).
An optimal way to cheat is to change the outcomes of the first, second, third and sixth game. Doing so, you end up winning all games (the string of the outcomes becomes WWWWWW). Hence, the new score is 11 = 1+2+2+2+2+2: 1 point for the first game and 2 points for all the other games.
Tags: greedy, implementation, sortings
Correct Solution:
```
I=input
for _ in[0]*int(I()):
n,k=map(int,I().split());s=I();c=s.count('W');n=min(n,c+k);a=sorted(map(len,filter(None,s.strip('L').split('W'))))
while a and c+a[0]<=n:c+=a.pop(0)
print((2*n-len(a)or 1)-1)
```
| 6,799 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.