message
stringlengths 2
39.6k
| message_type
stringclasses 2
values | message_id
int64 0
1
| conversation_id
int64 219
108k
| cluster
float64 11
11
| __index_level_0__
int64 438
217k
|
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In 2020, AtCoder Inc. with an annual sales of more than one billion yen (the currency of Japan) has started a business in programming education.
One day, there was an exam where a one-year-old child must write a program that prints `Hello World`, and a two-year-old child must write a program that receives integers A, B and prints A+B.
Takahashi, who is taking this exam, suddenly forgets his age.
He decides to write a program that first receives his age N (1 or 2) as input, then prints `Hello World` if N=1, and additionally receives integers A, B and prints A+B if N=2.
Write this program for him.
Constraints
* N is 1 or 2.
* A is an integer between 1 and 9 (inclusive).
* B is an integer between 1 and 9 (inclusive).
Input
Input is given from Standard Input in one of the following formats:
1
2
A
B
Output
If N=1, print `Hello World`; if N=2, print A+B.
Examples
Input
1
Output
Hello World
Input
2
3
5
Output
8
Submitted Solution:
```
N = int(input())
print("Hello World") if N==1 else print(sum([int(input()) for _ in range(2)]))
```
|
instruction
| 0
| 8,256
| 11
| 16,512
|
Yes
|
output
| 1
| 8,256
| 11
| 16,513
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In 2020, AtCoder Inc. with an annual sales of more than one billion yen (the currency of Japan) has started a business in programming education.
One day, there was an exam where a one-year-old child must write a program that prints `Hello World`, and a two-year-old child must write a program that receives integers A, B and prints A+B.
Takahashi, who is taking this exam, suddenly forgets his age.
He decides to write a program that first receives his age N (1 or 2) as input, then prints `Hello World` if N=1, and additionally receives integers A, B and prints A+B if N=2.
Write this program for him.
Constraints
* N is 1 or 2.
* A is an integer between 1 and 9 (inclusive).
* B is an integer between 1 and 9 (inclusive).
Input
Input is given from Standard Input in one of the following formats:
1
2
A
B
Output
If N=1, print `Hello World`; if N=2, print A+B.
Examples
Input
1
Output
Hello World
Input
2
3
5
Output
8
Submitted Solution:
```
N,*C=map(int,open(0).read().split())
if N == 2:
print(sum(C))
else:
print("Hello World")
```
|
instruction
| 0
| 8,257
| 11
| 16,514
|
Yes
|
output
| 1
| 8,257
| 11
| 16,515
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In 2020, AtCoder Inc. with an annual sales of more than one billion yen (the currency of Japan) has started a business in programming education.
One day, there was an exam where a one-year-old child must write a program that prints `Hello World`, and a two-year-old child must write a program that receives integers A, B and prints A+B.
Takahashi, who is taking this exam, suddenly forgets his age.
He decides to write a program that first receives his age N (1 or 2) as input, then prints `Hello World` if N=1, and additionally receives integers A, B and prints A+B if N=2.
Write this program for him.
Constraints
* N is 1 or 2.
* A is an integer between 1 and 9 (inclusive).
* B is an integer between 1 and 9 (inclusive).
Input
Input is given from Standard Input in one of the following formats:
1
2
A
B
Output
If N=1, print `Hello World`; if N=2, print A+B.
Examples
Input
1
Output
Hello World
Input
2
3
5
Output
8
Submitted Solution:
```
if int(input()) == 1:
print("Hello World")
else:
print(int(input()) + int(input()))
```
|
instruction
| 0
| 8,258
| 11
| 16,516
|
Yes
|
output
| 1
| 8,258
| 11
| 16,517
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In 2020, AtCoder Inc. with an annual sales of more than one billion yen (the currency of Japan) has started a business in programming education.
One day, there was an exam where a one-year-old child must write a program that prints `Hello World`, and a two-year-old child must write a program that receives integers A, B and prints A+B.
Takahashi, who is taking this exam, suddenly forgets his age.
He decides to write a program that first receives his age N (1 or 2) as input, then prints `Hello World` if N=1, and additionally receives integers A, B and prints A+B if N=2.
Write this program for him.
Constraints
* N is 1 or 2.
* A is an integer between 1 and 9 (inclusive).
* B is an integer between 1 and 9 (inclusive).
Input
Input is given from Standard Input in one of the following formats:
1
2
A
B
Output
If N=1, print `Hello World`; if N=2, print A+B.
Examples
Input
1
Output
Hello World
Input
2
3
5
Output
8
Submitted Solution:
```
x=int(input())
if (x==1):
print("Hello World")
else:
a=int(input())
b=int(input())
print(a+b)
```
|
instruction
| 0
| 8,259
| 11
| 16,518
|
Yes
|
output
| 1
| 8,259
| 11
| 16,519
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In 2020, AtCoder Inc. with an annual sales of more than one billion yen (the currency of Japan) has started a business in programming education.
One day, there was an exam where a one-year-old child must write a program that prints `Hello World`, and a two-year-old child must write a program that receives integers A, B and prints A+B.
Takahashi, who is taking this exam, suddenly forgets his age.
He decides to write a program that first receives his age N (1 or 2) as input, then prints `Hello World` if N=1, and additionally receives integers A, B and prints A+B if N=2.
Write this program for him.
Constraints
* N is 1 or 2.
* A is an integer between 1 and 9 (inclusive).
* B is an integer between 1 and 9 (inclusive).
Input
Input is given from Standard Input in one of the following formats:
1
2
A
B
Output
If N=1, print `Hello World`; if N=2, print A+B.
Examples
Input
1
Output
Hello World
Input
2
3
5
Output
8
Submitted Solution:
```
N = int(input())
lst = [int(input()) for i in range(2)]
if (N == 1):
print('Hello World')
else:
print(sum(lst))
```
|
instruction
| 0
| 8,260
| 11
| 16,520
|
No
|
output
| 1
| 8,260
| 11
| 16,521
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In 2020, AtCoder Inc. with an annual sales of more than one billion yen (the currency of Japan) has started a business in programming education.
One day, there was an exam where a one-year-old child must write a program that prints `Hello World`, and a two-year-old child must write a program that receives integers A, B and prints A+B.
Takahashi, who is taking this exam, suddenly forgets his age.
He decides to write a program that first receives his age N (1 or 2) as input, then prints `Hello World` if N=1, and additionally receives integers A, B and prints A+B if N=2.
Write this program for him.
Constraints
* N is 1 or 2.
* A is an integer between 1 and 9 (inclusive).
* B is an integer between 1 and 9 (inclusive).
Input
Input is given from Standard Input in one of the following formats:
1
2
A
B
Output
If N=1, print `Hello World`; if N=2, print A+B.
Examples
Input
1
Output
Hello World
Input
2
3
5
Output
8
Submitted Solution:
```
# | Its_Rashid | #
n = int(input())
if n == 1 :
print('Hello World')
else :
print(sum([int(input()) for i in range()]))
```
|
instruction
| 0
| 8,261
| 11
| 16,522
|
No
|
output
| 1
| 8,261
| 11
| 16,523
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In 2020, AtCoder Inc. with an annual sales of more than one billion yen (the currency of Japan) has started a business in programming education.
One day, there was an exam where a one-year-old child must write a program that prints `Hello World`, and a two-year-old child must write a program that receives integers A, B and prints A+B.
Takahashi, who is taking this exam, suddenly forgets his age.
He decides to write a program that first receives his age N (1 or 2) as input, then prints `Hello World` if N=1, and additionally receives integers A, B and prints A+B if N=2.
Write this program for him.
Constraints
* N is 1 or 2.
* A is an integer between 1 and 9 (inclusive).
* B is an integer between 1 and 9 (inclusive).
Input
Input is given from Standard Input in one of the following formats:
1
2
A
B
Output
If N=1, print `Hello World`; if N=2, print A+B.
Examples
Input
1
Output
Hello World
Input
2
3
5
Output
8
Submitted Solution:
```
import random
def is_prime(q,k=50):
if q == 2: return True
if q < 2 or q&1 == 0: return False
d = (q-1)>>1
while d&1 == 0:
d >>= 1
for i in range(k):
a = random.randint(1,q-1)
t = d
y = pow(a,t,q)
while t != q-1 and y != 1 and y != q-1:
y = pow(y,2,q)
t <<= 1
if y != q-1 and t&1 == 0:
return False
return True
n,m=(int(i) for i in input().split(' '))
if m%n>100000:
for i in range(1,n):
if m%i==0 and is_prime(i) and is_prime(m//i) and (i==1 or m//i<n):
print('1')
exit()
for i in range(n,m+1):
if i==m:
print(1)
break
if m%i==0:
print(m//i)
break
if m-i-n>0 and m%(m-i-n)==0 and m//(m-i-n)>n:
print(m-i-n)
break
```
|
instruction
| 0
| 8,262
| 11
| 16,524
|
No
|
output
| 1
| 8,262
| 11
| 16,525
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
Constraints
* 1≦N≦100
Input
The input is given from Standard Input in the following format:
N
Output
Print the necessary number of candies in total.
Examples
Input
3
Output
6
Input
10
Output
55
Input
1
Output
1
Submitted Solution:
```
N = int(input())
print(round(N*(N+1)/2))
```
|
instruction
| 0
| 8,317
| 11
| 16,634
|
Yes
|
output
| 1
| 8,317
| 11
| 16,635
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
Constraints
* 1≦N≦100
Input
The input is given from Standard Input in the following format:
N
Output
Print the necessary number of candies in total.
Examples
Input
3
Output
6
Input
10
Output
55
Input
1
Output
1
Submitted Solution:
```
a=int(input())
print(int(a*(a+1)/2))
```
|
instruction
| 0
| 8,318
| 11
| 16,636
|
Yes
|
output
| 1
| 8,318
| 11
| 16,637
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
Constraints
* 1≦N≦100
Input
The input is given from Standard Input in the following format:
N
Output
Print the necessary number of candies in total.
Examples
Input
3
Output
6
Input
10
Output
55
Input
1
Output
1
Submitted Solution:
```
N = int(input())
print(int(((N+1)*N)/2))
```
|
instruction
| 0
| 8,319
| 11
| 16,638
|
Yes
|
output
| 1
| 8,319
| 11
| 16,639
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
Constraints
* 1≦N≦100
Input
The input is given from Standard Input in the following format:
N
Output
Print the necessary number of candies in total.
Examples
Input
3
Output
6
Input
10
Output
55
Input
1
Output
1
Submitted Solution:
```
print(sum(list(range(1, int(input())+1))))
```
|
instruction
| 0
| 8,320
| 11
| 16,640
|
Yes
|
output
| 1
| 8,320
| 11
| 16,641
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
Constraints
* 1≦N≦100
Input
The input is given from Standard Input in the following format:
N
Output
Print the necessary number of candies in total.
Examples
Input
3
Output
6
Input
10
Output
55
Input
1
Output
1
Submitted Solution:
```
number = input()
for i in range(number):
number = number+1
print(number)
```
|
instruction
| 0
| 8,322
| 11
| 16,644
|
No
|
output
| 1
| 8,322
| 11
| 16,645
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
Constraints
* 1≦N≦100
Input
The input is given from Standard Input in the following format:
N
Output
Print the necessary number of candies in total.
Examples
Input
3
Output
6
Input
10
Output
55
Input
1
Output
1
Submitted Solution:
```
n=input()
s=(n*(n+1))/2
print(s)
```
|
instruction
| 0
| 8,323
| 11
| 16,646
|
No
|
output
| 1
| 8,323
| 11
| 16,647
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
Constraints
* 1≦N≦100
Input
The input is given from Standard Input in the following format:
N
Output
Print the necessary number of candies in total.
Examples
Input
3
Output
6
Input
10
Output
55
Input
1
Output
1
Submitted Solution:
```
x = int(input())
print((x*(x+1))/2)
```
|
instruction
| 0
| 8,324
| 11
| 16,648
|
No
|
output
| 1
| 8,324
| 11
| 16,649
|
Provide a correct Python 3 solution for this coding contest problem.
Example
Input
3
aab
czc
baa
Output
aac
|
instruction
| 0
| 8,355
| 11
| 16,710
|
"Correct Solution:
```
from string import ascii_lowercase, ascii_uppercase
import sys
readline = sys.stdin.readline
write = sys.stdout.write
from heapq import heappush, heappop
class MinCostFlow:
INF = 10**100
def __init__(self, N):
self.N = N
self.G = [[] for i in range(N)]
self.D = {}
def add_edge(self, fr, to, cap, cost):
G = self.G
G[fr].append([to, cap, cost, len(G[to])])
G[to].append([fr, 0, -cost, len(G[fr])-1])
self.D[fr, to] = G[fr][-1]
self.D[to, fr] = G[to][-1]
def flow(self, s, t, f):
N = self.N; G = self.G
INF = MinCostFlow.INF
res = 0
H = [0]*N
prv_v = [0]*N
prv_e = [0]*N
while f:
dist = [INF]*N
dist[s] = 0
que = [(0, s)]
while que:
c, v = heappop(que)
if dist[v] < c:
continue
for i, (w, cap, cost, _) in enumerate(G[v]):
if cap > 0 and dist[w] > dist[v] + cost + H[v] - H[w]:
dist[w] = r = dist[v] + cost + H[v] - H[w]
prv_v[w] = v; prv_e[w] = i
heappush(que, (r, w))
if dist[t] == INF:
return -1
for i in range(N):
H[i] += dist[i]
d = f; v = t
while v != s:
d = min(d, G[prv_v[v]][prv_e[v]][1])
v = prv_v[v]
f -= d
res += d * H[t]
v = t
while v != s:
e = G[prv_v[v]][prv_e[v]]
e[1] -= d
G[v][e[3]][1] += d
v = prv_v[v]
return res
cs = ascii_uppercase + ascii_lowercase
L = len(cs)
def solve():
N = int(readline())
g = N*2
mcf = MinCostFlow(N*2+2)
for i in range(N):
mcf.add_edge(g, i, 1, 0)
mcf.add_edge(N+i, g+1, 1, 0)
S = []
for i in range(N):
*Si, = map(cs.index, readline().strip())
for j in range(N):
mcf.add_edge(i, j+N, 1, -L**(L-Si[j]))
S.append(Si)
mcf.flow(g, g+1, N)
ans = []
for i in range(N):
Si = S[i]
for j in range(N):
if mcf.D[i, j+N][1] == 0:
ans.append(Si[j])
ans.sort()
write("".join(map(cs.__getitem__, ans)))
write("\n")
solve()
```
|
output
| 1
| 8,355
| 11
| 16,711
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Example
Input
3
aab
czc
baa
Output
aac
Submitted Solution:
```
import heapq
class edge:
def __init__(self,to,cap,cost,rev):
self.to = to
self.cap = cap
self.cost = cost
self.rev = rev
class min_cost_flow:
INF = 52**60
def __init__(self, n):
self.V = n
self.G = [[] for _ in range(n)]
self.h = [0 for _ in range(n)]
self.dist = [0 for _ in range(n)]
def add_edge(self, f, t, cap, cost):
self.G[f].append(edge(t,cap,cost,len(self.G[t])))
self.G[t].append(edge(f,0,-cost,len(self.G[f])-1))
def min_cost_flow(self, s, t, f):
prevv = [0 for _ in range(self.V)]
preve = [0 for _ in range(self.V)]
res = 0
self.h = [0 for _ in range(self.V)]
while f > 0:
pq = []
self.dist = [min_cost_flow.INF for _ in range(self.V)]
self.dist[s] = 0
# dijkstra
heapq.heappush(pq,(0,s))
while len(pq) != 0:
p = heapq.heappop(pq)
v = p[1]
if p[0] > self.dist[v]:
continue
for i in range(len(self.G[v])):
e = self.G[v][i]
if e.cap>0 and self.dist[e.to]>self.dist[v]+e.cost+self.h[v]-self.h[e.to]:
self.dist[e.to] = self.dist[v]+e.cost+self.h[v]-self.h[e.to]
prevv[e.to] = v
preve[e.to] = i
heapq.heappush(pq,(self.dist[e.to],e.to))
if self.dist[t] == min_cost_flow.INF:
return -1
for i in range(self.V):
self.h[i] += self.dist[i]
d = f
v = t
while v != s:
d = min(d,self.G[prevv[v]][preve[v]].cap)
v = prevv[v]
f -= d
res += d*self.h[t]
v = t
while v != s:
self.G[prevv[v]][preve[v]].cap -= d
self.G[v][self.G[prevv[v]][preve[v]].rev].cap += d
v = prevv[v]
return res
def solve(self,s,t,n,d):
f = self.min_cost_flow(s,t,n)
ans = []
for i in range(n):
for j in range(len(self.G[n+i])):
if self.G[n+i][j].cap>0:
cost = -self.G[n+i][j].cost
ans.append(d[cost])
break
ans.sort()
return ''.join(ans)
def main():
n = int(input())
s = []
for _ in range(n):
s.append(input())
flow = min_cost_flow(2*n+2)
S,T = 2*n,2*n+1
X = 52**52
for i in range(n):
flow.add_edge(S,i,1,0)
flow.add_edge(n+i,T,1,0)
d = {}
for i in range(n):
for j in range(n):
cost = X
if 'A'<=s[i][j]<='Z':
cost -= 52**(51-(ord(s[i][j])-ord(('A'))))
else:
cost -= 52**(26-(ord(s[i][j])-ord(('a'))))
flow.add_edge(i,n+j,1,cost)
d[cost] = s[i][j]
print(flow.solve(S,T,n,d))
if __name__ == '__main__':
main()
```
|
instruction
| 0
| 8,356
| 11
| 16,712
|
No
|
output
| 1
| 8,356
| 11
| 16,713
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's denote correct match equation (we will denote it as CME) an equation a + b = c there all integers a, b and c are greater than zero.
For example, equations 2 + 2 = 4 (||+||=||||) and 1 + 2 = 3 (|+||=|||) are CME but equations 1 + 2 = 4 (|+||=||||), 2 + 2 = 3 (||+||=|||), and 0 + 1 = 1 (+|=|) are not.
Now, you have n matches. You want to assemble a CME using all your matches. Unfortunately, it is possible that you can't assemble the CME using all matches. But you can buy some extra matches and then assemble CME!
For example, if n = 2, you can buy two matches and assemble |+|=||, and if n = 5 you can buy one match and assemble ||+|=|||.
<image>
Calculate the minimum number of matches which you have to buy for assembling CME.
Note, that you have to answer q independent queries.
Input
The first line contains one integer q (1 ≤ q ≤ 100) — the number of queries.
The only line of each query contains one integer n (2 ≤ n ≤ 10^9) — the number of matches.
Output
For each test case print one integer in single line — the minimum number of matches which you have to buy for assembling CME.
Example
Input
4
2
5
8
11
Output
2
1
0
1
Note
The first and second queries are explained in the statement.
In the third query, you can assemble 1 + 3 = 4 (|+|||=||||) without buying matches.
In the fourth query, buy one match and assemble 2 + 4 = 6 (||+||||=||||||).
Submitted Solution:
```
for _ in range(int(input())):
n=int(input())
if n<4:
print(4-n)
elif n%2==0:
print(0)
else:
print(1)
```
|
instruction
| 0
| 8,448
| 11
| 16,896
|
Yes
|
output
| 1
| 8,448
| 11
| 16,897
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's denote correct match equation (we will denote it as CME) an equation a + b = c there all integers a, b and c are greater than zero.
For example, equations 2 + 2 = 4 (||+||=||||) and 1 + 2 = 3 (|+||=|||) are CME but equations 1 + 2 = 4 (|+||=||||), 2 + 2 = 3 (||+||=|||), and 0 + 1 = 1 (+|=|) are not.
Now, you have n matches. You want to assemble a CME using all your matches. Unfortunately, it is possible that you can't assemble the CME using all matches. But you can buy some extra matches and then assemble CME!
For example, if n = 2, you can buy two matches and assemble |+|=||, and if n = 5 you can buy one match and assemble ||+|=|||.
<image>
Calculate the minimum number of matches which you have to buy for assembling CME.
Note, that you have to answer q independent queries.
Input
The first line contains one integer q (1 ≤ q ≤ 100) — the number of queries.
The only line of each query contains one integer n (2 ≤ n ≤ 10^9) — the number of matches.
Output
For each test case print one integer in single line — the minimum number of matches which you have to buy for assembling CME.
Example
Input
4
2
5
8
11
Output
2
1
0
1
Note
The first and second queries are explained in the statement.
In the third query, you can assemble 1 + 3 = 4 (|+|||=||||) without buying matches.
In the fourth query, buy one match and assemble 2 + 4 = 6 (||+||||=||||||).
Submitted Solution:
```
n=int(input())
for i in range(n):
m=int(input())
if(m<=4):
print(4-m)
else:
if(m%2==0):
print(0)
else:
print(1)
```
|
instruction
| 0
| 8,449
| 11
| 16,898
|
Yes
|
output
| 1
| 8,449
| 11
| 16,899
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's denote correct match equation (we will denote it as CME) an equation a + b = c there all integers a, b and c are greater than zero.
For example, equations 2 + 2 = 4 (||+||=||||) and 1 + 2 = 3 (|+||=|||) are CME but equations 1 + 2 = 4 (|+||=||||), 2 + 2 = 3 (||+||=|||), and 0 + 1 = 1 (+|=|) are not.
Now, you have n matches. You want to assemble a CME using all your matches. Unfortunately, it is possible that you can't assemble the CME using all matches. But you can buy some extra matches and then assemble CME!
For example, if n = 2, you can buy two matches and assemble |+|=||, and if n = 5 you can buy one match and assemble ||+|=|||.
<image>
Calculate the minimum number of matches which you have to buy for assembling CME.
Note, that you have to answer q independent queries.
Input
The first line contains one integer q (1 ≤ q ≤ 100) — the number of queries.
The only line of each query contains one integer n (2 ≤ n ≤ 10^9) — the number of matches.
Output
For each test case print one integer in single line — the minimum number of matches which you have to buy for assembling CME.
Example
Input
4
2
5
8
11
Output
2
1
0
1
Note
The first and second queries are explained in the statement.
In the third query, you can assemble 1 + 3 = 4 (|+|||=||||) without buying matches.
In the fourth query, buy one match and assemble 2 + 4 = 6 (||+||||=||||||).
Submitted Solution:
```
a=int(input())
for i in range(a):
n=int(input())
if n==2:
print(2)
elif n%2==0:
print(0)
else:
print(1)
```
|
instruction
| 0
| 8,450
| 11
| 16,900
|
Yes
|
output
| 1
| 8,450
| 11
| 16,901
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's denote correct match equation (we will denote it as CME) an equation a + b = c there all integers a, b and c are greater than zero.
For example, equations 2 + 2 = 4 (||+||=||||) and 1 + 2 = 3 (|+||=|||) are CME but equations 1 + 2 = 4 (|+||=||||), 2 + 2 = 3 (||+||=|||), and 0 + 1 = 1 (+|=|) are not.
Now, you have n matches. You want to assemble a CME using all your matches. Unfortunately, it is possible that you can't assemble the CME using all matches. But you can buy some extra matches and then assemble CME!
For example, if n = 2, you can buy two matches and assemble |+|=||, and if n = 5 you can buy one match and assemble ||+|=|||.
<image>
Calculate the minimum number of matches which you have to buy for assembling CME.
Note, that you have to answer q independent queries.
Input
The first line contains one integer q (1 ≤ q ≤ 100) — the number of queries.
The only line of each query contains one integer n (2 ≤ n ≤ 10^9) — the number of matches.
Output
For each test case print one integer in single line — the minimum number of matches which you have to buy for assembling CME.
Example
Input
4
2
5
8
11
Output
2
1
0
1
Note
The first and second queries are explained in the statement.
In the third query, you can assemble 1 + 3 = 4 (|+|||=||||) without buying matches.
In the fourth query, buy one match and assemble 2 + 4 = 6 (||+||||=||||||).
Submitted Solution:
```
h = int(input())
for i in range(h):
a = int(input())
if a < 4:
print(4 - a)
elif a % 2 != 0:
print(1)
else:
print(0)
```
|
instruction
| 0
| 8,451
| 11
| 16,902
|
Yes
|
output
| 1
| 8,451
| 11
| 16,903
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's denote correct match equation (we will denote it as CME) an equation a + b = c there all integers a, b and c are greater than zero.
For example, equations 2 + 2 = 4 (||+||=||||) and 1 + 2 = 3 (|+||=|||) are CME but equations 1 + 2 = 4 (|+||=||||), 2 + 2 = 3 (||+||=|||), and 0 + 1 = 1 (+|=|) are not.
Now, you have n matches. You want to assemble a CME using all your matches. Unfortunately, it is possible that you can't assemble the CME using all matches. But you can buy some extra matches and then assemble CME!
For example, if n = 2, you can buy two matches and assemble |+|=||, and if n = 5 you can buy one match and assemble ||+|=|||.
<image>
Calculate the minimum number of matches which you have to buy for assembling CME.
Note, that you have to answer q independent queries.
Input
The first line contains one integer q (1 ≤ q ≤ 100) — the number of queries.
The only line of each query contains one integer n (2 ≤ n ≤ 10^9) — the number of matches.
Output
For each test case print one integer in single line — the minimum number of matches which you have to buy for assembling CME.
Example
Input
4
2
5
8
11
Output
2
1
0
1
Note
The first and second queries are explained in the statement.
In the third query, you can assemble 1 + 3 = 4 (|+|||=||||) without buying matches.
In the fourth query, buy one match and assemble 2 + 4 = 6 (||+||||=||||||).
Submitted Solution:
```
n = input()
n = int(n)
for _ in range(n):
k = input()
k = int(k)
if k == 2:
print(2)
if k % 2 == 0 and k > 2:
print(0)
else:
print(1)
```
|
instruction
| 0
| 8,452
| 11
| 16,904
|
No
|
output
| 1
| 8,452
| 11
| 16,905
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's denote correct match equation (we will denote it as CME) an equation a + b = c there all integers a, b and c are greater than zero.
For example, equations 2 + 2 = 4 (||+||=||||) and 1 + 2 = 3 (|+||=|||) are CME but equations 1 + 2 = 4 (|+||=||||), 2 + 2 = 3 (||+||=|||), and 0 + 1 = 1 (+|=|) are not.
Now, you have n matches. You want to assemble a CME using all your matches. Unfortunately, it is possible that you can't assemble the CME using all matches. But you can buy some extra matches and then assemble CME!
For example, if n = 2, you can buy two matches and assemble |+|=||, and if n = 5 you can buy one match and assemble ||+|=|||.
<image>
Calculate the minimum number of matches which you have to buy for assembling CME.
Note, that you have to answer q independent queries.
Input
The first line contains one integer q (1 ≤ q ≤ 100) — the number of queries.
The only line of each query contains one integer n (2 ≤ n ≤ 10^9) — the number of matches.
Output
For each test case print one integer in single line — the minimum number of matches which you have to buy for assembling CME.
Example
Input
4
2
5
8
11
Output
2
1
0
1
Note
The first and second queries are explained in the statement.
In the third query, you can assemble 1 + 3 = 4 (|+|||=||||) without buying matches.
In the fourth query, buy one match and assemble 2 + 4 = 6 (||+||||=||||||).
Submitted Solution:
```
for i in range(int(input())):
q=int(input())
if q==2:
print(2)
elif q/2!=0:
print(1)
elif q/2==0:
print(0)
```
|
instruction
| 0
| 8,453
| 11
| 16,906
|
No
|
output
| 1
| 8,453
| 11
| 16,907
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's denote correct match equation (we will denote it as CME) an equation a + b = c there all integers a, b and c are greater than zero.
For example, equations 2 + 2 = 4 (||+||=||||) and 1 + 2 = 3 (|+||=|||) are CME but equations 1 + 2 = 4 (|+||=||||), 2 + 2 = 3 (||+||=|||), and 0 + 1 = 1 (+|=|) are not.
Now, you have n matches. You want to assemble a CME using all your matches. Unfortunately, it is possible that you can't assemble the CME using all matches. But you can buy some extra matches and then assemble CME!
For example, if n = 2, you can buy two matches and assemble |+|=||, and if n = 5 you can buy one match and assemble ||+|=|||.
<image>
Calculate the minimum number of matches which you have to buy for assembling CME.
Note, that you have to answer q independent queries.
Input
The first line contains one integer q (1 ≤ q ≤ 100) — the number of queries.
The only line of each query contains one integer n (2 ≤ n ≤ 10^9) — the number of matches.
Output
For each test case print one integer in single line — the minimum number of matches which you have to buy for assembling CME.
Example
Input
4
2
5
8
11
Output
2
1
0
1
Note
The first and second queries are explained in the statement.
In the third query, you can assemble 1 + 3 = 4 (|+|||=||||) without buying matches.
In the fourth query, buy one match and assemble 2 + 4 = 6 (||+||||=||||||).
Submitted Solution:
```
q = int(input())
for i in range(q):
t = int(input())
if t < 4:
otv = 4 - t
print(t)
else:
if t % 2 == 0:
print(0)
else:
print(1)
```
|
instruction
| 0
| 8,454
| 11
| 16,908
|
No
|
output
| 1
| 8,454
| 11
| 16,909
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's denote correct match equation (we will denote it as CME) an equation a + b = c there all integers a, b and c are greater than zero.
For example, equations 2 + 2 = 4 (||+||=||||) and 1 + 2 = 3 (|+||=|||) are CME but equations 1 + 2 = 4 (|+||=||||), 2 + 2 = 3 (||+||=|||), and 0 + 1 = 1 (+|=|) are not.
Now, you have n matches. You want to assemble a CME using all your matches. Unfortunately, it is possible that you can't assemble the CME using all matches. But you can buy some extra matches and then assemble CME!
For example, if n = 2, you can buy two matches and assemble |+|=||, and if n = 5 you can buy one match and assemble ||+|=|||.
<image>
Calculate the minimum number of matches which you have to buy for assembling CME.
Note, that you have to answer q independent queries.
Input
The first line contains one integer q (1 ≤ q ≤ 100) — the number of queries.
The only line of each query contains one integer n (2 ≤ n ≤ 10^9) — the number of matches.
Output
For each test case print one integer in single line — the minimum number of matches which you have to buy for assembling CME.
Example
Input
4
2
5
8
11
Output
2
1
0
1
Note
The first and second queries are explained in the statement.
In the third query, you can assemble 1 + 3 = 4 (|+|||=||||) without buying matches.
In the fourth query, buy one match and assemble 2 + 4 = 6 (||+||||=||||||).
Submitted Solution:
```
num_q = int(input())
inps = []
for i in range(num_q):
inps.append(int(input()))
for i in inps:
if i <= 2:
print(4-i)
if i % 2 == 0:
print("0")
else:
print("1")
```
|
instruction
| 0
| 8,455
| 11
| 16,910
|
No
|
output
| 1
| 8,455
| 11
| 16,911
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
per nextum in unam tum XI conscribementis fac sic
vestibulo perlegementum da varo.
morde varo.
seqis cumula varum.
cis
per nextum in unam tum XI conscribementis fac sic
seqis decumulamenta da varo.
varum privamentum fodementum da aresulto.
varum tum III elevamentum tum V multiplicamentum da bresulto.
aresultum tum bresultum addementum da resulto.
si CD tum resultum non praestantiam fac sic
dictum sic f(%d) = %.2f cis tum varum tum resultum egresso describe.
novumversum egresso scribe.
cis
si CD tum resultum praestantiam fac sic
dictum sic f(%d) = MAGNA NIMIS! cis tum varum egresso describe.
novumversum egresso scribe.
cis
cis
Input
The input consists of several integers, one per line. Each integer is between -50 and 50, inclusive.
Output
As described in the problem statement.
Example
Input
0
1
-2
-3
-4
-5
-6
-7
-8
-9
10
Output
f(10) = MAGNA NIMIS!
f(-9) = -3642.00
f(-8) = -2557.17
f(-7) = -1712.35
f(-6) = -1077.55
f(-5) = -622.76
f(-4) = -318.00
f(-3) = -133.27
f(-2) = -38.59
f(1) = 6.00
f(0) = 0.00
Submitted Solution:
```
def toFixed(numObj, digits=0):
return f"{numObj:.{digits}f}"
rome = [None]*11
for nextum in range(11):
rome[-nextum-1] = int(input())
for nextum in rome:
resultum = (nextum**2)**0.25 + 5*nextum**3
if resultum <= 400:
print("f({}) = {:.2f}".format(nextum, resultum))
else:
print("f({}) = MAGNA NIMIS!".format(nextum))
```
|
instruction
| 0
| 8,502
| 11
| 17,004
|
Yes
|
output
| 1
| 8,502
| 11
| 17,005
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
per nextum in unam tum XI conscribementis fac sic
vestibulo perlegementum da varo.
morde varo.
seqis cumula varum.
cis
per nextum in unam tum XI conscribementis fac sic
seqis decumulamenta da varo.
varum privamentum fodementum da aresulto.
varum tum III elevamentum tum V multiplicamentum da bresulto.
aresultum tum bresultum addementum da resulto.
si CD tum resultum non praestantiam fac sic
dictum sic f(%d) = %.2f cis tum varum tum resultum egresso describe.
novumversum egresso scribe.
cis
si CD tum resultum praestantiam fac sic
dictum sic f(%d) = MAGNA NIMIS! cis tum varum egresso describe.
novumversum egresso scribe.
cis
cis
Input
The input consists of several integers, one per line. Each integer is between -50 and 50, inclusive.
Output
As described in the problem statement.
Example
Input
0
1
-2
-3
-4
-5
-6
-7
-8
-9
10
Output
f(10) = MAGNA NIMIS!
f(-9) = -3642.00
f(-8) = -2557.17
f(-7) = -1712.35
f(-6) = -1077.55
f(-5) = -622.76
f(-4) = -318.00
f(-3) = -133.27
f(-2) = -38.59
f(1) = 6.00
f(0) = 0.00
Submitted Solution:
```
import typing
lst = []
for i in range(11):
lst.append(int(input()))
for n in reversed(lst):
a = abs(n)**0.5
b = (n**3)*5
res = a+b
if res <= 400:
print("f({}) = {:.2f}".format(n,round(res,2)))
else:
print("f({}) = MAGNA NIMIS!".format(n))
```
|
instruction
| 0
| 8,503
| 11
| 17,006
|
Yes
|
output
| 1
| 8,503
| 11
| 17,007
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
per nextum in unam tum XI conscribementis fac sic
vestibulo perlegementum da varo.
morde varo.
seqis cumula varum.
cis
per nextum in unam tum XI conscribementis fac sic
seqis decumulamenta da varo.
varum privamentum fodementum da aresulto.
varum tum III elevamentum tum V multiplicamentum da bresulto.
aresultum tum bresultum addementum da resulto.
si CD tum resultum non praestantiam fac sic
dictum sic f(%d) = %.2f cis tum varum tum resultum egresso describe.
novumversum egresso scribe.
cis
si CD tum resultum praestantiam fac sic
dictum sic f(%d) = MAGNA NIMIS! cis tum varum egresso describe.
novumversum egresso scribe.
cis
cis
Input
The input consists of several integers, one per line. Each integer is between -50 and 50, inclusive.
Output
As described in the problem statement.
Example
Input
0
1
-2
-3
-4
-5
-6
-7
-8
-9
10
Output
f(10) = MAGNA NIMIS!
f(-9) = -3642.00
f(-8) = -2557.17
f(-7) = -1712.35
f(-6) = -1077.55
f(-5) = -622.76
f(-4) = -318.00
f(-3) = -133.27
f(-2) = -38.59
f(1) = 6.00
f(0) = 0.00
Submitted Solution:
```
from collections import deque
import math
numbers = deque()
for _ in range(11):
numbers.append(int(input()))
for _ in range(11):
num = numbers.pop()
a = math.sqrt(abs(num))
b = num**3 * 5
res = a + b
if res < 400:
print("f(%d) = %.2f" % (num, res))
else:
print("f(%d) = MAGNA NIMIS!" % num)
```
|
instruction
| 0
| 8,504
| 11
| 17,008
|
Yes
|
output
| 1
| 8,504
| 11
| 17,009
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
per nextum in unam tum XI conscribementis fac sic
vestibulo perlegementum da varo.
morde varo.
seqis cumula varum.
cis
per nextum in unam tum XI conscribementis fac sic
seqis decumulamenta da varo.
varum privamentum fodementum da aresulto.
varum tum III elevamentum tum V multiplicamentum da bresulto.
aresultum tum bresultum addementum da resulto.
si CD tum resultum non praestantiam fac sic
dictum sic f(%d) = %.2f cis tum varum tum resultum egresso describe.
novumversum egresso scribe.
cis
si CD tum resultum praestantiam fac sic
dictum sic f(%d) = MAGNA NIMIS! cis tum varum egresso describe.
novumversum egresso scribe.
cis
cis
Input
The input consists of several integers, one per line. Each integer is between -50 and 50, inclusive.
Output
As described in the problem statement.
Example
Input
0
1
-2
-3
-4
-5
-6
-7
-8
-9
10
Output
f(10) = MAGNA NIMIS!
f(-9) = -3642.00
f(-8) = -2557.17
f(-7) = -1712.35
f(-6) = -1077.55
f(-5) = -622.76
f(-4) = -318.00
f(-3) = -133.27
f(-2) = -38.59
f(1) = 6.00
f(0) = 0.00
Submitted Solution:
```
from math import sqrt
a = []
for i in range(11):
a.append(int(input()))
for x in a[::-1]:
a = sqrt(abs(x))
b = 5 * x**3
if a + b <= 400:
print("f(%d) = %.2f" % (x, a + b))
else:
print("f(%d) = MAGNA NIMIS!" % x)
```
|
instruction
| 0
| 8,505
| 11
| 17,010
|
Yes
|
output
| 1
| 8,505
| 11
| 17,011
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
per nextum in unam tum XI conscribementis fac sic
vestibulo perlegementum da varo.
morde varo.
seqis cumula varum.
cis
per nextum in unam tum XI conscribementis fac sic
seqis decumulamenta da varo.
varum privamentum fodementum da aresulto.
varum tum III elevamentum tum V multiplicamentum da bresulto.
aresultum tum bresultum addementum da resulto.
si CD tum resultum non praestantiam fac sic
dictum sic f(%d) = %.2f cis tum varum tum resultum egresso describe.
novumversum egresso scribe.
cis
si CD tum resultum praestantiam fac sic
dictum sic f(%d) = MAGNA NIMIS! cis tum varum egresso describe.
novumversum egresso scribe.
cis
cis
Input
The input consists of several integers, one per line. Each integer is between -50 and 50, inclusive.
Output
As described in the problem statement.
Example
Input
0
1
-2
-3
-4
-5
-6
-7
-8
-9
10
Output
f(10) = MAGNA NIMIS!
f(-9) = -3642.00
f(-8) = -2557.17
f(-7) = -1712.35
f(-6) = -1077.55
f(-5) = -622.76
f(-4) = -318.00
f(-3) = -133.27
f(-2) = -38.59
f(1) = 6.00
f(0) = 0.00
Submitted Solution:
```
def solve(x):
if x>4 or x<-20:
print('f('+str(x)+')','=','MAGNA NIMIS!')
return 0
if x<0:
A=round((5*x*x*x+((-x)**0.5))*100)
if A%100==0:
A='-'+str(-A//100)+'.00'
elif A%10==0:
A='-'+str(-A//100)+'.'+str((-A//10)%10)+'0'
else:
A='-'+str(-A//100)+'.'+str(-A%100)
print('f('+str(x)+')','=',A)
return 0
else:
A=round((5*x*x*x+(x**0.5))*100)
if 0 and A>=40000:
A='MAGNA NIMIS!'
elif A%100==0:
A=str(A//100)+'.00'
elif A%10==0:
A=str(A//100)+'.'+str((A//10)%10)+'0'
else:
A=str(A//100)+'.'+str(A%100)
print('f('+str(x)+')','=',A)
return 0
Q=[int(input()) for i in range(11)]
for i in range(10,-1,-1):
solve(Q[i])
```
|
instruction
| 0
| 8,506
| 11
| 17,012
|
No
|
output
| 1
| 8,506
| 11
| 17,013
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
per nextum in unam tum XI conscribementis fac sic
vestibulo perlegementum da varo.
morde varo.
seqis cumula varum.
cis
per nextum in unam tum XI conscribementis fac sic
seqis decumulamenta da varo.
varum privamentum fodementum da aresulto.
varum tum III elevamentum tum V multiplicamentum da bresulto.
aresultum tum bresultum addementum da resulto.
si CD tum resultum non praestantiam fac sic
dictum sic f(%d) = %.2f cis tum varum tum resultum egresso describe.
novumversum egresso scribe.
cis
si CD tum resultum praestantiam fac sic
dictum sic f(%d) = MAGNA NIMIS! cis tum varum egresso describe.
novumversum egresso scribe.
cis
cis
Input
The input consists of several integers, one per line. Each integer is between -50 and 50, inclusive.
Output
As described in the problem statement.
Example
Input
0
1
-2
-3
-4
-5
-6
-7
-8
-9
10
Output
f(10) = MAGNA NIMIS!
f(-9) = -3642.00
f(-8) = -2557.17
f(-7) = -1712.35
f(-6) = -1077.55
f(-5) = -622.76
f(-4) = -318.00
f(-3) = -133.27
f(-2) = -38.59
f(1) = 6.00
f(0) = 0.00
Submitted Solution:
```
n=input()
n=input()
n=input()
n=input()
n=input()
n=input()
n=input()
n=input()
n=input()
n=input()
n=input()
print("f(10) = MAGNA NIMIS!\nf(-9) = -3642.00\nf(-8) = -2557.17\nf(-7) = -1712.35\nf(-6) = -1077.55\nf(-5) = -622.76\nf(-4) = -318.00\nf(-3) = -133.27\nf(-2) = -38.59\nf(1) = 6.00\nf(0) = 0.00")
```
|
instruction
| 0
| 8,507
| 11
| 17,014
|
No
|
output
| 1
| 8,507
| 11
| 17,015
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
per nextum in unam tum XI conscribementis fac sic
vestibulo perlegementum da varo.
morde varo.
seqis cumula varum.
cis
per nextum in unam tum XI conscribementis fac sic
seqis decumulamenta da varo.
varum privamentum fodementum da aresulto.
varum tum III elevamentum tum V multiplicamentum da bresulto.
aresultum tum bresultum addementum da resulto.
si CD tum resultum non praestantiam fac sic
dictum sic f(%d) = %.2f cis tum varum tum resultum egresso describe.
novumversum egresso scribe.
cis
si CD tum resultum praestantiam fac sic
dictum sic f(%d) = MAGNA NIMIS! cis tum varum egresso describe.
novumversum egresso scribe.
cis
cis
Input
The input consists of several integers, one per line. Each integer is between -50 and 50, inclusive.
Output
As described in the problem statement.
Example
Input
0
1
-2
-3
-4
-5
-6
-7
-8
-9
10
Output
f(10) = MAGNA NIMIS!
f(-9) = -3642.00
f(-8) = -2557.17
f(-7) = -1712.35
f(-6) = -1077.55
f(-5) = -622.76
f(-4) = -318.00
f(-3) = -133.27
f(-2) = -38.59
f(1) = 6.00
f(0) = 0.00
Submitted Solution:
```
def solve(x):
if x<0:
A=round((5*x*x*x+((-x)**0.5))*100)
if A%100==0:
A='-'+str(-A//100)+'.00'
elif A%10==0:
A='-'+str(-A//100)+'.'+str((-A//10)%10)+'0'
else:
A='-'+str(-A//100)+'.'+str(-A%100)
print('f('+str(x)+')','=',A)
return 0
else:
A=(5*x*x*x+(x**0.5))*100
if A>=40000:
A='MAGNA NIMIS!'
print('f('+str(x)+')','=',A)
return 0
A=round(A)
if A%100==0:
A=str(-(-A//100))+'.00'
elif A%10==0:
A=str(-(-A//100))+'.'+str((-(-A//10))%10)+'0'
else:
A=str(-(-A//100))+'.'+str(A%100)
print('f('+str(x)+')','=',A)
return 0
Q=[int(input()) for i in range(11)]
for i in range(10,-1,-1):
solve(Q[i])
```
|
instruction
| 0
| 8,508
| 11
| 17,016
|
No
|
output
| 1
| 8,508
| 11
| 17,017
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
per nextum in unam tum XI conscribementis fac sic
vestibulo perlegementum da varo.
morde varo.
seqis cumula varum.
cis
per nextum in unam tum XI conscribementis fac sic
seqis decumulamenta da varo.
varum privamentum fodementum da aresulto.
varum tum III elevamentum tum V multiplicamentum da bresulto.
aresultum tum bresultum addementum da resulto.
si CD tum resultum non praestantiam fac sic
dictum sic f(%d) = %.2f cis tum varum tum resultum egresso describe.
novumversum egresso scribe.
cis
si CD tum resultum praestantiam fac sic
dictum sic f(%d) = MAGNA NIMIS! cis tum varum egresso describe.
novumversum egresso scribe.
cis
cis
Input
The input consists of several integers, one per line. Each integer is between -50 and 50, inclusive.
Output
As described in the problem statement.
Example
Input
0
1
-2
-3
-4
-5
-6
-7
-8
-9
10
Output
f(10) = MAGNA NIMIS!
f(-9) = -3642.00
f(-8) = -2557.17
f(-7) = -1712.35
f(-6) = -1077.55
f(-5) = -622.76
f(-4) = -318.00
f(-3) = -133.27
f(-2) = -38.59
f(1) = 6.00
f(0) = 0.00
Submitted Solution:
```
ls = list()
for i in range(11):
n = int(input())
ls.append(n)
for i in range(10,-1,-1):
a=ls[i]
aresult=(abs(a))**(1/2)
bresult=a**3*5
result=aresult+bresult
if result<=400:
s = format(result, '.2f')
print('f(' + str(i) + ') = ' + s)
else:
print('f(' + str(i) + ') = MAGNA NIMIS!')
```
|
instruction
| 0
| 8,509
| 11
| 17,018
|
No
|
output
| 1
| 8,509
| 11
| 17,019
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The popular improv website Interpretation Impetus hosts regular improv contests and maintains a rating of the best performers. However, since improv can often go horribly wrong, the website is notorious for declaring improv contests unrated. It now holds a wager before each improv contest where the participants try to predict whether it will be rated or unrated, and they are now more popular than the improv itself.
Izzy and n other participants take part in each wager. First, they each make their prediction, expressed as 1 ("rated") or 0 ("unrated"). Izzy always goes last, so she knows the predictions of the other participants when making her own. Then, the actual competition takes place and it is declared either rated or unrated.
You need to write a program that will interactively play as Izzy. There will be m wagers held in 2021, and Izzy's goal is to have at most 1.3⋅ b + 100 wrong predictions after all those wagers, where b is the smallest number of wrong predictions that any other wager participant will have after all those wagers.
The number b is not known in advance. Izzy also knows nothing about the other participants — they might somehow always guess correctly, or their predictions might be correlated. Izzy's predictions, though, do not affect the predictions of the other participants and the decision on the contest being rated or not — in other words, in each test case, your program always receives the same inputs, no matter what it outputs.
Interaction
First, a solution must read two integers n (1 ≤ n ≤ 1000) and m (1 ≤ m ≤ 10 000). Then, the solution must process m wagers. For each of them, the solution must first read a string consisting of n 0s and 1s, in which the i-th character denotes the guess of the i-th participant. Then, the solution must print Izzy's guess as 0 or 1. Don't forget to flush the output after printing it! Then, the solution must read the actual outcome, also as 0 or 1, and then proceed to the next wager, if this wasn't the last one.
Your solution will be considered correct if it makes at most 1.3⋅ b + 100 mistakes, where b is the smallest number of mistakes made by any other participant. Note that if a solution outputs anything except 0 or 1 for a wager, it will be considered incorrect even if it made no other mistakes.
There are 200 test cases in this problem.
Example
Input
3 4
000
1
100
1
001
0
111
1
Output
0
0
1
1
Note
In the example, the participants made 1, 2, and 3 mistakes respectively, therefore b=1 (the smallest of these numbers). Izzy made 3 mistakes, which were not more than 1.3⋅ b + 100=101.3, so these outputs are good enough to pass this test case (as are any other valid outputs).
Submitted Solution:
```
from sys import stdout
from typing import List
def get_guesses() -> List[int]:
inp = input()
return [-1 if x == '0' else 1 for x in inp]
def guess(answer: int) -> None:
print(answer)
stdout.flush()
def get_ans() -> int:
true_ans = int(input())
return true_ans
def solve():
n, m = list(map(int, (input().split(" "))))
lr = .05
weights = [1.0] * n
weights.append(0) # bias
for i in range(m):
g = get_guesses()
g.append(1)
weighted_sum = sum([weights[j] * g[j] for j in range(len(g))])
if weighted_sum > 0:
guess(1)
else:
guess(0)
ans = get_ans()
# Square error
gradient = [g[i] * (2 * weighted_sum - weights[i] * ans) for i in range(len(g))]
weights = [weights[i] - gradient[i] * lr for i in range(len(weights))]
solve()
```
|
instruction
| 0
| 8,587
| 11
| 17,174
|
No
|
output
| 1
| 8,587
| 11
| 17,175
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The popular improv website Interpretation Impetus hosts regular improv contests and maintains a rating of the best performers. However, since improv can often go horribly wrong, the website is notorious for declaring improv contests unrated. It now holds a wager before each improv contest where the participants try to predict whether it will be rated or unrated, and they are now more popular than the improv itself.
Izzy and n other participants take part in each wager. First, they each make their prediction, expressed as 1 ("rated") or 0 ("unrated"). Izzy always goes last, so she knows the predictions of the other participants when making her own. Then, the actual competition takes place and it is declared either rated or unrated.
You need to write a program that will interactively play as Izzy. There will be m wagers held in 2021, and Izzy's goal is to have at most 1.3⋅ b + 100 wrong predictions after all those wagers, where b is the smallest number of wrong predictions that any other wager participant will have after all those wagers.
The number b is not known in advance. Izzy also knows nothing about the other participants — they might somehow always guess correctly, or their predictions might be correlated. Izzy's predictions, though, do not affect the predictions of the other participants and the decision on the contest being rated or not — in other words, in each test case, your program always receives the same inputs, no matter what it outputs.
Interaction
First, a solution must read two integers n (1 ≤ n ≤ 1000) and m (1 ≤ m ≤ 10 000). Then, the solution must process m wagers. For each of them, the solution must first read a string consisting of n 0s and 1s, in which the i-th character denotes the guess of the i-th participant. Then, the solution must print Izzy's guess as 0 or 1. Don't forget to flush the output after printing it! Then, the solution must read the actual outcome, also as 0 or 1, and then proceed to the next wager, if this wasn't the last one.
Your solution will be considered correct if it makes at most 1.3⋅ b + 100 mistakes, where b is the smallest number of mistakes made by any other participant. Note that if a solution outputs anything except 0 or 1 for a wager, it will be considered incorrect even if it made no other mistakes.
There are 200 test cases in this problem.
Example
Input
3 4
000
1
100
1
001
0
111
1
Output
0
0
1
1
Note
In the example, the participants made 1, 2, and 3 mistakes respectively, therefore b=1 (the smallest of these numbers). Izzy made 3 mistakes, which were not more than 1.3⋅ b + 100=101.3, so these outputs are good enough to pass this test case (as are any other valid outputs).
Submitted Solution:
```
print("I love 2020-2021 ICPC, NERC, Northern Eurasia so much")
```
|
instruction
| 0
| 8,588
| 11
| 17,176
|
No
|
output
| 1
| 8,588
| 11
| 17,177
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The popular improv website Interpretation Impetus hosts regular improv contests and maintains a rating of the best performers. However, since improv can often go horribly wrong, the website is notorious for declaring improv contests unrated. It now holds a wager before each improv contest where the participants try to predict whether it will be rated or unrated, and they are now more popular than the improv itself.
Izzy and n other participants take part in each wager. First, they each make their prediction, expressed as 1 ("rated") or 0 ("unrated"). Izzy always goes last, so she knows the predictions of the other participants when making her own. Then, the actual competition takes place and it is declared either rated or unrated.
You need to write a program that will interactively play as Izzy. There will be m wagers held in 2021, and Izzy's goal is to have at most 1.3⋅ b + 100 wrong predictions after all those wagers, where b is the smallest number of wrong predictions that any other wager participant will have after all those wagers.
The number b is not known in advance. Izzy also knows nothing about the other participants — they might somehow always guess correctly, or their predictions might be correlated. Izzy's predictions, though, do not affect the predictions of the other participants and the decision on the contest being rated or not — in other words, in each test case, your program always receives the same inputs, no matter what it outputs.
Interaction
First, a solution must read two integers n (1 ≤ n ≤ 1000) and m (1 ≤ m ≤ 10 000). Then, the solution must process m wagers. For each of them, the solution must first read a string consisting of n 0s and 1s, in which the i-th character denotes the guess of the i-th participant. Then, the solution must print Izzy's guess as 0 or 1. Don't forget to flush the output after printing it! Then, the solution must read the actual outcome, also as 0 or 1, and then proceed to the next wager, if this wasn't the last one.
Your solution will be considered correct if it makes at most 1.3⋅ b + 100 mistakes, where b is the smallest number of mistakes made by any other participant. Note that if a solution outputs anything except 0 or 1 for a wager, it will be considered incorrect even if it made no other mistakes.
There are 200 test cases in this problem.
Example
Input
3 4
000
1
100
1
001
0
111
1
Output
0
0
1
1
Note
In the example, the participants made 1, 2, and 3 mistakes respectively, therefore b=1 (the smallest of these numbers). Izzy made 3 mistakes, which were not more than 1.3⋅ b + 100=101.3, so these outputs are good enough to pass this test case (as are any other valid outputs).
Submitted Solution:
```
from sys import stdout
from typing import List
def get_guesses() -> List[int]:
inp = input()
return [-1 if x == '0' else 1 for x in inp]
def guess(answer: int) -> None:
print(answer)
stdout.flush()
def get_ans() -> int:
true_ans = int(input())
return true_ans
def solve():
n, m = list(map(int, (input().split(" "))))
lr = .005
weights = [1.0] * n
weights.append(0) # bias
for i in range(m):
g = get_guesses()
g.append(1)
weighted_sum = sum([weights[j] * g[j] for j in range(len(g))])
if weighted_sum > 0:
guess(1)
else:
guess(0)
ans = get_ans()
# Square error
gradient = [g[i] * (2 * weighted_sum - weights[i] * ans) for i in range(len(g))]
weights = [weights[i] - gradient[i] * lr for i in range(len(weights))]
solve()
```
|
instruction
| 0
| 8,589
| 11
| 17,178
|
No
|
output
| 1
| 8,589
| 11
| 17,179
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The popular improv website Interpretation Impetus hosts regular improv contests and maintains a rating of the best performers. However, since improv can often go horribly wrong, the website is notorious for declaring improv contests unrated. It now holds a wager before each improv contest where the participants try to predict whether it will be rated or unrated, and they are now more popular than the improv itself.
Izzy and n other participants take part in each wager. First, they each make their prediction, expressed as 1 ("rated") or 0 ("unrated"). Izzy always goes last, so she knows the predictions of the other participants when making her own. Then, the actual competition takes place and it is declared either rated or unrated.
You need to write a program that will interactively play as Izzy. There will be m wagers held in 2021, and Izzy's goal is to have at most 1.3⋅ b + 100 wrong predictions after all those wagers, where b is the smallest number of wrong predictions that any other wager participant will have after all those wagers.
The number b is not known in advance. Izzy also knows nothing about the other participants — they might somehow always guess correctly, or their predictions might be correlated. Izzy's predictions, though, do not affect the predictions of the other participants and the decision on the contest being rated or not — in other words, in each test case, your program always receives the same inputs, no matter what it outputs.
Interaction
First, a solution must read two integers n (1 ≤ n ≤ 1000) and m (1 ≤ m ≤ 10 000). Then, the solution must process m wagers. For each of them, the solution must first read a string consisting of n 0s and 1s, in which the i-th character denotes the guess of the i-th participant. Then, the solution must print Izzy's guess as 0 or 1. Don't forget to flush the output after printing it! Then, the solution must read the actual outcome, also as 0 or 1, and then proceed to the next wager, if this wasn't the last one.
Your solution will be considered correct if it makes at most 1.3⋅ b + 100 mistakes, where b is the smallest number of mistakes made by any other participant. Note that if a solution outputs anything except 0 or 1 for a wager, it will be considered incorrect even if it made no other mistakes.
There are 200 test cases in this problem.
Example
Input
3 4
000
1
100
1
001
0
111
1
Output
0
0
1
1
Note
In the example, the participants made 1, 2, and 3 mistakes respectively, therefore b=1 (the smallest of these numbers). Izzy made 3 mistakes, which were not more than 1.3⋅ b + 100=101.3, so these outputs are good enough to pass this test case (as are any other valid outputs).
Submitted Solution:
```
n,m = map(int,input().split())
l=[0 for i in range(n)]
s=input()
print(1)
for f in range(m-1):
x=input()
for i in range(n):
if(s[i]!=x):
l[i]+=1
m=0
for i in range(1,n-1):
if(l[i]<l[m]):
m=i
s=input()
print(s[m])
x=input()
```
|
instruction
| 0
| 8,590
| 11
| 17,180
|
No
|
output
| 1
| 8,590
| 11
| 17,181
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Peter wrote on the board a strictly increasing sequence of positive integers a1, a2, ..., an. Then Vasil replaced some digits in the numbers of this sequence by question marks. Thus, each question mark corresponds to exactly one lost digit.
Restore the the original sequence knowing digits remaining on the board.
Input
The first line of the input contains integer n (1 ≤ n ≤ 105) — the length of the sequence. Next n lines contain one element of the sequence each. Each element consists only of digits and question marks. No element starts from digit 0. Each element has length from 1 to 8 characters, inclusive.
Output
If the answer exists, print in the first line "YES" (without the quotes). Next n lines must contain the sequence of positive integers — a possible variant of Peter's sequence. The found sequence must be strictly increasing, it must be transformed from the given one by replacing each question mark by a single digit. All numbers on the resulting sequence must be written without leading zeroes. If there are multiple solutions, print any of them.
If there is no answer, print a single line "NO" (without the quotes).
Examples
Input
3
?
18
1?
Output
YES
1
18
19
Input
2
??
?
Output
NO
Input
5
12224
12??5
12226
?0000
?00000
Output
YES
12224
12225
12226
20000
100000
Submitted Solution:
```
count = int(input())
nprev = 0
sprev = "0"
ans = list()
trouble = False
for num in range(count):
s = input()
incr = 0
if len(s) < len(sprev):
incr = 1
elif len(s) > len(sprev):
n = 0
for i in range(len(s)):
if s[i] == "?":
if i == 0:
n = 1
else:
n *= 10
else:
n *= 10
n += int(s[i])
else:
n = 0
nprev += 1
sprev = str(nprev)
k10 = 1
incr = 0
for i in range(len(s)-1, -1, -1):
if s[i] == "?":
if incr == 0:
n += int(sprev[i]) * k10
k10 *= 10
else:
if sprev[i] < '9':
n += (int(sprev[i]) + 1) * k10
k10 *= 10
incr = 0
else:
k10 *= 10
else:
if s[i] < sprev[i]:
incr = 1
n += int(s[i]) * k10
k10 *= 10
if incr == 1:
print("NO")
trouble = True
break
else:
ans.append(n)
nprev = n
sprev = str(n)
if not trouble:
print("YES")
for n in ans:
print(n)
```
|
instruction
| 0
| 8,660
| 11
| 17,320
|
No
|
output
| 1
| 8,660
| 11
| 17,321
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
|
instruction
| 0
| 8,726
| 11
| 17,452
|
Tags: brute force, greedy
Correct Solution:
```
n=int(input())
a=[list(map(int,input().split())) for i in range(n)]
solved=[0]*5
score=[0]*5
for i in range(n):
for j in range(5):
solved[j]+=int(a[i][j]>-1)
for k in range(31*n+1):
for i in range(5):
tot=n+k
cur=solved[i]
cur+=k*(a[0][i]>-1 and a[1][i]>-1 and a[0][i]>a[1][i])
score[i]=500
while score[i]<3000 and 2*cur<=tot:
cur*=2;
score[i]+=500
res=[0,0]
for j in range(2):
for i in range(5):
res[j]+=(a[j][i]>-1)*score[i]/250*(250-a[j][i])
if res[0]>res[1]:
print(k)
break
else:
print("-1")
```
|
output
| 1
| 8,726
| 11
| 17,453
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
|
instruction
| 0
| 8,727
| 11
| 17,454
|
Tags: brute force, greedy
Correct Solution:
```
n = int(input())
t = [0] * n
for i in range(n):
t[i] = list(map(int, input().split()))
value = [0] * 5
solve = [0] * 5
for i in range(5):
solved = 0
for j in range(n):
if t[j][i] != -1:
solved += 1
else:
t[j][i] = 250
if (solved * 2 > n):
value[i] = 500
elif (solved * 4 > n):
value[i] = 1000
elif (solved * 8 > n):
value[i] = 1500
elif (solved * 16 > n):
value[i] = 2000
elif (solved * 32 > n):
value[i] = 2500
else:
value[i] = 3000
solve[i] = solved
vasya = 0
for i in range(5):
vasya += value[i] - value[i] // 250 * t[0][i]
petya = 0
for i in range(5):
petya += value[i] - value[i] // 250 * t[1][i]
pot = [[0] * 20000 for i in range(5)]
for problem in range(5):
if t[0][problem] < t[1][problem]:
cur_ac = 0
while 1:
if solve[problem] * 32 <= n + cur_ac:
win = 3000 - 3000 // 250 * t[0][problem] - (3000 - 3000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 16 <= n + cur_ac:
win = 2500 - 2500 // 250 * t[0][problem] - (2500 - 2500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 8 <= n + cur_ac:
win = 2000 - 2000 // 250 * t[0][problem] - (2000 - 2000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 4 <= n + cur_ac:
win = 1500 - 1500 // 250 * t[0][problem] - (1500 - 1500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 2 <= n + cur_ac:
win = 1000 - 1000 // 250 * t[0][problem] - (1000 - 1000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
else:
win = 500 - 500 // 250 * t[0][problem] - (500 - 500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
cur_ac += 1
if cur_ac == 20000:
break
elif t[0][problem] != 250:
cur_ac = 0
while 1:
if solve[problem] * 32 + cur_ac <= n + cur_ac:
win = 3000 - 3000 // 250 * t[0][problem] - (3000 - 3000 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 16 + cur_ac <= n + cur_ac:
win = 2500 - 2500 // 250 * t[0][problem] - (2500 - 2500 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 8 + cur_ac <= n + cur_ac:
win = 2000 - 2000 // 250 * t[0][problem] - (2000 - 2000 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 4 + cur_ac <= n + cur_ac:
win = 1500 - 1500 // 250 * t[0][problem] - (1500 - 1500 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 2 + cur_ac <= n + cur_ac:
win = 1000 - 1000 // 250 * t[0][problem] - (1000 - 1000 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
else:
win = 500 - 500 // 250 * t[0][problem] - (500 - 500 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
cur_ac += 1
if cur_ac == 20000:
break
else:
cur_ac = 0
while 1:
if solve[problem] * 32 <= n + cur_ac:
win = -(3000 - 3000 // 250 * t[1][problem]) -(
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 16 <= n + cur_ac:
win = -(2500 - 2500 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 8 <= n + cur_ac:
win = -(2000 - 2000 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 4 <= n + cur_ac:
win = -(1500 - 1500 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 2 <= n + cur_ac:
win = -(1000 - 1000 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
else:
win = -(500 - 500 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
cur_ac += 1
if cur_ac == 20000:
break
res = -1
maxi = 0
for i in range(5):
maxi = max(maxi, len(pot[i]))
for i in range(maxi):
tmp = 0
for pr in range(5):
if len(pot[pr]) <= i:
tmp += pot[pr][-1]
else:
tmp += pot[pr][i]
if tmp > petya - vasya:
res = i
break
print(res)
```
|
output
| 1
| 8,727
| 11
| 17,455
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
|
instruction
| 0
| 8,728
| 11
| 17,456
|
Tags: brute force, greedy
Correct Solution:
```
def get_value(parters, solved):
if solved * 32 <= parters:
return 3000
if solved * 16 <= parters:
return 2500
if solved * 8 <= parters:
return 2000
if solved * 4 <= parters:
return 1500
if solved * 2 <= parters:
return 1000
return 500
def points(value, time):
return value - value // 500 * time
n = int(input())
t = [0] * n
for i in range(n):
t[i] = list(map(int, input().split()))
value = [0] * 5
solve = [0] * 5
for i in range(5):
solved = 0
for j in range(n):
if t[j][i] != -1:
solved += 1
else:
t[j][i] = 250
value[i] = get_value(n, solved)
solve[i] = solved
vasya = 0
for i in range(5):
vasya += points(value[i], t[0][i])
petya = 0
for i in range(5):
petya += points(value[i], t[1][i])
pot = [[0] * 20000 for i in range(5)]
for problem in range(5):
for cur_ac in range(20000):
new_value = 0
if t[0][problem] < t[1][problem]:
new_value = get_value(n + cur_ac, solve[problem])
elif t[0][problem] != 250:
new_value = get_value(n + cur_ac, solve[problem] + cur_ac)
else:
new_value = get_value(n + cur_ac, solve[problem])
win = points(new_value, t[0][problem]) - points(new_value, t[1][problem]) - points(value[problem], t[0][problem]) + points(value[problem], t[1][problem])
pot[problem][cur_ac] = win
res = -1
for i in range(20000):
tmp = 0
for pr in range(5):
if len(pot[pr]) <= i:
tmp += pot[pr][-1]
else:
tmp += pot[pr][i]
if tmp > petya - vasya:
res = i
break
print(res)
```
|
output
| 1
| 8,728
| 11
| 17,457
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
|
instruction
| 0
| 8,729
| 11
| 17,458
|
Tags: brute force, greedy
Correct Solution:
```
from sys import stdin, stdout
fractionBoundaries = [1/2,1/4,1/8,1/16,1/32,0]
scoreList = [500,1000,1500,2000,2500,3000]
def assessScores(n,Vsol,Psol,solvers):
vScore=0
pScore=0
for i in range(5):
for j in range(6):
if solvers[i]/n>fractionBoundaries[j]:
qnScore=scoreList[j]
break
if Vsol[i]>=0:
vScore+=qnScore-(qnScore*Vsol[i]//250)
if Psol[i]>=0:
pScore+=qnScore-(qnScore*Psol[i]//250)
return vScore>pScore
def main():
n = int(stdin.readline().rstrip())
Vsol = [int(x) for x in stdin.readline().rstrip().split()]
Psol = [int(x) for x in stdin.readline().rstrip().split()]
solvers = [0]*5
for _ in range(n-2):
a = [int(x) for x in stdin.readline().rstrip().split()]
for i in range(5):
if a[i]>=0:
solvers[i]+=1
for i in range(5):
if Vsol[i]>=0:
solvers[i]+=1
if Psol[i]>=0:
solvers[i]+=1
newSolvers=0
vWins=[]
pWins=[]
for i in range(5):
if (Vsol[i]<Psol[i] and Vsol[i]>=0) or (Vsol[i]>=0 and Psol[i]<0):
vWins.append(i)
elif (Psol[i]<Vsol[i] and Psol[i]>=0 and Vsol[i]>=0):
pWins.append(i)
if len(vWins)==0:
print(-1)
else:
while not assessScores(n+newSolvers,Vsol,Psol,solvers) and newSolvers<=100000007:
solversNeeded=9999999999999
for i in range(5):
if i in vWins:
currentRatio = solvers[i]/(newSolvers+n)
for j in range(6):
if solvers[i]/(newSolvers+n)>fractionBoundaries[j]:
nextBoundary = fractionBoundaries[j]
break
if nextBoundary!=0:
if solvers[i]%nextBoundary==0:
solversNeeded = min([solvers[i]//nextBoundary - (newSolvers+n),solversNeeded])
else:
solversNeeded = min([solvers[i]//nextBoundary - (newSolvers+n)+1,solversNeeded])
elif i in pWins and Vsol[i]>0:
currentRatio = solvers[i]/(newSolvers+n)
for j in range(6):
if solvers[i]/(newSolvers+n)>fractionBoundaries[j]:
if j>0:
nextBoundary = fractionBoundaries[j-1]
solversNeeded = min([(nextBoundary*(newSolvers+n)-solvers[i])//(1-nextBoundary)+1,solversNeeded])
break
newSolvers+=solversNeeded
for x in pWins:
solvers[x]+=solversNeeded
if newSolvers>1000000007:
print(-1)
else:
print(int(newSolvers))
main()
```
|
output
| 1
| 8,729
| 11
| 17,459
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
|
instruction
| 0
| 8,730
| 11
| 17,460
|
Tags: brute force, greedy
Correct Solution:
```
import sys
inf = 10**9 + 7
def solve():
n = int(sys.stdin.readline())
v = [int(vi) for vi in sys.stdin.readline().split()] # Vesya
p = [int(pi) for pi in sys.stdin.readline().split()] # Petya
cnt = [0]*5
for i in range(5):
if v[i] != -1:
cnt[i] += 1
if p[i] != -1:
cnt[i] += 1
for i in range(n - 2):
a = [int(ai) for ai in sys.stdin.readline().split()]
for j in range(5):
if a[j] != -1:
cnt[j] += 1
for i in range(4000):
if check(n, v, p, cnt, i):
print(i)
return
print(-1)
def check(n, v, p, cnt, m):
tot = n + m
solved = cnt[:]
dif = 0
for i in range(5):
if p[i] != -1 and v[i] > p[i]:
solved[i] += m
for i in range(5):
if solved[i]*2 > tot:
max_score = 500
elif solved[i]*4 > tot:
max_score = 1000
elif solved[i]*8 > tot:
max_score = 1500
elif solved[i]*16 > tot:
max_score = 2000
elif solved[i]*32 > tot:
max_score = 2500
else:
max_score = 3000
if v[i] == p[i] == -1:
pass
elif v[i] == -1:
dif -= max_score * (250 - p[i]) // 250
elif p[i] == -1:
dif += max_score * (250 - v[i]) // 250
else:
dif += max_score * (p[i] - v[i]) // 250
return dif > 0
if __name__ == '__main__':
solve()
```
|
output
| 1
| 8,730
| 11
| 17,461
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
|
instruction
| 0
| 8,731
| 11
| 17,462
|
Tags: brute force, greedy
Correct Solution:
```
import sys
inf = 10**9 + 7
def solve():
n = int(sys.stdin.readline())
v = [int(vi) for vi in sys.stdin.readline().split()] # Vesya
p = [int(pi) for pi in sys.stdin.readline().split()] # Petya
cnt = [0]*5
for i in range(5):
if v[i] != -1:
cnt[i] += 1
if p[i] != -1:
cnt[i] += 1
for i in range(n - 2):
a = [int(ai) for ai in sys.stdin.readline().split()]
for j in range(5):
if a[j] != -1:
cnt[j] += 1
for i in range(10**5):
if check(n, v, p, cnt, i):
print(i)
return
print(-1)
def check(n, v, p, cnt, m):
tot = n + m
solved = cnt[:]
dif = 0
for i in range(5):
if p[i] != -1 and v[i] > p[i]:
solved[i] += m
for i in range(5):
if solved[i]*2 > tot:
max_score = 500
elif solved[i]*4 > tot:
max_score = 1000
elif solved[i]*8 > tot:
max_score = 1500
elif solved[i]*16 > tot:
max_score = 2000
elif solved[i]*32 > tot:
max_score = 2500
else:
max_score = 3000
if v[i] == p[i] == -1:
pass
elif v[i] == -1:
dif -= max_score * (250 - p[i]) // 250
elif p[i] == -1:
dif += max_score * (250 - v[i]) // 250
else:
dif += max_score * (p[i] - v[i]) // 250
return dif > 0
if __name__ == '__main__':
solve()
```
|
output
| 1
| 8,731
| 11
| 17,463
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
|
instruction
| 0
| 8,732
| 11
| 17,464
|
Tags: brute force, greedy
Correct Solution:
```
import sys
inf = 10**9 + 7
def solve():
def check(mid):
tot = n + mid
dif = 0
solved = cnt[:]
for i in range(5):
if v[i] != -1 and p[i] != -1 and p[i] < v[i]:
solved[i] += mid
for i in range(5):
if solved[i]*2 > tot:
max_score = 500
elif solved[i]*4 > tot:
max_score = 1000
elif solved[i]*8 > tot:
max_score = 1500
elif solved[i]*16 > tot:
max_score = 2000
elif solved[i]*32 > tot:
max_score = 2500
else:
max_score = 3000
if v[i] == p[i]:
pass
elif v[i] == -1:
dif += max_score * (250 - p[i]) // 250
elif p[i] == -1:
dif += -max_score * (250 - v[i]) // 250
else:
dif += max_score * (-p[i] + v[i]) // 250
# print(mid, dif)
return dif < 0
n = int(sys.stdin.readline())
cnt = [0]*5
v = [int(i) for i in sys.stdin.readline().split()]
for i in range(5):
if v[i] != -1:
cnt[i] += 1
p = [int(i) for i in sys.stdin.readline().split()]
for i in range(5):
if p[i] != -1:
cnt[i] += 1
for i in range(n - 2):
a = [int(ai) for ai in sys.stdin.readline().split()]
for j in range(5):
if a[j] != -1:
cnt[j] += 1
for i in range(6000):
if check(i):
print(i)
return
print(-1)
if __name__ == '__main__':
solve()
```
|
output
| 1
| 8,732
| 11
| 17,465
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
|
instruction
| 0
| 8,733
| 11
| 17,466
|
Tags: brute force, greedy
Correct Solution:
```
n=int(input())
a=[list(map(int,input().split())) for i in range(n)]
solved=[0 for i in range(5)]
score=[0 for i in range(5)]
for i in range(n):
for j in range(5):
solved[j]+=int(a[i][j]>-1)
for k in range(31*n+1):
for i in range(5):
tot=n+k
cur=solved[i]
if a[0][i]>-1 and a[1][i]>-1 and a[0][i]>a[1][i]:
cur+=k
score[i]=500
while score[i]<3000 and 2*cur<=tot:
cur*=2;
score[i]+=500
res=[0,0]
for j in range(2):
for i in range(5):
if a[j][i]>-1:
res[j]+=score[i]/250*(250-a[j][i])
if res[0]>res[1]:
print(k)
exit()
print("-1")
```
|
output
| 1
| 8,733
| 11
| 17,467
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
Submitted Solution:
```
def f(v, x, n):
if v<0:
return 0
elif x<<1>n:
return int( 500*(1-v/250))
elif x<<2>n:
return int(1000*(1-v/250))
elif x<<3>n:
return int(1500*(1-v/250))
elif x<<4>n:
return int(2000*(1-v/250))
elif x<<5>n:
return int(2500*(1-v/250))
else:
return int(3000*(1-v/250))
n=int(input())
a=[list(map(int, input().split())) for _ in range(n)]
c=[sum(_[i]>=0 for _ in a) for i in range(5)]
ans=-1
for i in range(10000):
p, q=0, 0
for j in range(5):
x, y=c[j], n
if a[0][j]>a[1][j] and a[1][j]>=0:
x+=i
p+=f(a[0][j], x, n+i)
q+=f(a[1][j], x, n+i)
if p>q:
ans=i
break
print(ans)
# Made By Mostafa_Khaled
```
|
instruction
| 0
| 8,734
| 11
| 17,468
|
Yes
|
output
| 1
| 8,734
| 11
| 17,469
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
Submitted Solution:
```
n = int(input())
t = [0] * n
for i in range(n):
t[i] = list(map(int, input().split()))
value = [0] * 5
solve = [0] * 5
for i in range(5):
solved = 0
for j in range(n):
if t[j][i] != -1:
solved += 1
else:
t[j][i] = 250
if (solved * 2 > n):
value[i] = 500
elif (solved * 4 > n):
value[i] = 1000
elif (solved * 8 > n):
value[i] = 1500
elif (solved * 16 > n):
value[i] = 2000
elif (solved * 32 > n):
value[i] = 2500
else:
value[i] = 3000
solve[i] = solved
vasya = 0
for i in range(5):
vasya += value[i] - value[i] // 250 * t[0][i]
petya = 0
for i in range(5):
petya += value[i] - value[i] // 250 * t[1][i]
pot = [[0] * 20000 for i in range(5)]
for problem in range(5):
if t[0][problem] < t[1][problem]:
cur_ac = 0
while 1:
if solve[problem] * 32 <= n + cur_ac:
win = 3000 - 3000 // 250 * t[0][problem] - (3000 - 3000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 16 <= n + cur_ac:
win = 2500 - 2500 // 250 * t[0][problem] - (2500 - 2500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 8 <= n + cur_ac:
win = 2000 - 2000 // 250 * t[0][problem] - (2000 - 2000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 4 <= n + cur_ac:
win = 1500 - 1500 // 250 * t[0][problem] - (1500 - 1500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 2 <= n + cur_ac:
win = 1000 - 1000 // 250 * t[0][problem] - (1000 - 1000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
else:
win = 500 - 500 // 250 * t[0][problem] - (500 - 500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
cur_ac += 1
if cur_ac == 20000:
break
elif t[0][problem] != 250:
cur_ac = 0
while 1:
if solve[problem] * 32 + cur_ac <= n + cur_ac:
win = 3000 - 3000 // 250 * t[0][problem] - (3000 - 3000 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 16 + cur_ac <= n + cur_ac:
win = 2500 - 2500 // 250 * t[0][problem] - (2500 - 2500 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 8 + cur_ac <= n + cur_ac:
win = 2000 - 2000 // 250 * t[0][problem] - (2000 - 2000 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 4 + cur_ac <= n + cur_ac:
win = 1500 - 1500 // 250 * t[0][problem] - (1500 - 1500 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 2 + cur_ac <= n + cur_ac:
win = 1000 - 1000 // 250 * t[0][problem] - (1000 - 1000 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
else:
win = 500 - 500 // 250 * t[0][problem] - (500 - 500 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
cur_ac += 1
if cur_ac == 20000:
break
else:
cur_ac = 0
while 1:
if solve[problem] * 32 <= n + cur_ac:
win = -(3000 - 3000 // 250 * t[1][problem]) -(
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
break
elif solve[problem] * 16 <= n + cur_ac:
win = -(2500 - 2500 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 8 <= n + cur_ac:
win = -(2000 - 2000 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 4 <= n + cur_ac:
win = -(1500 - 1500 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 2 <= n + cur_ac:
win = -(1000 - 1000 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
else:
win = -(500 - 500 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
cur_ac += 1
if cur_ac == 20000:
break
res = -1
maxi = 0
for i in range(5):
maxi = max(maxi, len(pot[i]))
for i in range(maxi):
tmp = 0
for pr in range(5):
if len(pot[pr]) <= i:
tmp += pot[pr][-1]
else:
tmp += pot[pr][i]
if tmp > petya - vasya:
res = i
break
if n == 98:
print(solve)
print(res)
```
|
instruction
| 0
| 8,735
| 11
| 17,470
|
No
|
output
| 1
| 8,735
| 11
| 17,471
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
Submitted Solution:
```
n = int(input())
Mines =[[int(x) for x in input().split(' ')] for y in range(n)]
diff =[]
for i in range(n):
diff.append(abs( Mines[i][0] - Mines[i][1] ))
print(diff.index(max(diff))+1)
```
|
instruction
| 0
| 8,736
| 11
| 17,472
|
No
|
output
| 1
| 8,736
| 11
| 17,473
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
Submitted Solution:
```
n = int(input())
t = [0] * n
for i in range(n):
t[i] = list(map(int, input().split()))
value = [0] * 5
solve = [0] * 5
for i in range(5):
solved = 0
for j in range(n):
if t[j][i] != -1:
solved += 1
else:
t[j][i] = 250
if (solved * 2 > n):
value[i] = 500
elif (solved * 4 > n):
value[i] = 1000
elif (solved * 8 > n):
value[i] = 1500
elif (solved * 16 > n):
value[i] = 2000
elif (solved * 32 > n):
value[i] = 2500
else:
value[i] = 3000
solve[i] = solved
vasya = 0
for i in range(5):
vasya += value[i] - value[i] // 250 * t[0][i]
petya = 0
for i in range(5):
petya += value[i] - value[i] // 250 * t[1][i]
pot = [[0] * 20000 for i in range(5)]
for problem in range(5):
if t[0][problem] < t[1][problem]:
cur_ac = 0
while 1:
if solve[problem] * 32 <= n + cur_ac:
win = 3000 - 3000 // 250 * t[0][problem] - (3000 - 3000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 16 <= n + cur_ac:
win = 2500 - 2500 // 250 * t[0][problem] - (2500 - 2500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 8 <= n + cur_ac:
win = 2000 - 2000 // 250 * t[0][problem] - (2000 - 2000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 4 <= n + cur_ac:
win = 1500 - 1500 // 250 * t[0][problem] - (1500 - 1500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 2 <= n + cur_ac:
win = 1000 - 1000 // 250 * t[0][problem] - (1000 - 1000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
else:
win = 500 - 500 // 250 * t[0][problem] - (500 - 500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
cur_ac += 1
if cur_ac == 20000:
break
elif t[0][problem] != 250:
cur_ac = 0
while 1:
if solve[problem] * 32 + cur_ac <= n + cur_ac:
win = 3000 - 3000 // 250 * t[0][problem] - (3000 - 3000 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 16 + cur_ac <= n + cur_ac:
win = 2500 - 2500 // 250 * t[0][problem] - (2500 - 2500 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 8 + cur_ac <= n + cur_ac:
win = 2000 - 2000 // 250 * t[0][problem] - (2000 - 2000 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 4 + cur_ac <= n + cur_ac:
win = 1500 - 1500 // 250 * t[0][problem] - (1500 - 1500 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 2 + cur_ac <= n + cur_ac:
win = 1000 - 1000 // 250 * t[0][problem] - (1000 - 1000 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
else:
win = 500 - 500 // 250 * t[0][problem] - (500 - 500 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
cur_ac += 1
if cur_ac == 20000:
break
else:
cur_ac = 0
while 1:
if solve[problem] * 32 <= n + cur_ac:
win = -(3000 - 3000 // 250 * t[1][problem]) -(
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
break
elif solve[problem] * 16 <= n + cur_ac:
win = -(2500 - 2500 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 8 <= n + cur_ac:
win = -(2000 - 2000 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 4 <= n + cur_ac:
win = -(1500 - 1500 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 2 <= n + cur_ac:
win = -(1000 - 1000 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
else:
win = -(500 - 500 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
cur_ac += 1
if cur_ac == 20000:
break
res = -1
maxi = 0
for i in range(5):
maxi = max(maxi, len(pot[i]))
for i in range(maxi):
tmp = 0
for pr in range(5):
if len(pot[pr]) <= i:
tmp += pot[pr][-1]
else:
tmp += pot[pr][i]
if n == 97 and i == 3007:
print(tmp)
if tmp > petya - vasya:
res = i
break
if (n == 97):
print(vasya, petya, solve)
print(res)
```
|
instruction
| 0
| 8,737
| 11
| 17,474
|
No
|
output
| 1
| 8,737
| 11
| 17,475
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
Submitted Solution:
```
n = int(input())
t = [0] * n
for i in range(n):
t[i] = list(map(int, input().split()))
value = [0] * 5
solve = [0] * 5
for i in range(5):
solved = 0
for j in range(n):
if t[j][i] != -1:
solved += 1
else:
t[j][i] = 250
if (solved * 2 > n):
value[i] = 500
elif (solved * 4 > n):
value[i] = 1000
elif (solved * 8 > n):
value[i] = 1500
elif (solved * 16 > n):
value[i] = 2000
elif (solved * 32 > n):
value[i] = 2500
else:
value[i] = 3000
solve[i] = solved
vasya = 0
for i in range(5):
vasya += value[i] - value[i] // 250 * t[0][i]
petya = 0
for i in range(5):
petya += value[i] - value[i] // 250 * t[1][i]
pot = [[0] * 200000 for i in range(5)]
for problem in range(5):
if t[0][problem] < t[1][problem]:
cur_ac = 0
while 1:
if solve[problem] * 32 <= n + cur_ac:
win = 3000 - 3000 // 250 * t[0][problem] - (3000 - 3000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
break
elif solve[problem] * 16 <= n + cur_ac:
win = 2500 - 2500 // 250 * t[0][problem] - (2500 - 2500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 8 <= n + cur_ac:
win = 2000 - 2000 // 250 * t[0][problem] - (2000 - 2000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 4 <= n + cur_ac:
win = 1500 - 1500 // 250 * t[0][problem] - (1500 - 1500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 2 <= n + cur_ac:
win = 1000 - 1000 // 250 * t[0][problem] - (1000 - 1000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
else:
win = 500 - 500 // 250 * t[0][problem] - (500 - 500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
cur_ac += 1
elif t[0][problem] != 250:
cur_ac = 0
while 1:
if solve[problem] * 32 + cur_ac <= n + cur_ac:
win = 3000 - 3000 // 250 * t[0][problem] - (3000 - 3000 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 16 + cur_ac <= n + cur_ac:
win = 2500 - 2500 // 250 * t[0][problem] - (2500 - 2500 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 8 + cur_ac <= n + cur_ac:
win = 2000 - 2000 // 250 * t[0][problem] - (2000 - 2000 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 4 + cur_ac <= n + cur_ac:
win = 1500 - 1500 // 250 * t[0][problem] - (1500 - 1500 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 2 + cur_ac <= n + cur_ac:
win = 1000 - 1000 // 250 * t[0][problem] - (1000 - 1000 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
else:
win = 500 - 500 // 250 * t[0][problem] - (500 - 500 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
break
cur_ac += 1
else:
cur_ac = 0
while 1:
if solve[problem] * 32 <= n + cur_ac:
win = -(3000 - 3000 // 250 * t[1][problem]) -(
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
break
elif solve[problem] * 16 <= n + cur_ac:
win = -(2500 - 2500 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 8 <= n + cur_ac:
win = -(2000 - 2000 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 4 <= n + cur_ac:
win = -(1500 - 1500 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 2 <= n + cur_ac:
win = -(1000 - 1000 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
else:
win = -(500 - 500 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
cur_ac += 1
res = -1
maxi = 0
for i in range(5):
maxi = max(maxi, len(pot[i]))
for i in range(maxi):
tmp = 0
for pr in range(5):
if len(pot[pr]) <= i:
tmp += pot[pr][-1]
else:
tmp += pot[pr][i]
if tmp > petya - vasya:
res = i
break
print(res)
```
|
instruction
| 0
| 8,738
| 11
| 17,476
|
No
|
output
| 1
| 8,738
| 11
| 17,477
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.