message stringlengths 2 45.8k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 254 108k | cluster float64 3 3 | __index_level_0__ int64 508 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It has been noted that if some ants are put in the junctions of the graphene integer lattice then they will act in the following fashion: every minute at each junction (x, y) containing at least four ants a group of four ants will be formed, and these four ants will scatter to the neighbouring junctions (x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1) β one ant in each direction. No other ant movements will happen. Ants never interfere with each other.
Scientists have put a colony of n ants into the junction (0, 0) and now they wish to know how many ants will there be at some given junctions, when the movement of the ants stops.
Input
First input line contains integers n (0 β€ n β€ 30000) and t (1 β€ t β€ 50000), where n is the number of ants in the colony and t is the number of queries. Each of the next t lines contains coordinates of a query junction: integers xi, yi ( - 109 β€ xi, yi β€ 109). Queries may coincide.
It is guaranteed that there will be a certain moment of time when no possible movements can happen (in other words, the process will eventually end).
Output
Print t integers, one per line β the number of ants at the corresponding junctions when the movement of the ants stops.
Examples
Input
1 3
0 1
0 0
0 -1
Output
0
1
0
Input
6 5
0 -2
0 -1
0 0
0 1
0 2
Output
0
1
2
1
0
Note
In the first sample the colony consists of the one ant, so nothing happens at all.
In the second sample the colony consists of 6 ants. At the first minute 4 ants scatter from (0, 0) to the neighbouring junctions. After that the process stops.
Submitted Solution:
```
f = lambda: map(int, input().split())
m = 100
n, t = f()
p = [[0] * m for i in range(m)]
p[1][0] = n // 4
g = 1
while g:
g = 0
for x in range(1, m):
if p[x][0] > 3:
g = 1
d = p[x][0] // 4
p[x + 1][0] += d
p[x - 1][0] += d
p[x][1] += d
p[x][0] %= 4
if p[x][x] > 3:
g = 1
d = p[x][x] // 4
p[x + 1][x] += d
p[x][x - 1] += d
p[x][x] %= 4
p[1][0] += p[0][0]
p[0][0] = 0
for x in range(1, m):
for y in range(1, x):
if p[x][y] > 3:
d = p[x][y] // 4
g = 1
p[x + 1][y] += d
p[x - 1][y] += d
p[x][y + 1] += d
p[x][y - 1] += d
if y - x == 1: p[x][x] += d
if y == 1: p[x][0] += d
p[x][y] %= 4
p[0][0] = n % 4
for j in range(t):
x, y = f()
x, y = abs(x), abs(y)
t = max(x, y)
print(p[t][x + y - t] if t < m else 0)
``` | instruction | 0 | 6,956 | 3 | 13,912 |
No | output | 1 | 6,956 | 3 | 13,913 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times b, b + a, b + 2a, b + 3a, ... and Morty screams at times d, d + c, d + 2c, d + 3c, ....
<image>
The Monster will catch them if at any point they scream at the same time, so it wants to know when it will catch them (the first time they scream at the same time) or that they will never scream at the same time.
Input
The first line of input contains two integers a and b (1 β€ a, b β€ 100).
The second line contains two integers c and d (1 β€ c, d β€ 100).
Output
Print the first time Rick and Morty will scream at the same time, or - 1 if they will never scream at the same time.
Examples
Input
20 2
9 19
Output
82
Input
2 1
16 12
Output
-1
Note
In the first sample testcase, Rick's 5th scream and Morty's 8th time are at time 82.
In the second sample testcase, all Rick's screams will be at odd times and Morty's will be at even times, so they will never scream at the same time.
Submitted Solution:
```
a,b=map(int,input().split())
c,d=map(int,input().split())
if b==d:
print(b)
else:
if b<d:
b+=((d-b)//a)*a
for i in range(200):
if (b+i*a-d)%c==0:
print(b+i*a)
break
else:
print(-1)
``` | instruction | 0 | 7,182 | 3 | 14,364 |
Yes | output | 1 | 7,182 | 3 | 14,365 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times b, b + a, b + 2a, b + 3a, ... and Morty screams at times d, d + c, d + 2c, d + 3c, ....
<image>
The Monster will catch them if at any point they scream at the same time, so it wants to know when it will catch them (the first time they scream at the same time) or that they will never scream at the same time.
Input
The first line of input contains two integers a and b (1 β€ a, b β€ 100).
The second line contains two integers c and d (1 β€ c, d β€ 100).
Output
Print the first time Rick and Morty will scream at the same time, or - 1 if they will never scream at the same time.
Examples
Input
20 2
9 19
Output
82
Input
2 1
16 12
Output
-1
Note
In the first sample testcase, Rick's 5th scream and Morty's 8th time are at time 82.
In the second sample testcase, all Rick's screams will be at odd times and Morty's will be at even times, so they will never scream at the same time.
Submitted Solution:
```
def gcd(a, b):
return a if b==0 else gcd(b, a%b)
a, b = map(int, input().split())
c, d = map(int, input().split())
g = gcd(a, c)
dif = abs(b-d)
if dif%g==0:
for t in range(max(b, d), 1000000):
if (t-b)%a==0 and (t-d)%c==0:
print(t)
break
else:
print(-1)
``` | instruction | 0 | 7,183 | 3 | 14,366 |
Yes | output | 1 | 7,183 | 3 | 14,367 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times b, b + a, b + 2a, b + 3a, ... and Morty screams at times d, d + c, d + 2c, d + 3c, ....
<image>
The Monster will catch them if at any point they scream at the same time, so it wants to know when it will catch them (the first time they scream at the same time) or that they will never scream at the same time.
Input
The first line of input contains two integers a and b (1 β€ a, b β€ 100).
The second line contains two integers c and d (1 β€ c, d β€ 100).
Output
Print the first time Rick and Morty will scream at the same time, or - 1 if they will never scream at the same time.
Examples
Input
20 2
9 19
Output
82
Input
2 1
16 12
Output
-1
Note
In the first sample testcase, Rick's 5th scream and Morty's 8th time are at time 82.
In the second sample testcase, all Rick's screams will be at odd times and Morty's will be at even times, so they will never scream at the same time.
Submitted Solution:
```
a,b=map(int,input().split())
s=0
c,d=map(int,input().split())
flag=0
while(d!=b):
if(s==100000):
print(-1)
b=d
flag=1
if(d<b):
d+=max(c*((b-d)//c),c)
else:
b+=max(a*((d-b)//a),a)
s+=1
if(flag==0):
print(b)
``` | instruction | 0 | 7,184 | 3 | 14,368 |
Yes | output | 1 | 7,184 | 3 | 14,369 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times b, b + a, b + 2a, b + 3a, ... and Morty screams at times d, d + c, d + 2c, d + 3c, ....
<image>
The Monster will catch them if at any point they scream at the same time, so it wants to know when it will catch them (the first time they scream at the same time) or that they will never scream at the same time.
Input
The first line of input contains two integers a and b (1 β€ a, b β€ 100).
The second line contains two integers c and d (1 β€ c, d β€ 100).
Output
Print the first time Rick and Morty will scream at the same time, or - 1 if they will never scream at the same time.
Examples
Input
20 2
9 19
Output
82
Input
2 1
16 12
Output
-1
Note
In the first sample testcase, Rick's 5th scream and Morty's 8th time are at time 82.
In the second sample testcase, all Rick's screams will be at odd times and Morty's will be at even times, so they will never scream at the same time.
Submitted Solution:
```
a, b = input().split()
c, d = input().split()
a, b, c, d = (int(x) for x in (a, b, c, d))
Rick = {(b + a * x) for x in range(1000005)}
Morty = {(d + c * x) for x in range(1000005)}
moments = Rick.intersection(Morty)
if len(moments)==0:
print(-1)
else:
print(min(moments))
``` | instruction | 0 | 7,185 | 3 | 14,370 |
Yes | output | 1 | 7,185 | 3 | 14,371 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times b, b + a, b + 2a, b + 3a, ... and Morty screams at times d, d + c, d + 2c, d + 3c, ....
<image>
The Monster will catch them if at any point they scream at the same time, so it wants to know when it will catch them (the first time they scream at the same time) or that they will never scream at the same time.
Input
The first line of input contains two integers a and b (1 β€ a, b β€ 100).
The second line contains two integers c and d (1 β€ c, d β€ 100).
Output
Print the first time Rick and Morty will scream at the same time, or - 1 if they will never scream at the same time.
Examples
Input
20 2
9 19
Output
82
Input
2 1
16 12
Output
-1
Note
In the first sample testcase, Rick's 5th scream and Morty's 8th time are at time 82.
In the second sample testcase, all Rick's screams will be at odd times and Morty's will be at even times, so they will never scream at the same time.
Submitted Solution:
```
b,a=map(int,input().split(' '))
d,c=map(int,input().split(' '))
r=-1
if(b>=d):
while(b>=d):
if(b==d):
r=b
b+=a
d+=c
else:
while(d>=b):
if(b==d):
r=b
b+=a
d+=c
print(str(r))
``` | instruction | 0 | 7,186 | 3 | 14,372 |
No | output | 1 | 7,186 | 3 | 14,373 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times b, b + a, b + 2a, b + 3a, ... and Morty screams at times d, d + c, d + 2c, d + 3c, ....
<image>
The Monster will catch them if at any point they scream at the same time, so it wants to know when it will catch them (the first time they scream at the same time) or that they will never scream at the same time.
Input
The first line of input contains two integers a and b (1 β€ a, b β€ 100).
The second line contains two integers c and d (1 β€ c, d β€ 100).
Output
Print the first time Rick and Morty will scream at the same time, or - 1 if they will never scream at the same time.
Examples
Input
20 2
9 19
Output
82
Input
2 1
16 12
Output
-1
Note
In the first sample testcase, Rick's 5th scream and Morty's 8th time are at time 82.
In the second sample testcase, all Rick's screams will be at odd times and Morty's will be at even times, so they will never scream at the same time.
Submitted Solution:
```
a,b = map(int,input().split())
c,d = map(int,input().split())
def rick(a,b,r):
return b+a*r
def morty(c,d,r):
return d+c*r
if (b%2 == 0 and d%2 != 0) or (b%2 != 0 and d%2 == 0):
print(-1)
else:
i = 0
j = 0
while True:
if rick(a,b,i) < morty(c,d,j):
i+=1
elif rick(a,b,i) > morty(c,d,j):
j+=1
else:
print(rick(a,b,i))
break
``` | instruction | 0 | 7,187 | 3 | 14,374 |
No | output | 1 | 7,187 | 3 | 14,375 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times b, b + a, b + 2a, b + 3a, ... and Morty screams at times d, d + c, d + 2c, d + 3c, ....
<image>
The Monster will catch them if at any point they scream at the same time, so it wants to know when it will catch them (the first time they scream at the same time) or that they will never scream at the same time.
Input
The first line of input contains two integers a and b (1 β€ a, b β€ 100).
The second line contains two integers c and d (1 β€ c, d β€ 100).
Output
Print the first time Rick and Morty will scream at the same time, or - 1 if they will never scream at the same time.
Examples
Input
20 2
9 19
Output
82
Input
2 1
16 12
Output
-1
Note
In the first sample testcase, Rick's 5th scream and Morty's 8th time are at time 82.
In the second sample testcase, all Rick's screams will be at odd times and Morty's will be at even times, so they will never scream at the same time.
Submitted Solution:
```
R = lambda:map(int, input().split())
a, b = R()
c, d = R()
s = set(range(b, 100**2, a)) and set(range(d, 100*2, c))
print(min(s) if s else -1)
``` | instruction | 0 | 7,188 | 3 | 14,376 |
No | output | 1 | 7,188 | 3 | 14,377 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times b, b + a, b + 2a, b + 3a, ... and Morty screams at times d, d + c, d + 2c, d + 3c, ....
<image>
The Monster will catch them if at any point they scream at the same time, so it wants to know when it will catch them (the first time they scream at the same time) or that they will never scream at the same time.
Input
The first line of input contains two integers a and b (1 β€ a, b β€ 100).
The second line contains two integers c and d (1 β€ c, d β€ 100).
Output
Print the first time Rick and Morty will scream at the same time, or - 1 if they will never scream at the same time.
Examples
Input
20 2
9 19
Output
82
Input
2 1
16 12
Output
-1
Note
In the first sample testcase, Rick's 5th scream and Morty's 8th time are at time 82.
In the second sample testcase, all Rick's screams will be at odd times and Morty's will be at even times, so they will never scream at the same time.
Submitted Solution:
```
import sys
from fractions import gcd
from math import floor
def egcd(b, n):
x0, x1, y0, y1 = 1, 0, 0, 1
while n != 0:
q, b, n = b // n, n, b % n
x0, x1 = x1, x0 - q * x1
y0, y1 = y1, y0 - q * y1
return b, x0, y0
def ans(rst):
print(rst)
sys.exit(0)
a, b = tuple(map(int, input().split()))
c, d = tuple(map(int, input().split()))
if a > c:
a, c = c, a
b, d = d, b
g, v, u = egcd(a, c)
print(g, u, v)
C = b - d + c - a
if C % g != 0:
ans(-1)
else:
t = max(floor(-C / c * u), floor(-C / a * v)) + 1
X = C / g * u + t * c / g
print(C, t, X)
ans(int(b + (X - 1) * a))
# if c == a:
# if b == d:
# ans(b)
# else:
# ans(-1)
# t = (d - b) / (a - c)
# if t.is_integer() and t > 0:
# ans(int(t))
# else:
# ans(-1)
``` | instruction | 0 | 7,189 | 3 | 14,378 |
No | output | 1 | 7,189 | 3 | 14,379 |
Provide tags and a correct Python 3 solution for this coding contest problem.
An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme.
Three distinct states i, j and k are selected, where i < j < k. After that the following process happens:
1. initially the atom is in the state i,
2. we spend Ek - Ei energy to put the atom in the state k,
3. the atom emits a photon with useful energy Ek - Ej and changes its state to the state j,
4. the atom spontaneously changes its state to the state i, losing energy Ej - Ei,
5. the process repeats from step 1.
Let's define the energy conversion efficiency as <image>, i. e. the ration between the useful energy of the photon and spent energy.
Due to some limitations, Arkady can only choose such three states that Ek - Ei β€ U.
Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints.
Input
The first line contains two integers n and U (3 β€ n β€ 105, 1 β€ U β€ 109) β the number of states and the maximum possible difference between Ek and Ei.
The second line contains a sequence of integers E1, E2, ..., En (1 β€ E1 < E2... < En β€ 109). It is guaranteed that all Ei are given in increasing order.
Output
If it is not possible to choose three states that satisfy all constraints, print -1.
Otherwise, print one real number Ξ· β the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9.
Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>.
Examples
Input
4 4
1 3 5 7
Output
0.5
Input
10 8
10 13 15 16 17 19 20 22 24 25
Output
0.875
Input
3 1
2 5 10
Output
-1
Note
In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <image>.
In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <image>. | instruction | 0 | 8,136 | 3 | 16,272 |
Tags: binary search, greedy, two pointers
Correct Solution:
```
n,u=map(int,input().split())
arr=list(map(int,input().split()))
# arr.sort()
j,i=1,0
maxi=-1
flag=0
for i in range(n-1):
if arr[i+1]-arr[i]<=u:
flag=1
if flag==0:
print("-1")
exit()
i=0
while(i<n-2):
while(1):
if j>=n:
j=n-1
break
if arr[j]-arr[i]>u:
j-=1
break
j+=1
if i==j:
j+=1
elif arr[j]==arr[i]:
pass
elif arr[j]-arr[i]<=u:
# print(i,j)
maxi=max(maxi,(arr[j]-arr[i+1])/(arr[j]-arr[i]))
i+=1
if maxi==0:
print("-1")
else:
print(maxi)
``` | output | 1 | 8,136 | 3 | 16,273 |
Provide tags and a correct Python 3 solution for this coding contest problem.
An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme.
Three distinct states i, j and k are selected, where i < j < k. After that the following process happens:
1. initially the atom is in the state i,
2. we spend Ek - Ei energy to put the atom in the state k,
3. the atom emits a photon with useful energy Ek - Ej and changes its state to the state j,
4. the atom spontaneously changes its state to the state i, losing energy Ej - Ei,
5. the process repeats from step 1.
Let's define the energy conversion efficiency as <image>, i. e. the ration between the useful energy of the photon and spent energy.
Due to some limitations, Arkady can only choose such three states that Ek - Ei β€ U.
Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints.
Input
The first line contains two integers n and U (3 β€ n β€ 105, 1 β€ U β€ 109) β the number of states and the maximum possible difference between Ek and Ei.
The second line contains a sequence of integers E1, E2, ..., En (1 β€ E1 < E2... < En β€ 109). It is guaranteed that all Ei are given in increasing order.
Output
If it is not possible to choose three states that satisfy all constraints, print -1.
Otherwise, print one real number Ξ· β the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9.
Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>.
Examples
Input
4 4
1 3 5 7
Output
0.5
Input
10 8
10 13 15 16 17 19 20 22 24 25
Output
0.875
Input
3 1
2 5 10
Output
-1
Note
In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <image>.
In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <image>. | instruction | 0 | 8,137 | 3 | 16,274 |
Tags: binary search, greedy, two pointers
Correct Solution:
```
n,U=map(int,input().split())
Ar=list(map(int,input().split()))
R = 0;
ans = -1;
for i in range(n):
while R + 1 < n and Ar[R + 1] - Ar[i] <= U:
R+=1
if i+1 < R:
ans = max((Ar[R] - Ar[i + 1]) / (Ar[R] - Ar[i]),ans);
print(ans)
``` | output | 1 | 8,137 | 3 | 16,275 |
Provide tags and a correct Python 3 solution for this coding contest problem.
An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme.
Three distinct states i, j and k are selected, where i < j < k. After that the following process happens:
1. initially the atom is in the state i,
2. we spend Ek - Ei energy to put the atom in the state k,
3. the atom emits a photon with useful energy Ek - Ej and changes its state to the state j,
4. the atom spontaneously changes its state to the state i, losing energy Ej - Ei,
5. the process repeats from step 1.
Let's define the energy conversion efficiency as <image>, i. e. the ration between the useful energy of the photon and spent energy.
Due to some limitations, Arkady can only choose such three states that Ek - Ei β€ U.
Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints.
Input
The first line contains two integers n and U (3 β€ n β€ 105, 1 β€ U β€ 109) β the number of states and the maximum possible difference between Ek and Ei.
The second line contains a sequence of integers E1, E2, ..., En (1 β€ E1 < E2... < En β€ 109). It is guaranteed that all Ei are given in increasing order.
Output
If it is not possible to choose three states that satisfy all constraints, print -1.
Otherwise, print one real number Ξ· β the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9.
Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>.
Examples
Input
4 4
1 3 5 7
Output
0.5
Input
10 8
10 13 15 16 17 19 20 22 24 25
Output
0.875
Input
3 1
2 5 10
Output
-1
Note
In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <image>.
In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <image>. | instruction | 0 | 8,138 | 3 | 16,276 |
Tags: binary search, greedy, two pointers
Correct Solution:
```
import sys
def read_two_int():
return map(int, sys.stdin.readline().strip().split(' '))
def fast_solution(n, U, E):
best = -1
R = 2
for i in range(n-2):
# move R forcefully
R = max(R, i+2)
while (R + 1 < n) and (E[R+1] - E[i] <= U):
R += 1
if E[R] - E[i] <= U:
efficiency = float(E[R] - E[i+1]) / (E[R] - E[i])
if best is None or efficiency > best:
best = efficiency
return best
n, U = read_two_int()
E = list(read_two_int())
print(fast_solution(n, U, E))
``` | output | 1 | 8,138 | 3 | 16,277 |
Provide tags and a correct Python 3 solution for this coding contest problem.
An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme.
Three distinct states i, j and k are selected, where i < j < k. After that the following process happens:
1. initially the atom is in the state i,
2. we spend Ek - Ei energy to put the atom in the state k,
3. the atom emits a photon with useful energy Ek - Ej and changes its state to the state j,
4. the atom spontaneously changes its state to the state i, losing energy Ej - Ei,
5. the process repeats from step 1.
Let's define the energy conversion efficiency as <image>, i. e. the ration between the useful energy of the photon and spent energy.
Due to some limitations, Arkady can only choose such three states that Ek - Ei β€ U.
Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints.
Input
The first line contains two integers n and U (3 β€ n β€ 105, 1 β€ U β€ 109) β the number of states and the maximum possible difference between Ek and Ei.
The second line contains a sequence of integers E1, E2, ..., En (1 β€ E1 < E2... < En β€ 109). It is guaranteed that all Ei are given in increasing order.
Output
If it is not possible to choose three states that satisfy all constraints, print -1.
Otherwise, print one real number Ξ· β the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9.
Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>.
Examples
Input
4 4
1 3 5 7
Output
0.5
Input
10 8
10 13 15 16 17 19 20 22 24 25
Output
0.875
Input
3 1
2 5 10
Output
-1
Note
In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <image>.
In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <image>. | instruction | 0 | 8,139 | 3 | 16,278 |
Tags: binary search, greedy, two pointers
Correct Solution:
```
n,u = map(int,input().split())
a = list(map(int,input().split()))
i = 0
j = 1
f = 1
ma = -1
while not((i==j) and (i==n-1)):
if j<=i:
j+=1
if j < n-1:
if a[j+1]-a[i] <= u:
j+=1
else:
if j-i >= 2:
f=0
#print(i,j)
ma = max(ma,(a[j]-a[i+1])/(a[j]-a[i]))
i+=1
else:
if j-i >= 2:
f=0
#print(i,j)
ma = max(ma,(a[j]-a[i+1])/(a[j]-a[i]))
i+=1
if f:print(-1)
else:print(ma)
``` | output | 1 | 8,139 | 3 | 16,279 |
Provide tags and a correct Python 3 solution for this coding contest problem.
An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme.
Three distinct states i, j and k are selected, where i < j < k. After that the following process happens:
1. initially the atom is in the state i,
2. we spend Ek - Ei energy to put the atom in the state k,
3. the atom emits a photon with useful energy Ek - Ej and changes its state to the state j,
4. the atom spontaneously changes its state to the state i, losing energy Ej - Ei,
5. the process repeats from step 1.
Let's define the energy conversion efficiency as <image>, i. e. the ration between the useful energy of the photon and spent energy.
Due to some limitations, Arkady can only choose such three states that Ek - Ei β€ U.
Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints.
Input
The first line contains two integers n and U (3 β€ n β€ 105, 1 β€ U β€ 109) β the number of states and the maximum possible difference between Ek and Ei.
The second line contains a sequence of integers E1, E2, ..., En (1 β€ E1 < E2... < En β€ 109). It is guaranteed that all Ei are given in increasing order.
Output
If it is not possible to choose three states that satisfy all constraints, print -1.
Otherwise, print one real number Ξ· β the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9.
Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>.
Examples
Input
4 4
1 3 5 7
Output
0.5
Input
10 8
10 13 15 16 17 19 20 22 24 25
Output
0.875
Input
3 1
2 5 10
Output
-1
Note
In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <image>.
In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <image>. | instruction | 0 | 8,140 | 3 | 16,280 |
Tags: binary search, greedy, two pointers
Correct Solution:
```
n, U = [int(c) for c in input().split(" ")]
E = [int(c) for c in input().split(" ")]
def binary_max_search(max_limit): # give index biggest, but less than max_limit
left, right = 0, n-1
while left < right:
mid = (left+right)//2 + 1
#print(left, mid, right)
if E[mid] <= max_limit:
left, right = mid, right
else:
left, right = left, mid - 1
return left
max_conversion_rate = -1
for i in range(n-2):
k = binary_max_search(U + E[i])
#print("Find for (%d, %d, K) = %d" % (i, i+1, k))
if k > i+1:
temp = (E[k] - E[i+1]) / (E[k] - E[i])
#print("Conversion rate = %f" % temp)
if temp > max_conversion_rate:
max_conversion_rate = temp
print(max_conversion_rate)
``` | output | 1 | 8,140 | 3 | 16,281 |
Provide tags and a correct Python 3 solution for this coding contest problem.
An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme.
Three distinct states i, j and k are selected, where i < j < k. After that the following process happens:
1. initially the atom is in the state i,
2. we spend Ek - Ei energy to put the atom in the state k,
3. the atom emits a photon with useful energy Ek - Ej and changes its state to the state j,
4. the atom spontaneously changes its state to the state i, losing energy Ej - Ei,
5. the process repeats from step 1.
Let's define the energy conversion efficiency as <image>, i. e. the ration between the useful energy of the photon and spent energy.
Due to some limitations, Arkady can only choose such three states that Ek - Ei β€ U.
Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints.
Input
The first line contains two integers n and U (3 β€ n β€ 105, 1 β€ U β€ 109) β the number of states and the maximum possible difference between Ek and Ei.
The second line contains a sequence of integers E1, E2, ..., En (1 β€ E1 < E2... < En β€ 109). It is guaranteed that all Ei are given in increasing order.
Output
If it is not possible to choose three states that satisfy all constraints, print -1.
Otherwise, print one real number Ξ· β the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9.
Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>.
Examples
Input
4 4
1 3 5 7
Output
0.5
Input
10 8
10 13 15 16 17 19 20 22 24 25
Output
0.875
Input
3 1
2 5 10
Output
-1
Note
In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <image>.
In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <image>. | instruction | 0 | 8,141 | 3 | 16,282 |
Tags: binary search, greedy, two pointers
Correct Solution:
```
def sss(l,r,tt):
f = -1
while(l<=r):
mid = (l + r) >> 1
if(a[mid]-a[tt] <= m):
f = mid
l = mid + 1
else :
r = mid - 1
return f
n , m = map(int, input().split())
a = [int(x) for x in input().split()]
f = 0
l = len(a)
#print("l==" + str(l))
Maxx = -1
for i in range(0,l-2):
if(a[i+2] - a[i]<= m):
k = sss(i+2,l-1,i)
if(k != -1):
Maxx = max(Maxx,(a[k] - a[i+1])/(a[k]-a[i]))
if(Maxx == -1):
print(-1)
else: print("%.15f\n" % Maxx)
``` | output | 1 | 8,141 | 3 | 16,283 |
Provide tags and a correct Python 3 solution for this coding contest problem.
An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme.
Three distinct states i, j and k are selected, where i < j < k. After that the following process happens:
1. initially the atom is in the state i,
2. we spend Ek - Ei energy to put the atom in the state k,
3. the atom emits a photon with useful energy Ek - Ej and changes its state to the state j,
4. the atom spontaneously changes its state to the state i, losing energy Ej - Ei,
5. the process repeats from step 1.
Let's define the energy conversion efficiency as <image>, i. e. the ration between the useful energy of the photon and spent energy.
Due to some limitations, Arkady can only choose such three states that Ek - Ei β€ U.
Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints.
Input
The first line contains two integers n and U (3 β€ n β€ 105, 1 β€ U β€ 109) β the number of states and the maximum possible difference between Ek and Ei.
The second line contains a sequence of integers E1, E2, ..., En (1 β€ E1 < E2... < En β€ 109). It is guaranteed that all Ei are given in increasing order.
Output
If it is not possible to choose three states that satisfy all constraints, print -1.
Otherwise, print one real number Ξ· β the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9.
Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>.
Examples
Input
4 4
1 3 5 7
Output
0.5
Input
10 8
10 13 15 16 17 19 20 22 24 25
Output
0.875
Input
3 1
2 5 10
Output
-1
Note
In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <image>.
In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <image>. | instruction | 0 | 8,142 | 3 | 16,284 |
Tags: binary search, greedy, two pointers
Correct Solution:
```
nE, U = [int(x) for x in input().split(" ")]
energies = [int(x) for x in input().split(" ")]
end = 0
best_ratio = -1
for beg in range(nE-2):
while(end+1 < nE and energies[end+1] - energies[beg] <= U):
end += 1
if end - beg < 2:
continue
new_ratio = (energies[end] - energies[beg+1]) / (energies[end] - energies[beg])
best_ratio = max(best_ratio, new_ratio)
if best_ratio == -1:
print(-1)
else:
print("%.20f" % best_ratio)
``` | output | 1 | 8,142 | 3 | 16,285 |
Provide tags and a correct Python 3 solution for this coding contest problem.
An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme.
Three distinct states i, j and k are selected, where i < j < k. After that the following process happens:
1. initially the atom is in the state i,
2. we spend Ek - Ei energy to put the atom in the state k,
3. the atom emits a photon with useful energy Ek - Ej and changes its state to the state j,
4. the atom spontaneously changes its state to the state i, losing energy Ej - Ei,
5. the process repeats from step 1.
Let's define the energy conversion efficiency as <image>, i. e. the ration between the useful energy of the photon and spent energy.
Due to some limitations, Arkady can only choose such three states that Ek - Ei β€ U.
Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints.
Input
The first line contains two integers n and U (3 β€ n β€ 105, 1 β€ U β€ 109) β the number of states and the maximum possible difference between Ek and Ei.
The second line contains a sequence of integers E1, E2, ..., En (1 β€ E1 < E2... < En β€ 109). It is guaranteed that all Ei are given in increasing order.
Output
If it is not possible to choose three states that satisfy all constraints, print -1.
Otherwise, print one real number Ξ· β the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9.
Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>.
Examples
Input
4 4
1 3 5 7
Output
0.5
Input
10 8
10 13 15 16 17 19 20 22 24 25
Output
0.875
Input
3 1
2 5 10
Output
-1
Note
In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <image>.
In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <image>. | instruction | 0 | 8,143 | 3 | 16,286 |
Tags: binary search, greedy, two pointers
Correct Solution:
```
n,U = map(int,input().split())
E = [int(x) for x in input().split()]
E.append(10**100)
k = 0
best = -1
for i in range(n):
while E[k+1]-E[i] <= U:
k += 1
j = i+1
if i<j<k:
best = max(best, (E[k]-E[j])/(E[k]-E[i]))
print(best)
``` | output | 1 | 8,143 | 3 | 16,287 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme.
Three distinct states i, j and k are selected, where i < j < k. After that the following process happens:
1. initially the atom is in the state i,
2. we spend Ek - Ei energy to put the atom in the state k,
3. the atom emits a photon with useful energy Ek - Ej and changes its state to the state j,
4. the atom spontaneously changes its state to the state i, losing energy Ej - Ei,
5. the process repeats from step 1.
Let's define the energy conversion efficiency as <image>, i. e. the ration between the useful energy of the photon and spent energy.
Due to some limitations, Arkady can only choose such three states that Ek - Ei β€ U.
Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints.
Input
The first line contains two integers n and U (3 β€ n β€ 105, 1 β€ U β€ 109) β the number of states and the maximum possible difference between Ek and Ei.
The second line contains a sequence of integers E1, E2, ..., En (1 β€ E1 < E2... < En β€ 109). It is guaranteed that all Ei are given in increasing order.
Output
If it is not possible to choose three states that satisfy all constraints, print -1.
Otherwise, print one real number Ξ· β the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9.
Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>.
Examples
Input
4 4
1 3 5 7
Output
0.5
Input
10 8
10 13 15 16 17 19 20 22 24 25
Output
0.875
Input
3 1
2 5 10
Output
-1
Note
In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <image>.
In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <image>.
Submitted Solution:
```
n, U = list(map(int, input().split()))
E = list(map(int, input().split()))
ind_i = 0
prev_ind_k = ind_i + 2
maxi_efficiency = -1
turn = 0
for ind_i in range(0, n - 2):
ind_j = ind_i + 1
prev_ind_k = max(prev_ind_k, ind_i + 2)
Ei = E[ind_i]
Ej = E[ind_j]
for ind_k in range(prev_ind_k, n + 1):
# print("ind_i, ind_k", ind_i, ind_k)
if ind_k == n:
prev_ind_k = n - 1
break
Ek = E[ind_k]
if (Ek - Ei) > U:
prev_ind_k = ind_k - 1
break
efficiency = (Ek - Ej) / (Ek - Ei)
# print("efficiency : ", efficiency)
if efficiency > maxi_efficiency:
# print(ind_i, ind_k)
maxi_efficiency = efficiency
print(maxi_efficiency)
# if (ind_i == n-3 and ind_j == n-2 and ind_k == n-1):
# break
# n, U = list(map(int, input().split()))
# E = list(map(int, input().split()))
# ind_i = 0
# ind_k = 2
# maxi_efficiency = -1
# turn = 0
# while ind_i < n - 2 and ind_k < n:
# # print("ind_i, ind_j : ", ind_i, ind_k)
# ind_j = ind_i + 1
# Ei = E[ind_i]
# Ej = E[ind_j]
# Ek = E[ind_k]
# if (Ek - Ei) > U:
# # print("too much")
# ind_i += 1
# ind_k = max(ind_k, ind_i + 2)
# continue
# else:
# efficiency = (Ek - Ej) / (Ek - Ei)
# # print("efficiency : ", efficiency)
# if efficiency > maxi_efficiency:
# print(ind_i, ind_k)
# maxi_efficiency = efficiency
# ind_k += 1
# print(maxi_efficiency)
# if (ind_i == n-3 and ind_j == n-2 and ind_k == n-1):
# break
# n, U = list(map(int, input().split()))
# E = list(map(int, input().split()))
# ind_i = 0
# maxi_efficiency = -1
# turn = 0
# while ind_i < n - 3:
# ind_j = ind_i + 1
# Ei = E[ind_i]
# Ej = E[ind_j]
# for ind_k in range(ind_j + 1, n):
# Ek = E[ind_k]
# if (Ek - Ei) > U:
# break
# efficiency = (Ek - Ej) / (Ek - Ei)
# # print("efficiency : ", efficiency)
# if efficiency > maxi_efficiency:
# maxi_efficiency = efficiency
# ind_i += 1
# print(maxi_efficiency)
# # if (ind_i == n-3 and ind_j == n-2 and ind_k == n-1):
# # break
``` | instruction | 0 | 8,144 | 3 | 16,288 |
Yes | output | 1 | 8,144 | 3 | 16,289 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme.
Three distinct states i, j and k are selected, where i < j < k. After that the following process happens:
1. initially the atom is in the state i,
2. we spend Ek - Ei energy to put the atom in the state k,
3. the atom emits a photon with useful energy Ek - Ej and changes its state to the state j,
4. the atom spontaneously changes its state to the state i, losing energy Ej - Ei,
5. the process repeats from step 1.
Let's define the energy conversion efficiency as <image>, i. e. the ration between the useful energy of the photon and spent energy.
Due to some limitations, Arkady can only choose such three states that Ek - Ei β€ U.
Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints.
Input
The first line contains two integers n and U (3 β€ n β€ 105, 1 β€ U β€ 109) β the number of states and the maximum possible difference between Ek and Ei.
The second line contains a sequence of integers E1, E2, ..., En (1 β€ E1 < E2... < En β€ 109). It is guaranteed that all Ei are given in increasing order.
Output
If it is not possible to choose three states that satisfy all constraints, print -1.
Otherwise, print one real number Ξ· β the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9.
Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>.
Examples
Input
4 4
1 3 5 7
Output
0.5
Input
10 8
10 13 15 16 17 19 20 22 24 25
Output
0.875
Input
3 1
2 5 10
Output
-1
Note
In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <image>.
In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <image>.
Submitted Solution:
```
n, u = map(int, input().split())
a = list(map(int, input().split()))
l, r = 0, 0
ans = -1
for i in range(n):
r = max(l, r)
while r < n - 1 and a[r + 1] - a[l] <= u:
r += 1
if r - l > 1 and a[r] - a[l] <= u:
ans = max(ans, (a[r] - a[l + 1]) / (a[r] - a[l]))
l += 1
print(ans)
``` | instruction | 0 | 8,145 | 3 | 16,290 |
Yes | output | 1 | 8,145 | 3 | 16,291 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme.
Three distinct states i, j and k are selected, where i < j < k. After that the following process happens:
1. initially the atom is in the state i,
2. we spend Ek - Ei energy to put the atom in the state k,
3. the atom emits a photon with useful energy Ek - Ej and changes its state to the state j,
4. the atom spontaneously changes its state to the state i, losing energy Ej - Ei,
5. the process repeats from step 1.
Let's define the energy conversion efficiency as <image>, i. e. the ration between the useful energy of the photon and spent energy.
Due to some limitations, Arkady can only choose such three states that Ek - Ei β€ U.
Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints.
Input
The first line contains two integers n and U (3 β€ n β€ 105, 1 β€ U β€ 109) β the number of states and the maximum possible difference between Ek and Ei.
The second line contains a sequence of integers E1, E2, ..., En (1 β€ E1 < E2... < En β€ 109). It is guaranteed that all Ei are given in increasing order.
Output
If it is not possible to choose three states that satisfy all constraints, print -1.
Otherwise, print one real number Ξ· β the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9.
Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>.
Examples
Input
4 4
1 3 5 7
Output
0.5
Input
10 8
10 13 15 16 17 19 20 22 24 25
Output
0.875
Input
3 1
2 5 10
Output
-1
Note
In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <image>.
In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <image>.
Submitted Solution:
```
# # vars: j, e, n, res, u
# n, u = map(int, input().split())
# e = list(map(int, input().split()))
# res = 0
# k = 2
# for i in range(n-1):
# while e[k]-e[i] <= u:
# vars: i, n, u
n, u = map(int, input().split())
e = list(map(int, input().split()))
res = -1
k = 2
for i in range(n-2):
j = i+1
k = max(k, j+1)
while (k < n) and (e[k]-e[i] <= u):
k += 1
k -= 1
if k > j:
res = max(res, (e[k]-e[j])/(e[k]-e[i]))
print(res)
``` | instruction | 0 | 8,146 | 3 | 16,292 |
Yes | output | 1 | 8,146 | 3 | 16,293 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme.
Three distinct states i, j and k are selected, where i < j < k. After that the following process happens:
1. initially the atom is in the state i,
2. we spend Ek - Ei energy to put the atom in the state k,
3. the atom emits a photon with useful energy Ek - Ej and changes its state to the state j,
4. the atom spontaneously changes its state to the state i, losing energy Ej - Ei,
5. the process repeats from step 1.
Let's define the energy conversion efficiency as <image>, i. e. the ration between the useful energy of the photon and spent energy.
Due to some limitations, Arkady can only choose such three states that Ek - Ei β€ U.
Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints.
Input
The first line contains two integers n and U (3 β€ n β€ 105, 1 β€ U β€ 109) β the number of states and the maximum possible difference between Ek and Ei.
The second line contains a sequence of integers E1, E2, ..., En (1 β€ E1 < E2... < En β€ 109). It is guaranteed that all Ei are given in increasing order.
Output
If it is not possible to choose three states that satisfy all constraints, print -1.
Otherwise, print one real number Ξ· β the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9.
Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>.
Examples
Input
4 4
1 3 5 7
Output
0.5
Input
10 8
10 13 15 16 17 19 20 22 24 25
Output
0.875
Input
3 1
2 5 10
Output
-1
Note
In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <image>.
In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <image>.
Submitted Solution:
```
n,u = map(int , input().split())
e = list(map(int , input().split()))
e = sorted(e)
r = 1
ans = -1
for i in range(n-2):
k = e[i+1] - e[i]
while r < n and e[r] - e[i] <= u:
r+=1
pr = r-1
if pr - i>= 2:
ans = max(ans, (e[pr] - e[i+1])/(e[pr] - e[i]))
if ans == -1:
print(-1)
exit()
print("%.12f" % ans)
``` | instruction | 0 | 8,147 | 3 | 16,294 |
Yes | output | 1 | 8,147 | 3 | 16,295 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme.
Three distinct states i, j and k are selected, where i < j < k. After that the following process happens:
1. initially the atom is in the state i,
2. we spend Ek - Ei energy to put the atom in the state k,
3. the atom emits a photon with useful energy Ek - Ej and changes its state to the state j,
4. the atom spontaneously changes its state to the state i, losing energy Ej - Ei,
5. the process repeats from step 1.
Let's define the energy conversion efficiency as <image>, i. e. the ration between the useful energy of the photon and spent energy.
Due to some limitations, Arkady can only choose such three states that Ek - Ei β€ U.
Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints.
Input
The first line contains two integers n and U (3 β€ n β€ 105, 1 β€ U β€ 109) β the number of states and the maximum possible difference between Ek and Ei.
The second line contains a sequence of integers E1, E2, ..., En (1 β€ E1 < E2... < En β€ 109). It is guaranteed that all Ei are given in increasing order.
Output
If it is not possible to choose three states that satisfy all constraints, print -1.
Otherwise, print one real number Ξ· β the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9.
Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>.
Examples
Input
4 4
1 3 5 7
Output
0.5
Input
10 8
10 13 15 16 17 19 20 22 24 25
Output
0.875
Input
3 1
2 5 10
Output
-1
Note
In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <image>.
In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <image>.
Submitted Solution:
```
par = input()
par = list(map(int, par.split()))
n, U = par[0], par[1]
E = input()
E = list(map(int, E.split()))
def max_le(seq, val):
idx = len(seq)-1
while idx >= 0:
if seq[idx] <= val:
return idx
idx -= 1
return None
res = max_le(E, E[0] + U)
f = -1
for i in range(n - 3):
idx = max_le(E, E[i] + U)
if idx == -1 or idx - i < 2:
continue
else:
f = max((E[idx] - E[i + 1]) / (E[idx] - E[i]), f)
print(f)
``` | instruction | 0 | 8,148 | 3 | 16,296 |
No | output | 1 | 8,148 | 3 | 16,297 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme.
Three distinct states i, j and k are selected, where i < j < k. After that the following process happens:
1. initially the atom is in the state i,
2. we spend Ek - Ei energy to put the atom in the state k,
3. the atom emits a photon with useful energy Ek - Ej and changes its state to the state j,
4. the atom spontaneously changes its state to the state i, losing energy Ej - Ei,
5. the process repeats from step 1.
Let's define the energy conversion efficiency as <image>, i. e. the ration between the useful energy of the photon and spent energy.
Due to some limitations, Arkady can only choose such three states that Ek - Ei β€ U.
Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints.
Input
The first line contains two integers n and U (3 β€ n β€ 105, 1 β€ U β€ 109) β the number of states and the maximum possible difference between Ek and Ei.
The second line contains a sequence of integers E1, E2, ..., En (1 β€ E1 < E2... < En β€ 109). It is guaranteed that all Ei are given in increasing order.
Output
If it is not possible to choose three states that satisfy all constraints, print -1.
Otherwise, print one real number Ξ· β the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9.
Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>.
Examples
Input
4 4
1 3 5 7
Output
0.5
Input
10 8
10 13 15 16 17 19 20 22 24 25
Output
0.875
Input
3 1
2 5 10
Output
-1
Note
In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <image>.
In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <image>.
Submitted Solution:
```
n, U = list(map(int , input().split()))
E = list(map(int , input().split()))
E.append(10**20)
E.append(10**20)
E.append(10**20)
start = 0
finish = 1
res = -1
while start < n-1:
while (E[finish] - E[start] >U) and start < n - 1 :
start += 1
while (E[finish+1] - E[start] <=U) and (finish+1 < n):
finish +=1
# print(start, finish)
if finish - start >1 and finish<n and start<n:
if E[finish] - E[start] <=U:
res = max(res, (E[finish] - E[start+1])/(E[finish]- E[start]))
# print(start, finish, (E[finish] - E[start+1])/(E[finish]- E[start]))
finish += 1
print(res)
``` | instruction | 0 | 8,149 | 3 | 16,298 |
No | output | 1 | 8,149 | 3 | 16,299 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme.
Three distinct states i, j and k are selected, where i < j < k. After that the following process happens:
1. initially the atom is in the state i,
2. we spend Ek - Ei energy to put the atom in the state k,
3. the atom emits a photon with useful energy Ek - Ej and changes its state to the state j,
4. the atom spontaneously changes its state to the state i, losing energy Ej - Ei,
5. the process repeats from step 1.
Let's define the energy conversion efficiency as <image>, i. e. the ration between the useful energy of the photon and spent energy.
Due to some limitations, Arkady can only choose such three states that Ek - Ei β€ U.
Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints.
Input
The first line contains two integers n and U (3 β€ n β€ 105, 1 β€ U β€ 109) β the number of states and the maximum possible difference between Ek and Ei.
The second line contains a sequence of integers E1, E2, ..., En (1 β€ E1 < E2... < En β€ 109). It is guaranteed that all Ei are given in increasing order.
Output
If it is not possible to choose three states that satisfy all constraints, print -1.
Otherwise, print one real number Ξ· β the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9.
Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>.
Examples
Input
4 4
1 3 5 7
Output
0.5
Input
10 8
10 13 15 16 17 19 20 22 24 25
Output
0.875
Input
3 1
2 5 10
Output
-1
Note
In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <image>.
In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <image>.
Submitted Solution:
```
n,U=list(map(int, input().split(' ')))
a=list(map(int, input().split(' ')))
import bisect
def max_eligible(a,x):
ind=bisect.bisect_right(a,x)
if ind < len(a):
return a[ind-1]
else:
return -1
max_val=-1
for i in range(n-2):
x = a[i]+U
val1 = max_eligible(a,x)
if val1!=-1 and val1!=a[i+1] and val1!=a[i]:
# print('hi')
val = (val1-a[i+1]) / (val1-a[i])
# print(val)
max_val=max(max_val,val)
# print(a[i],a[i+1],val1,max_val)
print(max_val)
``` | instruction | 0 | 8,150 | 3 | 16,300 |
No | output | 1 | 8,150 | 3 | 16,301 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme.
Three distinct states i, j and k are selected, where i < j < k. After that the following process happens:
1. initially the atom is in the state i,
2. we spend Ek - Ei energy to put the atom in the state k,
3. the atom emits a photon with useful energy Ek - Ej and changes its state to the state j,
4. the atom spontaneously changes its state to the state i, losing energy Ej - Ei,
5. the process repeats from step 1.
Let's define the energy conversion efficiency as <image>, i. e. the ration between the useful energy of the photon and spent energy.
Due to some limitations, Arkady can only choose such three states that Ek - Ei β€ U.
Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints.
Input
The first line contains two integers n and U (3 β€ n β€ 105, 1 β€ U β€ 109) β the number of states and the maximum possible difference between Ek and Ei.
The second line contains a sequence of integers E1, E2, ..., En (1 β€ E1 < E2... < En β€ 109). It is guaranteed that all Ei are given in increasing order.
Output
If it is not possible to choose three states that satisfy all constraints, print -1.
Otherwise, print one real number Ξ· β the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9.
Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>.
Examples
Input
4 4
1 3 5 7
Output
0.5
Input
10 8
10 13 15 16 17 19 20 22 24 25
Output
0.875
Input
3 1
2 5 10
Output
-1
Note
In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <image>.
In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <image>.
Submitted Solution:
```
n,u=map(int,input().split())
arr=list(map(int,input().split()))
# arr.sort()
j,i=1,0
maxi=-1
flag=0
for i in range(n-1):
if arr[i+1]-arr[i]<=u:
flag=1
if flag==0:
print("-1")
exit()
i=0
while(i<n-2):
while(1):
if j>=n:
j=n-1
break
if arr[j]-arr[i]>u:
j-=1
break
j+=1
if i==j:
j+=1
elif arr[j]==arr[i]:
pass
elif arr[j]-arr[i]<=u:
# print(i,j)
maxi=max(maxi,(arr[j]-arr[i+1])/(arr[j]-arr[i]))
i+=1
print(maxi)
``` | instruction | 0 | 8,151 | 3 | 16,302 |
No | output | 1 | 8,151 | 3 | 16,303 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi is an expert of Clone Jutsu, a secret art that creates copies of his body.
On a number line, there are N copies of Takahashi, numbered 1 through N. The i-th copy is located at position X_i and starts walking with velocity V_i in the positive direction at time 0.
Kenus is a master of Transformation Jutsu, and not only can he change into a person other than himself, but he can also transform another person into someone else.
Kenus can select some of the copies of Takahashi at time 0, and transform them into copies of Aoki, another Ninja. The walking velocity of a copy does not change when it transforms. From then on, whenever a copy of Takahashi and a copy of Aoki are at the same coordinate, that copy of Takahashi transforms into a copy of Aoki.
Among the 2^N ways to transform some copies of Takahashi into copies of Aoki at time 0, in how many ways will all the copies of Takahashi become copies of Aoki after a sufficiently long time? Find the count modulo 10^9+7.
Constraints
* 1 β€ N β€ 200000
* 1 β€ X_i,V_i β€ 10^9(1 β€ i β€ N)
* X_i and V_i are integers.
* All X_i are distinct.
* All V_i are distinct.
Input
The input is given from Standard Input in the following format:
N
X_1 V_1
:
X_N V_N
Output
Print the number of the ways that cause all the copies of Takahashi to turn into copies of Aoki after a sufficiently long time, modulo 10^9+7.
Examples
Input
3
2 5
6 1
3 7
Output
6
Input
4
3 7
2 9
8 16
10 8
Output
9 | instruction | 0 | 8,288 | 3 | 16,576 |
"Correct Solution:
```
class BIT():
def __init__(self,n,mod):
self.BIT=[0]*(n+1)
self.num=n
self.mod=mod
def query(self,idx):
res_sum = 0
mod=self.mod
while idx > 0:
res_sum += self.BIT[idx]
res_sum%=mod
idx -= idx&(-idx)
return res_sum
#Ai += x O(logN)
def update(self,idx,x):
mod=self.mod
while idx <= self.num:
self.BIT[idx] += x
self.BIT[idx]%=mod
idx += idx&(-idx)
return
import sys,bisect
input=sys.stdin.readline
mod=10**9+7
inv=pow(2,mod-2,mod)
N=int(input())
taka=[tuple(map(int,input().split())) for i in range(N)]
taka.sort()
V=[0]+[taka[i][1] for i in range(N)]+[10**15]
cummin=[V[i] for i in range(N+2)]
for i in range(N,-1,-1):
cummin[i]=min(cummin[i],cummin[i+1])
cummax=[V[i] for i in range(N+2)]
for i in range(1,N+2):
cummax[i]=max(cummax[i],cummax[i-1])
const=[]
for i in range(1,N+1):
R=bisect.bisect_right(cummin,V[i])-1
L=bisect.bisect_left(cummax,V[i])
const.append((L,R))
Lconst=[(i,10**15) for i in range(N+1)]
for L,R in const:
pL,pR=Lconst[L]
Lconst[L]=(L,min(R,pR))
_const=[]
for i in range(1,N+1):
L,R=Lconst[i]
if R!=10**15:
_const.append((L,R))
const=[]
for L,R in _const:
while const and const[-1][1]>=R:
const.pop()
const.append((L,R))
M=len(const)
const=[(-10**15,0)]+const
Rconst=[const[i][1] for i in range(M+1)]
B=BIT(M,mod)
dp=[1]*(M+1)
for i in range(1,M+1):
L,R=const[i]
id=bisect.bisect_left(Rconst,L)
res=(B.query(i-1)-B.query(id-1))%mod
l,r=const[id]
l=max(l,Rconst[id-1]+1)
res+=dp[id-1]*(pow(2,r-L+1,mod)-1)*pow(2,L-l,mod)%mod
res%=mod
dp[i]=res
if i!=M:
nR=Rconst[i+1]
add=dp[i]*(pow(2,nR-R,mod)-1)%mod
add%=mod
B.update(i,add)
cnt=0
data=[0]*(N+2)
for i in range(1,M+1):
L,R=const[i]
data[L]+=1
data[R+1]+=-1
for i in range(1,N+2):
data[i]+=data[i-1]
for i in range(1,N+1):
if data[i]==0:
cnt+=1
ans=pow(2,cnt,mod)*dp[M]
ans%=mod
print(ans)
``` | output | 1 | 8,288 | 3 | 16,577 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi is an expert of Clone Jutsu, a secret art that creates copies of his body.
On a number line, there are N copies of Takahashi, numbered 1 through N. The i-th copy is located at position X_i and starts walking with velocity V_i in the positive direction at time 0.
Kenus is a master of Transformation Jutsu, and not only can he change into a person other than himself, but he can also transform another person into someone else.
Kenus can select some of the copies of Takahashi at time 0, and transform them into copies of Aoki, another Ninja. The walking velocity of a copy does not change when it transforms. From then on, whenever a copy of Takahashi and a copy of Aoki are at the same coordinate, that copy of Takahashi transforms into a copy of Aoki.
Among the 2^N ways to transform some copies of Takahashi into copies of Aoki at time 0, in how many ways will all the copies of Takahashi become copies of Aoki after a sufficiently long time? Find the count modulo 10^9+7.
Constraints
* 1 β€ N β€ 200000
* 1 β€ X_i,V_i β€ 10^9(1 β€ i β€ N)
* X_i and V_i are integers.
* All X_i are distinct.
* All V_i are distinct.
Input
The input is given from Standard Input in the following format:
N
X_1 V_1
:
X_N V_N
Output
Print the number of the ways that cause all the copies of Takahashi to turn into copies of Aoki after a sufficiently long time, modulo 10^9+7.
Examples
Input
3
2 5
6 1
3 7
Output
6
Input
4
3 7
2 9
8 16
10 8
Output
9
Submitted Solution:
```
import sys
input=sys.stdin.readline
mod=10*9+7
N=int(input())
taka=[tuple(map(int,input().split())) for i in range(N)]
taka.sort()
V=[0]+[taka[i][1] for i in range(N)]+[10**15]
cummin=[V[i] for i in range(N+2)]
for i in range(N,-1,-1):
cummin[i]=min(cummin[i],cummin[i+1])
cummax=[V[i] for i in range(N+2)]
for i in range(1,N+2):
cummax[i]=max(cummax[i],cummax[i-1])
newV=[]
for i in range(1,N+1):
if not (V[i]>cummax[i-1] and cummin[i+1]>V[i]):
newV.append(V[i])
V=newV
N=len(V)
all=pow(2,N,mod)
highid,lowid=-1,-1
Vmax=cummax[-2]
Vmin=cummin[1]
for i in range(0,N):
if V[i]==Vmax:
highid=i+1
elif V[i]==Vmin:
lowid=i+1
high=pow(2,highid-1,mod)
low=pow(2,N-lowid,mod)
if highid>lowid:
highlow=pow(2,N+1-highid-lowid,mod)
else:
highlow=1
ans=all+highlow-high-low
print(ans%mod)
``` | instruction | 0 | 8,289 | 3 | 16,578 |
No | output | 1 | 8,289 | 3 | 16,579 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi is an expert of Clone Jutsu, a secret art that creates copies of his body.
On a number line, there are N copies of Takahashi, numbered 1 through N. The i-th copy is located at position X_i and starts walking with velocity V_i in the positive direction at time 0.
Kenus is a master of Transformation Jutsu, and not only can he change into a person other than himself, but he can also transform another person into someone else.
Kenus can select some of the copies of Takahashi at time 0, and transform them into copies of Aoki, another Ninja. The walking velocity of a copy does not change when it transforms. From then on, whenever a copy of Takahashi and a copy of Aoki are at the same coordinate, that copy of Takahashi transforms into a copy of Aoki.
Among the 2^N ways to transform some copies of Takahashi into copies of Aoki at time 0, in how many ways will all the copies of Takahashi become copies of Aoki after a sufficiently long time? Find the count modulo 10^9+7.
Constraints
* 1 β€ N β€ 200000
* 1 β€ X_i,V_i β€ 10^9(1 β€ i β€ N)
* X_i and V_i are integers.
* All X_i are distinct.
* All V_i are distinct.
Input
The input is given from Standard Input in the following format:
N
X_1 V_1
:
X_N V_N
Output
Print the number of the ways that cause all the copies of Takahashi to turn into copies of Aoki after a sufficiently long time, modulo 10^9+7.
Examples
Input
3
2 5
6 1
3 7
Output
6
Input
4
3 7
2 9
8 16
10 8
Output
9
Submitted Solution:
```
class BIT():
def __init__(self,n,mod):
self.BIT=[0]*(n+1)
self.num=n
self.mod=mod
def query(self,idx):
res_sum = 0
mod=self.mod
while idx > 0:
res_sum += self.BIT[idx]
res_sum%=mod
idx -= idx&(-idx)
return res_sum
#Ai += x O(logN)
def update(self,idx,x):
mod=self.mod
while idx <= self.num:
self.BIT[idx] += x
self.BIT[idx]%=mod
idx += idx&(-idx)
return
import sys,bisect
input=sys.stdin.readline
mod=10*9+7
N=int(input())
taka=[tuple(map(int,input().split())) for i in range(N)]
taka.sort()
V=[0]+[taka[i][1] for i in range(N)]+[10**15]
cummin=[V[i] for i in range(N+2)]
for i in range(N,-1,-1):
cummin[i]=min(cummin[i],cummin[i+1])
cummax=[V[i] for i in range(N+2)]
for i in range(1,N+2):
cummax[i]=max(cummax[i],cummax[i-1])
const=[]
for i in range(1,N+1):
R=bisect.bisect_right(cummin,V[i])-1
L=bisect.bisect_left(cummax,V[i])
const.append((L,R))
Lconst=[(i,10**15) for i in range(N+1)]
for L,R in const:
pL,pR=Lconst[L]
Lconst[L]=(L,min(R,pR))
_const=[]
for i in range(1,N+1):
L,R=Lconst[i]
if R!=10**15:
_const.append((L,R))
const=[]
for L,R in _const:
while const and const[-1][1]>=R:
const.pop()
const.append((L,R))
M=len(const)
const=[(-10**15,-10**15)]+const
Rconst=[const[i][1] for i in range(M+1)]
B=BIT(M,mod)
dp=[1]*(M+1)
for i in range(1,M+1):
L,R=const[i]
id=bisect.bisect_left(Rconst,L)
res=(B.query(i-1)-B.query(id-1))%mod
R=Rconst[id]
res+=dp[id-1]*(pow(2,R-L+1,mod)-1)%mod
res%=mod
dp[i]=res
if i!=M:
nR=Rconst[i+1]
add=dp[i]*(pow(2,nR-R,mod)-1)*pow(2,nR-L+1,mod)%mod
add%=mod
B.update(i,add)
cnt=0
data=[0]*(N+2)
for i in range(1,M+1):
L,R=const[i]
data[L]+=1
data[R+1]+=-1
for i in range(1,N+2):
data[i]+=data[i-1]
for i in range(1,N+1):
if data[i]==0:
cnt+=1
ans=pow(2,cnt,mod)*dp[M]
ans%=mod
print(ans)
``` | instruction | 0 | 8,290 | 3 | 16,580 |
No | output | 1 | 8,290 | 3 | 16,581 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi is an expert of Clone Jutsu, a secret art that creates copies of his body.
On a number line, there are N copies of Takahashi, numbered 1 through N. The i-th copy is located at position X_i and starts walking with velocity V_i in the positive direction at time 0.
Kenus is a master of Transformation Jutsu, and not only can he change into a person other than himself, but he can also transform another person into someone else.
Kenus can select some of the copies of Takahashi at time 0, and transform them into copies of Aoki, another Ninja. The walking velocity of a copy does not change when it transforms. From then on, whenever a copy of Takahashi and a copy of Aoki are at the same coordinate, that copy of Takahashi transforms into a copy of Aoki.
Among the 2^N ways to transform some copies of Takahashi into copies of Aoki at time 0, in how many ways will all the copies of Takahashi become copies of Aoki after a sufficiently long time? Find the count modulo 10^9+7.
Constraints
* 1 β€ N β€ 200000
* 1 β€ X_i,V_i β€ 10^9(1 β€ i β€ N)
* X_i and V_i are integers.
* All X_i are distinct.
* All V_i are distinct.
Input
The input is given from Standard Input in the following format:
N
X_1 V_1
:
X_N V_N
Output
Print the number of the ways that cause all the copies of Takahashi to turn into copies of Aoki after a sufficiently long time, modulo 10^9+7.
Examples
Input
3
2 5
6 1
3 7
Output
6
Input
4
3 7
2 9
8 16
10 8
Output
9
Submitted Solution:
```
class BIT():
def __init__(self,n,mod):
self.BIT=[0]*(n+1)
self.num=n
self.mod=mod
def query(self,idx):
res_sum = 0
mod=self.mod
while idx > 0:
res_sum += self.BIT[idx]
res_sum%=mod
idx -= idx&(-idx)
return res_sum
#Ai += x O(logN)
def update(self,idx,x):
mod=self.mod
while idx <= self.num:
self.BIT[idx] += x
self.BIT[idx]%=mod
idx += idx&(-idx)
return
import sys,bisect
input=sys.stdin.readline
mod=10*9+7
inv=pow(2,mod-2,mod)
N=int(input())
taka=[tuple(map(int,input().split())) for i in range(N)]
taka.sort()
V=[0]+[taka[i][1] for i in range(N)]+[10**15]
cummin=[V[i] for i in range(N+2)]
for i in range(N,-1,-1):
cummin[i]=min(cummin[i],cummin[i+1])
cummax=[V[i] for i in range(N+2)]
for i in range(1,N+2):
cummax[i]=max(cummax[i],cummax[i-1])
const=[]
for i in range(1,N+1):
R=bisect.bisect_right(cummin,V[i])-1
L=bisect.bisect_left(cummax,V[i])
const.append((L,R))
Lconst=[(i,10**15) for i in range(N+1)]
for L,R in const:
pL,pR=Lconst[L]
Lconst[L]=(L,min(R,pR))
_const=[]
for i in range(1,N+1):
L,R=Lconst[i]
if R!=10**15:
_const.append((L,R))
const=[]
for L,R in _const:
while const and const[-1][1]>=R:
const.pop()
const.append((L,R))
M=len(const)
const=[(-10**15,0)]+const
Rconst=[const[i][1] for i in range(M+1)]
B=BIT(M,mod)
dp=[1]*(M+1)
for i in range(1,M+1):
L,R=const[i]
id=bisect.bisect_left(Rconst,L)
res=(B.query(i-1)-B.query(id-1))%mod
r=Rconst[id]
res+=dp[id-1]*(pow(2,r-L+1,mod)-1)*pow(2,L-Rconst[id-1]-1,mod)%mod
res%=mod
dp[i]=res
if i!=M:
nR=Rconst[i+1]
add=dp[i]*(pow(2,nR-R,mod)-1)%mod
add%=mod
B.update(i,add)
cnt=0
data=[0]*(N+2)
for i in range(1,M+1):
L,R=const[i]
data[L]+=1
data[R+1]+=-1
for i in range(1,N+2):
data[i]+=data[i-1]
for i in range(1,N+1):
if data[i]==0:
cnt+=1
ans=pow(2,cnt,mod)*dp[M]
ans%=mod
print(ans)
``` | instruction | 0 | 8,291 | 3 | 16,582 |
No | output | 1 | 8,291 | 3 | 16,583 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi is an expert of Clone Jutsu, a secret art that creates copies of his body.
On a number line, there are N copies of Takahashi, numbered 1 through N. The i-th copy is located at position X_i and starts walking with velocity V_i in the positive direction at time 0.
Kenus is a master of Transformation Jutsu, and not only can he change into a person other than himself, but he can also transform another person into someone else.
Kenus can select some of the copies of Takahashi at time 0, and transform them into copies of Aoki, another Ninja. The walking velocity of a copy does not change when it transforms. From then on, whenever a copy of Takahashi and a copy of Aoki are at the same coordinate, that copy of Takahashi transforms into a copy of Aoki.
Among the 2^N ways to transform some copies of Takahashi into copies of Aoki at time 0, in how many ways will all the copies of Takahashi become copies of Aoki after a sufficiently long time? Find the count modulo 10^9+7.
Constraints
* 1 β€ N β€ 200000
* 1 β€ X_i,V_i β€ 10^9(1 β€ i β€ N)
* X_i and V_i are integers.
* All X_i are distinct.
* All V_i are distinct.
Input
The input is given from Standard Input in the following format:
N
X_1 V_1
:
X_N V_N
Output
Print the number of the ways that cause all the copies of Takahashi to turn into copies of Aoki after a sufficiently long time, modulo 10^9+7.
Examples
Input
3
2 5
6 1
3 7
Output
6
Input
4
3 7
2 9
8 16
10 8
Output
9
Submitted Solution:
```
class BIT():
def __init__(self,n,mod):
self.BIT=[0]*(n+1)
self.num=n
self.mod=mod
def query(self,idx):
res_sum = 0
mod=self.mod
while idx > 0:
res_sum += self.BIT[idx]
res_sum%=mod
idx -= idx&(-idx)
return res_sum
#Ai += x O(logN)
def update(self,idx,x):
mod=self.mod
while idx <= self.num:
self.BIT[idx] += x
self.BIT[idx]%=mod
idx += idx&(-idx)
return
import sys,bisect
input=sys.stdin.readline
mod=10*9+7
N=int(input())
taka=[tuple(map(int,input().split())) for i in range(N)]
taka.sort()
V=[0]+[taka[i][1] for i in range(N)]+[10**15]
cummin=[V[i] for i in range(N+2)]
for i in range(N,-1,-1):
cummin[i]=min(cummin[i],cummin[i+1])
cummax=[V[i] for i in range(N+2)]
for i in range(1,N+2):
cummax[i]=max(cummax[i],cummax[i-1])
const=[]
for i in range(1,N+1):
R=bisect.bisect_right(cummin,V[i])-1
L=bisect.bisect_left(cummax,V[i])
const.append((L,R))
Lconst=[(i,10**15) for i in range(N+1)]
for L,R in const:
pL,pR=Lconst[L]
Lconst[L]=(L,min(R,pR))
Rconst=[(-1,i) for i in range(N+1)]
for i in range(1,N+1):
L,R=Lconst[i]
if R!=10**15:
pL,pR=Rconst[R]
Rconst[R]=(max(pL,L),R)
_const=[]
for i in range(1,N+1):
L,R=Rconst[i]
if L!=-1:
_const.append((L,R))
_const.sort()
const=[]
for L,R in _const:
while const and const[-1][1]>=R:
cosnt.pop()
const.append((L,R))
M=len(const)
const=[(-10**15,-10**15)]+const
Rconst=[const[i][1] for i in range(M+1)]
B=BIT(M,mod)
dp=[1]*(M+1)
for i in range(1,M+1):
L,R=const[i]
id=bisect.bisect_left(Rconst,L)
res=(B.query(i-1)-B.query(id-1))%mod
R=Rconst[id]
res+=dp[id-1]*(pow(2,R-L+1,mod)-1)%mod
res%=mod
dp[i]=res
if i!=M:
nR=Rconst[i+1]
add=dp[i]*(pow(2,nR-R,mod)-1)%mod
add%=mod
B.update(i,add)
cnt=0
data=[0]*(N+2)
for i in range(1,M+1):
L,R=const[i]
data[L]+=1
data[R+1]+=-1
for i in range(1,N+2):
data[i]+=data[i-1]
for i in range(1,N+1):
if data[i]==0:
cnt+=1
ans=pow(2,cnt,mod)*dp[M]
ans%=mod
print(ans)
``` | instruction | 0 | 8,292 | 3 | 16,584 |
No | output | 1 | 8,292 | 3 | 16,585 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Everyone knows that computers become faster and faster. Recently Berland scientists have built a machine that can move itself back in time!
More specifically, it works as follows. It has an infinite grid and a robot which stands on one of the cells. Each cell of the grid can either be empty or contain 0 or 1. The machine also has a program which consists of instructions, which are being handled one by one. Each instruction is represented by exactly one symbol (letter or digit) and takes exactly one unit of time (say, second) to be performed, except the last type of operation (it's described below). Here they are:
* 0 or 1: the robot places this number into the cell he is currently at. If this cell wasn't empty before the operation, its previous number is replaced anyway.
* e: the robot erases the number into the cell he is at.
* l, r, u or d: the robot goes one cell to the left/right/up/down.
* s: the robot stays where he is for a unit of time.
* t: let x be 0, if the cell with the robot is empty, otherwise let x be one more than the digit in this cell (that is, x = 1 if the digit in this cell is 0, and x = 2 if the digit is 1). Then the machine travels x seconds back in time. Note that this doesn't change the instructions order, but it changes the position of the robot and the numbers in the grid as they were x units of time ago. You can consider this instruction to be equivalent to a Ctrl-Z pressed x times.
For example, let the board be completely empty, and the program be sr1t0. Let the robot initially be at (0, 0).
* [now is the moment 0, the command is s]: we do nothing.
* [now is the moment 1, the command is r]: we are now at (1, 0).
* [now is the moment 2, the command is 1]: we are at (1, 0), and this cell contains 1.
* [now is the moment 3, the command is t]: we travel 1 + 1 = 2 moments back, that is, to the moment 1.
* [now is the moment 1, the command is 0]: we are again at (0, 0), and the board is clear again, but after we follow this instruction, this cell has 0 in it. We've just rewritten the history. The consequences of the third instruction have never happened.
Now Berland scientists want to use their machine in practice. For example, they want to be able to add two integers.
Assume that the initial state of the machine is as follows:
* One positive integer is written in binary on the grid in such a way that its right bit is at the cell (0, 1), from left to right from the highest bit to the lowest bit.
* The other positive integer is written in binary on the grid in such a way that its right bit is at the cell (0, 0), from left to right from the highest bit to the lowest bit.
* All the other cells are empty.
* The robot is at (0, 0).
* We consider this state to be always in the past; that is, if you manage to travel to any negative moment, the board was always as described above, and the robot was at (0, 0) for eternity.
You are asked to write a program after which
* The robot stands on a non-empty cell,
* If we read the number starting from the cell with the robot and moving to the right until the first empty cell, this will be a + b in binary, from the highest bit to the lowest bit.
Note that there are no restrictions on other cells. In particular, there may be a digit just to the left to the robot after all instructions.
In each test you are given up to 1000 pairs (a, b), and your program must work for all these pairs. Also since the machine's memory is not very big, your program must consist of no more than 10^5 instructions.
Input
The first line contains the only integer t (1β€ tβ€ 1000) standing for the number of testcases. Each of the next t lines consists of two positive integers a and b (1β€ a, b < 2^{30}) in decimal.
Output
Output the only line consisting of no more than 10^5 symbols from 01eslrudt standing for your program.
Note that formally you may output different programs for different tests.
Example
Input
2
123456789 987654321
555555555 555555555
Output
0l1l1l0l0l0l1l1l1l0l1l0l1l1l0l0l0l1l0l1l1l1l0l0l0l1l0l0l0l0l1l0lr | instruction | 0 | 8,392 | 3 | 16,784 |
Tags: constructive algorithms
Correct Solution:
```
def C(x, y):
return x + '10' + y + 't' + y
def CBF(x, y):
return x + '01' + y + 't' + y
Cr = C('r', 'l')
Cl = C('l', 'r')
Cu = C('u', 'd')
Cd = C('d', 'u')
CBFr = CBF('r', 'l')
CBFl = CBF('l', 'r')
CBFu = CBF('u', 'd')
CBFd = CBF('d', 'u')
def CE(x, y):
return x+x+'0'+x+'1'+y+y+'10'+y+'t'+x+x+'t'+y+x+x+'e'+x+'e'+y+y+y
def MNE(x, y):
return CE(x, y) + x + C(y, x) + 'e' + y
def MNEall(n):
return (MNE('d', 'u') + 'l') * n + 'r' * n + 'u' + (MNE('u', 'd') + 'l') * n + 'r' * n + 'd'
def ADD():
return 'u' + Cu + 'u' + Cu + 'dd' + Cu + 'u' + Cu + 'u' + Cl + '010ltut' + Cd + 'dd'
def ADDc():
return ADD() + '0ulrtd' + ADD() + 'lltr'
def ADDbit():
return 'u' + Cu + 'u' + Cl + 'll0l1rrr' + ADDc() + 'dd' + Cu + 'u' + Cu + 'u' + Cl + ADDc() + 'dd'
def full(n):
return MNEall(n) + 'uuu' + '0l' * (n+1) + 'r' * (n+1) + 'ddd' + (ADDbit() + 'l') * n + 'uuu'
print(full(30))
``` | output | 1 | 8,392 | 3 | 16,785 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Everyone knows that computers become faster and faster. Recently Berland scientists have built a machine that can move itself back in time!
More specifically, it works as follows. It has an infinite grid and a robot which stands on one of the cells. Each cell of the grid can either be empty or contain 0 or 1. The machine also has a program which consists of instructions, which are being handled one by one. Each instruction is represented by exactly one symbol (letter or digit) and takes exactly one unit of time (say, second) to be performed, except the last type of operation (it's described below). Here they are:
* 0 or 1: the robot places this number into the cell he is currently at. If this cell wasn't empty before the operation, its previous number is replaced anyway.
* e: the robot erases the number into the cell he is at.
* l, r, u or d: the robot goes one cell to the left/right/up/down.
* s: the robot stays where he is for a unit of time.
* t: let x be 0, if the cell with the robot is empty, otherwise let x be one more than the digit in this cell (that is, x = 1 if the digit in this cell is 0, and x = 2 if the digit is 1). Then the machine travels x seconds back in time. Note that this doesn't change the instructions order, but it changes the position of the robot and the numbers in the grid as they were x units of time ago. You can consider this instruction to be equivalent to a Ctrl-Z pressed x times.
For example, let the board be completely empty, and the program be sr1t0. Let the robot initially be at (0, 0).
* [now is the moment 0, the command is s]: we do nothing.
* [now is the moment 1, the command is r]: we are now at (1, 0).
* [now is the moment 2, the command is 1]: we are at (1, 0), and this cell contains 1.
* [now is the moment 3, the command is t]: we travel 1 + 1 = 2 moments back, that is, to the moment 1.
* [now is the moment 1, the command is 0]: we are again at (0, 0), and the board is clear again, but after we follow this instruction, this cell has 0 in it. We've just rewritten the history. The consequences of the third instruction have never happened.
Now Berland scientists want to use their machine in practice. For example, they want to be able to add two integers.
Assume that the initial state of the machine is as follows:
* One positive integer is written in binary on the grid in such a way that its right bit is at the cell (0, 1), from left to right from the highest bit to the lowest bit.
* The other positive integer is written in binary on the grid in such a way that its right bit is at the cell (0, 0), from left to right from the highest bit to the lowest bit.
* All the other cells are empty.
* The robot is at (0, 0).
* We consider this state to be always in the past; that is, if you manage to travel to any negative moment, the board was always as described above, and the robot was at (0, 0) for eternity.
You are asked to write a program after which
* The robot stands on a non-empty cell,
* If we read the number starting from the cell with the robot and moving to the right until the first empty cell, this will be a + b in binary, from the highest bit to the lowest bit.
Note that there are no restrictions on other cells. In particular, there may be a digit just to the left to the robot after all instructions.
In each test you are given up to 1000 pairs (a, b), and your program must work for all these pairs. Also since the machine's memory is not very big, your program must consist of no more than 10^5 instructions.
Input
The first line contains the only integer t (1β€ tβ€ 1000) standing for the number of testcases. Each of the next t lines consists of two positive integers a and b (1β€ a, b < 2^{30}) in decimal.
Output
Output the only line consisting of no more than 10^5 symbols from 01eslrudt standing for your program.
Note that formally you may output different programs for different tests.
Example
Input
2
123456789 987654321
555555555 555555555
Output
0l1l1l0l0l0l1l1l1l0l1l0l1l1l0l0l0l1l0l1l1l1l0l0l0l1l0l0l0l0l1l0lr
Submitted Solution:
```
for g in range(int(input())):
x=input()
a=int(x[:x.index(' ')])
b=int(x[x.index(' '):])
r=a+b
re=''
while r!=0:
if int(r/2)!=r/2:
re += '1'
re += 'l'
r=int(r/2)
else:
re+='0'
re+='l'
r/=2
print(re[:len(re)-1])
``` | instruction | 0 | 8,393 | 3 | 16,786 |
No | output | 1 | 8,393 | 3 | 16,787 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Everyone knows that computers become faster and faster. Recently Berland scientists have built a machine that can move itself back in time!
More specifically, it works as follows. It has an infinite grid and a robot which stands on one of the cells. Each cell of the grid can either be empty or contain 0 or 1. The machine also has a program which consists of instructions, which are being handled one by one. Each instruction is represented by exactly one symbol (letter or digit) and takes exactly one unit of time (say, second) to be performed, except the last type of operation (it's described below). Here they are:
* 0 or 1: the robot places this number into the cell he is currently at. If this cell wasn't empty before the operation, its previous number is replaced anyway.
* e: the robot erases the number into the cell he is at.
* l, r, u or d: the robot goes one cell to the left/right/up/down.
* s: the robot stays where he is for a unit of time.
* t: let x be 0, if the cell with the robot is empty, otherwise let x be one more than the digit in this cell (that is, x = 1 if the digit in this cell is 0, and x = 2 if the digit is 1). Then the machine travels x seconds back in time. Note that this doesn't change the instructions order, but it changes the position of the robot and the numbers in the grid as they were x units of time ago. You can consider this instruction to be equivalent to a Ctrl-Z pressed x times.
For example, let the board be completely empty, and the program be sr1t0. Let the robot initially be at (0, 0).
* [now is the moment 0, the command is s]: we do nothing.
* [now is the moment 1, the command is r]: we are now at (1, 0).
* [now is the moment 2, the command is 1]: we are at (1, 0), and this cell contains 1.
* [now is the moment 3, the command is t]: we travel 1 + 1 = 2 moments back, that is, to the moment 1.
* [now is the moment 1, the command is 0]: we are again at (0, 0), and the board is clear again, but after we follow this instruction, this cell has 0 in it. We've just rewritten the history. The consequences of the third instruction have never happened.
Now Berland scientists want to use their machine in practice. For example, they want to be able to add two integers.
Assume that the initial state of the machine is as follows:
* One positive integer is written in binary on the grid in such a way that its right bit is at the cell (0, 1), from left to right from the highest bit to the lowest bit.
* The other positive integer is written in binary on the grid in such a way that its right bit is at the cell (0, 0), from left to right from the highest bit to the lowest bit.
* All the other cells are empty.
* The robot is at (0, 0).
* We consider this state to be always in the past; that is, if you manage to travel to any negative moment, the board was always as described above, and the robot was at (0, 0) for eternity.
You are asked to write a program after which
* The robot stands on a non-empty cell,
* If we read the number starting from the cell with the robot and moving to the right until the first empty cell, this will be a + b in binary, from the highest bit to the lowest bit.
Note that there are no restrictions on other cells. In particular, there may be a digit just to the left to the robot after all instructions.
In each test you are given up to 1000 pairs (a, b), and your program must work for all these pairs. Also since the machine's memory is not very big, your program must consist of no more than 10^5 instructions.
Input
The first line contains the only integer t (1β€ tβ€ 1000) standing for the number of testcases. Each of the next t lines consists of two positive integers a and b (1β€ a, b < 2^{30}) in decimal.
Output
Output the only line consisting of no more than 10^5 symbols from 01eslrudt standing for your program.
Note that formally you may output different programs for different tests.
Example
Input
2
123456789 987654321
555555555 555555555
Output
0l1l1l0l0l0l1l1l1l0l1l0l1l1l0l0l0l1l0l1l1l1l0l0l0l1l0l0l0l0l1l0lr
Submitted Solution:
```
for g in range(int(input())):
x=input()
a=int(x[:x.index(' ')])
b=int(x[x.index(' '):])
r=a+b
re=''
while r!=0:
if int(r/2)!=r/2:
re += '1'
re += 'l'
r=int(r/2)
else:
re+='0'
re+='l'
r/=2
print(re)
``` | instruction | 0 | 8,394 | 3 | 16,788 |
No | output | 1 | 8,394 | 3 | 16,789 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Everyone knows that computers become faster and faster. Recently Berland scientists have built a machine that can move itself back in time!
More specifically, it works as follows. It has an infinite grid and a robot which stands on one of the cells. Each cell of the grid can either be empty or contain 0 or 1. The machine also has a program which consists of instructions, which are being handled one by one. Each instruction is represented by exactly one symbol (letter or digit) and takes exactly one unit of time (say, second) to be performed, except the last type of operation (it's described below). Here they are:
* 0 or 1: the robot places this number into the cell he is currently at. If this cell wasn't empty before the operation, its previous number is replaced anyway.
* e: the robot erases the number into the cell he is at.
* l, r, u or d: the robot goes one cell to the left/right/up/down.
* s: the robot stays where he is for a unit of time.
* t: let x be 0, if the cell with the robot is empty, otherwise let x be one more than the digit in this cell (that is, x = 1 if the digit in this cell is 0, and x = 2 if the digit is 1). Then the machine travels x seconds back in time. Note that this doesn't change the instructions order, but it changes the position of the robot and the numbers in the grid as they were x units of time ago. You can consider this instruction to be equivalent to a Ctrl-Z pressed x times.
For example, let the board be completely empty, and the program be sr1t0. Let the robot initially be at (0, 0).
* [now is the moment 0, the command is s]: we do nothing.
* [now is the moment 1, the command is r]: we are now at (1, 0).
* [now is the moment 2, the command is 1]: we are at (1, 0), and this cell contains 1.
* [now is the moment 3, the command is t]: we travel 1 + 1 = 2 moments back, that is, to the moment 1.
* [now is the moment 1, the command is 0]: we are again at (0, 0), and the board is clear again, but after we follow this instruction, this cell has 0 in it. We've just rewritten the history. The consequences of the third instruction have never happened.
Now Berland scientists want to use their machine in practice. For example, they want to be able to add two integers.
Assume that the initial state of the machine is as follows:
* One positive integer is written in binary on the grid in such a way that its right bit is at the cell (0, 1), from left to right from the highest bit to the lowest bit.
* The other positive integer is written in binary on the grid in such a way that its right bit is at the cell (0, 0), from left to right from the highest bit to the lowest bit.
* All the other cells are empty.
* The robot is at (0, 0).
* We consider this state to be always in the past; that is, if you manage to travel to any negative moment, the board was always as described above, and the robot was at (0, 0) for eternity.
You are asked to write a program after which
* The robot stands on a non-empty cell,
* If we read the number starting from the cell with the robot and moving to the right until the first empty cell, this will be a + b in binary, from the highest bit to the lowest bit.
Note that there are no restrictions on other cells. In particular, there may be a digit just to the left to the robot after all instructions.
In each test you are given up to 1000 pairs (a, b), and your program must work for all these pairs. Also since the machine's memory is not very big, your program must consist of no more than 10^5 instructions.
Input
The first line contains the only integer t (1β€ tβ€ 1000) standing for the number of testcases. Each of the next t lines consists of two positive integers a and b (1β€ a, b < 2^{30}) in decimal.
Output
Output the only line consisting of no more than 10^5 symbols from 01eslrudt standing for your program.
Note that formally you may output different programs for different tests.
Example
Input
2
123456789 987654321
555555555 555555555
Output
0l1l1l0l0l0l1l1l1l0l1l0l1l1l0l0l0l1l0l1l1l1l0l0l0l1l0l0l0l0l1l0lr
Submitted Solution:
```
for g in range(int(input())):
x=input()
a=int(x[:x.index(' ')])
b=int(x[x.index(' '):])
r=a+b
re=''
while r!=0:
if int(r/2)!=r/2:
re += '1'
re += 'l'
r=int(r/2)
else:
re+='0'
re+='l'
r/=2
print(re[:len(re)-1]+'l0')
``` | instruction | 0 | 8,395 | 3 | 16,790 |
No | output | 1 | 8,395 | 3 | 16,791 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Everyone knows that computers become faster and faster. Recently Berland scientists have built a machine that can move itself back in time!
More specifically, it works as follows. It has an infinite grid and a robot which stands on one of the cells. Each cell of the grid can either be empty or contain 0 or 1. The machine also has a program which consists of instructions, which are being handled one by one. Each instruction is represented by exactly one symbol (letter or digit) and takes exactly one unit of time (say, second) to be performed, except the last type of operation (it's described below). Here they are:
* 0 or 1: the robot places this number into the cell he is currently at. If this cell wasn't empty before the operation, its previous number is replaced anyway.
* e: the robot erases the number into the cell he is at.
* l, r, u or d: the robot goes one cell to the left/right/up/down.
* s: the robot stays where he is for a unit of time.
* t: let x be 0, if the cell with the robot is empty, otherwise let x be one more than the digit in this cell (that is, x = 1 if the digit in this cell is 0, and x = 2 if the digit is 1). Then the machine travels x seconds back in time. Note that this doesn't change the instructions order, but it changes the position of the robot and the numbers in the grid as they were x units of time ago. You can consider this instruction to be equivalent to a Ctrl-Z pressed x times.
For example, let the board be completely empty, and the program be sr1t0. Let the robot initially be at (0, 0).
* [now is the moment 0, the command is s]: we do nothing.
* [now is the moment 1, the command is r]: we are now at (1, 0).
* [now is the moment 2, the command is 1]: we are at (1, 0), and this cell contains 1.
* [now is the moment 3, the command is t]: we travel 1 + 1 = 2 moments back, that is, to the moment 1.
* [now is the moment 1, the command is 0]: we are again at (0, 0), and the board is clear again, but after we follow this instruction, this cell has 0 in it. We've just rewritten the history. The consequences of the third instruction have never happened.
Now Berland scientists want to use their machine in practice. For example, they want to be able to add two integers.
Assume that the initial state of the machine is as follows:
* One positive integer is written in binary on the grid in such a way that its right bit is at the cell (0, 1), from left to right from the highest bit to the lowest bit.
* The other positive integer is written in binary on the grid in such a way that its right bit is at the cell (0, 0), from left to right from the highest bit to the lowest bit.
* All the other cells are empty.
* The robot is at (0, 0).
* We consider this state to be always in the past; that is, if you manage to travel to any negative moment, the board was always as described above, and the robot was at (0, 0) for eternity.
You are asked to write a program after which
* The robot stands on a non-empty cell,
* If we read the number starting from the cell with the robot and moving to the right until the first empty cell, this will be a + b in binary, from the highest bit to the lowest bit.
Note that there are no restrictions on other cells. In particular, there may be a digit just to the left to the robot after all instructions.
In each test you are given up to 1000 pairs (a, b), and your program must work for all these pairs. Also since the machine's memory is not very big, your program must consist of no more than 10^5 instructions.
Input
The first line contains the only integer t (1β€ tβ€ 1000) standing for the number of testcases. Each of the next t lines consists of two positive integers a and b (1β€ a, b < 2^{30}) in decimal.
Output
Output the only line consisting of no more than 10^5 symbols from 01eslrudt standing for your program.
Note that formally you may output different programs for different tests.
Example
Input
2
123456789 987654321
555555555 555555555
Output
0l1l1l0l0l0l1l1l1l0l1l0l1l1l0l0l0l1l0l1l1l1l0l0l0l1l0l0l0l0l1l0lr
Submitted Solution:
```
for g in range(int(input())):
x=input()
a=int(x[:x.index(' ')])
b=int(x[x.index(' '):])
r=a+b
re=''
while r!=0:
if int(r/2)!=r/2:
re += 'r'
re+='1'
r=int(r/2)
else:
re += 'r'
re+='0'
r/=2
er=''
for j in range(1,len(re)+1):
er+=re[-j]
for k in range(0,len(re),2):
er+='l'
print(er)
``` | instruction | 0 | 8,396 | 3 | 16,792 |
No | output | 1 | 8,396 | 3 | 16,793 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are a warrior fighting against the machine god Thor.
Thor challenge you to solve the following problem:
There are n conveyors arranged in a line numbered with integers from 1 to n from left to right. Each conveyor has a symbol "<" or ">". The initial state of the conveyor i is equal to the i-th character of the string s. There are n+1 holes numbered with integers from 0 to n. The hole 0 is on the left side of the conveyor 1, and for all i β₯ 1 the hole i is on the right side of the conveyor i.
When a ball is on the conveyor i, the ball moves by the next rules:
If the symbol "<" is on the conveyor i, then:
* If i=1, the ball falls into the hole 0.
* If the symbol "<" is on the conveyor i-1, the ball moves to the conveyor i-1.
* If the symbol ">" is on the conveyor i-1, the ball falls into the hole i-1.
If the symbol ">" is on the conveyor i, then:
* If i=n, the ball falls into the hole n.
* If the symbol ">" is on the conveyor i+1, the ball moves to the conveyor i+1.
* If the symbol "<" is on the conveyor i+1, the ball falls into the hole i.
You should answer next q queries, each query is defined by the pair of integers l, r (1 β€ l β€ r β€ n):
* First, for all conveyors l,l+1,...,r, the symbol "<" changes to ">" and vice versa. These changes remain for the next queries.
* After that, put one ball on each conveyor l,l+1,...,r. Then, each ball falls into some hole. Find the maximum number of balls in one hole. After the query all balls disappear and don't considered in the next queries.
Input
The first line contains two integers n, q (1 β€ n β€ 5 Γ 10^5 , 1 β€ q β€ 10^5).
The second line contains a string s of length n. It consists of characters "<" and ">".
Next q lines contain the descriptions of the queries, i-th of them contains two integers l, r (1 β€ l β€ r β€ n), describing the i-th query.
Output
Print q lines, in the i-th of them print the answer to the i-th query.
Example
Input
5 6
><>><
2 4
3 5
1 5
1 3
2 4
1 5
Output
3
3
5
3
2
3
Note
* In the first query, the conveyors change to ">><<<". After that, put a ball on each conveyor \{2,3,4\}. All three balls fall into the hole 2. So the answer is 3.
* In the second query, the conveyors change to ">>>>>". After that, put a ball on each conveyor \{3,4,5\}. All three balls fall into the hole 5. So the answer is 3.
* In the third query, the conveyors change to "<<<<<". After that, put a ball on each conveyor \{1,2,3,4,5\}. All five balls fall into the hole 0. So the answer is 5.
* In the fourth query, the conveyors change to ">>><<". After that, put a ball on each conveyor \{1,2,3\}. All three balls fall into the hole 3. So the answer is 3.
* In the fifth query, the conveyors change to "><<><". After that, put a ball on each conveyor \{2,3,4\}. Two balls fall into the hole 1, and one ball falls into the hole 4. So, the answer is 2.
* In the sixth query, the conveyors change to "<>><>". After that, put a ball on each conveyor \{1,2,3,4,5\}. Three balls fall into the hole 3, one ball falls into the hole 0 and one ball falls into the hole 5. So, the answer is 3.
Submitted Solution:
```
class node:
o_mx, c_mx, pref_o, pref_c, suf_o, suf_c, len = [0] * 7
pref, suf = [0, 0], [0, 0]
def __init__(self, z = -1):
#self.o_mx, self.c_mx, self.pref_o, self.pref_c, self.suf_o, self.suf_c, self.len = [0] * 7
#self.pref, self.suf = [0, 0], [0, 0]
if z == -1:
return
self.pref[z], self.suf[z], self.len = 1, 1, 1
def unite(a, b):
if a.len == 0:
return b
if b.len == 0:
return a
res = node()
res.len = a.len + b.len
for i in (0, 1):
res.pref[i] = a.pref[i]
if a.pref[i] == a.len:
res.pref[i] += b.pref[i]
res.suf[i] = b.suf[i]
if b.suf[i] == b.len:
res.suf[i] += a.suf[i]
res.o_mx = max(a.o_mx, b.o_mx)
res.c_mx = max(a.c_mx, b.c_mx)
if a.suf_o:
res.o_mx = max(res.o_mx, a.suf_o + b.pref[1])
if b.pref_o:
res.o_mx = max(res.o_mx, a.suf[0] + b.pref_o)
if a.suf[0] != 0 and b.pref[1] != 0:
res.o_mx = max(res.o_mx, a.suf[0] + b.pref[1])
if a.suf_c != 0:
res.c_mx = max(res.c_mx, a.suf_c + b.pref[0])
if b.pref_c != 0:
res.c_mx = max(res.c_mx, a.suf[1] + b.pref_c)
if a.suf[1] != 0 and b.pref[0] != 0:
res.c_mx = max(res.c_mx, a.suf[1] + b.pref[0])
res.pref_o = a.pref_o
if a.pref_o == a.len:
res.pref_o += b.pref[1]
if a.pref[0] == a.len and b.pref[1] > 0:
res.pref_o = a.pref[0] + b.pref[1]
if a.pref[0] == a.len and b.pref_o > 0:
res.pref_o = a.pref[0] + b.pref_o
res.pref_c = a.pref_c
if a.pref_c == a.len:
res.pref_c += b.pref[0]
if a.pref[1] == a.len and b.pref[0] > 0:
res.pref_c = a.pref[1] + b.pref[0]
if a.pref[1] == a.len and b.pref_c > 0:
res.pref_c = a.pref[1] + b.pref_c
res.suf_o = b.suf_o
if b.suf_o == b.len:
res.suf_o += a.suf[0]
if b.suf[1] == b.len and a.suf[0] > 0:
res.suf_o = b.suf[1] + a.suf[0]
if b.suf[1] == b.len and a.suf_o > 0:
res.suf_o = b.suf[1] + a.suf_o
res.suf_c = b.suf_c
if b.suf_c == b.len:
res.suf_c += a.suf[1]
if b.suf[0] == b.len and a.suf[1] > 0:
res.suf_c = b.suf[0] + a.suf[1]
if b.suf[0] == b.len and a.suf_c > 0:
res.suf_c = b.suf[0] + a.suf_c
return res
def build(v, tl, tr):
if tl == tr:
t[v] = node(s[tl] == '>')
return
tm = (tl + tr) // 2
build(v * 2, tl, tm)
build(v * 2 + 1, tm + 1, tr)
t[v] = unite(t[v * 2], t[v * 2 + 1])
def push(v, tl, tr):
if not pt[v]:
return
pt[v] = 0
t[v].pref[0], t[v].pref[1] = t[v].pref[1], t[v].pref[0]
t[v].suf[0], t[v].suf[1] = t[v].suf[1], t[v].suf[0]
t[v].o_mx, t[v].c_mx = t[v].c_mx, t[v].o_mx
t[v].pref_o, t[v].pref_c = t[v].pref_c, t[v].pref_o
t[v].suf_o, t[v].suf_c = t[v].suf_c, t[v].suf_o
if tl != tr:
pt[v * 2] ^= 1
pt[v * 2 + 1] ^= 1
def rev(v, tl, tr, l, r):
push(v, tl, tr)
if tl > r or tr < l:
return
if tl >= l and tr <= r:
pt[v] = 1
push(v, tl, tr)
return
tm = (tl + tr) // 2
rev(v * 2, tl, tm, l, r)
rev(v * 2 + 1, tm + 1, tr, l, r)
t[v] = unite(t[v * 2], t[v * 2 + 1])
def getNode(v, tl, tr, l, r):
if tl > r or tr < l:
return node()
push(v, tl, tr)
if tl >= l and tr <= r:
return t[v]
tm = (tl + tr) // 2
return unite(getNode(v * 2, tl, tm, l, r), getNode(v * 2 + 1, tm + 1, tr, l, r))
n, q = map(int, input().split())
s = input()
t, pt = [node()] * (4 * n + 50), [0] * (4 * n + 50)
build(1, 0, n - 1)
for i in range(q):
l, r = map(lambda v: int(v) - 1, input().split())
rev(1, 0, n - 1, l, r)
nd = getNode(1, 0, n - 1, l, r)
print(max(nd.pref[0], nd.suf[1], nd.c_mx))
``` | instruction | 0 | 8,526 | 3 | 17,052 |
No | output | 1 | 8,526 | 3 | 17,053 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are a warrior fighting against the machine god Thor.
Thor challenge you to solve the following problem:
There are n conveyors arranged in a line numbered with integers from 1 to n from left to right. Each conveyor has a symbol "<" or ">". The initial state of the conveyor i is equal to the i-th character of the string s. There are n+1 holes numbered with integers from 0 to n. The hole 0 is on the left side of the conveyor 1, and for all i β₯ 1 the hole i is on the right side of the conveyor i.
When a ball is on the conveyor i, the ball moves by the next rules:
If the symbol "<" is on the conveyor i, then:
* If i=1, the ball falls into the hole 0.
* If the symbol "<" is on the conveyor i-1, the ball moves to the conveyor i-1.
* If the symbol ">" is on the conveyor i-1, the ball falls into the hole i-1.
If the symbol ">" is on the conveyor i, then:
* If i=n, the ball falls into the hole n.
* If the symbol ">" is on the conveyor i+1, the ball moves to the conveyor i+1.
* If the symbol "<" is on the conveyor i+1, the ball falls into the hole i.
You should answer next q queries, each query is defined by the pair of integers l, r (1 β€ l β€ r β€ n):
* First, for all conveyors l,l+1,...,r, the symbol "<" changes to ">" and vice versa. These changes remain for the next queries.
* After that, put one ball on each conveyor l,l+1,...,r. Then, each ball falls into some hole. Find the maximum number of balls in one hole. After the query all balls disappear and don't considered in the next queries.
Input
The first line contains two integers n, q (1 β€ n β€ 5 Γ 10^5 , 1 β€ q β€ 10^5).
The second line contains a string s of length n. It consists of characters "<" and ">".
Next q lines contain the descriptions of the queries, i-th of them contains two integers l, r (1 β€ l β€ r β€ n), describing the i-th query.
Output
Print q lines, in the i-th of them print the answer to the i-th query.
Example
Input
5 6
><>><
2 4
3 5
1 5
1 3
2 4
1 5
Output
3
3
5
3
2
3
Note
* In the first query, the conveyors change to ">><<<". After that, put a ball on each conveyor \{2,3,4\}. All three balls fall into the hole 2. So the answer is 3.
* In the second query, the conveyors change to ">>>>>". After that, put a ball on each conveyor \{3,4,5\}. All three balls fall into the hole 5. So the answer is 3.
* In the third query, the conveyors change to "<<<<<". After that, put a ball on each conveyor \{1,2,3,4,5\}. All five balls fall into the hole 0. So the answer is 5.
* In the fourth query, the conveyors change to ">>><<". After that, put a ball on each conveyor \{1,2,3\}. All three balls fall into the hole 3. So the answer is 3.
* In the fifth query, the conveyors change to "><<><". After that, put a ball on each conveyor \{2,3,4\}. Two balls fall into the hole 1, and one ball falls into the hole 4. So, the answer is 2.
* In the sixth query, the conveyors change to "<>><>". After that, put a ball on each conveyor \{1,2,3,4,5\}. Three balls fall into the hole 3, one ball falls into the hole 0 and one ball falls into the hole 5. So, the answer is 3.
Submitted Solution:
```
from collections import deque
import math
import os
import random
import re
import sys
#n=list(map(int, input().split()))
#n=map(int, input().split())
class Stonesonthetable:
def solve(self,n,stones):
changes = 0
for i in range(1,n):
if(stones[i]==stones[i-1]):
changes+=1
return changes
'''
if __name__ == '__main__':
main()
'''
``` | instruction | 0 | 8,527 | 3 | 17,054 |
No | output | 1 | 8,527 | 3 | 17,055 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are a warrior fighting against the machine god Thor.
Thor challenge you to solve the following problem:
There are n conveyors arranged in a line numbered with integers from 1 to n from left to right. Each conveyor has a symbol "<" or ">". The initial state of the conveyor i is equal to the i-th character of the string s. There are n+1 holes numbered with integers from 0 to n. The hole 0 is on the left side of the conveyor 1, and for all i β₯ 1 the hole i is on the right side of the conveyor i.
When a ball is on the conveyor i, the ball moves by the next rules:
If the symbol "<" is on the conveyor i, then:
* If i=1, the ball falls into the hole 0.
* If the symbol "<" is on the conveyor i-1, the ball moves to the conveyor i-1.
* If the symbol ">" is on the conveyor i-1, the ball falls into the hole i-1.
If the symbol ">" is on the conveyor i, then:
* If i=n, the ball falls into the hole n.
* If the symbol ">" is on the conveyor i+1, the ball moves to the conveyor i+1.
* If the symbol "<" is on the conveyor i+1, the ball falls into the hole i.
You should answer next q queries, each query is defined by the pair of integers l, r (1 β€ l β€ r β€ n):
* First, for all conveyors l,l+1,...,r, the symbol "<" changes to ">" and vice versa. These changes remain for the next queries.
* After that, put one ball on each conveyor l,l+1,...,r. Then, each ball falls into some hole. Find the maximum number of balls in one hole. After the query all balls disappear and don't considered in the next queries.
Input
The first line contains two integers n, q (1 β€ n β€ 5 Γ 10^5 , 1 β€ q β€ 10^5).
The second line contains a string s of length n. It consists of characters "<" and ">".
Next q lines contain the descriptions of the queries, i-th of them contains two integers l, r (1 β€ l β€ r β€ n), describing the i-th query.
Output
Print q lines, in the i-th of them print the answer to the i-th query.
Example
Input
5 6
><>><
2 4
3 5
1 5
1 3
2 4
1 5
Output
3
3
5
3
2
3
Note
* In the first query, the conveyors change to ">><<<". After that, put a ball on each conveyor \{2,3,4\}. All three balls fall into the hole 2. So the answer is 3.
* In the second query, the conveyors change to ">>>>>". After that, put a ball on each conveyor \{3,4,5\}. All three balls fall into the hole 5. So the answer is 3.
* In the third query, the conveyors change to "<<<<<". After that, put a ball on each conveyor \{1,2,3,4,5\}. All five balls fall into the hole 0. So the answer is 5.
* In the fourth query, the conveyors change to ">>><<". After that, put a ball on each conveyor \{1,2,3\}. All three balls fall into the hole 3. So the answer is 3.
* In the fifth query, the conveyors change to "><<><". After that, put a ball on each conveyor \{2,3,4\}. Two balls fall into the hole 1, and one ball falls into the hole 4. So, the answer is 2.
* In the sixth query, the conveyors change to "<>><>". After that, put a ball on each conveyor \{1,2,3,4,5\}. Three balls fall into the hole 3, one ball falls into the hole 0 and one ball falls into the hole 5. So, the answer is 3.
Submitted Solution:
```
t = [int(x) for x in input().split()]
b = list(input())
n = t[1]
while n:
i=0
a = [int(x) for x in input().split()]
l = a[0]
i=l
r = a[1]
while i<r:
if b[i-1]=="<": b[i-1]=">"
else: b[i-1]="<"
i+=1
hole=[]
i=0
while i<len(b)-1:
thing=0
if b[i]==">" and b[i+1] == "<":
j=i
while j>=0 and b[j]==">":
thing+=1
j-=1
j=i+1
#print(thing)
while j<len(b) and b[j]=="<":
thing+=1
j+=1
#print(thing)
hole.append(thing)
i+=1
if b[i]==">":
j=i
thing = 0
while j>=0 and b[j]==">":
thing+=1
j-=1
hole.append(thing)
if b[0]=="<":
j=0
thing=0
while j<len(b) and b[j]=="<":
thing+=1
j+=1
hole.append(thing)
print(max(hole))
n-=1
``` | instruction | 0 | 8,528 | 3 | 17,056 |
No | output | 1 | 8,528 | 3 | 17,057 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are a warrior fighting against the machine god Thor.
Thor challenge you to solve the following problem:
There are n conveyors arranged in a line numbered with integers from 1 to n from left to right. Each conveyor has a symbol "<" or ">". The initial state of the conveyor i is equal to the i-th character of the string s. There are n+1 holes numbered with integers from 0 to n. The hole 0 is on the left side of the conveyor 1, and for all i β₯ 1 the hole i is on the right side of the conveyor i.
When a ball is on the conveyor i, the ball moves by the next rules:
If the symbol "<" is on the conveyor i, then:
* If i=1, the ball falls into the hole 0.
* If the symbol "<" is on the conveyor i-1, the ball moves to the conveyor i-1.
* If the symbol ">" is on the conveyor i-1, the ball falls into the hole i-1.
If the symbol ">" is on the conveyor i, then:
* If i=n, the ball falls into the hole n.
* If the symbol ">" is on the conveyor i+1, the ball moves to the conveyor i+1.
* If the symbol "<" is on the conveyor i+1, the ball falls into the hole i.
You should answer next q queries, each query is defined by the pair of integers l, r (1 β€ l β€ r β€ n):
* First, for all conveyors l,l+1,...,r, the symbol "<" changes to ">" and vice versa. These changes remain for the next queries.
* After that, put one ball on each conveyor l,l+1,...,r. Then, each ball falls into some hole. Find the maximum number of balls in one hole. After the query all balls disappear and don't considered in the next queries.
Input
The first line contains two integers n, q (1 β€ n β€ 5 Γ 10^5 , 1 β€ q β€ 10^5).
The second line contains a string s of length n. It consists of characters "<" and ">".
Next q lines contain the descriptions of the queries, i-th of them contains two integers l, r (1 β€ l β€ r β€ n), describing the i-th query.
Output
Print q lines, in the i-th of them print the answer to the i-th query.
Example
Input
5 6
><>><
2 4
3 5
1 5
1 3
2 4
1 5
Output
3
3
5
3
2
3
Note
* In the first query, the conveyors change to ">><<<". After that, put a ball on each conveyor \{2,3,4\}. All three balls fall into the hole 2. So the answer is 3.
* In the second query, the conveyors change to ">>>>>". After that, put a ball on each conveyor \{3,4,5\}. All three balls fall into the hole 5. So the answer is 3.
* In the third query, the conveyors change to "<<<<<". After that, put a ball on each conveyor \{1,2,3,4,5\}. All five balls fall into the hole 0. So the answer is 5.
* In the fourth query, the conveyors change to ">>><<". After that, put a ball on each conveyor \{1,2,3\}. All three balls fall into the hole 3. So the answer is 3.
* In the fifth query, the conveyors change to "><<><". After that, put a ball on each conveyor \{2,3,4\}. Two balls fall into the hole 1, and one ball falls into the hole 4. So, the answer is 2.
* In the sixth query, the conveyors change to "<>><>". After that, put a ball on each conveyor \{1,2,3,4,5\}. Three balls fall into the hole 3, one ball falls into the hole 0 and one ball falls into the hole 5. So, the answer is 3.
Submitted Solution:
```
#hello guys!
print("This is suicide!")
``` | instruction | 0 | 8,529 | 3 | 17,058 |
No | output | 1 | 8,529 | 3 | 17,059 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One remarkable day company "X" received k machines. And they were not simple machines, they were mechanical programmers! This was the last unsuccessful step before switching to android programmers, but that's another story.
The company has now n tasks, for each of them we know the start time of its execution si, the duration of its execution ti, and the company profit from its completion ci. Any machine can perform any task, exactly one at a time. If a machine has started to perform the task, it is busy at all moments of time from si to si + ti - 1, inclusive, and it cannot switch to another task.
You are required to select a set of tasks which can be done with these k machines, and which will bring the maximum total profit.
Input
The first line contains two integer numbers n and k (1 β€ n β€ 1000, 1 β€ k β€ 50) β the numbers of tasks and machines, correspondingly.
The next n lines contain space-separated groups of three integers si, ti, ci (1 β€ si, ti β€ 109, 1 β€ ci β€ 106), si is the time where they start executing the i-th task, ti is the duration of the i-th task and ci is the profit of its execution.
Output
Print n integers x1, x2, ..., xn. Number xi should equal 1, if task i should be completed and otherwise it should equal 0.
If there are several optimal solutions, print any of them.
Examples
Input
3 1
2 7 5
1 3 3
4 1 3
Output
0 1 1
Input
5 2
1 5 4
1 4 5
1 3 2
4 1 2
5 6 1
Output
1 1 0 0 1
Note
In the first sample the tasks need to be executed at moments of time 2 ... 8, 1 ... 3 and 4 ... 4, correspondingly. The first task overlaps with the second and the third ones, so we can execute either task one (profit 5) or tasks two and three (profit 6).
Submitted Solution:
```
from math import sqrt
n,m = map(int,input().split())
def dist(x1,y1,x2,y2):
d = (x1-x2)**2 + (y2-y1)**2
if sqrt(d)!=int(sqrt(d)):
return True
else:
return False
z = min(n,m)
print(z+1)
ans = []
ba = []
if n !=m :
for i in range(z+1):
if i!=0:
ans.append([i,i])
else:
ans.append([z,0])
for i in range(n+1):
for j in range(m+1):
if i!=0 or j!=0:
ba.append([i,j])
if m!=n:
for i in ba:
x,y = i
flag = 0
for j in ans:
a,b = j
z = dist(x,y,a,b)
if z == False:
flag = 1
break
if flag == 0 :
ans.append(i)
break
else:
for i in ba:
x,y = i
flag = 0
for j in ans:
a,b = j
z = dist(x,y,a,b)
if z == False:
flag = 1
break
if flag == 0 :
ans.append(i)
for i in ans:
print(i[0],i[1])
``` | instruction | 0 | 8,607 | 3 | 17,214 |
No | output | 1 | 8,607 | 3 | 17,215 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When Darth Vader gets bored, he sits down on the sofa, closes his eyes and thinks of an infinite rooted tree where each node has exactly n sons, at that for each node, the distance between it an its i-th left child equals to di. The Sith Lord loves counting the number of nodes in the tree that are at a distance at most x from the root. The distance is the sum of the lengths of edges on the path between nodes.
But he has got used to this activity and even grew bored of it. 'Why does he do that, then?' β you may ask. It's just that he feels superior knowing that only he can solve this problem.
Do you want to challenge Darth Vader himself? Count the required number of nodes. As the answer can be rather large, find it modulo 109 + 7.
Input
The first line contains two space-separated integers n and x (1 β€ n β€ 105, 0 β€ x β€ 109) β the number of children of each node and the distance from the root within the range of which you need to count the nodes.
The next line contains n space-separated integers di (1 β€ di β€ 100) β the length of the edge that connects each node with its i-th child.
Output
Print a single number β the number of vertexes in the tree at distance from the root equal to at most x.
Examples
Input
3 3
1 2 3
Output
8
Note
Pictures to the sample (the yellow color marks the nodes the distance to which is at most three)
<image>
Submitted Solution:
```
# fast io
from sys import stdin
_data = iter(stdin.read().split('\n'))
input = lambda: next(_data)
N = 101
MOD = 1000000007
c = [[0] * N for i in range(N)]
def mod_mul(a, b):
for i in range(N):
for j in range(N):
c[i][j] = 0
for i in range(N):
for k in range(N):
for j in range(N):
c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % MOD
return c
_, x = [int(v) for v in input().split()]
a = [[0] * N for i in range(N)]
a[0][N - 1] = 1
a[N - 1][N - 1] = 1
for d in map(int, input().split()):
a[0][d - 1] += 1
for i in range(1, N - 1):
a[i][i - 1] = 1
b = [0 for i in range(N)]
b[0] = 1
b[N - 1] = 1
r = [[1 if i == j else 0 for j in range(N)] for i in range(N)]
while x > 0:
if x & 1:
r, c = mod_mul(a, r), r
a, c = mod_mul(a, a), a
x >>= 1
c = [0] * N
for i in range(N):
for j in range(N):
c[i] = (c[i] + a[i][j] * b[j]) % MOD
print(c[0])
``` | instruction | 0 | 8,665 | 3 | 17,330 |
No | output | 1 | 8,665 | 3 | 17,331 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitones
Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads β major and minor.
Let's define a major triad. Let the triad consist of notes X, Y and Z. If we can order the notes so as the distance along the musical scale between X and Y equals 4 semitones and the distance between Y and Z is 3 semitones, then the triad is major. The distance between X and Z, accordingly, equals 7 semitones.
A minor triad is different in that the distance between X and Y should be 3 semitones and between Y and Z β 4 semitones.
For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# and F β 4 semitones.
Help Vasya classify the triad the teacher has given to him.
Input
The only line contains 3 space-separated notes in the above-given notation.
Output
Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously.
Examples
Input
C E G
Output
major
Input
C# B F
Output
minor
Input
A B H
Output
strange
Submitted Solution:
```
def permutations(ss):
s = str(ss).split()
x = s[0]
y = s[1]
z = s[2]
l = []
l.append(str(x+" "+y+" "+z))
l.append(str(x+" "+z+" "+y))
l.append(str(y+" "+z+" "+x))
l.append(str(y+" "+x+" "+z))
l.append(str(z+" "+x+" "+y))
l.append(str(z+" "+y+" "+x))
return l
dict = {'C': 1, 'G#': 9, 'E': 5, 'A': 10, 'B': 11, 'F': 6, 'D#': 4, 'G': 8, 'C#': 2, 'F#': 7, 'D': 3, 'H': 12}
st = input()
lis = permutations(st)
maj = False
min = False
for st in lis:
s = str(st).split()
first = dict[s[1]]-dict[s[0]]
if first<0:
first+=12
second = dict[s[2]]-dict[s[1]]
if second<0:
second+=12
if first == 4 and second==3:
maj = True
elif first==3 and second==4:
min = True
else:
continue
if maj:
print("major")
elif min:
print("minor")
else:
print("strange")
``` | instruction | 0 | 8,787 | 3 | 17,574 |
Yes | output | 1 | 8,787 | 3 | 17,575 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitones
Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads β major and minor.
Let's define a major triad. Let the triad consist of notes X, Y and Z. If we can order the notes so as the distance along the musical scale between X and Y equals 4 semitones and the distance between Y and Z is 3 semitones, then the triad is major. The distance between X and Z, accordingly, equals 7 semitones.
A minor triad is different in that the distance between X and Y should be 3 semitones and between Y and Z β 4 semitones.
For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# and F β 4 semitones.
Help Vasya classify the triad the teacher has given to him.
Input
The only line contains 3 space-separated notes in the above-given notation.
Output
Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously.
Examples
Input
C E G
Output
major
Input
C# B F
Output
minor
Input
A B H
Output
strange
Submitted Solution:
```
lt = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A' ,'B', 'H']
major = [[4,3], [3,5], [5,4]]
minor = [[3,4], [4,5], [5,3]]
x,y,z = input().split()
ind = [lt.index(p) for p in (x,y,z)]
ind.sort()
diff = [ind[1]-ind[0], ind[2]-ind[1]]
if diff in major:
print('major')
elif diff in minor:
print('minor')
else:
print('strange')
``` | instruction | 0 | 8,788 | 3 | 17,576 |
Yes | output | 1 | 8,788 | 3 | 17,577 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitones
Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads β major and minor.
Let's define a major triad. Let the triad consist of notes X, Y and Z. If we can order the notes so as the distance along the musical scale between X and Y equals 4 semitones and the distance between Y and Z is 3 semitones, then the triad is major. The distance between X and Z, accordingly, equals 7 semitones.
A minor triad is different in that the distance between X and Y should be 3 semitones and between Y and Z β 4 semitones.
For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# and F β 4 semitones.
Help Vasya classify the triad the teacher has given to him.
Input
The only line contains 3 space-separated notes in the above-given notation.
Output
Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously.
Examples
Input
C E G
Output
major
Input
C# B F
Output
minor
Input
A B H
Output
strange
Submitted Solution:
```
def low(ele,e2,e3,l):
loc1=-1
loc2=-1
for i in range(l.index(ele),12):
if l[i]==e2:
loc1=i
if l[i]==e3:
loc2=i
if loc1==-1:
d1=12-l.index(ele)+l.index(e2)
elif loc1!=-1:
d1=loc1-l.index(ele)
if loc2==-1:
d2=12-l.index(ele)+l.index(e3)
elif loc2!=-1:
d2=loc2-l.index(ele)
return d1,d2
l=['C', 'C#', 'D', 'D#', 'E', 'F','F#', 'G', 'G#', 'A','B', 'H']
X,Y,Z=[str(x) for x in input().split()]
#x is lowest
x1,x2=low(X,Y,Z,l)
if (x1==4 and x2==7) or (x1==7 and x2==4):
print("major")
elif (x1==3 and x2==7) or(x1==7 and x2==3):
print("minor")
else:
y1,y2=low(Y,X,Z,l)
if (y1==4 and y2==7) or (y1==7 and y2==4):
print("major")
elif (y1==3 and y2==7) or(y1==7 and y2==3):
print("minor")
else:
z1,z2=low(Z,X,Y,l)
if (z1==4 and z2==7) or (z1==7 and z2==4):
print("major")
elif (z1==3 and z2==7) or(z1==7 and z2==3):
print("minor")
else:
print("strange")
``` | instruction | 0 | 8,789 | 3 | 17,578 |
Yes | output | 1 | 8,789 | 3 | 17,579 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitones
Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads β major and minor.
Let's define a major triad. Let the triad consist of notes X, Y and Z. If we can order the notes so as the distance along the musical scale between X and Y equals 4 semitones and the distance between Y and Z is 3 semitones, then the triad is major. The distance between X and Z, accordingly, equals 7 semitones.
A minor triad is different in that the distance between X and Y should be 3 semitones and between Y and Z β 4 semitones.
For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# and F β 4 semitones.
Help Vasya classify the triad the teacher has given to him.
Input
The only line contains 3 space-separated notes in the above-given notation.
Output
Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously.
Examples
Input
C E G
Output
major
Input
C# B F
Output
minor
Input
A B H
Output
strange
Submitted Solution:
```
#import math
#n, m = input().split()
#n = int (n)
#m = int (m)
#n, m, k= input().split()
#n = int (n)
#m = int (m)
#k = int (k)
#l = int(l)
#m = int(input())
#s = input()
##t = input()
#a = list(map(char, input().split()))
#a.append('.')
#print(l)
#a = list(map(int, input().split()))
#c = sorted(c)
#x1, y1, x2, y2 =map(int,input().split())
#n = int(input())
#f = []
#t = [0]*n
#f = [(int(s1[0]),s1[1]), (int(s2[0]),s2[1]), (int(s3[0]), s3[1])]
#f1 = sorted(t, key = lambda tup: tup[0])
dic = {"C":0, "C#":1, "D":2, "D#":3, "E":4, "F":5, "F#":6, "G":7, "G#":8, "A":9, "B":10, "H":11}
X, Y, Z = input().split()
a = [dic[X], dic[Y], dic[Z]]
a = sorted(a)
X = a[0]
Y = a[1]
Z = a[2]
if ((Y-X == 3 and Z-Y == 4) or (X+12 -Z == 4 and Z -Y == 3) or(Y- X == 4 and X+12-Z == 3)):
print("minor")
elif ((Y-X == 4 and Z-Y == 3) or (X+12 -Z == 3 and Z -Y == 4) or(Y- X == 3 and X+12-Z == 4)):
print("major")
else:
print("strange")
``` | instruction | 0 | 8,790 | 3 | 17,580 |
Yes | output | 1 | 8,790 | 3 | 17,581 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitones
Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads β major and minor.
Let's define a major triad. Let the triad consist of notes X, Y and Z. If we can order the notes so as the distance along the musical scale between X and Y equals 4 semitones and the distance between Y and Z is 3 semitones, then the triad is major. The distance between X and Z, accordingly, equals 7 semitones.
A minor triad is different in that the distance between X and Y should be 3 semitones and between Y and Z β 4 semitones.
For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# and F β 4 semitones.
Help Vasya classify the triad the teacher has given to him.
Input
The only line contains 3 space-separated notes in the above-given notation.
Output
Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously.
Examples
Input
C E G
Output
major
Input
C# B F
Output
minor
Input
A B H
Output
strange
Submitted Solution:
```
NOTES = 'C C# D D# E F F# G G# A B H'.split()
a, b, c = sorted(map(NOTES.index, input().split()))
x, y = b-a, c-b
if (x,y) in ((4,3), (3,5)):
print('major')
elif (x,y) in ((3,4), (4,5)):
print('minor')
else:
print('strange')
``` | instruction | 0 | 8,791 | 3 | 17,582 |
No | output | 1 | 8,791 | 3 | 17,583 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitones
Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads β major and minor.
Let's define a major triad. Let the triad consist of notes X, Y and Z. If we can order the notes so as the distance along the musical scale between X and Y equals 4 semitones and the distance between Y and Z is 3 semitones, then the triad is major. The distance between X and Z, accordingly, equals 7 semitones.
A minor triad is different in that the distance between X and Y should be 3 semitones and between Y and Z β 4 semitones.
For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# and F β 4 semitones.
Help Vasya classify the triad the teacher has given to him.
Input
The only line contains 3 space-separated notes in the above-given notation.
Output
Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously.
Examples
Input
C E G
Output
major
Input
C# B F
Output
minor
Input
A B H
Output
strange
Submitted Solution:
```
def check(a,b,c):
if abs(a-b)%4==0 and abs(b-c)%3==0:
print("major")
exit()
elif abs(a-b)%3==0 and abs(b-c)%4==0:
print("minor")
exit()
a,b,c=(map(str,input().split()))
notes=["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H"]
a2=notes.index(a)%12
b2=notes.index(b)%12
c2=notes.index(c)%12
check(a2,b2,c2)
check(a2,c2,b2)
check(b2,a2,c2)
check(b2,c2,a2)
check(c2,a2,b2)
check(c2,b2,a2)
print("strange")
``` | instruction | 0 | 8,792 | 3 | 17,584 |
No | output | 1 | 8,792 | 3 | 17,585 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitones
Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads β major and minor.
Let's define a major triad. Let the triad consist of notes X, Y and Z. If we can order the notes so as the distance along the musical scale between X and Y equals 4 semitones and the distance between Y and Z is 3 semitones, then the triad is major. The distance between X and Z, accordingly, equals 7 semitones.
A minor triad is different in that the distance between X and Y should be 3 semitones and between Y and Z β 4 semitones.
For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# and F β 4 semitones.
Help Vasya classify the triad the teacher has given to him.
Input
The only line contains 3 space-separated notes in the above-given notation.
Output
Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously.
Examples
Input
C E G
Output
major
Input
C# B F
Output
minor
Input
A B H
Output
strange
Submitted Solution:
```
import math
a,b,c=[str(i) for i in input().split()]
l=['C','C#','D','D#','E','F','F#','G','G#','A','B','H']
d=abs(l.index(a)-l.index(b))
e=abs(l.index(b)-l.index(c))
f=abs(l.index(a)-l.index(c))
flag=0
if(d==4 or (12-d)==4):
flag=flag+1
if(e==3 or (12-e)==3):
flag=flag+1
if(f==7 or (12-f)==7):
flag=flag+1
sflag=0
if(d==4 or (12-d)==4):
sflag=sflag+1
if(e==3 or (12-e)==3):
sflag=sflag+1
if(flag==3):
print('major')
elif(sflag==2):
print('minor')
else:
print('strange')
``` | instruction | 0 | 8,793 | 3 | 17,586 |
No | output | 1 | 8,793 | 3 | 17,587 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitones
Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads β major and minor.
Let's define a major triad. Let the triad consist of notes X, Y and Z. If we can order the notes so as the distance along the musical scale between X and Y equals 4 semitones and the distance between Y and Z is 3 semitones, then the triad is major. The distance between X and Z, accordingly, equals 7 semitones.
A minor triad is different in that the distance between X and Y should be 3 semitones and between Y and Z β 4 semitones.
For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# and F β 4 semitones.
Help Vasya classify the triad the teacher has given to him.
Input
The only line contains 3 space-separated notes in the above-given notation.
Output
Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously.
Examples
Input
C E G
Output
major
Input
C# B F
Output
minor
Input
A B H
Output
strange
Submitted Solution:
```
# Author: SaykaT
# Problem: 88A.py
# Time Created: August 09(Sunday) 2020 || 04:38:42
#>-------------------------<#
import sys
input = sys.stdin.readline
#>-------------------------<#
# Helper Functions. -> Don't cluster your code.
# IO Functions. -> Input output
def io():
x, y, z = map(str, input().split())
x, y, z = sorted([x, y, z])
return x, y, z
# Main functions. -> Write the main solution here
def solve():
x, y, z = io()
notes = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'B', 'H']
notes += notes
x_y = 0
x_y_min = 0
y_z = 0
y_z_min = 0
for i in range(notes.index(x), len(notes)):
if notes[i]== y: break
else: x_y += 1
for i in range(notes.index(y), len(notes)):
if notes[i] == x: break
else: x_y_min += 1
for i in range(notes.index(y), len(notes)):
if notes[i] == z: break
else: y_z += 1
for i in range(notes.index(z), len(notes)):
if notes[i] == y: break
else: y_z_min += 1
x_y = min(x_y, x_y_min)
y_z = min(y_z, y_z_min)
if x_y == 4 and y_z == 3: ans = 'major'
elif x_y == 3 and y_z == 4: ans = 'minor'
else: ans = 'strange'
print(ans)
# Multiple test cases. -> When you have T test cases.
solve()
``` | instruction | 0 | 8,794 | 3 | 17,588 |
No | output | 1 | 8,794 | 3 | 17,589 |
Provide a correct Python 3 solution for this coding contest problem.
When a boy was cleaning up after his grand father passing, he found an old paper:
<image>
In addition, other side of the paper says that "go ahead a number of steps equivalent to the first integer, and turn clockwise by degrees equivalent to the second integer".
His grand mother says that Sanbonmatsu was standing at the center of town. However, now buildings are crammed side by side and people can not walk along exactly what the paper says in. Your task is to write a program which hunts for the treature on the paper.
For simplicity, 1 step is equivalent to 1 meter. Input consists of several pairs of two integers d (the first integer) and t (the second integer) separated by a comma. Input ends with "0, 0". Your program should print the coordinate (x, y) of the end point. There is the treature where x meters to the east and y meters to the north from the center of town.
You can assume that d β€ 100 and -180 β€ t β€ 180.
Input
A sequence of pairs of integers d and t which end with "0,0".
Output
Print the integer portion of x and y in a line respectively.
Example
Input
56,65
97,54
64,-4
55,76
42,-27
43,80
87,-86
55,-6
89,34
95,5
0,0
Output
171
-302 | instruction | 0 | 8,956 | 3 | 17,912 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
import sys
import os
from math import sin, cos
import math
def rotate_vector(v, rad):
x = v[0]
y = v[1]
new_x = cos(rad) * x - sin(rad) * y
new_y = sin(rad) * x + cos(rad) * y
return (new_x, new_y)
pos = [0, 0]
dir = [0, 1]
for s in sys.stdin:
length, degree = map(int, s.split(','))
# move
pos[0] += dir[0] * length
pos[1] += dir[1] * length
# rotate
rad = math.radians(degree)
rad *= -1
# rotated dir
dir = rotate_vector(dir, rad)
print(int(pos[0]))
print(int(pos[1]))
``` | output | 1 | 8,956 | 3 | 17,913 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.