message stringlengths 2 20.1k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 1.95k 109k | cluster float64 17 17 | __index_level_0__ int64 3.91k 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Daniel is organizing a football tournament. He has come up with the following tournament format:
1. In the first several (possibly zero) stages, while the number of teams is even, they split in pairs and play one game for each pair. At each stage the loser of each pair is eliminated (there are no draws). Such stages are held while the number of teams is even.
2. Eventually there will be an odd number of teams remaining. If there is one team remaining, it will be declared the winner, and the tournament ends. Otherwise each of the remaining teams will play with each other remaining team once in round robin tournament (if there are x teams, there will be <image> games), and the tournament ends.
For example, if there were 20 teams initially, they would begin by playing 10 games. So, 10 teams would be eliminated, and the remaining 10 would play 5 games. Then the remaining 5 teams would play 10 games in a round robin tournament. In total there would be 10+5+10=25 games.
Daniel has already booked the stadium for n games. Help him to determine how many teams he should invite so that the tournament needs exactly n games. You should print all possible numbers of teams that will yield exactly n games in ascending order, or -1 if there are no such numbers.
Input
The first line contains a single integer n (1 β€ n β€ 1018), the number of games that should be played.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output
Print all possible numbers of invited teams in ascending order, one per line. If exactly n games cannot be played, output one number: -1.
Examples
Input
3
Output
3
4
Input
25
Output
20
Input
2
Output
-1
Submitted Solution:
```
import sys
fin = sys.stdin
n = int(fin.readline())
def f(a, k):
return (a * (a - 1)) // 2 + a * (2 ** k - 1)
def ff(k):
result = 0
while k % 2 == 0:
k //= 2
result += k
result += (k * (k - 1)) // 2
return result
def find_a(k):
i, j = 1, n
while i <= j:
m = (i + j) // 2
value = f(m, k)
if value == n:
return m
if value < n:
i = m + 1
else:
j = m - 1
return -1
result = set()
for k in range(100):
a = find_a(k)
if a != -1:
t = a * 2 ** k
if ff(t) == n:
result.add(t)
#result.add((a, k))
#for i in result:
# print((i, ff(i)))
# if ff(i) != n:
# print(i)
if len(result) > 0:
print(" ".join(map(str, sorted(result))))
else:
print(-1)
``` | instruction | 0 | 92,076 | 17 | 184,152 |
Yes | output | 1 | 92,076 | 17 | 184,153 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Daniel is organizing a football tournament. He has come up with the following tournament format:
1. In the first several (possibly zero) stages, while the number of teams is even, they split in pairs and play one game for each pair. At each stage the loser of each pair is eliminated (there are no draws). Such stages are held while the number of teams is even.
2. Eventually there will be an odd number of teams remaining. If there is one team remaining, it will be declared the winner, and the tournament ends. Otherwise each of the remaining teams will play with each other remaining team once in round robin tournament (if there are x teams, there will be <image> games), and the tournament ends.
For example, if there were 20 teams initially, they would begin by playing 10 games. So, 10 teams would be eliminated, and the remaining 10 would play 5 games. Then the remaining 5 teams would play 10 games in a round robin tournament. In total there would be 10+5+10=25 games.
Daniel has already booked the stadium for n games. Help him to determine how many teams he should invite so that the tournament needs exactly n games. You should print all possible numbers of teams that will yield exactly n games in ascending order, or -1 if there are no such numbers.
Input
The first line contains a single integer n (1 β€ n β€ 1018), the number of games that should be played.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output
Print all possible numbers of invited teams in ascending order, one per line. If exactly n games cannot be played, output one number: -1.
Examples
Input
3
Output
3
4
Input
25
Output
20
Input
2
Output
-1
Submitted Solution:
```
def sqrt(num):
l=0
r=10**20+9
while l<r:
m=l+r>>1
if m*m>num:r=m
else:l=m+1
l-=1
return l
n=int(input())
p=0
cp=1
ans=[]
while p<=n:
sq=8*n+(1-2*p)**2
q=sqrt(sq)
if q*q==sq:
xtimes2=q-2*p+1
if xtimes2%2==0:
x=xtimes2//2
if x%2 and p*x+x*(x-1)//2==n:
ans.append(x*cp)
p+=cp
cp*=2
print(*sorted(set(ans)if ans else [-1]),sep='\n')
'''
n=p*x+x*(x-1)//2
x=(sqrt(8*n + (1-2p)^2 ) - 2p + 1)/2
'''
# Mon Oct 05 2020 17:17:55 GMT+0300 (ΠΠΎΡΠΊΠ²Π°, ΡΡΠ°Π½Π΄Π°ΡΡΠ½ΠΎΠ΅ Π²ΡΠ΅ΠΌΡ)
``` | instruction | 0 | 92,077 | 17 | 184,154 |
Yes | output | 1 | 92,077 | 17 | 184,155 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Daniel is organizing a football tournament. He has come up with the following tournament format:
1. In the first several (possibly zero) stages, while the number of teams is even, they split in pairs and play one game for each pair. At each stage the loser of each pair is eliminated (there are no draws). Such stages are held while the number of teams is even.
2. Eventually there will be an odd number of teams remaining. If there is one team remaining, it will be declared the winner, and the tournament ends. Otherwise each of the remaining teams will play with each other remaining team once in round robin tournament (if there are x teams, there will be <image> games), and the tournament ends.
For example, if there were 20 teams initially, they would begin by playing 10 games. So, 10 teams would be eliminated, and the remaining 10 would play 5 games. Then the remaining 5 teams would play 10 games in a round robin tournament. In total there would be 10+5+10=25 games.
Daniel has already booked the stadium for n games. Help him to determine how many teams he should invite so that the tournament needs exactly n games. You should print all possible numbers of teams that will yield exactly n games in ascending order, or -1 if there are no such numbers.
Input
The first line contains a single integer n (1 β€ n β€ 1018), the number of games that should be played.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output
Print all possible numbers of invited teams in ascending order, one per line. If exactly n games cannot be played, output one number: -1.
Examples
Input
3
Output
3
4
Input
25
Output
20
Input
2
Output
-1
Submitted Solution:
```
# ========= /\ /| |====/|
# | / \ | | / |
# | /____\ | | / |
# | / \ | | / |
# ========= / \ ===== |/====|
# code
# MOD = 998244353
# def pow(base , exp):
# if exp == -1:
# return pow(base , MOD - 2)
# res = 1
# base %= MOD
# while exp > 0:
# if exp % 2:
# res = (res * base) % MOD
# exp //= 2
# base = (base * base) % MOD
# res %= MOD
# return res
def main():
from math import sqrt
n = int(input())
ans = []
m = 0
num = 1
gps = 0
while gps <= n:
b = num * 2 - 3
c = n
a = 1
p = (-b + sqrt(b * b + 8 * c)) / (2 * a)
q = int(p)
# print(gps , m , num , q)
su = (q * (q - 1))//2 + q * (num - 1)
if q == p and q % 2 and su == n:
ans.append(num * q)
m += 1
num *= 2
gps = num - 1
if len(ans):
print(*ans , sep = '\n')
else:
print(-1)
return
if __name__ == "__main__":
main()
``` | instruction | 0 | 92,078 | 17 | 184,156 |
No | output | 1 | 92,078 | 17 | 184,157 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Daniel is organizing a football tournament. He has come up with the following tournament format:
1. In the first several (possibly zero) stages, while the number of teams is even, they split in pairs and play one game for each pair. At each stage the loser of each pair is eliminated (there are no draws). Such stages are held while the number of teams is even.
2. Eventually there will be an odd number of teams remaining. If there is one team remaining, it will be declared the winner, and the tournament ends. Otherwise each of the remaining teams will play with each other remaining team once in round robin tournament (if there are x teams, there will be <image> games), and the tournament ends.
For example, if there were 20 teams initially, they would begin by playing 10 games. So, 10 teams would be eliminated, and the remaining 10 would play 5 games. Then the remaining 5 teams would play 10 games in a round robin tournament. In total there would be 10+5+10=25 games.
Daniel has already booked the stadium for n games. Help him to determine how many teams he should invite so that the tournament needs exactly n games. You should print all possible numbers of teams that will yield exactly n games in ascending order, or -1 if there are no such numbers.
Input
The first line contains a single integer n (1 β€ n β€ 1018), the number of games that should be played.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output
Print all possible numbers of invited teams in ascending order, one per line. If exactly n games cannot be played, output one number: -1.
Examples
Input
3
Output
3
4
Input
25
Output
20
Input
2
Output
-1
Submitted Solution:
```
x = int(input())
l = []
for n in range(1,x+1,2):
if x%n==0:
a = (x//n-(n-1)//2+1)
a2 = a
while a != 1:
if a%2==1:
break
a /= 2
if a == 1:
l.append(n*a2)
l.sort()
for i in l: print(i)
``` | instruction | 0 | 92,079 | 17 | 184,158 |
No | output | 1 | 92,079 | 17 | 184,159 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Daniel is organizing a football tournament. He has come up with the following tournament format:
1. In the first several (possibly zero) stages, while the number of teams is even, they split in pairs and play one game for each pair. At each stage the loser of each pair is eliminated (there are no draws). Such stages are held while the number of teams is even.
2. Eventually there will be an odd number of teams remaining. If there is one team remaining, it will be declared the winner, and the tournament ends. Otherwise each of the remaining teams will play with each other remaining team once in round robin tournament (if there are x teams, there will be <image> games), and the tournament ends.
For example, if there were 20 teams initially, they would begin by playing 10 games. So, 10 teams would be eliminated, and the remaining 10 would play 5 games. Then the remaining 5 teams would play 10 games in a round robin tournament. In total there would be 10+5+10=25 games.
Daniel has already booked the stadium for n games. Help him to determine how many teams he should invite so that the tournament needs exactly n games. You should print all possible numbers of teams that will yield exactly n games in ascending order, or -1 if there are no such numbers.
Input
The first line contains a single integer n (1 β€ n β€ 1018), the number of games that should be played.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output
Print all possible numbers of invited teams in ascending order, one per line. If exactly n games cannot be played, output one number: -1.
Examples
Input
3
Output
3
4
Input
25
Output
20
Input
2
Output
-1
Submitted Solution:
```
import math
def square (a, x):
if a <= 0:
return 0
return a ** 2 == x
def sq (a):
b = int(math.sqrt (a))
if square (b - 1, a):
return b - 1
if (square (b, a)):
return b
if (square (b + 1, a)):
return b + 1
return 0
n = int(input())
ans = []
if sq (8 * n + 1):
t = sq (8 * n + 1);
if (t + 1) % 2 == 0:
ans.append ((t + 1) // 2)
k = 1
while (1 << k) < n:
b = (1 << (2 * k + 1)) - 3 * (1 << k)
c = (1 << (2 * k + 1)) * n
d = b ** 2 + 4 * c
if not sq (d):
k = k + 1
continue
t = sq (d)
t -= b
if t <= 0 or t % 2 != 0: continue
ans.append (t // 2)
k = k + 1
if len(ans) == 0:
print(-1)
else:
for x in sorted (ans):
print (x)
``` | instruction | 0 | 92,080 | 17 | 184,160 |
No | output | 1 | 92,080 | 17 | 184,161 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Daniel is organizing a football tournament. He has come up with the following tournament format:
1. In the first several (possibly zero) stages, while the number of teams is even, they split in pairs and play one game for each pair. At each stage the loser of each pair is eliminated (there are no draws). Such stages are held while the number of teams is even.
2. Eventually there will be an odd number of teams remaining. If there is one team remaining, it will be declared the winner, and the tournament ends. Otherwise each of the remaining teams will play with each other remaining team once in round robin tournament (if there are x teams, there will be <image> games), and the tournament ends.
For example, if there were 20 teams initially, they would begin by playing 10 games. So, 10 teams would be eliminated, and the remaining 10 would play 5 games. Then the remaining 5 teams would play 10 games in a round robin tournament. In total there would be 10+5+10=25 games.
Daniel has already booked the stadium for n games. Help him to determine how many teams he should invite so that the tournament needs exactly n games. You should print all possible numbers of teams that will yield exactly n games in ascending order, or -1 if there are no such numbers.
Input
The first line contains a single integer n (1 β€ n β€ 1018), the number of games that should be played.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output
Print all possible numbers of invited teams in ascending order, one per line. If exactly n games cannot be played, output one number: -1.
Examples
Input
3
Output
3
4
Input
25
Output
20
Input
2
Output
-1
Submitted Solution:
```
import math
x=int(input())
def tows(n):
ans=0
while(n>0):
ans+=2**n
n-=1
return ans
n=50
d=tows(50)
k=True
answer=[]
for n in range(50,-1,-1):
d=tows(n)
b=(d -1)
ans=[]
ans.append(-b/2 + math.sqrt(b**2 + 8*x)/2)
ans.append(-b/2 - math.sqrt(b**2 + 8*x)/2)
for item in ans:
if(item <1 or item%2!=1):
continue
answer.append(item*(2**(n)))
k=False
if(k):
print(-1)
answer.sort()
for item in answer:
print(int(item))
``` | instruction | 0 | 92,081 | 17 | 184,162 |
No | output | 1 | 92,081 | 17 | 184,163 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and the contest is not carried out;
2. on this day the gym is closed and the contest is carried out;
3. on this day the gym is open and the contest is not carried out;
4. on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).
Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.
Input
The first line contains a positive integer n (1 β€ n β€ 100) β the number of days of Vasya's vacations.
The second line contains the sequence of integers a1, a2, ..., an (0 β€ ai β€ 3) separated by space, where:
* ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out;
* ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out;
* ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out;
* ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out.
Output
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
* to do sport on any two consecutive days,
* to write the contest on any two consecutive days.
Examples
Input
4
1 3 2 0
Output
2
Input
7
1 3 3 2 1 2 3
Output
0
Input
2
2 2
Output
1
Note
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day. | instruction | 0 | 93,131 | 17 | 186,262 |
Tags: dp
Correct Solution:
```
n=int(input())
arr=[]
p=list(map(int,input().split()))
for i in range(n):
arr.append([10000,10000,10000,p[i]])
arr[0][0]=1
if(arr[0][3]==1 or arr[0][3]==3):
arr[0][1]=0
if(arr[0][3]==2 or arr[0][3]==3):
arr[0][2]=0
for i in range(1,n):
arr[i][0]=1+min(arr[i-1][0], arr[i-1][1], arr[i-1][2])
if(arr[i][3]==1 or arr[i][3]==3):
arr[i][1]=min(arr[i-1][0], arr[i-1][2])
if(arr[i][3]==2 or arr[i][3]==3):
arr[i][2]=min(arr[i-1][0], arr[i-1][1])
least=10000
for i in range(0,3):
least=min(least,arr[n-1][i])
print(least)
``` | output | 1 | 93,131 | 17 | 186,263 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and the contest is not carried out;
2. on this day the gym is closed and the contest is carried out;
3. on this day the gym is open and the contest is not carried out;
4. on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).
Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.
Input
The first line contains a positive integer n (1 β€ n β€ 100) β the number of days of Vasya's vacations.
The second line contains the sequence of integers a1, a2, ..., an (0 β€ ai β€ 3) separated by space, where:
* ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out;
* ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out;
* ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out;
* ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out.
Output
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
* to do sport on any two consecutive days,
* to write the contest on any two consecutive days.
Examples
Input
4
1 3 2 0
Output
2
Input
7
1 3 3 2 1 2 3
Output
0
Input
2
2 2
Output
1
Note
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day. | instruction | 0 | 93,132 | 17 | 186,264 |
Tags: dp
Correct Solution:
```
n = int(input())
x = [int(x) for x in input().split()]
x.append(-1)
rest = 0
if x[0] == 0:
rest = rest + 1
for i in range(1 , n):
if x[i] == 0:
rest = rest + 1
elif x[i] == 1 and x[i - 1] == 1:
rest = rest + 1
x[i] = 0
elif x[i] == 2 and x[i - 1] == 2:
rest = rest + 1
x[i] = 0
elif x[i] == 3:
if x[i - 1] == 1:
x[i] = 2
elif x[i - 1] == 2:
x[i] = 1
elif x[i - 1] == 0 and x[i + 1] == 2:
x[i] == 1
elif x[i - 1] == 0 and x[i + 1] == 1:
x[i] == 2
print(rest)
``` | output | 1 | 93,132 | 17 | 186,265 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and the contest is not carried out;
2. on this day the gym is closed and the contest is carried out;
3. on this day the gym is open and the contest is not carried out;
4. on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).
Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.
Input
The first line contains a positive integer n (1 β€ n β€ 100) β the number of days of Vasya's vacations.
The second line contains the sequence of integers a1, a2, ..., an (0 β€ ai β€ 3) separated by space, where:
* ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out;
* ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out;
* ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out;
* ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out.
Output
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
* to do sport on any two consecutive days,
* to write the contest on any two consecutive days.
Examples
Input
4
1 3 2 0
Output
2
Input
7
1 3 3 2 1 2 3
Output
0
Input
2
2 2
Output
1
Note
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day. | instruction | 0 | 93,133 | 17 | 186,266 |
Tags: dp
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
d = [[10 ** 6] * 3 for i in range(n)]
d[0][0] = 1
if a[0] & 1:
d[0][1] = 0
if a[0] & 2:
d[0][2] = 0
for i in range(1, n):
d[i][0] = min(d[i - 1]) + 1
if a[i] & 1:
d[i][1] = min(d[i - 1][0], d[i - 1][2])
if a[i] & 2:
d[i][2] = min(d[i - 1][0], d[i - 1][1])
print(min(d[-1]))
``` | output | 1 | 93,133 | 17 | 186,267 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and the contest is not carried out;
2. on this day the gym is closed and the contest is carried out;
3. on this day the gym is open and the contest is not carried out;
4. on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).
Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.
Input
The first line contains a positive integer n (1 β€ n β€ 100) β the number of days of Vasya's vacations.
The second line contains the sequence of integers a1, a2, ..., an (0 β€ ai β€ 3) separated by space, where:
* ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out;
* ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out;
* ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out;
* ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out.
Output
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
* to do sport on any two consecutive days,
* to write the contest on any two consecutive days.
Examples
Input
4
1 3 2 0
Output
2
Input
7
1 3 3 2 1 2 3
Output
0
Input
2
2 2
Output
1
Note
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day. | instruction | 0 | 93,134 | 17 | 186,268 |
Tags: dp
Correct Solution:
```
n = int(input())
l = list(map(int,input().split()))
if n == 1:
if l[0]==0:
print(1)
else:
print(0)
else:
dp = [[float('inf') for i in range(3)] for j in range(n)]
for i in range(n):
for j in range(3):
if i==0:
dp[i][0] = 1
if l[i] == 1:
dp[i][1] = 0
elif l[i]==2:
dp[i][2] = 0
elif l[i]==3:
dp[i][1] = 0
dp[i][2] = 0
else:
dp[i][0] = 1 + min(dp[i-1])
if l[i]==1:
dp[i][1] = min(dp[i-1][0],dp[i-1][2])
elif l[i]==2:
dp[i][2] = min(dp[i-1][0],dp[i-1][1])
elif l[i] == 3:
dp[i][1] = min(dp[i-1][0],dp[i-1][2])
dp[i][2] = min(dp[i-1][0],dp[i-1][1])
print(min(dp[-1]))
``` | output | 1 | 93,134 | 17 | 186,269 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and the contest is not carried out;
2. on this day the gym is closed and the contest is carried out;
3. on this day the gym is open and the contest is not carried out;
4. on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).
Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.
Input
The first line contains a positive integer n (1 β€ n β€ 100) β the number of days of Vasya's vacations.
The second line contains the sequence of integers a1, a2, ..., an (0 β€ ai β€ 3) separated by space, where:
* ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out;
* ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out;
* ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out;
* ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out.
Output
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
* to do sport on any two consecutive days,
* to write the contest on any two consecutive days.
Examples
Input
4
1 3 2 0
Output
2
Input
7
1 3 3 2 1 2 3
Output
0
Input
2
2 2
Output
1
Note
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day. | instruction | 0 | 93,135 | 17 | 186,270 |
Tags: dp
Correct Solution:
```
#not done yet
n = int(input())
alist = list(map(int, input().split()))
dp = [[101 for _ in range(4)] for _ in range(n+1)]
for i in range(4):
dp[0][i] = 0
for i in range(1,n+1):
dp[i][0] = min(dp[i-1][0], min(dp[i-1][1],dp[i-1][2]))+1
if alist[i-1] == 1:
dp[i][2] = min(dp[i-1][0], dp[i-1][1])
elif alist[i-1] == 2:
dp[i][1]=min(dp[i-1][0],dp[i-1][2])
elif alist[i-1] == 3:
dp[i][1]=min(dp[i-1][2],dp[i-1][0])
dp[i][2]=min(dp[i-1][1],dp[i-1][0])
print(min(dp[n][0],min(dp[n][1],dp[n][2])))
``` | output | 1 | 93,135 | 17 | 186,271 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and the contest is not carried out;
2. on this day the gym is closed and the contest is carried out;
3. on this day the gym is open and the contest is not carried out;
4. on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).
Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.
Input
The first line contains a positive integer n (1 β€ n β€ 100) β the number of days of Vasya's vacations.
The second line contains the sequence of integers a1, a2, ..., an (0 β€ ai β€ 3) separated by space, where:
* ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out;
* ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out;
* ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out;
* ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out.
Output
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
* to do sport on any two consecutive days,
* to write the contest on any two consecutive days.
Examples
Input
4
1 3 2 0
Output
2
Input
7
1 3 3 2 1 2 3
Output
0
Input
2
2 2
Output
1
Note
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day. | instruction | 0 | 93,136 | 17 | 186,272 |
Tags: dp
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
dp = [[0]*n for i in range(2)] #top = gym, bottom = contest, 1 = closed/rest
if a[0] == 0:
dp[0][0] = 1
dp[1][0] = 1
elif a[0] == 1:
dp[0][0] = 1
elif a[0] == 2:
dp[1][0] = 1
for i in range(1, n):
if a[i] == 0:
dp[0][i] = 1+min(dp[0][i-1], dp[1][i-1])
dp[1][i] = 1+min(dp[0][i-1], dp[1][i-1])
elif a[i] == 1:
dp[0][i] = 1+min(dp[0][i-1], dp[1][i-1])
dp[1][i] = dp[0][i-1]
elif a[i] == 2:
dp[0][i] = dp[1][i-1]
dp[1][i] = 1+min(dp[0][i-1], dp[1][i-1])
else:
dp[0][i] = dp[1][i-1]
dp[1][i] = dp[0][i-1]
print(min(dp[0][-1], dp[1][-1]))
``` | output | 1 | 93,136 | 17 | 186,273 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and the contest is not carried out;
2. on this day the gym is closed and the contest is carried out;
3. on this day the gym is open and the contest is not carried out;
4. on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).
Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.
Input
The first line contains a positive integer n (1 β€ n β€ 100) β the number of days of Vasya's vacations.
The second line contains the sequence of integers a1, a2, ..., an (0 β€ ai β€ 3) separated by space, where:
* ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out;
* ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out;
* ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out;
* ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out.
Output
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
* to do sport on any two consecutive days,
* to write the contest on any two consecutive days.
Examples
Input
4
1 3 2 0
Output
2
Input
7
1 3 3 2 1 2 3
Output
0
Input
2
2 2
Output
1
Note
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day. | instruction | 0 | 93,137 | 17 | 186,274 |
Tags: dp
Correct Solution:
```
# Description of the problem can be found at http://codeforces.com/problemset/problem/698/A
n = int(input())
l_n = list(map(int, input().split()))
p = l_n[0]
t = 1 if p == 0 else 0
for i in range(1, n):
if l_n[i] == p and p != 3:
l_n[i] = 0
elif l_n[i] == 3 and p != 3:
l_n[i] -= p
if l_n[i] == 0:
t += 1
p = l_n[i]
print(t)
``` | output | 1 | 93,137 | 17 | 186,275 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and the contest is not carried out;
2. on this day the gym is closed and the contest is carried out;
3. on this day the gym is open and the contest is not carried out;
4. on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).
Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.
Input
The first line contains a positive integer n (1 β€ n β€ 100) β the number of days of Vasya's vacations.
The second line contains the sequence of integers a1, a2, ..., an (0 β€ ai β€ 3) separated by space, where:
* ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out;
* ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out;
* ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out;
* ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out.
Output
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
* to do sport on any two consecutive days,
* to write the contest on any two consecutive days.
Examples
Input
4
1 3 2 0
Output
2
Input
7
1 3 3 2 1 2 3
Output
0
Input
2
2 2
Output
1
Note
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day. | instruction | 0 | 93,138 | 17 | 186,276 |
Tags: dp
Correct Solution:
```
n = int(input())
ls = list(map(int, input().split()))
ary = [[0, 0, 0] for j in range(n + 1)]
# 1 for contest
# 2 for gym
for i in range(1, n+ 1):
ma = max(ary[i - 1])
ary[i][0] = ma
ary[i][1] = max(ary[i-1][0], ary[i-1][2]) + (ls[i-1] == 1 or ls[i-1] == 3)
ary[i][2] = max(ary[i-1][0], ary[i-1][1]) + (ls[i-1] == 2 or ls[i-1] == 3)
print(n - max(ary[-1]))
``` | output | 1 | 93,138 | 17 | 186,277 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and the contest is not carried out;
2. on this day the gym is closed and the contest is carried out;
3. on this day the gym is open and the contest is not carried out;
4. on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).
Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.
Input
The first line contains a positive integer n (1 β€ n β€ 100) β the number of days of Vasya's vacations.
The second line contains the sequence of integers a1, a2, ..., an (0 β€ ai β€ 3) separated by space, where:
* ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out;
* ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out;
* ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out;
* ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out.
Output
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
* to do sport on any two consecutive days,
* to write the contest on any two consecutive days.
Examples
Input
4
1 3 2 0
Output
2
Input
7
1 3 3 2 1 2 3
Output
0
Input
2
2 2
Output
1
Note
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
Submitted Solution:
```
n = int(input())
a = list(map(int,input().split()))
memo = [[-1]*4 for i in range(n)]
def dp(i,prev):
if i == n:
return 0
if memo[i][prev] == -1:
memo[i][prev] = 1 + dp(i+1,0)
if a[i] == 1 or a[i] == 2:
if a[i] != prev:
memo[i][prev] = min(memo[i][prev],dp(i+1,a[i]))
elif a[i] == 3:
for x in range(1,3):
if x != prev:
memo[i][prev] = min(memo[i][prev],dp(i+1,x))
return memo[i][prev]
print(dp(0,0))
``` | instruction | 0 | 93,139 | 17 | 186,278 |
Yes | output | 1 | 93,139 | 17 | 186,279 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and the contest is not carried out;
2. on this day the gym is closed and the contest is carried out;
3. on this day the gym is open and the contest is not carried out;
4. on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).
Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.
Input
The first line contains a positive integer n (1 β€ n β€ 100) β the number of days of Vasya's vacations.
The second line contains the sequence of integers a1, a2, ..., an (0 β€ ai β€ 3) separated by space, where:
* ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out;
* ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out;
* ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out;
* ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out.
Output
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
* to do sport on any two consecutive days,
* to write the contest on any two consecutive days.
Examples
Input
4
1 3 2 0
Output
2
Input
7
1 3 3 2 1 2 3
Output
0
Input
2
2 2
Output
1
Note
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
Submitted Solution:
```
input()
l = list(map(int,input().split()))
r = 0
prev = 3
for i in l:
if (i == prev and prev != 3):
i = 0
elif (i == 3 and prev != 3):
i -= prev
if i == 0:
r = r + 1
prev = i
print(r)
``` | instruction | 0 | 93,140 | 17 | 186,280 |
Yes | output | 1 | 93,140 | 17 | 186,281 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and the contest is not carried out;
2. on this day the gym is closed and the contest is carried out;
3. on this day the gym is open and the contest is not carried out;
4. on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).
Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.
Input
The first line contains a positive integer n (1 β€ n β€ 100) β the number of days of Vasya's vacations.
The second line contains the sequence of integers a1, a2, ..., an (0 β€ ai β€ 3) separated by space, where:
* ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out;
* ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out;
* ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out;
* ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out.
Output
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
* to do sport on any two consecutive days,
* to write the contest on any two consecutive days.
Examples
Input
4
1 3 2 0
Output
2
Input
7
1 3 3 2 1 2 3
Output
0
Input
2
2 2
Output
1
Note
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
Submitted Solution:
```
# from sys import stdout
log = lambda *x: print(*x)
def cin(*fn, def_fn=str):
i,r = 0,[]
for c in input().split(' '):
r+=[(fn[i] if len(fn)>i else fn[0]) (c)]
i+=1
return r
INF = 1 << 33
def solve(a, n):
dp = []
for i in range(n+1):
dp += [[]]
for j in range(n+1):
dp[i] += [{1:0,10:0,11:0}]
for i in range(n, -1, -1):
for t in range(n-1, -1, -1):
for tf in [11, 10, 1]:
if i == n:
dp[i][t][tf] = i-t
continue
cc = (tf//10) and (a[i]==1 or a[i]==3)
cg = (tf%10) and (a[i]==2 or a[i]==3)
if not (cc or cg):
dp[i][t][tf] = dp[i+1][t][11]
continue
a1,a2=INF,INF
if cc: a1 = dp[i+1][t+1][1]
if cg: a2 = dp[i+1][t+1][10]
dp[i][t][tf] = min(a1, a2)
#}
#}
return min(dp[0][0][1], dp[0][0][10])
n, = cin(int)
a = cin(int)
log(solve(a, n))
``` | instruction | 0 | 93,141 | 17 | 186,282 |
Yes | output | 1 | 93,141 | 17 | 186,283 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and the contest is not carried out;
2. on this day the gym is closed and the contest is carried out;
3. on this day the gym is open and the contest is not carried out;
4. on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).
Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.
Input
The first line contains a positive integer n (1 β€ n β€ 100) β the number of days of Vasya's vacations.
The second line contains the sequence of integers a1, a2, ..., an (0 β€ ai β€ 3) separated by space, where:
* ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out;
* ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out;
* ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out;
* ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out.
Output
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
* to do sport on any two consecutive days,
* to write the contest on any two consecutive days.
Examples
Input
4
1 3 2 0
Output
2
Input
7
1 3 3 2 1 2 3
Output
0
Input
2
2 2
Output
1
Note
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
Submitted Solution:
```
# DEFINING SOME GOOD STUFF
from math import *
import threading
import sys
from collections import defaultdict
sys.setrecursionlimit(300000)
# threading.stack_size(10**5) # remember it cause mle
mod = 10 ** 9
inf = 10 ** 15
yes = 'YES'
no = 'NO'
# ------------------------------FASTIO----------------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# _______________________________________________________________#
def npr(n, r):
return factorial(n) // factorial(n - r) if n >= r else 0
def ncr(n, r):
return factorial(n) // (factorial(r) * factorial(n - r)) if n >= r else 0
def lower_bound(li, num):
answer = -1
start = 0
end = len(li) - 1
while (start <= end):
middle = (end + start) // 2
if li[middle] >= num:
answer = middle
end = middle - 1
else:
start = middle + 1
return answer # min index where x is not less than num
def upper_bound(li, num):
answer = -1
start = 0
end = len(li) - 1
while (start <= end):
middle = (end + start) // 2
if li[middle] <= num:
answer = middle
start = middle + 1
else:
end = middle - 1
return answer # max index where x is not greater than num
def abs(x):
return x if x >= 0 else -x
def binary_search(li, val):
# print(lb, ub, li)
ans = -1
lb = 0
ub = len(li) - 1
while (lb <= ub):
mid = (lb + ub) // 2
# print('mid is',mid, li[mid])
if li[mid] > val:
ub = mid - 1
elif val > li[mid]:
lb = mid + 1
else:
ans = mid # return index
break
return ans
def kadane(x): # maximum sum contiguous subarray
sum_so_far = 0
current_sum = 0
for i in x:
current_sum += i
if current_sum < 0:
current_sum = 0
else:
sum_so_far = max(sum_so_far, current_sum)
return sum_so_far
def pref(li):
pref_sum = [0]
for i in li:
pref_sum.append(pref_sum[-1] + i)
return pref_sum
def SieveOfEratosthenes(n):
prime = [True for i in range(n + 1)]
p = 2
li = []
while (p * p <= n):
if (prime[p] == True):
for i in range(p * p, n + 1, p):
prime[i] = False
p += 1
for p in range(2, len(prime)):
if prime[p]:
li.append(p)
return li
def primefactors(n):
factors = []
while (n % 2 == 0):
factors.append(2)
n //= 2
for i in range(3, int(sqrt(n)) + 1, 2): # only odd factors left
while n % i == 0:
factors.append(i)
n //= i
if n > 2: # incase of prime
factors.append(n)
return factors
def prod(li):
ans = 1
for i in li:
ans *= i
return ans
def dist(a, b):
d = abs(a[1] - b[1]) + abs(a[2] - b[2])
return d
def power_of_n(x, n):
cnt = 0
while (x % n == 0):
cnt += 1
x //= n
return cnt
def check(u,r,d,l):
f = 1
if u == 0 or d == 0:
if l == n or r == n:
f = 0
# print('1')
if l == 0 or r == 0:
if d == n or u == n:
f = 0
# print('2')
if u == 0 and d == 0:
if l >= n-1 or r >= n-1:
f = 0
# print('3')
if l == 0 and r == 0:
if d >= n-1 or u >= n-1:
f = 0
# print(4)
return f
# _______________________________________________________________#
# def main():
for _ in range(1):
# for _ in range(int(input()) if True else 1):
n = int(input())
# n, u, r, d, l = map(int, input().split())
a = list(map(int, input().split()))
# b = list(map(int, input().split()))
# c = list(map(int, input().split()))
# s = list(input())
# s = input()
# t = input()
# c = list(map(int,input().split()))
# adj = graph(n,m)
dp = [[0, 0, 0]]*(n+1)
for i in range(1, n+1):
dp[i] = [min(dp[i-1]) + 1] + dp[i][1:]
# print(dp)
if a[i-1] == 0:
dp[i][1] = dp[i-1][1] + 1
dp[i][2] = dp[i-1][2] + 1
elif a[i-1] == 1:
dp[i][1] = min(dp[i - 1][0], dp[i-1][2])
dp[i][2] = dp[i - 1][2] + 1
elif a[i-1] == 2:
dp[i][1] = dp[i-1][1]+1
dp[i][2] = min(dp[i-1][0], dp[i-1][1])
else:
dp[i][1] = min(dp[i-1][0], dp[i-1][2])
dp[i][2] = min(dp[i-1][0], dp[i-1][1])
# print(dp)
print(min(dp[-1]))
'''
t = threading.Thread(target=main)
t.start()
t.join()
'''
``` | instruction | 0 | 93,142 | 17 | 186,284 |
Yes | output | 1 | 93,142 | 17 | 186,285 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and the contest is not carried out;
2. on this day the gym is closed and the contest is carried out;
3. on this day the gym is open and the contest is not carried out;
4. on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).
Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.
Input
The first line contains a positive integer n (1 β€ n β€ 100) β the number of days of Vasya's vacations.
The second line contains the sequence of integers a1, a2, ..., an (0 β€ ai β€ 3) separated by space, where:
* ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out;
* ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out;
* ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out;
* ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out.
Output
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
* to do sport on any two consecutive days,
* to write the contest on any two consecutive days.
Examples
Input
4
1 3 2 0
Output
2
Input
7
1 3 3 2 1 2 3
Output
0
Input
2
2 2
Output
1
Note
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
Submitted Solution:
```
z,zz=input,lambda:list(map(int,z().split()))
zzz=lambda:[int(i) for i in stdin.readline().split()]
szz,graph,mod,szzz=lambda:sorted(zz()),{},10**9+7,lambda:sorted(zzz())
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac
def lcd(xnum1,xnum2):return (xnum1*xnum2//gcd(xnum1,xnum2))
def prime(x):
p=ceil(x**.5)+1
for i in range(2,p):
if (x%i==0 and x!=2) or x==0:return 0
return 1
def dfs(u,visit,graph):
visit[u]=True
for i in graph[u]:
if not visit[i]:
dfs(i,visit,graph)
###########################---Test-Case---#################################
"""
"""
###########################---START-CODING---##############################
n=int(z())
l=zzz()
cur=ans=0
for i in l:
if i==0:
cur=0
ans+=1
if i==1:
if cur in (0,1):
cur=2
else:
cur=0
ans+=1
if i==2:
if cur in(0,2):
cur=1
else:
ans+=1
cur=1
if i==3:
cur={0:0,1:2,2:1}[cur]
print(ans)
``` | instruction | 0 | 93,143 | 17 | 186,286 |
No | output | 1 | 93,143 | 17 | 186,287 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and the contest is not carried out;
2. on this day the gym is closed and the contest is carried out;
3. on this day the gym is open and the contest is not carried out;
4. on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).
Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.
Input
The first line contains a positive integer n (1 β€ n β€ 100) β the number of days of Vasya's vacations.
The second line contains the sequence of integers a1, a2, ..., an (0 β€ ai β€ 3) separated by space, where:
* ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out;
* ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out;
* ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out;
* ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out.
Output
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
* to do sport on any two consecutive days,
* to write the contest on any two consecutive days.
Examples
Input
4
1 3 2 0
Output
2
Input
7
1 3 3 2 1 2 3
Output
0
Input
2
2 2
Output
1
Note
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
Submitted Solution:
```
n = int(input())
mat = input().split()
flg = 0
res = 0
for i in mat:
if i == "0":
flg = 0
res +=1
elif i == "1":
if flg != 1: flg = 1
else: res+=1
elif i == "2":
if flg != -1: flg = -1
else: res+=1
elif i == "3":
if flg == 1: flg = -1
else: flg = 1
print(res)
``` | instruction | 0 | 93,144 | 17 | 186,288 |
No | output | 1 | 93,144 | 17 | 186,289 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and the contest is not carried out;
2. on this day the gym is closed and the contest is carried out;
3. on this day the gym is open and the contest is not carried out;
4. on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).
Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.
Input
The first line contains a positive integer n (1 β€ n β€ 100) β the number of days of Vasya's vacations.
The second line contains the sequence of integers a1, a2, ..., an (0 β€ ai β€ 3) separated by space, where:
* ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out;
* ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out;
* ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out;
* ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out.
Output
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
* to do sport on any two consecutive days,
* to write the contest on any two consecutive days.
Examples
Input
4
1 3 2 0
Output
2
Input
7
1 3 3 2 1 2 3
Output
0
Input
2
2 2
Output
1
Note
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
Submitted Solution:
```
n = int(input())
ls = list(map(int, input().split()))
from functools import lru_cache
@lru_cache(maxsize=None)
def f(i, last=''):
if i == n:
return 0
c = 0
for j in range(i, n):
if ls[j] == 0:
c += 1
last = ''
elif ls[j] == 1:
if last == 'contest':
c += 1
last = 'contest'
elif ls[j] == 2:
if last == 'gym':
c += 1
last = 'gym'
else:
if last == 'contest':
last = 'gym'
elif last == 'gym':
last = 'contest'
else:
return min(c + f(j + 1, 'contest'), c + f(j + 1, 'gym'))
return c
print(f(0))
``` | instruction | 0 | 93,145 | 17 | 186,290 |
No | output | 1 | 93,145 | 17 | 186,291 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and the contest is not carried out;
2. on this day the gym is closed and the contest is carried out;
3. on this day the gym is open and the contest is not carried out;
4. on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).
Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.
Input
The first line contains a positive integer n (1 β€ n β€ 100) β the number of days of Vasya's vacations.
The second line contains the sequence of integers a1, a2, ..., an (0 β€ ai β€ 3) separated by space, where:
* ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out;
* ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out;
* ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out;
* ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out.
Output
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
* to do sport on any two consecutive days,
* to write the contest on any two consecutive days.
Examples
Input
4
1 3 2 0
Output
2
Input
7
1 3 3 2 1 2 3
Output
0
Input
2
2 2
Output
1
Note
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
a.insert(0, 4)
vix = [0] * (n + 1)
for i in range(n):
if a[i] == 3:
a[i] = 3 - a[i - 1]
for m in range(1, n + 1):
if a[m] == a[m - 1]:
vix[m] += 1
a[m] = 0
elif a[m] == 0:
vix[m] += 1
vix[m] += vix[m - 1]
print(vix[-1])
``` | instruction | 0 | 93,146 | 17 | 186,292 |
No | output | 1 | 93,146 | 17 | 186,293 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
At the beginning of the new semester there is new schedule in the Berland State University. According to this schedule, n groups have lessons at the room 31. For each group the starting time of the lesson and the finishing time of the lesson are known. It has turned out that it is impossible to hold all lessons, because for some groups periods of their lessons intersect. If at some moment of time one groups finishes it's lesson, and the other group starts the lesson, their lessons don't intersect.
The dean wants to cancel the lesson in one group so that no two time periods of lessons of the remaining groups intersect. You are to find all ways to do that.
Input
The first line contains integer n (1 β€ n β€ 5000) β amount of groups, which have lessons in the room 31. Then n lines follow, each of them contains two integers li ri (1 β€ li < ri β€ 106) β starting and finishing times of lesson of the i-th group. It is possible that initially no two lessons intersect (see sample 1).
Output
Output integer k β amount of ways to cancel the lesson in exactly one group so that no two time periods of lessons of the remaining groups intersect. In the second line output k numbers β indexes of groups, where it is possible to cancel the lesson. Groups are numbered starting from 1 in the order that they were given in the input. Output the numbers in increasing order.
Examples
Input
3
3 10
20 30
1 3
Output
3
1 2 3
Input
4
3 10
20 30
1 3
1 39
Output
1
4
Input
3
1 5
2 6
3 7
Output
0
Submitted Solution:
```
class Pair:
start: int
end: int
collision: int
def __init__(self, start, end):
self.start = start
self.end = end
self.collision = 0
def have_collision(self):
self.collision += 1
k = []
b = int(input())
for i in range(b):
c, d = list(map(int, input().split()))
k.append(Pair(c, d))
for i in range(len(k)):
element = k[i]
for j in k[i + 1:]:
if j.start < element.start < j.end:
element.have_collision()
j.have_collision()
elif j.start < element.end < j.end:
element.have_collision()
j.have_collision()
coll = []
for i in k:
coll.append(i.collision)
#print(coll)
def check(list):
return all(i == list[0] for i in list)
if not all(coll):
print(len(coll))
print(" ".join(list(map(str, list(range(1, len(coll) + 1))))))
elif not check(coll):
maximum = max(coll)
print(1)
b = coll.index(maximum) + 1
print(b)
else:
print(0)
``` | instruction | 0 | 93,815 | 17 | 187,630 |
No | output | 1 | 93,815 | 17 | 187,631 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
At the beginning of the new semester there is new schedule in the Berland State University. According to this schedule, n groups have lessons at the room 31. For each group the starting time of the lesson and the finishing time of the lesson are known. It has turned out that it is impossible to hold all lessons, because for some groups periods of their lessons intersect. If at some moment of time one groups finishes it's lesson, and the other group starts the lesson, their lessons don't intersect.
The dean wants to cancel the lesson in one group so that no two time periods of lessons of the remaining groups intersect. You are to find all ways to do that.
Input
The first line contains integer n (1 β€ n β€ 5000) β amount of groups, which have lessons in the room 31. Then n lines follow, each of them contains two integers li ri (1 β€ li < ri β€ 106) β starting and finishing times of lesson of the i-th group. It is possible that initially no two lessons intersect (see sample 1).
Output
Output integer k β amount of ways to cancel the lesson in exactly one group so that no two time periods of lessons of the remaining groups intersect. In the second line output k numbers β indexes of groups, where it is possible to cancel the lesson. Groups are numbered starting from 1 in the order that they were given in the input. Output the numbers in increasing order.
Examples
Input
3
3 10
20 30
1 3
Output
3
1 2 3
Input
4
3 10
20 30
1 3
1 39
Output
1
4
Input
3
1 5
2 6
3 7
Output
0
Submitted Solution:
```
class Pair:
start: int
end: int
collision: int
def __init__(self, start, end):
self.start = start
self.end = end
self.collision = 0
def have_collision(self):
self.collision += 1
k = []
b = int(input())
for i in range(b):
c, d = list(map(int, input().split()))
k.append(Pair(c, d))
for i in range(len(k)):
element = k[i]
for j in k:
if j.start < element.start < j.end:
element.have_collision()
j.have_collision()
elif j.start < element.end < j.end:
element.have_collision()
j.have_collision()
coll = []
for i in k:
coll.append(i.collision)
#print(coll)
def check(list):
return all(i == list[0] for i in list)
if not all(coll) and coll[0]:
print(len(coll))
print(" ".join(list(map(str, list(range(1, len(coll) + 1))))))
elif check(coll) and (coll[0] == 1 or coll[0] == 0):
print(len(coll))
print(" ".join(list(map(str, list(range(1, len(coll) + 1))))))
elif not check(coll):
maximum = max(coll)
#print(len(coll) - 1)
if maximum == len(coll) - 1:
print(1)
b = coll.index(maximum) + 1
print(b)
else:
print(0)
else:
print(0)
``` | instruction | 0 | 93,817 | 17 | 187,634 |
No | output | 1 | 93,817 | 17 | 187,635 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are a coach at your local university. There are n students under your supervision, the programming skill of the i-th student is a_i.
You have to create a team for a new programming competition. As you know, the more students some team has the more probable its victory is! So you have to create a team with the maximum number of students. But you also know that a team should be balanced. It means that the programming skill of each pair of students in a created team should differ by no more than 5.
Your task is to report the maximum possible number of students in a balanced team.
Input
The first line of the input contains one integer n (1 β€ n β€ 2 β
10^5) β the number of students.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is a programming skill of the i-th student.
Output
Print one integer β the maximum possible number of students in a balanced team.
Examples
Input
6
1 10 17 12 15 2
Output
3
Input
10
1337 1337 1337 1337 1337 1337 1337 1337 1337 1337
Output
10
Input
6
1 1000 10000 10 100 1000000000
Output
1
Note
In the first example you can create a team with skills [12, 17, 15].
In the second example you can take all students in a team because their programming skills are equal.
In the third example you can create a team consisting of a single student (and you cannot create a team consisting of at least two students). | instruction | 0 | 94,458 | 17 | 188,916 |
Tags: sortings, two pointers
Correct Solution:
```
n=int(input())
a=list(map(int,input().split()))
a.sort()
l=r=0;ans=0
for i in range(n):
while l<r and a[r]-a[l]>5:
l+=1
ans=max(ans,r-l+1)
r+=1
print(ans)
``` | output | 1 | 94,458 | 17 | 188,917 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are a coach at your local university. There are n students under your supervision, the programming skill of the i-th student is a_i.
You have to create a team for a new programming competition. As you know, the more students some team has the more probable its victory is! So you have to create a team with the maximum number of students. But you also know that a team should be balanced. It means that the programming skill of each pair of students in a created team should differ by no more than 5.
Your task is to report the maximum possible number of students in a balanced team.
Input
The first line of the input contains one integer n (1 β€ n β€ 2 β
10^5) β the number of students.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is a programming skill of the i-th student.
Output
Print one integer β the maximum possible number of students in a balanced team.
Examples
Input
6
1 10 17 12 15 2
Output
3
Input
10
1337 1337 1337 1337 1337 1337 1337 1337 1337 1337
Output
10
Input
6
1 1000 10000 10 100 1000000000
Output
1
Note
In the first example you can create a team with skills [12, 17, 15].
In the second example you can take all students in a team because their programming skills are equal.
In the third example you can create a team consisting of a single student (and you cannot create a team consisting of at least two students). | instruction | 0 | 94,459 | 17 | 188,918 |
Tags: sortings, two pointers
Correct Solution:
```
n=int(input())
a=list(map(int,input().split()))
m=1
a.sort()
cur=1
d=0
l=1
for i in range(1,n):
d+=a[i]-a[i-1]
if d<=5:
cur+=1
m=max(m,cur)
else:
while d>5:
d-=a[l]-a[l-1]
l+=1
cur-=1
if d<=5:
cur+=1
m=max(m,cur)
print(m)
``` | output | 1 | 94,459 | 17 | 188,919 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are a coach at your local university. There are n students under your supervision, the programming skill of the i-th student is a_i.
You have to create a team for a new programming competition. As you know, the more students some team has the more probable its victory is! So you have to create a team with the maximum number of students. But you also know that a team should be balanced. It means that the programming skill of each pair of students in a created team should differ by no more than 5.
Your task is to report the maximum possible number of students in a balanced team.
Input
The first line of the input contains one integer n (1 β€ n β€ 2 β
10^5) β the number of students.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is a programming skill of the i-th student.
Output
Print one integer β the maximum possible number of students in a balanced team.
Examples
Input
6
1 10 17 12 15 2
Output
3
Input
10
1337 1337 1337 1337 1337 1337 1337 1337 1337 1337
Output
10
Input
6
1 1000 10000 10 100 1000000000
Output
1
Note
In the first example you can create a team with skills [12, 17, 15].
In the second example you can take all students in a team because their programming skills are equal.
In the third example you can create a team consisting of a single student (and you cannot create a team consisting of at least two students). | instruction | 0 | 94,460 | 17 | 188,920 |
Tags: sortings, two pointers
Correct Solution:
```
from bisect import bisect_right
n = int(input())
A = sorted(list(map(int, input().split())))
mx = 0
for i in range(n):
th = A[i] + 5
idx = bisect_right(A, th)
mx = max(mx, idx - i)
print(mx)
``` | output | 1 | 94,460 | 17 | 188,921 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are a coach at your local university. There are n students under your supervision, the programming skill of the i-th student is a_i.
You have to create a team for a new programming competition. As you know, the more students some team has the more probable its victory is! So you have to create a team with the maximum number of students. But you also know that a team should be balanced. It means that the programming skill of each pair of students in a created team should differ by no more than 5.
Your task is to report the maximum possible number of students in a balanced team.
Input
The first line of the input contains one integer n (1 β€ n β€ 2 β
10^5) β the number of students.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is a programming skill of the i-th student.
Output
Print one integer β the maximum possible number of students in a balanced team.
Examples
Input
6
1 10 17 12 15 2
Output
3
Input
10
1337 1337 1337 1337 1337 1337 1337 1337 1337 1337
Output
10
Input
6
1 1000 10000 10 100 1000000000
Output
1
Note
In the first example you can create a team with skills [12, 17, 15].
In the second example you can take all students in a team because their programming skills are equal.
In the third example you can create a team consisting of a single student (and you cannot create a team consisting of at least two students). | instruction | 0 | 94,461 | 17 | 188,922 |
Tags: sortings, two pointers
Correct Solution:
```
n = int(input())
a = input().split(" ")
a = [int(i) for i in a]
l=0
r=0
ans=1
a.sort()
# print(a)
while(l<=r and r<n):
if((a[r]-a[l])<=5):
ans = max(ans,(r-l+1))
r+=1
elif(l == r-1):
r+=1
else:
l+=1
# print(l,r)
print(ans)
``` | output | 1 | 94,461 | 17 | 188,923 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are a coach at your local university. There are n students under your supervision, the programming skill of the i-th student is a_i.
You have to create a team for a new programming competition. As you know, the more students some team has the more probable its victory is! So you have to create a team with the maximum number of students. But you also know that a team should be balanced. It means that the programming skill of each pair of students in a created team should differ by no more than 5.
Your task is to report the maximum possible number of students in a balanced team.
Input
The first line of the input contains one integer n (1 β€ n β€ 2 β
10^5) β the number of students.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is a programming skill of the i-th student.
Output
Print one integer β the maximum possible number of students in a balanced team.
Examples
Input
6
1 10 17 12 15 2
Output
3
Input
10
1337 1337 1337 1337 1337 1337 1337 1337 1337 1337
Output
10
Input
6
1 1000 10000 10 100 1000000000
Output
1
Note
In the first example you can create a team with skills [12, 17, 15].
In the second example you can take all students in a team because their programming skills are equal.
In the third example you can create a team consisting of a single student (and you cannot create a team consisting of at least two students). | instruction | 0 | 94,462 | 17 | 188,924 |
Tags: sortings, two pointers
Correct Solution:
```
n=int(input())
a=list(map(int,input().split()))
l=0
r=1
br=0
brm=1
a.sort()
while(r<n):
if(a[r]-a[l]<=5):
r=r+1
br=r-l
else:
l=l+1
if(l==r):
r=r+1
brm=max(brm,br)
print(brm)
``` | output | 1 | 94,462 | 17 | 188,925 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are a coach at your local university. There are n students under your supervision, the programming skill of the i-th student is a_i.
You have to create a team for a new programming competition. As you know, the more students some team has the more probable its victory is! So you have to create a team with the maximum number of students. But you also know that a team should be balanced. It means that the programming skill of each pair of students in a created team should differ by no more than 5.
Your task is to report the maximum possible number of students in a balanced team.
Input
The first line of the input contains one integer n (1 β€ n β€ 2 β
10^5) β the number of students.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is a programming skill of the i-th student.
Output
Print one integer β the maximum possible number of students in a balanced team.
Examples
Input
6
1 10 17 12 15 2
Output
3
Input
10
1337 1337 1337 1337 1337 1337 1337 1337 1337 1337
Output
10
Input
6
1 1000 10000 10 100 1000000000
Output
1
Note
In the first example you can create a team with skills [12, 17, 15].
In the second example you can take all students in a team because their programming skills are equal.
In the third example you can create a team consisting of a single student (and you cannot create a team consisting of at least two students). | instruction | 0 | 94,463 | 17 | 188,926 |
Tags: sortings, two pointers
Correct Solution:
```
import sys
n = int(sys.stdin.readline().strip())
a = list(map(int, sys.stdin.readline().strip().split()))
a.sort()
i = 0
j = 0
d = 1
while j < n - 1:
if a[j + 1] <= a[i] + 5:
j = j + 1
d = max([d, j - i + 1])
else:
i = i + 1
print(d)
``` | output | 1 | 94,463 | 17 | 188,927 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are a coach at your local university. There are n students under your supervision, the programming skill of the i-th student is a_i.
You have to create a team for a new programming competition. As you know, the more students some team has the more probable its victory is! So you have to create a team with the maximum number of students. But you also know that a team should be balanced. It means that the programming skill of each pair of students in a created team should differ by no more than 5.
Your task is to report the maximum possible number of students in a balanced team.
Input
The first line of the input contains one integer n (1 β€ n β€ 2 β
10^5) β the number of students.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is a programming skill of the i-th student.
Output
Print one integer β the maximum possible number of students in a balanced team.
Examples
Input
6
1 10 17 12 15 2
Output
3
Input
10
1337 1337 1337 1337 1337 1337 1337 1337 1337 1337
Output
10
Input
6
1 1000 10000 10 100 1000000000
Output
1
Note
In the first example you can create a team with skills [12, 17, 15].
In the second example you can take all students in a team because their programming skills are equal.
In the third example you can create a team consisting of a single student (and you cannot create a team consisting of at least two students). | instruction | 0 | 94,464 | 17 | 188,928 |
Tags: sortings, two pointers
Correct Solution:
```
import sys
import math
from functools import reduce
import bisect
def getN():
return int(input())
def getNM():
return map(int, input().split())
def getList():
return list(map(int, input().split()))
def input():
return sys.stdin.readline().rstrip()
def index(a, x, pos):
i = bisect.bisect(a, x) - 1
if i == len(a) or i == 0:
return -1
return i - pos + 1
#############
# MAIN CODE #
#############
n = getN()
arr = sorted(getList())
ans = 1
for i in range(n):
ans = max(ans, index(arr, arr[i] + 5, i))
print(ans)
``` | output | 1 | 94,464 | 17 | 188,929 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are a coach at your local university. There are n students under your supervision, the programming skill of the i-th student is a_i.
You have to create a team for a new programming competition. As you know, the more students some team has the more probable its victory is! So you have to create a team with the maximum number of students. But you also know that a team should be balanced. It means that the programming skill of each pair of students in a created team should differ by no more than 5.
Your task is to report the maximum possible number of students in a balanced team.
Input
The first line of the input contains one integer n (1 β€ n β€ 2 β
10^5) β the number of students.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is a programming skill of the i-th student.
Output
Print one integer β the maximum possible number of students in a balanced team.
Examples
Input
6
1 10 17 12 15 2
Output
3
Input
10
1337 1337 1337 1337 1337 1337 1337 1337 1337 1337
Output
10
Input
6
1 1000 10000 10 100 1000000000
Output
1
Note
In the first example you can create a team with skills [12, 17, 15].
In the second example you can take all students in a team because their programming skills are equal.
In the third example you can create a team consisting of a single student (and you cannot create a team consisting of at least two students). | instruction | 0 | 94,465 | 17 | 188,930 |
Tags: sortings, two pointers
Correct Solution:
```
n = int(input())
a = [int(j) for j in input().split()]
a.sort()
# arr = [a[0]]
ans = []
ma = 1
y = 0
if n == 1:
print(1)
else:
# print(a)
for x in range(1, len(a)):
# print(a[x], a[y])
while a[x]-a[y] > 5:
# print('t')
y += 1
ans += [x-y+1]
# print(ans)
print(max(ans))
``` | output | 1 | 94,465 | 17 | 188,931 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are a coach at your local university. There are n students under your supervision, the programming skill of the i-th student is a_i.
You have to create a team for a new programming competition. As you know, the more students some team has the more probable its victory is! So you have to create a team with the maximum number of students. But you also know that a team should be balanced. It means that the programming skill of each pair of students in a created team should differ by no more than 5.
Your task is to report the maximum possible number of students in a balanced team.
Input
The first line of the input contains one integer n (1 β€ n β€ 2 β
10^5) β the number of students.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is a programming skill of the i-th student.
Output
Print one integer β the maximum possible number of students in a balanced team.
Examples
Input
6
1 10 17 12 15 2
Output
3
Input
10
1337 1337 1337 1337 1337 1337 1337 1337 1337 1337
Output
10
Input
6
1 1000 10000 10 100 1000000000
Output
1
Note
In the first example you can create a team with skills [12, 17, 15].
In the second example you can take all students in a team because their programming skills are equal.
In the third example you can create a team consisting of a single student (and you cannot create a team consisting of at least two students).
Submitted Solution:
```
n = int(input())
A = list(map(int,input().split()))
A.sort()
ans=0;j=0
for i in range(n):
while(A[j]+5<A[i]):
j+=1
ans = max(ans,i-j+1)
print(ans)
``` | instruction | 0 | 94,466 | 17 | 188,932 |
Yes | output | 1 | 94,466 | 17 | 188,933 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are a coach at your local university. There are n students under your supervision, the programming skill of the i-th student is a_i.
You have to create a team for a new programming competition. As you know, the more students some team has the more probable its victory is! So you have to create a team with the maximum number of students. But you also know that a team should be balanced. It means that the programming skill of each pair of students in a created team should differ by no more than 5.
Your task is to report the maximum possible number of students in a balanced team.
Input
The first line of the input contains one integer n (1 β€ n β€ 2 β
10^5) β the number of students.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is a programming skill of the i-th student.
Output
Print one integer β the maximum possible number of students in a balanced team.
Examples
Input
6
1 10 17 12 15 2
Output
3
Input
10
1337 1337 1337 1337 1337 1337 1337 1337 1337 1337
Output
10
Input
6
1 1000 10000 10 100 1000000000
Output
1
Note
In the first example you can create a team with skills [12, 17, 15].
In the second example you can take all students in a team because their programming skills are equal.
In the third example you can create a team consisting of a single student (and you cannot create a team consisting of at least two students).
Submitted Solution:
```
n=int(input())
a=list(map(int, input().split()))
a.sort()
l=0
ans=0
for r in range(n):
while not a[r]-a[l]<=5:
l+=1
ans=max(ans, r-l+1)
print(ans)
``` | instruction | 0 | 94,467 | 17 | 188,934 |
Yes | output | 1 | 94,467 | 17 | 188,935 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are a coach at your local university. There are n students under your supervision, the programming skill of the i-th student is a_i.
You have to create a team for a new programming competition. As you know, the more students some team has the more probable its victory is! So you have to create a team with the maximum number of students. But you also know that a team should be balanced. It means that the programming skill of each pair of students in a created team should differ by no more than 5.
Your task is to report the maximum possible number of students in a balanced team.
Input
The first line of the input contains one integer n (1 β€ n β€ 2 β
10^5) β the number of students.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is a programming skill of the i-th student.
Output
Print one integer β the maximum possible number of students in a balanced team.
Examples
Input
6
1 10 17 12 15 2
Output
3
Input
10
1337 1337 1337 1337 1337 1337 1337 1337 1337 1337
Output
10
Input
6
1 1000 10000 10 100 1000000000
Output
1
Note
In the first example you can create a team with skills [12, 17, 15].
In the second example you can take all students in a team because their programming skills are equal.
In the third example you can create a team consisting of a single student (and you cannot create a team consisting of at least two students).
Submitted Solution:
```
c=dict()
def cou(x):
ans=0
for i in range(x,x+6):
if i in c:
ans+=c[i]
return ans
n=int(input())
a=[int(i) for i in input().split()]
b=set(a)
for i in a:
if i in c:
c[i]+=1
else:
c[i]=1
#for i in b:
# c[i]=a.count(i)
#a.sort()
m=0
for i in b:
y=cou(i)
if y>m:
m=y
#ii=i
print(m)#,ii)
``` | instruction | 0 | 94,468 | 17 | 188,936 |
Yes | output | 1 | 94,468 | 17 | 188,937 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are a coach at your local university. There are n students under your supervision, the programming skill of the i-th student is a_i.
You have to create a team for a new programming competition. As you know, the more students some team has the more probable its victory is! So you have to create a team with the maximum number of students. But you also know that a team should be balanced. It means that the programming skill of each pair of students in a created team should differ by no more than 5.
Your task is to report the maximum possible number of students in a balanced team.
Input
The first line of the input contains one integer n (1 β€ n β€ 2 β
10^5) β the number of students.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is a programming skill of the i-th student.
Output
Print one integer β the maximum possible number of students in a balanced team.
Examples
Input
6
1 10 17 12 15 2
Output
3
Input
10
1337 1337 1337 1337 1337 1337 1337 1337 1337 1337
Output
10
Input
6
1 1000 10000 10 100 1000000000
Output
1
Note
In the first example you can create a team with skills [12, 17, 15].
In the second example you can take all students in a team because their programming skills are equal.
In the third example you can create a team consisting of a single student (and you cannot create a team consisting of at least two students).
Submitted Solution:
```
import sys
from collections import Counter
def i_ints():
return map(int, sys.stdin.readline().split())
n, k = i_ints()
c = Counter(i_ints())
c2 = dict()
a = sorted(c)
for i in sorted(a):
c2[i] = sum(c[j] for j in range(i, i + 6))
# a are all possible levels of students
# c2[i] is maximal group size where lowest level is i
len_a = len(a)
next_group = [-1] * len(a)
for i in range(len_a):
for j in range(i + 1, len_a):
if a[j] > a[i] + 5:
next_group[i] = j
break
# if a group starts with i-th element,
# then the next possible group starts with next_group[i]-th element
maxes = [0] * n # for a maximum of 0 groups
for ii in range(k):
old_maxes = maxes
old_maxes.append(0) # access where next_group[...] == -1
maxes = []
# max number of groups, try to find better maxes each round
for i, aa in enumerate(a):
maxes.append(c2[a[i]] + old_maxes[next_group[i]])
m = 0
for i in range(len(a)-1, -1, -1):
if maxes[i] > m:
m = maxes[i]
else:
maxes[i] = m
print(max(maxes))
``` | instruction | 0 | 94,469 | 17 | 188,938 |
Yes | output | 1 | 94,469 | 17 | 188,939 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are a coach at your local university. There are n students under your supervision, the programming skill of the i-th student is a_i.
You have to create a team for a new programming competition. As you know, the more students some team has the more probable its victory is! So you have to create a team with the maximum number of students. But you also know that a team should be balanced. It means that the programming skill of each pair of students in a created team should differ by no more than 5.
Your task is to report the maximum possible number of students in a balanced team.
Input
The first line of the input contains one integer n (1 β€ n β€ 2 β
10^5) β the number of students.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is a programming skill of the i-th student.
Output
Print one integer β the maximum possible number of students in a balanced team.
Examples
Input
6
1 10 17 12 15 2
Output
3
Input
10
1337 1337 1337 1337 1337 1337 1337 1337 1337 1337
Output
10
Input
6
1 1000 10000 10 100 1000000000
Output
1
Note
In the first example you can create a team with skills [12, 17, 15].
In the second example you can take all students in a team because their programming skills are equal.
In the third example you can create a team consisting of a single student (and you cannot create a team consisting of at least two students).
Submitted Solution:
```
n = int(input())
A = list(map(int, input().strip().split()))
count = {}
A = sorted(A)
for a in A:
count[a] = 0
for i in range(len(A)):
count[A[i]] += 1
for j in range(i+1, i+6):
try:
if A[j] - A[i] <=5 and A[j]!= A[i]:
count[A[i]] += 1
except:
abc = 123
print(max(count.values()))
``` | instruction | 0 | 94,470 | 17 | 188,940 |
No | output | 1 | 94,470 | 17 | 188,941 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are a coach at your local university. There are n students under your supervision, the programming skill of the i-th student is a_i.
You have to create a team for a new programming competition. As you know, the more students some team has the more probable its victory is! So you have to create a team with the maximum number of students. But you also know that a team should be balanced. It means that the programming skill of each pair of students in a created team should differ by no more than 5.
Your task is to report the maximum possible number of students in a balanced team.
Input
The first line of the input contains one integer n (1 β€ n β€ 2 β
10^5) β the number of students.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is a programming skill of the i-th student.
Output
Print one integer β the maximum possible number of students in a balanced team.
Examples
Input
6
1 10 17 12 15 2
Output
3
Input
10
1337 1337 1337 1337 1337 1337 1337 1337 1337 1337
Output
10
Input
6
1 1000 10000 10 100 1000000000
Output
1
Note
In the first example you can create a team with skills [12, 17, 15].
In the second example you can take all students in a team because their programming skills are equal.
In the third example you can create a team consisting of a single student (and you cannot create a team consisting of at least two students).
Submitted Solution:
```
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
s = []
slen = 0
l = 0
for i in range(0, n):
if a[i] - a[l] <= 5:
slen += 1
else:
s.append(slen)
slen = 1
l = i
s.append(slen)
s = sorted(s, reverse=True)
ans = 0
for i in range(min(k, len(s))):
ans += s[i]
print (ans)
``` | instruction | 0 | 94,471 | 17 | 188,942 |
No | output | 1 | 94,471 | 17 | 188,943 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are a coach at your local university. There are n students under your supervision, the programming skill of the i-th student is a_i.
You have to create a team for a new programming competition. As you know, the more students some team has the more probable its victory is! So you have to create a team with the maximum number of students. But you also know that a team should be balanced. It means that the programming skill of each pair of students in a created team should differ by no more than 5.
Your task is to report the maximum possible number of students in a balanced team.
Input
The first line of the input contains one integer n (1 β€ n β€ 2 β
10^5) β the number of students.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is a programming skill of the i-th student.
Output
Print one integer β the maximum possible number of students in a balanced team.
Examples
Input
6
1 10 17 12 15 2
Output
3
Input
10
1337 1337 1337 1337 1337 1337 1337 1337 1337 1337
Output
10
Input
6
1 1000 10000 10 100 1000000000
Output
1
Note
In the first example you can create a team with skills [12, 17, 15].
In the second example you can take all students in a team because their programming skills are equal.
In the third example you can create a team consisting of a single student (and you cannot create a team consisting of at least two students).
Submitted Solution:
```
#
# tag(s):
def getMaxNumMembers(n, team):
team = sorted(team)
a = 0
b = 0
ans = 1
cont = 1
while b < (n-1):
if abs(team[b] - team[b+1]) <= 5:
if abs(team[b+1] - team[a]) <= 5:
cont += 1
if cont > ans:
ans = cont
b += 1
else:
cont = 1
a = b
b = b + 1
else:
cont = 1
a = b
b = b + 1
return ans
if __name__ == '__main__':
n = int(input())
team = map(int, input().split())
print(getMaxNumMembers(n, team))
``` | instruction | 0 | 94,472 | 17 | 188,944 |
No | output | 1 | 94,472 | 17 | 188,945 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are a coach at your local university. There are n students under your supervision, the programming skill of the i-th student is a_i.
You have to create a team for a new programming competition. As you know, the more students some team has the more probable its victory is! So you have to create a team with the maximum number of students. But you also know that a team should be balanced. It means that the programming skill of each pair of students in a created team should differ by no more than 5.
Your task is to report the maximum possible number of students in a balanced team.
Input
The first line of the input contains one integer n (1 β€ n β€ 2 β
10^5) β the number of students.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is a programming skill of the i-th student.
Output
Print one integer β the maximum possible number of students in a balanced team.
Examples
Input
6
1 10 17 12 15 2
Output
3
Input
10
1337 1337 1337 1337 1337 1337 1337 1337 1337 1337
Output
10
Input
6
1 1000 10000 10 100 1000000000
Output
1
Note
In the first example you can create a team with skills [12, 17, 15].
In the second example you can take all students in a team because their programming skills are equal.
In the third example you can create a team consisting of a single student (and you cannot create a team consisting of at least two students).
Submitted Solution:
```
n=int(input())
l=list(map(int,input().split()))
#l.sort()
count1=1
count=1
for i in range(0,n-1):
if abs(l[i+1]-l[i])<=5:
count+=1
if count1<count:
count1=count
else:
count=1
print(count1)
``` | instruction | 0 | 94,473 | 17 | 188,946 |
No | output | 1 | 94,473 | 17 | 188,947 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a famous olympiad, which has more than a hundred participants. The Olympiad consists of two stages: the elimination stage, and the final stage. At least a hundred participants will advance to the final stage. The elimination stage in turn consists of two contests.
A result of the elimination stage is the total score in two contests, but, unfortunately, the jury lost the final standings and has only standings for the first and for the second contest separately.
In each contest, the participants are ranked by their point score in non-increasing order. When two participants have a tie (earned the same score), they are ranked by their passport number (in accordance with local regulations, all passport numbers are distinct).
In the first contest, the participant on the 100-th place scored a points. Also, the jury checked all participants from the 1-st to the 100-th place (inclusive) in the first contest and found out that all of them have at least b points in the second contest.
Similarly, for the second contest, the participant on the 100-th place has c points. And the jury checked that all the participants from the 1-st to the 100-th place (inclusive) have at least d points in the first contest.
After two contests, all participants are ranked by their total score in two contests in non-increasing order. When participants have the same total score, tie-breaking with passport numbers is used. The cutoff score to qualify to the final stage is the total score of the participant on the 100-th place.
Given integers a, b, c, d, please help the jury determine the smallest possible value of the cutoff score.
Input
You need to process t test cases.
The first line contains an integer t (1 β€ t β€ 3025) β the number of test cases. Then descriptions of t test cases follow.
The first line of each test case contains four integers a, b, c, d (0 β€ a,\,b,\,c,\,d β€ 9; d β€ a; b β€ c).
One can show that for any test case satisfying the constraints above, there is at least one olympiad scenario possible.
Output
For each test case print a single integer β the smallest possible cutoff score in some olympiad scenario satisfying the given information.
Example
Input
2
1 2 2 1
4 8 9 2
Output
3
12
Note
For the first test case, consider the following olympiad scenario: there are 101 participants in the elimination stage, each having 1 point for the first contest and 2 points for the second contest. Hence the total score of the participant on the 100-th place is 3.
For the second test case, consider the following olympiad scenario:
* there are 50 participants with points 5 and 9 for the first and second contest respectively;
* 50 participants with points 4 and 8 for the first and second contest respectively;
* and 50 participants with points 2 and 9 for the first and second contest respectively.
Hence the total point score of the participant on the 100-th place is 12. | instruction | 0 | 94,584 | 17 | 189,168 |
Tags: greedy, math
Correct Solution:
```
import sys
from math import *
from fractions import *
def main():
#n = int(sys.stdin.readline().strip())
#p, q = map(int, sys.stdin.readline().split())
#q = list(map(int, sys.stdin.readline().split()))
a,b,c,d= map(int, sys.stdin.readline().split())
print(max(a + b, c + d))
for i in range(int(input()) - 1):
main()
main()
``` | output | 1 | 94,584 | 17 | 189,169 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a famous olympiad, which has more than a hundred participants. The Olympiad consists of two stages: the elimination stage, and the final stage. At least a hundred participants will advance to the final stage. The elimination stage in turn consists of two contests.
A result of the elimination stage is the total score in two contests, but, unfortunately, the jury lost the final standings and has only standings for the first and for the second contest separately.
In each contest, the participants are ranked by their point score in non-increasing order. When two participants have a tie (earned the same score), they are ranked by their passport number (in accordance with local regulations, all passport numbers are distinct).
In the first contest, the participant on the 100-th place scored a points. Also, the jury checked all participants from the 1-st to the 100-th place (inclusive) in the first contest and found out that all of them have at least b points in the second contest.
Similarly, for the second contest, the participant on the 100-th place has c points. And the jury checked that all the participants from the 1-st to the 100-th place (inclusive) have at least d points in the first contest.
After two contests, all participants are ranked by their total score in two contests in non-increasing order. When participants have the same total score, tie-breaking with passport numbers is used. The cutoff score to qualify to the final stage is the total score of the participant on the 100-th place.
Given integers a, b, c, d, please help the jury determine the smallest possible value of the cutoff score.
Input
You need to process t test cases.
The first line contains an integer t (1 β€ t β€ 3025) β the number of test cases. Then descriptions of t test cases follow.
The first line of each test case contains four integers a, b, c, d (0 β€ a,\,b,\,c,\,d β€ 9; d β€ a; b β€ c).
One can show that for any test case satisfying the constraints above, there is at least one olympiad scenario possible.
Output
For each test case print a single integer β the smallest possible cutoff score in some olympiad scenario satisfying the given information.
Example
Input
2
1 2 2 1
4 8 9 2
Output
3
12
Note
For the first test case, consider the following olympiad scenario: there are 101 participants in the elimination stage, each having 1 point for the first contest and 2 points for the second contest. Hence the total score of the participant on the 100-th place is 3.
For the second test case, consider the following olympiad scenario:
* there are 50 participants with points 5 and 9 for the first and second contest respectively;
* 50 participants with points 4 and 8 for the first and second contest respectively;
* and 50 participants with points 2 and 9 for the first and second contest respectively.
Hence the total point score of the participant on the 100-th place is 12. | instruction | 0 | 94,585 | 17 | 189,170 |
Tags: greedy, math
Correct Solution:
```
if __name__ == "__main__":
t = int(input())
while t:
a,b,c,d = list(map(int, input().split()))
print(max( min((a+b),(a+c)),(c+d) ))
t = t - 1
``` | output | 1 | 94,585 | 17 | 189,171 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a famous olympiad, which has more than a hundred participants. The Olympiad consists of two stages: the elimination stage, and the final stage. At least a hundred participants will advance to the final stage. The elimination stage in turn consists of two contests.
A result of the elimination stage is the total score in two contests, but, unfortunately, the jury lost the final standings and has only standings for the first and for the second contest separately.
In each contest, the participants are ranked by their point score in non-increasing order. When two participants have a tie (earned the same score), they are ranked by their passport number (in accordance with local regulations, all passport numbers are distinct).
In the first contest, the participant on the 100-th place scored a points. Also, the jury checked all participants from the 1-st to the 100-th place (inclusive) in the first contest and found out that all of them have at least b points in the second contest.
Similarly, for the second contest, the participant on the 100-th place has c points. And the jury checked that all the participants from the 1-st to the 100-th place (inclusive) have at least d points in the first contest.
After two contests, all participants are ranked by their total score in two contests in non-increasing order. When participants have the same total score, tie-breaking with passport numbers is used. The cutoff score to qualify to the final stage is the total score of the participant on the 100-th place.
Given integers a, b, c, d, please help the jury determine the smallest possible value of the cutoff score.
Input
You need to process t test cases.
The first line contains an integer t (1 β€ t β€ 3025) β the number of test cases. Then descriptions of t test cases follow.
The first line of each test case contains four integers a, b, c, d (0 β€ a,\,b,\,c,\,d β€ 9; d β€ a; b β€ c).
One can show that for any test case satisfying the constraints above, there is at least one olympiad scenario possible.
Output
For each test case print a single integer β the smallest possible cutoff score in some olympiad scenario satisfying the given information.
Example
Input
2
1 2 2 1
4 8 9 2
Output
3
12
Note
For the first test case, consider the following olympiad scenario: there are 101 participants in the elimination stage, each having 1 point for the first contest and 2 points for the second contest. Hence the total score of the participant on the 100-th place is 3.
For the second test case, consider the following olympiad scenario:
* there are 50 participants with points 5 and 9 for the first and second contest respectively;
* 50 participants with points 4 and 8 for the first and second contest respectively;
* and 50 participants with points 2 and 9 for the first and second contest respectively.
Hence the total point score of the participant on the 100-th place is 12. | instruction | 0 | 94,586 | 17 | 189,172 |
Tags: greedy, math
Correct Solution:
```
for _ in range(int(input())):
a,b,c,d=map(int,input().split())
print(a+b if (a+b)>=(c+d) else c+d)
``` | output | 1 | 94,586 | 17 | 189,173 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a famous olympiad, which has more than a hundred participants. The Olympiad consists of two stages: the elimination stage, and the final stage. At least a hundred participants will advance to the final stage. The elimination stage in turn consists of two contests.
A result of the elimination stage is the total score in two contests, but, unfortunately, the jury lost the final standings and has only standings for the first and for the second contest separately.
In each contest, the participants are ranked by their point score in non-increasing order. When two participants have a tie (earned the same score), they are ranked by their passport number (in accordance with local regulations, all passport numbers are distinct).
In the first contest, the participant on the 100-th place scored a points. Also, the jury checked all participants from the 1-st to the 100-th place (inclusive) in the first contest and found out that all of them have at least b points in the second contest.
Similarly, for the second contest, the participant on the 100-th place has c points. And the jury checked that all the participants from the 1-st to the 100-th place (inclusive) have at least d points in the first contest.
After two contests, all participants are ranked by their total score in two contests in non-increasing order. When participants have the same total score, tie-breaking with passport numbers is used. The cutoff score to qualify to the final stage is the total score of the participant on the 100-th place.
Given integers a, b, c, d, please help the jury determine the smallest possible value of the cutoff score.
Input
You need to process t test cases.
The first line contains an integer t (1 β€ t β€ 3025) β the number of test cases. Then descriptions of t test cases follow.
The first line of each test case contains four integers a, b, c, d (0 β€ a,\,b,\,c,\,d β€ 9; d β€ a; b β€ c).
One can show that for any test case satisfying the constraints above, there is at least one olympiad scenario possible.
Output
For each test case print a single integer β the smallest possible cutoff score in some olympiad scenario satisfying the given information.
Example
Input
2
1 2 2 1
4 8 9 2
Output
3
12
Note
For the first test case, consider the following olympiad scenario: there are 101 participants in the elimination stage, each having 1 point for the first contest and 2 points for the second contest. Hence the total score of the participant on the 100-th place is 3.
For the second test case, consider the following olympiad scenario:
* there are 50 participants with points 5 and 9 for the first and second contest respectively;
* 50 participants with points 4 and 8 for the first and second contest respectively;
* and 50 participants with points 2 and 9 for the first and second contest respectively.
Hence the total point score of the participant on the 100-th place is 12. | instruction | 0 | 94,587 | 17 | 189,174 |
Tags: greedy, math
Correct Solution:
```
def zip_sorted(a,b):
# sorted by a
a,b = zip(*sorted(zip(a,b)))
# sorted by b
sorted(zip(a, b), key=lambda x: x[1])
return a,b
import sys
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))
S = lambda : list(map(str,input().split()))
t,=I()
for t1 in range(t):
a,b,c,d = I()
print(max((a+b),(c+d)))
``` | output | 1 | 94,587 | 17 | 189,175 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a famous olympiad, which has more than a hundred participants. The Olympiad consists of two stages: the elimination stage, and the final stage. At least a hundred participants will advance to the final stage. The elimination stage in turn consists of two contests.
A result of the elimination stage is the total score in two contests, but, unfortunately, the jury lost the final standings and has only standings for the first and for the second contest separately.
In each contest, the participants are ranked by their point score in non-increasing order. When two participants have a tie (earned the same score), they are ranked by their passport number (in accordance with local regulations, all passport numbers are distinct).
In the first contest, the participant on the 100-th place scored a points. Also, the jury checked all participants from the 1-st to the 100-th place (inclusive) in the first contest and found out that all of them have at least b points in the second contest.
Similarly, for the second contest, the participant on the 100-th place has c points. And the jury checked that all the participants from the 1-st to the 100-th place (inclusive) have at least d points in the first contest.
After two contests, all participants are ranked by their total score in two contests in non-increasing order. When participants have the same total score, tie-breaking with passport numbers is used. The cutoff score to qualify to the final stage is the total score of the participant on the 100-th place.
Given integers a, b, c, d, please help the jury determine the smallest possible value of the cutoff score.
Input
You need to process t test cases.
The first line contains an integer t (1 β€ t β€ 3025) β the number of test cases. Then descriptions of t test cases follow.
The first line of each test case contains four integers a, b, c, d (0 β€ a,\,b,\,c,\,d β€ 9; d β€ a; b β€ c).
One can show that for any test case satisfying the constraints above, there is at least one olympiad scenario possible.
Output
For each test case print a single integer β the smallest possible cutoff score in some olympiad scenario satisfying the given information.
Example
Input
2
1 2 2 1
4 8 9 2
Output
3
12
Note
For the first test case, consider the following olympiad scenario: there are 101 participants in the elimination stage, each having 1 point for the first contest and 2 points for the second contest. Hence the total score of the participant on the 100-th place is 3.
For the second test case, consider the following olympiad scenario:
* there are 50 participants with points 5 and 9 for the first and second contest respectively;
* 50 participants with points 4 and 8 for the first and second contest respectively;
* and 50 participants with points 2 and 9 for the first and second contest respectively.
Hence the total point score of the participant on the 100-th place is 12. | instruction | 0 | 94,588 | 17 | 189,176 |
Tags: greedy, math
Correct Solution:
```
try:
for _ in range(int(input())):
a,b,c,d=map(int,input().split())
print(max((a+b),(c+d)))
except:
pass
``` | output | 1 | 94,588 | 17 | 189,177 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a famous olympiad, which has more than a hundred participants. The Olympiad consists of two stages: the elimination stage, and the final stage. At least a hundred participants will advance to the final stage. The elimination stage in turn consists of two contests.
A result of the elimination stage is the total score in two contests, but, unfortunately, the jury lost the final standings and has only standings for the first and for the second contest separately.
In each contest, the participants are ranked by their point score in non-increasing order. When two participants have a tie (earned the same score), they are ranked by their passport number (in accordance with local regulations, all passport numbers are distinct).
In the first contest, the participant on the 100-th place scored a points. Also, the jury checked all participants from the 1-st to the 100-th place (inclusive) in the first contest and found out that all of them have at least b points in the second contest.
Similarly, for the second contest, the participant on the 100-th place has c points. And the jury checked that all the participants from the 1-st to the 100-th place (inclusive) have at least d points in the first contest.
After two contests, all participants are ranked by their total score in two contests in non-increasing order. When participants have the same total score, tie-breaking with passport numbers is used. The cutoff score to qualify to the final stage is the total score of the participant on the 100-th place.
Given integers a, b, c, d, please help the jury determine the smallest possible value of the cutoff score.
Input
You need to process t test cases.
The first line contains an integer t (1 β€ t β€ 3025) β the number of test cases. Then descriptions of t test cases follow.
The first line of each test case contains four integers a, b, c, d (0 β€ a,\,b,\,c,\,d β€ 9; d β€ a; b β€ c).
One can show that for any test case satisfying the constraints above, there is at least one olympiad scenario possible.
Output
For each test case print a single integer β the smallest possible cutoff score in some olympiad scenario satisfying the given information.
Example
Input
2
1 2 2 1
4 8 9 2
Output
3
12
Note
For the first test case, consider the following olympiad scenario: there are 101 participants in the elimination stage, each having 1 point for the first contest and 2 points for the second contest. Hence the total score of the participant on the 100-th place is 3.
For the second test case, consider the following olympiad scenario:
* there are 50 participants with points 5 and 9 for the first and second contest respectively;
* 50 participants with points 4 and 8 for the first and second contest respectively;
* and 50 participants with points 2 and 9 for the first and second contest respectively.
Hence the total point score of the participant on the 100-th place is 12. | instruction | 0 | 94,589 | 17 | 189,178 |
Tags: greedy, math
Correct Solution:
```
def main():
t = int(input())
for i in range(t):
a, b, c, d = map(int, input().split())
print(max(a + b, c + d))
main()
``` | output | 1 | 94,589 | 17 | 189,179 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a famous olympiad, which has more than a hundred participants. The Olympiad consists of two stages: the elimination stage, and the final stage. At least a hundred participants will advance to the final stage. The elimination stage in turn consists of two contests.
A result of the elimination stage is the total score in two contests, but, unfortunately, the jury lost the final standings and has only standings for the first and for the second contest separately.
In each contest, the participants are ranked by their point score in non-increasing order. When two participants have a tie (earned the same score), they are ranked by their passport number (in accordance with local regulations, all passport numbers are distinct).
In the first contest, the participant on the 100-th place scored a points. Also, the jury checked all participants from the 1-st to the 100-th place (inclusive) in the first contest and found out that all of them have at least b points in the second contest.
Similarly, for the second contest, the participant on the 100-th place has c points. And the jury checked that all the participants from the 1-st to the 100-th place (inclusive) have at least d points in the first contest.
After two contests, all participants are ranked by their total score in two contests in non-increasing order. When participants have the same total score, tie-breaking with passport numbers is used. The cutoff score to qualify to the final stage is the total score of the participant on the 100-th place.
Given integers a, b, c, d, please help the jury determine the smallest possible value of the cutoff score.
Input
You need to process t test cases.
The first line contains an integer t (1 β€ t β€ 3025) β the number of test cases. Then descriptions of t test cases follow.
The first line of each test case contains four integers a, b, c, d (0 β€ a,\,b,\,c,\,d β€ 9; d β€ a; b β€ c).
One can show that for any test case satisfying the constraints above, there is at least one olympiad scenario possible.
Output
For each test case print a single integer β the smallest possible cutoff score in some olympiad scenario satisfying the given information.
Example
Input
2
1 2 2 1
4 8 9 2
Output
3
12
Note
For the first test case, consider the following olympiad scenario: there are 101 participants in the elimination stage, each having 1 point for the first contest and 2 points for the second contest. Hence the total score of the participant on the 100-th place is 3.
For the second test case, consider the following olympiad scenario:
* there are 50 participants with points 5 and 9 for the first and second contest respectively;
* 50 participants with points 4 and 8 for the first and second contest respectively;
* and 50 participants with points 2 and 9 for the first and second contest respectively.
Hence the total point score of the participant on the 100-th place is 12. | instruction | 0 | 94,590 | 17 | 189,180 |
Tags: greedy, math
Correct Solution:
```
import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
from itertools import permutations,combinations
def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var) : sys.stdout.write(' '.join(map(str, var))+'\n')
def out(var) : sys.stdout.write(str(var)+'\n')
#from decimal import Decimal
#from fractions import Fraction
sys.setrecursionlimit(100000)
INF = float('inf')
mod = 998244353
for t in range(int(data())):
a, b,c ,d=mdata()
out(max(a+b,c+d))
``` | output | 1 | 94,590 | 17 | 189,181 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a famous olympiad, which has more than a hundred participants. The Olympiad consists of two stages: the elimination stage, and the final stage. At least a hundred participants will advance to the final stage. The elimination stage in turn consists of two contests.
A result of the elimination stage is the total score in two contests, but, unfortunately, the jury lost the final standings and has only standings for the first and for the second contest separately.
In each contest, the participants are ranked by their point score in non-increasing order. When two participants have a tie (earned the same score), they are ranked by their passport number (in accordance with local regulations, all passport numbers are distinct).
In the first contest, the participant on the 100-th place scored a points. Also, the jury checked all participants from the 1-st to the 100-th place (inclusive) in the first contest and found out that all of them have at least b points in the second contest.
Similarly, for the second contest, the participant on the 100-th place has c points. And the jury checked that all the participants from the 1-st to the 100-th place (inclusive) have at least d points in the first contest.
After two contests, all participants are ranked by their total score in two contests in non-increasing order. When participants have the same total score, tie-breaking with passport numbers is used. The cutoff score to qualify to the final stage is the total score of the participant on the 100-th place.
Given integers a, b, c, d, please help the jury determine the smallest possible value of the cutoff score.
Input
You need to process t test cases.
The first line contains an integer t (1 β€ t β€ 3025) β the number of test cases. Then descriptions of t test cases follow.
The first line of each test case contains four integers a, b, c, d (0 β€ a,\,b,\,c,\,d β€ 9; d β€ a; b β€ c).
One can show that for any test case satisfying the constraints above, there is at least one olympiad scenario possible.
Output
For each test case print a single integer β the smallest possible cutoff score in some olympiad scenario satisfying the given information.
Example
Input
2
1 2 2 1
4 8 9 2
Output
3
12
Note
For the first test case, consider the following olympiad scenario: there are 101 participants in the elimination stage, each having 1 point for the first contest and 2 points for the second contest. Hence the total score of the participant on the 100-th place is 3.
For the second test case, consider the following olympiad scenario:
* there are 50 participants with points 5 and 9 for the first and second contest respectively;
* 50 participants with points 4 and 8 for the first and second contest respectively;
* and 50 participants with points 2 and 9 for the first and second contest respectively.
Hence the total point score of the participant on the 100-th place is 12. | instruction | 0 | 94,591 | 17 | 189,182 |
Tags: greedy, math
Correct Solution:
```
t = int(input())
while t > 0:
a, b, c, d = [int(x) for x in input().split()]
ans = max(a + b, c + d)
print(ans)
t -= 1
``` | output | 1 | 94,591 | 17 | 189,183 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a famous olympiad, which has more than a hundred participants. The Olympiad consists of two stages: the elimination stage, and the final stage. At least a hundred participants will advance to the final stage. The elimination stage in turn consists of two contests.
A result of the elimination stage is the total score in two contests, but, unfortunately, the jury lost the final standings and has only standings for the first and for the second contest separately.
In each contest, the participants are ranked by their point score in non-increasing order. When two participants have a tie (earned the same score), they are ranked by their passport number (in accordance with local regulations, all passport numbers are distinct).
In the first contest, the participant on the 100-th place scored a points. Also, the jury checked all participants from the 1-st to the 100-th place (inclusive) in the first contest and found out that all of them have at least b points in the second contest.
Similarly, for the second contest, the participant on the 100-th place has c points. And the jury checked that all the participants from the 1-st to the 100-th place (inclusive) have at least d points in the first contest.
After two contests, all participants are ranked by their total score in two contests in non-increasing order. When participants have the same total score, tie-breaking with passport numbers is used. The cutoff score to qualify to the final stage is the total score of the participant on the 100-th place.
Given integers a, b, c, d, please help the jury determine the smallest possible value of the cutoff score.
Input
You need to process t test cases.
The first line contains an integer t (1 β€ t β€ 3025) β the number of test cases. Then descriptions of t test cases follow.
The first line of each test case contains four integers a, b, c, d (0 β€ a,\,b,\,c,\,d β€ 9; d β€ a; b β€ c).
One can show that for any test case satisfying the constraints above, there is at least one olympiad scenario possible.
Output
For each test case print a single integer β the smallest possible cutoff score in some olympiad scenario satisfying the given information.
Example
Input
2
1 2 2 1
4 8 9 2
Output
3
12
Note
For the first test case, consider the following olympiad scenario: there are 101 participants in the elimination stage, each having 1 point for the first contest and 2 points for the second contest. Hence the total score of the participant on the 100-th place is 3.
For the second test case, consider the following olympiad scenario:
* there are 50 participants with points 5 and 9 for the first and second contest respectively;
* 50 participants with points 4 and 8 for the first and second contest respectively;
* and 50 participants with points 2 and 9 for the first and second contest respectively.
Hence the total point score of the participant on the 100-th place is 12.
Submitted Solution:
```
for i in range(int(input())):
a,b,c,d=map(int,input().split())
print(max((a+b),(c+d)))
``` | instruction | 0 | 94,592 | 17 | 189,184 |
Yes | output | 1 | 94,592 | 17 | 189,185 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a famous olympiad, which has more than a hundred participants. The Olympiad consists of two stages: the elimination stage, and the final stage. At least a hundred participants will advance to the final stage. The elimination stage in turn consists of two contests.
A result of the elimination stage is the total score in two contests, but, unfortunately, the jury lost the final standings and has only standings for the first and for the second contest separately.
In each contest, the participants are ranked by their point score in non-increasing order. When two participants have a tie (earned the same score), they are ranked by their passport number (in accordance with local regulations, all passport numbers are distinct).
In the first contest, the participant on the 100-th place scored a points. Also, the jury checked all participants from the 1-st to the 100-th place (inclusive) in the first contest and found out that all of them have at least b points in the second contest.
Similarly, for the second contest, the participant on the 100-th place has c points. And the jury checked that all the participants from the 1-st to the 100-th place (inclusive) have at least d points in the first contest.
After two contests, all participants are ranked by their total score in two contests in non-increasing order. When participants have the same total score, tie-breaking with passport numbers is used. The cutoff score to qualify to the final stage is the total score of the participant on the 100-th place.
Given integers a, b, c, d, please help the jury determine the smallest possible value of the cutoff score.
Input
You need to process t test cases.
The first line contains an integer t (1 β€ t β€ 3025) β the number of test cases. Then descriptions of t test cases follow.
The first line of each test case contains four integers a, b, c, d (0 β€ a,\,b,\,c,\,d β€ 9; d β€ a; b β€ c).
One can show that for any test case satisfying the constraints above, there is at least one olympiad scenario possible.
Output
For each test case print a single integer β the smallest possible cutoff score in some olympiad scenario satisfying the given information.
Example
Input
2
1 2 2 1
4 8 9 2
Output
3
12
Note
For the first test case, consider the following olympiad scenario: there are 101 participants in the elimination stage, each having 1 point for the first contest and 2 points for the second contest. Hence the total score of the participant on the 100-th place is 3.
For the second test case, consider the following olympiad scenario:
* there are 50 participants with points 5 and 9 for the first and second contest respectively;
* 50 participants with points 4 and 8 for the first and second contest respectively;
* and 50 participants with points 2 and 9 for the first and second contest respectively.
Hence the total point score of the participant on the 100-th place is 12.
Submitted Solution:
```
#(γ£ββ‘β)γ£ β₯ GLHF β₯
import os #(γ£ββ‘β)γ£
import sys #(γ£ββ‘β)γ£
from io import BytesIO, IOBase #(γ£ββ‘β)γ£
def main(): #(γ£ββ‘β)γ£
for tc in range(int(input())):
line = input().split()
a100, b, b100, a = int(line[0]), int(line[1]), int(line[2]), int(line[3])
print(max(a100+b, b100+a))
BUFSIZE = 8192 #(γ£ββ‘β)γ£
class FastIO(IOBase): #(γ£ββ‘β)γ£
newlines = 0 #(γ£ββ‘β)γ£
def __init__(self, file): #(γ£ββ‘β)γ£
self._fd = file.fileno() #(γ£ββ‘β)γ£
self.buffer = BytesIO() #(γ£ββ‘β)γ£
self.writable = "x" in file.mode or "r" not in file.mode #(γ£ββ‘β)γ£
self.write = self.buffer.write if self.writable else None #(γ£ββ‘β)γ£
def read(self): #(γ£ββ‘β)γ£
while True: #(γ£ββ‘β)γ£
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) #(γ£ββ‘β)γ£
if not b: #(γ£ββ‘β)γ£
break #(γ£ββ‘β)γ£
ptr = self.buffer.tell() #(γ£ββ‘β)γ£
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) #(γ£ββ‘β)γ£
self.newlines = 0 #(γ£ββ‘β)γ£
return self.buffer.read() #(γ£ββ‘β)γ£
def readline(self): #(γ£ββ‘β)γ£
while self.newlines == 0: #(γ£ββ‘β)γ£
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) #(γ£ββ‘β)γ£
self.newlines = b.count(b"\n") + (not b) #(γ£ββ‘β)γ£
ptr = self.buffer.tell() #(γ£ββ‘β)γ£
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) #(γ£ββ‘β)γ£
self.newlines -= 1 #(γ£ββ‘β)γ£
return self.buffer.readline() #(γ£ββ‘β)γ£
def flush(self): #(γ£ββ‘β)γ£
if self.writable: #(γ£ββ‘β)γ£
os.write(self._fd, self.buffer.getvalue()) #(γ£ββ‘β)γ£
self.buffer.truncate(0), self.buffer.seek(0) #(γ£ββ‘β)γ£
class IOWrapper(IOBase): #(γ£ββ‘β)γ£
def __init__(self, file): #(γ£ββ‘β)γ£
self.buffer = FastIO(file) #(γ£ββ‘β)γ£
self.flush = self.buffer.flush #(γ£ββ‘β)γ£
self.writable = self.buffer.writable #(γ£ββ‘β)γ£
self.write = lambda s: self.buffer.write(s.encode("ascii")) #(γ£ββ‘β)γ£
self.read = lambda: self.buffer.read().decode("ascii") #(γ£ββ‘β)γ£
self.readline = lambda: self.buffer.readline().decode("ascii") #(γ£ββ‘β)γ£
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) #(γ£ββ‘β)γ£
input = lambda: sys.stdin.readline().rstrip("\r\n") #(γ£ββ‘β)γ£
if __name__ == "__main__": #(γ£ββ‘β)γ£
main() #(γ£ββ‘β)γ£
#ββββββββββββββββββββββββββββββββββββ
#ββββββββββββββββββββββββββββββββββββ
#ββββββββββββββββββββββββββββββββββββ
#ββββββββββββββββββββββββββββββββββββ
#ββββββββββββββββββββββββββββββββββββ
#ββββββββββββββββββββββββββββββββββββ
``` | instruction | 0 | 94,593 | 17 | 189,186 |
Yes | output | 1 | 94,593 | 17 | 189,187 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.