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 |
|---|---|---|---|---|---|
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:
```
M = 10**9+7
r = tuple(tuple((j-i) * 4 % 13 for i in range(10)) for j in range(13))
d = [1] + [0] * 12
for c in input():
if c > "9":
d = [(sum(d[i] for i in j)) % M for j in r]
else:
d = [d[((j - int(c)) * 4 % 13)] for j in range(13)]
print(d[5])
``` | instruction | 0 | 70,550 | 5 | 141,100 |
Yes | output | 1 | 70,550 | 5 | 141,101 |
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()
s = list(S)
s.reverse()
#print (s)
lis = [0] * 13
lis[0] = 1
keta = 1
for i in range(len(S)):
nlis = [0] * 13
if s[i] == "?":
for j in range(10):
for k in range(13):
nlis[ (k + (j * keta)) % 13] += lis[k]
else:
now = int(s[i])
for k in range(13):
nlis[ (k + (now * keta)) % 13 ] += lis[k]
#print (nlis)
keta *= 10
for j in range(13):
lis[j] = nlis[j]
#print (lis)
print (lis[5] % (10**9 + 7))
``` | instruction | 0 | 70,552 | 5 | 141,104 |
No | output | 1 | 70,552 | 5 | 141,105 |
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 = list(input())
P = 10**9+7
Q = 13
dp = [0 for _ in range(Q)]
dp_pre = [0 for _ in range(Q)]
if S[0] == '?':
for i in range(10):
dp[i] = 1
else:
dp[int(S[0])] = 1
for i in range(1, len(S)):
for k in range(Q):
dp_pre[k] = dp[k]
dp[k] = 0
if S[i] == '?':
for j in range(10): # 数字
for k in range(Q): # 前の配列
q = (j+10*k)%Q
dp[q] += dp_pre[k]
else:
for k in range(Q):
q = (int(S[i])+10*k)%Q
dp[q] += dp_pre[k]
for k in range(Q):
dp[k] = dp[k] % P
ans = dp[5] % P
print(ans)
``` | instruction | 0 | 70,553 | 5 | 141,106 |
No | output | 1 | 70,553 | 5 | 141,107 |
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()
dp = [[0 for i in range(13)] for i in range(len(s))]
if s[-1] != "?":
dp[0][int(s[-1]) % 13] += 1
else:
for k in range(10):
dp[0][k % 13] += 1
for i in range(1,len(s)):
for r in range(13):
if s[-(i+1)] == "?":
for k in range(10):
dp[i][(k * (10**i) % 13 + r) % 13] += dp[i-1][r]
else:
dp[i][(int(s[-(i+1)]) * (10**i) % 13 + r) % 13] += dp[i-1][r]
for r in range(13)
dp[i][r] %= 10**9 + 7
print(dp[len(s)-1][5]%(10**9+7))
``` | instruction | 0 | 70,554 | 5 | 141,108 |
No | output | 1 | 70,554 | 5 | 141,109 |
Provide a correct Python 3 solution for this coding contest problem.
Aoki is playing with a sequence of numbers a_{1}, a_{2}, ..., a_{N}. Every second, he performs the following operation :
* Choose a positive integer k. For each element of the sequence v, Aoki may choose to replace v with its remainder when divided by k, or do nothing with v. The cost of this operation is 2^{k} (regardless of how many elements he changes).
Aoki wants to turn the sequence into b_{1}, b_{2}, ..., b_{N} (the order of the elements is important). Determine if it is possible for Aoki to perform this task and if yes, find the minimum cost required.
Constraints
* 1 \leq N \leq 50
* 0 \leq a_{i}, b_{i} \leq 50
* All values in the input are integers.
Input
Input is given from Standard Input in the following format:
N
a_{1} a_{2} ... a_{N}
b_{1} b_{2} ... b_{N}
Output
Print the minimum cost required to turn the original sequence into b_{1}, b_{2}, ..., b_{N}. If the task is impossible, output -1 instead.
Examples
Input
3
19 10 14
0 3 4
Output
160
Input
3
19 15 14
0 0 0
Output
2
Input
2
8 13
5 13
Output
-1
Input
4
2 0 1 8
2 0 1 8
Output
0
Input
1
50
13
Output
137438953472 | instruction | 0 | 70,587 | 5 | 141,174 |
"Correct Solution:
```
def rem(x,r):
if (x,r) == (1,0):
return [[1]]
if x <= 2*r:
return -1
ret = []
for i in range(1,x+1):
if x%i == r:
ret.append([i])
else:
s = rem(x%i,r)
if s == -1:
continue
else:
for j in s:
if j == -1:
continue
elif j[-1] < i:
ret.append([i]+j)
else:
ret.append([i]+j)
return ret
n = int(input())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
for xx,yy in zip(x,y):
if xx != yy and rem(xx,yy) == -1:
print(-1)
exit()
ls = [rem(xx,yy) if xx != yy else 0 for xx,yy in zip(x,y)]
flg = [0]*n
def findmx(lsi,ansst,mx):
ret = 100
if lsi == 0:
return 0
for lsls in lsi:
for j in lsls:
if j > mx:
return min(j,ret)
elif j in ansst:
continue
else:
ret = min(j,ret)
break
else:
return 0
else:
return ret
mxls = [ls[i][0][0] if type(ls[i]) == list else 0 for i in range(n)]
mx = max(mxls)
ansst = set((mx,))
mxcand = mx
while mxcand:
for i in range(n):
t = findmx(ls[i],ansst,mx)
mxls[i] = t
if t == 0:
flg[i] = 1
mxcand = max(mxls)
ansst.add(mxcand)
if flg.count(1) == n:
break
ans = 0
for b in ansst:
if b:
ans += 2**b
print(ans)
``` | output | 1 | 70,587 | 5 | 141,175 |
Provide a correct Python 3 solution for this coding contest problem.
Aoki is playing with a sequence of numbers a_{1}, a_{2}, ..., a_{N}. Every second, he performs the following operation :
* Choose a positive integer k. For each element of the sequence v, Aoki may choose to replace v with its remainder when divided by k, or do nothing with v. The cost of this operation is 2^{k} (regardless of how many elements he changes).
Aoki wants to turn the sequence into b_{1}, b_{2}, ..., b_{N} (the order of the elements is important). Determine if it is possible for Aoki to perform this task and if yes, find the minimum cost required.
Constraints
* 1 \leq N \leq 50
* 0 \leq a_{i}, b_{i} \leq 50
* All values in the input are integers.
Input
Input is given from Standard Input in the following format:
N
a_{1} a_{2} ... a_{N}
b_{1} b_{2} ... b_{N}
Output
Print the minimum cost required to turn the original sequence into b_{1}, b_{2}, ..., b_{N}. If the task is impossible, output -1 instead.
Examples
Input
3
19 10 14
0 3 4
Output
160
Input
3
19 15 14
0 0 0
Output
2
Input
2
8 13
5 13
Output
-1
Input
4
2 0 1 8
2 0 1 8
Output
0
Input
1
50
13
Output
137438953472 | instruction | 0 | 70,588 | 5 | 141,176 |
"Correct Solution:
```
def solve(bit_state, num, mod):
for div in range(1, num + 1):
if num % div == mod:
cand[i].append(bit_state | (1 << div))
if num % div > mod:
solve(bit_state | (1 << div), num % div, mod)
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cand = [[] for i in range(n)]
for i in range(n):
solve(0, a[i], b[i])
if a[i] == b[i]:
cand[i].append(0)
ans = 0
while True:
max_ = 0
for j in range(n):
min_ = 10 ** 5
for num in cand[j]:
min_ = min(min_, num.bit_length() - 1)
max_ = max(max_, min_)
if max_ == 0:
print(ans)
break
if max_ == 10 ** 5:
print(-1)
break
ans += 2 ** max_
tmp = [[] for i in range(n)]
for j in range(n):
for num in cand[j]:
if num & (1 << max_):
tmp[j].append(num - (1 << max_))
else:
tmp[j].append(num)
cand = tmp[0:]
``` | output | 1 | 70,588 | 5 | 141,177 |
Provide a correct Python 3 solution for this coding contest problem.
Aoki is playing with a sequence of numbers a_{1}, a_{2}, ..., a_{N}. Every second, he performs the following operation :
* Choose a positive integer k. For each element of the sequence v, Aoki may choose to replace v with its remainder when divided by k, or do nothing with v. The cost of this operation is 2^{k} (regardless of how many elements he changes).
Aoki wants to turn the sequence into b_{1}, b_{2}, ..., b_{N} (the order of the elements is important). Determine if it is possible for Aoki to perform this task and if yes, find the minimum cost required.
Constraints
* 1 \leq N \leq 50
* 0 \leq a_{i}, b_{i} \leq 50
* All values in the input are integers.
Input
Input is given from Standard Input in the following format:
N
a_{1} a_{2} ... a_{N}
b_{1} b_{2} ... b_{N}
Output
Print the minimum cost required to turn the original sequence into b_{1}, b_{2}, ..., b_{N}. If the task is impossible, output -1 instead.
Examples
Input
3
19 10 14
0 3 4
Output
160
Input
3
19 15 14
0 0 0
Output
2
Input
2
8 13
5 13
Output
-1
Input
4
2 0 1 8
2 0 1 8
Output
0
Input
1
50
13
Output
137438953472 | instruction | 0 | 70,589 | 5 | 141,178 |
"Correct Solution:
```
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
D = [[False] * 51 for i in range(51)]
use = []
def calc(a, b, D):
if a == b:
return True
d = {}
stack = [a]
while stack:
u = stack.pop()
if u == b:
return True
d[u] = 1
for w in range(1, 51):
if (u % w) in d:
continue
if D[u][u % w]:
stack.append(u % w)
return False
def check(n):
D = [[False] * 51 for i in range(51)]
for i in range(51):
for k in range(1, n):
D[i][i % k] = True
D[i][i] = True
for i in range(51):
for j in use:
D[i][i % j] = True
for a, b in zip(A, B):
if not calc(a, b, D):
return True
return False
if check(51):
print(-1)
exit()
ans = 0
for j in range(50, 0, -1):
if check(j):
use.append(j)
ans += 2 ** j
print(ans)
``` | output | 1 | 70,589 | 5 | 141,179 |
Provide a correct Python 3 solution for this coding contest problem.
Aoki is playing with a sequence of numbers a_{1}, a_{2}, ..., a_{N}. Every second, he performs the following operation :
* Choose a positive integer k. For each element of the sequence v, Aoki may choose to replace v with its remainder when divided by k, or do nothing with v. The cost of this operation is 2^{k} (regardless of how many elements he changes).
Aoki wants to turn the sequence into b_{1}, b_{2}, ..., b_{N} (the order of the elements is important). Determine if it is possible for Aoki to perform this task and if yes, find the minimum cost required.
Constraints
* 1 \leq N \leq 50
* 0 \leq a_{i}, b_{i} \leq 50
* All values in the input are integers.
Input
Input is given from Standard Input in the following format:
N
a_{1} a_{2} ... a_{N}
b_{1} b_{2} ... b_{N}
Output
Print the minimum cost required to turn the original sequence into b_{1}, b_{2}, ..., b_{N}. If the task is impossible, output -1 instead.
Examples
Input
3
19 10 14
0 3 4
Output
160
Input
3
19 15 14
0 0 0
Output
2
Input
2
8 13
5 13
Output
-1
Input
4
2 0 1 8
2 0 1 8
Output
0
Input
1
50
13
Output
137438953472 | instruction | 0 | 70,590 | 5 | 141,180 |
"Correct Solution:
```
def inpl(): return [int(i) for i in input().split()]
from collections import defaultdict
import sys
def edge(S):
e = defaultdict(lambda: set())
for i in range(N+1):
for j in S:
e[i].add(i%j)
e[i] = e[i] | {i}
return e
def path(edge):
p = defaultdict(lambda: set())
for st in range(N+1):
Q, p[st], new = [edge[st]]*3
while Q:
for j in Q:
new = new | edge[j]
Q = new - p[st]
p[st] = p[st] | new
return p
K = int(input())
A = inpl()
B = inpl()
for i in range(K):
if A[i] < B[i]:
print(-1)
sys.exit()
if A == B:
print(0)
sys.exit()
N = max(A)
T = []
for l in range(N,-1,-1):
S = T + list(range(1,1+l))
Pa = path(edge(S))
for i in range(K):
if B[i] not in Pa[A[i]]:
break
else:
continue
T.append(l+1)
if not T:
print(2)
sys.exit()
if N+1 in T:
print(-1)
sys.exit()
print(sum([2**i for i in T]))
``` | output | 1 | 70,590 | 5 | 141,181 |
Provide a correct Python 3 solution for this coding contest problem.
Aoki is playing with a sequence of numbers a_{1}, a_{2}, ..., a_{N}. Every second, he performs the following operation :
* Choose a positive integer k. For each element of the sequence v, Aoki may choose to replace v with its remainder when divided by k, or do nothing with v. The cost of this operation is 2^{k} (regardless of how many elements he changes).
Aoki wants to turn the sequence into b_{1}, b_{2}, ..., b_{N} (the order of the elements is important). Determine if it is possible for Aoki to perform this task and if yes, find the minimum cost required.
Constraints
* 1 \leq N \leq 50
* 0 \leq a_{i}, b_{i} \leq 50
* All values in the input are integers.
Input
Input is given from Standard Input in the following format:
N
a_{1} a_{2} ... a_{N}
b_{1} b_{2} ... b_{N}
Output
Print the minimum cost required to turn the original sequence into b_{1}, b_{2}, ..., b_{N}. If the task is impossible, output -1 instead.
Examples
Input
3
19 10 14
0 3 4
Output
160
Input
3
19 15 14
0 0 0
Output
2
Input
2
8 13
5 13
Output
-1
Input
4
2 0 1 8
2 0 1 8
Output
0
Input
1
50
13
Output
137438953472 | instruction | 0 | 70,591 | 5 | 141,182 |
"Correct Solution:
```
n = int(input())
xs = [int(c) for c in input().split()]
ys = [int(c) for c in input().split()]
def dp(x, y, mods):
if y > x:
return False
table = [False] * (x + 1)
table[x] = True
mods.sort(reverse=True)
for mod in mods:
for i in range(x + 1):
table[i % mod] = table[i % mod] or table[i]
return table[y]
def ok(mods):
return all(dp(x, y, list(mods)) for x, y in zip(xs, ys))
if not ok(range(1, 51)):
print(-1)
quit(0)
mods = []
for mod in range(50, 0, -1):
if not ok(mods + list(range(1, mod))):
mods.append(mod)
print(sum(2 ** mod for mod in mods))
``` | output | 1 | 70,591 | 5 | 141,183 |
Provide a correct Python 3 solution for this coding contest problem.
Aoki is playing with a sequence of numbers a_{1}, a_{2}, ..., a_{N}. Every second, he performs the following operation :
* Choose a positive integer k. For each element of the sequence v, Aoki may choose to replace v with its remainder when divided by k, or do nothing with v. The cost of this operation is 2^{k} (regardless of how many elements he changes).
Aoki wants to turn the sequence into b_{1}, b_{2}, ..., b_{N} (the order of the elements is important). Determine if it is possible for Aoki to perform this task and if yes, find the minimum cost required.
Constraints
* 1 \leq N \leq 50
* 0 \leq a_{i}, b_{i} \leq 50
* All values in the input are integers.
Input
Input is given from Standard Input in the following format:
N
a_{1} a_{2} ... a_{N}
b_{1} b_{2} ... b_{N}
Output
Print the minimum cost required to turn the original sequence into b_{1}, b_{2}, ..., b_{N}. If the task is impossible, output -1 instead.
Examples
Input
3
19 10 14
0 3 4
Output
160
Input
3
19 15 14
0 0 0
Output
2
Input
2
8 13
5 13
Output
-1
Input
4
2 0 1 8
2 0 1 8
Output
0
Input
1
50
13
Output
137438953472 | instruction | 0 | 70,592 | 5 | 141,184 |
"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():
n = I()
a = LI()
b = LI()
ans = 0
l = []
m = 51
for num in range(1,m+1)[::-1]:
res = list(range(1,num))+l
d = [[0 if i == j else float("inf") for j in range(m)] for i in range(m)]
for k in res:
for i in range(m):
d[i][i%k] = 0
for k in range(m):
for i in range(m):
for j in range(m):
nd = d[i][k]+d[k][j]
if nd < d[i][j]:
d[i][j] = nd
for i in range(n):
if d[a[i]][b[i]] == float("inf"):
break
else:
continue
if num == m:
print(-1)
return
else:
ans += 1<<num
l.append(num)
print(ans)
return
#Solve
if __name__ == "__main__":
solve()
``` | output | 1 | 70,592 | 5 | 141,185 |
Provide a correct Python 3 solution for this coding contest problem.
Aoki is playing with a sequence of numbers a_{1}, a_{2}, ..., a_{N}. Every second, he performs the following operation :
* Choose a positive integer k. For each element of the sequence v, Aoki may choose to replace v with its remainder when divided by k, or do nothing with v. The cost of this operation is 2^{k} (regardless of how many elements he changes).
Aoki wants to turn the sequence into b_{1}, b_{2}, ..., b_{N} (the order of the elements is important). Determine if it is possible for Aoki to perform this task and if yes, find the minimum cost required.
Constraints
* 1 \leq N \leq 50
* 0 \leq a_{i}, b_{i} \leq 50
* All values in the input are integers.
Input
Input is given from Standard Input in the following format:
N
a_{1} a_{2} ... a_{N}
b_{1} b_{2} ... b_{N}
Output
Print the minimum cost required to turn the original sequence into b_{1}, b_{2}, ..., b_{N}. If the task is impossible, output -1 instead.
Examples
Input
3
19 10 14
0 3 4
Output
160
Input
3
19 15 14
0 0 0
Output
2
Input
2
8 13
5 13
Output
-1
Input
4
2 0 1 8
2 0 1 8
Output
0
Input
1
50
13
Output
137438953472 | instruction | 0 | 70,593 | 5 | 141,186 |
"Correct Solution:
```
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
def main():
graph = [[] for _ in range(51)]
for start in range(51):
for cost in range(1,51):
if start%cost == 0:
graph[0].append((cost, start))
for end in range(1, 51):
for cost in range(end+1, 51):
start = end + cost
while start <= 50:
graph[end].append((cost, start))
start += cost
use = 0
for l in reversed(range(1, 52)):
for a, b in zip(A, B):
ok = False
q = [b]
checked = [False]*51
checked[b] = True
while q:
qq = []
for p in q:
if p == a:
ok = True
break
for cost, np in graph[p]:
if not checked[np] and (cost < l or use&(1<<cost)):
checked[np] = True
qq.append(np)
if ok: break
q = qq
if not ok:
if l == 51:
return -1
use |= (1<<l)
break
return use
if __name__ == "__main__":
print(main())
``` | output | 1 | 70,593 | 5 | 141,187 |
Provide a correct Python 3 solution for this coding contest problem.
Aoki is playing with a sequence of numbers a_{1}, a_{2}, ..., a_{N}. Every second, he performs the following operation :
* Choose a positive integer k. For each element of the sequence v, Aoki may choose to replace v with its remainder when divided by k, or do nothing with v. The cost of this operation is 2^{k} (regardless of how many elements he changes).
Aoki wants to turn the sequence into b_{1}, b_{2}, ..., b_{N} (the order of the elements is important). Determine if it is possible for Aoki to perform this task and if yes, find the minimum cost required.
Constraints
* 1 \leq N \leq 50
* 0 \leq a_{i}, b_{i} \leq 50
* All values in the input are integers.
Input
Input is given from Standard Input in the following format:
N
a_{1} a_{2} ... a_{N}
b_{1} b_{2} ... b_{N}
Output
Print the minimum cost required to turn the original sequence into b_{1}, b_{2}, ..., b_{N}. If the task is impossible, output -1 instead.
Examples
Input
3
19 10 14
0 3 4
Output
160
Input
3
19 15 14
0 0 0
Output
2
Input
2
8 13
5 13
Output
-1
Input
4
2 0 1 8
2 0 1 8
Output
0
Input
1
50
13
Output
137438953472 | instruction | 0 | 70,594 | 5 | 141,188 |
"Correct Solution:
```
def main():
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = [[None]*51 for _ in [0]*51] # 目的のあまり、現在の数値
for i in range(51):
d[i][i] = [[]]
for i in range(51): # あまり
for j in range(i+1, 51): # 現在の数値
temp = []
for kk in range(1, j+1): # 割る数
k = j % kk
if d[i][k] is None:
continue
for l in d[i][k]:
temp += [l+[kk]]
if temp == []:
temp = None
d[i][j] = temp
c = [d[bb][aa] for aa, bb in zip(a, b)]
if None in c:
print(-1)
return
ans = 0
while True:
M = -1
for i in range(n):
if [] in c[i]:
c[i] = [[]]
else:
m = min([j[-1] for j in c[i]])
M = max(M, m)
if M == -1:
break
ans += 2**M
for i in range(n):
temp = []
if c[i] == [[]]:
continue
for j in c[i]:
if j[-1] == M:
temp.append(j[:-1])
elif j[-1] < M:
temp.append(j)
c[i] = temp
print(ans)
main()
``` | output | 1 | 70,594 | 5 | 141,189 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Aoki is playing with a sequence of numbers a_{1}, a_{2}, ..., a_{N}. Every second, he performs the following operation :
* Choose a positive integer k. For each element of the sequence v, Aoki may choose to replace v with its remainder when divided by k, or do nothing with v. The cost of this operation is 2^{k} (regardless of how many elements he changes).
Aoki wants to turn the sequence into b_{1}, b_{2}, ..., b_{N} (the order of the elements is important). Determine if it is possible for Aoki to perform this task and if yes, find the minimum cost required.
Constraints
* 1 \leq N \leq 50
* 0 \leq a_{i}, b_{i} \leq 50
* All values in the input are integers.
Input
Input is given from Standard Input in the following format:
N
a_{1} a_{2} ... a_{N}
b_{1} b_{2} ... b_{N}
Output
Print the minimum cost required to turn the original sequence into b_{1}, b_{2}, ..., b_{N}. If the task is impossible, output -1 instead.
Examples
Input
3
19 10 14
0 3 4
Output
160
Input
3
19 15 14
0 0 0
Output
2
Input
2
8 13
5 13
Output
-1
Input
4
2 0 1 8
2 0 1 8
Output
0
Input
1
50
13
Output
137438953472
Submitted Solution:
```
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
if any([a < b for a,b in zip(A,B)]):
print(-1)
exit()
if A == B:
print(0)
exit()
def reachable(a,b,gr):
if a == b: return True
assert a > b
visited = [0] * (a+1)
stack = [a]
while stack:
v = stack.pop()
if v == b: return True
visited[v] = 1
for to in gr[v]:
if visited[to]: continue
stack.append(to)
return False
permanent_use = []
def need(n):
gr = [set() for i in range(51)]
for i in range(51):
for p in permanent_use:
gr[i].add(i%p)
for j in range(1,n):
gr[i].add(i%j)
for a,b in zip(A,B):
if not reachable(a,b,gr):
return True
return False
if need(51):
print(-1)
exit()
for i in range(50,0,-1):
if need(i):
permanent_use.append(i)
ans = 0
for p in permanent_use:
ans += 2**p
print(ans)
``` | instruction | 0 | 70,595 | 5 | 141,190 |
Yes | output | 1 | 70,595 | 5 | 141,191 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Aoki is playing with a sequence of numbers a_{1}, a_{2}, ..., a_{N}. Every second, he performs the following operation :
* Choose a positive integer k. For each element of the sequence v, Aoki may choose to replace v with its remainder when divided by k, or do nothing with v. The cost of this operation is 2^{k} (regardless of how many elements he changes).
Aoki wants to turn the sequence into b_{1}, b_{2}, ..., b_{N} (the order of the elements is important). Determine if it is possible for Aoki to perform this task and if yes, find the minimum cost required.
Constraints
* 1 \leq N \leq 50
* 0 \leq a_{i}, b_{i} \leq 50
* All values in the input are integers.
Input
Input is given from Standard Input in the following format:
N
a_{1} a_{2} ... a_{N}
b_{1} b_{2} ... b_{N}
Output
Print the minimum cost required to turn the original sequence into b_{1}, b_{2}, ..., b_{N}. If the task is impossible, output -1 instead.
Examples
Input
3
19 10 14
0 3 4
Output
160
Input
3
19 15 14
0 0 0
Output
2
Input
2
8 13
5 13
Output
-1
Input
4
2 0 1 8
2 0 1 8
Output
0
Input
1
50
13
Output
137438953472
Submitted Solution:
```
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
# a->b, possible with using at most c as max
T = [[[None] * 51 for _ in range(51)] for _ in range(51)]
def dp(a, b, c):
if T[a][b][c] is not None:
return T[a][b][c]
if a == b:
T[a][b][c] = True
return T[a][b][c]
# if c == 0:
# T[a][b][c] = b == 0
# return T[a][b][c]
if b >= c or a < b:
T[a][b][c] = False
return T[a][b][c]
if dp(a, b, c-1):
T[a][b][c] = True
return T[a][b][c]
else:
T[a][b][c] = dp(a % c, b, c-1)
return T[a][b][c]
T2 = [[None] * 51 for _ in range(51)]
def min_c(a, b):
if T2[a][b] is not None:
return T2[a][b]
for c in range(51):
if dp(a,b,c):
T2[a][b] = c
return T2[a][b]
T2[a][b] = 51
return T2[a][b]
#print(min_c(14,0))
#print(min_c(14,4))
def solve():
count = 0
for a, b in zip(A,B):
if a < b:
print(-1)
return
if a > b:
count += 1
# print(count)
# print(list(zip(A, B)))
# return
cost = 0
ABs = [{(a, b)} if a > b else set() for a, b in zip(A,B)]
while count:
# min->max
mm = [min(min_c(a, b) for a, b in s) if s else 0 for s in ABs]
m = max(mm)
if m > 50:
print(-1)
return
cost += 2 ** m
for i in range(len(ABs)):
if mm[i] == m:
new_s = set()
done = False
for a, b in ABs[i]:
if min_c(a % m, b) == 0:
done = True
break
elif min_c(a, b) == m:
new_s.add((a % m, b))
if done:
count -= 1
ABs[i] = set()
else:
ABs[i] = new_s
else: # optional
new_s = set()
done = False
for a, b in ABs[i]:
if min_c(a % m, b) == 0:
done = True
break
elif min_c(a % m, b) < m:
new_s.add((a % m, b))
if done:
count -= 1
ABs[i] = set()
else:
ABs[i].update(new_s)
print(cost)
solve()
``` | instruction | 0 | 70,596 | 5 | 141,192 |
Yes | output | 1 | 70,596 | 5 | 141,193 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Aoki is playing with a sequence of numbers a_{1}, a_{2}, ..., a_{N}. Every second, he performs the following operation :
* Choose a positive integer k. For each element of the sequence v, Aoki may choose to replace v with its remainder when divided by k, or do nothing with v. The cost of this operation is 2^{k} (regardless of how many elements he changes).
Aoki wants to turn the sequence into b_{1}, b_{2}, ..., b_{N} (the order of the elements is important). Determine if it is possible for Aoki to perform this task and if yes, find the minimum cost required.
Constraints
* 1 \leq N \leq 50
* 0 \leq a_{i}, b_{i} \leq 50
* All values in the input are integers.
Input
Input is given from Standard Input in the following format:
N
a_{1} a_{2} ... a_{N}
b_{1} b_{2} ... b_{N}
Output
Print the minimum cost required to turn the original sequence into b_{1}, b_{2}, ..., b_{N}. If the task is impossible, output -1 instead.
Examples
Input
3
19 10 14
0 3 4
Output
160
Input
3
19 15 14
0 0 0
Output
2
Input
2
8 13
5 13
Output
-1
Input
4
2 0 1 8
2 0 1 8
Output
0
Input
1
50
13
Output
137438953472
Submitted Solution:
```
"""
Writer: SPD_9X2
https://atcoder.jp/contests/agc022/tasks/agc022_c
ある t 以下のkで全て終わらせる < t+1を使う
なので、まず答えを満たすのに必要な最小の最大値を求める必要がある
大きい奴は使わない方がよい
→これを使わなくても答えが成立しうるか?を上から決めてく
計算量不安だけど平気そう
"""
def able(na,nb,lis):
if na < nb:
return False
elif na == nb:
return True
q = {}
q[na] = 1
for i in range(50,0,-1):
temp = []
if not lis[i]:
continue
for j in q:
if j % i == nb:
return True
elif j % i > nb:
temp.append(j % i)
for j in temp:
q[j] = 1
return False
N = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
lis = [True] * 51
import sys
for j in range(N):
if not able(a[j],b[j],lis):
print (-1)
sys.exit()
for i in range(50,0,-1):
lis[i] = False
for j in range(N):
ret = able(a[j],b[j],lis)
if not ret:
lis[i] = True
break
ans = 0
for i in range(1,51):
if lis[i]:
ans += 2**i
print (ans)
``` | instruction | 0 | 70,597 | 5 | 141,194 |
Yes | output | 1 | 70,597 | 5 | 141,195 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Aoki is playing with a sequence of numbers a_{1}, a_{2}, ..., a_{N}. Every second, he performs the following operation :
* Choose a positive integer k. For each element of the sequence v, Aoki may choose to replace v with its remainder when divided by k, or do nothing with v. The cost of this operation is 2^{k} (regardless of how many elements he changes).
Aoki wants to turn the sequence into b_{1}, b_{2}, ..., b_{N} (the order of the elements is important). Determine if it is possible for Aoki to perform this task and if yes, find the minimum cost required.
Constraints
* 1 \leq N \leq 50
* 0 \leq a_{i}, b_{i} \leq 50
* All values in the input are integers.
Input
Input is given from Standard Input in the following format:
N
a_{1} a_{2} ... a_{N}
b_{1} b_{2} ... b_{N}
Output
Print the minimum cost required to turn the original sequence into b_{1}, b_{2}, ..., b_{N}. If the task is impossible, output -1 instead.
Examples
Input
3
19 10 14
0 3 4
Output
160
Input
3
19 15 14
0 0 0
Output
2
Input
2
8 13
5 13
Output
-1
Input
4
2 0 1 8
2 0 1 8
Output
0
Input
1
50
13
Output
137438953472
Submitted Solution:
```
from heapq import heapify, heappush as hpush, heappop as hpop
def dijkstra(n, E, i0=0):
h = [[0, i0]]
D = [-1] * n
done = [0] * n
D[i0] = 0
while h:
d, i = hpop(h)
done[i] = 1
for j, w in E[i]:
nd = d + w
if D[j] < 0 or D[j] >= nd:
if done[j] == 0:
hpush(h, [nd, j])
D[j] = nd
return D
N = int(input())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
M = 51
X = [[] for _ in range(M)]
for i in range(1, M):
for j in range(1, i+1):
X[i].append([i%j, 2**j])
def chk(S):
M = 51
X = [[] for _ in range(M)]
for j in S:
for i in range(j, M):
X[i].append([i%j, 2**j])
DI = []
for i in range(M):
DI.append(dijkstra(M, X, i))
for i in range(N):
if DI[A[i]][B[i]] < 0:
return 0
return 1
L1 = [i for i in range(1, 51)]
L2 = []
if chk(L1) == 0:
print(-1)
else:
while L1:
while True:
if chk(L1 + L2):
if len(L1) == 0:
break
L1.pop()
else:
L2.append(L1[-1]+1 if L1 else 1)
L1 = [i for i in range(1, L2[-1])]
break
if len(L1) == 0:
break
print(sum([1<<l for l in L2]))
``` | instruction | 0 | 70,598 | 5 | 141,196 |
Yes | output | 1 | 70,598 | 5 | 141,197 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Aoki is playing with a sequence of numbers a_{1}, a_{2}, ..., a_{N}. Every second, he performs the following operation :
* Choose a positive integer k. For each element of the sequence v, Aoki may choose to replace v with its remainder when divided by k, or do nothing with v. The cost of this operation is 2^{k} (regardless of how many elements he changes).
Aoki wants to turn the sequence into b_{1}, b_{2}, ..., b_{N} (the order of the elements is important). Determine if it is possible for Aoki to perform this task and if yes, find the minimum cost required.
Constraints
* 1 \leq N \leq 50
* 0 \leq a_{i}, b_{i} \leq 50
* All values in the input are integers.
Input
Input is given from Standard Input in the following format:
N
a_{1} a_{2} ... a_{N}
b_{1} b_{2} ... b_{N}
Output
Print the minimum cost required to turn the original sequence into b_{1}, b_{2}, ..., b_{N}. If the task is impossible, output -1 instead.
Examples
Input
3
19 10 14
0 3 4
Output
160
Input
3
19 15 14
0 0 0
Output
2
Input
2
8 13
5 13
Output
-1
Input
4
2 0 1 8
2 0 1 8
Output
0
Input
1
50
13
Output
137438953472
Submitted Solution:
```
n = int(input())
xs = [int(c) for c in input().split()]
ys = [int(c) for c in input().split()]
def dp(x, y, mods):
table = [False] * (x + 1)
table[x] = True
mods.sort(reverse=True)
for mod in mods:
for i in range(x + 1):
table[i % mod] = table[i % mod] or table[i]
return table[y]
def ok(mods):
return all(dp(x, y, list(mods)) for x, y in zip(xs, ys))
if not ok(range(1, 51)):
print(-1)
quit(0)
mods = []
for mod in range(50, 0, -1):
if not ok(mods + list(range(1, mod))):
mods.append(mod)
print(sum(2 ** mod for mod in mods))
``` | instruction | 0 | 70,599 | 5 | 141,198 |
No | output | 1 | 70,599 | 5 | 141,199 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Aoki is playing with a sequence of numbers a_{1}, a_{2}, ..., a_{N}. Every second, he performs the following operation :
* Choose a positive integer k. For each element of the sequence v, Aoki may choose to replace v with its remainder when divided by k, or do nothing with v. The cost of this operation is 2^{k} (regardless of how many elements he changes).
Aoki wants to turn the sequence into b_{1}, b_{2}, ..., b_{N} (the order of the elements is important). Determine if it is possible for Aoki to perform this task and if yes, find the minimum cost required.
Constraints
* 1 \leq N \leq 50
* 0 \leq a_{i}, b_{i} \leq 50
* All values in the input are integers.
Input
Input is given from Standard Input in the following format:
N
a_{1} a_{2} ... a_{N}
b_{1} b_{2} ... b_{N}
Output
Print the minimum cost required to turn the original sequence into b_{1}, b_{2}, ..., b_{N}. If the task is impossible, output -1 instead.
Examples
Input
3
19 10 14
0 3 4
Output
160
Input
3
19 15 14
0 0 0
Output
2
Input
2
8 13
5 13
Output
-1
Input
4
2 0 1 8
2 0 1 8
Output
0
Input
1
50
13
Output
137438953472
Submitted Solution:
```
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
def main():
border = 12
graph = [[] for _ in range(51)]
for start in range(51):
for cost in range(1,51):
if start%cost == 0:
graph[0].append((cost, start))
for end in range(1, 51):
for cost in range(end+1, 51):
start = end + cost
while start <= 50:
graph[end].append((cost, start))
start += cost
mustconsider = [True]*N
basebit = 0
for i, (a, b) in enumerate(zip(A, B)):
if b >= border:
mustconsider[i] = False
if a >= 2*b+1:
basebit |= 1<<(a-b)
elif a != b:
return -1
# 立ってるbitのcostを使う
ans = 10**60
for bit in range(1<<(border-1)):
bit <<= 1
ok = True
using = [0 for _ in range(N)]
lowest = []
for i, (a, b) in enumerate(zip(A, B)):
if mustconsider[i]:
canreach = False
q = [b]
checked = [False]*51
checked[b] = True
while q:
qq = []
for p in q:
if p == a:
canreach = True
break
if 2*p+1 <= a:
n = 1
while (a-p)//n > p:
if (a-p)%n == 0:
using[i] |= 1<<((a-p)//n)
n += 1
for cost, np in graph[p]:
if (1<<cost)&bit and not checked[np]:
checked[np] = True
qq.append(np)
if canreach: break
q = qq
if not canreach:
if using[i] == 0:
ok = False
break
l = using[i] & -using[i]
lowest.append((l, i))
if ok:
now = bit|basebit
lowest.sort(reverse=True)
for l, i in lowest:
if using[i]&now: continue
now |= l
ans = min(ans, now)
if ans == 10**60:
return -1
return ans
if __name__ == "__main__":
print(main())
``` | instruction | 0 | 70,600 | 5 | 141,200 |
No | output | 1 | 70,600 | 5 | 141,201 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Aoki is playing with a sequence of numbers a_{1}, a_{2}, ..., a_{N}. Every second, he performs the following operation :
* Choose a positive integer k. For each element of the sequence v, Aoki may choose to replace v with its remainder when divided by k, or do nothing with v. The cost of this operation is 2^{k} (regardless of how many elements he changes).
Aoki wants to turn the sequence into b_{1}, b_{2}, ..., b_{N} (the order of the elements is important). Determine if it is possible for Aoki to perform this task and if yes, find the minimum cost required.
Constraints
* 1 \leq N \leq 50
* 0 \leq a_{i}, b_{i} \leq 50
* All values in the input are integers.
Input
Input is given from Standard Input in the following format:
N
a_{1} a_{2} ... a_{N}
b_{1} b_{2} ... b_{N}
Output
Print the minimum cost required to turn the original sequence into b_{1}, b_{2}, ..., b_{N}. If the task is impossible, output -1 instead.
Examples
Input
3
19 10 14
0 3 4
Output
160
Input
3
19 15 14
0 0 0
Output
2
Input
2
8 13
5 13
Output
-1
Input
4
2 0 1 8
2 0 1 8
Output
0
Input
1
50
13
Output
137438953472
Submitted Solution:
```
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
def main():
border = 13
graph = [[] for _ in range(51)]
for start in range(51):
for cost in range(1,51):
if start%cost == 0:
graph[start].append((cost, 0))
for end in range(1, 51):
for cost in range(end+1, 51):
start = end + cost
while start <= 50:
graph[start].append((cost, end))
start += cost
mustconsider = [True]*N
basebit = 0
for i, (a, b) in enumerate(zip(A, B)):
if b >= border:
mustconsider[i] = False
if a >= 2*b+1:
basebit |= 1<<(a-b)
else:
return -1
# 立ってるbitのcostを使う
ans = 10**60
for bit in range(1<<border):
ok = True
for i, (a, b) in enumerate(zip(A, B)):
if mustconsider[i]:
okcost = False
q = [a]
checked = [False]*51
checked[a] = True
while q:
qq = []
for p in q:
if p == b:
okcost = True
break
for cost, np in graph[p]:
if (1<<cost)&bit and not checked[np]:
checked[np] = True
qq.append(np)
if okcost: break
q = qq
if not okcost:
ok = False
break
if ok:
ans = bit|basebit
break
if ans == 10**60:
return -1
return ans
if __name__ == "__main__":
print(main())
``` | instruction | 0 | 70,601 | 5 | 141,202 |
No | output | 1 | 70,601 | 5 | 141,203 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Aoki is playing with a sequence of numbers a_{1}, a_{2}, ..., a_{N}. Every second, he performs the following operation :
* Choose a positive integer k. For each element of the sequence v, Aoki may choose to replace v with its remainder when divided by k, or do nothing with v. The cost of this operation is 2^{k} (regardless of how many elements he changes).
Aoki wants to turn the sequence into b_{1}, b_{2}, ..., b_{N} (the order of the elements is important). Determine if it is possible for Aoki to perform this task and if yes, find the minimum cost required.
Constraints
* 1 \leq N \leq 50
* 0 \leq a_{i}, b_{i} \leq 50
* All values in the input are integers.
Input
Input is given from Standard Input in the following format:
N
a_{1} a_{2} ... a_{N}
b_{1} b_{2} ... b_{N}
Output
Print the minimum cost required to turn the original sequence into b_{1}, b_{2}, ..., b_{N}. If the task is impossible, output -1 instead.
Examples
Input
3
19 10 14
0 3 4
Output
160
Input
3
19 15 14
0 0 0
Output
2
Input
2
8 13
5 13
Output
-1
Input
4
2 0 1 8
2 0 1 8
Output
0
Input
1
50
13
Output
137438953472
Submitted Solution:
```
#!/usr/bin/env python3
huge = 100
def get_k(a, b):
assert b >= 0 and a >= 0
if b == a:
return 0
if b == 0:
return 1
if 2 * b >= a:
return huge
for k in range(b + 1, a):
if a % k == b:
return k
return huge
n = int(input())
ai = list(map(int, input().split()))
bi = list(map(int, input().split()))
assert len(ai) == len(bi) == n
achievable = [{ai[i]} for i in range(n)]
res = 0
for roop in range(49):
max_k = 0
print(achievable)
for i in range(n):
min_k = huge
for a in achievable[i]:
k = get_k(a, bi[i])
min_k = min(min_k, k)
max_k = max(max_k, min_k)
if max_k == huge:
res = -1
break
if max_k == 0:
break
for i in range(n):
achievable[i].add(a % max_k)
res += 2 ** max_k
print(res)
``` | instruction | 0 | 70,602 | 5 | 141,204 |
No | output | 1 | 70,602 | 5 | 141,205 |
Provide a correct Python 3 solution for this coding contest problem.
For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0.
Constraints
* $1 \leq N \leq 10^5$
* $1 \leq K \leq 10^5$
* $1 \leq a_i \leq 10^5$
Input
The input is given in the following format.
$N$ $K$
$a_1$ $a_2$ ... $a_N$
Output
Print the smallest sub-array size in a line.
Examples
Input
6 2
4 1 2 1 3 5
Output
2
Input
6 3
4 1 2 1 3 5
Output
3
Input
3 4
1 2 3
Output
0 | instruction | 0 | 70,720 | 5 | 141,440 |
"Correct Solution:
```
n, k = map(int, input().split())
aa = list(map(int, input().split()))
cnts = [0] * (k + 1)
ans = 1e6
existing = 0
r = 0
for l in range(n - k + 1):
while r < n and existing < k:
a = aa[r]
if a <= k:
cnts[a] += 1
if cnts[a] == 1:
existing += 1
r += 1
if k == existing:
ans = min(ans, r - l)
a = aa[l]
if a <= k:
cnts[a] -= 1
if cnts[a] == 0:
existing -= 1
print(ans if ans < 1e6 else 0)
``` | output | 1 | 70,720 | 5 | 141,441 |
Provide a correct Python 3 solution for this coding contest problem.
For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0.
Constraints
* $1 \leq N \leq 10^5$
* $1 \leq K \leq 10^5$
* $1 \leq a_i \leq 10^5$
Input
The input is given in the following format.
$N$ $K$
$a_1$ $a_2$ ... $a_N$
Output
Print the smallest sub-array size in a line.
Examples
Input
6 2
4 1 2 1 3 5
Output
2
Input
6 3
4 1 2 1 3 5
Output
3
Input
3 4
1 2 3
Output
0 | instruction | 0 | 70,721 | 5 | 141,442 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
"""
Sliding Window - The Smallest Window II
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_3_B&lang=jp
"""
from collections import defaultdict
N, K = map(int, input().split())
A = [int(a) for a in input().split()]
left, right, num = 0, 0, 0
ans = float('inf')
count = defaultdict(int)
while True:
while right < N and num < K:
if count[A[right]] == 0 and A[right] <= K:
num += 1
count[A[right]] += 1
right += 1
if num < K:
break
ans = min(ans, right - left)
if count[A[left]] == 1 and A[left] <= K:
num -= 1
count[A[left]] -= 1
left += 1
print(ans if ans != float('inf') else 0)
``` | output | 1 | 70,721 | 5 | 141,443 |
Provide a correct Python 3 solution for this coding contest problem.
For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0.
Constraints
* $1 \leq N \leq 10^5$
* $1 \leq K \leq 10^5$
* $1 \leq a_i \leq 10^5$
Input
The input is given in the following format.
$N$ $K$
$a_1$ $a_2$ ... $a_N$
Output
Print the smallest sub-array size in a line.
Examples
Input
6 2
4 1 2 1 3 5
Output
2
Input
6 3
4 1 2 1 3 5
Output
3
Input
3 4
1 2 3
Output
0 | instruction | 0 | 70,722 | 5 | 141,444 |
"Correct Solution:
```
if __name__ == "__main__":
N, K = map(lambda x: int(x), input().split())
a = list(map(lambda x: int(x), input().split()))
ans = N + 1
idx = 0
num = 0
values = [0] * K
for s in range(N):
while (idx < N and num < K):
v = a[idx]
if (v <= K):
values[v - 1] += 1
if (1 == values[v - 1]):
num += 1
idx += 1
if (K == num):
ans = min(ans, idx - s)
v = a[s]
if (v <= K):
values[v - 1] -= 1
if (0 == values[v - 1]):
num -= 1
ans = ans if ans < N + 1 else 0
print(ans)
``` | output | 1 | 70,722 | 5 | 141,445 |
Provide a correct Python 3 solution for this coding contest problem.
For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0.
Constraints
* $1 \leq N \leq 10^5$
* $1 \leq K \leq 10^5$
* $1 \leq a_i \leq 10^5$
Input
The input is given in the following format.
$N$ $K$
$a_1$ $a_2$ ... $a_N$
Output
Print the smallest sub-array size in a line.
Examples
Input
6 2
4 1 2 1 3 5
Output
2
Input
6 3
4 1 2 1 3 5
Output
3
Input
3 4
1 2 3
Output
0 | instruction | 0 | 70,723 | 5 | 141,446 |
"Correct Solution:
```
import sys
n,k = map(int, input().split( ))
a = list(map(int, input().split( )))
tmp = max(a)
tmp2 = max(tmp,n,k)+1
chk = [0]*(tmp2)
for i in range(n):
chk[a[i]] += 1
if 0 in chk[1:k+1]:
print(0)
sys.exit()
right = n-1
left = 0
L = []
while right < n:
while chk[a[right]] > 1 or a[right] > k:
chk[a[right]] -= 1
right -= 1
ln = right - left + 1
L.append(ln)
while chk[a[left]] > 1 or a[left] > k:
chk[a[left]] -= 1
left += 1
ln = right - left + 1
L.append(ln)
chk[a[left]] -= 1
left += 1
while chk[a[left-1]] == 0:
right += 1
if right >= n:
break
chk[a[right]] += 1
ln = right -left +1
L.append(ln)
print(min(L))
``` | output | 1 | 70,723 | 5 | 141,447 |
Provide a correct Python 3 solution for this coding contest problem.
For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0.
Constraints
* $1 \leq N \leq 10^5$
* $1 \leq K \leq 10^5$
* $1 \leq a_i \leq 10^5$
Input
The input is given in the following format.
$N$ $K$
$a_1$ $a_2$ ... $a_N$
Output
Print the smallest sub-array size in a line.
Examples
Input
6 2
4 1 2 1 3 5
Output
2
Input
6 3
4 1 2 1 3 5
Output
3
Input
3 4
1 2 3
Output
0 | instruction | 0 | 70,725 | 5 | 141,450 |
"Correct Solution:
```
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def LIR(n): return [LI() for i in range(n)]
def MI(): return map(int, input().split())
#1:set
#1_A
"""
n,q = map(int, input().split(" "))
group = [[i] for i in range(n)]
key = [i for i in range(n)]
for i in range(q):
com, x, y = map(int, input().split(" "))
if com == 0:
if key[x] != key[y]:
v = key[y]
group[key[x]] = group[key[x]] + group[key[y]]
for j in group[v]:
key[j] = key[x]
group[v] = []
if com == 1:
if key[x] == key[y]:
print(1)
else:
print(0)
"""
#1_B
"""
def root(x,n):
if par[x][0] == x:
return [x,n+par[x][1]]
return root(par[x][0],par[x][1])
def unite(x,y):
rx = root(x)
ry = root(y)
if rx[0] == ry[0]:
return
par[rx][0] = ry[0]
par[rx][1] += ry[1]
n,q = map(int, input().split(" "))
par = [[i,0] for i in range(n)]
for i in range(q):
q = list(map(int, input().split(" ")))
if q[0] == 0:
if root(q[1],0) != root(q[])
"""
#2:range quary
#2_A
"""
n,q = map(int, input().split(" "))
k = 2**31-1
a = [float("inf") for i in range(n)]
for i in range(q):
com, x, y = map(int, input().split(" "))
if com == 0:
a[x] = y
else:
mi = k
for j in range(x, y+1):
if a[j] == float("inf"):
mi = min(mi, k)
else:
mi = min(mi,a[j])
print(mi)
"""
#2_B
#2_C
#2_D
#2_E
#2_F
#2_G
#2_H
#2_I
#3:sliding window
#3_A
"""
n,s = MI()
a = LI()
for i in range(1,n):
a[i] += a[i-1]
a.insert(0,0)
l = 0
r = 0
ans = float("inf")
if a[1] >= s:
print(1)
quit()
while r < n:
r += 1
if a[r]-a[l] >= s:
while a[r]-a[l] >= s and l < r:
l += 1
ans = min(ans, r-l+1)
if ans == float("inf"):
print(0)
quit()
print(ans)
"""
#4:coordinate compression
n,k = MI()
a = LI()
l = 0
r = 0
ans = float("inf")
fl = [0 for i in range(k+1)]
s = 0
if k == 1 and a[0] == 1:
print(1)
quit()
if a[0] <= k:
fl[a[0]] = 1
s = 1
while r < n-1:
r += 1
if a[r] <= k:
if not fl[a[r]]:
s += 1
fl[a[r]] += 1
if s == k:
while s == k:
l += 1
if a[l-1] <= k:
if fl[a[l-1]] == 1:
s -= 1
fl[a[l-1]] -= 1
ans = min(ans, r-l+2)
if ans == float("inf"):
print(0)
quit()
print(ans)
#5:comulative sum
#5_A
"""
n,t = map(int, input().split(" "))
num = [0 for i in range(t)]
for i in range(n):
l,r = map(int, input().split(" "))
num[l] += 1
if r < t:
num[r] -= 1
for i in range(1,t):
num[i] += num[i-1]
print(max(num))
"""
#5_B
"""
n = int(input())
lec = [[0 for i in range(1001)] for j in range(1001)]
max_x = 0
max_y = 0
for i in range(n):
x,y,s,t = map(int, input().split(" "))
lec[y][x] += 1
lec[y][s] -= 1
lec[t][x] -= 1
lec[t][s] += 1
max_x = max(max_x, s)
max_y = max(max_y, t)
for i in range(max_y+1):
for j in range(1, max_x+1):
lec[i][j] += lec[i][j-1]
for i in range(1, max_y+1):
for j in range(max_x+1):
lec[i][j] += lec[i-1][j]
ans = 0
for i in range(max_y+1):
for j in range(max_x+1):
ans = max(ans, lec[i][j])
print(ans)
"""
``` | output | 1 | 70,725 | 5 | 141,451 |
Provide a correct Python 3 solution for this coding contest problem.
For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0.
Constraints
* $1 \leq N \leq 10^5$
* $1 \leq K \leq 10^5$
* $1 \leq a_i \leq 10^5$
Input
The input is given in the following format.
$N$ $K$
$a_1$ $a_2$ ... $a_N$
Output
Print the smallest sub-array size in a line.
Examples
Input
6 2
4 1 2 1 3 5
Output
2
Input
6 3
4 1 2 1 3 5
Output
3
Input
3 4
1 2 3
Output
0 | instruction | 0 | 70,726 | 5 | 141,452 |
"Correct Solution:
```
N, K = map(int, input().split())
*A, = map(int, input().split())
ans = N+1
t = 0; u = [0]*K; c = 0
for s in range(N):
while t < N and c < K:
v = A[t]
if v <= K:
u[v-1] += 1
if u[v-1] == 1:
c += 1
t += 1
if c == K:
ans = min(ans, t-s)
v = A[s]
if v <= K:
u[v-1] -= 1
if u[v-1] == 0:
c -= 1
print(ans if ans < N+1 else 0)
``` | output | 1 | 70,726 | 5 | 141,453 |
Provide a correct Python 3 solution for this coding contest problem.
For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0.
Constraints
* $1 \leq N \leq 10^5$
* $1 \leq K \leq 10^5$
* $1 \leq a_i \leq 10^5$
Input
The input is given in the following format.
$N$ $K$
$a_1$ $a_2$ ... $a_N$
Output
Print the smallest sub-array size in a line.
Examples
Input
6 2
4 1 2 1 3 5
Output
2
Input
6 3
4 1 2 1 3 5
Output
3
Input
3 4
1 2 3
Output
0 | instruction | 0 | 70,727 | 5 | 141,454 |
"Correct Solution:
```
#!/usr/bin/env python3
# DSL_3_B: The Smallest Window II
class Window:
def __init__(self, k):
self.k = k
self.data = [0] * k
self.zeros = set(range(k))
def add(self, i):
if self.data[i-1] == 0:
self.zeros.remove(i-1)
self.data[i-1] += 1
def remove(self, i):
if self.data[i-1] == 1:
self.zeros.add(i-1)
self.data[i-1] -= 1
def removable(self, i):
return self.data[i-1] > 1
def open(self):
return len(self.zeros) == 0
def run():
n, k = [int(x) for x in input().split()]
li = [int(x) for x in input().split()]
w = Window(k)
i = 0
min_ = n+1
for j, v in enumerate(li):
if v <= k:
w.add(v)
while True:
if li[i] > k:
pass
elif w.removable(li[i]):
w.remove(li[i])
else:
break
i += 1
if w.open():
if min_ > j - i + 1:
min_ = j - i + 1
if min_ > n:
print(0)
else:
print(min_)
if __name__ == '__main__':
run()
``` | output | 1 | 70,727 | 5 | 141,455 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0.
Constraints
* $1 \leq N \leq 10^5$
* $1 \leq K \leq 10^5$
* $1 \leq a_i \leq 10^5$
Input
The input is given in the following format.
$N$ $K$
$a_1$ $a_2$ ... $a_N$
Output
Print the smallest sub-array size in a line.
Examples
Input
6 2
4 1 2 1 3 5
Output
2
Input
6 3
4 1 2 1 3 5
Output
3
Input
3 4
1 2 3
Output
0
Submitted Solution:
```
n, k = map(int, input().split())
aa = list(map(int, input().split()))
cnts = [0] * (k + 1)
ans = 1e6
existing = 0
r = 0
for l in range(n - k):
while r < n and existing < k:
a = aa[r]
if a <= k:
cnts[a] += 1
if cnts[a] == 1:
existing += 1
r += 1
ans = min(ans, r - l)
a = aa[l]
if a <= k:
cnts[a] -= 1
if cnts[a] == 0:
existing -= 1
print(ans if ans < 1e6 else 0)
``` | instruction | 0 | 70,728 | 5 | 141,456 |
No | output | 1 | 70,728 | 5 | 141,457 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0.
Constraints
* $1 \leq N \leq 10^5$
* $1 \leq K \leq 10^5$
* $1 \leq a_i \leq 10^5$
Input
The input is given in the following format.
$N$ $K$
$a_1$ $a_2$ ... $a_N$
Output
Print the smallest sub-array size in a line.
Examples
Input
6 2
4 1 2 1 3 5
Output
2
Input
6 3
4 1 2 1 3 5
Output
3
Input
3 4
1 2 3
Output
0
Submitted Solution:
```
n, k = map(int, input().split())
aa = list(map(int, input().split()))
cnts = [0] * (k + 1)
ans = 1e6
existing = 0
r = 0
for l in range(n - k + 1):
while r < n and existing < k:
a = aa[r]
if a <= k:
cnts[a] += 1
if cnts[a] == 1:
existing += 1
r += 1
ans = min(ans, r - l)
a = aa[l]
if a <= k:
cnts[a] -= 1
if cnts[a] == 0:
existing -= 1
print(ans if ans < 1e6 else 0)
``` | instruction | 0 | 70,729 | 5 | 141,458 |
No | output | 1 | 70,729 | 5 | 141,459 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets:
* 1+2*3=7
* 1*(2+3)=5
* 1*2*3=6
* (1+2)*3=9
Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2.
It's easy to see that the maximum value that you can obtain is 9.
Your task is: given a, b and c print the maximum value that you can get.
Input
The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).
Output
Print the maximum value of the expression that you can obtain.
Examples
Input
1
2
3
Output
9
Input
2
10
3
Output
60
Submitted Solution:
```
a=int(input())
b=int(input())
c=int(input())
A=a+b*c
B=a*(b+c)
C=a*b*c
D=(a+b)*c
E=a+b+c
list=[A,B,C,D,E]
large=max(list)
print(large)
``` | instruction | 0 | 71,143 | 5 | 142,286 |
Yes | output | 1 | 71,143 | 5 | 142,287 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets:
* 1+2*3=7
* 1*(2+3)=5
* 1*2*3=6
* (1+2)*3=9
Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2.
It's easy to see that the maximum value that you can obtain is 9.
Your task is: given a, b and c print the maximum value that you can get.
Input
The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).
Output
Print the maximum value of the expression that you can obtain.
Examples
Input
1
2
3
Output
9
Input
2
10
3
Output
60
Submitted Solution:
```
x =int(input())
y = int(input())
z =int(input())
a = list()
a.append(x+y+z)
a.append(x*(y+z))
a.append(x*y*z)
a.append((x+y)*z)
print(max(a))
``` | instruction | 0 | 71,144 | 5 | 142,288 |
Yes | output | 1 | 71,144 | 5 | 142,289 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets:
* 1+2*3=7
* 1*(2+3)=5
* 1*2*3=6
* (1+2)*3=9
Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2.
It's easy to see that the maximum value that you can obtain is 9.
Your task is: given a, b and c print the maximum value that you can get.
Input
The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).
Output
Print the maximum value of the expression that you can obtain.
Examples
Input
1
2
3
Output
9
Input
2
10
3
Output
60
Submitted Solution:
```
a = int(input())
b = int(input())
c = int(input())
print(max([(a+b)*c, a*b*c, a*(b+c), a+b*c, a*b+c, a+b+c]))
``` | instruction | 0 | 71,145 | 5 | 142,290 |
Yes | output | 1 | 71,145 | 5 | 142,291 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets:
* 1+2*3=7
* 1*(2+3)=5
* 1*2*3=6
* (1+2)*3=9
Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2.
It's easy to see that the maximum value that you can obtain is 9.
Your task is: given a, b and c print the maximum value that you can get.
Input
The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).
Output
Print the maximum value of the expression that you can obtain.
Examples
Input
1
2
3
Output
9
Input
2
10
3
Output
60
Submitted Solution:
```
a = int(input())
b = int(input())
c = int(input())
o1 = a + b + c
o2 = a * b * c
o3 = (a + b) * c
o4 = a + b * c
o5 = a * b + c
o6 = a * (b + c)
print(max(o1, o2, o3, o4, o5, o6))
``` | instruction | 0 | 71,146 | 5 | 142,292 |
Yes | output | 1 | 71,146 | 5 | 142,293 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets:
* 1+2*3=7
* 1*(2+3)=5
* 1*2*3=6
* (1+2)*3=9
Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2.
It's easy to see that the maximum value that you can obtain is 9.
Your task is: given a, b and c print the maximum value that you can get.
Input
The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).
Output
Print the maximum value of the expression that you can obtain.
Examples
Input
1
2
3
Output
9
Input
2
10
3
Output
60
Submitted Solution:
```
a = int(input())
b = int(input())
c = int(input())
if a == b == c == 1:
print(a + b + c)
elif a == 1:
print((a + b) * c)
elif c == 1:
print(a * (b + c))
elif max(a, b, c) == c:
if (a + b) > a * b:
print((a + b) * c)
else:
print(a * b * c)
elif max(a, b, c, ) == a:
if (b + c) > b * c:
print((b + c) * a)
else:
print(a * b * c)
elif max(a, b, c) == b:
if (a + c) > a * c:
print((b + min(a, b, c)) * c)
else:
print(a * b * c)
``` | instruction | 0 | 71,147 | 5 | 142,294 |
No | output | 1 | 71,147 | 5 | 142,295 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets:
* 1+2*3=7
* 1*(2+3)=5
* 1*2*3=6
* (1+2)*3=9
Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2.
It's easy to see that the maximum value that you can obtain is 9.
Your task is: given a, b and c print the maximum value that you can get.
Input
The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).
Output
Print the maximum value of the expression that you can obtain.
Examples
Input
1
2
3
Output
9
Input
2
10
3
Output
60
Submitted Solution:
```
i=int(input())
j=int(input())
k=int(input())
q=max(i,j,k)
print((i+j+k-q)*q)
``` | instruction | 0 | 71,148 | 5 | 142,296 |
No | output | 1 | 71,148 | 5 | 142,297 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets:
* 1+2*3=7
* 1*(2+3)=5
* 1*2*3=6
* (1+2)*3=9
Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2.
It's easy to see that the maximum value that you can obtain is 9.
Your task is: given a, b and c print the maximum value that you can get.
Input
The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).
Output
Print the maximum value of the expression that you can obtain.
Examples
Input
1
2
3
Output
9
Input
2
10
3
Output
60
Submitted Solution:
```
n1 = int(input())
n2 = int(input())
n3 = int(input())
if n1 >= 1 or n1 <= 10 and n2 >= 1 or n2 <= 10 and n3 >= 1 or n3 > 10:
if n1+n2*n3 > n1*(n2+n3) and n1*(n2+n3) > n1*n2*n3 and n1+n2*n3 > (n1+n2)*n3:
print(n1+n2*n3 )
elif n1*(n2+n3) > n1*n2*n3 and n1*n2*n3 > (n1+n2)*n3:
print(n1*(n2+n3))
elif n1*n2*n3 >( n1+n2)*n3:
print(n1*n2*n3)
else:
print((n1+n2)*n3)
# 1506176734281
``` | instruction | 0 | 71,149 | 5 | 142,298 |
No | output | 1 | 71,149 | 5 | 142,299 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets:
* 1+2*3=7
* 1*(2+3)=5
* 1*2*3=6
* (1+2)*3=9
Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2.
It's easy to see that the maximum value that you can obtain is 9.
Your task is: given a, b and c print the maximum value that you can get.
Input
The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).
Output
Print the maximum value of the expression that you can obtain.
Examples
Input
1
2
3
Output
9
Input
2
10
3
Output
60
Submitted Solution:
```
a = int(input())
b = int(input())
c = int(input())
v1 = a + b * c
v2 = a * (b + c)
v3 = a * b * c
v4 = (a + b) * c
res = max(v1, v2, v3, v4)
print(res)
``` | instruction | 0 | 71,150 | 5 | 142,300 |
No | output | 1 | 71,150 | 5 | 142,301 |
Provide a correct Python 3 solution for this coding contest problem.
Compute A \times B.
Constraints
* 1 \leq A \leq 100
* 1 \leq B \leq 100
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the value A \times B as an integer.
Examples
Input
2 5
Output
10
Input
100 100
Output
10000 | instruction | 0 | 71,383 | 5 | 142,766 |
"Correct Solution:
```
a, b = map(int, input().split())
print(a*b)
``` | output | 1 | 71,383 | 5 | 142,767 |
Provide a correct Python 3 solution for this coding contest problem.
Compute A \times B.
Constraints
* 1 \leq A \leq 100
* 1 \leq B \leq 100
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the value A \times B as an integer.
Examples
Input
2 5
Output
10
Input
100 100
Output
10000 | instruction | 0 | 71,384 | 5 | 142,768 |
"Correct Solution:
```
a,b=map(int,(input()).split())
print(a*b)
``` | output | 1 | 71,384 | 5 | 142,769 |
Provide a correct Python 3 solution for this coding contest problem.
Compute A \times B.
Constraints
* 1 \leq A \leq 100
* 1 \leq B \leq 100
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the value A \times B as an integer.
Examples
Input
2 5
Output
10
Input
100 100
Output
10000 | instruction | 0 | 71,385 | 5 | 142,770 |
"Correct Solution:
```
a, b = map(int,input().split())
p = a * b
print(p)
``` | output | 1 | 71,385 | 5 | 142,771 |
Provide a correct Python 3 solution for this coding contest problem.
Compute A \times B.
Constraints
* 1 \leq A \leq 100
* 1 \leq B \leq 100
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the value A \times B as an integer.
Examples
Input
2 5
Output
10
Input
100 100
Output
10000 | instruction | 0 | 71,386 | 5 | 142,772 |
"Correct Solution:
```
print(eval(input().replace(*(' *'))))
``` | output | 1 | 71,386 | 5 | 142,773 |
Provide a correct Python 3 solution for this coding contest problem.
Compute A \times B.
Constraints
* 1 \leq A \leq 100
* 1 \leq B \leq 100
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the value A \times B as an integer.
Examples
Input
2 5
Output
10
Input
100 100
Output
10000 | instruction | 0 | 71,387 | 5 | 142,774 |
"Correct Solution:
```
n, k = list(map(int,input().split()))
print(n*k)
``` | output | 1 | 71,387 | 5 | 142,775 |
Provide a correct Python 3 solution for this coding contest problem.
Compute A \times B.
Constraints
* 1 \leq A \leq 100
* 1 \leq B \leq 100
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the value A \times B as an integer.
Examples
Input
2 5
Output
10
Input
100 100
Output
10000 | instruction | 0 | 71,388 | 5 | 142,776 |
"Correct Solution:
```
A, B = map(int, input("").split())
print(A*B)
``` | output | 1 | 71,388 | 5 | 142,777 |
Provide a correct Python 3 solution for this coding contest problem.
Compute A \times B.
Constraints
* 1 \leq A \leq 100
* 1 \leq B \leq 100
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the value A \times B as an integer.
Examples
Input
2 5
Output
10
Input
100 100
Output
10000 | instruction | 0 | 71,389 | 5 | 142,778 |
"Correct Solution:
```
[A,B] = list(map(int,input().split()))
print(A*B)
``` | output | 1 | 71,389 | 5 | 142,779 |
Provide a correct Python 3 solution for this coding contest problem.
Compute A \times B.
Constraints
* 1 \leq A \leq 100
* 1 \leq B \leq 100
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the value A \times B as an integer.
Examples
Input
2 5
Output
10
Input
100 100
Output
10000 | instruction | 0 | 71,390 | 5 | 142,780 |
"Correct Solution:
```
A,B = map(int,input().split())
d = A * B
print(d)
``` | output | 1 | 71,390 | 5 | 142,781 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Compute A \times B.
Constraints
* 1 \leq A \leq 100
* 1 \leq B \leq 100
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the value A \times B as an integer.
Examples
Input
2 5
Output
10
Input
100 100
Output
10000
Submitted Solution:
```
a, b = input().split(' ')
print(int(a) * int(b))
``` | instruction | 0 | 71,391 | 5 | 142,782 |
Yes | output | 1 | 71,391 | 5 | 142,783 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Compute A \times B.
Constraints
* 1 \leq A \leq 100
* 1 \leq B \leq 100
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the value A \times B as an integer.
Examples
Input
2 5
Output
10
Input
100 100
Output
10000
Submitted Solution:
```
(A,B) = map(int,input().split())
print(A*B)
``` | instruction | 0 | 71,392 | 5 | 142,784 |
Yes | output | 1 | 71,392 | 5 | 142,785 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Compute A \times B.
Constraints
* 1 \leq A \leq 100
* 1 \leq B \leq 100
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the value A \times B as an integer.
Examples
Input
2 5
Output
10
Input
100 100
Output
10000
Submitted Solution:
```
A,B = map(int,input().split())
print(int(A)*int(B))
``` | instruction | 0 | 71,393 | 5 | 142,786 |
Yes | output | 1 | 71,393 | 5 | 142,787 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Compute A \times B.
Constraints
* 1 \leq A \leq 100
* 1 \leq B \leq 100
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the value A \times B as an integer.
Examples
Input
2 5
Output
10
Input
100 100
Output
10000
Submitted Solution:
```
A, B = map(int, input().split())
S = A * B
print(S)
``` | instruction | 0 | 71,394 | 5 | 142,788 |
Yes | output | 1 | 71,394 | 5 | 142,789 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Compute A \times B.
Constraints
* 1 \leq A \leq 100
* 1 \leq B \leq 100
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the value A \times B as an integer.
Examples
Input
2 5
Output
10
Input
100 100
Output
10000
Submitted Solution:
```
a, b = int(input())
print(a*b)
``` | instruction | 0 | 71,395 | 5 | 142,790 |
No | output | 1 | 71,395 | 5 | 142,791 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.