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 BerSoft n programmers work, the programmer i is characterized by a skill r_i.
A programmer a can be a mentor of a programmer b if and only if the skill of the programmer a is strictly greater than the skill of the programmer b (r_a > r_b) and programmers a and b are not in a quarrel.
You are given the skills of each programmers and a list of k pairs of the programmers, which are in a quarrel (pairs are unordered). For each programmer i, find the number of programmers, for which the programmer i can be a mentor.
Input
The first line contains two integers n and k (2 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ k ≤ min(2 ⋅ 10^5, (n ⋅ (n - 1))/(2))) — total number of programmers and number of pairs of programmers which are in a quarrel.
The second line contains a sequence of integers r_1, r_2, ..., r_n (1 ≤ r_i ≤ 10^{9}), where r_i equals to the skill of the i-th programmer.
Each of the following k lines contains two distinct integers x, y (1 ≤ x, y ≤ n, x ≠ y) — pair of programmers in a quarrel. The pairs are unordered, it means that if x is in a quarrel with y then y is in a quarrel with x. Guaranteed, that for each pair (x, y) there are no other pairs (x, y) and (y, x) in the input.
Output
Print n integers, the i-th number should be equal to the number of programmers, for which the i-th programmer can be a mentor. Programmers are numbered in the same order that their skills are given in the input.
Examples
Input
4 2
10 4 10 15
1 2
4 3
Output
0 0 1 2
Input
10 4
5 4 1 5 4 3 7 1 2 5
4 6
2 1
10 8
3 5
Output
5 4 0 5 3 3 9 0 2 5
Note
In the first example, the first programmer can not be mentor of any other (because only the second programmer has a skill, lower than first programmer skill, but they are in a quarrel). The second programmer can not be mentor of any other programmer, because his skill is minimal among others. The third programmer can be a mentor of the second programmer. The fourth programmer can be a mentor of the first and of the second programmers. He can not be a mentor of the third programmer, because they are in a quarrel.
Submitted Solution:
```
from collections import deque
n, k = map(int, input().split())
r = list(map(int, input().split()))
rr = []
rr.append([0, 0])
for i in range(n):
rr.append([r[i], i + 1])
rr.sort()
G = [[] for _ in range(n + 1)]
for _ in range(k):
a, b = map(int, input().split())
G[a].append(b)
G[b].append(a)
ng = [0] * (n + 1)
cnt = -1
ans = [0] * n
q = deque()
for i in range(1, n + 1):
q.append(rr[i][1])
if not rr[i - 1][0] == rr[i][0]:
while q:
ng[q.popleft()] = 1
cnt += 1
ngcnt = 0
for j in G[rr[i][1]]:
if ng[j]:
ngcnt += 1
ans[rr[i][1] - 1] = cnt - ngcnt
print(*ans)
``` | instruction | 0 | 75,642 | 11 | 151,284 |
No | output | 1 | 75,642 | 11 | 151,285 |
Provide a correct Python 3 solution for this coding contest problem.
The Smart Beaver from ABBYY came up with another splendid problem for the ABBYY Cup participants! This time the Beaver invites the contest participants to check out a problem on sorting documents by their subjects. Let's describe the problem:
You've got some training set of documents. For each document you know its subject. The subject in this problem is an integer from 1 to 3. Each of these numbers has a physical meaning. For instance, all documents with subject 3 are about trade.
You can download the training set of documents at the following link: http://download4.abbyy.com/a2/X2RZ2ZWXBG5VYWAL61H76ZQM/train.zip. The archive contains three directories with names "1", "2", "3". Directory named "1" contains documents on the 1-st subject, directory "2" contains documents on the 2-nd subject, and directory "3" contains documents on the 3-rd subject. Each document corresponds to exactly one file from some directory.
All documents have the following format: the first line contains the document identifier, the second line contains the name of the document, all subsequent lines contain the text of the document. The document identifier is used to make installing the problem more convenient and has no useful information for the participants.
You need to write a program that should indicate the subject for a given document. It is guaranteed that all documents given as input to your program correspond to one of the three subjects of the training set.
Input
The first line contains integer id (0 ≤ id ≤ 106) — the document identifier. The second line contains the name of the document. The third and the subsequent lines contain the text of the document. It is guaranteed that the size of any given document will not exceed 10 kilobytes.
The tests for this problem are divided into 10 groups. Documents of groups 1 and 2 are taken from the training set, but their identifiers will not match the identifiers specified in the training set. Groups from the 3-rd to the 10-th are roughly sorted by the author in ascending order of difficulty (these groups contain documents which aren't present in the training set).
Output
Print an integer from 1 to 3, inclusive — the number of the subject the given document corresponds to.
Examples | instruction | 0 | 76,127 | 11 | 152,254 |
"Correct Solution:
```
print('2')
``` | output | 1 | 76,127 | 11 | 152,255 |
Provide a correct Python 3 solution for this coding contest problem.
The Smart Beaver from ABBYY came up with another splendid problem for the ABBYY Cup participants! This time the Beaver invites the contest participants to check out a problem on sorting documents by their subjects. Let's describe the problem:
You've got some training set of documents. For each document you know its subject. The subject in this problem is an integer from 1 to 3. Each of these numbers has a physical meaning. For instance, all documents with subject 3 are about trade.
You can download the training set of documents at the following link: http://download4.abbyy.com/a2/X2RZ2ZWXBG5VYWAL61H76ZQM/train.zip. The archive contains three directories with names "1", "2", "3". Directory named "1" contains documents on the 1-st subject, directory "2" contains documents on the 2-nd subject, and directory "3" contains documents on the 3-rd subject. Each document corresponds to exactly one file from some directory.
All documents have the following format: the first line contains the document identifier, the second line contains the name of the document, all subsequent lines contain the text of the document. The document identifier is used to make installing the problem more convenient and has no useful information for the participants.
You need to write a program that should indicate the subject for a given document. It is guaranteed that all documents given as input to your program correspond to one of the three subjects of the training set.
Input
The first line contains integer id (0 ≤ id ≤ 106) — the document identifier. The second line contains the name of the document. The third and the subsequent lines contain the text of the document. It is guaranteed that the size of any given document will not exceed 10 kilobytes.
The tests for this problem are divided into 10 groups. Documents of groups 1 and 2 are taken from the training set, but their identifiers will not match the identifiers specified in the training set. Groups from the 3-rd to the 10-th are roughly sorted by the author in ascending order of difficulty (these groups contain documents which aren't present in the training set).
Output
Print an integer from 1 to 3, inclusive — the number of the subject the given document corresponds to.
Examples | instruction | 0 | 76,128 | 11 | 152,256 |
"Correct Solution:
```
print('1')
``` | output | 1 | 76,128 | 11 | 152,257 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y.
Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Each of the next t lines contains four integers x, y, p and q (0 ≤ x ≤ y ≤ 109; 0 ≤ p ≤ q ≤ 109; y > 0; q > 0).
It is guaranteed that p / q is an irreducible fraction.
Hacks. For hacks, an additional constraint of t ≤ 5 must be met.
Output
For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve.
Example
Input
4
3 10 1 2
7 14 3 8
20 70 2 7
5 6 1 1
Output
4
10
0
-1
Note
In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2.
In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8.
In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7.
In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1. | instruction | 0 | 76,364 | 11 | 152,728 |
Tags: binary search, math
Correct Solution:
```
def gcd(a, b):
if a == 0:
return [b, 0, 1]
d, x1, y1 = gcd (b % a, a)
return [d, y1 - (b // a) * x1, x1]
def find_any_solution(a, b, c):
g, x0, y0 = gcd(abs(a), abs(b))
if c % g != 0:
return [False, 0, 0, 0]
x0 *= c // g
y0 *= c // g
if a < 0:
x0 *= -1
if b < 0:
y0 *= -1
return [True, x0, y0, g]
def main():
x, y, p, q = [int(i) for i in input().split()]
if p == 0 and x != 0:
print(-1)
return 0
ok = find_any_solution(q, -p, p * y - x * q);
if not ok[0]:
print(-1)
return;
#print(ok)
a = ok[1]
b = ok[2]
g = ok[3]
ag = q // g
bg = (-p) // g;
#print(a, b, ag, bg)
if ag == -1 * bg and a > b:
print(-1)
return 0
l, r = -10 ** 18, 10 ** 18
while r - l > 1:
m = (l + r) // 2;
if a + m * bg >= 0:
l = m
else:
r = m
maxk = l
l, r = -10 ** 18, 10 ** 18
while r - l > 1:
m = (l + r) // 2;
if b - m * ag >= 0:
l = m
else:
r = m
maxk = min(maxk, l)
l, r = -10 ** 18, 10 ** 18
while r - l > 1:
m = (l + r) // 2
if a + m * bg <= b - m * ag:
l = m
else:
r = m
if ag != bg * -1:
maxk = min(l, maxk)
if b - maxk * ag + y == 0:
--maxk
if b - maxk * ag + y == 0:
print(-1)
return;
#print(maxk)
print(b - maxk * ag)
t = int(input())
for i in range(t):
main()
``` | output | 1 | 76,364 | 11 | 152,729 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y.
Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Each of the next t lines contains four integers x, y, p and q (0 ≤ x ≤ y ≤ 109; 0 ≤ p ≤ q ≤ 109; y > 0; q > 0).
It is guaranteed that p / q is an irreducible fraction.
Hacks. For hacks, an additional constraint of t ≤ 5 must be met.
Output
For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve.
Example
Input
4
3 10 1 2
7 14 3 8
20 70 2 7
5 6 1 1
Output
4
10
0
-1
Note
In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2.
In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8.
In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7.
In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1. | instruction | 0 | 76,365 | 11 | 152,730 |
Tags: binary search, math
Correct Solution:
```
t = int(input())
for _ in range(t):
x, y, p, q = map(int, input().split())
if p == q:
print(0 if x == y else -1)
elif p == 0:
print(0 if x == 0 else -1)
elif x * q == y * p:
print(0)
else:
l = 0
r = 2**64
cnt = 0
while l + 1 < r:
cnt += 1
c = (l + r) // 2
if x <= c * p <= x + c * q - y:
r = c
else:
l = c
print(r * q - y)
``` | output | 1 | 76,365 | 11 | 152,731 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y.
Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Each of the next t lines contains four integers x, y, p and q (0 ≤ x ≤ y ≤ 109; 0 ≤ p ≤ q ≤ 109; y > 0; q > 0).
It is guaranteed that p / q is an irreducible fraction.
Hacks. For hacks, an additional constraint of t ≤ 5 must be met.
Output
For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve.
Example
Input
4
3 10 1 2
7 14 3 8
20 70 2 7
5 6 1 1
Output
4
10
0
-1
Note
In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2.
In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8.
In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7.
In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1. | instruction | 0 | 76,366 | 11 | 152,732 |
Tags: binary search, math
Correct Solution:
```
#https://codeforces.com/problemset/problem/773/A
t = int(input())
for i in range(t):
x, y, p, q = map(int, input().split())
left = -1
right = 10**9
r = right
while left + 1 < right:
t = (left + right) // 2
if p*t >= x and q*t - p*t >= y - x:
right = t
else:
left = t
if not (p*r >= x and q*r - p*r >= y - x):
print(-1)
else:
print(q*right - y)
``` | output | 1 | 76,366 | 11 | 152,733 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y.
Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Each of the next t lines contains four integers x, y, p and q (0 ≤ x ≤ y ≤ 109; 0 ≤ p ≤ q ≤ 109; y > 0; q > 0).
It is guaranteed that p / q is an irreducible fraction.
Hacks. For hacks, an additional constraint of t ≤ 5 must be met.
Output
For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve.
Example
Input
4
3 10 1 2
7 14 3 8
20 70 2 7
5 6 1 1
Output
4
10
0
-1
Note
In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2.
In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8.
In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7.
In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1. | instruction | 0 | 76,367 | 11 | 152,734 |
Tags: binary search, math
Correct Solution:
```
import math
for _ in range(int(input())):
x, y, p, q = map(int, input().split())
if(q == p):
if(x == y):
print(0)
else:
print(-1)
continue
if(p == 0):
if(x ==0 ):
print(0)
else:
print(-1)
continue
t = int(math.ceil(max((y-x)/(q-p), x/p)))
print (q*t-y)
``` | output | 1 | 76,367 | 11 | 152,735 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y.
Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Each of the next t lines contains four integers x, y, p and q (0 ≤ x ≤ y ≤ 109; 0 ≤ p ≤ q ≤ 109; y > 0; q > 0).
It is guaranteed that p / q is an irreducible fraction.
Hacks. For hacks, an additional constraint of t ≤ 5 must be met.
Output
For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve.
Example
Input
4
3 10 1 2
7 14 3 8
20 70 2 7
5 6 1 1
Output
4
10
0
-1
Note
In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2.
In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8.
In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7.
In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1. | instruction | 0 | 76,368 | 11 | 152,736 |
Tags: binary search, math
Correct Solution:
```
import math
def main():
T = int(input())
for t in range(T):
solve()
def solve():
x, y, p, q = map(int, input().split())
if p == 1 and q == 1:
if x == y:
print(0)
else:
print(-1)
return
if p == 0 and q == 1:
if x == 0:
print(0)
else:
print(-1)
return
# n = max(math.ceil(y/q), math.ceil(x/p))
# while (n*q - y) < (n*p -x):
# n += 1
n = max(math.ceil(y/q), math.ceil(x/p), math.ceil((y-x)/(q-p)))
print(n*q-y)
if __name__ == "__main__":
# global stime
# stime = time.clock()
main()
``` | output | 1 | 76,368 | 11 | 152,737 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y.
Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Each of the next t lines contains four integers x, y, p and q (0 ≤ x ≤ y ≤ 109; 0 ≤ p ≤ q ≤ 109; y > 0; q > 0).
It is guaranteed that p / q is an irreducible fraction.
Hacks. For hacks, an additional constraint of t ≤ 5 must be met.
Output
For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve.
Example
Input
4
3 10 1 2
7 14 3 8
20 70 2 7
5 6 1 1
Output
4
10
0
-1
Note
In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2.
In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8.
In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7.
In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1. | instruction | 0 | 76,369 | 11 | 152,738 |
Tags: binary search, math
Correct Solution:
```
import math as mt
import sys,string,bisect
input=sys.stdin.readline
import random
from collections import deque,defaultdict
L=lambda : list(map(int,input().split()))
Ls=lambda : list(input().split())
M=lambda : map(int,input().split())
I=lambda :int(input())
d=defaultdict(int)
def extended_gcd(a,b):
if(a==0):
return(0,1)
x,y=extended_gcd(b%a,a)
return (y-(b//a)*x,x)
def check(x,y,p,q):
if(p>=x and (y-x)+p<=q):
return True
return False
t=I()
for _ in range(t):
x,y,p,q=M()
if(p==0 and x!=0):
print(-1)
else:
g=mt.gcd(x,y)
if(x//g==p and y//g==q):
print(0)
elif(p==q):
print(-1)
else:
l=0
r=1
while(not(check(x,y,p*r,q*r))):
l=r
r*=10
#print("p",l,r)
d=0
while(l<=r):
m=(l+r)//2
if(check(x,y,p*m,q*m)):
d=m
r=m-1
else:
l=m+1
if((q*d-y)<0):
print(-1)
else:
print(q*d-y)
``` | output | 1 | 76,369 | 11 | 152,739 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y.
Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Each of the next t lines contains four integers x, y, p and q (0 ≤ x ≤ y ≤ 109; 0 ≤ p ≤ q ≤ 109; y > 0; q > 0).
It is guaranteed that p / q is an irreducible fraction.
Hacks. For hacks, an additional constraint of t ≤ 5 must be met.
Output
For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve.
Example
Input
4
3 10 1 2
7 14 3 8
20 70 2 7
5 6 1 1
Output
4
10
0
-1
Note
In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2.
In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8.
In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7.
In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1. | instruction | 0 | 76,370 | 11 | 152,740 |
Tags: binary search, math
Correct Solution:
```
def check(np, nq):
return np >= x and nq >= y and (np - x <= nq - y)
t = int(input())
for i in range (t):
x, y, p, q = map(int, input().split())
l = 0
r = 10 ** 18 #pashm
while l < r - 1:
m = (l + r) // 2
if check(p * m, q * m):
r = m
else:
l = m
if r == 10 ** 18:
print (-1)
else:
ans = q * r - y
print(ans)
``` | output | 1 | 76,370 | 11 | 152,741 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y.
Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Each of the next t lines contains four integers x, y, p and q (0 ≤ x ≤ y ≤ 109; 0 ≤ p ≤ q ≤ 109; y > 0; q > 0).
It is guaranteed that p / q is an irreducible fraction.
Hacks. For hacks, an additional constraint of t ≤ 5 must be met.
Output
For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve.
Example
Input
4
3 10 1 2
7 14 3 8
20 70 2 7
5 6 1 1
Output
4
10
0
-1
Note
In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2.
In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8.
In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7.
In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1. | instruction | 0 | 76,371 | 11 | 152,742 |
Tags: binary search, math
Correct Solution:
```
def gcd(a,b):
while a != 0 and b != 0:
if a > b:
a = a % b
else:
b = b % a
return a + b
def check(x,y,p,q,m):
num = p * m
den = q * m
return (num - x >= 0) and ((den - y - (num - x)) >= 0)
def count(x,y,p,q,m):
num = p * m
den = q * m
return num - x + (den - y - (num - x))
def search(x,y,p,q):
l,r = -1, 10 ** 9 + 1
while r - l > 1:
m = (l + r) // 2
if check(x,y,p,q,m):
r = m
else:
l = m
if r == 10 ** 9 + 1:
print(-1)
else:
print(count(x,y,p,q,r))
n = int(input())
for i in range(n):
x,y,p,q = map(int, input().split())
search(x,y,p,q)
``` | output | 1 | 76,371 | 11 | 152,743 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y.
Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Each of the next t lines contains four integers x, y, p and q (0 ≤ x ≤ y ≤ 109; 0 ≤ p ≤ q ≤ 109; y > 0; q > 0).
It is guaranteed that p / q is an irreducible fraction.
Hacks. For hacks, an additional constraint of t ≤ 5 must be met.
Output
For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve.
Example
Input
4
3 10 1 2
7 14 3 8
20 70 2 7
5 6 1 1
Output
4
10
0
-1
Note
In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2.
In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8.
In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7.
In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
Submitted Solution:
```
def gcd(a, b):
if a == 0:
return [b, 0, 1]
d = gcd(b % a, a)
return [d[0], d[2] - (b // a) * d[1], d[1]]
t = int(input())
while t > 0:
t -= 1
x, y, p, q = map(int, input().split())
if p == q:
if x == y:
print(0)
else:
print(-1)
continue
if p == 0:
if x == 0:
print(0)
else:
print(-1)
continue
a = p - q
b = p
c = q * x - p * y
g, xa, ya = gcd(abs(a), abs(b))
if c % g != 0:
print(-1)
else:
xa *= c // g
ya *= c // g
if a < 0:
xa = -xa
if b < 0:
ya = -ya
if xa < 0:
gaps = (-xa + (b // g) - 1) // (b // g)
xa += gaps * (b // g)
ya -= gaps * (a // g)
if ya < 0:
gaps = (-ya + (-a // g) - 1) // (-a // g)
xa += gaps * (b // g)
ya -= gaps * (a // g)
#print(xa, ya, a, b, c)
if xa < 0 or ya < 0:
print(-1)
else:
addon = min(xa // (b // g), ya // (-a // g))
xa -= addon * (b // g)
ya += addon * (a // g)
print(xa + ya)
``` | instruction | 0 | 76,372 | 11 | 152,744 |
Yes | output | 1 | 76,372 | 11 | 152,745 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y.
Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Each of the next t lines contains four integers x, y, p and q (0 ≤ x ≤ y ≤ 109; 0 ≤ p ≤ q ≤ 109; y > 0; q > 0).
It is guaranteed that p / q is an irreducible fraction.
Hacks. For hacks, an additional constraint of t ≤ 5 must be met.
Output
For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve.
Example
Input
4
3 10 1 2
7 14 3 8
20 70 2 7
5 6 1 1
Output
4
10
0
-1
Note
In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2.
In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8.
In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7.
In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
Submitted Solution:
```
# cook your code here
def solve():
x, y, p, q = map(int, input().split())
if p == 0:
if x == 0:
print(0)
return
else:
print(-1)
return
if p == q:
if x == y:
print(0)
return
else:
print(-1)
return
var1 = ( p + x - 1 ) // p;
var2 = ((y - x) + (q - p) - 1) // (q - p);
max1 = max(var1, var2);
solution = (max1 * q) - y;
print(solution)
return
def main():
n = int(input())
for i in range (n):
solve()
main()
``` | instruction | 0 | 76,373 | 11 | 152,746 |
Yes | output | 1 | 76,373 | 11 | 152,747 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y.
Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Each of the next t lines contains four integers x, y, p and q (0 ≤ x ≤ y ≤ 109; 0 ≤ p ≤ q ≤ 109; y > 0; q > 0).
It is guaranteed that p / q is an irreducible fraction.
Hacks. For hacks, an additional constraint of t ≤ 5 must be met.
Output
For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve.
Example
Input
4
3 10 1 2
7 14 3 8
20 70 2 7
5 6 1 1
Output
4
10
0
-1
Note
In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2.
In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8.
In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7.
In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
Submitted Solution:
```
def ext_gcd(a, b):
if a == 0:
return b, 0, 1
else:
g, x, y = ext_gcd(b % a, a)
return g, y - (b // a) * x, x
def multinv(b, n):
g, x, trash = ext_gcd(b, n)
return x % n
def solve():
x, y, p, q = map(int, input().split(' '))
if p == q:
if x == y:
return 0
else:
return -1
if p == 0:
if x == 0:
return 0
else:
return -1
c = p * y - q * x
a = (multinv(q, p) * c ) % p
if ((q*a)-c)//p < a:
dif = (c//(q-p) - a)
dif = dif//p
a += p * (dif-3)
while ((q*a)-c)//p < a or a < 0:
a += p
return ((q*a)-c)//p
t = int(input())
for a0 in range(t):
print(solve())
``` | instruction | 0 | 76,374 | 11 | 152,748 |
Yes | output | 1 | 76,374 | 11 | 152,749 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y.
Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Each of the next t lines contains four integers x, y, p and q (0 ≤ x ≤ y ≤ 109; 0 ≤ p ≤ q ≤ 109; y > 0; q > 0).
It is guaranteed that p / q is an irreducible fraction.
Hacks. For hacks, an additional constraint of t ≤ 5 must be met.
Output
For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve.
Example
Input
4
3 10 1 2
7 14 3 8
20 70 2 7
5 6 1 1
Output
4
10
0
-1
Note
In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2.
In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8.
In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7.
In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
Submitted Solution:
```
def Ans(k):
x, y, p, q = k[0], k[1], k[2], k[3]
if (p/q == 1 and x != y) or (p == 0 and x!= 0):
print(-1)
elif p == 0 and x == 0:
print(0)
else:
up = 10**9
down = 1
dy = y-x
while (up > down + 1):
mid = (up+down)//2
## print(" up: " + str(up) + " mid: " + str(mid) + " down: " + str(down) )
qf = q*mid
pf = p*mid
dq = qf-pf
if( qf-y >= dq-dy and qf >= y and dq >= dy):
up = mid
else:
down = mid
if( q*down-y >= (q-p)*down-dy and q*down >= y and (q-p)*down >= dy):
print(q*down - y)
elif q*mid-y >= (q-p)*mid-dy and q*mid >= y and (q-p)*mid>=dy:
print(q*mid - y)
else:
print(q*up - y)
t = int( input() )
k = [0]*t
for i in range(t):
k[i] = list(map(int, input().split() ))
for i in range(t):
Ans(k[i])
``` | instruction | 0 | 76,375 | 11 | 152,750 |
Yes | output | 1 | 76,375 | 11 | 152,751 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y.
Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Each of the next t lines contains four integers x, y, p and q (0 ≤ x ≤ y ≤ 109; 0 ≤ p ≤ q ≤ 109; y > 0; q > 0).
It is guaranteed that p / q is an irreducible fraction.
Hacks. For hacks, an additional constraint of t ≤ 5 must be met.
Output
For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve.
Example
Input
4
3 10 1 2
7 14 3 8
20 70 2 7
5 6 1 1
Output
4
10
0
-1
Note
In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2.
In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8.
In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7.
In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
Submitted Solution:
```
import math
r = int(input())
for i in range(r):
x, y, p, q = list(map(int, input().split()))
if y % q == 0:
op = p * (y // q); oq = y
else:
op = p * (y // q + 1); oq = q * (y // q + 1)
for plus in range(100000):
if (oq - y >= op - x) and op - x >= 0:
print(oq - y)
break
else:
op += p; oq += q
if p == 1 and q == 1:
print(-1)
break
else:
print(-1)
``` | instruction | 0 | 76,376 | 11 | 152,752 |
No | output | 1 | 76,376 | 11 | 152,753 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y.
Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Each of the next t lines contains four integers x, y, p and q (0 ≤ x ≤ y ≤ 109; 0 ≤ p ≤ q ≤ 109; y > 0; q > 0).
It is guaranteed that p / q is an irreducible fraction.
Hacks. For hacks, an additional constraint of t ≤ 5 must be met.
Output
For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve.
Example
Input
4
3 10 1 2
7 14 3 8
20 70 2 7
5 6 1 1
Output
4
10
0
-1
Note
In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2.
In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8.
In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7.
In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
Submitted Solution:
```
import sys
sys.setrecursionlimit(1000000)
def xgcd(a,b):
if b==0:
return (1,0,abs(a))
x,y,g=xgcd(b,a%b)
return (y,x-(a//b)*y,g);
def ff(x,y,g,a,b,lbx,lby):
t=0
if b>=0:
t=(lbx-x)*g//b + int((lbx-x)*g%b!=0)
else:
t=(lbx-x)*g//b
x+=t*b//g
y-=t*a//g
x1=x;y1=y
t=0
if a>=0:
t=(lby-y)*g//a + int((lby-y)*g%a!=0)
else:
t=(lby-y)*g//a
x-=t*b//g
y+=t*a//g
x2=x;y2=y
#if x<lbx or y<lby:
# raise Exception;
if x1<lbx or y1<lbx:
return (x2,y2)
if x2<lbx or y2<lbx:
return (x1,y1)
return (x1,y1) if x1+y1<x2+y2 else (x2,y2)
t=int(input())
for _ in range(t):
try:
x,y,p,q=map(int,input().split())
a,b,g=xgcd(p-q, p)
if (q*x-p*y)%g:
print(-1)
continue
a*=(q*x-p*y)//g;
b*=(q*x-p*y)//g;
a,b=ff(a,b,g,p-q,p,0,0)
if a<0 or b<0:
print(-1)
else:
print(a+b)
except:
print(-1)
``` | instruction | 0 | 76,377 | 11 | 152,754 |
No | output | 1 | 76,377 | 11 | 152,755 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y.
Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Each of the next t lines contains four integers x, y, p and q (0 ≤ x ≤ y ≤ 109; 0 ≤ p ≤ q ≤ 109; y > 0; q > 0).
It is guaranteed that p / q is an irreducible fraction.
Hacks. For hacks, an additional constraint of t ≤ 5 must be met.
Output
For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve.
Example
Input
4
3 10 1 2
7 14 3 8
20 70 2 7
5 6 1 1
Output
4
10
0
-1
Note
In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2.
In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8.
In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7.
In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
Submitted Solution:
```
from sys import stdin, stdout
from math import ceil
def GCD(a, b):
if not b:
return a
else:
return GCD(b, a % b)
t = int(stdin.readline())
for i in range(t):
x, y, p, q = map(int, stdin.readline().split())
if (p / q == x / y):
stdout.write('0\n')
continue
l = -1
r = 10 ** 50
while (r - l > 1):
m = (r + l) // 2
def check(m):
if p * m >= x:
a = p * m - x
b = q * m - y - a
if b < 0:
a = 0
else:
a += b
return a
else:
return 0
if check(m):
r = m
else:
l = m
ans = check(r)
if (not ans):
stdout.write('-1')
else:
stdout.write(str(ans) + '\n')
``` | instruction | 0 | 76,378 | 11 | 152,756 |
No | output | 1 | 76,378 | 11 | 152,757 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y.
Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Each of the next t lines contains four integers x, y, p and q (0 ≤ x ≤ y ≤ 109; 0 ≤ p ≤ q ≤ 109; y > 0; q > 0).
It is guaranteed that p / q is an irreducible fraction.
Hacks. For hacks, an additional constraint of t ≤ 5 must be met.
Output
For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve.
Example
Input
4
3 10 1 2
7 14 3 8
20 70 2 7
5 6 1 1
Output
4
10
0
-1
Note
In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2.
In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8.
In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7.
In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
Submitted Solution:
```
import math
import sys
t=int(input())
for j in range(1,(t+1)):
x,y,p,q=(map(int,input().split()))
if(x/y==p/q):
print(0)
else:
f1=0
for i in range(1,2001):
tp=p*i
tq=q*i
if(tp>=x and tq>=y):
if(tp-x<=tq-y):
print(tq-y)
f1=1
break
if(not f1):
print(-1)
``` | instruction | 0 | 76,379 | 11 | 152,758 |
No | output | 1 | 76,379 | 11 | 152,759 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You will turn on the air conditioner if, and only if, the temperature of the room is 30 degrees Celsius or above.
The current temperature of the room is X degrees Celsius. Will you turn on the air conditioner?
Constraints
* -40 \leq X \leq 40
* X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
Print `Yes` if you will turn on the air conditioner; print `No` otherwise.
Examples
Input
25
Output
No
Input
30
Output
Yes
Submitted Solution:
```
X = int(input())
if X>=30:
print("Yes")
else:
print('No')
``` | instruction | 0 | 76,465 | 11 | 152,930 |
Yes | output | 1 | 76,465 | 11 | 152,931 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You will turn on the air conditioner if, and only if, the temperature of the room is 30 degrees Celsius or above.
The current temperature of the room is X degrees Celsius. Will you turn on the air conditioner?
Constraints
* -40 \leq X \leq 40
* X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
Print `Yes` if you will turn on the air conditioner; print `No` otherwise.
Examples
Input
25
Output
No
Input
30
Output
Yes
Submitted Solution:
```
X=int(input())
print(X>=30 and 'Yes' or 'No')
``` | instruction | 0 | 76,466 | 11 | 152,932 |
Yes | output | 1 | 76,466 | 11 | 152,933 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You will turn on the air conditioner if, and only if, the temperature of the room is 30 degrees Celsius or above.
The current temperature of the room is X degrees Celsius. Will you turn on the air conditioner?
Constraints
* -40 \leq X \leq 40
* X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
Print `Yes` if you will turn on the air conditioner; print `No` otherwise.
Examples
Input
25
Output
No
Input
30
Output
Yes
Submitted Solution:
```
print("Yes" if int(input()) >= 30 else "No")
``` | instruction | 0 | 76,467 | 11 | 152,934 |
Yes | output | 1 | 76,467 | 11 | 152,935 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You will turn on the air conditioner if, and only if, the temperature of the room is 30 degrees Celsius or above.
The current temperature of the room is X degrees Celsius. Will you turn on the air conditioner?
Constraints
* -40 \leq X \leq 40
* X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
Print `Yes` if you will turn on the air conditioner; print `No` otherwise.
Examples
Input
25
Output
No
Input
30
Output
Yes
Submitted Solution:
```
N = int(input())
print('No' if N < 30 else 'Yes')
``` | instruction | 0 | 76,468 | 11 | 152,936 |
Yes | output | 1 | 76,468 | 11 | 152,937 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You will turn on the air conditioner if, and only if, the temperature of the room is 30 degrees Celsius or above.
The current temperature of the room is X degrees Celsius. Will you turn on the air conditioner?
Constraints
* -40 \leq X \leq 40
* X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
Print `Yes` if you will turn on the air conditioner; print `No` otherwise.
Examples
Input
25
Output
No
Input
30
Output
Yes
Submitted Solution:
```
x = input()
if x => 30:
print("Yes")
else:
print("No")
``` | instruction | 0 | 76,469 | 11 | 152,938 |
No | output | 1 | 76,469 | 11 | 152,939 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You will turn on the air conditioner if, and only if, the temperature of the room is 30 degrees Celsius or above.
The current temperature of the room is X degrees Celsius. Will you turn on the air conditioner?
Constraints
* -40 \leq X \leq 40
* X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
Print `Yes` if you will turn on the air conditioner; print `No` otherwise.
Examples
Input
25
Output
No
Input
30
Output
Yes
Submitted Solution:
```
x=int(input())
if x<29:
print("No")
else:
print("Yes")
``` | instruction | 0 | 76,470 | 11 | 152,940 |
No | output | 1 | 76,470 | 11 | 152,941 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You will turn on the air conditioner if, and only if, the temperature of the room is 30 degrees Celsius or above.
The current temperature of the room is X degrees Celsius. Will you turn on the air conditioner?
Constraints
* -40 \leq X \leq 40
* X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
Print `Yes` if you will turn on the air conditioner; print `No` otherwise.
Examples
Input
25
Output
No
Input
30
Output
Yes
Submitted Solution:
```
X=int(input("X="))
if 30<=X<=40:
print("Yes")
elif:-40<=X<30
print("No")
``` | instruction | 0 | 76,471 | 11 | 152,942 |
No | output | 1 | 76,471 | 11 | 152,943 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You will turn on the air conditioner if, and only if, the temperature of the room is 30 degrees Celsius or above.
The current temperature of the room is X degrees Celsius. Will you turn on the air conditioner?
Constraints
* -40 \leq X \leq 40
* X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
Print `Yes` if you will turn on the air conditioner; print `No` otherwise.
Examples
Input
25
Output
No
Input
30
Output
Yes
Submitted Solution:
```
N = int(input())
if N >= 30:
print(Yes)
else:
print(No)
``` | instruction | 0 | 76,472 | 11 | 152,944 |
No | output | 1 | 76,472 | 11 | 152,945 |
Provide a correct Python 3 solution for this coding contest problem.
N programmers are going to participate in the preliminary stage of DDCC 20XX. Due to the size of the venue, however, at most 9 contestants can participate in the finals.
The preliminary stage consists of several rounds, which will take place as follows:
* All the N contestants will participate in the first round.
* When X contestants participate in some round, the number of contestants advancing to the next round will be decided as follows:
* The organizer will choose two consecutive digits in the decimal notation of X, and replace them with the sum of these digits. The number resulted will be the number of contestants advancing to the next round.
For example, when X = 2378, the number of contestants advancing to the next round will be 578 (if 2 and 3 are chosen), 2108 (if 3 and 7 are chosen), or 2315 (if 7 and 8 are chosen).
When X = 100, the number of contestants advancing to the next round will be 10, no matter which two digits are chosen.
* The preliminary stage ends when 9 or fewer contestants remain.
Ringo, the chief organizer, wants to hold as many rounds as possible. Find the maximum possible number of rounds in the preliminary stage.
Since the number of contestants, N, can be enormous, it is given to you as two integer sequences d_1, \ldots, d_M and c_1, \ldots, c_M, which means the following: the decimal notation of N consists of c_1 + c_2 + \ldots + c_M digits, whose first c_1 digits are all d_1, the following c_2 digits are all d_2, \ldots, and the last c_M digits are all d_M.
Constraints
* 1 \leq M \leq 200000
* 0 \leq d_i \leq 9
* d_1 \neq 0
* d_i \neq d_{i+1}
* c_i \geq 1
* 2 \leq c_1 + \ldots + c_M \leq 10^{15}
Input
Input is given from Standard Input in the following format:
M
d_1 c_1
d_2 c_2
:
d_M c_M
Output
Print the maximum possible number of rounds in the preliminary stage.
Examples
Input
2
2 2
9 1
Output
3
Input
3
1 1
0 8
7 1
Output
9 | instruction | 0 | 76,489 | 11 | 152,978 |
"Correct Solution:
```
I = [int(_) for _ in open(0).read().split()]
M = I[0]
D, C = I[1::2], I[2::2]
n = digit = 0
for d, c in zip(D, C):
n += d * c
digit += c
print((digit * 9 + n - 10) // 9)
``` | output | 1 | 76,489 | 11 | 152,979 |
Provide a correct Python 3 solution for this coding contest problem.
N programmers are going to participate in the preliminary stage of DDCC 20XX. Due to the size of the venue, however, at most 9 contestants can participate in the finals.
The preliminary stage consists of several rounds, which will take place as follows:
* All the N contestants will participate in the first round.
* When X contestants participate in some round, the number of contestants advancing to the next round will be decided as follows:
* The organizer will choose two consecutive digits in the decimal notation of X, and replace them with the sum of these digits. The number resulted will be the number of contestants advancing to the next round.
For example, when X = 2378, the number of contestants advancing to the next round will be 578 (if 2 and 3 are chosen), 2108 (if 3 and 7 are chosen), or 2315 (if 7 and 8 are chosen).
When X = 100, the number of contestants advancing to the next round will be 10, no matter which two digits are chosen.
* The preliminary stage ends when 9 or fewer contestants remain.
Ringo, the chief organizer, wants to hold as many rounds as possible. Find the maximum possible number of rounds in the preliminary stage.
Since the number of contestants, N, can be enormous, it is given to you as two integer sequences d_1, \ldots, d_M and c_1, \ldots, c_M, which means the following: the decimal notation of N consists of c_1 + c_2 + \ldots + c_M digits, whose first c_1 digits are all d_1, the following c_2 digits are all d_2, \ldots, and the last c_M digits are all d_M.
Constraints
* 1 \leq M \leq 200000
* 0 \leq d_i \leq 9
* d_1 \neq 0
* d_i \neq d_{i+1}
* c_i \geq 1
* 2 \leq c_1 + \ldots + c_M \leq 10^{15}
Input
Input is given from Standard Input in the following format:
M
d_1 c_1
d_2 c_2
:
d_M c_M
Output
Print the maximum possible number of rounds in the preliminary stage.
Examples
Input
2
2 2
9 1
Output
3
Input
3
1 1
0 8
7 1
Output
9 | instruction | 0 | 76,490 | 11 | 152,980 |
"Correct Solution:
```
M = int(input())
cnt = 0
cnt_c = 0
L = []
for _ in range(M):
d, c = map(int, input().split())
cnt += c*d
cnt_c += c
ans = (cnt-1) // 9 + cnt_c - 1
print(ans)
``` | output | 1 | 76,490 | 11 | 152,981 |
Provide a correct Python 3 solution for this coding contest problem.
N programmers are going to participate in the preliminary stage of DDCC 20XX. Due to the size of the venue, however, at most 9 contestants can participate in the finals.
The preliminary stage consists of several rounds, which will take place as follows:
* All the N contestants will participate in the first round.
* When X contestants participate in some round, the number of contestants advancing to the next round will be decided as follows:
* The organizer will choose two consecutive digits in the decimal notation of X, and replace them with the sum of these digits. The number resulted will be the number of contestants advancing to the next round.
For example, when X = 2378, the number of contestants advancing to the next round will be 578 (if 2 and 3 are chosen), 2108 (if 3 and 7 are chosen), or 2315 (if 7 and 8 are chosen).
When X = 100, the number of contestants advancing to the next round will be 10, no matter which two digits are chosen.
* The preliminary stage ends when 9 or fewer contestants remain.
Ringo, the chief organizer, wants to hold as many rounds as possible. Find the maximum possible number of rounds in the preliminary stage.
Since the number of contestants, N, can be enormous, it is given to you as two integer sequences d_1, \ldots, d_M and c_1, \ldots, c_M, which means the following: the decimal notation of N consists of c_1 + c_2 + \ldots + c_M digits, whose first c_1 digits are all d_1, the following c_2 digits are all d_2, \ldots, and the last c_M digits are all d_M.
Constraints
* 1 \leq M \leq 200000
* 0 \leq d_i \leq 9
* d_1 \neq 0
* d_i \neq d_{i+1}
* c_i \geq 1
* 2 \leq c_1 + \ldots + c_M \leq 10^{15}
Input
Input is given from Standard Input in the following format:
M
d_1 c_1
d_2 c_2
:
d_M c_M
Output
Print the maximum possible number of rounds in the preliminary stage.
Examples
Input
2
2 2
9 1
Output
3
Input
3
1 1
0 8
7 1
Output
9 | instruction | 0 | 76,491 | 11 | 152,982 |
"Correct Solution:
```
m=int(input())
n=0
s=0
for _ in range(m):
d,c=map(int,input().split())
n+=c
s+=c*d
print(n-1+(s-1)//9)
``` | output | 1 | 76,491 | 11 | 152,983 |
Provide a correct Python 3 solution for this coding contest problem.
N programmers are going to participate in the preliminary stage of DDCC 20XX. Due to the size of the venue, however, at most 9 contestants can participate in the finals.
The preliminary stage consists of several rounds, which will take place as follows:
* All the N contestants will participate in the first round.
* When X contestants participate in some round, the number of contestants advancing to the next round will be decided as follows:
* The organizer will choose two consecutive digits in the decimal notation of X, and replace them with the sum of these digits. The number resulted will be the number of contestants advancing to the next round.
For example, when X = 2378, the number of contestants advancing to the next round will be 578 (if 2 and 3 are chosen), 2108 (if 3 and 7 are chosen), or 2315 (if 7 and 8 are chosen).
When X = 100, the number of contestants advancing to the next round will be 10, no matter which two digits are chosen.
* The preliminary stage ends when 9 or fewer contestants remain.
Ringo, the chief organizer, wants to hold as many rounds as possible. Find the maximum possible number of rounds in the preliminary stage.
Since the number of contestants, N, can be enormous, it is given to you as two integer sequences d_1, \ldots, d_M and c_1, \ldots, c_M, which means the following: the decimal notation of N consists of c_1 + c_2 + \ldots + c_M digits, whose first c_1 digits are all d_1, the following c_2 digits are all d_2, \ldots, and the last c_M digits are all d_M.
Constraints
* 1 \leq M \leq 200000
* 0 \leq d_i \leq 9
* d_1 \neq 0
* d_i \neq d_{i+1}
* c_i \geq 1
* 2 \leq c_1 + \ldots + c_M \leq 10^{15}
Input
Input is given from Standard Input in the following format:
M
d_1 c_1
d_2 c_2
:
d_M c_M
Output
Print the maximum possible number of rounds in the preliminary stage.
Examples
Input
2
2 2
9 1
Output
3
Input
3
1 1
0 8
7 1
Output
9 | instruction | 0 | 76,492 | 11 | 152,984 |
"Correct Solution:
```
m=int(input())
counter=0
s=0
for i in range(m):
d,c=map(int,input().split())
counter+=d*c
s+=c
print(s-1+(counter-1)//9)
``` | output | 1 | 76,492 | 11 | 152,985 |
Provide a correct Python 3 solution for this coding contest problem.
N programmers are going to participate in the preliminary stage of DDCC 20XX. Due to the size of the venue, however, at most 9 contestants can participate in the finals.
The preliminary stage consists of several rounds, which will take place as follows:
* All the N contestants will participate in the first round.
* When X contestants participate in some round, the number of contestants advancing to the next round will be decided as follows:
* The organizer will choose two consecutive digits in the decimal notation of X, and replace them with the sum of these digits. The number resulted will be the number of contestants advancing to the next round.
For example, when X = 2378, the number of contestants advancing to the next round will be 578 (if 2 and 3 are chosen), 2108 (if 3 and 7 are chosen), or 2315 (if 7 and 8 are chosen).
When X = 100, the number of contestants advancing to the next round will be 10, no matter which two digits are chosen.
* The preliminary stage ends when 9 or fewer contestants remain.
Ringo, the chief organizer, wants to hold as many rounds as possible. Find the maximum possible number of rounds in the preliminary stage.
Since the number of contestants, N, can be enormous, it is given to you as two integer sequences d_1, \ldots, d_M and c_1, \ldots, c_M, which means the following: the decimal notation of N consists of c_1 + c_2 + \ldots + c_M digits, whose first c_1 digits are all d_1, the following c_2 digits are all d_2, \ldots, and the last c_M digits are all d_M.
Constraints
* 1 \leq M \leq 200000
* 0 \leq d_i \leq 9
* d_1 \neq 0
* d_i \neq d_{i+1}
* c_i \geq 1
* 2 \leq c_1 + \ldots + c_M \leq 10^{15}
Input
Input is given from Standard Input in the following format:
M
d_1 c_1
d_2 c_2
:
d_M c_M
Output
Print the maximum possible number of rounds in the preliminary stage.
Examples
Input
2
2 2
9 1
Output
3
Input
3
1 1
0 8
7 1
Output
9 | instruction | 0 | 76,493 | 11 | 152,986 |
"Correct Solution:
```
m = int(input())
x = 0
n = 0
for i in range(m):
d, c = map(int, input().split())
x += d * c
n += c
print(((x - 10) // 9 + 1 if x > 9 else 0) + n - 1)
``` | output | 1 | 76,493 | 11 | 152,987 |
Provide a correct Python 3 solution for this coding contest problem.
N programmers are going to participate in the preliminary stage of DDCC 20XX. Due to the size of the venue, however, at most 9 contestants can participate in the finals.
The preliminary stage consists of several rounds, which will take place as follows:
* All the N contestants will participate in the first round.
* When X contestants participate in some round, the number of contestants advancing to the next round will be decided as follows:
* The organizer will choose two consecutive digits in the decimal notation of X, and replace them with the sum of these digits. The number resulted will be the number of contestants advancing to the next round.
For example, when X = 2378, the number of contestants advancing to the next round will be 578 (if 2 and 3 are chosen), 2108 (if 3 and 7 are chosen), or 2315 (if 7 and 8 are chosen).
When X = 100, the number of contestants advancing to the next round will be 10, no matter which two digits are chosen.
* The preliminary stage ends when 9 or fewer contestants remain.
Ringo, the chief organizer, wants to hold as many rounds as possible. Find the maximum possible number of rounds in the preliminary stage.
Since the number of contestants, N, can be enormous, it is given to you as two integer sequences d_1, \ldots, d_M and c_1, \ldots, c_M, which means the following: the decimal notation of N consists of c_1 + c_2 + \ldots + c_M digits, whose first c_1 digits are all d_1, the following c_2 digits are all d_2, \ldots, and the last c_M digits are all d_M.
Constraints
* 1 \leq M \leq 200000
* 0 \leq d_i \leq 9
* d_1 \neq 0
* d_i \neq d_{i+1}
* c_i \geq 1
* 2 \leq c_1 + \ldots + c_M \leq 10^{15}
Input
Input is given from Standard Input in the following format:
M
d_1 c_1
d_2 c_2
:
d_M c_M
Output
Print the maximum possible number of rounds in the preliminary stage.
Examples
Input
2
2 2
9 1
Output
3
Input
3
1 1
0 8
7 1
Output
9 | instruction | 0 | 76,494 | 11 | 152,988 |
"Correct Solution:
```
m=int(input())
csum,dsum=0,0
for _ in range(m):
d,c=map(int,input().split())
dsum+=d*c
csum+=c
print(csum-1+(dsum-1)//9)
``` | output | 1 | 76,494 | 11 | 152,989 |
Provide a correct Python 3 solution for this coding contest problem.
N programmers are going to participate in the preliminary stage of DDCC 20XX. Due to the size of the venue, however, at most 9 contestants can participate in the finals.
The preliminary stage consists of several rounds, which will take place as follows:
* All the N contestants will participate in the first round.
* When X contestants participate in some round, the number of contestants advancing to the next round will be decided as follows:
* The organizer will choose two consecutive digits in the decimal notation of X, and replace them with the sum of these digits. The number resulted will be the number of contestants advancing to the next round.
For example, when X = 2378, the number of contestants advancing to the next round will be 578 (if 2 and 3 are chosen), 2108 (if 3 and 7 are chosen), or 2315 (if 7 and 8 are chosen).
When X = 100, the number of contestants advancing to the next round will be 10, no matter which two digits are chosen.
* The preliminary stage ends when 9 or fewer contestants remain.
Ringo, the chief organizer, wants to hold as many rounds as possible. Find the maximum possible number of rounds in the preliminary stage.
Since the number of contestants, N, can be enormous, it is given to you as two integer sequences d_1, \ldots, d_M and c_1, \ldots, c_M, which means the following: the decimal notation of N consists of c_1 + c_2 + \ldots + c_M digits, whose first c_1 digits are all d_1, the following c_2 digits are all d_2, \ldots, and the last c_M digits are all d_M.
Constraints
* 1 \leq M \leq 200000
* 0 \leq d_i \leq 9
* d_1 \neq 0
* d_i \neq d_{i+1}
* c_i \geq 1
* 2 \leq c_1 + \ldots + c_M \leq 10^{15}
Input
Input is given from Standard Input in the following format:
M
d_1 c_1
d_2 c_2
:
d_M c_M
Output
Print the maximum possible number of rounds in the preliminary stage.
Examples
Input
2
2 2
9 1
Output
3
Input
3
1 1
0 8
7 1
Output
9 | instruction | 0 | 76,495 | 11 | 152,990 |
"Correct Solution:
```
M = int(input())
d = [0] * M
c = [0] * M
for i in range(M):
d[i], c[i] = map(int, input().split())
D = 0
S = 0
for i in range(M):
D += c[i]
S += d[i] * c[i]
print((D - 1) + (S - 1) // 9)
``` | output | 1 | 76,495 | 11 | 152,991 |
Provide a correct Python 3 solution for this coding contest problem.
N programmers are going to participate in the preliminary stage of DDCC 20XX. Due to the size of the venue, however, at most 9 contestants can participate in the finals.
The preliminary stage consists of several rounds, which will take place as follows:
* All the N contestants will participate in the first round.
* When X contestants participate in some round, the number of contestants advancing to the next round will be decided as follows:
* The organizer will choose two consecutive digits in the decimal notation of X, and replace them with the sum of these digits. The number resulted will be the number of contestants advancing to the next round.
For example, when X = 2378, the number of contestants advancing to the next round will be 578 (if 2 and 3 are chosen), 2108 (if 3 and 7 are chosen), or 2315 (if 7 and 8 are chosen).
When X = 100, the number of contestants advancing to the next round will be 10, no matter which two digits are chosen.
* The preliminary stage ends when 9 or fewer contestants remain.
Ringo, the chief organizer, wants to hold as many rounds as possible. Find the maximum possible number of rounds in the preliminary stage.
Since the number of contestants, N, can be enormous, it is given to you as two integer sequences d_1, \ldots, d_M and c_1, \ldots, c_M, which means the following: the decimal notation of N consists of c_1 + c_2 + \ldots + c_M digits, whose first c_1 digits are all d_1, the following c_2 digits are all d_2, \ldots, and the last c_M digits are all d_M.
Constraints
* 1 \leq M \leq 200000
* 0 \leq d_i \leq 9
* d_1 \neq 0
* d_i \neq d_{i+1}
* c_i \geq 1
* 2 \leq c_1 + \ldots + c_M \leq 10^{15}
Input
Input is given from Standard Input in the following format:
M
d_1 c_1
d_2 c_2
:
d_M c_M
Output
Print the maximum possible number of rounds in the preliminary stage.
Examples
Input
2
2 2
9 1
Output
3
Input
3
1 1
0 8
7 1
Output
9 | instruction | 0 | 76,496 | 11 | 152,992 |
"Correct Solution:
```
M = int(input())
dcnt = 0
calc = 0
for i in range(M) :
c,d = map(int,input().split())
dcnt += d
calc += d*c
calc -= 1
res = calc//9 + dcnt - 1
print(res)
``` | output | 1 | 76,496 | 11 | 152,993 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N programmers are going to participate in the preliminary stage of DDCC 20XX. Due to the size of the venue, however, at most 9 contestants can participate in the finals.
The preliminary stage consists of several rounds, which will take place as follows:
* All the N contestants will participate in the first round.
* When X contestants participate in some round, the number of contestants advancing to the next round will be decided as follows:
* The organizer will choose two consecutive digits in the decimal notation of X, and replace them with the sum of these digits. The number resulted will be the number of contestants advancing to the next round.
For example, when X = 2378, the number of contestants advancing to the next round will be 578 (if 2 and 3 are chosen), 2108 (if 3 and 7 are chosen), or 2315 (if 7 and 8 are chosen).
When X = 100, the number of contestants advancing to the next round will be 10, no matter which two digits are chosen.
* The preliminary stage ends when 9 or fewer contestants remain.
Ringo, the chief organizer, wants to hold as many rounds as possible. Find the maximum possible number of rounds in the preliminary stage.
Since the number of contestants, N, can be enormous, it is given to you as two integer sequences d_1, \ldots, d_M and c_1, \ldots, c_M, which means the following: the decimal notation of N consists of c_1 + c_2 + \ldots + c_M digits, whose first c_1 digits are all d_1, the following c_2 digits are all d_2, \ldots, and the last c_M digits are all d_M.
Constraints
* 1 \leq M \leq 200000
* 0 \leq d_i \leq 9
* d_1 \neq 0
* d_i \neq d_{i+1}
* c_i \geq 1
* 2 \leq c_1 + \ldots + c_M \leq 10^{15}
Input
Input is given from Standard Input in the following format:
M
d_1 c_1
d_2 c_2
:
d_M c_M
Output
Print the maximum possible number of rounds in the preliminary stage.
Examples
Input
2
2 2
9 1
Output
3
Input
3
1 1
0 8
7 1
Output
9
Submitted Solution:
```
M = int(input())
ans, s = 0, 0
for _ in range(M):
d, c = map(int, input().split())
s += d*c
ans += c
ans += (s-1)//9 - 1
print(ans)
``` | instruction | 0 | 76,497 | 11 | 152,994 |
Yes | output | 1 | 76,497 | 11 | 152,995 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N programmers are going to participate in the preliminary stage of DDCC 20XX. Due to the size of the venue, however, at most 9 contestants can participate in the finals.
The preliminary stage consists of several rounds, which will take place as follows:
* All the N contestants will participate in the first round.
* When X contestants participate in some round, the number of contestants advancing to the next round will be decided as follows:
* The organizer will choose two consecutive digits in the decimal notation of X, and replace them with the sum of these digits. The number resulted will be the number of contestants advancing to the next round.
For example, when X = 2378, the number of contestants advancing to the next round will be 578 (if 2 and 3 are chosen), 2108 (if 3 and 7 are chosen), or 2315 (if 7 and 8 are chosen).
When X = 100, the number of contestants advancing to the next round will be 10, no matter which two digits are chosen.
* The preliminary stage ends when 9 or fewer contestants remain.
Ringo, the chief organizer, wants to hold as many rounds as possible. Find the maximum possible number of rounds in the preliminary stage.
Since the number of contestants, N, can be enormous, it is given to you as two integer sequences d_1, \ldots, d_M and c_1, \ldots, c_M, which means the following: the decimal notation of N consists of c_1 + c_2 + \ldots + c_M digits, whose first c_1 digits are all d_1, the following c_2 digits are all d_2, \ldots, and the last c_M digits are all d_M.
Constraints
* 1 \leq M \leq 200000
* 0 \leq d_i \leq 9
* d_1 \neq 0
* d_i \neq d_{i+1}
* c_i \geq 1
* 2 \leq c_1 + \ldots + c_M \leq 10^{15}
Input
Input is given from Standard Input in the following format:
M
d_1 c_1
d_2 c_2
:
d_M c_M
Output
Print the maximum possible number of rounds in the preliminary stage.
Examples
Input
2
2 2
9 1
Output
3
Input
3
1 1
0 8
7 1
Output
9
Submitted Solution:
```
M, *DC = map(int, open(0).read().split())
D, C = DC[::2], DC[1::2]
S = sum(d * c for d, c in zip(D, C))
print(sum(C) - 1 + (S - 1) // 9)
``` | instruction | 0 | 76,498 | 11 | 152,996 |
Yes | output | 1 | 76,498 | 11 | 152,997 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N programmers are going to participate in the preliminary stage of DDCC 20XX. Due to the size of the venue, however, at most 9 contestants can participate in the finals.
The preliminary stage consists of several rounds, which will take place as follows:
* All the N contestants will participate in the first round.
* When X contestants participate in some round, the number of contestants advancing to the next round will be decided as follows:
* The organizer will choose two consecutive digits in the decimal notation of X, and replace them with the sum of these digits. The number resulted will be the number of contestants advancing to the next round.
For example, when X = 2378, the number of contestants advancing to the next round will be 578 (if 2 and 3 are chosen), 2108 (if 3 and 7 are chosen), or 2315 (if 7 and 8 are chosen).
When X = 100, the number of contestants advancing to the next round will be 10, no matter which two digits are chosen.
* The preliminary stage ends when 9 or fewer contestants remain.
Ringo, the chief organizer, wants to hold as many rounds as possible. Find the maximum possible number of rounds in the preliminary stage.
Since the number of contestants, N, can be enormous, it is given to you as two integer sequences d_1, \ldots, d_M and c_1, \ldots, c_M, which means the following: the decimal notation of N consists of c_1 + c_2 + \ldots + c_M digits, whose first c_1 digits are all d_1, the following c_2 digits are all d_2, \ldots, and the last c_M digits are all d_M.
Constraints
* 1 \leq M \leq 200000
* 0 \leq d_i \leq 9
* d_1 \neq 0
* d_i \neq d_{i+1}
* c_i \geq 1
* 2 \leq c_1 + \ldots + c_M \leq 10^{15}
Input
Input is given from Standard Input in the following format:
M
d_1 c_1
d_2 c_2
:
d_M c_M
Output
Print the maximum possible number of rounds in the preliminary stage.
Examples
Input
2
2 2
9 1
Output
3
Input
3
1 1
0 8
7 1
Output
9
Submitted Solution:
```
m=int(input())
DC=[list(map(int,input().split())) for _ in range(m)]
D,S=0,0
for d,c in DC:
D +=c
S +=d*c
print(D-1+(S-1)//9)
``` | instruction | 0 | 76,499 | 11 | 152,998 |
Yes | output | 1 | 76,499 | 11 | 152,999 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N programmers are going to participate in the preliminary stage of DDCC 20XX. Due to the size of the venue, however, at most 9 contestants can participate in the finals.
The preliminary stage consists of several rounds, which will take place as follows:
* All the N contestants will participate in the first round.
* When X contestants participate in some round, the number of contestants advancing to the next round will be decided as follows:
* The organizer will choose two consecutive digits in the decimal notation of X, and replace them with the sum of these digits. The number resulted will be the number of contestants advancing to the next round.
For example, when X = 2378, the number of contestants advancing to the next round will be 578 (if 2 and 3 are chosen), 2108 (if 3 and 7 are chosen), or 2315 (if 7 and 8 are chosen).
When X = 100, the number of contestants advancing to the next round will be 10, no matter which two digits are chosen.
* The preliminary stage ends when 9 or fewer contestants remain.
Ringo, the chief organizer, wants to hold as many rounds as possible. Find the maximum possible number of rounds in the preliminary stage.
Since the number of contestants, N, can be enormous, it is given to you as two integer sequences d_1, \ldots, d_M and c_1, \ldots, c_M, which means the following: the decimal notation of N consists of c_1 + c_2 + \ldots + c_M digits, whose first c_1 digits are all d_1, the following c_2 digits are all d_2, \ldots, and the last c_M digits are all d_M.
Constraints
* 1 \leq M \leq 200000
* 0 \leq d_i \leq 9
* d_1 \neq 0
* d_i \neq d_{i+1}
* c_i \geq 1
* 2 \leq c_1 + \ldots + c_M \leq 10^{15}
Input
Input is given from Standard Input in the following format:
M
d_1 c_1
d_2 c_2
:
d_M c_M
Output
Print the maximum possible number of rounds in the preliminary stage.
Examples
Input
2
2 2
9 1
Output
3
Input
3
1 1
0 8
7 1
Output
9
Submitted Solution:
```
M = int(input())
keta = 0
count_sum = 0
for _ in range(M):
d,c= map(int,input().split(' '))
keta += c
count_sum += d*c
additional = count_sum//10
if 9 < count_sum:
print(keta-1 + (count_sum-1)//9)
else:
print(keta-1)
``` | instruction | 0 | 76,500 | 11 | 153,000 |
Yes | output | 1 | 76,500 | 11 | 153,001 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N programmers are going to participate in the preliminary stage of DDCC 20XX. Due to the size of the venue, however, at most 9 contestants can participate in the finals.
The preliminary stage consists of several rounds, which will take place as follows:
* All the N contestants will participate in the first round.
* When X contestants participate in some round, the number of contestants advancing to the next round will be decided as follows:
* The organizer will choose two consecutive digits in the decimal notation of X, and replace them with the sum of these digits. The number resulted will be the number of contestants advancing to the next round.
For example, when X = 2378, the number of contestants advancing to the next round will be 578 (if 2 and 3 are chosen), 2108 (if 3 and 7 are chosen), or 2315 (if 7 and 8 are chosen).
When X = 100, the number of contestants advancing to the next round will be 10, no matter which two digits are chosen.
* The preliminary stage ends when 9 or fewer contestants remain.
Ringo, the chief organizer, wants to hold as many rounds as possible. Find the maximum possible number of rounds in the preliminary stage.
Since the number of contestants, N, can be enormous, it is given to you as two integer sequences d_1, \ldots, d_M and c_1, \ldots, c_M, which means the following: the decimal notation of N consists of c_1 + c_2 + \ldots + c_M digits, whose first c_1 digits are all d_1, the following c_2 digits are all d_2, \ldots, and the last c_M digits are all d_M.
Constraints
* 1 \leq M \leq 200000
* 0 \leq d_i \leq 9
* d_1 \neq 0
* d_i \neq d_{i+1}
* c_i \geq 1
* 2 \leq c_1 + \ldots + c_M \leq 10^{15}
Input
Input is given from Standard Input in the following format:
M
d_1 c_1
d_2 c_2
:
d_M c_M
Output
Print the maximum possible number of rounds in the preliminary stage.
Examples
Input
2
2 2
9 1
Output
3
Input
3
1 1
0 8
7 1
Output
9
Submitted Solution:
```
M=int(input())
ans=0
A=[]
def f(x):
e=str(x)
n=len(e)
l=0
for i in e:
l+=int(i)
if l<10:
return l
else:
f(l)
for i in range(M):
d,c=map(int,input().split())
ans+=(c-1)+d*c//10
A.append(f(d*c))
if len(A)==1:
print(ans)
exit()
cnt=A[0]
for i in A[1:]:
if cnt+i<10:
cnt+=i
ans+=1
else:
e=str(cnt+i)
cnt=int(e[0])+int(e[1])
ans+=2
print(ans)
``` | instruction | 0 | 76,501 | 11 | 153,002 |
No | output | 1 | 76,501 | 11 | 153,003 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N programmers are going to participate in the preliminary stage of DDCC 20XX. Due to the size of the venue, however, at most 9 contestants can participate in the finals.
The preliminary stage consists of several rounds, which will take place as follows:
* All the N contestants will participate in the first round.
* When X contestants participate in some round, the number of contestants advancing to the next round will be decided as follows:
* The organizer will choose two consecutive digits in the decimal notation of X, and replace them with the sum of these digits. The number resulted will be the number of contestants advancing to the next round.
For example, when X = 2378, the number of contestants advancing to the next round will be 578 (if 2 and 3 are chosen), 2108 (if 3 and 7 are chosen), or 2315 (if 7 and 8 are chosen).
When X = 100, the number of contestants advancing to the next round will be 10, no matter which two digits are chosen.
* The preliminary stage ends when 9 or fewer contestants remain.
Ringo, the chief organizer, wants to hold as many rounds as possible. Find the maximum possible number of rounds in the preliminary stage.
Since the number of contestants, N, can be enormous, it is given to you as two integer sequences d_1, \ldots, d_M and c_1, \ldots, c_M, which means the following: the decimal notation of N consists of c_1 + c_2 + \ldots + c_M digits, whose first c_1 digits are all d_1, the following c_2 digits are all d_2, \ldots, and the last c_M digits are all d_M.
Constraints
* 1 \leq M \leq 200000
* 0 \leq d_i \leq 9
* d_1 \neq 0
* d_i \neq d_{i+1}
* c_i \geq 1
* 2 \leq c_1 + \ldots + c_M \leq 10^{15}
Input
Input is given from Standard Input in the following format:
M
d_1 c_1
d_2 c_2
:
d_M c_M
Output
Print the maximum possible number of rounds in the preliminary stage.
Examples
Input
2
2 2
9 1
Output
3
Input
3
1 1
0 8
7 1
Output
9
Submitted Solution:
```
import sys
input = sys.stdin.readline
m = int(input())
ans = 0
dc = []
prev = 0
for i in range(m):
d, c = [int(item) for item in input().split()]
ans += (prev + d * c) // 10
prev = (prev + d * c) % 10
if i == m - 1 and (prev + d * c) <= 9:
break
ans += c
print(ans-1)
``` | instruction | 0 | 76,502 | 11 | 153,004 |
No | output | 1 | 76,502 | 11 | 153,005 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N programmers are going to participate in the preliminary stage of DDCC 20XX. Due to the size of the venue, however, at most 9 contestants can participate in the finals.
The preliminary stage consists of several rounds, which will take place as follows:
* All the N contestants will participate in the first round.
* When X contestants participate in some round, the number of contestants advancing to the next round will be decided as follows:
* The organizer will choose two consecutive digits in the decimal notation of X, and replace them with the sum of these digits. The number resulted will be the number of contestants advancing to the next round.
For example, when X = 2378, the number of contestants advancing to the next round will be 578 (if 2 and 3 are chosen), 2108 (if 3 and 7 are chosen), or 2315 (if 7 and 8 are chosen).
When X = 100, the number of contestants advancing to the next round will be 10, no matter which two digits are chosen.
* The preliminary stage ends when 9 or fewer contestants remain.
Ringo, the chief organizer, wants to hold as many rounds as possible. Find the maximum possible number of rounds in the preliminary stage.
Since the number of contestants, N, can be enormous, it is given to you as two integer sequences d_1, \ldots, d_M and c_1, \ldots, c_M, which means the following: the decimal notation of N consists of c_1 + c_2 + \ldots + c_M digits, whose first c_1 digits are all d_1, the following c_2 digits are all d_2, \ldots, and the last c_M digits are all d_M.
Constraints
* 1 \leq M \leq 200000
* 0 \leq d_i \leq 9
* d_1 \neq 0
* d_i \neq d_{i+1}
* c_i \geq 1
* 2 \leq c_1 + \ldots + c_M \leq 10^{15}
Input
Input is given from Standard Input in the following format:
M
d_1 c_1
d_2 c_2
:
d_M c_M
Output
Print the maximum possible number of rounds in the preliminary stage.
Examples
Input
2
2 2
9 1
Output
3
Input
3
1 1
0 8
7 1
Output
9
Submitted Solution:
```
import sys
input = sys.stdin.readline
from collections import deque
q = deque()
def calc(d, c):
if c&1:
q.append(d)
if c == 1:
return 0
d *= 2
if d >= 10:
return c//2 * 2 + calc(1+d%10, c//2)
return c//2 + calc(d, c//2)
def main():
M = int(input())
ans = 0
for i in range(M):
d, c = map(int, input().split())
ans += calc(d, c)
num = q.popleft()
while len(q) > 0:
t = q.popleft()
num += t
if num >= 10:
num = 1 + num%10
ans += 1
ans += 1
print(ans)
if __name__ == "__main__":
main()
``` | instruction | 0 | 76,503 | 11 | 153,006 |
No | output | 1 | 76,503 | 11 | 153,007 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N programmers are going to participate in the preliminary stage of DDCC 20XX. Due to the size of the venue, however, at most 9 contestants can participate in the finals.
The preliminary stage consists of several rounds, which will take place as follows:
* All the N contestants will participate in the first round.
* When X contestants participate in some round, the number of contestants advancing to the next round will be decided as follows:
* The organizer will choose two consecutive digits in the decimal notation of X, and replace them with the sum of these digits. The number resulted will be the number of contestants advancing to the next round.
For example, when X = 2378, the number of contestants advancing to the next round will be 578 (if 2 and 3 are chosen), 2108 (if 3 and 7 are chosen), or 2315 (if 7 and 8 are chosen).
When X = 100, the number of contestants advancing to the next round will be 10, no matter which two digits are chosen.
* The preliminary stage ends when 9 or fewer contestants remain.
Ringo, the chief organizer, wants to hold as many rounds as possible. Find the maximum possible number of rounds in the preliminary stage.
Since the number of contestants, N, can be enormous, it is given to you as two integer sequences d_1, \ldots, d_M and c_1, \ldots, c_M, which means the following: the decimal notation of N consists of c_1 + c_2 + \ldots + c_M digits, whose first c_1 digits are all d_1, the following c_2 digits are all d_2, \ldots, and the last c_M digits are all d_M.
Constraints
* 1 \leq M \leq 200000
* 0 \leq d_i \leq 9
* d_1 \neq 0
* d_i \neq d_{i+1}
* c_i \geq 1
* 2 \leq c_1 + \ldots + c_M \leq 10^{15}
Input
Input is given from Standard Input in the following format:
M
d_1 c_1
d_2 c_2
:
d_M c_M
Output
Print the maximum possible number of rounds in the preliminary stage.
Examples
Input
2
2 2
9 1
Output
3
Input
3
1 1
0 8
7 1
Output
9
Submitted Solution:
```
M=int(input())
D,C=zip(*[map(int,input().split()) for i in range(M)])
def f(n):
return sum([int(c) for c in str(n)])
x,y=0,0
for d,c in zip(D,C):
x+=d*c//10
y+=f(d*c)
print(sum(C)-1+x+y//10)
``` | instruction | 0 | 76,504 | 11 | 153,008 |
No | output | 1 | 76,504 | 11 | 153,009 |
Provide a correct Python 3 solution for this coding contest problem.
Description
Since the cubic equation: ax ^ 3 + bx ^ 2 + cx + d = 0 is given, please check the number of positive real roots and the number of negative real roots, respectively.
The number of roots shall be counted including the multiple roots.
Input
The input consists of multiple test cases, and the number is recorded on the first line.
From the second line onward, the coefficients of the cubic equation are written in the form of a b c d. a is not 0, and each number is an integer value from -100 to 100.
Output
For a given cubic equation, output the number of positive real roots and the number of negative real roots separated by a space.
Example
Input
2
1 3 3 1
-10 0 0 0
Output
0 3
0 0 | instruction | 0 | 76,641 | 11 | 153,282 |
"Correct Solution:
```
import sys,queue,math,copy
from fractions import gcd
input = sys.stdin.readline
INF = 10**4
EPS = 10 ** (-8)
LI = lambda : [int(x) for x in input().split()]
_LI = lambda : [int(x)-1 for x in input().split()]
N = int(input())
for _ in range(N):
a,b,c,d = LI()
if a < 0:
a = -a
b = -b
c = -c
d = -d
f = lambda x: a*x*x*x + b*x*x + c*x + d
a_plus = 0
a_minus = 0
D = b * b - 3 * a * c
def count(x, y):
global a_plus,a_minus
if x > 0:
a_plus += y
elif x < 0:
a_minus += y
if D < 0:
# 単調増加/減少
count(-d,1)
elif D == 0:
if f(-b/(3*a)) == 0: #3重解
count(-b,3)
else: # 単調増加
count(-d,1)
else:
x1 = (- b - math.sqrt(D)) / (3*a)
x2 = (- b + math.sqrt(D)) / (3*a)
def bs(h,l):
if min(h,l) <= 0 <= max(h,l) and f(0) == 0:
return 0
while f(h) > f(l) + EPS:
m = (h + l)/2
if f(m) > 0:
h = m
else:
l = m
return l
if f(x1) > 0:
a1 = bs(x1,-INF)
count(a1,1)
if f(x2) < 0:
a1 = bs(x1,x2)
count(a1,1)
a1 = bs(INF,x2)
count(a1,1)
elif f(x2) == 0:
count(x2,2)
elif f(x1) == 0:
count(x1,2)
a1 = bs(INF,x2)
count(a1,1)
else: #f(x1) < 0
a1 = bs(INF,x2)
count(a1,1)
print (a_plus, a_minus)
``` | output | 1 | 76,641 | 11 | 153,283 |
Provide a correct Python 3 solution for this coding contest problem.
Description
Since the cubic equation: ax ^ 3 + bx ^ 2 + cx + d = 0 is given, please check the number of positive real roots and the number of negative real roots, respectively.
The number of roots shall be counted including the multiple roots.
Input
The input consists of multiple test cases, and the number is recorded on the first line.
From the second line onward, the coefficients of the cubic equation are written in the form of a b c d. a is not 0, and each number is an integer value from -100 to 100.
Output
For a given cubic equation, output the number of positive real roots and the number of negative real roots separated by a space.
Example
Input
2
1 3 3 1
-10 0 0 0
Output
0 3
0 0 | instruction | 0 | 76,642 | 11 | 153,284 |
"Correct Solution:
```
import math
n = int(input())
def F(a, b, c, d) :
return lambda x : a * x**3 + b * x**2 + c * x + d
def X(a, b, c) :
a = 3 * a
b = 2 * b
try :
D = math.sqrt(b**2 - 4 * a * c)
if D == 0 :
return 0
else :
return (-b + D) / (2 * a), (-b - D) / (2 * a)
except :
return -1
def boa(fz, lmax, lmin, p, n) :
if fz > 0 :
if lmin > 0 :
p, n = 2, 1
else :
n = 3
elif fz == 0 :
if 0 < lmin and lmax < 0 :
p, n = 1, 1
elif lmax > 0 :
p = 2
else :
n = 2
else :
if lmax > 0 :
p = 3
else :
p, n = 1, 2
return p, n
def ao(fz, lmax, p, n) :
if fz > 0 :
n = 2
elif fz == 0 :
if lmax == 0 :
p = 1
else :
n = 1
else :
if lmax > 0 :
p = 2
else :
p, n = 1, 1
return p, n
def bo(fz, lmin, p, n) :
if fz > 0 :
if lmin > 0 :
p, n = 1, 1
else :
n = 2
elif fz == 0 :
if lmin == 0 :
n = 1
else :
p = 1
else :
p = 2
return p, n
def aob(fz, p, n) :
if fz > 0 :
n = 1
elif fz < 0 :
p = 1
return p, n
def P(x, y) :
if x > 0 :
print(y, 0)
elif x < 0 :
print(0, y)
else :
print(0, 0)
for i in range(n) :
a, b, c, d = map(int, input().split())
if a < 0 :
a *= -1
b *= -1
c *= -1
d *= -1
f = F(a, b, c, d)
p = 0
# Positive integer
n = 0
# Negative integer
if X(a, b, c) == -1 :
P(-d, 1)
elif X(a, b, c) == 0 :
if f(-b / (3 * a)) == 0 :
P(-b, 3)
else :
P(-d, 1)
else :
if f(X(a, b, c)[0]) < f(X(a, b, c)[1]) :
lmax = X(a, b, c)[1]
# Local maximum
lmin = X(a, b, c)[0]
# Local minimum
else :
lmax = X(a, b, c)[0]
lmin = X(a, b, c)[1]
fmax = f(lmax)
fmin = f(lmin)
fz = f(0)
if lmax == lmin :
if lmax < 0 :
print(0, 3)
elif lmax > 0 :
print(3, 0)
else :
print(0, 0)
elif fmin < 0 and 0 < fmax :
pn = boa(fz, lmax, lmin, p, n)
print(pn[0], pn[1])
elif fmax == 0 :
pn = ao(fz, lmax, p, n)
print(pn[0], pn[1])
elif fmin == 0 :
pn = bo(fz, lmin, p, n)
print(pn[0], pn[1])
else :
pn = aob(fz, p, n)
print(pn[0], pn[1])
``` | output | 1 | 76,642 | 11 | 153,285 |
Provide a correct Python 3 solution for this coding contest problem.
Description
Since the cubic equation: ax ^ 3 + bx ^ 2 + cx + d = 0 is given, please check the number of positive real roots and the number of negative real roots, respectively.
The number of roots shall be counted including the multiple roots.
Input
The input consists of multiple test cases, and the number is recorded on the first line.
From the second line onward, the coefficients of the cubic equation are written in the form of a b c d. a is not 0, and each number is an integer value from -100 to 100.
Output
For a given cubic equation, output the number of positive real roots and the number of negative real roots separated by a space.
Example
Input
2
1 3 3 1
-10 0 0 0
Output
0 3
0 0 | instruction | 0 | 76,643 | 11 | 153,286 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
EPS = 10 ** -8
def bisearch_max(mn, mx, func):
""" 条件を満たす最大値を見つける二分探索(小数用) """
ok = mn
ng = mx
while abs(ok-ng) > 10**-12:
mid = (ok+ng) / 2
if func(mid):
# 上を探しに行く
ok = mid
else:
# 下を探しに行く
ng = mid
return ok
# 2次方程式の解の公式
def dim2formula(a, b, c):
from math import sqrt
try:
return (-b+sqrt(pow(b, 2)-4*a*c))/(2*a), (-b-sqrt(pow(b, 2)-4*a*c))/(2*a)
# 解なしはNoneを返却
except ValueError:
return (None, None)
# 3次→2次への微分
def calc1(a, b, c, d):
a *= 3
b *= 2
return (a, b, c)
# ax^3+bx^2+cx+dを解く
def calc2(x):
return a*x**3 + b*x**2 + c*x + d
# /のグラフ用
def check1(x):
res = calc2(x)
return res < 0
# \のグラフ用
def check2(x):
res = calc2(x)
return res > 0
for _ in range(INT()):
a, b, c, d = MAP()
ans = [0] * 2
a2, b2, c2 = calc1(a, b, c, d)
ans1, ans2 = dim2formula(a2, b2, c2)
# 微分して解いた結果が解なしなら、元の式は極値なしで解は1つ
if ans1 is None:
if a > 0:
# /のグラフ
x = bisearch_max(-INF, INF, check1)
else:
# \のグラフ
x = bisearch_max(-INF, INF, check2)
# x = 0 ならカウントしない
if abs(x) < EPS:
pass
elif x > 0:
ans[0] += 1
elif x < 0:
ans[1] += 1
# それ以外なら解は重解も含めると解は3つ
else:
ans1, ans2 = min(ans1, ans2), max(ans1, ans2)
# /\/のグラフ
if a > 0:
res1 = bisearch_max(-INF, ans1, check1)
res2 = bisearch_max(ans1, ans2, check2)
res3 = bisearch_max(ans2, INF, check1)
# \/\のグラフ
else:
res1 = bisearch_max(-INF, ans1, check2)
res2 = bisearch_max(ans1, ans2, check1)
res3 = bisearch_max(ans2, INF, check2)
# 3つの解候補
for x in [res1, res2, res3]:
# f(x) = 0 について確認
if abs(calc2(x)) < EPS:
# x = 0 ならカウントしない
if abs(x) < EPS:
continue
elif x > 0:
ans[0] += 1
elif x < 0:
ans[1] += 1
print(*ans)
``` | output | 1 | 76,643 | 11 | 153,287 |
Provide a correct Python 3 solution for this coding contest problem.
Description
Since the cubic equation: ax ^ 3 + bx ^ 2 + cx + d = 0 is given, please check the number of positive real roots and the number of negative real roots, respectively.
The number of roots shall be counted including the multiple roots.
Input
The input consists of multiple test cases, and the number is recorded on the first line.
From the second line onward, the coefficients of the cubic equation are written in the form of a b c d. a is not 0, and each number is an integer value from -100 to 100.
Output
For a given cubic equation, output the number of positive real roots and the number of negative real roots separated by a space.
Example
Input
2
1 3 3 1
-10 0 0 0
Output
0 3
0 0 | instruction | 0 | 76,645 | 11 | 153,290 |
"Correct Solution:
```
import math
def make_func1(a, b, c, d):
return lambda X : a*X**3 + b*X**2 + c*X + d
def make_func2(a, b, c):
return lambda x : 3*a*x**2 + 2*b*x + c
i = int(input())
for j in range(i):
a, b, c, d = map(int, input().split())
fX = make_func1(a, b, c, d)
fx = make_func2(a, b, c)
D_4 = b**2 - 3*a*c
if D_4<=0:
if 0<a:
if d<0:
pos=1
neg=0
if d==0:
pos=0
neg=0
if 0<d:
pos=0
neg=1
if a<0:
if d<0:
pos=0
neg=1
if d==0:
pos=0
neg=0
if 0<d:
pos=1
neg=0
if D_4>0 :
if 0<a:
p = (-b-math.sqrt(b**2-3*a*c))/(3*a)
q = (-b+math.sqrt(b**2-3*a*c))/(3*a)
if 0<fX(q) or fX(p)<0 :
if d<0:
pos=1
neg=0
if d==0:
pos=0
neg=0
if 0<d:
pos=0
neg=1
if fX(q)==0:
if d<0:
pos=3
neg=0
if d==0 and 0<p:
pos=2
neg=0
if 0<d and 0<q:
pos=2
neg=1
if d==0 and q==0:
pos=0
neg=1
if 0<d and q<0:
pos=0
neg=3
if fX(p)==0:
if d<0 and 0<p:
pos=3
neg=0
if d==0 and p==0:
pos=1
neg=0
if d<0 and p<0:
pos=1
neg=2
if d==0 and q<0:
pos=0
neg=2
if 0<d and q<0:
pos=0
neg=3
if fX(q)<0<fX(p):
if d<0 and 0<p:
pos=3
neg=0
if d==0 and 0<p:
pos=2
neg=0
if 0<d and 0<q:
pos=2
neg=1
if d==0 and p<0<q:
pos=1
neg=1
if d<0 and p<0:
pos=1
neg=2
if d==0 and q<0:
pos=0
neg=2
if 0<d and q<0:
pos=0
neg=3
if a<0:
p = (-b+math.sqrt(b**2-3*a*c))/(3*a)
q = (-b-math.sqrt(b**2-3*a*c))/(3*a)
if 0<fX(p) or fX(q)<0 :
if d<0:
pos=0
neg=1
if d==0:
pos=0
neg=0
if 0<d:
pos=1
neg=0
if fX(p)==0:
if 0<d and 0<p:
pos=3
neg=0
if d==0 and p==0:
pos=1
neg=0
if 0<d and p<0:
pos=1
neg=2
if d==0 and q<0:
pos=0
neg=2
if d<0 and q<0:
pos=0
neg=3
if fX(q)==0:
if 0<d and 0<p:
pos=3
neg=0
if d==0 and 0<p:
pos=2
neg=0
if d<0 and 0<q:
pos=2
neg=1
if d==0 and q==0:
pos=0
neg=1
if d<0 and q<0:
pos=0
neg=3
if fX(p)<0<fX(q):
if 0<d and 0<p:
pos=3
neg=0
if d==0 and 0<p:
pos=2
neg=0
if d<0 and 0<q:
pos=2
neg=1
if d==0 and p<0<q:
pos=1
neg=1
if 0<d and p<0:
pos=1
neg=2
if d==0 and q<0:
pos=0
neg=2
if d<0 and q<0:
pos=0
neg=3
print(pos,neg)
``` | output | 1 | 76,645 | 11 | 153,291 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Description
Since the cubic equation: ax ^ 3 + bx ^ 2 + cx + d = 0 is given, please check the number of positive real roots and the number of negative real roots, respectively.
The number of roots shall be counted including the multiple roots.
Input
The input consists of multiple test cases, and the number is recorded on the first line.
From the second line onward, the coefficients of the cubic equation are written in the form of a b c d. a is not 0, and each number is an integer value from -100 to 100.
Output
For a given cubic equation, output the number of positive real roots and the number of negative real roots separated by a space.
Example
Input
2
1 3 3 1
-10 0 0 0
Output
0 3
0 0
Submitted Solution:
```
import math
w1 = 1
w2 = 1/2 * (-1 + math.sqrt(3)*1j)
w3 = 1/2 * (-1 - math.sqrt(3)*1j)
n = int(input())
for i in range(n):
aa, bb, cc, dd = map(int, input().split())
a = bb / aa
b = cc / aa
c = dd / aa
p = -1/54 * (27 * c + 2 * (a ** 3) - 9 * a * b)
q = 1/9 * (3 * b - a ** 2)
r = 1/3 * a
x1 = w1 * (p + math.sqrt(p ** 2 + q ** 3)) ** (1/3) + w1 * (p - math.sqrt(p ** 2 + q ** 3)) ** (1/3) - r
x2 = w2 * (p + math.sqrt(p ** 2 + q ** 3)) ** (1/3) + w3 * (p - math.sqrt(p ** 2 + q ** 3)) ** (1/3) - r
x3 = w3 * (p + math.sqrt(p ** 2 + q ** 3)) ** (1/3) + w2 * (p - math.sqrt(p ** 2 + q ** 3)) ** (1/3) - r
plus = 0
minus = 0
for i in [x1, x2, x3]:
if i.imag == 0:
i = i.real
if i > 0:
plus += 1
elif i < 0:
minus += 1
print(plus, minus)
``` | instruction | 0 | 76,646 | 11 | 153,292 |
No | output | 1 | 76,646 | 11 | 153,293 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Example
Input
2 1
WE
Output
1 2
Submitted Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
n,m = LI()
a = [S() for _ in range(m)]
r = n
for i in range(n):
if r < i:
break
for j in range(m):
if a[j][i] == 'E':
r = i
break
return '{} {}'.format(r,r+1)
print(main())
``` | instruction | 0 | 76,650 | 11 | 153,300 |
No | output | 1 | 76,650 | 11 | 153,301 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As a professional private tutor, Kuroni has to gather statistics of an exam. Kuroni has appointed you to complete this important task. You must not disappoint him.
The exam consists of n questions, and m students have taken the exam. Each question was worth 1 point. Question i was solved by at least l_i and at most r_i students. Additionally, you know that the total score of all students is t.
Furthermore, you took a glance at the final ranklist of the quiz. The students were ranked from 1 to m, where rank 1 has the highest score and rank m has the lowest score. Ties were broken arbitrarily.
You know that the student at rank p_i had a score of s_i for 1 ≤ i ≤ q.
You wonder if there could have been a huge tie for first place. Help Kuroni determine the maximum number of students who could have gotten as many points as the student with rank 1, and the maximum possible score for rank 1 achieving this maximum number of students.
Input
The first line of input contains two integers (1 ≤ n, m ≤ 10^{5}), denoting the number of questions of the exam and the number of students respectively.
The next n lines contain two integers each, with the i-th line containing l_{i} and r_{i} (0 ≤ l_{i} ≤ r_{i} ≤ m).
The next line contains a single integer q (0 ≤ q ≤ m).
The next q lines contain two integers each, denoting p_{i} and s_{i} (1 ≤ p_{i} ≤ m, 0 ≤ s_{i} ≤ n). It is guaranteed that all p_{i} are distinct and if p_{i} ≤ p_{j}, then s_{i} ≥ s_{j}.
The last line contains a single integer t (0 ≤ t ≤ nm), denoting the total score of all students.
Output
Output two integers: the maximum number of students who could have gotten as many points as the student with rank 1, and the maximum possible score for rank 1 achieving this maximum number of students. If there is no valid arrangement that fits the given data, output -1 -1.
Examples
Input
5 4
2 4
2 3
1 1
0 1
0 0
1
4 1
7
Output
3 2
Input
5 6
0 6
0 6
2 5
6 6
4 6
1
3 3
30
Output
-1 -1
Note
For the first sample, here is one possible arrangement that fits the data:
Students 1 and 2 both solved problems 1 and 2.
Student 3 solved problems 2 and 3.
Student 4 solved problem 4.
The total score of all students is T = 7. Note that the scores of the students are 2, 2, 2 and 1 respectively, which satisfies the condition that the student at rank 4 gets exactly 1 point. Finally, 3 students tied for first with a maximum score of 2, and it can be proven that we cannot do better with any other arrangement.
Submitted Solution:
```
import math
n, m = list(map(int, input().split()))
questions = []
rank = [0]*m
for i in range(n):
trash1, trash2 = list(map(int, input().split()))
q = int(input())
already_ok = 0
already_people = n + 1
for i in range(q):
p, ok = list(map(int, input().split()))
already_ok = max(already_ok, ok)
already_people = min(already_people, p)
total = int(input())
if(already_ok == 0):
print(0, n)
elif(already_ok*n >= total):
print(int(total/already_ok), already_ok)
else:
if(int((total - already_ok)/math.ceil(total/(n - q))) < already_people):
print(int((total - already_ok)/math.ceil(total/(n - q))),math.ceil(total/(n - q)))
else:
print("-1 -1")
``` | instruction | 0 | 76,859 | 11 | 153,718 |
No | output | 1 | 76,859 | 11 | 153,719 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.