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 |
|---|---|---|---|---|---|
Provide a correct Python 3 solution for this coding contest problem.
In Group C of the 3rd year, we decided to use the "class flag" used at the sports festival on November 10, 2007 at future class reunions. So, in order to decide which students to keep the "class flag", I decided to play the following game using a large amount of candy that the teacher gave me the other day.
* Each student will take one candy in the order of student number.
* If candy remains after one round, continue to take candy in order from the person with the first student number.
* The person who picks up the last candy will be the student who keeps the "class flag".
There are 39 students in the 3rd grade C class. Their student numbers are 3C01 to 3C39. For example, if you have 50 candies and everyone in the class finishes taking the first candy, you will have 11 candies left. If you take it again in student number order, the last one will be taken by the 3C11 student. That is, the 3C11 student is the student who keeps the "class flag".
Create a program that takes the number of candies as input and outputs the student number of the student who stores the "class flag".
Input
Multiple test cases are given. Each test case is given in the following format. For each test case, an integer a (1 ≤ a ≤ 10000) representing the number of candies is given on one line. Process until the end of input (EOF).
The number of datasets does not exceed 20.
Output
For each test case, output the student number (half-width alphanumeric characters) of the student who stores the "class flag" on one line.
Example
Input
50
5576
5577
5578
Output
3C11
3C38
3C39
3C01 | instruction | 0 | 8,975 | 17 | 17,950 |
"Correct Solution:
```
while True:
try:
n = int(input())
except:
break
if n % 39 == 0:
ans = 39
else:
ans = n % 39
print("3C" + str(ans).zfill(2))
``` | output | 1 | 8,975 | 17 | 17,951 |
Provide a correct Python 3 solution for this coding contest problem.
In Group C of the 3rd year, we decided to use the "class flag" used at the sports festival on November 10, 2007 at future class reunions. So, in order to decide which students to keep the "class flag", I decided to play the following game using a large amount of candy that the teacher gave me the other day.
* Each student will take one candy in the order of student number.
* If candy remains after one round, continue to take candy in order from the person with the first student number.
* The person who picks up the last candy will be the student who keeps the "class flag".
There are 39 students in the 3rd grade C class. Their student numbers are 3C01 to 3C39. For example, if you have 50 candies and everyone in the class finishes taking the first candy, you will have 11 candies left. If you take it again in student number order, the last one will be taken by the 3C11 student. That is, the 3C11 student is the student who keeps the "class flag".
Create a program that takes the number of candies as input and outputs the student number of the student who stores the "class flag".
Input
Multiple test cases are given. Each test case is given in the following format. For each test case, an integer a (1 ≤ a ≤ 10000) representing the number of candies is given on one line. Process until the end of input (EOF).
The number of datasets does not exceed 20.
Output
For each test case, output the student number (half-width alphanumeric characters) of the student who stores the "class flag" on one line.
Example
Input
50
5576
5577
5578
Output
3C11
3C38
3C39
3C01 | instruction | 0 | 8,976 | 17 | 17,952 |
"Correct Solution:
```
while True:
try:
n = int(input().strip())
m = n % 39
if m==0:
s = "39"
else:
s = "%02d" % m
print("3C" + s)
except EOFError:
break
``` | output | 1 | 8,976 | 17 | 17,953 |
Provide a correct Python 3 solution for this coding contest problem.
In Group C of the 3rd year, we decided to use the "class flag" used at the sports festival on November 10, 2007 at future class reunions. So, in order to decide which students to keep the "class flag", I decided to play the following game using a large amount of candy that the teacher gave me the other day.
* Each student will take one candy in the order of student number.
* If candy remains after one round, continue to take candy in order from the person with the first student number.
* The person who picks up the last candy will be the student who keeps the "class flag".
There are 39 students in the 3rd grade C class. Their student numbers are 3C01 to 3C39. For example, if you have 50 candies and everyone in the class finishes taking the first candy, you will have 11 candies left. If you take it again in student number order, the last one will be taken by the 3C11 student. That is, the 3C11 student is the student who keeps the "class flag".
Create a program that takes the number of candies as input and outputs the student number of the student who stores the "class flag".
Input
Multiple test cases are given. Each test case is given in the following format. For each test case, an integer a (1 ≤ a ≤ 10000) representing the number of candies is given on one line. Process until the end of input (EOF).
The number of datasets does not exceed 20.
Output
For each test case, output the student number (half-width alphanumeric characters) of the student who stores the "class flag" on one line.
Example
Input
50
5576
5577
5578
Output
3C11
3C38
3C39
3C01 | instruction | 0 | 8,977 | 17 | 17,954 |
"Correct Solution:
```
while True:
try:
n = int(input())
except:
break
ans = n % 39
if ans == 0:
ans = "39"
else:
ans = "{0:02d}".format(ans)
print("3C"+ans)
``` | output | 1 | 8,977 | 17 | 17,955 |
Provide a correct Python 3 solution for this coding contest problem.
In Group C of the 3rd year, we decided to use the "class flag" used at the sports festival on November 10, 2007 at future class reunions. So, in order to decide which students to keep the "class flag", I decided to play the following game using a large amount of candy that the teacher gave me the other day.
* Each student will take one candy in the order of student number.
* If candy remains after one round, continue to take candy in order from the person with the first student number.
* The person who picks up the last candy will be the student who keeps the "class flag".
There are 39 students in the 3rd grade C class. Their student numbers are 3C01 to 3C39. For example, if you have 50 candies and everyone in the class finishes taking the first candy, you will have 11 candies left. If you take it again in student number order, the last one will be taken by the 3C11 student. That is, the 3C11 student is the student who keeps the "class flag".
Create a program that takes the number of candies as input and outputs the student number of the student who stores the "class flag".
Input
Multiple test cases are given. Each test case is given in the following format. For each test case, an integer a (1 ≤ a ≤ 10000) representing the number of candies is given on one line. Process until the end of input (EOF).
The number of datasets does not exceed 20.
Output
For each test case, output the student number (half-width alphanumeric characters) of the student who stores the "class flag" on one line.
Example
Input
50
5576
5577
5578
Output
3C11
3C38
3C39
3C01 | instruction | 0 | 8,978 | 17 | 17,956 |
"Correct Solution:
```
# AOJ 0148 Candy and Class Flag
# Python3 2018.6.18 bal4u
while True:
try: a = (int(input())-1) % 39 + 1
except: break
print("3C", format(a, "02d"), sep='')
``` | output | 1 | 8,978 | 17 | 17,957 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Group C of the 3rd year, we decided to use the "class flag" used at the sports festival on November 10, 2007 at future class reunions. So, in order to decide which students to keep the "class flag", I decided to play the following game using a large amount of candy that the teacher gave me the other day.
* Each student will take one candy in the order of student number.
* If candy remains after one round, continue to take candy in order from the person with the first student number.
* The person who picks up the last candy will be the student who keeps the "class flag".
There are 39 students in the 3rd grade C class. Their student numbers are 3C01 to 3C39. For example, if you have 50 candies and everyone in the class finishes taking the first candy, you will have 11 candies left. If you take it again in student number order, the last one will be taken by the 3C11 student. That is, the 3C11 student is the student who keeps the "class flag".
Create a program that takes the number of candies as input and outputs the student number of the student who stores the "class flag".
Input
Multiple test cases are given. Each test case is given in the following format. For each test case, an integer a (1 ≤ a ≤ 10000) representing the number of candies is given on one line. Process until the end of input (EOF).
The number of datasets does not exceed 20.
Output
For each test case, output the student number (half-width alphanumeric characters) of the student who stores the "class flag" on one line.
Example
Input
50
5576
5577
5578
Output
3C11
3C38
3C39
3C01
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0148
"""
import sys
from sys import stdin
input = stdin.readline
def main(args):
for line in sys.stdin:
candy = int(line)
hit = candy % 39
if hit == 0:
hit = 39
print('3C{:02d}'.format(hit))
if __name__ == '__main__':
main(sys.argv[1:])
``` | instruction | 0 | 8,979 | 17 | 17,958 |
Yes | output | 1 | 8,979 | 17 | 17,959 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Group C of the 3rd year, we decided to use the "class flag" used at the sports festival on November 10, 2007 at future class reunions. So, in order to decide which students to keep the "class flag", I decided to play the following game using a large amount of candy that the teacher gave me the other day.
* Each student will take one candy in the order of student number.
* If candy remains after one round, continue to take candy in order from the person with the first student number.
* The person who picks up the last candy will be the student who keeps the "class flag".
There are 39 students in the 3rd grade C class. Their student numbers are 3C01 to 3C39. For example, if you have 50 candies and everyone in the class finishes taking the first candy, you will have 11 candies left. If you take it again in student number order, the last one will be taken by the 3C11 student. That is, the 3C11 student is the student who keeps the "class flag".
Create a program that takes the number of candies as input and outputs the student number of the student who stores the "class flag".
Input
Multiple test cases are given. Each test case is given in the following format. For each test case, an integer a (1 ≤ a ≤ 10000) representing the number of candies is given on one line. Process until the end of input (EOF).
The number of datasets does not exceed 20.
Output
For each test case, output the student number (half-width alphanumeric characters) of the student who stores the "class flag" on one line.
Example
Input
50
5576
5577
5578
Output
3C11
3C38
3C39
3C01
Submitted Solution:
```
import sys
for i in sys.stdin:
p = int(i) % 39
if p == 0:
print("3C39")
elif p < 10:
print("3C0%d" %(p))
else:
print("3C%d" %(p))
``` | instruction | 0 | 8,980 | 17 | 17,960 |
Yes | output | 1 | 8,980 | 17 | 17,961 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Group C of the 3rd year, we decided to use the "class flag" used at the sports festival on November 10, 2007 at future class reunions. So, in order to decide which students to keep the "class flag", I decided to play the following game using a large amount of candy that the teacher gave me the other day.
* Each student will take one candy in the order of student number.
* If candy remains after one round, continue to take candy in order from the person with the first student number.
* The person who picks up the last candy will be the student who keeps the "class flag".
There are 39 students in the 3rd grade C class. Their student numbers are 3C01 to 3C39. For example, if you have 50 candies and everyone in the class finishes taking the first candy, you will have 11 candies left. If you take it again in student number order, the last one will be taken by the 3C11 student. That is, the 3C11 student is the student who keeps the "class flag".
Create a program that takes the number of candies as input and outputs the student number of the student who stores the "class flag".
Input
Multiple test cases are given. Each test case is given in the following format. For each test case, an integer a (1 ≤ a ≤ 10000) representing the number of candies is given on one line. Process until the end of input (EOF).
The number of datasets does not exceed 20.
Output
For each test case, output the student number (half-width alphanumeric characters) of the student who stores the "class flag" on one line.
Example
Input
50
5576
5577
5578
Output
3C11
3C38
3C39
3C01
Submitted Solution:
```
while True:
try:
n = int(input())
num = n % 39
if num == 0:
num = 39
if num < 10:
num = "0" + str(num)
print("3" + "C" + str(num))
except EOFError:
break
``` | instruction | 0 | 8,981 | 17 | 17,962 |
Yes | output | 1 | 8,981 | 17 | 17,963 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Group C of the 3rd year, we decided to use the "class flag" used at the sports festival on November 10, 2007 at future class reunions. So, in order to decide which students to keep the "class flag", I decided to play the following game using a large amount of candy that the teacher gave me the other day.
* Each student will take one candy in the order of student number.
* If candy remains after one round, continue to take candy in order from the person with the first student number.
* The person who picks up the last candy will be the student who keeps the "class flag".
There are 39 students in the 3rd grade C class. Their student numbers are 3C01 to 3C39. For example, if you have 50 candies and everyone in the class finishes taking the first candy, you will have 11 candies left. If you take it again in student number order, the last one will be taken by the 3C11 student. That is, the 3C11 student is the student who keeps the "class flag".
Create a program that takes the number of candies as input and outputs the student number of the student who stores the "class flag".
Input
Multiple test cases are given. Each test case is given in the following format. For each test case, an integer a (1 ≤ a ≤ 10000) representing the number of candies is given on one line. Process until the end of input (EOF).
The number of datasets does not exceed 20.
Output
For each test case, output the student number (half-width alphanumeric characters) of the student who stores the "class flag" on one line.
Example
Input
50
5576
5577
5578
Output
3C11
3C38
3C39
3C01
Submitted Solution:
```
def get_input():
while True:
try:
yield ''.join(input())
except EOFError:
break
N = list(get_input())
for l in range(len(N)):
n = int(N[l])
print("3C", end="")
ans = n % 39
if ans == 0:
print(39)
elif ans < 10:
print("0", end="")
print(ans)
else:
print(ans)
``` | instruction | 0 | 8,982 | 17 | 17,964 |
Yes | output | 1 | 8,982 | 17 | 17,965 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Group C of the 3rd year, we decided to use the "class flag" used at the sports festival on November 10, 2007 at future class reunions. So, in order to decide which students to keep the "class flag", I decided to play the following game using a large amount of candy that the teacher gave me the other day.
* Each student will take one candy in the order of student number.
* If candy remains after one round, continue to take candy in order from the person with the first student number.
* The person who picks up the last candy will be the student who keeps the "class flag".
There are 39 students in the 3rd grade C class. Their student numbers are 3C01 to 3C39. For example, if you have 50 candies and everyone in the class finishes taking the first candy, you will have 11 candies left. If you take it again in student number order, the last one will be taken by the 3C11 student. That is, the 3C11 student is the student who keeps the "class flag".
Create a program that takes the number of candies as input and outputs the student number of the student who stores the "class flag".
Input
Multiple test cases are given. Each test case is given in the following format. For each test case, an integer a (1 ≤ a ≤ 10000) representing the number of candies is given on one line. Process until the end of input (EOF).
The number of datasets does not exceed 20.
Output
For each test case, output the student number (half-width alphanumeric characters) of the student who stores the "class flag" on one line.
Example
Input
50
5576
5577
5578
Output
3C11
3C38
3C39
3C01
Submitted Solution:
```
while True:
try:
a = int(input())
except:
break
tmp = a - (a // 39) * 39
print("3C{:02d}".format(39 if tmp == 39 else tmp))
``` | instruction | 0 | 8,983 | 17 | 17,966 |
No | output | 1 | 8,983 | 17 | 17,967 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The annual college sports-ball tournament is approaching, which for trademark reasons we'll refer to as Third Month Insanity. There are a total of 2N teams participating in the tournament, numbered from 1 to 2N. The tournament lasts N rounds, with each round eliminating half the teams. The first round consists of 2N - 1 games, numbered starting from 1. In game i, team 2·i - 1 will play against team 2·i. The loser is eliminated and the winner advances to the next round (there are no ties). Each subsequent round has half as many games as the previous round, and in game i the winner of the previous round's game 2·i - 1 will play against the winner of the previous round's game 2·i.
Every year the office has a pool to see who can create the best bracket. A bracket is a set of winner predictions for every game. For games in the first round you may predict either team to win, but for games in later rounds the winner you predict must also be predicted as a winner in the previous round. Note that the bracket is fully constructed before any games are actually played. Correct predictions in the first round are worth 1 point, and correct predictions in each subsequent round are worth twice as many points as the previous, so correct predictions in the final game are worth 2N - 1 points.
For every pair of teams in the league, you have estimated the probability of each team winning if they play against each other. Now you want to construct a bracket with the maximum possible expected score.
Input
Input will begin with a line containing N (2 ≤ N ≤ 6).
2N lines follow, each with 2N integers. The j-th column of the i-th row indicates the percentage chance that team i will defeat team j, unless i = j, in which case the value will be 0. It is guaranteed that the i-th column of the j-th row plus the j-th column of the i-th row will add to exactly 100.
Output
Print the maximum possible expected score over all possible brackets. Your answer must be correct to within an absolute or relative error of 10 - 9.
Formally, let your answer be a, and the jury's answer be b. Your answer will be considered correct, if <image>.
Examples
Input
2
0 40 100 100
60 0 40 40
0 60 0 45
0 60 55 0
Output
1.75
Input
3
0 0 100 0 100 0 0 0
100 0 100 0 0 0 100 100
0 0 0 100 100 0 0 0
100 100 0 0 0 0 100 100
0 100 0 100 0 0 100 0
100 100 100 100 100 0 0 0
100 0 100 0 0 100 0 0
100 0 100 0 100 100 100 0
Output
12
Input
2
0 21 41 26
79 0 97 33
59 3 0 91
74 67 9 0
Output
3.141592
Note
In the first example, you should predict teams 1 and 4 to win in round 1, and team 1 to win in round 2. Recall that the winner you predict in round 2 must also be predicted as a winner in round 1. | instruction | 0 | 9,610 | 17 | 19,220 |
Tags: dp, probabilities, trees
Correct Solution:
```
import functools
n = int(input())
props = []
def preproc(a):
return float(a)/100.
for i in range(pow(2,n)):
props.append(list(map(preproc, input().split())))
wining_props = [] # list of lists. First index -- number of round, second -- num of team, value -- prop of wining
wining_props_first_round = []
for i in range(0, (2 ** n), 2):
# i, and i+1 teams playing
wining_prop_for_i = props[i][i + 1]
wining_props_first_round.append(wining_prop_for_i)
wining_props_first_round.append(1. - wining_prop_for_i)
wining_props.append(wining_props_first_round)
assert len(wining_props_first_round) == len(props)
for round_num in range(2, n + 1):
# calculate propabilitys for winning in i round for each team
# prop of winning in i round = prop of winning prev round + mo of win this one
# mo win this = for each team we can meet prop of them wining prev * prop we win them
# each team we can meet on round i = all teems // 2^i == we//2^i
this_round_wining_props = []
for team_num in range(2 ** n):
t = team_num // (2 ** round_num) * (2 ** (round_num))
teams_we_meet_this_round = [t + x for x in range(2 ** round_num)]
t = team_num // (2 ** (round_num-1)) * (2 ** (round_num-1))
teams_we_meet_prev_round = [t + x for x in range(2 ** (round_num-1))]
for tt in teams_we_meet_prev_round:
teams_we_meet_this_round.remove(tt)
this_team_wining_props = wining_props[round_num - 2][team_num] # -2 cause numeration
chances_win_i_team = []
for tm in teams_we_meet_this_round:
# chances we meet them * chances we win
chances_win_i_team.append(wining_props[round_num - 2][tm] * props[team_num][tm])
mo_win_this_round = sum(chances_win_i_team)
this_team_wining_props *= mo_win_this_round
this_round_wining_props.append(this_team_wining_props)
#assert 0.99 < sum(this_round_wining_props) < 1.01
wining_props.append(this_round_wining_props)
# now we got props of each win on each round. Lets bet on most propable winer and calculate revenue
#from left to right-1 is playing
@functools.lru_cache(maxsize=None)
def revenue(round_num, teams_left, teams_right, winner=-1):
split = ((teams_left + teams_right) // 2)
# let the strongest team win, we bet, and calculate to the bottom
if round_num == 1:
return wining_props[0][winner] if winner != -1 else max(wining_props[0][teams_left:teams_right])
if winner == -1:
results = []
for winner in range(teams_left, teams_right):
winner_prop = wining_props[round_num - 1][winner]
if winner >= split:
res = sum(
[revenue(round_num - 1, teams_left, split), revenue(round_num - 1, split, teams_right, winner),
winner_prop * (2 ** (round_num - 1))])
else:
res = sum(
[revenue(round_num - 1, teams_left, split, winner), revenue(round_num - 1, split, teams_right),
winner_prop * (2 ** (round_num - 1))])
results.append(res)
return max(results)
else:
winner_prop = wining_props[round_num - 1][winner]
if winner >= split:
res = sum(
[revenue(round_num - 1, teams_left, split), revenue(round_num - 1, split, teams_right, winner),
winner_prop * (2 ** (round_num - 1))])
else:
res = sum(
[revenue(round_num - 1, teams_left, split, winner), revenue(round_num - 1, split, teams_right),
winner_prop * (2 ** (round_num - 1))])
return res
print(revenue(n, 0, (2 ** n)))
``` | output | 1 | 9,610 | 17 | 19,221 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The annual college sports-ball tournament is approaching, which for trademark reasons we'll refer to as Third Month Insanity. There are a total of 2N teams participating in the tournament, numbered from 1 to 2N. The tournament lasts N rounds, with each round eliminating half the teams. The first round consists of 2N - 1 games, numbered starting from 1. In game i, team 2·i - 1 will play against team 2·i. The loser is eliminated and the winner advances to the next round (there are no ties). Each subsequent round has half as many games as the previous round, and in game i the winner of the previous round's game 2·i - 1 will play against the winner of the previous round's game 2·i.
Every year the office has a pool to see who can create the best bracket. A bracket is a set of winner predictions for every game. For games in the first round you may predict either team to win, but for games in later rounds the winner you predict must also be predicted as a winner in the previous round. Note that the bracket is fully constructed before any games are actually played. Correct predictions in the first round are worth 1 point, and correct predictions in each subsequent round are worth twice as many points as the previous, so correct predictions in the final game are worth 2N - 1 points.
For every pair of teams in the league, you have estimated the probability of each team winning if they play against each other. Now you want to construct a bracket with the maximum possible expected score.
Input
Input will begin with a line containing N (2 ≤ N ≤ 6).
2N lines follow, each with 2N integers. The j-th column of the i-th row indicates the percentage chance that team i will defeat team j, unless i = j, in which case the value will be 0. It is guaranteed that the i-th column of the j-th row plus the j-th column of the i-th row will add to exactly 100.
Output
Print the maximum possible expected score over all possible brackets. Your answer must be correct to within an absolute or relative error of 10 - 9.
Formally, let your answer be a, and the jury's answer be b. Your answer will be considered correct, if <image>.
Examples
Input
2
0 40 100 100
60 0 40 40
0 60 0 45
0 60 55 0
Output
1.75
Input
3
0 0 100 0 100 0 0 0
100 0 100 0 0 0 100 100
0 0 0 100 100 0 0 0
100 100 0 0 0 0 100 100
0 100 0 100 0 0 100 0
100 100 100 100 100 0 0 0
100 0 100 0 0 100 0 0
100 0 100 0 100 100 100 0
Output
12
Input
2
0 21 41 26
79 0 97 33
59 3 0 91
74 67 9 0
Output
3.141592
Note
In the first example, you should predict teams 1 and 4 to win in round 1, and team 1 to win in round 2. Recall that the winner you predict in round 2 must also be predicted as a winner in round 1. | instruction | 0 | 9,611 | 17 | 19,222 |
Tags: dp, probabilities, trees
Correct Solution:
```
n = int(input())
# Using the same index I would for a tree
m = 2**n
points = [0]*(2*m)
points[1] = 2**(n-1)
for i in range(1,m):
x = points[i]//2
points[2*i] = x
points[2*i+1] = x
P = [[int(x)/100.0 for x in input().split()] for _ in range(m)]
state = [[0.0]*64 for _ in range(2*m)]
for i in range(m):
state[m+i][i] = 1.0
for i in reversed(range(1,m)):
for j in range(m):
for k in range(j+1,m):
# x is probability that team j meets team k in match i
x = state[2*i][j]*state[2*i+1][k]
state[i][j] += P[j][k]*x
state[i][k] += P[k][j]*x
score = [[0]*64 for _ in range(2*m)]
for i in reversed(range(1,m)):
for j in range(m):
for k in range(m):
score[i][j] = max(score[i][j], score[2*i][j]+state[i][j]*points[i] + score[2*i+1][k])
score[i][j] = max(score[i][j], score[2*i+1][j]+state[i][j]*points[i] + score[2*i][k])
print(repr(max(score[1])))
``` | output | 1 | 9,611 | 17 | 19,223 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The annual college sports-ball tournament is approaching, which for trademark reasons we'll refer to as Third Month Insanity. There are a total of 2N teams participating in the tournament, numbered from 1 to 2N. The tournament lasts N rounds, with each round eliminating half the teams. The first round consists of 2N - 1 games, numbered starting from 1. In game i, team 2·i - 1 will play against team 2·i. The loser is eliminated and the winner advances to the next round (there are no ties). Each subsequent round has half as many games as the previous round, and in game i the winner of the previous round's game 2·i - 1 will play against the winner of the previous round's game 2·i.
Every year the office has a pool to see who can create the best bracket. A bracket is a set of winner predictions for every game. For games in the first round you may predict either team to win, but for games in later rounds the winner you predict must also be predicted as a winner in the previous round. Note that the bracket is fully constructed before any games are actually played. Correct predictions in the first round are worth 1 point, and correct predictions in each subsequent round are worth twice as many points as the previous, so correct predictions in the final game are worth 2N - 1 points.
For every pair of teams in the league, you have estimated the probability of each team winning if they play against each other. Now you want to construct a bracket with the maximum possible expected score.
Input
Input will begin with a line containing N (2 ≤ N ≤ 6).
2N lines follow, each with 2N integers. The j-th column of the i-th row indicates the percentage chance that team i will defeat team j, unless i = j, in which case the value will be 0. It is guaranteed that the i-th column of the j-th row plus the j-th column of the i-th row will add to exactly 100.
Output
Print the maximum possible expected score over all possible brackets. Your answer must be correct to within an absolute or relative error of 10 - 9.
Formally, let your answer be a, and the jury's answer be b. Your answer will be considered correct, if <image>.
Examples
Input
2
0 40 100 100
60 0 40 40
0 60 0 45
0 60 55 0
Output
1.75
Input
3
0 0 100 0 100 0 0 0
100 0 100 0 0 0 100 100
0 0 0 100 100 0 0 0
100 100 0 0 0 0 100 100
0 100 0 100 0 0 100 0
100 100 100 100 100 0 0 0
100 0 100 0 0 100 0 0
100 0 100 0 100 100 100 0
Output
12
Input
2
0 21 41 26
79 0 97 33
59 3 0 91
74 67 9 0
Output
3.141592
Note
In the first example, you should predict teams 1 and 4 to win in round 1, and team 1 to win in round 2. Recall that the winner you predict in round 2 must also be predicted as a winner in round 1. | instruction | 0 | 9,612 | 17 | 19,224 |
Tags: dp, probabilities, trees
Correct Solution:
```
n = int(input())
m = 1 << n
p = [list(map(int, input().split())) for i in range(m)]
u, x = [1] * m, [0] * m
v, y = u[:], x[:]
for i in range(n):
d = 1 << i
for j in range(m):
s = d * (j // d ^ 1)
v[j] = u[j] * sum(u[k] * p[j][k] for k in range(s, s + d)) / 100
y[j] = max(x[s: s + d]) + x[j] + v[j] * d
u, v, x, y = v, u, y, x
print(max(x))
``` | output | 1 | 9,612 | 17 | 19,225 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The annual college sports-ball tournament is approaching, which for trademark reasons we'll refer to as Third Month Insanity. There are a total of 2N teams participating in the tournament, numbered from 1 to 2N. The tournament lasts N rounds, with each round eliminating half the teams. The first round consists of 2N - 1 games, numbered starting from 1. In game i, team 2·i - 1 will play against team 2·i. The loser is eliminated and the winner advances to the next round (there are no ties). Each subsequent round has half as many games as the previous round, and in game i the winner of the previous round's game 2·i - 1 will play against the winner of the previous round's game 2·i.
Every year the office has a pool to see who can create the best bracket. A bracket is a set of winner predictions for every game. For games in the first round you may predict either team to win, but for games in later rounds the winner you predict must also be predicted as a winner in the previous round. Note that the bracket is fully constructed before any games are actually played. Correct predictions in the first round are worth 1 point, and correct predictions in each subsequent round are worth twice as many points as the previous, so correct predictions in the final game are worth 2N - 1 points.
For every pair of teams in the league, you have estimated the probability of each team winning if they play against each other. Now you want to construct a bracket with the maximum possible expected score.
Input
Input will begin with a line containing N (2 ≤ N ≤ 6).
2N lines follow, each with 2N integers. The j-th column of the i-th row indicates the percentage chance that team i will defeat team j, unless i = j, in which case the value will be 0. It is guaranteed that the i-th column of the j-th row plus the j-th column of the i-th row will add to exactly 100.
Output
Print the maximum possible expected score over all possible brackets. Your answer must be correct to within an absolute or relative error of 10 - 9.
Formally, let your answer be a, and the jury's answer be b. Your answer will be considered correct, if <image>.
Examples
Input
2
0 40 100 100
60 0 40 40
0 60 0 45
0 60 55 0
Output
1.75
Input
3
0 0 100 0 100 0 0 0
100 0 100 0 0 0 100 100
0 0 0 100 100 0 0 0
100 100 0 0 0 0 100 100
0 100 0 100 0 0 100 0
100 100 100 100 100 0 0 0
100 0 100 0 0 100 0 0
100 0 100 0 100 100 100 0
Output
12
Input
2
0 21 41 26
79 0 97 33
59 3 0 91
74 67 9 0
Output
3.141592
Note
In the first example, you should predict teams 1 and 4 to win in round 1, and team 1 to win in round 2. Recall that the winner you predict in round 2 must also be predicted as a winner in round 1.
Submitted Solution:
```
n = int(input())
props = []
def preproc(a):
return float(a)/100.
for i in range(pow(2,n)):
props.append(list(map(preproc, input().split())))
wining_props = [] # list of lists. First index -- number of round, second -- num of team, value -- prop of wining
wining_props_first_round = []
for i in range(0, (2 ** n), 2):
# i, and i+1 teams playing
wining_prop_for_i = props[i][i + 1]
wining_props_first_round.append(wining_prop_for_i)
wining_props_first_round.append(1. - wining_prop_for_i)
wining_props.append(wining_props_first_round)
assert len(wining_props_first_round) == len(props)
for round_num in range(2, n + 1):
# calculate propabilitys for winning in i round for each team
# prop of winning in i round = prop of winning prev round + mo of win this one
# mo win this = for each team we can meet prop of them wining prev * prop we win them
# each team we can meet on round i = all teems // 2^i == we//2^i
this_round_wining_props = []
for team_num in range(2 ** n):
t = team_num // (2 ** round_num) * (2 ** (round_num))
teams_we_meet_this_round = [t + x for x in range(2 ** round_num)]
t = team_num // (2 ** (round_num-1)) * (2 ** (round_num-1))
teams_we_meet_prev_round = [t + x for x in range(2 ** (round_num-1))]
for tt in teams_we_meet_prev_round:
teams_we_meet_this_round.remove(tt)
this_team_wining_props = wining_props[round_num - 2][team_num] # -2 cause numeration
chances_win_i_team = []
for tm in teams_we_meet_this_round:
# chances we meet them * chances we win
chances_win_i_team.append(wining_props[round_num - 2][tm] * props[team_num][tm])
mo_win_this_round = sum(chances_win_i_team)
this_team_wining_props *= mo_win_this_round
this_round_wining_props.append(this_team_wining_props)
#assert 0.99 < sum(this_round_wining_props) < 1.01
wining_props.append(this_round_wining_props)
# now we got props of each win on each round. Lets bet on most propable winer and calculate revenue
#from left to right-1 is playing
def revenue(round_num, teams_left, teams_right, winner=-1):
# let the strongest team win, we bet, and calculate to the bottom
if round_num == 1:
return wining_props[0][winner] if winner != -1 else max(wining_props[0][teams_left:teams_right])
if winner == -1:
winner_prop = max(wining_props[round_num-1][teams_left:teams_right])
winner = wining_props[round_num - 1].index(winner_prop)
else:
winner_prop = wining_props[round_num-1][winner]
split = ((teams_left + teams_right) // 2)
if winner >= split:
return sum([revenue(round_num - 1, teams_left, split), revenue(round_num - 1, split, teams_right, winner),
winner_prop * (2 ** (round_num - 1))])
else:
return sum([revenue(round_num - 1, teams_left, split, winner), revenue(round_num - 1, split, teams_right),
winner_prop * (2 ** (round_num - 1))])
print(revenue(n, 0, (2 ** n)))
``` | instruction | 0 | 9,613 | 17 | 19,226 |
No | output | 1 | 9,613 | 17 | 19,227 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The annual college sports-ball tournament is approaching, which for trademark reasons we'll refer to as Third Month Insanity. There are a total of 2N teams participating in the tournament, numbered from 1 to 2N. The tournament lasts N rounds, with each round eliminating half the teams. The first round consists of 2N - 1 games, numbered starting from 1. In game i, team 2·i - 1 will play against team 2·i. The loser is eliminated and the winner advances to the next round (there are no ties). Each subsequent round has half as many games as the previous round, and in game i the winner of the previous round's game 2·i - 1 will play against the winner of the previous round's game 2·i.
Every year the office has a pool to see who can create the best bracket. A bracket is a set of winner predictions for every game. For games in the first round you may predict either team to win, but for games in later rounds the winner you predict must also be predicted as a winner in the previous round. Note that the bracket is fully constructed before any games are actually played. Correct predictions in the first round are worth 1 point, and correct predictions in each subsequent round are worth twice as many points as the previous, so correct predictions in the final game are worth 2N - 1 points.
For every pair of teams in the league, you have estimated the probability of each team winning if they play against each other. Now you want to construct a bracket with the maximum possible expected score.
Input
Input will begin with a line containing N (2 ≤ N ≤ 6).
2N lines follow, each with 2N integers. The j-th column of the i-th row indicates the percentage chance that team i will defeat team j, unless i = j, in which case the value will be 0. It is guaranteed that the i-th column of the j-th row plus the j-th column of the i-th row will add to exactly 100.
Output
Print the maximum possible expected score over all possible brackets. Your answer must be correct to within an absolute or relative error of 10 - 9.
Formally, let your answer be a, and the jury's answer be b. Your answer will be considered correct, if <image>.
Examples
Input
2
0 40 100 100
60 0 40 40
0 60 0 45
0 60 55 0
Output
1.75
Input
3
0 0 100 0 100 0 0 0
100 0 100 0 0 0 100 100
0 0 0 100 100 0 0 0
100 100 0 0 0 0 100 100
0 100 0 100 0 0 100 0
100 100 100 100 100 0 0 0
100 0 100 0 0 100 0 0
100 0 100 0 100 100 100 0
Output
12
Input
2
0 21 41 26
79 0 97 33
59 3 0 91
74 67 9 0
Output
3.141592
Note
In the first example, you should predict teams 1 and 4 to win in round 1, and team 1 to win in round 2. Recall that the winner you predict in round 2 must also be predicted as a winner in round 1.
Submitted Solution:
```
n = int(input())
# Using the same index I would for a tree
m = 2**n
P = [[int(x)/100.0 for x in input().split()] for _ in range(m)]
state = [[0.0]*64 for _ in range(2*m)]
for i in range(m):
state[m+i][i] = 1.0
for i in reversed(range(1,m)):
for j in range(m):
for k in range(j,m):
# x is probability that team j meets team k in match i
x = state[2*i][j]*state[2*i+1][k]
state[i][j] += P[j][k]*x
state[i][k] += P[k][j]*x
winner = [-1]*(2*m)
winner[1] = max(range(m),key = lambda j: state[1][j])
for i in range(2,m):
if state[i][winner[i//2]]>0:
winner[i] = winner[i//2]
else:
winner[i] = max(range(m),key = lambda j: state[i][j])
points = [0]*(2*m)
points[1] = 2**(n-1)
for i in range(1,m):
x = points[i]//2
points[2*i] = x
points[2*i+1] = x
score = 0.0
score_fix = 0.0
for i in range(1,m):
x = points[i]*state[i][winner[i]]
y = x - score_fix
t = score + y
score_fix = (t - score) - y
score = t
print(repr(score))
``` | instruction | 0 | 9,614 | 17 | 19,228 |
No | output | 1 | 9,614 | 17 | 19,229 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The annual college sports-ball tournament is approaching, which for trademark reasons we'll refer to as Third Month Insanity. There are a total of 2N teams participating in the tournament, numbered from 1 to 2N. The tournament lasts N rounds, with each round eliminating half the teams. The first round consists of 2N - 1 games, numbered starting from 1. In game i, team 2·i - 1 will play against team 2·i. The loser is eliminated and the winner advances to the next round (there are no ties). Each subsequent round has half as many games as the previous round, and in game i the winner of the previous round's game 2·i - 1 will play against the winner of the previous round's game 2·i.
Every year the office has a pool to see who can create the best bracket. A bracket is a set of winner predictions for every game. For games in the first round you may predict either team to win, but for games in later rounds the winner you predict must also be predicted as a winner in the previous round. Note that the bracket is fully constructed before any games are actually played. Correct predictions in the first round are worth 1 point, and correct predictions in each subsequent round are worth twice as many points as the previous, so correct predictions in the final game are worth 2N - 1 points.
For every pair of teams in the league, you have estimated the probability of each team winning if they play against each other. Now you want to construct a bracket with the maximum possible expected score.
Input
Input will begin with a line containing N (2 ≤ N ≤ 6).
2N lines follow, each with 2N integers. The j-th column of the i-th row indicates the percentage chance that team i will defeat team j, unless i = j, in which case the value will be 0. It is guaranteed that the i-th column of the j-th row plus the j-th column of the i-th row will add to exactly 100.
Output
Print the maximum possible expected score over all possible brackets. Your answer must be correct to within an absolute or relative error of 10 - 9.
Formally, let your answer be a, and the jury's answer be b. Your answer will be considered correct, if <image>.
Examples
Input
2
0 40 100 100
60 0 40 40
0 60 0 45
0 60 55 0
Output
1.75
Input
3
0 0 100 0 100 0 0 0
100 0 100 0 0 0 100 100
0 0 0 100 100 0 0 0
100 100 0 0 0 0 100 100
0 100 0 100 0 0 100 0
100 100 100 100 100 0 0 0
100 0 100 0 0 100 0 0
100 0 100 0 100 100 100 0
Output
12
Input
2
0 21 41 26
79 0 97 33
59 3 0 91
74 67 9 0
Output
3.141592
Note
In the first example, you should predict teams 1 and 4 to win in round 1, and team 1 to win in round 2. Recall that the winner you predict in round 2 must also be predicted as a winner in round 1.
Submitted Solution:
```
n = int(input())
# Using the same index I would for a tree
m = 2**n
P = [[int(x)/100.0 for x in input().split()] for _ in range(m)]
state = [[0.0]*64 for _ in range(2*m)]
for i in range(m):
state[m+i][i] = 1.0
for i in reversed(range(1,m)):
for j in range(m):
for k in range(j,m):
# x is probability that team j meets team k in match i
x = state[2*i][j]*state[2*i+1][k]
state[i][j] += P[j][k]*x
state[i][k] += P[k][j]*x
winner = [-1]*(2*m)
winner[1] = max(range(m),key = lambda j: state[1][j])
for i in range(2,m):
if state[i][winner[i//2]]>0:
winner[i] = winner[i//2]
else:
winner[i] = max(range(m),key = lambda j: state[i][j])
points = [0]*(2*m)
points[1] = 2**(n-1)
for i in range(1,m):
x = points[i]//2
points[2*i] = x
points[2*i+1] = x
score = 0.0
for i in range(1,m):
score += points[i]*state[i][winner[i]]
print(repr(score))
``` | instruction | 0 | 9,615 | 17 | 19,230 |
No | output | 1 | 9,615 | 17 | 19,231 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice is a big fan of volleyball and especially of the very strong "Team A".
Volleyball match consists of up to five sets. During each set teams score one point for winning a ball. The first four sets are played until one of the teams scores at least 25 points and the fifth set is played until one of the teams scores at least 15 points. Moreover, if one of the teams scores 25 (or 15 in the fifth set) points while the other team scores 24 (or 14 in the fifth set), the set is played until the absolute difference between teams' points becomes two. The match ends when one of the teams wins three sets. The match score is the number of sets won by each team.
Alice found a book containing all the results of all matches played by "Team A". The book is old, and some parts of the book became unreadable. Alice can not read the information on how many sets each of the teams won, she can not read the information on how many points each of the teams scored in each set, she even does not know the number of sets played in a match. The only information she has is the total number of points scored by each of the teams in all the sets during a single match.
Alice wonders what is the best match score "Team A" could achieve in each of the matches. The bigger is the difference between the number of sets won by "Team A" and their opponent, the better is the match score. Find the best match score or conclude that no match could end like that. If there is a solution, then find any possible score for each set that results in the best match score.
Input
The first line contains a single integer m (1 ≤ m ≤ 50 000) — the number of matches found by Alice in the book.
Each of the next m lines contains two integers a and b (0 ≤ a, b ≤ 200) — the number of points scored by "Team A" and the number of points scored by their opponents respectively.
Output
Output the solution for every match in the same order as they are given in the input. If the teams could not score a and b points respectively, output "Impossible".
Otherwise, output the match score formatted as "x:y", where x is the number of sets won by "Team A" and y is the number of sets won by their opponent.
The next line should contain the set scores in the order they were played. Each set score should be printed in the same format as the match score, with x being the number of points scored by "Team A" in this set, and y being the number of points scored by their opponent.
Example
Input
6
75 0
90 90
20 0
0 75
78 50
80 100
Output
3:0
25:0 25:0 25:0
3:1
25:22 25:22 15:25 25:21
Impossible
0:3
0:25 0:25 0:25
3:0
25:11 28:26 25:13
3:2
25:17 0:25 25:22 15:25 15:11
Submitted Solution:
```
n = int(input())
for i in range(n):
t = list(map(int , input().split()))
x, y = max(t[0], t[1]), min(t[0], t[1])
if x < 75:
print('Impossible')
elif x-y <= 6:
a = (y-25-(x-52))//2
b = (y-25-(x-52))-(y-25-(x-52))//2
print('3:1\n'+str(x-50)+':'+str(x-52)+' 25:'+str(a)+' 25:'+str(b)+' 0:25')
elif x-y <= 52:
a = (y-(x-52))//2
b = (y-(x-52))-(y-(x-52))//2
print('3:0\n'+str(x-50)+':'+str(x-52)+' 25:'+str(a)+' 25:'+str(b))
elif x == 75:
print('3:0\n'+'25:'+str(y)+' 25:0 25:0')
else:
print('Impossible')
``` | instruction | 0 | 9,950 | 17 | 19,900 |
No | output | 1 | 9,950 | 17 | 19,901 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice is a big fan of volleyball and especially of the very strong "Team A".
Volleyball match consists of up to five sets. During each set teams score one point for winning a ball. The first four sets are played until one of the teams scores at least 25 points and the fifth set is played until one of the teams scores at least 15 points. Moreover, if one of the teams scores 25 (or 15 in the fifth set) points while the other team scores 24 (or 14 in the fifth set), the set is played until the absolute difference between teams' points becomes two. The match ends when one of the teams wins three sets. The match score is the number of sets won by each team.
Alice found a book containing all the results of all matches played by "Team A". The book is old, and some parts of the book became unreadable. Alice can not read the information on how many sets each of the teams won, she can not read the information on how many points each of the teams scored in each set, she even does not know the number of sets played in a match. The only information she has is the total number of points scored by each of the teams in all the sets during a single match.
Alice wonders what is the best match score "Team A" could achieve in each of the matches. The bigger is the difference between the number of sets won by "Team A" and their opponent, the better is the match score. Find the best match score or conclude that no match could end like that. If there is a solution, then find any possible score for each set that results in the best match score.
Input
The first line contains a single integer m (1 ≤ m ≤ 50 000) — the number of matches found by Alice in the book.
Each of the next m lines contains two integers a and b (0 ≤ a, b ≤ 200) — the number of points scored by "Team A" and the number of points scored by their opponents respectively.
Output
Output the solution for every match in the same order as they are given in the input. If the teams could not score a and b points respectively, output "Impossible".
Otherwise, output the match score formatted as "x:y", where x is the number of sets won by "Team A" and y is the number of sets won by their opponent.
The next line should contain the set scores in the order they were played. Each set score should be printed in the same format as the match score, with x being the number of points scored by "Team A" in this set, and y being the number of points scored by their opponent.
Example
Input
6
75 0
90 90
20 0
0 75
78 50
80 100
Output
3:0
25:0 25:0 25:0
3:1
25:22 25:22 15:25 25:21
Impossible
0:3
0:25 0:25 0:25
3:0
25:11 28:26 25:13
3:2
25:17 0:25 25:22 15:25 15:11
Submitted Solution:
```
def cc(x, y, bl, en):
if not bl:
print(str(x) + ':' + str(y), end=en)
else:
print(str(y) + ':' + str(x), end=en)
for _ in range(int(input())):
x, y = map(int, input().split())
bl = x < y
if bl:
x, y = y, x
if x < 75:
print('Impossible')
continue
else:
a = b = 0
if x == 75:
cc(3, 0, bl, '\n')
else:
a = x % 75
b = a + 2 if a > 23 else 25
if b > y:
print('Impossible')
continue
cc(3, 1, bl, '\n')
cc(a, b, bl, ' ')
x -= a
y -= b
c = y // 3
d = y % 3
cc(25, c + (1 if d > 0 else 0), bl, ' ')
if d > 0: d -= 1
cc(25, c + (1 if d > 0 else 0), bl, ' ')
if d > 0: d -= 1
cc(25, c + (1 if d > 0 else 0), bl, ' ')
if d > 0: d -= 1
print()
``` | instruction | 0 | 9,951 | 17 | 19,902 |
No | output | 1 | 9,951 | 17 | 19,903 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice is a big fan of volleyball and especially of the very strong "Team A".
Volleyball match consists of up to five sets. During each set teams score one point for winning a ball. The first four sets are played until one of the teams scores at least 25 points and the fifth set is played until one of the teams scores at least 15 points. Moreover, if one of the teams scores 25 (or 15 in the fifth set) points while the other team scores 24 (or 14 in the fifth set), the set is played until the absolute difference between teams' points becomes two. The match ends when one of the teams wins three sets. The match score is the number of sets won by each team.
Alice found a book containing all the results of all matches played by "Team A". The book is old, and some parts of the book became unreadable. Alice can not read the information on how many sets each of the teams won, she can not read the information on how many points each of the teams scored in each set, she even does not know the number of sets played in a match. The only information she has is the total number of points scored by each of the teams in all the sets during a single match.
Alice wonders what is the best match score "Team A" could achieve in each of the matches. The bigger is the difference between the number of sets won by "Team A" and their opponent, the better is the match score. Find the best match score or conclude that no match could end like that. If there is a solution, then find any possible score for each set that results in the best match score.
Input
The first line contains a single integer m (1 ≤ m ≤ 50 000) — the number of matches found by Alice in the book.
Each of the next m lines contains two integers a and b (0 ≤ a, b ≤ 200) — the number of points scored by "Team A" and the number of points scored by their opponents respectively.
Output
Output the solution for every match in the same order as they are given in the input. If the teams could not score a and b points respectively, output "Impossible".
Otherwise, output the match score formatted as "x:y", where x is the number of sets won by "Team A" and y is the number of sets won by their opponent.
The next line should contain the set scores in the order they were played. Each set score should be printed in the same format as the match score, with x being the number of points scored by "Team A" in this set, and y being the number of points scored by their opponent.
Example
Input
6
75 0
90 90
20 0
0 75
78 50
80 100
Output
3:0
25:0 25:0 25:0
3:1
25:22 25:22 15:25 25:21
Impossible
0:3
0:25 0:25 0:25
3:0
25:11 28:26 25:13
3:2
25:17 0:25 25:22 15:25 15:11
Submitted Solution:
```
def pro(x, y):
lis = []
if x < 75:
return []
elif x-y <= 6:
a = (y-25-(x-52))//2
b = (y-25-(x-52))-(y-25-(x-52))//2
lis = [3,1,0,25,x-50,x-52,25,a,25,b]
elif x-y <= 52:
a = (y-(x-52))//2
b = (y-(x-52))-(y-(x-52))//2
lis = [3,0,x-50,x-52,25,a,25,b]
elif x == 75:
lis = [3,0,25,y,25,0,25,0]
else:
return []
return lis
def c(x, y, lis):
if (x>=y):
return lis
else:
for i in range(0, len(lis), 2):
lis[i], lis[i+1] = lis[i+1], lis[i]
return lis
n = int(input())
for i in range(n):
t = list(map(int , input().split()))
x, y = t[0], t[1]
if pro(max(x,y), min(x,y)) == []:
print('Impossible')
else:
lis = c(x, y, pro(max(x,y), min(x,y)))
if len(lis) == 10:
a1,a2,a3,a4,a5,a6,a7,a8,a9,a10 = list(map(str, lis))
print(a1+':'+a2+'\n'+a3+':'+a4+' '+a5+':'+a6+' '+a7+':'+a8+' '+a9+':'+a10)
else:
a1,a2,a3,a4,a5,a6,a7,a8 = list(map(str, lis))
print(a1+':'+a2+'\n'+a3+':'+a4+' '+a5+':'+a6+' '+a7+':'+a8)
``` | instruction | 0 | 9,952 | 17 | 19,904 |
No | output | 1 | 9,952 | 17 | 19,905 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice is a big fan of volleyball and especially of the very strong "Team A".
Volleyball match consists of up to five sets. During each set teams score one point for winning a ball. The first four sets are played until one of the teams scores at least 25 points and the fifth set is played until one of the teams scores at least 15 points. Moreover, if one of the teams scores 25 (or 15 in the fifth set) points while the other team scores 24 (or 14 in the fifth set), the set is played until the absolute difference between teams' points becomes two. The match ends when one of the teams wins three sets. The match score is the number of sets won by each team.
Alice found a book containing all the results of all matches played by "Team A". The book is old, and some parts of the book became unreadable. Alice can not read the information on how many sets each of the teams won, she can not read the information on how many points each of the teams scored in each set, she even does not know the number of sets played in a match. The only information she has is the total number of points scored by each of the teams in all the sets during a single match.
Alice wonders what is the best match score "Team A" could achieve in each of the matches. The bigger is the difference between the number of sets won by "Team A" and their opponent, the better is the match score. Find the best match score or conclude that no match could end like that. If there is a solution, then find any possible score for each set that results in the best match score.
Input
The first line contains a single integer m (1 ≤ m ≤ 50 000) — the number of matches found by Alice in the book.
Each of the next m lines contains two integers a and b (0 ≤ a, b ≤ 200) — the number of points scored by "Team A" and the number of points scored by their opponents respectively.
Output
Output the solution for every match in the same order as they are given in the input. If the teams could not score a and b points respectively, output "Impossible".
Otherwise, output the match score formatted as "x:y", where x is the number of sets won by "Team A" and y is the number of sets won by their opponent.
The next line should contain the set scores in the order they were played. Each set score should be printed in the same format as the match score, with x being the number of points scored by "Team A" in this set, and y being the number of points scored by their opponent.
Example
Input
6
75 0
90 90
20 0
0 75
78 50
80 100
Output
3:0
25:0 25:0 25:0
3:1
25:22 25:22 15:25 25:21
Impossible
0:3
0:25 0:25 0:25
3:0
25:11 28:26 25:13
3:2
25:17 0:25 25:22 15:25 15:11
Submitted Solution:
```
n = int(input())
for i in range(n):
t = list(map(int , input().split()))
x, y = max(t[0], t[1]), min(t[0], t[1])
if x < 75:
print('Impossible')
elif x-y <= 6:
a = (y-25-(x-52))//2
b = (y-25-(x-52))-(y-25-(x-52))//2
print('3:1\n'+'0:25 '+str(x-50)+':'+str(x-52)+' 25:'+str(a)+' 25:'+str(b))
elif x-y <= 52:
a = (y-(x-52))//2
b = (y-(x-52))-(y-(x-52))//2
print('3:0\n'+str(x-50)+':'+str(x-52)+' 25:'+str(a)+' 25:'+str(b))
elif x == 75:
print('3:0\n'+'25:'+str(y)+' 25:0 25:0')
else:
print('Impossible')
``` | instruction | 0 | 9,953 | 17 | 19,906 |
No | output | 1 | 9,953 | 17 | 19,907 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Smart Beaver decided to be not only smart, but also a healthy beaver! And so he began to attend physical education classes at school X. In this school, physical education has a very creative teacher. One of his favorite warm-up exercises is throwing balls. Students line up. Each one gets a single ball in the beginning. The balls are numbered from 1 to n (by the demand of the inventory commission).
<image> Figure 1. The initial position for n = 5.
After receiving the balls the students perform the warm-up exercise. The exercise takes place in a few throws. For each throw the teacher chooses any two arbitrary different students who will participate in it. The selected students throw their balls to each other. Thus, after each throw the students remain in their positions, and the two balls are swapped.
<image> Figure 2. The example of a throw.
In this case there was a throw between the students, who were holding the 2-nd and the 4-th balls. Since the warm-up has many exercises, each of them can only continue for little time. Therefore, for each student we know the maximum number of throws he can participate in. For this lessons maximum number of throws will be 1 or 2.
Note that after all phases of the considered exercise any ball can end up with any student. Smart Beaver decided to formalize it and introduced the concept of the "ball order". The ball order is a sequence of n numbers that correspond to the order of balls in the line. The first number will match the number of the ball of the first from the left student in the line, the second number will match the ball of the second student, and so on. For example, in figure 2 the order of the balls was (1, 2, 3, 4, 5), and after the throw it was (1, 4, 3, 2, 5). Smart beaver knows the number of students and for each student he knows the maximum number of throws in which he can participate. And now he is wondering: what is the number of distinct ways of ball orders by the end of the exercise.
Input
The first line contains a single number n — the number of students in the line and the number of balls. The next line contains exactly n space-separated integers. Each number corresponds to a student in the line (the i-th number corresponds to the i-th from the left student in the line) and shows the number of throws he can participate in.
The input limits for scoring 30 points are (subproblem D1):
* 1 ≤ n ≤ 10.
The input limits for scoring 70 points are (subproblems D1+D2):
* 1 ≤ n ≤ 500.
The input limits for scoring 100 points are (subproblems D1+D2+D3):
* 1 ≤ n ≤ 1000000.
Output
The output should contain a single integer — the number of variants of ball orders after the warm up exercise is complete. As the number can be rather large, print it modulo 1000000007 (109 + 7).
Examples
Input
5
1 2 2 1 2
Output
120
Input
8
1 2 2 1 2 1 1 2
Output
16800 | instruction | 0 | 10,292 | 17 | 20,584 |
Tags: brute force, dp
Correct Solution:
```
m = 1000000007
n = int(input())
a = map(int, input().split())
t1, t2 = 0, 0
for i in a:
if i == 1:
t1 += 1
else:
t2 += 1
a = [1, 2]
for i in range(3, t1+1):
a = a[::-1]
a[1] = (a[0]+(i-1)*a[1])%m
if not t1 or t1 == 1:
a[1] = 1
for i in range(t1+1, n+1):
a[1] = a[1]*i%m
print(a[1])
``` | output | 1 | 10,292 | 17 | 20,585 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Smart Beaver decided to be not only smart, but also a healthy beaver! And so he began to attend physical education classes at school X. In this school, physical education has a very creative teacher. One of his favorite warm-up exercises is throwing balls. Students line up. Each one gets a single ball in the beginning. The balls are numbered from 1 to n (by the demand of the inventory commission).
<image> Figure 1. The initial position for n = 5.
After receiving the balls the students perform the warm-up exercise. The exercise takes place in a few throws. For each throw the teacher chooses any two arbitrary different students who will participate in it. The selected students throw their balls to each other. Thus, after each throw the students remain in their positions, and the two balls are swapped.
<image> Figure 2. The example of a throw.
In this case there was a throw between the students, who were holding the 2-nd and the 4-th balls. Since the warm-up has many exercises, each of them can only continue for little time. Therefore, for each student we know the maximum number of throws he can participate in. For this lessons maximum number of throws will be 1 or 2.
Note that after all phases of the considered exercise any ball can end up with any student. Smart Beaver decided to formalize it and introduced the concept of the "ball order". The ball order is a sequence of n numbers that correspond to the order of balls in the line. The first number will match the number of the ball of the first from the left student in the line, the second number will match the ball of the second student, and so on. For example, in figure 2 the order of the balls was (1, 2, 3, 4, 5), and after the throw it was (1, 4, 3, 2, 5). Smart beaver knows the number of students and for each student he knows the maximum number of throws in which he can participate. And now he is wondering: what is the number of distinct ways of ball orders by the end of the exercise.
Input
The first line contains a single number n — the number of students in the line and the number of balls. The next line contains exactly n space-separated integers. Each number corresponds to a student in the line (the i-th number corresponds to the i-th from the left student in the line) and shows the number of throws he can participate in.
The input limits for scoring 30 points are (subproblem D1):
* 1 ≤ n ≤ 10.
The input limits for scoring 70 points are (subproblems D1+D2):
* 1 ≤ n ≤ 500.
The input limits for scoring 100 points are (subproblems D1+D2+D3):
* 1 ≤ n ≤ 1000000.
Output
The output should contain a single integer — the number of variants of ball orders after the warm up exercise is complete. As the number can be rather large, print it modulo 1000000007 (109 + 7).
Examples
Input
5
1 2 2 1 2
Output
120
Input
8
1 2 2 1 2 1 1 2
Output
16800
Submitted Solution:
```
m = 1000000007
n = int(input())
a = map(int, input().split())
t1, t2 = 0, 0
for i in a:
if i == 1:
t1 += 1
else:
t2 += 1
a = [1, 2]
for i in range(3, t1+1):
a = a[::-1]
a[1] = (a[0]+(i-1)*a[1])%m
for i in range(t1+1, n+1):
a[1] = a[1]*i%m
print(a[1])
``` | instruction | 0 | 10,293 | 17 | 20,586 |
No | output | 1 | 10,293 | 17 | 20,587 |
Provide a correct Python 3 solution for this coding contest problem.
N contestants participated in a competition. The total of N-1 matches were played in a knockout tournament. For some reasons, the tournament may not be "fair" for all the contestants. That is, the number of the matches that must be played in order to win the championship may be different for each contestant. The structure of the tournament is formally described at the end of this statement.
After each match, there were always one winner and one loser. The last contestant standing was declared the champion.
<image>
Figure: an example of a tournament
For convenience, the contestants were numbered 1 through N. The contestant numbered 1 was the champion, and the contestant numbered i(2 ≦ i ≦ N) was defeated in a match against the contestant numbered a_i.
We will define the depth of the tournament as the maximum number of the matches that must be played in order to win the championship over all the contestants.
Find the minimum possible depth of the tournament.
The formal description of the structure of the tournament is as follows. In the i-th match, one of the following played against each other:
* Two predetermined contestants
* One predetermined contestant and the winner of the j-th match, where j(j<i) was predetermined
* The winner of the j-th match and the winner of the k-th match, where j and k (j,k<i, j ≠ k) were predetermined
Such structure is valid structure of the tournament, if and only if no contestant who has already been defeated in a match will never play in a match, regardless of the outcome of the matches.
Constraints
* 2 ≦ N ≦ 10^5
* 1 ≦ a_i ≦ N(2 ≦ i ≦ N)
* It is guaranteed that the input is consistent (that is, there exists at least one tournament that matches the given information).
Input
The input is given from Standard Input in the following format:
N
a_2
:
a_N
Output
Print the minimum possible depth of the tournament.
Examples
Input
5
1
1
2
4
Output
3
Input
7
1
2
1
3
1
4
Output
3
Input
4
4
4
1
Output
3 | instruction | 0 | 10,648 | 17 | 21,296 |
"Correct Solution:
```
import sys
sys.setrecursionlimit(500000)
N=int(input())
depth=[-1]*N
parent=[-1]*N
childs=[[] for i in range(N)]
depth[0]=0
def calc_depth(n):
for child in childs[n]:
depth[child]=depth[n]+1
calc_depth(child)
def calc_height(n):
if childs[n]==[]:
return 0
childs_height=[]
for child in childs[n]:
childs_height.append(calc_height(child))
childs_height.sort(reverse=True)
heightlist=[childs_height[i]+i for i in range(len(childs_height))]
return max(heightlist)+1
for i in range (1,N):
a=int(input())-1
childs[a].append(i)
print(calc_height(0))
``` | output | 1 | 10,648 | 17 | 21,297 |
Provide a correct Python 3 solution for this coding contest problem.
N contestants participated in a competition. The total of N-1 matches were played in a knockout tournament. For some reasons, the tournament may not be "fair" for all the contestants. That is, the number of the matches that must be played in order to win the championship may be different for each contestant. The structure of the tournament is formally described at the end of this statement.
After each match, there were always one winner and one loser. The last contestant standing was declared the champion.
<image>
Figure: an example of a tournament
For convenience, the contestants were numbered 1 through N. The contestant numbered 1 was the champion, and the contestant numbered i(2 ≦ i ≦ N) was defeated in a match against the contestant numbered a_i.
We will define the depth of the tournament as the maximum number of the matches that must be played in order to win the championship over all the contestants.
Find the minimum possible depth of the tournament.
The formal description of the structure of the tournament is as follows. In the i-th match, one of the following played against each other:
* Two predetermined contestants
* One predetermined contestant and the winner of the j-th match, where j(j<i) was predetermined
* The winner of the j-th match and the winner of the k-th match, where j and k (j,k<i, j ≠ k) were predetermined
Such structure is valid structure of the tournament, if and only if no contestant who has already been defeated in a match will never play in a match, regardless of the outcome of the matches.
Constraints
* 2 ≦ N ≦ 10^5
* 1 ≦ a_i ≦ N(2 ≦ i ≦ N)
* It is guaranteed that the input is consistent (that is, there exists at least one tournament that matches the given information).
Input
The input is given from Standard Input in the following format:
N
a_2
:
a_N
Output
Print the minimum possible depth of the tournament.
Examples
Input
5
1
1
2
4
Output
3
Input
7
1
2
1
3
1
4
Output
3
Input
4
4
4
1
Output
3 | instruction | 0 | 10,649 | 17 | 21,298 |
"Correct Solution:
```
#12:36
n = int(input())
peer = [[] for _ in range(n)]
for i in range(1,n):
j = int(input())-1
peer[i].append(j)
peer[j].append(i)
pre = [0 for _ in range(n)]
pre[0] = 10**6
seen = [0 for _ in range(n)]
seen[0] = 1
rank = []
now = [0]
while now:
rank.append(now)
last = now
now = []
for x in last:
for y in peer[x]:
if seen[y] == 0:
seen[y] = 1
pre[y] = x
now.append(y)
#print(pre)
#print(rank)
pstd = [[] for _ in range(n)]
rank.reverse()
l = len(rank)
for k in range(l):
if k == 0:
for z in rank[k]:
pstd[pre[z]].append(0)
continue
for z in rank[k]:
pstz = pstd[z]
pstz.sort()
tmp = -1
for w in pstz:
if tmp >= w:
tmp += 1
else:
tmp = w
if k != l-1:
pstd[pre[z]].append(tmp+1)
else:
print(tmp+1)
#print(pstd)
``` | output | 1 | 10,649 | 17 | 21,299 |
Provide a correct Python 3 solution for this coding contest problem.
N contestants participated in a competition. The total of N-1 matches were played in a knockout tournament. For some reasons, the tournament may not be "fair" for all the contestants. That is, the number of the matches that must be played in order to win the championship may be different for each contestant. The structure of the tournament is formally described at the end of this statement.
After each match, there were always one winner and one loser. The last contestant standing was declared the champion.
<image>
Figure: an example of a tournament
For convenience, the contestants were numbered 1 through N. The contestant numbered 1 was the champion, and the contestant numbered i(2 ≦ i ≦ N) was defeated in a match against the contestant numbered a_i.
We will define the depth of the tournament as the maximum number of the matches that must be played in order to win the championship over all the contestants.
Find the minimum possible depth of the tournament.
The formal description of the structure of the tournament is as follows. In the i-th match, one of the following played against each other:
* Two predetermined contestants
* One predetermined contestant and the winner of the j-th match, where j(j<i) was predetermined
* The winner of the j-th match and the winner of the k-th match, where j and k (j,k<i, j ≠ k) were predetermined
Such structure is valid structure of the tournament, if and only if no contestant who has already been defeated in a match will never play in a match, regardless of the outcome of the matches.
Constraints
* 2 ≦ N ≦ 10^5
* 1 ≦ a_i ≦ N(2 ≦ i ≦ N)
* It is guaranteed that the input is consistent (that is, there exists at least one tournament that matches the given information).
Input
The input is given from Standard Input in the following format:
N
a_2
:
a_N
Output
Print the minimum possible depth of the tournament.
Examples
Input
5
1
1
2
4
Output
3
Input
7
1
2
1
3
1
4
Output
3
Input
4
4
4
1
Output
3 | instruction | 0 | 10,650 | 17 | 21,300 |
"Correct Solution:
```
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5 + 5) # 再帰回数の上限!!
n = int(input())
A = [-1] + [int(input()) - 1 for i in range(n-1)]
M = [[] for i in range(n)]
for i in range(1, n):
M[A[i]].append(i)
# 0-indexedの場合
V = [0] * n
# print(M)
def des(x):
D = []
V[x] = 1
for i in M[x]:
if V[i] == 0:
V[i] = 1
D.append(des(i))
D.sort(reverse=True)
# print(x,D)
for i in range(len(D)):
D[i] += i+1
if len(D) == 0:
ans = 0
else:
ans = max(D)
return ans
print(des(0))
``` | output | 1 | 10,650 | 17 | 21,301 |
Provide a correct Python 3 solution for this coding contest problem.
N contestants participated in a competition. The total of N-1 matches were played in a knockout tournament. For some reasons, the tournament may not be "fair" for all the contestants. That is, the number of the matches that must be played in order to win the championship may be different for each contestant. The structure of the tournament is formally described at the end of this statement.
After each match, there were always one winner and one loser. The last contestant standing was declared the champion.
<image>
Figure: an example of a tournament
For convenience, the contestants were numbered 1 through N. The contestant numbered 1 was the champion, and the contestant numbered i(2 ≦ i ≦ N) was defeated in a match against the contestant numbered a_i.
We will define the depth of the tournament as the maximum number of the matches that must be played in order to win the championship over all the contestants.
Find the minimum possible depth of the tournament.
The formal description of the structure of the tournament is as follows. In the i-th match, one of the following played against each other:
* Two predetermined contestants
* One predetermined contestant and the winner of the j-th match, where j(j<i) was predetermined
* The winner of the j-th match and the winner of the k-th match, where j and k (j,k<i, j ≠ k) were predetermined
Such structure is valid structure of the tournament, if and only if no contestant who has already been defeated in a match will never play in a match, regardless of the outcome of the matches.
Constraints
* 2 ≦ N ≦ 10^5
* 1 ≦ a_i ≦ N(2 ≦ i ≦ N)
* It is guaranteed that the input is consistent (that is, there exists at least one tournament that matches the given information).
Input
The input is given from Standard Input in the following format:
N
a_2
:
a_N
Output
Print the minimum possible depth of the tournament.
Examples
Input
5
1
1
2
4
Output
3
Input
7
1
2
1
3
1
4
Output
3
Input
4
4
4
1
Output
3 | instruction | 0 | 10,651 | 17 | 21,302 |
"Correct Solution:
```
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy
sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7
n = I()
G = [[] for _ in range(n)]
win_against = [[] for _ in range(n)]
A = [-1]
for i in range(n - 1):
a = I()
A += [a - 1]
win_against[a - 1] += [i + 1]
in_degree = [len(i) for i in win_against]
dp = [0] * n
dq = deque()
for i in range(n):
if not in_degree[i]:
dq += ([i])
order = []
while dq:
x = dq.popleft()
order += [x]
if x == 0:
break
in_degree[A[x]] -= 1
if in_degree[A[x]] == 0:
dq += [A[x]]
for i in order:
ret = 0
s = sorted([dp[k] for k in win_against[i]])
for l in range(1, len(win_against[i]) + 1):
ret = max(ret, l + s.pop())
dp[i] = ret
print(dp[0])
``` | output | 1 | 10,651 | 17 | 21,303 |
Provide a correct Python 3 solution for this coding contest problem.
N contestants participated in a competition. The total of N-1 matches were played in a knockout tournament. For some reasons, the tournament may not be "fair" for all the contestants. That is, the number of the matches that must be played in order to win the championship may be different for each contestant. The structure of the tournament is formally described at the end of this statement.
After each match, there were always one winner and one loser. The last contestant standing was declared the champion.
<image>
Figure: an example of a tournament
For convenience, the contestants were numbered 1 through N. The contestant numbered 1 was the champion, and the contestant numbered i(2 ≦ i ≦ N) was defeated in a match against the contestant numbered a_i.
We will define the depth of the tournament as the maximum number of the matches that must be played in order to win the championship over all the contestants.
Find the minimum possible depth of the tournament.
The formal description of the structure of the tournament is as follows. In the i-th match, one of the following played against each other:
* Two predetermined contestants
* One predetermined contestant and the winner of the j-th match, where j(j<i) was predetermined
* The winner of the j-th match and the winner of the k-th match, where j and k (j,k<i, j ≠ k) were predetermined
Such structure is valid structure of the tournament, if and only if no contestant who has already been defeated in a match will never play in a match, regardless of the outcome of the matches.
Constraints
* 2 ≦ N ≦ 10^5
* 1 ≦ a_i ≦ N(2 ≦ i ≦ N)
* It is guaranteed that the input is consistent (that is, there exists at least one tournament that matches the given information).
Input
The input is given from Standard Input in the following format:
N
a_2
:
a_N
Output
Print the minimum possible depth of the tournament.
Examples
Input
5
1
1
2
4
Output
3
Input
7
1
2
1
3
1
4
Output
3
Input
4
4
4
1
Output
3 | instruction | 0 | 10,652 | 17 | 21,304 |
"Correct Solution:
```
import sys
sys.setrecursionlimit(10 ** 6)
def main():
N, *A = map(int, open(0))
E = [[] for _ in range(N + 1)]
for i, v in enumerate(A, 1):
E[v - 1].append(i)
def dfs(v):
D = sorted(map(dfs, E[v]))
return max([0] + [len(D) - i + d for i, d in enumerate(D)])
print(dfs(0))
main()
``` | output | 1 | 10,652 | 17 | 21,305 |
Provide a correct Python 3 solution for this coding contest problem.
N contestants participated in a competition. The total of N-1 matches were played in a knockout tournament. For some reasons, the tournament may not be "fair" for all the contestants. That is, the number of the matches that must be played in order to win the championship may be different for each contestant. The structure of the tournament is formally described at the end of this statement.
After each match, there were always one winner and one loser. The last contestant standing was declared the champion.
<image>
Figure: an example of a tournament
For convenience, the contestants were numbered 1 through N. The contestant numbered 1 was the champion, and the contestant numbered i(2 ≦ i ≦ N) was defeated in a match against the contestant numbered a_i.
We will define the depth of the tournament as the maximum number of the matches that must be played in order to win the championship over all the contestants.
Find the minimum possible depth of the tournament.
The formal description of the structure of the tournament is as follows. In the i-th match, one of the following played against each other:
* Two predetermined contestants
* One predetermined contestant and the winner of the j-th match, where j(j<i) was predetermined
* The winner of the j-th match and the winner of the k-th match, where j and k (j,k<i, j ≠ k) were predetermined
Such structure is valid structure of the tournament, if and only if no contestant who has already been defeated in a match will never play in a match, regardless of the outcome of the matches.
Constraints
* 2 ≦ N ≦ 10^5
* 1 ≦ a_i ≦ N(2 ≦ i ≦ N)
* It is guaranteed that the input is consistent (that is, there exists at least one tournament that matches the given information).
Input
The input is given from Standard Input in the following format:
N
a_2
:
a_N
Output
Print the minimum possible depth of the tournament.
Examples
Input
5
1
1
2
4
Output
3
Input
7
1
2
1
3
1
4
Output
3
Input
4
4
4
1
Output
3 | instruction | 0 | 10,653 | 17 | 21,306 |
"Correct Solution:
```
from collections import deque
import sys
input = sys.stdin.buffer.readline
N = int(input())
child = [[] for _ in range(N+1)]
for i in range(2, N+1):
par = int(input())
child[par].append(i)
que = deque()
que.append(1)
seq = []
while que:
v = que.popleft()
seq.append(v)
for u in child[v]:
que.append(u)
seq.reverse()
dp = [0] * (N+1)
for v in seq:
if child[v]:
w_child = []
for u in child[v]:
w_child.append(dp[u])
w_child.sort(reverse=True)
w = [w_child[i] + i + 1 for i in range(len(w_child))]
dp[v] = max(w)
print(dp[1])
``` | output | 1 | 10,653 | 17 | 21,307 |
Provide a correct Python 3 solution for this coding contest problem.
N contestants participated in a competition. The total of N-1 matches were played in a knockout tournament. For some reasons, the tournament may not be "fair" for all the contestants. That is, the number of the matches that must be played in order to win the championship may be different for each contestant. The structure of the tournament is formally described at the end of this statement.
After each match, there were always one winner and one loser. The last contestant standing was declared the champion.
<image>
Figure: an example of a tournament
For convenience, the contestants were numbered 1 through N. The contestant numbered 1 was the champion, and the contestant numbered i(2 ≦ i ≦ N) was defeated in a match against the contestant numbered a_i.
We will define the depth of the tournament as the maximum number of the matches that must be played in order to win the championship over all the contestants.
Find the minimum possible depth of the tournament.
The formal description of the structure of the tournament is as follows. In the i-th match, one of the following played against each other:
* Two predetermined contestants
* One predetermined contestant and the winner of the j-th match, where j(j<i) was predetermined
* The winner of the j-th match and the winner of the k-th match, where j and k (j,k<i, j ≠ k) were predetermined
Such structure is valid structure of the tournament, if and only if no contestant who has already been defeated in a match will never play in a match, regardless of the outcome of the matches.
Constraints
* 2 ≦ N ≦ 10^5
* 1 ≦ a_i ≦ N(2 ≦ i ≦ N)
* It is guaranteed that the input is consistent (that is, there exists at least one tournament that matches the given information).
Input
The input is given from Standard Input in the following format:
N
a_2
:
a_N
Output
Print the minimum possible depth of the tournament.
Examples
Input
5
1
1
2
4
Output
3
Input
7
1
2
1
3
1
4
Output
3
Input
4
4
4
1
Output
3 | instruction | 0 | 10,654 | 17 | 21,308 |
"Correct Solution:
```
import sys
sys.setrecursionlimit(10**6)
n = int(input())
tree = [list() for _ in range(n+1)]
for i in range(2,n+1):
a = int(input())
tree[a].append(i)
win = [0]*(n+1)
def dfs(v,win):
if tree[v] == []:
win[v] = 0
return win[v]
l = list()
for x in tree[v]:
dfs(x,win)
l.append(win[x])
l.sort(reverse=True)
win[v] = max(i+1+l[i] for i in range(len(l)))
return win[v]
print(dfs(1,win))
``` | output | 1 | 10,654 | 17 | 21,309 |
Provide a correct Python 3 solution for this coding contest problem.
N contestants participated in a competition. The total of N-1 matches were played in a knockout tournament. For some reasons, the tournament may not be "fair" for all the contestants. That is, the number of the matches that must be played in order to win the championship may be different for each contestant. The structure of the tournament is formally described at the end of this statement.
After each match, there were always one winner and one loser. The last contestant standing was declared the champion.
<image>
Figure: an example of a tournament
For convenience, the contestants were numbered 1 through N. The contestant numbered 1 was the champion, and the contestant numbered i(2 ≦ i ≦ N) was defeated in a match against the contestant numbered a_i.
We will define the depth of the tournament as the maximum number of the matches that must be played in order to win the championship over all the contestants.
Find the minimum possible depth of the tournament.
The formal description of the structure of the tournament is as follows. In the i-th match, one of the following played against each other:
* Two predetermined contestants
* One predetermined contestant and the winner of the j-th match, where j(j<i) was predetermined
* The winner of the j-th match and the winner of the k-th match, where j and k (j,k<i, j ≠ k) were predetermined
Such structure is valid structure of the tournament, if and only if no contestant who has already been defeated in a match will never play in a match, regardless of the outcome of the matches.
Constraints
* 2 ≦ N ≦ 10^5
* 1 ≦ a_i ≦ N(2 ≦ i ≦ N)
* It is guaranteed that the input is consistent (that is, there exists at least one tournament that matches the given information).
Input
The input is given from Standard Input in the following format:
N
a_2
:
a_N
Output
Print the minimum possible depth of the tournament.
Examples
Input
5
1
1
2
4
Output
3
Input
7
1
2
1
3
1
4
Output
3
Input
4
4
4
1
Output
3 | instruction | 0 | 10,655 | 17 | 21,310 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
from sys import setrecursionlimit
setrecursionlimit(10000000)
N = int(input())
C = [[] for _ in range(N)]
for i in range(1, N):
C[int(input())-1].append(i)
def cal(x):
if len(C[x]) == 0:
return 0
else:
D = sorted([cal(a) for a in C[x]], reverse=True)
res = 0
for i, d in enumerate(D, start=1):
res = max(res, i+d)
return res
print(cal(0))
``` | output | 1 | 10,655 | 17 | 21,311 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N contestants participated in a competition. The total of N-1 matches were played in a knockout tournament. For some reasons, the tournament may not be "fair" for all the contestants. That is, the number of the matches that must be played in order to win the championship may be different for each contestant. The structure of the tournament is formally described at the end of this statement.
After each match, there were always one winner and one loser. The last contestant standing was declared the champion.
<image>
Figure: an example of a tournament
For convenience, the contestants were numbered 1 through N. The contestant numbered 1 was the champion, and the contestant numbered i(2 ≦ i ≦ N) was defeated in a match against the contestant numbered a_i.
We will define the depth of the tournament as the maximum number of the matches that must be played in order to win the championship over all the contestants.
Find the minimum possible depth of the tournament.
The formal description of the structure of the tournament is as follows. In the i-th match, one of the following played against each other:
* Two predetermined contestants
* One predetermined contestant and the winner of the j-th match, where j(j<i) was predetermined
* The winner of the j-th match and the winner of the k-th match, where j and k (j,k<i, j ≠ k) were predetermined
Such structure is valid structure of the tournament, if and only if no contestant who has already been defeated in a match will never play in a match, regardless of the outcome of the matches.
Constraints
* 2 ≦ N ≦ 10^5
* 1 ≦ a_i ≦ N(2 ≦ i ≦ N)
* It is guaranteed that the input is consistent (that is, there exists at least one tournament that matches the given information).
Input
The input is given from Standard Input in the following format:
N
a_2
:
a_N
Output
Print the minimum possible depth of the tournament.
Examples
Input
5
1
1
2
4
Output
3
Input
7
1
2
1
3
1
4
Output
3
Input
4
4
4
1
Output
3
Submitted Solution:
```
import sys
sys.setrecursionlimit(10 ** 7)
N = int(input())
edge = [[] for _ in range(N)]
for node in range(1, N):
a = int(input())
edge[a-1].append(node)
def dfs(n):
"""
dfs(n) := nを根としたトーナメントの深さ
nの深さを浅くしたい
-> 深い場所に浅い頂点vを割り当てる
-> 対戦数が少ない人から対戦していく
"""
if not edge[n]:
return 0
que = []
for v in edge[n]:
que.append(dfs(v))
que.sort(reverse=True)
res = 0
for plus, depth in enumerate(que, start=1):
# 今までの対戦数 + どれくらい深くするか
res = max(res, depth + plus)
return res
print(dfs(0))
``` | instruction | 0 | 10,658 | 17 | 21,316 |
Yes | output | 1 | 10,658 | 17 | 21,317 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N contestants participated in a competition. The total of N-1 matches were played in a knockout tournament. For some reasons, the tournament may not be "fair" for all the contestants. That is, the number of the matches that must be played in order to win the championship may be different for each contestant. The structure of the tournament is formally described at the end of this statement.
After each match, there were always one winner and one loser. The last contestant standing was declared the champion.
<image>
Figure: an example of a tournament
For convenience, the contestants were numbered 1 through N. The contestant numbered 1 was the champion, and the contestant numbered i(2 ≦ i ≦ N) was defeated in a match against the contestant numbered a_i.
We will define the depth of the tournament as the maximum number of the matches that must be played in order to win the championship over all the contestants.
Find the minimum possible depth of the tournament.
The formal description of the structure of the tournament is as follows. In the i-th match, one of the following played against each other:
* Two predetermined contestants
* One predetermined contestant and the winner of the j-th match, where j(j<i) was predetermined
* The winner of the j-th match and the winner of the k-th match, where j and k (j,k<i, j ≠ k) were predetermined
Such structure is valid structure of the tournament, if and only if no contestant who has already been defeated in a match will never play in a match, regardless of the outcome of the matches.
Constraints
* 2 ≦ N ≦ 10^5
* 1 ≦ a_i ≦ N(2 ≦ i ≦ N)
* It is guaranteed that the input is consistent (that is, there exists at least one tournament that matches the given information).
Input
The input is given from Standard Input in the following format:
N
a_2
:
a_N
Output
Print the minimum possible depth of the tournament.
Examples
Input
5
1
1
2
4
Output
3
Input
7
1
2
1
3
1
4
Output
3
Input
4
4
4
1
Output
3
Submitted Solution:
```
n = int(input())
tree = [[] for i in range(n)]
for i in range(n - 1):
j = int(input())
j -= 1
i += 1
tree[i].append(j)
tree[j].append(i)
def dfs(pos):
if pos != 0 and len(tree[pos]) == 1:
return 1
li = []
for next_pos in tree[pos]:
if visited[next_pos]:
continue
visited[next_pos] = True
li.append(dfs(next_pos))
max_li = max(li)
len_li = len(li)
res = max(len_li + 1, max_li + 1)
return res
visited = [False] * n
visited[0] = True
print(dfs(0) - 1)
``` | instruction | 0 | 10,660 | 17 | 21,320 |
No | output | 1 | 10,660 | 17 | 21,321 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N contestants participated in a competition. The total of N-1 matches were played in a knockout tournament. For some reasons, the tournament may not be "fair" for all the contestants. That is, the number of the matches that must be played in order to win the championship may be different for each contestant. The structure of the tournament is formally described at the end of this statement.
After each match, there were always one winner and one loser. The last contestant standing was declared the champion.
<image>
Figure: an example of a tournament
For convenience, the contestants were numbered 1 through N. The contestant numbered 1 was the champion, and the contestant numbered i(2 ≦ i ≦ N) was defeated in a match against the contestant numbered a_i.
We will define the depth of the tournament as the maximum number of the matches that must be played in order to win the championship over all the contestants.
Find the minimum possible depth of the tournament.
The formal description of the structure of the tournament is as follows. In the i-th match, one of the following played against each other:
* Two predetermined contestants
* One predetermined contestant and the winner of the j-th match, where j(j<i) was predetermined
* The winner of the j-th match and the winner of the k-th match, where j and k (j,k<i, j ≠ k) were predetermined
Such structure is valid structure of the tournament, if and only if no contestant who has already been defeated in a match will never play in a match, regardless of the outcome of the matches.
Constraints
* 2 ≦ N ≦ 10^5
* 1 ≦ a_i ≦ N(2 ≦ i ≦ N)
* It is guaranteed that the input is consistent (that is, there exists at least one tournament that matches the given information).
Input
The input is given from Standard Input in the following format:
N
a_2
:
a_N
Output
Print the minimum possible depth of the tournament.
Examples
Input
5
1
1
2
4
Output
3
Input
7
1
2
1
3
1
4
Output
3
Input
4
4
4
1
Output
3
Submitted Solution:
```
import queue
n = int(input())
wl = [[] for i in range(n+1)]
for i in range(2,n+1):
ai = int(input())
wl[ai].append(i)
dp = [-1 for i in range(n+1)]
def calc_dp(a):
if len(wl[a]) == 0:
return 0
else:
dps = []
for i in wl[a]:
dps.append(calc_dp(i))
dps.sort(reverse=True)
ma = 0
for i,dpi in enumerate(dps):
if ma < dpi+i:
ma = dpi+i
return ma+1
print(calc_dp(1))
``` | instruction | 0 | 10,661 | 17 | 21,322 |
No | output | 1 | 10,661 | 17 | 21,323 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N contestants participated in a competition. The total of N-1 matches were played in a knockout tournament. For some reasons, the tournament may not be "fair" for all the contestants. That is, the number of the matches that must be played in order to win the championship may be different for each contestant. The structure of the tournament is formally described at the end of this statement.
After each match, there were always one winner and one loser. The last contestant standing was declared the champion.
<image>
Figure: an example of a tournament
For convenience, the contestants were numbered 1 through N. The contestant numbered 1 was the champion, and the contestant numbered i(2 ≦ i ≦ N) was defeated in a match against the contestant numbered a_i.
We will define the depth of the tournament as the maximum number of the matches that must be played in order to win the championship over all the contestants.
Find the minimum possible depth of the tournament.
The formal description of the structure of the tournament is as follows. In the i-th match, one of the following played against each other:
* Two predetermined contestants
* One predetermined contestant and the winner of the j-th match, where j(j<i) was predetermined
* The winner of the j-th match and the winner of the k-th match, where j and k (j,k<i, j ≠ k) were predetermined
Such structure is valid structure of the tournament, if and only if no contestant who has already been defeated in a match will never play in a match, regardless of the outcome of the matches.
Constraints
* 2 ≦ N ≦ 10^5
* 1 ≦ a_i ≦ N(2 ≦ i ≦ N)
* It is guaranteed that the input is consistent (that is, there exists at least one tournament that matches the given information).
Input
The input is given from Standard Input in the following format:
N
a_2
:
a_N
Output
Print the minimum possible depth of the tournament.
Examples
Input
5
1
1
2
4
Output
3
Input
7
1
2
1
3
1
4
Output
3
Input
4
4
4
1
Output
3
Submitted Solution:
```
#優勝者からの深さmax?
#優勝者が最初に負かした奴が沢山倒しているなら
n = int(input())
a=[0]+[int(input())-1 for _ in range(n-1)]
b = [[] for _ in range(n)]
for i in range(1,n):
b[a[i]].append(i)
from collections import deque
Q = deque()
d=[-1]*n
d[0]=0
Q.append(0)
while Q:
p=Q.popleft()
for q in b[p]:
if d[q]<0:
d[q]=d[p]+1
Q.append(q)
mxd = max(d)##保存しないと毎回求める
ans = mxd-1
for i in range(n):
if d[i]==mxd:
ans += 1
print(ans)
``` | instruction | 0 | 10,662 | 17 | 21,324 |
No | output | 1 | 10,662 | 17 | 21,325 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N contestants participated in a competition. The total of N-1 matches were played in a knockout tournament. For some reasons, the tournament may not be "fair" for all the contestants. That is, the number of the matches that must be played in order to win the championship may be different for each contestant. The structure of the tournament is formally described at the end of this statement.
After each match, there were always one winner and one loser. The last contestant standing was declared the champion.
<image>
Figure: an example of a tournament
For convenience, the contestants were numbered 1 through N. The contestant numbered 1 was the champion, and the contestant numbered i(2 ≦ i ≦ N) was defeated in a match against the contestant numbered a_i.
We will define the depth of the tournament as the maximum number of the matches that must be played in order to win the championship over all the contestants.
Find the minimum possible depth of the tournament.
The formal description of the structure of the tournament is as follows. In the i-th match, one of the following played against each other:
* Two predetermined contestants
* One predetermined contestant and the winner of the j-th match, where j(j<i) was predetermined
* The winner of the j-th match and the winner of the k-th match, where j and k (j,k<i, j ≠ k) were predetermined
Such structure is valid structure of the tournament, if and only if no contestant who has already been defeated in a match will never play in a match, regardless of the outcome of the matches.
Constraints
* 2 ≦ N ≦ 10^5
* 1 ≦ a_i ≦ N(2 ≦ i ≦ N)
* It is guaranteed that the input is consistent (that is, there exists at least one tournament that matches the given information).
Input
The input is given from Standard Input in the following format:
N
a_2
:
a_N
Output
Print the minimum possible depth of the tournament.
Examples
Input
5
1
1
2
4
Output
3
Input
7
1
2
1
3
1
4
Output
3
Input
4
4
4
1
Output
3
Submitted Solution:
```
n = int(input())
lst = [0 for i in range(n+1)]
a = [-1 for i in range(n+1)]
for i in range(n+1):
if i <= 1: continue
ai = int(input())
a[i] = ai
lst[ai] += 1
dic = {}
for i in range(n+1):
if i <= 1: continue
if a[i] in dic:
dic[a[i]].append((lst[i], i))
else:
dic[a[i]] = [(lst[i], i)]
for key in dic:
dic[key].sort()
tempmax = 0
now = 0
nxt = 1
while nxt != None:
tempmax = max(tempmax, lst[nxt]+now)
if nxt in dic:
nxt = dic[nxt].pop()[1]
else:
nxt = None
now += 1
print(tempmax)
``` | instruction | 0 | 10,663 | 17 | 21,326 |
No | output | 1 | 10,663 | 17 | 21,327 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which reads $n$ items and sorts them. Each item has attributes $\\{value, weight, type, date, name\\}$ and they are represented by $\\{$ integer, integer, upper-case letter, integer, string $\\}$ respectively. Sort the items based on the following priorities.
1. first by value (ascending)
2. in case of a tie, by weight (ascending)
3. in case of a tie, by type (ascending in lexicographic order)
4. in case of a tie, by date (ascending)
5. in case of a tie, by name (ascending in lexicographic order)
Constraints
* $1 \leq n \leq 100,000$
* $0 \leq v_i \leq 1,000,000,000$
* $0 \leq w_i \leq 1,000,000,000$
* $t_i$ is a upper-case letter
* $0 \leq d_i \leq 2,000,000,000,000$
* $1 \leq $ size of $s_i \leq 20$
* $s_i \ne s_j$ if $(i \ne j)$
Input
The input is given in the following format.
$n$
$v_0 \; w_0 \; t_0 \; d_0 \; s_0$
$v_1 \; w_1 \; t_1 \; d_1 \; s_1$
:
$v_{n-1} \; w_{n-1} \; t_{n-1} \; d_{n-1} \; s_{n-1}$
In the first line, the number of items $n$. In the following $n$ lines, attributes of each item are given. $v_i \; w_i \; t_i \; d_i \; s_i$ represent value, weight, type, date and name of the $i$-th item respectively.
Output
Print attributes of each item in order. Print an item in a line and adjacency attributes should be separated by a single space.
Example
Input
5
105 24 C 1500000000000 white
100 23 C 1500000000000 blue
105 23 A 1480000000000 pink
110 25 B 1500000000000 black
110 20 A 1300000000000 gree
Output
100 23 C 1500000000000 blue
105 23 A 1480000000000 pink
105 24 C 1500000000000 white
110 20 A 1300000000000 gree
110 25 B 1500000000000 black | instruction | 0 | 10,784 | 17 | 21,568 |
"Correct Solution:
```
import sys
n = int(input())
goods = [None] * n
for i, line in enumerate(sys.stdin.readlines()):
value, weight, serial, date, name = line.split()
goods[i] = (int(value), int(weight), serial, int(date), name)
goods.sort() #key=lambda x: (x[0], x[1], x[2], x[3], x[4]))
print('\n'.join(map(lambda x: " ".join(map(str, x)), goods)))
``` | output | 1 | 10,784 | 17 | 21,569 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which reads $n$ items and sorts them. Each item has attributes $\\{value, weight, type, date, name\\}$ and they are represented by $\\{$ integer, integer, upper-case letter, integer, string $\\}$ respectively. Sort the items based on the following priorities.
1. first by value (ascending)
2. in case of a tie, by weight (ascending)
3. in case of a tie, by type (ascending in lexicographic order)
4. in case of a tie, by date (ascending)
5. in case of a tie, by name (ascending in lexicographic order)
Constraints
* $1 \leq n \leq 100,000$
* $0 \leq v_i \leq 1,000,000,000$
* $0 \leq w_i \leq 1,000,000,000$
* $t_i$ is a upper-case letter
* $0 \leq d_i \leq 2,000,000,000,000$
* $1 \leq $ size of $s_i \leq 20$
* $s_i \ne s_j$ if $(i \ne j)$
Input
The input is given in the following format.
$n$
$v_0 \; w_0 \; t_0 \; d_0 \; s_0$
$v_1 \; w_1 \; t_1 \; d_1 \; s_1$
:
$v_{n-1} \; w_{n-1} \; t_{n-1} \; d_{n-1} \; s_{n-1}$
In the first line, the number of items $n$. In the following $n$ lines, attributes of each item are given. $v_i \; w_i \; t_i \; d_i \; s_i$ represent value, weight, type, date and name of the $i$-th item respectively.
Output
Print attributes of each item in order. Print an item in a line and adjacency attributes should be separated by a single space.
Example
Input
5
105 24 C 1500000000000 white
100 23 C 1500000000000 blue
105 23 A 1480000000000 pink
110 25 B 1500000000000 black
110 20 A 1300000000000 gree
Output
100 23 C 1500000000000 blue
105 23 A 1480000000000 pink
105 24 C 1500000000000 white
110 20 A 1300000000000 gree
110 25 B 1500000000000 black | instruction | 0 | 10,785 | 17 | 21,570 |
"Correct Solution:
```
n = int(input())
a = [input().split() for i in range(n)]
for i in range(4, -1, -1):
if i==4 or i==2:
a.sort(key=lambda x:x[i])
else:
a.sort(key=lambda x:int(x[i]))
for ele in a:
print(" ".join(map(str, ele)))
``` | output | 1 | 10,785 | 17 | 21,571 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which reads $n$ items and sorts them. Each item has attributes $\\{value, weight, type, date, name\\}$ and they are represented by $\\{$ integer, integer, upper-case letter, integer, string $\\}$ respectively. Sort the items based on the following priorities.
1. first by value (ascending)
2. in case of a tie, by weight (ascending)
3. in case of a tie, by type (ascending in lexicographic order)
4. in case of a tie, by date (ascending)
5. in case of a tie, by name (ascending in lexicographic order)
Constraints
* $1 \leq n \leq 100,000$
* $0 \leq v_i \leq 1,000,000,000$
* $0 \leq w_i \leq 1,000,000,000$
* $t_i$ is a upper-case letter
* $0 \leq d_i \leq 2,000,000,000,000$
* $1 \leq $ size of $s_i \leq 20$
* $s_i \ne s_j$ if $(i \ne j)$
Input
The input is given in the following format.
$n$
$v_0 \; w_0 \; t_0 \; d_0 \; s_0$
$v_1 \; w_1 \; t_1 \; d_1 \; s_1$
:
$v_{n-1} \; w_{n-1} \; t_{n-1} \; d_{n-1} \; s_{n-1}$
In the first line, the number of items $n$. In the following $n$ lines, attributes of each item are given. $v_i \; w_i \; t_i \; d_i \; s_i$ represent value, weight, type, date and name of the $i$-th item respectively.
Output
Print attributes of each item in order. Print an item in a line and adjacency attributes should be separated by a single space.
Example
Input
5
105 24 C 1500000000000 white
100 23 C 1500000000000 blue
105 23 A 1480000000000 pink
110 25 B 1500000000000 black
110 20 A 1300000000000 gree
Output
100 23 C 1500000000000 blue
105 23 A 1480000000000 pink
105 24 C 1500000000000 white
110 20 A 1300000000000 gree
110 25 B 1500000000000 black | instruction | 0 | 10,786 | 17 | 21,572 |
"Correct Solution:
```
n = int(input())
list_items = []
for _ in range(n):
v, w, t, d, s = input().split()
list_items.append([int(v), int(w), t, int(d), s])
for item in sorted(list_items):
print(*item)
``` | output | 1 | 10,786 | 17 | 21,573 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which reads $n$ items and sorts them. Each item has attributes $\\{value, weight, type, date, name\\}$ and they are represented by $\\{$ integer, integer, upper-case letter, integer, string $\\}$ respectively. Sort the items based on the following priorities.
1. first by value (ascending)
2. in case of a tie, by weight (ascending)
3. in case of a tie, by type (ascending in lexicographic order)
4. in case of a tie, by date (ascending)
5. in case of a tie, by name (ascending in lexicographic order)
Constraints
* $1 \leq n \leq 100,000$
* $0 \leq v_i \leq 1,000,000,000$
* $0 \leq w_i \leq 1,000,000,000$
* $t_i$ is a upper-case letter
* $0 \leq d_i \leq 2,000,000,000,000$
* $1 \leq $ size of $s_i \leq 20$
* $s_i \ne s_j$ if $(i \ne j)$
Input
The input is given in the following format.
$n$
$v_0 \; w_0 \; t_0 \; d_0 \; s_0$
$v_1 \; w_1 \; t_1 \; d_1 \; s_1$
:
$v_{n-1} \; w_{n-1} \; t_{n-1} \; d_{n-1} \; s_{n-1}$
In the first line, the number of items $n$. In the following $n$ lines, attributes of each item are given. $v_i \; w_i \; t_i \; d_i \; s_i$ represent value, weight, type, date and name of the $i$-th item respectively.
Output
Print attributes of each item in order. Print an item in a line and adjacency attributes should be separated by a single space.
Example
Input
5
105 24 C 1500000000000 white
100 23 C 1500000000000 blue
105 23 A 1480000000000 pink
110 25 B 1500000000000 black
110 20 A 1300000000000 gree
Output
100 23 C 1500000000000 blue
105 23 A 1480000000000 pink
105 24 C 1500000000000 white
110 20 A 1300000000000 gree
110 25 B 1500000000000 black | instruction | 0 | 10,787 | 17 | 21,574 |
"Correct Solution:
```
n = int(input())
tbl = []
for i in range(n):
a = input().split()
tbl.append((int(a[0]), int(a[1]), a[2], int(a[3]), a[4]))
tbl.sort()
for i in tbl:
print(*i)
``` | output | 1 | 10,787 | 17 | 21,575 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which reads $n$ items and sorts them. Each item has attributes $\\{value, weight, type, date, name\\}$ and they are represented by $\\{$ integer, integer, upper-case letter, integer, string $\\}$ respectively. Sort the items based on the following priorities.
1. first by value (ascending)
2. in case of a tie, by weight (ascending)
3. in case of a tie, by type (ascending in lexicographic order)
4. in case of a tie, by date (ascending)
5. in case of a tie, by name (ascending in lexicographic order)
Constraints
* $1 \leq n \leq 100,000$
* $0 \leq v_i \leq 1,000,000,000$
* $0 \leq w_i \leq 1,000,000,000$
* $t_i$ is a upper-case letter
* $0 \leq d_i \leq 2,000,000,000,000$
* $1 \leq $ size of $s_i \leq 20$
* $s_i \ne s_j$ if $(i \ne j)$
Input
The input is given in the following format.
$n$
$v_0 \; w_0 \; t_0 \; d_0 \; s_0$
$v_1 \; w_1 \; t_1 \; d_1 \; s_1$
:
$v_{n-1} \; w_{n-1} \; t_{n-1} \; d_{n-1} \; s_{n-1}$
In the first line, the number of items $n$. In the following $n$ lines, attributes of each item are given. $v_i \; w_i \; t_i \; d_i \; s_i$ represent value, weight, type, date and name of the $i$-th item respectively.
Output
Print attributes of each item in order. Print an item in a line and adjacency attributes should be separated by a single space.
Example
Input
5
105 24 C 1500000000000 white
100 23 C 1500000000000 blue
105 23 A 1480000000000 pink
110 25 B 1500000000000 black
110 20 A 1300000000000 gree
Output
100 23 C 1500000000000 blue
105 23 A 1480000000000 pink
105 24 C 1500000000000 white
110 20 A 1300000000000 gree
110 25 B 1500000000000 black | instruction | 0 | 10,788 | 17 | 21,576 |
"Correct Solution:
```
#組み込み関数頼み
#整数に直さないと2>10
n = int(input())
P = []
for _ in range(n):
p = list(map(str, input().split( )))
P.append(p)
for _ in range(n):
for i in range(2):
P[_][i] = int(P[_][i])
P[_][3] = int(P[_][3])
P.sort()
P.sort()
for _ in range(n):
print(*P[_])
``` | output | 1 | 10,788 | 17 | 21,577 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which reads $n$ items and sorts them. Each item has attributes $\\{value, weight, type, date, name\\}$ and they are represented by $\\{$ integer, integer, upper-case letter, integer, string $\\}$ respectively. Sort the items based on the following priorities.
1. first by value (ascending)
2. in case of a tie, by weight (ascending)
3. in case of a tie, by type (ascending in lexicographic order)
4. in case of a tie, by date (ascending)
5. in case of a tie, by name (ascending in lexicographic order)
Constraints
* $1 \leq n \leq 100,000$
* $0 \leq v_i \leq 1,000,000,000$
* $0 \leq w_i \leq 1,000,000,000$
* $t_i$ is a upper-case letter
* $0 \leq d_i \leq 2,000,000,000,000$
* $1 \leq $ size of $s_i \leq 20$
* $s_i \ne s_j$ if $(i \ne j)$
Input
The input is given in the following format.
$n$
$v_0 \; w_0 \; t_0 \; d_0 \; s_0$
$v_1 \; w_1 \; t_1 \; d_1 \; s_1$
:
$v_{n-1} \; w_{n-1} \; t_{n-1} \; d_{n-1} \; s_{n-1}$
In the first line, the number of items $n$. In the following $n$ lines, attributes of each item are given. $v_i \; w_i \; t_i \; d_i \; s_i$ represent value, weight, type, date and name of the $i$-th item respectively.
Output
Print attributes of each item in order. Print an item in a line and adjacency attributes should be separated by a single space.
Example
Input
5
105 24 C 1500000000000 white
100 23 C 1500000000000 blue
105 23 A 1480000000000 pink
110 25 B 1500000000000 black
110 20 A 1300000000000 gree
Output
100 23 C 1500000000000 blue
105 23 A 1480000000000 pink
105 24 C 1500000000000 white
110 20 A 1300000000000 gree
110 25 B 1500000000000 black | instruction | 0 | 10,789 | 17 | 21,578 |
"Correct Solution:
```
n=int(input())
tuples=[]
for _ in range(n):
obj=input().split(" ")
obj[0]=int(obj[0])
obj[1]=int(obj[1])
obj[3]=int(obj[3])
tuples.append(obj)
tuples=sorted(tuples)
for t in tuples:
print(t[0],t[1],t[2],t[3],t[4])
``` | output | 1 | 10,789 | 17 | 21,579 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which reads $n$ items and sorts them. Each item has attributes $\\{value, weight, type, date, name\\}$ and they are represented by $\\{$ integer, integer, upper-case letter, integer, string $\\}$ respectively. Sort the items based on the following priorities.
1. first by value (ascending)
2. in case of a tie, by weight (ascending)
3. in case of a tie, by type (ascending in lexicographic order)
4. in case of a tie, by date (ascending)
5. in case of a tie, by name (ascending in lexicographic order)
Constraints
* $1 \leq n \leq 100,000$
* $0 \leq v_i \leq 1,000,000,000$
* $0 \leq w_i \leq 1,000,000,000$
* $t_i$ is a upper-case letter
* $0 \leq d_i \leq 2,000,000,000,000$
* $1 \leq $ size of $s_i \leq 20$
* $s_i \ne s_j$ if $(i \ne j)$
Input
The input is given in the following format.
$n$
$v_0 \; w_0 \; t_0 \; d_0 \; s_0$
$v_1 \; w_1 \; t_1 \; d_1 \; s_1$
:
$v_{n-1} \; w_{n-1} \; t_{n-1} \; d_{n-1} \; s_{n-1}$
In the first line, the number of items $n$. In the following $n$ lines, attributes of each item are given. $v_i \; w_i \; t_i \; d_i \; s_i$ represent value, weight, type, date and name of the $i$-th item respectively.
Output
Print attributes of each item in order. Print an item in a line and adjacency attributes should be separated by a single space.
Example
Input
5
105 24 C 1500000000000 white
100 23 C 1500000000000 blue
105 23 A 1480000000000 pink
110 25 B 1500000000000 black
110 20 A 1300000000000 gree
Output
100 23 C 1500000000000 blue
105 23 A 1480000000000 pink
105 24 C 1500000000000 white
110 20 A 1300000000000 gree
110 25 B 1500000000000 black | instruction | 0 | 10,790 | 17 | 21,580 |
"Correct Solution:
```
class Tuple():
def __init__(self, v, w, t, d, s):
self.v = v
self.w = w
self.t = t
self.d = d
self.s = s
def main():
n = int(input())
Tuples = list()
for _ in range(n):
v, w, t, d, s = input().split()
p = Tuple(int(v), int(w), t, int(d), s)
Tuples.append(p)
Tuples.sort(key=lambda x : x.s)
Tuples.sort(key=lambda x : x.d)
Tuples.sort(key=lambda x : x.t)
Tuples.sort(key=lambda x : x.w)
Tuples.sort(key=lambda x : x.v)
for t in Tuples:
print(str(t.v) + " " + str(t.w) + " " + t.t + " " + str(t.d) + " " + t.s )
main()
``` | output | 1 | 10,790 | 17 | 21,581 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which reads $n$ items and sorts them. Each item has attributes $\\{value, weight, type, date, name\\}$ and they are represented by $\\{$ integer, integer, upper-case letter, integer, string $\\}$ respectively. Sort the items based on the following priorities.
1. first by value (ascending)
2. in case of a tie, by weight (ascending)
3. in case of a tie, by type (ascending in lexicographic order)
4. in case of a tie, by date (ascending)
5. in case of a tie, by name (ascending in lexicographic order)
Constraints
* $1 \leq n \leq 100,000$
* $0 \leq v_i \leq 1,000,000,000$
* $0 \leq w_i \leq 1,000,000,000$
* $t_i$ is a upper-case letter
* $0 \leq d_i \leq 2,000,000,000,000$
* $1 \leq $ size of $s_i \leq 20$
* $s_i \ne s_j$ if $(i \ne j)$
Input
The input is given in the following format.
$n$
$v_0 \; w_0 \; t_0 \; d_0 \; s_0$
$v_1 \; w_1 \; t_1 \; d_1 \; s_1$
:
$v_{n-1} \; w_{n-1} \; t_{n-1} \; d_{n-1} \; s_{n-1}$
In the first line, the number of items $n$. In the following $n$ lines, attributes of each item are given. $v_i \; w_i \; t_i \; d_i \; s_i$ represent value, weight, type, date and name of the $i$-th item respectively.
Output
Print attributes of each item in order. Print an item in a line and adjacency attributes should be separated by a single space.
Example
Input
5
105 24 C 1500000000000 white
100 23 C 1500000000000 blue
105 23 A 1480000000000 pink
110 25 B 1500000000000 black
110 20 A 1300000000000 gree
Output
100 23 C 1500000000000 blue
105 23 A 1480000000000 pink
105 24 C 1500000000000 white
110 20 A 1300000000000 gree
110 25 B 1500000000000 black | instruction | 0 | 10,791 | 17 | 21,582 |
"Correct Solution:
```
n = int(input())
l = []
for i in range(n):
a = input().split()
l.append((int(a[0]), int(a[1]), a[2], int(a[3]), a[4]))
l.sort()
for i in l:
print(*i)
``` | output | 1 | 10,791 | 17 | 21,583 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which reads $n$ items and sorts them. Each item has attributes $\\{value, weight, type, date, name\\}$ and they are represented by $\\{$ integer, integer, upper-case letter, integer, string $\\}$ respectively. Sort the items based on the following priorities.
1. first by value (ascending)
2. in case of a tie, by weight (ascending)
3. in case of a tie, by type (ascending in lexicographic order)
4. in case of a tie, by date (ascending)
5. in case of a tie, by name (ascending in lexicographic order)
Constraints
* $1 \leq n \leq 100,000$
* $0 \leq v_i \leq 1,000,000,000$
* $0 \leq w_i \leq 1,000,000,000$
* $t_i$ is a upper-case letter
* $0 \leq d_i \leq 2,000,000,000,000$
* $1 \leq $ size of $s_i \leq 20$
* $s_i \ne s_j$ if $(i \ne j)$
Input
The input is given in the following format.
$n$
$v_0 \; w_0 \; t_0 \; d_0 \; s_0$
$v_1 \; w_1 \; t_1 \; d_1 \; s_1$
:
$v_{n-1} \; w_{n-1} \; t_{n-1} \; d_{n-1} \; s_{n-1}$
In the first line, the number of items $n$. In the following $n$ lines, attributes of each item are given. $v_i \; w_i \; t_i \; d_i \; s_i$ represent value, weight, type, date and name of the $i$-th item respectively.
Output
Print attributes of each item in order. Print an item in a line and adjacency attributes should be separated by a single space.
Example
Input
5
105 24 C 1500000000000 white
100 23 C 1500000000000 blue
105 23 A 1480000000000 pink
110 25 B 1500000000000 black
110 20 A 1300000000000 gree
Output
100 23 C 1500000000000 blue
105 23 A 1480000000000 pink
105 24 C 1500000000000 white
110 20 A 1300000000000 gree
110 25 B 1500000000000 black
Submitted Solution:
```
tbl = []
n = int(input())
for i in range(n):
a = input().split()
tbl.append((int(a[0]),int(a[1]),a[2],int(a[3]),a[4]))
tbl.sort()
for i in tbl: print(*i)
``` | instruction | 0 | 10,792 | 17 | 21,584 |
Yes | output | 1 | 10,792 | 17 | 21,585 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which reads $n$ items and sorts them. Each item has attributes $\\{value, weight, type, date, name\\}$ and they are represented by $\\{$ integer, integer, upper-case letter, integer, string $\\}$ respectively. Sort the items based on the following priorities.
1. first by value (ascending)
2. in case of a tie, by weight (ascending)
3. in case of a tie, by type (ascending in lexicographic order)
4. in case of a tie, by date (ascending)
5. in case of a tie, by name (ascending in lexicographic order)
Constraints
* $1 \leq n \leq 100,000$
* $0 \leq v_i \leq 1,000,000,000$
* $0 \leq w_i \leq 1,000,000,000$
* $t_i$ is a upper-case letter
* $0 \leq d_i \leq 2,000,000,000,000$
* $1 \leq $ size of $s_i \leq 20$
* $s_i \ne s_j$ if $(i \ne j)$
Input
The input is given in the following format.
$n$
$v_0 \; w_0 \; t_0 \; d_0 \; s_0$
$v_1 \; w_1 \; t_1 \; d_1 \; s_1$
:
$v_{n-1} \; w_{n-1} \; t_{n-1} \; d_{n-1} \; s_{n-1}$
In the first line, the number of items $n$. In the following $n$ lines, attributes of each item are given. $v_i \; w_i \; t_i \; d_i \; s_i$ represent value, weight, type, date and name of the $i$-th item respectively.
Output
Print attributes of each item in order. Print an item in a line and adjacency attributes should be separated by a single space.
Example
Input
5
105 24 C 1500000000000 white
100 23 C 1500000000000 blue
105 23 A 1480000000000 pink
110 25 B 1500000000000 black
110 20 A 1300000000000 gree
Output
100 23 C 1500000000000 blue
105 23 A 1480000000000 pink
105 24 C 1500000000000 white
110 20 A 1300000000000 gree
110 25 B 1500000000000 black
Submitted Solution:
```
n = int(input())
a = []
for _ in range(n):
(v, w, t, d, s) = tuple(input().split())
a.append((int(v), int(w), t, int(d), s))
a.sort()
for i in a:
print(*i)
``` | instruction | 0 | 10,793 | 17 | 21,586 |
Yes | output | 1 | 10,793 | 17 | 21,587 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which reads $n$ items and sorts them. Each item has attributes $\\{value, weight, type, date, name\\}$ and they are represented by $\\{$ integer, integer, upper-case letter, integer, string $\\}$ respectively. Sort the items based on the following priorities.
1. first by value (ascending)
2. in case of a tie, by weight (ascending)
3. in case of a tie, by type (ascending in lexicographic order)
4. in case of a tie, by date (ascending)
5. in case of a tie, by name (ascending in lexicographic order)
Constraints
* $1 \leq n \leq 100,000$
* $0 \leq v_i \leq 1,000,000,000$
* $0 \leq w_i \leq 1,000,000,000$
* $t_i$ is a upper-case letter
* $0 \leq d_i \leq 2,000,000,000,000$
* $1 \leq $ size of $s_i \leq 20$
* $s_i \ne s_j$ if $(i \ne j)$
Input
The input is given in the following format.
$n$
$v_0 \; w_0 \; t_0 \; d_0 \; s_0$
$v_1 \; w_1 \; t_1 \; d_1 \; s_1$
:
$v_{n-1} \; w_{n-1} \; t_{n-1} \; d_{n-1} \; s_{n-1}$
In the first line, the number of items $n$. In the following $n$ lines, attributes of each item are given. $v_i \; w_i \; t_i \; d_i \; s_i$ represent value, weight, type, date and name of the $i$-th item respectively.
Output
Print attributes of each item in order. Print an item in a line and adjacency attributes should be separated by a single space.
Example
Input
5
105 24 C 1500000000000 white
100 23 C 1500000000000 blue
105 23 A 1480000000000 pink
110 25 B 1500000000000 black
110 20 A 1300000000000 gree
Output
100 23 C 1500000000000 blue
105 23 A 1480000000000 pink
105 24 C 1500000000000 white
110 20 A 1300000000000 gree
110 25 B 1500000000000 black
Submitted Solution:
```
import sys
if __name__ == '__main__':
n = int(input())
A = [sys.stdin.readline().split() for _ in range(n)]
B = sorted(A,key=lambda x:(int(x[0]),int(x[1]),x[2],int(x[3]),x[4]))
for i in range(n):
print(*B[i])
``` | instruction | 0 | 10,794 | 17 | 21,588 |
Yes | output | 1 | 10,794 | 17 | 21,589 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which reads $n$ items and sorts them. Each item has attributes $\\{value, weight, type, date, name\\}$ and they are represented by $\\{$ integer, integer, upper-case letter, integer, string $\\}$ respectively. Sort the items based on the following priorities.
1. first by value (ascending)
2. in case of a tie, by weight (ascending)
3. in case of a tie, by type (ascending in lexicographic order)
4. in case of a tie, by date (ascending)
5. in case of a tie, by name (ascending in lexicographic order)
Constraints
* $1 \leq n \leq 100,000$
* $0 \leq v_i \leq 1,000,000,000$
* $0 \leq w_i \leq 1,000,000,000$
* $t_i$ is a upper-case letter
* $0 \leq d_i \leq 2,000,000,000,000$
* $1 \leq $ size of $s_i \leq 20$
* $s_i \ne s_j$ if $(i \ne j)$
Input
The input is given in the following format.
$n$
$v_0 \; w_0 \; t_0 \; d_0 \; s_0$
$v_1 \; w_1 \; t_1 \; d_1 \; s_1$
:
$v_{n-1} \; w_{n-1} \; t_{n-1} \; d_{n-1} \; s_{n-1}$
In the first line, the number of items $n$. In the following $n$ lines, attributes of each item are given. $v_i \; w_i \; t_i \; d_i \; s_i$ represent value, weight, type, date and name of the $i$-th item respectively.
Output
Print attributes of each item in order. Print an item in a line and adjacency attributes should be separated by a single space.
Example
Input
5
105 24 C 1500000000000 white
100 23 C 1500000000000 blue
105 23 A 1480000000000 pink
110 25 B 1500000000000 black
110 20 A 1300000000000 gree
Output
100 23 C 1500000000000 blue
105 23 A 1480000000000 pink
105 24 C 1500000000000 white
110 20 A 1300000000000 gree
110 25 B 1500000000000 black
Submitted Solution:
```
N = int(input())
I = [input().split() for _ in range(N)]
for i in range(N):
I[i][0] = int(I[i][0])
I[i][1] = int(I[i][1])
I[i][3] = int(I[i][3])
I.sort()
for i in I:
print(*i)
``` | instruction | 0 | 10,795 | 17 | 21,590 |
Yes | output | 1 | 10,795 | 17 | 21,591 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which reads $n$ items and sorts them. Each item has attributes $\\{value, weight, type, date, name\\}$ and they are represented by $\\{$ integer, integer, upper-case letter, integer, string $\\}$ respectively. Sort the items based on the following priorities.
1. first by value (ascending)
2. in case of a tie, by weight (ascending)
3. in case of a tie, by type (ascending in lexicographic order)
4. in case of a tie, by date (ascending)
5. in case of a tie, by name (ascending in lexicographic order)
Constraints
* $1 \leq n \leq 100,000$
* $0 \leq v_i \leq 1,000,000,000$
* $0 \leq w_i \leq 1,000,000,000$
* $t_i$ is a upper-case letter
* $0 \leq d_i \leq 2,000,000,000,000$
* $1 \leq $ size of $s_i \leq 20$
* $s_i \ne s_j$ if $(i \ne j)$
Input
The input is given in the following format.
$n$
$v_0 \; w_0 \; t_0 \; d_0 \; s_0$
$v_1 \; w_1 \; t_1 \; d_1 \; s_1$
:
$v_{n-1} \; w_{n-1} \; t_{n-1} \; d_{n-1} \; s_{n-1}$
In the first line, the number of items $n$. In the following $n$ lines, attributes of each item are given. $v_i \; w_i \; t_i \; d_i \; s_i$ represent value, weight, type, date and name of the $i$-th item respectively.
Output
Print attributes of each item in order. Print an item in a line and adjacency attributes should be separated by a single space.
Example
Input
5
105 24 C 1500000000000 white
100 23 C 1500000000000 blue
105 23 A 1480000000000 pink
110 25 B 1500000000000 black
110 20 A 1300000000000 gree
Output
100 23 C 1500000000000 blue
105 23 A 1480000000000 pink
105 24 C 1500000000000 white
110 20 A 1300000000000 gree
110 25 B 1500000000000 black
Submitted Solution:
```
n = int(input())
items = [input().split(' ') for i in range(n)]
items = sorted(items)
for item in items:
print(' '.join(item))
``` | instruction | 0 | 10,796 | 17 | 21,592 |
No | output | 1 | 10,796 | 17 | 21,593 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After practice competition, participant number i got a score of ai. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question.
Input
The single line contains six integers a1, ..., a6 (0 ≤ ai ≤ 1000) — scores of the participants
Output
Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
Examples
Input
1 3 2 1 2 1
Output
YES
Input
1 1 1 1 1 99
Output
NO
Note
In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5.
In the second sample, score of participant number 6 is too high: his team score will be definitely greater. | instruction | 0 | 11,333 | 17 | 22,666 |
Tags: brute force
Correct Solution:
```
import itertools
a = [int(x) for x in input().split()]
index = list(range(6))
b = list(itertools.combinations(index, 3))
c = len(b)
for z in range(c):
for x in range(z+1, c):
if not any([y in b[x] for y in b[z]]):
if sum(a[y] for y in b[z]) == sum(a[y] for y in b[x]):
print('yes')
quit()
print('no')
``` | output | 1 | 11,333 | 17 | 22,667 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After practice competition, participant number i got a score of ai. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question.
Input
The single line contains six integers a1, ..., a6 (0 ≤ ai ≤ 1000) — scores of the participants
Output
Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
Examples
Input
1 3 2 1 2 1
Output
YES
Input
1 1 1 1 1 99
Output
NO
Note
In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5.
In the second sample, score of participant number 6 is too high: his team score will be definitely greater. | instruction | 0 | 11,334 | 17 | 22,668 |
Tags: brute force
Correct Solution:
```
n = list(map(int,input().split()))
#n = int(input())
x = len(n)
checked = [False,False,False,False,False,False]
def check(cur1,cur2):
if sum(checked)==6:
if cur1==cur2:
print("YES")
exit()
for i in range(x):
if checked[i] == False:
checked[i] = True
for j in range(x):
if checked[j] == False:
checked[j] = True
check(cur1+n[i],cur2+n[j])
checked[j]=False
checked[i]=False
check(0,0)
print("NO")
``` | output | 1 | 11,334 | 17 | 22,669 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After practice competition, participant number i got a score of ai. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question.
Input
The single line contains six integers a1, ..., a6 (0 ≤ ai ≤ 1000) — scores of the participants
Output
Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
Examples
Input
1 3 2 1 2 1
Output
YES
Input
1 1 1 1 1 99
Output
NO
Note
In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5.
In the second sample, score of participant number 6 is too high: his team score will be definitely greater. | instruction | 0 | 11,335 | 17 | 22,670 |
Tags: brute force
Correct Solution:
```
from itertools import combinations
l=list(map(int,input().split()))
s=sum(l);f=0
if s%2!=0:
print("NO")
f=1
else:
for i in combinations(l, 3):
if sum(i)==s//2:
print("YES")
f=1
break
if f==0:print("NO")
``` | output | 1 | 11,335 | 17 | 22,671 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.