message stringlengths 2 43.5k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 853 107k | cluster float64 24 24 | __index_level_0__ int64 1.71k 214k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
Each day in Berland consists of n hours. Polycarp likes time management. That's why he has a fixed schedule for each day β it is a sequence a_1, a_2, ..., a_n (each a_i is either 0 or 1), where a_i=0 if Polycarp works during the i-th hour of the day and a_i=1 if Polycarp rests during the i-th hour of the day.
Days go one after another endlessly and Polycarp uses the same schedule for each day.
What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day.
Input
The first line contains n (1 β€ n β€ 2β
10^5) β number of hours per day.
The second line contains n integer numbers a_1, a_2, ..., a_n (0 β€ a_i β€ 1), where a_i=0 if the i-th hour in a day is working and a_i=1 if the i-th hour is resting. It is guaranteed that a_i=0 for at least one i.
Output
Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day.
Examples
Input
5
1 0 1 0 1
Output
2
Input
6
0 1 0 1 1 0
Output
2
Input
7
1 0 1 1 1 0 1
Output
3
Input
3
0 0 0
Output
0
Note
In the first example, the maximal rest starts in last hour and goes to the first hour of the next day.
In the second example, Polycarp has maximal rest from the 4-th to the 5-th hour.
In the third example, Polycarp has maximal rest from the 3-rd to the 5-th hour.
In the fourth example, Polycarp has no rest at all. | instruction | 0 | 853 | 24 | 1,706 |
Tags: implementation
Correct Solution:
```
n=int(input())
a=list(map(int,input().split()))
k,m,s=n-1,0,0
while True:
if k<0 and a[k]!=1:
print(max(m,s))
exit()
if a[k]==1:
s+=1
else:
m=max(m,s)
s=0
k-=1
``` | output | 1 | 853 | 24 | 1,707 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Each day in Berland consists of n hours. Polycarp likes time management. That's why he has a fixed schedule for each day β it is a sequence a_1, a_2, ..., a_n (each a_i is either 0 or 1), where a_i=0 if Polycarp works during the i-th hour of the day and a_i=1 if Polycarp rests during the i-th hour of the day.
Days go one after another endlessly and Polycarp uses the same schedule for each day.
What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day.
Input
The first line contains n (1 β€ n β€ 2β
10^5) β number of hours per day.
The second line contains n integer numbers a_1, a_2, ..., a_n (0 β€ a_i β€ 1), where a_i=0 if the i-th hour in a day is working and a_i=1 if the i-th hour is resting. It is guaranteed that a_i=0 for at least one i.
Output
Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day.
Examples
Input
5
1 0 1 0 1
Output
2
Input
6
0 1 0 1 1 0
Output
2
Input
7
1 0 1 1 1 0 1
Output
3
Input
3
0 0 0
Output
0
Note
In the first example, the maximal rest starts in last hour and goes to the first hour of the next day.
In the second example, Polycarp has maximal rest from the 4-th to the 5-th hour.
In the third example, Polycarp has maximal rest from the 3-rd to the 5-th hour.
In the fourth example, Polycarp has no rest at all. | instruction | 0 | 854 | 24 | 1,708 |
Tags: implementation
Correct Solution:
```
n = int(input())
a = list(map(int, input().split())) * 2
cnt = 0
answ = 0
for i in range(2 * n):
if a[i]:
cnt += 1
else:
answ = max(answ, cnt)
cnt = 0
print(answ)
``` | output | 1 | 854 | 24 | 1,709 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Each day in Berland consists of n hours. Polycarp likes time management. That's why he has a fixed schedule for each day β it is a sequence a_1, a_2, ..., a_n (each a_i is either 0 or 1), where a_i=0 if Polycarp works during the i-th hour of the day and a_i=1 if Polycarp rests during the i-th hour of the day.
Days go one after another endlessly and Polycarp uses the same schedule for each day.
What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day.
Input
The first line contains n (1 β€ n β€ 2β
10^5) β number of hours per day.
The second line contains n integer numbers a_1, a_2, ..., a_n (0 β€ a_i β€ 1), where a_i=0 if the i-th hour in a day is working and a_i=1 if the i-th hour is resting. It is guaranteed that a_i=0 for at least one i.
Output
Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day.
Examples
Input
5
1 0 1 0 1
Output
2
Input
6
0 1 0 1 1 0
Output
2
Input
7
1 0 1 1 1 0 1
Output
3
Input
3
0 0 0
Output
0
Note
In the first example, the maximal rest starts in last hour and goes to the first hour of the next day.
In the second example, Polycarp has maximal rest from the 4-th to the 5-th hour.
In the third example, Polycarp has maximal rest from the 3-rd to the 5-th hour.
In the fourth example, Polycarp has no rest at all. | instruction | 0 | 855 | 24 | 1,710 |
Tags: implementation
Correct Solution:
```
num=int(input())
a=list(map(int, input().split()))
b=[]
a+=a #Same list is added to eachother bcz he can take consecutive rests i.e when a[n-1]==1 and a[0]==1 that is he can take rest before work and at end so his rest count increases
count=0
i=0
while i<2*num-1:
count=0
if a[i]==1:
count+=1
for j in range(i+1, 2*num):
#To find consecutive resting 1s
if a[j]==0:
break
else:
count+=1
i=j
else:
i+=1
b+=[count]
print(max(b))
``` | output | 1 | 855 | 24 | 1,711 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Each day in Berland consists of n hours. Polycarp likes time management. That's why he has a fixed schedule for each day β it is a sequence a_1, a_2, ..., a_n (each a_i is either 0 or 1), where a_i=0 if Polycarp works during the i-th hour of the day and a_i=1 if Polycarp rests during the i-th hour of the day.
Days go one after another endlessly and Polycarp uses the same schedule for each day.
What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day.
Input
The first line contains n (1 β€ n β€ 2β
10^5) β number of hours per day.
The second line contains n integer numbers a_1, a_2, ..., a_n (0 β€ a_i β€ 1), where a_i=0 if the i-th hour in a day is working and a_i=1 if the i-th hour is resting. It is guaranteed that a_i=0 for at least one i.
Output
Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day.
Examples
Input
5
1 0 1 0 1
Output
2
Input
6
0 1 0 1 1 0
Output
2
Input
7
1 0 1 1 1 0 1
Output
3
Input
3
0 0 0
Output
0
Note
In the first example, the maximal rest starts in last hour and goes to the first hour of the next day.
In the second example, Polycarp has maximal rest from the 4-th to the 5-th hour.
In the third example, Polycarp has maximal rest from the 3-rd to the 5-th hour.
In the fourth example, Polycarp has no rest at all. | instruction | 0 | 856 | 24 | 1,712 |
Tags: implementation
Correct Solution:
```
hours = int(input().strip())
schedule = input().strip().replace(' ', '')
schedule = ''.join([schedule, schedule])
schedule = schedule.split('0')
print(len(sorted(schedule, key=len)[-1]))
``` | output | 1 | 856 | 24 | 1,713 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Each day in Berland consists of n hours. Polycarp likes time management. That's why he has a fixed schedule for each day β it is a sequence a_1, a_2, ..., a_n (each a_i is either 0 or 1), where a_i=0 if Polycarp works during the i-th hour of the day and a_i=1 if Polycarp rests during the i-th hour of the day.
Days go one after another endlessly and Polycarp uses the same schedule for each day.
What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day.
Input
The first line contains n (1 β€ n β€ 2β
10^5) β number of hours per day.
The second line contains n integer numbers a_1, a_2, ..., a_n (0 β€ a_i β€ 1), where a_i=0 if the i-th hour in a day is working and a_i=1 if the i-th hour is resting. It is guaranteed that a_i=0 for at least one i.
Output
Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day.
Examples
Input
5
1 0 1 0 1
Output
2
Input
6
0 1 0 1 1 0
Output
2
Input
7
1 0 1 1 1 0 1
Output
3
Input
3
0 0 0
Output
0
Note
In the first example, the maximal rest starts in last hour and goes to the first hour of the next day.
In the second example, Polycarp has maximal rest from the 4-th to the 5-th hour.
In the third example, Polycarp has maximal rest from the 3-rd to the 5-th hour.
In the fourth example, Polycarp has no rest at all. | instruction | 0 | 857 | 24 | 1,714 |
Tags: implementation
Correct Solution:
```
f = int(input())
lis = list(map(int, input().split())) * 2
maxi = 0
cont = 0
for i in lis:
if(i == 1):
cont += 1
if (cont > maxi):
maxi = cont
else:
cont = 0
print(maxi)
``` | output | 1 | 857 | 24 | 1,715 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Each day in Berland consists of n hours. Polycarp likes time management. That's why he has a fixed schedule for each day β it is a sequence a_1, a_2, ..., a_n (each a_i is either 0 or 1), where a_i=0 if Polycarp works during the i-th hour of the day and a_i=1 if Polycarp rests during the i-th hour of the day.
Days go one after another endlessly and Polycarp uses the same schedule for each day.
What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day.
Input
The first line contains n (1 β€ n β€ 2β
10^5) β number of hours per day.
The second line contains n integer numbers a_1, a_2, ..., a_n (0 β€ a_i β€ 1), where a_i=0 if the i-th hour in a day is working and a_i=1 if the i-th hour is resting. It is guaranteed that a_i=0 for at least one i.
Output
Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day.
Examples
Input
5
1 0 1 0 1
Output
2
Input
6
0 1 0 1 1 0
Output
2
Input
7
1 0 1 1 1 0 1
Output
3
Input
3
0 0 0
Output
0
Note
In the first example, the maximal rest starts in last hour and goes to the first hour of the next day.
In the second example, Polycarp has maximal rest from the 4-th to the 5-th hour.
In the third example, Polycarp has maximal rest from the 3-rd to the 5-th hour.
In the fourth example, Polycarp has no rest at all. | instruction | 0 | 858 | 24 | 1,716 |
Tags: implementation
Correct Solution:
```
from itertools import groupby
print(max([0] + [sum(1 for _ in g) for k, g in groupby(list(map(int, (input(), input())[1].split(' '))) * 2) if k == 1]))
``` | output | 1 | 858 | 24 | 1,717 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Each day in Berland consists of n hours. Polycarp likes time management. That's why he has a fixed schedule for each day β it is a sequence a_1, a_2, ..., a_n (each a_i is either 0 or 1), where a_i=0 if Polycarp works during the i-th hour of the day and a_i=1 if Polycarp rests during the i-th hour of the day.
Days go one after another endlessly and Polycarp uses the same schedule for each day.
What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day.
Input
The first line contains n (1 β€ n β€ 2β
10^5) β number of hours per day.
The second line contains n integer numbers a_1, a_2, ..., a_n (0 β€ a_i β€ 1), where a_i=0 if the i-th hour in a day is working and a_i=1 if the i-th hour is resting. It is guaranteed that a_i=0 for at least one i.
Output
Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day.
Examples
Input
5
1 0 1 0 1
Output
2
Input
6
0 1 0 1 1 0
Output
2
Input
7
1 0 1 1 1 0 1
Output
3
Input
3
0 0 0
Output
0
Note
In the first example, the maximal rest starts in last hour and goes to the first hour of the next day.
In the second example, Polycarp has maximal rest from the 4-th to the 5-th hour.
In the third example, Polycarp has maximal rest from the 3-rd to the 5-th hour.
In the fourth example, Polycarp has no rest at all. | instruction | 0 | 859 | 24 | 1,718 |
Tags: implementation
Correct Solution:
```
n = int(input())
a = list(map(lambda w: len(w), (''.join(input().split())).split('0')))
ans = max(a)
if len(a) > 1:
ans = max(ans, a[0]+a[-1])
print(ans)
``` | output | 1 | 859 | 24 | 1,719 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Each day in Berland consists of n hours. Polycarp likes time management. That's why he has a fixed schedule for each day β it is a sequence a_1, a_2, ..., a_n (each a_i is either 0 or 1), where a_i=0 if Polycarp works during the i-th hour of the day and a_i=1 if Polycarp rests during the i-th hour of the day.
Days go one after another endlessly and Polycarp uses the same schedule for each day.
What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day.
Input
The first line contains n (1 β€ n β€ 2β
10^5) β number of hours per day.
The second line contains n integer numbers a_1, a_2, ..., a_n (0 β€ a_i β€ 1), where a_i=0 if the i-th hour in a day is working and a_i=1 if the i-th hour is resting. It is guaranteed that a_i=0 for at least one i.
Output
Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day.
Examples
Input
5
1 0 1 0 1
Output
2
Input
6
0 1 0 1 1 0
Output
2
Input
7
1 0 1 1 1 0 1
Output
3
Input
3
0 0 0
Output
0
Note
In the first example, the maximal rest starts in last hour and goes to the first hour of the next day.
In the second example, Polycarp has maximal rest from the 4-th to the 5-th hour.
In the third example, Polycarp has maximal rest from the 3-rd to the 5-th hour.
In the fourth example, Polycarp has no rest at all. | instruction | 0 | 860 | 24 | 1,720 |
Tags: implementation
Correct Solution:
```
n = int(input())
b = input()
b = b+" "+b
b = b.split("0")
b = [len(x.split()) for x in b]
print(max(b))
``` | output | 1 | 860 | 24 | 1,721 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Each day in Berland consists of n hours. Polycarp likes time management. That's why he has a fixed schedule for each day β it is a sequence a_1, a_2, ..., a_n (each a_i is either 0 or 1), where a_i=0 if Polycarp works during the i-th hour of the day and a_i=1 if Polycarp rests during the i-th hour of the day.
Days go one after another endlessly and Polycarp uses the same schedule for each day.
What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day.
Input
The first line contains n (1 β€ n β€ 2β
10^5) β number of hours per day.
The second line contains n integer numbers a_1, a_2, ..., a_n (0 β€ a_i β€ 1), where a_i=0 if the i-th hour in a day is working and a_i=1 if the i-th hour is resting. It is guaranteed that a_i=0 for at least one i.
Output
Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day.
Examples
Input
5
1 0 1 0 1
Output
2
Input
6
0 1 0 1 1 0
Output
2
Input
7
1 0 1 1 1 0 1
Output
3
Input
3
0 0 0
Output
0
Note
In the first example, the maximal rest starts in last hour and goes to the first hour of the next day.
In the second example, Polycarp has maximal rest from the 4-th to the 5-th hour.
In the third example, Polycarp has maximal rest from the 3-rd to the 5-th hour.
In the fourth example, Polycarp has no rest at all.
Submitted Solution:
```
n=int(input())
d=input().split()
f=0
rest=[0]
for i in range(n-1,-1*n,-1):
if d[i]=='1':
f+=1
rest.append(f)
else:
f=0
print(max(rest))
``` | instruction | 0 | 861 | 24 | 1,722 |
Yes | output | 1 | 861 | 24 | 1,723 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Each day in Berland consists of n hours. Polycarp likes time management. That's why he has a fixed schedule for each day β it is a sequence a_1, a_2, ..., a_n (each a_i is either 0 or 1), where a_i=0 if Polycarp works during the i-th hour of the day and a_i=1 if Polycarp rests during the i-th hour of the day.
Days go one after another endlessly and Polycarp uses the same schedule for each day.
What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day.
Input
The first line contains n (1 β€ n β€ 2β
10^5) β number of hours per day.
The second line contains n integer numbers a_1, a_2, ..., a_n (0 β€ a_i β€ 1), where a_i=0 if the i-th hour in a day is working and a_i=1 if the i-th hour is resting. It is guaranteed that a_i=0 for at least one i.
Output
Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day.
Examples
Input
5
1 0 1 0 1
Output
2
Input
6
0 1 0 1 1 0
Output
2
Input
7
1 0 1 1 1 0 1
Output
3
Input
3
0 0 0
Output
0
Note
In the first example, the maximal rest starts in last hour and goes to the first hour of the next day.
In the second example, Polycarp has maximal rest from the 4-th to the 5-th hour.
In the third example, Polycarp has maximal rest from the 3-rd to the 5-th hour.
In the fourth example, Polycarp has no rest at all.
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
contigous = 0
max_cont = 0
from_0 = False
for i in range(n):
if a[i]:
contigous += 1
else:
max_cont = max(max_cont, contigous)
contigous = 0
max_cont = max(max_cont, contigous)
if a[0] and a[-1]:
contigous = 0
for i in range(n):
if a[i]:
contigous += 1
else:
break
for j in range(n-1, -1, -1):
if a[j]:
contigous += 1
else:
break
max_cont = max(max_cont, contigous)
print(max_cont)
``` | instruction | 0 | 862 | 24 | 1,724 |
Yes | output | 1 | 862 | 24 | 1,725 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Each day in Berland consists of n hours. Polycarp likes time management. That's why he has a fixed schedule for each day β it is a sequence a_1, a_2, ..., a_n (each a_i is either 0 or 1), where a_i=0 if Polycarp works during the i-th hour of the day and a_i=1 if Polycarp rests during the i-th hour of the day.
Days go one after another endlessly and Polycarp uses the same schedule for each day.
What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day.
Input
The first line contains n (1 β€ n β€ 2β
10^5) β number of hours per day.
The second line contains n integer numbers a_1, a_2, ..., a_n (0 β€ a_i β€ 1), where a_i=0 if the i-th hour in a day is working and a_i=1 if the i-th hour is resting. It is guaranteed that a_i=0 for at least one i.
Output
Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day.
Examples
Input
5
1 0 1 0 1
Output
2
Input
6
0 1 0 1 1 0
Output
2
Input
7
1 0 1 1 1 0 1
Output
3
Input
3
0 0 0
Output
0
Note
In the first example, the maximal rest starts in last hour and goes to the first hour of the next day.
In the second example, Polycarp has maximal rest from the 4-th to the 5-th hour.
In the third example, Polycarp has maximal rest from the 3-rd to the 5-th hour.
In the fourth example, Polycarp has no rest at all.
Submitted Solution:
```
n = int(input())
s = input().split(' ')
mas = []
k = 0
for i in range(n):
if s[i] == '0':
mas.append(k)
mas.append(0)
k = 0
else:
k += 1
mas.append(k)
mas.append(mas[0]+mas[-1])
print(max(mas))
``` | instruction | 0 | 863 | 24 | 1,726 |
Yes | output | 1 | 863 | 24 | 1,727 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Each day in Berland consists of n hours. Polycarp likes time management. That's why he has a fixed schedule for each day β it is a sequence a_1, a_2, ..., a_n (each a_i is either 0 or 1), where a_i=0 if Polycarp works during the i-th hour of the day and a_i=1 if Polycarp rests during the i-th hour of the day.
Days go one after another endlessly and Polycarp uses the same schedule for each day.
What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day.
Input
The first line contains n (1 β€ n β€ 2β
10^5) β number of hours per day.
The second line contains n integer numbers a_1, a_2, ..., a_n (0 β€ a_i β€ 1), where a_i=0 if the i-th hour in a day is working and a_i=1 if the i-th hour is resting. It is guaranteed that a_i=0 for at least one i.
Output
Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day.
Examples
Input
5
1 0 1 0 1
Output
2
Input
6
0 1 0 1 1 0
Output
2
Input
7
1 0 1 1 1 0 1
Output
3
Input
3
0 0 0
Output
0
Note
In the first example, the maximal rest starts in last hour and goes to the first hour of the next day.
In the second example, Polycarp has maximal rest from the 4-th to the 5-th hour.
In the third example, Polycarp has maximal rest from the 3-rd to the 5-th hour.
In the fourth example, Polycarp has no rest at all.
Submitted Solution:
```
hours = input()
x = input().replace(' ', '')
x += x
max_all = 0
max_loc = 0
for i in x:
if i == '1':
max_loc += 1
else:
max_all = max(max_all, max_loc)
max_loc = 0
print(max_all)
``` | instruction | 0 | 864 | 24 | 1,728 |
Yes | output | 1 | 864 | 24 | 1,729 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Each day in Berland consists of n hours. Polycarp likes time management. That's why he has a fixed schedule for each day β it is a sequence a_1, a_2, ..., a_n (each a_i is either 0 or 1), where a_i=0 if Polycarp works during the i-th hour of the day and a_i=1 if Polycarp rests during the i-th hour of the day.
Days go one after another endlessly and Polycarp uses the same schedule for each day.
What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day.
Input
The first line contains n (1 β€ n β€ 2β
10^5) β number of hours per day.
The second line contains n integer numbers a_1, a_2, ..., a_n (0 β€ a_i β€ 1), where a_i=0 if the i-th hour in a day is working and a_i=1 if the i-th hour is resting. It is guaranteed that a_i=0 for at least one i.
Output
Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day.
Examples
Input
5
1 0 1 0 1
Output
2
Input
6
0 1 0 1 1 0
Output
2
Input
7
1 0 1 1 1 0 1
Output
3
Input
3
0 0 0
Output
0
Note
In the first example, the maximal rest starts in last hour and goes to the first hour of the next day.
In the second example, Polycarp has maximal rest from the 4-th to the 5-th hour.
In the third example, Polycarp has maximal rest from the 3-rd to the 5-th hour.
In the fourth example, Polycarp has no rest at all.
Submitted Solution:
```
n=int(input())
k=0
c=0
b=[]
for a in input().split():
b.append(int(a))
for i in range(1,n):
if b[i]==1 and b[i-1]==1:
k+=1
elif b[i]==1:
k=1
if k>c:
c=k
elif k>c:
c=k
if c==0 and b[0]==1:
c=1
if c==1 and b[0]==b[n-1]:
print(2)
else:
print(c)
``` | instruction | 0 | 865 | 24 | 1,730 |
No | output | 1 | 865 | 24 | 1,731 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Each day in Berland consists of n hours. Polycarp likes time management. That's why he has a fixed schedule for each day β it is a sequence a_1, a_2, ..., a_n (each a_i is either 0 or 1), where a_i=0 if Polycarp works during the i-th hour of the day and a_i=1 if Polycarp rests during the i-th hour of the day.
Days go one after another endlessly and Polycarp uses the same schedule for each day.
What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day.
Input
The first line contains n (1 β€ n β€ 2β
10^5) β number of hours per day.
The second line contains n integer numbers a_1, a_2, ..., a_n (0 β€ a_i β€ 1), where a_i=0 if the i-th hour in a day is working and a_i=1 if the i-th hour is resting. It is guaranteed that a_i=0 for at least one i.
Output
Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day.
Examples
Input
5
1 0 1 0 1
Output
2
Input
6
0 1 0 1 1 0
Output
2
Input
7
1 0 1 1 1 0 1
Output
3
Input
3
0 0 0
Output
0
Note
In the first example, the maximal rest starts in last hour and goes to the first hour of the next day.
In the second example, Polycarp has maximal rest from the 4-th to the 5-th hour.
In the third example, Polycarp has maximal rest from the 3-rd to the 5-th hour.
In the fourth example, Polycarp has no rest at all.
Submitted Solution:
```
n = int(input())
a = [str(i) for i in input().split()]
variants = ['1' * j for j in range(1, n + 1)]
rest = [len(i) for i in a if i in a]
a = ''.join(a)
a = list(a)
b = a[:]
a.reverse()
if len(rest) == 0:
print(0)
elif a[:max(rest)] == ['1'] * max(rest) and a[-1] == '1':
print(max(rest) + 1)
elif b[:max(rest)] == ['1'] * max(rest) and b[-1] == '1':
print(max(rest) + 1)
else:
print(max(rest))
``` | instruction | 0 | 866 | 24 | 1,732 |
No | output | 1 | 866 | 24 | 1,733 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Each day in Berland consists of n hours. Polycarp likes time management. That's why he has a fixed schedule for each day β it is a sequence a_1, a_2, ..., a_n (each a_i is either 0 or 1), where a_i=0 if Polycarp works during the i-th hour of the day and a_i=1 if Polycarp rests during the i-th hour of the day.
Days go one after another endlessly and Polycarp uses the same schedule for each day.
What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day.
Input
The first line contains n (1 β€ n β€ 2β
10^5) β number of hours per day.
The second line contains n integer numbers a_1, a_2, ..., a_n (0 β€ a_i β€ 1), where a_i=0 if the i-th hour in a day is working and a_i=1 if the i-th hour is resting. It is guaranteed that a_i=0 for at least one i.
Output
Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day.
Examples
Input
5
1 0 1 0 1
Output
2
Input
6
0 1 0 1 1 0
Output
2
Input
7
1 0 1 1 1 0 1
Output
3
Input
3
0 0 0
Output
0
Note
In the first example, the maximal rest starts in last hour and goes to the first hour of the next day.
In the second example, Polycarp has maximal rest from the 4-th to the 5-th hour.
In the third example, Polycarp has maximal rest from the 3-rd to the 5-th hour.
In the fourth example, Polycarp has no rest at all.
Submitted Solution:
```
n = int(input())
l = []
curr = 0
ans = []
s = input().split()
for i in range(n):
l.append(int(s[i]))
for i in range(n):
if l[i] == 1:
curr += 1
ans.append(curr)
else:
curr = 0
ans.append(0)
if l[0] == 1 and l[n-1] == 1:
i = 0
while l[i] != 0 and i != n-1:
i += 1
if i == n:
print(n)
else:
ans.append(l[n-1] + i)
print(max(ans))
else:
print(max(ans))
``` | instruction | 0 | 867 | 24 | 1,734 |
No | output | 1 | 867 | 24 | 1,735 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Each day in Berland consists of n hours. Polycarp likes time management. That's why he has a fixed schedule for each day β it is a sequence a_1, a_2, ..., a_n (each a_i is either 0 or 1), where a_i=0 if Polycarp works during the i-th hour of the day and a_i=1 if Polycarp rests during the i-th hour of the day.
Days go one after another endlessly and Polycarp uses the same schedule for each day.
What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day.
Input
The first line contains n (1 β€ n β€ 2β
10^5) β number of hours per day.
The second line contains n integer numbers a_1, a_2, ..., a_n (0 β€ a_i β€ 1), where a_i=0 if the i-th hour in a day is working and a_i=1 if the i-th hour is resting. It is guaranteed that a_i=0 for at least one i.
Output
Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day.
Examples
Input
5
1 0 1 0 1
Output
2
Input
6
0 1 0 1 1 0
Output
2
Input
7
1 0 1 1 1 0 1
Output
3
Input
3
0 0 0
Output
0
Note
In the first example, the maximal rest starts in last hour and goes to the first hour of the next day.
In the second example, Polycarp has maximal rest from the 4-th to the 5-th hour.
In the third example, Polycarp has maximal rest from the 3-rd to the 5-th hour.
In the fourth example, Polycarp has no rest at all.
Submitted Solution:
```
import math
if __name__ == "__main__":
n = int(input())
a1, *a = map(int, input().split())
a.insert(0, a1)
i, max_continuous_hour = 0, 0
try:
for _ in range(len(a)):
if a[i] == a[i+1] == 1 and max_continuous_hour < 2:
max_continuous_hour += 1.5
i += 1
except IndexError:
pass
if max_continuous_hour == 0:
if a[0] and a[-1] == 1:
max_continuous_hour += 2
if a[0] or a[-1] == 1:
max_continuous_hour += 1
print(math.ceil(max_continuous_hour))
``` | instruction | 0 | 868 | 24 | 1,736 |
No | output | 1 | 868 | 24 | 1,737 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, number sequence written like "1,2 ,3,..., 10" will be corrected to "1, 2, 3, ..., 10".
In this task you are given a string s, which is composed by a concatination of terms, each of which may be:
* a positive integer of an arbitrary length (leading zeroes are not allowed),
* a "comma" symbol (","),
* a "space" symbol (" "),
* "three dots" ("...", that is, exactly three points written one after another, also known as suspension points).
Polycarp wants to add and remove spaces in the string s to ensure the following:
* each comma is followed by exactly one space (if the comma is the last character in the string, this rule does not apply to it),
* each "three dots" term is preceded by exactly one space (if the dots are at the beginning of the string, this rule does not apply to the term),
* if two consecutive numbers were separated by spaces only (one or more), then exactly one of them should be left,
* there should not be other spaces.
Automate Polycarp's work and write a program that will process the given string s.
Input
The input data contains a single string s. Its length is from 1 to 255 characters. The string s does not begin and end with a space. Its content matches the description given above.
Output
Print the string s after it is processed. Your program's output should be exactly the same as the expected answer. It is permissible to end output line with a line-break character, and without it.
Examples
Input
1,2 ,3,..., 10
Output
1, 2, 3, ..., 10
Input
1,,,4...5......6
Output
1, , , 4 ...5 ... ...6
Input
...,1,2,3,...
Output
..., 1, 2, 3, ... | instruction | 0 | 2,149 | 24 | 4,298 |
Tags: implementation, strings
Correct Solution:
```
ans = input()
while " ," in ans:
ans = ans.replace(" ,", ",")
ans = ans.replace("...", " ...").replace(",", ", ")
for ps, pv in [(" ", " ")]:
while ps in ans: ans = ans.replace(ps, pv)
for d in "0123456789":
ans = ans.replace(". "+d, "."+d)
print(ans.strip(), end="")
``` | output | 1 | 2,149 | 24 | 4,299 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, number sequence written like "1,2 ,3,..., 10" will be corrected to "1, 2, 3, ..., 10".
In this task you are given a string s, which is composed by a concatination of terms, each of which may be:
* a positive integer of an arbitrary length (leading zeroes are not allowed),
* a "comma" symbol (","),
* a "space" symbol (" "),
* "three dots" ("...", that is, exactly three points written one after another, also known as suspension points).
Polycarp wants to add and remove spaces in the string s to ensure the following:
* each comma is followed by exactly one space (if the comma is the last character in the string, this rule does not apply to it),
* each "three dots" term is preceded by exactly one space (if the dots are at the beginning of the string, this rule does not apply to the term),
* if two consecutive numbers were separated by spaces only (one or more), then exactly one of them should be left,
* there should not be other spaces.
Automate Polycarp's work and write a program that will process the given string s.
Input
The input data contains a single string s. Its length is from 1 to 255 characters. The string s does not begin and end with a space. Its content matches the description given above.
Output
Print the string s after it is processed. Your program's output should be exactly the same as the expected answer. It is permissible to end output line with a line-break character, and without it.
Examples
Input
1,2 ,3,..., 10
Output
1, 2, 3, ..., 10
Input
1,,,4...5......6
Output
1, , , 4 ...5 ... ...6
Input
...,1,2,3,...
Output
..., 1, 2, 3, ... | instruction | 0 | 2,150 | 24 | 4,300 |
Tags: implementation, strings
Correct Solution:
```
#Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#-------------------game starts now-----------------------------------------------------
s=input()
l=list()
for i in range(len(s)):
if s[i]==' ':
if s[i-1]!=' ':
l.append(' ')
else:
l.append(s[i])
a=list()
#print(*l,sep='')
num=0
for i in range (len(l)):
if l[i]!=' ':
a.append(l[i])
else:
if l[i-1]!='.' and l[i+1]!='.' and l[i-1]!=',' and l[i+1]!=',':
a.append(' ')
n=len(a)
b=list()
#print(*a,sep='')
b.append(' ')
curr=0
for i in range(n):
if a[i]=='.':
curr+=1
else:
curr=0
if curr==4:
curr=1
if a[i]==',':
b.append(',')
b.append(' ')
elif a[i]=='.':
if curr==1 and b[-1]!=' ':
b.append(' ')
b.append('.')
else:
b.append('.')
else:
b.append(a[i])
j=len(b)
if b[-1]==' ':
j-=1
print(*b[1:j],sep='')
``` | output | 1 | 2,150 | 24 | 4,301 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, number sequence written like "1,2 ,3,..., 10" will be corrected to "1, 2, 3, ..., 10".
In this task you are given a string s, which is composed by a concatination of terms, each of which may be:
* a positive integer of an arbitrary length (leading zeroes are not allowed),
* a "comma" symbol (","),
* a "space" symbol (" "),
* "three dots" ("...", that is, exactly three points written one after another, also known as suspension points).
Polycarp wants to add and remove spaces in the string s to ensure the following:
* each comma is followed by exactly one space (if the comma is the last character in the string, this rule does not apply to it),
* each "three dots" term is preceded by exactly one space (if the dots are at the beginning of the string, this rule does not apply to the term),
* if two consecutive numbers were separated by spaces only (one or more), then exactly one of them should be left,
* there should not be other spaces.
Automate Polycarp's work and write a program that will process the given string s.
Input
The input data contains a single string s. Its length is from 1 to 255 characters. The string s does not begin and end with a space. Its content matches the description given above.
Output
Print the string s after it is processed. Your program's output should be exactly the same as the expected answer. It is permissible to end output line with a line-break character, and without it.
Examples
Input
1,2 ,3,..., 10
Output
1, 2, 3, ..., 10
Input
1,,,4...5......6
Output
1, , , 4 ...5 ... ...6
Input
...,1,2,3,...
Output
..., 1, 2, 3, ... | instruction | 0 | 2,151 | 24 | 4,302 |
Tags: implementation, strings
Correct Solution:
```
import sys
from itertools import *
from math import *
def solve():
s = input()
# s = input().split(',')
res = ""
i = 0
numberfound = False
spacefound = False
while i < len(s):
if s[i] == ' ':
i+=1
continue
if s[i] == '.':
if len(res) > 0 and res[-1] != ' ': res += ' ...'
else: res += '...'
i += 2
if s[i] == ',':
res += ', '
if s[i].isdigit():
if len(res) > 0 and res[-1].isdigit() and i > 0 and s[i-1] == ' ': res+=' '
if not (spacefound and numberfound): res += s[i]
numberfound = True
i += 1
if res[-1] == ' ': res = res[:len(res) - 1]
print(res)
# for term in s:
if sys.hexversion == 50594544 : sys.stdin = open("test.txt")
solve()
``` | output | 1 | 2,151 | 24 | 4,303 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, number sequence written like "1,2 ,3,..., 10" will be corrected to "1, 2, 3, ..., 10".
In this task you are given a string s, which is composed by a concatination of terms, each of which may be:
* a positive integer of an arbitrary length (leading zeroes are not allowed),
* a "comma" symbol (","),
* a "space" symbol (" "),
* "three dots" ("...", that is, exactly three points written one after another, also known as suspension points).
Polycarp wants to add and remove spaces in the string s to ensure the following:
* each comma is followed by exactly one space (if the comma is the last character in the string, this rule does not apply to it),
* each "three dots" term is preceded by exactly one space (if the dots are at the beginning of the string, this rule does not apply to the term),
* if two consecutive numbers were separated by spaces only (one or more), then exactly one of them should be left,
* there should not be other spaces.
Automate Polycarp's work and write a program that will process the given string s.
Input
The input data contains a single string s. Its length is from 1 to 255 characters. The string s does not begin and end with a space. Its content matches the description given above.
Output
Print the string s after it is processed. Your program's output should be exactly the same as the expected answer. It is permissible to end output line with a line-break character, and without it.
Examples
Input
1,2 ,3,..., 10
Output
1, 2, 3, ..., 10
Input
1,,,4...5......6
Output
1, , , 4 ...5 ... ...6
Input
...,1,2,3,...
Output
..., 1, 2, 3, ... | instruction | 0 | 2,152 | 24 | 4,304 |
Tags: implementation, strings
Correct Solution:
```
s=input()
while(' ' in s):
s=s.replace(' ',' ')
while(' ,' in s):
s=s.replace(' ,',',')
while('. ' in s):
s=s.replace('. ','.')
s=s.replace(',',', ')
s=s.replace('...',' ...')
if(s[0]==' '):
s=s[1:]
if(s[-1]==' '):
s=s[:len(s)-1]
while(' ' in s):
s=s.replace(' ',' ')
print(s)
``` | output | 1 | 2,152 | 24 | 4,305 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, number sequence written like "1,2 ,3,..., 10" will be corrected to "1, 2, 3, ..., 10".
In this task you are given a string s, which is composed by a concatination of terms, each of which may be:
* a positive integer of an arbitrary length (leading zeroes are not allowed),
* a "comma" symbol (","),
* a "space" symbol (" "),
* "three dots" ("...", that is, exactly three points written one after another, also known as suspension points).
Polycarp wants to add and remove spaces in the string s to ensure the following:
* each comma is followed by exactly one space (if the comma is the last character in the string, this rule does not apply to it),
* each "three dots" term is preceded by exactly one space (if the dots are at the beginning of the string, this rule does not apply to the term),
* if two consecutive numbers were separated by spaces only (one or more), then exactly one of them should be left,
* there should not be other spaces.
Automate Polycarp's work and write a program that will process the given string s.
Input
The input data contains a single string s. Its length is from 1 to 255 characters. The string s does not begin and end with a space. Its content matches the description given above.
Output
Print the string s after it is processed. Your program's output should be exactly the same as the expected answer. It is permissible to end output line with a line-break character, and without it.
Examples
Input
1,2 ,3,..., 10
Output
1, 2, 3, ..., 10
Input
1,,,4...5......6
Output
1, , , 4 ...5 ... ...6
Input
...,1,2,3,...
Output
..., 1, 2, 3, ... | instruction | 0 | 2,153 | 24 | 4,306 |
Tags: implementation, strings
Correct Solution:
```
import re
s = input().strip()
s = re.sub('(\d)\s+(?=\d)', r'\1x', s)
s = re.sub('\s', '', s)
s = re.sub(',', ', ', s)
s = re.sub('\.\.\.', ' ...', s)
s = re.sub('^\s|\s$', '', s)
s = re.sub('\s\s', ' ', s)
s = re.sub('x', ' ', s)
print(s)
``` | output | 1 | 2,153 | 24 | 4,307 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, number sequence written like "1,2 ,3,..., 10" will be corrected to "1, 2, 3, ..., 10".
In this task you are given a string s, which is composed by a concatination of terms, each of which may be:
* a positive integer of an arbitrary length (leading zeroes are not allowed),
* a "comma" symbol (","),
* a "space" symbol (" "),
* "three dots" ("...", that is, exactly three points written one after another, also known as suspension points).
Polycarp wants to add and remove spaces in the string s to ensure the following:
* each comma is followed by exactly one space (if the comma is the last character in the string, this rule does not apply to it),
* each "three dots" term is preceded by exactly one space (if the dots are at the beginning of the string, this rule does not apply to the term),
* if two consecutive numbers were separated by spaces only (one or more), then exactly one of them should be left,
* there should not be other spaces.
Automate Polycarp's work and write a program that will process the given string s.
Input
The input data contains a single string s. Its length is from 1 to 255 characters. The string s does not begin and end with a space. Its content matches the description given above.
Output
Print the string s after it is processed. Your program's output should be exactly the same as the expected answer. It is permissible to end output line with a line-break character, and without it.
Examples
Input
1,2 ,3,..., 10
Output
1, 2, 3, ..., 10
Input
1,,,4...5......6
Output
1, , , 4 ...5 ... ...6
Input
...,1,2,3,...
Output
..., 1, 2, 3, ... | instruction | 0 | 2,154 | 24 | 4,308 |
Tags: implementation, strings
Correct Solution:
```
ans = input()
while " ," in ans:
ans = ans.replace(" ,", ",")
ans = ans.replace("...", " ...").replace(",", ", ")
while " " in ans:
ans = ans.replace(" ", " ")
for d in "0123456789": ans = ans.replace(". " + d, "." + d)
print(ans.strip(), end="")
``` | output | 1 | 2,154 | 24 | 4,309 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, number sequence written like "1,2 ,3,..., 10" will be corrected to "1, 2, 3, ..., 10".
In this task you are given a string s, which is composed by a concatination of terms, each of which may be:
* a positive integer of an arbitrary length (leading zeroes are not allowed),
* a "comma" symbol (","),
* a "space" symbol (" "),
* "three dots" ("...", that is, exactly three points written one after another, also known as suspension points).
Polycarp wants to add and remove spaces in the string s to ensure the following:
* each comma is followed by exactly one space (if the comma is the last character in the string, this rule does not apply to it),
* each "three dots" term is preceded by exactly one space (if the dots are at the beginning of the string, this rule does not apply to the term),
* if two consecutive numbers were separated by spaces only (one or more), then exactly one of them should be left,
* there should not be other spaces.
Automate Polycarp's work and write a program that will process the given string s.
Input
The input data contains a single string s. Its length is from 1 to 255 characters. The string s does not begin and end with a space. Its content matches the description given above.
Output
Print the string s after it is processed. Your program's output should be exactly the same as the expected answer. It is permissible to end output line with a line-break character, and without it.
Examples
Input
1,2 ,3,..., 10
Output
1, 2, 3, ..., 10
Input
1,,,4...5......6
Output
1, , , 4 ...5 ... ...6
Input
...,1,2,3,...
Output
..., 1, 2, 3, ... | instruction | 0 | 2,155 | 24 | 4,310 |
Tags: implementation, strings
Correct Solution:
```
from sys import stdin,stdout
from math import gcd, ceil, sqrt
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
mod = 1000000007
s = is1()
res = ""
for j,i in enumerate(s):
if i == ',':
res += ", "
elif i.isdigit():
if s[j - 1] == " " and res[-1].isdigit():
res+=" "
res += i
elif i == ".":
if len(res)>0 and res[-1] != " " and res[-1] != ".":
res += " "
if len(res) >= 3 and res[-1] == "." and res[-2] == '.' and res[-3] == '.':
res+=" "
res += "."
elif i == " ":
if len(res)>0 and res[-1] not in "0123456789 .":
res += " "
print(res.strip())
``` | output | 1 | 2,155 | 24 | 4,311 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, number sequence written like "1,2 ,3,..., 10" will be corrected to "1, 2, 3, ..., 10".
In this task you are given a string s, which is composed by a concatination of terms, each of which may be:
* a positive integer of an arbitrary length (leading zeroes are not allowed),
* a "comma" symbol (","),
* a "space" symbol (" "),
* "three dots" ("...", that is, exactly three points written one after another, also known as suspension points).
Polycarp wants to add and remove spaces in the string s to ensure the following:
* each comma is followed by exactly one space (if the comma is the last character in the string, this rule does not apply to it),
* each "three dots" term is preceded by exactly one space (if the dots are at the beginning of the string, this rule does not apply to the term),
* if two consecutive numbers were separated by spaces only (one or more), then exactly one of them should be left,
* there should not be other spaces.
Automate Polycarp's work and write a program that will process the given string s.
Input
The input data contains a single string s. Its length is from 1 to 255 characters. The string s does not begin and end with a space. Its content matches the description given above.
Output
Print the string s after it is processed. Your program's output should be exactly the same as the expected answer. It is permissible to end output line with a line-break character, and without it.
Examples
Input
1,2 ,3,..., 10
Output
1, 2, 3, ..., 10
Input
1,,,4...5......6
Output
1, , , 4 ...5 ... ...6
Input
...,1,2,3,...
Output
..., 1, 2, 3, ... | instruction | 0 | 2,156 | 24 | 4,312 |
Tags: implementation, strings
Correct Solution:
```
s=input()
ans=' '.join(s.split())
ans=ans.replace(', ',',')
ans=ans.replace(' ,',',')
ans=ans.replace(',',', ')
ans=ans.replace('... ','...')
ans=ans.replace(' ...','...')
ans=ans.replace('...',' ...')
if ans[0]==' ':
ans=ans[:0]+ans[1:]
if ans[-1]==' ':
ans=ans[:-1]
print(ans)
``` | output | 1 | 2,156 | 24 | 4,313 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, number sequence written like "1,2 ,3,..., 10" will be corrected to "1, 2, 3, ..., 10".
In this task you are given a string s, which is composed by a concatination of terms, each of which may be:
* a positive integer of an arbitrary length (leading zeroes are not allowed),
* a "comma" symbol (","),
* a "space" symbol (" "),
* "three dots" ("...", that is, exactly three points written one after another, also known as suspension points).
Polycarp wants to add and remove spaces in the string s to ensure the following:
* each comma is followed by exactly one space (if the comma is the last character in the string, this rule does not apply to it),
* each "three dots" term is preceded by exactly one space (if the dots are at the beginning of the string, this rule does not apply to the term),
* if two consecutive numbers were separated by spaces only (one or more), then exactly one of them should be left,
* there should not be other spaces.
Automate Polycarp's work and write a program that will process the given string s.
Input
The input data contains a single string s. Its length is from 1 to 255 characters. The string s does not begin and end with a space. Its content matches the description given above.
Output
Print the string s after it is processed. Your program's output should be exactly the same as the expected answer. It is permissible to end output line with a line-break character, and without it.
Examples
Input
1,2 ,3,..., 10
Output
1, 2, 3, ..., 10
Input
1,,,4...5......6
Output
1, , , 4 ...5 ... ...6
Input
...,1,2,3,...
Output
..., 1, 2, 3, ...
Submitted Solution:
```
a=input()
b=''
c=0
n=len(a)
d=0
e=0
for i in range(n):
if a[i]=='.':
if c%3==0 and i!=0 and (e==0 or b[-1]!=' '):
b+=' '
e+=1
b+=a[i]
e+=1
c+=1
d=0
elif a[i]==',':
b+=a[i]
e+=1
if i!=n-1:
b+=' '
e+=1
d=0
elif a[i]!=' ':
if d==2:
b+=' '
e+=1
b+=a[i]
e+=1
d=1
else:
if d==1:
d=2
print(b)
``` | instruction | 0 | 2,157 | 24 | 4,314 |
Yes | output | 1 | 2,157 | 24 | 4,315 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, number sequence written like "1,2 ,3,..., 10" will be corrected to "1, 2, 3, ..., 10".
In this task you are given a string s, which is composed by a concatination of terms, each of which may be:
* a positive integer of an arbitrary length (leading zeroes are not allowed),
* a "comma" symbol (","),
* a "space" symbol (" "),
* "three dots" ("...", that is, exactly three points written one after another, also known as suspension points).
Polycarp wants to add and remove spaces in the string s to ensure the following:
* each comma is followed by exactly one space (if the comma is the last character in the string, this rule does not apply to it),
* each "three dots" term is preceded by exactly one space (if the dots are at the beginning of the string, this rule does not apply to the term),
* if two consecutive numbers were separated by spaces only (one or more), then exactly one of them should be left,
* there should not be other spaces.
Automate Polycarp's work and write a program that will process the given string s.
Input
The input data contains a single string s. Its length is from 1 to 255 characters. The string s does not begin and end with a space. Its content matches the description given above.
Output
Print the string s after it is processed. Your program's output should be exactly the same as the expected answer. It is permissible to end output line with a line-break character, and without it.
Examples
Input
1,2 ,3,..., 10
Output
1, 2, 3, ..., 10
Input
1,,,4...5......6
Output
1, , , 4 ...5 ... ...6
Input
...,1,2,3,...
Output
..., 1, 2, 3, ...
Submitted Solution:
```
s = input()
res = ''
i = 0
while i < len(s):
if s[i] == ',':
res += ','
if i != len(s)-1:
res += ' '
elif s[i] == '.':
if len(res) != 0:
if res[-1] != ' ':
res += ' '
res += '...'
i += 2
elif s[i].isdigit():
if len(res) != 0:
if s[i-1] == ' ' and res[-1].isdigit():
res += ' '
res += s[i]
i += 1
print(res)
``` | instruction | 0 | 2,158 | 24 | 4,316 |
Yes | output | 1 | 2,158 | 24 | 4,317 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, number sequence written like "1,2 ,3,..., 10" will be corrected to "1, 2, 3, ..., 10".
In this task you are given a string s, which is composed by a concatination of terms, each of which may be:
* a positive integer of an arbitrary length (leading zeroes are not allowed),
* a "comma" symbol (","),
* a "space" symbol (" "),
* "three dots" ("...", that is, exactly three points written one after another, also known as suspension points).
Polycarp wants to add and remove spaces in the string s to ensure the following:
* each comma is followed by exactly one space (if the comma is the last character in the string, this rule does not apply to it),
* each "three dots" term is preceded by exactly one space (if the dots are at the beginning of the string, this rule does not apply to the term),
* if two consecutive numbers were separated by spaces only (one or more), then exactly one of them should be left,
* there should not be other spaces.
Automate Polycarp's work and write a program that will process the given string s.
Input
The input data contains a single string s. Its length is from 1 to 255 characters. The string s does not begin and end with a space. Its content matches the description given above.
Output
Print the string s after it is processed. Your program's output should be exactly the same as the expected answer. It is permissible to end output line with a line-break character, and without it.
Examples
Input
1,2 ,3,..., 10
Output
1, 2, 3, ..., 10
Input
1,,,4...5......6
Output
1, , , 4 ...5 ... ...6
Input
...,1,2,3,...
Output
..., 1, 2, 3, ...
Submitted Solution:
```
s=input()
u=' '.join(s.split())
u=u.replace(', ',',')
u=u.replace(' ,',',')
u=u.replace(',',', ')
u=u.replace('... ','...')
u=u.replace(' ...','...')
u=u.replace('...',' ...')
if u[0]==' ':
u=u[:0]+u[1:]
if u[-1]==' ':
u=u[:-1]
print(u)
``` | instruction | 0 | 2,159 | 24 | 4,318 |
Yes | output | 1 | 2,159 | 24 | 4,319 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, number sequence written like "1,2 ,3,..., 10" will be corrected to "1, 2, 3, ..., 10".
In this task you are given a string s, which is composed by a concatination of terms, each of which may be:
* a positive integer of an arbitrary length (leading zeroes are not allowed),
* a "comma" symbol (","),
* a "space" symbol (" "),
* "three dots" ("...", that is, exactly three points written one after another, also known as suspension points).
Polycarp wants to add and remove spaces in the string s to ensure the following:
* each comma is followed by exactly one space (if the comma is the last character in the string, this rule does not apply to it),
* each "three dots" term is preceded by exactly one space (if the dots are at the beginning of the string, this rule does not apply to the term),
* if two consecutive numbers were separated by spaces only (one or more), then exactly one of them should be left,
* there should not be other spaces.
Automate Polycarp's work and write a program that will process the given string s.
Input
The input data contains a single string s. Its length is from 1 to 255 characters. The string s does not begin and end with a space. Its content matches the description given above.
Output
Print the string s after it is processed. Your program's output should be exactly the same as the expected answer. It is permissible to end output line with a line-break character, and without it.
Examples
Input
1,2 ,3,..., 10
Output
1, 2, 3, ..., 10
Input
1,,,4...5......6
Output
1, , , 4 ...5 ... ...6
Input
...,1,2,3,...
Output
..., 1, 2, 3, ...
Submitted Solution:
```
s = input()
for i in range(255):
s = s.replace(', ', ',')
s = s.replace(' ,', ',')
s = s.replace(' ...', '...')
s = s.replace('... ', '...')
s = s.replace(' ', ' ')
s = s.replace(',.', ', .')
for i in range(255):
s = s.replace(',,', ', ,')
s = s.replace('......', '... ...')
for i in range(10):
s = s.replace(',' + str(i), ', ' + str(i))
s = s.replace(str(i) + '...', str(i) + ' ...')
print(s.strip())
``` | instruction | 0 | 2,160 | 24 | 4,320 |
Yes | output | 1 | 2,160 | 24 | 4,321 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, number sequence written like "1,2 ,3,..., 10" will be corrected to "1, 2, 3, ..., 10".
In this task you are given a string s, which is composed by a concatination of terms, each of which may be:
* a positive integer of an arbitrary length (leading zeroes are not allowed),
* a "comma" symbol (","),
* a "space" symbol (" "),
* "three dots" ("...", that is, exactly three points written one after another, also known as suspension points).
Polycarp wants to add and remove spaces in the string s to ensure the following:
* each comma is followed by exactly one space (if the comma is the last character in the string, this rule does not apply to it),
* each "three dots" term is preceded by exactly one space (if the dots are at the beginning of the string, this rule does not apply to the term),
* if two consecutive numbers were separated by spaces only (one or more), then exactly one of them should be left,
* there should not be other spaces.
Automate Polycarp's work and write a program that will process the given string s.
Input
The input data contains a single string s. Its length is from 1 to 255 characters. The string s does not begin and end with a space. Its content matches the description given above.
Output
Print the string s after it is processed. Your program's output should be exactly the same as the expected answer. It is permissible to end output line with a line-break character, and without it.
Examples
Input
1,2 ,3,..., 10
Output
1, 2, 3, ..., 10
Input
1,,,4...5......6
Output
1, , , 4 ...5 ... ...6
Input
...,1,2,3,...
Output
..., 1, 2, 3, ...
Submitted Solution:
```
s = input()
s = s.split(" ")
s = [ i for i in s if len(i)]
s = " ".join(s)
s = s.strip()
s = s.split(",")
s = [i.strip() for i in s]
s = ", ".join(s).strip()
s = s.split("...")
s = " ...".join(s)
print(s.strip())
``` | instruction | 0 | 2,161 | 24 | 4,322 |
No | output | 1 | 2,161 | 24 | 4,323 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, number sequence written like "1,2 ,3,..., 10" will be corrected to "1, 2, 3, ..., 10".
In this task you are given a string s, which is composed by a concatination of terms, each of which may be:
* a positive integer of an arbitrary length (leading zeroes are not allowed),
* a "comma" symbol (","),
* a "space" symbol (" "),
* "three dots" ("...", that is, exactly three points written one after another, also known as suspension points).
Polycarp wants to add and remove spaces in the string s to ensure the following:
* each comma is followed by exactly one space (if the comma is the last character in the string, this rule does not apply to it),
* each "three dots" term is preceded by exactly one space (if the dots are at the beginning of the string, this rule does not apply to the term),
* if two consecutive numbers were separated by spaces only (one or more), then exactly one of them should be left,
* there should not be other spaces.
Automate Polycarp's work and write a program that will process the given string s.
Input
The input data contains a single string s. Its length is from 1 to 255 characters. The string s does not begin and end with a space. Its content matches the description given above.
Output
Print the string s after it is processed. Your program's output should be exactly the same as the expected answer. It is permissible to end output line with a line-break character, and without it.
Examples
Input
1,2 ,3,..., 10
Output
1, 2, 3, ..., 10
Input
1,,,4...5......6
Output
1, , , 4 ...5 ... ...6
Input
...,1,2,3,...
Output
..., 1, 2, 3, ...
Submitted Solution:
```
s = input()
while ' ' in s:
s = s.replace(' ', ' ')
print(s.replace('...', ' ...').replace(' ,', ',')
.replace(', ', ',').replace(',', ', ').strip())
``` | instruction | 0 | 2,162 | 24 | 4,324 |
No | output | 1 | 2,162 | 24 | 4,325 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, number sequence written like "1,2 ,3,..., 10" will be corrected to "1, 2, 3, ..., 10".
In this task you are given a string s, which is composed by a concatination of terms, each of which may be:
* a positive integer of an arbitrary length (leading zeroes are not allowed),
* a "comma" symbol (","),
* a "space" symbol (" "),
* "three dots" ("...", that is, exactly three points written one after another, also known as suspension points).
Polycarp wants to add and remove spaces in the string s to ensure the following:
* each comma is followed by exactly one space (if the comma is the last character in the string, this rule does not apply to it),
* each "three dots" term is preceded by exactly one space (if the dots are at the beginning of the string, this rule does not apply to the term),
* if two consecutive numbers were separated by spaces only (one or more), then exactly one of them should be left,
* there should not be other spaces.
Automate Polycarp's work and write a program that will process the given string s.
Input
The input data contains a single string s. Its length is from 1 to 255 characters. The string s does not begin and end with a space. Its content matches the description given above.
Output
Print the string s after it is processed. Your program's output should be exactly the same as the expected answer. It is permissible to end output line with a line-break character, and without it.
Examples
Input
1,2 ,3,..., 10
Output
1, 2, 3, ..., 10
Input
1,,,4...5......6
Output
1, , , 4 ...5 ... ...6
Input
...,1,2,3,...
Output
..., 1, 2, 3, ...
Submitted Solution:
```
v = input()
while " " in v: v = v.replace(" ", " ")
i = -1
ln = len(v)
acc = ""
def next():
global i
i += 1
if i >= ln:
return None
return v[i]
while True:
c = next()
if c == None: break
if c in "0123456789":
if len(acc) > 0 and acc[-1] == ",":
acc += " "
acc += c
if c == " ":
if len(acc) > 0 and acc[-1] != " ":
acc += c
if c == ".":
if len(acc) > 0 and acc[-1] != " ":
acc += " "
next(); next();
acc += "..."
if c == ",":
if len(acc) > 1 and acc[-1] == " " and acc[-2] != ",":
acc = acc[:-1] + ","
else:
if len(acc) > 0 and acc[-1] == ",":
acc += " "
acc += ","
print(acc.strip())
``` | instruction | 0 | 2,163 | 24 | 4,326 |
No | output | 1 | 2,163 | 24 | 4,327 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, number sequence written like "1,2 ,3,..., 10" will be corrected to "1, 2, 3, ..., 10".
In this task you are given a string s, which is composed by a concatination of terms, each of which may be:
* a positive integer of an arbitrary length (leading zeroes are not allowed),
* a "comma" symbol (","),
* a "space" symbol (" "),
* "three dots" ("...", that is, exactly three points written one after another, also known as suspension points).
Polycarp wants to add and remove spaces in the string s to ensure the following:
* each comma is followed by exactly one space (if the comma is the last character in the string, this rule does not apply to it),
* each "three dots" term is preceded by exactly one space (if the dots are at the beginning of the string, this rule does not apply to the term),
* if two consecutive numbers were separated by spaces only (one or more), then exactly one of them should be left,
* there should not be other spaces.
Automate Polycarp's work and write a program that will process the given string s.
Input
The input data contains a single string s. Its length is from 1 to 255 characters. The string s does not begin and end with a space. Its content matches the description given above.
Output
Print the string s after it is processed. Your program's output should be exactly the same as the expected answer. It is permissible to end output line with a line-break character, and without it.
Examples
Input
1,2 ,3,..., 10
Output
1, 2, 3, ..., 10
Input
1,,,4...5......6
Output
1, , , 4 ...5 ... ...6
Input
...,1,2,3,...
Output
..., 1, 2, 3, ...
Submitted Solution:
```
t, s, i, a, v = ' ', input() + ' ', 0, [], ' '
while i < len(s):
if s[i] == ',':
a.append(',')
elif s[i] == '.':
a.append('...')
i += 2
elif s[i].isdigit():
j = i
while s[j].isdigit():
j += 1
a.append(s[i:j])
i = j - 1
i += 1
a.append(' ')
i = 0
while i < len(a):
if a[i] == ',':
v += ', '
elif a[i] == '...':
v += (' ' if v[-1] != ' ' else '') + '...'
elif a[i].isdigit():
if a[i + 1].isdigit():
a.pop(i + 1)
v += (' ' if v[-1].isdigit() else '') + a[i]
i += 1
print(v.strip())
``` | instruction | 0 | 2,164 | 24 | 4,328 |
No | output | 1 | 2,164 | 24 | 4,329 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is preparing the first programming contest for robots. There are n problems in it, and a lot of robots are going to participate in it. Each robot solving the problem i gets p_i points, and the score of each robot in the competition is calculated as the sum of p_i over all problems i solved by it. For each problem, p_i is an integer not less than 1.
Two corporations specializing in problem-solving robot manufacturing, "Robo-Coder Inc." and "BionicSolver Industries", are going to register two robots (one for each corporation) for participation as well. Polycarp knows the advantages and flaws of robots produced by these companies, so, for each problem, he knows precisely whether each robot will solve it during the competition. Knowing this, he can try predicting the results β or manipulating them.
For some reason (which absolutely cannot involve bribing), Polycarp wants the "Robo-Coder Inc." robot to outperform the "BionicSolver Industries" robot in the competition. Polycarp wants to set the values of p_i in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot. However, if the values of p_i will be large, it may look very suspicious β so Polycarp wants to minimize the maximum value of p_i over all problems. Can you help Polycarp to determine the minimum possible upper bound on the number of points given for solving the problems?
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of problems.
The second line contains n integers r_1, r_2, ..., r_n (0 β€ r_i β€ 1). r_i = 1 means that the "Robo-Coder Inc." robot will solve the i-th problem, r_i = 0 means that it won't solve the i-th problem.
The third line contains n integers b_1, b_2, ..., b_n (0 β€ b_i β€ 1). b_i = 1 means that the "BionicSolver Industries" robot will solve the i-th problem, b_i = 0 means that it won't solve the i-th problem.
Output
If "Robo-Coder Inc." robot cannot outperform the "BionicSolver Industries" robot by any means, print one integer -1.
Otherwise, print the minimum possible value of max _{i = 1}^{n} p_i, if all values of p_i are set in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot.
Examples
Input
5
1 1 1 0 0
0 1 1 1 1
Output
3
Input
3
0 0 0
0 0 0
Output
-1
Input
4
1 1 1 1
1 1 1 1
Output
-1
Input
9
1 0 0 0 0 0 0 0 1
0 1 1 0 1 1 1 1 0
Output
4
Note
In the first example, one of the valid score assignments is p = [3, 1, 3, 1, 1]. Then the "Robo-Coder" gets 7 points, the "BionicSolver" β 6 points.
In the second example, both robots get 0 points, and the score distribution does not matter.
In the third example, both robots solve all problems, so their points are equal. | instruction | 0 | 2,601 | 24 | 5,202 |
Tags: greedy
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cn, nc = 0, 0
for i in range(n) :
if a[i] and (not b[i]) :
cn += 1
elif (not a[i]) and b[i] :
nc += 1
if not cn :
print(-1)
else :
print((nc + cn) // cn)
``` | output | 1 | 2,601 | 24 | 5,203 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is preparing the first programming contest for robots. There are n problems in it, and a lot of robots are going to participate in it. Each robot solving the problem i gets p_i points, and the score of each robot in the competition is calculated as the sum of p_i over all problems i solved by it. For each problem, p_i is an integer not less than 1.
Two corporations specializing in problem-solving robot manufacturing, "Robo-Coder Inc." and "BionicSolver Industries", are going to register two robots (one for each corporation) for participation as well. Polycarp knows the advantages and flaws of robots produced by these companies, so, for each problem, he knows precisely whether each robot will solve it during the competition. Knowing this, he can try predicting the results β or manipulating them.
For some reason (which absolutely cannot involve bribing), Polycarp wants the "Robo-Coder Inc." robot to outperform the "BionicSolver Industries" robot in the competition. Polycarp wants to set the values of p_i in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot. However, if the values of p_i will be large, it may look very suspicious β so Polycarp wants to minimize the maximum value of p_i over all problems. Can you help Polycarp to determine the minimum possible upper bound on the number of points given for solving the problems?
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of problems.
The second line contains n integers r_1, r_2, ..., r_n (0 β€ r_i β€ 1). r_i = 1 means that the "Robo-Coder Inc." robot will solve the i-th problem, r_i = 0 means that it won't solve the i-th problem.
The third line contains n integers b_1, b_2, ..., b_n (0 β€ b_i β€ 1). b_i = 1 means that the "BionicSolver Industries" robot will solve the i-th problem, b_i = 0 means that it won't solve the i-th problem.
Output
If "Robo-Coder Inc." robot cannot outperform the "BionicSolver Industries" robot by any means, print one integer -1.
Otherwise, print the minimum possible value of max _{i = 1}^{n} p_i, if all values of p_i are set in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot.
Examples
Input
5
1 1 1 0 0
0 1 1 1 1
Output
3
Input
3
0 0 0
0 0 0
Output
-1
Input
4
1 1 1 1
1 1 1 1
Output
-1
Input
9
1 0 0 0 0 0 0 0 1
0 1 1 0 1 1 1 1 0
Output
4
Note
In the first example, one of the valid score assignments is p = [3, 1, 3, 1, 1]. Then the "Robo-Coder" gets 7 points, the "BionicSolver" β 6 points.
In the second example, both robots get 0 points, and the score distribution does not matter.
In the third example, both robots solve all problems, so their points are equal. | instruction | 0 | 2,602 | 24 | 5,204 |
Tags: greedy
Correct Solution:
```
n=int(input())
r = list(map(int, input().split()))
b = list(map(int, input().split()))
rr=0
bb=0
for i in range(n):
if r[i]>b[i]:
rr+=1
elif r[i]<b[i]:
bb+=1
if rr==0:
print('-1')
else:
print(max(1, bb//rr + 1))
``` | output | 1 | 2,602 | 24 | 5,205 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is preparing the first programming contest for robots. There are n problems in it, and a lot of robots are going to participate in it. Each robot solving the problem i gets p_i points, and the score of each robot in the competition is calculated as the sum of p_i over all problems i solved by it. For each problem, p_i is an integer not less than 1.
Two corporations specializing in problem-solving robot manufacturing, "Robo-Coder Inc." and "BionicSolver Industries", are going to register two robots (one for each corporation) for participation as well. Polycarp knows the advantages and flaws of robots produced by these companies, so, for each problem, he knows precisely whether each robot will solve it during the competition. Knowing this, he can try predicting the results β or manipulating them.
For some reason (which absolutely cannot involve bribing), Polycarp wants the "Robo-Coder Inc." robot to outperform the "BionicSolver Industries" robot in the competition. Polycarp wants to set the values of p_i in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot. However, if the values of p_i will be large, it may look very suspicious β so Polycarp wants to minimize the maximum value of p_i over all problems. Can you help Polycarp to determine the minimum possible upper bound on the number of points given for solving the problems?
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of problems.
The second line contains n integers r_1, r_2, ..., r_n (0 β€ r_i β€ 1). r_i = 1 means that the "Robo-Coder Inc." robot will solve the i-th problem, r_i = 0 means that it won't solve the i-th problem.
The third line contains n integers b_1, b_2, ..., b_n (0 β€ b_i β€ 1). b_i = 1 means that the "BionicSolver Industries" robot will solve the i-th problem, b_i = 0 means that it won't solve the i-th problem.
Output
If "Robo-Coder Inc." robot cannot outperform the "BionicSolver Industries" robot by any means, print one integer -1.
Otherwise, print the minimum possible value of max _{i = 1}^{n} p_i, if all values of p_i are set in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot.
Examples
Input
5
1 1 1 0 0
0 1 1 1 1
Output
3
Input
3
0 0 0
0 0 0
Output
-1
Input
4
1 1 1 1
1 1 1 1
Output
-1
Input
9
1 0 0 0 0 0 0 0 1
0 1 1 0 1 1 1 1 0
Output
4
Note
In the first example, one of the valid score assignments is p = [3, 1, 3, 1, 1]. Then the "Robo-Coder" gets 7 points, the "BionicSolver" β 6 points.
In the second example, both robots get 0 points, and the score distribution does not matter.
In the third example, both robots solve all problems, so their points are equal. | instruction | 0 | 2,603 | 24 | 5,206 |
Tags: greedy
Correct Solution:
```
import sys
import os
import time
import collections
from collections import Counter, deque
import itertools
import math
import timeit
import random
import string
#########################
# imgur.com/Pkt7iIf.png #
#########################
def sieve(n):
if n < 2: return list()
prime = [True for _ in range(n + 1)]
p = 3
while p * p <= n:
if prime[p]:
for i in range(p * 2, n + 1, p):
prime[i] = False
p += 2
r = [2]
for p in range(3, n + 1, 2):
if prime[p]:
r.append(p)
return r
def divs(n, start=1):
divisors = []
for i in range(start, int(math.sqrt(n) + 1)):
if n % i == 0:
if n / i == i:
divisors.append(i)
else:
divisors.extend([i, n // i])
return divisors
def divn(n, primes):
divs_number = 1
for i in primes:
if n == 1:
return divs_number
t = 1
while n % i == 0:
t += 1
n //= i
divs_number *= t
def flin(d, x, default=-1):
left = right = -1
for i in range(len(d)):
if d[i] == x:
if left == -1: left = i
right = i
if left == -1:
return (default, default)
else:
return (left, right)
def ceil(n, k): return n // k + (n % k != 0)
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(map(int, input().split()))
def lcm(a, b): return abs(a * b) // math.gcd(a, b)
def prr(a, sep=' '): print(sep.join(map(str, a)))
def dd(): return collections.defaultdict(int)
def ddl(): return collections.defaultdict(list)
input = sys.stdin.readline
n = ii()
a = li()
b = li()
ar = br = 0
for i in range(n):
if a[i] == 1 != b[i]:
ar += 1
elif b[i] == 1 != a[i]:
br += 1
if ar == 0:
print(-1)
else:
print(ceil(br + 1, ar))
``` | output | 1 | 2,603 | 24 | 5,207 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is preparing the first programming contest for robots. There are n problems in it, and a lot of robots are going to participate in it. Each robot solving the problem i gets p_i points, and the score of each robot in the competition is calculated as the sum of p_i over all problems i solved by it. For each problem, p_i is an integer not less than 1.
Two corporations specializing in problem-solving robot manufacturing, "Robo-Coder Inc." and "BionicSolver Industries", are going to register two robots (one for each corporation) for participation as well. Polycarp knows the advantages and flaws of robots produced by these companies, so, for each problem, he knows precisely whether each robot will solve it during the competition. Knowing this, he can try predicting the results β or manipulating them.
For some reason (which absolutely cannot involve bribing), Polycarp wants the "Robo-Coder Inc." robot to outperform the "BionicSolver Industries" robot in the competition. Polycarp wants to set the values of p_i in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot. However, if the values of p_i will be large, it may look very suspicious β so Polycarp wants to minimize the maximum value of p_i over all problems. Can you help Polycarp to determine the minimum possible upper bound on the number of points given for solving the problems?
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of problems.
The second line contains n integers r_1, r_2, ..., r_n (0 β€ r_i β€ 1). r_i = 1 means that the "Robo-Coder Inc." robot will solve the i-th problem, r_i = 0 means that it won't solve the i-th problem.
The third line contains n integers b_1, b_2, ..., b_n (0 β€ b_i β€ 1). b_i = 1 means that the "BionicSolver Industries" robot will solve the i-th problem, b_i = 0 means that it won't solve the i-th problem.
Output
If "Robo-Coder Inc." robot cannot outperform the "BionicSolver Industries" robot by any means, print one integer -1.
Otherwise, print the minimum possible value of max _{i = 1}^{n} p_i, if all values of p_i are set in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot.
Examples
Input
5
1 1 1 0 0
0 1 1 1 1
Output
3
Input
3
0 0 0
0 0 0
Output
-1
Input
4
1 1 1 1
1 1 1 1
Output
-1
Input
9
1 0 0 0 0 0 0 0 1
0 1 1 0 1 1 1 1 0
Output
4
Note
In the first example, one of the valid score assignments is p = [3, 1, 3, 1, 1]. Then the "Robo-Coder" gets 7 points, the "BionicSolver" β 6 points.
In the second example, both robots get 0 points, and the score distribution does not matter.
In the third example, both robots solve all problems, so their points are equal. | instruction | 0 | 2,604 | 24 | 5,208 |
Tags: greedy
Correct Solution:
```
n = int(input())
r = list(map(int, input().split()))
b = list(map(int, input().split()))
nr = nb = 0
for i in range(n):
if r[i] and not b[i]:
nr += 1
elif not r[i] and b[i]:
nb += 1
if not nr:
print(-1)
exit()
ret = 1
while nr * ret <= nb:
ret += 1
print(ret)
``` | output | 1 | 2,604 | 24 | 5,209 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is preparing the first programming contest for robots. There are n problems in it, and a lot of robots are going to participate in it. Each robot solving the problem i gets p_i points, and the score of each robot in the competition is calculated as the sum of p_i over all problems i solved by it. For each problem, p_i is an integer not less than 1.
Two corporations specializing in problem-solving robot manufacturing, "Robo-Coder Inc." and "BionicSolver Industries", are going to register two robots (one for each corporation) for participation as well. Polycarp knows the advantages and flaws of robots produced by these companies, so, for each problem, he knows precisely whether each robot will solve it during the competition. Knowing this, he can try predicting the results β or manipulating them.
For some reason (which absolutely cannot involve bribing), Polycarp wants the "Robo-Coder Inc." robot to outperform the "BionicSolver Industries" robot in the competition. Polycarp wants to set the values of p_i in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot. However, if the values of p_i will be large, it may look very suspicious β so Polycarp wants to minimize the maximum value of p_i over all problems. Can you help Polycarp to determine the minimum possible upper bound on the number of points given for solving the problems?
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of problems.
The second line contains n integers r_1, r_2, ..., r_n (0 β€ r_i β€ 1). r_i = 1 means that the "Robo-Coder Inc." robot will solve the i-th problem, r_i = 0 means that it won't solve the i-th problem.
The third line contains n integers b_1, b_2, ..., b_n (0 β€ b_i β€ 1). b_i = 1 means that the "BionicSolver Industries" robot will solve the i-th problem, b_i = 0 means that it won't solve the i-th problem.
Output
If "Robo-Coder Inc." robot cannot outperform the "BionicSolver Industries" robot by any means, print one integer -1.
Otherwise, print the minimum possible value of max _{i = 1}^{n} p_i, if all values of p_i are set in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot.
Examples
Input
5
1 1 1 0 0
0 1 1 1 1
Output
3
Input
3
0 0 0
0 0 0
Output
-1
Input
4
1 1 1 1
1 1 1 1
Output
-1
Input
9
1 0 0 0 0 0 0 0 1
0 1 1 0 1 1 1 1 0
Output
4
Note
In the first example, one of the valid score assignments is p = [3, 1, 3, 1, 1]. Then the "Robo-Coder" gets 7 points, the "BionicSolver" β 6 points.
In the second example, both robots get 0 points, and the score distribution does not matter.
In the third example, both robots solve all problems, so their points are equal. | instruction | 0 | 2,605 | 24 | 5,210 |
Tags: greedy
Correct Solution:
```
'''def robots(t,q,s):
if q == s or sum(q) == 0:
return -1
else:
lista = []
cont = 0
p = []
l = []
e = 0
for i in range(t):
p.append(1)
if q[i] == 1:
lista.append([1,0,i])
l.append(1)
e += 1
if s[i] == 1:
cont += 1
for c in range(t):
contdois = 0
while contdois < cont+1:
for j in range(len(lista)):
if sum(l) < cont+1:
p[lista[j][2]] += 1
l[j] += 1
if s[lista[j][2]] == 1:
cont += 1
contdois += 1
return max(p)
t = int(input())
q = list(map(int,input().split()))
s = list(map(int,input().split()))
print(robots(t,q,s))'''
def robots(t,r,b):
if r == b or sum(r) == 0:
return -1
else:
x = 0
y = 0
for i in range(t):
if r[i] > b[i]:
x += 1
elif r[i] < b[i]:
y += 1
if x == 0:
return -1
else:
return (y+1)//x + bool((y+1)%x)
t = int(input())
q = list(map(int,input().split()))
s = list(map(int,input().split()))
print(robots(t,q,s))
``` | output | 1 | 2,605 | 24 | 5,211 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is preparing the first programming contest for robots. There are n problems in it, and a lot of robots are going to participate in it. Each robot solving the problem i gets p_i points, and the score of each robot in the competition is calculated as the sum of p_i over all problems i solved by it. For each problem, p_i is an integer not less than 1.
Two corporations specializing in problem-solving robot manufacturing, "Robo-Coder Inc." and "BionicSolver Industries", are going to register two robots (one for each corporation) for participation as well. Polycarp knows the advantages and flaws of robots produced by these companies, so, for each problem, he knows precisely whether each robot will solve it during the competition. Knowing this, he can try predicting the results β or manipulating them.
For some reason (which absolutely cannot involve bribing), Polycarp wants the "Robo-Coder Inc." robot to outperform the "BionicSolver Industries" robot in the competition. Polycarp wants to set the values of p_i in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot. However, if the values of p_i will be large, it may look very suspicious β so Polycarp wants to minimize the maximum value of p_i over all problems. Can you help Polycarp to determine the minimum possible upper bound on the number of points given for solving the problems?
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of problems.
The second line contains n integers r_1, r_2, ..., r_n (0 β€ r_i β€ 1). r_i = 1 means that the "Robo-Coder Inc." robot will solve the i-th problem, r_i = 0 means that it won't solve the i-th problem.
The third line contains n integers b_1, b_2, ..., b_n (0 β€ b_i β€ 1). b_i = 1 means that the "BionicSolver Industries" robot will solve the i-th problem, b_i = 0 means that it won't solve the i-th problem.
Output
If "Robo-Coder Inc." robot cannot outperform the "BionicSolver Industries" robot by any means, print one integer -1.
Otherwise, print the minimum possible value of max _{i = 1}^{n} p_i, if all values of p_i are set in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot.
Examples
Input
5
1 1 1 0 0
0 1 1 1 1
Output
3
Input
3
0 0 0
0 0 0
Output
-1
Input
4
1 1 1 1
1 1 1 1
Output
-1
Input
9
1 0 0 0 0 0 0 0 1
0 1 1 0 1 1 1 1 0
Output
4
Note
In the first example, one of the valid score assignments is p = [3, 1, 3, 1, 1]. Then the "Robo-Coder" gets 7 points, the "BionicSolver" β 6 points.
In the second example, both robots get 0 points, and the score distribution does not matter.
In the third example, both robots solve all problems, so their points are equal. | instruction | 0 | 2,606 | 24 | 5,212 |
Tags: greedy
Correct Solution:
```
for _ in range(1):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
k=0
for i in range(n):
if a[i]+b[i]!=2:
if a[i]==1:
ans+=1
elif b[i]==1:
k+=1
if ans==0:
print(-1)
else:
if k%ans==0:
print(k//ans+1)
else:
print(k//ans+1)
``` | output | 1 | 2,606 | 24 | 5,213 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is preparing the first programming contest for robots. There are n problems in it, and a lot of robots are going to participate in it. Each robot solving the problem i gets p_i points, and the score of each robot in the competition is calculated as the sum of p_i over all problems i solved by it. For each problem, p_i is an integer not less than 1.
Two corporations specializing in problem-solving robot manufacturing, "Robo-Coder Inc." and "BionicSolver Industries", are going to register two robots (one for each corporation) for participation as well. Polycarp knows the advantages and flaws of robots produced by these companies, so, for each problem, he knows precisely whether each robot will solve it during the competition. Knowing this, he can try predicting the results β or manipulating them.
For some reason (which absolutely cannot involve bribing), Polycarp wants the "Robo-Coder Inc." robot to outperform the "BionicSolver Industries" robot in the competition. Polycarp wants to set the values of p_i in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot. However, if the values of p_i will be large, it may look very suspicious β so Polycarp wants to minimize the maximum value of p_i over all problems. Can you help Polycarp to determine the minimum possible upper bound on the number of points given for solving the problems?
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of problems.
The second line contains n integers r_1, r_2, ..., r_n (0 β€ r_i β€ 1). r_i = 1 means that the "Robo-Coder Inc." robot will solve the i-th problem, r_i = 0 means that it won't solve the i-th problem.
The third line contains n integers b_1, b_2, ..., b_n (0 β€ b_i β€ 1). b_i = 1 means that the "BionicSolver Industries" robot will solve the i-th problem, b_i = 0 means that it won't solve the i-th problem.
Output
If "Robo-Coder Inc." robot cannot outperform the "BionicSolver Industries" robot by any means, print one integer -1.
Otherwise, print the minimum possible value of max _{i = 1}^{n} p_i, if all values of p_i are set in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot.
Examples
Input
5
1 1 1 0 0
0 1 1 1 1
Output
3
Input
3
0 0 0
0 0 0
Output
-1
Input
4
1 1 1 1
1 1 1 1
Output
-1
Input
9
1 0 0 0 0 0 0 0 1
0 1 1 0 1 1 1 1 0
Output
4
Note
In the first example, one of the valid score assignments is p = [3, 1, 3, 1, 1]. Then the "Robo-Coder" gets 7 points, the "BionicSolver" β 6 points.
In the second example, both robots get 0 points, and the score distribution does not matter.
In the third example, both robots solve all problems, so their points are equal. | instruction | 0 | 2,607 | 24 | 5,214 |
Tags: greedy
Correct Solution:
```
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]
def main():
input()
aa=LI()
bb=LI()
x=y=0
for a,b in zip(aa,bb):
if a>b:x+=1
if a<b:y+=1
if x==0:print(-1)
else:print((y+x)//x)
main()
``` | output | 1 | 2,607 | 24 | 5,215 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is preparing the first programming contest for robots. There are n problems in it, and a lot of robots are going to participate in it. Each robot solving the problem i gets p_i points, and the score of each robot in the competition is calculated as the sum of p_i over all problems i solved by it. For each problem, p_i is an integer not less than 1.
Two corporations specializing in problem-solving robot manufacturing, "Robo-Coder Inc." and "BionicSolver Industries", are going to register two robots (one for each corporation) for participation as well. Polycarp knows the advantages and flaws of robots produced by these companies, so, for each problem, he knows precisely whether each robot will solve it during the competition. Knowing this, he can try predicting the results β or manipulating them.
For some reason (which absolutely cannot involve bribing), Polycarp wants the "Robo-Coder Inc." robot to outperform the "BionicSolver Industries" robot in the competition. Polycarp wants to set the values of p_i in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot. However, if the values of p_i will be large, it may look very suspicious β so Polycarp wants to minimize the maximum value of p_i over all problems. Can you help Polycarp to determine the minimum possible upper bound on the number of points given for solving the problems?
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of problems.
The second line contains n integers r_1, r_2, ..., r_n (0 β€ r_i β€ 1). r_i = 1 means that the "Robo-Coder Inc." robot will solve the i-th problem, r_i = 0 means that it won't solve the i-th problem.
The third line contains n integers b_1, b_2, ..., b_n (0 β€ b_i β€ 1). b_i = 1 means that the "BionicSolver Industries" robot will solve the i-th problem, b_i = 0 means that it won't solve the i-th problem.
Output
If "Robo-Coder Inc." robot cannot outperform the "BionicSolver Industries" robot by any means, print one integer -1.
Otherwise, print the minimum possible value of max _{i = 1}^{n} p_i, if all values of p_i are set in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot.
Examples
Input
5
1 1 1 0 0
0 1 1 1 1
Output
3
Input
3
0 0 0
0 0 0
Output
-1
Input
4
1 1 1 1
1 1 1 1
Output
-1
Input
9
1 0 0 0 0 0 0 0 1
0 1 1 0 1 1 1 1 0
Output
4
Note
In the first example, one of the valid score assignments is p = [3, 1, 3, 1, 1]. Then the "Robo-Coder" gets 7 points, the "BionicSolver" β 6 points.
In the second example, both robots get 0 points, and the score distribution does not matter.
In the third example, both robots solve all problems, so their points are equal. | instruction | 0 | 2,608 | 24 | 5,216 |
Tags: greedy
Correct Solution:
```
t = int(input())
robo = [int(i) for i in input().split()]
bionic = [int(i) for i in input().split()]
robowin = 0
bionicwin = 0
for i in range(t):
if(robo[i] > bionic[i]):
robowin += 1
elif(robo[i] < bionic[i]):
bionicwin += 1
if(robowin == 0):
print(-1)
else:
print((bionicwin // robowin) + 1)
``` | output | 1 | 2,608 | 24 | 5,217 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is preparing the first programming contest for robots. There are n problems in it, and a lot of robots are going to participate in it. Each robot solving the problem i gets p_i points, and the score of each robot in the competition is calculated as the sum of p_i over all problems i solved by it. For each problem, p_i is an integer not less than 1.
Two corporations specializing in problem-solving robot manufacturing, "Robo-Coder Inc." and "BionicSolver Industries", are going to register two robots (one for each corporation) for participation as well. Polycarp knows the advantages and flaws of robots produced by these companies, so, for each problem, he knows precisely whether each robot will solve it during the competition. Knowing this, he can try predicting the results β or manipulating them.
For some reason (which absolutely cannot involve bribing), Polycarp wants the "Robo-Coder Inc." robot to outperform the "BionicSolver Industries" robot in the competition. Polycarp wants to set the values of p_i in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot. However, if the values of p_i will be large, it may look very suspicious β so Polycarp wants to minimize the maximum value of p_i over all problems. Can you help Polycarp to determine the minimum possible upper bound on the number of points given for solving the problems?
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of problems.
The second line contains n integers r_1, r_2, ..., r_n (0 β€ r_i β€ 1). r_i = 1 means that the "Robo-Coder Inc." robot will solve the i-th problem, r_i = 0 means that it won't solve the i-th problem.
The third line contains n integers b_1, b_2, ..., b_n (0 β€ b_i β€ 1). b_i = 1 means that the "BionicSolver Industries" robot will solve the i-th problem, b_i = 0 means that it won't solve the i-th problem.
Output
If "Robo-Coder Inc." robot cannot outperform the "BionicSolver Industries" robot by any means, print one integer -1.
Otherwise, print the minimum possible value of max _{i = 1}^{n} p_i, if all values of p_i are set in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot.
Examples
Input
5
1 1 1 0 0
0 1 1 1 1
Output
3
Input
3
0 0 0
0 0 0
Output
-1
Input
4
1 1 1 1
1 1 1 1
Output
-1
Input
9
1 0 0 0 0 0 0 0 1
0 1 1 0 1 1 1 1 0
Output
4
Note
In the first example, one of the valid score assignments is p = [3, 1, 3, 1, 1]. Then the "Robo-Coder" gets 7 points, the "BionicSolver" β 6 points.
In the second example, both robots get 0 points, and the score distribution does not matter.
In the third example, both robots solve all problems, so their points are equal.
Submitted Solution:
```
n=int(input())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
am=0
baal=0
for i in range(n):
if a[i]>b[i]:
am+=1
elif a[i]<b[i]:
baal+=1
if am==0:
print(-1)
else:
print((baal//am)+1)
``` | instruction | 0 | 2,609 | 24 | 5,218 |
Yes | output | 1 | 2,609 | 24 | 5,219 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is preparing the first programming contest for robots. There are n problems in it, and a lot of robots are going to participate in it. Each robot solving the problem i gets p_i points, and the score of each robot in the competition is calculated as the sum of p_i over all problems i solved by it. For each problem, p_i is an integer not less than 1.
Two corporations specializing in problem-solving robot manufacturing, "Robo-Coder Inc." and "BionicSolver Industries", are going to register two robots (one for each corporation) for participation as well. Polycarp knows the advantages and flaws of robots produced by these companies, so, for each problem, he knows precisely whether each robot will solve it during the competition. Knowing this, he can try predicting the results β or manipulating them.
For some reason (which absolutely cannot involve bribing), Polycarp wants the "Robo-Coder Inc." robot to outperform the "BionicSolver Industries" robot in the competition. Polycarp wants to set the values of p_i in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot. However, if the values of p_i will be large, it may look very suspicious β so Polycarp wants to minimize the maximum value of p_i over all problems. Can you help Polycarp to determine the minimum possible upper bound on the number of points given for solving the problems?
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of problems.
The second line contains n integers r_1, r_2, ..., r_n (0 β€ r_i β€ 1). r_i = 1 means that the "Robo-Coder Inc." robot will solve the i-th problem, r_i = 0 means that it won't solve the i-th problem.
The third line contains n integers b_1, b_2, ..., b_n (0 β€ b_i β€ 1). b_i = 1 means that the "BionicSolver Industries" robot will solve the i-th problem, b_i = 0 means that it won't solve the i-th problem.
Output
If "Robo-Coder Inc." robot cannot outperform the "BionicSolver Industries" robot by any means, print one integer -1.
Otherwise, print the minimum possible value of max _{i = 1}^{n} p_i, if all values of p_i are set in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot.
Examples
Input
5
1 1 1 0 0
0 1 1 1 1
Output
3
Input
3
0 0 0
0 0 0
Output
-1
Input
4
1 1 1 1
1 1 1 1
Output
-1
Input
9
1 0 0 0 0 0 0 0 1
0 1 1 0 1 1 1 1 0
Output
4
Note
In the first example, one of the valid score assignments is p = [3, 1, 3, 1, 1]. Then the "Robo-Coder" gets 7 points, the "BionicSolver" β 6 points.
In the second example, both robots get 0 points, and the score distribution does not matter.
In the third example, both robots solve all problems, so their points are equal.
Submitted Solution:
```
n = int(input())
robo=list(map(int,input().split()))
bionic=list(map(int,input().split()))
if robo.count(1) > bionic.count(1):
print(1)
elif robo.count(1) == bionic.count(1):
if robo == bionic:
print(-1)
else:
print(2)
else:
i0 = -1
sum=0
while i0 < len(robo)-1:
i0 += 1
if robo[i0] == 1:
if bionic[i0] == 1:
sum +=1
if sum == robo.count(1) :
print(-1)
elif sum == 0:
print((bionic.count(1)//(robo.count(1)))+1)
else:
print((bionic.count(1) - sum)//(robo.count(1)-sum)+1)
``` | instruction | 0 | 2,610 | 24 | 5,220 |
Yes | output | 1 | 2,610 | 24 | 5,221 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is preparing the first programming contest for robots. There are n problems in it, and a lot of robots are going to participate in it. Each robot solving the problem i gets p_i points, and the score of each robot in the competition is calculated as the sum of p_i over all problems i solved by it. For each problem, p_i is an integer not less than 1.
Two corporations specializing in problem-solving robot manufacturing, "Robo-Coder Inc." and "BionicSolver Industries", are going to register two robots (one for each corporation) for participation as well. Polycarp knows the advantages and flaws of robots produced by these companies, so, for each problem, he knows precisely whether each robot will solve it during the competition. Knowing this, he can try predicting the results β or manipulating them.
For some reason (which absolutely cannot involve bribing), Polycarp wants the "Robo-Coder Inc." robot to outperform the "BionicSolver Industries" robot in the competition. Polycarp wants to set the values of p_i in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot. However, if the values of p_i will be large, it may look very suspicious β so Polycarp wants to minimize the maximum value of p_i over all problems. Can you help Polycarp to determine the minimum possible upper bound on the number of points given for solving the problems?
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of problems.
The second line contains n integers r_1, r_2, ..., r_n (0 β€ r_i β€ 1). r_i = 1 means that the "Robo-Coder Inc." robot will solve the i-th problem, r_i = 0 means that it won't solve the i-th problem.
The third line contains n integers b_1, b_2, ..., b_n (0 β€ b_i β€ 1). b_i = 1 means that the "BionicSolver Industries" robot will solve the i-th problem, b_i = 0 means that it won't solve the i-th problem.
Output
If "Robo-Coder Inc." robot cannot outperform the "BionicSolver Industries" robot by any means, print one integer -1.
Otherwise, print the minimum possible value of max _{i = 1}^{n} p_i, if all values of p_i are set in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot.
Examples
Input
5
1 1 1 0 0
0 1 1 1 1
Output
3
Input
3
0 0 0
0 0 0
Output
-1
Input
4
1 1 1 1
1 1 1 1
Output
-1
Input
9
1 0 0 0 0 0 0 0 1
0 1 1 0 1 1 1 1 0
Output
4
Note
In the first example, one of the valid score assignments is p = [3, 1, 3, 1, 1]. Then the "Robo-Coder" gets 7 points, the "BionicSolver" β 6 points.
In the second example, both robots get 0 points, and the score distribution does not matter.
In the third example, both robots solve all problems, so their points are equal.
Submitted Solution:
```
n=int(input())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
x=sum(1 for i in range(n) if a[i]>b[i])
y=sum(1 for i in range(n) if a[i]<b[i])
if x==0: print(-1)
else:
print(y//x+1)
``` | instruction | 0 | 2,611 | 24 | 5,222 |
Yes | output | 1 | 2,611 | 24 | 5,223 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is preparing the first programming contest for robots. There are n problems in it, and a lot of robots are going to participate in it. Each robot solving the problem i gets p_i points, and the score of each robot in the competition is calculated as the sum of p_i over all problems i solved by it. For each problem, p_i is an integer not less than 1.
Two corporations specializing in problem-solving robot manufacturing, "Robo-Coder Inc." and "BionicSolver Industries", are going to register two robots (one for each corporation) for participation as well. Polycarp knows the advantages and flaws of robots produced by these companies, so, for each problem, he knows precisely whether each robot will solve it during the competition. Knowing this, he can try predicting the results β or manipulating them.
For some reason (which absolutely cannot involve bribing), Polycarp wants the "Robo-Coder Inc." robot to outperform the "BionicSolver Industries" robot in the competition. Polycarp wants to set the values of p_i in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot. However, if the values of p_i will be large, it may look very suspicious β so Polycarp wants to minimize the maximum value of p_i over all problems. Can you help Polycarp to determine the minimum possible upper bound on the number of points given for solving the problems?
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of problems.
The second line contains n integers r_1, r_2, ..., r_n (0 β€ r_i β€ 1). r_i = 1 means that the "Robo-Coder Inc." robot will solve the i-th problem, r_i = 0 means that it won't solve the i-th problem.
The third line contains n integers b_1, b_2, ..., b_n (0 β€ b_i β€ 1). b_i = 1 means that the "BionicSolver Industries" robot will solve the i-th problem, b_i = 0 means that it won't solve the i-th problem.
Output
If "Robo-Coder Inc." robot cannot outperform the "BionicSolver Industries" robot by any means, print one integer -1.
Otherwise, print the minimum possible value of max _{i = 1}^{n} p_i, if all values of p_i are set in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot.
Examples
Input
5
1 1 1 0 0
0 1 1 1 1
Output
3
Input
3
0 0 0
0 0 0
Output
-1
Input
4
1 1 1 1
1 1 1 1
Output
-1
Input
9
1 0 0 0 0 0 0 0 1
0 1 1 0 1 1 1 1 0
Output
4
Note
In the first example, one of the valid score assignments is p = [3, 1, 3, 1, 1]. Then the "Robo-Coder" gets 7 points, the "BionicSolver" β 6 points.
In the second example, both robots get 0 points, and the score distribution does not matter.
In the third example, both robots solve all problems, so their points are equal.
Submitted Solution:
```
n=int(input())
arr1=[int(k) for k in input().split()]
arr2=[int(k) for k in input().split()]
count1,count2,count3,count4=0,0,0,0
for i in range(n):
if arr1[i]==1:
count1+=1
if arr2[i]==1:
count2+=1
if count1>count2:
print("1")
elif count1==count2==n:
print("-1")
elif count1==count2==0:
print("-1")
else:
for i in range(n):
if arr1[i]==0 and arr2[i]==1:
count3+=1
if arr1[i]==1 and arr2[i]==0:
count4+=1
if (count4==0 and count3==0) or count4==0:
print("-1")
else:
print(count3//count4+1)
``` | instruction | 0 | 2,612 | 24 | 5,224 |
Yes | output | 1 | 2,612 | 24 | 5,225 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is preparing the first programming contest for robots. There are n problems in it, and a lot of robots are going to participate in it. Each robot solving the problem i gets p_i points, and the score of each robot in the competition is calculated as the sum of p_i over all problems i solved by it. For each problem, p_i is an integer not less than 1.
Two corporations specializing in problem-solving robot manufacturing, "Robo-Coder Inc." and "BionicSolver Industries", are going to register two robots (one for each corporation) for participation as well. Polycarp knows the advantages and flaws of robots produced by these companies, so, for each problem, he knows precisely whether each robot will solve it during the competition. Knowing this, he can try predicting the results β or manipulating them.
For some reason (which absolutely cannot involve bribing), Polycarp wants the "Robo-Coder Inc." robot to outperform the "BionicSolver Industries" robot in the competition. Polycarp wants to set the values of p_i in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot. However, if the values of p_i will be large, it may look very suspicious β so Polycarp wants to minimize the maximum value of p_i over all problems. Can you help Polycarp to determine the minimum possible upper bound on the number of points given for solving the problems?
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of problems.
The second line contains n integers r_1, r_2, ..., r_n (0 β€ r_i β€ 1). r_i = 1 means that the "Robo-Coder Inc." robot will solve the i-th problem, r_i = 0 means that it won't solve the i-th problem.
The third line contains n integers b_1, b_2, ..., b_n (0 β€ b_i β€ 1). b_i = 1 means that the "BionicSolver Industries" robot will solve the i-th problem, b_i = 0 means that it won't solve the i-th problem.
Output
If "Robo-Coder Inc." robot cannot outperform the "BionicSolver Industries" robot by any means, print one integer -1.
Otherwise, print the minimum possible value of max _{i = 1}^{n} p_i, if all values of p_i are set in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot.
Examples
Input
5
1 1 1 0 0
0 1 1 1 1
Output
3
Input
3
0 0 0
0 0 0
Output
-1
Input
4
1 1 1 1
1 1 1 1
Output
-1
Input
9
1 0 0 0 0 0 0 0 1
0 1 1 0 1 1 1 1 0
Output
4
Note
In the first example, one of the valid score assignments is p = [3, 1, 3, 1, 1]. Then the "Robo-Coder" gets 7 points, the "BionicSolver" β 6 points.
In the second example, both robots get 0 points, and the score distribution does not matter.
In the third example, both robots solve all problems, so their points are equal.
Submitted Solution:
```
def f():
n = int(input())
li1 = list(map(int, input().split()))
li2 = list(map(int, input().split()))
sum1 = sum(li1); sum2 = sum(li2)
cnt = 0
if li1 == li2 or sum1 == 0:
print("-1")
return
if sum1 > sum2:
print("1")
else:
for i in range(n):
if li1[i] == 1 and li2[i] == 0:
cnt = cnt+1
sum1 -= cnt
temp = sum1
i = 2
while sum1<sum2:
sum1 = temp
sum1 += (cnt*i)
i+=1
print(i)
f()
``` | instruction | 0 | 2,613 | 24 | 5,226 |
No | output | 1 | 2,613 | 24 | 5,227 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is preparing the first programming contest for robots. There are n problems in it, and a lot of robots are going to participate in it. Each robot solving the problem i gets p_i points, and the score of each robot in the competition is calculated as the sum of p_i over all problems i solved by it. For each problem, p_i is an integer not less than 1.
Two corporations specializing in problem-solving robot manufacturing, "Robo-Coder Inc." and "BionicSolver Industries", are going to register two robots (one for each corporation) for participation as well. Polycarp knows the advantages and flaws of robots produced by these companies, so, for each problem, he knows precisely whether each robot will solve it during the competition. Knowing this, he can try predicting the results β or manipulating them.
For some reason (which absolutely cannot involve bribing), Polycarp wants the "Robo-Coder Inc." robot to outperform the "BionicSolver Industries" robot in the competition. Polycarp wants to set the values of p_i in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot. However, if the values of p_i will be large, it may look very suspicious β so Polycarp wants to minimize the maximum value of p_i over all problems. Can you help Polycarp to determine the minimum possible upper bound on the number of points given for solving the problems?
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of problems.
The second line contains n integers r_1, r_2, ..., r_n (0 β€ r_i β€ 1). r_i = 1 means that the "Robo-Coder Inc." robot will solve the i-th problem, r_i = 0 means that it won't solve the i-th problem.
The third line contains n integers b_1, b_2, ..., b_n (0 β€ b_i β€ 1). b_i = 1 means that the "BionicSolver Industries" robot will solve the i-th problem, b_i = 0 means that it won't solve the i-th problem.
Output
If "Robo-Coder Inc." robot cannot outperform the "BionicSolver Industries" robot by any means, print one integer -1.
Otherwise, print the minimum possible value of max _{i = 1}^{n} p_i, if all values of p_i are set in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot.
Examples
Input
5
1 1 1 0 0
0 1 1 1 1
Output
3
Input
3
0 0 0
0 0 0
Output
-1
Input
4
1 1 1 1
1 1 1 1
Output
-1
Input
9
1 0 0 0 0 0 0 0 1
0 1 1 0 1 1 1 1 0
Output
4
Note
In the first example, one of the valid score assignments is p = [3, 1, 3, 1, 1]. Then the "Robo-Coder" gets 7 points, the "BionicSolver" β 6 points.
In the second example, both robots get 0 points, and the score distribution does not matter.
In the third example, both robots solve all problems, so their points are equal.
Submitted Solution:
```
n = int(input())
arr1 = map(int, input().split())
arr2 = map(int, input().split())
re1 = 0
re2 = 0
s = 0
for i, j in zip(arr1, arr2):
s += i
if i != j:
if i == 1:
re1 += 1
else:
re2 += 1
if re1 == 0 or re1 == re2 or s == 0:
print(-1)
elif re2 == 0:
print(1)
elif re2 >= re1:
print(re2//re1 + 1)
else:
print(1)
``` | instruction | 0 | 2,614 | 24 | 5,228 |
No | output | 1 | 2,614 | 24 | 5,229 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is preparing the first programming contest for robots. There are n problems in it, and a lot of robots are going to participate in it. Each robot solving the problem i gets p_i points, and the score of each robot in the competition is calculated as the sum of p_i over all problems i solved by it. For each problem, p_i is an integer not less than 1.
Two corporations specializing in problem-solving robot manufacturing, "Robo-Coder Inc." and "BionicSolver Industries", are going to register two robots (one for each corporation) for participation as well. Polycarp knows the advantages and flaws of robots produced by these companies, so, for each problem, he knows precisely whether each robot will solve it during the competition. Knowing this, he can try predicting the results β or manipulating them.
For some reason (which absolutely cannot involve bribing), Polycarp wants the "Robo-Coder Inc." robot to outperform the "BionicSolver Industries" robot in the competition. Polycarp wants to set the values of p_i in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot. However, if the values of p_i will be large, it may look very suspicious β so Polycarp wants to minimize the maximum value of p_i over all problems. Can you help Polycarp to determine the minimum possible upper bound on the number of points given for solving the problems?
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of problems.
The second line contains n integers r_1, r_2, ..., r_n (0 β€ r_i β€ 1). r_i = 1 means that the "Robo-Coder Inc." robot will solve the i-th problem, r_i = 0 means that it won't solve the i-th problem.
The third line contains n integers b_1, b_2, ..., b_n (0 β€ b_i β€ 1). b_i = 1 means that the "BionicSolver Industries" robot will solve the i-th problem, b_i = 0 means that it won't solve the i-th problem.
Output
If "Robo-Coder Inc." robot cannot outperform the "BionicSolver Industries" robot by any means, print one integer -1.
Otherwise, print the minimum possible value of max _{i = 1}^{n} p_i, if all values of p_i are set in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot.
Examples
Input
5
1 1 1 0 0
0 1 1 1 1
Output
3
Input
3
0 0 0
0 0 0
Output
-1
Input
4
1 1 1 1
1 1 1 1
Output
-1
Input
9
1 0 0 0 0 0 0 0 1
0 1 1 0 1 1 1 1 0
Output
4
Note
In the first example, one of the valid score assignments is p = [3, 1, 3, 1, 1]. Then the "Robo-Coder" gets 7 points, the "BionicSolver" β 6 points.
In the second example, both robots get 0 points, and the score distribution does not matter.
In the third example, both robots solve all problems, so their points are equal.
Submitted Solution:
```
#!/bin/python3
import math
import os
import random
import re
import sys
def get_max_len(a, b):
if len(a) != len(b) or len(a)==1:
return -1
wins = 0
loses = 0
for i in range(len(a)):
if a[i] == 1 and b[i] == 0:
wins += 1
elif a[i] == 0 and b[i] == 1:
loses += 1
if wins != 0:
p = loses // wins
return p + 1
else:
return -1
if __name__ == '__main__':
t = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(str(get_max_len(a,b)))
``` | instruction | 0 | 2,615 | 24 | 5,230 |
No | output | 1 | 2,615 | 24 | 5,231 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is preparing the first programming contest for robots. There are n problems in it, and a lot of robots are going to participate in it. Each robot solving the problem i gets p_i points, and the score of each robot in the competition is calculated as the sum of p_i over all problems i solved by it. For each problem, p_i is an integer not less than 1.
Two corporations specializing in problem-solving robot manufacturing, "Robo-Coder Inc." and "BionicSolver Industries", are going to register two robots (one for each corporation) for participation as well. Polycarp knows the advantages and flaws of robots produced by these companies, so, for each problem, he knows precisely whether each robot will solve it during the competition. Knowing this, he can try predicting the results β or manipulating them.
For some reason (which absolutely cannot involve bribing), Polycarp wants the "Robo-Coder Inc." robot to outperform the "BionicSolver Industries" robot in the competition. Polycarp wants to set the values of p_i in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot. However, if the values of p_i will be large, it may look very suspicious β so Polycarp wants to minimize the maximum value of p_i over all problems. Can you help Polycarp to determine the minimum possible upper bound on the number of points given for solving the problems?
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of problems.
The second line contains n integers r_1, r_2, ..., r_n (0 β€ r_i β€ 1). r_i = 1 means that the "Robo-Coder Inc." robot will solve the i-th problem, r_i = 0 means that it won't solve the i-th problem.
The third line contains n integers b_1, b_2, ..., b_n (0 β€ b_i β€ 1). b_i = 1 means that the "BionicSolver Industries" robot will solve the i-th problem, b_i = 0 means that it won't solve the i-th problem.
Output
If "Robo-Coder Inc." robot cannot outperform the "BionicSolver Industries" robot by any means, print one integer -1.
Otherwise, print the minimum possible value of max _{i = 1}^{n} p_i, if all values of p_i are set in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot.
Examples
Input
5
1 1 1 0 0
0 1 1 1 1
Output
3
Input
3
0 0 0
0 0 0
Output
-1
Input
4
1 1 1 1
1 1 1 1
Output
-1
Input
9
1 0 0 0 0 0 0 0 1
0 1 1 0 1 1 1 1 0
Output
4
Note
In the first example, one of the valid score assignments is p = [3, 1, 3, 1, 1]. Then the "Robo-Coder" gets 7 points, the "BionicSolver" β 6 points.
In the second example, both robots get 0 points, and the score distribution does not matter.
In the third example, both robots solve all problems, so their points are equal.
Submitted Solution:
```
T = 1
for test_no in range(T):
n = int(input())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
x, y = 0, 0
for i in range(n):
if l1[i] == 1 and l2[i] == 0:
x += 1
elif l1[i] == 0 and l2[i] == 1:
y += 1
if x > 0 and y > 0:
print(y // x + 1)
else:
print(-1)
``` | instruction | 0 | 2,616 | 24 | 5,232 |
No | output | 1 | 2,616 | 24 | 5,233 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus is an amateur businessman. Recently he was surprised to find out that the market for paper scissors is completely free! Without further ado, Polycarpus decided to start producing and selling such scissors.
Polycaprus calculated that the optimal celling price for such scissors would be p bourles. However, he read somewhere that customers are attracted by prices that say something like "Special Offer! Super price 999 bourles!". So Polycarpus decided to lower the price a little if it leads to the desired effect.
Polycarpus agrees to lower the price by no more than d bourles so that the number of nines at the end of the resulting price is maximum. If there are several ways to do it, he chooses the maximum possible price.
Note, Polycarpus counts only the trailing nines in a price.
Input
The first line contains two integers p and d (1 β€ p β€ 1018; 0 β€ d < p) β the initial price of scissors and the maximum possible price reduction.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
Print the required price β the maximum price that ends with the largest number of nines and that is less than p by no more than d.
The required number shouldn't have leading zeroes.
Examples
Input
1029 102
Output
999
Input
27191 17
Output
27189 | instruction | 0 | 2,734 | 24 | 5,468 |
Tags: implementation
Correct Solution:
```
p,d=map(int,input().split())
k=1;ans=p;
while(1):
if(p-p%10**k-1<p-d or p-p%10**k-1==-1):
break
elif(p-p%10**k-1>=p-d):
ans=p-p%10**k-1
if(p-ans==10**k):
ans=p
k+=1
print(ans)
``` | output | 1 | 2,734 | 24 | 5,469 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus is an amateur businessman. Recently he was surprised to find out that the market for paper scissors is completely free! Without further ado, Polycarpus decided to start producing and selling such scissors.
Polycaprus calculated that the optimal celling price for such scissors would be p bourles. However, he read somewhere that customers are attracted by prices that say something like "Special Offer! Super price 999 bourles!". So Polycarpus decided to lower the price a little if it leads to the desired effect.
Polycarpus agrees to lower the price by no more than d bourles so that the number of nines at the end of the resulting price is maximum. If there are several ways to do it, he chooses the maximum possible price.
Note, Polycarpus counts only the trailing nines in a price.
Input
The first line contains two integers p and d (1 β€ p β€ 1018; 0 β€ d < p) β the initial price of scissors and the maximum possible price reduction.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
Print the required price β the maximum price that ends with the largest number of nines and that is less than p by no more than d.
The required number shouldn't have leading zeroes.
Examples
Input
1029 102
Output
999
Input
27191 17
Output
27189 | instruction | 0 | 2,735 | 24 | 5,470 |
Tags: implementation
Correct Solution:
```
a,b=map(int,input().split())
a += 1
n=a
k=10
while(True):
if ((a%k)>b):
break
n=a-(a%k)
k*=10
print(n-1)
``` | output | 1 | 2,735 | 24 | 5,471 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.