message stringlengths 2 16.2k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 575 109k | cluster float64 16 16 | __index_level_0__ int64 1.15k 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N Snukes called Snuke 1, Snuke 2, ..., Snuke N live in a town.
There are K kinds of snacks sold in this town, called Snack 1, Snack 2, ..., Snack K. The following d_i Snukes have Snack i: Snuke A_{i, 1}, A_{i, 2}, \cdots, A_{i, {d_i}}.
Takahashi will walk around this town and make mischief on the Snukes who have no snacks. How many Snukes will fall victim to Takahashi's mischief?
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq K \leq 100
* 1 \leq d_i \leq N
* 1 \leq A_{i, 1} < \cdots < A_{i, d_i} \leq N
Input
Input is given from Standard Input in the following format:
N K
d_1
A_{1, 1} \cdots A_{1, d_1}
\vdots
d_K
A_{K, 1} \cdots A_{K, d_K}
Output
Print the answer.
Examples
Input
3 2
2
1 3
1
3
Output
1
Input
3 3
1
3
1
3
1
3
Output
2
Submitted Solution:
```
N,K = map(int,input().split())
d = int(input())
A = [list(map(int,input().split())) for _ in range(N)]
print(N-d)
``` | instruction | 0 | 78,889 | 16 | 157,778 |
No | output | 1 | 78,889 | 16 | 157,779 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N Snukes called Snuke 1, Snuke 2, ..., Snuke N live in a town.
There are K kinds of snacks sold in this town, called Snack 1, Snack 2, ..., Snack K. The following d_i Snukes have Snack i: Snuke A_{i, 1}, A_{i, 2}, \cdots, A_{i, {d_i}}.
Takahashi will walk around this town and make mischief on the Snukes who have no snacks. How many Snukes will fall victim to Takahashi's mischief?
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq K \leq 100
* 1 \leq d_i \leq N
* 1 \leq A_{i, 1} < \cdots < A_{i, d_i} \leq N
Input
Input is given from Standard Input in the following format:
N K
d_1
A_{1, 1} \cdots A_{1, d_1}
\vdots
d_K
A_{K, 1} \cdots A_{K, d_K}
Output
Print the answer.
Examples
Input
3 2
2
1 3
1
3
Output
1
Input
3 3
1
3
1
3
1
3
Output
2
Submitted Solution:
```
n, k = map(int,input().split())
A = []
N = []
N = set(range(1,n+1))
for i in range(1,k+1):
d = int(input())
a=set(map(int,input().split()))
A += a
ans = list(N-A)
print(len(ans))
``` | instruction | 0 | 78,890 | 16 | 157,780 |
No | output | 1 | 78,890 | 16 | 157,781 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N Snukes called Snuke 1, Snuke 2, ..., Snuke N live in a town.
There are K kinds of snacks sold in this town, called Snack 1, Snack 2, ..., Snack K. The following d_i Snukes have Snack i: Snuke A_{i, 1}, A_{i, 2}, \cdots, A_{i, {d_i}}.
Takahashi will walk around this town and make mischief on the Snukes who have no snacks. How many Snukes will fall victim to Takahashi's mischief?
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq K \leq 100
* 1 \leq d_i \leq N
* 1 \leq A_{i, 1} < \cdots < A_{i, d_i} \leq N
Input
Input is given from Standard Input in the following format:
N K
d_1
A_{1, 1} \cdots A_{1, d_1}
\vdots
d_K
A_{K, 1} \cdots A_{K, d_K}
Output
Print the answer.
Examples
Input
3 2
2
1 3
1
3
Output
1
Input
3 3
1
3
1
3
1
3
Output
2
Submitted Solution:
```
n,k = map(int,input().split())
l = [0]*n
for i in range(k):
d = int(input())
a = list(map(int,input().split()))
for j in range(1,len(a)+1):
l[j-1] += 1
print(l.count(0))
``` | instruction | 0 | 78,891 | 16 | 157,782 |
No | output | 1 | 78,891 | 16 | 157,783 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1 | instruction | 0 | 78,924 | 16 | 157,848 |
"Correct Solution:
```
n=int(input())
b=list(map(int,input().split()))
ans=[0]*n
t=0
while t<n:
res=t
for i in range(n-t):
if b[n-t-1-i]==n-t-i:
ans[t]=b[n-t-1-i]
b.remove(b[n-t-1-i])
t+=1
break
if t==res:
print(-1)
exit()
for i in range(n):
print(ans[n-1-i])
``` | output | 1 | 78,924 | 16 | 157,849 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1 | instruction | 0 | 78,925 | 16 | 157,850 |
"Correct Solution:
```
n,*b=map(int,open(0).read().split())
b=[0]+b
ans=[]
for i in range(n):
for i in range(len(b)-1,0,-1):
if i==b[i]:
ans.append(b.pop(i))
break
else:
print(-1)
exit()
for i in ans[::-1]:
print(i)
``` | output | 1 | 78,925 | 16 | 157,851 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1 | instruction | 0 | 78,926 | 16 | 157,852 |
"Correct Solution:
```
N = int(input())
B = [int(i) for i in input().split()]
result = []
for i in range(N):
for j in range(N - i - 1, -1, -1):
if j + 1 == B[j]:
result.insert(0, B.pop(j))
break
else:
print(-1)
quit()
for ri in result:
print(ri)
``` | output | 1 | 78,926 | 16 | 157,853 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1 | instruction | 0 | 78,927 | 16 | 157,854 |
"Correct Solution:
```
n=int(input())
b=[int(i) for i in input().split()]
c=[]
for _ in range(n):
for i in range(len(b)-1,-1,-1):
if i+1==b[i]:
del b[i]
c.append(i+1)
break
else:
print(-1)
exit()
for i in c[::-1]:
print(i)
``` | output | 1 | 78,927 | 16 | 157,855 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1 | instruction | 0 | 78,928 | 16 | 157,856 |
"Correct Solution:
```
n = int(input())
b= list(map(int, input().split()))
v = []
while b:
x = -1
for i in range(len(b)):
if b[i] == i + 1:
x = i
if x == -1:
print(-1)
exit()
v.append(b[x])
del b[x]
for e in reversed(v):
print(e)
``` | output | 1 | 78,928 | 16 | 157,857 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1 | instruction | 0 | 78,929 | 16 | 157,858 |
"Correct Solution:
```
n=int(input())
l=list(map(int,input().split()))
b=[]
for i in range(n):
for j in range(n-i)[::-1]:
if l[j]==j+1:
del l[j]
b.append(j+1)
break
else:
print(-1)
exit()
print(*b[::-1],sep="\n")
``` | output | 1 | 78,929 | 16 | 157,859 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1 | instruction | 0 | 78,930 | 16 | 157,860 |
"Correct Solution:
```
import sys
N = int(input())
A = list(map(int,input().split()))
for n in range(N):
if A[n] > n+1:
print(-1)
sys.exit()
ans = []
while A != []:
tmp = 0
for p in range(len(A)):
if A[p] == p+1:
tmp = p
ans.insert(0,A.pop(tmp))
for x in ans:
print(x)
``` | output | 1 | 78,930 | 16 | 157,861 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1 | instruction | 0 | 78,931 | 16 | 157,862 |
"Correct Solution:
```
N = int(input())
B = [int(i) for i in input().split()]
result = []
for bi in B:
if bi - 1 > len(result):
print(-1)
quit()
result.insert(bi - 1, bi)
for ri in result:
print(ri)
``` | output | 1 | 78,931 | 16 | 157,863 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1
Submitted Solution:
```
n = int(input())
b = list(map(int, input().split()))
ans = []
for k in range(n):
for i in reversed(range(n - k)):
a = b[i]
if i + 1 == a:
ans.append(b.pop(i))
break
if b != []:
print(-1)
else:
for a in reversed(ans):
print(a)
``` | instruction | 0 | 78,932 | 16 | 157,864 |
Yes | output | 1 | 78,932 | 16 | 157,865 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1
Submitted Solution:
```
n = int(input())
b = [int(i) for i in input().split()]
a = []
for i in range(n):
f = 1
for j in range(len(b)-1, -1, -1):
if b[j] == j+1:
b = b[:j]+b[j+1:]
a.append(j+1)
f=0
break
if f == 1:
print(-1)
exit()
a.reverse()
for i in a:
print(i)
``` | instruction | 0 | 78,933 | 16 | 157,866 |
Yes | output | 1 | 78,933 | 16 | 157,867 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1
Submitted Solution:
```
N = int(input())
array = input().split()
flag = True
lst = [0]
for i in range(1, N+1):
x = int(array[i-1])
if len(lst) < x:
flag = False
break
lst.insert(x, x)
if flag:
for i in lst[1:]:
print(i)
else:
print(-1)
``` | instruction | 0 | 78,934 | 16 | 157,868 |
Yes | output | 1 | 78,934 | 16 | 157,869 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1
Submitted Solution:
```
n=int(input())
m=list(map(int,input().split()))
ans=[]
for i in range(n):
for j in range(n-1-i,-1,-1):
if not m[j]==j+1:
continue
#m[j]==j
ans.append(j+1)
m=m[:j]+m[j+1:]
break
if not len(m)==0:
print(-1)
else:
for i in range(n):
print(ans[n-1-i])
``` | instruction | 0 | 78,935 | 16 | 157,870 |
Yes | output | 1 | 78,935 | 16 | 157,871 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1
Submitted Solution:
```
import sys
input = sys.stdin.readline # NOQA
sys.setrecursionlimit(10 ** 7) # NOQA
def dfs(N, a, i, b):
if i == N + 1:
if a == b:
return a
else:
return None
i += 1
for j in range(1, i):
A = a[:]
A.insert(j-1, j)
res = dfs(N, A, i, b)
if res is not None:
return res
def main():
N = int(input())
b = list(map(int, input().split()))
res = dfs(N, [], 1, b)
if res is None:
print(-1)
else:
print(*res, sep="\n")
if __name__ == "__main__":
main()
``` | instruction | 0 | 78,936 | 16 | 157,872 |
No | output | 1 | 78,936 | 16 | 157,873 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1
Submitted Solution:
```
N = int(input())
B = list(map(int,input().split()))
ans = []
while N > 0:
ok = False
for i in range(N)[::-1]:
b = B[i]
if b == (i+1):
ans.append(b)
ok = True
break
if ok:
N -= 1
else:
break
if N != 0:
print(-1)
else:
print("\n".join(map(str,ans[::-1])))
``` | instruction | 0 | 78,937 | 16 | 157,874 |
No | output | 1 | 78,937 | 16 | 157,875 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1
Submitted Solution:
```
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
from sys import stdin
###########################################
############################################
#from sys import stdin
import numpy as np
# read data for n sequences.
n = stdin.readline().split()
data = stdin.readline().split()
out = []
token = 0
# check first data and return -1 if != 1
if int(data[0]) != 1:
token = -1
else:
# print first data
out.append(1)
for i,x in enumerate(data):
data[i]=int(x)
# split to multiple data.
x = 1
split = []
chunck = []
#while x < len(data):
for i,num in enumerate(data[x:]):
chunck.append(num)
if num == 1:
split.append(chunck)
chunck=[]
x = i+1
split.append(chunck)
for x in reversed(split):
maxnum=max(x)
if x == [1]:
out.append(1)
else:
for i in range(1,maxnum+1):
if i in x:
count = x.count(i)
if x.index(i) >= i-2:
for xx in range(count):
out.append(i)
else:
token = -1
if token == -1:
print(-1)
else:
# print outputs
for x in out:
print(x)
``` | instruction | 0 | 78,938 | 16 | 157,876 |
No | output | 1 | 78,938 | 16 | 157,877 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1
Submitted Solution:
```
N = int(input())
Bin = list(map(int, input().split()))
B = []
Btmp = [Bin[0]]
for i in range(1, N):
if Bin[i] == 1:
B.append(Btmp)
Btmp = []
Btmp.append(Bin[i])
else:
B.append(Btmp)
#print(B)
#print(list(reversed(B)))
def solve(arr):
ret = []
while len(arr) > 0:
before = len(arr)
for i in reversed(range(len(arr))):
if arr[i] == i + 1:
ret.append(arr.pop(i))
break
if len(arr) == before:
return None
return reversed(ret)
A = []
success = True
for Bsub in reversed(B):
tmp = solve(Bsub)
if tmp == None:
success = False
break
A.extend(tmp)
#print(A)
if success:
for a in A:
print(a)
else:
print(-1)
``` | instruction | 0 | 78,939 | 16 | 157,878 |
No | output | 1 | 78,939 | 16 | 157,879 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?
Constraints
* 1 ≤ N,A,B ≤ 10^9
* A and B are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print the number of the different possible sums.
Examples
Input
4 4 6
Output
5
Input
5 4 3
Output
0
Input
1 7 10
Output
0
Input
1 3 3
Output
1 | instruction | 0 | 78,977 | 16 | 157,954 |
"Correct Solution:
```
N,A,B = map(int,input().split())
print(max((N-1)*B+A-(N-1)*A-B+1,0))
``` | output | 1 | 78,977 | 16 | 157,955 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?
Constraints
* 1 ≤ N,A,B ≤ 10^9
* A and B are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print the number of the different possible sums.
Examples
Input
4 4 6
Output
5
Input
5 4 3
Output
0
Input
1 7 10
Output
0
Input
1 3 3
Output
1 | instruction | 0 | 78,978 | 16 | 157,956 |
"Correct Solution:
```
n, a, b = map(int, input().split())
min_a_b = a * (n-1) + b
max_a_b = a + b * (n-1)
print(max(0, max_a_b - min_a_b + 1))
``` | output | 1 | 78,978 | 16 | 157,957 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?
Constraints
* 1 ≤ N,A,B ≤ 10^9
* A and B are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print the number of the different possible sums.
Examples
Input
4 4 6
Output
5
Input
5 4 3
Output
0
Input
1 7 10
Output
0
Input
1 3 3
Output
1 | instruction | 0 | 78,979 | 16 | 157,958 |
"Correct Solution:
```
n,a,b=map(int,input().split())
n-=2;print(max(b*n-a*n+1,0))
``` | output | 1 | 78,979 | 16 | 157,959 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?
Constraints
* 1 ≤ N,A,B ≤ 10^9
* A and B are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print the number of the different possible sums.
Examples
Input
4 4 6
Output
5
Input
5 4 3
Output
0
Input
1 7 10
Output
0
Input
1 3 3
Output
1 | instruction | 0 | 78,980 | 16 | 157,960 |
"Correct Solution:
```
N, A, B = map(int, input().split())
maxi = A + B*(N-1)
mini = A*(N-1) + B
print(max(0, maxi-mini+1))
``` | output | 1 | 78,980 | 16 | 157,961 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?
Constraints
* 1 ≤ N,A,B ≤ 10^9
* A and B are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print the number of the different possible sums.
Examples
Input
4 4 6
Output
5
Input
5 4 3
Output
0
Input
1 7 10
Output
0
Input
1 3 3
Output
1 | instruction | 0 | 78,981 | 16 | 157,962 |
"Correct Solution:
```
#A問題
N,A,B = map(int,input().split())
dif = B-A
n = N-2
print(max(n*dif+1,0))
``` | output | 1 | 78,981 | 16 | 157,963 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?
Constraints
* 1 ≤ N,A,B ≤ 10^9
* A and B are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print the number of the different possible sums.
Examples
Input
4 4 6
Output
5
Input
5 4 3
Output
0
Input
1 7 10
Output
0
Input
1 3 3
Output
1 | instruction | 0 | 78,982 | 16 | 157,964 |
"Correct Solution:
```
N,A,B=map(int, input().split())
if N==1:
print(int(A==B))
elif A>B:
print(0)
else:
print((N-2)*(B-A)+1)
``` | output | 1 | 78,982 | 16 | 157,965 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?
Constraints
* 1 ≤ N,A,B ≤ 10^9
* A and B are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print the number of the different possible sums.
Examples
Input
4 4 6
Output
5
Input
5 4 3
Output
0
Input
1 7 10
Output
0
Input
1 3 3
Output
1 | instruction | 0 | 78,983 | 16 | 157,966 |
"Correct Solution:
```
N, A, B = map(int, input().split())
hi = A + B * (N-1)
lo = B + A * (N-1)
print(max(hi - lo + 1, 0))
``` | output | 1 | 78,983 | 16 | 157,967 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?
Constraints
* 1 ≤ N,A,B ≤ 10^9
* A and B are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print the number of the different possible sums.
Examples
Input
4 4 6
Output
5
Input
5 4 3
Output
0
Input
1 7 10
Output
0
Input
1 3 3
Output
1 | instruction | 0 | 78,984 | 16 | 157,968 |
"Correct Solution:
```
n,a,b = map(int,input().split())
print(max(0,(n-1)*b + a - ((n-1)*a + b) + 1))
``` | output | 1 | 78,984 | 16 | 157,969 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?
Constraints
* 1 ≤ N,A,B ≤ 10^9
* A and B are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print the number of the different possible sums.
Examples
Input
4 4 6
Output
5
Input
5 4 3
Output
0
Input
1 7 10
Output
0
Input
1 3 3
Output
1
Submitted Solution:
```
n,a,b=map(int,input().split())
ans=b*(n-1)+a-a*(n-1)-b+1
if ans<=0:
print(0)
else:
print(ans)
``` | instruction | 0 | 78,985 | 16 | 157,970 |
Yes | output | 1 | 78,985 | 16 | 157,971 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?
Constraints
* 1 ≤ N,A,B ≤ 10^9
* A and B are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print the number of the different possible sums.
Examples
Input
4 4 6
Output
5
Input
5 4 3
Output
0
Input
1 7 10
Output
0
Input
1 3 3
Output
1
Submitted Solution:
```
n,a,b = map(int, input().split())
mn = a*(n-1) + b
mx = a + b*(n-1)
print(max(0,mx-mn+1))
``` | instruction | 0 | 78,986 | 16 | 157,972 |
Yes | output | 1 | 78,986 | 16 | 157,973 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?
Constraints
* 1 ≤ N,A,B ≤ 10^9
* A and B are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print the number of the different possible sums.
Examples
Input
4 4 6
Output
5
Input
5 4 3
Output
0
Input
1 7 10
Output
0
Input
1 3 3
Output
1
Submitted Solution:
```
n, a, b = map(int, input().split())
ans = max(0, (b - a) * (n - 2) + 1)
print(ans)
``` | instruction | 0 | 78,987 | 16 | 157,974 |
Yes | output | 1 | 78,987 | 16 | 157,975 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?
Constraints
* 1 ≤ N,A,B ≤ 10^9
* A and B are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print the number of the different possible sums.
Examples
Input
4 4 6
Output
5
Input
5 4 3
Output
0
Input
1 7 10
Output
0
Input
1 3 3
Output
1
Submitted Solution:
```
N, A, B = map(int, input().split())
print(max(0, (B - A) * (N - 2) + 1))
``` | instruction | 0 | 78,988 | 16 | 157,976 |
Yes | output | 1 | 78,988 | 16 | 157,977 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?
Constraints
* 1 ≤ N,A,B ≤ 10^9
* A and B are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print the number of the different possible sums.
Examples
Input
4 4 6
Output
5
Input
5 4 3
Output
0
Input
1 7 10
Output
0
Input
1 3 3
Output
1
Submitted Solution:
```
# 3 .. 6 N=4とすると真ん中2つは(3, 3)~(6, 6)までで、1ずつインクリメントして全種類網羅できる
# 3+3 ~ 6+6までの12-6+1種類
n, a, b = map(int, input().split())
if b < a:
print(0)
elif n == 2 and a <= b or n == 1:
print(1)
else:
minn = (n - 2) * a
maxn = (n - 2) * b
print(maxn - minn + 1)
``` | instruction | 0 | 78,989 | 16 | 157,978 |
No | output | 1 | 78,989 | 16 | 157,979 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?
Constraints
* 1 ≤ N,A,B ≤ 10^9
* A and B are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print the number of the different possible sums.
Examples
Input
4 4 6
Output
5
Input
5 4 3
Output
0
Input
1 7 10
Output
0
Input
1 3 3
Output
1
Submitted Solution:
```
N, A, B = map(int, input().split())
if N == 1:
if A == B:
print(1)
else:
print(0)
elif A > B:
print(0)
else:
c = 0
for _ in range(N-2):
c += (B-A)
print(c+1)
``` | instruction | 0 | 78,990 | 16 | 157,980 |
No | output | 1 | 78,990 | 16 | 157,981 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?
Constraints
* 1 ≤ N,A,B ≤ 10^9
* A and B are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print the number of the different possible sums.
Examples
Input
4 4 6
Output
5
Input
5 4 3
Output
0
Input
1 7 10
Output
0
Input
1 3 3
Output
1
Submitted Solution:
```
N,A,B = map(int,input().split())
maxi = B*(N-1) + A
mini = A*(N-1) + B
if A > B:
print(0)
elif A == B:
print(1)
else:
print(maxi - mini + 1)
``` | instruction | 0 | 78,991 | 16 | 157,982 |
No | output | 1 | 78,991 | 16 | 157,983 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?
Constraints
* 1 ≤ N,A,B ≤ 10^9
* A and B are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print the number of the different possible sums.
Examples
Input
4 4 6
Output
5
Input
5 4 3
Output
0
Input
1 7 10
Output
0
Input
1 3 3
Output
1
Submitted Solution:
```
N,a,b=map(int, input().split())
if a>b:
print(0)
elif a<b and N==1:
print(0)
else:
print(b*2-a*2+1)
``` | instruction | 0 | 78,992 | 16 | 157,984 |
No | output | 1 | 78,992 | 16 | 157,985 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke stands on a number line. He has L ears, and he will walk along the line continuously under the following conditions:
* He never visits a point with coordinate less than 0, or a point with coordinate greater than L.
* He starts walking at a point with integer coordinate, and also finishes walking at a point with integer coordinate.
* He only changes direction at a point with integer coordinate.
Each time when Snuke passes a point with coordinate i-0.5, where i is an integer, he put a stone in his i-th ear.
After Snuke finishes walking, Ringo will repeat the following operations in some order so that, for each i, Snuke's i-th ear contains A_i stones:
* Put a stone in one of Snuke's ears.
* Remove a stone from one of Snuke's ears.
Find the minimum number of operations required when Ringo can freely decide how Snuke walks.
Constraints
* 1 \leq L \leq 2\times 10^5
* 0 \leq A_i \leq 10^9(1\leq i\leq L)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
L
A_1
:
A_L
Output
Print the minimum number of operations required when Ringo can freely decide how Snuke walks.
Examples
Input
4
1
0
2
3
Output
1
Input
8
2
0
0
2
1
3
4
1
Output
3
Input
7
314159265
358979323
846264338
327950288
419716939
937510582
0
Output
1 | instruction | 0 | 80,654 | 16 | 161,308 |
"Correct Solution:
```
n = int(input())
a = [int(input()) for i in range(n)]
# 0区間、偶数区間(2以上)、奇数区間、偶数区間(2以上)、0区間
dp = [[0] * (5) for i in range(n + 1)]
for i in range(n):
dp[i + 1][0] = dp[i][0] + a[i]
dp[i + 1][1] = min(dp[i][0:2]) + (a[i] % 2)
if a[i] == 0:
dp[i + 1][1] += 2
dp[i + 1][2] = min(dp[i][0:3]) + (a[i] + 1) % 2
dp[i + 1][3] = min(dp[i][0:4]) + (a[i] % 2)
if a[i] == 0:
dp[i + 1][3] += 2
dp[i + 1][4] = min(dp[i][0:5]) + a[i]
print(min(dp[-1]))
``` | output | 1 | 80,654 | 16 | 161,309 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke stands on a number line. He has L ears, and he will walk along the line continuously under the following conditions:
* He never visits a point with coordinate less than 0, or a point with coordinate greater than L.
* He starts walking at a point with integer coordinate, and also finishes walking at a point with integer coordinate.
* He only changes direction at a point with integer coordinate.
Each time when Snuke passes a point with coordinate i-0.5, where i is an integer, he put a stone in his i-th ear.
After Snuke finishes walking, Ringo will repeat the following operations in some order so that, for each i, Snuke's i-th ear contains A_i stones:
* Put a stone in one of Snuke's ears.
* Remove a stone from one of Snuke's ears.
Find the minimum number of operations required when Ringo can freely decide how Snuke walks.
Constraints
* 1 \leq L \leq 2\times 10^5
* 0 \leq A_i \leq 10^9(1\leq i\leq L)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
L
A_1
:
A_L
Output
Print the minimum number of operations required when Ringo can freely decide how Snuke walks.
Examples
Input
4
1
0
2
3
Output
1
Input
8
2
0
0
2
1
3
4
1
Output
3
Input
7
314159265
358979323
846264338
327950288
419716939
937510582
0
Output
1 | instruction | 0 | 80,655 | 16 | 161,310 |
"Correct Solution:
```
l = int(input())
a = [int(input()) for _ in range(l)]
a.insert(0, 0)
dp = [[1000000] * (l + 1) for _ in range(4)]
for i in range(4):
dp[i][0] = 0
for i in range(1, l + 1):
dp[0][i] = dp[0][i - 1] + a[i]
for i in range(1, 4):
for j in range(1, l + 1):
if i == 2:
x = abs(a[j] % 2 - 1)
else:
x = abs(2 - min(a[j] % 2 + 2, a[j]))
dp[i][j] = min(dp[i - 1][j], dp[i][j - 1] + x)
ans = dp[3][l]
s = 0
for i in range(l - 1, -1, -1):
s += a[i + 1]
ans = min(ans, dp[3][i] + s)
print(ans)
``` | output | 1 | 80,655 | 16 | 161,311 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke stands on a number line. He has L ears, and he will walk along the line continuously under the following conditions:
* He never visits a point with coordinate less than 0, or a point with coordinate greater than L.
* He starts walking at a point with integer coordinate, and also finishes walking at a point with integer coordinate.
* He only changes direction at a point with integer coordinate.
Each time when Snuke passes a point with coordinate i-0.5, where i is an integer, he put a stone in his i-th ear.
After Snuke finishes walking, Ringo will repeat the following operations in some order so that, for each i, Snuke's i-th ear contains A_i stones:
* Put a stone in one of Snuke's ears.
* Remove a stone from one of Snuke's ears.
Find the minimum number of operations required when Ringo can freely decide how Snuke walks.
Constraints
* 1 \leq L \leq 2\times 10^5
* 0 \leq A_i \leq 10^9(1\leq i\leq L)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
L
A_1
:
A_L
Output
Print the minimum number of operations required when Ringo can freely decide how Snuke walks.
Examples
Input
4
1
0
2
3
Output
1
Input
8
2
0
0
2
1
3
4
1
Output
3
Input
7
314159265
358979323
846264338
327950288
419716939
937510582
0
Output
1 | instruction | 0 | 80,656 | 16 | 161,312 |
"Correct Solution:
```
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10 ** 8)
ni = lambda: int(sys.stdin.readline())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
ns = lambda: sys.stdin.readline().rstrip()
L = ni()
# odd => 0, even => 1
A = [ni() for _ in range(L)]
assert len(A) == L
INF = 1 << 60
S = 5 # num of states
def solve():
dp = [[INF] * S for _ in range(L + 1)]
for s in range(S):
dp[0][s] = 0
for i in range(1, L + 1):
a = A[i - 1]
dp[i][0] = dp[i - 1][0] + a
tm = min(dp[i - 1][0], dp[i - 1][1])
dp[i][1] = tm + (2 if a == 0 else a % 2)
tm = min(tm, dp[i - 1][2])
dp[i][2] = tm + (1 - a % 2)
tm = min(tm, dp[i - 1][3])
dp[i][3] = tm + (2 if a == 0 else a % 2)
tm = min(tm, dp[i - 1][4])
dp[i][4] = tm + a
# print(*dp, sep="\n", file=sys.stderr)
return min(dp[L])
print(solve())
``` | output | 1 | 80,656 | 16 | 161,313 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke stands on a number line. He has L ears, and he will walk along the line continuously under the following conditions:
* He never visits a point with coordinate less than 0, or a point with coordinate greater than L.
* He starts walking at a point with integer coordinate, and also finishes walking at a point with integer coordinate.
* He only changes direction at a point with integer coordinate.
Each time when Snuke passes a point with coordinate i-0.5, where i is an integer, he put a stone in his i-th ear.
After Snuke finishes walking, Ringo will repeat the following operations in some order so that, for each i, Snuke's i-th ear contains A_i stones:
* Put a stone in one of Snuke's ears.
* Remove a stone from one of Snuke's ears.
Find the minimum number of operations required when Ringo can freely decide how Snuke walks.
Constraints
* 1 \leq L \leq 2\times 10^5
* 0 \leq A_i \leq 10^9(1\leq i\leq L)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
L
A_1
:
A_L
Output
Print the minimum number of operations required when Ringo can freely decide how Snuke walks.
Examples
Input
4
1
0
2
3
Output
1
Input
8
2
0
0
2
1
3
4
1
Output
3
Input
7
314159265
358979323
846264338
327950288
419716939
937510582
0
Output
1 | instruction | 0 | 80,657 | 16 | 161,314 |
"Correct Solution:
```
l = int(input())
a = [int(input()) for _ in range(l)]
dp = [[0]*5 for _ in range(l)]
if a[0] == 0:
dp[0] = [a[0],2,1,2,a[0]]
elif a[0]%2 == 0:
dp[0] = [a[0],0,1,0,a[0]]
else:
dp[0] = [a[0],1,0,1,a[0]]
for i in range(1,l):
dp[i][0] = dp[i-1][0]+a[i]
dp[i][2] = min(dp[i-1][0:3])+1-a[i]%2
dp[i][4] = min(dp[i-1][0:5])+a[i]
if a[i]!=0:
dp[i][3] = min(dp[i-1][0:4])+a[i]%2
dp[i][1] = min(dp[i-1][0], dp[i-1][1])+a[i]%2
else:
dp[i][3] = min(dp[i-1][0:4])+2
dp[i][1] = min(dp[i-1][0], dp[i-1][1])+2
print(min(dp[l-1]))
``` | output | 1 | 80,657 | 16 | 161,315 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke stands on a number line. He has L ears, and he will walk along the line continuously under the following conditions:
* He never visits a point with coordinate less than 0, or a point with coordinate greater than L.
* He starts walking at a point with integer coordinate, and also finishes walking at a point with integer coordinate.
* He only changes direction at a point with integer coordinate.
Each time when Snuke passes a point with coordinate i-0.5, where i is an integer, he put a stone in his i-th ear.
After Snuke finishes walking, Ringo will repeat the following operations in some order so that, for each i, Snuke's i-th ear contains A_i stones:
* Put a stone in one of Snuke's ears.
* Remove a stone from one of Snuke's ears.
Find the minimum number of operations required when Ringo can freely decide how Snuke walks.
Constraints
* 1 \leq L \leq 2\times 10^5
* 0 \leq A_i \leq 10^9(1\leq i\leq L)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
L
A_1
:
A_L
Output
Print the minimum number of operations required when Ringo can freely decide how Snuke walks.
Examples
Input
4
1
0
2
3
Output
1
Input
8
2
0
0
2
1
3
4
1
Output
3
Input
7
314159265
358979323
846264338
327950288
419716939
937510582
0
Output
1 | instruction | 0 | 80,658 | 16 | 161,316 |
"Correct Solution:
```
def main():
l = int(input())
nums = [int(input()) for _ in range(l)]
dp = [[0 for _ in range(5)] for _ in range(l + 1)]
for i in range(l):
dp[i + 1][0] = dp[i][0] + nums[i]
dp[i + 1][1] = min(dp[i][:2]) + (nums[i] % 2 if nums[i] != 0 else 2)
dp[i + 1][2] = min(dp[i][:3]) + (nums[i] + 1) % 2
dp[i + 1][3] = min(dp[i][:4]) + (nums[i] % 2 if nums[i] != 0 else 2)
dp[i + 1][4] = min(dp[i]) + nums[i]
print(min(dp[l]))
if __name__ == '__main__':
main()
``` | output | 1 | 80,658 | 16 | 161,317 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke stands on a number line. He has L ears, and he will walk along the line continuously under the following conditions:
* He never visits a point with coordinate less than 0, or a point with coordinate greater than L.
* He starts walking at a point with integer coordinate, and also finishes walking at a point with integer coordinate.
* He only changes direction at a point with integer coordinate.
Each time when Snuke passes a point with coordinate i-0.5, where i is an integer, he put a stone in his i-th ear.
After Snuke finishes walking, Ringo will repeat the following operations in some order so that, for each i, Snuke's i-th ear contains A_i stones:
* Put a stone in one of Snuke's ears.
* Remove a stone from one of Snuke's ears.
Find the minimum number of operations required when Ringo can freely decide how Snuke walks.
Constraints
* 1 \leq L \leq 2\times 10^5
* 0 \leq A_i \leq 10^9(1\leq i\leq L)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
L
A_1
:
A_L
Output
Print the minimum number of operations required when Ringo can freely decide how Snuke walks.
Examples
Input
4
1
0
2
3
Output
1
Input
8
2
0
0
2
1
3
4
1
Output
3
Input
7
314159265
358979323
846264338
327950288
419716939
937510582
0
Output
1 | instruction | 0 | 80,659 | 16 | 161,318 |
"Correct Solution:
```
#https://atcoder.jp/contests/yahoo-procon2019-qual/tasks/yahoo_procon2019_qual_d
#2019-02-10
#DP
L = int(input())
A = [int(input()) for i in range(L)]
DP = [[float("inf") for i in range(5)] for j in range(L+1)]
for i in range(5):
DP[0][i] = 0
def cost(s, i, A):
if s == 0 or s == 4:
return A[i]
elif s == 1 or s == 3:
if A[i] > 0:
if A[i]%2 == 0:
return 0
else:
return 1
else:
return 2
else:
if A[i]%2 == 1:
return 0
else:
return 1
for i in range(L):
DP[i+1][0] = DP[i][0] + cost(0, i, A)
DP[i+1][1] = min(DP[i][:2]) + cost(1, i, A)
DP[i+1][2] = min(DP[i][:3]) + cost(2, i, A)
DP[i+1][3] = min(DP[i][:4]) + cost(3, i, A)
DP[i+1][4] = min(DP[i][:5]) + cost(4, i, A)
print(min(DP[L]))
``` | output | 1 | 80,659 | 16 | 161,319 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke stands on a number line. He has L ears, and he will walk along the line continuously under the following conditions:
* He never visits a point with coordinate less than 0, or a point with coordinate greater than L.
* He starts walking at a point with integer coordinate, and also finishes walking at a point with integer coordinate.
* He only changes direction at a point with integer coordinate.
Each time when Snuke passes a point with coordinate i-0.5, where i is an integer, he put a stone in his i-th ear.
After Snuke finishes walking, Ringo will repeat the following operations in some order so that, for each i, Snuke's i-th ear contains A_i stones:
* Put a stone in one of Snuke's ears.
* Remove a stone from one of Snuke's ears.
Find the minimum number of operations required when Ringo can freely decide how Snuke walks.
Constraints
* 1 \leq L \leq 2\times 10^5
* 0 \leq A_i \leq 10^9(1\leq i\leq L)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
L
A_1
:
A_L
Output
Print the minimum number of operations required when Ringo can freely decide how Snuke walks.
Examples
Input
4
1
0
2
3
Output
1
Input
8
2
0
0
2
1
3
4
1
Output
3
Input
7
314159265
358979323
846264338
327950288
419716939
937510582
0
Output
1 | instruction | 0 | 80,660 | 16 | 161,320 |
"Correct Solution:
```
import sys
input = sys.stdin.readline
N = int(input())
A = [int(input()) for _ in range(N)]
dp = [[0]*5 for _ in range(N+1)]
for i, a in enumerate(A):
b = a%2 if a > 0 else 2
dp[i+1][0] = dp[i][0] + a
dp[i+1][1] = min(dp[i][1], dp[i][0]) + b
dp[i+1][2] = min([dp[i][2], dp[i][1], dp[i][0]]) + (a+1)%2
dp[i+1][3] = min([dp[i][3], dp[i][2], dp[i][1], dp[i][0]]) + b
dp[i+1][4] = min(dp[i]) + a
ans = min([dp[N][4], dp[N][3], dp[N][2]])
print(ans)
``` | output | 1 | 80,660 | 16 | 161,321 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke stands on a number line. He has L ears, and he will walk along the line continuously under the following conditions:
* He never visits a point with coordinate less than 0, or a point with coordinate greater than L.
* He starts walking at a point with integer coordinate, and also finishes walking at a point with integer coordinate.
* He only changes direction at a point with integer coordinate.
Each time when Snuke passes a point with coordinate i-0.5, where i is an integer, he put a stone in his i-th ear.
After Snuke finishes walking, Ringo will repeat the following operations in some order so that, for each i, Snuke's i-th ear contains A_i stones:
* Put a stone in one of Snuke's ears.
* Remove a stone from one of Snuke's ears.
Find the minimum number of operations required when Ringo can freely decide how Snuke walks.
Constraints
* 1 \leq L \leq 2\times 10^5
* 0 \leq A_i \leq 10^9(1\leq i\leq L)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
L
A_1
:
A_L
Output
Print the minimum number of operations required when Ringo can freely decide how Snuke walks.
Examples
Input
4
1
0
2
3
Output
1
Input
8
2
0
0
2
1
3
4
1
Output
3
Input
7
314159265
358979323
846264338
327950288
419716939
937510582
0
Output
1 | instruction | 0 | 80,661 | 16 | 161,322 |
"Correct Solution:
```
L=int(input())
A=[int(input()) for _ in range(L)]
dp=[[0 for _ in range(5)] for _ in range(L+1)]
for i in range(1,L+1):
a=A[i-1]
back = a%2 if a>0 else 2
through = (a+1)%2
dp[i][0]=dp[i-1][0]+a
dp[i][1]=min(dp[i-1][0:2])+back
dp[i][2]=min(dp[i-1][0:3])+through
dp[i][3]=min(dp[i-1][0:4])+back
dp[i][4]=min(dp[i-1][0:5])+a
print(min(dp[L]))
``` | output | 1 | 80,661 | 16 | 161,323 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke stands on a number line. He has L ears, and he will walk along the line continuously under the following conditions:
* He never visits a point with coordinate less than 0, or a point with coordinate greater than L.
* He starts walking at a point with integer coordinate, and also finishes walking at a point with integer coordinate.
* He only changes direction at a point with integer coordinate.
Each time when Snuke passes a point with coordinate i-0.5, where i is an integer, he put a stone in his i-th ear.
After Snuke finishes walking, Ringo will repeat the following operations in some order so that, for each i, Snuke's i-th ear contains A_i stones:
* Put a stone in one of Snuke's ears.
* Remove a stone from one of Snuke's ears.
Find the minimum number of operations required when Ringo can freely decide how Snuke walks.
Constraints
* 1 \leq L \leq 2\times 10^5
* 0 \leq A_i \leq 10^9(1\leq i\leq L)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
L
A_1
:
A_L
Output
Print the minimum number of operations required when Ringo can freely decide how Snuke walks.
Examples
Input
4
1
0
2
3
Output
1
Input
8
2
0
0
2
1
3
4
1
Output
3
Input
7
314159265
358979323
846264338
327950288
419716939
937510582
0
Output
1
Submitted Solution:
```
#https://atcoder.jp/contests/yahoo-procon2019-qual/tasks/yahoo_procon2019_qual_d
#2019-02-10
#DP
L = int(input())
A = [int(input()) for i in range(L)]
DP = [[0 for i in range(5)] for j in range(L+1)]
def cost(s, a):
if s == 0 or s == 4:
return a
elif s == 1 or s == 3:
if a > 0:
return a%2
else:
return 2
else:
return (a+1)%2
for i in range(L):
a = A[i]
DP[i+1][0] = min(DP[i][:1]) + cost(0, a)
DP[i+1][1] = min(DP[i][:2]) + cost(1, a)
DP[i+1][2] = min(DP[i][:3]) + cost(2, a)
DP[i+1][3] = min(DP[i][:4]) + cost(3, a)
DP[i+1][4] = min(DP[i][:5]) + cost(4, a)
print(min(DP[L]))
``` | instruction | 0 | 80,662 | 16 | 161,324 |
Yes | output | 1 | 80,662 | 16 | 161,325 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke stands on a number line. He has L ears, and he will walk along the line continuously under the following conditions:
* He never visits a point with coordinate less than 0, or a point with coordinate greater than L.
* He starts walking at a point with integer coordinate, and also finishes walking at a point with integer coordinate.
* He only changes direction at a point with integer coordinate.
Each time when Snuke passes a point with coordinate i-0.5, where i is an integer, he put a stone in his i-th ear.
After Snuke finishes walking, Ringo will repeat the following operations in some order so that, for each i, Snuke's i-th ear contains A_i stones:
* Put a stone in one of Snuke's ears.
* Remove a stone from one of Snuke's ears.
Find the minimum number of operations required when Ringo can freely decide how Snuke walks.
Constraints
* 1 \leq L \leq 2\times 10^5
* 0 \leq A_i \leq 10^9(1\leq i\leq L)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
L
A_1
:
A_L
Output
Print the minimum number of operations required when Ringo can freely decide how Snuke walks.
Examples
Input
4
1
0
2
3
Output
1
Input
8
2
0
0
2
1
3
4
1
Output
3
Input
7
314159265
358979323
846264338
327950288
419716939
937510582
0
Output
1
Submitted Solution:
```
L = int(input())
A = [int(input()) for i in range(L)]
DP = [[0 for i in range(5)] for j in range(L+1)]
def cost(s, a):
if s == 0 or s == 4:
return a
elif s == 1 or s == 3:
if a > 0:
return a%2
else:
return 2
else:
return (a+1)%2
for i in range(L):
DP[i+1][0] = min(DP[i][:1]) + cost(0, A[i])
DP[i+1][1] = min(DP[i][:2]) + cost(1, A[i])
DP[i+1][2] = min(DP[i][:3]) + cost(2, A[i])
DP[i+1][3] = min(DP[i][:4]) + cost(3, A[i])
DP[i+1][4] = min(DP[i][:5]) + cost(4, A[i])
print(min(DP[L]))
``` | instruction | 0 | 80,663 | 16 | 161,326 |
Yes | output | 1 | 80,663 | 16 | 161,327 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke stands on a number line. He has L ears, and he will walk along the line continuously under the following conditions:
* He never visits a point with coordinate less than 0, or a point with coordinate greater than L.
* He starts walking at a point with integer coordinate, and also finishes walking at a point with integer coordinate.
* He only changes direction at a point with integer coordinate.
Each time when Snuke passes a point with coordinate i-0.5, where i is an integer, he put a stone in his i-th ear.
After Snuke finishes walking, Ringo will repeat the following operations in some order so that, for each i, Snuke's i-th ear contains A_i stones:
* Put a stone in one of Snuke's ears.
* Remove a stone from one of Snuke's ears.
Find the minimum number of operations required when Ringo can freely decide how Snuke walks.
Constraints
* 1 \leq L \leq 2\times 10^5
* 0 \leq A_i \leq 10^9(1\leq i\leq L)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
L
A_1
:
A_L
Output
Print the minimum number of operations required when Ringo can freely decide how Snuke walks.
Examples
Input
4
1
0
2
3
Output
1
Input
8
2
0
0
2
1
3
4
1
Output
3
Input
7
314159265
358979323
846264338
327950288
419716939
937510582
0
Output
1
Submitted Solution:
```
def main():
L, *A = map(int, open(0))
D = [(2, 1), (1, 0), (0, 1)]
s0 = s1 = s2 = s3 = s4 = 0
for a in A:
e, o = D[(a - 1) % 2 + 1 if a else 0]
s0 += a
s1 = min(s0, s1 + e)
s2 = min(s1, s2 + o)
s3 = min(s2, s3 + e)
s4 = min(s3, s4 + a)
print(min(s0, s1, s2, s3, s4))
if __name__ == '__main__':
main()
``` | instruction | 0 | 80,664 | 16 | 161,328 |
Yes | output | 1 | 80,664 | 16 | 161,329 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke stands on a number line. He has L ears, and he will walk along the line continuously under the following conditions:
* He never visits a point with coordinate less than 0, or a point with coordinate greater than L.
* He starts walking at a point with integer coordinate, and also finishes walking at a point with integer coordinate.
* He only changes direction at a point with integer coordinate.
Each time when Snuke passes a point with coordinate i-0.5, where i is an integer, he put a stone in his i-th ear.
After Snuke finishes walking, Ringo will repeat the following operations in some order so that, for each i, Snuke's i-th ear contains A_i stones:
* Put a stone in one of Snuke's ears.
* Remove a stone from one of Snuke's ears.
Find the minimum number of operations required when Ringo can freely decide how Snuke walks.
Constraints
* 1 \leq L \leq 2\times 10^5
* 0 \leq A_i \leq 10^9(1\leq i\leq L)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
L
A_1
:
A_L
Output
Print the minimum number of operations required when Ringo can freely decide how Snuke walks.
Examples
Input
4
1
0
2
3
Output
1
Input
8
2
0
0
2
1
3
4
1
Output
3
Input
7
314159265
358979323
846264338
327950288
419716939
937510582
0
Output
1
Submitted Solution:
```
# -*- coding: utf-8 -*-
L = int(input())
A = [int(input()) for _ in range(L)]
DP = [0] * 5
# ----- L ----- S ----- G ----- R -----
# |--0--| |--1--| |--2--| |--3--| |--4--|
# |--*--| |--偶--| |--奇--| |--偶--| |--*--|
for i in range(L):
DP[4] = min(DP[0:5]) + A[i]
DP[3] = min(DP[0:4]) + (A[i] % 2 if A[i] != 0 else 2)
DP[2] = min(DP[0:3]) + ((A[i] + 1) % 2)
DP[1] = min(DP[0:2]) + (A[i] % 2 if A[i] != 0 else 2)
DP[0] = DP[0] + A[i]
print(min(DP))
``` | instruction | 0 | 80,665 | 16 | 161,330 |
Yes | output | 1 | 80,665 | 16 | 161,331 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke stands on a number line. He has L ears, and he will walk along the line continuously under the following conditions:
* He never visits a point with coordinate less than 0, or a point with coordinate greater than L.
* He starts walking at a point with integer coordinate, and also finishes walking at a point with integer coordinate.
* He only changes direction at a point with integer coordinate.
Each time when Snuke passes a point with coordinate i-0.5, where i is an integer, he put a stone in his i-th ear.
After Snuke finishes walking, Ringo will repeat the following operations in some order so that, for each i, Snuke's i-th ear contains A_i stones:
* Put a stone in one of Snuke's ears.
* Remove a stone from one of Snuke's ears.
Find the minimum number of operations required when Ringo can freely decide how Snuke walks.
Constraints
* 1 \leq L \leq 2\times 10^5
* 0 \leq A_i \leq 10^9(1\leq i\leq L)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
L
A_1
:
A_L
Output
Print the minimum number of operations required when Ringo can freely decide how Snuke walks.
Examples
Input
4
1
0
2
3
Output
1
Input
8
2
0
0
2
1
3
4
1
Output
3
Input
7
314159265
358979323
846264338
327950288
419716939
937510582
0
Output
1
Submitted Solution:
```
from itertools import accumulate
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
L = int(input())
l = [0]*L
l2 = [0]*L
for i in range(L):
a = int(input())
l[i] = a % 2
l = list(accumulate(l))
for i in range(L):
l2[i] = abs(i+1-2*l[i])
ind = l2.index(max(l2))
ans = ind+1 - l[ind]+l[-1]-l[ind]
ans2 = l[ind] + L-ind-1 - l[-1]+l[ind]
print(min(ans, ans2))
``` | instruction | 0 | 80,666 | 16 | 161,332 |
No | output | 1 | 80,666 | 16 | 161,333 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke stands on a number line. He has L ears, and he will walk along the line continuously under the following conditions:
* He never visits a point with coordinate less than 0, or a point with coordinate greater than L.
* He starts walking at a point with integer coordinate, and also finishes walking at a point with integer coordinate.
* He only changes direction at a point with integer coordinate.
Each time when Snuke passes a point with coordinate i-0.5, where i is an integer, he put a stone in his i-th ear.
After Snuke finishes walking, Ringo will repeat the following operations in some order so that, for each i, Snuke's i-th ear contains A_i stones:
* Put a stone in one of Snuke's ears.
* Remove a stone from one of Snuke's ears.
Find the minimum number of operations required when Ringo can freely decide how Snuke walks.
Constraints
* 1 \leq L \leq 2\times 10^5
* 0 \leq A_i \leq 10^9(1\leq i\leq L)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
L
A_1
:
A_L
Output
Print the minimum number of operations required when Ringo can freely decide how Snuke walks.
Examples
Input
4
1
0
2
3
Output
1
Input
8
2
0
0
2
1
3
4
1
Output
3
Input
7
314159265
358979323
846264338
327950288
419716939
937510582
0
Output
1
Submitted Solution:
```
import sys
input = sys.stdin.readline
N = int(input())
A = [int(input()) for _ in range(N)]
p1 = 0
p2 = 0
P1 = [0]
P2 = [0]
for a in A:
if a == 0:
p1 -= 2
p2 += 1
elif a % 2 == 0:
p2 -= 1
elif a % 2 == 1:
p1 -= 1
p2 += 1
p1 += a
P1.append(p1)
P2.append(p2)
S = sum(A)
dp = [[0, 0, 0, 0] for _ in range(N+1)]
dp[N] = [P1[N], P1[N]+P2[N], P1[N], 0]
for i in reversed(range(N)):
dp[i][0] = max(dp[i+1][0], P1[i])
dp[i][1] = max(dp[i+1][1], P2[i]+dp[i][0])
dp[i][2] = min(dp[i+1][2], P2[i]-dp[i][1])
dp[i][3] = min(dp[i+1][3], P1[i]+dp[i][2])
print(dp[0][3]+S)
``` | instruction | 0 | 80,667 | 16 | 161,334 |
No | output | 1 | 80,667 | 16 | 161,335 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke stands on a number line. He has L ears, and he will walk along the line continuously under the following conditions:
* He never visits a point with coordinate less than 0, or a point with coordinate greater than L.
* He starts walking at a point with integer coordinate, and also finishes walking at a point with integer coordinate.
* He only changes direction at a point with integer coordinate.
Each time when Snuke passes a point with coordinate i-0.5, where i is an integer, he put a stone in his i-th ear.
After Snuke finishes walking, Ringo will repeat the following operations in some order so that, for each i, Snuke's i-th ear contains A_i stones:
* Put a stone in one of Snuke's ears.
* Remove a stone from one of Snuke's ears.
Find the minimum number of operations required when Ringo can freely decide how Snuke walks.
Constraints
* 1 \leq L \leq 2\times 10^5
* 0 \leq A_i \leq 10^9(1\leq i\leq L)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
L
A_1
:
A_L
Output
Print the minimum number of operations required when Ringo can freely decide how Snuke walks.
Examples
Input
4
1
0
2
3
Output
1
Input
8
2
0
0
2
1
3
4
1
Output
3
Input
7
314159265
358979323
846264338
327950288
419716939
937510582
0
Output
1
Submitted Solution:
```
L = int(input())
inf = float('inf')
dp = [[inf] * (L+1) for _ in range(5)]
dp[0][0] = 0
for i in range(1, L+1):
a = int(input())
if a == 0:
dp[0][i] = dp[0][i-1] + a
dp[1][i] = min(dp[0][i-1], dp[1][i-1] + 2)
dp[2][i] = min(dp[0][i-1], dp[1][i-1], dp[2][i-1]) + 1
dp[3][i] = min(dp[0][i-1], dp[1][i-1], dp[2][i-1], dp[3][i-1]) + 2
dp[4][i] = min(dp[0][i-1], dp[1][i-1], dp[2][i-1], dp[3][i-1], dp[4][i-1])
else:
b = a & 1
c = not b
dp[0][i] = dp[0][i-1] + a
dp[1][i] = min(dp[0][i-1], dp[1][i-1]) + b
dp[2][i] = min(dp[0][i-1], dp[1][i-1], dp[2][i-1]) + c
dp[3][i] = min(dp[0][i-1], dp[1][i-1], dp[2][i-1], dp[3][i-1]) + b
dp[4][i] = min(dp[0][i-1], dp[1][i-1], dp[2][i-1], dp[3][i-1]) + a
print(min(dp[3][L], dp[4][L]))
``` | instruction | 0 | 80,668 | 16 | 161,336 |
No | output | 1 | 80,668 | 16 | 161,337 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.