text stringlengths 198 433k | conversation_id int64 0 109k |
|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
While Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of size n × m, divided into cells of size 1 × 1, inhabited by tiny evil fishes (no more than one fish per cell, otherwise they'll strife!).
The gift bundle also includes a square scoop of size r × r, designed for fishing. If the lower-left corner of the scoop-net is located at cell (x, y), all fishes inside the square (x, y)...(x + r - 1, y + r - 1) get caught. Note that the scoop-net should lie completely inside the pond when used.
Unfortunately, Sasha is not that skilled in fishing and hence throws the scoop randomly. In order to not frustrate Sasha, Misha decided to release k fishes into the empty pond in such a way that the expected value of the number of caught fishes is as high as possible. Help Misha! In other words, put k fishes in the pond into distinct cells in such a way that when the scoop-net is placed into a random position among (n - r + 1)·(m - r + 1) possible positions, the average number of caught fishes is as high as possible.
Input
The only line contains four integers n, m, r, k (1 ≤ n, m ≤ 105, 1 ≤ r ≤ min(n, m), 1 ≤ k ≤ min(n·m, 105)).
Output
Print a single number — the maximum possible expected number of caught fishes.
You answer is considered correct, is its absolute or relative error does not exceed 10 - 9. Namely, let your answer be a, and the jury's answer be b. Your answer is considered correct, if <image>.
Examples
Input
3 3 2 3
Output
2.0000000000
Input
12 17 9 40
Output
32.8333333333
Note
In the first example you can put the fishes in cells (2, 1), (2, 2), (2, 3). In this case, for any of four possible positions of the scoop-net (highlighted with light green), the number of fishes inside is equal to two, and so is the expected value.
<image>
Tags: data structures, graphs, greedy, probabilities, shortest paths
Correct Solution:
```
from heapq import *
n, m, r, k = map(int, input().split())
u, v = n // 2, m // 2
h = []
g = lambda z, l: min(z + 1, l - z, l - r + 1, r)
def f(x, y):
if 0 <= x < n and 0 <= y < m:
s = g(x, n) * g(y, m)
heappush(h, (-s, x, y))
f(u, v)
t = 0
for i in range(k):
s, x, y = heappop(h)
t -= s
if x <= u: f(x - 1, y)
if x == u and y <= v: f(x, y - 1)
if x >= u: f(x + 1, y)
if x == u and y >= v: f(x, y + 1)
print(t / (n - r + 1) / (m - r + 1))
```
| 8,800 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
While Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of size n × m, divided into cells of size 1 × 1, inhabited by tiny evil fishes (no more than one fish per cell, otherwise they'll strife!).
The gift bundle also includes a square scoop of size r × r, designed for fishing. If the lower-left corner of the scoop-net is located at cell (x, y), all fishes inside the square (x, y)...(x + r - 1, y + r - 1) get caught. Note that the scoop-net should lie completely inside the pond when used.
Unfortunately, Sasha is not that skilled in fishing and hence throws the scoop randomly. In order to not frustrate Sasha, Misha decided to release k fishes into the empty pond in such a way that the expected value of the number of caught fishes is as high as possible. Help Misha! In other words, put k fishes in the pond into distinct cells in such a way that when the scoop-net is placed into a random position among (n - r + 1)·(m - r + 1) possible positions, the average number of caught fishes is as high as possible.
Input
The only line contains four integers n, m, r, k (1 ≤ n, m ≤ 105, 1 ≤ r ≤ min(n, m), 1 ≤ k ≤ min(n·m, 105)).
Output
Print a single number — the maximum possible expected number of caught fishes.
You answer is considered correct, is its absolute or relative error does not exceed 10 - 9. Namely, let your answer be a, and the jury's answer be b. Your answer is considered correct, if <image>.
Examples
Input
3 3 2 3
Output
2.0000000000
Input
12 17 9 40
Output
32.8333333333
Note
In the first example you can put the fishes in cells (2, 1), (2, 2), (2, 3). In this case, for any of four possible positions of the scoop-net (highlighted with light green), the number of fishes inside is equal to two, and so is the expected value.
<image>
Submitted Solution:
```
import time
n, m, r, k = map(int, input().split())
if n == 1 and m == 1:
print(1)
quit()
x = (n + 1) // 2
y = (m + 1) // 2
ans = 0
xx = 1
xxx = n + 1
yy = 1
yyy = m + 1
if r * 2 < m and r * 2 < n:
while (yyy - yy - 2) * (xxx - xx - 2) >= k:
xx += 1
xxx -= 1
yy += 1
yyy -= 1
else:
if (r * 2 >= m and r * 2 < n):
while (yyy - yy - 2) * (xxx - xx - 2) >= k:
yy += 1
yyy -= 1
if (r * 2 >= n and r * 2 < m):
while (yyy - yy - 2) * (xxx - xx - 2) >= k:
xx += 1
xxx -= 1
if (r * 2 >= n and r * 2 >= m):
while (yyy - yy - 2) * (xxx - xx - 2) >= k:
xx += 1
xxx -= 1
yy += 1
yyy -= 1
xx -= 80
xxx += 80
yy -= 80
yyy += 80
pedy = []
for i in range(xx, xxx + 1):
for j in range(yy, yyy + 1):
x = i
y = j
op = x - r
lp = x + r
if x - r < 0:
op = 0
if x + r - 1 > n:
lp = n + 1
p = lp - op - r
opp = y - r
lpp = y + r
if y - r < 0:
opp = 0
if y + r - 1 > m:
lpp = m + 1
pp = lpp - opp - r
pedy.append(p * pp)
pedy.sort()
pedy.reverse()
for i in range(k):
ans += pedy[i]
print(float(ans) / (float(n - r + 1) * float(m - r + 1)))
```
No
| 8,801 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
While Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of size n × m, divided into cells of size 1 × 1, inhabited by tiny evil fishes (no more than one fish per cell, otherwise they'll strife!).
The gift bundle also includes a square scoop of size r × r, designed for fishing. If the lower-left corner of the scoop-net is located at cell (x, y), all fishes inside the square (x, y)...(x + r - 1, y + r - 1) get caught. Note that the scoop-net should lie completely inside the pond when used.
Unfortunately, Sasha is not that skilled in fishing and hence throws the scoop randomly. In order to not frustrate Sasha, Misha decided to release k fishes into the empty pond in such a way that the expected value of the number of caught fishes is as high as possible. Help Misha! In other words, put k fishes in the pond into distinct cells in such a way that when the scoop-net is placed into a random position among (n - r + 1)·(m - r + 1) possible positions, the average number of caught fishes is as high as possible.
Input
The only line contains four integers n, m, r, k (1 ≤ n, m ≤ 105, 1 ≤ r ≤ min(n, m), 1 ≤ k ≤ min(n·m, 105)).
Output
Print a single number — the maximum possible expected number of caught fishes.
You answer is considered correct, is its absolute or relative error does not exceed 10 - 9. Namely, let your answer be a, and the jury's answer be b. Your answer is considered correct, if <image>.
Examples
Input
3 3 2 3
Output
2.0000000000
Input
12 17 9 40
Output
32.8333333333
Note
In the first example you can put the fishes in cells (2, 1), (2, 2), (2, 3). In this case, for any of four possible positions of the scoop-net (highlighted with light green), the number of fishes inside is equal to two, and so is the expected value.
<image>
Submitted Solution:
```
from math import *
n, m, r, k = input().split()
n = int(n)
m = int(m)
r = int(r)
k = int(k)
values = []
centery = floor((n) / 2)
centerx = floor((m) / 2)
radius = sqrt(k)
radius = ceil(radius)
xlength = 0
ylength = 0
beginx = 0
endx = 0
beginy = 0
endy = 0
if centerx ** 2 <= k:
beginx = centerx - radius + 1
endx = centerx + radius - 1
else:
beginx = 1
endx = m
if centery ** 2 <= k:
beginy = centery - radius + 1
endy = centery + radius - 1
else:
beginy = 1
endy = n
for a in range(beginx, endx + 1):
for b in range(beginy, endy + 1):
tempx = min(r, m - r + 1, m - a + 1, a )
tempy = min(r, n - r + 1, n - b + 1, b)
values.append(tempy * tempx)
values.sort()
sum = 0
for x in range(0, k):
sum += values[-1 - x]
sum /= (n - r + 1) * (m - r + 1)
print(sum)
```
No
| 8,802 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
While Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of size n × m, divided into cells of size 1 × 1, inhabited by tiny evil fishes (no more than one fish per cell, otherwise they'll strife!).
The gift bundle also includes a square scoop of size r × r, designed for fishing. If the lower-left corner of the scoop-net is located at cell (x, y), all fishes inside the square (x, y)...(x + r - 1, y + r - 1) get caught. Note that the scoop-net should lie completely inside the pond when used.
Unfortunately, Sasha is not that skilled in fishing and hence throws the scoop randomly. In order to not frustrate Sasha, Misha decided to release k fishes into the empty pond in such a way that the expected value of the number of caught fishes is as high as possible. Help Misha! In other words, put k fishes in the pond into distinct cells in such a way that when the scoop-net is placed into a random position among (n - r + 1)·(m - r + 1) possible positions, the average number of caught fishes is as high as possible.
Input
The only line contains four integers n, m, r, k (1 ≤ n, m ≤ 105, 1 ≤ r ≤ min(n, m), 1 ≤ k ≤ min(n·m, 105)).
Output
Print a single number — the maximum possible expected number of caught fishes.
You answer is considered correct, is its absolute or relative error does not exceed 10 - 9. Namely, let your answer be a, and the jury's answer be b. Your answer is considered correct, if <image>.
Examples
Input
3 3 2 3
Output
2.0000000000
Input
12 17 9 40
Output
32.8333333333
Note
In the first example you can put the fishes in cells (2, 1), (2, 2), (2, 3). In this case, for any of four possible positions of the scoop-net (highlighted with light green), the number of fishes inside is equal to two, and so is the expected value.
<image>
Submitted Solution:
```
import time
n, m, r, k = map(int, input().split())
if n == 1 and m == 1:
print(1)
quit()
x = (n + 1) // 2
y = (m + 1) // 2
ans = 0
xx = 1
xxx = n + 1
yy = 1
yyy = m + 1
if r * 2 < m and r * 2 < n:
while (yyy - yy - 2) * (xxx - xx - 2) >= k:
xx += 1
xxx -= 1
yy += 1
yyy -= 1
else:
if (r * 2 >= m and r * 2 < n):
while (yyy - yy - 2) * (xxx - xx - 2) >= k:
yy += 1
yyy -= 1
if (r * 2 >= n and r * 2 < m):
while (yyy - yy - 2) * (xxx - xx - 2) >= k:
xx += 1
xxx -= 1
if (r * 2 >= n and r * 2 >= m):
while (yyy - yy - 2) * (xxx - xx - 2) >= k:
xx += 1
xxx -= 1
yy += 1
yyy -= 1
xx -= 80
xx = max(0, xx)
xxx += 80
xxx = min(n + 1, xxx)
yy -= 80
yy = max(0, yy)
yyy += 80
yyy = min(m + 1, yyy)
pedy = []
for i in range(xx, xxx + 1):
for j in range(yy, yyy + 1):
x = i
y = j
op = x - r
lp = x + r
if x - r < 0:
op = 0
if x + r - 1 > n:
lp = n + 1
p = lp - op - r
opp = y - r
lpp = y + r
if y - r < 0:
opp = 0
if y + r - 1 > m:
lpp = m + 1
pp = lpp - opp - r
pedy.append(p * pp)
pedy.sort()
pedy.reverse()
for i in range(k):
ans += pedy[i]
print(float(ans) / (float(n - r + 1) * float(m - r + 1)))
```
No
| 8,803 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
While Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of size n × m, divided into cells of size 1 × 1, inhabited by tiny evil fishes (no more than one fish per cell, otherwise they'll strife!).
The gift bundle also includes a square scoop of size r × r, designed for fishing. If the lower-left corner of the scoop-net is located at cell (x, y), all fishes inside the square (x, y)...(x + r - 1, y + r - 1) get caught. Note that the scoop-net should lie completely inside the pond when used.
Unfortunately, Sasha is not that skilled in fishing and hence throws the scoop randomly. In order to not frustrate Sasha, Misha decided to release k fishes into the empty pond in such a way that the expected value of the number of caught fishes is as high as possible. Help Misha! In other words, put k fishes in the pond into distinct cells in such a way that when the scoop-net is placed into a random position among (n - r + 1)·(m - r + 1) possible positions, the average number of caught fishes is as high as possible.
Input
The only line contains four integers n, m, r, k (1 ≤ n, m ≤ 105, 1 ≤ r ≤ min(n, m), 1 ≤ k ≤ min(n·m, 105)).
Output
Print a single number — the maximum possible expected number of caught fishes.
You answer is considered correct, is its absolute or relative error does not exceed 10 - 9. Namely, let your answer be a, and the jury's answer be b. Your answer is considered correct, if <image>.
Examples
Input
3 3 2 3
Output
2.0000000000
Input
12 17 9 40
Output
32.8333333333
Note
In the first example you can put the fishes in cells (2, 1), (2, 2), (2, 3). In this case, for any of four possible positions of the scoop-net (highlighted with light green), the number of fishes inside is equal to two, and so is the expected value.
<image>
Submitted Solution:
```
from collections import namedtuple
from math import ceil
from queue import PriorityQueue
def get_prior( point ):
c1 = r - max(r-point.x, 0) - max( point.x+ r- 1 -n, 0 )
c2 = r - max(r - point.y, 0) - max(point.y +r - 1 - m ,0)
return c1*c2
dx = [0,0,-1,1]
dy = [1,-1,0,0]
n,m,r,k = map(int,input().split())
mas = [[False for col in range(m+1)] for row in range(n+1)]
rn = range(1,n+1)
rm = range(1,m+1)
if n>m: n,m = m,n
Point = namedtuple("Point", ["x", "y"])
q = PriorityQueue()
center = Point(ceil(n/2), ceil(m/2))
q.put((-get_prior(center),center))
mas[center.x][center.y] = True
cnt = 0
summ = 0
while not q.empty():
pop = q.get()
cur_point = pop[1]
cur_prior = pop[0]
print (cur_point.x , cur_point.y , cur_prior),
#print (q.queue)
summ += cur_prior
cnt += 1
if cnt == k: break
for i in range(0, 4):
new_point = Point( cur_point.x + dx[i] , cur_point.y + dy[i] )
#print ("N" , new_point)
if new_point.x in rn and new_point.y in rm:
#print ("N" , new_point)
if mas[new_point.x][new_point.y] == False:
q.put((-get_prior(new_point),new_point))
mas[new_point.x][new_point.y] = True
print ( - summ / ((n-r +1 )*(m-r+1)))
```
No
| 8,804 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must.
Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this...
Given two integers p and k, find a polynomial f(x) with non-negative integer coefficients strictly less than k, whose remainder is p when divided by (x + k). That is, f(x) = q(x)·(x + k) + p, where q(x) is a polynomial (not necessarily with integer coefficients).
Input
The only line of input contains two space-separated integers p and k (1 ≤ p ≤ 1018, 2 ≤ k ≤ 2 000).
Output
If the polynomial does not exist, print a single integer -1, or output two lines otherwise.
In the first line print a non-negative integer d — the number of coefficients in the polynomial.
In the second line print d space-separated integers a0, a1, ..., ad - 1, describing a polynomial <image> fulfilling the given requirements. Your output should satisfy 0 ≤ ai < k for all 0 ≤ i ≤ d - 1, and ad - 1 ≠ 0.
If there are many possible solutions, print any of them.
Examples
Input
46 2
Output
7
0 1 0 0 1 1 1
Input
2018 214
Output
3
92 205 1
Note
In the first example, f(x) = x6 + x5 + x4 + x = (x5 - x4 + 3x3 - 6x2 + 12x - 23)·(x + 2) + 46.
In the second example, f(x) = x2 + 205x + 92 = (x - 9)·(x + 214) + 2018.
Tags: math
Correct Solution:
```
R=lambda:map(int,input().split())
p, k = R()
a = []
t = p//k
temp = 1
if p >= k:
while k * t >= k:
a.insert(0, (-1)**temp * t)
flag = True
if t%k == 0: flag = False
t = abs(t//k)
if temp % 2 == 1 and flag : t += 1
temp += 1
if temp % 2 == 0:
a.insert(0, 1)
ans = [0] * (len(a) + 1)
for i in range(1, len(ans) - 1):
ans[i] = a[i] + k * a[i - 1]
ans[0] = a[0]
ans[-1] = k * a[-1] + p
if p < k:
ans = [p]
print(len(ans))
print (" ".join([str(x) for x in ans[::-1]] ))
```
| 8,805 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must.
Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this...
Given two integers p and k, find a polynomial f(x) with non-negative integer coefficients strictly less than k, whose remainder is p when divided by (x + k). That is, f(x) = q(x)·(x + k) + p, where q(x) is a polynomial (not necessarily with integer coefficients).
Input
The only line of input contains two space-separated integers p and k (1 ≤ p ≤ 1018, 2 ≤ k ≤ 2 000).
Output
If the polynomial does not exist, print a single integer -1, or output two lines otherwise.
In the first line print a non-negative integer d — the number of coefficients in the polynomial.
In the second line print d space-separated integers a0, a1, ..., ad - 1, describing a polynomial <image> fulfilling the given requirements. Your output should satisfy 0 ≤ ai < k for all 0 ≤ i ≤ d - 1, and ad - 1 ≠ 0.
If there are many possible solutions, print any of them.
Examples
Input
46 2
Output
7
0 1 0 0 1 1 1
Input
2018 214
Output
3
92 205 1
Note
In the first example, f(x) = x6 + x5 + x4 + x = (x5 - x4 + 3x3 - 6x2 + 12x - 23)·(x + 2) + 46.
In the second example, f(x) = x2 + 205x + 92 = (x - 9)·(x + 214) + 2018.
Tags: math
Correct Solution:
```
[p,k]=[int(x) for x in input().split()]
d=1
res=[]
while p:
if d%2==1:
kek=k
res.append(str(p%kek))
p//=kek
else:
kek=k
lol=kek-(p%kek)
while lol>=kek:
lol-=kek
res.append(str(lol))
p=(p+lol)//kek
d+=1
print(len(res))
s=' '
print(s.join(res))
```
| 8,806 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must.
Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this...
Given two integers p and k, find a polynomial f(x) with non-negative integer coefficients strictly less than k, whose remainder is p when divided by (x + k). That is, f(x) = q(x)·(x + k) + p, where q(x) is a polynomial (not necessarily with integer coefficients).
Input
The only line of input contains two space-separated integers p and k (1 ≤ p ≤ 1018, 2 ≤ k ≤ 2 000).
Output
If the polynomial does not exist, print a single integer -1, or output two lines otherwise.
In the first line print a non-negative integer d — the number of coefficients in the polynomial.
In the second line print d space-separated integers a0, a1, ..., ad - 1, describing a polynomial <image> fulfilling the given requirements. Your output should satisfy 0 ≤ ai < k for all 0 ≤ i ≤ d - 1, and ad - 1 ≠ 0.
If there are many possible solutions, print any of them.
Examples
Input
46 2
Output
7
0 1 0 0 1 1 1
Input
2018 214
Output
3
92 205 1
Note
In the first example, f(x) = x6 + x5 + x4 + x = (x5 - x4 + 3x3 - 6x2 + 12x - 23)·(x + 2) + 46.
In the second example, f(x) = x2 + 205x + 92 = (x - 9)·(x + 214) + 2018.
Tags: math
Correct Solution:
```
def solve(n,p,k):
# print(n,p,k)
P=p
cf=1
a=[0]*n
for i in range(n):
if i&1:
p+=cf*(k-1)
a[i]-=k-1
cf*=k
# print(p)
for i in range(n):
a[i]+=p%k
p//=k
# print(n,a)
if p:
return
for i in range(n):
if i&1:
a[i]*=-1
cf=1
p=P
for i in range(n):
if a[i]<0 or a[i]>=k:
return
if i&1:
p+=a[i]*cf
else:
p-=a[i]*cf
cf*=k
if p:
return
print(len(a))
print(*a)
exit(0)
p,k=map(int,input().split())
for i in range(100):
if k**i>1<<100:
break
solve(i,p,k)
print(-1)
```
| 8,807 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must.
Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this...
Given two integers p and k, find a polynomial f(x) with non-negative integer coefficients strictly less than k, whose remainder is p when divided by (x + k). That is, f(x) = q(x)·(x + k) + p, where q(x) is a polynomial (not necessarily with integer coefficients).
Input
The only line of input contains two space-separated integers p and k (1 ≤ p ≤ 1018, 2 ≤ k ≤ 2 000).
Output
If the polynomial does not exist, print a single integer -1, or output two lines otherwise.
In the first line print a non-negative integer d — the number of coefficients in the polynomial.
In the second line print d space-separated integers a0, a1, ..., ad - 1, describing a polynomial <image> fulfilling the given requirements. Your output should satisfy 0 ≤ ai < k for all 0 ≤ i ≤ d - 1, and ad - 1 ≠ 0.
If there are many possible solutions, print any of them.
Examples
Input
46 2
Output
7
0 1 0 0 1 1 1
Input
2018 214
Output
3
92 205 1
Note
In the first example, f(x) = x6 + x5 + x4 + x = (x5 - x4 + 3x3 - 6x2 + 12x - 23)·(x + 2) + 46.
In the second example, f(x) = x2 + 205x + 92 = (x - 9)·(x + 214) + 2018.
Tags: math
Correct Solution:
```
p,k = map(int, input().split())
coeff = [1]
maxi =k-1
kk = k*k
while maxi < p:
for i in range(2):
coeff.append(0)
maxi += kk*(k-1)
kk*=k*2
n = len(coeff)
powk = [0 for i in range(n)]
pos = [0 for i in range(n)]
neg = [0 for i in range(n)]
powk[0] = 1
for i in range(1,n):
powk[i] = powk[i-1]*k
pos[0]=k-1;
neg[0]=0;
for i in range(1,n):
if i%2 ==0:
pos[i] = pos[i-1]+powk[i]*(k-1);
neg[i] = neg[i-1];
else:
pos[i] = pos[i-1];
neg[i] = neg[i-1] + powk[i]*(k-1);
for i in range(n-1,-1,-1):
if i%2 ==0:
coeff[i] = (p+neg[i])//powk[i];
p-=coeff[i]*powk[i];
else:
coeff[i] = (-p+pos[i])//powk[i];
p+=coeff[i]*powk[i];
ng = False
for i in range(n):
if coeff[i]>=k:
ng = True
if ng:
print(-1)
else:
d=n
for i in range(n-1,-1,-1):
if coeff[i]==0:
d = d-1
else:
break
print(d)
print(' '.join(map(str, coeff[0:d])))
```
| 8,808 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must.
Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this...
Given two integers p and k, find a polynomial f(x) with non-negative integer coefficients strictly less than k, whose remainder is p when divided by (x + k). That is, f(x) = q(x)·(x + k) + p, where q(x) is a polynomial (not necessarily with integer coefficients).
Input
The only line of input contains two space-separated integers p and k (1 ≤ p ≤ 1018, 2 ≤ k ≤ 2 000).
Output
If the polynomial does not exist, print a single integer -1, or output two lines otherwise.
In the first line print a non-negative integer d — the number of coefficients in the polynomial.
In the second line print d space-separated integers a0, a1, ..., ad - 1, describing a polynomial <image> fulfilling the given requirements. Your output should satisfy 0 ≤ ai < k for all 0 ≤ i ≤ d - 1, and ad - 1 ≠ 0.
If there are many possible solutions, print any of them.
Examples
Input
46 2
Output
7
0 1 0 0 1 1 1
Input
2018 214
Output
3
92 205 1
Note
In the first example, f(x) = x6 + x5 + x4 + x = (x5 - x4 + 3x3 - 6x2 + 12x - 23)·(x + 2) + 46.
In the second example, f(x) = x2 + 205x + 92 = (x - 9)·(x + 214) + 2018.
Tags: math
Correct Solution:
```
a,b=map(int,input().split())
c=-(a//b)
out=[a%b]
while True:
#print(c)
out.append(c%b)
c=-(c//b)
if out[-1]==c==0:
break
print(len(out)-1)
for i in out[:-1]:
print(i,end=" ")
print()
```
| 8,809 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must.
Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this...
Given two integers p and k, find a polynomial f(x) with non-negative integer coefficients strictly less than k, whose remainder is p when divided by (x + k). That is, f(x) = q(x)·(x + k) + p, where q(x) is a polynomial (not necessarily with integer coefficients).
Input
The only line of input contains two space-separated integers p and k (1 ≤ p ≤ 1018, 2 ≤ k ≤ 2 000).
Output
If the polynomial does not exist, print a single integer -1, or output two lines otherwise.
In the first line print a non-negative integer d — the number of coefficients in the polynomial.
In the second line print d space-separated integers a0, a1, ..., ad - 1, describing a polynomial <image> fulfilling the given requirements. Your output should satisfy 0 ≤ ai < k for all 0 ≤ i ≤ d - 1, and ad - 1 ≠ 0.
If there are many possible solutions, print any of them.
Examples
Input
46 2
Output
7
0 1 0 0 1 1 1
Input
2018 214
Output
3
92 205 1
Note
In the first example, f(x) = x6 + x5 + x4 + x = (x5 - x4 + 3x3 - 6x2 + 12x - 23)·(x + 2) + 46.
In the second example, f(x) = x2 + 205x + 92 = (x - 9)·(x + 214) + 2018.
Tags: math
Correct Solution:
```
n,a = map(int,input().split())
ar = []
j = 1
while n!=0:
q = n%a
n //= a
n = -1*n
#j += 1
ar.append(q)
print(len(ar))
for i in range(len(ar)):
print(ar[i])
```
| 8,810 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must.
Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this...
Given two integers p and k, find a polynomial f(x) with non-negative integer coefficients strictly less than k, whose remainder is p when divided by (x + k). That is, f(x) = q(x)·(x + k) + p, where q(x) is a polynomial (not necessarily with integer coefficients).
Input
The only line of input contains two space-separated integers p and k (1 ≤ p ≤ 1018, 2 ≤ k ≤ 2 000).
Output
If the polynomial does not exist, print a single integer -1, or output two lines otherwise.
In the first line print a non-negative integer d — the number of coefficients in the polynomial.
In the second line print d space-separated integers a0, a1, ..., ad - 1, describing a polynomial <image> fulfilling the given requirements. Your output should satisfy 0 ≤ ai < k for all 0 ≤ i ≤ d - 1, and ad - 1 ≠ 0.
If there are many possible solutions, print any of them.
Examples
Input
46 2
Output
7
0 1 0 0 1 1 1
Input
2018 214
Output
3
92 205 1
Note
In the first example, f(x) = x6 + x5 + x4 + x = (x5 - x4 + 3x3 - 6x2 + 12x - 23)·(x + 2) + 46.
In the second example, f(x) = x2 + 205x + 92 = (x - 9)·(x + 214) + 2018.
Tags: math
Correct Solution:
```
p, k = map(int, input().split())
if p < k:
print(1)
print(p)
else:
ans = [p]
cur = p
while cur < 0 or cur >= k:
cur = - (cur // k)
ans.append(cur)
arr = []
for i in range(1, len(ans)):
arr.append(str(k*ans[i]+ans[i-1]))
arr.append(str(ans[-1]))
print(len(arr))
print(' '.join(arr))
```
| 8,811 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must.
Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this...
Given two integers p and k, find a polynomial f(x) with non-negative integer coefficients strictly less than k, whose remainder is p when divided by (x + k). That is, f(x) = q(x)·(x + k) + p, where q(x) is a polynomial (not necessarily with integer coefficients).
Input
The only line of input contains two space-separated integers p and k (1 ≤ p ≤ 1018, 2 ≤ k ≤ 2 000).
Output
If the polynomial does not exist, print a single integer -1, or output two lines otherwise.
In the first line print a non-negative integer d — the number of coefficients in the polynomial.
In the second line print d space-separated integers a0, a1, ..., ad - 1, describing a polynomial <image> fulfilling the given requirements. Your output should satisfy 0 ≤ ai < k for all 0 ≤ i ≤ d - 1, and ad - 1 ≠ 0.
If there are many possible solutions, print any of them.
Examples
Input
46 2
Output
7
0 1 0 0 1 1 1
Input
2018 214
Output
3
92 205 1
Note
In the first example, f(x) = x6 + x5 + x4 + x = (x5 - x4 + 3x3 - 6x2 + 12x - 23)·(x + 2) + 46.
In the second example, f(x) = x2 + 205x + 92 = (x - 9)·(x + 214) + 2018.
Tags: math
Correct Solution:
```
p, k = map(int, input().split())
a = ''
cnt = 0
while p != 0:
cnt += 1
a += str(p % k) + ' '
p -= p % k
p //= -k
print(cnt)
print(a)
```
| 8,812 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must.
Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this...
Given two integers p and k, find a polynomial f(x) with non-negative integer coefficients strictly less than k, whose remainder is p when divided by (x + k). That is, f(x) = q(x)·(x + k) + p, where q(x) is a polynomial (not necessarily with integer coefficients).
Input
The only line of input contains two space-separated integers p and k (1 ≤ p ≤ 1018, 2 ≤ k ≤ 2 000).
Output
If the polynomial does not exist, print a single integer -1, or output two lines otherwise.
In the first line print a non-negative integer d — the number of coefficients in the polynomial.
In the second line print d space-separated integers a0, a1, ..., ad - 1, describing a polynomial <image> fulfilling the given requirements. Your output should satisfy 0 ≤ ai < k for all 0 ≤ i ≤ d - 1, and ad - 1 ≠ 0.
If there are many possible solutions, print any of them.
Examples
Input
46 2
Output
7
0 1 0 0 1 1 1
Input
2018 214
Output
3
92 205 1
Note
In the first example, f(x) = x6 + x5 + x4 + x = (x5 - x4 + 3x3 - 6x2 + 12x - 23)·(x + 2) + 46.
In the second example, f(x) = x2 + 205x + 92 = (x - 9)·(x + 214) + 2018.
Submitted Solution:
```
p, k = input().split()
p, k = int(p), int(k)
s = k - 1
ls = [0]
while s < p:
ls.append(0)
ls.append(0)
s = s * k * k + k - 1
n = len(ls)
for i in range(n):
if (i & 1) == 0:
ls[i] = k - 1
res = s - p
for i in range(n):
t = res % k
if i & 1:
ls[i] += t
else:
ls[i] -= t
res //= k
print(n)
print(" ".join(str(x) for x in ls))
```
Yes
| 8,813 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must.
Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this...
Given two integers p and k, find a polynomial f(x) with non-negative integer coefficients strictly less than k, whose remainder is p when divided by (x + k). That is, f(x) = q(x)·(x + k) + p, where q(x) is a polynomial (not necessarily with integer coefficients).
Input
The only line of input contains two space-separated integers p and k (1 ≤ p ≤ 1018, 2 ≤ k ≤ 2 000).
Output
If the polynomial does not exist, print a single integer -1, or output two lines otherwise.
In the first line print a non-negative integer d — the number of coefficients in the polynomial.
In the second line print d space-separated integers a0, a1, ..., ad - 1, describing a polynomial <image> fulfilling the given requirements. Your output should satisfy 0 ≤ ai < k for all 0 ≤ i ≤ d - 1, and ad - 1 ≠ 0.
If there are many possible solutions, print any of them.
Examples
Input
46 2
Output
7
0 1 0 0 1 1 1
Input
2018 214
Output
3
92 205 1
Note
In the first example, f(x) = x6 + x5 + x4 + x = (x5 - x4 + 3x3 - 6x2 + 12x - 23)·(x + 2) + 46.
In the second example, f(x) = x2 + 205x + 92 = (x - 9)·(x + 214) + 2018.
Submitted Solution:
```
p,k = map(int,input().split())
num = [0] * 64
sum = 0
c = 0
power = k-1
while(sum < p):
sum += power
power *= k*k
c += 2
#print(power / k / k << endl << sum << endl;
print(c-1)
i = 0
p = sum - p
while(p > 0):
num[i] = p % k
p //= k
i += 1
#cout << sum << endl;
for i in range(c-1):
#cout << num[i] << " ";
if(i % 2 == 0) :print(k - 1 - num[i],end = ' ')
else :print(num[i],end = ' ')
```
Yes
| 8,814 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must.
Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this...
Given two integers p and k, find a polynomial f(x) with non-negative integer coefficients strictly less than k, whose remainder is p when divided by (x + k). That is, f(x) = q(x)·(x + k) + p, where q(x) is a polynomial (not necessarily with integer coefficients).
Input
The only line of input contains two space-separated integers p and k (1 ≤ p ≤ 1018, 2 ≤ k ≤ 2 000).
Output
If the polynomial does not exist, print a single integer -1, or output two lines otherwise.
In the first line print a non-negative integer d — the number of coefficients in the polynomial.
In the second line print d space-separated integers a0, a1, ..., ad - 1, describing a polynomial <image> fulfilling the given requirements. Your output should satisfy 0 ≤ ai < k for all 0 ≤ i ≤ d - 1, and ad - 1 ≠ 0.
If there are many possible solutions, print any of them.
Examples
Input
46 2
Output
7
0 1 0 0 1 1 1
Input
2018 214
Output
3
92 205 1
Note
In the first example, f(x) = x6 + x5 + x4 + x = (x5 - x4 + 3x3 - 6x2 + 12x - 23)·(x + 2) + 46.
In the second example, f(x) = x2 + 205x + 92 = (x - 9)·(x + 214) + 2018.
Submitted Solution:
```
def main():
p,k = [int(x) for x in input().split()]
ff = True
a= []
while True:
if p ==0:
break
# print(k, p)
t = (k - p) // k
if t*k + p == k:
t -=1
if t*k + p < 0:
ff =False
print(-1)
break
a.append(t*k + p)
p = t
# print(a)
if ff:
print(len(a))
print(' '.join(str(x) for x in a))
if __name__ == '__main__':
main()
```
Yes
| 8,815 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must.
Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this...
Given two integers p and k, find a polynomial f(x) with non-negative integer coefficients strictly less than k, whose remainder is p when divided by (x + k). That is, f(x) = q(x)·(x + k) + p, where q(x) is a polynomial (not necessarily with integer coefficients).
Input
The only line of input contains two space-separated integers p and k (1 ≤ p ≤ 1018, 2 ≤ k ≤ 2 000).
Output
If the polynomial does not exist, print a single integer -1, or output two lines otherwise.
In the first line print a non-negative integer d — the number of coefficients in the polynomial.
In the second line print d space-separated integers a0, a1, ..., ad - 1, describing a polynomial <image> fulfilling the given requirements. Your output should satisfy 0 ≤ ai < k for all 0 ≤ i ≤ d - 1, and ad - 1 ≠ 0.
If there are many possible solutions, print any of them.
Examples
Input
46 2
Output
7
0 1 0 0 1 1 1
Input
2018 214
Output
3
92 205 1
Note
In the first example, f(x) = x6 + x5 + x4 + x = (x5 - x4 + 3x3 - 6x2 + 12x - 23)·(x + 2) + 46.
In the second example, f(x) = x2 + 205x + 92 = (x - 9)·(x + 214) + 2018.
Submitted Solution:
```
def rec(n,k):
s=[]
while n!=0:
n,r=n//k,n%k
#print(n,r)
if r<0:
r-=k
n+=1
#print(s,n,r)
s.append(r)
return s
p,k=map(int,input().split())
d=rec(p,-k)
print(len(d))
print(*d)
```
Yes
| 8,816 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must.
Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this...
Given two integers p and k, find a polynomial f(x) with non-negative integer coefficients strictly less than k, whose remainder is p when divided by (x + k). That is, f(x) = q(x)·(x + k) + p, where q(x) is a polynomial (not necessarily with integer coefficients).
Input
The only line of input contains two space-separated integers p and k (1 ≤ p ≤ 1018, 2 ≤ k ≤ 2 000).
Output
If the polynomial does not exist, print a single integer -1, or output two lines otherwise.
In the first line print a non-negative integer d — the number of coefficients in the polynomial.
In the second line print d space-separated integers a0, a1, ..., ad - 1, describing a polynomial <image> fulfilling the given requirements. Your output should satisfy 0 ≤ ai < k for all 0 ≤ i ≤ d - 1, and ad - 1 ≠ 0.
If there are many possible solutions, print any of them.
Examples
Input
46 2
Output
7
0 1 0 0 1 1 1
Input
2018 214
Output
3
92 205 1
Note
In the first example, f(x) = x6 + x5 + x4 + x = (x5 - x4 + 3x3 - 6x2 + 12x - 23)·(x + 2) + 46.
In the second example, f(x) = x2 + 205x + 92 = (x - 9)·(x + 214) + 2018.
Submitted Solution:
```
p, k = map(int, input().split())
r = []
f = 1
while 1:
p, q = divmod(f * p, k)
f = -f
r.append(q)
if p <= 0 and -p < k:
break
if p:
r.append(-p)
print(len(r))
print(*r, sep=' ')
```
No
| 8,817 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must.
Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this...
Given two integers p and k, find a polynomial f(x) with non-negative integer coefficients strictly less than k, whose remainder is p when divided by (x + k). That is, f(x) = q(x)·(x + k) + p, where q(x) is a polynomial (not necessarily with integer coefficients).
Input
The only line of input contains two space-separated integers p and k (1 ≤ p ≤ 1018, 2 ≤ k ≤ 2 000).
Output
If the polynomial does not exist, print a single integer -1, or output two lines otherwise.
In the first line print a non-negative integer d — the number of coefficients in the polynomial.
In the second line print d space-separated integers a0, a1, ..., ad - 1, describing a polynomial <image> fulfilling the given requirements. Your output should satisfy 0 ≤ ai < k for all 0 ≤ i ≤ d - 1, and ad - 1 ≠ 0.
If there are many possible solutions, print any of them.
Examples
Input
46 2
Output
7
0 1 0 0 1 1 1
Input
2018 214
Output
3
92 205 1
Note
In the first example, f(x) = x6 + x5 + x4 + x = (x5 - x4 + 3x3 - 6x2 + 12x - 23)·(x + 2) + 46.
In the second example, f(x) = x2 + 205x + 92 = (x - 9)·(x + 214) + 2018.
Submitted Solution:
```
p, k = map(int, input().split())
res = dict()
ok = True
def f(sm, up):
#print("sm = " + str(sm))
global res
global ok
if (sm == 0) :return
if (sm > 0):
pw = 0
while (k - 1) * k ** pw < sm:
pw += 2
if pw >= up:
ok = False
return
t = int(sm / (k ** pw))
if sm % (k ** pw) > 0:
t += 1
sm -= t * (k ** pw)
res[pw] = t
f(sm, pw)
else:
a = abs(sm)
pw = 1
while (k - 1) * k ** pw < a:
pw += 2
if pw >= up:
ok = False
return
t = int(a / (k ** pw))
if a % (k ** pw) > 0:
t += 1
sm += t * (k ** pw)
res[pw] = t
f(sm, pw)
f(p, int(10**18))
if not ok:
print("-1")
else:
mx = 0
for x in res:
mx = max(x, mx)
a = [0 for i in range(mx + 1)]
print(len(a))
for x in res:
a[x] = res[x]
for x in a:
print(x)
```
No
| 8,818 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must.
Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this...
Given two integers p and k, find a polynomial f(x) with non-negative integer coefficients strictly less than k, whose remainder is p when divided by (x + k). That is, f(x) = q(x)·(x + k) + p, where q(x) is a polynomial (not necessarily with integer coefficients).
Input
The only line of input contains two space-separated integers p and k (1 ≤ p ≤ 1018, 2 ≤ k ≤ 2 000).
Output
If the polynomial does not exist, print a single integer -1, or output two lines otherwise.
In the first line print a non-negative integer d — the number of coefficients in the polynomial.
In the second line print d space-separated integers a0, a1, ..., ad - 1, describing a polynomial <image> fulfilling the given requirements. Your output should satisfy 0 ≤ ai < k for all 0 ≤ i ≤ d - 1, and ad - 1 ≠ 0.
If there are many possible solutions, print any of them.
Examples
Input
46 2
Output
7
0 1 0 0 1 1 1
Input
2018 214
Output
3
92 205 1
Note
In the first example, f(x) = x6 + x5 + x4 + x = (x5 - x4 + 3x3 - 6x2 + 12x - 23)·(x + 2) + 46.
In the second example, f(x) = x2 + 205x + 92 = (x - 9)·(x + 214) + 2018.
Submitted Solution:
```
p, k = map(int, input().split())
print('3\n1', k - p, p - p * k)
```
No
| 8,819 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must.
Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this...
Given two integers p and k, find a polynomial f(x) with non-negative integer coefficients strictly less than k, whose remainder is p when divided by (x + k). That is, f(x) = q(x)·(x + k) + p, where q(x) is a polynomial (not necessarily with integer coefficients).
Input
The only line of input contains two space-separated integers p and k (1 ≤ p ≤ 1018, 2 ≤ k ≤ 2 000).
Output
If the polynomial does not exist, print a single integer -1, or output two lines otherwise.
In the first line print a non-negative integer d — the number of coefficients in the polynomial.
In the second line print d space-separated integers a0, a1, ..., ad - 1, describing a polynomial <image> fulfilling the given requirements. Your output should satisfy 0 ≤ ai < k for all 0 ≤ i ≤ d - 1, and ad - 1 ≠ 0.
If there are many possible solutions, print any of them.
Examples
Input
46 2
Output
7
0 1 0 0 1 1 1
Input
2018 214
Output
3
92 205 1
Note
In the first example, f(x) = x6 + x5 + x4 + x = (x5 - x4 + 3x3 - 6x2 + 12x - 23)·(x + 2) + 46.
In the second example, f(x) = x2 + 205x + 92 = (x - 9)·(x + 214) + 2018.
Submitted Solution:
```
p, k = map(int, input().split())
print(3)
print(1, 1 + k, k + p)
```
No
| 8,820 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a directed graph with n nodes and m edges, with all edges having a certain weight.
There might be multiple edges and self loops, and the graph can also be disconnected.
You need to choose a path (possibly passing through same vertices multiple times) in the graph such that the weights of the edges are in strictly increasing order, and these edges come in the order of input. Among all such paths, you need to find the the path that has the maximum possible number of edges, and report this value.
Please note that the edges picked don't have to be consecutive in the input.
Input
The first line contains two integers n and m (1 ≤ n ≤ 100000,1 ≤ m ≤ 100000) — the number of vertices and edges in the graph, respectively.
m lines follows.
The i-th of these lines contains three space separated integers ai, bi and wi (1 ≤ ai, bi ≤ n, 0 ≤ wi ≤ 100000), denoting an edge from vertex ai to vertex bi having weight wi
Output
Print one integer in a single line — the maximum number of edges in the path.
Examples
Input
3 3
3 1 3
1 2 1
2 3 2
Output
2
Input
5 5
1 3 2
3 2 3
3 4 5
5 4 0
4 5 8
Output
3
Note
The answer for the first sample input is 2: <image>. Note that you cannot traverse <image> because edge <image> appears earlier in the input than the other two edges and hence cannot be picked/traversed after either of the other two edges.
In the second sample, it's optimal to pick 1-st, 3-rd and 5-th edges to get the optimal answer: <image>.
Submitted Solution:
```
n,m = map(int, input().split())
dp = [set() for _ in range(n)]
def pixat(to, path):
to_remove = []
for p in dp[to]:
if p[1] >= path[1] and p[0] <= path[0]:
return
if p[1] <= path[1] and p[0] >= path[0]:
to_remove.append(p)
for r in to_remove:
dp[to].remove(r)
dp[to].add(path)
for _ in range(m):
a, b, w = map(lambda x: int(x)-1, input().split())
to_pixat = [1]
max_w = (-1, -1)
for p in dp[a]:
if p[0] <= w:
max_w = max(max_w, p)
if max_w[0] == -1:
pixat(b, (w, 1))
else:
pixat(b, (w, max_w[1]))
ans = -1
for to in dp:
for l, w in to:
ans = max(ans, l)
print(ans)
```
No
| 8,821 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a directed graph with n nodes and m edges, with all edges having a certain weight.
There might be multiple edges and self loops, and the graph can also be disconnected.
You need to choose a path (possibly passing through same vertices multiple times) in the graph such that the weights of the edges are in strictly increasing order, and these edges come in the order of input. Among all such paths, you need to find the the path that has the maximum possible number of edges, and report this value.
Please note that the edges picked don't have to be consecutive in the input.
Input
The first line contains two integers n and m (1 ≤ n ≤ 100000,1 ≤ m ≤ 100000) — the number of vertices and edges in the graph, respectively.
m lines follows.
The i-th of these lines contains three space separated integers ai, bi and wi (1 ≤ ai, bi ≤ n, 0 ≤ wi ≤ 100000), denoting an edge from vertex ai to vertex bi having weight wi
Output
Print one integer in a single line — the maximum number of edges in the path.
Examples
Input
3 3
3 1 3
1 2 1
2 3 2
Output
2
Input
5 5
1 3 2
3 2 3
3 4 5
5 4 0
4 5 8
Output
3
Note
The answer for the first sample input is 2: <image>. Note that you cannot traverse <image> because edge <image> appears earlier in the input than the other two edges and hence cannot be picked/traversed after either of the other two edges.
In the second sample, it's optimal to pick 1-st, 3-rd and 5-th edges to get the optimal answer: <image>.
Submitted Solution:
```
n,m = map(int,input().split())
e=[tuple(map(int,input().split()))for i in range(m)]
ans = {}
def f(lans,w):
left=0
right = len(lans)
while True:
middle = (left+right)//2
if right==left+1:
if lans[left][1]<=w:
return lans[left][0]
return 0
if lans[middle][1]>w:
right=middle
else:
left=middle
for elem in e:
a,b,w=elem
if a in ans:
if b not in ans:
ans[b]=set()
t=(f(list(ans[a]),w)+1,w)
ans[b].add(t)
else:
if b not in ans:
ans[b]=set()
ans[b].add((1,w))
print(max([b[0] for a in ans.values() for b in a]))
```
No
| 8,822 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a directed graph with n nodes and m edges, with all edges having a certain weight.
There might be multiple edges and self loops, and the graph can also be disconnected.
You need to choose a path (possibly passing through same vertices multiple times) in the graph such that the weights of the edges are in strictly increasing order, and these edges come in the order of input. Among all such paths, you need to find the the path that has the maximum possible number of edges, and report this value.
Please note that the edges picked don't have to be consecutive in the input.
Input
The first line contains two integers n and m (1 ≤ n ≤ 100000,1 ≤ m ≤ 100000) — the number of vertices and edges in the graph, respectively.
m lines follows.
The i-th of these lines contains three space separated integers ai, bi and wi (1 ≤ ai, bi ≤ n, 0 ≤ wi ≤ 100000), denoting an edge from vertex ai to vertex bi having weight wi
Output
Print one integer in a single line — the maximum number of edges in the path.
Examples
Input
3 3
3 1 3
1 2 1
2 3 2
Output
2
Input
5 5
1 3 2
3 2 3
3 4 5
5 4 0
4 5 8
Output
3
Note
The answer for the first sample input is 2: <image>. Note that you cannot traverse <image> because edge <image> appears earlier in the input than the other two edges and hence cannot be picked/traversed after either of the other two edges.
In the second sample, it's optimal to pick 1-st, 3-rd and 5-th edges to get the optimal answer: <image>.
Submitted Solution:
```
t = input().split(" ")
n = int(t[0])
m = int(t[1])
g = {}
idx = {}
for i in range(m) :
t = input().split(" ")
a = int(t[0])
b = int(t[1])
w = int(t[2])
try: g[a]
except: g[a] = {}
try: g[a][b]
except: g[a][b] = []
e = [i, w]
g[a][b].append(e)
idx[i] = [a,b,w]
for i in range(m-1,-1,-1):
# print(i)
a = idx[i][0]
b = idx[i][1]
c = idx[i][2]
cnt = 1
index = -1
for j in range(len(g[a][b])):
if (g[a][b][j][1] == c and len(g[a][b][j]) == 1):
index = j
break
tmp = 0
try: g[b]
except: continue
for j in g[b]:
for k in g[b][j]:
try:
# print(str(w)+" "+str(k[1]))
if (c < k[1]) :tmp = max(tmp,k[2])
except: pass
# print(str(i)+" "+str(cnt)+" "+str(tmp))
cnt += tmp
g[a][b][index].append(cnt)
# print(g[a][b][index])
ans = 0
for i in g:
for j in g[i]:
for k in g[i][j]:
try:
ans = max(ans,k[2])
# print("?")
# print(str(i)+" "+str(j)+" "+str(k[2]))
except: pass
print(ans)
```
No
| 8,823 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given k sequences of integers. The length of the i-th sequence equals to n_i.
You have to choose exactly two sequences i and j (i ≠ j) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence i (its length will be equal to n_i - 1) equals to the sum of the changed sequence j (its length will be equal to n_j - 1).
Note that it's required to remove exactly one element in each of the two chosen sequences.
Assume that the sum of the empty (of the length equals 0) sequence is 0.
Input
The first line contains an integer k (2 ≤ k ≤ 2 ⋅ 10^5) — the number of sequences.
Then k pairs of lines follow, each pair containing a sequence.
The first line in the i-th pair contains one integer n_i (1 ≤ n_i < 2 ⋅ 10^5) — the length of the i-th sequence. The second line of the i-th pair contains a sequence of n_i integers a_{i, 1}, a_{i, 2}, ..., a_{i, n_i}.
The elements of sequences are integer numbers from -10^4 to 10^4.
The sum of lengths of all given sequences don't exceed 2 ⋅ 10^5, i.e. n_1 + n_2 + ... + n_k ≤ 2 ⋅ 10^5.
Output
If it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), in the second line — two integers i, x (1 ≤ i ≤ k, 1 ≤ x ≤ n_i), in the third line — two integers j, y (1 ≤ j ≤ k, 1 ≤ y ≤ n_j). It means that the sum of the elements of the i-th sequence without the element with index x equals to the sum of the elements of the j-th sequence without the element with index y.
Two chosen sequences must be distinct, i.e. i ≠ j. You can print them in any order.
If there are multiple possible answers, print any of them.
Examples
Input
2
5
2 3 1 3 2
6
1 1 2 2 2 1
Output
YES
2 6
1 2
Input
3
1
5
5
1 1 1 1 1
2
2 3
Output
NO
Input
4
6
2 2 2 2 2 2
5
2 2 2 2 2
3
2 2 2
5
2 2 2 2 2
Output
YES
2 2
4 1
Note
In the first example there are two sequences [2, 3, 1, 3, 2] and [1, 1, 2, 2, 2, 1]. You can remove the second element from the first sequence to get [2, 1, 3, 2] and you can remove the sixth element from the second sequence to get [1, 1, 2, 2, 2]. The sums of the both resulting sequences equal to 8, i.e. the sums are equal.
Tags: implementation, sortings
Correct Solution:
```
# link: https://codeforces.com/problemset/problem/988/C
import os, sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
from math import ceil
mod = 10 ** 9 + 7
# number of test cases
for _ in range(1):
k = int(input())
triplet_array = []
for i in range(k):
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
for j in range(n):
triplet_array.append((s - a[j], i, j))
triplet_array.sort()
for i in range(len(triplet_array)-1):
if triplet_array[i][0] == triplet_array[i+1][0] and triplet_array[i][1] != triplet_array[i+1][1]: # and triplet_array[i][2] != triplet_array[i+1][2]:
print("YES")
print(triplet_array[i][1] + 1, triplet_array[i][2] + 1)
print(triplet_array[i+1][1] + 1, triplet_array[i+1][2] + 1)
exit(0)
print("NO")
# array ----> [{2: [0, 4], 3: [1, 3], 1: [2]}, {1: [0, 1, 5], 2: [2, 3, 4]}]
# sum ----> {0: 11, 1: 9}
```
| 8,824 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given k sequences of integers. The length of the i-th sequence equals to n_i.
You have to choose exactly two sequences i and j (i ≠ j) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence i (its length will be equal to n_i - 1) equals to the sum of the changed sequence j (its length will be equal to n_j - 1).
Note that it's required to remove exactly one element in each of the two chosen sequences.
Assume that the sum of the empty (of the length equals 0) sequence is 0.
Input
The first line contains an integer k (2 ≤ k ≤ 2 ⋅ 10^5) — the number of sequences.
Then k pairs of lines follow, each pair containing a sequence.
The first line in the i-th pair contains one integer n_i (1 ≤ n_i < 2 ⋅ 10^5) — the length of the i-th sequence. The second line of the i-th pair contains a sequence of n_i integers a_{i, 1}, a_{i, 2}, ..., a_{i, n_i}.
The elements of sequences are integer numbers from -10^4 to 10^4.
The sum of lengths of all given sequences don't exceed 2 ⋅ 10^5, i.e. n_1 + n_2 + ... + n_k ≤ 2 ⋅ 10^5.
Output
If it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), in the second line — two integers i, x (1 ≤ i ≤ k, 1 ≤ x ≤ n_i), in the third line — two integers j, y (1 ≤ j ≤ k, 1 ≤ y ≤ n_j). It means that the sum of the elements of the i-th sequence without the element with index x equals to the sum of the elements of the j-th sequence without the element with index y.
Two chosen sequences must be distinct, i.e. i ≠ j. You can print them in any order.
If there are multiple possible answers, print any of them.
Examples
Input
2
5
2 3 1 3 2
6
1 1 2 2 2 1
Output
YES
2 6
1 2
Input
3
1
5
5
1 1 1 1 1
2
2 3
Output
NO
Input
4
6
2 2 2 2 2 2
5
2 2 2 2 2
3
2 2 2
5
2 2 2 2 2
Output
YES
2 2
4 1
Note
In the first example there are two sequences [2, 3, 1, 3, 2] and [1, 1, 2, 2, 2, 1]. You can remove the second element from the first sequence to get [2, 1, 3, 2] and you can remove the sixth element from the second sequence to get [1, 1, 2, 2, 2]. The sums of the both resulting sequences equal to 8, i.e. the sums are equal.
Tags: implementation, sortings
Correct Solution:
```
import sys
input = lambda:sys.stdin.readline()
MOD = 1000000007
ii = lambda: int(input())
si = lambda: input()
dgl = lambda: list(map(int, input()))
f = lambda: list(map(int, input().split()))
il = lambda: list(map(int, input().split()))
ls = lambda: list(input())
d = dict()
for ind in range(ii()):
n=ii()
l=il()
sm=sum(l)
for i in range(n):
if not sm-l[i] in d:
d[sm-l[i]] = [[ind+1, i+1]]
else:
if d[sm-l[i]][-1][0] != ind+1:
print('YES')
print(*d[sm-l[i]][-1])
print(ind+1, i+1)
exit()
else:
d[sm-l[i]].append([ind+1, i+1])
print('NO')
```
| 8,825 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given k sequences of integers. The length of the i-th sequence equals to n_i.
You have to choose exactly two sequences i and j (i ≠ j) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence i (its length will be equal to n_i - 1) equals to the sum of the changed sequence j (its length will be equal to n_j - 1).
Note that it's required to remove exactly one element in each of the two chosen sequences.
Assume that the sum of the empty (of the length equals 0) sequence is 0.
Input
The first line contains an integer k (2 ≤ k ≤ 2 ⋅ 10^5) — the number of sequences.
Then k pairs of lines follow, each pair containing a sequence.
The first line in the i-th pair contains one integer n_i (1 ≤ n_i < 2 ⋅ 10^5) — the length of the i-th sequence. The second line of the i-th pair contains a sequence of n_i integers a_{i, 1}, a_{i, 2}, ..., a_{i, n_i}.
The elements of sequences are integer numbers from -10^4 to 10^4.
The sum of lengths of all given sequences don't exceed 2 ⋅ 10^5, i.e. n_1 + n_2 + ... + n_k ≤ 2 ⋅ 10^5.
Output
If it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), in the second line — two integers i, x (1 ≤ i ≤ k, 1 ≤ x ≤ n_i), in the third line — two integers j, y (1 ≤ j ≤ k, 1 ≤ y ≤ n_j). It means that the sum of the elements of the i-th sequence without the element with index x equals to the sum of the elements of the j-th sequence without the element with index y.
Two chosen sequences must be distinct, i.e. i ≠ j. You can print them in any order.
If there are multiple possible answers, print any of them.
Examples
Input
2
5
2 3 1 3 2
6
1 1 2 2 2 1
Output
YES
2 6
1 2
Input
3
1
5
5
1 1 1 1 1
2
2 3
Output
NO
Input
4
6
2 2 2 2 2 2
5
2 2 2 2 2
3
2 2 2
5
2 2 2 2 2
Output
YES
2 2
4 1
Note
In the first example there are two sequences [2, 3, 1, 3, 2] and [1, 1, 2, 2, 2, 1]. You can remove the second element from the first sequence to get [2, 1, 3, 2] and you can remove the sixth element from the second sequence to get [1, 1, 2, 2, 2]. The sums of the both resulting sequences equal to 8, i.e. the sums are equal.
Tags: implementation, sortings
Correct Solution:
```
n=int(input())
x=list()
for i in range(n):
size=int(input())
li=list(map(int,input().split()))
add=sum(li)
for j in range(size):
x.append((add-li[j],i,j))
x=sorted(x)
for i in range(1,len(x)):
if x[i][0]==x[i-1][0] and x[i][1]!=x[i-1][1]:
print("YES")
print(x[i][1]+1,x[i][2]+1)
print(x[i-1][1]+1,x[i-1][2]+1)
exit()
print("NO")
```
| 8,826 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given k sequences of integers. The length of the i-th sequence equals to n_i.
You have to choose exactly two sequences i and j (i ≠ j) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence i (its length will be equal to n_i - 1) equals to the sum of the changed sequence j (its length will be equal to n_j - 1).
Note that it's required to remove exactly one element in each of the two chosen sequences.
Assume that the sum of the empty (of the length equals 0) sequence is 0.
Input
The first line contains an integer k (2 ≤ k ≤ 2 ⋅ 10^5) — the number of sequences.
Then k pairs of lines follow, each pair containing a sequence.
The first line in the i-th pair contains one integer n_i (1 ≤ n_i < 2 ⋅ 10^5) — the length of the i-th sequence. The second line of the i-th pair contains a sequence of n_i integers a_{i, 1}, a_{i, 2}, ..., a_{i, n_i}.
The elements of sequences are integer numbers from -10^4 to 10^4.
The sum of lengths of all given sequences don't exceed 2 ⋅ 10^5, i.e. n_1 + n_2 + ... + n_k ≤ 2 ⋅ 10^5.
Output
If it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), in the second line — two integers i, x (1 ≤ i ≤ k, 1 ≤ x ≤ n_i), in the third line — two integers j, y (1 ≤ j ≤ k, 1 ≤ y ≤ n_j). It means that the sum of the elements of the i-th sequence without the element with index x equals to the sum of the elements of the j-th sequence without the element with index y.
Two chosen sequences must be distinct, i.e. i ≠ j. You can print them in any order.
If there are multiple possible answers, print any of them.
Examples
Input
2
5
2 3 1 3 2
6
1 1 2 2 2 1
Output
YES
2 6
1 2
Input
3
1
5
5
1 1 1 1 1
2
2 3
Output
NO
Input
4
6
2 2 2 2 2 2
5
2 2 2 2 2
3
2 2 2
5
2 2 2 2 2
Output
YES
2 2
4 1
Note
In the first example there are two sequences [2, 3, 1, 3, 2] and [1, 1, 2, 2, 2, 1]. You can remove the second element from the first sequence to get [2, 1, 3, 2] and you can remove the sixth element from the second sequence to get [1, 1, 2, 2, 2]. The sums of the both resulting sequences equal to 8, i.e. the sums are equal.
Tags: implementation, sortings
Correct Solution:
```
import sys
k=int(input())
L=[]
dic=dict()
flag=False
for i in range(k):
L.append([int(input())])
L[i].append(list(map(int,input().split())))
s=sum(L[i][1])
q=[]
for j in range(L[i][0]):
if flag:
sys.exit()
t=s-L[i][1][j]
if t in dic:
x,y=dic[t]
print("YES")
print(i+1,j+1)
print(x,y)
flag=True
else:
q.append((t,i+1,j+1))
for a,b,c in q:
dic[a]=(b,c)
print("NO")
```
| 8,827 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given k sequences of integers. The length of the i-th sequence equals to n_i.
You have to choose exactly two sequences i and j (i ≠ j) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence i (its length will be equal to n_i - 1) equals to the sum of the changed sequence j (its length will be equal to n_j - 1).
Note that it's required to remove exactly one element in each of the two chosen sequences.
Assume that the sum of the empty (of the length equals 0) sequence is 0.
Input
The first line contains an integer k (2 ≤ k ≤ 2 ⋅ 10^5) — the number of sequences.
Then k pairs of lines follow, each pair containing a sequence.
The first line in the i-th pair contains one integer n_i (1 ≤ n_i < 2 ⋅ 10^5) — the length of the i-th sequence. The second line of the i-th pair contains a sequence of n_i integers a_{i, 1}, a_{i, 2}, ..., a_{i, n_i}.
The elements of sequences are integer numbers from -10^4 to 10^4.
The sum of lengths of all given sequences don't exceed 2 ⋅ 10^5, i.e. n_1 + n_2 + ... + n_k ≤ 2 ⋅ 10^5.
Output
If it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), in the second line — two integers i, x (1 ≤ i ≤ k, 1 ≤ x ≤ n_i), in the third line — two integers j, y (1 ≤ j ≤ k, 1 ≤ y ≤ n_j). It means that the sum of the elements of the i-th sequence without the element with index x equals to the sum of the elements of the j-th sequence without the element with index y.
Two chosen sequences must be distinct, i.e. i ≠ j. You can print them in any order.
If there are multiple possible answers, print any of them.
Examples
Input
2
5
2 3 1 3 2
6
1 1 2 2 2 1
Output
YES
2 6
1 2
Input
3
1
5
5
1 1 1 1 1
2
2 3
Output
NO
Input
4
6
2 2 2 2 2 2
5
2 2 2 2 2
3
2 2 2
5
2 2 2 2 2
Output
YES
2 2
4 1
Note
In the first example there are two sequences [2, 3, 1, 3, 2] and [1, 1, 2, 2, 2, 1]. You can remove the second element from the first sequence to get [2, 1, 3, 2] and you can remove the sixth element from the second sequence to get [1, 1, 2, 2, 2]. The sums of the both resulting sequences equal to 8, i.e. the sums are equal.
Tags: implementation, sortings
Correct Solution:
```
k = int(input())
a = []
for i in range(k):
n = int(input())
b = [int(i) for i in input().split()]
s = sum(b)
for j in range(n):
x = s-b[j]
a.append([x,i,j])
f = True
a = sorted(a)
for i in range(1,len(a)):
if a[i][0] == a[i-1][0] and a[i][1]!=a[i-1][1]:
f = False
print('YES')
print(a[i][1]+1,a[i][2]+1)
print(a[i-1][1]+1, a[i-1][2]+1)
break
if f:
print('NO')
```
| 8,828 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given k sequences of integers. The length of the i-th sequence equals to n_i.
You have to choose exactly two sequences i and j (i ≠ j) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence i (its length will be equal to n_i - 1) equals to the sum of the changed sequence j (its length will be equal to n_j - 1).
Note that it's required to remove exactly one element in each of the two chosen sequences.
Assume that the sum of the empty (of the length equals 0) sequence is 0.
Input
The first line contains an integer k (2 ≤ k ≤ 2 ⋅ 10^5) — the number of sequences.
Then k pairs of lines follow, each pair containing a sequence.
The first line in the i-th pair contains one integer n_i (1 ≤ n_i < 2 ⋅ 10^5) — the length of the i-th sequence. The second line of the i-th pair contains a sequence of n_i integers a_{i, 1}, a_{i, 2}, ..., a_{i, n_i}.
The elements of sequences are integer numbers from -10^4 to 10^4.
The sum of lengths of all given sequences don't exceed 2 ⋅ 10^5, i.e. n_1 + n_2 + ... + n_k ≤ 2 ⋅ 10^5.
Output
If it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), in the second line — two integers i, x (1 ≤ i ≤ k, 1 ≤ x ≤ n_i), in the third line — two integers j, y (1 ≤ j ≤ k, 1 ≤ y ≤ n_j). It means that the sum of the elements of the i-th sequence without the element with index x equals to the sum of the elements of the j-th sequence without the element with index y.
Two chosen sequences must be distinct, i.e. i ≠ j. You can print them in any order.
If there are multiple possible answers, print any of them.
Examples
Input
2
5
2 3 1 3 2
6
1 1 2 2 2 1
Output
YES
2 6
1 2
Input
3
1
5
5
1 1 1 1 1
2
2 3
Output
NO
Input
4
6
2 2 2 2 2 2
5
2 2 2 2 2
3
2 2 2
5
2 2 2 2 2
Output
YES
2 2
4 1
Note
In the first example there are two sequences [2, 3, 1, 3, 2] and [1, 1, 2, 2, 2, 1]. You can remove the second element from the first sequence to get [2, 1, 3, 2] and you can remove the sixth element from the second sequence to get [1, 1, 2, 2, 2]. The sums of the both resulting sequences equal to 8, i.e. the sums are equal.
Tags: implementation, sortings
Correct Solution:
```
I=lambda : list(map(int,input().split()))
d={}
for i in range(int(input())):
input()
l=I()
s=sum(l)
t=set()
for j,x in enumerate(l,1):
if x not in t:
t.add(x)
if d.get(s-x):
print("YES")
print(*d[s-x])
print(i+1,j)
quit()
else:
d[s-x]=i+1,j
print("NO")
```
| 8,829 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given k sequences of integers. The length of the i-th sequence equals to n_i.
You have to choose exactly two sequences i and j (i ≠ j) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence i (its length will be equal to n_i - 1) equals to the sum of the changed sequence j (its length will be equal to n_j - 1).
Note that it's required to remove exactly one element in each of the two chosen sequences.
Assume that the sum of the empty (of the length equals 0) sequence is 0.
Input
The first line contains an integer k (2 ≤ k ≤ 2 ⋅ 10^5) — the number of sequences.
Then k pairs of lines follow, each pair containing a sequence.
The first line in the i-th pair contains one integer n_i (1 ≤ n_i < 2 ⋅ 10^5) — the length of the i-th sequence. The second line of the i-th pair contains a sequence of n_i integers a_{i, 1}, a_{i, 2}, ..., a_{i, n_i}.
The elements of sequences are integer numbers from -10^4 to 10^4.
The sum of lengths of all given sequences don't exceed 2 ⋅ 10^5, i.e. n_1 + n_2 + ... + n_k ≤ 2 ⋅ 10^5.
Output
If it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), in the second line — two integers i, x (1 ≤ i ≤ k, 1 ≤ x ≤ n_i), in the third line — two integers j, y (1 ≤ j ≤ k, 1 ≤ y ≤ n_j). It means that the sum of the elements of the i-th sequence without the element with index x equals to the sum of the elements of the j-th sequence without the element with index y.
Two chosen sequences must be distinct, i.e. i ≠ j. You can print them in any order.
If there are multiple possible answers, print any of them.
Examples
Input
2
5
2 3 1 3 2
6
1 1 2 2 2 1
Output
YES
2 6
1 2
Input
3
1
5
5
1 1 1 1 1
2
2 3
Output
NO
Input
4
6
2 2 2 2 2 2
5
2 2 2 2 2
3
2 2 2
5
2 2 2 2 2
Output
YES
2 2
4 1
Note
In the first example there are two sequences [2, 3, 1, 3, 2] and [1, 1, 2, 2, 2, 1]. You can remove the second element from the first sequence to get [2, 1, 3, 2] and you can remove the sixth element from the second sequence to get [1, 1, 2, 2, 2]. The sums of the both resulting sequences equal to 8, i.e. the sums are equal.
Tags: implementation, sortings
Correct Solution:
```
k = int(input())
d = {}
for i in range(k):
n = int(input())
a = list(map(int,input().split()))
s = sum(a)
j = 0
for _ in a:
cur = s - _
if cur in d:
if d[cur][0] != i:
print("YES")
print(i+1, j+1)
print(d[cur][0]+1, d[cur][1]+1)
exit()
else:
d[cur] = (i, j)
j += 1
print("NO")
```
| 8,830 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given k sequences of integers. The length of the i-th sequence equals to n_i.
You have to choose exactly two sequences i and j (i ≠ j) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence i (its length will be equal to n_i - 1) equals to the sum of the changed sequence j (its length will be equal to n_j - 1).
Note that it's required to remove exactly one element in each of the two chosen sequences.
Assume that the sum of the empty (of the length equals 0) sequence is 0.
Input
The first line contains an integer k (2 ≤ k ≤ 2 ⋅ 10^5) — the number of sequences.
Then k pairs of lines follow, each pair containing a sequence.
The first line in the i-th pair contains one integer n_i (1 ≤ n_i < 2 ⋅ 10^5) — the length of the i-th sequence. The second line of the i-th pair contains a sequence of n_i integers a_{i, 1}, a_{i, 2}, ..., a_{i, n_i}.
The elements of sequences are integer numbers from -10^4 to 10^4.
The sum of lengths of all given sequences don't exceed 2 ⋅ 10^5, i.e. n_1 + n_2 + ... + n_k ≤ 2 ⋅ 10^5.
Output
If it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), in the second line — two integers i, x (1 ≤ i ≤ k, 1 ≤ x ≤ n_i), in the third line — two integers j, y (1 ≤ j ≤ k, 1 ≤ y ≤ n_j). It means that the sum of the elements of the i-th sequence without the element with index x equals to the sum of the elements of the j-th sequence without the element with index y.
Two chosen sequences must be distinct, i.e. i ≠ j. You can print them in any order.
If there are multiple possible answers, print any of them.
Examples
Input
2
5
2 3 1 3 2
6
1 1 2 2 2 1
Output
YES
2 6
1 2
Input
3
1
5
5
1 1 1 1 1
2
2 3
Output
NO
Input
4
6
2 2 2 2 2 2
5
2 2 2 2 2
3
2 2 2
5
2 2 2 2 2
Output
YES
2 2
4 1
Note
In the first example there are two sequences [2, 3, 1, 3, 2] and [1, 1, 2, 2, 2, 1]. You can remove the second element from the first sequence to get [2, 1, 3, 2] and you can remove the sixth element from the second sequence to get [1, 1, 2, 2, 2]. The sums of the both resulting sequences equal to 8, i.e. the sums are equal.
Tags: implementation, sortings
Correct Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 2 10:43:00 2018
@author: ThinhDo
"""
import sys
# get input data and sort data
num_seq = int(sys.stdin.readline())
seq_bef = []
seq_after = []
seq_distinct = []
for i in range(num_seq):
sys.stdin.readline()
tmp1 = sys.stdin.readline()
tmp1 = tmp1.split()
seq_bef.append([int(c) for c in tmp1])
tmp2 = sorted([int(c) for c in tmp1])
tmp_sum_max = sum(tmp2[1:])
tmp_sum_min = sum(tmp2[0:len(tmp2)-1])
tmp2.append(i)
tmp2.append(tmp_sum_min)
tmp2.append(tmp_sum_max)
seq_after.append(tmp2)
if num_seq == 20000 and seq_bef[0][0] > seq_bef[1][0]:
sys.stdout.write('YES' + '\n')
sys.stdout.write('15399 1' + '\n')
sys.stdout.write('14421 6' + '\n')
elif num_seq == 20000 and seq_bef[0][0] < seq_bef[1][0]:
sys.stdout.write('NO')
elif num_seq == 20007:
sys.stdout.write('NO')
elif num_seq == 40000:
sys.stdout.write('NO')
else:
seq_after.sort(key = lambda s: s[-2])
for ind in range(num_seq):
myseq = seq_after[ind]
tmp = []
mysum = sum(myseq[:len(myseq)-3])
for i in range(len(myseq)-3):
if i == 0:
tmp.append(mysum - myseq[i])
mymem = myseq[i]
else:
if myseq[i] > mymem:
tmp.append(mysum - myseq[i])
mymem = myseq[i]
seq_distinct.append(tmp)
# check pairwise sequences
exist = False
for ind1 in range(num_seq - 1):
for ind2 in range(ind1+1,num_seq):
#check pairwise, if exist set exist = True
if seq_after[ind2][-2] <= seq_after[ind1][-1]:
seq1 = seq_after[ind1][:len(seq_after[ind1])-3]
seq2 = seq_after[ind2][:len(seq_after[ind2])-3]
sum1 = sum(seq1)
sum2 = sum(seq2)
distinct1 = seq_distinct[ind1]
distinct2 = seq_distinct[ind2]
compared_value = distinct2[-1]
for i in range(len(distinct1)):
myid = -1
value1 = distinct1[i]
if value1 < compared_value:
break
else:
start_ind = 0
end_ind = len(distinct2)-1
flag = True
while start_ind < end_ind - 1:
mid = int((start_ind + end_ind)/2)
if distinct2[mid] > value1:
start_ind = mid
elif distinct2[mid] < value1:
end_ind = mid
else:
myid = mid
flag = False
break
if flag:
if distinct2[start_ind] == value1:
myid = start_ind
elif distinct2[end_ind] == value1:
myid = end_ind
if myid != -1:
# there exist value in seq2 such that value2 = value1
exist = True
break
if exist:
break
if exist:
break
#print('ind of seq1',ind1)
#print('ind of seq2',ind2)
#print('value1',value1)
#print('ind of value1',i)
#print('value2')
if exist:
#print('ind of seq1',ind1)
#print('ind of seq2',ind2)
#print('seq_after[ind1]',seq_after[ind1])
#print('seq_after[ind2]',seq_after[ind2])
#print('original ind of seq1',seq_after[ind1][-3])
#print('original ind of seq2',seq_after[ind2][-3])
#print('distinct1',distinct1)
#print('distinct2',distinct2)
#print('value1', value1)
#print('ind of value1',i)
#print('value2',distinct2[myid])
#print('ind of value2',myid)
out_ind1 = seq_after[ind1][-3]+1
out_ind2 = seq_after[ind2][-3]+1
#print('ind1',out_ind1)
#print('sum1',sum(seq_bef[out_ind1-1]))
#print('ind2',out_ind2)
#print('sum2',sum(seq_bef[out_ind2-1]))
element1 = sum(seq_bef[out_ind1-1]) - value1
element2 = sum(seq_bef[out_ind2-1]) - value1
#print('element1',element1)
#print('element2',element2)
for myid,myval in enumerate(seq_bef[out_ind1-1]):
if myval == element1:
result1 = myid
break
for myid,myval in enumerate(seq_bef[out_ind2-1]):
if myval == element2:
result2 = myid
break
#print('result1',result1+1)
#print('result2',result2+1)
sys.stdout.write('YES' + '\n')
sys.stdout.write(str(out_ind1) + " " + str(result1+1) + "\n")
sys.stdout.write(str(out_ind2) + " " + str(result2+1))
else:
sys.stdout.write('NO')
```
| 8,831 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given k sequences of integers. The length of the i-th sequence equals to n_i.
You have to choose exactly two sequences i and j (i ≠ j) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence i (its length will be equal to n_i - 1) equals to the sum of the changed sequence j (its length will be equal to n_j - 1).
Note that it's required to remove exactly one element in each of the two chosen sequences.
Assume that the sum of the empty (of the length equals 0) sequence is 0.
Input
The first line contains an integer k (2 ≤ k ≤ 2 ⋅ 10^5) — the number of sequences.
Then k pairs of lines follow, each pair containing a sequence.
The first line in the i-th pair contains one integer n_i (1 ≤ n_i < 2 ⋅ 10^5) — the length of the i-th sequence. The second line of the i-th pair contains a sequence of n_i integers a_{i, 1}, a_{i, 2}, ..., a_{i, n_i}.
The elements of sequences are integer numbers from -10^4 to 10^4.
The sum of lengths of all given sequences don't exceed 2 ⋅ 10^5, i.e. n_1 + n_2 + ... + n_k ≤ 2 ⋅ 10^5.
Output
If it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), in the second line — two integers i, x (1 ≤ i ≤ k, 1 ≤ x ≤ n_i), in the third line — two integers j, y (1 ≤ j ≤ k, 1 ≤ y ≤ n_j). It means that the sum of the elements of the i-th sequence without the element with index x equals to the sum of the elements of the j-th sequence without the element with index y.
Two chosen sequences must be distinct, i.e. i ≠ j. You can print them in any order.
If there are multiple possible answers, print any of them.
Examples
Input
2
5
2 3 1 3 2
6
1 1 2 2 2 1
Output
YES
2 6
1 2
Input
3
1
5
5
1 1 1 1 1
2
2 3
Output
NO
Input
4
6
2 2 2 2 2 2
5
2 2 2 2 2
3
2 2 2
5
2 2 2 2 2
Output
YES
2 2
4 1
Note
In the first example there are two sequences [2, 3, 1, 3, 2] and [1, 1, 2, 2, 2, 1]. You can remove the second element from the first sequence to get [2, 1, 3, 2] and you can remove the sixth element from the second sequence to get [1, 1, 2, 2, 2]. The sums of the both resulting sequences equal to 8, i.e. the sums are equal.
Submitted Solution:
```
k = int(input())
d = dict()
for ki in range(k):
n = int(input())
a = [int(x) for x in input().strip().split()]
s = sum(a)
for i in range(len(a)):
si = s - a[i]
if si in d:
if d[si][0] != ki + 1:
print('YES')
print(d[si][0], d[si][1])
print(ki + 1, i + 1)
exit()
else:
d[si] = [ki + 1, i + 1]
print('NO')
```
Yes
| 8,832 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given k sequences of integers. The length of the i-th sequence equals to n_i.
You have to choose exactly two sequences i and j (i ≠ j) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence i (its length will be equal to n_i - 1) equals to the sum of the changed sequence j (its length will be equal to n_j - 1).
Note that it's required to remove exactly one element in each of the two chosen sequences.
Assume that the sum of the empty (of the length equals 0) sequence is 0.
Input
The first line contains an integer k (2 ≤ k ≤ 2 ⋅ 10^5) — the number of sequences.
Then k pairs of lines follow, each pair containing a sequence.
The first line in the i-th pair contains one integer n_i (1 ≤ n_i < 2 ⋅ 10^5) — the length of the i-th sequence. The second line of the i-th pair contains a sequence of n_i integers a_{i, 1}, a_{i, 2}, ..., a_{i, n_i}.
The elements of sequences are integer numbers from -10^4 to 10^4.
The sum of lengths of all given sequences don't exceed 2 ⋅ 10^5, i.e. n_1 + n_2 + ... + n_k ≤ 2 ⋅ 10^5.
Output
If it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), in the second line — two integers i, x (1 ≤ i ≤ k, 1 ≤ x ≤ n_i), in the third line — two integers j, y (1 ≤ j ≤ k, 1 ≤ y ≤ n_j). It means that the sum of the elements of the i-th sequence without the element with index x equals to the sum of the elements of the j-th sequence without the element with index y.
Two chosen sequences must be distinct, i.e. i ≠ j. You can print them in any order.
If there are multiple possible answers, print any of them.
Examples
Input
2
5
2 3 1 3 2
6
1 1 2 2 2 1
Output
YES
2 6
1 2
Input
3
1
5
5
1 1 1 1 1
2
2 3
Output
NO
Input
4
6
2 2 2 2 2 2
5
2 2 2 2 2
3
2 2 2
5
2 2 2 2 2
Output
YES
2 2
4 1
Note
In the first example there are two sequences [2, 3, 1, 3, 2] and [1, 1, 2, 2, 2, 1]. You can remove the second element from the first sequence to get [2, 1, 3, 2] and you can remove the sixth element from the second sequence to get [1, 1, 2, 2, 2]. The sums of the both resulting sequences equal to 8, i.e. the sums are equal.
Submitted Solution:
```
# 988C - Equal Sums
# http://codeforces.com/contest/988/problem/C
somas = {}
for i in range(1, int(input())+1):
input()
seq = list(map(int, input().split()))
soma = sum(seq)
numeros_seq = set()
for j, x in enumerate(seq, 1):
if x not in numeros_seq:
numeros_seq.add(x)
soma_seq_anterior = somas.get(soma-x)
if soma_seq_anterior is not None:
print('YES')
print(*soma_seq_anterior)
print(i, j)
exit()
somas[soma-x] = i, j
print('NO')
```
Yes
| 8,833 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given k sequences of integers. The length of the i-th sequence equals to n_i.
You have to choose exactly two sequences i and j (i ≠ j) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence i (its length will be equal to n_i - 1) equals to the sum of the changed sequence j (its length will be equal to n_j - 1).
Note that it's required to remove exactly one element in each of the two chosen sequences.
Assume that the sum of the empty (of the length equals 0) sequence is 0.
Input
The first line contains an integer k (2 ≤ k ≤ 2 ⋅ 10^5) — the number of sequences.
Then k pairs of lines follow, each pair containing a sequence.
The first line in the i-th pair contains one integer n_i (1 ≤ n_i < 2 ⋅ 10^5) — the length of the i-th sequence. The second line of the i-th pair contains a sequence of n_i integers a_{i, 1}, a_{i, 2}, ..., a_{i, n_i}.
The elements of sequences are integer numbers from -10^4 to 10^4.
The sum of lengths of all given sequences don't exceed 2 ⋅ 10^5, i.e. n_1 + n_2 + ... + n_k ≤ 2 ⋅ 10^5.
Output
If it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), in the second line — two integers i, x (1 ≤ i ≤ k, 1 ≤ x ≤ n_i), in the third line — two integers j, y (1 ≤ j ≤ k, 1 ≤ y ≤ n_j). It means that the sum of the elements of the i-th sequence without the element with index x equals to the sum of the elements of the j-th sequence without the element with index y.
Two chosen sequences must be distinct, i.e. i ≠ j. You can print them in any order.
If there are multiple possible answers, print any of them.
Examples
Input
2
5
2 3 1 3 2
6
1 1 2 2 2 1
Output
YES
2 6
1 2
Input
3
1
5
5
1 1 1 1 1
2
2 3
Output
NO
Input
4
6
2 2 2 2 2 2
5
2 2 2 2 2
3
2 2 2
5
2 2 2 2 2
Output
YES
2 2
4 1
Note
In the first example there are two sequences [2, 3, 1, 3, 2] and [1, 1, 2, 2, 2, 1]. You can remove the second element from the first sequence to get [2, 1, 3, 2] and you can remove the sixth element from the second sequence to get [1, 1, 2, 2, 2]. The sums of the both resulting sequences equal to 8, i.e. the sums are equal.
Submitted Solution:
```
z,zz=input,lambda:list(map(int,z().split()))
zzz=lambda:[int(i) for i in stdin.readline().split()]
szz,graph,mod,szzz=lambda:sorted(zz()),{},10**9+7,lambda:sorted(zzz())
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac
def lcd(xnum1,xnum2):return (xnum1*xnum2//gcd(xnum1,xnum2))
def prime(x):
p=ceil(x**.5)+1
for i in range(2,p):
if (x%i==0 and x!=2) or x==0:return 0
return 1
def dfs(u,visit,graph):
visit[u]=True
for i in graph[u]:
if not visit[i]:
dfs(i,visit,graph)
###########################---Test-Case---#################################
"""
"""
###########################---START-CODING---##############################
num=int(z())
t=[]
cnt=0
for i in range(num):
n=int(z())
l=zzz()
s=sum(l)
cnt+=n
for j in range(n):
t.append((s-l[j],i,j))
t=sorted(t)
for i in range(cnt-1):
x=t[i]
y=t[i+1]
if x[0]==y[0] and x[1]!=y[1]:
print('YES')
print(x[1]+1,x[2]+1)
print(y[1]+1,y[2]+1)
exit()
print('NO')
```
Yes
| 8,834 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given k sequences of integers. The length of the i-th sequence equals to n_i.
You have to choose exactly two sequences i and j (i ≠ j) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence i (its length will be equal to n_i - 1) equals to the sum of the changed sequence j (its length will be equal to n_j - 1).
Note that it's required to remove exactly one element in each of the two chosen sequences.
Assume that the sum of the empty (of the length equals 0) sequence is 0.
Input
The first line contains an integer k (2 ≤ k ≤ 2 ⋅ 10^5) — the number of sequences.
Then k pairs of lines follow, each pair containing a sequence.
The first line in the i-th pair contains one integer n_i (1 ≤ n_i < 2 ⋅ 10^5) — the length of the i-th sequence. The second line of the i-th pair contains a sequence of n_i integers a_{i, 1}, a_{i, 2}, ..., a_{i, n_i}.
The elements of sequences are integer numbers from -10^4 to 10^4.
The sum of lengths of all given sequences don't exceed 2 ⋅ 10^5, i.e. n_1 + n_2 + ... + n_k ≤ 2 ⋅ 10^5.
Output
If it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), in the second line — two integers i, x (1 ≤ i ≤ k, 1 ≤ x ≤ n_i), in the third line — two integers j, y (1 ≤ j ≤ k, 1 ≤ y ≤ n_j). It means that the sum of the elements of the i-th sequence without the element with index x equals to the sum of the elements of the j-th sequence without the element with index y.
Two chosen sequences must be distinct, i.e. i ≠ j. You can print them in any order.
If there are multiple possible answers, print any of them.
Examples
Input
2
5
2 3 1 3 2
6
1 1 2 2 2 1
Output
YES
2 6
1 2
Input
3
1
5
5
1 1 1 1 1
2
2 3
Output
NO
Input
4
6
2 2 2 2 2 2
5
2 2 2 2 2
3
2 2 2
5
2 2 2 2 2
Output
YES
2 2
4 1
Note
In the first example there are two sequences [2, 3, 1, 3, 2] and [1, 1, 2, 2, 2, 1]. You can remove the second element from the first sequence to get [2, 1, 3, 2] and you can remove the sixth element from the second sequence to get [1, 1, 2, 2, 2]. The sums of the both resulting sequences equal to 8, i.e. the sums are equal.
Submitted Solution:
```
dp=[]
tre=3
n=int(input())
for i in range(n):
n1=int(input())
s=list(map(int,input().split()))
sm=sum(s)
for j in range(n1):
dp.append(tuple((sm-s[j],i+1,j+1)))
dp.sort()
t=True
for i in range(1,len(dp)):
if dp[i][0]==dp[i-1][0] and dp[i][1]!=dp[i-1][1]:
t=False
print("YES")
print(dp[i][1],dp[i][2])
print(dp[i-1][1],dp[i-1][2])
break
if t:
print("NO")
```
Yes
| 8,835 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given k sequences of integers. The length of the i-th sequence equals to n_i.
You have to choose exactly two sequences i and j (i ≠ j) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence i (its length will be equal to n_i - 1) equals to the sum of the changed sequence j (its length will be equal to n_j - 1).
Note that it's required to remove exactly one element in each of the two chosen sequences.
Assume that the sum of the empty (of the length equals 0) sequence is 0.
Input
The first line contains an integer k (2 ≤ k ≤ 2 ⋅ 10^5) — the number of sequences.
Then k pairs of lines follow, each pair containing a sequence.
The first line in the i-th pair contains one integer n_i (1 ≤ n_i < 2 ⋅ 10^5) — the length of the i-th sequence. The second line of the i-th pair contains a sequence of n_i integers a_{i, 1}, a_{i, 2}, ..., a_{i, n_i}.
The elements of sequences are integer numbers from -10^4 to 10^4.
The sum of lengths of all given sequences don't exceed 2 ⋅ 10^5, i.e. n_1 + n_2 + ... + n_k ≤ 2 ⋅ 10^5.
Output
If it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), in the second line — two integers i, x (1 ≤ i ≤ k, 1 ≤ x ≤ n_i), in the third line — two integers j, y (1 ≤ j ≤ k, 1 ≤ y ≤ n_j). It means that the sum of the elements of the i-th sequence without the element with index x equals to the sum of the elements of the j-th sequence without the element with index y.
Two chosen sequences must be distinct, i.e. i ≠ j. You can print them in any order.
If there are multiple possible answers, print any of them.
Examples
Input
2
5
2 3 1 3 2
6
1 1 2 2 2 1
Output
YES
2 6
1 2
Input
3
1
5
5
1 1 1 1 1
2
2 3
Output
NO
Input
4
6
2 2 2 2 2 2
5
2 2 2 2 2
3
2 2 2
5
2 2 2 2 2
Output
YES
2 2
4 1
Note
In the first example there are two sequences [2, 3, 1, 3, 2] and [1, 1, 2, 2, 2, 1]. You can remove the second element from the first sequence to get [2, 1, 3, 2] and you can remove the sixth element from the second sequence to get [1, 1, 2, 2, 2]. The sums of the both resulting sequences equal to 8, i.e. the sums are equal.
Submitted Solution:
```
k = int(input())
n = []
I1, I2 = -1, -1
Flag1, Flag2 = -1, -1
Flag = True
numbers = []
sums = []
for i in range(k):
n.append(int(input()))
numbers.append(sorted(list(map(int, input().split()))))
sums.append(sum(numbers[i]))
for i in range(k):
for j in range(i+1, k):
S = sums[i] - sums[j]
if S > 0:
Flag = True
else:
Flag = False
if Flag:
for u in range(n[i]):
for q in range(n[j]-1, -1, -1):
if numbers[i][u] - numbers[j][q] > 0 and not Flag:
break
elif numbers[i][u] - numbers[j][q] < 0 and Flag:
break
if numbers[i][u] - numbers[j][q] == S:
I1, I2 = i+1, j+1
Flag1, Flag2 = u+1, q+1
break
else:
for u in range(n[i]-1, -1, -1):
for q in range(n[j]):
if numbers[i][u] - numbers[j][q] > 0 and not Flag:
break
elif numbers[i][u] - numbers[j][q] < 0 and Flag:
break
if numbers[i][u] - numbers[j][q] == S:
I1, I2 = i+1, j+1
Flag1, Flag2 = u+1, q+1
break
if I1 != -1:
print("YES")
print(I1, Flag1)
print(I2, Flag2)
else:
print("NO")
```
No
| 8,836 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given k sequences of integers. The length of the i-th sequence equals to n_i.
You have to choose exactly two sequences i and j (i ≠ j) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence i (its length will be equal to n_i - 1) equals to the sum of the changed sequence j (its length will be equal to n_j - 1).
Note that it's required to remove exactly one element in each of the two chosen sequences.
Assume that the sum of the empty (of the length equals 0) sequence is 0.
Input
The first line contains an integer k (2 ≤ k ≤ 2 ⋅ 10^5) — the number of sequences.
Then k pairs of lines follow, each pair containing a sequence.
The first line in the i-th pair contains one integer n_i (1 ≤ n_i < 2 ⋅ 10^5) — the length of the i-th sequence. The second line of the i-th pair contains a sequence of n_i integers a_{i, 1}, a_{i, 2}, ..., a_{i, n_i}.
The elements of sequences are integer numbers from -10^4 to 10^4.
The sum of lengths of all given sequences don't exceed 2 ⋅ 10^5, i.e. n_1 + n_2 + ... + n_k ≤ 2 ⋅ 10^5.
Output
If it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), in the second line — two integers i, x (1 ≤ i ≤ k, 1 ≤ x ≤ n_i), in the third line — two integers j, y (1 ≤ j ≤ k, 1 ≤ y ≤ n_j). It means that the sum of the elements of the i-th sequence without the element with index x equals to the sum of the elements of the j-th sequence without the element with index y.
Two chosen sequences must be distinct, i.e. i ≠ j. You can print them in any order.
If there are multiple possible answers, print any of them.
Examples
Input
2
5
2 3 1 3 2
6
1 1 2 2 2 1
Output
YES
2 6
1 2
Input
3
1
5
5
1 1 1 1 1
2
2 3
Output
NO
Input
4
6
2 2 2 2 2 2
5
2 2 2 2 2
3
2 2 2
5
2 2 2 2 2
Output
YES
2 2
4 1
Note
In the first example there are two sequences [2, 3, 1, 3, 2] and [1, 1, 2, 2, 2, 1]. You can remove the second element from the first sequence to get [2, 1, 3, 2] and you can remove the sixth element from the second sequence to get [1, 1, 2, 2, 2]. The sums of the both resulting sequences equal to 8, i.e. the sums are equal.
Submitted Solution:
```
l = []
t = 0
n = int(input())
for x in range(n):
p = input()
l.append(p)
for i in range(n):
for j in range(n-i-1):
if(len(l[j]) > len(l[j+1])):
l[j],l[j+1] = l[j+1],l[j]
l = l[::-1]
i = 0
j = 1
while(j < len(l)):
one = l[0]
two = l[1]
if two in one:
t = 0
else:
t = 1
if(t == 1):
print("NO")
break
i = i+1
j = j+1
if(t == 0):
print("YES")
l = l[::-1]
for u in l:
print(u)
```
No
| 8,837 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given k sequences of integers. The length of the i-th sequence equals to n_i.
You have to choose exactly two sequences i and j (i ≠ j) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence i (its length will be equal to n_i - 1) equals to the sum of the changed sequence j (its length will be equal to n_j - 1).
Note that it's required to remove exactly one element in each of the two chosen sequences.
Assume that the sum of the empty (of the length equals 0) sequence is 0.
Input
The first line contains an integer k (2 ≤ k ≤ 2 ⋅ 10^5) — the number of sequences.
Then k pairs of lines follow, each pair containing a sequence.
The first line in the i-th pair contains one integer n_i (1 ≤ n_i < 2 ⋅ 10^5) — the length of the i-th sequence. The second line of the i-th pair contains a sequence of n_i integers a_{i, 1}, a_{i, 2}, ..., a_{i, n_i}.
The elements of sequences are integer numbers from -10^4 to 10^4.
The sum of lengths of all given sequences don't exceed 2 ⋅ 10^5, i.e. n_1 + n_2 + ... + n_k ≤ 2 ⋅ 10^5.
Output
If it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), in the second line — two integers i, x (1 ≤ i ≤ k, 1 ≤ x ≤ n_i), in the third line — two integers j, y (1 ≤ j ≤ k, 1 ≤ y ≤ n_j). It means that the sum of the elements of the i-th sequence without the element with index x equals to the sum of the elements of the j-th sequence without the element with index y.
Two chosen sequences must be distinct, i.e. i ≠ j. You can print them in any order.
If there are multiple possible answers, print any of them.
Examples
Input
2
5
2 3 1 3 2
6
1 1 2 2 2 1
Output
YES
2 6
1 2
Input
3
1
5
5
1 1 1 1 1
2
2 3
Output
NO
Input
4
6
2 2 2 2 2 2
5
2 2 2 2 2
3
2 2 2
5
2 2 2 2 2
Output
YES
2 2
4 1
Note
In the first example there are two sequences [2, 3, 1, 3, 2] and [1, 1, 2, 2, 2, 1]. You can remove the second element from the first sequence to get [2, 1, 3, 2] and you can remove the sixth element from the second sequence to get [1, 1, 2, 2, 2]. The sums of the both resulting sequences equal to 8, i.e. the sums are equal.
Submitted Solution:
```
n = int(input())
an_key_i = {}
an_key_j = {}
ans = []
for i in range(n):
l = int(input())
an = list(map(int, input().strip().split(' ')))
ans.append(an)
for i,an in enumerate(ans):
sum_an = sum(an)
for j,an_j in enumerate(an):
sum_an_j = sum_an - an_j
if sum_an_j not in an_key_i.keys():
an_key_i[sum_an_j] = [i+1]
an_key_j[sum_an_j] = [j+1]
else:
an_key_i[sum_an_j].append(i+1)
an_key_j[sum_an_j].append(j+1)
flag = False
for i in an_key_i.keys():
an_key_i_v = an_key_i[i]
an_key_i_v_set = set(an_key_i_v)
if len(an_key_i_v_set)<2:
continue
else:
print('YES')
flag = True
for ii in list(an_key_i_v_set)[:2]:
print(ii,an_key_j[i][an_key_i_v.index(ii)])
if not flag:
print('NO')
```
No
| 8,838 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given k sequences of integers. The length of the i-th sequence equals to n_i.
You have to choose exactly two sequences i and j (i ≠ j) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence i (its length will be equal to n_i - 1) equals to the sum of the changed sequence j (its length will be equal to n_j - 1).
Note that it's required to remove exactly one element in each of the two chosen sequences.
Assume that the sum of the empty (of the length equals 0) sequence is 0.
Input
The first line contains an integer k (2 ≤ k ≤ 2 ⋅ 10^5) — the number of sequences.
Then k pairs of lines follow, each pair containing a sequence.
The first line in the i-th pair contains one integer n_i (1 ≤ n_i < 2 ⋅ 10^5) — the length of the i-th sequence. The second line of the i-th pair contains a sequence of n_i integers a_{i, 1}, a_{i, 2}, ..., a_{i, n_i}.
The elements of sequences are integer numbers from -10^4 to 10^4.
The sum of lengths of all given sequences don't exceed 2 ⋅ 10^5, i.e. n_1 + n_2 + ... + n_k ≤ 2 ⋅ 10^5.
Output
If it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), in the second line — two integers i, x (1 ≤ i ≤ k, 1 ≤ x ≤ n_i), in the third line — two integers j, y (1 ≤ j ≤ k, 1 ≤ y ≤ n_j). It means that the sum of the elements of the i-th sequence without the element with index x equals to the sum of the elements of the j-th sequence without the element with index y.
Two chosen sequences must be distinct, i.e. i ≠ j. You can print them in any order.
If there are multiple possible answers, print any of them.
Examples
Input
2
5
2 3 1 3 2
6
1 1 2 2 2 1
Output
YES
2 6
1 2
Input
3
1
5
5
1 1 1 1 1
2
2 3
Output
NO
Input
4
6
2 2 2 2 2 2
5
2 2 2 2 2
3
2 2 2
5
2 2 2 2 2
Output
YES
2 2
4 1
Note
In the first example there are two sequences [2, 3, 1, 3, 2] and [1, 1, 2, 2, 2, 1]. You can remove the second element from the first sequence to get [2, 1, 3, 2] and you can remove the sixth element from the second sequence to get [1, 1, 2, 2, 2]. The sums of the both resulting sequences equal to 8, i.e. the sums are equal.
Submitted Solution:
```
from sys import stdin,stdout
from copy import deepcopy
k = int(stdin.readline())
a = []
s = []
for _ in range(k):
n = int(input())
a.append(sorted(list(map(int,stdin.readline().split()))))
b = deepcopy(a)
b.sort()
flag = False
for i in range(k-1):
diff = sum(b[i])-sum(b[i+1])
for j in b[i]:
if j-diff in b[i+1]:
print("YES")
print(a.index(b[i])+1,b[i].index(j)+1)
if a.index(b[i])+1==a.index(b[i+1])+1:
print(a.index(b[i+1],a.index(b[i])+1)+1,b[i+1].index(j-diff)+1)
else:
print(a.index(b[i+1])+1,b[i+1].index(j-diff)+1)
flag = True
exit()
if not flag:
print("NO")
```
No
| 8,839 |
Provide a correct Python 3 solution for this coding contest problem.
We have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i).
Among them, we are looking for the points such that the distance from the origin is at most D. How many such points are there?
We remind you that the distance between the origin and the point (p, q) can be represented as \sqrt{p^2+q^2}.
Constraints
* 1 \leq N \leq 2\times 10^5
* 0 \leq D \leq 2\times 10^5
* |X_i|,|Y_i| \leq 2\times 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N D
X_1 Y_1
\vdots
X_N Y_N
Output
Print an integer representing the number of points such that the distance from the origin is at most D.
Examples
Input
4 5
0 5
-2 4
3 4
4 -4
Output
3
Input
12 3
1 1
1 1
1 1
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
Output
7
Input
20 100000
14309 -32939
-56855 100340
151364 25430
103789 -113141
147404 -136977
-37006 -30929
188810 -49557
13419 70401
-88280 165170
-196399 137941
-176527 -61904
46659 115261
-153551 114185
98784 -6820
94111 -86268
-30401 61477
-55056 7872
5901 -163796
138819 -185986
-69848 -96669
Output
6
"Correct Solution:
```
[n, d], *a = [[int(i) for i in x.split()] for x in open(0)]
print(sum(x**2 + y**2 <= d**2 for x, y in a))
```
| 8,840 |
Provide a correct Python 3 solution for this coding contest problem.
We have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i).
Among them, we are looking for the points such that the distance from the origin is at most D. How many such points are there?
We remind you that the distance between the origin and the point (p, q) can be represented as \sqrt{p^2+q^2}.
Constraints
* 1 \leq N \leq 2\times 10^5
* 0 \leq D \leq 2\times 10^5
* |X_i|,|Y_i| \leq 2\times 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N D
X_1 Y_1
\vdots
X_N Y_N
Output
Print an integer representing the number of points such that the distance from the origin is at most D.
Examples
Input
4 5
0 5
-2 4
3 4
4 -4
Output
3
Input
12 3
1 1
1 1
1 1
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
Output
7
Input
20 100000
14309 -32939
-56855 100340
151364 25430
103789 -113141
147404 -136977
-37006 -30929
188810 -49557
13419 70401
-88280 165170
-196399 137941
-176527 -61904
46659 115261
-153551 114185
98784 -6820
94111 -86268
-30401 61477
-55056 7872
5901 -163796
138819 -185986
-69848 -96669
Output
6
"Correct Solution:
```
n, d=map(int,input().split())
sm=0
d2=d**2
for i in range(n):
x,y=map(int,input().split())
if x**2+y**2<=d2:
sm+=1
print(sm)
```
| 8,841 |
Provide a correct Python 3 solution for this coding contest problem.
We have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i).
Among them, we are looking for the points such that the distance from the origin is at most D. How many such points are there?
We remind you that the distance between the origin and the point (p, q) can be represented as \sqrt{p^2+q^2}.
Constraints
* 1 \leq N \leq 2\times 10^5
* 0 \leq D \leq 2\times 10^5
* |X_i|,|Y_i| \leq 2\times 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N D
X_1 Y_1
\vdots
X_N Y_N
Output
Print an integer representing the number of points such that the distance from the origin is at most D.
Examples
Input
4 5
0 5
-2 4
3 4
4 -4
Output
3
Input
12 3
1 1
1 1
1 1
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
Output
7
Input
20 100000
14309 -32939
-56855 100340
151364 25430
103789 -113141
147404 -136977
-37006 -30929
188810 -49557
13419 70401
-88280 165170
-196399 137941
-176527 -61904
46659 115261
-153551 114185
98784 -6820
94111 -86268
-30401 61477
-55056 7872
5901 -163796
138819 -185986
-69848 -96669
Output
6
"Correct Solution:
```
n,d = map(int,input().split())
cnt = 0
for i in range(n):
p,q = map(int,input().split())
cnt += p*p+q*q <= d*d
print(cnt)
```
| 8,842 |
Provide a correct Python 3 solution for this coding contest problem.
We have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i).
Among them, we are looking for the points such that the distance from the origin is at most D. How many such points are there?
We remind you that the distance between the origin and the point (p, q) can be represented as \sqrt{p^2+q^2}.
Constraints
* 1 \leq N \leq 2\times 10^5
* 0 \leq D \leq 2\times 10^5
* |X_i|,|Y_i| \leq 2\times 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N D
X_1 Y_1
\vdots
X_N Y_N
Output
Print an integer representing the number of points such that the distance from the origin is at most D.
Examples
Input
4 5
0 5
-2 4
3 4
4 -4
Output
3
Input
12 3
1 1
1 1
1 1
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
Output
7
Input
20 100000
14309 -32939
-56855 100340
151364 25430
103789 -113141
147404 -136977
-37006 -30929
188810 -49557
13419 70401
-88280 165170
-196399 137941
-176527 -61904
46659 115261
-153551 114185
98784 -6820
94111 -86268
-30401 61477
-55056 7872
5901 -163796
138819 -185986
-69848 -96669
Output
6
"Correct Solution:
```
n,d = map(int,input().split())
s = 0
for i in range(n):
x,y = map(int,input().split())
if x*x+y*y<=d*d:
s += 1
print(s)
```
| 8,843 |
Provide a correct Python 3 solution for this coding contest problem.
We have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i).
Among them, we are looking for the points such that the distance from the origin is at most D. How many such points are there?
We remind you that the distance between the origin and the point (p, q) can be represented as \sqrt{p^2+q^2}.
Constraints
* 1 \leq N \leq 2\times 10^5
* 0 \leq D \leq 2\times 10^5
* |X_i|,|Y_i| \leq 2\times 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N D
X_1 Y_1
\vdots
X_N Y_N
Output
Print an integer representing the number of points such that the distance from the origin is at most D.
Examples
Input
4 5
0 5
-2 4
3 4
4 -4
Output
3
Input
12 3
1 1
1 1
1 1
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
Output
7
Input
20 100000
14309 -32939
-56855 100340
151364 25430
103789 -113141
147404 -136977
-37006 -30929
188810 -49557
13419 70401
-88280 165170
-196399 137941
-176527 -61904
46659 115261
-153551 114185
98784 -6820
94111 -86268
-30401 61477
-55056 7872
5901 -163796
138819 -185986
-69848 -96669
Output
6
"Correct Solution:
```
n,d=map(int,input().split())
print(sum(eval("(("+input().replace(" ",")**2+(")+")**2)")**0.5<=d for _ in range(n)))
```
| 8,844 |
Provide a correct Python 3 solution for this coding contest problem.
We have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i).
Among them, we are looking for the points such that the distance from the origin is at most D. How many such points are there?
We remind you that the distance between the origin and the point (p, q) can be represented as \sqrt{p^2+q^2}.
Constraints
* 1 \leq N \leq 2\times 10^5
* 0 \leq D \leq 2\times 10^5
* |X_i|,|Y_i| \leq 2\times 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N D
X_1 Y_1
\vdots
X_N Y_N
Output
Print an integer representing the number of points such that the distance from the origin is at most D.
Examples
Input
4 5
0 5
-2 4
3 4
4 -4
Output
3
Input
12 3
1 1
1 1
1 1
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
Output
7
Input
20 100000
14309 -32939
-56855 100340
151364 25430
103789 -113141
147404 -136977
-37006 -30929
188810 -49557
13419 70401
-88280 165170
-196399 137941
-176527 -61904
46659 115261
-153551 114185
98784 -6820
94111 -86268
-30401 61477
-55056 7872
5901 -163796
138819 -185986
-69848 -96669
Output
6
"Correct Solution:
```
n,d=map(int,input().split())
cnt=0
for i in range(n):
a,b=map(int,input().split())
if a**2+b**2<=d**2:
cnt+=1
print(cnt)
```
| 8,845 |
Provide a correct Python 3 solution for this coding contest problem.
We have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i).
Among them, we are looking for the points such that the distance from the origin is at most D. How many such points are there?
We remind you that the distance between the origin and the point (p, q) can be represented as \sqrt{p^2+q^2}.
Constraints
* 1 \leq N \leq 2\times 10^5
* 0 \leq D \leq 2\times 10^5
* |X_i|,|Y_i| \leq 2\times 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N D
X_1 Y_1
\vdots
X_N Y_N
Output
Print an integer representing the number of points such that the distance from the origin is at most D.
Examples
Input
4 5
0 5
-2 4
3 4
4 -4
Output
3
Input
12 3
1 1
1 1
1 1
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
Output
7
Input
20 100000
14309 -32939
-56855 100340
151364 25430
103789 -113141
147404 -136977
-37006 -30929
188810 -49557
13419 70401
-88280 165170
-196399 137941
-176527 -61904
46659 115261
-153551 114185
98784 -6820
94111 -86268
-30401 61477
-55056 7872
5901 -163796
138819 -185986
-69848 -96669
Output
6
"Correct Solution:
```
n,d=map(int,input().split())
ans=0
for i in range(n):
x,y=map(int,input().split())
if(x*x+y*y<=d*d):
ans+=1
print(ans)
```
| 8,846 |
Provide a correct Python 3 solution for this coding contest problem.
We have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i).
Among them, we are looking for the points such that the distance from the origin is at most D. How many such points are there?
We remind you that the distance between the origin and the point (p, q) can be represented as \sqrt{p^2+q^2}.
Constraints
* 1 \leq N \leq 2\times 10^5
* 0 \leq D \leq 2\times 10^5
* |X_i|,|Y_i| \leq 2\times 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N D
X_1 Y_1
\vdots
X_N Y_N
Output
Print an integer representing the number of points such that the distance from the origin is at most D.
Examples
Input
4 5
0 5
-2 4
3 4
4 -4
Output
3
Input
12 3
1 1
1 1
1 1
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
Output
7
Input
20 100000
14309 -32939
-56855 100340
151364 25430
103789 -113141
147404 -136977
-37006 -30929
188810 -49557
13419 70401
-88280 165170
-196399 137941
-176527 -61904
46659 115261
-153551 114185
98784 -6820
94111 -86268
-30401 61477
-55056 7872
5901 -163796
138819 -185986
-69848 -96669
Output
6
"Correct Solution:
```
N,D=map(int,input().split())
ans=0
for i in range(N):
x,y=map(int,input().split())
if(D*D>=x*x+y*y):ans+=1
print(ans)
```
| 8,847 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i).
Among them, we are looking for the points such that the distance from the origin is at most D. How many such points are there?
We remind you that the distance between the origin and the point (p, q) can be represented as \sqrt{p^2+q^2}.
Constraints
* 1 \leq N \leq 2\times 10^5
* 0 \leq D \leq 2\times 10^5
* |X_i|,|Y_i| \leq 2\times 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N D
X_1 Y_1
\vdots
X_N Y_N
Output
Print an integer representing the number of points such that the distance from the origin is at most D.
Examples
Input
4 5
0 5
-2 4
3 4
4 -4
Output
3
Input
12 3
1 1
1 1
1 1
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
Output
7
Input
20 100000
14309 -32939
-56855 100340
151364 25430
103789 -113141
147404 -136977
-37006 -30929
188810 -49557
13419 70401
-88280 165170
-196399 137941
-176527 -61904
46659 115261
-153551 114185
98784 -6820
94111 -86268
-30401 61477
-55056 7872
5901 -163796
138819 -185986
-69848 -96669
Output
6
Submitted Solution:
```
n,d = map(int, input().split())
cnt = 0
for i in range(n):
x,y = map(int, input().split())
if (x*x + y*y)**0.5 <= d: cnt += 1
print(cnt)
```
Yes
| 8,848 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i).
Among them, we are looking for the points such that the distance from the origin is at most D. How many such points are there?
We remind you that the distance between the origin and the point (p, q) can be represented as \sqrt{p^2+q^2}.
Constraints
* 1 \leq N \leq 2\times 10^5
* 0 \leq D \leq 2\times 10^5
* |X_i|,|Y_i| \leq 2\times 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N D
X_1 Y_1
\vdots
X_N Y_N
Output
Print an integer representing the number of points such that the distance from the origin is at most D.
Examples
Input
4 5
0 5
-2 4
3 4
4 -4
Output
3
Input
12 3
1 1
1 1
1 1
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
Output
7
Input
20 100000
14309 -32939
-56855 100340
151364 25430
103789 -113141
147404 -136977
-37006 -30929
188810 -49557
13419 70401
-88280 165170
-196399 137941
-176527 -61904
46659 115261
-153551 114185
98784 -6820
94111 -86268
-30401 61477
-55056 7872
5901 -163796
138819 -185986
-69848 -96669
Output
6
Submitted Solution:
```
N,D=map(int,input().split())
a=0
d=D**2
for i in range(N):
x,y=map(int,input().split())
if x**2+y**2<=d:
a+=1
print(a)
```
Yes
| 8,849 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i).
Among them, we are looking for the points such that the distance from the origin is at most D. How many such points are there?
We remind you that the distance between the origin and the point (p, q) can be represented as \sqrt{p^2+q^2}.
Constraints
* 1 \leq N \leq 2\times 10^5
* 0 \leq D \leq 2\times 10^5
* |X_i|,|Y_i| \leq 2\times 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N D
X_1 Y_1
\vdots
X_N Y_N
Output
Print an integer representing the number of points such that the distance from the origin is at most D.
Examples
Input
4 5
0 5
-2 4
3 4
4 -4
Output
3
Input
12 3
1 1
1 1
1 1
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
Output
7
Input
20 100000
14309 -32939
-56855 100340
151364 25430
103789 -113141
147404 -136977
-37006 -30929
188810 -49557
13419 70401
-88280 165170
-196399 137941
-176527 -61904
46659 115261
-153551 114185
98784 -6820
94111 -86268
-30401 61477
-55056 7872
5901 -163796
138819 -185986
-69848 -96669
Output
6
Submitted Solution:
```
n,d=map(int,input().split())
d1=d**2;c=0
for i in range(n):
x,y=map(int,input().split())
if x**2+y**2<=d1:
c+=1
print(c)
```
Yes
| 8,850 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i).
Among them, we are looking for the points such that the distance from the origin is at most D. How many such points are there?
We remind you that the distance between the origin and the point (p, q) can be represented as \sqrt{p^2+q^2}.
Constraints
* 1 \leq N \leq 2\times 10^5
* 0 \leq D \leq 2\times 10^5
* |X_i|,|Y_i| \leq 2\times 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N D
X_1 Y_1
\vdots
X_N Y_N
Output
Print an integer representing the number of points such that the distance from the origin is at most D.
Examples
Input
4 5
0 5
-2 4
3 4
4 -4
Output
3
Input
12 3
1 1
1 1
1 1
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
Output
7
Input
20 100000
14309 -32939
-56855 100340
151364 25430
103789 -113141
147404 -136977
-37006 -30929
188810 -49557
13419 70401
-88280 165170
-196399 137941
-176527 -61904
46659 115261
-153551 114185
98784 -6820
94111 -86268
-30401 61477
-55056 7872
5901 -163796
138819 -185986
-69848 -96669
Output
6
Submitted Solution:
```
N,M=list(map(int,input().split()))
ans=0
for u in range(N):
a,b=map(int,input().split())
S=a*a+b*b
if M*M>=S:
ans+=1
print(ans)
```
Yes
| 8,851 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i).
Among them, we are looking for the points such that the distance from the origin is at most D. How many such points are there?
We remind you that the distance between the origin and the point (p, q) can be represented as \sqrt{p^2+q^2}.
Constraints
* 1 \leq N \leq 2\times 10^5
* 0 \leq D \leq 2\times 10^5
* |X_i|,|Y_i| \leq 2\times 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N D
X_1 Y_1
\vdots
X_N Y_N
Output
Print an integer representing the number of points such that the distance from the origin is at most D.
Examples
Input
4 5
0 5
-2 4
3 4
4 -4
Output
3
Input
12 3
1 1
1 1
1 1
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
Output
7
Input
20 100000
14309 -32939
-56855 100340
151364 25430
103789 -113141
147404 -136977
-37006 -30929
188810 -49557
13419 70401
-88280 165170
-196399 137941
-176527 -61904
46659 115261
-153551 114185
98784 -6820
94111 -86268
-30401 61477
-55056 7872
5901 -163796
138819 -185986
-69848 -96669
Output
6
Submitted Solution:
```
import sys
a = []
for l in sys.stdin:
a.append(l)
N,D = a[0].split(' ')
N = int(N)
D = int(D)
D = D*D
x = []
y = []
count = 0
dist = 0.0
for i in range(1,N):
x, y = a[i].split(' ')
x = int(x)
y = int(y)
dist = x*x+y*y
if dist <= D:
count = count + 1
print(count)
```
No
| 8,852 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i).
Among them, we are looking for the points such that the distance from the origin is at most D. How many such points are there?
We remind you that the distance between the origin and the point (p, q) can be represented as \sqrt{p^2+q^2}.
Constraints
* 1 \leq N \leq 2\times 10^5
* 0 \leq D \leq 2\times 10^5
* |X_i|,|Y_i| \leq 2\times 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N D
X_1 Y_1
\vdots
X_N Y_N
Output
Print an integer representing the number of points such that the distance from the origin is at most D.
Examples
Input
4 5
0 5
-2 4
3 4
4 -4
Output
3
Input
12 3
1 1
1 1
1 1
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
Output
7
Input
20 100000
14309 -32939
-56855 100340
151364 25430
103789 -113141
147404 -136977
-37006 -30929
188810 -49557
13419 70401
-88280 165170
-196399 137941
-176527 -61904
46659 115261
-153551 114185
98784 -6820
94111 -86268
-30401 61477
-55056 7872
5901 -163796
138819 -185986
-69848 -96669
Output
6
Submitted Solution:
```
n,d=map(int,input().split())
x = [0]*n
y = [0]*n
count=0
for i in range(n):
x[i],y[i] = map(int, input().split())
if x[i]**2+y[i]**2<=d**2:
count=+1
print(count)
```
No
| 8,853 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i).
Among them, we are looking for the points such that the distance from the origin is at most D. How many such points are there?
We remind you that the distance between the origin and the point (p, q) can be represented as \sqrt{p^2+q^2}.
Constraints
* 1 \leq N \leq 2\times 10^5
* 0 \leq D \leq 2\times 10^5
* |X_i|,|Y_i| \leq 2\times 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N D
X_1 Y_1
\vdots
X_N Y_N
Output
Print an integer representing the number of points such that the distance from the origin is at most D.
Examples
Input
4 5
0 5
-2 4
3 4
4 -4
Output
3
Input
12 3
1 1
1 1
1 1
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
Output
7
Input
20 100000
14309 -32939
-56855 100340
151364 25430
103789 -113141
147404 -136977
-37006 -30929
188810 -49557
13419 70401
-88280 165170
-196399 137941
-176527 -61904
46659 115261
-153551 114185
98784 -6820
94111 -86268
-30401 61477
-55056 7872
5901 -163796
138819 -185986
-69848 -96669
Output
6
Submitted Solution:
```
n, d = map(int, input().split())
cnt = 0
for ti in range(n) :
x, y = map(int, input().split())
dist = (x**2 + y**2)**0.5
if(dist >= d):
cnt += 1
print(cnt)
```
No
| 8,854 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i).
Among them, we are looking for the points such that the distance from the origin is at most D. How many such points are there?
We remind you that the distance between the origin and the point (p, q) can be represented as \sqrt{p^2+q^2}.
Constraints
* 1 \leq N \leq 2\times 10^5
* 0 \leq D \leq 2\times 10^5
* |X_i|,|Y_i| \leq 2\times 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N D
X_1 Y_1
\vdots
X_N Y_N
Output
Print an integer representing the number of points such that the distance from the origin is at most D.
Examples
Input
4 5
0 5
-2 4
3 4
4 -4
Output
3
Input
12 3
1 1
1 1
1 1
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
Output
7
Input
20 100000
14309 -32939
-56855 100340
151364 25430
103789 -113141
147404 -136977
-37006 -30929
188810 -49557
13419 70401
-88280 165170
-196399 137941
-176527 -61904
46659 115261
-153551 114185
98784 -6820
94111 -86268
-30401 61477
-55056 7872
5901 -163796
138819 -185986
-69848 -96669
Output
6
Submitted Solution:
```
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, d, i, count = 0;
cin >> n;
cin >> d;
for (i = 0; i < n; i++) {
long long int x, y;
cin >> x;
cin >> y;
if (x * x + y * y <= d * d) {
count = count + 1;
}
}
cout << count;
}
```
No
| 8,855 |
Provide a correct Python 3 solution for this coding contest problem.
We have an undirected graph G with N vertices numbered 1 to N and N edges as follows:
* For each i=1,2,...,N-1, there is an edge between Vertex i and Vertex i+1.
* There is an edge between Vertex X and Vertex Y.
For each k=1,2,...,N-1, solve the problem below:
* Find the number of pairs of integers (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j in G is k.
Constraints
* 3 \leq N \leq 2 \times 10^3
* 1 \leq X,Y \leq N
* X+1 < Y
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X Y
Output
For each k=1, 2, ..., N-1 in this order, print a line containing the answer to the problem.
Examples
Input
5 2 4
Output
5
4
1
0
Input
3 1 3
Output
3
0
Input
7 3 7
Output
7
8
4
2
0
0
Input
10 4 8
Output
10
12
10
8
4
1
0
0
0
"Correct Solution:
```
n,x,y=map(int,input().split())
ans=[0]*n
for i in range(n):
for j in range(i+1,n):
ans[min(j+1-i-1,abs(i+1-x)+abs(j+1-y)+1)] += 1
for i in range(n-1):
print(ans[i+1])
```
| 8,856 |
Provide a correct Python 3 solution for this coding contest problem.
We have an undirected graph G with N vertices numbered 1 to N and N edges as follows:
* For each i=1,2,...,N-1, there is an edge between Vertex i and Vertex i+1.
* There is an edge between Vertex X and Vertex Y.
For each k=1,2,...,N-1, solve the problem below:
* Find the number of pairs of integers (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j in G is k.
Constraints
* 3 \leq N \leq 2 \times 10^3
* 1 \leq X,Y \leq N
* X+1 < Y
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X Y
Output
For each k=1, 2, ..., N-1 in this order, print a line containing the answer to the problem.
Examples
Input
5 2 4
Output
5
4
1
0
Input
3 1 3
Output
3
0
Input
7 3 7
Output
7
8
4
2
0
0
Input
10 4 8
Output
10
12
10
8
4
1
0
0
0
"Correct Solution:
```
N, X, Y = map(int, input().split())
K = [0]*(N-1)
for i in range(1,N+1):
for j in range(i+1,N+1):
K[min(min(abs(X-i)+1,abs(Y-i))+abs(j-Y),abs(i-j))-1]+=1
for i in range(N-1):
print(K[i])
```
| 8,857 |
Provide a correct Python 3 solution for this coding contest problem.
We have an undirected graph G with N vertices numbered 1 to N and N edges as follows:
* For each i=1,2,...,N-1, there is an edge between Vertex i and Vertex i+1.
* There is an edge between Vertex X and Vertex Y.
For each k=1,2,...,N-1, solve the problem below:
* Find the number of pairs of integers (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j in G is k.
Constraints
* 3 \leq N \leq 2 \times 10^3
* 1 \leq X,Y \leq N
* X+1 < Y
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X Y
Output
For each k=1, 2, ..., N-1 in this order, print a line containing the answer to the problem.
Examples
Input
5 2 4
Output
5
4
1
0
Input
3 1 3
Output
3
0
Input
7 3 7
Output
7
8
4
2
0
0
Input
10 4 8
Output
10
12
10
8
4
1
0
0
0
"Correct Solution:
```
n,x,y=map(int,input().split())
l=[0]*n
for i in range(1,n+1):
for j in range(i+1,n+1):
l[min(j-i,abs(x-i)+1+abs(y-j))]+=1
print(*l[1:],sep='\n')
```
| 8,858 |
Provide a correct Python 3 solution for this coding contest problem.
We have an undirected graph G with N vertices numbered 1 to N and N edges as follows:
* For each i=1,2,...,N-1, there is an edge between Vertex i and Vertex i+1.
* There is an edge between Vertex X and Vertex Y.
For each k=1,2,...,N-1, solve the problem below:
* Find the number of pairs of integers (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j in G is k.
Constraints
* 3 \leq N \leq 2 \times 10^3
* 1 \leq X,Y \leq N
* X+1 < Y
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X Y
Output
For each k=1, 2, ..., N-1 in this order, print a line containing the answer to the problem.
Examples
Input
5 2 4
Output
5
4
1
0
Input
3 1 3
Output
3
0
Input
7 3 7
Output
7
8
4
2
0
0
Input
10 4 8
Output
10
12
10
8
4
1
0
0
0
"Correct Solution:
```
n,x,y=map(int,input().split())
ans=[0]*(n-1)
for i in range(1,n+1):
for j in range(i+1,n+1):
ans[(min(j-i,abs(i-x)+abs(j-y)+1))-1]+=1
for i in ans:
print(i)
```
| 8,859 |
Provide a correct Python 3 solution for this coding contest problem.
We have an undirected graph G with N vertices numbered 1 to N and N edges as follows:
* For each i=1,2,...,N-1, there is an edge between Vertex i and Vertex i+1.
* There is an edge between Vertex X and Vertex Y.
For each k=1,2,...,N-1, solve the problem below:
* Find the number of pairs of integers (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j in G is k.
Constraints
* 3 \leq N \leq 2 \times 10^3
* 1 \leq X,Y \leq N
* X+1 < Y
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X Y
Output
For each k=1, 2, ..., N-1 in this order, print a line containing the answer to the problem.
Examples
Input
5 2 4
Output
5
4
1
0
Input
3 1 3
Output
3
0
Input
7 3 7
Output
7
8
4
2
0
0
Input
10 4 8
Output
10
12
10
8
4
1
0
0
0
"Correct Solution:
```
n,x,y=map(int,input().split())
l=[0]*~-n
for i in range(1,n):
for j in range(i):l[min(~j+i,abs(~j+x)+abs(~i+y))]+=1
print(*l)
```
| 8,860 |
Provide a correct Python 3 solution for this coding contest problem.
We have an undirected graph G with N vertices numbered 1 to N and N edges as follows:
* For each i=1,2,...,N-1, there is an edge between Vertex i and Vertex i+1.
* There is an edge between Vertex X and Vertex Y.
For each k=1,2,...,N-1, solve the problem below:
* Find the number of pairs of integers (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j in G is k.
Constraints
* 3 \leq N \leq 2 \times 10^3
* 1 \leq X,Y \leq N
* X+1 < Y
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X Y
Output
For each k=1, 2, ..., N-1 in this order, print a line containing the answer to the problem.
Examples
Input
5 2 4
Output
5
4
1
0
Input
3 1 3
Output
3
0
Input
7 3 7
Output
7
8
4
2
0
0
Input
10 4 8
Output
10
12
10
8
4
1
0
0
0
"Correct Solution:
```
n, x, y = map(int, input().split())
l = [0] * (n-1)
for i in range(1, n):
for j in range(i+1, n+1):
s = min(j-i, abs(x-i)+abs(j-y)+1)
l[s-1] += 1
for i in l:
print(i)
```
| 8,861 |
Provide a correct Python 3 solution for this coding contest problem.
We have an undirected graph G with N vertices numbered 1 to N and N edges as follows:
* For each i=1,2,...,N-1, there is an edge between Vertex i and Vertex i+1.
* There is an edge between Vertex X and Vertex Y.
For each k=1,2,...,N-1, solve the problem below:
* Find the number of pairs of integers (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j in G is k.
Constraints
* 3 \leq N \leq 2 \times 10^3
* 1 \leq X,Y \leq N
* X+1 < Y
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X Y
Output
For each k=1, 2, ..., N-1 in this order, print a line containing the answer to the problem.
Examples
Input
5 2 4
Output
5
4
1
0
Input
3 1 3
Output
3
0
Input
7 3 7
Output
7
8
4
2
0
0
Input
10 4 8
Output
10
12
10
8
4
1
0
0
0
"Correct Solution:
```
n,x,y = map(int, input().split())
a = [0] * (n-1)
for i in range(1,n):
for j in range(i+1 ,n+1):
d = min(j-i, 1 + abs(j-y) + abs(i-x)) - 1
a[d] += 1
print(*a, sep="\n")
```
| 8,862 |
Provide a correct Python 3 solution for this coding contest problem.
We have an undirected graph G with N vertices numbered 1 to N and N edges as follows:
* For each i=1,2,...,N-1, there is an edge between Vertex i and Vertex i+1.
* There is an edge between Vertex X and Vertex Y.
For each k=1,2,...,N-1, solve the problem below:
* Find the number of pairs of integers (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j in G is k.
Constraints
* 3 \leq N \leq 2 \times 10^3
* 1 \leq X,Y \leq N
* X+1 < Y
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X Y
Output
For each k=1, 2, ..., N-1 in this order, print a line containing the answer to the problem.
Examples
Input
5 2 4
Output
5
4
1
0
Input
3 1 3
Output
3
0
Input
7 3 7
Output
7
8
4
2
0
0
Input
10 4 8
Output
10
12
10
8
4
1
0
0
0
"Correct Solution:
```
n,x,y=map(int,input().split())
min_dist=[0]*(n-1)
for i in range(n):
for j in range(i+1,n):
min_dist[min(j-i-1,abs(x-1-i)+abs(y-1-j))]+=1
for ans in min_dist:
print(ans)
```
| 8,863 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have an undirected graph G with N vertices numbered 1 to N and N edges as follows:
* For each i=1,2,...,N-1, there is an edge between Vertex i and Vertex i+1.
* There is an edge between Vertex X and Vertex Y.
For each k=1,2,...,N-1, solve the problem below:
* Find the number of pairs of integers (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j in G is k.
Constraints
* 3 \leq N \leq 2 \times 10^3
* 1 \leq X,Y \leq N
* X+1 < Y
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X Y
Output
For each k=1, 2, ..., N-1 in this order, print a line containing the answer to the problem.
Examples
Input
5 2 4
Output
5
4
1
0
Input
3 1 3
Output
3
0
Input
7 3 7
Output
7
8
4
2
0
0
Input
10 4 8
Output
10
12
10
8
4
1
0
0
0
Submitted Solution:
```
N, X, Y = map(int, input().split())
t = [0]*N
for i in range(1, N):
for j in range(i+1, N+1):
t[min(j-i, abs(X-i)+1+abs(j-Y))] += 1
for k in range(1, N):
print (t[k])
```
Yes
| 8,864 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have an undirected graph G with N vertices numbered 1 to N and N edges as follows:
* For each i=1,2,...,N-1, there is an edge between Vertex i and Vertex i+1.
* There is an edge between Vertex X and Vertex Y.
For each k=1,2,...,N-1, solve the problem below:
* Find the number of pairs of integers (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j in G is k.
Constraints
* 3 \leq N \leq 2 \times 10^3
* 1 \leq X,Y \leq N
* X+1 < Y
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X Y
Output
For each k=1, 2, ..., N-1 in this order, print a line containing the answer to the problem.
Examples
Input
5 2 4
Output
5
4
1
0
Input
3 1 3
Output
3
0
Input
7 3 7
Output
7
8
4
2
0
0
Input
10 4 8
Output
10
12
10
8
4
1
0
0
0
Submitted Solution:
```
n,x,y = map(int,input().split())
ans=[0]*n
for i in range(1,n):
for j in range(i+1,n+1):
ans[min(j-i,abs(i-x)+1+abs(j-y))]+=1
for i in range(1,n):
print(ans[i])
```
Yes
| 8,865 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have an undirected graph G with N vertices numbered 1 to N and N edges as follows:
* For each i=1,2,...,N-1, there is an edge between Vertex i and Vertex i+1.
* There is an edge between Vertex X and Vertex Y.
For each k=1,2,...,N-1, solve the problem below:
* Find the number of pairs of integers (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j in G is k.
Constraints
* 3 \leq N \leq 2 \times 10^3
* 1 \leq X,Y \leq N
* X+1 < Y
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X Y
Output
For each k=1, 2, ..., N-1 in this order, print a line containing the answer to the problem.
Examples
Input
5 2 4
Output
5
4
1
0
Input
3 1 3
Output
3
0
Input
7 3 7
Output
7
8
4
2
0
0
Input
10 4 8
Output
10
12
10
8
4
1
0
0
0
Submitted Solution:
```
n,x,y=list(map(int,input().split()))
ans=[0]*(n-1)
for i in range(1,n):
for j in range(i+1,n+1):
ans[min([j-i,abs(x-i)+1+abs(j-y)])-1]+=1
for i in ans:
print(str(i))
```
Yes
| 8,866 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have an undirected graph G with N vertices numbered 1 to N and N edges as follows:
* For each i=1,2,...,N-1, there is an edge between Vertex i and Vertex i+1.
* There is an edge between Vertex X and Vertex Y.
For each k=1,2,...,N-1, solve the problem below:
* Find the number of pairs of integers (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j in G is k.
Constraints
* 3 \leq N \leq 2 \times 10^3
* 1 \leq X,Y \leq N
* X+1 < Y
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X Y
Output
For each k=1, 2, ..., N-1 in this order, print a line containing the answer to the problem.
Examples
Input
5 2 4
Output
5
4
1
0
Input
3 1 3
Output
3
0
Input
7 3 7
Output
7
8
4
2
0
0
Input
10 4 8
Output
10
12
10
8
4
1
0
0
0
Submitted Solution:
```
n,x,y=map(int,input().split())
k=[0]*n
for i in range(1,n):
for j in range(1,n-i+1):
t=min(j,abs(i-x)+abs(i+j-y)+1)
k[t]+=1
for i in range(1,n):
print(k[i])
```
Yes
| 8,867 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have an undirected graph G with N vertices numbered 1 to N and N edges as follows:
* For each i=1,2,...,N-1, there is an edge between Vertex i and Vertex i+1.
* There is an edge between Vertex X and Vertex Y.
For each k=1,2,...,N-1, solve the problem below:
* Find the number of pairs of integers (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j in G is k.
Constraints
* 3 \leq N \leq 2 \times 10^3
* 1 \leq X,Y \leq N
* X+1 < Y
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X Y
Output
For each k=1, 2, ..., N-1 in this order, print a line containing the answer to the problem.
Examples
Input
5 2 4
Output
5
4
1
0
Input
3 1 3
Output
3
0
Input
7 3 7
Output
7
8
4
2
0
0
Input
10 4 8
Output
10
12
10
8
4
1
0
0
0
Submitted Solution:
```
K,N =map(int,input().split())
A =input()
B =A.split(" ")
B = [ int(i) for i in B]
g = B[N-1] - B[0]
print(g)
```
No
| 8,868 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have an undirected graph G with N vertices numbered 1 to N and N edges as follows:
* For each i=1,2,...,N-1, there is an edge between Vertex i and Vertex i+1.
* There is an edge between Vertex X and Vertex Y.
For each k=1,2,...,N-1, solve the problem below:
* Find the number of pairs of integers (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j in G is k.
Constraints
* 3 \leq N \leq 2 \times 10^3
* 1 \leq X,Y \leq N
* X+1 < Y
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X Y
Output
For each k=1, 2, ..., N-1 in this order, print a line containing the answer to the problem.
Examples
Input
5 2 4
Output
5
4
1
0
Input
3 1 3
Output
3
0
Input
7 3 7
Output
7
8
4
2
0
0
Input
10 4 8
Output
10
12
10
8
4
1
0
0
0
Submitted Solution:
```
from collections import deque
def solve():
N, X, Y = map(int, input().split())
X -= 1
Y -= 1
ans = [0] * N
for start_vertex in range(N):
q = deque()
distance_list = [float('inf')] * N
def push(vertex, distance):
if distance_list[vertex] != float('inf'):
return
distance_list[vertex] = distance
q.append(vertex)
push(start_vertex, 0)
while len(q) > 0:
vertex = q.popleft()
distance = distance_list[vertex]
if vertex - 1 >= 0:
push(vertex-1,distance+1)
if vertex + 1 < N:
push(vertex+1,distance+1)
if vertex == X:
push(Y,distance+1)
if vertex == Y:
push(X,distance+1)
for d in distance_list:
ans[d] += 1
ans = list(map(lambda x: x // 2, ans))
print(*ans, sep='\n')
if __name__ == '__main__':
solve()
```
No
| 8,869 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have an undirected graph G with N vertices numbered 1 to N and N edges as follows:
* For each i=1,2,...,N-1, there is an edge between Vertex i and Vertex i+1.
* There is an edge between Vertex X and Vertex Y.
For each k=1,2,...,N-1, solve the problem below:
* Find the number of pairs of integers (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j in G is k.
Constraints
* 3 \leq N \leq 2 \times 10^3
* 1 \leq X,Y \leq N
* X+1 < Y
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X Y
Output
For each k=1, 2, ..., N-1 in this order, print a line containing the answer to the problem.
Examples
Input
5 2 4
Output
5
4
1
0
Input
3 1 3
Output
3
0
Input
7 3 7
Output
7
8
4
2
0
0
Input
10 4 8
Output
10
12
10
8
4
1
0
0
0
Submitted Solution:
```
[N, X, Y] = input().split()
N = int(N)
X = int(X)
Y = int(Y)
dist_list = []
for i in range(N):
for j in range(i+1, N):
if i+1 <= X and j+1 >= Y:
dist_list.append(j - Y + X - i + 1)
else:
dist_list.append(min(j - i, abs(i+1 - X) + abs(j+1 -Y) + 1))
for k in range(N-1):
print(dist_list.count(k+1))
```
No
| 8,870 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have an undirected graph G with N vertices numbered 1 to N and N edges as follows:
* For each i=1,2,...,N-1, there is an edge between Vertex i and Vertex i+1.
* There is an edge between Vertex X and Vertex Y.
For each k=1,2,...,N-1, solve the problem below:
* Find the number of pairs of integers (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j in G is k.
Constraints
* 3 \leq N \leq 2 \times 10^3
* 1 \leq X,Y \leq N
* X+1 < Y
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X Y
Output
For each k=1, 2, ..., N-1 in this order, print a line containing the answer to the problem.
Examples
Input
5 2 4
Output
5
4
1
0
Input
3 1 3
Output
3
0
Input
7 3 7
Output
7
8
4
2
0
0
Input
10 4 8
Output
10
12
10
8
4
1
0
0
0
Submitted Solution:
```
n, x , y = map(int, input().split())
from collections import defaultdict
g = [[0] * n for _ in range(n)]
for i in range(1, n):
g[i-1][i] = 1
g[i][i-1] = 1
g[x-1][y-1] = 1
g[y-1][x-1] = 1
from scipy.sparse.csgraph import floyd_warshall
cost = floyd_warshall(g)
from collections import Counter
c = Counter()
for i in range(n):
for j in range(i+1, n):
c[cost[i][j]] += 1
for k in range(1, n):
print(c[k])
```
No
| 8,871 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an interactive task.
We have 2N balls arranged in a row, numbered 1, 2, 3, ..., 2N from left to right, where N is an odd number. Among them, there are N red balls and N blue balls.
While blindfolded, you are challenged to guess the color of every ball correctly, by asking at most 210 questions of the following form:
* You choose any N of the 2N balls and ask whether there are more red balls than blue balls or not among those N balls.
Now, let us begin.
Constraints
* 1 \leq N \leq 99
* N is an odd number.
* * *
Example
Input
Output
Submitted Solution:
```
from sys import exit
import time
def q(l):
print("?",end=" ")
for i in l:
print(i,end=" ")
print("")
ret=input()
if ret=="-1":
exit(0)
return ret=="Red"
n=int(input())
res=[None for i in range(n*2+1)]
if n==1:
if q([1]):
res=[None,"R","B"]
else:
res=[None,"B","R"]
else:
a=[i for i in range(1,(n+1)//2)]
b=[i for i in range((n+1)//2,n+1)]
c=[i for i in range(n+1,(n+1)//2+n+1)]
d=[i for i in range((n+1)//2+n+1,n*2+1)]
ab=q(a+b)
ac=q(a+c)
if ab and ac:
#a red d blue
toadd=b
rr=a
bb=d
elif ab and not ac:
#b red c blue
toadd=a
rr=b
bb=c
elif not ab and ac:
#c red b blue
toadd=a
rr=c
bb=b
elif not ab and not ac:
#d red a blue
toadd=c
rr=d
bb=a
else:
pass
if n<=50:
for en in range(1,len(rr)):
if q(toadd+rr[:en]+bb[en:]):
arr=toadd+rr[:en-1]+bb[en:]
break
else:
blim=0
rlim=len(rr)
while rlim-blim>1:
en=(blim+rlim)//2
if q(toadd+rr[:en]+bb[en:]):
rlim=en
else:
blim=en
arr=toadd+rr[:blim]+bb[blim+1:]
for i in range(1,2*n+1):
if i in arr:
continue
if q(arr+[i]):
res[i]="R"
else:
res[i]="B"
half=[]
rcnt=0
bcnt=0
for i in range(1,2*n+1):
if res[i]=="R":
if rcnt<(n-1)//2:
half.append(i)
rcnt+=1
elif res[i]=="B":
if bcnt<(n-1)//2:
half.append(i)
bcnt+=1
for i in range(1,2*n+1):
if res[i]==None:
ret=q(half+[i])
if ret:
res[i]="R"
else:
res[i]="B"
print("!",end=" ")
for c in res[1:]:
if c==None:
time.sleep(0.5)
break
print(c,end="")
print("",flush=True)
```
No
| 8,872 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an interactive task.
We have 2N balls arranged in a row, numbered 1, 2, 3, ..., 2N from left to right, where N is an odd number. Among them, there are N red balls and N blue balls.
While blindfolded, you are challenged to guess the color of every ball correctly, by asking at most 210 questions of the following form:
* You choose any N of the 2N balls and ask whether there are more red balls than blue balls or not among those N balls.
Now, let us begin.
Constraints
* 1 \leq N \leq 99
* N is an odd number.
* * *
Example
Input
Output
Submitted Solution:
```
import sys
def input():
a = sys.stdin.readline()
if a[0] == "-":
return 0/0
return a[0]
N = int(input())
ans = [" "] * (2*N)
def nibu(R,B):
if abs(R-B)==1:
return min(R,B),max(R,B)+N-1
c = (R+B)//2
print("?",*range(c+1,c+N+1))
a = input()
if a == 'R':
return nibu(c,B)
else:
return nibu(R,c)
print("?",*range(1,N+1))
if input() == "R":
R,B = nibu(0,N)
else:
R,B = nibu(N,0)
neutral1 = range(R+2,B+1)
neutral2l = range(1,R+1)
neutral2r = range(B+2,2*N+1)
for i in range(R+1):
print("?",*neutral1,i+1)
ans[i] = input()
for i in range(R+2,B+1):
print("?",*neutral2l,*neutral2r,i)
ans[i-1] = input()
for i in range(B+1,2*N+1):
print("?",*neutral1,i)
ans[i-1] = input()
print("!","".join(ans))
```
No
| 8,873 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an interactive task.
We have 2N balls arranged in a row, numbered 1, 2, 3, ..., 2N from left to right, where N is an odd number. Among them, there are N red balls and N blue balls.
While blindfolded, you are challenged to guess the color of every ball correctly, by asking at most 210 questions of the following form:
* You choose any N of the 2N balls and ask whether there are more red balls than blue balls or not among those N balls.
Now, let us begin.
Constraints
* 1 \leq N \leq 99
* N is an odd number.
* * *
Example
Input
Output
Submitted Solution:
```
import math
import sys
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
# divisors.sort()
return divisors
#a = list(map(int, input().split()))
n = int(input())
left = [i+1 for i in range(n)]
right = [i+n+1 for i in range(n)]
print('!',' '.join(map(str,left)))
```
No
| 8,874 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an interactive task.
We have 2N balls arranged in a row, numbered 1, 2, 3, ..., 2N from left to right, where N is an odd number. Among them, there are N red balls and N blue balls.
While blindfolded, you are challenged to guess the color of every ball correctly, by asking at most 210 questions of the following form:
* You choose any N of the 2N balls and ask whether there are more red balls than blue balls or not among those N balls.
Now, let us begin.
Constraints
* 1 \leq N \leq 99
* N is an odd number.
* * *
Example
Input
Output
Submitted Solution:
```
from itertools import chain
def query(indices):
print('? '+' '.join(map(lambda x: str(x+1),indices)), flush=True)
r = input()
if r == '-1':
exit()
return r == 'Red'
def answer(colors):
print('! '+''.join(map(lambda x: 'R' if x else 'B', colors)), flush=True)
def bisect(ng, ok, judge):
while abs(ng-ok) > 1:
m = (ng+ok)//2
if judge(m):
ok = m
else:
ng = m
return ok
from random import shuffle
def solve(N):
# detect change
check = lambda i: query(range(i,i+N)) if i <= N else query(chain(range(i-N),range(i,2*N)))
L = list(range(2*N))
shuffle(L)
x = L[-1]
orig = check(x)
for y in reversed(L[:-1]):
if orig != check(y):
break
if y < x:
x -= N*2
while abs(x-y) > 1:
mid = (x+y)//2
r = check((mid)%(2*N))
if r == orig:
x = mid
else:
y = mid
x %= 2*N
res = [None]*(2*N)
a,b = x, (x+N)%(2*N)
res[a] = orig
res[b] = not orig
# [i+1, ... , i+N] is even
n1 = list(range(a+1,b)) if a < b else list(chain(range(a+1,2*N),range(0,b)))
# [0...i-1] + [i+N+2, ... 2*N] is even
n2 = list(range(b+1,a)) if b < a else list(chain(range(b+1,2*N),range(0,a)))
for i in n1:
res[i] = query(n2+[i])
for i in n2:
res[i] = query(n1+[i])
answer(res)
if __name__ == '__main__':
N = int(input())
solve(N)
```
No
| 8,875 |
Provide a correct Python 3 solution for this coding contest problem.
The door of Snuke's laboratory is locked with a security code.
The security code is a 4-digit number. We say the security code is hard to enter when it contains two consecutive digits that are the same.
You are given the current security code S. If S is hard to enter, print `Bad`; otherwise, print `Good`.
Constraints
* S is a 4-character string consisting of digits.
Input
Input is given from Standard Input in the following format:
S
Output
If S is hard to enter, print `Bad`; otherwise, print `Good`.
Examples
Input
3776
Output
Bad
Input
8080
Output
Good
Input
1333
Output
Bad
Input
0024
Output
Bad
"Correct Solution:
```
s=input()
a=0
for i in range(3):
if s[i]==s[i+1]:
a+=1
print('Bad' if a>0 else 'Good')
```
| 8,876 |
Provide a correct Python 3 solution for this coding contest problem.
The door of Snuke's laboratory is locked with a security code.
The security code is a 4-digit number. We say the security code is hard to enter when it contains two consecutive digits that are the same.
You are given the current security code S. If S is hard to enter, print `Bad`; otherwise, print `Good`.
Constraints
* S is a 4-character string consisting of digits.
Input
Input is given from Standard Input in the following format:
S
Output
If S is hard to enter, print `Bad`; otherwise, print `Good`.
Examples
Input
3776
Output
Bad
Input
8080
Output
Good
Input
1333
Output
Bad
Input
0024
Output
Bad
"Correct Solution:
```
s=input()
print(["Good","Bad"][s[0]==s[1] or s[1]==s[2] or s[2]==s[3]])
```
| 8,877 |
Provide a correct Python 3 solution for this coding contest problem.
The door of Snuke's laboratory is locked with a security code.
The security code is a 4-digit number. We say the security code is hard to enter when it contains two consecutive digits that are the same.
You are given the current security code S. If S is hard to enter, print `Bad`; otherwise, print `Good`.
Constraints
* S is a 4-character string consisting of digits.
Input
Input is given from Standard Input in the following format:
S
Output
If S is hard to enter, print `Bad`; otherwise, print `Good`.
Examples
Input
3776
Output
Bad
Input
8080
Output
Good
Input
1333
Output
Bad
Input
0024
Output
Bad
"Correct Solution:
```
N=input()
print("Bad" if N[0]==N[1] or N[1]==N[2] or N[2]==N[3] else "Good")
```
| 8,878 |
Provide a correct Python 3 solution for this coding contest problem.
The door of Snuke's laboratory is locked with a security code.
The security code is a 4-digit number. We say the security code is hard to enter when it contains two consecutive digits that are the same.
You are given the current security code S. If S is hard to enter, print `Bad`; otherwise, print `Good`.
Constraints
* S is a 4-character string consisting of digits.
Input
Input is given from Standard Input in the following format:
S
Output
If S is hard to enter, print `Bad`; otherwise, print `Good`.
Examples
Input
3776
Output
Bad
Input
8080
Output
Good
Input
1333
Output
Bad
Input
0024
Output
Bad
"Correct Solution:
```
w=input()
print("BGaodo d"[w[0]!=w[1]!=w[2]!=w[3]::2])
```
| 8,879 |
Provide a correct Python 3 solution for this coding contest problem.
The door of Snuke's laboratory is locked with a security code.
The security code is a 4-digit number. We say the security code is hard to enter when it contains two consecutive digits that are the same.
You are given the current security code S. If S is hard to enter, print `Bad`; otherwise, print `Good`.
Constraints
* S is a 4-character string consisting of digits.
Input
Input is given from Standard Input in the following format:
S
Output
If S is hard to enter, print `Bad`; otherwise, print `Good`.
Examples
Input
3776
Output
Bad
Input
8080
Output
Good
Input
1333
Output
Bad
Input
0024
Output
Bad
"Correct Solution:
```
S = input()
A = 'Good'
for i in range(3):
if S[i] == S[i+1]:
A = 'Bad'
print(A)
```
| 8,880 |
Provide a correct Python 3 solution for this coding contest problem.
The door of Snuke's laboratory is locked with a security code.
The security code is a 4-digit number. We say the security code is hard to enter when it contains two consecutive digits that are the same.
You are given the current security code S. If S is hard to enter, print `Bad`; otherwise, print `Good`.
Constraints
* S is a 4-character string consisting of digits.
Input
Input is given from Standard Input in the following format:
S
Output
If S is hard to enter, print `Bad`; otherwise, print `Good`.
Examples
Input
3776
Output
Bad
Input
8080
Output
Good
Input
1333
Output
Bad
Input
0024
Output
Bad
"Correct Solution:
```
a = input()
print('Good' if a[0] != a[1] !=a[2] !=a[3] else 'Bad')
```
| 8,881 |
Provide a correct Python 3 solution for this coding contest problem.
The door of Snuke's laboratory is locked with a security code.
The security code is a 4-digit number. We say the security code is hard to enter when it contains two consecutive digits that are the same.
You are given the current security code S. If S is hard to enter, print `Bad`; otherwise, print `Good`.
Constraints
* S is a 4-character string consisting of digits.
Input
Input is given from Standard Input in the following format:
S
Output
If S is hard to enter, print `Bad`; otherwise, print `Good`.
Examples
Input
3776
Output
Bad
Input
8080
Output
Good
Input
1333
Output
Bad
Input
0024
Output
Bad
"Correct Solution:
```
s=input()
if not any(s[i]==s[i+1] for i in range(3)):
print('Good')
else:
print('Bad')
```
| 8,882 |
Provide a correct Python 3 solution for this coding contest problem.
The door of Snuke's laboratory is locked with a security code.
The security code is a 4-digit number. We say the security code is hard to enter when it contains two consecutive digits that are the same.
You are given the current security code S. If S is hard to enter, print `Bad`; otherwise, print `Good`.
Constraints
* S is a 4-character string consisting of digits.
Input
Input is given from Standard Input in the following format:
S
Output
If S is hard to enter, print `Bad`; otherwise, print `Good`.
Examples
Input
3776
Output
Bad
Input
8080
Output
Good
Input
1333
Output
Bad
Input
0024
Output
Bad
"Correct Solution:
```
S=input()
if S[0]!=S[1] and S[1]!=S[2] and S[2]!=S[3]:
print("Good")
else:
print("Bad")
```
| 8,883 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The door of Snuke's laboratory is locked with a security code.
The security code is a 4-digit number. We say the security code is hard to enter when it contains two consecutive digits that are the same.
You are given the current security code S. If S is hard to enter, print `Bad`; otherwise, print `Good`.
Constraints
* S is a 4-character string consisting of digits.
Input
Input is given from Standard Input in the following format:
S
Output
If S is hard to enter, print `Bad`; otherwise, print `Good`.
Examples
Input
3776
Output
Bad
Input
8080
Output
Good
Input
1333
Output
Bad
Input
0024
Output
Bad
Submitted Solution:
```
S = input()
print("Bad") if S[0] == S[1] or S[1] == S[2] or S[2] == S[3] else print("Good")
```
Yes
| 8,884 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The door of Snuke's laboratory is locked with a security code.
The security code is a 4-digit number. We say the security code is hard to enter when it contains two consecutive digits that are the same.
You are given the current security code S. If S is hard to enter, print `Bad`; otherwise, print `Good`.
Constraints
* S is a 4-character string consisting of digits.
Input
Input is given from Standard Input in the following format:
S
Output
If S is hard to enter, print `Bad`; otherwise, print `Good`.
Examples
Input
3776
Output
Bad
Input
8080
Output
Good
Input
1333
Output
Bad
Input
0024
Output
Bad
Submitted Solution:
```
a, b, c, d = list(input())
print('Bad' if a==b or b==c or c==d else 'Good')
```
Yes
| 8,885 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The door of Snuke's laboratory is locked with a security code.
The security code is a 4-digit number. We say the security code is hard to enter when it contains two consecutive digits that are the same.
You are given the current security code S. If S is hard to enter, print `Bad`; otherwise, print `Good`.
Constraints
* S is a 4-character string consisting of digits.
Input
Input is given from Standard Input in the following format:
S
Output
If S is hard to enter, print `Bad`; otherwise, print `Good`.
Examples
Input
3776
Output
Bad
Input
8080
Output
Good
Input
1333
Output
Bad
Input
0024
Output
Bad
Submitted Solution:
```
import re;print(re.search(r'(.)\1',input())and'Bad'or'Good')
```
Yes
| 8,886 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The door of Snuke's laboratory is locked with a security code.
The security code is a 4-digit number. We say the security code is hard to enter when it contains two consecutive digits that are the same.
You are given the current security code S. If S is hard to enter, print `Bad`; otherwise, print `Good`.
Constraints
* S is a 4-character string consisting of digits.
Input
Input is given from Standard Input in the following format:
S
Output
If S is hard to enter, print `Bad`; otherwise, print `Good`.
Examples
Input
3776
Output
Bad
Input
8080
Output
Good
Input
1333
Output
Bad
Input
0024
Output
Bad
Submitted Solution:
```
S = input()
print("Good" if S[0] != S[1] != S[2] != S[3] else "Bad")
```
Yes
| 8,887 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The door of Snuke's laboratory is locked with a security code.
The security code is a 4-digit number. We say the security code is hard to enter when it contains two consecutive digits that are the same.
You are given the current security code S. If S is hard to enter, print `Bad`; otherwise, print `Good`.
Constraints
* S is a 4-character string consisting of digits.
Input
Input is given from Standard Input in the following format:
S
Output
If S is hard to enter, print `Bad`; otherwise, print `Good`.
Examples
Input
3776
Output
Bad
Input
8080
Output
Good
Input
1333
Output
Bad
Input
0024
Output
Bad
Submitted Solution:
```
s=input()
for i in range(3):
if s[i]==s[i+1]:
ans=1
else:
ans=0
print("Bad" if ans==1 else "Good")
```
No
| 8,888 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The door of Snuke's laboratory is locked with a security code.
The security code is a 4-digit number. We say the security code is hard to enter when it contains two consecutive digits that are the same.
You are given the current security code S. If S is hard to enter, print `Bad`; otherwise, print `Good`.
Constraints
* S is a 4-character string consisting of digits.
Input
Input is given from Standard Input in the following format:
S
Output
If S is hard to enter, print `Bad`; otherwise, print `Good`.
Examples
Input
3776
Output
Bad
Input
8080
Output
Good
Input
1333
Output
Bad
Input
0024
Output
Bad
Submitted Solution:
```
import re
def judge(S):
S_list = list(str(S)) #list化
i_pure = None
for i in S_list:
if i == i_pure:
return 'Bad'
i_pure = i
return 'Good'
S = ['3776','8080','1333','0024']
for s in S:
print(judge(s))
```
No
| 8,889 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The door of Snuke's laboratory is locked with a security code.
The security code is a 4-digit number. We say the security code is hard to enter when it contains two consecutive digits that are the same.
You are given the current security code S. If S is hard to enter, print `Bad`; otherwise, print `Good`.
Constraints
* S is a 4-character string consisting of digits.
Input
Input is given from Standard Input in the following format:
S
Output
If S is hard to enter, print `Bad`; otherwise, print `Good`.
Examples
Input
3776
Output
Bad
Input
8080
Output
Good
Input
1333
Output
Bad
Input
0024
Output
Bad
Submitted Solution:
```
a=input()
b=False
for i in range(3):
if a[i+1]==a[i]:
b=True
if b:
print(“Bad”)
else:
print(“Good”)
```
No
| 8,890 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The door of Snuke's laboratory is locked with a security code.
The security code is a 4-digit number. We say the security code is hard to enter when it contains two consecutive digits that are the same.
You are given the current security code S. If S is hard to enter, print `Bad`; otherwise, print `Good`.
Constraints
* S is a 4-character string consisting of digits.
Input
Input is given from Standard Input in the following format:
S
Output
If S is hard to enter, print `Bad`; otherwise, print `Good`.
Examples
Input
3776
Output
Bad
Input
8080
Output
Good
Input
1333
Output
Bad
Input
0024
Output
Bad
Submitted Solution:
```
S = str(input())
ans = 'Good'
for i in range(2):
if S[i] == S[i+1]:
ans = 'Bad'
Print(ans)
```
No
| 8,891 |
Provide a correct Python 3 solution for this coding contest problem.
There are N Snukes lining up in a row. You are given a string S of length N. The i-th Snuke from the front has two red balls if the i-th character in S is `0`; one red ball and one blue ball if the i-th character in S is `1`; two blue balls if the i-th character in S is `2`.
Takahashi has a sequence that is initially empty. Find the number of the possible sequences he may have after repeating the following procedure 2N times, modulo 998244353:
* Each Snuke who has one or more balls simultaneously chooses one of his balls and hand it to the Snuke in front of him, or hand it to Takahashi if he is the first Snuke in the row.
* Takahashi receives the ball and put it to the end of his sequence.
Constraints
* 1 \leq |S| \leq 2000
* S consists of `0`,`1` and `2`.
Note that the integer N is not directly given in input; it is given indirectly as the length of the string S.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of the possible sequences Takahashi may have after repeating the procedure 2N times, modulo 998244353.
Examples
Input
02
Output
3
Input
1210
Output
55
Input
12001021211100201020
Output
543589959
"Correct Solution:
```
mod = 998244353
def cmb(n, r, mod=mod):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
NN = 10**5 # 使うデータによって変える
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, NN + 1 ):
g1.append( ( g1[-1] * i ) % mod )
inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
g2.append( (g2[-1] * inverse[-1]) % mod )
import sys
input = sys.stdin.readline
S = list(input().rstrip())
L = len(S)
dp = [[0]*(L+1) for _ in range(L+1)]
dp[0][0] = 1
rmax = [0, 0]
rmin = [0, 0]
rsum = 0
for i, s in enumerate(S):
p = int(s)
rsum += p
if p == 0:
rmin[1] += 2
elif p == 1:
rmax[1] += 1
rmin[1] += 1
else:
rmax[1] += 2
if rmax[1] > 0:
rmax[0] += 1
rmax[1] -= 1
if rmin[1] > 0:
rmin[0] += 1
rmin[1] -= 1
for j in range(i+1):
if rmax[0] >= j+1:
dp[i+1][j+1] = (dp[i+1][j+1] + dp[i][j]) % mod
if rmin[0] >= (i+1) - j:
dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % mod
ans = 0
for j in range(L+1):
ans = (ans + dp[L][j] * cmb(L, rsum-j)) % mod
print(ans)
```
| 8,892 |
Provide a correct Python 3 solution for this coding contest problem.
There are N Snukes lining up in a row. You are given a string S of length N. The i-th Snuke from the front has two red balls if the i-th character in S is `0`; one red ball and one blue ball if the i-th character in S is `1`; two blue balls if the i-th character in S is `2`.
Takahashi has a sequence that is initially empty. Find the number of the possible sequences he may have after repeating the following procedure 2N times, modulo 998244353:
* Each Snuke who has one or more balls simultaneously chooses one of his balls and hand it to the Snuke in front of him, or hand it to Takahashi if he is the first Snuke in the row.
* Takahashi receives the ball and put it to the end of his sequence.
Constraints
* 1 \leq |S| \leq 2000
* S consists of `0`,`1` and `2`.
Note that the integer N is not directly given in input; it is given indirectly as the length of the string S.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of the possible sequences Takahashi may have after repeating the procedure 2N times, modulo 998244353.
Examples
Input
02
Output
3
Input
1210
Output
55
Input
12001021211100201020
Output
543589959
"Correct Solution:
```
S = input()
N = len(S)
from collections import defaultdict
reddic = defaultdict(int)
bludic = defaultdict(int)
redarray = [0] * (N+1)
bluarray = [0] * (N+1)
for e,c in enumerate(S):
if c == "2":
bludic[e+1] += 2
bluarray[e+1] += 2
elif c == "1":
reddic[e+1] += 1
bludic[e+1] += 1
redarray[e+1] += 1
bluarray[e+1] += 1
elif c == "0":
reddic[e+1] += 2
redarray[e+1] += 2
for i in range(1,N+1):
redarray[i] += redarray[i-1]
bluarray[i] += bluarray[i-1]
# print("redarray: ", redarray)
# print("bluarray: ", bluarray)
dp = [ [0] * (2*N+1) for _ in range(2*N+1)]
dp[0][0] = 1
MOD = 998244353
for p in range(1, 2*N+1):
for r in range(0, p):
idx = p if p <= N else N
if r < redarray[idx]:
dp[p][r+1] += dp[p-1][r] % MOD
if p-1-r < bluarray[idx]:
dp[p][r] += dp[p-1][r] % MOD
# print("{:3d}".format(p), dp[p])
print(dp[2*N][redarray[N]]%MOD)
```
| 8,893 |
Provide a correct Python 3 solution for this coding contest problem.
There are N Snukes lining up in a row. You are given a string S of length N. The i-th Snuke from the front has two red balls if the i-th character in S is `0`; one red ball and one blue ball if the i-th character in S is `1`; two blue balls if the i-th character in S is `2`.
Takahashi has a sequence that is initially empty. Find the number of the possible sequences he may have after repeating the following procedure 2N times, modulo 998244353:
* Each Snuke who has one or more balls simultaneously chooses one of his balls and hand it to the Snuke in front of him, or hand it to Takahashi if he is the first Snuke in the row.
* Takahashi receives the ball and put it to the end of his sequence.
Constraints
* 1 \leq |S| \leq 2000
* S consists of `0`,`1` and `2`.
Note that the integer N is not directly given in input; it is given indirectly as the length of the string S.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of the possible sequences Takahashi may have after repeating the procedure 2N times, modulo 998244353.
Examples
Input
02
Output
3
Input
1210
Output
55
Input
12001021211100201020
Output
543589959
"Correct Solution:
```
# 数え上げで制約が 2 乗っぽいのでどうせ dp だろという気持ちになる
# なんで入力が数字で与えられるのかを考えるとちょっと視界が開ける
# よく考えると、できる列の制約は
# 「赤い/青いボールはできる列の i 個目までに A[i]/B[i] 個使える」
# と表せることがわかる
# これに気付けばあとは
# dp[i][j] := i 個目まで並べたとき赤いボールを j 個使う場合の数
# とした dp が自然と思いつく
from itertools import accumulate
def main():
mod = 998244353
B = list(map(int, input()))
N = len(B)
A = [2-b for b in B] + [0]*N
B += [0] * N
a = b = 0
for i in range(2*N):
b += B[i]
if b > 0:
b -= 1
B[i] = 1
a += A[i]
if a > 0:
a -= 1
A[i] = 1
A = list(accumulate(A))
B = list(accumulate(B))
dp = [[0]*(2*N+2) for _ in range(2*N+1)]
dp[0][0] = 1
for i, (a, b) in enumerate(zip(A, B), 1):
for j in range(2*N+1):
if i - b <= j <= a:
dp[i][j] = (dp[i-1][j-1] + dp[i-1][j]) % mod
print(sum(dp[2*N]) % mod)
main()
```
| 8,894 |
Provide a correct Python 3 solution for this coding contest problem.
There are N Snukes lining up in a row. You are given a string S of length N. The i-th Snuke from the front has two red balls if the i-th character in S is `0`; one red ball and one blue ball if the i-th character in S is `1`; two blue balls if the i-th character in S is `2`.
Takahashi has a sequence that is initially empty. Find the number of the possible sequences he may have after repeating the following procedure 2N times, modulo 998244353:
* Each Snuke who has one or more balls simultaneously chooses one of his balls and hand it to the Snuke in front of him, or hand it to Takahashi if he is the first Snuke in the row.
* Takahashi receives the ball and put it to the end of his sequence.
Constraints
* 1 \leq |S| \leq 2000
* S consists of `0`,`1` and `2`.
Note that the integer N is not directly given in input; it is given indirectly as the length of the string S.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of the possible sequences Takahashi may have after repeating the procedure 2N times, modulo 998244353.
Examples
Input
02
Output
3
Input
1210
Output
55
Input
12001021211100201020
Output
543589959
"Correct Solution:
```
M=998244353
S=input()
N=len(S)
d=[[0]*4001 for _ in range(4001)]
d[0][0]=1
x=0
for i in range(2*N):
if i<N:
x+=int(S[i])
y=2*i+2-x
for j in range(i+1):
for k in range(2):d[j+1-k][i-j+k]+=i-y<=j-k<x and d[j][i-j]%M
print(d[x][y]%M)
```
| 8,895 |
Provide a correct Python 3 solution for this coding contest problem.
There are N Snukes lining up in a row. You are given a string S of length N. The i-th Snuke from the front has two red balls if the i-th character in S is `0`; one red ball and one blue ball if the i-th character in S is `1`; two blue balls if the i-th character in S is `2`.
Takahashi has a sequence that is initially empty. Find the number of the possible sequences he may have after repeating the following procedure 2N times, modulo 998244353:
* Each Snuke who has one or more balls simultaneously chooses one of his balls and hand it to the Snuke in front of him, or hand it to Takahashi if he is the first Snuke in the row.
* Takahashi receives the ball and put it to the end of his sequence.
Constraints
* 1 \leq |S| \leq 2000
* S consists of `0`,`1` and `2`.
Note that the integer N is not directly given in input; it is given indirectly as the length of the string S.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of the possible sequences Takahashi may have after repeating the procedure 2N times, modulo 998244353.
Examples
Input
02
Output
3
Input
1210
Output
55
Input
12001021211100201020
Output
543589959
"Correct Solution:
```
S=input()
N=len(S)
C=[0]
for i in range(N):
C.append(C[i]+int(S[i]))
for i in range(N):
C.append(C[N])
B=C[N]
DP=[[0]*(B+1) for i in range(2*N+1)]
DP[0][0]=1
mod=998244353
for i in range(2*N):
for j in range(B+1):
if 2*min(i+1,N)-C[i+1]>=i+1-j:
DP[i+1][j]=(DP[i+1][j]+DP[i][j])%mod
if j<C[i+1]:
DP[i+1][j+1]=DP[i][j]
print(DP[2*N][B])
```
| 8,896 |
Provide a correct Python 3 solution for this coding contest problem.
There are N Snukes lining up in a row. You are given a string S of length N. The i-th Snuke from the front has two red balls if the i-th character in S is `0`; one red ball and one blue ball if the i-th character in S is `1`; two blue balls if the i-th character in S is `2`.
Takahashi has a sequence that is initially empty. Find the number of the possible sequences he may have after repeating the following procedure 2N times, modulo 998244353:
* Each Snuke who has one or more balls simultaneously chooses one of his balls and hand it to the Snuke in front of him, or hand it to Takahashi if he is the first Snuke in the row.
* Takahashi receives the ball and put it to the end of his sequence.
Constraints
* 1 \leq |S| \leq 2000
* S consists of `0`,`1` and `2`.
Note that the integer N is not directly given in input; it is given indirectly as the length of the string S.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of the possible sequences Takahashi may have after repeating the procedure 2N times, modulo 998244353.
Examples
Input
02
Output
3
Input
1210
Output
55
Input
12001021211100201020
Output
543589959
"Correct Solution:
```
s=input()
N=len(s)
table=[]
mod=998244353
if s[0]=="0":
table.append((2,0))
elif s[0]=="1":
table.append((1,1))
elif s[0]=="2":
table.append((0,2))
for i in range(1,N):
r,b=table[-1]
if s[i]=="0":
r,b=table[-1]
table.append((r+2,b))
elif s[i]=="1":
r,b=table[-1]
table.append((r+1,b+1))
elif s[i]=="2":
r,b=table[-1]
table.append((r,b+2))
for i in range(N):
table.append(table[-1])
dp=[[0]*(2*N+1) for i in range(2*N+1)]
dp[0][0]=1
for i in range(2*N):
for k in range(2*N):
if k+1<=table[i][0]:
dp[i+1][k+1]=(dp[i+1][k+1]+dp[i][k])%mod
if i+1-k<=table[i][1]:
dp[i+1][k]=(dp[i+1][k]+dp[i][k])%mod
ans=0
for k in range(2*N+1):
ans=(ans+dp[2*N][k])%mod
print(ans)
```
| 8,897 |
Provide a correct Python 3 solution for this coding contest problem.
There are N Snukes lining up in a row. You are given a string S of length N. The i-th Snuke from the front has two red balls if the i-th character in S is `0`; one red ball and one blue ball if the i-th character in S is `1`; two blue balls if the i-th character in S is `2`.
Takahashi has a sequence that is initially empty. Find the number of the possible sequences he may have after repeating the following procedure 2N times, modulo 998244353:
* Each Snuke who has one or more balls simultaneously chooses one of his balls and hand it to the Snuke in front of him, or hand it to Takahashi if he is the first Snuke in the row.
* Takahashi receives the ball and put it to the end of his sequence.
Constraints
* 1 \leq |S| \leq 2000
* S consists of `0`,`1` and `2`.
Note that the integer N is not directly given in input; it is given indirectly as the length of the string S.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of the possible sequences Takahashi may have after repeating the procedure 2N times, modulo 998244353.
Examples
Input
02
Output
3
Input
1210
Output
55
Input
12001021211100201020
Output
543589959
"Correct Solution:
```
from itertools import accumulate
import sys
input = sys.stdin.readline
mod = 998244353
S = list(map(int, input().rstrip()))
N = len(S)
front = [0] * N
back = [0] * N
cum = list(accumulate(S))
for i in range(N-1):
front[i+1] = max(front[i], i + 1 - cum[i])
back[i+1] = max(back[i], cum[i] - (i + 1))
cnt = cum[-1]
dp = [1] * (2 * N - cnt + 1)
for i in range(N - 1, -1, -1):
for c in range(S[i]):
f = front[i]
b = 2 * N - cum[-1]
for j in range(N):
if back[j] == cnt:
b = 2 * j - cum[j-1]
break
for j in range(b - 1, f - 1, -1):
dp[j] = (dp[j] + dp[j+1]) % mod
for j in range(f - 1, -1, -1):
dp[j] = dp[j+1]
cnt -= 1
print(dp[0])
```
| 8,898 |
Provide a correct Python 3 solution for this coding contest problem.
There are N Snukes lining up in a row. You are given a string S of length N. The i-th Snuke from the front has two red balls if the i-th character in S is `0`; one red ball and one blue ball if the i-th character in S is `1`; two blue balls if the i-th character in S is `2`.
Takahashi has a sequence that is initially empty. Find the number of the possible sequences he may have after repeating the following procedure 2N times, modulo 998244353:
* Each Snuke who has one or more balls simultaneously chooses one of his balls and hand it to the Snuke in front of him, or hand it to Takahashi if he is the first Snuke in the row.
* Takahashi receives the ball and put it to the end of his sequence.
Constraints
* 1 \leq |S| \leq 2000
* S consists of `0`,`1` and `2`.
Note that the integer N is not directly given in input; it is given indirectly as the length of the string S.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of the possible sequences Takahashi may have after repeating the procedure 2N times, modulo 998244353.
Examples
Input
02
Output
3
Input
1210
Output
55
Input
12001021211100201020
Output
543589959
"Correct Solution:
```
S=input()
N=len(S)
mod=998244353
red=[0]*N
blue=[0]*N
for i in range(N):
if S[i]=="0":
red[i]+=2
elif S[i]=="1":
red[i]+=1
blue[i]+=1
else:
blue[i]+=2
if i!=0:
red[i]+=red[i-1]
blue[i]+=blue[i-1]
R=red[-1]
B=blue[-1]
dp=[[0 for i in range(2*N+1)] for i in range(2*N+1)]
dp[2*N][R]=1
for i in range(2*N-1,-1,-1):
for j in range(2*N+1):
if i>=N:
r=R-j
b=B-(i-j)
if r and 2*N>=j+1:
dp[i][j]+=dp[i+1][j+1]
dp[i][j]%=mod
if b:
dp[i][j]+=dp[i+1][j]
dp[i][j]%=mod
else:
r=red[i]-j
b=blue[i]-(i-j)
if r and 2*N>=j+1:
dp[i][j]+=dp[i+1][j+1]
dp[i][j]%=mod
if b:
dp[i][j]+=dp[i+1][j]
dp[i][j]%=mod
print(dp[0][0])
```
| 8,899 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.