message stringlengths 2 44.5k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 42 109k | cluster float64 5 5 | __index_level_0__ int64 84 217k |
|---|---|---|---|---|---|
Provide a correct Python 3 solution for this coding contest problem.
You are given four integers: H, W, h and w (1 ≤ h ≤ H, 1 ≤ w ≤ W). Determine whether there exists a matrix such that all of the following conditions are held, and construct one such matrix if the answer is positive:
* The matrix has H rows and W columns.
* Each element of the matrix is an integer between -10^9 and 10^9 (inclusive).
* The sum of all the elements of the matrix is positive.
* The sum of all the elements within every subrectangle with h rows and w columns in the matrix is negative.
Constraints
* 1 ≤ h ≤ H ≤ 500
* 1 ≤ w ≤ W ≤ 500
Input
Input is given from Standard Input in the following format:
H W h w
Output
If there does not exist a matrix that satisfies all of the conditions, print `No`.
Otherwise, print `Yes` in the first line, and print a matrix in the subsequent lines in the following format:
a_{11} ... a_{1W}
:
a_{H1} ... a_{HW}
Here, a_{ij} represents the (i,\ j) element of the matrix.
Examples
Input
3 3 2 2
Output
Yes
1 1 1
1 -4 1
1 1 1
Input
2 4 1 2
Output
No
Input
3 4 2 3
Output
Yes
2 -5 8 7
3 -5 -4 -5
2 1 -1 7 | instruction | 0 | 69,673 | 5 | 139,346 |
"Correct Solution:
```
H, W, h, w = map(int, input().split())
def solve(H, W, h, w):
if (W % w == 0 and H % h == 0):
return False, []
if (W % w == 0):
return True, solve_vertical(H, W, h, w)
return True, solve_horizontal(H, W, h, w)
def solve_horizontal(H, W, h, w):
return [solve_horizontal_core(W, w)] * H
def solve_horizontal_core(W, w):
m, r = divmod(W, w)
row = [0] * W
row[0] = m + 1
row[w - 1] = - m - 2
for i in range(w, W):
row[i] = row[i - w]
return row
def solve_vertical(H, W, h, w):
col = solve_horizontal_core(H, h)
m = []
for c in col:
m.append([c] * W)
return m
yesno, mat = solve(H, W, h, w)
if yesno:
print('Yes')
for row in mat:
print(*row)
else:
print('No')
``` | output | 1 | 69,673 | 5 | 139,347 |
Provide a correct Python 3 solution for this coding contest problem.
You are given four integers: H, W, h and w (1 ≤ h ≤ H, 1 ≤ w ≤ W). Determine whether there exists a matrix such that all of the following conditions are held, and construct one such matrix if the answer is positive:
* The matrix has H rows and W columns.
* Each element of the matrix is an integer between -10^9 and 10^9 (inclusive).
* The sum of all the elements of the matrix is positive.
* The sum of all the elements within every subrectangle with h rows and w columns in the matrix is negative.
Constraints
* 1 ≤ h ≤ H ≤ 500
* 1 ≤ w ≤ W ≤ 500
Input
Input is given from Standard Input in the following format:
H W h w
Output
If there does not exist a matrix that satisfies all of the conditions, print `No`.
Otherwise, print `Yes` in the first line, and print a matrix in the subsequent lines in the following format:
a_{11} ... a_{1W}
:
a_{H1} ... a_{HW}
Here, a_{ij} represents the (i,\ j) element of the matrix.
Examples
Input
3 3 2 2
Output
Yes
1 1 1
1 -4 1
1 1 1
Input
2 4 1 2
Output
No
Input
3 4 2 3
Output
Yes
2 -5 8 7
3 -5 -4 -5
2 1 -1 7 | instruction | 0 | 69,674 | 5 | 139,348 |
"Correct Solution:
```
#設定
import sys
input = sys.stdin.buffer.readline
#ライブラリインポート
from collections import defaultdict
#入力受け取り
def getlist():
return list(map(int, input().split()))
#処理内容
def main():
H, W, h, w = getlist()
L = [[1] * W for i in range(H)]
if h * w != 1:
x = (10 ** 9 - 1) // (h * w - 1)
for i in range(H):
for j in range(W):
L[i][j] = x
for i in range(H // h):
for j in range(W // w):
L[(i + 1) * h - 1][(j + 1) * w - 1] = - 10 ** 9
s = 0
for i in range(H):
for j in range(W):
s += L[i][j]
if s < 0:
print("No")
return
print("Yes")
for i in range(H):
print(" ".join(list(map(str, L[i]))))
if __name__ == '__main__':
main()
``` | output | 1 | 69,674 | 5 | 139,349 |
Provide a correct Python 3 solution for this coding contest problem.
You are given four integers: H, W, h and w (1 ≤ h ≤ H, 1 ≤ w ≤ W). Determine whether there exists a matrix such that all of the following conditions are held, and construct one such matrix if the answer is positive:
* The matrix has H rows and W columns.
* Each element of the matrix is an integer between -10^9 and 10^9 (inclusive).
* The sum of all the elements of the matrix is positive.
* The sum of all the elements within every subrectangle with h rows and w columns in the matrix is negative.
Constraints
* 1 ≤ h ≤ H ≤ 500
* 1 ≤ w ≤ W ≤ 500
Input
Input is given from Standard Input in the following format:
H W h w
Output
If there does not exist a matrix that satisfies all of the conditions, print `No`.
Otherwise, print `Yes` in the first line, and print a matrix in the subsequent lines in the following format:
a_{11} ... a_{1W}
:
a_{H1} ... a_{HW}
Here, a_{ij} represents the (i,\ j) element of the matrix.
Examples
Input
3 3 2 2
Output
Yes
1 1 1
1 -4 1
1 1 1
Input
2 4 1 2
Output
No
Input
3 4 2 3
Output
Yes
2 -5 8 7
3 -5 -4 -5
2 1 -1 7 | instruction | 0 | 69,675 | 5 | 139,350 |
"Correct Solution:
```
h, w, h0, w0 = map(int, input().split())
if h0 == w0 == 1:
print("No")
exit()
x, y = h // h0, w // w0
a1cnt = h0 * w0 - 1
a1sum, a2sum = h * w - x * y, x * y
a1 = ((pow(10, 9) - 1) // a1cnt)
a2 = -(a1 * a1cnt + 1)
asum = a1 * a1sum + a2 * a2sum
print("Yes" if asum > 0 else "No")
if asum > 0:
for i in range(1, h + 1):
a = [0] * w
for j in range(1, w + 1):
a[j - 1] = a2 if i % h0 == j % w0 == 0 else a1
print(*a)
``` | output | 1 | 69,675 | 5 | 139,351 |
Provide a correct Python 3 solution for this coding contest problem.
You are given four integers: H, W, h and w (1 ≤ h ≤ H, 1 ≤ w ≤ W). Determine whether there exists a matrix such that all of the following conditions are held, and construct one such matrix if the answer is positive:
* The matrix has H rows and W columns.
* Each element of the matrix is an integer between -10^9 and 10^9 (inclusive).
* The sum of all the elements of the matrix is positive.
* The sum of all the elements within every subrectangle with h rows and w columns in the matrix is negative.
Constraints
* 1 ≤ h ≤ H ≤ 500
* 1 ≤ w ≤ W ≤ 500
Input
Input is given from Standard Input in the following format:
H W h w
Output
If there does not exist a matrix that satisfies all of the conditions, print `No`.
Otherwise, print `Yes` in the first line, and print a matrix in the subsequent lines in the following format:
a_{11} ... a_{1W}
:
a_{H1} ... a_{HW}
Here, a_{ij} represents the (i,\ j) element of the matrix.
Examples
Input
3 3 2 2
Output
Yes
1 1 1
1 -4 1
1 1 1
Input
2 4 1 2
Output
No
Input
3 4 2 3
Output
Yes
2 -5 8 7
3 -5 -4 -5
2 1 -1 7 | instruction | 0 | 69,676 | 5 | 139,352 |
"Correct Solution:
```
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
H,W,h,w = LI()
if W%w != 0:
s = [0]+[100000]*(w-1)
for i in range(W-w+1):
s.append(s[-w]-1)
a = [s[i]-s[i-1] for i in range(1,W+1)]
print("Yes")
for i in range(H):
print(*a)
elif H%h != 0:
H,W,h,w = W,H,w,h
s = [0]+[100000]*(w-1)
for i in range(W-w+1):
s.append(s[-w]-1)
a = [s[i]-s[i-1] for i in range(1,W+1)]
print("Yes")
ans = [[a[i]]*H for i in range(W)]
for i in range(W):
print(*ans[i])
else:
print("No")
return
#Solve
if __name__ == "__main__":
solve()
``` | output | 1 | 69,676 | 5 | 139,353 |
Provide a correct Python 3 solution for this coding contest problem.
You are given four integers: H, W, h and w (1 ≤ h ≤ H, 1 ≤ w ≤ W). Determine whether there exists a matrix such that all of the following conditions are held, and construct one such matrix if the answer is positive:
* The matrix has H rows and W columns.
* Each element of the matrix is an integer between -10^9 and 10^9 (inclusive).
* The sum of all the elements of the matrix is positive.
* The sum of all the elements within every subrectangle with h rows and w columns in the matrix is negative.
Constraints
* 1 ≤ h ≤ H ≤ 500
* 1 ≤ w ≤ W ≤ 500
Input
Input is given from Standard Input in the following format:
H W h w
Output
If there does not exist a matrix that satisfies all of the conditions, print `No`.
Otherwise, print `Yes` in the first line, and print a matrix in the subsequent lines in the following format:
a_{11} ... a_{1W}
:
a_{H1} ... a_{HW}
Here, a_{ij} represents the (i,\ j) element of the matrix.
Examples
Input
3 3 2 2
Output
Yes
1 1 1
1 -4 1
1 1 1
Input
2 4 1 2
Output
No
Input
3 4 2 3
Output
Yes
2 -5 8 7
3 -5 -4 -5
2 1 -1 7 | instruction | 0 | 69,677 | 5 | 139,354 |
"Correct Solution:
```
H,W,h,w=map(int,input().split())
if H%h==0 and W%w==0:
print("No")
else:
c=10**9
ans=[[(c-1)//(h*w-1) for i in range(W)] for j in range(H)]
for i in range(H):
for j in range(W):
if (i+1)%h==0 and (j+1)%w==0:
ans[i][j]=-c
if sum(ans[i][j] for i in range(H) for j in range(W))>0:
print("Yes")
for i in range(H):
print(*ans[i])
else:
print("No")
``` | output | 1 | 69,677 | 5 | 139,355 |
Provide a correct Python 3 solution for this coding contest problem.
You are given four integers: H, W, h and w (1 ≤ h ≤ H, 1 ≤ w ≤ W). Determine whether there exists a matrix such that all of the following conditions are held, and construct one such matrix if the answer is positive:
* The matrix has H rows and W columns.
* Each element of the matrix is an integer between -10^9 and 10^9 (inclusive).
* The sum of all the elements of the matrix is positive.
* The sum of all the elements within every subrectangle with h rows and w columns in the matrix is negative.
Constraints
* 1 ≤ h ≤ H ≤ 500
* 1 ≤ w ≤ W ≤ 500
Input
Input is given from Standard Input in the following format:
H W h w
Output
If there does not exist a matrix that satisfies all of the conditions, print `No`.
Otherwise, print `Yes` in the first line, and print a matrix in the subsequent lines in the following format:
a_{11} ... a_{1W}
:
a_{H1} ... a_{HW}
Here, a_{ij} represents the (i,\ j) element of the matrix.
Examples
Input
3 3 2 2
Output
Yes
1 1 1
1 -4 1
1 1 1
Input
2 4 1 2
Output
No
Input
3 4 2 3
Output
Yes
2 -5 8 7
3 -5 -4 -5
2 1 -1 7 | instruction | 0 | 69,678 | 5 | 139,356 |
"Correct Solution:
```
def compose(W, w):
A = [0]*W
S = [0]*(W+1)
S[W%w] = 1000
for j in range(W-w+1):
S[j+w] = S[j] - 1
for j in range(W):
A[j] = S[j+1] - S[j]
return A
H, W, h, w = map(int, input().split())
if H%h == 0 and W%w == 0:
print("No")
else:
print("Yes")
if W%w:
S = compose(W, w)
for _ in range(H):
print(*S)
else:
S = compose(H, h)
for i in range(H):
print(*[S[i] for _ in range(W)])
``` | output | 1 | 69,678 | 5 | 139,357 |
Provide a correct Python 3 solution for this coding contest problem.
You are given four integers: H, W, h and w (1 ≤ h ≤ H, 1 ≤ w ≤ W). Determine whether there exists a matrix such that all of the following conditions are held, and construct one such matrix if the answer is positive:
* The matrix has H rows and W columns.
* Each element of the matrix is an integer between -10^9 and 10^9 (inclusive).
* The sum of all the elements of the matrix is positive.
* The sum of all the elements within every subrectangle with h rows and w columns in the matrix is negative.
Constraints
* 1 ≤ h ≤ H ≤ 500
* 1 ≤ w ≤ W ≤ 500
Input
Input is given from Standard Input in the following format:
H W h w
Output
If there does not exist a matrix that satisfies all of the conditions, print `No`.
Otherwise, print `Yes` in the first line, and print a matrix in the subsequent lines in the following format:
a_{11} ... a_{1W}
:
a_{H1} ... a_{HW}
Here, a_{ij} represents the (i,\ j) element of the matrix.
Examples
Input
3 3 2 2
Output
Yes
1 1 1
1 -4 1
1 1 1
Input
2 4 1 2
Output
No
Input
3 4 2 3
Output
Yes
2 -5 8 7
3 -5 -4 -5
2 1 -1 7 | instruction | 0 | 69,679 | 5 | 139,358 |
"Correct Solution:
```
H, W, h, w = map(int, input().split())
if H%h == W%w == 0:
print('No')
exit(0)
print('Yes')
f = 0
a, b = W, w
if not W%w:
f = 1
a, b = H, h
l = [0]*(a+1)
l[1] = 10**6
for i in range(2, a+1):
if i >= b:
l[i] = l[i-b] - 1
else:
l[i] = l[i-1] - 1
assert(l[-1] > 0)
g = [l[i+1] - l[i] for i in range(a)]
if f:
for x in g:
print(*([x]*W))
else:
for _ in range(H):
print(*g)
``` | output | 1 | 69,679 | 5 | 139,359 |
Provide a correct Python 3 solution for this coding contest problem.
You are given four integers: H, W, h and w (1 ≤ h ≤ H, 1 ≤ w ≤ W). Determine whether there exists a matrix such that all of the following conditions are held, and construct one such matrix if the answer is positive:
* The matrix has H rows and W columns.
* Each element of the matrix is an integer between -10^9 and 10^9 (inclusive).
* The sum of all the elements of the matrix is positive.
* The sum of all the elements within every subrectangle with h rows and w columns in the matrix is negative.
Constraints
* 1 ≤ h ≤ H ≤ 500
* 1 ≤ w ≤ W ≤ 500
Input
Input is given from Standard Input in the following format:
H W h w
Output
If there does not exist a matrix that satisfies all of the conditions, print `No`.
Otherwise, print `Yes` in the first line, and print a matrix in the subsequent lines in the following format:
a_{11} ... a_{1W}
:
a_{H1} ... a_{HW}
Here, a_{ij} represents the (i,\ j) element of the matrix.
Examples
Input
3 3 2 2
Output
Yes
1 1 1
1 -4 1
1 1 1
Input
2 4 1 2
Output
No
Input
3 4 2 3
Output
Yes
2 -5 8 7
3 -5 -4 -5
2 1 -1 7 | instruction | 0 | 69,680 | 5 | 139,360 |
"Correct Solution:
```
H,W,h,w = map(int,input().split())
if H%h == 0 and W%w == 0:
print('No')
exit()
print('Yes')
n = 1000
if W%w:
m = -((w-1)*n + 1)
row = [m if i%w==w-1 else n for i in range(W)]
for i in range(H):
print(*row)
else:
m = -((h-1)*n + 1)
for i in range(H):
if i%h == h-1:
print(*([m] * W))
else:
print(*([n] * W))
``` | output | 1 | 69,680 | 5 | 139,361 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given four integers: H, W, h and w (1 ≤ h ≤ H, 1 ≤ w ≤ W). Determine whether there exists a matrix such that all of the following conditions are held, and construct one such matrix if the answer is positive:
* The matrix has H rows and W columns.
* Each element of the matrix is an integer between -10^9 and 10^9 (inclusive).
* The sum of all the elements of the matrix is positive.
* The sum of all the elements within every subrectangle with h rows and w columns in the matrix is negative.
Constraints
* 1 ≤ h ≤ H ≤ 500
* 1 ≤ w ≤ W ≤ 500
Input
Input is given from Standard Input in the following format:
H W h w
Output
If there does not exist a matrix that satisfies all of the conditions, print `No`.
Otherwise, print `Yes` in the first line, and print a matrix in the subsequent lines in the following format:
a_{11} ... a_{1W}
:
a_{H1} ... a_{HW}
Here, a_{ij} represents the (i,\ j) element of the matrix.
Examples
Input
3 3 2 2
Output
Yes
1 1 1
1 -4 1
1 1 1
Input
2 4 1 2
Output
No
Input
3 4 2 3
Output
Yes
2 -5 8 7
3 -5 -4 -5
2 1 -1 7
Submitted Solution:
```
import sys
input = sys.stdin.readline
H, W, h, w = map(int, input().split())
unit = 10 ** 9 - 1
c = H * W
for i in range(h - 1, H, h):
for j in range(w - 1, W, w): c -= 1
if c == 0:
print("No")
exit(0)
res = [[unit // c] * W for _ in range(H)]
for i in range(h - 1, H, h):
for j in range(w - 1, W, w): res[i][j] = -(unit // c * (h * w - 1) + 1)
if sum([sum(r) for r in res]) > 0:
print("Yes")
for r in res: print(*r)
else: print("No")
``` | instruction | 0 | 69,681 | 5 | 139,362 |
Yes | output | 1 | 69,681 | 5 | 139,363 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given four integers: H, W, h and w (1 ≤ h ≤ H, 1 ≤ w ≤ W). Determine whether there exists a matrix such that all of the following conditions are held, and construct one such matrix if the answer is positive:
* The matrix has H rows and W columns.
* Each element of the matrix is an integer between -10^9 and 10^9 (inclusive).
* The sum of all the elements of the matrix is positive.
* The sum of all the elements within every subrectangle with h rows and w columns in the matrix is negative.
Constraints
* 1 ≤ h ≤ H ≤ 500
* 1 ≤ w ≤ W ≤ 500
Input
Input is given from Standard Input in the following format:
H W h w
Output
If there does not exist a matrix that satisfies all of the conditions, print `No`.
Otherwise, print `Yes` in the first line, and print a matrix in the subsequent lines in the following format:
a_{11} ... a_{1W}
:
a_{H1} ... a_{HW}
Here, a_{ij} represents the (i,\ j) element of the matrix.
Examples
Input
3 3 2 2
Output
Yes
1 1 1
1 -4 1
1 1 1
Input
2 4 1 2
Output
No
Input
3 4 2 3
Output
Yes
2 -5 8 7
3 -5 -4 -5
2 1 -1 7
Submitted Solution:
```
def get_1d(H, h):
ret = [0] * (H + 1)
for s in range(h):
for x, i in enumerate(range(s, H, h)):
ret[i] = -x
for x, i in enumerate(range(H, 0, -h)):
ret[i] = x + 1
return [x1 - x0 for x0, x1 in zip(ret, ret[1:])]
def solve(H, W, h, w):
if H % h == 0 and W % w == 0:
return False
ans = []
if H % h > 0:
col = get_1d(H, h)
ans.extend([x] * W for x in col)
else:
row = get_1d(W, w)
ans.extend([row] * H)
return ans
H, W, h, w = map(int, input().split())
ans = solve(H, W, h, w)
if ans == False:
print('No')
else:
print('Yes')
for row in ans:
print(*row)
``` | instruction | 0 | 69,682 | 5 | 139,364 |
Yes | output | 1 | 69,682 | 5 | 139,365 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given four integers: H, W, h and w (1 ≤ h ≤ H, 1 ≤ w ≤ W). Determine whether there exists a matrix such that all of the following conditions are held, and construct one such matrix if the answer is positive:
* The matrix has H rows and W columns.
* Each element of the matrix is an integer between -10^9 and 10^9 (inclusive).
* The sum of all the elements of the matrix is positive.
* The sum of all the elements within every subrectangle with h rows and w columns in the matrix is negative.
Constraints
* 1 ≤ h ≤ H ≤ 500
* 1 ≤ w ≤ W ≤ 500
Input
Input is given from Standard Input in the following format:
H W h w
Output
If there does not exist a matrix that satisfies all of the conditions, print `No`.
Otherwise, print `Yes` in the first line, and print a matrix in the subsequent lines in the following format:
a_{11} ... a_{1W}
:
a_{H1} ... a_{HW}
Here, a_{ij} represents the (i,\ j) element of the matrix.
Examples
Input
3 3 2 2
Output
Yes
1 1 1
1 -4 1
1 1 1
Input
2 4 1 2
Output
No
Input
3 4 2 3
Output
Yes
2 -5 8 7
3 -5 -4 -5
2 1 -1 7
Submitted Solution:
```
H, W, h, w = map(int, input().split())
if H % h == 0 and W % w == 0:
print("No")
quit()
print("Yes")
def solve(H, W, h, w):
S = [0] * (W + 1)
S[W % w] = 1 + W // w
for i in range(w, W + 1):
S[i] = S[i - w] - 1
return [[S[i + 1] - S[i] for i in range(W)]] * H
if W % w != 0:
A = solve(H, W, h, w)
else:
A = [r for r in zip(*solve(W, H, w, h))]
for a in A:
print(*a)
``` | instruction | 0 | 69,683 | 5 | 139,366 |
Yes | output | 1 | 69,683 | 5 | 139,367 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given four integers: H, W, h and w (1 ≤ h ≤ H, 1 ≤ w ≤ W). Determine whether there exists a matrix such that all of the following conditions are held, and construct one such matrix if the answer is positive:
* The matrix has H rows and W columns.
* Each element of the matrix is an integer between -10^9 and 10^9 (inclusive).
* The sum of all the elements of the matrix is positive.
* The sum of all the elements within every subrectangle with h rows and w columns in the matrix is negative.
Constraints
* 1 ≤ h ≤ H ≤ 500
* 1 ≤ w ≤ W ≤ 500
Input
Input is given from Standard Input in the following format:
H W h w
Output
If there does not exist a matrix that satisfies all of the conditions, print `No`.
Otherwise, print `Yes` in the first line, and print a matrix in the subsequent lines in the following format:
a_{11} ... a_{1W}
:
a_{H1} ... a_{HW}
Here, a_{ij} represents the (i,\ j) element of the matrix.
Examples
Input
3 3 2 2
Output
Yes
1 1 1
1 -4 1
1 1 1
Input
2 4 1 2
Output
No
Input
3 4 2 3
Output
Yes
2 -5 8 7
3 -5 -4 -5
2 1 -1 7
Submitted Solution:
```
def solve(W,w):
A=[1]*W
for i in range(W-1,w-1,-1):
A[i-w]=A[i]+1
A[w-1::w]=[-i for i in range(1,W//w+1)]
for i in range(W-2,-1,-1):
A[i+1]-=A[i]
return A
H,W,h,w=map(int, input().split())
if W%w:
print("Yes")
A=solve(W,w)
for _ in range(H):
print(*A)
elif H%h:
print("Yes")
A=solve(H,h)
for i in range(H):
print(*[A[i]]*W)
else:
print("No")
``` | instruction | 0 | 69,684 | 5 | 139,368 |
Yes | output | 1 | 69,684 | 5 | 139,369 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given four integers: H, W, h and w (1 ≤ h ≤ H, 1 ≤ w ≤ W). Determine whether there exists a matrix such that all of the following conditions are held, and construct one such matrix if the answer is positive:
* The matrix has H rows and W columns.
* Each element of the matrix is an integer between -10^9 and 10^9 (inclusive).
* The sum of all the elements of the matrix is positive.
* The sum of all the elements within every subrectangle with h rows and w columns in the matrix is negative.
Constraints
* 1 ≤ h ≤ H ≤ 500
* 1 ≤ w ≤ W ≤ 500
Input
Input is given from Standard Input in the following format:
H W h w
Output
If there does not exist a matrix that satisfies all of the conditions, print `No`.
Otherwise, print `Yes` in the first line, and print a matrix in the subsequent lines in the following format:
a_{11} ... a_{1W}
:
a_{H1} ... a_{HW}
Here, a_{ij} represents the (i,\ j) element of the matrix.
Examples
Input
3 3 2 2
Output
Yes
1 1 1
1 -4 1
1 1 1
Input
2 4 1 2
Output
No
Input
3 4 2 3
Output
Yes
2 -5 8 7
3 -5 -4 -5
2 1 -1 7
Submitted Solution:
```
H, W, h, w = map(int, input().split())
if H % h == 0 and W % w == 0:
print("No")
else:
print("Yes")
R = [[0]*W for i in range(H)]
for i in range(0, H, h):
for j in range(0, W, w):
R[i][j] += 3
if i+h-1 < H:
R[i+h-1][j] += 3
if j+w-1 < W:
R[i][j+w-1] += 3
if i+h-1 < H and j+w-1 < W:
R[i+h-1][j+w-1] -= 10
for r in R:
print(*r)
``` | instruction | 0 | 69,685 | 5 | 139,370 |
No | output | 1 | 69,685 | 5 | 139,371 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given four integers: H, W, h and w (1 ≤ h ≤ H, 1 ≤ w ≤ W). Determine whether there exists a matrix such that all of the following conditions are held, and construct one such matrix if the answer is positive:
* The matrix has H rows and W columns.
* Each element of the matrix is an integer between -10^9 and 10^9 (inclusive).
* The sum of all the elements of the matrix is positive.
* The sum of all the elements within every subrectangle with h rows and w columns in the matrix is negative.
Constraints
* 1 ≤ h ≤ H ≤ 500
* 1 ≤ w ≤ W ≤ 500
Input
Input is given from Standard Input in the following format:
H W h w
Output
If there does not exist a matrix that satisfies all of the conditions, print `No`.
Otherwise, print `Yes` in the first line, and print a matrix in the subsequent lines in the following format:
a_{11} ... a_{1W}
:
a_{H1} ... a_{HW}
Here, a_{ij} represents the (i,\ j) element of the matrix.
Examples
Input
3 3 2 2
Output
Yes
1 1 1
1 -4 1
1 1 1
Input
2 4 1 2
Output
No
Input
3 4 2 3
Output
Yes
2 -5 8 7
3 -5 -4 -5
2 1 -1 7
Submitted Solution:
```
def main():
H, W, h, w = list(map(int, input().split()))
if H % h == 0 and W % w == 0:
print('No')
return
a = [[1] * W for _ in range(H)]
for x in range(h - 1, H, h):
for y in range(w - 1, W, w):
a[x][y] = -h * w
if h == 1 or w == 1:
for x in range(H):
for y in range(W):
if a[x][y] > 0:
a[x][y] = 10 ** 4
else:
a[x][y] = -1 - (h * w - 1) * 10 ** 4
s = 0
for i in range(H):
s += sum(a[i])
if s <= 0:
print('No')
else:
print('Yes')
for i in range(H):
print(*a[i])
if __name__ == '__main__':
main()
``` | instruction | 0 | 69,686 | 5 | 139,372 |
No | output | 1 | 69,686 | 5 | 139,373 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given four integers: H, W, h and w (1 ≤ h ≤ H, 1 ≤ w ≤ W). Determine whether there exists a matrix such that all of the following conditions are held, and construct one such matrix if the answer is positive:
* The matrix has H rows and W columns.
* Each element of the matrix is an integer between -10^9 and 10^9 (inclusive).
* The sum of all the elements of the matrix is positive.
* The sum of all the elements within every subrectangle with h rows and w columns in the matrix is negative.
Constraints
* 1 ≤ h ≤ H ≤ 500
* 1 ≤ w ≤ W ≤ 500
Input
Input is given from Standard Input in the following format:
H W h w
Output
If there does not exist a matrix that satisfies all of the conditions, print `No`.
Otherwise, print `Yes` in the first line, and print a matrix in the subsequent lines in the following format:
a_{11} ... a_{1W}
:
a_{H1} ... a_{HW}
Here, a_{ij} represents the (i,\ j) element of the matrix.
Examples
Input
3 3 2 2
Output
Yes
1 1 1
1 -4 1
1 1 1
Input
2 4 1 2
Output
No
Input
3 4 2 3
Output
Yes
2 -5 8 7
3 -5 -4 -5
2 1 -1 7
Submitted Solution:
```
print("No")
``` | instruction | 0 | 69,687 | 5 | 139,374 |
No | output | 1 | 69,687 | 5 | 139,375 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given four integers: H, W, h and w (1 ≤ h ≤ H, 1 ≤ w ≤ W). Determine whether there exists a matrix such that all of the following conditions are held, and construct one such matrix if the answer is positive:
* The matrix has H rows and W columns.
* Each element of the matrix is an integer between -10^9 and 10^9 (inclusive).
* The sum of all the elements of the matrix is positive.
* The sum of all the elements within every subrectangle with h rows and w columns in the matrix is negative.
Constraints
* 1 ≤ h ≤ H ≤ 500
* 1 ≤ w ≤ W ≤ 500
Input
Input is given from Standard Input in the following format:
H W h w
Output
If there does not exist a matrix that satisfies all of the conditions, print `No`.
Otherwise, print `Yes` in the first line, and print a matrix in the subsequent lines in the following format:
a_{11} ... a_{1W}
:
a_{H1} ... a_{HW}
Here, a_{ij} represents the (i,\ j) element of the matrix.
Examples
Input
3 3 2 2
Output
Yes
1 1 1
1 -4 1
1 1 1
Input
2 4 1 2
Output
No
Input
3 4 2 3
Output
Yes
2 -5 8 7
3 -5 -4 -5
2 1 -1 7
Submitted Solution:
```
H, W, h, w = map(int, input().split())
if H % h == 0 and W % w == 0:
print('No')
exit()
big = 1000000
mul = h*w-1
print('Yes')
for y in range(1, H+1):
arr = []
for x in range(1, W+1):
if y % h == 0 and x % w == 0:
arr.append(-(big*mul+1))
else:
arr.append(big)
print(' '.join(map(str, arr)))
``` | instruction | 0 | 69,688 | 5 | 139,376 |
No | output | 1 | 69,688 | 5 | 139,377 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer sequence a of length N. How many permutations p of the integers 1 through N satisfy the following condition?
* For each 1 ≤ i ≤ N, at least one of the following holds: p_i = a_i and p_{p_i} = a_i.
Find the count modulo 10^9 + 7.
Constraints
* 1 ≤ N ≤ 10^5
* a_i is an integer.
* 1 ≤ a_i ≤ N
Input
The input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N
Output
Print the number of the permutations p that satisfy the condition, modulo 10^9 + 7.
Examples
Input
3
1 2 3
Output
4
Input
2
1 1
Output
1
Input
3
2 1 1
Output
2
Input
3
1 1 1
Output
0
Input
13
2 1 4 3 6 7 5 9 10 8 8 9 11
Output
6
Submitted Solution:
```
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(lambda x: int(x), input().split(' ')))
print(n)
``` | instruction | 0 | 69,689 | 5 | 139,378 |
No | output | 1 | 69,689 | 5 | 139,379 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ujan needs some rest from cleaning, so he started playing with infinite sequences. He has two integers n and k. He creates an infinite sequence s by repeating the following steps.
1. Find k smallest distinct positive integers that are not in s. Let's call them u_{1}, u_{2}, …, u_{k} from the smallest to the largest.
2. Append u_{1}, u_{2}, …, u_{k} and ∑_{i=1}^{k} u_{i} to s in this order.
3. Go back to the first step.
Ujan will stop procrastinating when he writes the number n in the sequence s. Help him find the index of n in s. In other words, find the integer x such that s_{x} = n. It's possible to prove that all positive integers are included in s only once.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^{5}), the number of test cases.
Each of the following t lines contains two integers n and k (1 ≤ n ≤ 10^{18}, 2 ≤ k ≤ 10^{6}), the number to be found in the sequence s and the parameter used to create the sequence s.
Output
In each of the t lines, output the answer for the corresponding test case.
Example
Input
2
10 2
40 5
Output
11
12
Note
In the first sample, s = (1, 2, 3, 4, 5, 9, 6, 7, 13, 8, 10, 18, …). 10 is the 11-th number here, so the answer is 11.
In the second sample, s = (1, 2, 3, 4, 5, 15, 6, 7, 8, 9, 10, 40, …).
Submitted Solution:
```
def Solve(x,n,k):
if x==0:
return k*(k+1)//2
return k*(k+1)//2-x%k+max(0,min((x%k+1)*k-Solve(x//k,n,k)+1,k))
T=int(input())
for i in range(T):
n,k=map(int,input().split())
K=k*k+1
m=(n-1)//K
x=m*K+Solve(m,n,k)
if x==n:
print((m+1)*(k+1))
else:
print((n-(m+(n>=x))*(k+1)-1)//k)
``` | instruction | 0 | 69,943 | 5 | 139,886 |
No | output | 1 | 69,943 | 5 | 139,887 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ujan needs some rest from cleaning, so he started playing with infinite sequences. He has two integers n and k. He creates an infinite sequence s by repeating the following steps.
1. Find k smallest distinct positive integers that are not in s. Let's call them u_{1}, u_{2}, …, u_{k} from the smallest to the largest.
2. Append u_{1}, u_{2}, …, u_{k} and ∑_{i=1}^{k} u_{i} to s in this order.
3. Go back to the first step.
Ujan will stop procrastinating when he writes the number n in the sequence s. Help him find the index of n in s. In other words, find the integer x such that s_{x} = n. It's possible to prove that all positive integers are included in s only once.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^{5}), the number of test cases.
Each of the following t lines contains two integers n and k (1 ≤ n ≤ 10^{18}, 2 ≤ k ≤ 10^{6}), the number to be found in the sequence s and the parameter used to create the sequence s.
Output
In each of the t lines, output the answer for the corresponding test case.
Example
Input
2
10 2
40 5
Output
11
12
Note
In the first sample, s = (1, 2, 3, 4, 5, 9, 6, 7, 13, 8, 10, 18, …). 10 is the 11-th number here, so the answer is 11.
In the second sample, s = (1, 2, 3, 4, 5, 15, 6, 7, 8, 9, 10, 40, …).
Submitted Solution:
```
def query(d,k):
if not d:
return k*k+1>>1
t = query(d//k,k)
v = d%k
s = (k*(k+1)>>1)-v
if((v+1)*k>=t):
s += min(k,(v+1)*k-t+1)
return s
test = int(input())
while(test):
n,k = map(int,input().split())
test -= 1
u = (n-1)/(k*k+1)
v = (n-1)%(k*k+1)+1
t = query(u,k)
if t!= v:
if t<v:
v-= 1
print(u*k*(k+1)+v+(v-1)/k)
else:
r = u%k+1
print((u/k)*k*(k+1)+r*k+1)
``` | instruction | 0 | 69,944 | 5 | 139,888 |
No | output | 1 | 69,944 | 5 | 139,889 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ujan needs some rest from cleaning, so he started playing with infinite sequences. He has two integers n and k. He creates an infinite sequence s by repeating the following steps.
1. Find k smallest distinct positive integers that are not in s. Let's call them u_{1}, u_{2}, …, u_{k} from the smallest to the largest.
2. Append u_{1}, u_{2}, …, u_{k} and ∑_{i=1}^{k} u_{i} to s in this order.
3. Go back to the first step.
Ujan will stop procrastinating when he writes the number n in the sequence s. Help him find the index of n in s. In other words, find the integer x such that s_{x} = n. It's possible to prove that all positive integers are included in s only once.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^{5}), the number of test cases.
Each of the following t lines contains two integers n and k (1 ≤ n ≤ 10^{18}, 2 ≤ k ≤ 10^{6}), the number to be found in the sequence s and the parameter used to create the sequence s.
Output
In each of the t lines, output the answer for the corresponding test case.
Example
Input
2
10 2
40 5
Output
11
12
Note
In the first sample, s = (1, 2, 3, 4, 5, 9, 6, 7, 13, 8, 10, 18, …). 10 is the 11-th number here, so the answer is 11.
In the second sample, s = (1, 2, 3, 4, 5, 15, 6, 7, 8, 9, 10, 40, …).
Submitted Solution:
```
def query(d,k):
if not d:
return k*k+1>>1
t = query(d//k,k)
v = d%k
s = (k*(k+1)>>1)-v
if((v+1)*k>=t):
s += min(k,(v+1)*k-t+1)
return s
test = int(input())
while(test):
n,k = map(int,input().split())
test -= 1
u = (n-1)//(k*k+1)
v = (n-1)%(k*k+1)+1
t = query(u,k)
if t!=v:
if t<v:
v-= 1
print(u*k*(k+1)+v+(v-1)//k)
else:
r = u%k+1
print((u//k)*k*(k+1)+r*(k+1))
``` | instruction | 0 | 69,945 | 5 | 139,890 |
No | output | 1 | 69,945 | 5 | 139,891 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
Input
The first line of the input contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≤ ai ≤ 109).
All the numbers in the lines are separated by single spaces.
Output
On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}.
Examples
Input
6 2
2 3 6 5 4 10
Output
3
Note
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
Submitted Solution:
```
'''input
10 2
1 2 3 4 5 6 7 8 9 10
'''
# practicing a skill right after sleep improves it a lot quickly
from sys import stdin, setrecursionlimit
import collections
# main starts
n, k = list(map(int, stdin.readline().split()))
myset = set(map(int, stdin.readline().split()))
count = 0
can = dict()
for i in myset:
can[i] = True
for i in myset:
if i * k in myset and can[i] == True:
count += 1
can[i * k] = False
print(n - count)
``` | instruction | 0 | 70,144 | 5 | 140,288 |
No | output | 1 | 70,144 | 5 | 140,289 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that
1. 1 ≤ i, j ≤ N
2. S[i] = S[j], that is the i-th symbol of string S is equal to the j-th.
Input
The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105.
Output
Print a single number which represents the number of pairs i and j with the needed property. Pairs (x, y) and (y, x) should be considered different, i.e. the ordered pairs count.
Examples
Input
great10
Output
7
Input
aaaaaaaaaa
Output
100
Submitted Solution:
```
import sys
import os.path
import math
import heapq
from sys import stdin,stdout
from collections import*
from math import gcd,ceil,floor
mod = int(1e9+7)
##input=sys.stdin.readline
if os.path.exists('Updated prg/Input3d.txt'):
sys.stdout=open("Updated prg/Output3d.txt","w")
sys.stdin=open("Updated prg/Input3d.txt","r")
def sinp():return input()
def ninp():return int(sinp())
def mapinp():return map(int,sinp().split())
def linp():return list(mapinp())
def sl():return list(sinp())
def prnt(a):print(a)
s1=sinp()
l1=Counter(s1)
c=0
for i in l1:
c=c+(l1[i]*l1[i])
prnt(c)
``` | instruction | 0 | 70,221 | 5 | 140,442 |
Yes | output | 1 | 70,221 | 5 | 140,443 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Lena is a programmer. She got a task to solve at work.
There is an empty set of pairs of integers and n queries to process. Each query is one of three types:
1. Add a pair (a, b) to the set.
2. Remove a pair added in the query number i. All queries are numbered with integers from 1 to n.
3. For a given integer q find the maximal value x·q + y over all pairs (x, y) from the set.
Help Lena to process the queries.
Input
The first line of input contains integer n (1 ≤ n ≤ 3·105) — the number of queries.
Each of the next n lines starts with integer t (1 ≤ t ≤ 3) — the type of the query.
A pair of integers a and b ( - 109 ≤ a, b ≤ 109) follows in the query of the first type.
An integer i (1 ≤ i ≤ n) follows in the query of the second type. It is guaranteed that i is less than the number of the query, the query number i has the first type and the pair from the i-th query is not already removed.
An integer q ( - 109 ≤ q ≤ 109) follows in the query of the third type.
Output
For the queries of the third type print on a separate line the desired maximal value of x·q + y.
If there are no pairs in the set print "EMPTY SET".
Example
Input
7
3 1
1 2 3
3 1
1 -1 100
3 1
2 4
3 1
Output
EMPTY SET
5
99
5
Submitted Solution:
```
n = int(input())
s = set()
for i in range(1, n+1):
inp = list(map(int, input().split()))
t, rest = inp[0], inp[1:]
if t == 1:
s.add((i, rest[0], rest[1]))
elif t == 2:
rm = None
for elem in s:
if elem[0] == rest[0]:
rm = elem
break
s.remove(rm)
elif t == 3:
if len(s) == 0:
print("EMPTY SET")
else:
mx = 0
for elem in s:
tmp = elem[1]*rest[0] + elem[2]
if tmp > mx:
mx = tmp
print(mx)
``` | instruction | 0 | 70,308 | 5 | 140,616 |
No | output | 1 | 70,308 | 5 | 140,617 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Lena is a programmer. She got a task to solve at work.
There is an empty set of pairs of integers and n queries to process. Each query is one of three types:
1. Add a pair (a, b) to the set.
2. Remove a pair added in the query number i. All queries are numbered with integers from 1 to n.
3. For a given integer q find the maximal value x·q + y over all pairs (x, y) from the set.
Help Lena to process the queries.
Input
The first line of input contains integer n (1 ≤ n ≤ 3·105) — the number of queries.
Each of the next n lines starts with integer t (1 ≤ t ≤ 3) — the type of the query.
A pair of integers a and b ( - 109 ≤ a, b ≤ 109) follows in the query of the first type.
An integer i (1 ≤ i ≤ n) follows in the query of the second type. It is guaranteed that i is less than the number of the query, the query number i has the first type and the pair from the i-th query is not already removed.
An integer q ( - 109 ≤ q ≤ 109) follows in the query of the third type.
Output
For the queries of the third type print on a separate line the desired maximal value of x·q + y.
If there are no pairs in the set print "EMPTY SET".
Example
Input
7
3 1
1 2 3
3 1
1 -1 100
3 1
2 4
3 1
Output
EMPTY SET
5
99
5
Submitted Solution:
```
n = int(input())
s = set()
for i in range(1, n+1):
inp = list(map(int, input().split()))
t, rest = inp[0], inp[1:]
if t == 1:
s.add((i, rest[0], rest[1]))
elif t == 2:
rm = None
for elem in s:
if elem[0] == rest[0]:
rm = elem
break
s.remove(rm)
elif t == 3:
if len(s) == 0:
print("EMPTY SET")
else:
mx = max(s)[1]*max(s)[0] + max(s)[2]
for elem in s:
tmp = elem[1]*rest[0] + elem[2]
if tmp > mx:
mx = tmp
print(mx)
``` | instruction | 0 | 70,309 | 5 | 140,618 |
No | output | 1 | 70,309 | 5 | 140,619 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Lena is a programmer. She got a task to solve at work.
There is an empty set of pairs of integers and n queries to process. Each query is one of three types:
1. Add a pair (a, b) to the set.
2. Remove a pair added in the query number i. All queries are numbered with integers from 1 to n.
3. For a given integer q find the maximal value x·q + y over all pairs (x, y) from the set.
Help Lena to process the queries.
Input
The first line of input contains integer n (1 ≤ n ≤ 3·105) — the number of queries.
Each of the next n lines starts with integer t (1 ≤ t ≤ 3) — the type of the query.
A pair of integers a and b ( - 109 ≤ a, b ≤ 109) follows in the query of the first type.
An integer i (1 ≤ i ≤ n) follows in the query of the second type. It is guaranteed that i is less than the number of the query, the query number i has the first type and the pair from the i-th query is not already removed.
An integer q ( - 109 ≤ q ≤ 109) follows in the query of the third type.
Output
For the queries of the third type print on a separate line the desired maximal value of x·q + y.
If there are no pairs in the set print "EMPTY SET".
Example
Input
7
3 1
1 2 3
3 1
1 -1 100
3 1
2 4
3 1
Output
EMPTY SET
5
99
5
Submitted Solution:
```
n = int(input())
s = set()
for i in range(1, n+1):
inp = list(map(int, input().split()))
t, rest = inp[0], inp[1:]
if t == 1:
s.add((i, rest[0], rest[1]))
elif t == 2:
rm = None
for elem in s:
if elem[0] == rest[0]:
rm = elem
break
s.remove(rm)
elif t == 3:
if len(s) == 0:
print("EMPTY SET")
else:
mx = 0
for elem in s:
tmp = elem[1]*rest[0] + elem[2]
if tmp > mx or mx == 0:
mx = tmp
print(mx)
``` | instruction | 0 | 70,310 | 5 | 140,620 |
No | output | 1 | 70,310 | 5 | 140,621 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Lena is a programmer. She got a task to solve at work.
There is an empty set of pairs of integers and n queries to process. Each query is one of three types:
1. Add a pair (a, b) to the set.
2. Remove a pair added in the query number i. All queries are numbered with integers from 1 to n.
3. For a given integer q find the maximal value x·q + y over all pairs (x, y) from the set.
Help Lena to process the queries.
Input
The first line of input contains integer n (1 ≤ n ≤ 3·105) — the number of queries.
Each of the next n lines starts with integer t (1 ≤ t ≤ 3) — the type of the query.
A pair of integers a and b ( - 109 ≤ a, b ≤ 109) follows in the query of the first type.
An integer i (1 ≤ i ≤ n) follows in the query of the second type. It is guaranteed that i is less than the number of the query, the query number i has the first type and the pair from the i-th query is not already removed.
An integer q ( - 109 ≤ q ≤ 109) follows in the query of the third type.
Output
For the queries of the third type print on a separate line the desired maximal value of x·q + y.
If there are no pairs in the set print "EMPTY SET".
Example
Input
7
3 1
1 2 3
3 1
1 -1 100
3 1
2 4
3 1
Output
EMPTY SET
5
99
5
Submitted Solution:
```
import sys
n = int(input())
data = set()
for i in range(1, n+1):
inp = list(map(int, input().split()))
t, rest = inp[0], inp[1:]
if t == 1:
k = i#len(data)+1
a = rest[0]
b = rest[1]
data.add((k, a, b))
elif t == 2:
rm = None
for elem in data:
if elem[0] == rest[0]:
rm = elem
break
data.discard(rm)
elif t == 3:
# print(data)
if len(data) == 0:
print("EMPTY SET")
else:
q = rest[0]
mx = -sys.maxsize
for k, x, y in data:
tmp = x*q + y
if tmp > mx:
mx = tmp
print(mx)
``` | instruction | 0 | 70,311 | 5 | 140,622 |
No | output | 1 | 70,311 | 5 | 140,623 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction.
A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a fraction has zero numerals after the decimal point.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^5) — the number of queries.
Next n lines contain queries, one per line. Each line contains three integers p, q, and b (0 ≤ p ≤ 10^{18}, 1 ≤ q ≤ 10^{18}, 2 ≤ b ≤ 10^{18}). All numbers are given in notation with base 10.
Output
For each question, in a separate line, print Finite if the fraction is finite and Infinite otherwise.
Examples
Input
2
6 12 10
4 3 10
Output
Finite
Infinite
Input
4
1 1 2
9 36 2
4 12 3
3 5 4
Output
Finite
Finite
Finite
Infinite
Note
6/12 = 1/2 = 0,5_{10}
4/3 = 1,(3)_{10}
9/36 = 1/4 = 0,01_2
4/12 = 1/3 = 0,1_3
Submitted Solution:
```
import sys
def readInts(): return [int(x) for x in sys.stdin.readline().split()]
def readInt(): return int(sys.stdin.readline())
def print(x):
sys.stdout.write(str(x) + "\n")
def solve():
n = readInt()
for _ in range(n):
p, q, b = readInts()
if p * pow(b, 64, q) % q != 0:
print("Infinite")
else:
print("Finite")
def main():
t = 1
# t = readInt()
for _ in range(t):
solve()
main()
``` | instruction | 0 | 70,485 | 5 | 140,970 |
Yes | output | 1 | 70,485 | 5 | 140,971 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction.
A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a fraction has zero numerals after the decimal point.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^5) — the number of queries.
Next n lines contain queries, one per line. Each line contains three integers p, q, and b (0 ≤ p ≤ 10^{18}, 1 ≤ q ≤ 10^{18}, 2 ≤ b ≤ 10^{18}). All numbers are given in notation with base 10.
Output
For each question, in a separate line, print Finite if the fraction is finite and Infinite otherwise.
Examples
Input
2
6 12 10
4 3 10
Output
Finite
Infinite
Input
4
1 1 2
9 36 2
4 12 3
3 5 4
Output
Finite
Finite
Finite
Infinite
Note
6/12 = 1/2 = 0,5_{10}
4/3 = 1,(3)_{10}
9/36 = 1/4 = 0,01_2
4/12 = 1/3 = 0,1_3
Submitted Solution:
```
import math
for _ in range(int(input())):
a,b,c=map(int,input().split())
s=str(a/b)
k='0'+s[s.find('.'):]
#print("Initial:",k)
count=0;t=1
while(float(k)!=0):
count+=1
s=str(float(k)*c)
k='0'+s[s.find('.'):]
#print(k)
if count>8:
break
if count!=9:
print("Finite")
else:
print("Infinite")
``` | instruction | 0 | 70,489 | 5 | 140,978 |
No | output | 1 | 70,489 | 5 | 140,979 |
Provide a correct Python 3 solution for this coding contest problem.
Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).
Consider a sequence A satisfying the following conditions:
* A is a sequence of N positive integers.
* 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.
Let us define a score of this sequence as follows:
* The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)
Find the maximum possible score of A.
Constraints
* All values in input are integers.
* 2 ≤ N ≤ 10
* 1 \leq M \leq 10
* 1 \leq Q \leq 50
* 1 \leq a_i < b_i \leq N ( i = 1, 2, ..., Q )
* 0 \leq c_i \leq M - 1 ( i = 1, 2, ..., Q )
* (a_i, b_i, c_i) \neq (a_j, b_j, c_j) (where i \neq j)
* 1 \leq d_i \leq 10^5 ( i = 1, 2, ..., Q )
Input
Input is given from Standard Input in the following format:
N M Q
a_1 b_1 c_1 d_1
:
a_Q b_Q c_Q d_Q
Output
Print the maximum possible score of A.
Examples
Input
3 4 3
1 3 3 100
1 2 2 10
2 3 2 10
Output
110
Input
4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328
Output
357500
Input
10 10 1
1 10 9 1
Output
1 | instruction | 0 | 70,507 | 5 | 141,014 |
"Correct Solution:
```
from itertools import combinations_with_replacement
N, M, Q = [int(n) for n in input().split()]
X = [[int(n) for n in input().split()] for _ in range(Q)]
ans = 0
for A in combinations_with_replacement(range(1, M+1), N):
t = 0
for x in X:
if A[x[1]-1]-A[x[0]-1] == x[2]: t += x[3]
ans = max(ans, t)
print(ans)
``` | output | 1 | 70,507 | 5 | 141,015 |
Provide a correct Python 3 solution for this coding contest problem.
Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).
Consider a sequence A satisfying the following conditions:
* A is a sequence of N positive integers.
* 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.
Let us define a score of this sequence as follows:
* The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)
Find the maximum possible score of A.
Constraints
* All values in input are integers.
* 2 ≤ N ≤ 10
* 1 \leq M \leq 10
* 1 \leq Q \leq 50
* 1 \leq a_i < b_i \leq N ( i = 1, 2, ..., Q )
* 0 \leq c_i \leq M - 1 ( i = 1, 2, ..., Q )
* (a_i, b_i, c_i) \neq (a_j, b_j, c_j) (where i \neq j)
* 1 \leq d_i \leq 10^5 ( i = 1, 2, ..., Q )
Input
Input is given from Standard Input in the following format:
N M Q
a_1 b_1 c_1 d_1
:
a_Q b_Q c_Q d_Q
Output
Print the maximum possible score of A.
Examples
Input
3 4 3
1 3 3 100
1 2 2 10
2 3 2 10
Output
110
Input
4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328
Output
357500
Input
10 10 1
1 10 9 1
Output
1 | instruction | 0 | 70,508 | 5 | 141,016 |
"Correct Solution:
```
import itertools
n,m,q=map(int,input().split())
l=[list(map(int,input().split()))for i in range(q)]
y=0
for i in itertools.combinations_with_replacement(range(1,m+1),n):
x=0
for a,b,c,d in l:
if i[b-1]-i[a-1]==c:x+=d
y=max(y,x)
print(y)
``` | output | 1 | 70,508 | 5 | 141,017 |
Provide a correct Python 3 solution for this coding contest problem.
Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).
Consider a sequence A satisfying the following conditions:
* A is a sequence of N positive integers.
* 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.
Let us define a score of this sequence as follows:
* The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)
Find the maximum possible score of A.
Constraints
* All values in input are integers.
* 2 ≤ N ≤ 10
* 1 \leq M \leq 10
* 1 \leq Q \leq 50
* 1 \leq a_i < b_i \leq N ( i = 1, 2, ..., Q )
* 0 \leq c_i \leq M - 1 ( i = 1, 2, ..., Q )
* (a_i, b_i, c_i) \neq (a_j, b_j, c_j) (where i \neq j)
* 1 \leq d_i \leq 10^5 ( i = 1, 2, ..., Q )
Input
Input is given from Standard Input in the following format:
N M Q
a_1 b_1 c_1 d_1
:
a_Q b_Q c_Q d_Q
Output
Print the maximum possible score of A.
Examples
Input
3 4 3
1 3 3 100
1 2 2 10
2 3 2 10
Output
110
Input
4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328
Output
357500
Input
10 10 1
1 10 9 1
Output
1 | instruction | 0 | 70,509 | 5 | 141,018 |
"Correct Solution:
```
import itertools
N, M, Q = map(int, input().split())
query = [tuple(map(int, input().split())) for _ in range(Q)]
ans = 0
for p in itertools.combinations_with_replacement(range(1, M+1), N):
A = list(p)
s = 0
for a, b, c, d in query:
s += d if A[b-1]-A[a-1] == c else 0
ans = max(ans, s)
print(ans)
``` | output | 1 | 70,509 | 5 | 141,019 |
Provide a correct Python 3 solution for this coding contest problem.
Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).
Consider a sequence A satisfying the following conditions:
* A is a sequence of N positive integers.
* 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.
Let us define a score of this sequence as follows:
* The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)
Find the maximum possible score of A.
Constraints
* All values in input are integers.
* 2 ≤ N ≤ 10
* 1 \leq M \leq 10
* 1 \leq Q \leq 50
* 1 \leq a_i < b_i \leq N ( i = 1, 2, ..., Q )
* 0 \leq c_i \leq M - 1 ( i = 1, 2, ..., Q )
* (a_i, b_i, c_i) \neq (a_j, b_j, c_j) (where i \neq j)
* 1 \leq d_i \leq 10^5 ( i = 1, 2, ..., Q )
Input
Input is given from Standard Input in the following format:
N M Q
a_1 b_1 c_1 d_1
:
a_Q b_Q c_Q d_Q
Output
Print the maximum possible score of A.
Examples
Input
3 4 3
1 3 3 100
1 2 2 10
2 3 2 10
Output
110
Input
4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328
Output
357500
Input
10 10 1
1 10 9 1
Output
1 | instruction | 0 | 70,510 | 5 | 141,020 |
"Correct Solution:
```
import itertools
n, m, q = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(q)]
r = 0
for A in itertools.combinations_with_replacement(range(m), n):
s = 0
for i in range(q):
if A[x[i][1] - 1] - A[x[i][0] - 1] == x[i][2]:
s += x[i][3]
r = max(r, s)
print(r)
``` | output | 1 | 70,510 | 5 | 141,021 |
Provide a correct Python 3 solution for this coding contest problem.
Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).
Consider a sequence A satisfying the following conditions:
* A is a sequence of N positive integers.
* 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.
Let us define a score of this sequence as follows:
* The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)
Find the maximum possible score of A.
Constraints
* All values in input are integers.
* 2 ≤ N ≤ 10
* 1 \leq M \leq 10
* 1 \leq Q \leq 50
* 1 \leq a_i < b_i \leq N ( i = 1, 2, ..., Q )
* 0 \leq c_i \leq M - 1 ( i = 1, 2, ..., Q )
* (a_i, b_i, c_i) \neq (a_j, b_j, c_j) (where i \neq j)
* 1 \leq d_i \leq 10^5 ( i = 1, 2, ..., Q )
Input
Input is given from Standard Input in the following format:
N M Q
a_1 b_1 c_1 d_1
:
a_Q b_Q c_Q d_Q
Output
Print the maximum possible score of A.
Examples
Input
3 4 3
1 3 3 100
1 2 2 10
2 3 2 10
Output
110
Input
4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328
Output
357500
Input
10 10 1
1 10 9 1
Output
1 | instruction | 0 | 70,511 | 5 | 141,022 |
"Correct Solution:
```
import itertools
n,m,q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(q)]
l = range(1,m+1)
point = 0
for v in itertools.combinations_with_replacement(l,n):
p = 0
for a,b,c,d in abcd:
if v[b-1] - v[a-1] == c:
p += d
if p > point: point = p
print(point)
``` | output | 1 | 70,511 | 5 | 141,023 |
Provide a correct Python 3 solution for this coding contest problem.
Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).
Consider a sequence A satisfying the following conditions:
* A is a sequence of N positive integers.
* 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.
Let us define a score of this sequence as follows:
* The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)
Find the maximum possible score of A.
Constraints
* All values in input are integers.
* 2 ≤ N ≤ 10
* 1 \leq M \leq 10
* 1 \leq Q \leq 50
* 1 \leq a_i < b_i \leq N ( i = 1, 2, ..., Q )
* 0 \leq c_i \leq M - 1 ( i = 1, 2, ..., Q )
* (a_i, b_i, c_i) \neq (a_j, b_j, c_j) (where i \neq j)
* 1 \leq d_i \leq 10^5 ( i = 1, 2, ..., Q )
Input
Input is given from Standard Input in the following format:
N M Q
a_1 b_1 c_1 d_1
:
a_Q b_Q c_Q d_Q
Output
Print the maximum possible score of A.
Examples
Input
3 4 3
1 3 3 100
1 2 2 10
2 3 2 10
Output
110
Input
4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328
Output
357500
Input
10 10 1
1 10 9 1
Output
1 | instruction | 0 | 70,512 | 5 | 141,024 |
"Correct Solution:
```
n,m,q=map(int,input().split())
l=[]
for i in range(q):
l.append(list(map(int,input().split())))
li=[]
for i in range(m):
li.append(i+1)
import itertools
ans=0
for lis in itertools.combinations_with_replacement(li, n):
lis=list(lis)
an=0
for z in l:
a,b,c,d=z
if lis[b-1]-lis[a-1]==c:
an+=d
ans=max(an,ans)
print(ans)
``` | output | 1 | 70,512 | 5 | 141,025 |
Provide a correct Python 3 solution for this coding contest problem.
Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).
Consider a sequence A satisfying the following conditions:
* A is a sequence of N positive integers.
* 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.
Let us define a score of this sequence as follows:
* The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)
Find the maximum possible score of A.
Constraints
* All values in input are integers.
* 2 ≤ N ≤ 10
* 1 \leq M \leq 10
* 1 \leq Q \leq 50
* 1 \leq a_i < b_i \leq N ( i = 1, 2, ..., Q )
* 0 \leq c_i \leq M - 1 ( i = 1, 2, ..., Q )
* (a_i, b_i, c_i) \neq (a_j, b_j, c_j) (where i \neq j)
* 1 \leq d_i \leq 10^5 ( i = 1, 2, ..., Q )
Input
Input is given from Standard Input in the following format:
N M Q
a_1 b_1 c_1 d_1
:
a_Q b_Q c_Q d_Q
Output
Print the maximum possible score of A.
Examples
Input
3 4 3
1 3 3 100
1 2 2 10
2 3 2 10
Output
110
Input
4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328
Output
357500
Input
10 10 1
1 10 9 1
Output
1 | instruction | 0 | 70,513 | 5 | 141,026 |
"Correct Solution:
```
N, M, Q, *ABCD = map(int, open(0).read().split())
L = list(zip(*[iter(ABCD)] * 4))
def solve(A):
if len(A) == N:
return sum(d for a, b, c, d in L if A[b - 1] - A[a - 1] == c)
return max(solve(A + [i]) for i in range(A[-1], M + 1))
print(solve([1]))
``` | output | 1 | 70,513 | 5 | 141,027 |
Provide a correct Python 3 solution for this coding contest problem.
Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).
Consider a sequence A satisfying the following conditions:
* A is a sequence of N positive integers.
* 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.
Let us define a score of this sequence as follows:
* The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)
Find the maximum possible score of A.
Constraints
* All values in input are integers.
* 2 ≤ N ≤ 10
* 1 \leq M \leq 10
* 1 \leq Q \leq 50
* 1 \leq a_i < b_i \leq N ( i = 1, 2, ..., Q )
* 0 \leq c_i \leq M - 1 ( i = 1, 2, ..., Q )
* (a_i, b_i, c_i) \neq (a_j, b_j, c_j) (where i \neq j)
* 1 \leq d_i \leq 10^5 ( i = 1, 2, ..., Q )
Input
Input is given from Standard Input in the following format:
N M Q
a_1 b_1 c_1 d_1
:
a_Q b_Q c_Q d_Q
Output
Print the maximum possible score of A.
Examples
Input
3 4 3
1 3 3 100
1 2 2 10
2 3 2 10
Output
110
Input
4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328
Output
357500
Input
10 10 1
1 10 9 1
Output
1 | instruction | 0 | 70,514 | 5 | 141,028 |
"Correct Solution:
```
import itertools
n, m, q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(q)]
v = list(itertools.combinations_with_replacement(range(1, m+1), n))
ans = 0
for i in v:
s = 0
for a, b, c, d in abcd:
if i[b-1] - i[a-1] == c:
s += d
ans = max(ans, s)
print(ans)
``` | output | 1 | 70,514 | 5 | 141,029 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).
Consider a sequence A satisfying the following conditions:
* A is a sequence of N positive integers.
* 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.
Let us define a score of this sequence as follows:
* The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)
Find the maximum possible score of A.
Constraints
* All values in input are integers.
* 2 ≤ N ≤ 10
* 1 \leq M \leq 10
* 1 \leq Q \leq 50
* 1 \leq a_i < b_i \leq N ( i = 1, 2, ..., Q )
* 0 \leq c_i \leq M - 1 ( i = 1, 2, ..., Q )
* (a_i, b_i, c_i) \neq (a_j, b_j, c_j) (where i \neq j)
* 1 \leq d_i \leq 10^5 ( i = 1, 2, ..., Q )
Input
Input is given from Standard Input in the following format:
N M Q
a_1 b_1 c_1 d_1
:
a_Q b_Q c_Q d_Q
Output
Print the maximum possible score of A.
Examples
Input
3 4 3
1 3 3 100
1 2 2 10
2 3 2 10
Output
110
Input
4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328
Output
357500
Input
10 10 1
1 10 9 1
Output
1
Submitted Solution:
```
import itertools
n,m,q=map(int,input().split())
d=[list(map(int,input().split())) for i in range(q)]
ans=0
for i in list(itertools.combinations_with_replacement(list(range(1,m+1)), n)):
a=list(i)
hantei=0
for j in range(q):
if (a[d[j][1]-1]-a[d[j][0]-1])==d[j][2]:
hantei+=d[j][3]
ans=max(ans,hantei)
print(ans)
``` | instruction | 0 | 70,515 | 5 | 141,030 |
Yes | output | 1 | 70,515 | 5 | 141,031 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).
Consider a sequence A satisfying the following conditions:
* A is a sequence of N positive integers.
* 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.
Let us define a score of this sequence as follows:
* The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)
Find the maximum possible score of A.
Constraints
* All values in input are integers.
* 2 ≤ N ≤ 10
* 1 \leq M \leq 10
* 1 \leq Q \leq 50
* 1 \leq a_i < b_i \leq N ( i = 1, 2, ..., Q )
* 0 \leq c_i \leq M - 1 ( i = 1, 2, ..., Q )
* (a_i, b_i, c_i) \neq (a_j, b_j, c_j) (where i \neq j)
* 1 \leq d_i \leq 10^5 ( i = 1, 2, ..., Q )
Input
Input is given from Standard Input in the following format:
N M Q
a_1 b_1 c_1 d_1
:
a_Q b_Q c_Q d_Q
Output
Print the maximum possible score of A.
Examples
Input
3 4 3
1 3 3 100
1 2 2 10
2 3 2 10
Output
110
Input
4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328
Output
357500
Input
10 10 1
1 10 9 1
Output
1
Submitted Solution:
```
N,M,Q=map(int,input().split())
ABCD=[list(map(int,input().split())) for i in range(Q)]
from itertools import combinations
ans=0
for p in combinations(range(N+M-1),N):
r=0
for a,b,c,d in ABCD:
if p[b-1]-b+1-(p[a-1]-(a-1))==c:
r+=d
ans=max(ans,r)
print(ans)
``` | instruction | 0 | 70,516 | 5 | 141,032 |
Yes | output | 1 | 70,516 | 5 | 141,033 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).
Consider a sequence A satisfying the following conditions:
* A is a sequence of N positive integers.
* 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.
Let us define a score of this sequence as follows:
* The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)
Find the maximum possible score of A.
Constraints
* All values in input are integers.
* 2 ≤ N ≤ 10
* 1 \leq M \leq 10
* 1 \leq Q \leq 50
* 1 \leq a_i < b_i \leq N ( i = 1, 2, ..., Q )
* 0 \leq c_i \leq M - 1 ( i = 1, 2, ..., Q )
* (a_i, b_i, c_i) \neq (a_j, b_j, c_j) (where i \neq j)
* 1 \leq d_i \leq 10^5 ( i = 1, 2, ..., Q )
Input
Input is given from Standard Input in the following format:
N M Q
a_1 b_1 c_1 d_1
:
a_Q b_Q c_Q d_Q
Output
Print the maximum possible score of A.
Examples
Input
3 4 3
1 3 3 100
1 2 2 10
2 3 2 10
Output
110
Input
4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328
Output
357500
Input
10 10 1
1 10 9 1
Output
1
Submitted Solution:
```
import itertools
n,m,q=map(int,input().split())
abcd=[list(map(int,input().split())) for _ in range(q)]
ans=0
for i in itertools.combinations_with_replacement(range(1,m+1),n):
total=0
for j in range(q):
if i[abcd[j][1]-1]-i[abcd[j][0]-1]==abcd[j][2]:
total+=abcd[j][3]
ans=max(ans,total)
print(ans)
``` | instruction | 0 | 70,517 | 5 | 141,034 |
Yes | output | 1 | 70,517 | 5 | 141,035 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).
Consider a sequence A satisfying the following conditions:
* A is a sequence of N positive integers.
* 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.
Let us define a score of this sequence as follows:
* The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)
Find the maximum possible score of A.
Constraints
* All values in input are integers.
* 2 ≤ N ≤ 10
* 1 \leq M \leq 10
* 1 \leq Q \leq 50
* 1 \leq a_i < b_i \leq N ( i = 1, 2, ..., Q )
* 0 \leq c_i \leq M - 1 ( i = 1, 2, ..., Q )
* (a_i, b_i, c_i) \neq (a_j, b_j, c_j) (where i \neq j)
* 1 \leq d_i \leq 10^5 ( i = 1, 2, ..., Q )
Input
Input is given from Standard Input in the following format:
N M Q
a_1 b_1 c_1 d_1
:
a_Q b_Q c_Q d_Q
Output
Print the maximum possible score of A.
Examples
Input
3 4 3
1 3 3 100
1 2 2 10
2 3 2 10
Output
110
Input
4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328
Output
357500
Input
10 10 1
1 10 9 1
Output
1
Submitted Solution:
```
import itertools
N,M,Q=map(int,input().split())
L=[list(map(int, input().split())) for _ in range(Q)]
m=[x for x in range(1, M+1)]
A=list(itertools.combinations_with_replacement(m ,N))
ans=0
for a in A:
d=0
for i in range(Q):
if a[L[i][1]-1]-a[L[i][0]-1]==L[i][2]:
d+=L[i][3]
ans=max(ans,d)
print(ans)
``` | instruction | 0 | 70,518 | 5 | 141,036 |
Yes | output | 1 | 70,518 | 5 | 141,037 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).
Consider a sequence A satisfying the following conditions:
* A is a sequence of N positive integers.
* 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.
Let us define a score of this sequence as follows:
* The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)
Find the maximum possible score of A.
Constraints
* All values in input are integers.
* 2 ≤ N ≤ 10
* 1 \leq M \leq 10
* 1 \leq Q \leq 50
* 1 \leq a_i < b_i \leq N ( i = 1, 2, ..., Q )
* 0 \leq c_i \leq M - 1 ( i = 1, 2, ..., Q )
* (a_i, b_i, c_i) \neq (a_j, b_j, c_j) (where i \neq j)
* 1 \leq d_i \leq 10^5 ( i = 1, 2, ..., Q )
Input
Input is given from Standard Input in the following format:
N M Q
a_1 b_1 c_1 d_1
:
a_Q b_Q c_Q d_Q
Output
Print the maximum possible score of A.
Examples
Input
3 4 3
1 3 3 100
1 2 2 10
2 3 2 10
Output
110
Input
4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328
Output
357500
Input
10 10 1
1 10 9 1
Output
1
Submitted Solution:
```
#import itertools
n,m,q = map(int,input().split())
abcd = [input() for _ in range(q)]
#x = itertools.product(range(1,m+1),repeat=n)
x = []
for i in range(1,m+1):
for j in range(i,m+1):
for k in range(j, m+1):
for l in range(k,m+1):
x.append([i,j,k,l])
tmp = 0
ans = 0
for xi in x:
tmp = 0
for i in abcd:
a,b,c,d = map(int,i.split())
if xi[b-1] - xi[a-1] == c:
tmp += d
ans = max(ans,tmp)
print(ans)
``` | instruction | 0 | 70,519 | 5 | 141,038 |
No | output | 1 | 70,519 | 5 | 141,039 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).
Consider a sequence A satisfying the following conditions:
* A is a sequence of N positive integers.
* 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.
Let us define a score of this sequence as follows:
* The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)
Find the maximum possible score of A.
Constraints
* All values in input are integers.
* 2 ≤ N ≤ 10
* 1 \leq M \leq 10
* 1 \leq Q \leq 50
* 1 \leq a_i < b_i \leq N ( i = 1, 2, ..., Q )
* 0 \leq c_i \leq M - 1 ( i = 1, 2, ..., Q )
* (a_i, b_i, c_i) \neq (a_j, b_j, c_j) (where i \neq j)
* 1 \leq d_i \leq 10^5 ( i = 1, 2, ..., Q )
Input
Input is given from Standard Input in the following format:
N M Q
a_1 b_1 c_1 d_1
:
a_Q b_Q c_Q d_Q
Output
Print the maximum possible score of A.
Examples
Input
3 4 3
1 3 3 100
1 2 2 10
2 3 2 10
Output
110
Input
4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328
Output
357500
Input
10 10 1
1 10 9 1
Output
1
Submitted Solution:
```
n, m, q = input().split()
n = int( n )
m = int( m )
q = int( q )
a = []
b = []
c = []
d = []
for i in range( int( q ) ):
a_i, b_i, c_i, d_i = input().split()
a.append( int( a_i ) )
b.append( int( b_i ) )
c.append( int( c_i ) )
d.append( int( d_i ) )
array = [ 1 ] * n
array_list = [ array ]
i = 0
while True:
for k in range( array_list[i][-1], m + 1 ):
array_list.append( array_list[i][1:] + [ k ] )
#print( array_list[i][1:] + [ k ] )
i = i + 1
if len( array_list ) > 1000:
break
max_score = 0
for array in array_list:
score = 0
for i in range( q ):
#print( i, a[i], b[i], c[i], array )
if array[b[i]-1] - array[a[i]-1] == c[i]:
score = score + d[i]
if max_score < score:
max_score = score
print( max_score )
``` | instruction | 0 | 70,520 | 5 | 141,040 |
No | output | 1 | 70,520 | 5 | 141,041 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).
Consider a sequence A satisfying the following conditions:
* A is a sequence of N positive integers.
* 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.
Let us define a score of this sequence as follows:
* The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)
Find the maximum possible score of A.
Constraints
* All values in input are integers.
* 2 ≤ N ≤ 10
* 1 \leq M \leq 10
* 1 \leq Q \leq 50
* 1 \leq a_i < b_i \leq N ( i = 1, 2, ..., Q )
* 0 \leq c_i \leq M - 1 ( i = 1, 2, ..., Q )
* (a_i, b_i, c_i) \neq (a_j, b_j, c_j) (where i \neq j)
* 1 \leq d_i \leq 10^5 ( i = 1, 2, ..., Q )
Input
Input is given from Standard Input in the following format:
N M Q
a_1 b_1 c_1 d_1
:
a_Q b_Q c_Q d_Q
Output
Print the maximum possible score of A.
Examples
Input
3 4 3
1 3 3 100
1 2 2 10
2 3 2 10
Output
110
Input
4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328
Output
357500
Input
10 10 1
1 10 9 1
Output
1
Submitted Solution:
```
import itertools
N, M, Q = map(int,input().split())
ABCD = [tuple(map(int, input().split())) for _ in range(Q)]
ans = 0
for s in itertools.combinations_with_replacement(range(1,N+1),N):
temp = 0
for i in range(Q):
if s[ABCD[i][1]-1] - s[ABCD[i][0]-1] == ABCD[i][2]:
temp += ABCD[i][3]
ans = max(ans,temp)
print(ans)
``` | instruction | 0 | 70,521 | 5 | 141,042 |
No | output | 1 | 70,521 | 5 | 141,043 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).
Consider a sequence A satisfying the following conditions:
* A is a sequence of N positive integers.
* 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.
Let us define a score of this sequence as follows:
* The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)
Find the maximum possible score of A.
Constraints
* All values in input are integers.
* 2 ≤ N ≤ 10
* 1 \leq M \leq 10
* 1 \leq Q \leq 50
* 1 \leq a_i < b_i \leq N ( i = 1, 2, ..., Q )
* 0 \leq c_i \leq M - 1 ( i = 1, 2, ..., Q )
* (a_i, b_i, c_i) \neq (a_j, b_j, c_j) (where i \neq j)
* 1 \leq d_i \leq 10^5 ( i = 1, 2, ..., Q )
Input
Input is given from Standard Input in the following format:
N M Q
a_1 b_1 c_1 d_1
:
a_Q b_Q c_Q d_Q
Output
Print the maximum possible score of A.
Examples
Input
3 4 3
1 3 3 100
1 2 2 10
2 3 2 10
Output
110
Input
4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328
Output
357500
Input
10 10 1
1 10 9 1
Output
1
Submitted Solution:
```
# import math
# from collections import Counter
# N = int(input()) # 1行, 単数
# arg = list(map(int, input().split())) # 1行, 配列
# D = Counter(arg) # 出現数カウント
# print('Yes')
# print('No')
# print()
arg = list(map(int, input().split())) # 1行, 配列
N = arg[0]
M = arg[1]
Q = arg[2]
listA=[]
maxim = 0
while True:
try:
listA.append(list(map(int,input().split())))
except:
break;
A = []
As = []
for x in range(1,M+1):
A = [x] * N
As.append(list(A))
for i in list(range(N-1,0,-1)):
while A[i] < M:
A[i] = A[i] + 1
As.append(list(A))
for item in As:
letMaxim = 0
for l in listA:
if item[l[1]-1] - item[l[0]-1] == l[2]:
letMaxim = letMaxim + l[3]
if maxim < letMaxim:
maxim = letMaxim
print(maxim)
``` | instruction | 0 | 70,522 | 5 | 141,044 |
No | output | 1 | 70,522 | 5 | 141,045 |
Provide a correct Python 3 solution for this coding contest problem.
Given is a string S. Each character in S is either a digit (`0`, ..., `9`) or `?`.
Among the integers obtained by replacing each occurrence of `?` with a digit, how many have a remainder of 5 when divided by 13? An integer may begin with 0.
Since the answer can be enormous, print the count modulo 10^9+7.
Constraints
* S is a string consisting of digits (`0`, ..., `9`) and `?`.
* 1 \leq |S| \leq 10^5
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of integers satisfying the condition, modulo 10^9+7.
Examples
Input
??2??5
Output
768
Input
?44
Output
1
Input
7?4
Output
0
Input
?6?42???8??2??06243????9??3???7258??5??7???????774????4?1??17???9?5?70???76???
Output
153716888 | instruction | 0 | 70,541 | 5 | 141,082 |
"Correct Solution:
```
s=input()
n=len(s)
v=[[0]*13 for i in range(n+1)]
v[0][0]=1
m=10**9+7
for i in range(n):
for j in range(13):
for k in range(10):
x=(10*j+k)%13
v[i+1][x]=(v[i+1][x]+(1 if s[i]=='?' or s[i]==str(k) else 0)*v[i][j])%m
print(v[n][5])
``` | output | 1 | 70,541 | 5 | 141,083 |
Provide a correct Python 3 solution for this coding contest problem.
Given is a string S. Each character in S is either a digit (`0`, ..., `9`) or `?`.
Among the integers obtained by replacing each occurrence of `?` with a digit, how many have a remainder of 5 when divided by 13? An integer may begin with 0.
Since the answer can be enormous, print the count modulo 10^9+7.
Constraints
* S is a string consisting of digits (`0`, ..., `9`) and `?`.
* 1 \leq |S| \leq 10^5
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of integers satisfying the condition, modulo 10^9+7.
Examples
Input
??2??5
Output
768
Input
?44
Output
1
Input
7?4
Output
0
Input
?6?42???8??2??06243????9??3???7258??5??7???????774????4?1??17???9?5?70???76???
Output
153716888 | instruction | 0 | 70,543 | 5 | 141,086 |
"Correct Solution:
```
S = input()
N = len(S)
mod = 10**9 + 7
dp = [[0] * 13 for _ in range(N+1)]
dp[0][0] = 1
for i in range(N):
if S[i] == '?':
for j in range(10):
for k in range(13):
dp[i+1][(k*10+j)%13] += dp[i][k] % mod
else:
for k in range(13):
dp[i+1][(k*10+int(S[i]))%13] += dp[i][k] % mod
print(dp[-1][5] % mod)
``` | output | 1 | 70,543 | 5 | 141,087 |
Provide a correct Python 3 solution for this coding contest problem.
Given is a string S. Each character in S is either a digit (`0`, ..., `9`) or `?`.
Among the integers obtained by replacing each occurrence of `?` with a digit, how many have a remainder of 5 when divided by 13? An integer may begin with 0.
Since the answer can be enormous, print the count modulo 10^9+7.
Constraints
* S is a string consisting of digits (`0`, ..., `9`) and `?`.
* 1 \leq |S| \leq 10^5
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of integers satisfying the condition, modulo 10^9+7.
Examples
Input
??2??5
Output
768
Input
?44
Output
1
Input
7?4
Output
0
Input
?6?42???8??2??06243????9??3???7258??5??7???????774????4?1??17???9?5?70???76???
Output
153716888 | instruction | 0 | 70,544 | 5 | 141,088 |
"Correct Solution:
```
S=input()
l=len(S)
mod=10**9+7
dp=[[0 for j in range(13)] for i in range(l+1)]
dp[0][0]=1
for i in range(l):
if S[i]=='?':
for k in range(13):
for j in range(10):
dp[i+1][(k*10+j)%13]+=dp[i][k]%mod
else:
for k in range(13):
dp[i+1][(k*10 + int(S[i]))%13]+=dp[i][k]%mod
print(dp[-1][5]%mod)
``` | output | 1 | 70,544 | 5 | 141,089 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a string S. Each character in S is either a digit (`0`, ..., `9`) or `?`.
Among the integers obtained by replacing each occurrence of `?` with a digit, how many have a remainder of 5 when divided by 13? An integer may begin with 0.
Since the answer can be enormous, print the count modulo 10^9+7.
Constraints
* S is a string consisting of digits (`0`, ..., `9`) and `?`.
* 1 \leq |S| \leq 10^5
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of integers satisfying the condition, modulo 10^9+7.
Examples
Input
??2??5
Output
768
Input
?44
Output
1
Input
7?4
Output
0
Input
?6?42???8??2??06243????9??3???7258??5??7???????774????4?1??17???9?5?70???76???
Output
153716888
Submitted Solution:
```
S = input()
N = len(S)
su = 0
L = [0]*13
L[0] = 1
M = [1, 10, 9, 12, 3, 4]
mod = 10**9+7
for i, c in enumerate(S[::-1]):
m = M[i % 6]
if c=="?":
Lc = L[:]
for j in range(m, m*10, m):
for k in range(13):
idx = (k+j)%13
L[idx] = (L[idx] + Lc[k]) % mod
else:
su += int(c) * m
print(L[(-su+5)%13])
``` | instruction | 0 | 70,547 | 5 | 141,094 |
Yes | output | 1 | 70,547 | 5 | 141,095 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a string S. Each character in S is either a digit (`0`, ..., `9`) or `?`.
Among the integers obtained by replacing each occurrence of `?` with a digit, how many have a remainder of 5 when divided by 13? An integer may begin with 0.
Since the answer can be enormous, print the count modulo 10^9+7.
Constraints
* S is a string consisting of digits (`0`, ..., `9`) and `?`.
* 1 \leq |S| \leq 10^5
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of integers satisfying the condition, modulo 10^9+7.
Examples
Input
??2??5
Output
768
Input
?44
Output
1
Input
7?4
Output
0
Input
?6?42???8??2??06243????9??3???7258??5??7???????774????4?1??17???9?5?70???76???
Output
153716888
Submitted Solution:
```
mod = 10 ** 9 + 7
s = input()
dp = [0] * 13
dp[0] = 1
for i in range(len(s)):
dp2 = [0] * 13
for j in range(10):
if (s[i] == '?') | (s[i] == str(j)):
for k in range(13):
dp2[(10 * k + j) % 13] += dp[k]
dp2[(10 * k + j) % 13] %= mod
dp = dp2
print(dp[5])
``` | instruction | 0 | 70,548 | 5 | 141,096 |
Yes | output | 1 | 70,548 | 5 | 141,097 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a string S. Each character in S is either a digit (`0`, ..., `9`) or `?`.
Among the integers obtained by replacing each occurrence of `?` with a digit, how many have a remainder of 5 when divided by 13? An integer may begin with 0.
Since the answer can be enormous, print the count modulo 10^9+7.
Constraints
* S is a string consisting of digits (`0`, ..., `9`) and `?`.
* 1 \leq |S| \leq 10^5
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of integers satisfying the condition, modulo 10^9+7.
Examples
Input
??2??5
Output
768
Input
?44
Output
1
Input
7?4
Output
0
Input
?6?42???8??2??06243????9??3???7258??5??7???????774????4?1??17???9?5?70???76???
Output
153716888
Submitted Solution:
```
def f(i,k):
for j in range(13):
dp[i+1][(j*10+k)%13]+=dp[i][j]
dp[i+1][(j*10+k)%13]%=mod
mod=10**9+7
s=input()
n=len(s)
dp=[[0]*13 for i in range(10**5+1)]
dp[0][0]=mul=1
for i in range(n):
if s[i]=='?':
for k in range(10):
f(i,k)
else:
f(i,int(s[i]))
print(dp[n][5]%mod)
``` | instruction | 0 | 70,549 | 5 | 141,098 |
Yes | output | 1 | 70,549 | 5 | 141,099 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.