text stringlengths 216 39.6k | conversation_id int64 219 108k | embedding list | cluster int64 11 11 |
|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
AtCoder currently hosts three types of contests: ABC, ARC, and AGC. As the number of users has grown, in order to meet the needs of more users, AtCoder has decided to increase the number of contests to 26 types, from AAC to AZC. For convenience, we number these 26 types as type 1 through type 26. AtCoder wants to schedule contests for D days so that user satisfaction is as high as possible. For every day, AtCoder will hold exactly one contest, and each contest will end on that day. The satisfaction is calculated as follows.
* The satisfaction at the beginning of day 1 is 0. Satisfaction can be negative.
* Holding contests increases satisfaction. The amount of increase will vary depending on a variety of factors. Specifically, we know in advance that holding a contest of type i on day d will increase the satisfaction by s_{d,i}.
* If a particular type of contest is not held for a while, the satisfaction decreases. Each contest type i has an integer c_i, and at the end of each day d=1,2,...,D, the satisfaction decreases as follows. Let \mathrm{last}(d,i) be the last day before day d (including d) on which a contest of type i was held. If contests of type i have never been held yet, we define \mathrm{last}(d,i)=0. At the end of day d, the satisfaction decreases by \sum _{i=1}^{26}c_i \times (d-\mathrm{last}(d,i)).
Please schedule contests on behalf of AtCoder. If the satisfaction at the end of day D is S, you will get a score of \max(10^6 + S, 0). There are 50 test cases, and the score of a submission is the total scores for each test case. You can make submissions multiple times, and the highest score among your submissions will be your score.
Constraints
* D = 365
* Each c_i is an integer satisfying 0\leq c_i \leq 100.
* Each s_{d,i} is an integer satisfying 0\leq s_{d,i} \leq 20000.
Input
Input is given from Standard Input in the following format:
D
c_1 c_2 \cdots c_{26}
s_{1,1} s_{1,2} \cdots s_{1,26}
\vdots
s_{D,1} s_{D,2} \cdots s_{D,26}
Output
Let t_d (1\leq t_d \leq 26) be the type of the contest that will be held at day d. Print D integers t_d to Standard Output in the following format:
t_1
t_2
\vdots
t_D
Any output that does not follow the above format may result in ~~0 points~~ WA for that test case.
Input Generation
Each integer c_i and s_{d,i} is generated independently and uniformly at random from the integers in the range described in the problem statement.
Example
Input
5
86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192
Output
1
17
13
14
13
Submitted Solution:
```
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
for i in range(D):
print(i % 26 + 1)
```
Yes
| 74,765 | [
0.42822265625,
0.1236572265625,
-0.2347412109375,
0.262939453125,
-0.58984375,
-0.544921875,
-0.339599609375,
0.3818359375,
0.10064697265625,
0.64404296875,
0.51220703125,
-0.50244140625,
-0.03131103515625,
-1.017578125,
-0.0633544921875,
-0.297607421875,
-0.391357421875,
-0.835937... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
AtCoder currently hosts three types of contests: ABC, ARC, and AGC. As the number of users has grown, in order to meet the needs of more users, AtCoder has decided to increase the number of contests to 26 types, from AAC to AZC. For convenience, we number these 26 types as type 1 through type 26. AtCoder wants to schedule contests for D days so that user satisfaction is as high as possible. For every day, AtCoder will hold exactly one contest, and each contest will end on that day. The satisfaction is calculated as follows.
* The satisfaction at the beginning of day 1 is 0. Satisfaction can be negative.
* Holding contests increases satisfaction. The amount of increase will vary depending on a variety of factors. Specifically, we know in advance that holding a contest of type i on day d will increase the satisfaction by s_{d,i}.
* If a particular type of contest is not held for a while, the satisfaction decreases. Each contest type i has an integer c_i, and at the end of each day d=1,2,...,D, the satisfaction decreases as follows. Let \mathrm{last}(d,i) be the last day before day d (including d) on which a contest of type i was held. If contests of type i have never been held yet, we define \mathrm{last}(d,i)=0. At the end of day d, the satisfaction decreases by \sum _{i=1}^{26}c_i \times (d-\mathrm{last}(d,i)).
Please schedule contests on behalf of AtCoder. If the satisfaction at the end of day D is S, you will get a score of \max(10^6 + S, 0). There are 50 test cases, and the score of a submission is the total scores for each test case. You can make submissions multiple times, and the highest score among your submissions will be your score.
Constraints
* D = 365
* Each c_i is an integer satisfying 0\leq c_i \leq 100.
* Each s_{d,i} is an integer satisfying 0\leq s_{d,i} \leq 20000.
Input
Input is given from Standard Input in the following format:
D
c_1 c_2 \cdots c_{26}
s_{1,1} s_{1,2} \cdots s_{1,26}
\vdots
s_{D,1} s_{D,2} \cdots s_{D,26}
Output
Let t_d (1\leq t_d \leq 26) be the type of the contest that will be held at day d. Print D integers t_d to Standard Output in the following format:
t_1
t_2
\vdots
t_D
Any output that does not follow the above format may result in ~~0 points~~ WA for that test case.
Input Generation
Each integer c_i and s_{d,i} is generated independently and uniformly at random from the integers in the range described in the problem statement.
Example
Input
5
86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192
Output
1
17
13
14
13
Submitted Solution:
```
d = int(input())
c = list(map(int, input().split()))
for i in range(d):
s = list(map(int, input().split()))
num = max(s)
print(l.index(num)+1)
```
No
| 74,766 | [
0.42822265625,
0.1236572265625,
-0.2347412109375,
0.262939453125,
-0.58984375,
-0.544921875,
-0.339599609375,
0.3818359375,
0.10064697265625,
0.64404296875,
0.51220703125,
-0.50244140625,
-0.03131103515625,
-1.017578125,
-0.0633544921875,
-0.297607421875,
-0.391357421875,
-0.835937... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
AtCoder currently hosts three types of contests: ABC, ARC, and AGC. As the number of users has grown, in order to meet the needs of more users, AtCoder has decided to increase the number of contests to 26 types, from AAC to AZC. For convenience, we number these 26 types as type 1 through type 26. AtCoder wants to schedule contests for D days so that user satisfaction is as high as possible. For every day, AtCoder will hold exactly one contest, and each contest will end on that day. The satisfaction is calculated as follows.
* The satisfaction at the beginning of day 1 is 0. Satisfaction can be negative.
* Holding contests increases satisfaction. The amount of increase will vary depending on a variety of factors. Specifically, we know in advance that holding a contest of type i on day d will increase the satisfaction by s_{d,i}.
* If a particular type of contest is not held for a while, the satisfaction decreases. Each contest type i has an integer c_i, and at the end of each day d=1,2,...,D, the satisfaction decreases as follows. Let \mathrm{last}(d,i) be the last day before day d (including d) on which a contest of type i was held. If contests of type i have never been held yet, we define \mathrm{last}(d,i)=0. At the end of day d, the satisfaction decreases by \sum _{i=1}^{26}c_i \times (d-\mathrm{last}(d,i)).
Please schedule contests on behalf of AtCoder. If the satisfaction at the end of day D is S, you will get a score of \max(10^6 + S, 0). There are 50 test cases, and the score of a submission is the total scores for each test case. You can make submissions multiple times, and the highest score among your submissions will be your score.
Constraints
* D = 365
* Each c_i is an integer satisfying 0\leq c_i \leq 100.
* Each s_{d,i} is an integer satisfying 0\leq s_{d,i} \leq 20000.
Input
Input is given from Standard Input in the following format:
D
c_1 c_2 \cdots c_{26}
s_{1,1} s_{1,2} \cdots s_{1,26}
\vdots
s_{D,1} s_{D,2} \cdots s_{D,26}
Output
Let t_d (1\leq t_d \leq 26) be the type of the contest that will be held at day d. Print D integers t_d to Standard Output in the following format:
t_1
t_2
\vdots
t_D
Any output that does not follow the above format may result in ~~0 points~~ WA for that test case.
Input Generation
Each integer c_i and s_{d,i} is generated independently and uniformly at random from the integers in the range described in the problem statement.
Example
Input
5
86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192
Output
1
17
13
14
13
Submitted Solution:
```
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
import time, random
start = time.time()
D = int(input())
c = list(map(int, input().split()))
s = [None]*D
for i in range(D):
s[i] = list(map(int, input().split()))
current = [0]*26
ans = [None]*D
def greedy():
ans = [None]*D
for i,ss in enumerate(s):
vs = [None]*26
for j in range(26):
vs[j] = (ss[j] + current[j], j)
current[j] += c[j]
vs.sort()
v = vs[-1][1]
ans[i] = v+1
current[v] = 0
return ans
def val(ans):
current = [0]*26
val = 0
for i,(ss, v) in enumerate(zip(s, ans)):
for j in range(26):
current[j] += c[j]
current[v-1] = 0
val += ss[i] - sum(current)
return val
ans = greedy()
num = 2
ren = 0
while (time.time()-start)<=1.90:
v = val(ans)
# print(v)
index = random.sample(range(D),num)
prev = index[0]
tmp = ans[prev]
tmpans = ans[:]
for ind in index[1:]:
ans[prev] = ans[ind]
prev = ind
ans[index[-1]] = tmp
if v<val(ans):
pass
else:
ren += 1
if ren>=100:
num = min(num+1, D)
res = 0
ans = tmpans
# print(v)
write("\n".join(map(str, ans)))
```
No
| 74,767 | [
0.42822265625,
0.1236572265625,
-0.2347412109375,
0.262939453125,
-0.58984375,
-0.544921875,
-0.339599609375,
0.3818359375,
0.10064697265625,
0.64404296875,
0.51220703125,
-0.50244140625,
-0.03131103515625,
-1.017578125,
-0.0633544921875,
-0.297607421875,
-0.391357421875,
-0.835937... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
AtCoder currently hosts three types of contests: ABC, ARC, and AGC. As the number of users has grown, in order to meet the needs of more users, AtCoder has decided to increase the number of contests to 26 types, from AAC to AZC. For convenience, we number these 26 types as type 1 through type 26. AtCoder wants to schedule contests for D days so that user satisfaction is as high as possible. For every day, AtCoder will hold exactly one contest, and each contest will end on that day. The satisfaction is calculated as follows.
* The satisfaction at the beginning of day 1 is 0. Satisfaction can be negative.
* Holding contests increases satisfaction. The amount of increase will vary depending on a variety of factors. Specifically, we know in advance that holding a contest of type i on day d will increase the satisfaction by s_{d,i}.
* If a particular type of contest is not held for a while, the satisfaction decreases. Each contest type i has an integer c_i, and at the end of each day d=1,2,...,D, the satisfaction decreases as follows. Let \mathrm{last}(d,i) be the last day before day d (including d) on which a contest of type i was held. If contests of type i have never been held yet, we define \mathrm{last}(d,i)=0. At the end of day d, the satisfaction decreases by \sum _{i=1}^{26}c_i \times (d-\mathrm{last}(d,i)).
Please schedule contests on behalf of AtCoder. If the satisfaction at the end of day D is S, you will get a score of \max(10^6 + S, 0). There are 50 test cases, and the score of a submission is the total scores for each test case. You can make submissions multiple times, and the highest score among your submissions will be your score.
Constraints
* D = 365
* Each c_i is an integer satisfying 0\leq c_i \leq 100.
* Each s_{d,i} is an integer satisfying 0\leq s_{d,i} \leq 20000.
Input
Input is given from Standard Input in the following format:
D
c_1 c_2 \cdots c_{26}
s_{1,1} s_{1,2} \cdots s_{1,26}
\vdots
s_{D,1} s_{D,2} \cdots s_{D,26}
Output
Let t_d (1\leq t_d \leq 26) be the type of the contest that will be held at day d. Print D integers t_d to Standard Output in the following format:
t_1
t_2
\vdots
t_D
Any output that does not follow the above format may result in ~~0 points~~ WA for that test case.
Input Generation
Each integer c_i and s_{d,i} is generated independently and uniformly at random from the integers in the range described in the problem statement.
Example
Input
5
86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192
Output
1
17
13
14
13
Submitted Solution:
```
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
D = I()
c = [0] + LI()
s = [0] + [[0] + LI() for _ in range(D)]
last = [[0]*27 for _ in range(D+1)]
t = [0]
for i in range(1,D+1):
r = 0
manzoku = 0
for j in range(1,27):
m = s[i][j]
for k in range(1,27):
if k != j:
m -= c[k]*(i-last[i-1][k])
else:
continue
if j == 1:
r = 1
manzoku = m
else:
if manzoku < m:
manzoku = m
r = j
t.append(r)
for j in range(1,27):
if j == r:
last[i][j] = i
else:
last[i][j] = last[i-1][j]
M = D*26
dq = []
for i in range(1,D+1):
for j in range(1,27):
dq.append([i,j])
from copy import deepcopy
for i in range(M):
d,q = dq[i]
t0 = t[d]
last2 = deepcopy(last)
manzoku = s[d][q] - s[d][t0]
for j in range(d,D+1):
if j == d:
last2[d][t0] = last2[d-1][t0]
manzoku -= c[t0] * (d - last2[d][t0])
last2[d][q] = d
manzoku += c[q] * (d - last2[d-1][q])
else:
if last2[j][t0] == d:
last2[j][t0] = last2[d-1][t0]
manzoku -= c[t0] * (d - last2[d][t0])
if last2[j][q] == last2[d-1][q]:
last2[j][q] = d
manzoku += c[q] * (d - last2[d-1][q])
if manzoku > 0:
t[d] = q
last = last2
del t[0]
print(*t,sep='\n')
```
No
| 74,768 | [
0.42822265625,
0.1236572265625,
-0.2347412109375,
0.262939453125,
-0.58984375,
-0.544921875,
-0.339599609375,
0.3818359375,
0.10064697265625,
0.64404296875,
0.51220703125,
-0.50244140625,
-0.03131103515625,
-1.017578125,
-0.0633544921875,
-0.297607421875,
-0.391357421875,
-0.835937... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
AtCoder currently hosts three types of contests: ABC, ARC, and AGC. As the number of users has grown, in order to meet the needs of more users, AtCoder has decided to increase the number of contests to 26 types, from AAC to AZC. For convenience, we number these 26 types as type 1 through type 26. AtCoder wants to schedule contests for D days so that user satisfaction is as high as possible. For every day, AtCoder will hold exactly one contest, and each contest will end on that day. The satisfaction is calculated as follows.
* The satisfaction at the beginning of day 1 is 0. Satisfaction can be negative.
* Holding contests increases satisfaction. The amount of increase will vary depending on a variety of factors. Specifically, we know in advance that holding a contest of type i on day d will increase the satisfaction by s_{d,i}.
* If a particular type of contest is not held for a while, the satisfaction decreases. Each contest type i has an integer c_i, and at the end of each day d=1,2,...,D, the satisfaction decreases as follows. Let \mathrm{last}(d,i) be the last day before day d (including d) on which a contest of type i was held. If contests of type i have never been held yet, we define \mathrm{last}(d,i)=0. At the end of day d, the satisfaction decreases by \sum _{i=1}^{26}c_i \times (d-\mathrm{last}(d,i)).
Please schedule contests on behalf of AtCoder. If the satisfaction at the end of day D is S, you will get a score of \max(10^6 + S, 0). There are 50 test cases, and the score of a submission is the total scores for each test case. You can make submissions multiple times, and the highest score among your submissions will be your score.
Constraints
* D = 365
* Each c_i is an integer satisfying 0\leq c_i \leq 100.
* Each s_{d,i} is an integer satisfying 0\leq s_{d,i} \leq 20000.
Input
Input is given from Standard Input in the following format:
D
c_1 c_2 \cdots c_{26}
s_{1,1} s_{1,2} \cdots s_{1,26}
\vdots
s_{D,1} s_{D,2} \cdots s_{D,26}
Output
Let t_d (1\leq t_d \leq 26) be the type of the contest that will be held at day d. Print D integers t_d to Standard Output in the following format:
t_1
t_2
\vdots
t_D
Any output that does not follow the above format may result in ~~0 points~~ WA for that test case.
Input Generation
Each integer c_i and s_{d,i} is generated independently and uniformly at random from the integers in the range described in the problem statement.
Example
Input
5
86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192
Output
1
17
13
14
13
Submitted Solution:
```
ans = [1]*365
for i in range(365):
ans[i]=i%25 + 2
for i in range(365):
print(i,ans[i])
```
No
| 74,769 | [
0.42822265625,
0.1236572265625,
-0.2347412109375,
0.262939453125,
-0.58984375,
-0.544921875,
-0.339599609375,
0.3818359375,
0.10064697265625,
0.64404296875,
0.51220703125,
-0.50244140625,
-0.03131103515625,
-1.017578125,
-0.0633544921875,
-0.297607421875,
-0.391357421875,
-0.835937... | 11 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural power.
Takahashi himself, on the other hand, will score 0 on all the exams without studying more. For each hour of study, he can increase his score on some exam by 1. (He can only study for an integer number of hours.) However, he cannot score more than X on an exam, since the perfect score for all the exams is X.
Print the minimum number of study hours required for Takahashi to win.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq X \leq 10^5
* 0 \leq b_i \leq X (1 \leq i \leq N)
* 1 \leq l_i \leq u_i \leq 10^5 (1 \leq i \leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
Output
Print the minimum number of study hours required for Takahashi to win.
Examples
Input
2 100
85 2 3
60 1 1
Output
115
Input
2 100
85 2 3
60 10 10
Output
77
Input
1 100000
31415 2718 2818
Output
31415
Input
10 1000
451 4593 6263
324 310 6991
378 1431 7068
71 1757 9218
204 3676 4328
840 6221 9080
684 1545 8511
709 5467 8674
862 6504 9835
283 4965 9980
Output
2540
"Correct Solution:
```
from itertools import accumulate
N, X = map(int, input().split())
BLUs = [tuple(map(int, input().split())) for _ in range(N)]
vs = [(L*B + U*(X-B), i) for i, (B, L, U) in enumerate(BLUs)]
vs.sort(reverse=True)
accV = 0
accVs = [0]
for v, i in vs:
accV += v
accVs.append(accV)
D0 = -sum([L*B for B, L, U in BLUs])
def isOK(k):
q = k // X
r = k % X
for odr, (v, i) in enumerate(vs):
B, L, U = BLUs[i]
d = D0
if odr < q:
d += accVs[q+1] - v
else:
d += accVs[q]
if r <= B:
d += L*r
else:
d += L*B + U*(r-B)
if d >= 0:
return True
return False
ng, ok = -1, N*X
while abs(ok-ng) > 1:
mid = (ng+ok) // 2
if isOK(mid):
ok = mid
else:
ng = mid
print(ok)
```
| 74,802 | [
0.452880859375,
0.2171630859375,
0.0278167724609375,
0.01236724853515625,
-0.29638671875,
-0.09625244140625,
0.0946044921875,
-0.025665283203125,
-0.09765625,
0.9228515625,
0.58349609375,
0.139892578125,
0.09454345703125,
-1.0771484375,
-0.51318359375,
-0.158203125,
-0.7724609375,
... | 11 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural power.
Takahashi himself, on the other hand, will score 0 on all the exams without studying more. For each hour of study, he can increase his score on some exam by 1. (He can only study for an integer number of hours.) However, he cannot score more than X on an exam, since the perfect score for all the exams is X.
Print the minimum number of study hours required for Takahashi to win.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq X \leq 10^5
* 0 \leq b_i \leq X (1 \leq i \leq N)
* 1 \leq l_i \leq u_i \leq 10^5 (1 \leq i \leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
Output
Print the minimum number of study hours required for Takahashi to win.
Examples
Input
2 100
85 2 3
60 1 1
Output
115
Input
2 100
85 2 3
60 10 10
Output
77
Input
1 100000
31415 2718 2818
Output
31415
Input
10 1000
451 4593 6263
324 310 6991
378 1431 7068
71 1757 9218
204 3676 4328
840 6221 9080
684 1545 8511
709 5467 8674
862 6504 9835
283 4965 9980
Output
2540
"Correct Solution:
```
import sys
n, x = list(map(int, input().split()))
exams = []
norma = 0
for i, line in enumerate(sys.stdin):
b, l, u = map(int, line.split())
exams.append((u * x - b * (u - l), b, l, u, i))
norma += b * l
exams_sorted = sorted(exams, reverse=True)
remain_norma = norma
sub_d = -1
i = 0
used = set()
for i, (d, b, l, u, ei) in enumerate(exams_sorted):
if remain_norma < d:
sub_d = d
break
remain_norma -= d
used.add(ei)
if sub_d == -1:
print(n * x)
exit()
base_ans = i * x
base_remain_norma = remain_norma
ans = 10 ** 10
for d, b, l, u, i in exams:
if i in used:
curr_remain_norma = base_remain_norma + d - sub_d
else:
curr_remain_norma = base_remain_norma
if curr_remain_norma <= b * l:
extra = (curr_remain_norma - 1) // l + 1
else:
extra = (curr_remain_norma + b * (u - l) - 1) // u + 1
if extra > x:
continue
ans = min(ans, base_ans + extra)
print(ans)
```
| 74,803 | [
0.46826171875,
0.2330322265625,
0.032867431640625,
0.025299072265625,
-0.302001953125,
-0.06005859375,
0.08758544921875,
-0.0253448486328125,
-0.0843505859375,
0.9228515625,
0.58154296875,
0.1395263671875,
0.0869140625,
-1.0673828125,
-0.52880859375,
-0.1492919921875,
-0.7509765625,
... | 11 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural power.
Takahashi himself, on the other hand, will score 0 on all the exams without studying more. For each hour of study, he can increase his score on some exam by 1. (He can only study for an integer number of hours.) However, he cannot score more than X on an exam, since the perfect score for all the exams is X.
Print the minimum number of study hours required for Takahashi to win.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq X \leq 10^5
* 0 \leq b_i \leq X (1 \leq i \leq N)
* 1 \leq l_i \leq u_i \leq 10^5 (1 \leq i \leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
Output
Print the minimum number of study hours required for Takahashi to win.
Examples
Input
2 100
85 2 3
60 1 1
Output
115
Input
2 100
85 2 3
60 10 10
Output
77
Input
1 100000
31415 2718 2818
Output
31415
Input
10 1000
451 4593 6263
324 310 6991
378 1431 7068
71 1757 9218
204 3676 4328
840 6221 9080
684 1545 8511
709 5467 8674
862 6504 9835
283 4965 9980
Output
2540
"Correct Solution:
```
n, x = list(map(int, input().split()))
B = 0
blu = []
s = [0 for i in range(n)]
for i in range(n):
b, l, u = list(map(int, input().split()))
blu.append((b, l, u, x*u-b*u+b*l))
B += b*l
blu.sort(key=lambda x: x[3], reverse=True)
for i in range(n):
if i==0:
s[i] = blu[i][3]
else:
s[i] = s[i-1] + blu[i][3]
ok = n*x
ng = -1
while ok-ng>1:
A = 0
mid = (ok+ng)//2
k = mid//x
t = mid%x
for i in range(n):
if t<=blu[i][0]:
rm = t*blu[i][1]
else:
rm = t*blu[i][2] - blu[i][0]*(blu[i][2]-blu[i][1])
if k==0:
A = max(A, rm)
elif i<k:
A = max(A, s[k]-blu[i][3]+rm)
else:
A = max(A, s[k-1]+rm)
if A>=B:
ok = mid
else:
ng = mid
print(ok)
```
| 74,804 | [
0.453857421875,
0.219970703125,
0.029083251953125,
0.0115966796875,
-0.302490234375,
-0.09967041015625,
0.096435546875,
-0.0275115966796875,
-0.10443115234375,
0.92041015625,
0.5849609375,
0.1424560546875,
0.09857177734375,
-1.078125,
-0.5126953125,
-0.1552734375,
-0.77734375,
-0.7... | 11 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural power.
Takahashi himself, on the other hand, will score 0 on all the exams without studying more. For each hour of study, he can increase his score on some exam by 1. (He can only study for an integer number of hours.) However, he cannot score more than X on an exam, since the perfect score for all the exams is X.
Print the minimum number of study hours required for Takahashi to win.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq X \leq 10^5
* 0 \leq b_i \leq X (1 \leq i \leq N)
* 1 \leq l_i \leq u_i \leq 10^5 (1 \leq i \leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
Output
Print the minimum number of study hours required for Takahashi to win.
Examples
Input
2 100
85 2 3
60 1 1
Output
115
Input
2 100
85 2 3
60 10 10
Output
77
Input
1 100000
31415 2718 2818
Output
31415
Input
10 1000
451 4593 6263
324 310 6991
378 1431 7068
71 1757 9218
204 3676 4328
840 6221 9080
684 1545 8511
709 5467 8674
862 6504 9835
283 4965 9980
Output
2540
"Correct Solution:
```
import math
INF = 10**18
n, x = [int(item) for item in input().split()]
blu = [[int(item) for item in input().split()] for _ in range(n)]
s_score_list = []
full_score_list = []
for i, (b, l, u) in enumerate(blu):
s_score_list.append(b * l)
full_score_list.append([(x-b) * u + b * l, i])
s_score = sum(s_score_list)
full_score_list.sort(reverse=True)
t_score = 0
full_score_set = set()
for i in range(n):
full_score_set.add(full_score_list[i][1])
t_score += full_score_list[i][0]
if t_score >= s_score:
last_index = full_score_list[i][1]
surplus = t_score - s_score
shortage = s_score - t_score + full_score_list[i][0]
break
# Minimize time in full-score-set
max_reduction = 0
for i, (b, l, u) in enumerate(blu):
if i in full_score_set:
if (x-b) * u >= surplus:
max_reduction = max(max_reduction, int(math.floor(surplus / u)))
elif (x-b) * u + b * l >= surplus:
max_reduction = max(max_reduction, (x-b) + int(math.floor((surplus - (x-b)*u) / l)))
ans = x * len(full_score_set) - max_reduction
# Take lest of score in not full_scores
full_score_set.remove(last_index)
min_promotion = INF
for i, (b, l, u) in enumerate(blu):
if i in full_score_set:
continue
if b*l >= shortage:
min_promotion = min(min_promotion, int(math.ceil(shortage / l)))
elif b*l + (x-b)*u >= shortage:
min_promotion = min(min_promotion, b + int(math.ceil((shortage - b*l) / u)))
ans = min(ans, min_promotion + x * len(full_score_set))
print(ans)
```
| 74,805 | [
0.459716796875,
0.21728515625,
0.01361846923828125,
0.00972747802734375,
-0.283203125,
-0.073974609375,
0.0911865234375,
-0.0210723876953125,
-0.0855712890625,
0.927734375,
0.57421875,
0.146484375,
0.0933837890625,
-1.072265625,
-0.497802734375,
-0.1455078125,
-0.77001953125,
-0.75... | 11 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural power.
Takahashi himself, on the other hand, will score 0 on all the exams without studying more. For each hour of study, he can increase his score on some exam by 1. (He can only study for an integer number of hours.) However, he cannot score more than X on an exam, since the perfect score for all the exams is X.
Print the minimum number of study hours required for Takahashi to win.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq X \leq 10^5
* 0 \leq b_i \leq X (1 \leq i \leq N)
* 1 \leq l_i \leq u_i \leq 10^5 (1 \leq i \leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
Output
Print the minimum number of study hours required for Takahashi to win.
Examples
Input
2 100
85 2 3
60 1 1
Output
115
Input
2 100
85 2 3
60 10 10
Output
77
Input
1 100000
31415 2718 2818
Output
31415
Input
10 1000
451 4593 6263
324 310 6991
378 1431 7068
71 1757 9218
204 3676 4328
840 6221 9080
684 1545 8511
709 5467 8674
862 6504 9835
283 4965 9980
Output
2540
"Correct Solution:
```
N, X = map(int, input().split())
items = []
for i in range(N):
b, l, u = map(int, input().split())
items.append((b, l, u, u * (X - b), - b * l))
items = sorted(items, key=lambda x: -(x[3] - x[4]))
def f(num):
cnt = num // X
mod = num % X
point = 0
for i in range(cnt):
point += items[i][3]
for i in range(cnt, N):
point += items[i][4]
if mod == 0:
if point >= 0:
return True
else:
return False
else:
tmp = -float("inf")
for i, tmp2 in enumerate(items):
b, l, u, d1, d2 = tmp2
if mod >= b:
mul = u * (mod - b)
else:
mul = l * (mod - b)
if i < cnt:
tmp = max(tmp, point - d1 + mul + items[cnt][3] - items[cnt][4])
else:
tmp = max(tmp, point - d2 + mul)
if tmp >= 0:
return True
else:
return False
ok = N * X + 1
ng = - 1
while (ok - ng) > 1:
mid = (ok + ng) // 2
if f(mid):
ok = mid
else:
ng = mid
print(ok)
```
| 74,806 | [
0.453857421875,
0.219970703125,
0.029083251953125,
0.0115966796875,
-0.302490234375,
-0.09967041015625,
0.096435546875,
-0.0275115966796875,
-0.10443115234375,
0.92041015625,
0.5849609375,
0.1424560546875,
0.09857177734375,
-1.078125,
-0.5126953125,
-0.1552734375,
-0.77734375,
-0.7... | 11 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural power.
Takahashi himself, on the other hand, will score 0 on all the exams without studying more. For each hour of study, he can increase his score on some exam by 1. (He can only study for an integer number of hours.) However, he cannot score more than X on an exam, since the perfect score for all the exams is X.
Print the minimum number of study hours required for Takahashi to win.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq X \leq 10^5
* 0 \leq b_i \leq X (1 \leq i \leq N)
* 1 \leq l_i \leq u_i \leq 10^5 (1 \leq i \leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
Output
Print the minimum number of study hours required for Takahashi to win.
Examples
Input
2 100
85 2 3
60 1 1
Output
115
Input
2 100
85 2 3
60 10 10
Output
77
Input
1 100000
31415 2718 2818
Output
31415
Input
10 1000
451 4593 6263
324 310 6991
378 1431 7068
71 1757 9218
204 3676 4328
840 6221 9080
684 1545 8511
709 5467 8674
862 6504 9835
283 4965 9980
Output
2540
"Correct Solution:
```
from itertools import accumulate
import sys
input = sys.stdin.readline
def solve():
N, X = map(int, input().split())
tests = []
D0 = 0
for _ in range(N):
B, L, U = map(int, input().split())
v = L*B + U*(X-B)
tests.append((v, B, L, U))
D0 -= L*B
tests.sort(reverse=True)
accVs = list(accumulate([0] + tests, lambda accX, X: accX + X[0]))
def isOK(k):
q = k // X
r = k % X
accV = accVs[q+1]
for v, B, L, U in tests[:q]:
d = D0 + accV - v
if r <= B:
d += L*r
else:
d += L*B + U*(r-B)
if d >= 0:
return True
accV = accVs[q]
for v, B, L, U in tests[q:]:
d = D0 + accV
if r <= B:
d += L*r
else:
d += L*B + U*(r-B)
if d >= 0:
return True
return False
ng, ok = -1, N*X
while abs(ok-ng) > 1:
mid = (ng+ok) // 2
if isOK(mid):
ok = mid
else:
ng = mid
return ok
print(solve())
```
| 74,807 | [
0.452880859375,
0.2171630859375,
0.0278167724609375,
0.01236724853515625,
-0.29638671875,
-0.09625244140625,
0.0946044921875,
-0.025665283203125,
-0.09765625,
0.9228515625,
0.58349609375,
0.139892578125,
0.09454345703125,
-1.0771484375,
-0.51318359375,
-0.158203125,
-0.7724609375,
... | 11 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural power.
Takahashi himself, on the other hand, will score 0 on all the exams without studying more. For each hour of study, he can increase his score on some exam by 1. (He can only study for an integer number of hours.) However, he cannot score more than X on an exam, since the perfect score for all the exams is X.
Print the minimum number of study hours required for Takahashi to win.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq X \leq 10^5
* 0 \leq b_i \leq X (1 \leq i \leq N)
* 1 \leq l_i \leq u_i \leq 10^5 (1 \leq i \leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
Output
Print the minimum number of study hours required for Takahashi to win.
Examples
Input
2 100
85 2 3
60 1 1
Output
115
Input
2 100
85 2 3
60 10 10
Output
77
Input
1 100000
31415 2718 2818
Output
31415
Input
10 1000
451 4593 6263
324 310 6991
378 1431 7068
71 1757 9218
204 3676 4328
840 6221 9080
684 1545 8511
709 5467 8674
862 6504 9835
283 4965 9980
Output
2540
"Correct Solution:
```
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def II(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
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 SI(): return input()
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
from bisect import bisect_right, bisect_left
def main():
N, X = LI()
b_l_u = []
for i in range(N):
b_l_u.append(LI())
sum_of_test = [ (b_l_u_i[1]*b_l_u_i[0]+b_l_u_i[2]*(X-b_l_u_i[0]), i) for i,b_l_u_i in enumerate(b_l_u)]
sum_of_test.sort(reverse=True) # O(nlogn)
cumsum_of_test = []
tmp = 0
for i in sum_of_test: # O(n)
tmp += i[0]
cumsum_of_test.append(tmp)
B = sum([l*b for b, l, u in b_l_u]) # O(n)
head = bisect_right(cumsum_of_test, B)-1
cumsum = cumsum_of_test[head]
take_li = []
for j, (sum_, i) in enumerate(sum_of_test): # O(N)
# cumsum の中に入っていたら、引く。
if j <= head:
new_head = bisect_right(cumsum_of_test, B+sum_)-1 # O(log N)
new_cumsum = cumsum_of_test[new_head] - sum_
left = B - new_cumsum
take_1 = X * new_head
else:
left = B - cumsum
take_1 = X*(head+1)
if head==-1: # i番目を下からとっていくコードのみでOK.
left = B
take_1 = 0
b, l, u = b_l_u[i]
from math import ceil
if left/l <= b:
take = ceil(left/l)
else:
take = b + ceil((left - b*l)/u)
if take > X: continue
take_li.append(take+take_1)
print(min(take_li))
main()
```
| 74,808 | [
0.46826171875,
0.2330322265625,
0.032867431640625,
0.025299072265625,
-0.302001953125,
-0.06005859375,
0.08758544921875,
-0.0253448486328125,
-0.0843505859375,
0.9228515625,
0.58154296875,
0.1395263671875,
0.0869140625,
-1.0673828125,
-0.52880859375,
-0.1492919921875,
-0.7509765625,
... | 11 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural power.
Takahashi himself, on the other hand, will score 0 on all the exams without studying more. For each hour of study, he can increase his score on some exam by 1. (He can only study for an integer number of hours.) However, he cannot score more than X on an exam, since the perfect score for all the exams is X.
Print the minimum number of study hours required for Takahashi to win.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq X \leq 10^5
* 0 \leq b_i \leq X (1 \leq i \leq N)
* 1 \leq l_i \leq u_i \leq 10^5 (1 \leq i \leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
Output
Print the minimum number of study hours required for Takahashi to win.
Examples
Input
2 100
85 2 3
60 1 1
Output
115
Input
2 100
85 2 3
60 10 10
Output
77
Input
1 100000
31415 2718 2818
Output
31415
Input
10 1000
451 4593 6263
324 310 6991
378 1431 7068
71 1757 9218
204 3676 4328
840 6221 9080
684 1545 8511
709 5467 8674
862 6504 9835
283 4965 9980
Output
2540
"Correct Solution:
```
N,X=map(int,input().split())
blu=[list(map(int,input().split())) for i in range(N)]
S=0
data=[]
low=0
high=0
for i in range(N):
b,l,u=blu[i]
high+=b
data.append([u*(X-b)+l*b,i])
S-=b*l
data.sort(reverse=True)
lst=[data[0][0]]
lsls=[data[0][1]]
for i in range(1,N):
lst.append(lst[-1]+data[i][0])
lsls.append(data[i][1])
while high-low>1:
mid=(high+low)//2
ppp=mid//X
qqq=mid%X
SS=S
if ppp>0:
SS+=lst[ppp-1]
num=0
for i in range(ppp,N):
b,l,u=blu[lsls[i]]
if qqq>=b:
num1=b*l+(qqq-b)*u
else:
num1=qqq*l
num=max(num,num1)
SS+=num
SSS=S+lst[ppp]
num=-float("inf")
for i in range(ppp):
zzz,ind=data[i]
b,l,u=blu[ind]
if qqq>=b:
num1=-zzz+b*l+(qqq-b)*u
else:
num1=-zzz+qqq*l
num=max(num,num1)
SSS+=num
SS=max(SS,SSS)
if SS>=0:
high=mid
else:
low=mid
print(high)
```
| 74,809 | [
0.453857421875,
0.219970703125,
0.029083251953125,
0.0115966796875,
-0.302490234375,
-0.09967041015625,
0.096435546875,
-0.0275115966796875,
-0.10443115234375,
0.92041015625,
0.5849609375,
0.1424560546875,
0.09857177734375,
-1.078125,
-0.5126953125,
-0.1552734375,
-0.77734375,
-0.7... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural power.
Takahashi himself, on the other hand, will score 0 on all the exams without studying more. For each hour of study, he can increase his score on some exam by 1. (He can only study for an integer number of hours.) However, he cannot score more than X on an exam, since the perfect score for all the exams is X.
Print the minimum number of study hours required for Takahashi to win.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq X \leq 10^5
* 0 \leq b_i \leq X (1 \leq i \leq N)
* 1 \leq l_i \leq u_i \leq 10^5 (1 \leq i \leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
Output
Print the minimum number of study hours required for Takahashi to win.
Examples
Input
2 100
85 2 3
60 1 1
Output
115
Input
2 100
85 2 3
60 10 10
Output
77
Input
1 100000
31415 2718 2818
Output
31415
Input
10 1000
451 4593 6263
324 310 6991
378 1431 7068
71 1757 9218
204 3676 4328
840 6221 9080
684 1545 8511
709 5467 8674
862 6504 9835
283 4965 9980
Output
2540
Submitted Solution:
```
import sys,heapq,time
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
DBG = True and False
def ddprint(x):
if DBG:
print(x)
n,x = inm()
blu = []
pt = 0
for i in range(n):
b,l,u = inm()
s = u*(x-b) + l*b
v = s/x
t = x
heapq.heappush(blu, (-v,s,t,b,l,u,i))
pt -= l*b
if pt==0:
print(0)
exit()
ans = []
reached = False
sum = 0
while len(blu)>0:
mv,s,t,b,l,u,r = heapq.heappop(blu)
nxtpt = pt + s
ddprint("v {} s {} t {} b {} l {} u {} pt {} nx {} sum {}".format(-mv,s,t,b,l,u,pt,nxtpt,sum))
if nxtpt < 0:
ans.append((s,b,l,u))
pt = nxtpt
sum += t
continue
elif nxtpt == 0: # < (u if pt+l*b<0 else l):
if not reached:
ans.append((s,b,l,u))
pt2 = pt + u*x - u*b + l*b
sum += t
break
else: # nxtpt > 0
m = pt + l*b
ddprint("m {}".format(m))
if m>=0:
t = (-pt+l-1)//l
else:
m = -m
t = b + (m+u-1)//u
if not reached:
ans.append((s,b,l,u))
pt2 = pt + u*x - u*b + l*b
reached = True
s = -pt
ddprint("s/t {} s {} t {}".format(s/t,s,t))
heapq.heappush(blu, (-s/t,s,t,b,l,u,-1))
sum2 = x * (len(ans)-1)
for z in ans[:-1]:
s,b,l,u = z
pt = pt2 - s
m = pt + l*b
if m>=0:
t = (-pt+l-1)//l
else:
t = b+(-m+u-1)//u
if sum2+t < sum:
sum = sum2+t
print(sum)
```
Yes
| 74,810 | [
0.432373046875,
0.194580078125,
-0.01171875,
0.0894775390625,
-0.322509765625,
-0.09814453125,
0.040283203125,
0.0035610198974609375,
-0.1361083984375,
0.99169921875,
0.6083984375,
0.20849609375,
0.0155792236328125,
-1.0224609375,
-0.46923828125,
-0.209228515625,
-0.72509765625,
-0... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural power.
Takahashi himself, on the other hand, will score 0 on all the exams without studying more. For each hour of study, he can increase his score on some exam by 1. (He can only study for an integer number of hours.) However, he cannot score more than X on an exam, since the perfect score for all the exams is X.
Print the minimum number of study hours required for Takahashi to win.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq X \leq 10^5
* 0 \leq b_i \leq X (1 \leq i \leq N)
* 1 \leq l_i \leq u_i \leq 10^5 (1 \leq i \leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
Output
Print the minimum number of study hours required for Takahashi to win.
Examples
Input
2 100
85 2 3
60 1 1
Output
115
Input
2 100
85 2 3
60 10 10
Output
77
Input
1 100000
31415 2718 2818
Output
31415
Input
10 1000
451 4593 6263
324 310 6991
378 1431 7068
71 1757 9218
204 3676 4328
840 6221 9080
684 1545 8511
709 5467 8674
862 6504 9835
283 4965 9980
Output
2540
Submitted Solution:
```
import sys
input = sys.stdin.readline
from itertools import accumulate
def main():
N,X=map(int,input().split())
A=[list(map(int,input().split())) for i in range(N)]
A.sort(key=lambda x:x[2]*(X-x[0])+x[0]*x[1],reverse=True)
ALL=[a[2]*(X-a[0])+a[0]*a[1] for a in A]
SUM=[0]+list(accumulate(ALL))
MAX=0
MINUS=0
for a,r,l in A:
MAX+=a
MINUS+=a*r
OUT=-1
def binsearch(score):
alluse=score//X
rest=score-alluse*X
for ri in range(N):
plus=0
b,l,u=A[ri]
if rest<b:
plus+=rest*l
else:
plus+=rest*u+b*l-b*u
if alluse<=ri:
plus+=SUM[alluse]
else:
plus+=SUM[alluse+1]-ALL[ri]
#print(score,ri,plus)
if plus>=MINUS:
return 1
return 0
while MAX-OUT>1:
mid=(MAX+OUT)//2
if binsearch(mid)==1:
MAX=mid
else:
OUT=mid
print(MAX)
main()
```
Yes
| 74,811 | [
0.432373046875,
0.194580078125,
-0.01171875,
0.0894775390625,
-0.322509765625,
-0.09814453125,
0.040283203125,
0.0035610198974609375,
-0.1361083984375,
0.99169921875,
0.6083984375,
0.20849609375,
0.0155792236328125,
-1.0224609375,
-0.46923828125,
-0.209228515625,
-0.72509765625,
-0... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural power.
Takahashi himself, on the other hand, will score 0 on all the exams without studying more. For each hour of study, he can increase his score on some exam by 1. (He can only study for an integer number of hours.) However, he cannot score more than X on an exam, since the perfect score for all the exams is X.
Print the minimum number of study hours required for Takahashi to win.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq X \leq 10^5
* 0 \leq b_i \leq X (1 \leq i \leq N)
* 1 \leq l_i \leq u_i \leq 10^5 (1 \leq i \leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
Output
Print the minimum number of study hours required for Takahashi to win.
Examples
Input
2 100
85 2 3
60 1 1
Output
115
Input
2 100
85 2 3
60 10 10
Output
77
Input
1 100000
31415 2718 2818
Output
31415
Input
10 1000
451 4593 6263
324 310 6991
378 1431 7068
71 1757 9218
204 3676 4328
840 6221 9080
684 1545 8511
709 5467 8674
862 6504 9835
283 4965 9980
Output
2540
Submitted Solution:
```
from operator import itemgetter
N, X = map(int, input().split())
S = [list(map(int, input().split())) for i in range(N)]
A = []
aoki = 0
for i, (b, l, u) in enumerate(S):
A.append([(X-b)*u + (b)*l, i])
aoki += b*l
A.sort(reverse=True, key=itemgetter(0))
ans = 0
tak = 0
for iaaaa, (a, i) in enumerate(A):
if aoki >= a:
aoki -= a
ans += X
if aoki==0:
print(ans)
exit()
else:
break
mi = float("inf")
aoki_ = aoki
for j in range(iaaaa, N):
a, i = A[j]
b, l, u = S[i]
aoki = aoki_
an, m = divmod(aoki, l)
if m!=0:
an += 1
mi = min(mi, an)
aoki += (u-l) * b
an, m = divmod(aoki, u)
if m!=0:
an += 1
mi = min(mi, an)
ans_ = ans + mi
a, i = A[iaaaa]
aoki_ -= a
#aoki_ = -aoki
anss = (iaaaa)*X
mi = float("inf")
for a, i in A[:iaaaa]:
b, l, u = S[i]
aoki = aoki_ + a
an, m = divmod(aoki, l)
if m!=0:
an += 1
mi = min(mi, an)
aoki += (u-l) * b
an, m = divmod(aoki, u)
if m!=0:
an += 1
mi = min(mi, an)
print(min(ans_, anss+mi))
```
Yes
| 74,812 | [
0.432373046875,
0.194580078125,
-0.01171875,
0.0894775390625,
-0.322509765625,
-0.09814453125,
0.040283203125,
0.0035610198974609375,
-0.1361083984375,
0.99169921875,
0.6083984375,
0.20849609375,
0.0155792236328125,
-1.0224609375,
-0.46923828125,
-0.209228515625,
-0.72509765625,
-0... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural power.
Takahashi himself, on the other hand, will score 0 on all the exams without studying more. For each hour of study, he can increase his score on some exam by 1. (He can only study for an integer number of hours.) However, he cannot score more than X on an exam, since the perfect score for all the exams is X.
Print the minimum number of study hours required for Takahashi to win.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq X \leq 10^5
* 0 \leq b_i \leq X (1 \leq i \leq N)
* 1 \leq l_i \leq u_i \leq 10^5 (1 \leq i \leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
Output
Print the minimum number of study hours required for Takahashi to win.
Examples
Input
2 100
85 2 3
60 1 1
Output
115
Input
2 100
85 2 3
60 10 10
Output
77
Input
1 100000
31415 2718 2818
Output
31415
Input
10 1000
451 4593 6263
324 310 6991
378 1431 7068
71 1757 9218
204 3676 4328
840 6221 9080
684 1545 8511
709 5467 8674
862 6504 9835
283 4965 9980
Output
2540
Submitted Solution:
```
# 解説
def accumulate(a):
su = 0
yield su
for x in a:
su += x
yield su
def solve_agc034c():
from collections import namedtuple
import sys
input = sys.stdin.readline
Test = namedtuple('Test', 'Aoki_score lower_bound upper_bound')
Test.D_partial = lambda self, score: \
self.lower_bound * score if score <= self.Aoki_score \
else self.upper_bound * score - (self.upper_bound - self.lower_bound) * self.Aoki_score
def is_ok(init_rest):
"""init_rest: 勉強に使える時間"""
take, rest = divmod(init_rest, X)
if take > N - 1:
r = take - (N - 1)
take = N - 1
rest += r * X
for i, partial_solve_test in enumerate(tests, start=1):
when_full = partial_solve_test.D_partial(X)
if i <= take:
su = acc[take + 1] - when_full
else:
su = acc[take]
when_partial = partial_solve_test.D_partial(min(X, rest))
d = INIT_D + su + when_partial
if d >= 0:
return True
return False
def binary_search(*, ok, ng, is_ok):
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if is_ok(mid):
ok = mid
else:
ng = mid
return ok
N, X = map(int, input().split())
tests = []
for _ in range(N):
row = map(int, input().split())
tests.append(Test(*row))
tests.sort(key=lambda test: test.D_partial(X), reverse=True)
# 勝つ科目と負ける科目を決める
# 勝つ科目は重要度をupper_boundにする
# 負ける科目は重要度をlower_boundにする
INIT_D = -sum(test.lower_bound * test.Aoki_score for test in tests)
*acc, = accumulate(test.D_partial(X) for test in tests)
res = binary_search(ok=10 ** 10, ng=-1, is_ok=is_ok)
# D>=0となる勉強時間
print(res)
return
if __name__ == '__main__':
solve_agc034c()
```
Yes
| 74,813 | [
0.432373046875,
0.194580078125,
-0.01171875,
0.0894775390625,
-0.322509765625,
-0.09814453125,
0.040283203125,
0.0035610198974609375,
-0.1361083984375,
0.99169921875,
0.6083984375,
0.20849609375,
0.0155792236328125,
-1.0224609375,
-0.46923828125,
-0.209228515625,
-0.72509765625,
-0... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural power.
Takahashi himself, on the other hand, will score 0 on all the exams without studying more. For each hour of study, he can increase his score on some exam by 1. (He can only study for an integer number of hours.) However, he cannot score more than X on an exam, since the perfect score for all the exams is X.
Print the minimum number of study hours required for Takahashi to win.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq X \leq 10^5
* 0 \leq b_i \leq X (1 \leq i \leq N)
* 1 \leq l_i \leq u_i \leq 10^5 (1 \leq i \leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
Output
Print the minimum number of study hours required for Takahashi to win.
Examples
Input
2 100
85 2 3
60 1 1
Output
115
Input
2 100
85 2 3
60 10 10
Output
77
Input
1 100000
31415 2718 2818
Output
31415
Input
10 1000
451 4593 6263
324 310 6991
378 1431 7068
71 1757 9218
204 3676 4328
840 6221 9080
684 1545 8511
709 5467 8674
862 6504 9835
283 4965 9980
Output
2540
Submitted Solution:
```
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
DBG = True and False
def ddprint(x):
if DBG:
print(x)
n,x = inm()
blu = []
pt = 0
for i in range(n):
b,l,u = inm()
v = u - (u-l)*b/x
blu.append((v,b,l,u))
pt -= l*b
blu.sort()
sum = 0
while len(blu)>0:
v,b,l,u = blu.pop()
nxtpt = pt + l*b + u*(x-b)
ddprint("v {} b {} l {} u {} pt {} nx {} sum {}".format(v,b,l,u,pt,nxtpt,sum))
if nxtpt < 0:
pt = nxtpt
sum += x
continue
elif nxtpt == 0:
pt = 0
sum += x
print(sum)
exit()
else: # nxtpt > 0
blu.append((v,b,l,u))
break
# on the next step, we can go above zero
mn = 999999999
for z in blu:
v,b,l,u = z
m = pt + l*b
ddprint("m {}".format(m))
if m>=0:
t = b - (m)//l
else:
m = -m
t = b + (m+u-1)//u
if t>x:
continue
if t<mn:
mn = t
print(sum+mn)
```
No
| 74,814 | [
0.432373046875,
0.194580078125,
-0.01171875,
0.0894775390625,
-0.322509765625,
-0.09814453125,
0.040283203125,
0.0035610198974609375,
-0.1361083984375,
0.99169921875,
0.6083984375,
0.20849609375,
0.0155792236328125,
-1.0224609375,
-0.46923828125,
-0.209228515625,
-0.72509765625,
-0... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural power.
Takahashi himself, on the other hand, will score 0 on all the exams without studying more. For each hour of study, he can increase his score on some exam by 1. (He can only study for an integer number of hours.) However, he cannot score more than X on an exam, since the perfect score for all the exams is X.
Print the minimum number of study hours required for Takahashi to win.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq X \leq 10^5
* 0 \leq b_i \leq X (1 \leq i \leq N)
* 1 \leq l_i \leq u_i \leq 10^5 (1 \leq i \leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
Output
Print the minimum number of study hours required for Takahashi to win.
Examples
Input
2 100
85 2 3
60 1 1
Output
115
Input
2 100
85 2 3
60 10 10
Output
77
Input
1 100000
31415 2718 2818
Output
31415
Input
10 1000
451 4593 6263
324 310 6991
378 1431 7068
71 1757 9218
204 3676 4328
840 6221 9080
684 1545 8511
709 5467 8674
862 6504 9835
283 4965 9980
Output
2540
Submitted Solution:
```
N,X=map(int,input().split())
blu=[list(map(int,input().split())) for i in range(N)]
S=0
data=[]
for i in range(N):
b,l,u=blu[i]
data.append([u*(X-b)+l*b,i])
S-=b*l
data.sort(reverse=True)
flag=[0]*N
ans=0
for i in range(N):
SS=S+data[i][0]
if SS<0:
S=SS
flag[data[i][1]]=1
ans+=X
else:
break
num=float("inf")
for i in range(N):
if flag[i]==1:
continue
b,l,u=blu[i]
if (S+b*l)%u==0:
a=b-(S+b*l)//u
else:
a=b-(S+b*l)//u+1
if S%l==0:
a=min(a,-S//l)
else:
a=min(a,-S//l+1)
num=min(num,a)
ans+=num
print(ans)
```
No
| 74,815 | [
0.432373046875,
0.194580078125,
-0.01171875,
0.0894775390625,
-0.322509765625,
-0.09814453125,
0.040283203125,
0.0035610198974609375,
-0.1361083984375,
0.99169921875,
0.6083984375,
0.20849609375,
0.0155792236328125,
-1.0224609375,
-0.46923828125,
-0.209228515625,
-0.72509765625,
-0... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural power.
Takahashi himself, on the other hand, will score 0 on all the exams without studying more. For each hour of study, he can increase his score on some exam by 1. (He can only study for an integer number of hours.) However, he cannot score more than X on an exam, since the perfect score for all the exams is X.
Print the minimum number of study hours required for Takahashi to win.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq X \leq 10^5
* 0 \leq b_i \leq X (1 \leq i \leq N)
* 1 \leq l_i \leq u_i \leq 10^5 (1 \leq i \leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
Output
Print the minimum number of study hours required for Takahashi to win.
Examples
Input
2 100
85 2 3
60 1 1
Output
115
Input
2 100
85 2 3
60 10 10
Output
77
Input
1 100000
31415 2718 2818
Output
31415
Input
10 1000
451 4593 6263
324 310 6991
378 1431 7068
71 1757 9218
204 3676 4328
840 6221 9080
684 1545 8511
709 5467 8674
862 6504 9835
283 4965 9980
Output
2540
Submitted Solution:
```
def get(list,n):
sum=0
a=[]
for i in range(len(list)):
sum+=list[i][0]*list[i][1]
a.append([(n-list[i][0])*list[i][2],i])
a.sort()
i,z=0,True
count=0
a.reverse()
while i<len(a) and z:
sum-=(100*list[a[i][1]][2])
count+=100
if sum<0:
z=False
else:
i+=1
sum+=100*list[a[i][1]][2]
count-=100
if sum%(list[a[i][1]][2])==0:
count+=sum//list[a[i][1]][2]
else:
count+=sum//(list[a[i][1]][2]+1)
return count
m=list(map(int,input().strip().split()))
l=[]
for i in range(m[0]):
l.append(list(map(int,input().strip().split())))
print(get(l,m[1]))
```
No
| 74,816 | [
0.432373046875,
0.194580078125,
-0.01171875,
0.0894775390625,
-0.322509765625,
-0.09814453125,
0.040283203125,
0.0035610198974609375,
-0.1361083984375,
0.99169921875,
0.6083984375,
0.20849609375,
0.0155792236328125,
-1.0224609375,
-0.46923828125,
-0.209228515625,
-0.72509765625,
-0... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural power.
Takahashi himself, on the other hand, will score 0 on all the exams without studying more. For each hour of study, he can increase his score on some exam by 1. (He can only study for an integer number of hours.) However, he cannot score more than X on an exam, since the perfect score for all the exams is X.
Print the minimum number of study hours required for Takahashi to win.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq X \leq 10^5
* 0 \leq b_i \leq X (1 \leq i \leq N)
* 1 \leq l_i \leq u_i \leq 10^5 (1 \leq i \leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
Output
Print the minimum number of study hours required for Takahashi to win.
Examples
Input
2 100
85 2 3
60 1 1
Output
115
Input
2 100
85 2 3
60 10 10
Output
77
Input
1 100000
31415 2718 2818
Output
31415
Input
10 1000
451 4593 6263
324 310 6991
378 1431 7068
71 1757 9218
204 3676 4328
840 6221 9080
684 1545 8511
709 5467 8674
862 6504 9835
283 4965 9980
Output
2540
Submitted Solution:
```
n,x = map(int,input().split())
base_score =0
my_score = 0
ans = 0
b = []
l = []
u = []
sco = []
for i in range(n):
ba,la,ua = map(int,input().split())
b.append(ba)
l.append(la)
u.append(ua)
sco.append([ba,la,ua])
base_score += ba*la
#print(base_score)
for i in range(n):
sco[i].append((x*sco[i][2])-(sco[i][0]*(sco[i][2]-sco[i][1])))
sco = sorted(sco, key = lambda a: a[3] )
#print(sco)
while my_score<=base_score:
if (base_score - my_score) <= sco[-1][3]:
k = base_score - my_score
#print(k)
my_score = base_score+1
ans += ((k-1)//sco[-1][1])+1
else:
my_score += sco[-1][3]
ans += x
sco.pop(-1)
#print(sco)
#print(base_score,my_score,ans)
print(ans)
```
No
| 74,817 | [
0.432373046875,
0.194580078125,
-0.01171875,
0.0894775390625,
-0.322509765625,
-0.09814453125,
0.040283203125,
0.0035610198974609375,
-0.1361083984375,
0.99169921875,
0.6083984375,
0.20849609375,
0.0155792236328125,
-1.0224609375,
-0.46923828125,
-0.209228515625,
-0.72509765625,
-0... | 11 |
Provide a correct Python 3 solution for this coding contest problem.
Ms. Iyo Kiffa-Australis has a balance and only two kinds of weights to measure a dose of medicine.
For example, to measure 200mg of aspirin using 300mg weights and 700mg weights, she can put one 700mg weight on the side of the medicine and three 300mg weights on the opposite side (Figure 1). Although she could put four 300mg weights on the medicine side and two 700mg weights on the other (Figure 2), she would not choose this solution because it is less convenient to use more weights.
You are asked to help her by calculating how many weights are required.
<image>
Figure 1: To measure 200mg of aspirin using three 300mg weights and one 700mg weight
<image>
Figure 2: To measure 200mg of aspirin using four 300mg weights and two 700mg weights
Input
The input is a sequence of datasets. A dataset is a line containing three positive integers a, b, and d separated by a space. The following relations hold: a ≠ b, a ≤ 10000, b ≤ 10000, and d ≤ 50000. You may assume that it is possible to measure d mg using a combination of a mg and b mg weights. In other words, you need not consider “no solution” cases.
The end of the input is indicated by a line containing three zeros separated by a space. It is not a dataset.
Output
The output should be composed of lines, each corresponding to an input dataset (a, b, d). An output line should contain two nonnegative integers x and y separated by a space. They should satisfy the following three conditions.
* You can measure d mg using x many a mg weights and y many b mg weights.
* The total number of weights (x + y) is the smallest among those pairs of nonnegative integers satisfying the previous condition.
* The total mass of weights (ax + by) is the smallest among those pairs of nonnegative integers satisfying the previous two conditions.
No extra characters (e.g. extra spaces) should appear in the output.
Example
Input
700 300 200
500 200 300
500 200 500
275 110 330
275 110 385
648 375 4002
3 1 10000
0 0 0
Output
1 3
1 1
1 0
0 3
1 1
49 74
3333 1
"Correct Solution:
```
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = I()
return l
def LIR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = LI()
return l
def SR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = S()
return l
def LSR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = LS()
return l
sys.setrecursionlimit(1000000)
mod = 1000000007
#A
def A():
s = S()
d = 0
ans = 0
k = 0
for i in s:
if i == "R":
if d == 0:
k = 1
d += 1
d %= 4
if d == 0 and k:ans += 1
else:
if d == 0:
k = 0
d -= 1
d %= 4
print(ans)
return
#B
def B():
while 1:
a,b,d = LI()
if a == b == d == 0:
quit()
ans = []
l = []
m = float("inf")
for x in range(-50000,50001):
if (d-a*x)%b == 0:
y = (d-a*x)//b
k = abs(x)+abs(y)
if k < m:
m = k
for x in range(-50000,50001):
if (d-a*x)%b == 0:
y = (d-a*x)//b
k = abs(x)+abs(y)
if k == m:
ans.append((abs(x),abs(y)))
l.append(a*abs(x)+b*abs(y))
print(*ans[l.index(min(l))])
return
#C
def C():
return
#D
def D():
return
#E
def E():
return
#F
def F():
return
#G
def G():
return
#H
def H():
return
#I
def I_():
return
#J
def J():
return
#Solve
if __name__ == "__main__":
B()
```
| 74,889 | [
0.37109375,
0.06787109375,
0.05108642578125,
0.109375,
-0.9794921875,
-0.23681640625,
0.239013671875,
0.38818359375,
-0.053863525390625,
0.607421875,
0.331787109375,
-0.5712890625,
0.09478759765625,
-0.6181640625,
-0.418701171875,
0.51513671875,
-0.826171875,
-0.91845703125,
-0.1... | 11 |
Provide a correct Python 3 solution for this coding contest problem.
Ms. Iyo Kiffa-Australis has a balance and only two kinds of weights to measure a dose of medicine.
For example, to measure 200mg of aspirin using 300mg weights and 700mg weights, she can put one 700mg weight on the side of the medicine and three 300mg weights on the opposite side (Figure 1). Although she could put four 300mg weights on the medicine side and two 700mg weights on the other (Figure 2), she would not choose this solution because it is less convenient to use more weights.
You are asked to help her by calculating how many weights are required.
<image>
Figure 1: To measure 200mg of aspirin using three 300mg weights and one 700mg weight
<image>
Figure 2: To measure 200mg of aspirin using four 300mg weights and two 700mg weights
Input
The input is a sequence of datasets. A dataset is a line containing three positive integers a, b, and d separated by a space. The following relations hold: a ≠ b, a ≤ 10000, b ≤ 10000, and d ≤ 50000. You may assume that it is possible to measure d mg using a combination of a mg and b mg weights. In other words, you need not consider “no solution” cases.
The end of the input is indicated by a line containing three zeros separated by a space. It is not a dataset.
Output
The output should be composed of lines, each corresponding to an input dataset (a, b, d). An output line should contain two nonnegative integers x and y separated by a space. They should satisfy the following three conditions.
* You can measure d mg using x many a mg weights and y many b mg weights.
* The total number of weights (x + y) is the smallest among those pairs of nonnegative integers satisfying the previous condition.
* The total mass of weights (ax + by) is the smallest among those pairs of nonnegative integers satisfying the previous two conditions.
No extra characters (e.g. extra spaces) should appear in the output.
Example
Input
700 300 200
500 200 300
500 200 500
275 110 330
275 110 385
648 375 4002
3 1 10000
0 0 0
Output
1 3
1 1
1 0
0 3
1 1
49 74
3333 1
"Correct 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 = 10**9+7
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():
rr = []
while True:
a,b,c = LI()
if a == 0:
break
r = inf
x = inf
y = inf
for i in range(c*5):
t = a * i
if t < c and (c - t) % b == 0:
tr = c
tx = i
ty = (c-t) // b
if x+y > tx+ty or (x+y==tx+ty and r > tr):
r = tr
x = tx
y = ty
if t >= c and (t-c) % b == 0:
tr = t - c + t
tx = i
ty = (t-c) // b
if x+y > tx+ty or (x+y==tx+ty and r > tr):
r = tr
x = tx
y = ty
if (t+c) % b == 0:
tr = t + c + t
tx = i
ty = (t+c) // b
if x+y > tx+ty or (x+y==tx+ty and r > tr):
r = tr
x = tx
y = ty
rr.append('{} {}'.format(x,y))
return '\n'.join(map(str,rr))
print(main())
```
| 74,890 | [
0.348388671875,
0.042633056640625,
0.05194091796875,
0.10784912109375,
-0.98291015625,
-0.245849609375,
0.2059326171875,
0.356689453125,
-0.06842041015625,
0.59814453125,
0.32275390625,
-0.5810546875,
0.10577392578125,
-0.62646484375,
-0.405029296875,
0.509765625,
-0.8447265625,
-0... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ms. Iyo Kiffa-Australis has a balance and only two kinds of weights to measure a dose of medicine.
For example, to measure 200mg of aspirin using 300mg weights and 700mg weights, she can put one 700mg weight on the side of the medicine and three 300mg weights on the opposite side (Figure 1). Although she could put four 300mg weights on the medicine side and two 700mg weights on the other (Figure 2), she would not choose this solution because it is less convenient to use more weights.
You are asked to help her by calculating how many weights are required.
<image>
Figure 1: To measure 200mg of aspirin using three 300mg weights and one 700mg weight
<image>
Figure 2: To measure 200mg of aspirin using four 300mg weights and two 700mg weights
Input
The input is a sequence of datasets. A dataset is a line containing three positive integers a, b, and d separated by a space. The following relations hold: a ≠ b, a ≤ 10000, b ≤ 10000, and d ≤ 50000. You may assume that it is possible to measure d mg using a combination of a mg and b mg weights. In other words, you need not consider “no solution” cases.
The end of the input is indicated by a line containing three zeros separated by a space. It is not a dataset.
Output
The output should be composed of lines, each corresponding to an input dataset (a, b, d). An output line should contain two nonnegative integers x and y separated by a space. They should satisfy the following three conditions.
* You can measure d mg using x many a mg weights and y many b mg weights.
* The total number of weights (x + y) is the smallest among those pairs of nonnegative integers satisfying the previous condition.
* The total mass of weights (ax + by) is the smallest among those pairs of nonnegative integers satisfying the previous two conditions.
No extra characters (e.g. extra spaces) should appear in the output.
Example
Input
700 300 200
500 200 300
500 200 500
275 110 330
275 110 385
648 375 4002
3 1 10000
0 0 0
Output
1 3
1 1
1 0
0 3
1 1
49 74
3333 1
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 = 10**9+7
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():
rr = []
while True:
a,b,c = LI()
if a == 0:
break
r = inf
x = inf
y = inf
for i in range(c+1):
t = a * i
if t < c and (c - t) % b == 0:
tr = c
tx = i
ty = (c-t) // b
if x+y > tx+ty or (x+y==tx+ty and r > tr):
r = tr
x = tx
y = ty
if t >= c and (t-c) % b == 0:
tr = t - c + t
tx = i
ty = (t-c) // b
if x+y > tx+ty or (x+y==tx+ty and r > tr):
r = tr
x = tx
y = ty
if (t+c) % b == 0:
tr = t + c + t
tx = i
ty = (t+c) // b
if x+y > tx+ty or (x+y==tx+ty and r > tr):
r = tr
x = tx
y = ty
rr.append('{} {}'.format(x,y))
return '\n'.join(map(str,rr))
print(main())
```
No
| 74,891 | [
0.363037109375,
0.16796875,
0.13427734375,
0.0992431640625,
-1.0498046875,
-0.15234375,
0.1629638671875,
0.380615234375,
-0.049041748046875,
0.552734375,
0.300048828125,
-0.5087890625,
0.0634765625,
-0.67529296875,
-0.422119140625,
0.53759765625,
-0.720703125,
-0.92724609375,
-0.... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Little Elephant loves playing with arrays. He has array a, consisting of n positive integers, indexed from 1 to n. Let's denote the number with index i as ai.
Additionally the Little Elephant has m queries to the array, each query is characterised by a pair of integers lj and rj (1 ≤ lj ≤ rj ≤ n). For each query lj, rj the Little Elephant has to count, how many numbers x exist, such that number x occurs exactly x times among numbers alj, alj + 1, ..., arj.
Help the Little Elephant to count the answers to all queries.
Input
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the size of array a and the number of queries to it. The next line contains n space-separated positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). Next m lines contain descriptions of queries, one per line. The j-th of these lines contains the description of the j-th query as two space-separated integers lj and rj (1 ≤ lj ≤ rj ≤ n).
Output
In m lines print m integers — the answers to the queries. The j-th line should contain the answer to the j-th query.
Examples
Input
7 2
3 1 2 2 3 3 7
1 7
3 4
Output
3
1
Submitted Solution:
```
import sys
from collections import Counter
input=sys.stdin.readline
n,m=map(int,input().split())
a=list(map(int,input().split()))
cnt=Counter(a)
maybe={}
for val,c in cnt.items(): # count which may be in each [l:r] and label
if c>=val:
l=len(maybe)
maybe[val]=l
# len(maybe)~sqrt(n)
pref=[[0]*len(maybe)]
for i in range(n):
pref.append(pref[-1][:])
if a[i] in maybe:
pref[-1][maybe[a[i]]]+=1
for _ in range(m):
l,r=map(int,input().split())
cur=0
for val,c in maybe.items():
if pref[r][c]-pref[l-1][c]==val:
cur+=1
print(cur)
```
Yes
| 75,327 | [
0.4140625,
0.385009765625,
-0.0528564453125,
0.062744140625,
-0.454345703125,
-0.455810546875,
-0.21142578125,
0.45556640625,
0.442138671875,
0.888671875,
0.416015625,
0.1292724609375,
-0.3017578125,
-0.72412109375,
-0.537109375,
0.359375,
-0.66845703125,
-0.73388671875,
-0.75585... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Little Elephant loves playing with arrays. He has array a, consisting of n positive integers, indexed from 1 to n. Let's denote the number with index i as ai.
Additionally the Little Elephant has m queries to the array, each query is characterised by a pair of integers lj and rj (1 ≤ lj ≤ rj ≤ n). For each query lj, rj the Little Elephant has to count, how many numbers x exist, such that number x occurs exactly x times among numbers alj, alj + 1, ..., arj.
Help the Little Elephant to count the answers to all queries.
Input
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the size of array a and the number of queries to it. The next line contains n space-separated positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). Next m lines contain descriptions of queries, one per line. The j-th of these lines contains the description of the j-th query as two space-separated integers lj and rj (1 ≤ lj ≤ rj ≤ n).
Output
In m lines print m integers — the answers to the queries. The j-th line should contain the answer to the j-th query.
Examples
Input
7 2
3 1 2 2 3 3 7
1 7
3 4
Output
3
1
Submitted Solution:
```
from collections import defaultdict
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
n,m=map(int,input().split())
query=[[] for j in range(int(n**0.5)+1)]
arr=list(map(int,input().split()))
for j in range(m):
x,y=map(int,input().split())
query[int(x/n**0.5)].append([x-1,y-1,j])
q=[]
for j in query:
j.sort(key=lambda x:x[1])
for p in j:
q.append(p)
d=defaultdict(lambda:0)
j=0
currL,currR,x= 1,0,0
res=[0]*(m)
while(j<len(q)):
L,R=q[j][0],q[j][1]
while currL < L:
d[arr[currL]]-=1
if d[arr[currL]]==(arr[currL]-1):
x-=1
if d[arr[currL]] == (arr[currL]):
x += 1
currL += 1
while currL > L:
currL -= 1
d[arr[currL]] += 1
if d[arr[currL]]==(arr[currL]+1):
x-=1
if d[arr[currL]]==(arr[currL]):
x+=1
while currR<R:
currR += 1
d[arr[currR]] += 1
if d[arr[currR]]==(arr[currR]+1):
x-=1
if d[arr[currR]] == (arr[currR]):
x += 1
while currR > R:
d[arr[currR]] -= 1
if d[arr[currR]]==(arr[currR]-1):
x-=1
if d[arr[currR]] == (arr[currR]):
x += 1
currR -= 1
res[q[j][2]]=x
j+=1
for j in res:
print(j)
```
Yes
| 75,328 | [
0.4306640625,
0.3515625,
0.0183868408203125,
0.169921875,
-0.487548828125,
-0.4140625,
-0.1524658203125,
0.451904296875,
0.51220703125,
0.9248046875,
0.35791015625,
0.09088134765625,
-0.24755859375,
-0.7080078125,
-0.484619140625,
0.4130859375,
-0.5771484375,
-0.80615234375,
-0.7... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Little Elephant loves playing with arrays. He has array a, consisting of n positive integers, indexed from 1 to n. Let's denote the number with index i as ai.
Additionally the Little Elephant has m queries to the array, each query is characterised by a pair of integers lj and rj (1 ≤ lj ≤ rj ≤ n). For each query lj, rj the Little Elephant has to count, how many numbers x exist, such that number x occurs exactly x times among numbers alj, alj + 1, ..., arj.
Help the Little Elephant to count the answers to all queries.
Input
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the size of array a and the number of queries to it. The next line contains n space-separated positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). Next m lines contain descriptions of queries, one per line. The j-th of these lines contains the description of the j-th query as two space-separated integers lj and rj (1 ≤ lj ≤ rj ≤ n).
Output
In m lines print m integers — the answers to the queries. The j-th line should contain the answer to the j-th query.
Examples
Input
7 2
3 1 2 2 3 3 7
1 7
3 4
Output
3
1
Submitted Solution:
```
# -*- coding:utf-8 -*-
"""
created by shuangquan.huang at 1/8/20
for each query l, r; how many x that count of x in range [l, r] equals x
for each query ends with x, query (l, x) with Fenwick tree
"""
import collections
import time
import os
import sys
import bisect
import heapq
from typing import List
def solve(N, M, A, Q):
bit = [0 for _ in range(N)]
def add(index, val):
while index < N:
bit[index] += val
index |= index + 1
def query(index):
index = min(index, N-1)
s = 0
while index >= 0:
s += bit[index]
index = (index & (index + 1)) - 1
return s
q = collections.defaultdict(list)
for i, (l, r) in enumerate(Q):
q[r].append((l, i))
ans = [0 for _ in range(M)]
vi = collections.defaultdict(list)
for i, v in enumerate(A):
vi[v].append(i)
lv = len(vi[v])
if lv >= v:
add(i, 1)
if lv == v + 1:
add(vi[v][-v-1], -1)
if lv > v + 1:
add(vi[v][-v-2], 1)
for l, qi in q[i]:
ans[qi] = query(i) - query(l-1)
print('\n'.join(map(str, ans)))
N, M = map(int, input().split())
A = [int(x) for x in input().split()]
Q = []
for i in range(M):
l, r = map(int, input().split())
Q.append((l-1, r-1))
solve(N, M, A, Q)
```
No
| 75,334 | [
0.41259765625,
0.28271484375,
-0.022857666015625,
0.18505859375,
-0.41015625,
-0.43994140625,
-0.1800537109375,
0.42919921875,
0.4833984375,
0.88232421875,
0.367919921875,
0.09222412109375,
-0.259521484375,
-0.66796875,
-0.497314453125,
0.3720703125,
-0.564453125,
-0.6728515625,
... | 11 |
Provide tags and a correct Python 3 solution for this coding contest problem.
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.
To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.
Output
Print a single integer — the answer to the problem.
Examples
Input
3 5
1 2 3
1 2 2 3 3
Output
0
Input
3 5
1 2 3
1 1 1 1 1
Output
2
Input
3 1
2 3 4
1
Output
3
Note
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
Tags: brute force, greedy, two pointers
Correct Solution:
```
number_of_problems, number_of_prepared_problems = map(int, input().split())
required_problems = list(map(int, input().split()))
prepared_problems = list(map(int, input().split()))
idx_required = idx_prepared = 0
while idx_required < number_of_problems and idx_prepared < number_of_prepared_problems:
if prepared_problems[idx_prepared] >= required_problems[idx_required]:
idx_required += 1
idx_prepared += 1
result = number_of_problems - idx_required
print(result)
```
| 75,385 | [
0.68505859375,
-0.315673828125,
0.282958984375,
0.190185546875,
-0.5185546875,
-0.82080078125,
-0.1375732421875,
0.4560546875,
0.15283203125,
0.71044921875,
0.8837890625,
-0.4775390625,
-0.0230560302734375,
-0.935546875,
-0.20166015625,
-0.059173583984375,
-0.8017578125,
-0.6420898... | 11 |
Provide tags and a correct Python 3 solution for this coding contest problem.
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.
To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.
Output
Print a single integer — the answer to the problem.
Examples
Input
3 5
1 2 3
1 2 2 3 3
Output
0
Input
3 5
1 2 3
1 1 1 1 1
Output
2
Input
3 1
2 3 4
1
Output
3
Note
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
Tags: brute force, greedy, two pointers
Correct Solution:
```
def inp():
return map(int, input().split())
n, m = inp()
a = list(inp())
b = list(inp())
count = 0
j = 0
for i in range(n):
while j < m:
if b[j] >= a[i]:
count += 1
j += 1
break
else:
j += 1
print(n - count)
```
| 75,386 | [
0.68505859375,
-0.315673828125,
0.282958984375,
0.190185546875,
-0.5185546875,
-0.82080078125,
-0.1375732421875,
0.4560546875,
0.15283203125,
0.71044921875,
0.8837890625,
-0.4775390625,
-0.0230560302734375,
-0.935546875,
-0.20166015625,
-0.059173583984375,
-0.8017578125,
-0.6420898... | 11 |
Provide tags and a correct Python 3 solution for this coding contest problem.
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.
To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.
Output
Print a single integer — the answer to the problem.
Examples
Input
3 5
1 2 3
1 2 2 3 3
Output
0
Input
3 5
1 2 3
1 1 1 1 1
Output
2
Input
3 1
2 3 4
1
Output
3
Note
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
Tags: brute force, greedy, two pointers
Correct Solution:
```
n, m = list(map(int, input().rstrip().split()))
a = list(map(int, input().rstrip().split()))
b = list(map(int, input().rstrip().split()))
li = [0] * n
k = 0
for i in range(m):
#b[i]
for j in range(k, n):
if li[j] == 0 and a[j] <= b[i]:
li[j] = 1
k = j
break
count = 0
for i in li:
if i == 0:
count += 1
print(count)
```
| 75,387 | [
0.68505859375,
-0.315673828125,
0.282958984375,
0.190185546875,
-0.5185546875,
-0.82080078125,
-0.1375732421875,
0.4560546875,
0.15283203125,
0.71044921875,
0.8837890625,
-0.4775390625,
-0.0230560302734375,
-0.935546875,
-0.20166015625,
-0.059173583984375,
-0.8017578125,
-0.6420898... | 11 |
Provide tags and a correct Python 3 solution for this coding contest problem.
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.
To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.
Output
Print a single integer — the answer to the problem.
Examples
Input
3 5
1 2 3
1 2 2 3 3
Output
0
Input
3 5
1 2 3
1 1 1 1 1
Output
2
Input
3 1
2 3 4
1
Output
3
Note
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
Tags: brute force, greedy, two pointers
Correct Solution:
```
n, m = map(int,input().split())
must = list(map(int,input().split()))
have = list(map(int,input().split()))
mi = hi = 0
while mi<n and hi<m:
if must[mi]>have[hi]:
#move on to next have elem
hi+=1
else:
# move on to next needed must
mi+=1
hi+=1
print(n-mi)
```
| 75,388 | [
0.68505859375,
-0.315673828125,
0.282958984375,
0.190185546875,
-0.5185546875,
-0.82080078125,
-0.1375732421875,
0.4560546875,
0.15283203125,
0.71044921875,
0.8837890625,
-0.4775390625,
-0.0230560302734375,
-0.935546875,
-0.20166015625,
-0.059173583984375,
-0.8017578125,
-0.6420898... | 11 |
Provide tags and a correct Python 3 solution for this coding contest problem.
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.
To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.
Output
Print a single integer — the answer to the problem.
Examples
Input
3 5
1 2 3
1 2 2 3 3
Output
0
Input
3 5
1 2 3
1 1 1 1 1
Output
2
Input
3 1
2 3 4
1
Output
3
Note
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
Tags: brute force, greedy, two pointers
Correct Solution:
```
from bisect import bisect_left
def binr(a, x, lo=0, hi=None):
hi = hi if hi is not None else len(a)
pos = bisect_left(a,x,lo,hi)
if pos < hi:
return pos
else:
return -1
n,m = map(int,input().split())
d = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
fl = True
ans = 0
for i in d:
if (i not in a):
fl = False
if fl == True:
print(0)
exit()
for i in range(n):
if d[i] in a:
d[i] = 0
r = binr(a,d[i])
if r == -1:
ans += 1
else:
a[r] = -1
a.sort()
print(ans)
```
| 75,389 | [
0.68505859375,
-0.315673828125,
0.282958984375,
0.190185546875,
-0.5185546875,
-0.82080078125,
-0.1375732421875,
0.4560546875,
0.15283203125,
0.71044921875,
0.8837890625,
-0.4775390625,
-0.0230560302734375,
-0.935546875,
-0.20166015625,
-0.059173583984375,
-0.8017578125,
-0.6420898... | 11 |
Provide tags and a correct Python 3 solution for this coding contest problem.
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.
To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.
Output
Print a single integer — the answer to the problem.
Examples
Input
3 5
1 2 3
1 2 2 3 3
Output
0
Input
3 5
1 2 3
1 1 1 1 1
Output
2
Input
3 1
2 3 4
1
Output
3
Note
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
Tags: brute force, greedy, two pointers
Correct Solution:
```
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
i = j = 0
while i < n and j < m:
if a[i] <= b[j]:
i += 1
j += 1
print(n - i)
```
| 75,390 | [
0.68505859375,
-0.315673828125,
0.282958984375,
0.190185546875,
-0.5185546875,
-0.82080078125,
-0.1375732421875,
0.4560546875,
0.15283203125,
0.71044921875,
0.8837890625,
-0.4775390625,
-0.0230560302734375,
-0.935546875,
-0.20166015625,
-0.059173583984375,
-0.8017578125,
-0.6420898... | 11 |
Provide tags and a correct Python 3 solution for this coding contest problem.
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.
To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.
Output
Print a single integer — the answer to the problem.
Examples
Input
3 5
1 2 3
1 2 2 3 3
Output
0
Input
3 5
1 2 3
1 1 1 1 1
Output
2
Input
3 1
2 3 4
1
Output
3
Note
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
Tags: brute force, greedy, two pointers
Correct Solution:
```
n,m = map(int , input().split())
a = list(map(int , input().split()))
b = list(map(int , input().split()))
i=0
j=0
while i<n and j<m:
if a[i] <= b[j]:
i+=1
j+=1
print(n-i)
```
| 75,391 | [
0.68505859375,
-0.315673828125,
0.282958984375,
0.190185546875,
-0.5185546875,
-0.82080078125,
-0.1375732421875,
0.4560546875,
0.15283203125,
0.71044921875,
0.8837890625,
-0.4775390625,
-0.0230560302734375,
-0.935546875,
-0.20166015625,
-0.059173583984375,
-0.8017578125,
-0.6420898... | 11 |
Provide tags and a correct Python 3 solution for this coding contest problem.
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.
To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.
Output
Print a single integer — the answer to the problem.
Examples
Input
3 5
1 2 3
1 2 2 3 3
Output
0
Input
3 5
1 2 3
1 1 1 1 1
Output
2
Input
3 1
2 3 4
1
Output
3
Note
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
Tags: brute force, greedy, two pointers
Correct Solution:
```
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt = 0
j = 0
for i in range(n):
while j < m:
if a[i] <= b[j]:
cnt += 1
j += 1
break
else:
j += 1
print(n - cnt)
```
| 75,392 | [
0.68505859375,
-0.315673828125,
0.282958984375,
0.190185546875,
-0.5185546875,
-0.82080078125,
-0.1375732421875,
0.4560546875,
0.15283203125,
0.71044921875,
0.8837890625,
-0.4775390625,
-0.0230560302734375,
-0.935546875,
-0.20166015625,
-0.059173583984375,
-0.8017578125,
-0.6420898... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.
To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.
Output
Print a single integer — the answer to the problem.
Examples
Input
3 5
1 2 3
1 2 2 3 3
Output
0
Input
3 5
1 2 3
1 1 1 1 1
Output
2
Input
3 1
2 3 4
1
Output
3
Note
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
Submitted Solution:
```
n, m = map(int, input().split())
a = [int(k) for k in input().split()]
b = [int(j) for j in input().split()]
f = 0
f1 = 0
while f < n and f1 < m:
if b[f1] >= a[f]:
f += 1
f1 += 1
print(n - f)
```
Yes
| 75,393 | [
0.72607421875,
-0.224365234375,
0.2010498046875,
0.1341552734375,
-0.6474609375,
-0.64111328125,
-0.2427978515625,
0.5419921875,
0.07958984375,
0.67578125,
0.7392578125,
-0.401123046875,
-0.05780029296875,
-0.89990234375,
-0.21240234375,
-0.1737060546875,
-0.75341796875,
-0.6733398... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.
To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.
Output
Print a single integer — the answer to the problem.
Examples
Input
3 5
1 2 3
1 2 2 3 3
Output
0
Input
3 5
1 2 3
1 1 1 1 1
Output
2
Input
3 1
2 3 4
1
Output
3
Note
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
Submitted Solution:
```
n, m = map(int, input().split())
good = list(map(int, input().split()))
prepared = list(map(int, input().split()))
i = 0
j = 0
count = 0 # Number of good prepared problems
while i < n and j < m:
if prepared[j] >= good[i]:
i += 1
j += 1
count += 1
else:
j += 1
print(n - count)
```
Yes
| 75,394 | [
0.72607421875,
-0.224365234375,
0.2010498046875,
0.1341552734375,
-0.6474609375,
-0.64111328125,
-0.2427978515625,
0.5419921875,
0.07958984375,
0.67578125,
0.7392578125,
-0.401123046875,
-0.05780029296875,
-0.89990234375,
-0.21240234375,
-0.1737060546875,
-0.75341796875,
-0.6733398... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.
To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.
Output
Print a single integer — the answer to the problem.
Examples
Input
3 5
1 2 3
1 2 2 3 3
Output
0
Input
3 5
1 2 3
1 1 1 1 1
Output
2
Input
3 1
2 3 4
1
Output
3
Note
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
Submitted Solution:
```
ii=lambda:int(input())
kk=lambda:map(int, input().split())
ll=lambda:list(kk())
n,m=kk()
ps,bs=ll(),ll()
b=c=0
for a in range(n):
while b<m and bs[b]<ps[a]: b+=1
if b==m:c+=1
else:b+=1
print(c)
```
Yes
| 75,395 | [
0.72607421875,
-0.224365234375,
0.2010498046875,
0.1341552734375,
-0.6474609375,
-0.64111328125,
-0.2427978515625,
0.5419921875,
0.07958984375,
0.67578125,
0.7392578125,
-0.401123046875,
-0.05780029296875,
-0.89990234375,
-0.21240234375,
-0.1737060546875,
-0.75341796875,
-0.6733398... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.
To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.
Output
Print a single integer — the answer to the problem.
Examples
Input
3 5
1 2 3
1 2 2 3 3
Output
0
Input
3 5
1 2 3
1 1 1 1 1
Output
2
Input
3 1
2 3 4
1
Output
3
Note
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
Submitted Solution:
```
# Method 1:
# n, m = map(int, input().split(' '))
# a = list(map(int, input().split(' ')))
# b = list(map(int, input().split(' ')))
#
# i = j = 0
# while i < n and j < m:
# if b[j] >= a[i]:
# i += 1
# j += 1
# else:
# j += 1
# print(n - i)
# Method 2:
def inp():
return map(int, input().split())
n, m = inp()
a = list(inp())
b = list(inp())
count = 0
j = 0
for i in range(n):
while j < m:
if b[j] >= a[i]:
count += 1
j += 1
break
else:
j += 1
print(n - count)
'''
Note:
Example:
3 5
1 2 3
1 1 1 4 5
while i < n and j < m (stopping condition)
if b[j] >= a[i]:
i ++
j ++
else:
j ++
ans = n - i
time complexity: O(m) vì chỉ có mỗi biến j tăng sau mỗi vòng lặp
- why use 2 pointers:
+ 2 mảng đã đc sắp xếp
+ 2 biến chạy, ko cần reset biến chạy sau mỗi vòng lặp
'''
```
Yes
| 75,396 | [
0.72607421875,
-0.224365234375,
0.2010498046875,
0.1341552734375,
-0.6474609375,
-0.64111328125,
-0.2427978515625,
0.5419921875,
0.07958984375,
0.67578125,
0.7392578125,
-0.401123046875,
-0.05780029296875,
-0.89990234375,
-0.21240234375,
-0.1737060546875,
-0.75341796875,
-0.6733398... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.
To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.
Output
Print a single integer — the answer to the problem.
Examples
Input
3 5
1 2 3
1 2 2 3 3
Output
0
Input
3 5
1 2 3
1 1 1 1 1
Output
2
Input
3 1
2 3 4
1
Output
3
Note
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
Submitted Solution:
```
n,m = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = [0]* len(A)
for i in range(len(A)):
C[i] = A[i]
A.sort()
B.sort()
k = 0
def search_index(x, A):
# ищет левый индекс максимально близкого и меньшего или равного числу x
l = -1
r = len(A)
while r - l > 1:
m = int((l + r) / 2)
if A[m] <= x:
l = m
else:
r = m
return l
i = len(A) - 1
j = len(B) - 1
if len(B) >= len(A):
while i > -1 and j > -1:
if B[j] < A[i]:
k += 1
i -= 1
j -= 1
if j == -1 and i > 0:
k += i+1
else:
k = len(A)
q = len(A)
for y in range(len(B)-1,-1,-1):
w = search_index(B[y],A[:q])
q = w
if w == -1:
break
else:
k -= 1
print(k)
```
No
| 75,397 | [
0.72607421875,
-0.224365234375,
0.2010498046875,
0.1341552734375,
-0.6474609375,
-0.64111328125,
-0.2427978515625,
0.5419921875,
0.07958984375,
0.67578125,
0.7392578125,
-0.401123046875,
-0.05780029296875,
-0.89990234375,
-0.21240234375,
-0.1737060546875,
-0.75341796875,
-0.6733398... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.
To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.
Output
Print a single integer — the answer to the problem.
Examples
Input
3 5
1 2 3
1 2 2 3 3
Output
0
Input
3 5
1 2 3
1 1 1 1 1
Output
2
Input
3 1
2 3 4
1
Output
3
Note
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
Submitted Solution:
```
#Problem 1 George & Round
first = input('').split()
n = int(first[0])
m = int(first[1])
listA = list(map(int,input('').split()))
listB = list(map(int,input('').split()))
count = 0
for i in range(0, len(listA)):
if listA[i] not in listB:
count += 1
print(count)
```
No
| 75,398 | [
0.72607421875,
-0.224365234375,
0.2010498046875,
0.1341552734375,
-0.6474609375,
-0.64111328125,
-0.2427978515625,
0.5419921875,
0.07958984375,
0.67578125,
0.7392578125,
-0.401123046875,
-0.05780029296875,
-0.89990234375,
-0.21240234375,
-0.1737060546875,
-0.75341796875,
-0.6733398... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.
To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.
Output
Print a single integer — the answer to the problem.
Examples
Input
3 5
1 2 3
1 2 2 3 3
Output
0
Input
3 5
1 2 3
1 1 1 1 1
Output
2
Input
3 1
2 3 4
1
Output
3
Note
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
Submitted Solution:
```
n, m = map(int, input().split())
ns = set(map(int, input().split()))
bs = set(map(int, input().split()))
print(n - len(ns & bs))
```
No
| 75,399 | [
0.72607421875,
-0.224365234375,
0.2010498046875,
0.1341552734375,
-0.6474609375,
-0.64111328125,
-0.2427978515625,
0.5419921875,
0.07958984375,
0.67578125,
0.7392578125,
-0.401123046875,
-0.05780029296875,
-0.89990234375,
-0.21240234375,
-0.1737060546875,
-0.75341796875,
-0.6733398... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.
To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.
Output
Print a single integer — the answer to the problem.
Examples
Input
3 5
1 2 3
1 2 2 3 3
Output
0
Input
3 5
1 2 3
1 1 1 1 1
Output
2
Input
3 1
2 3 4
1
Output
3
Note
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
Submitted Solution:
```
n,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = set(b)
a = set(a)
z = c.intersection(a)
if(n<m):
print(abs(n-m))
else:
print(n-len(z))
```
No
| 75,400 | [
0.72607421875,
-0.224365234375,
0.2010498046875,
0.1341552734375,
-0.6474609375,
-0.64111328125,
-0.2427978515625,
0.5419921875,
0.07958984375,
0.67578125,
0.7392578125,
-0.401123046875,
-0.05780029296875,
-0.89990234375,
-0.21240234375,
-0.1737060546875,
-0.75341796875,
-0.6733398... | 11 |
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:
```
n, e = map(int, input().split())
r = list(map(int, input().split()))
d = [0] * n
for ee in range(e):
x, y = map(int, input().split())
x -= 1; y -= 1
if r[x] == r[y]: continue
if r[x] < r[y]: x, y = y, x
d[x] += 1
inds = sorted(range(n), key = lambda i: r[i])
j = 0
ans = [0] * n
for i in inds:
while r[inds[j]] < r[i]: j += 1
ans[i] = j - d[i]
print(*ans)
```
Yes
| 75,635 | [
0.54541015625,
0.06854248046875,
-0.2091064453125,
-0.1920166015625,
-0.591796875,
-0.493408203125,
-0.3349609375,
0.30615234375,
-0.2137451171875,
1.0380859375,
0.376953125,
-0.01276397705078125,
0.319091796875,
-0.82275390625,
-0.1259765625,
0.1702880859375,
-0.6123046875,
-1.034... | 11 |
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:
```
import bisect
n,k = map(int,input().split())
r = list(map(int,input().split()))
t = sorted(r)
l = [0] * n
for i in range(k):
a,b = map(int,input().split())
a -= 1
b -= 1
if r[a] > r[b]:
l[a] += 1
elif r[a] < r[b]:
l[b] += 1
for i in range(n):
print(bisect.bisect_left(t,r[i]) - l[i],end=' ')
```
Yes
| 75,636 | [
0.54541015625,
0.06854248046875,
-0.2091064453125,
-0.1920166015625,
-0.591796875,
-0.493408203125,
-0.3349609375,
0.30615234375,
-0.2137451171875,
1.0380859375,
0.376953125,
-0.01276397705078125,
0.319091796875,
-0.82275390625,
-0.1259765625,
0.1702880859375,
-0.6123046875,
-1.034... | 11 |
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 defaultdict
from collections import Counter
n,k = map(int,input().split())
r = list(map(int,input().split()))
D = defaultdict(lambda : 0)
for i in range(k) :
a,b = map(int,input().split())
if D[a-1] == 0 :
D[a-1] = {b-1}
else :
D[a-1].add(b-1)
if D[b-1] == 0 :
D[b-1] = {a-1}
else :
D[b-1].add(a-1)
P = Counter(r)
g = sorted(range(n),key = lambda x:r[x],reverse = True )
i = 0
out = []
while(i < n -1) :
s = n - 1 - i - (P[r[g[i]]] - 1)
P[r[g[i]]] -= 1
if D[g[i]] != 0 :
for el in D[g[i]] :
if r[el] < r[g[i]] :
s -= 1
out.append([g[i],s])
i += 1
out.append([g[n-1],0])
out = sorted(out, key = lambda x:x[0])
t = [out[i][1] for i in range(n)]
print(*t,sep = ' ')
```
Yes
| 75,637 | [
0.54541015625,
0.06854248046875,
-0.2091064453125,
-0.1920166015625,
-0.591796875,
-0.493408203125,
-0.3349609375,
0.30615234375,
-0.2137451171875,
1.0380859375,
0.376953125,
-0.01276397705078125,
0.319091796875,
-0.82275390625,
-0.1259765625,
0.1702880859375,
-0.6123046875,
-1.034... | 11 |
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:
```
n,k=map(int,input().split())
r=list(map(int,input().split()))
h=[0]*n
for _ in range(k):
a,b=map(int,input().split())
if r[a-1]<r[b-1]:h[b-1]+=1
if r[b-1]<r[a-1]:h[a-1]+=1
x=[[r[i],i] for i in range(n)]
x.sort()
o=['0']*n
u=0
for i in range(1, n):
if x[i][0]!=x[i-1][0]:
u=i
o[x[i][1]]=str(max(0,u-h[x[i][1]]))
print(' '.join(o))
```
Yes
| 75,638 | [
0.54541015625,
0.06854248046875,
-0.2091064453125,
-0.1920166015625,
-0.591796875,
-0.493408203125,
-0.3349609375,
0.30615234375,
-0.2137451171875,
1.0380859375,
0.376953125,
-0.01276397705078125,
0.319091796875,
-0.82275390625,
-0.1259765625,
0.1702880859375,
-0.6123046875,
-1.034... | 11 |
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:
```
n, k = [int(i) for i in input().split()]
r = []
r2 = []
c = 0
for i in input().split():
m = [int(i), c]
r2.append(m)
r.append(m)
c += 1
r2.sort()
s = [0] * n
for i in range(n):
if i == 0:
None
elif r2[i][0] == r2[i - 1][0]:
s[r2[i][1]] = s[r2[i - 1][1]]
else:
s[r2[i][1]] = i
for i in range(k):
x, y = [int(i) for i in input().split()]
if r[x - 1] > r[y - 1]:
if s[x - 1] > 0:
s[x - 1] -= 1
elif r[x - 1] < r[y - 1]:
if s[y - 1] > 0:
s[y - 1] -= 1
print(*s)
```
No
| 75,639 | [
0.54541015625,
0.06854248046875,
-0.2091064453125,
-0.1920166015625,
-0.591796875,
-0.493408203125,
-0.3349609375,
0.30615234375,
-0.2137451171875,
1.0380859375,
0.376953125,
-0.01276397705078125,
0.319091796875,
-0.82275390625,
-0.1259765625,
0.1702880859375,
-0.6123046875,
-1.034... | 11 |
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:
```
n,k=map(int,input().split())
q=[[] for i in range(n)]
skills=list(map(int,input().split()))
for i in range(k):
a,b=map(int,input().split())
q[a-1].append(b-1)
for i in range(n):
count=0
for j in range(n):
if(skills[i]>skills[j] and j not in q[i]):
count+=1
print(count,end=' ')
```
No
| 75,640 | [
0.54541015625,
0.06854248046875,
-0.2091064453125,
-0.1920166015625,
-0.591796875,
-0.493408203125,
-0.3349609375,
0.30615234375,
-0.2137451171875,
1.0380859375,
0.376953125,
-0.01276397705078125,
0.319091796875,
-0.82275390625,
-0.1259765625,
0.1702880859375,
-0.6123046875,
-1.034... | 11 |
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:
```
params = [int(s) for s in input().split(" ")]
n = params[0]
k = params[1]
skills = [int(s) for s in input().split(" ")]
indexes_sorted= [b[0] for b in sorted(enumerate(skills),key=lambda i:i[1])]
bad_relations={}
for i in range(k):
items = [int(s) for s in input().split(" ")]
first = items[0] - 1
second= items[1] - 1
if skills[first] > skills[second]:
bad_relations[first] = bad_relations.get(first, 0) + 1
elif skills[second]> skills[first]:
bad_relations[second] = bad_relations.get(first, 0) + 1
num_the_same=0
results = {}
prev=None
for idx, index in enumerate(indexes_sorted):
skill = skills[index]
if skill==prev:
num_the_same+=1
else:
num_the_same=0
cnt = idx - num_the_same - bad_relations.get(index,0)
if cnt < 0:
cnt= 0
results[index]= cnt
prev= skill
final=''
for i in range(n):
final+=str((results[i])) + " "
print(final.strip())
```
No
| 75,641 | [
0.54541015625,
0.06854248046875,
-0.2091064453125,
-0.1920166015625,
-0.591796875,
-0.493408203125,
-0.3349609375,
0.30615234375,
-0.2137451171875,
1.0380859375,
0.376953125,
-0.01276397705078125,
0.319091796875,
-0.82275390625,
-0.1259765625,
0.1702880859375,
-0.6123046875,
-1.034... | 11 |
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)
```
No
| 75,642 | [
0.54541015625,
0.06854248046875,
-0.2091064453125,
-0.1920166015625,
-0.591796875,
-0.493408203125,
-0.3349609375,
0.30615234375,
-0.2137451171875,
1.0380859375,
0.376953125,
-0.01276397705078125,
0.319091796875,
-0.82275390625,
-0.1259765625,
0.1702880859375,
-0.6123046875,
-1.034... | 11 |
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
"Correct Solution:
```
print('2')
```
| 76,127 | [
0.41845703125,
-0.08306884765625,
-0.00977325439453125,
0.3193359375,
-0.400634765625,
-0.1575927734375,
-0.10443115234375,
0.1527099609375,
0.296875,
0.7490234375,
0.303466796875,
-0.2080078125,
0.3349609375,
-0.51953125,
-0.61376953125,
0.212158203125,
-0.3603515625,
-0.751464843... | 11 |
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
"Correct Solution:
```
print('1')
```
| 76,128 | [
0.41845703125,
-0.08306884765625,
-0.00977325439453125,
0.3193359375,
-0.400634765625,
-0.1575927734375,
-0.10443115234375,
0.1527099609375,
0.296875,
0.7490234375,
0.303466796875,
-0.2080078125,
0.3349609375,
-0.51953125,
-0.61376953125,
0.212158203125,
-0.3603515625,
-0.751464843... | 11 |
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.
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()
```
| 76,364 | [
0.30859375,
-0.1788330078125,
0.0207977294921875,
0.364990234375,
-0.61181640625,
-0.44677734375,
-0.10662841796875,
0.05743408203125,
0.1630859375,
0.87939453125,
0.62158203125,
0.03814697265625,
0.093017578125,
-0.50390625,
-0.152587890625,
0.4814453125,
-0.09674072265625,
-0.536... | 11 |
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.
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)
```
| 76,365 | [
0.302734375,
-0.1627197265625,
-0.031402587890625,
0.3642578125,
-0.64794921875,
-0.472900390625,
-0.13232421875,
0.11798095703125,
0.085205078125,
0.86181640625,
0.64306640625,
0.10614013671875,
0.09539794921875,
-0.54150390625,
-0.176513671875,
0.4013671875,
-0.11846923828125,
-0... | 11 |
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.
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)
```
| 76,366 | [
0.322265625,
-0.17578125,
-0.061614990234375,
0.3818359375,
-0.65966796875,
-0.467041015625,
-0.140869140625,
0.09771728515625,
0.1099853515625,
0.8466796875,
0.60302734375,
0.1358642578125,
0.09454345703125,
-0.52294921875,
-0.172607421875,
0.46337890625,
-0.032196044921875,
-0.53... | 11 |
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.
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)
```
| 76,367 | [
0.27880859375,
-0.1405029296875,
-0.02838134765625,
0.37353515625,
-0.619140625,
-0.424072265625,
-0.138671875,
0.1492919921875,
0.087646484375,
0.85595703125,
0.66015625,
0.1142578125,
0.09014892578125,
-0.5263671875,
-0.1412353515625,
0.39599609375,
-0.13232421875,
-0.5419921875,... | 11 |
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.
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()
```
| 76,368 | [
0.3115234375,
-0.152587890625,
-0.040313720703125,
0.347900390625,
-0.60302734375,
-0.407958984375,
-0.1627197265625,
0.15869140625,
0.1334228515625,
0.82958984375,
0.62744140625,
0.096435546875,
0.110107421875,
-0.5205078125,
-0.15966796875,
0.432373046875,
-0.10308837890625,
-0.5... | 11 |
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.
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)
```
| 76,369 | [
0.2626953125,
-0.06640625,
0.0252227783203125,
0.328857421875,
-0.68798828125,
-0.349853515625,
-0.1697998046875,
0.09033203125,
0.1572265625,
0.8642578125,
0.677734375,
0.0185699462890625,
0.0155181884765625,
-0.5263671875,
-0.2476806640625,
0.432373046875,
-0.09124755859375,
-0.5... | 11 |
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.
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)
```
| 76,370 | [
0.330078125,
-0.1395263671875,
-0.024627685546875,
0.383056640625,
-0.65869140625,
-0.49365234375,
-0.126953125,
0.091552734375,
0.13232421875,
0.8466796875,
0.60498046875,
0.10491943359375,
0.08709716796875,
-0.53466796875,
-0.188232421875,
0.475830078125,
-0.0787353515625,
-0.606... | 11 |
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.
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)
```
| 76,371 | [
0.29296875,
-0.20458984375,
0.02825927734375,
0.370849609375,
-0.60400390625,
-0.44482421875,
-0.10687255859375,
0.057098388671875,
0.132568359375,
0.8837890625,
0.62744140625,
0.052825927734375,
0.088623046875,
-0.51806640625,
-0.1837158203125,
0.4931640625,
-0.08349609375,
-0.556... | 11 |
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)
```
Yes
| 76,372 | [
0.32470703125,
-0.138671875,
-0.02569580078125,
0.262939453125,
-0.69287109375,
-0.3115234375,
-0.1923828125,
0.191650390625,
0.0243377685546875,
0.77294921875,
0.51220703125,
0.053802490234375,
0.07574462890625,
-0.525390625,
-0.201904296875,
0.4287109375,
-0.10711669921875,
-0.64... | 11 |
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()
```
Yes
| 76,373 | [
0.277099609375,
-0.110595703125,
-0.09075927734375,
0.2073974609375,
-0.69921875,
-0.325927734375,
-0.2431640625,
0.283203125,
0.0504150390625,
0.7861328125,
0.560546875,
0.10662841796875,
0.1602783203125,
-0.54248046875,
-0.2115478515625,
0.47216796875,
-0.10272216796875,
-0.62011... | 11 |
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())
```
Yes
| 76,374 | [
0.26318359375,
-0.1282958984375,
0.01099395751953125,
0.303466796875,
-0.65234375,
-0.327880859375,
-0.22021484375,
0.1669921875,
0.0733642578125,
0.86669921875,
0.54296875,
0.0305938720703125,
0.09600830078125,
-0.57568359375,
-0.2091064453125,
0.481689453125,
-0.06884765625,
-0.7... | 11 |
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])
```
Yes
| 76,375 | [
0.324951171875,
-0.141357421875,
-0.058807373046875,
0.23583984375,
-0.72314453125,
-0.394775390625,
-0.219970703125,
0.2418212890625,
0.043548583984375,
0.80419921875,
0.5146484375,
0.10272216796875,
0.11004638671875,
-0.51318359375,
-0.259521484375,
0.405517578125,
-0.1085815429687... | 11 |
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)
```
No
| 76,376 | [
0.326904296875,
-0.155517578125,
-0.07586669921875,
0.22265625,
-0.7470703125,
-0.3974609375,
-0.2034912109375,
0.27490234375,
0.01611328125,
0.80419921875,
0.53173828125,
0.1077880859375,
0.0748291015625,
-0.50244140625,
-0.2237548828125,
0.455078125,
-0.09185791015625,
-0.6357421... | 11 |
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)
```
No
| 76,377 | [
0.372802734375,
-0.07830810546875,
0.03106689453125,
0.343994140625,
-0.7587890625,
-0.4013671875,
-0.200439453125,
0.1927490234375,
-0.031036376953125,
0.79833984375,
0.477783203125,
0.0982666015625,
0.0740966796875,
-0.4697265625,
-0.139404296875,
0.391357421875,
-0.10614013671875,... | 11 |
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')
```
No
| 76,378 | [
0.31103515625,
-0.1334228515625,
0.0312042236328125,
0.287109375,
-0.73046875,
-0.308349609375,
-0.22119140625,
0.2113037109375,
-0.0003249645233154297,
0.78857421875,
0.491943359375,
0.0684814453125,
0.05352783203125,
-0.4736328125,
-0.1842041015625,
0.404052734375,
-0.1019287109375... | 11 |
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)
```
No
| 76,379 | [
0.31396484375,
-0.1317138671875,
-0.06396484375,
0.243896484375,
-0.7421875,
-0.380126953125,
-0.2490234375,
0.248291015625,
0.015625,
0.8125,
0.48779296875,
0.14013671875,
0.06976318359375,
-0.51171875,
-0.233154296875,
0.438232421875,
-0.08135986328125,
-0.64306640625,
-0.38012... | 11 |
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')
```
Yes
| 76,465 | [
0.440185546875,
0.2135009765625,
-0.399169921875,
-0.03619384765625,
-0.720703125,
-0.137451171875,
0.00019097328186035156,
0.41455078125,
0.1007080078125,
0.96533203125,
0.66162109375,
-0.044708251953125,
0.115234375,
-0.93798828125,
-0.203857421875,
-0.0980224609375,
-0.966796875,
... | 11 |
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')
```
Yes
| 76,466 | [
0.454833984375,
0.2080078125,
-0.38037109375,
-0.049835205078125,
-0.6982421875,
-0.1529541015625,
-0.0020503997802734375,
0.390625,
0.118896484375,
0.97705078125,
0.6640625,
-0.0128631591796875,
0.10565185546875,
-0.9287109375,
-0.195556640625,
-0.0963134765625,
-0.95947265625,
-0... | 11 |
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")
```
Yes
| 76,467 | [
0.427734375,
0.216064453125,
-0.417236328125,
-0.048614501953125,
-0.74169921875,
-0.164306640625,
0.0284423828125,
0.42138671875,
0.0994873046875,
0.96337890625,
0.64453125,
-0.0277557373046875,
0.14697265625,
-0.9228515625,
-0.2427978515625,
-0.11309814453125,
-0.9658203125,
-0.6... | 11 |
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')
```
Yes
| 76,468 | [
0.451904296875,
0.2158203125,
-0.3837890625,
-0.04925537109375,
-0.6787109375,
-0.169189453125,
0.01409912109375,
0.386474609375,
0.0936279296875,
1.0078125,
0.6826171875,
-0.033203125,
0.133056640625,
-0.95166015625,
-0.2103271484375,
-0.10784912109375,
-0.98974609375,
-0.66699218... | 11 |
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")
```
No
| 76,469 | [
0.430908203125,
0.256591796875,
-0.37353515625,
-0.051666259765625,
-0.75390625,
-0.129150390625,
0.01035308837890625,
0.423095703125,
0.1131591796875,
0.97265625,
0.66552734375,
-0.045318603515625,
0.155517578125,
-0.94775390625,
-0.210693359375,
-0.0927734375,
-0.96142578125,
-0.... | 11 |
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")
```
No
| 76,470 | [
0.435791015625,
0.2310791015625,
-0.385986328125,
-0.034576416015625,
-0.70458984375,
-0.1571044921875,
0.0013456344604492188,
0.402587890625,
0.099609375,
0.99951171875,
0.64892578125,
-0.059112548828125,
0.1160888671875,
-0.9287109375,
-0.208251953125,
-0.09490966796875,
-0.9643554... | 11 |
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")
```
No
| 76,471 | [
0.439697265625,
0.22998046875,
-0.40625,
-0.0309600830078125,
-0.79833984375,
-0.1729736328125,
-0.05859375,
0.447998046875,
0.10345458984375,
0.998046875,
0.65771484375,
-0.0031108856201171875,
0.08721923828125,
-0.93359375,
-0.1644287109375,
-0.135498046875,
-0.8935546875,
-0.659... | 11 |
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)
```
No
| 76,472 | [
0.4501953125,
0.2235107421875,
-0.40283203125,
-0.0487060546875,
-0.71630859375,
-0.15869140625,
0.01372528076171875,
0.388916015625,
0.0850830078125,
1.0087890625,
0.6669921875,
-0.050048828125,
0.127197265625,
-0.9384765625,
-0.2017822265625,
-0.105224609375,
-0.99267578125,
-0.6... | 11 |
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
"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)
```
| 76,489 | [
0.1697998046875,
-0.408935546875,
0.09124755859375,
0.06829833984375,
-0.269287109375,
-0.2000732421875,
-0.1959228515625,
0.4912109375,
-0.076416015625,
1.0185546875,
0.81640625,
-0.316162109375,
0.27197265625,
-0.71484375,
-0.2568359375,
0.5556640625,
-0.79248046875,
-1.013671875... | 11 |
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
"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)
```
| 76,490 | [
0.1697998046875,
-0.408935546875,
0.09124755859375,
0.06829833984375,
-0.269287109375,
-0.2000732421875,
-0.1959228515625,
0.4912109375,
-0.076416015625,
1.0185546875,
0.81640625,
-0.316162109375,
0.27197265625,
-0.71484375,
-0.2568359375,
0.5556640625,
-0.79248046875,
-1.013671875... | 11 |
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
"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)
```
| 76,491 | [
0.1697998046875,
-0.408935546875,
0.09124755859375,
0.06829833984375,
-0.269287109375,
-0.2000732421875,
-0.1959228515625,
0.4912109375,
-0.076416015625,
1.0185546875,
0.81640625,
-0.316162109375,
0.27197265625,
-0.71484375,
-0.2568359375,
0.5556640625,
-0.79248046875,
-1.013671875... | 11 |
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
"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)
```
| 76,492 | [
0.1697998046875,
-0.408935546875,
0.09124755859375,
0.06829833984375,
-0.269287109375,
-0.2000732421875,
-0.1959228515625,
0.4912109375,
-0.076416015625,
1.0185546875,
0.81640625,
-0.316162109375,
0.27197265625,
-0.71484375,
-0.2568359375,
0.5556640625,
-0.79248046875,
-1.013671875... | 11 |
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
"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)
```
| 76,493 | [
0.1697998046875,
-0.408935546875,
0.09124755859375,
0.06829833984375,
-0.269287109375,
-0.2000732421875,
-0.1959228515625,
0.4912109375,
-0.076416015625,
1.0185546875,
0.81640625,
-0.316162109375,
0.27197265625,
-0.71484375,
-0.2568359375,
0.5556640625,
-0.79248046875,
-1.013671875... | 11 |
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
"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)
```
| 76,494 | [
0.1697998046875,
-0.408935546875,
0.09124755859375,
0.06829833984375,
-0.269287109375,
-0.2000732421875,
-0.1959228515625,
0.4912109375,
-0.076416015625,
1.0185546875,
0.81640625,
-0.316162109375,
0.27197265625,
-0.71484375,
-0.2568359375,
0.5556640625,
-0.79248046875,
-1.013671875... | 11 |
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
"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)
```
| 76,495 | [
0.1697998046875,
-0.408935546875,
0.09124755859375,
0.06829833984375,
-0.269287109375,
-0.2000732421875,
-0.1959228515625,
0.4912109375,
-0.076416015625,
1.0185546875,
0.81640625,
-0.316162109375,
0.27197265625,
-0.71484375,
-0.2568359375,
0.5556640625,
-0.79248046875,
-1.013671875... | 11 |
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
"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)
```
| 76,496 | [
0.1697998046875,
-0.408935546875,
0.09124755859375,
0.06829833984375,
-0.269287109375,
-0.2000732421875,
-0.1959228515625,
0.4912109375,
-0.076416015625,
1.0185546875,
0.81640625,
-0.316162109375,
0.27197265625,
-0.71484375,
-0.2568359375,
0.5556640625,
-0.79248046875,
-1.013671875... | 11 |
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)
```
Yes
| 76,497 | [
0.201904296875,
-0.38916015625,
0.1318359375,
-0.009857177734375,
-0.336669921875,
-0.118896484375,
-0.2939453125,
0.517578125,
-0.1026611328125,
1.0146484375,
0.7705078125,
-0.2369384765625,
0.18798828125,
-0.6884765625,
-0.2352294921875,
0.52783203125,
-0.74267578125,
-1.00976562... | 11 |
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)
```
Yes
| 76,498 | [
0.201904296875,
-0.38916015625,
0.1318359375,
-0.009857177734375,
-0.336669921875,
-0.118896484375,
-0.2939453125,
0.517578125,
-0.1026611328125,
1.0146484375,
0.7705078125,
-0.2369384765625,
0.18798828125,
-0.6884765625,
-0.2352294921875,
0.52783203125,
-0.74267578125,
-1.00976562... | 11 |
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)
```
Yes
| 76,499 | [
0.201904296875,
-0.38916015625,
0.1318359375,
-0.009857177734375,
-0.336669921875,
-0.118896484375,
-0.2939453125,
0.517578125,
-0.1026611328125,
1.0146484375,
0.7705078125,
-0.2369384765625,
0.18798828125,
-0.6884765625,
-0.2352294921875,
0.52783203125,
-0.74267578125,
-1.00976562... | 11 |
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)
```
Yes
| 76,500 | [
0.201904296875,
-0.38916015625,
0.1318359375,
-0.009857177734375,
-0.336669921875,
-0.118896484375,
-0.2939453125,
0.517578125,
-0.1026611328125,
1.0146484375,
0.7705078125,
-0.2369384765625,
0.18798828125,
-0.6884765625,
-0.2352294921875,
0.52783203125,
-0.74267578125,
-1.00976562... | 11 |
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)
```
No
| 76,501 | [
0.201904296875,
-0.38916015625,
0.1318359375,
-0.009857177734375,
-0.336669921875,
-0.118896484375,
-0.2939453125,
0.517578125,
-0.1026611328125,
1.0146484375,
0.7705078125,
-0.2369384765625,
0.18798828125,
-0.6884765625,
-0.2352294921875,
0.52783203125,
-0.74267578125,
-1.00976562... | 11 |
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)
```
No
| 76,502 | [
0.201904296875,
-0.38916015625,
0.1318359375,
-0.009857177734375,
-0.336669921875,
-0.118896484375,
-0.2939453125,
0.517578125,
-0.1026611328125,
1.0146484375,
0.7705078125,
-0.2369384765625,
0.18798828125,
-0.6884765625,
-0.2352294921875,
0.52783203125,
-0.74267578125,
-1.00976562... | 11 |
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()
```
No
| 76,503 | [
0.201904296875,
-0.38916015625,
0.1318359375,
-0.009857177734375,
-0.336669921875,
-0.118896484375,
-0.2939453125,
0.517578125,
-0.1026611328125,
1.0146484375,
0.7705078125,
-0.2369384765625,
0.18798828125,
-0.6884765625,
-0.2352294921875,
0.52783203125,
-0.74267578125,
-1.00976562... | 11 |
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)
```
No
| 76,504 | [
0.201904296875,
-0.38916015625,
0.1318359375,
-0.009857177734375,
-0.336669921875,
-0.118896484375,
-0.2939453125,
0.517578125,
-0.1026611328125,
1.0146484375,
0.7705078125,
-0.2369384765625,
0.18798828125,
-0.6884765625,
-0.2352294921875,
0.52783203125,
-0.74267578125,
-1.00976562... | 11 |
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
"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)
```
| 76,641 | [
0.337158203125,
0.193603515625,
0.046112060546875,
0.04345703125,
-0.49169921875,
-0.208984375,
0.11077880859375,
0.537109375,
0.330078125,
0.990234375,
0.85009765625,
-0.1121826171875,
0.08056640625,
-0.97802734375,
-0.634765625,
-0.1280517578125,
-0.41845703125,
-0.381103515625,
... | 11 |
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
"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])
```
| 76,642 | [
0.442626953125,
0.273193359375,
-0.01885986328125,
0.10186767578125,
-0.61376953125,
-0.31591796875,
0.0556640625,
0.53125,
0.178466796875,
0.87744140625,
0.6142578125,
0.0406494140625,
-0.09619140625,
-0.8955078125,
-0.5927734375,
-0.06756591796875,
-0.486328125,
-0.366455078125,
... | 11 |
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
"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)
```
| 76,643 | [
0.294189453125,
0.253662109375,
0.057098388671875,
0.0146636962890625,
-0.68798828125,
-0.163330078125,
0.003643035888671875,
0.41943359375,
0.2147216796875,
0.8515625,
0.62744140625,
0.034698486328125,
0.054656982421875,
-0.83984375,
-0.52783203125,
-0.08868408203125,
-0.5029296875,... | 11 |
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
"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)
```
| 76,645 | [
0.3173828125,
0.367919921875,
0.05181884765625,
0.06378173828125,
-0.60302734375,
-0.399169921875,
0.0987548828125,
0.6044921875,
0.062408447265625,
0.77490234375,
0.70361328125,
-0.0809326171875,
-0.0902099609375,
-0.7509765625,
-0.66455078125,
-0.026031494140625,
-0.481689453125,
... | 11 |
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)
```
No
| 76,646 | [
0.231689453125,
0.2646484375,
0.004863739013671875,
0.077880859375,
-0.78271484375,
-0.15966796875,
-0.07861328125,
0.494384765625,
0.1859130859375,
0.9091796875,
0.68994140625,
-0.01023101806640625,
-0.08978271484375,
-0.95458984375,
-0.51220703125,
0.0270233154296875,
-0.3979492187... | 11 |
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())
```
No
| 76,650 | [
0.2239990234375,
0.057281494140625,
0.0036563873291015625,
-0.058624267578125,
-0.90380859375,
-0.1826171875,
-0.249755859375,
0.174560546875,
0.281982421875,
1.1943359375,
0.2139892578125,
-0.07781982421875,
0.150390625,
-0.455322265625,
-0.60205078125,
-0.12115478515625,
-0.7138671... | 11 |
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")
```
No
| 76,859 | [
0.40185546875,
0.1243896484375,
-0.299560546875,
0.2244873046875,
-0.5341796875,
-0.199462890625,
-0.17041015625,
0.3837890625,
0.05426025390625,
0.99609375,
0.52197265625,
0.1112060546875,
0.201416015625,
-0.7236328125,
-0.7294921875,
0.1982421875,
-0.46826171875,
-0.884765625,
... | 11 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.