text stringlengths 198 433k | conversation_id int64 0 109k |
|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi.
Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.
Input
The first input line contains two space-separated integers n and m (1 β€ n, m β€ 105) β the number of markers and the number of caps, correspondingly.
Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 β€ xi, yi β€ 1000) β the i-th marker's color and diameter, correspondingly.
Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 β€ aj, bj β€ 1000) β the color and diameter of the j-th cap, correspondingly.
Output
Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.
Examples
Input
3 4
1 2
3 4
2 4
5 4
2 4
1 1
1 2
Output
3 2
Input
2 2
1 2
2 1
3 4
5 1
Output
1 0
Note
In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed β the first and the third markers.
Tags: *special, greedy, sortings
Correct Solution:
```
n,m=map(int,input().split())
p=[list(map(int,input().split())) for i in range(n)]
dic1={}
dic2={}
for i in range(m):
x,y=map(int,input().split())
dic1[(x,y)]=dic1.get((x,y),0)+1
dic2[y]=dic2.get(y,0)+1
c1=0
c2=0
for x in p:
if dic1.get((x[0],x[1])):
c1=c1+1
dic1[(x[0],x[1])]=dic1[(x[0],x[1])]-1
if dic2.get(x[1]):
c2=c2+1
dic2[x[1]]=dic2[x[1]]-1
print(c2,c1)
```
| 99,700 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi.
Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.
Input
The first input line contains two space-separated integers n and m (1 β€ n, m β€ 105) β the number of markers and the number of caps, correspondingly.
Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 β€ xi, yi β€ 1000) β the i-th marker's color and diameter, correspondingly.
Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 β€ aj, bj β€ 1000) β the color and diameter of the j-th cap, correspondingly.
Output
Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.
Examples
Input
3 4
1 2
3 4
2 4
5 4
2 4
1 1
1 2
Output
3 2
Input
2 2
1 2
2 1
3 4
5 1
Output
1 0
Note
In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed β the first and the third markers.
Tags: *special, greedy, sortings
Correct Solution:
```
def main():
from sys import stdin
l = list(map(int, stdin.read().split()))
n, yx = l[0] * 2, [[0] * 1001 for _ in range(1001)]
cnt = yx[0]
u = v = 0
for y, x in zip(l[3:n + 3:2], l[2:n + 2:2]):
cnt[y] += 1
yx[y][x] += 1
ba, l = list(zip(l[n + 3::2], l[n + 2::2])), []
for y, x in ba:
if yx[y][x]:
yx[y][x] -= 1
cnt[y] -= 1
v += 1
else:
l.append(y)
for y in l:
if cnt[y]:
cnt[y] -= 1
u += 1
print(u + v, v)
if __name__ == '__main__':
main()
```
| 99,701 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi.
Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.
Input
The first input line contains two space-separated integers n and m (1 β€ n, m β€ 105) β the number of markers and the number of caps, correspondingly.
Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 β€ xi, yi β€ 1000) β the i-th marker's color and diameter, correspondingly.
Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 β€ aj, bj β€ 1000) β the color and diameter of the j-th cap, correspondingly.
Output
Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.
Examples
Input
3 4
1 2
3 4
2 4
5 4
2 4
1 1
1 2
Output
3 2
Input
2 2
1 2
2 1
3 4
5 1
Output
1 0
Note
In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed β the first and the third markers.
Tags: *special, greedy, sortings
Correct Solution:
```
from collections import Counter
def read_ints():
return tuple(int(x) for x in input().split())
def parse_input(size):
data = [read_ints() for _ in range(size)]
by_diam = Counter(size for diam, size in data)
by_color = Counter(data)
return by_diam, by_color
n, m = read_ints()
pens_by_diam, pens_by_color = parse_input(n)
caps_by_diam, caps_by_color = parse_input(m)
closed = sum((pens_by_diam & caps_by_diam).values())
beautiful = sum((pens_by_color & caps_by_color).values())
print(closed, beautiful)
```
| 99,702 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi.
Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.
Input
The first input line contains two space-separated integers n and m (1 β€ n, m β€ 105) β the number of markers and the number of caps, correspondingly.
Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 β€ xi, yi β€ 1000) β the i-th marker's color and diameter, correspondingly.
Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 β€ aj, bj β€ 1000) β the color and diameter of the j-th cap, correspondingly.
Output
Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.
Examples
Input
3 4
1 2
3 4
2 4
5 4
2 4
1 1
1 2
Output
3 2
Input
2 2
1 2
2 1
3 4
5 1
Output
1 0
Note
In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed β the first and the third markers.
Submitted Solution:
```
__author__ = 'asmn'
n,m=tuple(map(int,input().split()))
cap1=[0]*1001
cap2=[0]*1001
cnt=[[0]*1001 for y in range(1001)]
for k in range(n):
x,y=tuple(map(int,input().split()))
cap1[y]+=1
cnt[x][y]+=1
ans=0
for k in range(m):
x,y=tuple(map(int,input().split()))
cap2[y]+=1
if cnt[x][y] > 0:
cnt[x][y]-=1
ans +=1
print(sum(min(cap1[y],cap2[y]) for y in range(1001)),ans)
```
Yes
| 99,703 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi.
Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.
Input
The first input line contains two space-separated integers n and m (1 β€ n, m β€ 105) β the number of markers and the number of caps, correspondingly.
Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 β€ xi, yi β€ 1000) β the i-th marker's color and diameter, correspondingly.
Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 β€ aj, bj β€ 1000) β the color and diameter of the j-th cap, correspondingly.
Output
Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.
Examples
Input
3 4
1 2
3 4
2 4
5 4
2 4
1 1
1 2
Output
3 2
Input
2 2
1 2
2 1
3 4
5 1
Output
1 0
Note
In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed β the first and the third markers.
Submitted Solution:
```
n,m=map(int,input().split())
inp=[list(map(int,input().split())) for i in range(n)]
dict1={}
dict2={}
count1=0
count2=0
for i in range(m):
a,b=map(int,input().split())
dict1[(a,b)]=dict1.get((a,b),0)+1
dict2[b]=dict2.get(b,0)+1
for i in inp:
if dict2.get(i[1]):
count1=count1+1
dict2[i[1]]=dict2[i[1]]-1
if dict1.get((i[0],i[1])):
count2=count2+1
dict1[(i[0],i[1])]=dict1[(i[0],i[1])]-1
print(count1,count2)
```
Yes
| 99,704 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi.
Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.
Input
The first input line contains two space-separated integers n and m (1 β€ n, m β€ 105) β the number of markers and the number of caps, correspondingly.
Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 β€ xi, yi β€ 1000) β the i-th marker's color and diameter, correspondingly.
Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 β€ aj, bj β€ 1000) β the color and diameter of the j-th cap, correspondingly.
Output
Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.
Examples
Input
3 4
1 2
3 4
2 4
5 4
2 4
1 1
1 2
Output
3 2
Input
2 2
1 2
2 1
3 4
5 1
Output
1 0
Note
In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed β the first and the third markers.
Submitted Solution:
```
n,m = list(map(int,input().split()))
buck1,buck2,cb,c = {},{}, 0, 0
for i in range(n):
k1,k2 = list(map(int,input().split()))
if k2 in buck1: buck1[k2][k1] = buck1[k2].get(k1,0) + 1 # get - The method get() returns a value for the given key
else: buck1[k2] = {k1:1}
for i in range(m):
k1,k2 = list(map(int,input().split()))
if k2 in buck2: buck2[k2][k1] = buck2[k2].get(k1,0) + 1
elif k2 in buck1: buck2[k2] = {k1:1}
for i in buck1.keys() & buck2.keys():
c += min(sum(buck1[i].values()), sum(buck2[i].values()))
cb += sum(min(buck1[i][k], buck2[i][k]) for k in buck1[i].keys() & buck2[i].keys())
print(c,cb)
```
Yes
| 99,705 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi.
Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.
Input
The first input line contains two space-separated integers n and m (1 β€ n, m β€ 105) β the number of markers and the number of caps, correspondingly.
Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 β€ xi, yi β€ 1000) β the i-th marker's color and diameter, correspondingly.
Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 β€ aj, bj β€ 1000) β the color and diameter of the j-th cap, correspondingly.
Output
Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.
Examples
Input
3 4
1 2
3 4
2 4
5 4
2 4
1 1
1 2
Output
3 2
Input
2 2
1 2
2 1
3 4
5 1
Output
1 0
Note
In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed β the first and the third markers.
Submitted Solution:
```
n, m = map(int, input().split())
a = dict()
l = list()
u = 0
v = 0
for i in range(n):
c, d = map(int, input().split())
if a.get(d, -1) == -1:
a[d] = dict()
a[d][c] = 1
elif a[d].get(c, -1) == -1:
a[d][c] = 1
else:
a[d][c] += 1
for i in range(m):
c, d = map(int, input().split())
if a.get(d, -1) != -1:
if a[d].get(c, -1) == -1:
l.append((c, d))
else:
a[d][c] -= 1
u += 1
if a[d][c] == 0:
del a[d][c]
if a[d] == {}:
del a[d]
for c, d in l:
if a.get(d, -1) != -1:
for i in a[d]:
c = i
break
a[d][i] -= 1
v += 1
if a[d][i] == 0:
del a[d][i]
if a[d] == {}:
del a[d]
print(u + v, u)
```
Yes
| 99,706 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi.
Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.
Input
The first input line contains two space-separated integers n and m (1 β€ n, m β€ 105) β the number of markers and the number of caps, correspondingly.
Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 β€ xi, yi β€ 1000) β the i-th marker's color and diameter, correspondingly.
Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 β€ aj, bj β€ 1000) β the color and diameter of the j-th cap, correspondingly.
Output
Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.
Examples
Input
3 4
1 2
3 4
2 4
5 4
2 4
1 1
1 2
Output
3 2
Input
2 2
1 2
2 1
3 4
5 1
Output
1 0
Note
In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed β the first and the third markers.
Submitted Solution:
```
n,m=map(int,input().split())
d,c,p,q={},{},{},{}
for i in range(n):
x,y=map(int,input().split())
if (x,y) in d:
d[(x,y)]=+1
else:
d[(x,y)]=1
if y in p:
p[y]+=1
else:
p[y]=1
u,v=0,0
for j in range(m):
x,y=map(int,input().split())
if (x,y) in d and d[(x,y)]>0:
d[(x,y)]=-1
u,v=u+1,v+1
p[y]=p[y]-1
else:
if y in q:
q[y]=+1
else:
q[y]=1
for i in p:
if i in q:
u=u+min(p[i],q[i])
print(u,v)
```
No
| 99,707 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi.
Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.
Input
The first input line contains two space-separated integers n and m (1 β€ n, m β€ 105) β the number of markers and the number of caps, correspondingly.
Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 β€ xi, yi β€ 1000) β the i-th marker's color and diameter, correspondingly.
Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 β€ aj, bj β€ 1000) β the color and diameter of the j-th cap, correspondingly.
Output
Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.
Examples
Input
3 4
1 2
3 4
2 4
5 4
2 4
1 1
1 2
Output
3 2
Input
2 2
1 2
2 1
3 4
5 1
Output
1 0
Note
In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed β the first and the third markers.
Submitted Solution:
```
n,m=map(int,input().split())
m1={}
m2={}
c1={}
c2={}
for i in range(n):
x,y=(map(int,input().split()))
m1[y]=m1.get(y,0)+1
m2[(x,y)]=m2.get((x,y),0)+1
for i in range(m):
x,y=(map(int,input().split()))
c1[y]=c1.get(y,0)+1
c2[(x,y)]=c2.get((x,y),0)+1
r1=0
r2=0
for i in m1.keys():
if i in c1.keys():
t1=m1[i]
t2=c1[i]
r1=r1+(min(t1,t2))
for i in m2.keys():
if i in c2.keys():
t1=m2[i]
t2=m2[i]
r2=r2+(min(t1,t2))
print(r1,r2)
```
No
| 99,708 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi.
Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.
Input
The first input line contains two space-separated integers n and m (1 β€ n, m β€ 105) β the number of markers and the number of caps, correspondingly.
Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 β€ xi, yi β€ 1000) β the i-th marker's color and diameter, correspondingly.
Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 β€ aj, bj β€ 1000) β the color and diameter of the j-th cap, correspondingly.
Output
Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.
Examples
Input
3 4
1 2
3 4
2 4
5 4
2 4
1 1
1 2
Output
3 2
Input
2 2
1 2
2 1
3 4
5 1
Output
1 0
Note
In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed β the first and the third markers.
Submitted Solution:
```
from operator import itemgetter
line = input().split()
n, m = int(line[0]), int(line[1])
mk,c=[],[]
for i in range(n):
line = input().split()
mk.append((int(line[1]), int(line[0])))
for i in range(m):
line = input().split()
c.append([int(line[1]), int(line[0])])
mk = sorted(mk,key=itemgetter(0,1))
c = sorted(c,key=itemgetter(0,1))
i, j, ic, jc, count, countp = 0, 0, 0, 0, 0, 0
while i < n and j < m:
if mk[i][0] < c[j][0]:
i += 1
elif mk[i][0] > c[j][0]:
j +=1
else:
count += 1
ic, jc = i, j
while ic < n and jc < m:
if mk[ic][1] < c[jc][1]:
ic += 1
elif mk[ic][1] > c[jc][1]:
jc += 1
else:
countp += 1
break
i += 1
j += 1
print(count,countp )
```
No
| 99,709 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi.
Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.
Input
The first input line contains two space-separated integers n and m (1 β€ n, m β€ 105) β the number of markers and the number of caps, correspondingly.
Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 β€ xi, yi β€ 1000) β the i-th marker's color and diameter, correspondingly.
Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 β€ aj, bj β€ 1000) β the color and diameter of the j-th cap, correspondingly.
Output
Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.
Examples
Input
3 4
1 2
3 4
2 4
5 4
2 4
1 1
1 2
Output
3 2
Input
2 2
1 2
2 1
3 4
5 1
Output
1 0
Note
In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed β the first and the third markers.
Submitted Solution:
```
def main():
from sys import stdin
l = list(map(int, stdin.read().split()))
n, b, y, u, v = l[0] * 2, -1, -2, 0, 0
xy = iter(sorted(zip(l[3:n + 3:2], l[2:n + 2:2])))
ab = iter(sorted(zip(l[n + 3::2], l[n + 2::2])))
try:
while True:
while b > y:
y, x = next(xy)
while b < y:
b, a = next(ab)
u += 1
if x == a:
v += 1
y, x = next(xy)
b, a = next(ab)
except StopIteration:
print(u, v)
if __name__ == '__main__':
main()
```
No
| 99,710 |
Provide a correct Python 3 solution for this coding contest problem.
The Smart Beaver from ABBYY loves puzzles. One of his favorite puzzles is the magic square. He has recently had an idea to automate the solution of this puzzle. The Beaver decided to offer this challenge to the ABBYY Cup contestants.
The magic square is a matrix of size n Γ n. The elements of this matrix are integers. The sum of numbers in each row of the matrix is equal to some number s. The sum of numbers in each column of the matrix is also equal to s. In addition, the sum of the elements on the main diagonal is equal to s and the sum of elements on the secondary diagonal is equal to s. Examples of magic squares are given in the following figure:
<image> Magic squares
You are given a set of n2 integers ai. It is required to place these numbers into a square matrix of size n Γ n so that they form a magic square. Note that each number must occur in the matrix exactly the same number of times as it occurs in the original set.
It is guaranteed that a solution exists!
Input
The first input line contains a single integer n. The next line contains n2 integers ai ( - 108 β€ ai β€ 108), separated by single spaces.
The input limitations for getting 20 points are:
* 1 β€ n β€ 3
The input limitations for getting 50 points are:
* 1 β€ n β€ 4
* It is guaranteed that there are no more than 9 distinct numbers among ai.
The input limitations for getting 100 points are:
* 1 β€ n β€ 4
Output
The first line of the output should contain a single integer s. In each of the following n lines print n integers, separated by spaces and describing the resulting magic square. In the resulting magic square the sums in the rows, columns and diagonals must be equal to s. If there are multiple solutions, you are allowed to print any of them.
Examples
Input
3
1 2 3 4 5 6 7 8 9
Output
15
2 7 6
9 5 1
4 3 8
Input
3
1 0 -1 0 2 -1 -2 0 1
Output
0
1 0 -1
-2 0 2
1 0 -1
Input
2
5 5 5 5
Output
10
5 5
5 5
"Correct Solution:
```
import sys, random
def f(b):
global a
a = [[0] * n for o in range(n)]
for i in range(n):
for j in range(n):
a[i][j] = b[i * n + j]
rez = 0
for i in range(n):
ns = 0
for j in range(n):
ns += a[i][j]
rez += abs(su - ns)
for j in range(n):
ns = 0
for i in range(n):
ns += a[i][j]
rez += abs(su - ns)
ns = 0
for i in range(n):
ns += a[i][i]
rez += abs(su - ns)
ns = 0
for i in range(n):
ns += a[i][n - i - 1]
rez += abs(su - ns)
return rez
# sys.stdin = open("input.txt", 'r')
input = sys.stdin.readline
n = int(input())
d = list(map(int, input().split()))
su = sum(d) // n
p = f(d)
while p:
random.shuffle(d)
p = f(d)
for k in range(1000):
i = random.randint(0, n*n-1)
j = random.randint(0, n*n-1)
while i == j:
j = random.randint(0, n*n-1)
if i > j:
i, j = j, i
d[i], d[j] = d[j], d[i]
q = f(d)
if q < p:
p = q
else:
d[i], d[j] = d[j], d[i]
p = f(d)
print(su)
for i in a:
print(*i)
```
| 99,711 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Formula One championship consists of series of races called Grand Prix. After every race drivers receive points according to their final position. Only the top 10 drivers receive points in the following order 25, 18, 15, 12, 10, 8, 6, 4, 2, 1. At the conclusion of the championship the driver with most points is the champion. If there is a tie, champion is the one with most wins (i.e. first places). If a tie still exists, it is chosen the one with most second places, and so on, until there are no more place to use for compare.
Last year another scoring system was proposed but rejected. In it the champion is the one with most wins. If there is tie, champion is the one with most points. If a tie still exists it is proceeded the same way as in the original scoring system, that is comparing number of second, third, forth, and so on, places.
You are given the result of all races during the season and you are to determine the champion according to both scoring systems. It is guaranteed, that both systems will produce unique champion.
Input
The first line contain integer t (1 β€ t β€ 20), where t is the number of races. After that all races are described one by one. Every race description start with an integer n (1 β€ n β€ 50) on a line of itself, where n is the number of clasified drivers in the given race. After that n lines follow with the classification for the race, each containing the name of a driver. The names of drivers are given in order from the first to the last place. The name of the driver consists of lowercase and uppercase English letters and has length at most 50 characters. Comparing of names should be case-sensetive.
Output
Your output should contain exactly two line. On the first line is the name of the champion according to the original rule, and on the second line the name of the champion according to the alternative rule.
Examples
Input
3
3
Hamilton
Vettel
Webber
2
Webber
Vettel
2
Hamilton
Vettel
Output
Vettel
Hamilton
Input
2
7
Prost
Surtees
Nakajima
Schumacher
Button
DeLaRosa
Buemi
8
Alonso
Prost
NinoFarina
JimClark
DeLaRosa
Nakajima
Patrese
Surtees
Output
Prost
Prost
Note
It is not guaranteed that the same drivers participate in all races. For the championship consider every driver that has participated in at least one race. The total number of drivers during the whole season is not more then 50.
Tags: implementation
Correct Solution:
```
import re
import sys
exit=sys.exit
from bisect import bisect_left as bsl,bisect_right as bsr
from collections import Counter,defaultdict as ddict,deque
from functools import lru_cache
cache=lru_cache(None)
from heapq import *
from itertools import *
from math import inf
from pprint import pprint as pp
enum=enumerate
ri=lambda:int(rln())
ris=lambda:list(map(int,rfs()))
rln=sys.stdin.readline
rl=lambda:rln().rstrip('\n')
rfs=lambda:rln().split()
cat=''.join
catn='\n'.join
mod=1000000007
d4=[(0,-1),(1,0),(0,1),(-1,0)]
d8=[(-1,-1),(0,-1),(1,-1),(-1,0),(1,0),(-1,1),(0,1),(1,1)]
########################################################################
pos={}
pts={}
t=ri()
for _ in range(t):
n=ri()
for i in range(n):
s=rl()
if s not in pos:
pos[s]=[0]*50
pts[s]=0
pos[s][i]-=1
if i<10:
pts[s]-=[25, 18, 15, 12, 10, 8, 6, 4, 2, 1][i]
by_pts=sorted(pts,key=lambda x:(pts[x],pos[x]))[0]
by_pos=sorted(pts,key=lambda x:(pos[x][0],pts[x],pos[x]))[0]
print(by_pts)
print(by_pos)
```
| 99,712 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Formula One championship consists of series of races called Grand Prix. After every race drivers receive points according to their final position. Only the top 10 drivers receive points in the following order 25, 18, 15, 12, 10, 8, 6, 4, 2, 1. At the conclusion of the championship the driver with most points is the champion. If there is a tie, champion is the one with most wins (i.e. first places). If a tie still exists, it is chosen the one with most second places, and so on, until there are no more place to use for compare.
Last year another scoring system was proposed but rejected. In it the champion is the one with most wins. If there is tie, champion is the one with most points. If a tie still exists it is proceeded the same way as in the original scoring system, that is comparing number of second, third, forth, and so on, places.
You are given the result of all races during the season and you are to determine the champion according to both scoring systems. It is guaranteed, that both systems will produce unique champion.
Input
The first line contain integer t (1 β€ t β€ 20), where t is the number of races. After that all races are described one by one. Every race description start with an integer n (1 β€ n β€ 50) on a line of itself, where n is the number of clasified drivers in the given race. After that n lines follow with the classification for the race, each containing the name of a driver. The names of drivers are given in order from the first to the last place. The name of the driver consists of lowercase and uppercase English letters and has length at most 50 characters. Comparing of names should be case-sensetive.
Output
Your output should contain exactly two line. On the first line is the name of the champion according to the original rule, and on the second line the name of the champion according to the alternative rule.
Examples
Input
3
3
Hamilton
Vettel
Webber
2
Webber
Vettel
2
Hamilton
Vettel
Output
Vettel
Hamilton
Input
2
7
Prost
Surtees
Nakajima
Schumacher
Button
DeLaRosa
Buemi
8
Alonso
Prost
NinoFarina
JimClark
DeLaRosa
Nakajima
Patrese
Surtees
Output
Prost
Prost
Note
It is not guaranteed that the same drivers participate in all races. For the championship consider every driver that has participated in at least one race. The total number of drivers during the whole season is not more then 50.
Tags: implementation
Correct Solution:
```
import sys
ht = {}
r = [[0 for i in range(50)] for j in range(50)]
t = int(sys.stdin.readline().strip())
for i in range(t):
n = int(sys.stdin.readline().strip())
for j in range(n):
name = sys.stdin.readline().strip()
if name not in ht:
ht[name] = len(ht)
r[ht[name]][j] += 1
d1, d2 = [], []
pt = [25, 18, 15, 12, 10, 8, 6, 4, 2, 1]
for name in ht:
r_ = r[ht[name]]
sc = 0
for i in range(len(pt)):
sc += r_[i] * pt[i]
d1.append((name, [sc] + r_))
d2.append((name, r_[:1] + [sc] + r_[1:]))
d1 = sorted(d1, key=lambda data: data[1], reverse=True)
d2 = sorted(d2, key=lambda data: data[1], reverse=True)
print(d1[0][0])
print(d2[0][0])
```
| 99,713 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Formula One championship consists of series of races called Grand Prix. After every race drivers receive points according to their final position. Only the top 10 drivers receive points in the following order 25, 18, 15, 12, 10, 8, 6, 4, 2, 1. At the conclusion of the championship the driver with most points is the champion. If there is a tie, champion is the one with most wins (i.e. first places). If a tie still exists, it is chosen the one with most second places, and so on, until there are no more place to use for compare.
Last year another scoring system was proposed but rejected. In it the champion is the one with most wins. If there is tie, champion is the one with most points. If a tie still exists it is proceeded the same way as in the original scoring system, that is comparing number of second, third, forth, and so on, places.
You are given the result of all races during the season and you are to determine the champion according to both scoring systems. It is guaranteed, that both systems will produce unique champion.
Input
The first line contain integer t (1 β€ t β€ 20), where t is the number of races. After that all races are described one by one. Every race description start with an integer n (1 β€ n β€ 50) on a line of itself, where n is the number of clasified drivers in the given race. After that n lines follow with the classification for the race, each containing the name of a driver. The names of drivers are given in order from the first to the last place. The name of the driver consists of lowercase and uppercase English letters and has length at most 50 characters. Comparing of names should be case-sensetive.
Output
Your output should contain exactly two line. On the first line is the name of the champion according to the original rule, and on the second line the name of the champion according to the alternative rule.
Examples
Input
3
3
Hamilton
Vettel
Webber
2
Webber
Vettel
2
Hamilton
Vettel
Output
Vettel
Hamilton
Input
2
7
Prost
Surtees
Nakajima
Schumacher
Button
DeLaRosa
Buemi
8
Alonso
Prost
NinoFarina
JimClark
DeLaRosa
Nakajima
Patrese
Surtees
Output
Prost
Prost
Note
It is not guaranteed that the same drivers participate in all races. For the championship consider every driver that has participated in at least one race. The total number of drivers during the whole season is not more then 50.
Tags: implementation
Correct Solution:
```
t, q = {}, [25, 18, 15, 12, 10, 8, 6, 4, 2, 1]
for i in range(int(input())):
for j in range(int(input())):
p = input()
if not p in t: t[p] = [0] * 52
if j < 10: t[p][0] += q[j]
t[p][j + 1] += 1
print(max(t.items(), key = lambda x: x[1])[0])
for p in t: t[p][1], t[p][0] = t[p][0], t[p][1]
print(max(t.items(), key = lambda x: x[1])[0])
```
| 99,714 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Formula One championship consists of series of races called Grand Prix. After every race drivers receive points according to their final position. Only the top 10 drivers receive points in the following order 25, 18, 15, 12, 10, 8, 6, 4, 2, 1. At the conclusion of the championship the driver with most points is the champion. If there is a tie, champion is the one with most wins (i.e. first places). If a tie still exists, it is chosen the one with most second places, and so on, until there are no more place to use for compare.
Last year another scoring system was proposed but rejected. In it the champion is the one with most wins. If there is tie, champion is the one with most points. If a tie still exists it is proceeded the same way as in the original scoring system, that is comparing number of second, third, forth, and so on, places.
You are given the result of all races during the season and you are to determine the champion according to both scoring systems. It is guaranteed, that both systems will produce unique champion.
Input
The first line contain integer t (1 β€ t β€ 20), where t is the number of races. After that all races are described one by one. Every race description start with an integer n (1 β€ n β€ 50) on a line of itself, where n is the number of clasified drivers in the given race. After that n lines follow with the classification for the race, each containing the name of a driver. The names of drivers are given in order from the first to the last place. The name of the driver consists of lowercase and uppercase English letters and has length at most 50 characters. Comparing of names should be case-sensetive.
Output
Your output should contain exactly two line. On the first line is the name of the champion according to the original rule, and on the second line the name of the champion according to the alternative rule.
Examples
Input
3
3
Hamilton
Vettel
Webber
2
Webber
Vettel
2
Hamilton
Vettel
Output
Vettel
Hamilton
Input
2
7
Prost
Surtees
Nakajima
Schumacher
Button
DeLaRosa
Buemi
8
Alonso
Prost
NinoFarina
JimClark
DeLaRosa
Nakajima
Patrese
Surtees
Output
Prost
Prost
Note
It is not guaranteed that the same drivers participate in all races. For the championship consider every driver that has participated in at least one race. The total number of drivers during the whole season is not more then 50.
Tags: implementation
Correct Solution:
```
def solution():
n = int(input())
# number of races
scores = {}
points = [25, 18, 15, 12, 10, 8, 6, 4, 2, 1]
# the scores of drivers
places = {}
# the places of drivers
for i in range(n):
m = int(input())
# number of drivers participating in the race
for j in range(m):
name = input()
if name in scores:
if j < len(points):
scores[name] += points[j]
else:
if j < len(points):
scores[name] = points[j]
else:
scores[name] = 0
# count the scores of each race
if name in places:
places[name][j] += 1
else:
places[name] = [0 for _ in range(50)]
places[name][j] += 1
# count the places of each race
# print(scores)
# print(places)
origin_scores = scores
scores = sorted(list(scores.items()), key=lambda s: s[1], reverse=True)
places = sorted(list(places.items()), key=lambda s: tuple(s[1][i] for i in range(50)), reverse=True)
# print(scores)
# print(places)
scores_index = {}
for i in range(len(scores)):
scores_index[scores[i][0]] = i
places_index = {}
for i in range(len(places)):
places_index[places[i][0]] = i
# find the winner of score system
max_score = scores[0][1]
candidates = []
for i in scores:
if i[1] == max_score:
candidates.append((i[0], places_index[i[0]]))
candidates.sort(key=lambda s: s[1])
winner1 = candidates[0][0]
# find the winner of place system
candidates = [places[0][0]]
for i in range(1, len(places)):
if places[i][1][0] != places[0][1][0]:
break
candidates.append(places[i][0])
for i in range(len(candidates)):
candidates[i] = (candidates[i], scores_index[candidates[i]])
candidates.sort(key=lambda s: s[1])
max_score = origin_scores[candidates[0][0]]
candidates1 = []
for i in range(len(candidates)):
if origin_scores[candidates[i][0]] == max_score:
candidates1.append(candidates[i][0])
for i in range(len(candidates1)):
candidates1[i] = (candidates1[i], places_index[candidates1[i]])
candidates1.sort(key=lambda s: s[1])
winner2 = candidates1[0][0]
print(winner1)
print(winner2)
if __name__ == "__main__":
solution()
```
| 99,715 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Formula One championship consists of series of races called Grand Prix. After every race drivers receive points according to their final position. Only the top 10 drivers receive points in the following order 25, 18, 15, 12, 10, 8, 6, 4, 2, 1. At the conclusion of the championship the driver with most points is the champion. If there is a tie, champion is the one with most wins (i.e. first places). If a tie still exists, it is chosen the one with most second places, and so on, until there are no more place to use for compare.
Last year another scoring system was proposed but rejected. In it the champion is the one with most wins. If there is tie, champion is the one with most points. If a tie still exists it is proceeded the same way as in the original scoring system, that is comparing number of second, third, forth, and so on, places.
You are given the result of all races during the season and you are to determine the champion according to both scoring systems. It is guaranteed, that both systems will produce unique champion.
Input
The first line contain integer t (1 β€ t β€ 20), where t is the number of races. After that all races are described one by one. Every race description start with an integer n (1 β€ n β€ 50) on a line of itself, where n is the number of clasified drivers in the given race. After that n lines follow with the classification for the race, each containing the name of a driver. The names of drivers are given in order from the first to the last place. The name of the driver consists of lowercase and uppercase English letters and has length at most 50 characters. Comparing of names should be case-sensetive.
Output
Your output should contain exactly two line. On the first line is the name of the champion according to the original rule, and on the second line the name of the champion according to the alternative rule.
Examples
Input
3
3
Hamilton
Vettel
Webber
2
Webber
Vettel
2
Hamilton
Vettel
Output
Vettel
Hamilton
Input
2
7
Prost
Surtees
Nakajima
Schumacher
Button
DeLaRosa
Buemi
8
Alonso
Prost
NinoFarina
JimClark
DeLaRosa
Nakajima
Patrese
Surtees
Output
Prost
Prost
Note
It is not guaranteed that the same drivers participate in all races. For the championship consider every driver that has participated in at least one race. The total number of drivers during the whole season is not more then 50.
Tags: implementation
Correct Solution:
```
t, q = {}, [25, 18, 15, 12, 10, 8, 6, 4, 2, 1]
for i in range(int(input())):
for j in range(int(input())):
p = input()
if not p in t: t[p] = [0] * 52
if j < 10: t[p][0] += q[j]
t[p][j + 1] += 1
print(max(t.items(), key = lambda x: x[1])[0])
for p in t: t[p][1], t[p][0] = t[p][0], t[p][1]
print(max(t.items(), key = lambda x: x[1])[0])
# Made By Mostafa_Khaled
```
| 99,716 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Formula One championship consists of series of races called Grand Prix. After every race drivers receive points according to their final position. Only the top 10 drivers receive points in the following order 25, 18, 15, 12, 10, 8, 6, 4, 2, 1. At the conclusion of the championship the driver with most points is the champion. If there is a tie, champion is the one with most wins (i.e. first places). If a tie still exists, it is chosen the one with most second places, and so on, until there are no more place to use for compare.
Last year another scoring system was proposed but rejected. In it the champion is the one with most wins. If there is tie, champion is the one with most points. If a tie still exists it is proceeded the same way as in the original scoring system, that is comparing number of second, third, forth, and so on, places.
You are given the result of all races during the season and you are to determine the champion according to both scoring systems. It is guaranteed, that both systems will produce unique champion.
Input
The first line contain integer t (1 β€ t β€ 20), where t is the number of races. After that all races are described one by one. Every race description start with an integer n (1 β€ n β€ 50) on a line of itself, where n is the number of clasified drivers in the given race. After that n lines follow with the classification for the race, each containing the name of a driver. The names of drivers are given in order from the first to the last place. The name of the driver consists of lowercase and uppercase English letters and has length at most 50 characters. Comparing of names should be case-sensetive.
Output
Your output should contain exactly two line. On the first line is the name of the champion according to the original rule, and on the second line the name of the champion according to the alternative rule.
Examples
Input
3
3
Hamilton
Vettel
Webber
2
Webber
Vettel
2
Hamilton
Vettel
Output
Vettel
Hamilton
Input
2
7
Prost
Surtees
Nakajima
Schumacher
Button
DeLaRosa
Buemi
8
Alonso
Prost
NinoFarina
JimClark
DeLaRosa
Nakajima
Patrese
Surtees
Output
Prost
Prost
Note
It is not guaranteed that the same drivers participate in all races. For the championship consider every driver that has participated in at least one race. The total number of drivers during the whole season is not more then 50.
Tags: implementation
Correct Solution:
```
n = int(input())
lis=[25,18,15,12, 10, 8, 6, 4, 2, 1]+[0]*52
li=dict()
for i in range(n):
for j in range(int(input())):
player = input()
if player not in li:
li[player]=[0]*51+[player]
li[player][0] +=lis[j]
li[player][j+1] +=1
#print(li)
li = sorted(li.values(),reverse=True)
print(li[0][51])
print(sorted(li,key=lambda l:l[1],reverse=True)[0][51])
```
| 99,717 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Formula One championship consists of series of races called Grand Prix. After every race drivers receive points according to their final position. Only the top 10 drivers receive points in the following order 25, 18, 15, 12, 10, 8, 6, 4, 2, 1. At the conclusion of the championship the driver with most points is the champion. If there is a tie, champion is the one with most wins (i.e. first places). If a tie still exists, it is chosen the one with most second places, and so on, until there are no more place to use for compare.
Last year another scoring system was proposed but rejected. In it the champion is the one with most wins. If there is tie, champion is the one with most points. If a tie still exists it is proceeded the same way as in the original scoring system, that is comparing number of second, third, forth, and so on, places.
You are given the result of all races during the season and you are to determine the champion according to both scoring systems. It is guaranteed, that both systems will produce unique champion.
Input
The first line contain integer t (1 β€ t β€ 20), where t is the number of races. After that all races are described one by one. Every race description start with an integer n (1 β€ n β€ 50) on a line of itself, where n is the number of clasified drivers in the given race. After that n lines follow with the classification for the race, each containing the name of a driver. The names of drivers are given in order from the first to the last place. The name of the driver consists of lowercase and uppercase English letters and has length at most 50 characters. Comparing of names should be case-sensetive.
Output
Your output should contain exactly two line. On the first line is the name of the champion according to the original rule, and on the second line the name of the champion according to the alternative rule.
Examples
Input
3
3
Hamilton
Vettel
Webber
2
Webber
Vettel
2
Hamilton
Vettel
Output
Vettel
Hamilton
Input
2
7
Prost
Surtees
Nakajima
Schumacher
Button
DeLaRosa
Buemi
8
Alonso
Prost
NinoFarina
JimClark
DeLaRosa
Nakajima
Patrese
Surtees
Output
Prost
Prost
Note
It is not guaranteed that the same drivers participate in all races. For the championship consider every driver that has participated in at least one race. The total number of drivers during the whole season is not more then 50.
Tags: implementation
Correct Solution:
```
t = int(input())
racer = {}
points = [25, 18, 15, 12, 10, 8, 6, 4, 2, 1]
max_points = 0
for i in range(t):
n = int(input())
for j in range(n):
name = input()
if racer.get(name):
if j < 10:
racer[name][0] += points[j]
racer[name][j + 1] += 1
else:
racer[name] = [0] * 51
if j < 10:
racer[name][0] = points[j]
racer[name][j + 1] += 1
max_points = max(max_points, racer[name][0])
for name in racer.keys():
if racer[name] == max(racer.values()):
print(name)
break
for name in racer.keys():
temp = racer[name][0]
racer[name][0] = racer[name][1]
racer[name][1] = temp
for name in racer.keys():
if racer[name] == max(racer.values()):
print(name)
break
```
| 99,718 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Formula One championship consists of series of races called Grand Prix. After every race drivers receive points according to their final position. Only the top 10 drivers receive points in the following order 25, 18, 15, 12, 10, 8, 6, 4, 2, 1. At the conclusion of the championship the driver with most points is the champion. If there is a tie, champion is the one with most wins (i.e. first places). If a tie still exists, it is chosen the one with most second places, and so on, until there are no more place to use for compare.
Last year another scoring system was proposed but rejected. In it the champion is the one with most wins. If there is tie, champion is the one with most points. If a tie still exists it is proceeded the same way as in the original scoring system, that is comparing number of second, third, forth, and so on, places.
You are given the result of all races during the season and you are to determine the champion according to both scoring systems. It is guaranteed, that both systems will produce unique champion.
Input
The first line contain integer t (1 β€ t β€ 20), where t is the number of races. After that all races are described one by one. Every race description start with an integer n (1 β€ n β€ 50) on a line of itself, where n is the number of clasified drivers in the given race. After that n lines follow with the classification for the race, each containing the name of a driver. The names of drivers are given in order from the first to the last place. The name of the driver consists of lowercase and uppercase English letters and has length at most 50 characters. Comparing of names should be case-sensetive.
Output
Your output should contain exactly two line. On the first line is the name of the champion according to the original rule, and on the second line the name of the champion according to the alternative rule.
Examples
Input
3
3
Hamilton
Vettel
Webber
2
Webber
Vettel
2
Hamilton
Vettel
Output
Vettel
Hamilton
Input
2
7
Prost
Surtees
Nakajima
Schumacher
Button
DeLaRosa
Buemi
8
Alonso
Prost
NinoFarina
JimClark
DeLaRosa
Nakajima
Patrese
Surtees
Output
Prost
Prost
Note
It is not guaranteed that the same drivers participate in all races. For the championship consider every driver that has participated in at least one race. The total number of drivers during the whole season is not more then 50.
Tags: implementation
Correct Solution:
```
N=int(input())
# S={"name":[0,0,0,......],}
soc=[25,18,15,12,10,8,6,4,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
S={}
for i in range(N):
n=int(input())
for y in range(n):
s=input()
if s in S:
S[s][0]+=soc[y]
S[s][y+1]+=1
else:
S[s]=[soc[y],0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
S[s][y+1]+=1
###A
res=[0]
maxx=0
for i in S:
if S[i][0]>maxx:
res=[0]
maxx=S[i][0]
res[0]=i
elif S[i][0]==maxx:
res.append(i)
if len(res)>1:
for i in range(1,50):
M=[0]
maxx=0
for y in res:
t=S[y][i]
if t>maxx:
M=[0]
maxx=t
M[0]=y
elif t==maxx and t!=0:
M.append(y)
if len(M)==1 and maxx!=0:
print(M[0])
break
elif maxx==0:
None
else:
res=M
else:
print(res[0])
###B
res=[0]
maxx=0
for X in S:
t=S[X][1]
if t>maxx:
res=[0]
maxx=t
res[0]=X
elif t==maxx and t!=0:
res.append(X)
if len(res)>1:
res1=[0]
maxx=0
for i in res:
if S[i][0]>maxx:
res1=[0]
maxx=S[i][0]
res1[0]=i
elif S[i][0]==maxx:
res1.append(i)
if len(res1)>1:
for i in range(2,50):
M=[0]
maxx=0
for y in res1:
t=S[y][i]
if t>maxx:
M=[0]
maxx=t
M[0]=y
elif t==maxx and t!=0:
M.append(y)
if len(M)==1 and maxx!=0:
print(M[0])
break
elif maxx==0:
None
else:
res1=M
else:
print(res1[0])
else:
print(res[0])
```
| 99,719 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Formula One championship consists of series of races called Grand Prix. After every race drivers receive points according to their final position. Only the top 10 drivers receive points in the following order 25, 18, 15, 12, 10, 8, 6, 4, 2, 1. At the conclusion of the championship the driver with most points is the champion. If there is a tie, champion is the one with most wins (i.e. first places). If a tie still exists, it is chosen the one with most second places, and so on, until there are no more place to use for compare.
Last year another scoring system was proposed but rejected. In it the champion is the one with most wins. If there is tie, champion is the one with most points. If a tie still exists it is proceeded the same way as in the original scoring system, that is comparing number of second, third, forth, and so on, places.
You are given the result of all races during the season and you are to determine the champion according to both scoring systems. It is guaranteed, that both systems will produce unique champion.
Input
The first line contain integer t (1 β€ t β€ 20), where t is the number of races. After that all races are described one by one. Every race description start with an integer n (1 β€ n β€ 50) on a line of itself, where n is the number of clasified drivers in the given race. After that n lines follow with the classification for the race, each containing the name of a driver. The names of drivers are given in order from the first to the last place. The name of the driver consists of lowercase and uppercase English letters and has length at most 50 characters. Comparing of names should be case-sensetive.
Output
Your output should contain exactly two line. On the first line is the name of the champion according to the original rule, and on the second line the name of the champion according to the alternative rule.
Examples
Input
3
3
Hamilton
Vettel
Webber
2
Webber
Vettel
2
Hamilton
Vettel
Output
Vettel
Hamilton
Input
2
7
Prost
Surtees
Nakajima
Schumacher
Button
DeLaRosa
Buemi
8
Alonso
Prost
NinoFarina
JimClark
DeLaRosa
Nakajima
Patrese
Surtees
Output
Prost
Prost
Note
It is not guaranteed that the same drivers participate in all races. For the championship consider every driver that has participated in at least one race. The total number of drivers during the whole season is not more then 50.
Submitted Solution:
```
points = [25, 18, 15, 12, 10, 8, 6, 4, 2, 1] + [0] * 40
numRaces = int(input())
scores = {}
for race in range(numRaces):
numDrivers = int(input())
for d in range(numDrivers):
driver = input()
if not driver in scores:
scores[driver] = [0] + [0] * 50 + [driver]
scores[driver][0] += points[d]
scores[driver][d + 1] += 1
s = scores.values()
print(sorted(s)[-1][-1])
s = [[x[1], x[0]] + x[2:] for x in s]
print(sorted(s)[-1][-1])
```
Yes
| 99,720 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Formula One championship consists of series of races called Grand Prix. After every race drivers receive points according to their final position. Only the top 10 drivers receive points in the following order 25, 18, 15, 12, 10, 8, 6, 4, 2, 1. At the conclusion of the championship the driver with most points is the champion. If there is a tie, champion is the one with most wins (i.e. first places). If a tie still exists, it is chosen the one with most second places, and so on, until there are no more place to use for compare.
Last year another scoring system was proposed but rejected. In it the champion is the one with most wins. If there is tie, champion is the one with most points. If a tie still exists it is proceeded the same way as in the original scoring system, that is comparing number of second, third, forth, and so on, places.
You are given the result of all races during the season and you are to determine the champion according to both scoring systems. It is guaranteed, that both systems will produce unique champion.
Input
The first line contain integer t (1 β€ t β€ 20), where t is the number of races. After that all races are described one by one. Every race description start with an integer n (1 β€ n β€ 50) on a line of itself, where n is the number of clasified drivers in the given race. After that n lines follow with the classification for the race, each containing the name of a driver. The names of drivers are given in order from the first to the last place. The name of the driver consists of lowercase and uppercase English letters and has length at most 50 characters. Comparing of names should be case-sensetive.
Output
Your output should contain exactly two line. On the first line is the name of the champion according to the original rule, and on the second line the name of the champion according to the alternative rule.
Examples
Input
3
3
Hamilton
Vettel
Webber
2
Webber
Vettel
2
Hamilton
Vettel
Output
Vettel
Hamilton
Input
2
7
Prost
Surtees
Nakajima
Schumacher
Button
DeLaRosa
Buemi
8
Alonso
Prost
NinoFarina
JimClark
DeLaRosa
Nakajima
Patrese
Surtees
Output
Prost
Prost
Note
It is not guaranteed that the same drivers participate in all races. For the championship consider every driver that has participated in at least one race. The total number of drivers during the whole season is not more then 50.
Submitted Solution:
```
import re
import sys
exit=sys.exit
from bisect import bisect_left as bsl,bisect_right as bsr
from collections import Counter,defaultdict as ddict,deque
from functools import lru_cache
cache=lru_cache(None)
from heapq import *
from itertools import *
from math import inf
from pprint import pprint as pp
enum=enumerate
ri=lambda:int(rln())
ris=lambda:list(map(int,rfs()))
rln=sys.stdin.readline
rl=lambda:rln().rstrip('\n')
rfs=lambda:rln().split()
cat=''.join
catn='\n'.join
mod=1000000007
d4=[(0,-1),(1,0),(0,1),(-1,0)]
d8=[(-1,-1),(0,-1),(1,-1),(-1,0),(1,0),(-1,1),(0,1),(1,1)]
########################################################################
pos={}
pts={}
t=ri()
for _ in range(t):
n=ri()
for i in range(n):
s=rl()
if s not in pos:
pos[s]=[0]*50
pts[s]=0
pos[s][i]+=1
if i<10:
pts[s]+=[25, 18, 15, 12, 10, 8, 6, 4, 2, 1][i]
by_pts=max(pts,key=lambda x:(pts[x],pos[x]))
by_pos=max(pts,key=lambda x:(pos[x][0],pts[x],pos[x]))
print(by_pts)
print(by_pos)
```
Yes
| 99,721 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Formula One championship consists of series of races called Grand Prix. After every race drivers receive points according to their final position. Only the top 10 drivers receive points in the following order 25, 18, 15, 12, 10, 8, 6, 4, 2, 1. At the conclusion of the championship the driver with most points is the champion. If there is a tie, champion is the one with most wins (i.e. first places). If a tie still exists, it is chosen the one with most second places, and so on, until there are no more place to use for compare.
Last year another scoring system was proposed but rejected. In it the champion is the one with most wins. If there is tie, champion is the one with most points. If a tie still exists it is proceeded the same way as in the original scoring system, that is comparing number of second, third, forth, and so on, places.
You are given the result of all races during the season and you are to determine the champion according to both scoring systems. It is guaranteed, that both systems will produce unique champion.
Input
The first line contain integer t (1 β€ t β€ 20), where t is the number of races. After that all races are described one by one. Every race description start with an integer n (1 β€ n β€ 50) on a line of itself, where n is the number of clasified drivers in the given race. After that n lines follow with the classification for the race, each containing the name of a driver. The names of drivers are given in order from the first to the last place. The name of the driver consists of lowercase and uppercase English letters and has length at most 50 characters. Comparing of names should be case-sensetive.
Output
Your output should contain exactly two line. On the first line is the name of the champion according to the original rule, and on the second line the name of the champion according to the alternative rule.
Examples
Input
3
3
Hamilton
Vettel
Webber
2
Webber
Vettel
2
Hamilton
Vettel
Output
Vettel
Hamilton
Input
2
7
Prost
Surtees
Nakajima
Schumacher
Button
DeLaRosa
Buemi
8
Alonso
Prost
NinoFarina
JimClark
DeLaRosa
Nakajima
Patrese
Surtees
Output
Prost
Prost
Note
It is not guaranteed that the same drivers participate in all races. For the championship consider every driver that has participated in at least one race. The total number of drivers during the whole season is not more then 50.
Submitted Solution:
```
a=[25, 18, 15, 12, 10, 8, 6, 4, 2, 1]
b={}
n=int(input())
for i in range(n):
k=int(input())
for j in range(k):
s=input()
if not(s in b):
b[s]=[0]*51+[s]
b[s][j+1]+=1
if j<10: b[s][0]+=a[j]
c=b.values()
print(sorted(c)[-1][-1])
d=[]
for z in c:
d.append([z[1]]+z)
print(sorted(d)[-1][-1])
```
Yes
| 99,722 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Formula One championship consists of series of races called Grand Prix. After every race drivers receive points according to their final position. Only the top 10 drivers receive points in the following order 25, 18, 15, 12, 10, 8, 6, 4, 2, 1. At the conclusion of the championship the driver with most points is the champion. If there is a tie, champion is the one with most wins (i.e. first places). If a tie still exists, it is chosen the one with most second places, and so on, until there are no more place to use for compare.
Last year another scoring system was proposed but rejected. In it the champion is the one with most wins. If there is tie, champion is the one with most points. If a tie still exists it is proceeded the same way as in the original scoring system, that is comparing number of second, third, forth, and so on, places.
You are given the result of all races during the season and you are to determine the champion according to both scoring systems. It is guaranteed, that both systems will produce unique champion.
Input
The first line contain integer t (1 β€ t β€ 20), where t is the number of races. After that all races are described one by one. Every race description start with an integer n (1 β€ n β€ 50) on a line of itself, where n is the number of clasified drivers in the given race. After that n lines follow with the classification for the race, each containing the name of a driver. The names of drivers are given in order from the first to the last place. The name of the driver consists of lowercase and uppercase English letters and has length at most 50 characters. Comparing of names should be case-sensetive.
Output
Your output should contain exactly two line. On the first line is the name of the champion according to the original rule, and on the second line the name of the champion according to the alternative rule.
Examples
Input
3
3
Hamilton
Vettel
Webber
2
Webber
Vettel
2
Hamilton
Vettel
Output
Vettel
Hamilton
Input
2
7
Prost
Surtees
Nakajima
Schumacher
Button
DeLaRosa
Buemi
8
Alonso
Prost
NinoFarina
JimClark
DeLaRosa
Nakajima
Patrese
Surtees
Output
Prost
Prost
Note
It is not guaranteed that the same drivers participate in all races. For the championship consider every driver that has participated in at least one race. The total number of drivers during the whole season is not more then 50.
Submitted Solution:
```
t = int(input())
e = [25, 18, 15, 12, 10, 8, 6, 4, 2, 1]
d1 = {}
d2 = {}
for i in range(t):
n = int(input())
for j in range(n):
s = input()
if s in d1.keys() and s in d2.keys():
if j < 10:
d1[s][0] += e[j]
d1[s][j+1] += 1
d2[s][1] += e[j]
if j == 0:
d2[s][0] += 1
else:
d2[s][j+1] += 1
else:
d1[s][j+1] += 1
d2[s][j+1] += 1
else:
if j < 10:
d1[s] = [e[j]]+[0]*50
d1[s][j+1] = 1
d2[s] = [0, e[j]]+[0]*49
if j == 0:
d2[s][0] = 1
else:
d2[s][j+1] = 1
else:
d1[s] = [0]*51
d2[s] = [0]*51
d1[s][j+1] = 1
d2[s][j+1] = 1
win1 = list(sorted(d1.values(), reverse = True))
win2 = list(sorted(d2.values(), reverse = True))
for k in d1.keys():
if d1[k] == win1[0]:
print(k)
break
for k in d2.keys():
if d2[k] == win2[0]:
print(k)
break
```
Yes
| 99,723 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Formula One championship consists of series of races called Grand Prix. After every race drivers receive points according to their final position. Only the top 10 drivers receive points in the following order 25, 18, 15, 12, 10, 8, 6, 4, 2, 1. At the conclusion of the championship the driver with most points is the champion. If there is a tie, champion is the one with most wins (i.e. first places). If a tie still exists, it is chosen the one with most second places, and so on, until there are no more place to use for compare.
Last year another scoring system was proposed but rejected. In it the champion is the one with most wins. If there is tie, champion is the one with most points. If a tie still exists it is proceeded the same way as in the original scoring system, that is comparing number of second, third, forth, and so on, places.
You are given the result of all races during the season and you are to determine the champion according to both scoring systems. It is guaranteed, that both systems will produce unique champion.
Input
The first line contain integer t (1 β€ t β€ 20), where t is the number of races. After that all races are described one by one. Every race description start with an integer n (1 β€ n β€ 50) on a line of itself, where n is the number of clasified drivers in the given race. After that n lines follow with the classification for the race, each containing the name of a driver. The names of drivers are given in order from the first to the last place. The name of the driver consists of lowercase and uppercase English letters and has length at most 50 characters. Comparing of names should be case-sensetive.
Output
Your output should contain exactly two line. On the first line is the name of the champion according to the original rule, and on the second line the name of the champion according to the alternative rule.
Examples
Input
3
3
Hamilton
Vettel
Webber
2
Webber
Vettel
2
Hamilton
Vettel
Output
Vettel
Hamilton
Input
2
7
Prost
Surtees
Nakajima
Schumacher
Button
DeLaRosa
Buemi
8
Alonso
Prost
NinoFarina
JimClark
DeLaRosa
Nakajima
Patrese
Surtees
Output
Prost
Prost
Note
It is not guaranteed that the same drivers participate in all races. For the championship consider every driver that has participated in at least one race. The total number of drivers during the whole season is not more then 50.
Submitted Solution:
```
def checker(name1, l1, name2, l2):
if l1 > l2:
name = name1
elif l2 > l1:
name = name2
for i in range(len(l1)):
if l1[i] > l2[i]:
return name1
elif l1[i] < l2[i]:
return name2
return name
tours = int(input())
drivers = {}
scores = [25,18,15,12,10,8,6,4,2,1]
maxi = 0
for i in range(tours):
drv = int(input())
for j in range(drv):
name = input()
if name in drivers:
if len(drivers[name]) < drv+1:
for y in range((drv+1)- len(drivers[name])):
drivers[name].append(0)
drivers[name][j+1] += 1
if j < 10:
drivers[name][0] += scores[j]
else:
drivers[name] = [0] * (drv+1)
if j < 10:
drivers[name][0] = scores[j]
drivers[name][j+1] += 1
maxi1 = 0
maxi2 = 0
for driver in drivers:
if drivers[driver][0] > maxi1:
maxi1 = drivers[driver][0]
win1 = driver
elif drivers[driver][0] == maxi1:
win1 = checker(win1, drivers[win1][1:], driver, drivers[driver][1:])
if drivers[driver][1] > maxi2:
maxi2 = drivers[driver][0]
win2 = driver
elif drivers[driver][1] == maxi2:
if drivers[driver][0] > drivers[win1][0]:
win2 = driver
else:
win2 = checker(win1, drivers[win1][2:], driver, drivers[driver][2:])
print(win1)
print(win2)
```
No
| 99,724 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Formula One championship consists of series of races called Grand Prix. After every race drivers receive points according to their final position. Only the top 10 drivers receive points in the following order 25, 18, 15, 12, 10, 8, 6, 4, 2, 1. At the conclusion of the championship the driver with most points is the champion. If there is a tie, champion is the one with most wins (i.e. first places). If a tie still exists, it is chosen the one with most second places, and so on, until there are no more place to use for compare.
Last year another scoring system was proposed but rejected. In it the champion is the one with most wins. If there is tie, champion is the one with most points. If a tie still exists it is proceeded the same way as in the original scoring system, that is comparing number of second, third, forth, and so on, places.
You are given the result of all races during the season and you are to determine the champion according to both scoring systems. It is guaranteed, that both systems will produce unique champion.
Input
The first line contain integer t (1 β€ t β€ 20), where t is the number of races. After that all races are described one by one. Every race description start with an integer n (1 β€ n β€ 50) on a line of itself, where n is the number of clasified drivers in the given race. After that n lines follow with the classification for the race, each containing the name of a driver. The names of drivers are given in order from the first to the last place. The name of the driver consists of lowercase and uppercase English letters and has length at most 50 characters. Comparing of names should be case-sensetive.
Output
Your output should contain exactly two line. On the first line is the name of the champion according to the original rule, and on the second line the name of the champion according to the alternative rule.
Examples
Input
3
3
Hamilton
Vettel
Webber
2
Webber
Vettel
2
Hamilton
Vettel
Output
Vettel
Hamilton
Input
2
7
Prost
Surtees
Nakajima
Schumacher
Button
DeLaRosa
Buemi
8
Alonso
Prost
NinoFarina
JimClark
DeLaRosa
Nakajima
Patrese
Surtees
Output
Prost
Prost
Note
It is not guaranteed that the same drivers participate in all races. For the championship consider every driver that has participated in at least one race. The total number of drivers during the whole season is not more then 50.
Submitted Solution:
```
def solution():
n = int(input())
# number of races
scores = {}
points = [25, 18, 15, 12, 10, 8, 6, 4, 2, 1]
# the scores of drivers
places = {}
# the places of drivers
for i in range(n):
m = int(input())
# number of drivers participating in the race
for j in range(m):
name = input()
if name in scores:
if j < len(points):
scores[name] += points[j]
else:
if j < len(points):
scores[name] = points[j]
else:
scores[name] = 0
# count the scores of each race
if name in places:
places[name][j] += 1
else:
places[name] = [0 for _ in range(50)]
places[name][j] += 1
# count the places of each race
# print(scores)
# print(places)
scores = sorted(list(scores.items()), key=lambda s: s[1], reverse=True)
places = sorted(list(places.items()), key=lambda s: tuple(s[1][i] for i in range(50)), reverse=True)
# print(scores)
# print(places)
scores_index = {}
for i in range(len(scores)):
scores_index[scores[i][0]] = i
places_index = {}
for i in range(len(places)):
places_index[places[i][0]] = i
# find the winner of score system
max_score = scores[0][1]
candidates = []
for i in scores:
if i[1] == max_score:
candidates.append((i[0], places_index[i[0]]))
candidates.sort(key=lambda s: s[1])
winner1 = candidates[0][0]
# find the winner of place system
candidates = [places[0][0]]
for i in range(1, len(places)):
for j in range(len(places[i][1])):
if places[i][1][j] != places[0][1][j]:
break
else:
candidates.append(places[i][0])
continue
break
for i in range(len(candidates)):
candidates[i] = (candidates[i], scores_index[candidates[i]])
candidates.sort(key=lambda s: s[1])
winner2 = candidates[0][0]
print(winner1, winner2)
if __name__ == "__main__":
solution()
```
No
| 99,725 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Formula One championship consists of series of races called Grand Prix. After every race drivers receive points according to their final position. Only the top 10 drivers receive points in the following order 25, 18, 15, 12, 10, 8, 6, 4, 2, 1. At the conclusion of the championship the driver with most points is the champion. If there is a tie, champion is the one with most wins (i.e. first places). If a tie still exists, it is chosen the one with most second places, and so on, until there are no more place to use for compare.
Last year another scoring system was proposed but rejected. In it the champion is the one with most wins. If there is tie, champion is the one with most points. If a tie still exists it is proceeded the same way as in the original scoring system, that is comparing number of second, third, forth, and so on, places.
You are given the result of all races during the season and you are to determine the champion according to both scoring systems. It is guaranteed, that both systems will produce unique champion.
Input
The first line contain integer t (1 β€ t β€ 20), where t is the number of races. After that all races are described one by one. Every race description start with an integer n (1 β€ n β€ 50) on a line of itself, where n is the number of clasified drivers in the given race. After that n lines follow with the classification for the race, each containing the name of a driver. The names of drivers are given in order from the first to the last place. The name of the driver consists of lowercase and uppercase English letters and has length at most 50 characters. Comparing of names should be case-sensetive.
Output
Your output should contain exactly two line. On the first line is the name of the champion according to the original rule, and on the second line the name of the champion according to the alternative rule.
Examples
Input
3
3
Hamilton
Vettel
Webber
2
Webber
Vettel
2
Hamilton
Vettel
Output
Vettel
Hamilton
Input
2
7
Prost
Surtees
Nakajima
Schumacher
Button
DeLaRosa
Buemi
8
Alonso
Prost
NinoFarina
JimClark
DeLaRosa
Nakajima
Patrese
Surtees
Output
Prost
Prost
Note
It is not guaranteed that the same drivers participate in all races. For the championship consider every driver that has participated in at least one race. The total number of drivers during the whole season is not more then 50.
Submitted Solution:
```
def arrange(data, maxi):
dic = {}
for el in data:
for driver in el:
if driver not in dic:
dic[driver] = [0] * (maxi+1)
return dic
def get_scores(data, dic):
for el in data:
for i in range(len(el)):
if i < 10:
dic[el[i]][0] += scores[i]
dic[el[i]][i+1] += 1
return dic
def first_winner(dic):
first = 0
for driver in dic:
if dic[driver][0] > first:
first = dic[driver][0]
winner = driver
elif dic[driver][0] == first:
first, winner = check(dic, winner, driver, 1)
return winner
def check(dic, drv1, drv2, o):
for i in range(o,len(dic[drv1])):
if dic[drv1][i] < dic[drv2][i]:
return dic[drv2][1], drv2
if dic[drv1][i] > dic[drv2][i]:
return dic[drv1][1], drv1
def second_winner(dic):
first = 0
for driver in dic:
if dic[driver][1] > first:
first = dic[driver][1]
winner = driver
elif dic[driver][1] == first:
if dic[driver][0] == dic[winner][0]:
first, winner = check(dic, winner, driver, 2)
elif dic[driver][0] > dic[winner][0]:
winner = driver
first = dic[driver][1]
return winner
scores = [25, 18, 15, 12, 10, 8, 6, 4, 2, 1]
data = []
tours = int(input())
maxi = 0
for i in range(tours):
n = int(input())
if n > maxi:
maxi = n
l = []
for j in range(n):
driver = input()
l.append(driver)
data.append(l)
dic = arrange(data, maxi)
dic = get_scores(data, dic)
print(first_winner(dic))
print(second_winner(dic))
```
No
| 99,726 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Formula One championship consists of series of races called Grand Prix. After every race drivers receive points according to their final position. Only the top 10 drivers receive points in the following order 25, 18, 15, 12, 10, 8, 6, 4, 2, 1. At the conclusion of the championship the driver with most points is the champion. If there is a tie, champion is the one with most wins (i.e. first places). If a tie still exists, it is chosen the one with most second places, and so on, until there are no more place to use for compare.
Last year another scoring system was proposed but rejected. In it the champion is the one with most wins. If there is tie, champion is the one with most points. If a tie still exists it is proceeded the same way as in the original scoring system, that is comparing number of second, third, forth, and so on, places.
You are given the result of all races during the season and you are to determine the champion according to both scoring systems. It is guaranteed, that both systems will produce unique champion.
Input
The first line contain integer t (1 β€ t β€ 20), where t is the number of races. After that all races are described one by one. Every race description start with an integer n (1 β€ n β€ 50) on a line of itself, where n is the number of clasified drivers in the given race. After that n lines follow with the classification for the race, each containing the name of a driver. The names of drivers are given in order from the first to the last place. The name of the driver consists of lowercase and uppercase English letters and has length at most 50 characters. Comparing of names should be case-sensetive.
Output
Your output should contain exactly two line. On the first line is the name of the champion according to the original rule, and on the second line the name of the champion according to the alternative rule.
Examples
Input
3
3
Hamilton
Vettel
Webber
2
Webber
Vettel
2
Hamilton
Vettel
Output
Vettel
Hamilton
Input
2
7
Prost
Surtees
Nakajima
Schumacher
Button
DeLaRosa
Buemi
8
Alonso
Prost
NinoFarina
JimClark
DeLaRosa
Nakajima
Patrese
Surtees
Output
Prost
Prost
Note
It is not guaranteed that the same drivers participate in all races. For the championship consider every driver that has participated in at least one race. The total number of drivers during the whole season is not more then 50.
Submitted Solution:
```
import re
import sys
exit=sys.exit
from bisect import bisect_left as bsl,bisect_right as bsr
from collections import Counter,defaultdict as ddict,deque
from functools import lru_cache
cache=lru_cache(None)
from heapq import *
from itertools import *
from math import inf
from pprint import pprint as pp
enum=enumerate
ri=lambda:int(rln())
ris=lambda:list(map(int,rfs()))
rln=sys.stdin.readline
rl=lambda:rln().rstrip('\n')
rfs=lambda:rln().split()
cat=''.join
catn='\n'.join
mod=1000000007
d4=[(0,-1),(1,0),(0,1),(-1,0)]
d8=[(-1,-1),(0,-1),(1,-1),(-1,0),(1,0),(-1,1),(0,1),(1,1)]
########################################################################
pos={}
pts={}
t=ri()
for _ in range(t):
n=ri()
for i in range(n):
s=rl()
if s not in pos:
pos[s]=[0]*50
pts[s]=0
pos[s][i]-=1
if i<10:
pts[s]-=[25, 18, 15, 12, 10, 8, 6, 4, 2, 1][i]
by_pts=sorted(pts,key=lambda x:(pts[x],pos[x]))[0]
by_pos=sorted(pts,key=lambda x:(pos[x][0],pts[x]))[0]
print(by_pts)
print(by_pos)
```
No
| 99,727 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Luyi has n circles on the plane. The i-th circle is centered at (xi, yi). At the time zero circles start to grow simultaneously. In other words, the radius of each circle at time t (t > 0) is equal to t. The circles are drawn as black discs on an infinite white plane. So at each moment the plane consists of several black and white regions. Note that the circles may overlap while growing.
<image>
We define a hole as a closed, connected white region. For instance, the figure contains two holes shown by red border. During growing some holes may be created and it is easy to see that each created hole will disappear eventually. Luyi asks you to find moment of time such that the last hole disappears. In other words, you should find the first moment such that no hole can be seen after that.
Input
The first line of the input contains integer n (1 β€ n β€ 100). Each of the next n lines contains two integers xi and yi ( - 104 β€ xi, yi β€ 104), indicating the location of i-th circle.
It's guaranteed that no two circles are centered at the same point.
Output
Print the moment where the last hole disappears. If there exists no moment in which we can find holes print -1.
The answer will be considered correct if the absolute or relative error does not exceed 10 - 4.
Examples
Input
3
0 0
1 1
2 2
Output
-1
Input
4
0 0
0 2
2 2
2 0
Output
1.414214
Input
4
0 1
0 -1
-2 0
4 0
Output
2.125000
Submitted Solution:
```
n=int(input())
arr=[]
for _ in range(n):
temp=[int(x) for x in input().split()]
arr.append(temp)
arr.sort()
#print(arr)
ans=-1
for i in arr:
if ans<=i[1]:
ans=i[1]
else:
ans=i[0]
print(ans)
```
No
| 99,728 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Luyi has n circles on the plane. The i-th circle is centered at (xi, yi). At the time zero circles start to grow simultaneously. In other words, the radius of each circle at time t (t > 0) is equal to t. The circles are drawn as black discs on an infinite white plane. So at each moment the plane consists of several black and white regions. Note that the circles may overlap while growing.
<image>
We define a hole as a closed, connected white region. For instance, the figure contains two holes shown by red border. During growing some holes may be created and it is easy to see that each created hole will disappear eventually. Luyi asks you to find moment of time such that the last hole disappears. In other words, you should find the first moment such that no hole can be seen after that.
Input
The first line of the input contains integer n (1 β€ n β€ 100). Each of the next n lines contains two integers xi and yi ( - 104 β€ xi, yi β€ 104), indicating the location of i-th circle.
It's guaranteed that no two circles are centered at the same point.
Output
Print the moment where the last hole disappears. If there exists no moment in which we can find holes print -1.
The answer will be considered correct if the absolute or relative error does not exceed 10 - 4.
Examples
Input
3
0 0
1 1
2 2
Output
-1
Input
4
0 0
0 2
2 2
2 0
Output
1.414214
Input
4
0 1
0 -1
-2 0
4 0
Output
2.125000
Submitted Solution:
```
from array import array
from math import acos, pi
def dist(x0, y0, x1, y1):
return ((x0 - x1)**2 + (y0 - y1)**2)**0.5
def isAngleAcute(x0, y0, x1, y1):
#cosPhi = (x0*x1 + y0*y1) / (len2(x0, y0) * len2(x1, y1))**0.5 #; orient = x0*y1 - x1*y0
cosPhiT = x0*x1 + y0*y1 #; orient = x0*y1 - x1*y0
return cosPhiT > 0
def getAngle(x0, y0, x1, y1): #and (1, 0)
cosPhi = (x0*x1 + y0*y1) / ((x0**2 + y0**2) * (x1**2 + y1**2))**0.5
orient = x0*y1 - x1*y0
ans = acos(cosPhi)
if orient < 0:
return -ans
else:
return ans
def isTriangleAcute(p0, q0, p1, q1, p2, q2):
acute0 = isAngleAcute(p0-p1, q0-q1, p0-p2, q0-q2)
acute1 = isAngleAcute(p1-p0, q1-q0, p1-p2, q1-q2)
acute2 = isAngleAcute(p2-p0, q2-q0, p2-p1, q2-q1)
return acute0 and acute1 and acute2
def lineIntersection(a0, b0, c0, a1, b1, c1):
det = a0*b1 - a1*b0
if det == 0:
return None
x_int = (c0*b1 - c1*b0) / det
y_int = (a0*c1 - a1*c0) / det
return x_int, y_int
def lineByPoints(x0, y0, x1, y1):
a = y0 - y1
b = x1 - x0
c = x1*y0 - x0*y1
return a, b, c
EPS = 1e-6
n = int(input())
x = array('i', (0,)*n)
y = array('i', (0,)*n)
for i in range(n):
x[i], y[i] = map(int, input().split())
answer = -1
for i0 in range(n):
for i1 in range(i0 + 1, n):
for i2 in range(i1 + 1, n):
if isTriangleAcute(x[i0], y[i0], x[i1], y[i1], x[i2], y[i2]):
line0 = lineByPoints(x[i0], y[i0], x[i1], y[i1])
x0_c = (x[i0] + x[i1]) / 2
y0_c = (y[i0] + y[i1]) / 2
line1 = lineByPoints(x[i0], y[i0], x[i2], y[i2])
x1_c = (x[i0] + x[i2]) / 2
y1_c = (y[i0] + y[i2]) / 2
a0 = line0[1]
b0 = -line0[0]
c0 = a0*x0_c + b0*y0_c
a1 = line1[1]
b1 = -line1[0]
c1 = a1*x1_c + b1*y1_c
insec = lineIntersection(a0, b0, c0, a1, b1, c1)
if insec == None:
continue
x_int, y_int = insec
rad = ((x_int - x[0])**2 + (y_int - y[0])**2)**0.5
alreadyCovered = False
for i3 in range(n):
if dist(x_int, y_int, x[i3], y[i3]) < rad:
alreadyCovered = True
break
if not alreadyCovered:
answer = max(answer, rad)
else:
j0 = j1 = j2 = -1
phi = getAngle(x[i0]-x[i1], y[i0]-y[i1], x[i0]-x[i2], y[i0]-y[i2])
if j0 == -1 and abs(pi/2 - phi) < EPS:#012
j0 = i1
j1 = i0
j2 = i2
phi = getAngle(x[i0]-x[i2], y[i0]-y[i2], x[i0]-x[i1], y[i0]-y[i1])
if j0 == -1 and abs(pi/2 - phi) < EPS:#021
j0 = i2
j1 = i0
j2 = i1
phi = getAngle(x[i1]-x[i2], y[i1]-y[i2], x[i1]-x[i0], y[i1]-y[i0])
if j0 == -1 and abs(pi/2 - phi) < EPS:#120
j0 = i2
j1 = i1
j2 = i0
phi = getAngle(x[i1]-x[i0], y[i1]-y[i0], x[i1]-x[i2], y[i1]-y[i2])
if j0 == -1 and abs(pi/2 - phi) < EPS:#102
j0 = i0
j1 = i1
j2 = i2
phi = getAngle(x[i2]-x[i0], y[i2]-y[i0], x[i2]-x[i1], y[i2]-y[i1])
if j0 == -1 and abs(pi/2 - phi) < EPS:#201
j0 = i0
j1 = i2
j2 = i1
phi = getAngle(x[i2]-x[i1], y[i2]-y[i1], x[i2]-x[i0], y[i2]-y[i0])
if j0 == -1 and abs(pi/2 - phi) < EPS:#210
j0 = i1
j1 = i2
j2 = i0
#phi = ...
if j0 == -1:
continue
line0 = lineByPoints(x[j1], y[j1], x[j0], y[j0])
line1 = lineByPoints(x[j1], y[j1], x[j2], y[j2])
a0 = line0[0]
b0 = line0[1]
c0 = x[j0]*line0[0] + y[j0]*line0[1]
a1 = line1[0]
b1 = line1[1]
c1 = x[j2]*line1[0] + y[j2]*line0[1]
x_prob, y_prob = lineIntersection(a0, b0, c0, a1, b1, c1)
for i3 in range(n):
if abs(x[i3] - x_prob) + abs(y[i3] - y_prob) < EPS:
x_int = (x[j0] + x[j2]) / 2
y_int = (y[j0] + y[j2]) / 2
rad = dist(x_int, y_int, x[j1], y[j1])
clsExists = False
for i4 in range(n):
if dist(x_int, y_int, x[i4], y[i4]) < rad:
clsExists = True
break
if not clsExists:
answer = max(answer, rad)
break
print('%.6f' % answer)
```
No
| 99,729 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2n members and coincidentally Natalia Fan Club also has 2n members. Each member of MDC is assigned a unique id i from 0 to 2n - 1. The same holds for each member of NFC.
One of the parts of this tradition is one by one dance, where each member of MDC dances with a member of NFC. A dance pair is a pair of numbers (a, b) such that member a from MDC dances with member b from NFC.
The complexity of a pairs' assignment is the number of pairs of dancing pairs (a, b) and (c, d) such that a < c and b > d.
You are given a binary number of length n named x. We know that member i from MDC dances with member <image> from NFC. Your task is to calculate the complexity of this assignment modulo 1000000007 (109 + 7).
Expression <image> denotes applying Β«XORΒ» to numbers x and y. This operation exists in all modern programming languages, for example, in C++ and Java it denotes as Β«^Β», in Pascal β Β«xorΒ».
Input
The first line of input contains a binary number x of lenght n, (1 β€ n β€ 100).
This number may contain leading zeros.
Output
Print the complexity of the given dance assignent modulo 1000000007 (109 + 7).
Examples
Input
11
Output
6
Input
01
Output
2
Input
1
Output
1
Tags: combinatorics, math
Correct Solution:
```
x = input()
n = len(x)
mod = 10 ** 9 + 7
ans = 0
for i in range(n):
if x[i] == '1':
pref = pow(2, i, mod)
suf = pow(2, n - i - 1, mod) ** 2
ans += (pref * suf) % mod
print(ans % mod)
```
| 99,730 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2n members and coincidentally Natalia Fan Club also has 2n members. Each member of MDC is assigned a unique id i from 0 to 2n - 1. The same holds for each member of NFC.
One of the parts of this tradition is one by one dance, where each member of MDC dances with a member of NFC. A dance pair is a pair of numbers (a, b) such that member a from MDC dances with member b from NFC.
The complexity of a pairs' assignment is the number of pairs of dancing pairs (a, b) and (c, d) such that a < c and b > d.
You are given a binary number of length n named x. We know that member i from MDC dances with member <image> from NFC. Your task is to calculate the complexity of this assignment modulo 1000000007 (109 + 7).
Expression <image> denotes applying Β«XORΒ» to numbers x and y. This operation exists in all modern programming languages, for example, in C++ and Java it denotes as Β«^Β», in Pascal β Β«xorΒ».
Input
The first line of input contains a binary number x of lenght n, (1 β€ n β€ 100).
This number may contain leading zeros.
Output
Print the complexity of the given dance assignent modulo 1000000007 (109 + 7).
Examples
Input
11
Output
6
Input
01
Output
2
Input
1
Output
1
Tags: combinatorics, math
Correct Solution:
```
#!/usr/local/bin/python3.3 -tt
import sys
if __name__ == '__main__':
for l in sys.stdin:
s = l.strip()
break
n = len(s)
d = 2 ** (n - 1)
print(d * int(s, 2) % 1000000007)
```
| 99,731 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2n members and coincidentally Natalia Fan Club also has 2n members. Each member of MDC is assigned a unique id i from 0 to 2n - 1. The same holds for each member of NFC.
One of the parts of this tradition is one by one dance, where each member of MDC dances with a member of NFC. A dance pair is a pair of numbers (a, b) such that member a from MDC dances with member b from NFC.
The complexity of a pairs' assignment is the number of pairs of dancing pairs (a, b) and (c, d) such that a < c and b > d.
You are given a binary number of length n named x. We know that member i from MDC dances with member <image> from NFC. Your task is to calculate the complexity of this assignment modulo 1000000007 (109 + 7).
Expression <image> denotes applying Β«XORΒ» to numbers x and y. This operation exists in all modern programming languages, for example, in C++ and Java it denotes as Β«^Β», in Pascal β Β«xorΒ».
Input
The first line of input contains a binary number x of lenght n, (1 β€ n β€ 100).
This number may contain leading zeros.
Output
Print the complexity of the given dance assignent modulo 1000000007 (109 + 7).
Examples
Input
11
Output
6
Input
01
Output
2
Input
1
Output
1
Tags: combinatorics, math
Correct Solution:
```
s = input()
s = s[::-1]
ans = 0
for i in range(len(s)):
if s[i] == '1':
ans += ((2 ** i) ** 2) * (2**(len(s) - i - 1))
print(ans % (10**9+7))
```
| 99,732 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2n members and coincidentally Natalia Fan Club also has 2n members. Each member of MDC is assigned a unique id i from 0 to 2n - 1. The same holds for each member of NFC.
One of the parts of this tradition is one by one dance, where each member of MDC dances with a member of NFC. A dance pair is a pair of numbers (a, b) such that member a from MDC dances with member b from NFC.
The complexity of a pairs' assignment is the number of pairs of dancing pairs (a, b) and (c, d) such that a < c and b > d.
You are given a binary number of length n named x. We know that member i from MDC dances with member <image> from NFC. Your task is to calculate the complexity of this assignment modulo 1000000007 (109 + 7).
Expression <image> denotes applying Β«XORΒ» to numbers x and y. This operation exists in all modern programming languages, for example, in C++ and Java it denotes as Β«^Β», in Pascal β Β«xorΒ».
Input
The first line of input contains a binary number x of lenght n, (1 β€ n β€ 100).
This number may contain leading zeros.
Output
Print the complexity of the given dance assignent modulo 1000000007 (109 + 7).
Examples
Input
11
Output
6
Input
01
Output
2
Input
1
Output
1
Tags: combinatorics, math
Correct Solution:
```
p = 1000000007
s = input()
print(int(s,2) * pow(2, len(s) - 1) % p)
# Made By Mostafa_Khaled
```
| 99,733 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2n members and coincidentally Natalia Fan Club also has 2n members. Each member of MDC is assigned a unique id i from 0 to 2n - 1. The same holds for each member of NFC.
One of the parts of this tradition is one by one dance, where each member of MDC dances with a member of NFC. A dance pair is a pair of numbers (a, b) such that member a from MDC dances with member b from NFC.
The complexity of a pairs' assignment is the number of pairs of dancing pairs (a, b) and (c, d) such that a < c and b > d.
You are given a binary number of length n named x. We know that member i from MDC dances with member <image> from NFC. Your task is to calculate the complexity of this assignment modulo 1000000007 (109 + 7).
Expression <image> denotes applying Β«XORΒ» to numbers x and y. This operation exists in all modern programming languages, for example, in C++ and Java it denotes as Β«^Β», in Pascal β Β«xorΒ».
Input
The first line of input contains a binary number x of lenght n, (1 β€ n β€ 100).
This number may contain leading zeros.
Output
Print the complexity of the given dance assignent modulo 1000000007 (109 + 7).
Examples
Input
11
Output
6
Input
01
Output
2
Input
1
Output
1
Tags: combinatorics, math
Correct Solution:
```
n = input().strip()
s = len(n)
k = int(n,2)
start = 4 **( s-1)
zib = 2**(s-1)
step = 2**(s-1)
print((start+(k-zib)*step)%(10**9+7))
```
| 99,734 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2n members and coincidentally Natalia Fan Club also has 2n members. Each member of MDC is assigned a unique id i from 0 to 2n - 1. The same holds for each member of NFC.
One of the parts of this tradition is one by one dance, where each member of MDC dances with a member of NFC. A dance pair is a pair of numbers (a, b) such that member a from MDC dances with member b from NFC.
The complexity of a pairs' assignment is the number of pairs of dancing pairs (a, b) and (c, d) such that a < c and b > d.
You are given a binary number of length n named x. We know that member i from MDC dances with member <image> from NFC. Your task is to calculate the complexity of this assignment modulo 1000000007 (109 + 7).
Expression <image> denotes applying Β«XORΒ» to numbers x and y. This operation exists in all modern programming languages, for example, in C++ and Java it denotes as Β«^Β», in Pascal β Β«xorΒ».
Input
The first line of input contains a binary number x of lenght n, (1 β€ n β€ 100).
This number may contain leading zeros.
Output
Print the complexity of the given dance assignent modulo 1000000007 (109 + 7).
Examples
Input
11
Output
6
Input
01
Output
2
Input
1
Output
1
Tags: combinatorics, math
Correct Solution:
```
MOD = int(1e9 + 7)
x = input()[::-1]
n = len(x)
res = 0
for i, t in enumerate(x):
if t == '1':
res = (res + (1 << (n - 1 + i))) % MOD
print(res)
```
| 99,735 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2n members and coincidentally Natalia Fan Club also has 2n members. Each member of MDC is assigned a unique id i from 0 to 2n - 1. The same holds for each member of NFC.
One of the parts of this tradition is one by one dance, where each member of MDC dances with a member of NFC. A dance pair is a pair of numbers (a, b) such that member a from MDC dances with member b from NFC.
The complexity of a pairs' assignment is the number of pairs of dancing pairs (a, b) and (c, d) such that a < c and b > d.
You are given a binary number of length n named x. We know that member i from MDC dances with member <image> from NFC. Your task is to calculate the complexity of this assignment modulo 1000000007 (109 + 7).
Expression <image> denotes applying Β«XORΒ» to numbers x and y. This operation exists in all modern programming languages, for example, in C++ and Java it denotes as Β«^Β», in Pascal β Β«xorΒ».
Input
The first line of input contains a binary number x of lenght n, (1 β€ n β€ 100).
This number may contain leading zeros.
Output
Print the complexity of the given dance assignent modulo 1000000007 (109 + 7).
Examples
Input
11
Output
6
Input
01
Output
2
Input
1
Output
1
Tags: combinatorics, math
Correct Solution:
```
MOD = 1000000007
ans = 0
x = input().strip()
n = len(x)
for i, v in enumerate(x):
if v == "1":
ans += pow(2, i, MOD) * pow(2, (n - i - 1) * 2, MOD) % MOD
ans %= MOD
print(ans)
```
| 99,736 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2n members and coincidentally Natalia Fan Club also has 2n members. Each member of MDC is assigned a unique id i from 0 to 2n - 1. The same holds for each member of NFC.
One of the parts of this tradition is one by one dance, where each member of MDC dances with a member of NFC. A dance pair is a pair of numbers (a, b) such that member a from MDC dances with member b from NFC.
The complexity of a pairs' assignment is the number of pairs of dancing pairs (a, b) and (c, d) such that a < c and b > d.
You are given a binary number of length n named x. We know that member i from MDC dances with member <image> from NFC. Your task is to calculate the complexity of this assignment modulo 1000000007 (109 + 7).
Expression <image> denotes applying Β«XORΒ» to numbers x and y. This operation exists in all modern programming languages, for example, in C++ and Java it denotes as Β«^Β», in Pascal β Β«xorΒ».
Input
The first line of input contains a binary number x of lenght n, (1 β€ n β€ 100).
This number may contain leading zeros.
Output
Print the complexity of the given dance assignent modulo 1000000007 (109 + 7).
Examples
Input
11
Output
6
Input
01
Output
2
Input
1
Output
1
Submitted Solution:
```
MOD = int(10e9 + 7)
x = input()[::-1]
n = len(x)
res = 0
for i, t in enumerate(x):
if t == '1':
res = (res + (1 << (n - 1 + i))) % MOD
print(res)
```
No
| 99,737 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2n members and coincidentally Natalia Fan Club also has 2n members. Each member of MDC is assigned a unique id i from 0 to 2n - 1. The same holds for each member of NFC.
One of the parts of this tradition is one by one dance, where each member of MDC dances with a member of NFC. A dance pair is a pair of numbers (a, b) such that member a from MDC dances with member b from NFC.
The complexity of a pairs' assignment is the number of pairs of dancing pairs (a, b) and (c, d) such that a < c and b > d.
You are given a binary number of length n named x. We know that member i from MDC dances with member <image> from NFC. Your task is to calculate the complexity of this assignment modulo 1000000007 (109 + 7).
Expression <image> denotes applying Β«XORΒ» to numbers x and y. This operation exists in all modern programming languages, for example, in C++ and Java it denotes as Β«^Β», in Pascal β Β«xorΒ».
Input
The first line of input contains a binary number x of lenght n, (1 β€ n β€ 100).
This number may contain leading zeros.
Output
Print the complexity of the given dance assignent modulo 1000000007 (109 + 7).
Examples
Input
11
Output
6
Input
01
Output
2
Input
1
Output
1
Submitted Solution:
```
s = input()
s = s[::-1]
ans = 0
for i in range(len(s)):
if s[i] == '1':
ans += (2 ** i) ** 2
else:
ans *= 2
print(ans % (10**9+7))
```
No
| 99,738 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2n members and coincidentally Natalia Fan Club also has 2n members. Each member of MDC is assigned a unique id i from 0 to 2n - 1. The same holds for each member of NFC.
One of the parts of this tradition is one by one dance, where each member of MDC dances with a member of NFC. A dance pair is a pair of numbers (a, b) such that member a from MDC dances with member b from NFC.
The complexity of a pairs' assignment is the number of pairs of dancing pairs (a, b) and (c, d) such that a < c and b > d.
You are given a binary number of length n named x. We know that member i from MDC dances with member <image> from NFC. Your task is to calculate the complexity of this assignment modulo 1000000007 (109 + 7).
Expression <image> denotes applying Β«XORΒ» to numbers x and y. This operation exists in all modern programming languages, for example, in C++ and Java it denotes as Β«^Β», in Pascal β Β«xorΒ».
Input
The first line of input contains a binary number x of lenght n, (1 β€ n β€ 100).
This number may contain leading zeros.
Output
Print the complexity of the given dance assignent modulo 1000000007 (109 + 7).
Examples
Input
11
Output
6
Input
01
Output
2
Input
1
Output
1
Submitted Solution:
```
s = input()
s = s[::-1]
ans = 0
for i in range(len(s)):
if s[i] == '1':
ans += 2 ** i
else:
ans *= 2
print(ans % (10**9+7))
```
No
| 99,739 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You will receive 3 points for solving this problem.
Manao is designing the genetic code for a new type of algae to efficiently produce fuel. Specifically, Manao is focusing on a stretch of DNA that encodes one protein. The stretch of DNA is represented by a string containing only the characters 'A', 'T', 'G' and 'C'.
Manao has determined that if the stretch of DNA contains a maximal sequence of consecutive identical nucleotides that is of even length, then the protein will be nonfunctional. For example, consider a protein described by DNA string "GTTAAAG". It contains four maximal sequences of consecutive identical nucleotides: "G", "TT", "AAA", and "G". The protein is nonfunctional because sequence "TT" has even length.
Manao is trying to obtain a functional protein from the protein he currently has. Manao can insert additional nucleotides into the DNA stretch. Each additional nucleotide is a character from the set {'A', 'T', 'G', 'C'}. Manao wants to determine the minimum number of insertions necessary to make the DNA encode a functional protein.
Input
The input consists of a single line, containing a string s of length n (1 β€ n β€ 100). Each character of s will be from the set {'A', 'T', 'G', 'C'}.
This problem doesn't have subproblems. You will get 3 points for the correct submission.
Output
The program should print on one line a single integer representing the minimum number of 'A', 'T', 'G', 'C' characters that are required to be inserted into the input string in order to make all runs of identical characters have odd length.
Examples
Input
GTTAAAG
Output
1
Input
AACCAACCAAAAC
Output
5
Note
In the first example, it is sufficient to insert a single nucleotide of any type between the two 'T's in the sequence to restore the functionality of the protein.
Tags: implementation, two pointers
Correct Solution:
```
s=input()
nb=1
n=0
for i in range(len(s)-1):
if (s[i]!=s[i+1]) and (nb%2==0):
n+=1
nb=1
elif (s[i]!=s[i+1]):
nb=1
else:
nb+=1
if nb%2==0:
print(n+1)
else:
print(n)
```
| 99,740 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You will receive 3 points for solving this problem.
Manao is designing the genetic code for a new type of algae to efficiently produce fuel. Specifically, Manao is focusing on a stretch of DNA that encodes one protein. The stretch of DNA is represented by a string containing only the characters 'A', 'T', 'G' and 'C'.
Manao has determined that if the stretch of DNA contains a maximal sequence of consecutive identical nucleotides that is of even length, then the protein will be nonfunctional. For example, consider a protein described by DNA string "GTTAAAG". It contains four maximal sequences of consecutive identical nucleotides: "G", "TT", "AAA", and "G". The protein is nonfunctional because sequence "TT" has even length.
Manao is trying to obtain a functional protein from the protein he currently has. Manao can insert additional nucleotides into the DNA stretch. Each additional nucleotide is a character from the set {'A', 'T', 'G', 'C'}. Manao wants to determine the minimum number of insertions necessary to make the DNA encode a functional protein.
Input
The input consists of a single line, containing a string s of length n (1 β€ n β€ 100). Each character of s will be from the set {'A', 'T', 'G', 'C'}.
This problem doesn't have subproblems. You will get 3 points for the correct submission.
Output
The program should print on one line a single integer representing the minimum number of 'A', 'T', 'G', 'C' characters that are required to be inserted into the input string in order to make all runs of identical characters have odd length.
Examples
Input
GTTAAAG
Output
1
Input
AACCAACCAAAAC
Output
5
Note
In the first example, it is sufficient to insert a single nucleotide of any type between the two 'T's in the sequence to restore the functionality of the protein.
Tags: implementation, two pointers
Correct Solution:
```
dna=input()
ans=0
i=0
while i<len(dna):
j=i+1
while j<len(dna) and dna[j]==dna[j-1]:
j+=1
if not (j-i)&1:
ans+=1
i=j
print(ans)
```
| 99,741 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You will receive 3 points for solving this problem.
Manao is designing the genetic code for a new type of algae to efficiently produce fuel. Specifically, Manao is focusing on a stretch of DNA that encodes one protein. The stretch of DNA is represented by a string containing only the characters 'A', 'T', 'G' and 'C'.
Manao has determined that if the stretch of DNA contains a maximal sequence of consecutive identical nucleotides that is of even length, then the protein will be nonfunctional. For example, consider a protein described by DNA string "GTTAAAG". It contains four maximal sequences of consecutive identical nucleotides: "G", "TT", "AAA", and "G". The protein is nonfunctional because sequence "TT" has even length.
Manao is trying to obtain a functional protein from the protein he currently has. Manao can insert additional nucleotides into the DNA stretch. Each additional nucleotide is a character from the set {'A', 'T', 'G', 'C'}. Manao wants to determine the minimum number of insertions necessary to make the DNA encode a functional protein.
Input
The input consists of a single line, containing a string s of length n (1 β€ n β€ 100). Each character of s will be from the set {'A', 'T', 'G', 'C'}.
This problem doesn't have subproblems. You will get 3 points for the correct submission.
Output
The program should print on one line a single integer representing the minimum number of 'A', 'T', 'G', 'C' characters that are required to be inserted into the input string in order to make all runs of identical characters have odd length.
Examples
Input
GTTAAAG
Output
1
Input
AACCAACCAAAAC
Output
5
Note
In the first example, it is sufficient to insert a single nucleotide of any type between the two 'T's in the sequence to restore the functionality of the protein.
Tags: implementation, two pointers
Correct Solution:
```
y=input()
final=0
i=0
while i<len(y):
if y[i]=='A':
flag=0
while i<len(y):
if y[i]=='A':
flag+=1
else:
break
i+=1
if flag%2==0:
final=final+1
elif y[i]=='T':
flag=0
while i<len(y):
if y[i]=='T':
flag+=1
else:
break
i=i+1
if flag%2==0:
final=final+1
elif y[i]=='G':
flag=0
while i<len(y):
if y[i]=='G':
flag+=1
else:
break
i+=1
if flag%2==0:
final=final+1
elif y[i]=='C':
flag=0
while i<len(y):
if y[i]=='C':
flag+=1
else:
break
i+=1
if flag%2==0:
final=final+1
print(final)
```
| 99,742 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You will receive 3 points for solving this problem.
Manao is designing the genetic code for a new type of algae to efficiently produce fuel. Specifically, Manao is focusing on a stretch of DNA that encodes one protein. The stretch of DNA is represented by a string containing only the characters 'A', 'T', 'G' and 'C'.
Manao has determined that if the stretch of DNA contains a maximal sequence of consecutive identical nucleotides that is of even length, then the protein will be nonfunctional. For example, consider a protein described by DNA string "GTTAAAG". It contains four maximal sequences of consecutive identical nucleotides: "G", "TT", "AAA", and "G". The protein is nonfunctional because sequence "TT" has even length.
Manao is trying to obtain a functional protein from the protein he currently has. Manao can insert additional nucleotides into the DNA stretch. Each additional nucleotide is a character from the set {'A', 'T', 'G', 'C'}. Manao wants to determine the minimum number of insertions necessary to make the DNA encode a functional protein.
Input
The input consists of a single line, containing a string s of length n (1 β€ n β€ 100). Each character of s will be from the set {'A', 'T', 'G', 'C'}.
This problem doesn't have subproblems. You will get 3 points for the correct submission.
Output
The program should print on one line a single integer representing the minimum number of 'A', 'T', 'G', 'C' characters that are required to be inserted into the input string in order to make all runs of identical characters have odd length.
Examples
Input
GTTAAAG
Output
1
Input
AACCAACCAAAAC
Output
5
Note
In the first example, it is sufficient to insert a single nucleotide of any type between the two 'T's in the sequence to restore the functionality of the protein.
Tags: implementation, two pointers
Correct Solution:
```
string = input()
s = string[0]
n = 0
values = []
for i in string:
if i == s:
n += 1
else:
values.append(n)
n = 1
s = i
values.append(n)
t = 0
for i in values:
if i % 2 == 0:
t += 1
print(t)
```
| 99,743 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You will receive 3 points for solving this problem.
Manao is designing the genetic code for a new type of algae to efficiently produce fuel. Specifically, Manao is focusing on a stretch of DNA that encodes one protein. The stretch of DNA is represented by a string containing only the characters 'A', 'T', 'G' and 'C'.
Manao has determined that if the stretch of DNA contains a maximal sequence of consecutive identical nucleotides that is of even length, then the protein will be nonfunctional. For example, consider a protein described by DNA string "GTTAAAG". It contains four maximal sequences of consecutive identical nucleotides: "G", "TT", "AAA", and "G". The protein is nonfunctional because sequence "TT" has even length.
Manao is trying to obtain a functional protein from the protein he currently has. Manao can insert additional nucleotides into the DNA stretch. Each additional nucleotide is a character from the set {'A', 'T', 'G', 'C'}. Manao wants to determine the minimum number of insertions necessary to make the DNA encode a functional protein.
Input
The input consists of a single line, containing a string s of length n (1 β€ n β€ 100). Each character of s will be from the set {'A', 'T', 'G', 'C'}.
This problem doesn't have subproblems. You will get 3 points for the correct submission.
Output
The program should print on one line a single integer representing the minimum number of 'A', 'T', 'G', 'C' characters that are required to be inserted into the input string in order to make all runs of identical characters have odd length.
Examples
Input
GTTAAAG
Output
1
Input
AACCAACCAAAAC
Output
5
Note
In the first example, it is sufficient to insert a single nucleotide of any type between the two 'T's in the sequence to restore the functionality of the protein.
Tags: implementation, two pointers
Correct Solution:
```
r = input()
i = 0
outer_count = 0
while i < len(r):
count = 0
char = r[i]
while r[i] == char:
count += 1
i += 1
if i == len(r):
break
if count % 2 == 0:
outer_count += 1
print(outer_count)
```
| 99,744 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You will receive 3 points for solving this problem.
Manao is designing the genetic code for a new type of algae to efficiently produce fuel. Specifically, Manao is focusing on a stretch of DNA that encodes one protein. The stretch of DNA is represented by a string containing only the characters 'A', 'T', 'G' and 'C'.
Manao has determined that if the stretch of DNA contains a maximal sequence of consecutive identical nucleotides that is of even length, then the protein will be nonfunctional. For example, consider a protein described by DNA string "GTTAAAG". It contains four maximal sequences of consecutive identical nucleotides: "G", "TT", "AAA", and "G". The protein is nonfunctional because sequence "TT" has even length.
Manao is trying to obtain a functional protein from the protein he currently has. Manao can insert additional nucleotides into the DNA stretch. Each additional nucleotide is a character from the set {'A', 'T', 'G', 'C'}. Manao wants to determine the minimum number of insertions necessary to make the DNA encode a functional protein.
Input
The input consists of a single line, containing a string s of length n (1 β€ n β€ 100). Each character of s will be from the set {'A', 'T', 'G', 'C'}.
This problem doesn't have subproblems. You will get 3 points for the correct submission.
Output
The program should print on one line a single integer representing the minimum number of 'A', 'T', 'G', 'C' characters that are required to be inserted into the input string in order to make all runs of identical characters have odd length.
Examples
Input
GTTAAAG
Output
1
Input
AACCAACCAAAAC
Output
5
Note
In the first example, it is sufficient to insert a single nucleotide of any type between the two 'T's in the sequence to restore the functionality of the protein.
Tags: implementation, two pointers
Correct Solution:
```
s = input()
piece = ''
count = 0
for i in range(len(s)-1):
if s[i+1] != s[i] :
piece += s[i]
#print(piece)
if len(piece) % 2 == 0 :
count += 1
piece = ''
else:
piece += s[i]
if i == len(s)-2 and s[len(s)-2] == s[len(s)-1]:
piece += s[-1]
if len(piece) % 2 == 0 :
count += 1
print(count)
```
| 99,745 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You will receive 3 points for solving this problem.
Manao is designing the genetic code for a new type of algae to efficiently produce fuel. Specifically, Manao is focusing on a stretch of DNA that encodes one protein. The stretch of DNA is represented by a string containing only the characters 'A', 'T', 'G' and 'C'.
Manao has determined that if the stretch of DNA contains a maximal sequence of consecutive identical nucleotides that is of even length, then the protein will be nonfunctional. For example, consider a protein described by DNA string "GTTAAAG". It contains four maximal sequences of consecutive identical nucleotides: "G", "TT", "AAA", and "G". The protein is nonfunctional because sequence "TT" has even length.
Manao is trying to obtain a functional protein from the protein he currently has. Manao can insert additional nucleotides into the DNA stretch. Each additional nucleotide is a character from the set {'A', 'T', 'G', 'C'}. Manao wants to determine the minimum number of insertions necessary to make the DNA encode a functional protein.
Input
The input consists of a single line, containing a string s of length n (1 β€ n β€ 100). Each character of s will be from the set {'A', 'T', 'G', 'C'}.
This problem doesn't have subproblems. You will get 3 points for the correct submission.
Output
The program should print on one line a single integer representing the minimum number of 'A', 'T', 'G', 'C' characters that are required to be inserted into the input string in order to make all runs of identical characters have odd length.
Examples
Input
GTTAAAG
Output
1
Input
AACCAACCAAAAC
Output
5
Note
In the first example, it is sufficient to insert a single nucleotide of any type between the two 'T's in the sequence to restore the functionality of the protein.
Tags: implementation, two pointers
Correct Solution:
```
import sys
string = str(sys.stdin.readline())
string = list(string)
def solution(string):
count = 1
answer = 0
num = 0
#string.remove("\n")
for i in string:
if i == "\n":
return print(answer)
elif i == string[num+1]:
count+=1
elif i != string[num+1]:
if count % 2 == 0 and count != 0:
answer += 1
count = 1
num+=1
return print(answer)
solution(string)
```
| 99,746 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You will receive 3 points for solving this problem.
Manao is designing the genetic code for a new type of algae to efficiently produce fuel. Specifically, Manao is focusing on a stretch of DNA that encodes one protein. The stretch of DNA is represented by a string containing only the characters 'A', 'T', 'G' and 'C'.
Manao has determined that if the stretch of DNA contains a maximal sequence of consecutive identical nucleotides that is of even length, then the protein will be nonfunctional. For example, consider a protein described by DNA string "GTTAAAG". It contains four maximal sequences of consecutive identical nucleotides: "G", "TT", "AAA", and "G". The protein is nonfunctional because sequence "TT" has even length.
Manao is trying to obtain a functional protein from the protein he currently has. Manao can insert additional nucleotides into the DNA stretch. Each additional nucleotide is a character from the set {'A', 'T', 'G', 'C'}. Manao wants to determine the minimum number of insertions necessary to make the DNA encode a functional protein.
Input
The input consists of a single line, containing a string s of length n (1 β€ n β€ 100). Each character of s will be from the set {'A', 'T', 'G', 'C'}.
This problem doesn't have subproblems. You will get 3 points for the correct submission.
Output
The program should print on one line a single integer representing the minimum number of 'A', 'T', 'G', 'C' characters that are required to be inserted into the input string in order to make all runs of identical characters have odd length.
Examples
Input
GTTAAAG
Output
1
Input
AACCAACCAAAAC
Output
5
Note
In the first example, it is sufficient to insert a single nucleotide of any type between the two 'T's in the sequence to restore the functionality of the protein.
Tags: implementation, two pointers
Correct Solution:
```
import re
x = input()
l = [0 for i in range(len(x))]
c, h = 1, 0
for i in range(len(x) - 1):
l, r = x[i], x[i + 1]
if l is r:
c += 1
else:
if c % 2 is 0:
h += 1
c = 1
if c % 2 is 0:
h += 1
print(h)
# g = re.findall(r'G+', x)
# t = re.findall(r'T+', x)
# a = re.findall(r'A+', x)
# c = re.findall(r'C+', x)
# print(g, a, t, c)
```
| 99,747 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You will receive 3 points for solving this problem.
Manao is designing the genetic code for a new type of algae to efficiently produce fuel. Specifically, Manao is focusing on a stretch of DNA that encodes one protein. The stretch of DNA is represented by a string containing only the characters 'A', 'T', 'G' and 'C'.
Manao has determined that if the stretch of DNA contains a maximal sequence of consecutive identical nucleotides that is of even length, then the protein will be nonfunctional. For example, consider a protein described by DNA string "GTTAAAG". It contains four maximal sequences of consecutive identical nucleotides: "G", "TT", "AAA", and "G". The protein is nonfunctional because sequence "TT" has even length.
Manao is trying to obtain a functional protein from the protein he currently has. Manao can insert additional nucleotides into the DNA stretch. Each additional nucleotide is a character from the set {'A', 'T', 'G', 'C'}. Manao wants to determine the minimum number of insertions necessary to make the DNA encode a functional protein.
Input
The input consists of a single line, containing a string s of length n (1 β€ n β€ 100). Each character of s will be from the set {'A', 'T', 'G', 'C'}.
This problem doesn't have subproblems. You will get 3 points for the correct submission.
Output
The program should print on one line a single integer representing the minimum number of 'A', 'T', 'G', 'C' characters that are required to be inserted into the input string in order to make all runs of identical characters have odd length.
Examples
Input
GTTAAAG
Output
1
Input
AACCAACCAAAAC
Output
5
Note
In the first example, it is sufficient to insert a single nucleotide of any type between the two 'T's in the sequence to restore the functionality of the protein.
Submitted Solution:
```
a=input()
a=" ".join(a)
a=a.split()
suma=0
contador=0
for k in range (len(a)):
if a[k]!="*":
igual=a[k]
contador=0
for r in range (k+1,len(a)):
if a[k]==a[r]:
contador=contador+1
a[r]="*"
else:
break
if contador%2!=0:
suma=suma+1
print(suma)
```
Yes
| 99,748 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You will receive 3 points for solving this problem.
Manao is designing the genetic code for a new type of algae to efficiently produce fuel. Specifically, Manao is focusing on a stretch of DNA that encodes one protein. The stretch of DNA is represented by a string containing only the characters 'A', 'T', 'G' and 'C'.
Manao has determined that if the stretch of DNA contains a maximal sequence of consecutive identical nucleotides that is of even length, then the protein will be nonfunctional. For example, consider a protein described by DNA string "GTTAAAG". It contains four maximal sequences of consecutive identical nucleotides: "G", "TT", "AAA", and "G". The protein is nonfunctional because sequence "TT" has even length.
Manao is trying to obtain a functional protein from the protein he currently has. Manao can insert additional nucleotides into the DNA stretch. Each additional nucleotide is a character from the set {'A', 'T', 'G', 'C'}. Manao wants to determine the minimum number of insertions necessary to make the DNA encode a functional protein.
Input
The input consists of a single line, containing a string s of length n (1 β€ n β€ 100). Each character of s will be from the set {'A', 'T', 'G', 'C'}.
This problem doesn't have subproblems. You will get 3 points for the correct submission.
Output
The program should print on one line a single integer representing the minimum number of 'A', 'T', 'G', 'C' characters that are required to be inserted into the input string in order to make all runs of identical characters have odd length.
Examples
Input
GTTAAAG
Output
1
Input
AACCAACCAAAAC
Output
5
Note
In the first example, it is sufficient to insert a single nucleotide of any type between the two 'T's in the sequence to restore the functionality of the protein.
Submitted Solution:
```
s=input()
cnts = []
cnt=1
for i in range(1,len(s)):
if s[i] == s[i-1]:
cnt+=1
else:
cnts.append(cnt)
cnt = 1
cnts.append(cnt)
print(sum([1*int(cnts[i]%2==0) for i in range(len(cnts))]))
```
Yes
| 99,749 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You will receive 3 points for solving this problem.
Manao is designing the genetic code for a new type of algae to efficiently produce fuel. Specifically, Manao is focusing on a stretch of DNA that encodes one protein. The stretch of DNA is represented by a string containing only the characters 'A', 'T', 'G' and 'C'.
Manao has determined that if the stretch of DNA contains a maximal sequence of consecutive identical nucleotides that is of even length, then the protein will be nonfunctional. For example, consider a protein described by DNA string "GTTAAAG". It contains four maximal sequences of consecutive identical nucleotides: "G", "TT", "AAA", and "G". The protein is nonfunctional because sequence "TT" has even length.
Manao is trying to obtain a functional protein from the protein he currently has. Manao can insert additional nucleotides into the DNA stretch. Each additional nucleotide is a character from the set {'A', 'T', 'G', 'C'}. Manao wants to determine the minimum number of insertions necessary to make the DNA encode a functional protein.
Input
The input consists of a single line, containing a string s of length n (1 β€ n β€ 100). Each character of s will be from the set {'A', 'T', 'G', 'C'}.
This problem doesn't have subproblems. You will get 3 points for the correct submission.
Output
The program should print on one line a single integer representing the minimum number of 'A', 'T', 'G', 'C' characters that are required to be inserted into the input string in order to make all runs of identical characters have odd length.
Examples
Input
GTTAAAG
Output
1
Input
AACCAACCAAAAC
Output
5
Note
In the first example, it is sufficient to insert a single nucleotide of any type between the two 'T's in the sequence to restore the functionality of the protein.
Submitted Solution:
```
n = input()
x = 1
cnt = 0
for i in range(len(n)-1):
if(n[i] == n[i+1]):
x+=1
else:
if(x % 2 == 0):
cnt += 1
x = 1
if(x % 2==0):
print(cnt+1)
else:
print(cnt)
```
Yes
| 99,750 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You will receive 3 points for solving this problem.
Manao is designing the genetic code for a new type of algae to efficiently produce fuel. Specifically, Manao is focusing on a stretch of DNA that encodes one protein. The stretch of DNA is represented by a string containing only the characters 'A', 'T', 'G' and 'C'.
Manao has determined that if the stretch of DNA contains a maximal sequence of consecutive identical nucleotides that is of even length, then the protein will be nonfunctional. For example, consider a protein described by DNA string "GTTAAAG". It contains four maximal sequences of consecutive identical nucleotides: "G", "TT", "AAA", and "G". The protein is nonfunctional because sequence "TT" has even length.
Manao is trying to obtain a functional protein from the protein he currently has. Manao can insert additional nucleotides into the DNA stretch. Each additional nucleotide is a character from the set {'A', 'T', 'G', 'C'}. Manao wants to determine the minimum number of insertions necessary to make the DNA encode a functional protein.
Input
The input consists of a single line, containing a string s of length n (1 β€ n β€ 100). Each character of s will be from the set {'A', 'T', 'G', 'C'}.
This problem doesn't have subproblems. You will get 3 points for the correct submission.
Output
The program should print on one line a single integer representing the minimum number of 'A', 'T', 'G', 'C' characters that are required to be inserted into the input string in order to make all runs of identical characters have odd length.
Examples
Input
GTTAAAG
Output
1
Input
AACCAACCAAAAC
Output
5
Note
In the first example, it is sufficient to insert a single nucleotide of any type between the two 'T's in the sequence to restore the functionality of the protein.
Submitted Solution:
```
import itertools
if __name__ == "__main__":
s = input()
z = [(x[0], len(list(x[1]))) for x in itertools.groupby(s)]
count = 0
for i in z:
if i[1] %2 ==0:
count +=1
print(count)
```
Yes
| 99,751 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You will receive 3 points for solving this problem.
Manao is designing the genetic code for a new type of algae to efficiently produce fuel. Specifically, Manao is focusing on a stretch of DNA that encodes one protein. The stretch of DNA is represented by a string containing only the characters 'A', 'T', 'G' and 'C'.
Manao has determined that if the stretch of DNA contains a maximal sequence of consecutive identical nucleotides that is of even length, then the protein will be nonfunctional. For example, consider a protein described by DNA string "GTTAAAG". It contains four maximal sequences of consecutive identical nucleotides: "G", "TT", "AAA", and "G". The protein is nonfunctional because sequence "TT" has even length.
Manao is trying to obtain a functional protein from the protein he currently has. Manao can insert additional nucleotides into the DNA stretch. Each additional nucleotide is a character from the set {'A', 'T', 'G', 'C'}. Manao wants to determine the minimum number of insertions necessary to make the DNA encode a functional protein.
Input
The input consists of a single line, containing a string s of length n (1 β€ n β€ 100). Each character of s will be from the set {'A', 'T', 'G', 'C'}.
This problem doesn't have subproblems. You will get 3 points for the correct submission.
Output
The program should print on one line a single integer representing the minimum number of 'A', 'T', 'G', 'C' characters that are required to be inserted into the input string in order to make all runs of identical characters have odd length.
Examples
Input
GTTAAAG
Output
1
Input
AACCAACCAAAAC
Output
5
Note
In the first example, it is sufficient to insert a single nucleotide of any type between the two 'T's in the sequence to restore the functionality of the protein.
Submitted Solution:
```
arr = input()
count = 0
insertion = 0
for i in range(1,len(arr)):
if arr[i] == arr[i-1]:
count += 1
else:
if (count+1) % 2 == 0:
insertion += 1
count = 0
print(insertion)
```
No
| 99,752 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You will receive 3 points for solving this problem.
Manao is designing the genetic code for a new type of algae to efficiently produce fuel. Specifically, Manao is focusing on a stretch of DNA that encodes one protein. The stretch of DNA is represented by a string containing only the characters 'A', 'T', 'G' and 'C'.
Manao has determined that if the stretch of DNA contains a maximal sequence of consecutive identical nucleotides that is of even length, then the protein will be nonfunctional. For example, consider a protein described by DNA string "GTTAAAG". It contains four maximal sequences of consecutive identical nucleotides: "G", "TT", "AAA", and "G". The protein is nonfunctional because sequence "TT" has even length.
Manao is trying to obtain a functional protein from the protein he currently has. Manao can insert additional nucleotides into the DNA stretch. Each additional nucleotide is a character from the set {'A', 'T', 'G', 'C'}. Manao wants to determine the minimum number of insertions necessary to make the DNA encode a functional protein.
Input
The input consists of a single line, containing a string s of length n (1 β€ n β€ 100). Each character of s will be from the set {'A', 'T', 'G', 'C'}.
This problem doesn't have subproblems. You will get 3 points for the correct submission.
Output
The program should print on one line a single integer representing the minimum number of 'A', 'T', 'G', 'C' characters that are required to be inserted into the input string in order to make all runs of identical characters have odd length.
Examples
Input
GTTAAAG
Output
1
Input
AACCAACCAAAAC
Output
5
Note
In the first example, it is sufficient to insert a single nucleotide of any type between the two 'T's in the sequence to restore the functionality of the protein.
Submitted Solution:
```
import sys
string = str(sys.stdin.readline())
string = list(string)
string.remove("\n")
def solution(string):
count_A = 0
count_T = 0
count_G = 0
count_C = 0
answer = 0
for i in string:
if i == "A":
count_A += 1
if count_C % 2 == 0 and count_C != 0:
answer+=1
count_C = 0
if count_G % 2 == 0 and count_G != 0:
answer+=1
count_G = 0
if count_T % 2 == 0 and count_T != 0:
answer+=1
count_T = 0
if i == string[-1] and count_A % 2 == 0 and count_A != 0:
answer+=1
if i == "T":
count_T += 1
if count_C % 2 == 0 and count_C != 0:
answer+=1
count_C = 0
if count_G % 2 == 0 and count_G != 0:
answer+=1
count_G = 0
if count_A % 2 == 0 and count_A != 0:
answer+=1
count_A = 0
if i == string[-1] and count_T % 2 == 0 and count_T != 0:
answer+=1
if i == "G":
count_G += 1
if count_C % 2 == 0 and count_C != 0:
answer+=1
count_C = 0
if count_A % 2 == 0 and count_A != 0:
answer+=1
count_A = 0
if count_T % 2 == 0 and count_T != 0:
answer+=1
count_T = 0
if i == string[-1] and count_G % 2 == 0 and count_G != 0:
answer+=1
if i == "C":
count_C += 1
if count_A % 2 == 0 and count_A != 0:
answer+=1
count_A = 0
if count_G % 2 == 0 and count_G != 0:
answer+=1
count_G = 0
if count_T % 2 == 0 and count_T != 0:
answer+=1
count_T = 0
if i == string[-1] and count_C % 2 == 0 and count_C != 0:
answer+=1
return print(answer)
solution(string)
```
No
| 99,753 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You will receive 3 points for solving this problem.
Manao is designing the genetic code for a new type of algae to efficiently produce fuel. Specifically, Manao is focusing on a stretch of DNA that encodes one protein. The stretch of DNA is represented by a string containing only the characters 'A', 'T', 'G' and 'C'.
Manao has determined that if the stretch of DNA contains a maximal sequence of consecutive identical nucleotides that is of even length, then the protein will be nonfunctional. For example, consider a protein described by DNA string "GTTAAAG". It contains four maximal sequences of consecutive identical nucleotides: "G", "TT", "AAA", and "G". The protein is nonfunctional because sequence "TT" has even length.
Manao is trying to obtain a functional protein from the protein he currently has. Manao can insert additional nucleotides into the DNA stretch. Each additional nucleotide is a character from the set {'A', 'T', 'G', 'C'}. Manao wants to determine the minimum number of insertions necessary to make the DNA encode a functional protein.
Input
The input consists of a single line, containing a string s of length n (1 β€ n β€ 100). Each character of s will be from the set {'A', 'T', 'G', 'C'}.
This problem doesn't have subproblems. You will get 3 points for the correct submission.
Output
The program should print on one line a single integer representing the minimum number of 'A', 'T', 'G', 'C' characters that are required to be inserted into the input string in order to make all runs of identical characters have odd length.
Examples
Input
GTTAAAG
Output
1
Input
AACCAACCAAAAC
Output
5
Note
In the first example, it is sufficient to insert a single nucleotide of any type between the two 'T's in the sequence to restore the functionality of the protein.
Submitted Solution:
```
s=input()
cnts = []
cnt=1
for i in range(1,len(s)):
if s[i] == s[i-1]:
cnt+=1
else:
cnts.append(cnt)
cnt = 1
print(sum([1*int(cnts[i]%2==0) for i in range(len(cnts))]))
```
No
| 99,754 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You will receive 3 points for solving this problem.
Manao is designing the genetic code for a new type of algae to efficiently produce fuel. Specifically, Manao is focusing on a stretch of DNA that encodes one protein. The stretch of DNA is represented by a string containing only the characters 'A', 'T', 'G' and 'C'.
Manao has determined that if the stretch of DNA contains a maximal sequence of consecutive identical nucleotides that is of even length, then the protein will be nonfunctional. For example, consider a protein described by DNA string "GTTAAAG". It contains four maximal sequences of consecutive identical nucleotides: "G", "TT", "AAA", and "G". The protein is nonfunctional because sequence "TT" has even length.
Manao is trying to obtain a functional protein from the protein he currently has. Manao can insert additional nucleotides into the DNA stretch. Each additional nucleotide is a character from the set {'A', 'T', 'G', 'C'}. Manao wants to determine the minimum number of insertions necessary to make the DNA encode a functional protein.
Input
The input consists of a single line, containing a string s of length n (1 β€ n β€ 100). Each character of s will be from the set {'A', 'T', 'G', 'C'}.
This problem doesn't have subproblems. You will get 3 points for the correct submission.
Output
The program should print on one line a single integer representing the minimum number of 'A', 'T', 'G', 'C' characters that are required to be inserted into the input string in order to make all runs of identical characters have odd length.
Examples
Input
GTTAAAG
Output
1
Input
AACCAACCAAAAC
Output
5
Note
In the first example, it is sufficient to insert a single nucleotide of any type between the two 'T's in the sequence to restore the functionality of the protein.
Submitted Solution:
```
import re
x = input()
l = [0 for i in range(len(x))]
c, h = 1, 0
for i in range(len(x) - 1):
l, r = x[i], x[i + 1]
if l is r:
c += 1
else:
if c % 2 is 0:
h += 1
c = 1
print(h)
```
No
| 99,755 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One of the most important products of the R1 company is a popular @r1.com mail service. The R1 mailboxes receive and send millions of emails every day.
Today, the online news thundered with terrible information. The R1 database crashed and almost no data could be saved except for one big string. The developers assume that the string contains the letters of some users of the R1 mail. Recovering letters is a tedious mostly manual work. So before you start this process, it was decided to estimate the difficulty of recovering. Namely, we need to calculate the number of different substrings of the saved string that form correct e-mail addresses.
We assume that valid addresses are only the e-mail addresses which meet the following criteria:
* the address should begin with a non-empty sequence of letters, numbers, characters '_', starting with a letter;
* then must go character '@';
* then must go a non-empty sequence of letters or numbers;
* then must go character '.';
* the address must end with a non-empty sequence of letters.
You got lucky again and the job was entrusted to you! Please note that the substring is several consecutive characters in a string. Two substrings, one consisting of the characters of the string with numbers l1, l1 + 1, l1 + 2, ..., r1 and the other one consisting of the characters of the string with numbers l2, l2 + 1, l2 + 2, ..., r2, are considered distinct if l1 β l2 or r1 β r2.
Input
The first and the only line contains the sequence of characters s1s2... sn (1 β€ n β€ 106) β the saved string. It is guaranteed that the given string contains only small English letters, digits and characters '.', '_', '@'.
Output
Print in a single line the number of substrings that are valid e-mail addresses.
Examples
Input
gerald.agapov1991@gmail.com
Output
18
Input
x@x.x@x.x_e_@r1.com
Output
8
Input
a___@1.r
Output
1
Input
.asd123__..@
Output
0
Note
In the first test case all the substrings that are correct e-mail addresses begin from one of the letters of the word agapov and end in one of the letters of the word com.
In the second test case note that the e-mail x@x.x is considered twice in the answer. Note that in this example the e-mail entries overlap inside the string.
Tags: implementation
Correct Solution:
```
from sys import stdin, stdout, setrecursionlimit
input = stdin.readline
# setrecursionlimit(int(1e6))
inf = float('inf')
from functools import cmp_to_key
from collections import defaultdict as dd
from collections import Counter, deque
from heapq import *
import math
from math import floor, ceil, sqrt
def geti(): return map(int, input().strip().split())
def getl(): return list(map(int, input().strip().split()))
def getis(): return map(str, input().strip().split())
def getls(): return list(map(str, input().strip().split()))
def gets(): return input().strip()
def geta(): return int(input())
def print_s(s): stdout.write(s+'\n')
def solve():
s = gets()
before = after = 0
n = len(s)
i = 0
ans = 0
while i < n:
while i < n and s[i] != '@':
if s[i].isalpha():
before += 1
if s[i] == '.':
before = 0
i += 1
# print('b', before)
if i < n and s[i] == '@':
i += 1
ok = True
temp = 0
good = False
while i < n and s[i] != '.':
if s[i] == '_' or s[i] == '@':
ok = False
break
if s[i].isalpha():
temp += 1
i += 1
good = True
if not ok or not good:
before = temp
after = 0
continue
if i < n and s[i] == '.':
i += 1
while i < n and s[i].isalpha():
after += 1
i += 1
# print('a', after)
ans += before * after
before = after
after = 0
print(ans)
if __name__=='__main__':
solve()
```
| 99,756 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One of the most important products of the R1 company is a popular @r1.com mail service. The R1 mailboxes receive and send millions of emails every day.
Today, the online news thundered with terrible information. The R1 database crashed and almost no data could be saved except for one big string. The developers assume that the string contains the letters of some users of the R1 mail. Recovering letters is a tedious mostly manual work. So before you start this process, it was decided to estimate the difficulty of recovering. Namely, we need to calculate the number of different substrings of the saved string that form correct e-mail addresses.
We assume that valid addresses are only the e-mail addresses which meet the following criteria:
* the address should begin with a non-empty sequence of letters, numbers, characters '_', starting with a letter;
* then must go character '@';
* then must go a non-empty sequence of letters or numbers;
* then must go character '.';
* the address must end with a non-empty sequence of letters.
You got lucky again and the job was entrusted to you! Please note that the substring is several consecutive characters in a string. Two substrings, one consisting of the characters of the string with numbers l1, l1 + 1, l1 + 2, ..., r1 and the other one consisting of the characters of the string with numbers l2, l2 + 1, l2 + 2, ..., r2, are considered distinct if l1 β l2 or r1 β r2.
Input
The first and the only line contains the sequence of characters s1s2... sn (1 β€ n β€ 106) β the saved string. It is guaranteed that the given string contains only small English letters, digits and characters '.', '_', '@'.
Output
Print in a single line the number of substrings that are valid e-mail addresses.
Examples
Input
gerald.agapov1991@gmail.com
Output
18
Input
x@x.x@x.x_e_@r1.com
Output
8
Input
a___@1.r
Output
1
Input
.asd123__..@
Output
0
Note
In the first test case all the substrings that are correct e-mail addresses begin from one of the letters of the word agapov and end in one of the letters of the word com.
In the second test case note that the e-mail x@x.x is considered twice in the answer. Note that in this example the e-mail entries overlap inside the string.
Submitted Solution:
```
from sys import stdin, stdout, setrecursionlimit
input = stdin.readline
# setrecursionlimit(int(1e6))
inf = float('inf')
from functools import cmp_to_key
from collections import defaultdict as dd
from collections import Counter, deque
from heapq import *
import math
from math import floor, ceil, sqrt
def geti(): return map(int, input().strip().split())
def getl(): return list(map(int, input().strip().split()))
def getis(): return map(str, input().strip().split())
def getls(): return list(map(str, input().strip().split()))
def gets(): return input().strip()
def geta(): return int(input())
def print_s(s): stdout.write(s+'\n')
def solve():
s = gets()
before = after = 0
n = len(s)
i = 0
ans = 0
while i < n:
while i < n and s[i] != '@':
if s[i].isalpha():
before += 1
if s[i] == '.':
before = 0
i += 1
# print('b', before)
if i < n and s[i] == '@':
i += 1
ok = True
temp = 0
while i < n and s[i] != '.':
if s[i] == '_' or s[i] == '@':
ok = False
break
if s[i].isalpha():
temp += 1
i += 1
if not ok:
before = temp
after = 0
continue
if i < n and s[i] == '.':
i += 1
while i < n and s[i].isalpha():
after += 1
i += 1
# print('a', after)
ans += before * after
before = after
after = 0
print(ans)
if __name__=='__main__':
solve()
```
No
| 99,757 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One of the most important products of the R1 company is a popular @r1.com mail service. The R1 mailboxes receive and send millions of emails every day.
Today, the online news thundered with terrible information. The R1 database crashed and almost no data could be saved except for one big string. The developers assume that the string contains the letters of some users of the R1 mail. Recovering letters is a tedious mostly manual work. So before you start this process, it was decided to estimate the difficulty of recovering. Namely, we need to calculate the number of different substrings of the saved string that form correct e-mail addresses.
We assume that valid addresses are only the e-mail addresses which meet the following criteria:
* the address should begin with a non-empty sequence of letters, numbers, characters '_', starting with a letter;
* then must go character '@';
* then must go a non-empty sequence of letters or numbers;
* then must go character '.';
* the address must end with a non-empty sequence of letters.
You got lucky again and the job was entrusted to you! Please note that the substring is several consecutive characters in a string. Two substrings, one consisting of the characters of the string with numbers l1, l1 + 1, l1 + 2, ..., r1 and the other one consisting of the characters of the string with numbers l2, l2 + 1, l2 + 2, ..., r2, are considered distinct if l1 β l2 or r1 β r2.
Input
The first and the only line contains the sequence of characters s1s2... sn (1 β€ n β€ 106) β the saved string. It is guaranteed that the given string contains only small English letters, digits and characters '.', '_', '@'.
Output
Print in a single line the number of substrings that are valid e-mail addresses.
Examples
Input
gerald.agapov1991@gmail.com
Output
18
Input
x@x.x@x.x_e_@r1.com
Output
8
Input
a___@1.r
Output
1
Input
.asd123__..@
Output
0
Note
In the first test case all the substrings that are correct e-mail addresses begin from one of the letters of the word agapov and end in one of the letters of the word com.
In the second test case note that the e-mail x@x.x is considered twice in the answer. Note that in this example the e-mail entries overlap inside the string.
Submitted Solution:
```
from sys import stdin, stdout, setrecursionlimit
input = stdin.readline
# setrecursionlimit(int(1e6))
inf = float('inf')
from functools import cmp_to_key
from collections import defaultdict as dd
from collections import Counter, deque
from heapq import *
import math
from math import floor, ceil, sqrt
def geti(): return map(int, input().strip().split())
def getl(): return list(map(int, input().strip().split()))
def getis(): return map(str, input().strip().split())
def getls(): return list(map(str, input().strip().split()))
def gets(): return input().strip()
def geta(): return int(input())
def print_s(s): stdout.write(s+'\n')
def solve():
s = gets()
before = after = 0
n = len(s)
i = 0
ans = 0
while i < n:
while i < n and s[i] != '@':
if s[i].isalpha():
before += 1
if s[i] == '.':
before = 0
i += 1
# print('b', before)
if i < n and s[i] == '@':
i += 1
ok = True
temp = 0
while i < n and s[i] != '.':
if s[i] == '_' or s[i] == '@':
ok = False
break
if s[i].isalpha():
temp += 1
i += 1
if not ok:
before = temp
continue
if i < n and s[i] == '.':
i += 1
while i < n and s[i].isalpha():
after += 1
i += 1
# print('a', after)
ans += before * after
before = after
after = 0
print(ans)
if __name__=='__main__':
solve()
```
No
| 99,758 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One of the most important products of the R1 company is a popular @r1.com mail service. The R1 mailboxes receive and send millions of emails every day.
Today, the online news thundered with terrible information. The R1 database crashed and almost no data could be saved except for one big string. The developers assume that the string contains the letters of some users of the R1 mail. Recovering letters is a tedious mostly manual work. So before you start this process, it was decided to estimate the difficulty of recovering. Namely, we need to calculate the number of different substrings of the saved string that form correct e-mail addresses.
We assume that valid addresses are only the e-mail addresses which meet the following criteria:
* the address should begin with a non-empty sequence of letters, numbers, characters '_', starting with a letter;
* then must go character '@';
* then must go a non-empty sequence of letters or numbers;
* then must go character '.';
* the address must end with a non-empty sequence of letters.
You got lucky again and the job was entrusted to you! Please note that the substring is several consecutive characters in a string. Two substrings, one consisting of the characters of the string with numbers l1, l1 + 1, l1 + 2, ..., r1 and the other one consisting of the characters of the string with numbers l2, l2 + 1, l2 + 2, ..., r2, are considered distinct if l1 β l2 or r1 β r2.
Input
The first and the only line contains the sequence of characters s1s2... sn (1 β€ n β€ 106) β the saved string. It is guaranteed that the given string contains only small English letters, digits and characters '.', '_', '@'.
Output
Print in a single line the number of substrings that are valid e-mail addresses.
Examples
Input
gerald.agapov1991@gmail.com
Output
18
Input
x@x.x@x.x_e_@r1.com
Output
8
Input
a___@1.r
Output
1
Input
.asd123__..@
Output
0
Note
In the first test case all the substrings that are correct e-mail addresses begin from one of the letters of the word agapov and end in one of the letters of the word com.
In the second test case note that the e-mail x@x.x is considered twice in the answer. Note that in this example the e-mail entries overlap inside the string.
Submitted Solution:
```
a=input()
if a=='gerald.agapov1991@gmail.com':
print(18)
elif a=='x@x.x@x.x_e_@r1.com':
print(8)
elif a=='a___@1.r':
print(1)
elif a=='.asd123__..@':
print(0)
a=a.split('@')
if ((len(a)==0) or (a[0]=='') or (a[1]=='') or (a[1].split('.')[1]=='')):
print(0)
```
No
| 99,759 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One of the most important products of the R1 company is a popular @r1.com mail service. The R1 mailboxes receive and send millions of emails every day.
Today, the online news thundered with terrible information. The R1 database crashed and almost no data could be saved except for one big string. The developers assume that the string contains the letters of some users of the R1 mail. Recovering letters is a tedious mostly manual work. So before you start this process, it was decided to estimate the difficulty of recovering. Namely, we need to calculate the number of different substrings of the saved string that form correct e-mail addresses.
We assume that valid addresses are only the e-mail addresses which meet the following criteria:
* the address should begin with a non-empty sequence of letters, numbers, characters '_', starting with a letter;
* then must go character '@';
* then must go a non-empty sequence of letters or numbers;
* then must go character '.';
* the address must end with a non-empty sequence of letters.
You got lucky again and the job was entrusted to you! Please note that the substring is several consecutive characters in a string. Two substrings, one consisting of the characters of the string with numbers l1, l1 + 1, l1 + 2, ..., r1 and the other one consisting of the characters of the string with numbers l2, l2 + 1, l2 + 2, ..., r2, are considered distinct if l1 β l2 or r1 β r2.
Input
The first and the only line contains the sequence of characters s1s2... sn (1 β€ n β€ 106) β the saved string. It is guaranteed that the given string contains only small English letters, digits and characters '.', '_', '@'.
Output
Print in a single line the number of substrings that are valid e-mail addresses.
Examples
Input
gerald.agapov1991@gmail.com
Output
18
Input
x@x.x@x.x_e_@r1.com
Output
8
Input
a___@1.r
Output
1
Input
.asd123__..@
Output
0
Note
In the first test case all the substrings that are correct e-mail addresses begin from one of the letters of the word agapov and end in one of the letters of the word com.
In the second test case note that the e-mail x@x.x is considered twice in the answer. Note that in this example the e-mail entries overlap inside the string.
Submitted Solution:
```
st = input()
prsnt_cur = 0
len_st = len(st)
def get_email(st):
global prsnt_cur, len_st
start = prsnt_cur
#user name checking
if not('a' <= st[prsnt_cur] and st[prsnt_cur] <= 'z'):
prsnt_cur += 1
return False
while True:
if st[prsnt_cur] == '@':
prsnt_cur += 1
break
elif not ( ('a' <= st[prsnt_cur] and st[prsnt_cur] <= 'z') or ( '1' <= st[prsnt_cur] and st[prsnt_cur] <= '9') or ( st[prsnt_cur]== '_') ) :
prsnt_cur += 1
return False
else:
prsnt_cur += 1
if prsnt_cur == len_st:
return False
#service provider
if st[prsnt_cur]== '.':
prsnt_cur +=1
return False
while True:
if st[prsnt_cur] == '.':
prsnt_cur +=1
break
elif not (('a' <= st[prsnt_cur] and st[prsnt_cur] <= 'z') or ( '1' <= st[prsnt_cur] and st[prsnt_cur] <= '9')) :
prsnt_cur += 1
return False
else:
prsnt_cur +=1
if prsnt_cur == len_st:
return False
#dom check
if not ('a' <= st[prsnt_cur] and st[prsnt_cur] <= 'z'):
prsnt_cur += 1
return False
while True:
if not ('a' <= st[prsnt_cur] and st[prsnt_cur] <= 'z'):
prsnt_cur += 1
break
else:
prsnt_cur +=1
if prsnt_cur == len_st:
break
return st[start:prsnt_cur]
def sub_st(st):
letters_in_un = 0
letters_in_dom=0
i = 0
while st[i]!='@':
if 'a' <= st[i] and st[i] <='z':
letters_in_un += 1
i +=1
i = len(st) - 1
while True:
if st[i]!= '.':
letters_in_dom +=1
else:
break
i -=1
return letters_in_un * letters_in_dom
email=''
result = 0
while prsnt_cur < len_st:
email = get_email(st)
if email!= False:
result += sub_st(email)
print(result)
```
No
| 99,760 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text.
Input
The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading.
Output
If Vasya can write the given anonymous letter, print YES, otherwise print NO
Examples
Input
Instead of dogging Your footsteps it disappears but you dont notice anything
where is your dog
Output
NO
Input
Instead of dogging Your footsteps it disappears but you dont notice anything
Your dog is upstears
Output
YES
Input
Instead of dogging your footsteps it disappears but you dont notice anything
Your dog is upstears
Output
NO
Input
abcdefg hijk
k j i h g f e d c b a
Output
YES
Tags: implementation, strings
Correct Solution:
```
heading = input()
text = input()
hcounts = {}
for char in heading:
if char != ' ':
if char in hcounts:
hcounts[char] += 1
else:
hcounts[char] = 1
impos = False
for char in text:
if char != ' ':
if char in hcounts:
hcounts[char] -= 1
if hcounts[char] < 0:
impos = True
break
else:
impos = True
if impos:
print('NO')
else:
print('YES')
```
| 99,761 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text.
Input
The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading.
Output
If Vasya can write the given anonymous letter, print YES, otherwise print NO
Examples
Input
Instead of dogging Your footsteps it disappears but you dont notice anything
where is your dog
Output
NO
Input
Instead of dogging Your footsteps it disappears but you dont notice anything
Your dog is upstears
Output
YES
Input
Instead of dogging your footsteps it disappears but you dont notice anything
Your dog is upstears
Output
NO
Input
abcdefg hijk
k j i h g f e d c b a
Output
YES
Tags: implementation, strings
Correct Solution:
```
def chrnum(s,a):
ans=0
for i in s:
if i==a:ans+=1
return ans
s1=input()
s2=input()
s1=s1.replace(' ','')
s2=s2.replace(' ','')
def fn(s1,s2):
for i in s2:
if chrnum(s2,i)>chrnum(s1,i):return 'NO'
return 'YES'
print(fn(s1,s2))
```
| 99,762 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text.
Input
The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading.
Output
If Vasya can write the given anonymous letter, print YES, otherwise print NO
Examples
Input
Instead of dogging Your footsteps it disappears but you dont notice anything
where is your dog
Output
NO
Input
Instead of dogging Your footsteps it disappears but you dont notice anything
Your dog is upstears
Output
YES
Input
Instead of dogging your footsteps it disappears but you dont notice anything
Your dog is upstears
Output
NO
Input
abcdefg hijk
k j i h g f e d c b a
Output
YES
Tags: implementation, strings
Correct Solution:
```
heading = input()
text = input()
for letter in text:
if letter != ' ':
if letter in heading:
heading = heading.replace(letter, '', 1)
else:
print("NO")
exit()
print("YES")
```
| 99,763 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text.
Input
The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading.
Output
If Vasya can write the given anonymous letter, print YES, otherwise print NO
Examples
Input
Instead of dogging Your footsteps it disappears but you dont notice anything
where is your dog
Output
NO
Input
Instead of dogging Your footsteps it disappears but you dont notice anything
Your dog is upstears
Output
YES
Input
Instead of dogging your footsteps it disappears but you dont notice anything
Your dog is upstears
Output
NO
Input
abcdefg hijk
k j i h g f e d c b a
Output
YES
Tags: implementation, strings
Correct Solution:
```
s1 = list(input().replace(' ', ''))
s2 = list(input().replace(' ', ''))
s3 = []
for i in s2:
if i in s1:
s1.remove(i)
s3.append(i)
if len(s3) == len(s2):
print('YES')
else:
print('NO')
```
| 99,764 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text.
Input
The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading.
Output
If Vasya can write the given anonymous letter, print YES, otherwise print NO
Examples
Input
Instead of dogging Your footsteps it disappears but you dont notice anything
where is your dog
Output
NO
Input
Instead of dogging Your footsteps it disappears but you dont notice anything
Your dog is upstears
Output
YES
Input
Instead of dogging your footsteps it disappears but you dont notice anything
Your dog is upstears
Output
NO
Input
abcdefg hijk
k j i h g f e d c b a
Output
YES
Tags: implementation, strings
Correct Solution:
```
s1=input()
s2=input()
b=list(set(s2))
if ' ' in b:
b.remove(' ')
c=0
for i in b:
if s2.count(i)<=s1.count(i):
c+=1
if c==len(b):
print('YES')
else:
print('NO')
```
| 99,765 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text.
Input
The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading.
Output
If Vasya can write the given anonymous letter, print YES, otherwise print NO
Examples
Input
Instead of dogging Your footsteps it disappears but you dont notice anything
where is your dog
Output
NO
Input
Instead of dogging Your footsteps it disappears but you dont notice anything
Your dog is upstears
Output
YES
Input
Instead of dogging your footsteps it disappears but you dont notice anything
Your dog is upstears
Output
NO
Input
abcdefg hijk
k j i h g f e d c b a
Output
YES
Tags: implementation, strings
Correct Solution:
```
# Long Contest 1, Problem J
head = input()
text = input()
hm = {}
for ch in head:
if ch == ' ':
continue
hm[ch] = hm.get(ch, 0)+1
tm = {}
for ch in text:
if ch == ' ':
continue
tm[ch] = tm.get(ch, 0)+1
flag = True
for ch, tcount in tm.items():
hcount = hm.get(ch, 0)
if hcount == 0 or hcount < tcount:
flag = False
break
if flag:
print('YES')
else:
print('NO')
```
| 99,766 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text.
Input
The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading.
Output
If Vasya can write the given anonymous letter, print YES, otherwise print NO
Examples
Input
Instead of dogging Your footsteps it disappears but you dont notice anything
where is your dog
Output
NO
Input
Instead of dogging Your footsteps it disappears but you dont notice anything
Your dog is upstears
Output
YES
Input
Instead of dogging your footsteps it disappears but you dont notice anything
Your dog is upstears
Output
NO
Input
abcdefg hijk
k j i h g f e d c b a
Output
YES
Tags: implementation, strings
Correct Solution:
```
s = input()
text = input()
headers = {}
for char in s:
try: headers[char] += 1
except: headers[char] = 0
for char in text:
if char == ' ': continue
if char in headers:
if headers[char] >= 0:
headers[char] -= 1
else:
print('NO')
exit()
else:
print('NO')
exit()
print('YES')
```
| 99,767 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text.
Input
The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading.
Output
If Vasya can write the given anonymous letter, print YES, otherwise print NO
Examples
Input
Instead of dogging Your footsteps it disappears but you dont notice anything
where is your dog
Output
NO
Input
Instead of dogging Your footsteps it disappears but you dont notice anything
Your dog is upstears
Output
YES
Input
Instead of dogging your footsteps it disappears but you dont notice anything
Your dog is upstears
Output
NO
Input
abcdefg hijk
k j i h g f e d c b a
Output
YES
Tags: implementation, strings
Correct Solution:
```
def removeSpace(x):
res = ""
for _ in range(len(x)):
if x[_] != " ":
res += x[_]
return res
string1 = sorted(removeSpace(input()))
string2 = sorted(removeSpace(input()))
temp = 0
count = len(string2)
for i in range(count):
if string2[i] in string1:
string1.remove(string2[i])
temp += 1
if temp == count:
print("YES")
else:
print("NO")
```
| 99,768 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text.
Input
The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading.
Output
If Vasya can write the given anonymous letter, print YES, otherwise print NO
Examples
Input
Instead of dogging Your footsteps it disappears but you dont notice anything
where is your dog
Output
NO
Input
Instead of dogging Your footsteps it disappears but you dont notice anything
Your dog is upstears
Output
YES
Input
Instead of dogging your footsteps it disappears but you dont notice anything
Your dog is upstears
Output
NO
Input
abcdefg hijk
k j i h g f e d c b a
Output
YES
Submitted Solution:
```
from collections import Counter
class CodeforcesTask43BSolution:
def __init__(self):
self.result = ''
self.s1 = ''
self.s2 = ''
def read_input(self):
self.s1 = input().replace(" ", "")
self.s2 = input().replace(" ", "")
def process_task(self):
avail = Counter(self.s1)
needed = Counter(self.s2)
can = True
for key in needed.keys():
if key in avail:
if avail[key] < needed[key]:
can = False
break
else:
can = False
break
self.result = "YES" if can else "NO"
def get_result(self):
return self.result
if __name__ == "__main__":
Solution = CodeforcesTask43BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())
```
Yes
| 99,769 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text.
Input
The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading.
Output
If Vasya can write the given anonymous letter, print YES, otherwise print NO
Examples
Input
Instead of dogging Your footsteps it disappears but you dont notice anything
where is your dog
Output
NO
Input
Instead of dogging Your footsteps it disappears but you dont notice anything
Your dog is upstears
Output
YES
Input
Instead of dogging your footsteps it disappears but you dont notice anything
Your dog is upstears
Output
NO
Input
abcdefg hijk
k j i h g f e d c b a
Output
YES
Submitted Solution:
```
h =input()
s =input()
c=0
for i in s:
if(i!=" "):
if(s.count(i)>h.count(i)):
c=c+1
print("YES" if(c==0) else "NO")
```
Yes
| 99,770 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text.
Input
The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading.
Output
If Vasya can write the given anonymous letter, print YES, otherwise print NO
Examples
Input
Instead of dogging Your footsteps it disappears but you dont notice anything
where is your dog
Output
NO
Input
Instead of dogging Your footsteps it disappears but you dont notice anything
Your dog is upstears
Output
YES
Input
Instead of dogging your footsteps it disappears but you dont notice anything
Your dog is upstears
Output
NO
Input
abcdefg hijk
k j i h g f e d c b a
Output
YES
Submitted Solution:
```
s_one = input()
s_one = list(s_one)
s_one = list(filter((" ").__ne__, s_one))
s_two = input()
s_two = list(s_two)
s_two = list(filter((" ").__ne__, s_two))
no = False
for c in s_two:
if c not in s_one:
print("NO")
no = True
break
else:
s_one.remove(c)
if no == False:
print("YES")
```
Yes
| 99,771 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text.
Input
The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading.
Output
If Vasya can write the given anonymous letter, print YES, otherwise print NO
Examples
Input
Instead of dogging Your footsteps it disappears but you dont notice anything
where is your dog
Output
NO
Input
Instead of dogging Your footsteps it disappears but you dont notice anything
Your dog is upstears
Output
YES
Input
Instead of dogging your footsteps it disappears but you dont notice anything
Your dog is upstears
Output
NO
Input
abcdefg hijk
k j i h g f e d c b a
Output
YES
Submitted Solution:
```
from collections import Counter
def main():
heading = input()
text = input()
hcnt = Counter(heading)
htxt = Counter(text)
del hcnt[' ']
del htxt[' ']
for k, v in htxt.items():
if hcnt[k] < v:
print('NO')
return
print('YES')
if __name__ == "__main__":
main()
```
Yes
| 99,772 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text.
Input
The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading.
Output
If Vasya can write the given anonymous letter, print YES, otherwise print NO
Examples
Input
Instead of dogging Your footsteps it disappears but you dont notice anything
where is your dog
Output
NO
Input
Instead of dogging Your footsteps it disappears but you dont notice anything
Your dog is upstears
Output
YES
Input
Instead of dogging your footsteps it disappears but you dont notice anything
Your dog is upstears
Output
NO
Input
abcdefg hijk
k j i h g f e d c b a
Output
YES
Submitted Solution:
```
n = input()
heading = []
for ele in n :
heading.append(ele)
x = input()
text = []
for ele in x:
text.append(ele)
head = []
for ele in heading:
if ele.strip():
head.append(ele)
tex = []
for ele in text:
if ele.strip():
tex.append(ele)
#print("heading:",head)
#print("text:",tex)
for ele in tex:
if ele not in head:
print("NO")
exit()
tex.remove(ele)
head.remove(ele)
print("YES")
```
No
| 99,773 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text.
Input
The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading.
Output
If Vasya can write the given anonymous letter, print YES, otherwise print NO
Examples
Input
Instead of dogging Your footsteps it disappears but you dont notice anything
where is your dog
Output
NO
Input
Instead of dogging Your footsteps it disappears but you dont notice anything
Your dog is upstears
Output
YES
Input
Instead of dogging your footsteps it disappears but you dont notice anything
Your dog is upstears
Output
NO
Input
abcdefg hijk
k j i h g f e d c b a
Output
YES
Submitted Solution:
```
import math as M
import heapq as H
import itertools as I
import collections as C
from itertools import groupby as gb
from math import log10 ,log2,ceil,factorial as f
from itertools import combinations_with_replacement as com
arr = lambda x :map(x,input().split())
var = lambda x:x(input())
s1 = var(str)
s2 = var(str)
s1 = C.Counter(s1)
s2 = C.Counter(s2)
f=0
try:
for i in s2:
if s2[i]>s1[i]:
f=1
except:
f=1
if f==1:print("NO")
else:print("YES")
```
No
| 99,774 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text.
Input
The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading.
Output
If Vasya can write the given anonymous letter, print YES, otherwise print NO
Examples
Input
Instead of dogging Your footsteps it disappears but you dont notice anything
where is your dog
Output
NO
Input
Instead of dogging Your footsteps it disappears but you dont notice anything
Your dog is upstears
Output
YES
Input
Instead of dogging your footsteps it disappears but you dont notice anything
Your dog is upstears
Output
NO
Input
abcdefg hijk
k j i h g f e d c b a
Output
YES
Submitted Solution:
```
import collections as c
a=input().replace(' ','')
b=input().replace(' ','')
#print(a,b)
aa=c.Counter(a)
bb=c.Counter(b)
print("YES") if aa-bb else print("NO")
```
No
| 99,775 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text.
Input
The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading.
Output
If Vasya can write the given anonymous letter, print YES, otherwise print NO
Examples
Input
Instead of dogging Your footsteps it disappears but you dont notice anything
where is your dog
Output
NO
Input
Instead of dogging Your footsteps it disappears but you dont notice anything
Your dog is upstears
Output
YES
Input
Instead of dogging your footsteps it disappears but you dont notice anything
Your dog is upstears
Output
NO
Input
abcdefg hijk
k j i h g f e d c b a
Output
YES
Submitted Solution:
```
s1 = input()
s2 = input()
flag = True
for i in range(len(s2)):
if not s1.__contains__(s2[i]):
flag = False
break
else:
if s1.__contains__(s2[i]):
s1.replace(s2[i], '')
s2.replace(s2[i], '')
else:
flag = False
break
if flag:
print('YES')
else:
print('NO')
```
No
| 99,776 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's denote as <image> the number of bits set ('1' bits) in the binary representation of the non-negative integer x.
You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l β€ x β€ r, and <image> is maximum possible. If there are multiple such numbers find the smallest of them.
Input
The first line contains integer n β the number of queries (1 β€ n β€ 10000).
Each of the following n lines contain two integers li, ri β the arguments for the corresponding query (0 β€ li β€ ri β€ 1018).
Output
For each query print the answer in a separate line.
Examples
Input
3
1 2
2 4
1 10
Output
1
3
7
Note
The binary representations of numbers from 1 to 10 are listed below:
110 = 12
210 = 102
310 = 112
410 = 1002
510 = 1012
610 = 1102
710 = 1112
810 = 10002
910 = 10012
1010 = 10102
Tags: bitmasks, constructive algorithms
Correct Solution:
```
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")
# ------------------------------
from math import factorial
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush
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())
def comb(n, m): return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0
def perm(n, m): return factorial(n) // (factorial(n - m)) if n >= m else 0
def mdis(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2)
def ctd(chr): return ord(chr)-ord("a")
mod = 998244353
INF = float('inf')
# ------------------------------
def main():
for _ in range(N()):
l, r = RL()
bl = int(r).bit_length()
res = 0
for i in range(bl-1, -1, -1):
nb = 1<<i
if l&nb==r&nb:
if l&nb==nb: res+=nb
else:
res+=(1<<i)-1
if '0' not in bin(r)[-i-1:]: res+=1<<i
break
print(res)
if __name__ == "__main__":
main()
```
| 99,777 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's denote as <image> the number of bits set ('1' bits) in the binary representation of the non-negative integer x.
You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l β€ x β€ r, and <image> is maximum possible. If there are multiple such numbers find the smallest of them.
Input
The first line contains integer n β the number of queries (1 β€ n β€ 10000).
Each of the following n lines contain two integers li, ri β the arguments for the corresponding query (0 β€ li β€ ri β€ 1018).
Output
For each query print the answer in a separate line.
Examples
Input
3
1 2
2 4
1 10
Output
1
3
7
Note
The binary representations of numbers from 1 to 10 are listed below:
110 = 12
210 = 102
310 = 112
410 = 1002
510 = 1012
610 = 1102
710 = 1112
810 = 10002
910 = 10012
1010 = 10102
Tags: bitmasks, constructive algorithms
Correct Solution:
```
n = int(input())
for i in range(n):
l,r = map(int,input().split())
while ((l|(l+1))<=r): l|=(l+1)
print(l)
```
| 99,778 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's denote as <image> the number of bits set ('1' bits) in the binary representation of the non-negative integer x.
You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l β€ x β€ r, and <image> is maximum possible. If there are multiple such numbers find the smallest of them.
Input
The first line contains integer n β the number of queries (1 β€ n β€ 10000).
Each of the following n lines contain two integers li, ri β the arguments for the corresponding query (0 β€ li β€ ri β€ 1018).
Output
For each query print the answer in a separate line.
Examples
Input
3
1 2
2 4
1 10
Output
1
3
7
Note
The binary representations of numbers from 1 to 10 are listed below:
110 = 12
210 = 102
310 = 112
410 = 1002
510 = 1012
610 = 1102
710 = 1112
810 = 10002
910 = 10012
1010 = 10102
Tags: bitmasks, constructive algorithms
Correct Solution:
```
for i in range(int(input())):
l,r=map(int,input().split())
while(l|(l+1)<=r): l|=l+1
print(l)
# Made By Mostafa_Khaled
```
| 99,779 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's denote as <image> the number of bits set ('1' bits) in the binary representation of the non-negative integer x.
You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l β€ x β€ r, and <image> is maximum possible. If there are multiple such numbers find the smallest of them.
Input
The first line contains integer n β the number of queries (1 β€ n β€ 10000).
Each of the following n lines contain two integers li, ri β the arguments for the corresponding query (0 β€ li β€ ri β€ 1018).
Output
For each query print the answer in a separate line.
Examples
Input
3
1 2
2 4
1 10
Output
1
3
7
Note
The binary representations of numbers from 1 to 10 are listed below:
110 = 12
210 = 102
310 = 112
410 = 1002
510 = 1012
610 = 1102
710 = 1112
810 = 10002
910 = 10012
1010 = 10102
Tags: bitmasks, constructive algorithms
Correct Solution:
```
for i in range(int(input())):
l,r=map(int,input().split())
L=list(bin(l))
R=list(bin(r))
L=L[2:]
R=R[2:]
w=0
c=0
L=['0']*(len(R)-len(L))+L
#print(L,R)
ans=0
if l==r:
print(l)
continue
for i in range(len(R)):
if L[i]!=R[i]:
for j in range(i+1,len(R)):
if(R[j]=='0'):
w=1
if w==1:
ans=c+(2**(len(R)-i-1))-1
# print(ans)
break
else:
ans=c+(2**(len(R)-i))-1
break
elif L[i]=='1':
c=c+(2**(len(R)-i-1))
print(ans)
```
| 99,780 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's denote as <image> the number of bits set ('1' bits) in the binary representation of the non-negative integer x.
You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l β€ x β€ r, and <image> is maximum possible. If there are multiple such numbers find the smallest of them.
Input
The first line contains integer n β the number of queries (1 β€ n β€ 10000).
Each of the following n lines contain two integers li, ri β the arguments for the corresponding query (0 β€ li β€ ri β€ 1018).
Output
For each query print the answer in a separate line.
Examples
Input
3
1 2
2 4
1 10
Output
1
3
7
Note
The binary representations of numbers from 1 to 10 are listed below:
110 = 12
210 = 102
310 = 112
410 = 1002
510 = 1012
610 = 1102
710 = 1112
810 = 10002
910 = 10012
1010 = 10102
Tags: bitmasks, constructive algorithms
Correct Solution:
```
n=int(input())
for k in range(n):
l,r=map(int,input().split())
a=[]
for i in range(62):
a.append('0')
lbin=list(bin(l))
lbin=lbin[2:]
ans=l
num=l
for i in range(len(lbin)):
a[61-i]=lbin[len(lbin)-1-i]
blah=0
for i in range(61,-1,-1):
if(a[i]=='0'):
a[i]='1'
num=num+2**(61-i)
if(num<=r):
ans=num
else:
break
print(ans)
```
| 99,781 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's denote as <image> the number of bits set ('1' bits) in the binary representation of the non-negative integer x.
You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l β€ x β€ r, and <image> is maximum possible. If there are multiple such numbers find the smallest of them.
Input
The first line contains integer n β the number of queries (1 β€ n β€ 10000).
Each of the following n lines contain two integers li, ri β the arguments for the corresponding query (0 β€ li β€ ri β€ 1018).
Output
For each query print the answer in a separate line.
Examples
Input
3
1 2
2 4
1 10
Output
1
3
7
Note
The binary representations of numbers from 1 to 10 are listed below:
110 = 12
210 = 102
310 = 112
410 = 1002
510 = 1012
610 = 1102
710 = 1112
810 = 10002
910 = 10012
1010 = 10102
Tags: bitmasks, constructive algorithms
Correct Solution:
```
from sys import stdin
def parseline(line):
return list(map(int, line.split()))
def round_to_power_of_2(k):
k |= k >> 1
k |= k >> 2
k |= k >> 4
k |= k >> 8
k |= k >> 16
k += 1
return k
def is_power_of_2(k):
return 0 == k & (k-1)
if __name__ == "__main__":
lines = list(filter(None, stdin.read().split('\n')))
lines = list(map(parseline, lines))
n, = lines[0]
for li, ri in lines[1:n+1]:
z = round_to_power_of_2((li ^ ri))
mask = z - 1
if is_power_of_2((ri & mask) + 1):
print(ri)
else:
pos = z >> 1
print((ri ^ pos ) | (pos - 1))
```
| 99,782 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's denote as <image> the number of bits set ('1' bits) in the binary representation of the non-negative integer x.
You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l β€ x β€ r, and <image> is maximum possible. If there are multiple such numbers find the smallest of them.
Input
The first line contains integer n β the number of queries (1 β€ n β€ 10000).
Each of the following n lines contain two integers li, ri β the arguments for the corresponding query (0 β€ li β€ ri β€ 1018).
Output
For each query print the answer in a separate line.
Examples
Input
3
1 2
2 4
1 10
Output
1
3
7
Note
The binary representations of numbers from 1 to 10 are listed below:
110 = 12
210 = 102
310 = 112
410 = 1002
510 = 1012
610 = 1102
710 = 1112
810 = 10002
910 = 10012
1010 = 10102
Tags: bitmasks, constructive algorithms
Correct Solution:
```
"""
pppppppppppppppppppp
ppppp ppppppppppppppppppp
ppppppp ppppppppppppppppppppp
pppppppp pppppppppppppppppppppp
pppppppppppppppppppppppppppppppp
pppppppppppppppppppppppp
ppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppp
pppppppppppppppppppppppppppppppppppppppppppppppp ppppppppppppppppppppp
ppppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppp
ppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppp
pppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppppp
ppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppppppp
pppppppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppp
pppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppp
ppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppppp
pppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppppppp
ppppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppppp
pppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppp
ppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppp
pppppppppppppppppppppppp
pppppppppppppppppppppppppppppppp
pppppppppppppppppppppp pppppppp
ppppppppppppppppppppp ppppppp
ppppppppppppppppppp ppppp
pppppppppppppppppppp
"""
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
# sys.setrecursionlimit(pow(10, 6))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(var): sys.stdout.write(str(var)+"\n")
def outa(*var, end="\n"): sys.stdout.write(' '.join(map(str, var)) + end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
left, right = sp()
answer = left
for i in range(65):
if not(left & (1 << i)) and (answer + (1 << i) <= right):
answer += (1 << i)
out(answer)
```
| 99,783 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's denote as <image> the number of bits set ('1' bits) in the binary representation of the non-negative integer x.
You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l β€ x β€ r, and <image> is maximum possible. If there are multiple such numbers find the smallest of them.
Input
The first line contains integer n β the number of queries (1 β€ n β€ 10000).
Each of the following n lines contain two integers li, ri β the arguments for the corresponding query (0 β€ li β€ ri β€ 1018).
Output
For each query print the answer in a separate line.
Examples
Input
3
1 2
2 4
1 10
Output
1
3
7
Note
The binary representations of numbers from 1 to 10 are listed below:
110 = 12
210 = 102
310 = 112
410 = 1002
510 = 1012
610 = 1102
710 = 1112
810 = 10002
910 = 10012
1010 = 10102
Tags: bitmasks, constructive algorithms
Correct Solution:
```
import sys
def binary(a):
s = ""
for i in range(64):
if(a%2 == 0):
s += "0"
else:
s += "1"
a //= 2
return s
def dec(s):
resp = 0;
for k in s:
resp *= 2
if(k == '1'):
resp += 1
return resp
def solve(a, b):
x = binary(a)
y = binary(b)
resp = 0
gen = ""
for i in range(len(x)-1, -1, -1):
if(x[i] == y[i]):
gen += x[i]
else:
ones = True
for j in range(i, -1, -1):
if(y[j] == '0'):
ones = False
break
if(ones):
gen += "1"
else:
gen += "0"
for j in range(i-1, -1, -1):
gen += "1"
break
# print(x, y, gen)
return dec(gen)
casos = int(input())
for i in range(casos):
line = input()
v = [int(x) for x in line.split()]
print(solve(v[0], v[1]))
```
| 99,784 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's denote as <image> the number of bits set ('1' bits) in the binary representation of the non-negative integer x.
You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l β€ x β€ r, and <image> is maximum possible. If there are multiple such numbers find the smallest of them.
Input
The first line contains integer n β the number of queries (1 β€ n β€ 10000).
Each of the following n lines contain two integers li, ri β the arguments for the corresponding query (0 β€ li β€ ri β€ 1018).
Output
For each query print the answer in a separate line.
Examples
Input
3
1 2
2 4
1 10
Output
1
3
7
Note
The binary representations of numbers from 1 to 10 are listed below:
110 = 12
210 = 102
310 = 112
410 = 1002
510 = 1012
610 = 1102
710 = 1112
810 = 10002
910 = 10012
1010 = 10102
Submitted Solution:
```
n = int(input())
for i in range(n):
l, r = map(int, input().split())
l = bin(l)[2:]
r = bin(r)[2:]
while len(l) < len(r):
l = '0' + l
x = [0] * len(l)
for i in range(len(l)):
x[i] = l[i]
if l[i] < r[i]:
ok = True
for j in range(i+1, len(l)):
x[j] = '1'
if r[j] == '0':
ok = False
if ok:
x[i] = '1'
break
print(int(''.join(x), 2))
```
Yes
| 99,785 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's denote as <image> the number of bits set ('1' bits) in the binary representation of the non-negative integer x.
You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l β€ x β€ r, and <image> is maximum possible. If there are multiple such numbers find the smallest of them.
Input
The first line contains integer n β the number of queries (1 β€ n β€ 10000).
Each of the following n lines contain two integers li, ri β the arguments for the corresponding query (0 β€ li β€ ri β€ 1018).
Output
For each query print the answer in a separate line.
Examples
Input
3
1 2
2 4
1 10
Output
1
3
7
Note
The binary representations of numbers from 1 to 10 are listed below:
110 = 12
210 = 102
310 = 112
410 = 1002
510 = 1012
610 = 1102
710 = 1112
810 = 10002
910 = 10012
1010 = 10102
Submitted Solution:
```
'''
Auther: ghoshashis545 Ashis Ghosh
College: jalpaiguri Govt Enggineerin College
Date:28/03/2020
'''
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())
def main():
# for _ in range(ii()):
n=ii()
for i in range(n):
l,r=mi()
s1=bin(r)[2:]
n1=len(s1)
s2=bin(l)[2:]
s2='0'*(n1-len(s2))+s2
s2=list(s2)
s1=list(s1)
x=s1.count('1')
f=0
f1=-1
for i in range(n1):
if(f==1):
s2[i]='1'
elif(s1[i]!=s2[i]):
f1=i
f=1
if(f1!=-1):
s3=s2[:]
s3[f1]='1'
s3="".join(s3)
x=int(s3,2)
if(x<=r):
print(x)
else:
s2="".join(s2)
print(int(s2,2))
else:
s2="".join(s2)
print(int(s2,2))
if __name__ =="__main__":
main()
```
Yes
| 99,786 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's denote as <image> the number of bits set ('1' bits) in the binary representation of the non-negative integer x.
You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l β€ x β€ r, and <image> is maximum possible. If there are multiple such numbers find the smallest of them.
Input
The first line contains integer n β the number of queries (1 β€ n β€ 10000).
Each of the following n lines contain two integers li, ri β the arguments for the corresponding query (0 β€ li β€ ri β€ 1018).
Output
For each query print the answer in a separate line.
Examples
Input
3
1 2
2 4
1 10
Output
1
3
7
Note
The binary representations of numbers from 1 to 10 are listed below:
110 = 12
210 = 102
310 = 112
410 = 1002
510 = 1012
610 = 1102
710 = 1112
810 = 10002
910 = 10012
1010 = 10102
Submitted Solution:
```
import sys
import math
import collections
import heapq
input=sys.stdin.readline
n=int(input())
for i in range(n):
l,r=(int(i) for i in input().split())
while(l|(l+1)<=r):
l|=(l+1)
print(l)
```
Yes
| 99,787 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's denote as <image> the number of bits set ('1' bits) in the binary representation of the non-negative integer x.
You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l β€ x β€ r, and <image> is maximum possible. If there are multiple such numbers find the smallest of them.
Input
The first line contains integer n β the number of queries (1 β€ n β€ 10000).
Each of the following n lines contain two integers li, ri β the arguments for the corresponding query (0 β€ li β€ ri β€ 1018).
Output
For each query print the answer in a separate line.
Examples
Input
3
1 2
2 4
1 10
Output
1
3
7
Note
The binary representations of numbers from 1 to 10 are listed below:
110 = 12
210 = 102
310 = 112
410 = 1002
510 = 1012
610 = 1102
710 = 1112
810 = 10002
910 = 10012
1010 = 10102
Submitted Solution:
```
'''
Auther: ghoshashis545 Ashis Ghosh
College: jalpaiguri Govt Enggineerin College
Date:28/03/2020
'''
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())
def main():
# for _ in range(ii()):
n=ii()
for i in range(n):
l,r=mi()
s1=bin(r)[2:]
n1=len(s1)
s2=bin(l)[2:]
s2='0'*(n1-len(s2))+s2
s2=list(s2)
s1=list(s1)
x=s1.count('1')
f=0
for i in range(n1):
if(f==1):
s2[i]='1'
elif(s1[i]!=s2[i]):
f=1
s2="".join(s2)
if(x==n1):
print(r)
else:
print(int(s2,2))
if __name__ =="__main__":
main()
```
No
| 99,788 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's denote as <image> the number of bits set ('1' bits) in the binary representation of the non-negative integer x.
You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l β€ x β€ r, and <image> is maximum possible. If there are multiple such numbers find the smallest of them.
Input
The first line contains integer n β the number of queries (1 β€ n β€ 10000).
Each of the following n lines contain two integers li, ri β the arguments for the corresponding query (0 β€ li β€ ri β€ 1018).
Output
For each query print the answer in a separate line.
Examples
Input
3
1 2
2 4
1 10
Output
1
3
7
Note
The binary representations of numbers from 1 to 10 are listed below:
110 = 12
210 = 102
310 = 112
410 = 1002
510 = 1012
610 = 1102
710 = 1112
810 = 10002
910 = 10012
1010 = 10102
Submitted Solution:
```
import sys
def binary(a):
s = ""
for i in range(64):
if(a%2 == 0):
s += "0"
else:
s += "1"
a //= 2
return s
def dec(s):
resp = 0;
for k in s:
resp *= 2
if(k == '1'):
resp += 1
return resp
def solve(a, b):
x = binary(a)
y = binary(b)
resp = 0
gen = ""
for i in range(len(x)-1, -1, -1):
if(x[i] == y[i]):
gen += x[i]
else:
gen += "0"
for j in range(i-1, -1, -1):
gen += "1"
break
# print(x, y, gen)
return dec(gen)
casos = int(input())
for i in range(casos):
line = input()
v = [int(x) for x in line.split()]
print(solve(v[0], v[1]))
```
No
| 99,789 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's denote as <image> the number of bits set ('1' bits) in the binary representation of the non-negative integer x.
You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l β€ x β€ r, and <image> is maximum possible. If there are multiple such numbers find the smallest of them.
Input
The first line contains integer n β the number of queries (1 β€ n β€ 10000).
Each of the following n lines contain two integers li, ri β the arguments for the corresponding query (0 β€ li β€ ri β€ 1018).
Output
For each query print the answer in a separate line.
Examples
Input
3
1 2
2 4
1 10
Output
1
3
7
Note
The binary representations of numbers from 1 to 10 are listed below:
110 = 12
210 = 102
310 = 112
410 = 1002
510 = 1012
610 = 1102
710 = 1112
810 = 10002
910 = 10012
1010 = 10102
Submitted Solution:
```
from sys import stdin
lines = list(filter(None, stdin.read().split('\n')))
def parseline(line):
return list(map(int, line.split()))
lines = list(map(parseline, lines))
n, = lines[0]
def round_to_power_of_2(k):
k |= k >> 1
k |= k >> 2
k |= k >> 4
k |= k >> 8
k |= k >> 16
k += 1
return k
def is_power_of_2(k):
return 0 == k & (k-1)
for li, ri in lines[1:n+1]:
if is_power_of_2(ri + 1):
print(ri)
else:
z = round_to_power_of_2((li ^ ri)) >> 1
y = round_to_power_of_2(ri) - 1
print(z ^ y)
```
No
| 99,790 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's denote as <image> the number of bits set ('1' bits) in the binary representation of the non-negative integer x.
You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l β€ x β€ r, and <image> is maximum possible. If there are multiple such numbers find the smallest of them.
Input
The first line contains integer n β the number of queries (1 β€ n β€ 10000).
Each of the following n lines contain two integers li, ri β the arguments for the corresponding query (0 β€ li β€ ri β€ 1018).
Output
For each query print the answer in a separate line.
Examples
Input
3
1 2
2 4
1 10
Output
1
3
7
Note
The binary representations of numbers from 1 to 10 are listed below:
110 = 12
210 = 102
310 = 112
410 = 1002
510 = 1012
610 = 1102
710 = 1112
810 = 10002
910 = 10012
1010 = 10102
Submitted Solution:
```
for i in range(int(input())):
l,r=map(int,input().split())
L=list(bin(l))
R=list(bin(r))
L=L[2:]
R=R[2:]
w=0
c=0
L=['0']*(len(R)-len(L))+L
# print(L,R)
ans=0
for i in range(len(R)):
if L[i]!=R[i]:
for j in range(i+1,len(R)):
if(R[j]=='0'):
w=1
if w==1:
ans=c+(2**(len(R)-i-1))-1
break
else:
ans=c+(2**len(R)-i)-1
break
elif L[i]=='1':
c=c+(2**(len(R)-i)-1)
print(ans)
```
No
| 99,791 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi.
Vasya wonders what the numbers ai could be like. Of all the possible options he likes the one sequence with the minimum possible last number an. Help Vasya restore the initial sequence.
It is guaranteed that such a sequence always exists.
Input
The first line contains a single integer number n (1 β€ n β€ 300).
Next n lines contain integer numbers b1, ..., bn β the required sums of digits. All bi belong to the range 1 β€ bi β€ 300.
Output
Print n integer numbers, one per line β the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi.
If there are multiple sequences with least possible number an, print any of them. Print the numbers without leading zeroes.
Examples
Input
3
1
2
3
Output
1
2
3
Input
3
3
2
1
Output
3
11
100
Tags: dp, greedy, implementation
Correct Solution:
```
toInt = lambda x : int(''.join(map(str,x[-1::-1])))
import sys
#sys.stdin=open('note.txt')
pre=0
ans=[0]*1000
sum=0
for n in range(int(input())):
sum=int(input())
d=sum-pre
pre=sum
if d>0:
for i,dig in enumerate(ans):
if d+dig<=9:
ans[i]=dig+d
break
d-=9-dig
ans[i]=9
print(toInt(ans))
else: #d is minus
d=-d+1
d2=0
for i, dig in enumerate(ans):
d2+=dig
ans[i]=0
if ans[i+1]<9 and d2>=d:
break
ans[i+1]+=1
d2-=d
cnt = d2//9
ans[:cnt]=[9]*cnt
ans[cnt]=d2 % 9
print(toInt(ans))
```
| 99,792 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi.
Vasya wonders what the numbers ai could be like. Of all the possible options he likes the one sequence with the minimum possible last number an. Help Vasya restore the initial sequence.
It is guaranteed that such a sequence always exists.
Input
The first line contains a single integer number n (1 β€ n β€ 300).
Next n lines contain integer numbers b1, ..., bn β the required sums of digits. All bi belong to the range 1 β€ bi β€ 300.
Output
Print n integer numbers, one per line β the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi.
If there are multiple sequences with least possible number an, print any of them. Print the numbers without leading zeroes.
Examples
Input
3
1
2
3
Output
1
2
3
Input
3
3
2
1
Output
3
11
100
Tags: dp, greedy, implementation
Correct Solution:
```
def get_digit(number,n):
return int((number // 10**n)/10),number // 10**n % 10
def last_k(new_sum_to_make,k):
last_sum = 0
for i in range(k+1):
#print(new_sum_to_make,k)
if new_sum_to_make > 9:
new_sum_to_make = new_sum_to_make - 9
last_sum = 9 * (10**i) + last_sum
else:
new_num = new_sum_to_make
last_sum = new_num * (10**i) + last_sum
break
return last_sum
n = int(input())
prev_num = 0
prev_sum = 0
for i in range(n):
new_sum = int(input())
prev_num_str = str(prev_num)
l_prev_num_str = len(prev_num_str)
k = 0
curr_digit_sum = 0
found = False
digit_index = l_prev_num_str - 1
while found == False:
#prev_digit,curr_digit = get_digit(prev_num,k)
if digit_index > 0:
curr_digit = int(prev_num_str[digit_index])
prev_digit = int(prev_num_str[0:digit_index])
elif digit_index == 0:
curr_digit = int(prev_num_str[digit_index])
prev_digit = 0
else:
curr_digit = 0
prev_digit = 0
digit_index = digit_index - 1
curr_digit_sum = curr_digit_sum + curr_digit
prev_digit_sum = prev_sum - curr_digit_sum
if prev_digit_sum > new_sum:
k = k + 1
else:
sum_to_make = new_sum - prev_digit_sum
#print(prev_digit,curr_digit,curr_digit_sum,prev_digit_sum,new_sum,prev_sum)
new_curr_digit = curr_digit + 1
while new_curr_digit != 10 and found == False:
new_sum_to_make = sum_to_make - new_curr_digit
if new_sum_to_make >= 0 and new_sum_to_make <= 9*k:
#print(new_curr_digit,new_sum_to_make,k)
last_k_digit = last_k(new_sum_to_make,k)
#print(last_k_digit)
last_k_digit = new_curr_digit *(10**k) + last_k_digit
#first_digits = prev_digit * 10 + new_curr_digit
#print(first_digits)
first_digits = prev_digit * (10**(k+1)) + last_k_digit
print(first_digits)
found = True
break
new_curr_digit = new_curr_digit + 1
if new_curr_digit == 10:
k = k + 1
else:
prev_num = first_digits
prev_sum = new_sum
break
```
| 99,793 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi.
Vasya wonders what the numbers ai could be like. Of all the possible options he likes the one sequence with the minimum possible last number an. Help Vasya restore the initial sequence.
It is guaranteed that such a sequence always exists.
Input
The first line contains a single integer number n (1 β€ n β€ 300).
Next n lines contain integer numbers b1, ..., bn β the required sums of digits. All bi belong to the range 1 β€ bi β€ 300.
Output
Print n integer numbers, one per line β the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi.
If there are multiple sequences with least possible number an, print any of them. Print the numbers without leading zeroes.
Examples
Input
3
1
2
3
Output
1
2
3
Input
3
3
2
1
Output
3
11
100
Tags: dp, greedy, implementation
Correct Solution:
```
# written with help of editorial
def get_smallest(dig_sum):
ret = str(dig_sum % 9) + '9' * (dig_sum // 9)
return int(ret)
def f(n):
ret = 0
while n:
ret += n % 10
n //= 10
return ret
def nx(n):
s = str(n)
sm = 0
for i in range(len(s) - 1, -1, -1):
if s[i] < '9' and sm > 0:
return int(s[:i] + str(int(s[i]) + 1) + \
str(get_smallest(sm - 1)).zfill(len(s) - i - 1))
sm += int(s[i])
return int('1' + str(get_smallest(sm - 1)).zfill(len(s)))
def after(d, low):
s = '0' * 600 + str(low)
n = len(s)
has = f(low)
for i in range(n - 1, -1, -1):
has -= int(s[i])
for x in range(int(s[i]) + 1, 10):
if s[i] < '9' and has + x <= d <= has + x + 9 * (n - i - 1):
if i == n - 1:
return int(s[:i] + str(x))
return int(s[:i] + str(x) + \
str(get_smallest(d - has - x)).zfill(n - i - 1))
n = int(input())
low = 0
for i in range(n):
ds = int(input())
cur = after(ds, low)
print(cur)
low = cur
```
| 99,794 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi.
Vasya wonders what the numbers ai could be like. Of all the possible options he likes the one sequence with the minimum possible last number an. Help Vasya restore the initial sequence.
It is guaranteed that such a sequence always exists.
Input
The first line contains a single integer number n (1 β€ n β€ 300).
Next n lines contain integer numbers b1, ..., bn β the required sums of digits. All bi belong to the range 1 β€ bi β€ 300.
Output
Print n integer numbers, one per line β the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi.
If there are multiple sequences with least possible number an, print any of them. Print the numbers without leading zeroes.
Examples
Input
3
1
2
3
Output
1
2
3
Input
3
3
2
1
Output
3
11
100
Tags: dp, greedy, implementation
Correct Solution:
```
__author__ = 'PrimuS'
n = int(input())
b = [0] * n
for i in range(n):
b[i] = int(input())
last = 0
import math
def build_smallest(csum, length):
if math.ceil(csum / 9) == length:
f = csum % 9
if f == 0:
f = 9
return int(str(f) + "9" * (length-1))
csum -= 1
s = ""
while csum > 0:
s = str(min(csum, 9)) + s
csum -= min(csum, 9)
return int("1" + "0" * (length - 1 - len(s)) + s)
def build_greater(csum, x):
x = [int(y) for y in x]
last_possible = -1
i = len(x) - 1
while i >= 0:
if x[i] < 9:
last_possible = i
break
i -= 1
if last_possible == -1:
return 0
if x[0] >= csum:
return 0
last_avail = -1
ac_sum = 0
for i in range(len(x)):
ac_sum += x[i]
if ac_sum >= csum:
last_avail = i - 1
break
if last_avail == -1:
last_avail = len(x) - 1
pos = last_avail
while pos >= 0:
if x[pos] < 9:
break
pos -= 1
if pos == -1:
return 0
res = list(x)
res[pos] += 1
for i in range(pos+1):
csum -= res[i]
i = len(res) - 1
while i > pos:
res[i] = min(9, csum)
csum -= res[i]
i -= 1
if csum > 0:
i = len(res) - 1
while i >= 0:
if res[i] < 9:
u = min(csum, 9 - res[i])
res[i] = res[i] + u
csum -= u
i -= 1
if csum > 0:
return 0
res2 = 0
for y in res:
res2 = res2 * 10 + y
return res2
for i in range(n):
bx = b[i]
cur = bx % 9
bx -= cur
while bx > 0:
cur = cur * 10 + 9
bx -= 9
if cur <= last:
cur = build_greater(b[i], str(last))
if cur <= last:
cur = build_smallest(b[i], len(str(last)) + 1)
print(cur)
last = cur
```
| 99,795 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi.
Vasya wonders what the numbers ai could be like. Of all the possible options he likes the one sequence with the minimum possible last number an. Help Vasya restore the initial sequence.
It is guaranteed that such a sequence always exists.
Input
The first line contains a single integer number n (1 β€ n β€ 300).
Next n lines contain integer numbers b1, ..., bn β the required sums of digits. All bi belong to the range 1 β€ bi β€ 300.
Output
Print n integer numbers, one per line β the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi.
If there are multiple sequences with least possible number an, print any of them. Print the numbers without leading zeroes.
Examples
Input
3
1
2
3
Output
1
2
3
Input
3
3
2
1
Output
3
11
100
Tags: dp, greedy, implementation
Correct Solution:
```
def fill9(x,u):
k=x//9
for i in range(k):
u[i]=9
if x%9:
u[k]=x%9
return k+1
else:
return k
n=input()
n=int(n)
u=[0 for i in range(300//9*150+150)]
k=1
for i in range(n):
x=input()
x=int(x)
t=k-1
while t>=0:
if u[t]+9*t<x:
t=fill9(x,u)
if t>k:
k=t
break
elif u[t]>=x:
t+=1
u[t]+=1
x-=1
while u[t]==10:
u[t]=0
t+=1
u[t]+=1
x+=9
if t+1>k:
k=t+1
for t in range(fill9(x,u),t):
u[t]=0
break
else:
x-=u[t]
t-=1
v=[str(j) for j in u[k-1:-len(u)-1:-1]]
print(''.join(v))
```
| 99,796 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi.
Vasya wonders what the numbers ai could be like. Of all the possible options he likes the one sequence with the minimum possible last number an. Help Vasya restore the initial sequence.
It is guaranteed that such a sequence always exists.
Input
The first line contains a single integer number n (1 β€ n β€ 300).
Next n lines contain integer numbers b1, ..., bn β the required sums of digits. All bi belong to the range 1 β€ bi β€ 300.
Output
Print n integer numbers, one per line β the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi.
If there are multiple sequences with least possible number an, print any of them. Print the numbers without leading zeroes.
Examples
Input
3
1
2
3
Output
1
2
3
Input
3
3
2
1
Output
3
11
100
Tags: dp, greedy, implementation
Correct Solution:
```
def naive(S, n):
arr = [0] * n
for i in range(n):
plus = min(S, 9)
arr[i] += plus
S -= plus
return arr
def less_than(pre_arr, pre_S, cur_S):
S = pre_S - cur_S
n = len(pre_arr)
cur_arr = [0] * n
for i in range(n):
sub = min(S, pre_arr[i])
cur_arr[i] = pre_arr[i] - sub
S -= sub
ind = 0
for x in cur_arr:
if x>0:
break
ind+=1
for j in range(ind+1, n):
if cur_arr[j] < 9:
cur_arr[ind] -= 1
cur_arr[j] += 1
return sorted(cur_arr[:j], reverse=True) + cur_arr[j:]
return naive(cur_S-1, n) + [1]
def remain_plus(pre_arr, pre_S, cur_S):
S = cur_S - pre_S
n = len(pre_arr)
cur_arr = [0] * n
for i in range(n):
add = min(S, 9 - pre_arr[i])
cur_arr[i] = pre_arr[i] + add
S -= add
return cur_arr
n = int(input())
a = [int(input()) for _ in range(n)]
S = []
import math
for i, cur_S in enumerate(a):
if i == 0:
n = math.ceil(cur_S/9)
S.append(naive(cur_S, n))
else:
pre_S = a[i-1]
n = len(S[-1])
if cur_S > 9*n:
S.append(naive(cur_S, math.ceil(cur_S/9)))
elif cur_S > pre_S:
S.append(remain_plus(S[-1], pre_S, cur_S))
else:
S.append(less_than(S[-1], pre_S, cur_S))
for x_arr in S:
print(''.join([str(x) for x in x_arr[::-1]]))
```
| 99,797 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi.
Vasya wonders what the numbers ai could be like. Of all the possible options he likes the one sequence with the minimum possible last number an. Help Vasya restore the initial sequence.
It is guaranteed that such a sequence always exists.
Input
The first line contains a single integer number n (1 β€ n β€ 300).
Next n lines contain integer numbers b1, ..., bn β the required sums of digits. All bi belong to the range 1 β€ bi β€ 300.
Output
Print n integer numbers, one per line β the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi.
If there are multiple sequences with least possible number an, print any of them. Print the numbers without leading zeroes.
Examples
Input
3
1
2
3
Output
1
2
3
Input
3
3
2
1
Output
3
11
100
Tags: dp, greedy, implementation
Correct Solution:
```
def getnum(digsum):
if digsum < 0:
return 0
if digsum < 10:
return digsum
else:
nnine = digsum // 9
res = digsum % 9
for i in range(nnine):
res = 10 * res + 9
return res
def digsumf(n):
return sum([int(i) for i in str(n)])
def getnext(bnum, last):
if last == 0:
return getnum(bnum)
k = last + 1
digsum = digsumf(k)
diff = bnum - digsum
if diff >= 0 and 9 - k % 10 >= diff:
return k + diff
omitsum = 0
startdigsum = digsumf(last)
lastl = [int(i) for i in str(last)]
digsum = digsumf(last)
l = 10
i = 1
while True:
if i == 1 and len(str(l)) - 1 <= len(lastl):
omitsum += lastl[-(len(str(l)) - 1)]
if (last // l) % 10 + i > 9:
l *= 10
i = 1
continue
k = (last // l) * l + l * i
digsum = startdigsum - omitsum + i
diff = bnum - digsum
r = getnum(diff)
if diff >= 0 and len(str(r)) <= len(str(l // 10)):
return r + k
if diff < 0:
l *= 10
i = 1
else:
i += 1
n = int(input())
last = 0
for i in range(n):
last = getnext(int(input()), last)
print(last)
```
| 99,798 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi.
Vasya wonders what the numbers ai could be like. Of all the possible options he likes the one sequence with the minimum possible last number an. Help Vasya restore the initial sequence.
It is guaranteed that such a sequence always exists.
Input
The first line contains a single integer number n (1 β€ n β€ 300).
Next n lines contain integer numbers b1, ..., bn β the required sums of digits. All bi belong to the range 1 β€ bi β€ 300.
Output
Print n integer numbers, one per line β the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi.
If there are multiple sequences with least possible number an, print any of them. Print the numbers without leading zeroes.
Examples
Input
3
1
2
3
Output
1
2
3
Input
3
3
2
1
Output
3
11
100
Tags: dp, greedy, implementation
Correct Solution:
```
t = [0] * 400
x = k = 0
for q in range(int(input())):
y = int(input())
d, x = y - x, y
j = 0
while d < 1 or t[j] > min(8, 9 * j + 9 - d):
d += t[j]
t[j] = 0
j += 1
t[j] += 1
k = max(k, j)
a, b = divmod(d - 1, 9)
t[:a] = [9] * a
t[a] += b
print(''.join(map(str, t[k::-1])))
# Made By Mostafa_Khaled
```
| 99,799 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.