message stringlengths 2 65.1k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 0 108k | cluster float64 14 14 | __index_level_0__ int64 0 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day, n people (n is an even number) met on a plaza and made two round dances, each round dance consists of exactly n/2 people. Your task is to find the number of ways n people can make two round dances if each round dance consists of exactly n/2 people. Each person should belong to exactly one of these two round dances.
Round dance is a dance circle consisting of 1 or more people. Two round dances are indistinguishable (equal) if one can be transformed to another by choosing the first participant. For example, round dances [1, 3, 4, 2], [4, 2, 1, 3] and [2, 1, 3, 4] are indistinguishable.
For example, if n=2 then the number of ways is 1: one round dance consists of the first person and the second one of the second person.
For example, if n=4 then the number of ways is 3. Possible options:
* one round dance β [1,2], another β [3,4];
* one round dance β [2,4], another β [3,1];
* one round dance β [4,1], another β [3,2].
Your task is to find the number of ways n people can make two round dances if each round dance consists of exactly n/2 people.
Input
The input contains one integer n (2 β€ n β€ 20), n is an even number.
Output
Print one integer β the number of ways to make two round dances. It is guaranteed that the answer fits in the 64-bit integer data type.
Examples
Input
2
Output
1
Input
4
Output
3
Input
8
Output
1260
Input
20
Output
12164510040883200
Submitted Solution:
```
from sys import stdin
input = stdin.readline
from math import factorial
#
# def solve():
if __name__ == '__main__':
n = int(input())
print(2*factorial(n)//n//n)
``` | instruction | 0 | 79,343 | 14 | 158,686 |
Yes | output | 1 | 79,343 | 14 | 158,687 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day, n people (n is an even number) met on a plaza and made two round dances, each round dance consists of exactly n/2 people. Your task is to find the number of ways n people can make two round dances if each round dance consists of exactly n/2 people. Each person should belong to exactly one of these two round dances.
Round dance is a dance circle consisting of 1 or more people. Two round dances are indistinguishable (equal) if one can be transformed to another by choosing the first participant. For example, round dances [1, 3, 4, 2], [4, 2, 1, 3] and [2, 1, 3, 4] are indistinguishable.
For example, if n=2 then the number of ways is 1: one round dance consists of the first person and the second one of the second person.
For example, if n=4 then the number of ways is 3. Possible options:
* one round dance β [1,2], another β [3,4];
* one round dance β [2,4], another β [3,1];
* one round dance β [4,1], another β [3,2].
Your task is to find the number of ways n people can make two round dances if each round dance consists of exactly n/2 people.
Input
The input contains one integer n (2 β€ n β€ 20), n is an even number.
Output
Print one integer β the number of ways to make two round dances. It is guaranteed that the answer fits in the 64-bit integer data type.
Examples
Input
2
Output
1
Input
4
Output
3
Input
8
Output
1260
Input
20
Output
12164510040883200
Submitted Solution:
```
n=int(input())
ans=1
for i in range(n//2):
ans=ans*(n-i-1)//(i+1)
for i in range(1,n//2):
ans=ans*i*i
print(ans)
``` | instruction | 0 | 79,344 | 14 | 158,688 |
Yes | output | 1 | 79,344 | 14 | 158,689 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day, n people (n is an even number) met on a plaza and made two round dances, each round dance consists of exactly n/2 people. Your task is to find the number of ways n people can make two round dances if each round dance consists of exactly n/2 people. Each person should belong to exactly one of these two round dances.
Round dance is a dance circle consisting of 1 or more people. Two round dances are indistinguishable (equal) if one can be transformed to another by choosing the first participant. For example, round dances [1, 3, 4, 2], [4, 2, 1, 3] and [2, 1, 3, 4] are indistinguishable.
For example, if n=2 then the number of ways is 1: one round dance consists of the first person and the second one of the second person.
For example, if n=4 then the number of ways is 3. Possible options:
* one round dance β [1,2], another β [3,4];
* one round dance β [2,4], another β [3,1];
* one round dance β [4,1], another β [3,2].
Your task is to find the number of ways n people can make two round dances if each round dance consists of exactly n/2 people.
Input
The input contains one integer n (2 β€ n β€ 20), n is an even number.
Output
Print one integer β the number of ways to make two round dances. It is guaranteed that the answer fits in the 64-bit integer data type.
Examples
Input
2
Output
1
Input
4
Output
3
Input
8
Output
1260
Input
20
Output
12164510040883200
Submitted Solution:
```
import math
x = int(input())
y = math.factorial(x)
z = y*2/x**2
print(int(z))
``` | instruction | 0 | 79,345 | 14 | 158,690 |
Yes | output | 1 | 79,345 | 14 | 158,691 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day, n people (n is an even number) met on a plaza and made two round dances, each round dance consists of exactly n/2 people. Your task is to find the number of ways n people can make two round dances if each round dance consists of exactly n/2 people. Each person should belong to exactly one of these two round dances.
Round dance is a dance circle consisting of 1 or more people. Two round dances are indistinguishable (equal) if one can be transformed to another by choosing the first participant. For example, round dances [1, 3, 4, 2], [4, 2, 1, 3] and [2, 1, 3, 4] are indistinguishable.
For example, if n=2 then the number of ways is 1: one round dance consists of the first person and the second one of the second person.
For example, if n=4 then the number of ways is 3. Possible options:
* one round dance β [1,2], another β [3,4];
* one round dance β [2,4], another β [3,1];
* one round dance β [4,1], another β [3,2].
Your task is to find the number of ways n people can make two round dances if each round dance consists of exactly n/2 people.
Input
The input contains one integer n (2 β€ n β€ 20), n is an even number.
Output
Print one integer β the number of ways to make two round dances. It is guaranteed that the answer fits in the 64-bit integer data type.
Examples
Input
2
Output
1
Input
4
Output
3
Input
8
Output
1260
Input
20
Output
12164510040883200
Submitted Solution:
```
import math
a = int(input())
print((2 * math.factorial(a - 1)) / a)
``` | instruction | 0 | 79,346 | 14 | 158,692 |
No | output | 1 | 79,346 | 14 | 158,693 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day, n people (n is an even number) met on a plaza and made two round dances, each round dance consists of exactly n/2 people. Your task is to find the number of ways n people can make two round dances if each round dance consists of exactly n/2 people. Each person should belong to exactly one of these two round dances.
Round dance is a dance circle consisting of 1 or more people. Two round dances are indistinguishable (equal) if one can be transformed to another by choosing the first participant. For example, round dances [1, 3, 4, 2], [4, 2, 1, 3] and [2, 1, 3, 4] are indistinguishable.
For example, if n=2 then the number of ways is 1: one round dance consists of the first person and the second one of the second person.
For example, if n=4 then the number of ways is 3. Possible options:
* one round dance β [1,2], another β [3,4];
* one round dance β [2,4], another β [3,1];
* one round dance β [4,1], another β [3,2].
Your task is to find the number of ways n people can make two round dances if each round dance consists of exactly n/2 people.
Input
The input contains one integer n (2 β€ n β€ 20), n is an even number.
Output
Print one integer β the number of ways to make two round dances. It is guaranteed that the answer fits in the 64-bit integer data type.
Examples
Input
2
Output
1
Input
4
Output
3
Input
8
Output
1260
Input
20
Output
12164510040883200
Submitted Solution:
```
import sys
#from collections import deque #Counter
def rl():
return sys.stdin.readline().strip()
def pr( something ):
sys.stdout.write( str(something) + '\n')
def pra( array ):
sys.stdout.write( ' '.join([str(x) for x in array]) + '\n')
def solve(array):
return array
if __name__ == '__main__':
N = int( rl() )
H = N//2
#num_pairings = N choose H
def fact(n):
return 1 if n <= 1 else n*fact(n-1)
num_pairings = fact(N)//(2*fact(H)**2)
#print(f'np[{N}]={num_pairings}')
#now within each of those how many ways to make circles???
if True:
ncirc = 1 if H <= 3 else fact(H-1)#//2
#print(f'ncirc={ncirc}')
pr(num_pairings*ncirc*ncirc)
else:
ncirc = [0]*(H+1)
if H >= 1:
ncirc[1] = 1
if H >= 2:
ncirc[2] = 1
if H >= 3:
ncirc[3] = 1
for i in range(4,H+1):
ncirc[i] = ncirc[i-1] * (i//2)
#print(f'ncirc = {ncirc}')
pr(num_pairings*ncirc[-1]*ncirc[-1])
``` | instruction | 0 | 79,347 | 14 | 158,694 |
No | output | 1 | 79,347 | 14 | 158,695 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day, n people (n is an even number) met on a plaza and made two round dances, each round dance consists of exactly n/2 people. Your task is to find the number of ways n people can make two round dances if each round dance consists of exactly n/2 people. Each person should belong to exactly one of these two round dances.
Round dance is a dance circle consisting of 1 or more people. Two round dances are indistinguishable (equal) if one can be transformed to another by choosing the first participant. For example, round dances [1, 3, 4, 2], [4, 2, 1, 3] and [2, 1, 3, 4] are indistinguishable.
For example, if n=2 then the number of ways is 1: one round dance consists of the first person and the second one of the second person.
For example, if n=4 then the number of ways is 3. Possible options:
* one round dance β [1,2], another β [3,4];
* one round dance β [2,4], another β [3,1];
* one round dance β [4,1], another β [3,2].
Your task is to find the number of ways n people can make two round dances if each round dance consists of exactly n/2 people.
Input
The input contains one integer n (2 β€ n β€ 20), n is an even number.
Output
Print one integer β the number of ways to make two round dances. It is guaranteed that the answer fits in the 64-bit integer data type.
Examples
Input
2
Output
1
Input
4
Output
3
Input
8
Output
1260
Input
20
Output
12164510040883200
Submitted Solution:
```
import math
def fac(n):
sol=[0]*20
sol[0]=1
sol[1]=2
sol[2]=6
sol[3]=24
sol[4]=120
sol[5]=720
if sol[n-1]>0:
return sol[n-1]
else:
ans=n*fac(n-1)
sol[n-1]=ans
return sol[n-1]
n=int(input())
so=fac(n)
a=math.log2(n)
so=so//n
x=2**(a-1)
so=so//x
print(int(so))
``` | instruction | 0 | 79,348 | 14 | 158,696 |
No | output | 1 | 79,348 | 14 | 158,697 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day, n people (n is an even number) met on a plaza and made two round dances, each round dance consists of exactly n/2 people. Your task is to find the number of ways n people can make two round dances if each round dance consists of exactly n/2 people. Each person should belong to exactly one of these two round dances.
Round dance is a dance circle consisting of 1 or more people. Two round dances are indistinguishable (equal) if one can be transformed to another by choosing the first participant. For example, round dances [1, 3, 4, 2], [4, 2, 1, 3] and [2, 1, 3, 4] are indistinguishable.
For example, if n=2 then the number of ways is 1: one round dance consists of the first person and the second one of the second person.
For example, if n=4 then the number of ways is 3. Possible options:
* one round dance β [1,2], another β [3,4];
* one round dance β [2,4], another β [3,1];
* one round dance β [4,1], another β [3,2].
Your task is to find the number of ways n people can make two round dances if each round dance consists of exactly n/2 people.
Input
The input contains one integer n (2 β€ n β€ 20), n is an even number.
Output
Print one integer β the number of ways to make two round dances. It is guaranteed that the answer fits in the 64-bit integer data type.
Examples
Input
2
Output
1
Input
4
Output
3
Input
8
Output
1260
Input
20
Output
12164510040883200
Submitted Solution:
```
n=int(input())
ans=1
for i in range(3,n+1):
if i!=n//2:
ans=ans*i
if n==4 or n==8 or n==16:
ans=ans//4
elif n==2:
ans=1
elif (n//2)%2==1:
ans=ans//2
else:
ans=ans//(n//2)
print(ans)
``` | instruction | 0 | 79,349 | 14 | 158,698 |
No | output | 1 | 79,349 | 14 | 158,699 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A festival will be held in a town's main street. There are n sections in the main street. The sections are numbered 1 through n from left to right. The distance between each adjacent sections is 1.
In the festival m fireworks will be launched. The i-th (1 β€ i β€ m) launching is on time ti at section ai. If you are at section x (1 β€ x β€ n) at the time of i-th launching, you'll gain happiness value bi - |ai - x| (note that the happiness value might be a negative value).
You can move up to d length units in a unit time interval, but it's prohibited to go out of the main street. Also you can be in an arbitrary section at initial time moment (time equals to 1), and want to maximize the sum of happiness that can be gained from watching fireworks. Find the maximum total happiness.
Note that two or more fireworks can be launched at the same time.
Input
The first line contains three integers n, m, d (1 β€ n β€ 150000; 1 β€ m β€ 300; 1 β€ d β€ n).
Each of the next m lines contains integers ai, bi, ti (1 β€ ai β€ n; 1 β€ bi β€ 109; 1 β€ ti β€ 109). The i-th line contains description of the i-th launching.
It is guaranteed that the condition ti β€ ti + 1 (1 β€ i < m) will be satisfied.
Output
Print a single integer β the maximum sum of happiness that you can gain from watching all the fireworks.
Please, do not write the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
50 3 1
49 1 1
26 1 4
6 1 10
Output
-31
Input
10 2 1
1 1000 4
9 1000 4
Output
1992 | instruction | 0 | 79,466 | 14 | 158,932 |
Tags: data structures, dp, math
Correct Solution:
```
class SortedList(list):
def add(self, other):
left = -1
right = len(self)
while right - left > 1:
mid = (right + left) >> 1
if other < self[mid]:
right = mid
else:
left = mid
super().insert(right, other)
INF = int(3e18)
def solve_good(n, m, d, a, b, t):
left = SortedList()
left.append(-INF)
right = SortedList()
right.append(INF)
lborder = -INF
rborder = INF
tprev = 0
ans = 0
for ai, bi, ti in zip(a, b, t):
ans += bi
dt = ti - tprev
interval = dt * d
tprev = ti
lborder += interval
rborder -= interval
lefta = lborder + ai
righta = rborder - (n - ai)
if lefta < left[-1]:
top = left.pop()
ans -= abs(top - lefta)
left.add(lefta)
left.add(lefta)
right.add(rborder - (n - abs(top - lborder)))
elif righta > right[0]:
top = right.pop(0)
ans -= abs(top - righta)
right.add(righta)
right.add(righta)
left.add(lborder + n - abs(top - rborder))
else:
left.add(lefta)
right.add(righta)
return ans
n, m, d = [int(elem) for elem in input().split()]
a, b, t = [], [], []
for i in range(m):
ai, bi, ti = [int(elem) for elem in input().split()]
a.append(ai)
b.append(bi)
t.append(ti)
print(solve_good(n, m, d, a, b, t))
``` | output | 1 | 79,466 | 14 | 158,933 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A festival will be held in a town's main street. There are n sections in the main street. The sections are numbered 1 through n from left to right. The distance between each adjacent sections is 1.
In the festival m fireworks will be launched. The i-th (1 β€ i β€ m) launching is on time ti at section ai. If you are at section x (1 β€ x β€ n) at the time of i-th launching, you'll gain happiness value bi - |ai - x| (note that the happiness value might be a negative value).
You can move up to d length units in a unit time interval, but it's prohibited to go out of the main street. Also you can be in an arbitrary section at initial time moment (time equals to 1), and want to maximize the sum of happiness that can be gained from watching fireworks. Find the maximum total happiness.
Note that two or more fireworks can be launched at the same time.
Input
The first line contains three integers n, m, d (1 β€ n β€ 150000; 1 β€ m β€ 300; 1 β€ d β€ n).
Each of the next m lines contains integers ai, bi, ti (1 β€ ai β€ n; 1 β€ bi β€ 109; 1 β€ ti β€ 109). The i-th line contains description of the i-th launching.
It is guaranteed that the condition ti β€ ti + 1 (1 β€ i < m) will be satisfied.
Output
Print a single integer β the maximum sum of happiness that you can gain from watching all the fireworks.
Please, do not write the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
50 3 1
49 1 1
26 1 4
6 1 10
Output
-31
Input
10 2 1
1 1000 4
9 1000 4
Output
1992 | instruction | 0 | 79,467 | 14 | 158,934 |
Tags: data structures, dp, math
Correct Solution:
```
from collections import deque
def rollingmax(x, y, r, a):
k = 2 * r + 1
d = deque()
lx = len(x)
for i in range(lx + r):
if i < lx:
while d and d[-1][1] <= x[i]:
d.pop()
d.append((i, x[i]))
while d and d[0][0] <= i - k:
d.popleft()
if i >= r:
y[i - r] = d[0][1] - abs(i - r - a)
n, m, d = [int(x) for x in input().split()]
a, ball, t0 = [int(x) for x in input().split()]
f = [-abs(i - a) for i in range(1, n + 1)]
g = [0] * n
for _ in range(m - 1):
a, b, t = [int(x) for x in input().split()]
ball += b
r = min(n - 1, (t - t0) * d)
t0 = t
rollingmax(f, g, r, a - 1)
f, g = g, f
print(max(f) + ball)
``` | output | 1 | 79,467 | 14 | 158,935 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A festival will be held in a town's main street. There are n sections in the main street. The sections are numbered 1 through n from left to right. The distance between each adjacent sections is 1.
In the festival m fireworks will be launched. The i-th (1 β€ i β€ m) launching is on time ti at section ai. If you are at section x (1 β€ x β€ n) at the time of i-th launching, you'll gain happiness value bi - |ai - x| (note that the happiness value might be a negative value).
You can move up to d length units in a unit time interval, but it's prohibited to go out of the main street. Also you can be in an arbitrary section at initial time moment (time equals to 1), and want to maximize the sum of happiness that can be gained from watching fireworks. Find the maximum total happiness.
Note that two or more fireworks can be launched at the same time.
Input
The first line contains three integers n, m, d (1 β€ n β€ 150000; 1 β€ m β€ 300; 1 β€ d β€ n).
Each of the next m lines contains integers ai, bi, ti (1 β€ ai β€ n; 1 β€ bi β€ 109; 1 β€ ti β€ 109). The i-th line contains description of the i-th launching.
It is guaranteed that the condition ti β€ ti + 1 (1 β€ i < m) will be satisfied.
Output
Print a single integer β the maximum sum of happiness that you can gain from watching all the fireworks.
Please, do not write the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
50 3 1
49 1 1
26 1 4
6 1 10
Output
-31
Input
10 2 1
1 1000 4
9 1000 4
Output
1992 | instruction | 0 | 79,468 | 14 | 158,936 |
Tags: data structures, dp, math
Correct Solution:
```
from collections import deque
n,m,v=map(int,input().split())
x,t,b,bt,dp,mi,mi2,mi3,dpmin,dp2=[0]*300,[0]*300,0,0,[[0]*2for i in range(150001)],0,100000000000000,10000000000000,0,[0]*150001
d=deque()
for i in range(m):
x[i],b,t[i]=map(int,input().split())
bt+=b
for i2 in range(m-1):
if i2==0:
for i in range(1,n+1):
dp[i][0]=abs(i-x[0])
if mi2>dp[i][0]:
mi2=dp[i][0]
if m==1:
break
if(t[i2+1]-t[i2])*v>=n:
mi3=mi2
mi2=1000000000000000000
for i in range(1,n+1):
dp[i][0]=mi3+abs(i-x[i2+1])
if mi2>dp[i][0]:
mi2=dp[i][0]
continue
mi2=1000000000000000000
for i in range(1,n+1+(t[i2+1]-t[i2])*v):
if i<=n:
while (len(d)>0 and dp[i][0]<=d[len(d)-1][0]):
d.pop()
dp[i][1]=i+2*(t[i2+1]-t[i2])*v+1
d.append(dp[i])
if d[0][1]==i:
d.popleft()
if i-(t[i2+1]-t[i2])*v>=1:
dp2[i-(t[i2+1]-t[i2])*v]=d[0][0]+abs(x[i2+1]-(i-(t[i2+1]-t[i2])*v))
for i in range(1,n+1):
dp[i][0]=dp2[i]
if dp2[i]<mi2:
mi2=dp2[i]
d.clear()
for i in range(1,n+1):
if i==1:
mi=dp[i][0]
if dp[i][0]<mi:
mi=dp[i][0]
print(bt-mi)
``` | output | 1 | 79,468 | 14 | 158,937 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Because of budget cuts one IT company established new non-financial reward system instead of bonuses.
Two kinds of actions are rewarded: fixing critical bugs and suggesting new interesting features. A man who fixed a critical bug gets "I fixed a critical bug" pennant on his table. A man who suggested a new interesting feature gets "I suggested a new feature" pennant on his table.
Because of the limited budget of the new reward system only 5 "I fixed a critical bug" pennants and 3 "I suggested a new feature" pennants were bought.
In order to use these pennants for a long time they were made challenge ones. When a man fixes a new critical bug one of the earlier awarded "I fixed a critical bug" pennants is passed on to his table. When a man suggests a new interesting feature one of the earlier awarded "I suggested a new feature" pennants is passed on to his table.
One man can have several pennants of one type and of course he can have pennants of both types on his table. There are n tables in the IT company. Find the number of ways to place the pennants on these tables given that each pennant is situated on one of the tables and each table is big enough to contain any number of pennants.
Input
The only line of the input contains one integer n (1 β€ n β€ 500) β the number of tables in the IT company.
Output
Output one integer β the amount of ways to place the pennants on n tables.
Examples
Input
2
Output
24 | instruction | 0 | 79,563 | 14 | 159,126 |
Tags: combinatorics, math
Correct Solution:
```
def main():
N = 505
C = []
for i in range(N):
C.append([])
for j in range(N):
C[i].append(0)
for i in range(N):
C[i][i] = 1
for i in range(N):
C[i][0] = 1
for i in range(2, N):
for k in range(1, i):
C[i][k] = C[i - 1][k - 1] + C[i - 1][k]
n = int(input())
print(C[n + 4][5] * C[n + 2][3])
main()
``` | output | 1 | 79,563 | 14 | 159,127 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Because of budget cuts one IT company established new non-financial reward system instead of bonuses.
Two kinds of actions are rewarded: fixing critical bugs and suggesting new interesting features. A man who fixed a critical bug gets "I fixed a critical bug" pennant on his table. A man who suggested a new interesting feature gets "I suggested a new feature" pennant on his table.
Because of the limited budget of the new reward system only 5 "I fixed a critical bug" pennants and 3 "I suggested a new feature" pennants were bought.
In order to use these pennants for a long time they were made challenge ones. When a man fixes a new critical bug one of the earlier awarded "I fixed a critical bug" pennants is passed on to his table. When a man suggests a new interesting feature one of the earlier awarded "I suggested a new feature" pennants is passed on to his table.
One man can have several pennants of one type and of course he can have pennants of both types on his table. There are n tables in the IT company. Find the number of ways to place the pennants on these tables given that each pennant is situated on one of the tables and each table is big enough to contain any number of pennants.
Input
The only line of the input contains one integer n (1 β€ n β€ 500) β the number of tables in the IT company.
Output
Output one integer β the amount of ways to place the pennants on n tables.
Examples
Input
2
Output
24 | instruction | 0 | 79,564 | 14 | 159,128 |
Tags: combinatorics, math
Correct Solution:
```
from math import factorial
def C(n, k):
return factorial(n) // (factorial(n - k) * factorial(k));
def solve(x, n):
return C(x + n - 1, n - 1)
n = int(input())
print(solve(5, n) * solve(3, n))
``` | output | 1 | 79,564 | 14 | 159,129 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Because of budget cuts one IT company established new non-financial reward system instead of bonuses.
Two kinds of actions are rewarded: fixing critical bugs and suggesting new interesting features. A man who fixed a critical bug gets "I fixed a critical bug" pennant on his table. A man who suggested a new interesting feature gets "I suggested a new feature" pennant on his table.
Because of the limited budget of the new reward system only 5 "I fixed a critical bug" pennants and 3 "I suggested a new feature" pennants were bought.
In order to use these pennants for a long time they were made challenge ones. When a man fixes a new critical bug one of the earlier awarded "I fixed a critical bug" pennants is passed on to his table. When a man suggests a new interesting feature one of the earlier awarded "I suggested a new feature" pennants is passed on to his table.
One man can have several pennants of one type and of course he can have pennants of both types on his table. There are n tables in the IT company. Find the number of ways to place the pennants on these tables given that each pennant is situated on one of the tables and each table is big enough to contain any number of pennants.
Input
The only line of the input contains one integer n (1 β€ n β€ 500) β the number of tables in the IT company.
Output
Output one integer β the amount of ways to place the pennants on n tables.
Examples
Input
2
Output
24 | instruction | 0 | 79,565 | 14 | 159,130 |
Tags: combinatorics, math
Correct Solution:
```
n = int(input())
print (n * (n + 1) * (n + 2) * (n + 3) * (n + 4) // 120 * n * (n + 1) * (n + 2) // 6)
``` | output | 1 | 79,565 | 14 | 159,131 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Because of budget cuts one IT company established new non-financial reward system instead of bonuses.
Two kinds of actions are rewarded: fixing critical bugs and suggesting new interesting features. A man who fixed a critical bug gets "I fixed a critical bug" pennant on his table. A man who suggested a new interesting feature gets "I suggested a new feature" pennant on his table.
Because of the limited budget of the new reward system only 5 "I fixed a critical bug" pennants and 3 "I suggested a new feature" pennants were bought.
In order to use these pennants for a long time they were made challenge ones. When a man fixes a new critical bug one of the earlier awarded "I fixed a critical bug" pennants is passed on to his table. When a man suggests a new interesting feature one of the earlier awarded "I suggested a new feature" pennants is passed on to his table.
One man can have several pennants of one type and of course he can have pennants of both types on his table. There are n tables in the IT company. Find the number of ways to place the pennants on these tables given that each pennant is situated on one of the tables and each table is big enough to contain any number of pennants.
Input
The only line of the input contains one integer n (1 β€ n β€ 500) β the number of tables in the IT company.
Output
Output one integer β the amount of ways to place the pennants on n tables.
Examples
Input
2
Output
24 | instruction | 0 | 79,566 | 14 | 159,132 |
Tags: combinatorics, math
Correct Solution:
```
n = int(input())
ans = int((5+n-1)*(5+n-2)*(5+n-3)*(5+n-4)*(5+n-5)/5/4/3/2)*int((3+n-1)*(3+n-2)*(3+n-3)/3/2)
print(int(ans))
``` | output | 1 | 79,566 | 14 | 159,133 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Because of budget cuts one IT company established new non-financial reward system instead of bonuses.
Two kinds of actions are rewarded: fixing critical bugs and suggesting new interesting features. A man who fixed a critical bug gets "I fixed a critical bug" pennant on his table. A man who suggested a new interesting feature gets "I suggested a new feature" pennant on his table.
Because of the limited budget of the new reward system only 5 "I fixed a critical bug" pennants and 3 "I suggested a new feature" pennants were bought.
In order to use these pennants for a long time they were made challenge ones. When a man fixes a new critical bug one of the earlier awarded "I fixed a critical bug" pennants is passed on to his table. When a man suggests a new interesting feature one of the earlier awarded "I suggested a new feature" pennants is passed on to his table.
One man can have several pennants of one type and of course he can have pennants of both types on his table. There are n tables in the IT company. Find the number of ways to place the pennants on these tables given that each pennant is situated on one of the tables and each table is big enough to contain any number of pennants.
Input
The only line of the input contains one integer n (1 β€ n β€ 500) β the number of tables in the IT company.
Output
Output one integer β the amount of ways to place the pennants on n tables.
Examples
Input
2
Output
24 | instruction | 0 | 79,567 | 14 | 159,134 |
Tags: combinatorics, math
Correct Solution:
```
n = int(input())
from functools import lru_cache
@lru_cache(maxsize = None)
def fun(i , k , p):
if i == n:
if k == 0 and p == 0:
return 1
return 0
ans = 0
for x in range(6):
for y in range(4):
if x <= k and y <= p:
ans += fun(i + 1 , k - x , p - y)
return ans
print(fun(0 , 5 , 3))
``` | output | 1 | 79,567 | 14 | 159,135 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Because of budget cuts one IT company established new non-financial reward system instead of bonuses.
Two kinds of actions are rewarded: fixing critical bugs and suggesting new interesting features. A man who fixed a critical bug gets "I fixed a critical bug" pennant on his table. A man who suggested a new interesting feature gets "I suggested a new feature" pennant on his table.
Because of the limited budget of the new reward system only 5 "I fixed a critical bug" pennants and 3 "I suggested a new feature" pennants were bought.
In order to use these pennants for a long time they were made challenge ones. When a man fixes a new critical bug one of the earlier awarded "I fixed a critical bug" pennants is passed on to his table. When a man suggests a new interesting feature one of the earlier awarded "I suggested a new feature" pennants is passed on to his table.
One man can have several pennants of one type and of course he can have pennants of both types on his table. There are n tables in the IT company. Find the number of ways to place the pennants on these tables given that each pennant is situated on one of the tables and each table is big enough to contain any number of pennants.
Input
The only line of the input contains one integer n (1 β€ n β€ 500) β the number of tables in the IT company.
Output
Output one integer β the amount of ways to place the pennants on n tables.
Examples
Input
2
Output
24 | instruction | 0 | 79,568 | 14 | 159,136 |
Tags: combinatorics, math
Correct Solution:
```
n=int(input())
print( (n*(n+1)*(n+2)*(n+3)*(n+4)//(2*3*4*5))*
(n*(n+1)*(n+2)//(2*3)) )
``` | output | 1 | 79,568 | 14 | 159,137 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Because of budget cuts one IT company established new non-financial reward system instead of bonuses.
Two kinds of actions are rewarded: fixing critical bugs and suggesting new interesting features. A man who fixed a critical bug gets "I fixed a critical bug" pennant on his table. A man who suggested a new interesting feature gets "I suggested a new feature" pennant on his table.
Because of the limited budget of the new reward system only 5 "I fixed a critical bug" pennants and 3 "I suggested a new feature" pennants were bought.
In order to use these pennants for a long time they were made challenge ones. When a man fixes a new critical bug one of the earlier awarded "I fixed a critical bug" pennants is passed on to his table. When a man suggests a new interesting feature one of the earlier awarded "I suggested a new feature" pennants is passed on to his table.
One man can have several pennants of one type and of course he can have pennants of both types on his table. There are n tables in the IT company. Find the number of ways to place the pennants on these tables given that each pennant is situated on one of the tables and each table is big enough to contain any number of pennants.
Input
The only line of the input contains one integer n (1 β€ n β€ 500) β the number of tables in the IT company.
Output
Output one integer β the amount of ways to place the pennants on n tables.
Examples
Input
2
Output
24 | instruction | 0 | 79,569 | 14 | 159,138 |
Tags: combinatorics, math
Correct Solution:
```
import math
fac = math.factorial
n = int(input())
def nCr(n,k):
return fac(n)//(fac(n-k)*fac(k))
t = nCr(5+n-1,5)*nCr(3+n-1,3)
print((t))
``` | output | 1 | 79,569 | 14 | 159,139 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Because of budget cuts one IT company established new non-financial reward system instead of bonuses.
Two kinds of actions are rewarded: fixing critical bugs and suggesting new interesting features. A man who fixed a critical bug gets "I fixed a critical bug" pennant on his table. A man who suggested a new interesting feature gets "I suggested a new feature" pennant on his table.
Because of the limited budget of the new reward system only 5 "I fixed a critical bug" pennants and 3 "I suggested a new feature" pennants were bought.
In order to use these pennants for a long time they were made challenge ones. When a man fixes a new critical bug one of the earlier awarded "I fixed a critical bug" pennants is passed on to his table. When a man suggests a new interesting feature one of the earlier awarded "I suggested a new feature" pennants is passed on to his table.
One man can have several pennants of one type and of course he can have pennants of both types on his table. There are n tables in the IT company. Find the number of ways to place the pennants on these tables given that each pennant is situated on one of the tables and each table is big enough to contain any number of pennants.
Input
The only line of the input contains one integer n (1 β€ n β€ 500) β the number of tables in the IT company.
Output
Output one integer β the amount of ways to place the pennants on n tables.
Examples
Input
2
Output
24 | instruction | 0 | 79,570 | 14 | 159,140 |
Tags: combinatorics, math
Correct Solution:
```
from math import factorial as f
n = int(input())
print(int((int(f(n + 4) / (f(n - 1) * f(5)))) * (int(f(n + 2) / (f(n - 1) * f(3))))))
``` | output | 1 | 79,570 | 14 | 159,141 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arkady words in a large company. There are n employees working in a system of a strict hierarchy. Namely, each employee, with an exception of the CEO, has exactly one immediate manager. The CEO is a manager (through a chain of immediate managers) of all employees.
Each employee has an integer rank. The CEO has rank equal to 1, each other employee has rank equal to the rank of his immediate manager plus 1.
Arkady has a good post in the company, however, he feels that he is nobody in the company's structure, and there are a lot of people who can replace him. He introduced the value of replaceability. Consider an employee a and an employee b, the latter being manager of a (not necessarily immediate). Then the replaceability r(a, b) of a with respect to b is the number of subordinates (not necessarily immediate) of the manager b, whose rank is not greater than the rank of a. Apart from replaceability, Arkady introduced the value of negligibility. The negligibility za of employee a equals the sum of his replaceabilities with respect to all his managers, i.e. <image>, where the sum is taken over all his managers b.
Arkady is interested not only in negligibility of himself, but also in negligibility of all employees in the company. Find the negligibility of each employee for Arkady.
Input
The first line contains single integer n (1 β€ n β€ 5Β·105) β the number of employees in the company.
The second line contains n integers p1, p2, ..., pn (0 β€ pi β€ n), where pi = 0 if the i-th employee is the CEO, otherwise pi equals the id of the immediate manager of the employee with id i. The employees are numbered from 1 to n. It is guaranteed that there is exactly one 0 among these values, and also that the CEO is a manager (not necessarily immediate) for all the other employees.
Output
Print n integers β the negligibilities of all employees in the order of their ids: z1, z2, ..., zn.
Examples
Input
4
0 1 2 1
Output
0 2 4 2
Input
5
2 3 4 5 0
Output
10 6 3 1 0
Input
5
0 1 1 1 3
Output
0 3 3 3 5
Note
Consider the first example:
* The CEO has no managers, thus z1 = 0.
* r(2, 1) = 2 (employees 2 and 4 suit the conditions, employee 3 has too large rank). Thus z2 = r(2, 1) = 2.
* Similarly, z4 = r(4, 1) = 2.
* r(3, 2) = 1 (employee 3 is a subordinate of 2 and has suitable rank). r(3, 1) = 3 (employees 2, 3, 4 suit the conditions). Thus z3 = r(3, 2) + r(3, 1) = 4.
Submitted Solution:
```
class Node:
def __init__(self, parent=None, rank=None, child_count=0, z=None):
self.parent = parent
self.rank = rank
self.child_count = child_count
self.z = z
def __str__(self):
return " ".join(['parent', str(self.parent),
'rank', str(self.rank),
'child_count', str(self.child_count),
'z', str(self.z)])
def visit(node_id, tree):
if tree[node_id].z is not None:
return
parent_id = tree[node_id].parent
if parent_id == 0:
tree[node_id].rank = 1
tree[node_id].z = 0
return
if tree[parent_id].z is None:
visit(parent_id, tree)
tree[node_id].rank = tree[parent_id].rank + 1
tree[node_id].z = tree[parent_id].z + tree[parent_id].rank * tree[parent_id].child_count
if __name__ == "__main__":
node_count = int(input())
parents = [int(x) for x in input().split()]
tree = {}
for node in range(node_count):
curr_id = node + 1
parent_id = parents[node]
if curr_id not in tree:
tree[curr_id] = Node()
tree[curr_id].parent = parent_id
if parent_id != 0:
if parent_id not in tree:
tree[parent_id] = Node()
tree[parent_id].child_count += 1
for node in tree:
visit(node, tree)
print(" ".join([str(tree[node].z) for node in tree]))
``` | instruction | 0 | 79,642 | 14 | 159,284 |
No | output | 1 | 79,642 | 14 | 159,285 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are two main kinds of events in the life of top-model: fashion shows and photo shoots. Participating in any of these events affects the rating of appropriate top-model. After each photo shoot model's rating increases by a and after each fashion show decreases by b (designers do too many experiments nowadays). Moreover, sometimes top-models participates in talk shows. After participating in talk show model becomes more popular and increasing of her rating after photo shoots become c and decreasing of her rating after fashion show becomes d.
Izabella wants to participate in a talk show, but she wants to do it in such a way that her rating will never become negative. Help her to find a suitable moment for participating in the talk show.
Let's assume that model's career begins in moment 0. At that moment Izabella's rating was equal to start. If talk show happens in moment t if will affect all events in model's life in interval of time [t..t + len) (including t and not including t + len), where len is duration of influence.
Izabella wants to participate in a talk show, but she wants to do it in such a way that her rating will not become become negative before talk show or during period of influence of talk show. Help her to find a suitable moment for participating in the talk show.
Input
In first line there are 7 positive integers n, a, b, c, d, start, len (1 β€ n β€ 3Β·105, 0 β€ start β€ 109, 1 β€ a, b, c, d, len β€ 109), where n is a number of fashion shows and photo shoots, a, b, c and d are rating changes described above, start is an initial rating of model and len is a duration of influence of talk show.
In next n lines descriptions of events are given. Each of those lines contains two integers ti and qi (1 β€ ti β€ 109, 0 β€ q β€ 1) β moment, in which event happens and type of this event. Type 0 corresponds to the fashion show and type 1 β to photo shoot.
Events are given in order of increasing ti, all ti are different.
Output
Print one non-negative integer t β the moment of time in which talk show should happen to make Izabella's rating non-negative before talk show and during period of influence of talk show. If there are multiple answers print smallest of them. If there are no such moments, print - 1.
Examples
Input
5 1 1 1 4 0 5
1 1
2 1
3 1
4 0
5 0
Output
6
Input
1 1 2 1 2 1 2
1 0
Output
-1 | instruction | 0 | 79,643 | 14 | 159,286 |
Tags: data structures, two pointers
Correct Solution:
```
from sys import stdin
from collections import deque
def main():
n, a, b, c, d, st, l = map(int, input().split())
q = deque()
po = q.popleft
pu = q.append
mq = deque()
mpop = mq.pop
mpo = mq.popleft
mpu = mq.append
sb = [0] * (n + 1)
mst = st
pu((0, 0, mst, st))
pp = 0
for i, line in enumerate(stdin):
line = line.split()
t = int(line[0], 10)
while q and q[0][0] + l <= t:
p, j, ma, sa = po()
if ma < 0:
print (-1)
return
while mq and mq[0][1] < p:
mpo()
sa += (-sb[j] + mq[0][0]) if mq else 0
if ma > sa:
ma = sa
if ma >= 0:
print (min(pp, p))
return
pp = p + 1
pu((t, i, mst, st))
if line[1] == '1':
st += a
x = sb[i] + c
else:
st -= b
x = sb[i] - d
if mst > st:
mst = st
while mq and mq[-1][0] > x:
mpop()
mpu((x, t))
sb[i+1] = x
pu((t + 1, n, mst, st))
while q:
p, j, ma, sa = po()
if ma < 0:
print (-1)
return
while mq and mq[0][1] < p:
mpo()
sa += (-sb[j] + mq[0][0]) if mq else 0
if ma > sa:
ma = sa
if ma >= 0:
print (min(pp, p))
return
pp = p + 1
print (-1)
main()
``` | output | 1 | 79,643 | 14 | 159,287 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are two main kinds of events in the life of top-model: fashion shows and photo shoots. Participating in any of these events affects the rating of appropriate top-model. After each photo shoot model's rating increases by a and after each fashion show decreases by b (designers do too many experiments nowadays). Moreover, sometimes top-models participates in talk shows. After participating in talk show model becomes more popular and increasing of her rating after photo shoots become c and decreasing of her rating after fashion show becomes d.
Izabella wants to participate in a talk show, but she wants to do it in such a way that her rating will never become negative. Help her to find a suitable moment for participating in the talk show.
Let's assume that model's career begins in moment 0. At that moment Izabella's rating was equal to start. If talk show happens in moment t if will affect all events in model's life in interval of time [t..t + len) (including t and not including t + len), where len is duration of influence.
Izabella wants to participate in a talk show, but she wants to do it in such a way that her rating will not become become negative before talk show or during period of influence of talk show. Help her to find a suitable moment for participating in the talk show.
Input
In first line there are 7 positive integers n, a, b, c, d, start, len (1 β€ n β€ 3Β·105, 0 β€ start β€ 109, 1 β€ a, b, c, d, len β€ 109), where n is a number of fashion shows and photo shoots, a, b, c and d are rating changes described above, start is an initial rating of model and len is a duration of influence of talk show.
In next n lines descriptions of events are given. Each of those lines contains two integers ti and qi (1 β€ ti β€ 109, 0 β€ q β€ 1) β moment, in which event happens and type of this event. Type 0 corresponds to the fashion show and type 1 β to photo shoot.
Events are given in order of increasing ti, all ti are different.
Output
Print one non-negative integer t β the moment of time in which talk show should happen to make Izabella's rating non-negative before talk show and during period of influence of talk show. If there are multiple answers print smallest of them. If there are no such moments, print - 1.
Examples
Input
5 1 1 1 4 0 5
1 1
2 1
3 1
4 0
5 0
Output
6
Input
1 1 2 1 2 1 2
1 0
Output
-1
Submitted Solution:
```
import math
def bifind(x, pivot):
#find the first number's subscript in x
#s.t. the number is bigger or queal than pivot
l, r = 0, len(x)
#bi find in [l,r)
while (r-l) > 1:# it must come to 1 before come to 0
mid = int((l+r)/2)
if x[mid] >= pivot:# if true
r = mid
else:
l = mid
if (x[l] < pivot)and(x[r] >= pivot):
return r
if (x[l] >= pivot)and(x[r] >= pivot):
return l
return -1
def f(i,j):#ST[j,i]葨瀺[i,i+2^j-1]θΏδΈͺεΊι΄ε
ηζε°εΌ
if ST[j][i] != -15289758923 :return ST[j][i]
if j == 0 :
ST[j][i] = total[i]
return ST[j][i]
ans = min(f(i,j-1),f(i+2**(j-1),j-1))
ST[j][i] = ans
return ans
def g(x,y):
i = min(x,y)
j = max(x,y)
k = int(math.log(j-i+1)/math.log(2))
return min(f(i,k), f(j-2**k+1,k))
#return the min number in total[i,j]
n, a, b, c, d, start, l = map(int, input().split())
photo = []
fashion = []
t = []
q = []
hhh = start
ddl = 12345677801234
for i in range(n):
x, y = map(int,input().split())
if x > ddl:
continue
t.append(x)
q.append(y)
if y : hhh += a
else : hhh -= b
if (y < 0) and (ddl != 12345677801234):
ddl = x + l
n = len(t)
count = [start]
#count[i] = the rating of first i event happend without inflence
deadline = 12345677801234
for i in range(n):
if q[i]: count.append(count[i] + a)
else : count.append(count[i] - b)
if count[i+1] < 0:
deadline = t[i]
break
#must start talk show before t[i]
if q[0]:
total = [c]
else:
total = [-d]
#total[i] = the rating after i+1 event happend with inflence
for i in range(1, n):
if q[i]: total.append(total[i-1] + c)
else : total.append(total[i-1] - d)
ST = []
for i in range(19):
ST.append([-15289758923 for ppp in range(300005-2**i)])
for i in range(n):
ST[0][i] = total[i]
t.append(10000000000)
tpoint = [0]
for i in range(n):#all possible answer
tpoint.append(t[i]+1)
tpoint.append(t[i]-l+1)
ans = 1234567881234
for i in tpoint:
if (i >= ans) and (ans != 1234567881234) : continue
if i >= deadline : continue
if i < 0 : continue
x, y = bifind(t, i), bifind(t, i+l)
#print(i,x,y)
#the influence is last in [x,y) in t
init = count[x-1]
if x == y:
if init >=0:
ans = min(i, ans)
continue
if x : xiu = total[x-1]
else : xiu = 0
if g(x,y-1) - xiu + init >= 0:
ans = min(i, ans)
if ans == 1234567881234: print(-1)
else : print(ans)
``` | instruction | 0 | 79,644 | 14 | 159,288 |
No | output | 1 | 79,644 | 14 | 159,289 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are two main kinds of events in the life of top-model: fashion shows and photo shoots. Participating in any of these events affects the rating of appropriate top-model. After each photo shoot model's rating increases by a and after each fashion show decreases by b (designers do too many experiments nowadays). Moreover, sometimes top-models participates in talk shows. After participating in talk show model becomes more popular and increasing of her rating after photo shoots become c and decreasing of her rating after fashion show becomes d.
Izabella wants to participate in a talk show, but she wants to do it in such a way that her rating will never become negative. Help her to find a suitable moment for participating in the talk show.
Let's assume that model's career begins in moment 0. At that moment Izabella's rating was equal to start. If talk show happens in moment t if will affect all events in model's life in interval of time [t..t + len) (including t and not including t + len), where len is duration of influence.
Izabella wants to participate in a talk show, but she wants to do it in such a way that her rating will not become become negative before talk show or during period of influence of talk show. Help her to find a suitable moment for participating in the talk show.
Input
In first line there are 7 positive integers n, a, b, c, d, start, len (1 β€ n β€ 3Β·105, 0 β€ start β€ 109, 1 β€ a, b, c, d, len β€ 109), where n is a number of fashion shows and photo shoots, a, b, c and d are rating changes described above, start is an initial rating of model and len is a duration of influence of talk show.
In next n lines descriptions of events are given. Each of those lines contains two integers ti and qi (1 β€ ti β€ 109, 0 β€ q β€ 1) β moment, in which event happens and type of this event. Type 0 corresponds to the fashion show and type 1 β to photo shoot.
Events are given in order of increasing ti, all ti are different.
Output
Print one non-negative integer t β the moment of time in which talk show should happen to make Izabella's rating non-negative before talk show and during period of influence of talk show. If there are multiple answers print smallest of them. If there are no such moments, print - 1.
Examples
Input
5 1 1 1 4 0 5
1 1
2 1
3 1
4 0
5 0
Output
6
Input
1 1 2 1 2 1 2
1 0
Output
-1
Submitted Solution:
```
n,a,b,c,d,start,len=list(map(int,input().split()))
t=[]
event=[]
delts=int(start)
def main():
global delts, event, t
for i in range(n):
x, y = list(map(int, input().split()))
if y == 1:
delts += a
event.append(a)
else:
delts -= b
event.append(-b)
t.append(x)
res = int(start)
k = -1
event=[0]+event
t=t+[10000000]
for i in [0]+t:
k += 1
z = int(k)
kol = int(res)
if z==0:
z=1
while i + len > t[z]:
#print(kol,z)
if event[z] == a:
kol += c
else:
kol -= d
if kol<0:
#print(kol,z,'vixod')
break
z += 1
else:
#print(i)
return
#print(kol,i)
res += event[k]
if delts < 0:
print(-1)
else:
print(max(t) + 1)
return
main()
``` | instruction | 0 | 79,645 | 14 | 159,290 |
No | output | 1 | 79,645 | 14 | 159,291 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are two main kinds of events in the life of top-model: fashion shows and photo shoots. Participating in any of these events affects the rating of appropriate top-model. After each photo shoot model's rating increases by a and after each fashion show decreases by b (designers do too many experiments nowadays). Moreover, sometimes top-models participates in talk shows. After participating in talk show model becomes more popular and increasing of her rating after photo shoots become c and decreasing of her rating after fashion show becomes d.
Izabella wants to participate in a talk show, but she wants to do it in such a way that her rating will never become negative. Help her to find a suitable moment for participating in the talk show.
Let's assume that model's career begins in moment 0. At that moment Izabella's rating was equal to start. If talk show happens in moment t if will affect all events in model's life in interval of time [t..t + len) (including t and not including t + len), where len is duration of influence.
Izabella wants to participate in a talk show, but she wants to do it in such a way that her rating will not become become negative before talk show or during period of influence of talk show. Help her to find a suitable moment for participating in the talk show.
Input
In first line there are 7 positive integers n, a, b, c, d, start, len (1 β€ n β€ 3Β·105, 0 β€ start β€ 109, 1 β€ a, b, c, d, len β€ 109), where n is a number of fashion shows and photo shoots, a, b, c and d are rating changes described above, start is an initial rating of model and len is a duration of influence of talk show.
In next n lines descriptions of events are given. Each of those lines contains two integers ti and qi (1 β€ ti β€ 109, 0 β€ q β€ 1) β moment, in which event happens and type of this event. Type 0 corresponds to the fashion show and type 1 β to photo shoot.
Events are given in order of increasing ti, all ti are different.
Output
Print one non-negative integer t β the moment of time in which talk show should happen to make Izabella's rating non-negative before talk show and during period of influence of talk show. If there are multiple answers print smallest of them. If there are no such moments, print - 1.
Examples
Input
5 1 1 1 4 0 5
1 1
2 1
3 1
4 0
5 0
Output
6
Input
1 1 2 1 2 1 2
1 0
Output
-1
Submitted Solution:
```
# -*- coding: utf-8 -*-
import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
"""
created by shhuan at 2017/11/4 01:08
"""
n, a, b, c, d, start, l = map(int, input().split())
A = []
for i in range(n):
t, q = map(int, input().split())
A.append((t, q))
# fashion show, -b, -d
# photo shoot, +a, +c
left1 = [0] * (n+1)
left2 = [0] * (n+1)
left1[0] = start
left2[0] = start
lasti = -1
for i in range(1, n+1):
t, q = A[i-1]
# q=0, fashion show
# q=1, photo shoot
if q == 0:
left1[i] = left1[i-1] - b
left2[i] = left2[i-1] - d
else:
left1[i] = left1[i-1] + a
left2[i] = left2[i-1] + c
if lasti < 0 and left1[i] < 0:
lasti = i
se = set()
uk = 0
for i in range(0, n+1):
if left1[i] < 0:
print(-1)
exit(0)
if i:
se.remove(left2[i])
while uk < n and A[uk][0] - 1 < A[i][0] + l:
se.add(left2[uk])
uk += 1
if not se:
print(A[i][0] + 1)
exit(0)
v = min(se)
v += left1[i] - left2[i]
if v >= 0:
print(A[i][0] + 1)
exit(0)
``` | instruction | 0 | 79,646 | 14 | 159,292 |
No | output | 1 | 79,646 | 14 | 159,293 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are two main kinds of events in the life of top-model: fashion shows and photo shoots. Participating in any of these events affects the rating of appropriate top-model. After each photo shoot model's rating increases by a and after each fashion show decreases by b (designers do too many experiments nowadays). Moreover, sometimes top-models participates in talk shows. After participating in talk show model becomes more popular and increasing of her rating after photo shoots become c and decreasing of her rating after fashion show becomes d.
Izabella wants to participate in a talk show, but she wants to do it in such a way that her rating will never become negative. Help her to find a suitable moment for participating in the talk show.
Let's assume that model's career begins in moment 0. At that moment Izabella's rating was equal to start. If talk show happens in moment t if will affect all events in model's life in interval of time [t..t + len) (including t and not including t + len), where len is duration of influence.
Izabella wants to participate in a talk show, but she wants to do it in such a way that her rating will not become become negative before talk show or during period of influence of talk show. Help her to find a suitable moment for participating in the talk show.
Input
In first line there are 7 positive integers n, a, b, c, d, start, len (1 β€ n β€ 3Β·105, 0 β€ start β€ 109, 1 β€ a, b, c, d, len β€ 109), where n is a number of fashion shows and photo shoots, a, b, c and d are rating changes described above, start is an initial rating of model and len is a duration of influence of talk show.
In next n lines descriptions of events are given. Each of those lines contains two integers ti and qi (1 β€ ti β€ 109, 0 β€ q β€ 1) β moment, in which event happens and type of this event. Type 0 corresponds to the fashion show and type 1 β to photo shoot.
Events are given in order of increasing ti, all ti are different.
Output
Print one non-negative integer t β the moment of time in which talk show should happen to make Izabella's rating non-negative before talk show and during period of influence of talk show. If there are multiple answers print smallest of them. If there are no such moments, print - 1.
Examples
Input
5 1 1 1 4 0 5
1 1
2 1
3 1
4 0
5 0
Output
6
Input
1 1 2 1 2 1 2
1 0
Output
-1
Submitted Solution:
```
# -*- coding: utf-8 -*-
import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
"""
created by shhuan at 2017/11/4 01:08
"""
n, a, b, c, d, start, l = map(int, input().split())
A = []
for i in range(n):
A.append([int(x) for x in input().split()])
sm = [0] * (n+1)
ps = [0] * (n+1)
fs = [0] * (n+1)
sm[0] = start
X = 0
for i in range(1, n+1):
if A[i-1][1] == 1:
sm[i] = sm[i-1] + a
ps[i] = ps[i-1] + 1
fs[i] = fs[i-1]
else:
sm[i] = sm[i-1] - b
ps[i] = ps[i-1]
fs[i] = fs[i-1] + 1
X = min(X, sm[i])
ts = [x[0] for x in A]
if X >= 0:
print(ts[-1] + 1)
exit(0)
for si, s in enumerate(ts):
# update timerange [ti, ti+l)
ti = bisect.bisect_left(ts, s+l)
ti -= 1
if 0 <= ti < n:
t = ts[ti]
if s <= t < s+l:
p = ps[ti+1]-ps[si]
f = fs[ti+1]-fs[si]
diff = p*(c-a) + f*(b-d)
if diff >= abs(X):
print(s)
exit(0)
print(-1)
``` | instruction | 0 | 79,647 | 14 | 159,294 |
No | output | 1 | 79,647 | 14 | 159,295 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, then one individual kills the other one: a rock kills scissors, scissors kill paper, and paper kills a rock. Your task is to determine for each species what is the probability that this species will be the only one to inhabit this island after a long enough period of time.
Input
The single line contains three integers r, s and p (1 β€ r, s, p β€ 100) β the original number of individuals in the species of rock, scissors and paper, respectively.
Output
Print three space-separated real numbers: the probabilities, at which the rocks, the scissors and the paper will be the only surviving species, respectively. The answer will be considered correct if the relative or absolute error of each number doesn't exceed 10 - 9.
Examples
Input
2 2 2
Output
0.333333333333 0.333333333333 0.333333333333
Input
2 1 2
Output
0.150000000000 0.300000000000 0.550000000000
Input
1 1 3
Output
0.057142857143 0.657142857143 0.285714285714 | instruction | 0 | 80,403 | 14 | 160,806 |
Tags: dp, probabilities
Correct Solution:
```
r, s, p = map(int, input().split())
dp = [[[0] * (p+1) for _ in range(s+1)] for _ in range(r+1)]
dp[r][s][p] = 1
def nCk(n, k):
if n <= k:
return 1
res = 1
for i in range(k):
res *= n-i
for i in range(k):
res //= (i+1)
return res
C = [nCk(i, 2) for i in range(r+s+p+1)]
for ri in range(r, -1, -1):
for si in range(s, -1, -1):
for pi in range(p, -1, -1):
t = ri * si + si * pi + pi * ri
if t == 0: continue
if ri > 0:
dp[ri-1][si][pi] += dp[ri][si][pi] * ri * pi / t
if si > 0:
dp[ri][si-1][pi] += dp[ri][si][pi] * ri * si / t
if pi > 0:
dp[ri][si][pi-1] += dp[ri][si][pi] * si * pi / t
r_sum = sum([dp[ri][0][0] for ri in range(r+1)])
s_sum = sum([dp[0][si][0] for si in range(s+1)])
p_sum = sum([dp[0][0][pi] for pi in range(p+1)])
print(r_sum, s_sum, p_sum)
``` | output | 1 | 80,403 | 14 | 160,807 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, then one individual kills the other one: a rock kills scissors, scissors kill paper, and paper kills a rock. Your task is to determine for each species what is the probability that this species will be the only one to inhabit this island after a long enough period of time.
Input
The single line contains three integers r, s and p (1 β€ r, s, p β€ 100) β the original number of individuals in the species of rock, scissors and paper, respectively.
Output
Print three space-separated real numbers: the probabilities, at which the rocks, the scissors and the paper will be the only surviving species, respectively. The answer will be considered correct if the relative or absolute error of each number doesn't exceed 10 - 9.
Examples
Input
2 2 2
Output
0.333333333333 0.333333333333 0.333333333333
Input
2 1 2
Output
0.150000000000 0.300000000000 0.550000000000
Input
1 1 3
Output
0.057142857143 0.657142857143 0.285714285714 | instruction | 0 | 80,404 | 14 | 160,808 |
Tags: dp, probabilities
Correct Solution:
```
def read_data():
r, s, p = map(int, input().split())
return r, s, p
def P(r, s, p):
global memo
if memo[r][s][p]:
return memo[r][s][p]
if r == 0:
return (0, 1, 0)
if s == 0:
return (0, 0, 1)
if p == 0:
return (1, 0, 0)
rs = r * s
rp = r * p
sp = s * p
denom = rs + rp + sp
prs = rs / denom
prp = rp / denom
psp = sp / denom
r1, s1, p1 = P(r, s-1, p)
r2, s2, p2 = P(r-1, s, p)
r3, s3, p3 = P(r, s, p-1)
new_r = r1 * prs + r2 * prp + r3 * psp
new_s = s1 * prs + s2 * prp + s3 * psp
new_p = p1 * prs + p2 * prp + p3 * psp
memo[r][s][p] = (new_r, new_s, new_p)
memo[s][p][r] = (new_s, new_p, new_r)
memo[p][r][s] = (new_p, new_r, new_s)
return new_r, new_s, new_p
if __name__ == '__main__':
r, s, p = read_data()
memo = [[[False] * 101 for i in range(101)] for j in range(101)]
pr, ps, pp = P(r, s, p)
print('{:.12} {:.12} {:.12}'.format(pr, ps, pp))
``` | output | 1 | 80,404 | 14 | 160,809 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, then one individual kills the other one: a rock kills scissors, scissors kill paper, and paper kills a rock. Your task is to determine for each species what is the probability that this species will be the only one to inhabit this island after a long enough period of time.
Input
The single line contains three integers r, s and p (1 β€ r, s, p β€ 100) β the original number of individuals in the species of rock, scissors and paper, respectively.
Output
Print three space-separated real numbers: the probabilities, at which the rocks, the scissors and the paper will be the only surviving species, respectively. The answer will be considered correct if the relative or absolute error of each number doesn't exceed 10 - 9.
Examples
Input
2 2 2
Output
0.333333333333 0.333333333333 0.333333333333
Input
2 1 2
Output
0.150000000000 0.300000000000 0.550000000000
Input
1 1 3
Output
0.057142857143 0.657142857143 0.285714285714 | instruction | 0 | 80,405 | 14 | 160,810 |
Tags: dp, probabilities
Correct Solution:
```
r, s, p = map(int, input().split())
memo = [[[-1] * 101 for _ in range(101)] for _ in range(101)]
def f(n):
return n * (n - 1) // 2
def dfs(r, s, p):
if memo[r][s][p] > -0.5:
return memo[r][s][p]
n = r + s + p
if r == 0:
memo[r][s][p] = 0.0
return memo[r][s][p]
if s == 0 and p == 0:
memo[r][s][p] = 1.0
return memo[r][s][p]
ans = 0.0
d = 1 - f(r) / f(n) - f(s) / f(n) - f(p) / f(n)
if r > 0 and s > 0:
ans += ((r * s) / f(n)) * dfs(r, s - 1, p)
if s > 0 and p > 0:
ans += ((s * p) / f(n)) * dfs(r, s, p - 1)
if p > 0 and r > 0:
ans += ((p * r) / f(n)) * dfs(r - 1, s, p)
memo[r][s][p] = ans / d
return memo[r][s][p]
print(dfs(r, s, p), dfs(s, p, r), dfs(p, r, s))
``` | output | 1 | 80,405 | 14 | 160,811 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, then one individual kills the other one: a rock kills scissors, scissors kill paper, and paper kills a rock. Your task is to determine for each species what is the probability that this species will be the only one to inhabit this island after a long enough period of time.
Input
The single line contains three integers r, s and p (1 β€ r, s, p β€ 100) β the original number of individuals in the species of rock, scissors and paper, respectively.
Output
Print three space-separated real numbers: the probabilities, at which the rocks, the scissors and the paper will be the only surviving species, respectively. The answer will be considered correct if the relative or absolute error of each number doesn't exceed 10 - 9.
Examples
Input
2 2 2
Output
0.333333333333 0.333333333333 0.333333333333
Input
2 1 2
Output
0.150000000000 0.300000000000 0.550000000000
Input
1 1 3
Output
0.057142857143 0.657142857143 0.285714285714 | instruction | 0 | 80,406 | 14 | 160,812 |
Tags: dp, probabilities
Correct Solution:
```
dp = [[[-1]*105 for _ in range(105)] for __ in range(105)]
dp2 = [[[-1]*105 for _ in range(105)] for __ in range(105)]
dp3 = [[[-1]*105 for _ in range(105)] for __ in range(105)]
#r, p, s
def f(x, y, z):
if dp[x][y][z] != -1:
return (dp[x][y][z])
if x == 0:
return 0
if y == 0:
return 1
if z == 0:
return 0
sumx = x*y+y*z+x*z
dp[x][y][z] = x*y/sumx*f(x-1,y,z)+y*z/sumx*f(x,y-1,z)+x*z/sumx*f(x,y,z-1)
return dp[x][y][z]
def f2(x, y, z):
if dp2[x][y][z] != -1:
return (dp2[x][y][z])
if x == 0:
return 1
if y == 0:
return 0
if z == 0:
return 0
sumx = x*y+y*z+x*z
dp2[x][y][z] = x*y/sumx*f2(x-1,y,z)+y*z/sumx*f2(x,y-1,z)+x*z/sumx*f2(x,y,z-1)
return dp2[x][y][z]
def f3(x, y, z):
if dp3[x][y][z] != -1:
return (dp3[x][y][z])
if x == 0:
return 0
if y == 0:
return 0
if z == 0:
return 1
sumx = x*y+y*z+x*z
dp3[x][y][z]= x*y/sumx*f3(x-1,y,z)+y*z/sumx*f3(x,y-1,z)+x*z/sumx*f3(x,y,z-1)
return dp3[x][y][z]
x, y, z = map(int, input().split(' '))
print(f(x, z, y), f2(x, z, y), f3(x, z, y))
``` | output | 1 | 80,406 | 14 | 160,813 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, then one individual kills the other one: a rock kills scissors, scissors kill paper, and paper kills a rock. Your task is to determine for each species what is the probability that this species will be the only one to inhabit this island after a long enough period of time.
Input
The single line contains three integers r, s and p (1 β€ r, s, p β€ 100) β the original number of individuals in the species of rock, scissors and paper, respectively.
Output
Print three space-separated real numbers: the probabilities, at which the rocks, the scissors and the paper will be the only surviving species, respectively. The answer will be considered correct if the relative or absolute error of each number doesn't exceed 10 - 9.
Examples
Input
2 2 2
Output
0.333333333333 0.333333333333 0.333333333333
Input
2 1 2
Output
0.150000000000 0.300000000000 0.550000000000
Input
1 1 3
Output
0.057142857143 0.657142857143 0.285714285714 | instruction | 0 | 80,407 | 14 | 160,814 |
Tags: dp, probabilities
Correct Solution:
```
import sys
input = sys.stdin.readline
def I():return input().strip()
def II():return int(input().strip())
def LI():return [*map(int,input().strip().split())]
import string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter, OrderedDict
from itertools import permutations, combinations, groupby
from operator import itemgetter
rock, scissor, paper = LI()
dp = [[[0 for p in range(paper + 1)] for s in range(scissor + 1)] for r in range(rock + 1)]
dp[rock][scissor][paper] = 1
for r in range(rock, -1, -1):
for s in range(scissor, -1, -1):
for p in range(paper, -1, -1):
currsum = p * r + r * s + s * p
if not currsum:
continue
if r >= 1:
dp[r - 1][s][p] += (p * r) / currsum * dp[r][s][p]
if s >= 1:
dp[r][s - 1][p] += (r * s) / currsum * dp[r][s][p]
if p >= 1:
dp[r][s][p - 1] += (s * p) / currsum * dp[r][s][p]
pr = sum(dp[i][0][0] for i in range(1, rock + 1))
ps = sum(dp[0][i][0] for i in range(1, scissor + 1))
pp = sum(dp[0][0][i] for i in range(1, paper + 1))
print(round(pr, 12), round(ps, 12), round(pp, 12))
``` | output | 1 | 80,407 | 14 | 160,815 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, then one individual kills the other one: a rock kills scissors, scissors kill paper, and paper kills a rock. Your task is to determine for each species what is the probability that this species will be the only one to inhabit this island after a long enough period of time.
Input
The single line contains three integers r, s and p (1 β€ r, s, p β€ 100) β the original number of individuals in the species of rock, scissors and paper, respectively.
Output
Print three space-separated real numbers: the probabilities, at which the rocks, the scissors and the paper will be the only surviving species, respectively. The answer will be considered correct if the relative or absolute error of each number doesn't exceed 10 - 9.
Examples
Input
2 2 2
Output
0.333333333333 0.333333333333 0.333333333333
Input
2 1 2
Output
0.150000000000 0.300000000000 0.550000000000
Input
1 1 3
Output
0.057142857143 0.657142857143 0.285714285714 | instruction | 0 | 80,408 | 14 | 160,816 |
Tags: dp, probabilities
Correct Solution:
```
#540D
[r,s,p] = list(map(float,input().split()))
def prob(k,n,b,mem):
if k > 0 and n >= 0 and b == 0:
return [1.,0.,0.],mem
elif k == 0 and n > 0 and b >= 0:
return [0.,1.,0.],mem
elif k >= 0 and n == 0 and b > 0:
return [0.,0.,1.],mem
elif k < 0 or n < 0 or b < 0:
return [0.,0.,0.],mem
elif k == n and k == b and k > 0:
return [1./3.,1./3.,1./3.],mem
elif not(mem[int(k)][int(n)][int(b)] == None):
l = mem[int(k)][int(n)][int(b)]
return l, mem
else:
if mem[int(k-1)][int(n)][int(b)] == None:
g0,mem = prob(k-1,n,b,mem)
else:
g0 = mem[int(k-1)][int(n)][int(b)];
if mem[int(k)][int(n-1)][int(b)] == None:
g1,mem = prob(k,n-1,b,mem)
else:
g1 = mem[int(k)][int(n-1)][int(b)];
if mem[int(k)][int(n)][int(b-1)] == None:
g2,mem = prob(k,n,b-1,mem)
else:
g2 = mem[int(k)][int(n)][int(b-1)];
l = []
x = k*b
y = k*n
z = n*b
r = x + y + z
for i in range(3):
l.append((x*g0[i]+y*g1[i]+z*g2[i])/r)
if (k==2. and n == 2. and l == 1):
print(mem[int(k)][int(n)][int(b)])
mem[int(k)][int(n)][int(b)] = l
if (k==2. and n == 2. and l == 1):
print(mem[int(k)][int(n)][int(b)])
return l,mem
list_size = int(max([r,s,p]))+1
mem = [None] * 120
for i in range(list_size):
mem[i] = [None] * list_size
for i in range(list_size):
for j in range(list_size):
mem[i][j] = [None]*list_size
s,x = prob(r,s,p,mem)
for i in range(3):
print(s[i], end=' ')
``` | output | 1 | 80,408 | 14 | 160,817 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, then one individual kills the other one: a rock kills scissors, scissors kill paper, and paper kills a rock. Your task is to determine for each species what is the probability that this species will be the only one to inhabit this island after a long enough period of time.
Input
The single line contains three integers r, s and p (1 β€ r, s, p β€ 100) β the original number of individuals in the species of rock, scissors and paper, respectively.
Output
Print three space-separated real numbers: the probabilities, at which the rocks, the scissors and the paper will be the only surviving species, respectively. The answer will be considered correct if the relative or absolute error of each number doesn't exceed 10 - 9.
Examples
Input
2 2 2
Output
0.333333333333 0.333333333333 0.333333333333
Input
2 1 2
Output
0.150000000000 0.300000000000 0.550000000000
Input
1 1 3
Output
0.057142857143 0.657142857143 0.285714285714 | instruction | 0 | 80,409 | 14 | 160,818 |
Tags: dp, probabilities
Correct Solution:
```
r, s, p = [int(x) for x in input().split()]
dp = [[[0 for i in range(105)] for j in range(105)] for k in range(105)]
dp[r][s][p] = 1
for i in range(r, -1, -1):
for j in range(s, -1, -1):
for k in range(p,-1, -1):
dnr = i * j + j * k + i * k
if i > 0 and j > 0:
dp[i][j - 1][k] += (i * j * dp[i][j][k]) / dnr
if j > 0 and k > 0:
dp[i][j][k - 1] += (j * k * dp[i][j][k]) / dnr
if k > 0 and i > 0:
dp[i - 1][j][k] += (k * i * dp[i][j][k]) / dnr
roc, sci, pap = [0] * 3
for i in range(105):
roc += dp[i][0][0]
sci += dp[0][i][0]
pap += dp[0][0][i]
print(roc, sci, pap)
``` | output | 1 | 80,409 | 14 | 160,819 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, then one individual kills the other one: a rock kills scissors, scissors kill paper, and paper kills a rock. Your task is to determine for each species what is the probability that this species will be the only one to inhabit this island after a long enough period of time.
Input
The single line contains three integers r, s and p (1 β€ r, s, p β€ 100) β the original number of individuals in the species of rock, scissors and paper, respectively.
Output
Print three space-separated real numbers: the probabilities, at which the rocks, the scissors and the paper will be the only surviving species, respectively. The answer will be considered correct if the relative or absolute error of each number doesn't exceed 10 - 9.
Examples
Input
2 2 2
Output
0.333333333333 0.333333333333 0.333333333333
Input
2 1 2
Output
0.150000000000 0.300000000000 0.550000000000
Input
1 1 3
Output
0.057142857143 0.657142857143 0.285714285714 | instruction | 0 | 80,410 | 14 | 160,820 |
Tags: dp, probabilities
Correct Solution:
```
A, B, C = map(lambda x: int(x)+1, input().split())
M = max(max(A, B), C)
p = [[[0] * (M) for i in range(M)] for j in range(M)]
for a in range(M):
for b in range(M):
for c in range(M):
val=0
if a == 0 or b == 0:
val=0
elif c == 0:
val=1
else:
div = a*b + b*c + c*a
val = (a*b) / div * p[a][b-1][c] + \
(b*c) / div * p[a][b][c-1] + \
(a*c) / div * p[a-1][b][c]
p[a][b][c]=val
print(p[A-1][B-1][C-1], p[B-1][C-1][A-1], p[C-1][A-1][B-1])
``` | output | 1 | 80,410 | 14 | 160,821 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n workers in a company, each of them has a unique id from 1 to n. Exaclty one of them is a chief, his id is s. Each worker except the chief has exactly one immediate superior.
There was a request to each of the workers to tell how how many superiors (not only immediate). Worker's superiors are his immediate superior, the immediate superior of the his immediate superior, and so on. For example, if there are three workers in the company, from which the first is the chief, the second worker's immediate superior is the first, the third worker's immediate superior is the second, then the third worker has two superiors, one of them is immediate and one not immediate. The chief is a superior to all the workers except himself.
Some of the workers were in a hurry and made a mistake. You are to find the minimum number of workers that could make a mistake.
Input
The first line contains two positive integers n and s (1 β€ n β€ 2Β·105, 1 β€ s β€ n) β the number of workers and the id of the chief.
The second line contains n integers a1, a2, ..., an (0 β€ ai β€ n - 1), where ai is the number of superiors (not only immediate) the worker with id i reported about.
Output
Print the minimum number of workers that could make a mistake.
Examples
Input
3 2
2 0 2
Output
1
Input
5 3
1 0 0 4 1
Output
2
Note
In the first example it is possible that only the first worker made a mistake. Then:
* the immediate superior of the first worker is the second worker,
* the immediate superior of the third worker is the first worker,
* the second worker is the chief. | instruction | 0 | 80,475 | 14 | 160,950 |
Tags: constructive algorithms, data structures, graphs, greedy, sortings
Correct Solution:
```
n, root = map(int, input().split())
a = list(map(int, input().split()))
def push(d, x, val):
if x not in d:
d[x] = 0
d[x]+=val
if d[x]==0:
del d[x]
d = {}
for x in a:
push(d, x, 1)
min_ = 0
root -= 1
inf = 9999999
if a[root] != 0:
min_+=1
push(d, a[root], -1)
push(d, 0, 1)
if 0 in d and d[0] > 1:
add = d[0] - 1
min_+=add
push(d, inf, add)
d[0] = 1
S = [[val, num] for val, num in sorted(d.items(), key = lambda x:x[0])]
#print(min_, S)
cur = -1
i = 0
while i < len(S):
remain = S[i][0] - (cur+1)
while remain > 0:
val, num = S[-1]
if val == S[i][0]:
if val != inf:
min_ += min(remain, num)
break
else:
add = min(num, remain)
remain -= add
if val != inf:
min_ += add
if num == add:
S.pop()
else:
S[-1][1] -= add
cur=S[i][0]
i+=1
print(min_)
``` | output | 1 | 80,475 | 14 | 160,951 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n workers in a company, each of them has a unique id from 1 to n. Exaclty one of them is a chief, his id is s. Each worker except the chief has exactly one immediate superior.
There was a request to each of the workers to tell how how many superiors (not only immediate). Worker's superiors are his immediate superior, the immediate superior of the his immediate superior, and so on. For example, if there are three workers in the company, from which the first is the chief, the second worker's immediate superior is the first, the third worker's immediate superior is the second, then the third worker has two superiors, one of them is immediate and one not immediate. The chief is a superior to all the workers except himself.
Some of the workers were in a hurry and made a mistake. You are to find the minimum number of workers that could make a mistake.
Input
The first line contains two positive integers n and s (1 β€ n β€ 2Β·105, 1 β€ s β€ n) β the number of workers and the id of the chief.
The second line contains n integers a1, a2, ..., an (0 β€ ai β€ n - 1), where ai is the number of superiors (not only immediate) the worker with id i reported about.
Output
Print the minimum number of workers that could make a mistake.
Examples
Input
3 2
2 0 2
Output
1
Input
5 3
1 0 0 4 1
Output
2
Note
In the first example it is possible that only the first worker made a mistake. Then:
* the immediate superior of the first worker is the second worker,
* the immediate superior of the third worker is the first worker,
* the second worker is the chief. | instruction | 0 | 80,476 | 14 | 160,952 |
Tags: constructive algorithms, data structures, graphs, greedy, sortings
Correct Solution:
```
n,s = map(int,input().split())
A = list(map(int,input().split()))
if A[s-1] != 0:
per = 1
A[s-1] = 0
else:
per = 0
A.sort()
maxs = max(A)
ans = [0] * (maxs + 1)
answer = maxs + 1
o = -1
for j in range(n):
if A[j] == 0:
o += 1
if ans[A[j]] == 0:
ans[A[j]] = 1
answer -= 1
an = per + max(o, answer)
for j in range(n-2,-1,-1):
for t in range(A[j+1]-1, A[j] -1,-1):
if ans[t] == 0:
answer -= 1
an = min(an, per + max(answer,o+n - j - 1))
print(an)
``` | output | 1 | 80,476 | 14 | 160,953 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n workers in a company, each of them has a unique id from 1 to n. Exaclty one of them is a chief, his id is s. Each worker except the chief has exactly one immediate superior.
There was a request to each of the workers to tell how how many superiors (not only immediate). Worker's superiors are his immediate superior, the immediate superior of the his immediate superior, and so on. For example, if there are three workers in the company, from which the first is the chief, the second worker's immediate superior is the first, the third worker's immediate superior is the second, then the third worker has two superiors, one of them is immediate and one not immediate. The chief is a superior to all the workers except himself.
Some of the workers were in a hurry and made a mistake. You are to find the minimum number of workers that could make a mistake.
Input
The first line contains two positive integers n and s (1 β€ n β€ 2Β·105, 1 β€ s β€ n) β the number of workers and the id of the chief.
The second line contains n integers a1, a2, ..., an (0 β€ ai β€ n - 1), where ai is the number of superiors (not only immediate) the worker with id i reported about.
Output
Print the minimum number of workers that could make a mistake.
Examples
Input
3 2
2 0 2
Output
1
Input
5 3
1 0 0 4 1
Output
2
Note
In the first example it is possible that only the first worker made a mistake. Then:
* the immediate superior of the first worker is the second worker,
* the immediate superior of the third worker is the first worker,
* the second worker is the chief. | instruction | 0 | 80,477 | 14 | 160,954 |
Tags: constructive algorithms, data structures, graphs, greedy, sortings
Correct Solution:
```
[n, s] = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
mistakes = 0
mistakes += (a[s-1] is not 0)
a[s - 1] = 0
numSuperiors = [0]*(2*100000+100)
for superiors in a:
numSuperiors[superiors] += 1
cachedMistakes = 0
while numSuperiors[0] != 1:
cachedMistakes += 1
numSuperiors[0] -= 1
rightIndex = len(numSuperiors) - 1
leftIndex = 0
while True:
while True:
if numSuperiors[leftIndex] == 0 and cachedMistakes != 0:
numSuperiors[leftIndex] += 1
cachedMistakes -= 1
mistakes += 1
if numSuperiors[leftIndex] == 0:
break
leftIndex += 1
while numSuperiors[rightIndex] == 0:
rightIndex -= 1
if leftIndex >= rightIndex:
break
numSuperiors[rightIndex] -= 1
cachedMistakes += 1
print(mistakes)
``` | output | 1 | 80,477 | 14 | 160,955 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n workers in a company, each of them has a unique id from 1 to n. Exaclty one of them is a chief, his id is s. Each worker except the chief has exactly one immediate superior.
There was a request to each of the workers to tell how how many superiors (not only immediate). Worker's superiors are his immediate superior, the immediate superior of the his immediate superior, and so on. For example, if there are three workers in the company, from which the first is the chief, the second worker's immediate superior is the first, the third worker's immediate superior is the second, then the third worker has two superiors, one of them is immediate and one not immediate. The chief is a superior to all the workers except himself.
Some of the workers were in a hurry and made a mistake. You are to find the minimum number of workers that could make a mistake.
Input
The first line contains two positive integers n and s (1 β€ n β€ 2Β·105, 1 β€ s β€ n) β the number of workers and the id of the chief.
The second line contains n integers a1, a2, ..., an (0 β€ ai β€ n - 1), where ai is the number of superiors (not only immediate) the worker with id i reported about.
Output
Print the minimum number of workers that could make a mistake.
Examples
Input
3 2
2 0 2
Output
1
Input
5 3
1 0 0 4 1
Output
2
Note
In the first example it is possible that only the first worker made a mistake. Then:
* the immediate superior of the first worker is the second worker,
* the immediate superior of the third worker is the first worker,
* the second worker is the chief. | instruction | 0 | 80,478 | 14 | 160,956 |
Tags: constructive algorithms, data structures, graphs, greedy, sortings
Correct Solution:
```
""" This is a solution to the problem Subordinates on codeforces.com
There is a DAG with n nodes, pointing towards the root, without further constraints.
Given: for each node, a number signifying the count of (direct and indirect) predecessors, and the ID of root s.
Some of these counts might be wrong. Give the minimum amount of wrong counts.
For details, see
http://codeforces.com/problemset/problem/729/E
"""
#Idea: count = level of DAG. Check constraints: root has 0 predecessors, level 0 has only one count, each level to the last has be > 0
from sys import stdin
#lines = open("input.txt", 'r').readlines()
lines = stdin.readlines()
n, s = map(int, lines[0].split())
counts = list(map(int, lines[1].split()))
totalwrong = 0
if counts[s-1] > 0: # root has to be 0
totalwrong += 1
counts[s-1] = 0
maxlevel = max(counts)
# count number of nodes on levels
levelcount = [0] * (max(counts) + 1)
for c in counts:
levelcount[c] += 1
curwrong = levelcount[0] - 1 # only one root
levelcount[0] = 1
totalwrong += curwrong
curlevel = 0
while curlevel <= maxlevel:
lc = levelcount[curlevel]
if lc == 0: # a mistake
if curwrong > 0: # still mistakes available, just use them to fill
curwrong -= 1
levelcount[curlevel] = 1
else: # else fill from last level
levelcount[maxlevel] -= 1
levelcount[curlevel] = 1
totalwrong += 1
while levelcount[maxlevel] == 0:
maxlevel -= 1 # as levelcount[curlevel] = 1, this aborts at some point
curlevel += 1
print(totalwrong)
``` | output | 1 | 80,478 | 14 | 160,957 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n workers in a company, each of them has a unique id from 1 to n. Exaclty one of them is a chief, his id is s. Each worker except the chief has exactly one immediate superior.
There was a request to each of the workers to tell how how many superiors (not only immediate). Worker's superiors are his immediate superior, the immediate superior of the his immediate superior, and so on. For example, if there are three workers in the company, from which the first is the chief, the second worker's immediate superior is the first, the third worker's immediate superior is the second, then the third worker has two superiors, one of them is immediate and one not immediate. The chief is a superior to all the workers except himself.
Some of the workers were in a hurry and made a mistake. You are to find the minimum number of workers that could make a mistake.
Input
The first line contains two positive integers n and s (1 β€ n β€ 2Β·105, 1 β€ s β€ n) β the number of workers and the id of the chief.
The second line contains n integers a1, a2, ..., an (0 β€ ai β€ n - 1), where ai is the number of superiors (not only immediate) the worker with id i reported about.
Output
Print the minimum number of workers that could make a mistake.
Examples
Input
3 2
2 0 2
Output
1
Input
5 3
1 0 0 4 1
Output
2
Note
In the first example it is possible that only the first worker made a mistake. Then:
* the immediate superior of the first worker is the second worker,
* the immediate superior of the third worker is the first worker,
* the second worker is the chief. | instruction | 0 | 80,479 | 14 | 160,958 |
Tags: constructive algorithms, data structures, graphs, greedy, sortings
Correct Solution:
```
f = lambda: map(int, input().split())
n, s = f()
c = [0] * n
t = list(f())
for i in t: c[i] += 1
k = t[s - 1]
c[k] -= 1
d = c[0]
c += [d]
d += k > 0
i, j = 1, n
while i < j:
if c[i]: i += 1
elif c[j]:
c[j] -= 1
i += 1
d += j < n
else: j -= 1
print(d)
``` | output | 1 | 80,479 | 14 | 160,959 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n workers in a company, each of them has a unique id from 1 to n. Exaclty one of them is a chief, his id is s. Each worker except the chief has exactly one immediate superior.
There was a request to each of the workers to tell how how many superiors (not only immediate). Worker's superiors are his immediate superior, the immediate superior of the his immediate superior, and so on. For example, if there are three workers in the company, from which the first is the chief, the second worker's immediate superior is the first, the third worker's immediate superior is the second, then the third worker has two superiors, one of them is immediate and one not immediate. The chief is a superior to all the workers except himself.
Some of the workers were in a hurry and made a mistake. You are to find the minimum number of workers that could make a mistake.
Input
The first line contains two positive integers n and s (1 β€ n β€ 2Β·105, 1 β€ s β€ n) β the number of workers and the id of the chief.
The second line contains n integers a1, a2, ..., an (0 β€ ai β€ n - 1), where ai is the number of superiors (not only immediate) the worker with id i reported about.
Output
Print the minimum number of workers that could make a mistake.
Examples
Input
3 2
2 0 2
Output
1
Input
5 3
1 0 0 4 1
Output
2
Note
In the first example it is possible that only the first worker made a mistake. Then:
* the immediate superior of the first worker is the second worker,
* the immediate superior of the third worker is the first worker,
* the second worker is the chief.
Submitted Solution:
```
n,s = map(int,input().split())
A = list(map(int,input().split()))
if A[s-1] != 0:
per = 1
A[s-1] = 0
else:
per = 0
maxs = max(A)
ans = [0] * maxs
answer = maxs
o = -1
for j in range(n):
if A[j] == 0:
o += 1
if A[j] <= maxs - 1 and ans[A[j]] == 0:
ans[A[j]] = 1
answer -= 1
print(per + max(o,answer))
``` | instruction | 0 | 80,480 | 14 | 160,960 |
No | output | 1 | 80,480 | 14 | 160,961 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n workers in a company, each of them has a unique id from 1 to n. Exaclty one of them is a chief, his id is s. Each worker except the chief has exactly one immediate superior.
There was a request to each of the workers to tell how how many superiors (not only immediate). Worker's superiors are his immediate superior, the immediate superior of the his immediate superior, and so on. For example, if there are three workers in the company, from which the first is the chief, the second worker's immediate superior is the first, the third worker's immediate superior is the second, then the third worker has two superiors, one of them is immediate and one not immediate. The chief is a superior to all the workers except himself.
Some of the workers were in a hurry and made a mistake. You are to find the minimum number of workers that could make a mistake.
Input
The first line contains two positive integers n and s (1 β€ n β€ 2Β·105, 1 β€ s β€ n) β the number of workers and the id of the chief.
The second line contains n integers a1, a2, ..., an (0 β€ ai β€ n - 1), where ai is the number of superiors (not only immediate) the worker with id i reported about.
Output
Print the minimum number of workers that could make a mistake.
Examples
Input
3 2
2 0 2
Output
1
Input
5 3
1 0 0 4 1
Output
2
Note
In the first example it is possible that only the first worker made a mistake. Then:
* the immediate superior of the first worker is the second worker,
* the immediate superior of the third worker is the first worker,
* the second worker is the chief.
Submitted Solution:
```
n,s = map(int,input().split())
A = list(map(int,input().split()))
maxs = max(A)
ans = [0] * maxs
answer = maxs
o = -1
for j in range(n):
if A[j] == 0:
o += 1
if A[j] <= maxs - 1 and ans[A[j]] == 0:
ans[A[j]] = 1
answer -= 1
print(max(o,maxs - answer))
``` | instruction | 0 | 80,481 | 14 | 160,962 |
No | output | 1 | 80,481 | 14 | 160,963 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n workers in a company, each of them has a unique id from 1 to n. Exaclty one of them is a chief, his id is s. Each worker except the chief has exactly one immediate superior.
There was a request to each of the workers to tell how how many superiors (not only immediate). Worker's superiors are his immediate superior, the immediate superior of the his immediate superior, and so on. For example, if there are three workers in the company, from which the first is the chief, the second worker's immediate superior is the first, the third worker's immediate superior is the second, then the third worker has two superiors, one of them is immediate and one not immediate. The chief is a superior to all the workers except himself.
Some of the workers were in a hurry and made a mistake. You are to find the minimum number of workers that could make a mistake.
Input
The first line contains two positive integers n and s (1 β€ n β€ 2Β·105, 1 β€ s β€ n) β the number of workers and the id of the chief.
The second line contains n integers a1, a2, ..., an (0 β€ ai β€ n - 1), where ai is the number of superiors (not only immediate) the worker with id i reported about.
Output
Print the minimum number of workers that could make a mistake.
Examples
Input
3 2
2 0 2
Output
1
Input
5 3
1 0 0 4 1
Output
2
Note
In the first example it is possible that only the first worker made a mistake. Then:
* the immediate superior of the first worker is the second worker,
* the immediate superior of the third worker is the first worker,
* the second worker is the chief.
Submitted Solution:
```
f = lambda: map(int, input().split())
n, s = f()
c = [0] * (n + 1)
t = list(f())
for i in t: c[i] += 1
k = t[s - 1]
c[k] -= 1
c[n] = d = c[0] + (k > 0)
i, j = 1, n
while i < j:
if c[i]: i += 1
elif c[j]:
c[j] -= 1
i += 1
d += j < n
else: j -= 1
print(d)
``` | instruction | 0 | 80,482 | 14 | 160,964 |
No | output | 1 | 80,482 | 14 | 160,965 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n workers in a company, each of them has a unique id from 1 to n. Exaclty one of them is a chief, his id is s. Each worker except the chief has exactly one immediate superior.
There was a request to each of the workers to tell how how many superiors (not only immediate). Worker's superiors are his immediate superior, the immediate superior of the his immediate superior, and so on. For example, if there are three workers in the company, from which the first is the chief, the second worker's immediate superior is the first, the third worker's immediate superior is the second, then the third worker has two superiors, one of them is immediate and one not immediate. The chief is a superior to all the workers except himself.
Some of the workers were in a hurry and made a mistake. You are to find the minimum number of workers that could make a mistake.
Input
The first line contains two positive integers n and s (1 β€ n β€ 2Β·105, 1 β€ s β€ n) β the number of workers and the id of the chief.
The second line contains n integers a1, a2, ..., an (0 β€ ai β€ n - 1), where ai is the number of superiors (not only immediate) the worker with id i reported about.
Output
Print the minimum number of workers that could make a mistake.
Examples
Input
3 2
2 0 2
Output
1
Input
5 3
1 0 0 4 1
Output
2
Note
In the first example it is possible that only the first worker made a mistake. Then:
* the immediate superior of the first worker is the second worker,
* the immediate superior of the third worker is the first worker,
* the second worker is the chief.
Submitted Solution:
```
f = lambda: map(int, input().split())
n, s = f()
c = [0] * n
t = list(f())
for i in t: c[i] += 1
k = t[s - 1]
c[k] -= 1
d = c[0]
i, j = 1, n - 1
while i < j:
if c[i]: i += 1
elif c[j]:
c[j] -= 1
i += 1
d += 1
else: j -= 1
print(d)
``` | instruction | 0 | 80,483 | 14 | 160,966 |
No | output | 1 | 80,483 | 14 | 160,967 |
Provide a correct Python 3 solution for this coding contest problem.
You are the planning manager of an animation production company. What animation production companies produce these days is not limited to animation itself. Related products, such as figures of characters and character song CDs, are also important sources of revenue. How much this profit can be increased depends solely on you, the director of the planning department.
Obviously, these related products are not something that should be released in the dark clouds. This is because it takes a lot of time and budget to develop a product. Even if you release a figure of an anime character, you have to limit it to popular characters that are expected to sell a lot.
One of the means to measure the popularity of a character is popularity voting. You've been planning some popularity polls so far, but it seems that viewers are becoming dissatisfied with the project. There is an urgent need to establish other methods for measuring popularity.
So you made a hypothesis. The popularity of a character is proportional to the total appearance time in the main part of the anime. To test this hypothesis, you decided to write a program that aggregates the appearance times of each character.
Input
The input consists of multiple cases. Each case is given in the following format.
n
name0 m0 d0,0 ... d0, m0-1
name1 m1 d1,0 ... d1, m1-1
..
..
..
namen-1 mn-1 dn-1,0 ... dn-1, mn-1-1
n represents the number of characters.
namei represents the name of the character.
mi represents the type of time the character was shown.
After mi, mi integers di and j are given.
di and j represent the time when the character was shown.
The end of the input is given by a line consisting of n = 0
If only one character appears on the screen at a given time, that character can get n points.
Every time one more character appears at the same time, the points obtained for the character reflected at that time decrease by one.
If n characters are shown at the same time, 1 point will be added to each of n characters.
The input satisfies the following constraints.
2 β€ n β€ 20
0 β€ mi β€ 30
0 β€ di, j <30
Di and j are all different for the i-th character.
namei contains only uppercase or lowercase letters and is no longer than 10.
Output
Output the points of the character with the smallest points and their names separated by a single space.
If there are multiple characters with the smallest points, select the person with the smallest name in lexicographical order.
Example
Input
4
akzakr 2 1 8
fnmyi 5 2 3 4 6 9
tsnukk 5 2 3 4 7 9
yskwcnt 6 3 4 7 8 9 10
4
akzakr 1 2
fnmyi 3 10 11 12
tsnukk 2 1 8
yskwcnt 2 1 8
5
knmmdk 2 13 19
akmhmr 4 13 15 19 22
mksyk 6 3 7 12 13 15 19
skrkyk 3 1 4 8
tmemm 3 1 17 24
5
knmmdk 5 5 6 16 18 26
akmhmr 9 3 4 7 11 14 15 17 18 20
mksyk 5 6 13 25 27 28
skrkyk 4 3 16 23 24
tmemm 3 6 12 20
14
hrkamm 6 4 6 8 10 20 22
mkhsi 6 1 10 12 15 22 27
hbkgnh 2 4 9
chyksrg 8 3 4 12 15 16 20 25 28
mktkkc 6 0 1 8 15 17 20
tknsj 6 6 8 18 19 25 26
yyitktk 3 3 12 18
ykhhgwr 5 3 9 10 11 24
amftm 7 2 6 8 12 13 14 17
mmftm 4 6 12 16 18
rtkakzk 3 14 15 21
azsmur 7 1 2 4 12 15 18 20
iormns 2 4 20
ktrotns 6 7 12 14 17 20 25
14
hrkamm 2 4 21
mkhsi 6 2 3 8 11 18 20
hbkgnh 4 4 16 28 29
chyksrg 5 0 3 9 17 22
mktkkc 2 7 18
tknsj 3 3 9 23
yyitktk 3 10 13 25
ykhhgwr 2 18 26
amftm 3 13 18 22
mmftm 4 1 20 24 27
rtkakzk 2 1 10
azsmur 5 2 5 10 14 17
iormns 3 9 15 16
ktrotns 5 7 12 16 17 20
0
Output
7 akzakr
4 akzakr
6 knmmdk
12 tmemm
19 iormns
24 mktkkc | instruction | 0 | 80,759 | 14 | 161,518 |
"Correct Solution:
```
from collections import defaultdict
while True:
n = int(input())
if n == 0:
break
score = {}
dic = defaultdict(list)
for _ in range(n):
line = input().split()
name = line[0]
score[name] = 0
for d in line[2:]:
dic[d].append(name)
for v in dic.values():
p = n - len(v) + 1
for name in v:
score[name] += p
print(*min([(v, k) for k, v in score.items()]))
``` | output | 1 | 80,759 | 14 | 161,519 |
Provide a correct Python 3 solution for this coding contest problem.
You are the planning manager of an animation production company. What animation production companies produce these days is not limited to animation itself. Related products, such as figures of characters and character song CDs, are also important sources of revenue. How much this profit can be increased depends solely on you, the director of the planning department.
Obviously, these related products are not something that should be released in the dark clouds. This is because it takes a lot of time and budget to develop a product. Even if you release a figure of an anime character, you have to limit it to popular characters that are expected to sell a lot.
One of the means to measure the popularity of a character is popularity voting. You've been planning some popularity polls so far, but it seems that viewers are becoming dissatisfied with the project. There is an urgent need to establish other methods for measuring popularity.
So you made a hypothesis. The popularity of a character is proportional to the total appearance time in the main part of the anime. To test this hypothesis, you decided to write a program that aggregates the appearance times of each character.
Input
The input consists of multiple cases. Each case is given in the following format.
n
name0 m0 d0,0 ... d0, m0-1
name1 m1 d1,0 ... d1, m1-1
..
..
..
namen-1 mn-1 dn-1,0 ... dn-1, mn-1-1
n represents the number of characters.
namei represents the name of the character.
mi represents the type of time the character was shown.
After mi, mi integers di and j are given.
di and j represent the time when the character was shown.
The end of the input is given by a line consisting of n = 0
If only one character appears on the screen at a given time, that character can get n points.
Every time one more character appears at the same time, the points obtained for the character reflected at that time decrease by one.
If n characters are shown at the same time, 1 point will be added to each of n characters.
The input satisfies the following constraints.
2 β€ n β€ 20
0 β€ mi β€ 30
0 β€ di, j <30
Di and j are all different for the i-th character.
namei contains only uppercase or lowercase letters and is no longer than 10.
Output
Output the points of the character with the smallest points and their names separated by a single space.
If there are multiple characters with the smallest points, select the person with the smallest name in lexicographical order.
Example
Input
4
akzakr 2 1 8
fnmyi 5 2 3 4 6 9
tsnukk 5 2 3 4 7 9
yskwcnt 6 3 4 7 8 9 10
4
akzakr 1 2
fnmyi 3 10 11 12
tsnukk 2 1 8
yskwcnt 2 1 8
5
knmmdk 2 13 19
akmhmr 4 13 15 19 22
mksyk 6 3 7 12 13 15 19
skrkyk 3 1 4 8
tmemm 3 1 17 24
5
knmmdk 5 5 6 16 18 26
akmhmr 9 3 4 7 11 14 15 17 18 20
mksyk 5 6 13 25 27 28
skrkyk 4 3 16 23 24
tmemm 3 6 12 20
14
hrkamm 6 4 6 8 10 20 22
mkhsi 6 1 10 12 15 22 27
hbkgnh 2 4 9
chyksrg 8 3 4 12 15 16 20 25 28
mktkkc 6 0 1 8 15 17 20
tknsj 6 6 8 18 19 25 26
yyitktk 3 3 12 18
ykhhgwr 5 3 9 10 11 24
amftm 7 2 6 8 12 13 14 17
mmftm 4 6 12 16 18
rtkakzk 3 14 15 21
azsmur 7 1 2 4 12 15 18 20
iormns 2 4 20
ktrotns 6 7 12 14 17 20 25
14
hrkamm 2 4 21
mkhsi 6 2 3 8 11 18 20
hbkgnh 4 4 16 28 29
chyksrg 5 0 3 9 17 22
mktkkc 2 7 18
tknsj 3 3 9 23
yyitktk 3 10 13 25
ykhhgwr 2 18 26
amftm 3 13 18 22
mmftm 4 1 20 24 27
rtkakzk 2 1 10
azsmur 5 2 5 10 14 17
iormns 3 9 15 16
ktrotns 5 7 12 16 17 20
0
Output
7 akzakr
4 akzakr
6 knmmdk
12 tmemm
19 iormns
24 mktkkc | instruction | 0 | 80,760 | 14 | 161,520 |
"Correct Solution:
```
while True:
try:
n = int(input())
except:
break
if n == 0: break
char = []
name = []
times = []
scores = {i: n + 1 for i in range(30)}
for i in range(n):
char = input().split()
name.append(char[0])
times.append(list(map(int, char[2:])))
for t in times[i]:
scores[t] = scores[t] - 1
res = {}
for i in range(n):
res[i] = sum([scores[t] for t in times[i]])
score = min(res.values())
names = [name[i] for i in range(n) if score == res[i]]
names.sort()
print(score, names[0])
``` | output | 1 | 80,760 | 14 | 161,521 |
Provide a correct Python 3 solution for this coding contest problem.
You are the planning manager of an animation production company. What animation production companies produce these days is not limited to animation itself. Related products, such as figures of characters and character song CDs, are also important sources of revenue. How much this profit can be increased depends solely on you, the director of the planning department.
Obviously, these related products are not something that should be released in the dark clouds. This is because it takes a lot of time and budget to develop a product. Even if you release a figure of an anime character, you have to limit it to popular characters that are expected to sell a lot.
One of the means to measure the popularity of a character is popularity voting. You've been planning some popularity polls so far, but it seems that viewers are becoming dissatisfied with the project. There is an urgent need to establish other methods for measuring popularity.
So you made a hypothesis. The popularity of a character is proportional to the total appearance time in the main part of the anime. To test this hypothesis, you decided to write a program that aggregates the appearance times of each character.
Input
The input consists of multiple cases. Each case is given in the following format.
n
name0 m0 d0,0 ... d0, m0-1
name1 m1 d1,0 ... d1, m1-1
..
..
..
namen-1 mn-1 dn-1,0 ... dn-1, mn-1-1
n represents the number of characters.
namei represents the name of the character.
mi represents the type of time the character was shown.
After mi, mi integers di and j are given.
di and j represent the time when the character was shown.
The end of the input is given by a line consisting of n = 0
If only one character appears on the screen at a given time, that character can get n points.
Every time one more character appears at the same time, the points obtained for the character reflected at that time decrease by one.
If n characters are shown at the same time, 1 point will be added to each of n characters.
The input satisfies the following constraints.
2 β€ n β€ 20
0 β€ mi β€ 30
0 β€ di, j <30
Di and j are all different for the i-th character.
namei contains only uppercase or lowercase letters and is no longer than 10.
Output
Output the points of the character with the smallest points and their names separated by a single space.
If there are multiple characters with the smallest points, select the person with the smallest name in lexicographical order.
Example
Input
4
akzakr 2 1 8
fnmyi 5 2 3 4 6 9
tsnukk 5 2 3 4 7 9
yskwcnt 6 3 4 7 8 9 10
4
akzakr 1 2
fnmyi 3 10 11 12
tsnukk 2 1 8
yskwcnt 2 1 8
5
knmmdk 2 13 19
akmhmr 4 13 15 19 22
mksyk 6 3 7 12 13 15 19
skrkyk 3 1 4 8
tmemm 3 1 17 24
5
knmmdk 5 5 6 16 18 26
akmhmr 9 3 4 7 11 14 15 17 18 20
mksyk 5 6 13 25 27 28
skrkyk 4 3 16 23 24
tmemm 3 6 12 20
14
hrkamm 6 4 6 8 10 20 22
mkhsi 6 1 10 12 15 22 27
hbkgnh 2 4 9
chyksrg 8 3 4 12 15 16 20 25 28
mktkkc 6 0 1 8 15 17 20
tknsj 6 6 8 18 19 25 26
yyitktk 3 3 12 18
ykhhgwr 5 3 9 10 11 24
amftm 7 2 6 8 12 13 14 17
mmftm 4 6 12 16 18
rtkakzk 3 14 15 21
azsmur 7 1 2 4 12 15 18 20
iormns 2 4 20
ktrotns 6 7 12 14 17 20 25
14
hrkamm 2 4 21
mkhsi 6 2 3 8 11 18 20
hbkgnh 4 4 16 28 29
chyksrg 5 0 3 9 17 22
mktkkc 2 7 18
tknsj 3 3 9 23
yyitktk 3 10 13 25
ykhhgwr 2 18 26
amftm 3 13 18 22
mmftm 4 1 20 24 27
rtkakzk 2 1 10
azsmur 5 2 5 10 14 17
iormns 3 9 15 16
ktrotns 5 7 12 16 17 20
0
Output
7 akzakr
4 akzakr
6 knmmdk
12 tmemm
19 iormns
24 mktkkc | instruction | 0 | 80,761 | 14 | 161,522 |
"Correct Solution:
```
# AOJ 1074: Popularity Estimation
# Python3 2018.7.10 bal4u
while True:
n = int(input())
if n == 0: break
f, tbl = [0]*31, []
for i in range(n):
a = input().split()
nm = a.pop(0)
m = int(a.pop(0))
d = list(map(int, a))
tbl.append([0, nm, d])
for i in d: f[i] += 1
for i in range(n):
for j in tbl[i][2]: tbl[i][0] += n-f[j]+1
tbl.sort(key=lambda x:(x[0],x[1]))
print(tbl[0][0], tbl[0][1])
``` | output | 1 | 80,761 | 14 | 161,523 |
Provide a correct Python 3 solution for this coding contest problem.
You are the planning manager of an animation production company. What animation production companies produce these days is not limited to animation itself. Related products, such as figures of characters and character song CDs, are also important sources of revenue. How much this profit can be increased depends solely on you, the director of the planning department.
Obviously, these related products are not something that should be released in the dark clouds. This is because it takes a lot of time and budget to develop a product. Even if you release a figure of an anime character, you have to limit it to popular characters that are expected to sell a lot.
One of the means to measure the popularity of a character is popularity voting. You've been planning some popularity polls so far, but it seems that viewers are becoming dissatisfied with the project. There is an urgent need to establish other methods for measuring popularity.
So you made a hypothesis. The popularity of a character is proportional to the total appearance time in the main part of the anime. To test this hypothesis, you decided to write a program that aggregates the appearance times of each character.
Input
The input consists of multiple cases. Each case is given in the following format.
n
name0 m0 d0,0 ... d0, m0-1
name1 m1 d1,0 ... d1, m1-1
..
..
..
namen-1 mn-1 dn-1,0 ... dn-1, mn-1-1
n represents the number of characters.
namei represents the name of the character.
mi represents the type of time the character was shown.
After mi, mi integers di and j are given.
di and j represent the time when the character was shown.
The end of the input is given by a line consisting of n = 0
If only one character appears on the screen at a given time, that character can get n points.
Every time one more character appears at the same time, the points obtained for the character reflected at that time decrease by one.
If n characters are shown at the same time, 1 point will be added to each of n characters.
The input satisfies the following constraints.
2 β€ n β€ 20
0 β€ mi β€ 30
0 β€ di, j <30
Di and j are all different for the i-th character.
namei contains only uppercase or lowercase letters and is no longer than 10.
Output
Output the points of the character with the smallest points and their names separated by a single space.
If there are multiple characters with the smallest points, select the person with the smallest name in lexicographical order.
Example
Input
4
akzakr 2 1 8
fnmyi 5 2 3 4 6 9
tsnukk 5 2 3 4 7 9
yskwcnt 6 3 4 7 8 9 10
4
akzakr 1 2
fnmyi 3 10 11 12
tsnukk 2 1 8
yskwcnt 2 1 8
5
knmmdk 2 13 19
akmhmr 4 13 15 19 22
mksyk 6 3 7 12 13 15 19
skrkyk 3 1 4 8
tmemm 3 1 17 24
5
knmmdk 5 5 6 16 18 26
akmhmr 9 3 4 7 11 14 15 17 18 20
mksyk 5 6 13 25 27 28
skrkyk 4 3 16 23 24
tmemm 3 6 12 20
14
hrkamm 6 4 6 8 10 20 22
mkhsi 6 1 10 12 15 22 27
hbkgnh 2 4 9
chyksrg 8 3 4 12 15 16 20 25 28
mktkkc 6 0 1 8 15 17 20
tknsj 6 6 8 18 19 25 26
yyitktk 3 3 12 18
ykhhgwr 5 3 9 10 11 24
amftm 7 2 6 8 12 13 14 17
mmftm 4 6 12 16 18
rtkakzk 3 14 15 21
azsmur 7 1 2 4 12 15 18 20
iormns 2 4 20
ktrotns 6 7 12 14 17 20 25
14
hrkamm 2 4 21
mkhsi 6 2 3 8 11 18 20
hbkgnh 4 4 16 28 29
chyksrg 5 0 3 9 17 22
mktkkc 2 7 18
tknsj 3 3 9 23
yyitktk 3 10 13 25
ykhhgwr 2 18 26
amftm 3 13 18 22
mmftm 4 1 20 24 27
rtkakzk 2 1 10
azsmur 5 2 5 10 14 17
iormns 3 9 15 16
ktrotns 5 7 12 16 17 20
0
Output
7 akzakr
4 akzakr
6 knmmdk
12 tmemm
19 iormns
24 mktkkc | instruction | 0 | 80,762 | 14 | 161,524 |
"Correct Solution:
```
from collections import defaultdict
while 1:
N = int(input())
if N == 0:
break
D = defaultdict(list)
S = [None]*N
for i in range(N):
name, _, *ts = input().split()
S[i] = name
for t in map(int, ts):
D[t].append(i)
P = [0]*N
for vs in D.values():
p = N+1 - len(vs)
for v in vs:
P[v] += p
m = min(P)
U = [S[i] for i in range(N) if P[i] == m]
print(m, min(U))
``` | output | 1 | 80,762 | 14 | 161,525 |
Provide a correct Python 3 solution for this coding contest problem.
You are the planning manager of an animation production company. What animation production companies produce these days is not limited to animation itself. Related products, such as figures of characters and character song CDs, are also important sources of revenue. How much this profit can be increased depends solely on you, the director of the planning department.
Obviously, these related products are not something that should be released in the dark clouds. This is because it takes a lot of time and budget to develop a product. Even if you release a figure of an anime character, you have to limit it to popular characters that are expected to sell a lot.
One of the means to measure the popularity of a character is popularity voting. You've been planning some popularity polls so far, but it seems that viewers are becoming dissatisfied with the project. There is an urgent need to establish other methods for measuring popularity.
So you made a hypothesis. The popularity of a character is proportional to the total appearance time in the main part of the anime. To test this hypothesis, you decided to write a program that aggregates the appearance times of each character.
Input
The input consists of multiple cases. Each case is given in the following format.
n
name0 m0 d0,0 ... d0, m0-1
name1 m1 d1,0 ... d1, m1-1
..
..
..
namen-1 mn-1 dn-1,0 ... dn-1, mn-1-1
n represents the number of characters.
namei represents the name of the character.
mi represents the type of time the character was shown.
After mi, mi integers di and j are given.
di and j represent the time when the character was shown.
The end of the input is given by a line consisting of n = 0
If only one character appears on the screen at a given time, that character can get n points.
Every time one more character appears at the same time, the points obtained for the character reflected at that time decrease by one.
If n characters are shown at the same time, 1 point will be added to each of n characters.
The input satisfies the following constraints.
2 β€ n β€ 20
0 β€ mi β€ 30
0 β€ di, j <30
Di and j are all different for the i-th character.
namei contains only uppercase or lowercase letters and is no longer than 10.
Output
Output the points of the character with the smallest points and their names separated by a single space.
If there are multiple characters with the smallest points, select the person with the smallest name in lexicographical order.
Example
Input
4
akzakr 2 1 8
fnmyi 5 2 3 4 6 9
tsnukk 5 2 3 4 7 9
yskwcnt 6 3 4 7 8 9 10
4
akzakr 1 2
fnmyi 3 10 11 12
tsnukk 2 1 8
yskwcnt 2 1 8
5
knmmdk 2 13 19
akmhmr 4 13 15 19 22
mksyk 6 3 7 12 13 15 19
skrkyk 3 1 4 8
tmemm 3 1 17 24
5
knmmdk 5 5 6 16 18 26
akmhmr 9 3 4 7 11 14 15 17 18 20
mksyk 5 6 13 25 27 28
skrkyk 4 3 16 23 24
tmemm 3 6 12 20
14
hrkamm 6 4 6 8 10 20 22
mkhsi 6 1 10 12 15 22 27
hbkgnh 2 4 9
chyksrg 8 3 4 12 15 16 20 25 28
mktkkc 6 0 1 8 15 17 20
tknsj 6 6 8 18 19 25 26
yyitktk 3 3 12 18
ykhhgwr 5 3 9 10 11 24
amftm 7 2 6 8 12 13 14 17
mmftm 4 6 12 16 18
rtkakzk 3 14 15 21
azsmur 7 1 2 4 12 15 18 20
iormns 2 4 20
ktrotns 6 7 12 14 17 20 25
14
hrkamm 2 4 21
mkhsi 6 2 3 8 11 18 20
hbkgnh 4 4 16 28 29
chyksrg 5 0 3 9 17 22
mktkkc 2 7 18
tknsj 3 3 9 23
yyitktk 3 10 13 25
ykhhgwr 2 18 26
amftm 3 13 18 22
mmftm 4 1 20 24 27
rtkakzk 2 1 10
azsmur 5 2 5 10 14 17
iormns 3 9 15 16
ktrotns 5 7 12 16 17 20
0
Output
7 akzakr
4 akzakr
6 knmmdk
12 tmemm
19 iormns
24 mktkkc | instruction | 0 | 80,763 | 14 | 161,526 |
"Correct Solution:
```
from itertools import combinations as C
while True:
n = int(input())
if n == 0: break
d, dd, ddd = {}, {}, {}
names = []
for i in range(n):
nmd = input().split()
d[nmd[0]] = nmd[2:]
names.append(nmd[0])
for cc in list(C(d.items(), n-1)):
t, tt = [], []
for c in cc:
t.append(c[0])
tt += c[1]
for name in names:
if name not in t:
dd[name] = tt
break
for k in d.keys():
tmp = 0
for v in d[k]:
tmp += n-dd[k].count(v)
ddd[k] = tmp
ans = sorted(ddd.items(), key=lambda x: (x[1], x[0]))[0]
print(ans[1], ans[0])
``` | output | 1 | 80,763 | 14 | 161,527 |
Provide a correct Python 3 solution for this coding contest problem.
You are the planning manager of an animation production company. What animation production companies produce these days is not limited to animation itself. Related products, such as figures of characters and character song CDs, are also important sources of revenue. How much this profit can be increased depends solely on you, the director of the planning department.
Obviously, these related products are not something that should be released in the dark clouds. This is because it takes a lot of time and budget to develop a product. Even if you release a figure of an anime character, you have to limit it to popular characters that are expected to sell a lot.
One of the means to measure the popularity of a character is popularity voting. You've been planning some popularity polls so far, but it seems that viewers are becoming dissatisfied with the project. There is an urgent need to establish other methods for measuring popularity.
So you made a hypothesis. The popularity of a character is proportional to the total appearance time in the main part of the anime. To test this hypothesis, you decided to write a program that aggregates the appearance times of each character.
Input
The input consists of multiple cases. Each case is given in the following format.
n
name0 m0 d0,0 ... d0, m0-1
name1 m1 d1,0 ... d1, m1-1
..
..
..
namen-1 mn-1 dn-1,0 ... dn-1, mn-1-1
n represents the number of characters.
namei represents the name of the character.
mi represents the type of time the character was shown.
After mi, mi integers di and j are given.
di and j represent the time when the character was shown.
The end of the input is given by a line consisting of n = 0
If only one character appears on the screen at a given time, that character can get n points.
Every time one more character appears at the same time, the points obtained for the character reflected at that time decrease by one.
If n characters are shown at the same time, 1 point will be added to each of n characters.
The input satisfies the following constraints.
2 β€ n β€ 20
0 β€ mi β€ 30
0 β€ di, j <30
Di and j are all different for the i-th character.
namei contains only uppercase or lowercase letters and is no longer than 10.
Output
Output the points of the character with the smallest points and their names separated by a single space.
If there are multiple characters with the smallest points, select the person with the smallest name in lexicographical order.
Example
Input
4
akzakr 2 1 8
fnmyi 5 2 3 4 6 9
tsnukk 5 2 3 4 7 9
yskwcnt 6 3 4 7 8 9 10
4
akzakr 1 2
fnmyi 3 10 11 12
tsnukk 2 1 8
yskwcnt 2 1 8
5
knmmdk 2 13 19
akmhmr 4 13 15 19 22
mksyk 6 3 7 12 13 15 19
skrkyk 3 1 4 8
tmemm 3 1 17 24
5
knmmdk 5 5 6 16 18 26
akmhmr 9 3 4 7 11 14 15 17 18 20
mksyk 5 6 13 25 27 28
skrkyk 4 3 16 23 24
tmemm 3 6 12 20
14
hrkamm 6 4 6 8 10 20 22
mkhsi 6 1 10 12 15 22 27
hbkgnh 2 4 9
chyksrg 8 3 4 12 15 16 20 25 28
mktkkc 6 0 1 8 15 17 20
tknsj 6 6 8 18 19 25 26
yyitktk 3 3 12 18
ykhhgwr 5 3 9 10 11 24
amftm 7 2 6 8 12 13 14 17
mmftm 4 6 12 16 18
rtkakzk 3 14 15 21
azsmur 7 1 2 4 12 15 18 20
iormns 2 4 20
ktrotns 6 7 12 14 17 20 25
14
hrkamm 2 4 21
mkhsi 6 2 3 8 11 18 20
hbkgnh 4 4 16 28 29
chyksrg 5 0 3 9 17 22
mktkkc 2 7 18
tknsj 3 3 9 23
yyitktk 3 10 13 25
ykhhgwr 2 18 26
amftm 3 13 18 22
mmftm 4 1 20 24 27
rtkakzk 2 1 10
azsmur 5 2 5 10 14 17
iormns 3 9 15 16
ktrotns 5 7 12 16 17 20
0
Output
7 akzakr
4 akzakr
6 knmmdk
12 tmemm
19 iormns
24 mktkkc | instruction | 0 | 80,764 | 14 | 161,528 |
"Correct Solution:
```
while True:
player_nun = int(input())
if player_nun == 0:
break
#?????????????????????
whole_data = []
for i in range(0, player_nun):
dat = input().split()
p_data = []
p_data.append(dat[0])
for x in dat[1:]:
p_data.append(int(x))
whole_data.append(p_data)
#???????????????????????????????????????
xel = {}
for i in whole_data:
for x in i[2:]:
if x in xel:
xel[x] += 1
else:
xel[x] = 1
#??????????????????????????Β’?????????
score = {}
for y in xel.keys():
score[y] = player_nun + 1 - xel[y]
#????????Β’??Β¨????????????????????????????????????
result = []
for i in whole_data:
player_score = []
player_score.append(i[0])
player_score.append(0)
for x in i[2:]:
player_score[1] += score[x]
result.append(player_score)
#?????????????????????????Β¬?????????????????Β±???????
min_score = min(x[1] for x in result)
winners = []
for x in result:
if x[1] == min_score:
winners.append(x[0])
print(str(min_score) + " " + sorted(winners)[0])
#??Β£??????????????????????????????
``` | output | 1 | 80,764 | 14 | 161,529 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are the planning manager of an animation production company. What animation production companies produce these days is not limited to animation itself. Related products, such as figures of characters and character song CDs, are also important sources of revenue. How much this profit can be increased depends solely on you, the director of the planning department.
Obviously, these related products are not something that should be released in the dark clouds. This is because it takes a lot of time and budget to develop a product. Even if you release a figure of an anime character, you have to limit it to popular characters that are expected to sell a lot.
One of the means to measure the popularity of a character is popularity voting. You've been planning some popularity polls so far, but it seems that viewers are becoming dissatisfied with the project. There is an urgent need to establish other methods for measuring popularity.
So you made a hypothesis. The popularity of a character is proportional to the total appearance time in the main part of the anime. To test this hypothesis, you decided to write a program that aggregates the appearance times of each character.
Input
The input consists of multiple cases. Each case is given in the following format.
n
name0 m0 d0,0 ... d0, m0-1
name1 m1 d1,0 ... d1, m1-1
..
..
..
namen-1 mn-1 dn-1,0 ... dn-1, mn-1-1
n represents the number of characters.
namei represents the name of the character.
mi represents the type of time the character was shown.
After mi, mi integers di and j are given.
di and j represent the time when the character was shown.
The end of the input is given by a line consisting of n = 0
If only one character appears on the screen at a given time, that character can get n points.
Every time one more character appears at the same time, the points obtained for the character reflected at that time decrease by one.
If n characters are shown at the same time, 1 point will be added to each of n characters.
The input satisfies the following constraints.
2 β€ n β€ 20
0 β€ mi β€ 30
0 β€ di, j <30
Di and j are all different for the i-th character.
namei contains only uppercase or lowercase letters and is no longer than 10.
Output
Output the points of the character with the smallest points and their names separated by a single space.
If there are multiple characters with the smallest points, select the person with the smallest name in lexicographical order.
Example
Input
4
akzakr 2 1 8
fnmyi 5 2 3 4 6 9
tsnukk 5 2 3 4 7 9
yskwcnt 6 3 4 7 8 9 10
4
akzakr 1 2
fnmyi 3 10 11 12
tsnukk 2 1 8
yskwcnt 2 1 8
5
knmmdk 2 13 19
akmhmr 4 13 15 19 22
mksyk 6 3 7 12 13 15 19
skrkyk 3 1 4 8
tmemm 3 1 17 24
5
knmmdk 5 5 6 16 18 26
akmhmr 9 3 4 7 11 14 15 17 18 20
mksyk 5 6 13 25 27 28
skrkyk 4 3 16 23 24
tmemm 3 6 12 20
14
hrkamm 6 4 6 8 10 20 22
mkhsi 6 1 10 12 15 22 27
hbkgnh 2 4 9
chyksrg 8 3 4 12 15 16 20 25 28
mktkkc 6 0 1 8 15 17 20
tknsj 6 6 8 18 19 25 26
yyitktk 3 3 12 18
ykhhgwr 5 3 9 10 11 24
amftm 7 2 6 8 12 13 14 17
mmftm 4 6 12 16 18
rtkakzk 3 14 15 21
azsmur 7 1 2 4 12 15 18 20
iormns 2 4 20
ktrotns 6 7 12 14 17 20 25
14
hrkamm 2 4 21
mkhsi 6 2 3 8 11 18 20
hbkgnh 4 4 16 28 29
chyksrg 5 0 3 9 17 22
mktkkc 2 7 18
tknsj 3 3 9 23
yyitktk 3 10 13 25
ykhhgwr 2 18 26
amftm 3 13 18 22
mmftm 4 1 20 24 27
rtkakzk 2 1 10
azsmur 5 2 5 10 14 17
iormns 3 9 15 16
ktrotns 5 7 12 16 17 20
0
Output
7 akzakr
4 akzakr
6 knmmdk
12 tmemm
19 iormns
24 mktkkc
Submitted Solution:
```
while True:
#player_nun = int(input())
player_nun = 4
if player_nun == 0:
break
#?????????????????????
whole_data = []
for i in (0, player_nun):
#dat = input().split()
#p_data = []
#p_data.append(dat[0])
for x in dat[1:]:
p_data.append(int(x))
whole_data.append(p_data)
#???????????????????????????????????????
xel = {}
for i in whole_data:
for x in i[2:]:
if x in xel:
xel[x] += 1
else:
xel[x] = 1
#??????????????????????????Β’?????????
score = {}
for y in xel.keys():
score[y] = 5 - xel[y]
#????????Β’??Β¨????????????????????????????????????
result = []
for i in whole_data:
player_score = []
player_score.append(i[0])
player_score.append(0)
for x in i[2:]:
player_score[1] += score[x]
result.append(player_score)
#?????????????????????????Β¬?????????????????Β±???????
min_score = min(x[1] for x in result)
winners = []
for x in result:
if x[1] == min_score:
winners.append(x[0])
print(str(min_score) + " " + sorted(winners)[0])
``` | instruction | 0 | 80,765 | 14 | 161,530 |
No | output | 1 | 80,765 | 14 | 161,531 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are the planning manager of an animation production company. What animation production companies produce these days is not limited to animation itself. Related products, such as figures of characters and character song CDs, are also important sources of revenue. How much this profit can be increased depends solely on you, the director of the planning department.
Obviously, these related products are not something that should be released in the dark clouds. This is because it takes a lot of time and budget to develop a product. Even if you release a figure of an anime character, you have to limit it to popular characters that are expected to sell a lot.
One of the means to measure the popularity of a character is popularity voting. You've been planning some popularity polls so far, but it seems that viewers are becoming dissatisfied with the project. There is an urgent need to establish other methods for measuring popularity.
So you made a hypothesis. The popularity of a character is proportional to the total appearance time in the main part of the anime. To test this hypothesis, you decided to write a program that aggregates the appearance times of each character.
Input
The input consists of multiple cases. Each case is given in the following format.
n
name0 m0 d0,0 ... d0, m0-1
name1 m1 d1,0 ... d1, m1-1
..
..
..
namen-1 mn-1 dn-1,0 ... dn-1, mn-1-1
n represents the number of characters.
namei represents the name of the character.
mi represents the type of time the character was shown.
After mi, mi integers di and j are given.
di and j represent the time when the character was shown.
The end of the input is given by a line consisting of n = 0
If only one character appears on the screen at a given time, that character can get n points.
Every time one more character appears at the same time, the points obtained for the character reflected at that time decrease by one.
If n characters are shown at the same time, 1 point will be added to each of n characters.
The input satisfies the following constraints.
2 β€ n β€ 20
0 β€ mi β€ 30
0 β€ di, j <30
Di and j are all different for the i-th character.
namei contains only uppercase or lowercase letters and is no longer than 10.
Output
Output the points of the character with the smallest points and their names separated by a single space.
If there are multiple characters with the smallest points, select the person with the smallest name in lexicographical order.
Example
Input
4
akzakr 2 1 8
fnmyi 5 2 3 4 6 9
tsnukk 5 2 3 4 7 9
yskwcnt 6 3 4 7 8 9 10
4
akzakr 1 2
fnmyi 3 10 11 12
tsnukk 2 1 8
yskwcnt 2 1 8
5
knmmdk 2 13 19
akmhmr 4 13 15 19 22
mksyk 6 3 7 12 13 15 19
skrkyk 3 1 4 8
tmemm 3 1 17 24
5
knmmdk 5 5 6 16 18 26
akmhmr 9 3 4 7 11 14 15 17 18 20
mksyk 5 6 13 25 27 28
skrkyk 4 3 16 23 24
tmemm 3 6 12 20
14
hrkamm 6 4 6 8 10 20 22
mkhsi 6 1 10 12 15 22 27
hbkgnh 2 4 9
chyksrg 8 3 4 12 15 16 20 25 28
mktkkc 6 0 1 8 15 17 20
tknsj 6 6 8 18 19 25 26
yyitktk 3 3 12 18
ykhhgwr 5 3 9 10 11 24
amftm 7 2 6 8 12 13 14 17
mmftm 4 6 12 16 18
rtkakzk 3 14 15 21
azsmur 7 1 2 4 12 15 18 20
iormns 2 4 20
ktrotns 6 7 12 14 17 20 25
14
hrkamm 2 4 21
mkhsi 6 2 3 8 11 18 20
hbkgnh 4 4 16 28 29
chyksrg 5 0 3 9 17 22
mktkkc 2 7 18
tknsj 3 3 9 23
yyitktk 3 10 13 25
ykhhgwr 2 18 26
amftm 3 13 18 22
mmftm 4 1 20 24 27
rtkakzk 2 1 10
azsmur 5 2 5 10 14 17
iormns 3 9 15 16
ktrotns 5 7 12 16 17 20
0
Output
7 akzakr
4 akzakr
6 knmmdk
12 tmemm
19 iormns
24 mktkkc
Submitted Solution:
```
while True:
player_nun = int(input())
player_nun = 4
if player_nun == 0:
break
#?????????????????????
whole_data = []
for i in (0, player_nun):
dat = input().split()
p_data = []
p_data.append(dat[0])
for x in dat[1:]:
p_data.append(int(x))
whole_data.append(p_data)
#???????????????????????????????????????
xel = {}
for i in whole_data:
for x in i[2:]:
if x in xel:
xel[x] += 1
else:
xel[x] = 1
#??????????????????????????Β’?????????
score = {}
for y in xel.keys():
score[y] = 5 - xel[y]
#????????Β’??Β¨????????????????????????????????????
result = []
for i in whole_data:
player_score = []
player_score.append(i[0])
player_score.append(0)
for x in i[2:]:
player_score[1] += score[x]
result.append(player_score)
#?????????????????????????Β¬?????????????????Β±???????
min_score = min(x[1] for x in result)
winners = []
for x in result:
if x[1] == min_score:
winners.append(x[0])
print(str(min_score) + " " + sorted(winners)[0])
``` | instruction | 0 | 80,766 | 14 | 161,532 |
No | output | 1 | 80,766 | 14 | 161,533 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are the planning manager of an animation production company. What animation production companies produce these days is not limited to animation itself. Related products, such as figures of characters and character song CDs, are also important sources of revenue. How much this profit can be increased depends solely on you, the director of the planning department.
Obviously, these related products are not something that should be released in the dark clouds. This is because it takes a lot of time and budget to develop a product. Even if you release a figure of an anime character, you have to limit it to popular characters that are expected to sell a lot.
One of the means to measure the popularity of a character is popularity voting. You've been planning some popularity polls so far, but it seems that viewers are becoming dissatisfied with the project. There is an urgent need to establish other methods for measuring popularity.
So you made a hypothesis. The popularity of a character is proportional to the total appearance time in the main part of the anime. To test this hypothesis, you decided to write a program that aggregates the appearance times of each character.
Input
The input consists of multiple cases. Each case is given in the following format.
n
name0 m0 d0,0 ... d0, m0-1
name1 m1 d1,0 ... d1, m1-1
..
..
..
namen-1 mn-1 dn-1,0 ... dn-1, mn-1-1
n represents the number of characters.
namei represents the name of the character.
mi represents the type of time the character was shown.
After mi, mi integers di and j are given.
di and j represent the time when the character was shown.
The end of the input is given by a line consisting of n = 0
If only one character appears on the screen at a given time, that character can get n points.
Every time one more character appears at the same time, the points obtained for the character reflected at that time decrease by one.
If n characters are shown at the same time, 1 point will be added to each of n characters.
The input satisfies the following constraints.
2 β€ n β€ 20
0 β€ mi β€ 30
0 β€ di, j <30
Di and j are all different for the i-th character.
namei contains only uppercase or lowercase letters and is no longer than 10.
Output
Output the points of the character with the smallest points and their names separated by a single space.
If there are multiple characters with the smallest points, select the person with the smallest name in lexicographical order.
Example
Input
4
akzakr 2 1 8
fnmyi 5 2 3 4 6 9
tsnukk 5 2 3 4 7 9
yskwcnt 6 3 4 7 8 9 10
4
akzakr 1 2
fnmyi 3 10 11 12
tsnukk 2 1 8
yskwcnt 2 1 8
5
knmmdk 2 13 19
akmhmr 4 13 15 19 22
mksyk 6 3 7 12 13 15 19
skrkyk 3 1 4 8
tmemm 3 1 17 24
5
knmmdk 5 5 6 16 18 26
akmhmr 9 3 4 7 11 14 15 17 18 20
mksyk 5 6 13 25 27 28
skrkyk 4 3 16 23 24
tmemm 3 6 12 20
14
hrkamm 6 4 6 8 10 20 22
mkhsi 6 1 10 12 15 22 27
hbkgnh 2 4 9
chyksrg 8 3 4 12 15 16 20 25 28
mktkkc 6 0 1 8 15 17 20
tknsj 6 6 8 18 19 25 26
yyitktk 3 3 12 18
ykhhgwr 5 3 9 10 11 24
amftm 7 2 6 8 12 13 14 17
mmftm 4 6 12 16 18
rtkakzk 3 14 15 21
azsmur 7 1 2 4 12 15 18 20
iormns 2 4 20
ktrotns 6 7 12 14 17 20 25
14
hrkamm 2 4 21
mkhsi 6 2 3 8 11 18 20
hbkgnh 4 4 16 28 29
chyksrg 5 0 3 9 17 22
mktkkc 2 7 18
tknsj 3 3 9 23
yyitktk 3 10 13 25
ykhhgwr 2 18 26
amftm 3 13 18 22
mmftm 4 1 20 24 27
rtkakzk 2 1 10
azsmur 5 2 5 10 14 17
iormns 3 9 15 16
ktrotns 5 7 12 16 17 20
0
Output
7 akzakr
4 akzakr
6 knmmdk
12 tmemm
19 iormns
24 mktkkc
Submitted Solution:
```
while True:
player_nun = int(input())
if player_nun == 0:
break
#?????????????????????
whole_data = []
for i in range(0, player_nun):
dat = input().split()
p_data = []
p_data.append(dat[0])
for x in dat[1:]:
p_data.append(int(x))
whole_data.append(p_data)
print(whole_data)
#???????????????????????????????????????
xel = {}
for i in whole_data:
for x in i[2:]:
if x in xel:
xel[x] += 1
else:
xel[x] = 1
#??????????????????????????Β’?????????
score = {}
for y in xel.keys():
score[y] = 5 - xel[y]
#????????Β’??Β¨????????????????????????????????????
result = []
for i in whole_data:
player_score = []
player_score.append(i[0])
player_score.append(0)
for x in i[2:]:
player_score[1] += score[x]
result.append(player_score)
#?????????????????????????Β¬?????????????????Β±???????
min_score = min(x[1] for x in result)
winners = []
for x in result:
if x[1] == min_score:
winners.append(x[0])
print(str(min_score) + " " + sorted(winners)[0])
``` | instruction | 0 | 80,767 | 14 | 161,534 |
No | output | 1 | 80,767 | 14 | 161,535 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.