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 tags and a correct Python 3 solution for this coding contest problem.
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate.
The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.
At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.
Determine who will win the elections.
Input
The first line of the input contains two integers n, m (1 ≤ n, m ≤ 100) — the number of candidates and of cities, respectively.
Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≤ j ≤ n, 1 ≤ i ≤ m, 0 ≤ aij ≤ 109) denotes the number of votes for candidate j in city i.
It is guaranteed that the total number of people in all the cities does not exceed 109.
Output
Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.
Examples
Input
3 3
1 2 3
2 3 1
1 2 1
Output
2
Input
3 4
10 10 3
5 1 6
2 2 2
1 5 7
Output
1
Note
Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.
Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index. | instruction | 0 | 36,511 | 17 | 73,022 |
Tags: implementation
Correct Solution:
```
n,m=map(int,input().split())
a=list()
for i in range(m):
a.append([int(i) for i in input().split()])
if(n==1):
print(1)
else:
if(m==1):
x=1
y=0
for i in range(n):
if(y<a[0][i]):
y=a[0][i]
x=i+1
print(x)
else:
k=[0]*m
for i in range(m):
x=-1
for j in range(n):
if(a[i][j]>x):
x=a[i][j]
k[i]=j+1
k=sorted(k)
h,x,y=1,0,1
for i in range(len(k)-1):
if(k[i]==k[i+1]):
h+=1
if(x<h):
x=h
y=k[i]
else:
h=1
print(y)
``` | output | 1 | 36,511 | 17 | 73,023 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate.
The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.
At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.
Determine who will win the elections.
Input
The first line of the input contains two integers n, m (1 ≤ n, m ≤ 100) — the number of candidates and of cities, respectively.
Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≤ j ≤ n, 1 ≤ i ≤ m, 0 ≤ aij ≤ 109) denotes the number of votes for candidate j in city i.
It is guaranteed that the total number of people in all the cities does not exceed 109.
Output
Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.
Examples
Input
3 3
1 2 3
2 3 1
1 2 1
Output
2
Input
3 4
10 10 3
5 1 6
2 2 2
1 5 7
Output
1
Note
Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.
Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
Submitted Solution:
```
n,m = [int(i) for i in input().split()]
city = [0]*n
for i in range(m):
vote = [int(j) for j in input().split()]
maximum1 = max(vote)
for j in range(n):
if vote[j] == maximum1:
city[j] += 1
break
#print(city)
maximum2 = max(city)
for k in range(n):
if city[k] == maximum2:
print(k+1)
break
``` | instruction | 0 | 36,512 | 17 | 73,024 |
Yes | output | 1 | 36,512 | 17 | 73,025 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate.
The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.
At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.
Determine who will win the elections.
Input
The first line of the input contains two integers n, m (1 ≤ n, m ≤ 100) — the number of candidates and of cities, respectively.
Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≤ j ≤ n, 1 ≤ i ≤ m, 0 ≤ aij ≤ 109) denotes the number of votes for candidate j in city i.
It is guaranteed that the total number of people in all the cities does not exceed 109.
Output
Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.
Examples
Input
3 3
1 2 3
2 3 1
1 2 1
Output
2
Input
3 4
10 10 3
5 1 6
2 2 2
1 5 7
Output
1
Note
Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.
Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
Submitted Solution:
```
x, y = list(map(int, input().split()))
lista = []
ans = [0]*x
for i in range(y):
lista.append(list(map(int, input().split())))
for i in range(y):
ans[lista[i].index(max(lista[i]))]+=1
print(ans.index(max(ans))+1)
``` | instruction | 0 | 36,513 | 17 | 73,026 |
Yes | output | 1 | 36,513 | 17 | 73,027 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate.
The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.
At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.
Determine who will win the elections.
Input
The first line of the input contains two integers n, m (1 ≤ n, m ≤ 100) — the number of candidates and of cities, respectively.
Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≤ j ≤ n, 1 ≤ i ≤ m, 0 ≤ aij ≤ 109) denotes the number of votes for candidate j in city i.
It is guaranteed that the total number of people in all the cities does not exceed 109.
Output
Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.
Examples
Input
3 3
1 2 3
2 3 1
1 2 1
Output
2
Input
3 4
10 10 3
5 1 6
2 2 2
1 5 7
Output
1
Note
Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.
Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
Submitted Solution:
```
n, m = map(int, input().split(' '))
a = []
for i in range(m):
a.append(list(map(int, input().split(' '))))
v = [0]*n
for aa in a:
v[aa.index(max(aa))] += 1
print(v.index(max(v))+1)
``` | instruction | 0 | 36,514 | 17 | 73,028 |
Yes | output | 1 | 36,514 | 17 | 73,029 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate.
The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.
At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.
Determine who will win the elections.
Input
The first line of the input contains two integers n, m (1 ≤ n, m ≤ 100) — the number of candidates and of cities, respectively.
Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≤ j ≤ n, 1 ≤ i ≤ m, 0 ≤ aij ≤ 109) denotes the number of votes for candidate j in city i.
It is guaranteed that the total number of people in all the cities does not exceed 109.
Output
Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.
Examples
Input
3 3
1 2 3
2 3 1
1 2 1
Output
2
Input
3 4
10 10 3
5 1 6
2 2 2
1 5 7
Output
1
Note
Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.
Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
Submitted Solution:
```
n,m=input().split()
n=int(n)
m=int(m)
l=[]
for i in range(m):
l1=input().split()
for j in range(n):
l1[j]=int(l1[j])
l.append(l1)
r=[]
for i in range(m):
k=0
p=0
for j in range(n):
if(l[i][j]>k):
k=l[i][j]
p=j
r.append(p)
s=[0]*n
for i in range(n):
if(s[i]==0):
s[i]=r.count(i)
q=max(s)
for i in range(n):
if(s[i]==q):
print(i+1)
break
``` | instruction | 0 | 36,515 | 17 | 73,030 |
Yes | output | 1 | 36,515 | 17 | 73,031 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate.
The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.
At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.
Determine who will win the elections.
Input
The first line of the input contains two integers n, m (1 ≤ n, m ≤ 100) — the number of candidates and of cities, respectively.
Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≤ j ≤ n, 1 ≤ i ≤ m, 0 ≤ aij ≤ 109) denotes the number of votes for candidate j in city i.
It is guaranteed that the total number of people in all the cities does not exceed 109.
Output
Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.
Examples
Input
3 3
1 2 3
2 3 1
1 2 1
Output
2
Input
3 4
10 10 3
5 1 6
2 2 2
1 5 7
Output
1
Note
Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.
Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
Submitted Solution:
```
n,m=list(map(int, input().split()))
ans=[]
for i in range(m):
ls=list(map(int, input().split()))
ans.append(ls);
res = list()
for j in range(0, len(ans[0])):
tmp = 0
for i in range(0, len(ans)):
tmp = tmp + ans[i][j]
res.append(tmp)
print(res.index(max(res))+1)
``` | instruction | 0 | 36,516 | 17 | 73,032 |
No | output | 1 | 36,516 | 17 | 73,033 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate.
The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.
At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.
Determine who will win the elections.
Input
The first line of the input contains two integers n, m (1 ≤ n, m ≤ 100) — the number of candidates and of cities, respectively.
Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≤ j ≤ n, 1 ≤ i ≤ m, 0 ≤ aij ≤ 109) denotes the number of votes for candidate j in city i.
It is guaranteed that the total number of people in all the cities does not exceed 109.
Output
Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.
Examples
Input
3 3
1 2 3
2 3 1
1 2 1
Output
2
Input
3 4
10 10 3
5 1 6
2 2 2
1 5 7
Output
1
Note
Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.
Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
Submitted Solution:
```
x,y=[int(x) for x in input().split()]
c=[0]*x
for i in range(y):
z=[int(a) for a in input().split()]
a=z.index(max(z))
c[a]=c[a]+1
print(c)
print(c.index(max(c))+1)
``` | instruction | 0 | 36,517 | 17 | 73,034 |
No | output | 1 | 36,517 | 17 | 73,035 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate.
The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.
At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.
Determine who will win the elections.
Input
The first line of the input contains two integers n, m (1 ≤ n, m ≤ 100) — the number of candidates and of cities, respectively.
Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≤ j ≤ n, 1 ≤ i ≤ m, 0 ≤ aij ≤ 109) denotes the number of votes for candidate j in city i.
It is guaranteed that the total number of people in all the cities does not exceed 109.
Output
Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.
Examples
Input
3 3
1 2 3
2 3 1
1 2 1
Output
2
Input
3 4
10 10 3
5 1 6
2 2 2
1 5 7
Output
1
Note
Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.
Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
Submitted Solution:
```
def determine_winner(cities_data):
cities_winners = []
winners = []
for i in range(len(cities_data)):
max_votes = 0
for j in range(len(cities_data[i])):
if cities_data[i][j] >= max_votes:
max_votes = cities_data[i][j]
for z in range(len(cities_data[i])):
if cities_data[i][z] == max_votes:
winners.append(z)
break
element = 0
count = 0
for i in range(len(winners)):
temp_element = winners[i]
temp_count = 0
for j in range(len(winners)):
if winners[j] == temp_element:
temp_count += 1
if temp_count > count:
count = temp_count
element = temp_element
return element+1
#return max(set(winners), key=winners.count)+1
def convert_into_int(arr):
for i in range(len(arr)):
arr[i] = int(arr[i])
return arr
inputs_nums = input().split(' ')
inputs_nums = convert_into_int(inputs_nums)
inputs_data = []
for i in range(inputs_nums[1]):
input_data = input().split(' ')
input_data = convert_into_int(input_data)
inputs_data.append(input_data)
print(determine_winner(inputs_data))
``` | instruction | 0 | 36,518 | 17 | 73,036 |
No | output | 1 | 36,518 | 17 | 73,037 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate.
The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.
At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.
Determine who will win the elections.
Input
The first line of the input contains two integers n, m (1 ≤ n, m ≤ 100) — the number of candidates and of cities, respectively.
Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≤ j ≤ n, 1 ≤ i ≤ m, 0 ≤ aij ≤ 109) denotes the number of votes for candidate j in city i.
It is guaranteed that the total number of people in all the cities does not exceed 109.
Output
Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.
Examples
Input
3 3
1 2 3
2 3 1
1 2 1
Output
2
Input
3 4
10 10 3
5 1 6
2 2 2
1 5 7
Output
1
Note
Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.
Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
Submitted Solution:
```
[n,m] = list(map(int, input().split(" ")))
v1 = []
for i in range(m):
l = list(map(int, input().split(" ")))
v1.append(l.index(max(l))+1)
v2 = list(map(lambda x: v1.count(x), v1))
r = v2.index(max(v2))
print(v1[r])
``` | instruction | 0 | 36,519 | 17 | 73,038 |
No | output | 1 | 36,519 | 17 | 73,039 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A group of n friends enjoys playing popular video game Toda 2. There is a rating system describing skill level of each player, initially the rating of the i-th friend is ri.
The friends decided to take part in the championship as a team. But they should have equal ratings to be allowed to compose a single team consisting of all n friends. So the friends are faced with the problem: how to make all their ratings equal.
One way to change ratings is to willingly lose in some matches. Friends can form a party consisting of two to five (but not more than n) friends and play a match in the game. When the party loses, the rating of each of its members decreases by 1. A rating can't become negative, so ri = 0 doesn't change after losing.
The friends can take part in multiple matches, each time making a party from any subset of friends (but remember about constraints on party size: from 2 to 5 members).
The friends want to make their ratings equal but as high as possible.
Help the friends develop a strategy of losing the matches so that all their ratings become equal and the resulting rating is maximum possible.
Input
The first line contains a single integer n (2 ≤ n ≤ 100) — the number of friends.
The second line contains n non-negative integers r1, r2, ..., rn (0 ≤ ri ≤ 100), where ri is the initial rating of the i-th friend.
Output
In the first line, print a single integer R — the final rating of each of the friends.
In the second line, print integer t — the number of matches the friends have to play. Each of the following t lines should contain n characters '0' or '1', where the j-th character of the i-th line is equal to:
* '0', if friend j should not play in match i,
* '1', if friend j should play in match i.
Each line should contain between two and five characters '1', inclusive.
The value t should not exceed 104, it is guaranteed that such solution exists.
Remember that you shouldn't minimize the value t, but you should maximize R. If there are multiple solutions, print any of them.
Examples
Input
5
4 5 1 7 4
Output
1
8
01010
00011
01010
10010
00011
11000
00011
11000
Input
2
1 2
Output
0
2
11
11
Input
3
1 1 1
Output
1
0 | instruction | 0 | 36,557 | 17 | 73,114 |
Tags: greedy, implementation
Correct Solution:
```
n = int(input())
L = list(map(int, input().split()))
ans = 0
M = []
while max(L) != min(L):
ans += 1
k = max(L)
if L.count(k) == 3:
s = ''
for i in range(len(L)):
if L[i] == k:
s += '1'
L[i] -= 1
else:
s += '0'
M.append(s)
else:
max_1 = 0
max_2 = 1
if L[max_1] < L[max_2]:
max_1, max_2 = max_2, max_1
for i in range(2, n):
if L[i] > L[max_1]:
max_2, max_1 = max_1, i
elif L[i] > L[max_2]:
max_2 = i
s = ''
for i in range(n):
if i == max_1 or i == max_2:
s += '1'
else:
s += '0'
M.append(s)
L[max_1] -= 1
if L[max_1] < 0:
L[max_1] = 0
L[max_2] -= 1
if L[max_2] < 0:
L[max_2] = 0
print(max(L))
print(ans)
for i in M:
print(i)
# Made By Mostafa_Khaled
``` | output | 1 | 36,557 | 17 | 73,115 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A group of n friends enjoys playing popular video game Toda 2. There is a rating system describing skill level of each player, initially the rating of the i-th friend is ri.
The friends decided to take part in the championship as a team. But they should have equal ratings to be allowed to compose a single team consisting of all n friends. So the friends are faced with the problem: how to make all their ratings equal.
One way to change ratings is to willingly lose in some matches. Friends can form a party consisting of two to five (but not more than n) friends and play a match in the game. When the party loses, the rating of each of its members decreases by 1. A rating can't become negative, so ri = 0 doesn't change after losing.
The friends can take part in multiple matches, each time making a party from any subset of friends (but remember about constraints on party size: from 2 to 5 members).
The friends want to make their ratings equal but as high as possible.
Help the friends develop a strategy of losing the matches so that all their ratings become equal and the resulting rating is maximum possible.
Input
The first line contains a single integer n (2 ≤ n ≤ 100) — the number of friends.
The second line contains n non-negative integers r1, r2, ..., rn (0 ≤ ri ≤ 100), where ri is the initial rating of the i-th friend.
Output
In the first line, print a single integer R — the final rating of each of the friends.
In the second line, print integer t — the number of matches the friends have to play. Each of the following t lines should contain n characters '0' or '1', where the j-th character of the i-th line is equal to:
* '0', if friend j should not play in match i,
* '1', if friend j should play in match i.
Each line should contain between two and five characters '1', inclusive.
The value t should not exceed 104, it is guaranteed that such solution exists.
Remember that you shouldn't minimize the value t, but you should maximize R. If there are multiple solutions, print any of them.
Examples
Input
5
4 5 1 7 4
Output
1
8
01010
00011
01010
10010
00011
11000
00011
11000
Input
2
1 2
Output
0
2
11
11
Input
3
1 1 1
Output
1
0 | instruction | 0 | 36,558 | 17 | 73,116 |
Tags: greedy, implementation
Correct Solution:
```
import collections
def temp(list1):
list2 = list(list1)
list3=[]
cnt = collections.Counter()
for i in range(len(list1)):
cnt[list1[i]]+=1
tep = max(list1)
if cnt[tep] != 1:
if cnt[tep] <= 5:
for i in range(5):
if tep in list2:
list3.append(list2.index(tep))
list2[list2.index(tep)] = -1
else:
break
else:
for i in range(4):
if tep in list2:
list3.append(list2.index(tep))
list2[list2.index(tep)] = -1
else:
break
else:
list3.append(list1.index(tep))
list2.remove(tep)
list3.append(list1.index(max(list2)))
return list3
n = int(input())
intgrade = list(map(int, input().split()))
bitlists=[]
if len(set(intgrade)) == 1:
print(intgrade[0])
print(0)
else:
while len(set(intgrade)) != 1:
listA = temp(intgrade)
bitlist=''
for i in range(len(listA)):
if intgrade[listA[i]] > 0:
intgrade[listA[i]]-=1
for i in range(n):
if i in listA:
bitlist+="1"
else:
bitlist+="0"
bitlists.append(bitlist)
print(intgrade[0])
print(len(bitlists))
for i in range(len(bitlists)):
print(bitlists[i])
``` | output | 1 | 36,558 | 17 | 73,117 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A group of n friends enjoys playing popular video game Toda 2. There is a rating system describing skill level of each player, initially the rating of the i-th friend is ri.
The friends decided to take part in the championship as a team. But they should have equal ratings to be allowed to compose a single team consisting of all n friends. So the friends are faced with the problem: how to make all their ratings equal.
One way to change ratings is to willingly lose in some matches. Friends can form a party consisting of two to five (but not more than n) friends and play a match in the game. When the party loses, the rating of each of its members decreases by 1. A rating can't become negative, so ri = 0 doesn't change after losing.
The friends can take part in multiple matches, each time making a party from any subset of friends (but remember about constraints on party size: from 2 to 5 members).
The friends want to make their ratings equal but as high as possible.
Help the friends develop a strategy of losing the matches so that all their ratings become equal and the resulting rating is maximum possible.
Input
The first line contains a single integer n (2 ≤ n ≤ 100) — the number of friends.
The second line contains n non-negative integers r1, r2, ..., rn (0 ≤ ri ≤ 100), where ri is the initial rating of the i-th friend.
Output
In the first line, print a single integer R — the final rating of each of the friends.
In the second line, print integer t — the number of matches the friends have to play. Each of the following t lines should contain n characters '0' or '1', where the j-th character of the i-th line is equal to:
* '0', if friend j should not play in match i,
* '1', if friend j should play in match i.
Each line should contain between two and five characters '1', inclusive.
The value t should not exceed 104, it is guaranteed that such solution exists.
Remember that you shouldn't minimize the value t, but you should maximize R. If there are multiple solutions, print any of them.
Examples
Input
5
4 5 1 7 4
Output
1
8
01010
00011
01010
10010
00011
11000
00011
11000
Input
2
1 2
Output
0
2
11
11
Input
3
1 1 1
Output
1
0 | instruction | 0 | 36,559 | 17 | 73,118 |
Tags: greedy, implementation
Correct Solution:
```
# coding=utf-8
"""Codeforces 730a solution."""
from operator import itemgetter
class CodeforcesTask730ASolution:
def __init__(self):
self.result = ''
self.players = 0
self.rating = []
def read_input(self):
self.players = int(input())
self.rating = [int(x) for x in input().split(" ")]
def process_task(self):
if self.players > 2:
moves = []
players = [[x + 1, self.rating[x]] for x in range(self.players)]
players.sort(key=itemgetter(1), reverse=True)
while players[1][1] != players[-1][1]:
players[0][1] = max(0, players[0][1] - 1)
players[1][1] = max(0, players[1][1] - 1)
moves.append([players[0][0], players[1][0]])
players.sort(key=itemgetter(1), reverse=True)
if players[0][1] != players[-1][1]:
added = False
for m in moves:
if not players[0][0] in m:
m.append(players[0][0])
players[0][1] = max(0, players[0][1] - 1)
added = True
break
if not added:
#print("edge case 1")
#print(players)
moves.append([players[-1][0], players[0][0]])
players[0][1] = max(0, players[0][1] - 1)
players[-1][1] = max(0, players[-1][1] - 1)
players.sort(key=itemgetter(1), reverse=True)
while players[0][1] != players[-1][1] and players[1][1] != players[-1][1]:
#print(players)
players[0][1] = max(0, players[0][1] - 1)
players[1][1] = max(0, players[1][1] - 1)
moves.append([players[0][0], players[1][0]])
players.sort(key=itemgetter(1), reverse=True)
if players[0][1] != players[-1][1]:
added = False
for m in moves:
if not players[0][0] in m:
m.append(players[0][0])
players[0][1] = max(0, players[0][1] - 1)
added = True
break
if not added:
#print(players)
#print("edge case 2")
moves.append([players[-1][0], players[0][0]])
players[0][1] = max(0, players[0][1] - 1)
players[-1][1] = max(0, players[-1][1] - 1)
players.sort(key=itemgetter(1), reverse=True)
while players[0][1] != players[-1][1] and players[1][1] != players[-1][1]:
# print(players)
players[0][1] = max(0, players[0][1] - 1)
players[1][1] = max(0, players[1][1] - 1)
moves.append([players[0][0], players[1][0]])
players.sort(key=itemgetter(1), reverse=True)
if players[0][1] != players[-1][1]:
added = False
for m in moves:
if not players[0][0] in m:
m.append(players[0][0])
players[0][1] = max(0, players[0][1] - 1)
added = True
break
if not added:
# print(players)
#print("edge case 3")
moves.append([players[-1][0], players[0][0]])
players[0][1] = max(0, players[0][1] - 1)
players[-1][1] = max(0, players[-1][1] - 1)
players.sort(key=itemgetter(1), reverse=True)
while players[0][1] != players[-1][1] and players[1][1] != players[-1][1]:
# print(players)
players[0][1] = max(0, players[0][1] - 1)
players[1][1] = max(0, players[1][1] - 1)
moves.append([players[0][0], players[1][0]])
players.sort(key=itemgetter(1), reverse=True)
if players[0][1] != players[-1][1]:
added = False
for m in moves:
if not players[0][0] in m:
m.append(players[0][0])
players[0][1] = max(0, players[0][1] - 1)
added = True
break
if not added:
# print(players)
#print("edge case 4")
moves.append([players[-1][0], players[0][0]])
players[0][1] = max(0, players[0][1] - 1)
players[-1][1] = max(0, players[-1][1] - 1)
players.sort(key=itemgetter(1), reverse=True)
while players[0][1] != players[-1][1] and players[1][1] != players[-1][1]:
# print(players)
players[0][1] = max(0, players[0][1] - 1)
players[1][1] = max(0, players[1][1] - 1)
moves.append([players[0][0], players[1][0]])
players.sort(key=itemgetter(1), reverse=True)
if players[0][1] != players[-1][1]:
added = False
for m in moves:
if not players[0][0] in m:
m.append(players[0][0])
players[0][1] = max(0, players[0][1] - 1)
added = True
break
if not added:
# print(players)
print("edge case 5")
players.sort(key=itemgetter(1), reverse=True)
print(players[-1][1])
print(len(moves))
for m in moves:
print("".join(["1" if x + 1 in m else "0" for x in range(self.players)]))
else:
if self.rating[0] == self.rating[1]:
print(self.rating[0])
print("0")
else:
print("0")
print(max(self.rating))
for x in range(max(self.rating)):
print("11")
def get_result(self):
return self.result
if __name__ == "__main__":
Solution = CodeforcesTask730ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())
``` | output | 1 | 36,559 | 17 | 73,119 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A group of n friends enjoys playing popular video game Toda 2. There is a rating system describing skill level of each player, initially the rating of the i-th friend is ri.
The friends decided to take part in the championship as a team. But they should have equal ratings to be allowed to compose a single team consisting of all n friends. So the friends are faced with the problem: how to make all their ratings equal.
One way to change ratings is to willingly lose in some matches. Friends can form a party consisting of two to five (but not more than n) friends and play a match in the game. When the party loses, the rating of each of its members decreases by 1. A rating can't become negative, so ri = 0 doesn't change after losing.
The friends can take part in multiple matches, each time making a party from any subset of friends (but remember about constraints on party size: from 2 to 5 members).
The friends want to make their ratings equal but as high as possible.
Help the friends develop a strategy of losing the matches so that all their ratings become equal and the resulting rating is maximum possible.
Input
The first line contains a single integer n (2 ≤ n ≤ 100) — the number of friends.
The second line contains n non-negative integers r1, r2, ..., rn (0 ≤ ri ≤ 100), where ri is the initial rating of the i-th friend.
Output
In the first line, print a single integer R — the final rating of each of the friends.
In the second line, print integer t — the number of matches the friends have to play. Each of the following t lines should contain n characters '0' or '1', where the j-th character of the i-th line is equal to:
* '0', if friend j should not play in match i,
* '1', if friend j should play in match i.
Each line should contain between two and five characters '1', inclusive.
The value t should not exceed 104, it is guaranteed that such solution exists.
Remember that you shouldn't minimize the value t, but you should maximize R. If there are multiple solutions, print any of them.
Examples
Input
5
4 5 1 7 4
Output
1
8
01010
00011
01010
10010
00011
11000
00011
11000
Input
2
1 2
Output
0
2
11
11
Input
3
1 1 1
Output
1
0 | instruction | 0 | 36,560 | 17 | 73,120 |
Tags: greedy, implementation
Correct Solution:
```
n = int(input())
d = list(map(int, input().split()))
answer = []
while not all(i == d[0] for i in d):
i = max(range(n), key = lambda x: d[x])
max1 = d[i]
d[i] = -1
j = max(range(n), key = lambda x: d[x])
max2 = d[j]
d[j] = -1
z = max(range(n), key = lambda x: d[x])
if max1 == max2 and max1 == d[z]:
for t in range(n):
if t != i and t != j and t != z:
break
if all(d[v] == d[t] for v in range(n) if v != i and v != j and v != z) and d[t] < max1:
d[i] = max1 -1
d[j] = max2 - 1
d[z] -= 1
answer.append(''.join('1' if k == i or k == j or k ==z else '0' for k in range(n)))
continue
#print(i, j, max1, max2)
d[i] = max(max1 - 1, 0)
d[j] = max(max2 - 1, 0)
answer.append(''.join('1' if k == i or k == j else '0' for k in range(n)))
print(d[0])
print(len(answer))
for i in answer:
print(i)
``` | output | 1 | 36,560 | 17 | 73,121 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A group of n friends enjoys playing popular video game Toda 2. There is a rating system describing skill level of each player, initially the rating of the i-th friend is ri.
The friends decided to take part in the championship as a team. But they should have equal ratings to be allowed to compose a single team consisting of all n friends. So the friends are faced with the problem: how to make all their ratings equal.
One way to change ratings is to willingly lose in some matches. Friends can form a party consisting of two to five (but not more than n) friends and play a match in the game. When the party loses, the rating of each of its members decreases by 1. A rating can't become negative, so ri = 0 doesn't change after losing.
The friends can take part in multiple matches, each time making a party from any subset of friends (but remember about constraints on party size: from 2 to 5 members).
The friends want to make their ratings equal but as high as possible.
Help the friends develop a strategy of losing the matches so that all their ratings become equal and the resulting rating is maximum possible.
Input
The first line contains a single integer n (2 ≤ n ≤ 100) — the number of friends.
The second line contains n non-negative integers r1, r2, ..., rn (0 ≤ ri ≤ 100), where ri is the initial rating of the i-th friend.
Output
In the first line, print a single integer R — the final rating of each of the friends.
In the second line, print integer t — the number of matches the friends have to play. Each of the following t lines should contain n characters '0' or '1', where the j-th character of the i-th line is equal to:
* '0', if friend j should not play in match i,
* '1', if friend j should play in match i.
Each line should contain between two and five characters '1', inclusive.
The value t should not exceed 104, it is guaranteed that such solution exists.
Remember that you shouldn't minimize the value t, but you should maximize R. If there are multiple solutions, print any of them.
Examples
Input
5
4 5 1 7 4
Output
1
8
01010
00011
01010
10010
00011
11000
00011
11000
Input
2
1 2
Output
0
2
11
11
Input
3
1 1 1
Output
1
0 | instruction | 0 | 36,561 | 17 | 73,122 |
Tags: greedy, implementation
Correct Solution:
```
# https://codeforces.com/problemset/problem/730/A
#
import heapq
def solve_for_0(d, max_, ans):
pos_M = list(d[max_])[0]
pos_m = list(d[0])[0]
for _ in range(max_):
ans.append([pos_M, pos_m])
def solve_one_seg(d, max_, min_, ans):
seg = list(d[max_])
n = len(seg)
if n <= 5:
for _ in range(max_ - min_):
ans.append(seg)
else:
ori = []
for i in range(0, n, 2):
if i == n-1:
ori[-1].append(seg[i])
else:
ori.append([seg[i], seg[i+1]])
for _ in range(max_ - min_):
ans.extend(ori)
def push(d, x, val, i):
if x not in d:
d[x] = set()
if val == 1:
d[x].add(i)
else:
d[x].remove(i)
if len(d[x]) == 0:
del d[x]
def check(d):
if len(d) != 2:
return 'none', None
max_ = max(list(d.keys()))
min_ = min(list(d.keys()))
if len(d[max_]) >= 2:
return 'seg', [max_, min_]
elif min_ == 0:
return '0', [max_]
return 'none', None
def pr(ans, n):
print(len(ans))
arr = [[0]*n for _ in range(len(ans))]
for i, val in enumerate(ans):
for ind in val:
arr[i][ind] = 1
S = ''
for s in arr:
S += ''.join([str(x) for x in s])
S += '\n'
print(S)
#5
#4 5 1 7 4
n = int(input())#len(arr)
arr = list(map(int, input().split()))#[1,3,1,3,2,3,2,3,2,3,2,3,2,3]
ans = []
Q = []
d = {}
for i, x in enumerate(arr):
push(d, x, 1, i)
heapq.heappush(Q, (-x, x, i))
if len(d) == 1:
print(list(d.keys())[0])
print(0)
else:
while True:
type_, arg = check(d)
if type_ == 'none':
val1, num1, i1 = heapq.heappop(Q)
val2, num2, i2 = heapq.heappop(Q)
push(d, num1, -1, i1)
push(d, num2, -1, i2)
ans.append([i1, i2])
new1 = max(0, num1-1)
new2 = max(0, num2-1)
heapq.heappush(Q, (-new1, new1, i1))
heapq.heappush(Q, (-new2, new2, i2))
push(d, new1, 1, i1)
push(d, new2, 1, i2)
elif type_ == 'seg':
max_, min_ = arg[0], arg[1]
solve_one_seg(d, max_, min_, ans)
print(min_)
pr(ans, n)
break
else:
max_ = arg[0]
solve_for_0(d, max_, ans)
print(0)
pr(ans, n)
break
``` | output | 1 | 36,561 | 17 | 73,123 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A group of n friends enjoys playing popular video game Toda 2. There is a rating system describing skill level of each player, initially the rating of the i-th friend is ri.
The friends decided to take part in the championship as a team. But they should have equal ratings to be allowed to compose a single team consisting of all n friends. So the friends are faced with the problem: how to make all their ratings equal.
One way to change ratings is to willingly lose in some matches. Friends can form a party consisting of two to five (but not more than n) friends and play a match in the game. When the party loses, the rating of each of its members decreases by 1. A rating can't become negative, so ri = 0 doesn't change after losing.
The friends can take part in multiple matches, each time making a party from any subset of friends (but remember about constraints on party size: from 2 to 5 members).
The friends want to make their ratings equal but as high as possible.
Help the friends develop a strategy of losing the matches so that all their ratings become equal and the resulting rating is maximum possible.
Input
The first line contains a single integer n (2 ≤ n ≤ 100) — the number of friends.
The second line contains n non-negative integers r1, r2, ..., rn (0 ≤ ri ≤ 100), where ri is the initial rating of the i-th friend.
Output
In the first line, print a single integer R — the final rating of each of the friends.
In the second line, print integer t — the number of matches the friends have to play. Each of the following t lines should contain n characters '0' or '1', where the j-th character of the i-th line is equal to:
* '0', if friend j should not play in match i,
* '1', if friend j should play in match i.
Each line should contain between two and five characters '1', inclusive.
The value t should not exceed 104, it is guaranteed that such solution exists.
Remember that you shouldn't minimize the value t, but you should maximize R. If there are multiple solutions, print any of them.
Examples
Input
5
4 5 1 7 4
Output
1
8
01010
00011
01010
10010
00011
11000
00011
11000
Input
2
1 2
Output
0
2
11
11
Input
3
1 1 1
Output
1
0 | instruction | 0 | 36,562 | 17 | 73,124 |
Tags: greedy, implementation
Correct Solution:
```
n = int(input())
L = list(map(int, input().split()))
ans = 0
M = []
while max(L) != min(L):
ans += 1
k = max(L)
if L.count(k) == 3:
s = ''
for i in range(len(L)):
if L[i] == k:
s += '1'
L[i] -= 1
else:
s += '0'
M.append(s)
else:
max_1 = 0
max_2 = 1
if L[max_1] < L[max_2]:
max_1, max_2 = max_2, max_1
for i in range(2, n):
if L[i] > L[max_1]:
max_2, max_1 = max_1, i
elif L[i] > L[max_2]:
max_2 = i
s = ''
for i in range(n):
if i == max_1 or i == max_2:
s += '1'
else:
s += '0'
M.append(s)
L[max_1] -= 1
if L[max_1] < 0:
L[max_1] = 0
L[max_2] -= 1
if L[max_2] < 0:
L[max_2] = 0
print(max(L))
print(ans)
for i in M:
print(i)
``` | output | 1 | 36,562 | 17 | 73,125 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A group of n friends enjoys playing popular video game Toda 2. There is a rating system describing skill level of each player, initially the rating of the i-th friend is ri.
The friends decided to take part in the championship as a team. But they should have equal ratings to be allowed to compose a single team consisting of all n friends. So the friends are faced with the problem: how to make all their ratings equal.
One way to change ratings is to willingly lose in some matches. Friends can form a party consisting of two to five (but not more than n) friends and play a match in the game. When the party loses, the rating of each of its members decreases by 1. A rating can't become negative, so ri = 0 doesn't change after losing.
The friends can take part in multiple matches, each time making a party from any subset of friends (but remember about constraints on party size: from 2 to 5 members).
The friends want to make their ratings equal but as high as possible.
Help the friends develop a strategy of losing the matches so that all their ratings become equal and the resulting rating is maximum possible.
Input
The first line contains a single integer n (2 ≤ n ≤ 100) — the number of friends.
The second line contains n non-negative integers r1, r2, ..., rn (0 ≤ ri ≤ 100), where ri is the initial rating of the i-th friend.
Output
In the first line, print a single integer R — the final rating of each of the friends.
In the second line, print integer t — the number of matches the friends have to play. Each of the following t lines should contain n characters '0' or '1', where the j-th character of the i-th line is equal to:
* '0', if friend j should not play in match i,
* '1', if friend j should play in match i.
Each line should contain between two and five characters '1', inclusive.
The value t should not exceed 104, it is guaranteed that such solution exists.
Remember that you shouldn't minimize the value t, but you should maximize R. If there are multiple solutions, print any of them.
Examples
Input
5
4 5 1 7 4
Output
1
8
01010
00011
01010
10010
00011
11000
00011
11000
Input
2
1 2
Output
0
2
11
11
Input
3
1 1 1
Output
1
0 | instruction | 0 | 36,563 | 17 | 73,126 |
Tags: greedy, implementation
Correct Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Thu Nov 2 13:36:10 2017
@author: savit
"""
def sum1(b):
sum1=0
for i in range(len(b)):
sum1+=b[i][0]
return sum1
n=int(input())
a=list(map(int,input().split()))
if(n!=2):
do=True
b=[]
min2=min(a)
for i in range(n):
a[i]-=min2
b.append([a[i],i])
prin=[]
b.sort()
prinx=-1
if(sum(a)==1 and min2!=0):
min2-=1
for i in range(n):
b[i][0]+=1
if(sum1(b)%2):
if(b[-3][0]==0):
if(min2==0):
do=False
else:
min2-=1
for i in range(n):
b[i][0]+=1
if(do):
b[-1][0]-=1
b[-2][0]-=1
b[-3][0]-=1
prinx=(b[-1][1],b[-2][1],b[-3][1])
b.sort()
while(b[-1][0]!=0 and do):
if(b[-2][0]==0):
if(min2==0):
do=False
else:
min2-=1
for i in range(n):
b[i][0]+=1
if(sum1(b)%2):
if(prinx==-1):
b[-1][0]-=1
b[-2][0]-=1
b[-3][0]-=1
prinx=(b[-1][1],b[-2][1],b[-3][1])
b.sort()
else:
prin.append([prinx[0],prinx[1]])
prin.append([prinx[2],b[-1][1]])
b[-1][0]-=1
prinx=-1
b[-1][0]-=1
b[-2][0]-=1
prin.append([b[-1][1],b[-2][1]])
b.sort()
if(not do):
while(b[-1][0]>0):
b[-1][0]-=1
prin.append([b[-1][1],b[-2][1]])
x=[0 for i in range(n)]
print(min2)
if(prinx!=-1):
print(len(prin)+1)
x[prinx[0]]=1
x[prinx[1]]=1
x[prinx[2]]=1
print(*x,sep='')
x[prinx[0]]=0
x[prinx[1]]=0
x[prinx[2]]=0
else:
print(len(prin))
for i in prin:
x[i[0]]=1
x[i[1]]=1
print(*x,sep='')
x[i[0]]=0
x[i[1]]=0
else:
if(a[1]==a[0]):
print(a[0])
print(0)
else:
print(0)
print(max(a))
for i in range(max(a)):
print('11')
``` | output | 1 | 36,563 | 17 | 73,127 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A group of n friends enjoys playing popular video game Toda 2. There is a rating system describing skill level of each player, initially the rating of the i-th friend is ri.
The friends decided to take part in the championship as a team. But they should have equal ratings to be allowed to compose a single team consisting of all n friends. So the friends are faced with the problem: how to make all their ratings equal.
One way to change ratings is to willingly lose in some matches. Friends can form a party consisting of two to five (but not more than n) friends and play a match in the game. When the party loses, the rating of each of its members decreases by 1. A rating can't become negative, so ri = 0 doesn't change after losing.
The friends can take part in multiple matches, each time making a party from any subset of friends (but remember about constraints on party size: from 2 to 5 members).
The friends want to make their ratings equal but as high as possible.
Help the friends develop a strategy of losing the matches so that all their ratings become equal and the resulting rating is maximum possible.
Input
The first line contains a single integer n (2 ≤ n ≤ 100) — the number of friends.
The second line contains n non-negative integers r1, r2, ..., rn (0 ≤ ri ≤ 100), where ri is the initial rating of the i-th friend.
Output
In the first line, print a single integer R — the final rating of each of the friends.
In the second line, print integer t — the number of matches the friends have to play. Each of the following t lines should contain n characters '0' or '1', where the j-th character of the i-th line is equal to:
* '0', if friend j should not play in match i,
* '1', if friend j should play in match i.
Each line should contain between two and five characters '1', inclusive.
The value t should not exceed 104, it is guaranteed that such solution exists.
Remember that you shouldn't minimize the value t, but you should maximize R. If there are multiple solutions, print any of them.
Examples
Input
5
4 5 1 7 4
Output
1
8
01010
00011
01010
10010
00011
11000
00011
11000
Input
2
1 2
Output
0
2
11
11
Input
3
1 1 1
Output
1
0 | instruction | 0 | 36,564 | 17 | 73,128 |
Tags: greedy, implementation
Correct Solution:
```
n = (int(input()))
R = list(map(int,input().split()))
Time = 0;
check = False
Output = []
while (check == False):
pos_max = []; pos_sec = []; Max_sec = -1;
Max_num = 0; Max = -1;
Min = 999999999; Time += 1;
string = ''
for i in range(len(R)-1,-1,-1):
if (R[i] < Min):
Min = R[i]
if (R[i] > Max):
Max_sec = Max; Max = R[i];
pos_sec = pos_max; pos_max = [];
pos_max.append(i);
Max_num = 1
elif (R[i] == Max):
Max_num += 1;
pos_max.append(i)
elif (R[i] > Max_sec):
Max_sec = R[i]
pos_sec = []
pos_sec.append(i)
# print(Max,' ',Max_sec,' ',pos_max,' ',pos_sec,' ',R)
if (Max == Min):
check = True
break
if (Max_num > 1):
if (Max_num % 2 == 1):
j = 0; some = []
for k in range(n-1,-1,-1):
if (pos_max[j] == k):
if (R[k] != 0): R[k] -= 1;
some.append(k)
j += 1;
if (j > 2): j = 0;
j = len(some)-1
for k in range(n):
if (some[j] == k):
string += '1'
j -= 1
if (j < 0): j = 0;
else : string += '0';
else :
j = 0; some = [];
for k in range(n-1,-1,-1):
if (pos_max[j] == k):
if (R[k] != 0): R[k] -= 1;
some.append(k);
# print('1', end='')
j += 1;
if (j > 1): j = 1;
j = len(some)-1
for k in range(n):
if (some[j] == k):
string += '1'
j -= 1
if (j < 0): j = 0;
else : string += '0';
else :
for k in range(n):
## print('k is ',k)
if (pos_max[0] == k):
if (R[k] != 0): R[k] -= 1;
string += '1'
#print('1', end='')
continue
if (pos_sec[0] == k):
if (R[k] != 0): R[k] -= 1;
string += '1'
#print('1', end='')
continue
string += '0'
#print('0', end='');
# print('\n')
Output.append(string)
print(Max)
print(Time-1)
for i in range(len(Output)):
print(Output[i])
``` | output | 1 | 36,564 | 17 | 73,129 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A group of n friends enjoys playing popular video game Toda 2. There is a rating system describing skill level of each player, initially the rating of the i-th friend is ri.
The friends decided to take part in the championship as a team. But they should have equal ratings to be allowed to compose a single team consisting of all n friends. So the friends are faced with the problem: how to make all their ratings equal.
One way to change ratings is to willingly lose in some matches. Friends can form a party consisting of two to five (but not more than n) friends and play a match in the game. When the party loses, the rating of each of its members decreases by 1. A rating can't become negative, so ri = 0 doesn't change after losing.
The friends can take part in multiple matches, each time making a party from any subset of friends (but remember about constraints on party size: from 2 to 5 members).
The friends want to make their ratings equal but as high as possible.
Help the friends develop a strategy of losing the matches so that all their ratings become equal and the resulting rating is maximum possible.
Input
The first line contains a single integer n (2 ≤ n ≤ 100) — the number of friends.
The second line contains n non-negative integers r1, r2, ..., rn (0 ≤ ri ≤ 100), where ri is the initial rating of the i-th friend.
Output
In the first line, print a single integer R — the final rating of each of the friends.
In the second line, print integer t — the number of matches the friends have to play. Each of the following t lines should contain n characters '0' or '1', where the j-th character of the i-th line is equal to:
* '0', if friend j should not play in match i,
* '1', if friend j should play in match i.
Each line should contain between two and five characters '1', inclusive.
The value t should not exceed 104, it is guaranteed that such solution exists.
Remember that you shouldn't minimize the value t, but you should maximize R. If there are multiple solutions, print any of them.
Examples
Input
5
4 5 1 7 4
Output
1
8
01010
00011
01010
10010
00011
11000
00011
11000
Input
2
1 2
Output
0
2
11
11
Input
3
1 1 1
Output
1
0
Submitted Solution:
```
# coding=utf-8
"""Codeforces 730a solution."""
from operator import itemgetter
class CodeforcesTask730ASolution:
def __init__(self):
self.result = ''
self.players = 0
self.rating = []
def read_input(self):
self.players = int(input())
self.rating = [int(x) for x in input().split(" ")]
def process_task(self):
if self.players > 2:
moves = []
players = [[x + 1, self.rating[x]] for x in range(self.players)]
players.sort(key=itemgetter(1), reverse=True)
while players[1][1] != players[-1][1]:
players[0][1] = max(0, players[0][1] - 1)
players[1][1] = max(0, players[1][1] - 1)
moves.append([players[0][0], players[1][0]])
players.sort(key=itemgetter(1), reverse=True)
if players[0][1] != players[-1][1]:
added = False
for m in moves:
if not players[0][0] in m:
m.append(players[0][0])
players[0][1] = max(0, players[0][1] - 1)
added = True
break
if not added:
#print("edge case 1")
#print(players)
moves.append([players[-1][0], players[0][0]])
players[0][1] = max(0, players[0][1] - 1)
players[-1][1] = max(0, players[-1][1] - 1)
players.sort(key=itemgetter(1), reverse=True)
while players[0][1] != players[-1][1] and players[1][1] != players[-1][1]:
#print(players)
players[0][1] = max(0, players[0][1] - 1)
players[1][1] = max(0, players[1][1] - 1)
moves.append([players[0][0], players[1][0]])
players.sort(key=itemgetter(1), reverse=True)
if players[0][1] != players[-1][1]:
added = False
for m in moves:
if not players[0][0] in m:
m.append(players[0][0])
players[0][1] = max(0, players[0][1] - 1)
added = True
break
if not added:
#print(players)
#print("edge case 2")
moves.append([players[-1][0], players[0][0]])
players[0][1] = max(0, players[0][1] - 1)
players[-1][1] = max(0, players[-1][1] - 1)
players.sort(key=itemgetter(1), reverse=True)
while players[0][1] != players[-1][1] and players[1][1] != players[-1][1]:
# print(players)
players[0][1] = max(0, players[0][1] - 1)
players[1][1] = max(0, players[1][1] - 1)
moves.append([players[0][0], players[1][0]])
players.sort(key=itemgetter(1), reverse=True)
if players[0][1] != players[-1][1]:
added = False
for m in moves:
if not players[0][0] in m:
m.append(players[0][0])
players[0][1] = max(0, players[0][1] - 1)
added = True
break
if not added:
# print(players)
#print("edge case 3")
moves.append([players[-1][0], players[0][0]])
players[0][1] = max(0, players[0][1] - 1)
players[-1][1] = max(0, players[-1][1] - 1)
players.sort(key=itemgetter(1), reverse=True)
while players[0][1] != players[-1][1] and players[1][1] != players[-1][1]:
# print(players)
players[0][1] = max(0, players[0][1] - 1)
players[1][1] = max(0, players[1][1] - 1)
moves.append([players[0][0], players[1][0]])
players.sort(key=itemgetter(1), reverse=True)
if players[0][1] != players[-1][1]:
added = False
for m in moves:
if not players[0][0] in m:
m.append(players[0][0])
players[0][1] = max(0, players[0][1] - 1)
added = True
break
if not added:
# print(players)
print("edge case 4")
players.sort(key=itemgetter(1), reverse=True)
print(players[-1][1])
print(len(moves))
for m in moves:
print("".join(["1" if x + 1 in m else "0" for x in range(self.players)]))
else:
if self.rating[0] == self.rating[1]:
print(self.rating[0])
print("0")
else:
print("0")
print(max(self.rating))
for x in range(max(self.rating)):
print("11")
def get_result(self):
return self.result
if __name__ == "__main__":
Solution = CodeforcesTask730ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())
``` | instruction | 0 | 36,565 | 17 | 73,130 |
No | output | 1 | 36,565 | 17 | 73,131 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A group of n friends enjoys playing popular video game Toda 2. There is a rating system describing skill level of each player, initially the rating of the i-th friend is ri.
The friends decided to take part in the championship as a team. But they should have equal ratings to be allowed to compose a single team consisting of all n friends. So the friends are faced with the problem: how to make all their ratings equal.
One way to change ratings is to willingly lose in some matches. Friends can form a party consisting of two to five (but not more than n) friends and play a match in the game. When the party loses, the rating of each of its members decreases by 1. A rating can't become negative, so ri = 0 doesn't change after losing.
The friends can take part in multiple matches, each time making a party from any subset of friends (but remember about constraints on party size: from 2 to 5 members).
The friends want to make their ratings equal but as high as possible.
Help the friends develop a strategy of losing the matches so that all their ratings become equal and the resulting rating is maximum possible.
Input
The first line contains a single integer n (2 ≤ n ≤ 100) — the number of friends.
The second line contains n non-negative integers r1, r2, ..., rn (0 ≤ ri ≤ 100), where ri is the initial rating of the i-th friend.
Output
In the first line, print a single integer R — the final rating of each of the friends.
In the second line, print integer t — the number of matches the friends have to play. Each of the following t lines should contain n characters '0' or '1', where the j-th character of the i-th line is equal to:
* '0', if friend j should not play in match i,
* '1', if friend j should play in match i.
Each line should contain between two and five characters '1', inclusive.
The value t should not exceed 104, it is guaranteed that such solution exists.
Remember that you shouldn't minimize the value t, but you should maximize R. If there are multiple solutions, print any of them.
Examples
Input
5
4 5 1 7 4
Output
1
8
01010
00011
01010
10010
00011
11000
00011
11000
Input
2
1 2
Output
0
2
11
11
Input
3
1 1 1
Output
1
0
Submitted Solution:
```
a = int(input())
b = list(map(int, input().split()))
c = []
while True:
d = '0'*a
if b.count(b[0])==len(b):
break
else:
n = b.index(max(b))
if max(b)>0:
i = max(b)-1
else:
i = 0
b[n] = 0
m = b.index(max(b))
if max(b)>0:
j = max(b)-1
else:
j = 0
b[m] = j
b[n] = i
d = d[0:m]+'1'+d[m+1::]
d = d[0:n]+'1'+d[n+1::]
c.append(d)
print(b[0])
print(len(c))
for i in c:
print(i)
``` | instruction | 0 | 36,566 | 17 | 73,132 |
No | output | 1 | 36,566 | 17 | 73,133 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A group of n friends enjoys playing popular video game Toda 2. There is a rating system describing skill level of each player, initially the rating of the i-th friend is ri.
The friends decided to take part in the championship as a team. But they should have equal ratings to be allowed to compose a single team consisting of all n friends. So the friends are faced with the problem: how to make all their ratings equal.
One way to change ratings is to willingly lose in some matches. Friends can form a party consisting of two to five (but not more than n) friends and play a match in the game. When the party loses, the rating of each of its members decreases by 1. A rating can't become negative, so ri = 0 doesn't change after losing.
The friends can take part in multiple matches, each time making a party from any subset of friends (but remember about constraints on party size: from 2 to 5 members).
The friends want to make their ratings equal but as high as possible.
Help the friends develop a strategy of losing the matches so that all their ratings become equal and the resulting rating is maximum possible.
Input
The first line contains a single integer n (2 ≤ n ≤ 100) — the number of friends.
The second line contains n non-negative integers r1, r2, ..., rn (0 ≤ ri ≤ 100), where ri is the initial rating of the i-th friend.
Output
In the first line, print a single integer R — the final rating of each of the friends.
In the second line, print integer t — the number of matches the friends have to play. Each of the following t lines should contain n characters '0' or '1', where the j-th character of the i-th line is equal to:
* '0', if friend j should not play in match i,
* '1', if friend j should play in match i.
Each line should contain between two and five characters '1', inclusive.
The value t should not exceed 104, it is guaranteed that such solution exists.
Remember that you shouldn't minimize the value t, but you should maximize R. If there are multiple solutions, print any of them.
Examples
Input
5
4 5 1 7 4
Output
1
8
01010
00011
01010
10010
00011
11000
00011
11000
Input
2
1 2
Output
0
2
11
11
Input
3
1 1 1
Output
1
0
Submitted Solution:
```
# coding=utf-8
"""Codeforces 730a solution."""
from operator import itemgetter
class CodeforcesTask730ASolution:
def __init__(self):
self.result = ''
self.players = 0
self.rating = []
def read_input(self):
self.players = int(input())
self.rating = [int(x) for x in input().split(" ")]
def process_task(self):
if self.players > 2:
moves = []
players = [[x + 1, self.rating[x]] for x in range(self.players)]
players.sort(key=itemgetter(1), reverse=True)
while players[1][1] != players[-1][1]:
players[0][1] = max(0, players[0][1] - 1)
players[1][1] = max(0, players[1][1] - 1)
moves.append([players[0][0], players[1][0]])
players.sort(key=itemgetter(1), reverse=True)
if players[0][1] != players[-1][1]:
added = False
for m in moves:
if not players[0][0] in m:
m.append(players[0][0])
players[0][1] = max(0, players[0][1] - 1)
added = True
break
if not added:
#print("edge case 1")
#print(players)
moves.append([players[-1][0], players[0][0]])
players[0][1] = max(0, players[0][1] - 1)
players[-1][1] = max(0, players[-1][1] - 1)
while players[0][1] != players[-1][1]:
players[0][1] = max(0, players[0][1] - 1)
players[1][1] = max(0, players[1][1] - 1)
moves.append([players[0][0], players[1][0]])
players.sort(key=itemgetter(1), reverse=True)
if players[0][1] != players[-1][1]:
added = False
for m in moves:
if not players[0][0] in m:
m.append(players[0][0])
players[0][1] = max(0, players[0][1] - 1)
added = True
break
if not added:
#print(players)
print("edge case 2")
players.sort(key=itemgetter(1), reverse=True)
print(players[-1][1])
print(len(moves))
for m in moves:
print("".join(["1" if x + 1 in m else "0" for x in range(self.players)]))
else:
if self.rating[0] == self.rating[1]:
print(self.rating[0])
print("0")
else:
print("0")
for x in range(max(self.rating)):
print("11")
def get_result(self):
return self.result
if __name__ == "__main__":
Solution = CodeforcesTask730ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())
``` | instruction | 0 | 36,567 | 17 | 73,134 |
No | output | 1 | 36,567 | 17 | 73,135 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A group of n friends enjoys playing popular video game Toda 2. There is a rating system describing skill level of each player, initially the rating of the i-th friend is ri.
The friends decided to take part in the championship as a team. But they should have equal ratings to be allowed to compose a single team consisting of all n friends. So the friends are faced with the problem: how to make all their ratings equal.
One way to change ratings is to willingly lose in some matches. Friends can form a party consisting of two to five (but not more than n) friends and play a match in the game. When the party loses, the rating of each of its members decreases by 1. A rating can't become negative, so ri = 0 doesn't change after losing.
The friends can take part in multiple matches, each time making a party from any subset of friends (but remember about constraints on party size: from 2 to 5 members).
The friends want to make their ratings equal but as high as possible.
Help the friends develop a strategy of losing the matches so that all their ratings become equal and the resulting rating is maximum possible.
Input
The first line contains a single integer n (2 ≤ n ≤ 100) — the number of friends.
The second line contains n non-negative integers r1, r2, ..., rn (0 ≤ ri ≤ 100), where ri is the initial rating of the i-th friend.
Output
In the first line, print a single integer R — the final rating of each of the friends.
In the second line, print integer t — the number of matches the friends have to play. Each of the following t lines should contain n characters '0' or '1', where the j-th character of the i-th line is equal to:
* '0', if friend j should not play in match i,
* '1', if friend j should play in match i.
Each line should contain between two and five characters '1', inclusive.
The value t should not exceed 104, it is guaranteed that such solution exists.
Remember that you shouldn't minimize the value t, but you should maximize R. If there are multiple solutions, print any of them.
Examples
Input
5
4 5 1 7 4
Output
1
8
01010
00011
01010
10010
00011
11000
00011
11000
Input
2
1 2
Output
0
2
11
11
Input
3
1 1 1
Output
1
0
Submitted Solution:
```
a = int(input())
b = list(map(int, input().split()))
c = []
while True:
d = '0'*a
if b.count(b[-1]) == a:
break
else:
n = b.index(max(b))
if max(b)>0:
i = max(b)-1
else:
i = 0
b[n] = 0
m = b.index(max(b))
if max(b)>0:
j = max(b)-1
else:
j = 0
b[m] = j
b[n] = i
d = d[0:m]+'1'+d[m+1::]
d = d[0:n]+'1'+d[n+1::]
c.append(d)
print(b[0])
print(len(c))
for i in c:
print(i)
``` | instruction | 0 | 36,568 | 17 | 73,136 |
No | output | 1 | 36,568 | 17 | 73,137 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of lines in the description. Then follow n lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
Output
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
Examples
Input
1
ABC
Output
ABC
Input
5
A
ABA
ABA
A
A
Output
A | instruction | 0 | 37,179 | 17 | 74,358 |
Tags: strings
Correct Solution:
```
n = int(input())
d = []
for i in range(n):
s = input()
d.append(s)
l1 = d[0]
l2 = 0
k1 = 0
k2 = 0
for i in range(len(d)):
if d[i] == l1:
k1 += 1
else:
l2 = d[i]
for i in range(len(d)):
if d[i] == l2:
k2 += 1
if k1 > k2:
print(l1)
else:
print(l2)
``` | output | 1 | 37,179 | 17 | 74,359 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of lines in the description. Then follow n lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
Output
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
Examples
Input
1
ABC
Output
ABC
Input
5
A
ABA
ABA
A
A
Output
A | instruction | 0 | 37,180 | 17 | 74,360 |
Tags: strings
Correct Solution:
```
n=int(input())
b=[]
for i in range(n):
b.append(input())
print(max(set(b), key=b.count))
``` | output | 1 | 37,180 | 17 | 74,361 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of lines in the description. Then follow n lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
Output
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
Examples
Input
1
ABC
Output
ABC
Input
5
A
ABA
ABA
A
A
Output
A | instruction | 0 | 37,181 | 17 | 74,362 |
Tags: strings
Correct Solution:
```
from collections import Counter
goals = []
T = int(input())
if T == 1:
print(str(input().strip()))
else:
for i in range(T):
goals.append(str(input().strip()))
keys = Counter(goals).keys()
values = Counter(goals).values()
if(len(keys))<=1:
k1, = keys
print(k1)
else:
k1, k2 = keys
x1, x2 = values
print(k1) if x1>x2 else print(k2)
``` | output | 1 | 37,181 | 17 | 74,363 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of lines in the description. Then follow n lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
Output
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
Examples
Input
1
ABC
Output
ABC
Input
5
A
ABA
ABA
A
A
Output
A | instruction | 0 | 37,182 | 17 | 74,364 |
Tags: strings
Correct Solution:
```
n=int(input())
l=[]
for i in range(n):
l.append(input())
a=0
b=0
j=0
c=l[0]
for i in range(n):
if l[i]==c:
a+=1
else:
b+=1
j=i
if a>b:
print(l[0])
else:
print(l[j])
``` | output | 1 | 37,182 | 17 | 74,365 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of lines in the description. Then follow n lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
Output
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
Examples
Input
1
ABC
Output
ABC
Input
5
A
ABA
ABA
A
A
Output
A | instruction | 0 | 37,183 | 17 | 74,366 |
Tags: strings
Correct Solution:
```
######################################################################
# Write your code here
import sys
from math import *
input = sys.stdin.readline
#import resource
#resource.setrlimit(resource.RLIMIT_STACK, [0x10000000, resource.RLIM_INFINITY])
#sys.setrecursionlimit(0x100000)
# Write your code here
RI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
rw = lambda : input().strip().split()
ls = lambda : list(input().strip()) # for strings to list of char
from collections import defaultdict as df
import heapq
#heapq.heapify(li) heappush(li,4) heappop(li)
#import random
#random.shuffle(list)
infinite = float('inf')
#######################################################################
n=int(input())
d=df(int)
for i in range(n):
a=input().strip()
d[a]+=1
maxo=0
ans=""
for i in d:
if(d[i]>maxo):
maxo=d[i]
ans=i
print(ans)
``` | output | 1 | 37,183 | 17 | 74,367 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of lines in the description. Then follow n lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
Output
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
Examples
Input
1
ABC
Output
ABC
Input
5
A
ABA
ABA
A
A
Output
A | instruction | 0 | 37,184 | 17 | 74,368 |
Tags: strings
Correct Solution:
```
n=int(input())
lst=[]
for i in range(n):
str1=input()
lst.append(str1)
ele=lst[0]
lst1=[]
lst2=[]
for i in range(len(lst)):
if lst[i]!=ele:
lst2.append(lst[i])
else:
lst1.append(lst[i])
if len(lst1)>len(lst2):
print(lst1[0])
else:
print(lst2[0])
``` | output | 1 | 37,184 | 17 | 74,369 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of lines in the description. Then follow n lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
Output
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
Examples
Input
1
ABC
Output
ABC
Input
5
A
ABA
ABA
A
A
Output
A | instruction | 0 | 37,185 | 17 | 74,370 |
Tags: strings
Correct Solution:
```
a = {}
n = int(input())
for i in range(n):
s = input()
try:
a[s] += 1
except:
a[s] = 1
for i in a.keys():
if a[s]>a[i]:
print(s)
exit(0)
elif a[s]!=a[i]:
print(i)
exit(0)
print(s)
``` | output | 1 | 37,185 | 17 | 74,371 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of lines in the description. Then follow n lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
Output
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
Examples
Input
1
ABC
Output
ABC
Input
5
A
ABA
ABA
A
A
Output
A | instruction | 0 | 37,186 | 17 | 74,372 |
Tags: strings
Correct Solution:
```
from collections import Counter
n = int(input())
c = Counter([input() for i in range(n)])
print(c.most_common()[0][0])
``` | output | 1 | 37,186 | 17 | 74,373 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of lines in the description. Then follow n lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
Output
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
Examples
Input
1
ABC
Output
ABC
Input
5
A
ABA
ABA
A
A
Output
A
Submitted Solution:
```
n=int(input())
str1=input()
c1=1
c2=0
x=0
for i in range(n-1):
str=input()
if str==str1:
c1+=1
else:
c2+=1
if x==0:
str2=str
x=1
if c1>c2:
print(str1)
else:
print(str2)
``` | instruction | 0 | 37,187 | 17 | 74,374 |
Yes | output | 1 | 37,187 | 17 | 74,375 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of lines in the description. Then follow n lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
Output
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
Examples
Input
1
ABC
Output
ABC
Input
5
A
ABA
ABA
A
A
Output
A
Submitted Solution:
```
def main():
n = int(input())
m = []
for _ in range(n):
x = input()
m.append(x)
name = 0
s = 0
for i in m:
if m.count(i) > s:
s = m.count(i)
name = i
print(name)
main()
``` | instruction | 0 | 37,188 | 17 | 74,376 |
Yes | output | 1 | 37,188 | 17 | 74,377 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of lines in the description. Then follow n lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
Output
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
Examples
Input
1
ABC
Output
ABC
Input
5
A
ABA
ABA
A
A
Output
A
Submitted Solution:
```
scores = int(input())
goals = {}
for i in range(scores):
team = input()
goals[team] = goals.get(team, 0) + 1
print(sorted((v, k) for k, v in goals.items())[-1][-1])
``` | instruction | 0 | 37,189 | 17 | 74,378 |
Yes | output | 1 | 37,189 | 17 | 74,379 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of lines in the description. Then follow n lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
Output
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
Examples
Input
1
ABC
Output
ABC
Input
5
A
ABA
ABA
A
A
Output
A
Submitted Solution:
```
n = int(input())
f = str(input())
fscore = 1
sscore = 0
s = ''
for i in range(n-1):
n = str(input())
if n == f :
fscore += 1
else:
s = n
sscore += 1
if fscore > sscore:
print(f)
exit()
print(s)
``` | instruction | 0 | 37,190 | 17 | 74,380 |
Yes | output | 1 | 37,190 | 17 | 74,381 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of lines in the description. Then follow n lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
Output
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
Examples
Input
1
ABC
Output
ABC
Input
5
A
ABA
ABA
A
A
Output
A
Submitted Solution:
```
n= int(input())
if n==1:
s= input()
tep= list(s)
if len(set(tep))== len(tep):
print(s)
else:
dic={}
for i in range(n):
t= tep[i]
for j in range(len(t)):
if t[j] not in dic:
dic[t[j]]=1
else:
dic[t[j]]+=1
m= max(dic, key= dic.get)
print(m)
else:
l=[]
for _ in range(n):
s= list(input())
l.append(s)
dic={}
for i in range(n):
t= l[i]
for j in range(len(t)):
if t[j] not in dic:
dic[t[j]]=1
else:
dic[t[j]]+=1
m= max(dic, key= dic.get)
print(m)
``` | instruction | 0 | 37,191 | 17 | 74,382 |
No | output | 1 | 37,191 | 17 | 74,383 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of lines in the description. Then follow n lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
Output
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
Examples
Input
1
ABC
Output
ABC
Input
5
A
ABA
ABA
A
A
Output
A
Submitted Solution:
```
n=int(input())
res=""
for i in range(n):
a=input()
res=res+a
c=set(res)
c=list(c)
d=[]
for j in range(len(c)):
c1=0
for k in range(len(res)):
if ord(c[j])==ord(res[k]):
c1+=1
d.append(c1)
g=max(d)
s=""
for l in range(len(d)):
if d[l]==g:
s=s+c[l]
fo=""
for m in range(len(res)):
if res[m] in s:
if res[m] not in fo:
fo=fo+res[m]
print(fo)
``` | instruction | 0 | 37,192 | 17 | 74,384 |
No | output | 1 | 37,192 | 17 | 74,385 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of lines in the description. Then follow n lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
Output
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
Examples
Input
1
ABC
Output
ABC
Input
5
A
ABA
ABA
A
A
Output
A
Submitted Solution:
```
inp = int(input())
i = j = ans = 0
arr = []
arr1 = []
while i < inp:
inp1 = input()
if inp == 1:
print(inp1)
exit()
arr.append(inp1)
i+=1
while j < len(arr)-1:
b = arr.count(arr[j])
arr1.append(b)
if arr1[j] > ans:
ans = arr1[j]
j+=1
print(ans)
``` | instruction | 0 | 37,193 | 17 | 74,386 |
No | output | 1 | 37,193 | 17 | 74,387 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of lines in the description. Then follow n lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
Output
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
Examples
Input
1
ABC
Output
ABC
Input
5
A
ABA
ABA
A
A
Output
A
Submitted Solution:
```
scores = int(input())
goals = {}
for i in range(scores):
team = input()
goals[team] = goals.get(team, 0) + 1
print([k for k, v in sorted(goals.items(), reverse=True)][-1])
``` | instruction | 0 | 37,194 | 17 | 74,388 |
No | output | 1 | 37,194 | 17 | 74,389 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.
The tournament takes place in the following way (below, m is the number of the participants of the current round):
* let k be the maximal power of the number 2 such that k ≤ m,
* k participants compete in the current round and a half of them passes to the next round, the other m - k participants pass to the next round directly,
* when only one participant remains, the tournament finishes.
Each match requires b bottles of water for each participant and one bottle for the judge. Besides p towels are given to each participant for the whole tournament.
Find the number of bottles and towels needed for the tournament.
Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose).
Input
The only line contains three integers n, b, p (1 ≤ n, b, p ≤ 500) — the number of participants and the parameters described in the problem statement.
Output
Print two integers x and y — the number of bottles and towels need for the tournament.
Examples
Input
5 2 3
Output
20 15
Input
8 2 4
Output
35 32
Note
In the first example will be three rounds:
1. in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge),
2. in the second round will be only one match, so we need another 5 bottles of water,
3. in the third round will also be only one match, so we need another 5 bottles of water.
So in total we need 20 bottles of water.
In the second example no participant will move on to some round directly. | instruction | 0 | 37,275 | 17 | 74,550 |
Tags: implementation, math
Correct Solution:
```
n, b, p = [int(x) for x in input().split()]
b1, p1 = 0, n*p
while n > 1:
n1 = 2 << (n.bit_length()-2)
b1 += (2*b + 1) * n1 // 2
n -= n1//2
print(b1, p1)
``` | output | 1 | 37,275 | 17 | 74,551 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.
The tournament takes place in the following way (below, m is the number of the participants of the current round):
* let k be the maximal power of the number 2 such that k ≤ m,
* k participants compete in the current round and a half of them passes to the next round, the other m - k participants pass to the next round directly,
* when only one participant remains, the tournament finishes.
Each match requires b bottles of water for each participant and one bottle for the judge. Besides p towels are given to each participant for the whole tournament.
Find the number of bottles and towels needed for the tournament.
Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose).
Input
The only line contains three integers n, b, p (1 ≤ n, b, p ≤ 500) — the number of participants and the parameters described in the problem statement.
Output
Print two integers x and y — the number of bottles and towels need for the tournament.
Examples
Input
5 2 3
Output
20 15
Input
8 2 4
Output
35 32
Note
In the first example will be three rounds:
1. in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge),
2. in the second round will be only one match, so we need another 5 bottles of water,
3. in the third round will also be only one match, so we need another 5 bottles of water.
So in total we need 20 bottles of water.
In the second example no participant will move on to some round directly. | instruction | 0 | 37,276 | 17 | 74,552 |
Tags: implementation, math
Correct Solution:
```
n, b, p = list(map(int, input().split(" ")))
dup = n
ans = 0
while n>1:
ans += (n//2)*(2*b + 1)
n = n//2 + n%2
print(ans, p*dup)
``` | output | 1 | 37,276 | 17 | 74,553 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.
The tournament takes place in the following way (below, m is the number of the participants of the current round):
* let k be the maximal power of the number 2 such that k ≤ m,
* k participants compete in the current round and a half of them passes to the next round, the other m - k participants pass to the next round directly,
* when only one participant remains, the tournament finishes.
Each match requires b bottles of water for each participant and one bottle for the judge. Besides p towels are given to each participant for the whole tournament.
Find the number of bottles and towels needed for the tournament.
Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose).
Input
The only line contains three integers n, b, p (1 ≤ n, b, p ≤ 500) — the number of participants and the parameters described in the problem statement.
Output
Print two integers x and y — the number of bottles and towels need for the tournament.
Examples
Input
5 2 3
Output
20 15
Input
8 2 4
Output
35 32
Note
In the first example will be three rounds:
1. in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge),
2. in the second round will be only one match, so we need another 5 bottles of water,
3. in the third round will also be only one match, so we need another 5 bottles of water.
So in total we need 20 bottles of water.
In the second example no participant will move on to some round directly. | instruction | 0 | 37,277 | 17 | 74,554 |
Tags: implementation, math
Correct Solution:
```
n, b, p = [int(t) for t in input().split()]
print((n-1)*(2*b+1), n*p)
``` | output | 1 | 37,277 | 17 | 74,555 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.
The tournament takes place in the following way (below, m is the number of the participants of the current round):
* let k be the maximal power of the number 2 such that k ≤ m,
* k participants compete in the current round and a half of them passes to the next round, the other m - k participants pass to the next round directly,
* when only one participant remains, the tournament finishes.
Each match requires b bottles of water for each participant and one bottle for the judge. Besides p towels are given to each participant for the whole tournament.
Find the number of bottles and towels needed for the tournament.
Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose).
Input
The only line contains three integers n, b, p (1 ≤ n, b, p ≤ 500) — the number of participants and the parameters described in the problem statement.
Output
Print two integers x and y — the number of bottles and towels need for the tournament.
Examples
Input
5 2 3
Output
20 15
Input
8 2 4
Output
35 32
Note
In the first example will be three rounds:
1. in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge),
2. in the second round will be only one match, so we need another 5 bottles of water,
3. in the third round will also be only one match, so we need another 5 bottles of water.
So in total we need 20 bottles of water.
In the second example no participant will move on to some round directly. | instruction | 0 | 37,278 | 17 | 74,556 |
Tags: implementation, math
Correct Solution:
```
# from dust i have come, dust i will be
import math
def highestPowerOfTwo(n):
p = int(math.log2(n))
return int(math.pow(2, p))
n, b, p = map(int, input().split())
x = 0;
y = p * n
while n > 1:
k = highestPowerOfTwo(n)
x += (k * b + k//2)
n -= (k // 2)
print(x, y)
``` | output | 1 | 37,278 | 17 | 74,557 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.
The tournament takes place in the following way (below, m is the number of the participants of the current round):
* let k be the maximal power of the number 2 such that k ≤ m,
* k participants compete in the current round and a half of them passes to the next round, the other m - k participants pass to the next round directly,
* when only one participant remains, the tournament finishes.
Each match requires b bottles of water for each participant and one bottle for the judge. Besides p towels are given to each participant for the whole tournament.
Find the number of bottles and towels needed for the tournament.
Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose).
Input
The only line contains three integers n, b, p (1 ≤ n, b, p ≤ 500) — the number of participants and the parameters described in the problem statement.
Output
Print two integers x and y — the number of bottles and towels need for the tournament.
Examples
Input
5 2 3
Output
20 15
Input
8 2 4
Output
35 32
Note
In the first example will be three rounds:
1. in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge),
2. in the second round will be only one match, so we need another 5 bottles of water,
3. in the third round will also be only one match, so we need another 5 bottles of water.
So in total we need 20 bottles of water.
In the second example no participant will move on to some round directly. | instruction | 0 | 37,279 | 17 | 74,558 |
Tags: implementation, math
Correct Solution:
```
s=input().split()
n=int(s[0])
b=int(s[1])
p=int(s[2])
print((n-1)*(2*b+1))
print(n*p)
``` | output | 1 | 37,279 | 17 | 74,559 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.
The tournament takes place in the following way (below, m is the number of the participants of the current round):
* let k be the maximal power of the number 2 such that k ≤ m,
* k participants compete in the current round and a half of them passes to the next round, the other m - k participants pass to the next round directly,
* when only one participant remains, the tournament finishes.
Each match requires b bottles of water for each participant and one bottle for the judge. Besides p towels are given to each participant for the whole tournament.
Find the number of bottles and towels needed for the tournament.
Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose).
Input
The only line contains three integers n, b, p (1 ≤ n, b, p ≤ 500) — the number of participants and the parameters described in the problem statement.
Output
Print two integers x and y — the number of bottles and towels need for the tournament.
Examples
Input
5 2 3
Output
20 15
Input
8 2 4
Output
35 32
Note
In the first example will be three rounds:
1. in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge),
2. in the second round will be only one match, so we need another 5 bottles of water,
3. in the third round will also be only one match, so we need another 5 bottles of water.
So in total we need 20 bottles of water.
In the second example no participant will move on to some round directly. | instruction | 0 | 37,280 | 17 | 74,560 |
Tags: implementation, math
Correct Solution:
```
def power_of_two(n):
sqr=1
while(sqr <= n):
sqr=sqr*2
return (sqr//2)
n,b,p = map(int, input().split())
kol_b = 0
kol_p = n*p
m = n
while (m > 1):
k = power_of_two(m)
game = k//2
kol_b = kol_b + k*b + game
m = m - k + game
print(kol_b, kol_p)
# Tue Oct 13 2020 14:44:54 GMT+0300 (Москва, стандартное время)
``` | output | 1 | 37,280 | 17 | 74,561 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.
The tournament takes place in the following way (below, m is the number of the participants of the current round):
* let k be the maximal power of the number 2 such that k ≤ m,
* k participants compete in the current round and a half of them passes to the next round, the other m - k participants pass to the next round directly,
* when only one participant remains, the tournament finishes.
Each match requires b bottles of water for each participant and one bottle for the judge. Besides p towels are given to each participant for the whole tournament.
Find the number of bottles and towels needed for the tournament.
Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose).
Input
The only line contains three integers n, b, p (1 ≤ n, b, p ≤ 500) — the number of participants and the parameters described in the problem statement.
Output
Print two integers x and y — the number of bottles and towels need for the tournament.
Examples
Input
5 2 3
Output
20 15
Input
8 2 4
Output
35 32
Note
In the first example will be three rounds:
1. in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge),
2. in the second round will be only one match, so we need another 5 bottles of water,
3. in the third round will also be only one match, so we need another 5 bottles of water.
So in total we need 20 bottles of water.
In the second example no participant will move on to some round directly. | instruction | 0 | 37,281 | 17 | 74,562 |
Tags: implementation, math
Correct Solution:
```
import math
def hp2(n):
p=int(math.log(n, 2));
return int(pow(2, p));
n,b,p=[int(x) for x in input().split()]
towels=p*n
bottles=0
k=0
m=n
while(m!=1):
k=hp2(m)
bottles+=(b*k)+(k/2)
m=m-k+(k/2)
print(int(bottles), towels)
``` | output | 1 | 37,281 | 17 | 74,563 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.
The tournament takes place in the following way (below, m is the number of the participants of the current round):
* let k be the maximal power of the number 2 such that k ≤ m,
* k participants compete in the current round and a half of them passes to the next round, the other m - k participants pass to the next round directly,
* when only one participant remains, the tournament finishes.
Each match requires b bottles of water for each participant and one bottle for the judge. Besides p towels are given to each participant for the whole tournament.
Find the number of bottles and towels needed for the tournament.
Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose).
Input
The only line contains three integers n, b, p (1 ≤ n, b, p ≤ 500) — the number of participants and the parameters described in the problem statement.
Output
Print two integers x and y — the number of bottles and towels need for the tournament.
Examples
Input
5 2 3
Output
20 15
Input
8 2 4
Output
35 32
Note
In the first example will be three rounds:
1. in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge),
2. in the second round will be only one match, so we need another 5 bottles of water,
3. in the third round will also be only one match, so we need another 5 bottles of water.
So in total we need 20 bottles of water.
In the second example no participant will move on to some round directly. | instruction | 0 | 37,282 | 17 | 74,564 |
Tags: implementation, math
Correct Solution:
```
n, b, p=map(int, input(). split())
print((n-1)*(2*b+1), p*n)
# Mon Oct 12 2020 22:21:52 GMT+0300 (Москва, стандартное время)
``` | output | 1 | 37,282 | 17 | 74,565 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.
The tournament takes place in the following way (below, m is the number of the participants of the current round):
* let k be the maximal power of the number 2 such that k ≤ m,
* k participants compete in the current round and a half of them passes to the next round, the other m - k participants pass to the next round directly,
* when only one participant remains, the tournament finishes.
Each match requires b bottles of water for each participant and one bottle for the judge. Besides p towels are given to each participant for the whole tournament.
Find the number of bottles and towels needed for the tournament.
Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose).
Input
The only line contains three integers n, b, p (1 ≤ n, b, p ≤ 500) — the number of participants and the parameters described in the problem statement.
Output
Print two integers x and y — the number of bottles and towels need for the tournament.
Examples
Input
5 2 3
Output
20 15
Input
8 2 4
Output
35 32
Note
In the first example will be three rounds:
1. in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge),
2. in the second round will be only one match, so we need another 5 bottles of water,
3. in the third round will also be only one match, so we need another 5 bottles of water.
So in total we need 20 bottles of water.
In the second example no participant will move on to some round directly.
Submitted Solution:
```
import math
n, b, p = [int(x) for x in input().split(' ')]
t = n * p
m = 0
while n > 1:
m += 2 ** (math.floor(math.log(n, 2)) - 1)
n -= 2 ** (math.floor(math.log(n, 2)) - 1)
print(m * (2 * b + 1), t)
``` | instruction | 0 | 37,283 | 17 | 74,566 |
Yes | output | 1 | 37,283 | 17 | 74,567 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.
The tournament takes place in the following way (below, m is the number of the participants of the current round):
* let k be the maximal power of the number 2 such that k ≤ m,
* k participants compete in the current round and a half of them passes to the next round, the other m - k participants pass to the next round directly,
* when only one participant remains, the tournament finishes.
Each match requires b bottles of water for each participant and one bottle for the judge. Besides p towels are given to each participant for the whole tournament.
Find the number of bottles and towels needed for the tournament.
Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose).
Input
The only line contains three integers n, b, p (1 ≤ n, b, p ≤ 500) — the number of participants and the parameters described in the problem statement.
Output
Print two integers x and y — the number of bottles and towels need for the tournament.
Examples
Input
5 2 3
Output
20 15
Input
8 2 4
Output
35 32
Note
In the first example will be three rounds:
1. in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge),
2. in the second round will be only one match, so we need another 5 bottles of water,
3. in the third round will also be only one match, so we need another 5 bottles of water.
So in total we need 20 bottles of water.
In the second example no participant will move on to some round directly.
Submitted Solution:
```
import math
(n, b, p) = map(int, input().split())
m = n
bottles = 0
papers = p * n
while m > 1:
k = 2 ** math.floor(math.log(m, 2))
bottles += k * b
bottles += k // 2
m = m - k + k // 2
print(bottles, papers)
``` | instruction | 0 | 37,284 | 17 | 74,568 |
Yes | output | 1 | 37,284 | 17 | 74,569 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.
The tournament takes place in the following way (below, m is the number of the participants of the current round):
* let k be the maximal power of the number 2 such that k ≤ m,
* k participants compete in the current round and a half of them passes to the next round, the other m - k participants pass to the next round directly,
* when only one participant remains, the tournament finishes.
Each match requires b bottles of water for each participant and one bottle for the judge. Besides p towels are given to each participant for the whole tournament.
Find the number of bottles and towels needed for the tournament.
Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose).
Input
The only line contains three integers n, b, p (1 ≤ n, b, p ≤ 500) — the number of participants and the parameters described in the problem statement.
Output
Print two integers x and y — the number of bottles and towels need for the tournament.
Examples
Input
5 2 3
Output
20 15
Input
8 2 4
Output
35 32
Note
In the first example will be three rounds:
1. in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge),
2. in the second round will be only one match, so we need another 5 bottles of water,
3. in the third round will also be only one match, so we need another 5 bottles of water.
So in total we need 20 bottles of water.
In the second example no participant will move on to some round directly.
Submitted Solution:
```
read = lambda: map(int, input().split())
n, b, p = read()
y = p * n
x = 0
while n > 1:
p = 0
while 2 ** p <= n: p += 1
k = 2 ** (p - 1)
x += (k // 2) * (2 * b + 1)
n = n - k + k // 2
print(x, y)
``` | instruction | 0 | 37,285 | 17 | 74,570 |
Yes | output | 1 | 37,285 | 17 | 74,571 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.
The tournament takes place in the following way (below, m is the number of the participants of the current round):
* let k be the maximal power of the number 2 such that k ≤ m,
* k participants compete in the current round and a half of them passes to the next round, the other m - k participants pass to the next round directly,
* when only one participant remains, the tournament finishes.
Each match requires b bottles of water for each participant and one bottle for the judge. Besides p towels are given to each participant for the whole tournament.
Find the number of bottles and towels needed for the tournament.
Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose).
Input
The only line contains three integers n, b, p (1 ≤ n, b, p ≤ 500) — the number of participants and the parameters described in the problem statement.
Output
Print two integers x and y — the number of bottles and towels need for the tournament.
Examples
Input
5 2 3
Output
20 15
Input
8 2 4
Output
35 32
Note
In the first example will be three rounds:
1. in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge),
2. in the second round will be only one match, so we need another 5 bottles of water,
3. in the third round will also be only one match, so we need another 5 bottles of water.
So in total we need 20 bottles of water.
In the second example no participant will move on to some round directly.
Submitted Solution:
```
import math
from math import *
n,b,p = map(int, input().split(' '))
#n,b,p = 5,2,3
ansb = 0
ansp = p * n
while n > 1:
t = floor(log(n)/log(2))
m = 2**t
ansb += (2*b + 1) * (m/2)
n -= m/2
print(int(ansb), int(ansp))
``` | instruction | 0 | 37,286 | 17 | 74,572 |
Yes | output | 1 | 37,286 | 17 | 74,573 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.
The tournament takes place in the following way (below, m is the number of the participants of the current round):
* let k be the maximal power of the number 2 such that k ≤ m,
* k participants compete in the current round and a half of them passes to the next round, the other m - k participants pass to the next round directly,
* when only one participant remains, the tournament finishes.
Each match requires b bottles of water for each participant and one bottle for the judge. Besides p towels are given to each participant for the whole tournament.
Find the number of bottles and towels needed for the tournament.
Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose).
Input
The only line contains three integers n, b, p (1 ≤ n, b, p ≤ 500) — the number of participants and the parameters described in the problem statement.
Output
Print two integers x and y — the number of bottles and towels need for the tournament.
Examples
Input
5 2 3
Output
20 15
Input
8 2 4
Output
35 32
Note
In the first example will be three rounds:
1. in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge),
2. in the second round will be only one match, so we need another 5 bottles of water,
3. in the third round will also be only one match, so we need another 5 bottles of water.
So in total we need 20 bottles of water.
In the second example no participant will move on to some round directly.
Submitted Solution:
```
n, b, p = map(int, input().split())
if n < 3:
if n == 2:
print(2*b+1, 2*p)
elif n == 1:
print(0, p)
else:
q = n
qs = 0
while q != 1:
s = 2
e = 1
while s-1 < q:
s *= 2
e += 1
q -= s**0.5//2
qs += (s**0.5)*b+e-1
print(int(qs), n*p)
# Fri Oct 16 2020 22:11:32 GMT+0300 (Москва, стандартное время)
``` | instruction | 0 | 37,287 | 17 | 74,574 |
No | output | 1 | 37,287 | 17 | 74,575 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.