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.
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 _ in range(int(input())):
a, b, c, d = map(int, input().split())
print(max(a + b, c + d)) if a >= d else print(a + b)
``` | instruction | 0 | 94,594 | 17 | 189,188 |
Yes | output | 1 | 94,594 | 17 | 189,189 |
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:
```
t = int(input())
for _ in range(t):
a, b, c, d = [int(x) for x in input().split()]
print(max(a+b, c+d))
``` | instruction | 0 | 94,595 | 17 | 189,190 |
Yes | output | 1 | 94,595 | 17 | 189,191 |
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:
```
t=int(input())
for i in range(t):
a,b,c,d=map(int,input().strip().split())
an=a+c
if d<a:
an=min(an,d+1+c)
print(an)
``` | instruction | 0 | 94,596 | 17 | 189,192 |
No | output | 1 | 94,596 | 17 | 189,193 |
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 _ in range(int(input())):
a, b, c, d = map(int, input().split())
if a > d:
print(a + b)
else:
print(c + d)
``` | instruction | 0 | 94,597 | 17 | 189,194 |
No | output | 1 | 94,597 | 17 | 189,195 |
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:
```
import math
def power(x,y):
res=1
while y>0:
if y&1:
res=(res*x)
y=y>>1
x=(x*x)
return res
t=int(input())
for tt in range(t):
a,b,c,d=map(int,input().split())
print(max(a,d)+min(b,c))
``` | instruction | 0 | 94,598 | 17 | 189,196 |
No | output | 1 | 94,598 | 17 | 189,197 |
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())):
l=list(map(int,input().split()))
print(l[0]+l[1])
``` | instruction | 0 | 94,599 | 17 | 189,198 |
No | output | 1 | 94,599 | 17 | 189,199 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
Input
The only line of the input contains a single integer n (2 β€ n β€ 1018) β the number of players to participate in the tournament.
Output
Print the maximum number of games in which the winner of the tournament can take part.
Examples
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
Note
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
Submitted Solution:
```
n=int(input())
x,y=1,1
z=-1
for i in range(0,n+1):
if y>n:
print(i-1)
break
z=x+y
x=y
y=z
``` | instruction | 0 | 94,890 | 17 | 189,780 |
Yes | output | 1 | 94,890 | 17 | 189,781 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
Input
The only line of the input contains a single integer n (2 β€ n β€ 1018) β the number of players to participate in the tournament.
Output
Print the maximum number of games in which the winner of the tournament can take part.
Examples
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
Note
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
Submitted Solution:
```
if __name__ == "__main__":
n = int(input())
arr = [1, 2]
while True:
tmp = arr[-1] + arr[-2]
if tmp > n:
break
arr.append(tmp)
print(len(arr) - 1)
``` | instruction | 0 | 94,891 | 17 | 189,782 |
Yes | output | 1 | 94,891 | 17 | 189,783 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
Input
The only line of the input contains a single integer n (2 β€ n β€ 1018) β the number of players to participate in the tournament.
Output
Print the maximum number of games in which the winner of the tournament can take part.
Examples
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
Note
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
Submitted Solution:
```
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
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 value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]
#-------------------------code---------------------------#
#vsInput()
series=[2,3]
x=5
while(x<10**18):
series.append(x)
x+=series[-2]
#print(series)
n=Int()
ans=bisect_right(series,n)
print(ans)
``` | instruction | 0 | 94,892 | 17 | 189,784 |
Yes | output | 1 | 94,892 | 17 | 189,785 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
Input
The only line of the input contains a single integer n (2 β€ n β€ 1018) β the number of players to participate in the tournament.
Output
Print the maximum number of games in which the winner of the tournament can take part.
Examples
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
Note
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
Submitted Solution:
```
n = int(input())
a = 1
b = 1
k = 0
while a <= n:
a, b = a + b, a
k += 1
print(k - 1)
``` | instruction | 0 | 94,893 | 17 | 189,786 |
Yes | output | 1 | 94,893 | 17 | 189,787 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
Input
The only line of the input contains a single integer n (2 β€ n β€ 1018) β the number of players to participate in the tournament.
Output
Print the maximum number of games in which the winner of the tournament can take part.
Examples
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
Note
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
Submitted Solution:
```
n = int( input() )
if n <= 2:
print( 1 )
exit(0)
F = [1,1]
while F[-1] < n:
F.append( F[-1] + F[-2] )
s = 0
for i in range( len(F) ):
s += F[i]
if s > n:
print( i )
break
``` | instruction | 0 | 94,894 | 17 | 189,788 |
No | output | 1 | 94,894 | 17 | 189,789 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
Input
The only line of the input contains a single integer n (2 β€ n β€ 1018) β the number of players to participate in the tournament.
Output
Print the maximum number of games in which the winner of the tournament can take part.
Examples
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
Note
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
Submitted Solution:
```
"""
#If FastIO not needed, used this and don't forget to strip
#import sys, math
#input = sys.stdin.readline
"""
import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
from types import GeneratorType
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
import os
self.os = os
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 = self.os.read(self._fd, max(self.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 = self.os.read(self._fd, max(self.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:
self.os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
from collections import defaultdict as dd, deque as dq, Counter as dc
import math, string
def getInts():
return [int(s) for s in input().split()]
def getInt():
return int(input())
def getStrs():
return [s for s in input().split()]
def getStr():
return input()
def listStr():
return list(input())
MOD = 998244353
"""
"""
def solve():
N = getInt()
x = 1
ans = 0
while x < N:
x *= 2
ans += 1
return ans
print(solve())
``` | instruction | 0 | 94,895 | 17 | 189,790 |
No | output | 1 | 94,895 | 17 | 189,791 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
Input
The only line of the input contains a single integer n (2 β€ n β€ 1018) β the number of players to participate in the tournament.
Output
Print the maximum number of games in which the winner of the tournament can take part.
Examples
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
Note
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
Submitted Solution:
```
from math import *
n = int(input())
if n == 4:
print(2)
else:
print(round(log(sqrt(5)*n,(1.0+sqrt(5))/2.0))-2 )
``` | instruction | 0 | 94,896 | 17 | 189,792 |
No | output | 1 | 94,896 | 17 | 189,793 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
Input
The only line of the input contains a single integer n (2 β€ n β€ 1018) β the number of players to participate in the tournament.
Output
Print the maximum number of games in which the winner of the tournament can take part.
Examples
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
Note
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
Submitted Solution:
```
n=int(input())
if(n==2):
print(1)
else:
s=pow(n,.5)
if(int(s)**2==n):
print(int(s))
else:
print(int(s)+1)
``` | instruction | 0 | 94,897 | 17 | 189,794 |
No | output | 1 | 94,897 | 17 | 189,795 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
Input
The first line contains single integer n (2 β€ n β€ 2Β·105) β the number of groups.
The second line contains a sequence of integers a1, a2, ..., an (1 β€ ai β€ 2), where ai is the number of people in group i.
Output
Print the maximum number of teams of three people the coach can form.
Examples
Input
4
1 1 2 1
Output
1
Input
2
2 2
Output
0
Input
7
2 2 2 1 1 1 1
Output
3
Input
3
1 1 1
Output
1
Note
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
* The first group (of two people) and the seventh group (of one person),
* The second group (of two people) and the sixth group (of one person),
* The third group (of two people) and the fourth group (of one person). | instruction | 0 | 94,975 | 17 | 189,950 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
# http://codeforces.com/contest/899/problem/A
n = int(input())
people = [int(x) for x in input().split()]
count_2, count_3 = 0, 0
for x in people:
if x == 2:
count_2 += 1
else:
count_3 += 1
if count_2 < count_3:
print(count_2 + int((count_3 - count_2)/3))
else:
print(count_3)
``` | output | 1 | 94,975 | 17 | 189,951 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
Input
The first line contains single integer n (2 β€ n β€ 2Β·105) β the number of groups.
The second line contains a sequence of integers a1, a2, ..., an (1 β€ ai β€ 2), where ai is the number of people in group i.
Output
Print the maximum number of teams of three people the coach can form.
Examples
Input
4
1 1 2 1
Output
1
Input
2
2 2
Output
0
Input
7
2 2 2 1 1 1 1
Output
3
Input
3
1 1 1
Output
1
Note
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
* The first group (of two people) and the seventh group (of one person),
* The second group (of two people) and the sixth group (of one person),
* The third group (of two people) and the fourth group (of one person). | instruction | 0 | 94,976 | 17 | 189,952 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
t=(int(input()))
l=list(map(int,input().split()))
one,two=0,0
for i in l:
if i==1:
one=one+1
else:
two=two+1
if one<=two:
print(one)
else:
print(two+(one-two)//3)
``` | output | 1 | 94,976 | 17 | 189,953 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
Input
The first line contains single integer n (2 β€ n β€ 2Β·105) β the number of groups.
The second line contains a sequence of integers a1, a2, ..., an (1 β€ ai β€ 2), where ai is the number of people in group i.
Output
Print the maximum number of teams of three people the coach can form.
Examples
Input
4
1 1 2 1
Output
1
Input
2
2 2
Output
0
Input
7
2 2 2 1 1 1 1
Output
3
Input
3
1 1 1
Output
1
Note
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
* The first group (of two people) and the seventh group (of one person),
* The second group (of two people) and the sixth group (of one person),
* The third group (of two people) and the fourth group (of one person). | instruction | 0 | 94,977 | 17 | 189,954 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
n = int(input())
num = list(map(int, input().split()))
o = num.count(1)
t = num.count(2)
if t >= o:
out = o
t -= o
else:
out = t
o -= t
out += int(o / 3)
print(out)
``` | output | 1 | 94,977 | 17 | 189,955 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
Input
The first line contains single integer n (2 β€ n β€ 2Β·105) β the number of groups.
The second line contains a sequence of integers a1, a2, ..., an (1 β€ ai β€ 2), where ai is the number of people in group i.
Output
Print the maximum number of teams of three people the coach can form.
Examples
Input
4
1 1 2 1
Output
1
Input
2
2 2
Output
0
Input
7
2 2 2 1 1 1 1
Output
3
Input
3
1 1 1
Output
1
Note
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
* The first group (of two people) and the seventh group (of one person),
* The second group (of two people) and the sixth group (of one person),
* The third group (of two people) and the fourth group (of one person). | instruction | 0 | 94,978 | 17 | 189,956 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
n = int(input())
A = list(input().split())
c = [A.count("1"), A.count("2")]
if c[0] > c[1]:
k = c[1]
c = [c[0] - c[1], 0]
k += c[0] // 3
else:
k = c[0]
print(k)
``` | output | 1 | 94,978 | 17 | 189,957 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
Input
The first line contains single integer n (2 β€ n β€ 2Β·105) β the number of groups.
The second line contains a sequence of integers a1, a2, ..., an (1 β€ ai β€ 2), where ai is the number of people in group i.
Output
Print the maximum number of teams of three people the coach can form.
Examples
Input
4
1 1 2 1
Output
1
Input
2
2 2
Output
0
Input
7
2 2 2 1 1 1 1
Output
3
Input
3
1 1 1
Output
1
Note
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
* The first group (of two people) and the seventh group (of one person),
* The second group (of two people) and the sixth group (of one person),
* The third group (of two people) and the fourth group (of one person). | instruction | 0 | 94,979 | 17 | 189,958 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Fri Apr 3 01:33:24 2020
@author: Designer
"""
even=0
odd=0
a=int(input(''))
b=str(input('').strip())
for i in range(0,len(b),2):
if b[i] == '2':
even=even+1
else:
odd=odd+1
if odd == 0:
print(0)
elif even>odd:
print(odd)
else:
c=odd-even
n=c//3
print(even+n)
``` | output | 1 | 94,979 | 17 | 189,959 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
Input
The first line contains single integer n (2 β€ n β€ 2Β·105) β the number of groups.
The second line contains a sequence of integers a1, a2, ..., an (1 β€ ai β€ 2), where ai is the number of people in group i.
Output
Print the maximum number of teams of three people the coach can form.
Examples
Input
4
1 1 2 1
Output
1
Input
2
2 2
Output
0
Input
7
2 2 2 1 1 1 1
Output
3
Input
3
1 1 1
Output
1
Note
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
* The first group (of two people) and the seventh group (of one person),
* The second group (of two people) and the sixth group (of one person),
* The third group (of two people) and the fourth group (of one person). | instruction | 0 | 94,980 | 17 | 189,960 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
cnt = min(a.count(1), a.count(2))
ans = cnt + max(0, (a.count(1) - cnt) // 3)
print(ans)
``` | output | 1 | 94,980 | 17 | 189,961 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
Input
The first line contains single integer n (2 β€ n β€ 2Β·105) β the number of groups.
The second line contains a sequence of integers a1, a2, ..., an (1 β€ ai β€ 2), where ai is the number of people in group i.
Output
Print the maximum number of teams of three people the coach can form.
Examples
Input
4
1 1 2 1
Output
1
Input
2
2 2
Output
0
Input
7
2 2 2 1 1 1 1
Output
3
Input
3
1 1 1
Output
1
Note
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
* The first group (of two people) and the seventh group (of one person),
* The second group (of two people) and the sixth group (of one person),
* The third group (of two people) and the fourth group (of one person). | instruction | 0 | 94,981 | 17 | 189,962 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
input()
data = list(map(int, input().split()))
n1 = data.count(1)
n2 = len(data) - n1
print(min(n1, n2) + (n1 - min(n1, n2)) // 3)
``` | output | 1 | 94,981 | 17 | 189,963 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
Input
The first line contains single integer n (2 β€ n β€ 2Β·105) β the number of groups.
The second line contains a sequence of integers a1, a2, ..., an (1 β€ ai β€ 2), where ai is the number of people in group i.
Output
Print the maximum number of teams of three people the coach can form.
Examples
Input
4
1 1 2 1
Output
1
Input
2
2 2
Output
0
Input
7
2 2 2 1 1 1 1
Output
3
Input
3
1 1 1
Output
1
Note
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
* The first group (of two people) and the seventh group (of one person),
* The second group (of two people) and the sixth group (of one person),
* The third group (of two people) and the fourth group (of one person). | instruction | 0 | 94,982 | 17 | 189,964 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
n = int(input())
l = [int(i) for i in input().split(" ")]
one = l.count(1)
two = n - one
result = 0
if two >= one:
result = one
else:
result += two
one = one - two
result += int(one/3)
print(result)
``` | output | 1 | 94,982 | 17 | 189,965 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
Input
The first line contains single integer n (2 β€ n β€ 2Β·105) β the number of groups.
The second line contains a sequence of integers a1, a2, ..., an (1 β€ ai β€ 2), where ai is the number of people in group i.
Output
Print the maximum number of teams of three people the coach can form.
Examples
Input
4
1 1 2 1
Output
1
Input
2
2 2
Output
0
Input
7
2 2 2 1 1 1 1
Output
3
Input
3
1 1 1
Output
1
Note
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
* The first group (of two people) and the seventh group (of one person),
* The second group (of two people) and the sixth group (of one person),
* The third group (of two people) and the fourth group (of one person).
Submitted Solution:
```
n=int(input())
stu = input().split()
lis = list(map(int,stu))
ones = lis.count(1)
twos = lis.count(2)
if twos<=ones:
ans = twos + (ones-twos)//3
else:
ans = ones
print(ans)
``` | instruction | 0 | 94,983 | 17 | 189,966 |
Yes | output | 1 | 94,983 | 17 | 189,967 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
Input
The first line contains single integer n (2 β€ n β€ 2Β·105) β the number of groups.
The second line contains a sequence of integers a1, a2, ..., an (1 β€ ai β€ 2), where ai is the number of people in group i.
Output
Print the maximum number of teams of three people the coach can form.
Examples
Input
4
1 1 2 1
Output
1
Input
2
2 2
Output
0
Input
7
2 2 2 1 1 1 1
Output
3
Input
3
1 1 1
Output
1
Note
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
* The first group (of two people) and the seventh group (of one person),
* The second group (of two people) and the sixth group (of one person),
* The third group (of two people) and the fourth group (of one person).
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split()))
x=a.count(1)
y=n-x
ans=min(x,y)
x-=ans
ans+=x//3
print(ans)
``` | instruction | 0 | 94,984 | 17 | 189,968 |
Yes | output | 1 | 94,984 | 17 | 189,969 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
Input
The first line contains single integer n (2 β€ n β€ 2Β·105) β the number of groups.
The second line contains a sequence of integers a1, a2, ..., an (1 β€ ai β€ 2), where ai is the number of people in group i.
Output
Print the maximum number of teams of three people the coach can form.
Examples
Input
4
1 1 2 1
Output
1
Input
2
2 2
Output
0
Input
7
2 2 2 1 1 1 1
Output
3
Input
3
1 1 1
Output
1
Note
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
* The first group (of two people) and the seventh group (of one person),
* The second group (of two people) and the sixth group (of one person),
* The third group (of two people) and the fourth group (of one person).
Submitted Solution:
```
import sys,collections
sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()
n = I()
a = Is()
two = a.count(2)
one = a.count(1)
twoOne = min(one,two)
print(twoOne + (one-twoOne)//3)
``` | instruction | 0 | 94,985 | 17 | 189,970 |
Yes | output | 1 | 94,985 | 17 | 189,971 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
Input
The first line contains single integer n (2 β€ n β€ 2Β·105) β the number of groups.
The second line contains a sequence of integers a1, a2, ..., an (1 β€ ai β€ 2), where ai is the number of people in group i.
Output
Print the maximum number of teams of three people the coach can form.
Examples
Input
4
1 1 2 1
Output
1
Input
2
2 2
Output
0
Input
7
2 2 2 1 1 1 1
Output
3
Input
3
1 1 1
Output
1
Note
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
* The first group (of two people) and the seventh group (of one person),
* The second group (of two people) and the sixth group (of one person),
* The third group (of two people) and the fourth group (of one person).
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split()))
one=a.count(1)
two=a.count(2)
if one>two:
print(two+(one-two)//3)
else:
print(one)
``` | instruction | 0 | 94,986 | 17 | 189,972 |
Yes | output | 1 | 94,986 | 17 | 189,973 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
Input
The first line contains single integer n (2 β€ n β€ 2Β·105) β the number of groups.
The second line contains a sequence of integers a1, a2, ..., an (1 β€ ai β€ 2), where ai is the number of people in group i.
Output
Print the maximum number of teams of three people the coach can form.
Examples
Input
4
1 1 2 1
Output
1
Input
2
2 2
Output
0
Input
7
2 2 2 1 1 1 1
Output
3
Input
3
1 1 1
Output
1
Note
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
* The first group (of two people) and the seventh group (of one person),
* The second group (of two people) and the sixth group (of one person),
* The third group (of two people) and the fourth group (of one person).
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split()))
if 1 not in a:
print("0")
elif 2 not in a:
print(n//3)
else:
x=a.count(1)
y=a.count(2)
if y>=x:
print(x)
else:
print(x + ((x-y)//3))
``` | instruction | 0 | 94,987 | 17 | 189,974 |
No | output | 1 | 94,987 | 17 | 189,975 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
Input
The first line contains single integer n (2 β€ n β€ 2Β·105) β the number of groups.
The second line contains a sequence of integers a1, a2, ..., an (1 β€ ai β€ 2), where ai is the number of people in group i.
Output
Print the maximum number of teams of three people the coach can form.
Examples
Input
4
1 1 2 1
Output
1
Input
2
2 2
Output
0
Input
7
2 2 2 1 1 1 1
Output
3
Input
3
1 1 1
Output
1
Note
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
* The first group (of two people) and the seventh group (of one person),
* The second group (of two people) and the sixth group (of one person),
* The third group (of two people) and the fourth group (of one person).
Submitted Solution:
```
n=int(input())
stu = input().split()
lis = list(map(int,stu))
ones = lis.count(1)
twos = lis.count(2)
if twos<=ones:
ans = twos + (ones-twos)//3
else:
ans = ones + ((twos-ones)*2)//6
print(ans)
``` | instruction | 0 | 94,988 | 17 | 189,976 |
No | output | 1 | 94,988 | 17 | 189,977 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
Input
The first line contains single integer n (2 β€ n β€ 2Β·105) β the number of groups.
The second line contains a sequence of integers a1, a2, ..., an (1 β€ ai β€ 2), where ai is the number of people in group i.
Output
Print the maximum number of teams of three people the coach can form.
Examples
Input
4
1 1 2 1
Output
1
Input
2
2 2
Output
0
Input
7
2 2 2 1 1 1 1
Output
3
Input
3
1 1 1
Output
1
Note
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
* The first group (of two people) and the seventh group (of one person),
* The second group (of two people) and the sixth group (of one person),
* The third group (of two people) and the fourth group (of one person).
Submitted Solution:
```
a=int(input())
l=list(map(int,input().split()))
o=l.count(1)
t=a-o
if t<=o:
print(t+(o-t)//3)
else:
print(o//3)
``` | instruction | 0 | 94,989 | 17 | 189,978 |
No | output | 1 | 94,989 | 17 | 189,979 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
Input
The first line contains single integer n (2 β€ n β€ 2Β·105) β the number of groups.
The second line contains a sequence of integers a1, a2, ..., an (1 β€ ai β€ 2), where ai is the number of people in group i.
Output
Print the maximum number of teams of three people the coach can form.
Examples
Input
4
1 1 2 1
Output
1
Input
2
2 2
Output
0
Input
7
2 2 2 1 1 1 1
Output
3
Input
3
1 1 1
Output
1
Note
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
* The first group (of two people) and the seventh group (of one person),
* The second group (of two people) and the sixth group (of one person),
* The third group (of two people) and the fourth group (of one person).
Submitted Solution:
```
n=int(input())
m=list(map(int,input().split()))
if (len(set(m)))==1 and list(set(m))!=[1] :
print(0)
else:
if list(set(m))==[1]:
print(n//3)
else:
print(min(n-(m.count(2)),(m.count(2))))
``` | instruction | 0 | 94,990 | 17 | 189,980 |
No | output | 1 | 94,990 | 17 | 189,981 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC).
A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si β how many students who play basketball belong to this department.
Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department.
Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other.
Input
The first line contains three integers n, m and h (1 β€ n β€ 100, 1 β€ m β€ 1000, 1 β€ h β€ m) β the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly.
The second line contains a single-space-separated list of m integers si (1 β€ si β€ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa.
Output
Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6.
Examples
Input
3 2 1
2 1
Output
1
Input
3 2 1
1 1
Output
-1
Input
3 2 1
2 2
Output
0.666667
Note
In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department.
In the second example, there are not enough players.
In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team. | instruction | 0 | 95,306 | 17 | 190,612 |
Tags: combinatorics, dp, math, probabilities
Correct Solution:
```
n,m,h=map(int,input().split())
s=list(map(int,input().split()))
a=1
S=sum(s)
for i in range(S-s[h-1]+1,S):
a*=(i-n+1)/i
print(-1 if S<n else 1-a)
# Made By Mostafa_Khaled
``` | output | 1 | 95,306 | 17 | 190,613 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC).
A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si β how many students who play basketball belong to this department.
Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department.
Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other.
Input
The first line contains three integers n, m and h (1 β€ n β€ 100, 1 β€ m β€ 1000, 1 β€ h β€ m) β the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly.
The second line contains a single-space-separated list of m integers si (1 β€ si β€ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa.
Output
Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6.
Examples
Input
3 2 1
2 1
Output
1
Input
3 2 1
1 1
Output
-1
Input
3 2 1
2 2
Output
0.666667
Note
In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department.
In the second example, there are not enough players.
In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team. | instruction | 0 | 95,307 | 17 | 190,614 |
Tags: combinatorics, dp, math, probabilities
Correct Solution:
```
"""
atleast 1 =1- zero of them (only wafa)
"""
n,m,h=map(int,input().split())
M=[int(x) for x in input().split()]
M=[0]+M
tot=sum(M)
if tot<n:
print(-1)
else:
tot-=1
M[h]-=1
ans=1.0
others=tot-M[h]
for i in range(0,n-1):
ans*=(others-i)/(tot-i)#if i is in ..wt abt others
print(1.0-ans)
``` | output | 1 | 95,307 | 17 | 190,615 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC).
A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si β how many students who play basketball belong to this department.
Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department.
Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other.
Input
The first line contains three integers n, m and h (1 β€ n β€ 100, 1 β€ m β€ 1000, 1 β€ h β€ m) β the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly.
The second line contains a single-space-separated list of m integers si (1 β€ si β€ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa.
Output
Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6.
Examples
Input
3 2 1
2 1
Output
1
Input
3 2 1
1 1
Output
-1
Input
3 2 1
2 2
Output
0.666667
Note
In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department.
In the second example, there are not enough players.
In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team. | instruction | 0 | 95,308 | 17 | 190,616 |
Tags: combinatorics, dp, math, probabilities
Correct Solution:
```
n,m,h = map(int,input().split())
lis = list(map(int,input().split()))
if sum(lis)<n:
print(-1)
else:
s=sum(lis)
ans=1
for i in range(n-1):
ans*=(s-lis[h-1]-i)
ans/=(s-i-1)
print(1-ans)
``` | output | 1 | 95,308 | 17 | 190,617 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC).
A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si β how many students who play basketball belong to this department.
Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department.
Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other.
Input
The first line contains three integers n, m and h (1 β€ n β€ 100, 1 β€ m β€ 1000, 1 β€ h β€ m) β the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly.
The second line contains a single-space-separated list of m integers si (1 β€ si β€ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa.
Output
Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6.
Examples
Input
3 2 1
2 1
Output
1
Input
3 2 1
1 1
Output
-1
Input
3 2 1
2 2
Output
0.666667
Note
In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department.
In the second example, there are not enough players.
In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team. | instruction | 0 | 95,309 | 17 | 190,618 |
Tags: combinatorics, dp, math, probabilities
Correct Solution:
```
import sys
import math
n,m,h = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
total = sum(arr)
if (total < n):
print ("-1")
sys.exit()
total1 = total - arr[h-1]
rem = total - total1-1
total = total - 1
ans = 1
'''
#start = total - (n-1)
#print (start)
x = start
#print (rem)
for i in range(rem-1):
start = float(float(start) * float(x-(i+1)))
print (start)
'''
for i in range(n-1):
x = float(total1 - i)
y = float(total - i)
#print (i,x,y)
ans = float(ans * float(x/y))
#print (ans)
ans = float(ans)
print("{0:.10f}".format(round(1-ans,10)))
``` | output | 1 | 95,309 | 17 | 190,619 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC).
A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si β how many students who play basketball belong to this department.
Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department.
Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other.
Input
The first line contains three integers n, m and h (1 β€ n β€ 100, 1 β€ m β€ 1000, 1 β€ h β€ m) β the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly.
The second line contains a single-space-separated list of m integers si (1 β€ si β€ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa.
Output
Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6.
Examples
Input
3 2 1
2 1
Output
1
Input
3 2 1
1 1
Output
-1
Input
3 2 1
2 2
Output
0.666667
Note
In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department.
In the second example, there are not enough players.
In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team.
Submitted Solution:
```
def ncr(nn,rr):
ans=1
if rr>nn:
return 0
for i in range(rr):
p=nn-i
q=i+1
ans *=(p/q)
return ans
n,m,h = map(int,input().split())
lis = list(map(int,input().split()))
if sum(lis)<n:
print(-1)
else:
s=sum(lis)
a=ncr(s-1,n-1)
b=ncr(s-lis[h-1],n-1)
print(1-b/a)
``` | instruction | 0 | 95,310 | 17 | 190,620 |
No | output | 1 | 95,310 | 17 | 190,621 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC).
A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si β how many students who play basketball belong to this department.
Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department.
Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other.
Input
The first line contains three integers n, m and h (1 β€ n β€ 100, 1 β€ m β€ 1000, 1 β€ h β€ m) β the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly.
The second line contains a single-space-separated list of m integers si (1 β€ si β€ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa.
Output
Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6.
Examples
Input
3 2 1
2 1
Output
1
Input
3 2 1
1 1
Output
-1
Input
3 2 1
2 2
Output
0.666667
Note
In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department.
In the second example, there are not enough players.
In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team.
Submitted Solution:
```
def ncr(nn,rr):
ans=1
if rr>nn:
return 0
for i in range(rr):
p=nn-i
q=i+1
ans *=(p/q)
return ans
n,m,h = map(int,input().split())
lis = list(map(int,input().split()))
if sum(lis)<n:
print(-1)
else:
s=sum(lis)
if h==766:
print("0.128032")
else:
a=ncr(s-1,n-1)
b=ncr(s-lis[h-1],n-1)
print(1-b/a)
``` | instruction | 0 | 95,311 | 17 | 190,622 |
No | output | 1 | 95,311 | 17 | 190,623 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC).
A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si β how many students who play basketball belong to this department.
Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department.
Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other.
Input
The first line contains three integers n, m and h (1 β€ n β€ 100, 1 β€ m β€ 1000, 1 β€ h β€ m) β the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly.
The second line contains a single-space-separated list of m integers si (1 β€ si β€ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa.
Output
Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6.
Examples
Input
3 2 1
2 1
Output
1
Input
3 2 1
1 1
Output
-1
Input
3 2 1
2 2
Output
0.666667
Note
In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department.
In the second example, there are not enough players.
In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team.
Submitted Solution:
```
import sys
import operator as op
from functools import reduce
import math
def ncr(n,r):
if (n < r):
return 0
if (r > n /2):
r = n- r
ans = 1
for x in range(1,r+1):
ans = (ans * (n-r+x))
ans = (ans/x)
return ans
n,m,h = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
total = sum(arr)
if (total < n):
print ("-1")
sys.exit()
total1 = total - arr[h-1]
ans1 = float(ncr(total1,n-1))
ans2 = float(ncr(total-1,n-1))
#print (total1,ans1,ans2)
ans = float(1 - (ans1/ans2))
print("{0:.10f}".format(round(ans,10)))
``` | instruction | 0 | 95,312 | 17 | 190,624 |
No | output | 1 | 95,312 | 17 | 190,625 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n students standing in a row. Two coaches are forming two teams β the first coach chooses the first team and the second coach chooses the second team.
The i-th student has integer programming skill a_i. All programming skills are distinct and between 1 and n, inclusive.
Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and k closest students to the left of him and k closest students to the right of him (if there are less than k students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team).
Your problem is to determine which students will be taken into the first team and which students will be taken into the second team.
Input
The first line of the input contains two integers n and k (1 β€ k β€ n β€ 2 β
10^5) β the number of students and the value determining the range of chosen students during each move, respectively.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ n), where a_i is the programming skill of the i-th student. It is guaranteed that all programming skills are distinct.
Output
Print a string of n characters; i-th character should be 1 if i-th student joins the first team, or 2 otherwise.
Examples
Input
5 2
2 4 5 3 1
Output
11111
Input
5 1
2 1 3 5 4
Output
22111
Input
7 1
7 2 1 3 5 4 6
Output
1121122
Input
5 1
2 4 5 3 1
Output
21112
Note
In the first example the first coach chooses the student on a position 3, and the row becomes empty (all students join the first team).
In the second example the first coach chooses the student on position 4, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team).
In the third example the first coach chooses the student on position 1, and the row becomes [1, 3, 5, 4, 6] (students with programming skills [2, 7] join the first team). Then the second coach chooses the student on position 5, and the row becomes [1, 3, 5] (students with programming skills [4, 6] join the second team). Then the first coach chooses the student on position 3, and the row becomes [1] (students with programming skills [3, 5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 1 joins the second team).
In the fourth example the first coach chooses the student on position 3, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). | instruction | 0 | 96,157 | 17 | 192,314 |
Tags: data structures, implementation, sortings
Correct Solution:
```
inf = 10 ** 6
n, k = map(int, input().split())
a = [-inf] + list(map(int, input().split()))
ans = [-1]*(n+10)
leftnext = [-1]*(n+10)
rightnext = [-1]*(n+10)
for i in range(1, n + 1):
rightnext[i] = i + 1
leftnext[i] = i - 1
visited = [False]*(n+10)
stack = [(a[i], i) for i in range(1, n+1)]
stack.sort()
phase = 0
loop = 0
while stack:
loop += 1
while stack and visited[stack[-1][1]] == True:
stack.pop()
if not stack:
continue
value, index = stack.pop()
ans[index] = phase + 1
rightcnt, leftcnt = 0, 0
lend, rend = -1, -1
now = index
while rightcnt <= k and now <= n:
rightcnt += 1
now = rightnext[now]
if rightcnt <= k:
visited[now] = True
ans[now] = phase + 1
rend = now
now = index
while leftcnt <= k and now >= 1:
leftcnt += 1
now = leftnext[now]
if leftcnt <= k:
visited[now] = True
ans[now] = phase + 1
lend = now
leftnext[rend] = lend
rightnext[lend] = rend
phase += 1
phase %= 2
print("".join(map(str,ans[1:n+1])))
``` | output | 1 | 96,157 | 17 | 192,315 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n students standing in a row. Two coaches are forming two teams β the first coach chooses the first team and the second coach chooses the second team.
The i-th student has integer programming skill a_i. All programming skills are distinct and between 1 and n, inclusive.
Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and k closest students to the left of him and k closest students to the right of him (if there are less than k students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team).
Your problem is to determine which students will be taken into the first team and which students will be taken into the second team.
Input
The first line of the input contains two integers n and k (1 β€ k β€ n β€ 2 β
10^5) β the number of students and the value determining the range of chosen students during each move, respectively.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ n), where a_i is the programming skill of the i-th student. It is guaranteed that all programming skills are distinct.
Output
Print a string of n characters; i-th character should be 1 if i-th student joins the first team, or 2 otherwise.
Examples
Input
5 2
2 4 5 3 1
Output
11111
Input
5 1
2 1 3 5 4
Output
22111
Input
7 1
7 2 1 3 5 4 6
Output
1121122
Input
5 1
2 4 5 3 1
Output
21112
Note
In the first example the first coach chooses the student on a position 3, and the row becomes empty (all students join the first team).
In the second example the first coach chooses the student on position 4, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team).
In the third example the first coach chooses the student on position 1, and the row becomes [1, 3, 5, 4, 6] (students with programming skills [2, 7] join the first team). Then the second coach chooses the student on position 5, and the row becomes [1, 3, 5] (students with programming skills [4, 6] join the second team). Then the first coach chooses the student on position 3, and the row becomes [1] (students with programming skills [3, 5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 1 joins the second team).
In the fourth example the first coach chooses the student on position 3, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). | instruction | 0 | 96,158 | 17 | 192,316 |
Tags: data structures, implementation, sortings
Correct Solution:
```
n, k = map(int, input().split())
lst = map(int, input().split())
def debug():
print('-')
lst = [0 for _ in range(n)]
for i in range(n):
node = table[i]
lst[node.index] = node.team
print (''.join(str(x) for x in lst))
print('-')
class Node:
def __init__(self, index):
self.index = index
self.team = 0
self.prev = None
self.next = None
table = [None for _ in range(n)]
prev_node = None
for index, element in enumerate(lst):
node = Node(index)
if prev_node:
prev_node.next = node
node.prev = prev_node
table[element - 1] = node
prev_node = node
team = 1
for i in reversed(range(n)):
# taken
if table[i].team != 0:
continue
node = table[i]
node.team = team
next_node = node.next
for j in range(k):
if next_node is None:
break
next_node.team = team
next_node = next_node.next
prev_node = node.prev
for j in range(k):
if prev_node is None:
break
prev_node.team = team
prev_node = prev_node.prev
if prev_node is not None:
prev_node.next = next_node
if next_node is not None:
next_node.prev = prev_node
team = 1 if team == 2 else 2
lst = [0 for _ in range(n)]
for i in range(n):
node = table[i]
lst[node.index] = node.team
print (''.join(str(x) for x in lst))
``` | output | 1 | 96,158 | 17 | 192,317 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n students standing in a row. Two coaches are forming two teams β the first coach chooses the first team and the second coach chooses the second team.
The i-th student has integer programming skill a_i. All programming skills are distinct and between 1 and n, inclusive.
Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and k closest students to the left of him and k closest students to the right of him (if there are less than k students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team).
Your problem is to determine which students will be taken into the first team and which students will be taken into the second team.
Input
The first line of the input contains two integers n and k (1 β€ k β€ n β€ 2 β
10^5) β the number of students and the value determining the range of chosen students during each move, respectively.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ n), where a_i is the programming skill of the i-th student. It is guaranteed that all programming skills are distinct.
Output
Print a string of n characters; i-th character should be 1 if i-th student joins the first team, or 2 otherwise.
Examples
Input
5 2
2 4 5 3 1
Output
11111
Input
5 1
2 1 3 5 4
Output
22111
Input
7 1
7 2 1 3 5 4 6
Output
1121122
Input
5 1
2 4 5 3 1
Output
21112
Note
In the first example the first coach chooses the student on a position 3, and the row becomes empty (all students join the first team).
In the second example the first coach chooses the student on position 4, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team).
In the third example the first coach chooses the student on position 1, and the row becomes [1, 3, 5, 4, 6] (students with programming skills [2, 7] join the first team). Then the second coach chooses the student on position 5, and the row becomes [1, 3, 5] (students with programming skills [4, 6] join the second team). Then the first coach chooses the student on position 3, and the row becomes [1] (students with programming skills [3, 5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 1 joins the second team).
In the fourth example the first coach chooses the student on position 3, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). | instruction | 0 | 96,159 | 17 | 192,318 |
Tags: data structures, implementation, sortings
Correct Solution:
```
# AC
import sys
class Main:
def __init__(self):
self.buff = None
self.index = 0
def next(self):
if self.buff is None or self.index == len(self.buff):
self.buff = sys.stdin.readline().split()
self.index = 0
val = self.buff[self.index]
self.index += 1
return val
def next_int(self):
return int(self.next())
def solve(self):
n = self.next_int()
k = self.next_int()
x = [self.next_int() for _ in range(0, n)]
bf = [x - 1 for x in range(0, n)]
nx = [x + 1 for x in range(0, n)]
t = [0 for _ in range(0, n)]
od = [0 for _ in range(0, n)]
for i in range(0, n):
od[x[i] - 1] = i
tt = 1
for i in range(n - 1, -1, -1):
if t[od[i]] == 0:
o = od[i]
t[o] = tt
for _ in range(0, k):
o = bf[o]
if o == -1:
break
t[o] = tt
oo = od[i]
for _ in range(0, k):
oo = nx[oo]
if oo == n:
break
t[oo] = tt
if o != -1 and bf[o] != -1:
nx[bf[o]] = oo if oo == n else nx[oo]
if oo != n and nx[oo] != n:
bf[nx[oo]] = o if o == -1 else bf[o]
tt = 3 - tt
print(''.join(map(lambda xx: str(xx), t)))
if __name__ == '__main__':
Main().solve()
``` | output | 1 | 96,159 | 17 | 192,319 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n students standing in a row. Two coaches are forming two teams β the first coach chooses the first team and the second coach chooses the second team.
The i-th student has integer programming skill a_i. All programming skills are distinct and between 1 and n, inclusive.
Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and k closest students to the left of him and k closest students to the right of him (if there are less than k students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team).
Your problem is to determine which students will be taken into the first team and which students will be taken into the second team.
Input
The first line of the input contains two integers n and k (1 β€ k β€ n β€ 2 β
10^5) β the number of students and the value determining the range of chosen students during each move, respectively.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ n), where a_i is the programming skill of the i-th student. It is guaranteed that all programming skills are distinct.
Output
Print a string of n characters; i-th character should be 1 if i-th student joins the first team, or 2 otherwise.
Examples
Input
5 2
2 4 5 3 1
Output
11111
Input
5 1
2 1 3 5 4
Output
22111
Input
7 1
7 2 1 3 5 4 6
Output
1121122
Input
5 1
2 4 5 3 1
Output
21112
Note
In the first example the first coach chooses the student on a position 3, and the row becomes empty (all students join the first team).
In the second example the first coach chooses the student on position 4, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team).
In the third example the first coach chooses the student on position 1, and the row becomes [1, 3, 5, 4, 6] (students with programming skills [2, 7] join the first team). Then the second coach chooses the student on position 5, and the row becomes [1, 3, 5] (students with programming skills [4, 6] join the second team). Then the first coach chooses the student on position 3, and the row becomes [1] (students with programming skills [3, 5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 1 joins the second team).
In the fourth example the first coach chooses the student on position 3, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). | instruction | 0 | 96,160 | 17 | 192,320 |
Tags: data structures, implementation, sortings
Correct Solution:
```
n,k=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
team=[0]*n
nxt=[x+1 for x in range(len(a))]
nxt[-1]=n+2*k
prv=[x-1 for x in range(len(a))]
prv[0]=-2*k
loc=[0]*(len(a)+1)
for i,v in enumerate(a):
loc[v]=i
left=n
val=1
while left>0:
start=loc[left]
left = left - 1
if team[start]>0:
continue
team[start]=val
nx=nxt[start]
pv=prv[start]
if pv>=0:
nxt[pv]=nx
if nx<n:
prv[nx]=pv
ctdown=k
while nx<n and ctdown>0:
team[nx]=val
if prv[nx]>=0:
nxt[prv[nx]] = nxt[nx]
if nxt[nx]<n:
prv[nxt[nx]] = prv[nx]
nx = nxt[nx]
ctdown = ctdown - 1
ctdown=k
while pv>=0 and ctdown>0:
team[pv]=val
if prv[pv]>=0:
nxt[prv[pv]] = nxt[pv]
if nxt[pv]<n:
prv[nxt[pv]] = prv[pv]
pv = prv[pv]
ctdown = ctdown - 1
val = 3 - val
print("".join(str(x) for x in team))
``` | output | 1 | 96,160 | 17 | 192,321 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n students standing in a row. Two coaches are forming two teams β the first coach chooses the first team and the second coach chooses the second team.
The i-th student has integer programming skill a_i. All programming skills are distinct and between 1 and n, inclusive.
Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and k closest students to the left of him and k closest students to the right of him (if there are less than k students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team).
Your problem is to determine which students will be taken into the first team and which students will be taken into the second team.
Input
The first line of the input contains two integers n and k (1 β€ k β€ n β€ 2 β
10^5) β the number of students and the value determining the range of chosen students during each move, respectively.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ n), where a_i is the programming skill of the i-th student. It is guaranteed that all programming skills are distinct.
Output
Print a string of n characters; i-th character should be 1 if i-th student joins the first team, or 2 otherwise.
Examples
Input
5 2
2 4 5 3 1
Output
11111
Input
5 1
2 1 3 5 4
Output
22111
Input
7 1
7 2 1 3 5 4 6
Output
1121122
Input
5 1
2 4 5 3 1
Output
21112
Note
In the first example the first coach chooses the student on a position 3, and the row becomes empty (all students join the first team).
In the second example the first coach chooses the student on position 4, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team).
In the third example the first coach chooses the student on position 1, and the row becomes [1, 3, 5, 4, 6] (students with programming skills [2, 7] join the first team). Then the second coach chooses the student on position 5, and the row becomes [1, 3, 5] (students with programming skills [4, 6] join the second team). Then the first coach chooses the student on position 3, and the row becomes [1] (students with programming skills [3, 5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 1 joins the second team).
In the fourth example the first coach chooses the student on position 3, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). | instruction | 0 | 96,161 | 17 | 192,322 |
Tags: data structures, implementation, sortings
Correct Solution:
```
def solve(n, k, a):
pre, nex, d = {}, {}, {}
for i in range(n):
pre[i] = i - 1
nex[i] = i + 1
d[a[i]] = i
a.sort(reverse=True)
res = [0] * n
turn = 1
for x in a:
index = d[x]
if res[index]: continue
res[index] = turn
left, right = pre[index], nex[index]
for i in range(k):
if left < 0: break
res[left] = turn
left = pre[left]
for i in range(k):
if right >= n: break
res[right] = turn
right = nex[right]
nex[left] = right
pre[right] = left
turn = 3 - turn
return ''.join(map(str, res))
n,k = map(int, input().split())
a = list(map(int, input().split()))
print(solve(n, k, a))
``` | output | 1 | 96,161 | 17 | 192,323 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n students standing in a row. Two coaches are forming two teams β the first coach chooses the first team and the second coach chooses the second team.
The i-th student has integer programming skill a_i. All programming skills are distinct and between 1 and n, inclusive.
Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and k closest students to the left of him and k closest students to the right of him (if there are less than k students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team).
Your problem is to determine which students will be taken into the first team and which students will be taken into the second team.
Input
The first line of the input contains two integers n and k (1 β€ k β€ n β€ 2 β
10^5) β the number of students and the value determining the range of chosen students during each move, respectively.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ n), where a_i is the programming skill of the i-th student. It is guaranteed that all programming skills are distinct.
Output
Print a string of n characters; i-th character should be 1 if i-th student joins the first team, or 2 otherwise.
Examples
Input
5 2
2 4 5 3 1
Output
11111
Input
5 1
2 1 3 5 4
Output
22111
Input
7 1
7 2 1 3 5 4 6
Output
1121122
Input
5 1
2 4 5 3 1
Output
21112
Note
In the first example the first coach chooses the student on a position 3, and the row becomes empty (all students join the first team).
In the second example the first coach chooses the student on position 4, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team).
In the third example the first coach chooses the student on position 1, and the row becomes [1, 3, 5, 4, 6] (students with programming skills [2, 7] join the first team). Then the second coach chooses the student on position 5, and the row becomes [1, 3, 5] (students with programming skills [4, 6] join the second team). Then the first coach chooses the student on position 3, and the row becomes [1] (students with programming skills [3, 5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 1 joins the second team).
In the fourth example the first coach chooses the student on position 3, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). | instruction | 0 | 96,162 | 17 | 192,324 |
Tags: data structures, implementation, sortings
Correct Solution:
```
class Node:
def __init__(self, v, i):
self.v = v
self.i = i
self.left = None
self.right = None
n, k = map(int, input().split())
nums = list(map(int, input().split()))
nodes = [Node(v, i) for i, v in enumerate(nums)]
sort = [[v, i] for i, v in enumerate(nums)]
sort = sorted(sort, key = lambda x: [x[0], x[1]],reverse=True)
for i in range(len(nodes)):
if i < len(nodes) - 1:
nodes[i].right = nodes[i + 1]
if i > 0:
nodes[i].left = nodes[i - 1]
ans = [0] * n
team = 1
for pair in sort:
v, i = pair
# if nodes[i].left == None and nodes[i].right == None:
# continue
if nodes[i].i == None:
continue
# print(v, i)
ans[i] = team if team == 1 else 2
cur = nodes[i].right
right = None
for j in range(k):
if cur == None:
break
right = cur.right
ans[cur.i] = team if team == 1 else 2
cur.i = None
cur = right
cur = nodes[i].left
# print(cur.i, cur.v)
left = None
for j in range(k):
if cur == None:
break
left = cur.left
ans[cur.i] = team if team == 1 else 2
cur.i = None
cur = left
# if left == None and right == None:
# break
if left:
left.right = right
if right:
right.left = left
team = team ^ 1
print(''.join([str(i) for i in ans]))
``` | output | 1 | 96,162 | 17 | 192,325 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n students standing in a row. Two coaches are forming two teams β the first coach chooses the first team and the second coach chooses the second team.
The i-th student has integer programming skill a_i. All programming skills are distinct and between 1 and n, inclusive.
Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and k closest students to the left of him and k closest students to the right of him (if there are less than k students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team).
Your problem is to determine which students will be taken into the first team and which students will be taken into the second team.
Input
The first line of the input contains two integers n and k (1 β€ k β€ n β€ 2 β
10^5) β the number of students and the value determining the range of chosen students during each move, respectively.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ n), where a_i is the programming skill of the i-th student. It is guaranteed that all programming skills are distinct.
Output
Print a string of n characters; i-th character should be 1 if i-th student joins the first team, or 2 otherwise.
Examples
Input
5 2
2 4 5 3 1
Output
11111
Input
5 1
2 1 3 5 4
Output
22111
Input
7 1
7 2 1 3 5 4 6
Output
1121122
Input
5 1
2 4 5 3 1
Output
21112
Note
In the first example the first coach chooses the student on a position 3, and the row becomes empty (all students join the first team).
In the second example the first coach chooses the student on position 4, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team).
In the third example the first coach chooses the student on position 1, and the row becomes [1, 3, 5, 4, 6] (students with programming skills [2, 7] join the first team). Then the second coach chooses the student on position 5, and the row becomes [1, 3, 5] (students with programming skills [4, 6] join the second team). Then the first coach chooses the student on position 3, and the row becomes [1] (students with programming skills [3, 5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 1 joins the second team).
In the fourth example the first coach chooses the student on position 3, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). | instruction | 0 | 96,163 | 17 | 192,326 |
Tags: data structures, implementation, sortings
Correct Solution:
```
import sys
input = sys.stdin.readline
n,k=map(int,input().split())
A=list(map(int,input().split()))
A_INV=[-1]*n
for i in range(n):
A_INV[A[i]-1]=i
L=list(range(-1,n-1))
R=list(range(1,n+1))
USELIST=[0]*n
ANS=[0]*n
NOW=1
for a in A_INV[::-1]:
if USELIST[a]==1:
continue
USELIST[a]=1
ANS[a]=NOW
if 0<=a<n and 0<=L[a]<n:
R[L[a]]=R[a]
if 0<=a<n and 0<=R[a]<n:
L[R[a]]=L[a]
r=a
for step in range(k):
r=R[r]
if r<0 or r>=n:
break
ANS[r]=NOW
USELIST[r]=1
if 0<=r<n and 0<=L[r]<n:
R[L[r]]=R[r]
if 0<=r<n and 0<=R[r]<n:
L[R[r]]=L[r]
l=a
for step in range(k):
l=L[l]
if l<0 or l>=n:
break
ANS[l]=NOW
USELIST[l]=1
if 0<=l<n and 0<=L[l]<n:
R[L[l]]=R[l]
if 0<=l<n and 0<=R[l]<n:
L[R[l]]=L[l]
NOW=3-NOW
#print(*ANS,USELIST,L,R)
print("".join(map(str,ANS)))
``` | output | 1 | 96,163 | 17 | 192,327 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n students standing in a row. Two coaches are forming two teams β the first coach chooses the first team and the second coach chooses the second team.
The i-th student has integer programming skill a_i. All programming skills are distinct and between 1 and n, inclusive.
Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and k closest students to the left of him and k closest students to the right of him (if there are less than k students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team).
Your problem is to determine which students will be taken into the first team and which students will be taken into the second team.
Input
The first line of the input contains two integers n and k (1 β€ k β€ n β€ 2 β
10^5) β the number of students and the value determining the range of chosen students during each move, respectively.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ n), where a_i is the programming skill of the i-th student. It is guaranteed that all programming skills are distinct.
Output
Print a string of n characters; i-th character should be 1 if i-th student joins the first team, or 2 otherwise.
Examples
Input
5 2
2 4 5 3 1
Output
11111
Input
5 1
2 1 3 5 4
Output
22111
Input
7 1
7 2 1 3 5 4 6
Output
1121122
Input
5 1
2 4 5 3 1
Output
21112
Note
In the first example the first coach chooses the student on a position 3, and the row becomes empty (all students join the first team).
In the second example the first coach chooses the student on position 4, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team).
In the third example the first coach chooses the student on position 1, and the row becomes [1, 3, 5, 4, 6] (students with programming skills [2, 7] join the first team). Then the second coach chooses the student on position 5, and the row becomes [1, 3, 5] (students with programming skills [4, 6] join the second team). Then the first coach chooses the student on position 3, and the row becomes [1] (students with programming skills [3, 5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 1 joins the second team).
In the fourth example the first coach chooses the student on position 3, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). | instruction | 0 | 96,164 | 17 | 192,328 |
Tags: data structures, implementation, sortings
Correct Solution:
```
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
left = [i-1 for i in range(n)]
right = [i+1 for i in range(n)]
ans = [0] * n
def next(i):
upd = [i]
i = right[i]
while i < n and ans[i] != 0:
upd.append(i)
i = right[i]
for x in upd:
right[x] = i
return i
def prev(i):
upd = [i]
i = left[i]
while i >= 0 and ans[i] != 0:
upd.append(i)
i = left[i]
for x in upd:
left[x] = i
return i
a = list(map(int, input().split()))
pos = [0] * (n+1)
for i in range(n):
pos[a[i]] = i
team = 1
for x in range(n, 0, -1):
i = pos[x]
if ans[i] != 0:
continue;
ans[i] = team
j = i
for _ in range(k):
j = next(j)
if j >= n:
break
ans[j] = team
j = i
for _ in range(k):
j = prev(j)
if j < 0:
break
ans[j] = team
team = 3 - team
print(''.join(map(str, ans)))
``` | output | 1 | 96,164 | 17 | 192,329 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n students standing in a row. Two coaches are forming two teams β the first coach chooses the first team and the second coach chooses the second team.
The i-th student has integer programming skill a_i. All programming skills are distinct and between 1 and n, inclusive.
Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and k closest students to the left of him and k closest students to the right of him (if there are less than k students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team).
Your problem is to determine which students will be taken into the first team and which students will be taken into the second team.
Input
The first line of the input contains two integers n and k (1 β€ k β€ n β€ 2 β
10^5) β the number of students and the value determining the range of chosen students during each move, respectively.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ n), where a_i is the programming skill of the i-th student. It is guaranteed that all programming skills are distinct.
Output
Print a string of n characters; i-th character should be 1 if i-th student joins the first team, or 2 otherwise.
Examples
Input
5 2
2 4 5 3 1
Output
11111
Input
5 1
2 1 3 5 4
Output
22111
Input
7 1
7 2 1 3 5 4 6
Output
1121122
Input
5 1
2 4 5 3 1
Output
21112
Note
In the first example the first coach chooses the student on a position 3, and the row becomes empty (all students join the first team).
In the second example the first coach chooses the student on position 4, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team).
In the third example the first coach chooses the student on position 1, and the row becomes [1, 3, 5, 4, 6] (students with programming skills [2, 7] join the first team). Then the second coach chooses the student on position 5, and the row becomes [1, 3, 5] (students with programming skills [4, 6] join the second team). Then the first coach chooses the student on position 3, and the row becomes [1] (students with programming skills [3, 5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 1 joins the second team).
In the fourth example the first coach chooses the student on position 3, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team).
Submitted Solution:
```
#! /usr/bin/env python3
# -*- coding: UTF-8 -*-
class BitTree:
def __init__(self, size):
self.size = size
self.arr = [0 for _ in range(size + 1)]
def add(self, idx, val):
i = idx
while i <= self.size:
self.arr[i] += val
i += i & (-i)
def sum(self, idx):
ret = 0
i = idx
while i > 0:
ret += self.arr[i]
i -= i & (-i)
return ret
def find_left(self, idx, k):
x = self.sum(idx)
l, r = 1, idx
while l <= r:
m = (l + r) // 2
tmp = self.sum(idx) - self.sum(m - 1)
if tmp > k:
l = m + 1
else:
r = m - 1
return l
def find_right(self, idx, k):
x = self.sum(idx)
l, r = idx, self.size
while l <= r:
m = (l + r) // 2
tmp = self.sum(m - 1) - self.sum(idx)
if tmp < k:
r = m - 1
else:
l = m + 1
return r
def find_left(lst, ans, idx, k, tag):
idx = lst[idx][0]
while k > 0 and idx >= 1:
ans[idx] = tag
k -= 1
idx = lst[idx][0]
return max(idx, 0)
def find_right(lst, ans, idx, k, tag, n):
idx = lst[idx][1]
while k > 0 and idx <= n:
ans[idx] = tag
k -= 1
idx = lst[idx][1]
return min(idx, n+1)
def main():
line = input()
n, k = int(line.split(' ')[0]), int(line.split(' ')[1])
line = input()
ans = ['0' for _ in range(n + 2)]
arr = []
lst = []
for i in range(n + 2):
lst.append([max(i - 1, 0), min(i + 1, n + 1)])
for i, val in enumerate(line.split(' ')):
arr.append((i + 1, int(val)))
arr.sort(key=lambda x: x[1], reverse=True)
tag = 1
for item in arr:
idx = item[0]
if ans[idx] != '0':
continue
ans[idx] = str(tag)
left = find_left(lst, ans, idx, k, str(tag))
right = find_right(lst, ans, idx, k, str(tag), n)
lst[left][1] = right
lst[right][0] = left
tag = 3 - tag
print(''.join(ans[1:-1]))
# print(''.join(ans))
if __name__ == '__main__':
main()
``` | instruction | 0 | 96,165 | 17 | 192,330 |
Yes | output | 1 | 96,165 | 17 | 192,331 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n students standing in a row. Two coaches are forming two teams β the first coach chooses the first team and the second coach chooses the second team.
The i-th student has integer programming skill a_i. All programming skills are distinct and between 1 and n, inclusive.
Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and k closest students to the left of him and k closest students to the right of him (if there are less than k students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team).
Your problem is to determine which students will be taken into the first team and which students will be taken into the second team.
Input
The first line of the input contains two integers n and k (1 β€ k β€ n β€ 2 β
10^5) β the number of students and the value determining the range of chosen students during each move, respectively.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ n), where a_i is the programming skill of the i-th student. It is guaranteed that all programming skills are distinct.
Output
Print a string of n characters; i-th character should be 1 if i-th student joins the first team, or 2 otherwise.
Examples
Input
5 2
2 4 5 3 1
Output
11111
Input
5 1
2 1 3 5 4
Output
22111
Input
7 1
7 2 1 3 5 4 6
Output
1121122
Input
5 1
2 4 5 3 1
Output
21112
Note
In the first example the first coach chooses the student on a position 3, and the row becomes empty (all students join the first team).
In the second example the first coach chooses the student on position 4, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team).
In the third example the first coach chooses the student on position 1, and the row becomes [1, 3, 5, 4, 6] (students with programming skills [2, 7] join the first team). Then the second coach chooses the student on position 5, and the row becomes [1, 3, 5] (students with programming skills [4, 6] join the second team). Then the first coach chooses the student on position 3, and the row becomes [1] (students with programming skills [3, 5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 1 joins the second team).
In the fourth example the first coach chooses the student on position 3, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team).
Submitted Solution:
```
#pajenegod
def delete(i,grp):
l = left[i]
r = right[i]
if l != -1:
right[l] = r
if r != n:
left[r] = l
used[i] = grp
n,k = map(int,input().split())
arr = list(map(int,input().split()))
left = [-1]*n
right = [n]*n
used = [-1]*n
for i in range(n):
left[i] = i-1
right[i] = i+1
order = sorted(range(n) , key = lambda i : arr[i] , reverse = True)
grp = 1
for i in order:
if used[i] != -1:
continue
l = left[i]
r = right[i]
delete(i,grp)
cnt = 0
while l != -1 and cnt < k:
cnt += 1
temp = left[l]
delete(l,grp)
l = temp
cnt = 0
while r != n and cnt < k:
cnt += 1
temp = right[r]
delete(r,grp)
r = temp
if grp == 1:
grp = 2
else:
grp = 1
print(*used,sep='')
``` | instruction | 0 | 96,166 | 17 | 192,332 |
Yes | output | 1 | 96,166 | 17 | 192,333 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n students standing in a row. Two coaches are forming two teams β the first coach chooses the first team and the second coach chooses the second team.
The i-th student has integer programming skill a_i. All programming skills are distinct and between 1 and n, inclusive.
Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and k closest students to the left of him and k closest students to the right of him (if there are less than k students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team).
Your problem is to determine which students will be taken into the first team and which students will be taken into the second team.
Input
The first line of the input contains two integers n and k (1 β€ k β€ n β€ 2 β
10^5) β the number of students and the value determining the range of chosen students during each move, respectively.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ n), where a_i is the programming skill of the i-th student. It is guaranteed that all programming skills are distinct.
Output
Print a string of n characters; i-th character should be 1 if i-th student joins the first team, or 2 otherwise.
Examples
Input
5 2
2 4 5 3 1
Output
11111
Input
5 1
2 1 3 5 4
Output
22111
Input
7 1
7 2 1 3 5 4 6
Output
1121122
Input
5 1
2 4 5 3 1
Output
21112
Note
In the first example the first coach chooses the student on a position 3, and the row becomes empty (all students join the first team).
In the second example the first coach chooses the student on position 4, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team).
In the third example the first coach chooses the student on position 1, and the row becomes [1, 3, 5, 4, 6] (students with programming skills [2, 7] join the first team). Then the second coach chooses the student on position 5, and the row becomes [1, 3, 5] (students with programming skills [4, 6] join the second team). Then the first coach chooses the student on position 3, and the row becomes [1] (students with programming skills [3, 5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 1 joins the second team).
In the fourth example the first coach chooses the student on position 3, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team).
Submitted Solution:
```
def input_ints():
return [int(x) for x in input().split()]
class Node:
def __init__(self, val):
self.prev = None
self.next = None
self.val = val
self.team = None
_, k = input_ints()
nodes = [Node(x) for x in input_ints()]
order = [i for i, x in sorted(enumerate(nodes), key=lambda x: x[1].val, reverse=True)]
for a, b in zip(nodes, nodes[1:]):
a.next = b
b.prev = a
team = 1
for i in order:
node = nodes[i]
if node.team:
continue
left = node
for _ in range(k+1):
if left:
left.team = team
left = left.prev
else:
break
right = node
for _ in range(k+1):
if right:
right.team = team
right = right.next
else:
break
if left:
left.next = right
if right:
right.prev = left
team = (team == 1) + 1
print(''.join(str(x.team) for x in nodes))
``` | instruction | 0 | 96,167 | 17 | 192,334 |
Yes | output | 1 | 96,167 | 17 | 192,335 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n students standing in a row. Two coaches are forming two teams β the first coach chooses the first team and the second coach chooses the second team.
The i-th student has integer programming skill a_i. All programming skills are distinct and between 1 and n, inclusive.
Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and k closest students to the left of him and k closest students to the right of him (if there are less than k students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team).
Your problem is to determine which students will be taken into the first team and which students will be taken into the second team.
Input
The first line of the input contains two integers n and k (1 β€ k β€ n β€ 2 β
10^5) β the number of students and the value determining the range of chosen students during each move, respectively.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ n), where a_i is the programming skill of the i-th student. It is guaranteed that all programming skills are distinct.
Output
Print a string of n characters; i-th character should be 1 if i-th student joins the first team, or 2 otherwise.
Examples
Input
5 2
2 4 5 3 1
Output
11111
Input
5 1
2 1 3 5 4
Output
22111
Input
7 1
7 2 1 3 5 4 6
Output
1121122
Input
5 1
2 4 5 3 1
Output
21112
Note
In the first example the first coach chooses the student on a position 3, and the row becomes empty (all students join the first team).
In the second example the first coach chooses the student on position 4, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team).
In the third example the first coach chooses the student on position 1, and the row becomes [1, 3, 5, 4, 6] (students with programming skills [2, 7] join the first team). Then the second coach chooses the student on position 5, and the row becomes [1, 3, 5] (students with programming skills [4, 6] join the second team). Then the first coach chooses the student on position 3, and the row becomes [1] (students with programming skills [3, 5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 1 joins the second team).
In the fourth example the first coach chooses the student on position 3, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team).
Submitted Solution:
```
'''input
5 1
2 4 5 3 1
'''
from sys import stdin
import math
from copy import deepcopy
import collections
# heap dict source code
def doc(s):
if hasattr(s, '__call__'):
s = s.__doc__
def f(g):
g.__doc__ = s
return g
return f
class heapdict(collections.MutableMapping):
__marker = object()
@staticmethod
def _parent(i):
return ((i - 1) >> 1)
@staticmethod
def _left(i):
return ((i << 1) + 1)
@staticmethod
def _right(i):
return ((i+1) << 1)
def __init__(self, *args, **kw):
self.heap = []
self.d = {}
self.update(*args, **kw)
@doc(dict.clear)
def clear(self):
self.heap.clear()
self.d.clear()
@doc(dict.__setitem__)
def __setitem__(self, key, value):
if key in self.d:
self.pop(key)
wrapper = [value, key, len(self)]
self.d[key] = wrapper
self.heap.append(wrapper)
self._decrease_key(len(self.heap)-1)
def _min_heapify(self, i):
l = self._left(i)
r = self._right(i)
n = len(self.heap)
if l < n and self.heap[l][0] < self.heap[i][0]:
low = l
else:
low = i
if r < n and self.heap[r][0] < self.heap[low][0]:
low = r
if low != i:
self._swap(i, low)
self._min_heapify(low)
def _decrease_key(self, i):
while i:
parent = self._parent(i)
if self.heap[parent][0] < self.heap[i][0]: break
self._swap(i, parent)
i = parent
def _swap(self, i, j):
self.heap[i], self.heap[j] = self.heap[j], self.heap[i]
self.heap[i][2] = i
self.heap[j][2] = j
@doc(dict.__delitem__)
def __delitem__(self, key):
wrapper = self.d[key]
while wrapper[2]:
parentpos = self._parent(wrapper[2])
parent = self.heap[parentpos]
self._swap(wrapper[2], parent[2])
self.popitem()
@doc(dict.__getitem__)
def __getitem__(self, key):
return self.d[key][0]
@doc(dict.__iter__)
def __iter__(self):
return iter(self.d)
def popitem(self):
"""D.popitem() -> (k, v), remove and return the (key, value) pair with lowest\nvalue; but raise KeyError if D is empty."""
wrapper = self.heap[0]
if len(self.heap) == 1:
self.heap.pop()
else:
self.heap[0] = self.heap.pop(-1)
self.heap[0][2] = 0
self._min_heapify(0)
del self.d[wrapper[1]]
return wrapper[1], wrapper[0]
@doc(dict.__len__)
def __len__(self):
return len(self.d)
def peekitem(self):
"""D.peekitem() -> (k, v), return the (key, value) pair with lowest value;\n but raise KeyError if D is empty."""
return (self.heap[0][1], self.heap[0][0])
del doc
__all__ = ['heapdict']
def heap_delete(mypq, index):
if index in mypq:
mypq[index] = -float('inf')
mypq.popitem()
def get_left_right(arr, n):
aux = []
for i in range(n):
aux.append([arr[i], i - 1, i + 1])
return aux
def add_left(arr, mypq, myset, index, k):
left = index
count = 0
while left != -1 and count < k:
left = arr[left][1]
if left == -1:
break
myset.add(arr[left][0])
heap_delete(mypq, left)
count += 1
if left == -1:
arr[index][1] = -1
else:
arr[index][1] = arr[left][1]
arr[left][2] = index
def add_right(arr, mypq, myset, index, k):
right = index
count = 0
while right != len(arr) and count < k:
right = arr[right][2]
if right == len(arr):
break
myset.add(arr[right][0])
heap_delete(mypq, right)
count += 1
if right == len(arr):
arr[index][2] = len(arr)
else:
arr[index][2] = arr[right][2]
arr[right][1] = index
# main starts
n, k = list(map(int, stdin.readline().split()))
arr = list(map(int, stdin.readline().split()))
arr = get_left_right(arr, n)
# making heap dict
mypq = heapdict()
for i in range(n):
mypq[i] = -arr[i][0]
# assigning team
first = set()
second = set()
chance = 0
while len(mypq) > 0:
if chance == 0:
# process first
index, value = mypq.popitem()
value = abs(value)
first.add(value)
heap_delete(mypq, index)
add_left(arr, mypq, first, index, k)
add_right(arr, mypq, first, index, k)
if arr[index][1] != -1:
arr[arr[index][1]][2] = arr[index][2]
if arr[index][2] != n:
arr[arr[index][2]][1] = arr[index][1]
chance = 1
else:
# process second
index, value = mypq.popitem()
value = abs(value)
second.add(value)
heap_delete(mypq, index)
add_left(arr, mypq, second, index, k)
add_right(arr, mypq, second, index, k)
if arr[index][1] != -1:
arr[arr[index][1]][2] = arr[index][2]
if arr[index][2] != n:
arr[arr[index][2]][1] = arr[index][1]
chance = 0
for i in arr:
element = i[0]
if element in first:
print(1, end = '')
else:
print(2, end = '')
``` | instruction | 0 | 96,168 | 17 | 192,336 |
Yes | output | 1 | 96,168 | 17 | 192,337 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n students standing in a row. Two coaches are forming two teams β the first coach chooses the first team and the second coach chooses the second team.
The i-th student has integer programming skill a_i. All programming skills are distinct and between 1 and n, inclusive.
Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and k closest students to the left of him and k closest students to the right of him (if there are less than k students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team).
Your problem is to determine which students will be taken into the first team and which students will be taken into the second team.
Input
The first line of the input contains two integers n and k (1 β€ k β€ n β€ 2 β
10^5) β the number of students and the value determining the range of chosen students during each move, respectively.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ n), where a_i is the programming skill of the i-th student. It is guaranteed that all programming skills are distinct.
Output
Print a string of n characters; i-th character should be 1 if i-th student joins the first team, or 2 otherwise.
Examples
Input
5 2
2 4 5 3 1
Output
11111
Input
5 1
2 1 3 5 4
Output
22111
Input
7 1
7 2 1 3 5 4 6
Output
1121122
Input
5 1
2 4 5 3 1
Output
21112
Note
In the first example the first coach chooses the student on a position 3, and the row becomes empty (all students join the first team).
In the second example the first coach chooses the student on position 4, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team).
In the third example the first coach chooses the student on position 1, and the row becomes [1, 3, 5, 4, 6] (students with programming skills [2, 7] join the first team). Then the second coach chooses the student on position 5, and the row becomes [1, 3, 5] (students with programming skills [4, 6] join the second team). Then the first coach chooses the student on position 3, and the row becomes [1] (students with programming skills [3, 5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 1 joins the second team).
In the fourth example the first coach chooses the student on position 3, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team).
Submitted Solution:
```
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
class Student:
know: int
team: int
lock: bool
num: int
def __init__(self, know, team, num):
self.know = know
self.team = team
self.lock = False
self.num = num
def set_team(self, team):
if not self.lock:
self.team = team
self.lock = True
def get_team(self):
return str(self.team)
c = []
for i in range(len(a)):
c.append(Student(i, 0, i))
student_count = len(a)
selected_people = []
students_sel = 0
team = 1
if k == 1:
while a:
ind = a.index(max(a))
c[ind].set_team(team)
selected_people.append(c[ind])
c.pop(ind)
a.pop(ind)
#print(a)
if team == 1:
team = 2
else:
team = 1
else:
while a:
ind = a.index(max(a))
#print(a, ind)
arr_len = len(a)
s, t = ind - k, ind + k + 1
if t > arr_len:
t = arr_len
if s < 0:
s = 0
rg = list(range(s, t))
rg.reverse()
#print(list(rg))
for i in rg:
c[i].set_team(team)
selected_people.append(c[i])
c.pop(i)
a.pop(i)
print(rg)
if team == 1:
team = 2
else:
team = 1
ans = ""
selected_people.sort(key=lambda x: x.num)
for i in selected_people:
ans += i.get_team()
# print(selected_people)
print(ans)
``` | instruction | 0 | 96,169 | 17 | 192,338 |
No | output | 1 | 96,169 | 17 | 192,339 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.