message stringlengths 2 44.5k | message_type stringclasses 2
values | message_id int64 0 1 | conversation_id int64 42 109k | cluster float64 5 5 | __index_level_0__ int64 84 217k |
|---|---|---|---|---|---|
Provide a correct Python 3 solution for this coding contest problem.
We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller. (The operation is the same as the one in Problem D.)
* Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1.
It can be proved that the largest element in the sequence becomes N-1 or smaller after a finite number of operations.
You are given the sequence a_i. Find the number of times we will perform the above operation.
Constraints
* 2 ≤ N ≤ 50
* 0 ≤ a_i ≤ 10^{16} + 1000
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N
Output
Print the number of times the operation will be performed.
Examples
Input
4
3 3 3 3
Output
0
Input
3
1 0 3
Output
1
Input
2
2 2
Output
2
Input
7
27 0 0 0 0 0 0
Output
3
Input
10
1000 193 256 777 0 1 1192 1234567891011 48 425
Output
1234567894848 | instruction | 0 | 67,095 | 5 | 134,190 |
"Correct Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
gosa = 1.0 / 10**9
mod = 10**9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def main():
N = I()
a = LI()
r = 0
f = True
while f:
f = False
for i in range(N):
if a[i] < N:
continue
f = True
t = a[i] // N
r += t
for j in range(N):
if i == j:
continue
a[j] += t
a[i] -= t * N
return r
print(main())
``` | output | 1 | 67,095 | 5 | 134,191 |
Provide a correct Python 3 solution for this coding contest problem.
We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller. (The operation is the same as the one in Problem D.)
* Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1.
It can be proved that the largest element in the sequence becomes N-1 or smaller after a finite number of operations.
You are given the sequence a_i. Find the number of times we will perform the above operation.
Constraints
* 2 ≤ N ≤ 50
* 0 ≤ a_i ≤ 10^{16} + 1000
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N
Output
Print the number of times the operation will be performed.
Examples
Input
4
3 3 3 3
Output
0
Input
3
1 0 3
Output
1
Input
2
2 2
Output
2
Input
7
27 0 0 0 0 0 0
Output
3
Input
10
1000 193 256 777 0 1 1192 1234567891011 48 425
Output
1234567894848 | instruction | 0 | 67,096 | 5 | 134,192 |
"Correct Solution:
```
n = int(input())
A = list(int(x) for x in input().split())
ans = 0
while max(A) >= n:
m = max(A)
index = A.index(m)
count = m // n
ans += count
A = [a + count for a in A]
A[index] -= n * count + count
print(ans)
``` | output | 1 | 67,096 | 5 | 134,193 |
Provide a correct Python 3 solution for this coding contest problem.
We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller. (The operation is the same as the one in Problem D.)
* Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1.
It can be proved that the largest element in the sequence becomes N-1 or smaller after a finite number of operations.
You are given the sequence a_i. Find the number of times we will perform the above operation.
Constraints
* 2 ≤ N ≤ 50
* 0 ≤ a_i ≤ 10^{16} + 1000
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N
Output
Print the number of times the operation will be performed.
Examples
Input
4
3 3 3 3
Output
0
Input
3
1 0 3
Output
1
Input
2
2 2
Output
2
Input
7
27 0 0 0 0 0 0
Output
3
Input
10
1000 193 256 777 0 1 1192 1234567891011 48 425
Output
1234567894848 | instruction | 0 | 67,097 | 5 | 134,194 |
"Correct Solution:
```
# https://pitsbuffersolution.com/compro/atcoder/arc079e.php
def main():
N = int(input())
*a, = map(int, input().split())
tot = sum(a)
def is_ok(k):
b = (x + k - (N - 1) for x in a)
cnt = 0
for x in b:
cnt += (x + N) // (N + 1)
return cnt <= k
ret = 0
k = max(0, tot - N * (N - 1))
while k <= tot:
if is_ok(k):
ret = k
break
k += 1
print(ret)
if __name__ == '__main__':
main()
``` | output | 1 | 67,097 | 5 | 134,195 |
Provide a correct Python 3 solution for this coding contest problem.
We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller. (The operation is the same as the one in Problem D.)
* Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1.
It can be proved that the largest element in the sequence becomes N-1 or smaller after a finite number of operations.
You are given the sequence a_i. Find the number of times we will perform the above operation.
Constraints
* 2 ≤ N ≤ 50
* 0 ≤ a_i ≤ 10^{16} + 1000
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N
Output
Print the number of times the operation will be performed.
Examples
Input
4
3 3 3 3
Output
0
Input
3
1 0 3
Output
1
Input
2
2 2
Output
2
Input
7
27 0 0 0 0 0 0
Output
3
Input
10
1000 193 256 777 0 1 1192 1234567891011 48 425
Output
1234567894848 | instruction | 0 | 67,098 | 5 | 134,196 |
"Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
p = 0
q = 0
for x in a:
q += x
p = max(0, q-n*(n-1))
for y in range(p, q+1):
z = 0
for x in a:
z += (x+y+1)//(n+1)
if y >= z:
print(y)
break
``` | output | 1 | 67,098 | 5 | 134,197 |
Provide a correct Python 3 solution for this coding contest problem.
We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller. (The operation is the same as the one in Problem D.)
* Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1.
It can be proved that the largest element in the sequence becomes N-1 or smaller after a finite number of operations.
You are given the sequence a_i. Find the number of times we will perform the above operation.
Constraints
* 2 ≤ N ≤ 50
* 0 ≤ a_i ≤ 10^{16} + 1000
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N
Output
Print the number of times the operation will be performed.
Examples
Input
4
3 3 3 3
Output
0
Input
3
1 0 3
Output
1
Input
2
2 2
Output
2
Input
7
27 0 0 0 0 0 0
Output
3
Input
10
1000 193 256 777 0 1 1192 1234567891011 48 425
Output
1234567894848 | instruction | 0 | 67,099 | 5 | 134,198 |
"Correct Solution:
```
import sys
sys.setrecursionlimit(10**7)
readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))
from math import ceil
n = readint()
a = readints()
ans = 0
for i in range(n):
a.sort()
if a[-1]<n:
break
ans += 1
for j in range(n-1):
a[j]+=1
a[-1]-=n
a.sort()
while a[-1]-a[0]>n+1:
x = ceil((a[-1]-a[0]-n-1)/(n+1))
ans += x
for j in range(n-1):
a[j] += x
a[-1] -= n*x
a.sort()
if a[-1]>n:
ans += (a[0]-n+1)*n
A = a[0]
for i in range(n):
a[i] -= A-n+1
while a[-1]>=n:
ans += 1
for j in range(n-1):
a[j]+=1
a[-1]-=n
a.sort()
print(ans)
``` | output | 1 | 67,099 | 5 | 134,199 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller. (The operation is the same as the one in Problem D.)
* Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1.
It can be proved that the largest element in the sequence becomes N-1 or smaller after a finite number of operations.
You are given the sequence a_i. Find the number of times we will perform the above operation.
Constraints
* 2 ≤ N ≤ 50
* 0 ≤ a_i ≤ 10^{16} + 1000
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N
Output
Print the number of times the operation will be performed.
Examples
Input
4
3 3 3 3
Output
0
Input
3
1 0 3
Output
1
Input
2
2 2
Output
2
Input
7
27 0 0 0 0 0 0
Output
3
Input
10
1000 193 256 777 0 1 1192 1234567891011 48 425
Output
1234567894848
Submitted Solution:
```
N=int(input())
a=[int(i) for i in input().split()]
ans=0
while True:
f=0
for i in range(N):
if a[i]>=N:
d=a[i]//N
ans+=d
a[i]%=N
for j in range(N):
if i!=j:
a[j]+=d
else:
f+=1
if f==N:
break
print(ans)
``` | instruction | 0 | 67,100 | 5 | 134,200 |
Yes | output | 1 | 67,100 | 5 | 134,201 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller. (The operation is the same as the one in Problem D.)
* Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1.
It can be proved that the largest element in the sequence becomes N-1 or smaller after a finite number of operations.
You are given the sequence a_i. Find the number of times we will perform the above operation.
Constraints
* 2 ≤ N ≤ 50
* 0 ≤ a_i ≤ 10^{16} + 1000
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N
Output
Print the number of times the operation will be performed.
Examples
Input
4
3 3 3 3
Output
0
Input
3
1 0 3
Output
1
Input
2
2 2
Output
2
Input
7
27 0 0 0 0 0 0
Output
3
Input
10
1000 193 256 777 0 1 1192 1234567891011 48 425
Output
1234567894848
Submitted Solution:
```
N = int(input())
A = list(map(int,input().split()))
count = 0
flag = True
while flag:
c = [0]*N
for i in range(N):
c[i] = A[i]//N
A[i] %= N
S = sum(c)
flag = False
for i in range(N):
A[i]+=S-c[i]
if A[i]>=N:
flag=True
count += S
print(count)
``` | instruction | 0 | 67,101 | 5 | 134,202 |
Yes | output | 1 | 67,101 | 5 | 134,203 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller. (The operation is the same as the one in Problem D.)
* Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1.
It can be proved that the largest element in the sequence becomes N-1 or smaller after a finite number of operations.
You are given the sequence a_i. Find the number of times we will perform the above operation.
Constraints
* 2 ≤ N ≤ 50
* 0 ≤ a_i ≤ 10^{16} + 1000
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N
Output
Print the number of times the operation will be performed.
Examples
Input
4
3 3 3 3
Output
0
Input
3
1 0 3
Output
1
Input
2
2 2
Output
2
Input
7
27 0 0 0 0 0 0
Output
3
Input
10
1000 193 256 777 0 1 1192 1234567891011 48 425
Output
1234567894848
Submitted Solution:
```
N = int(input())
A = list(map(int, input().split()))
def judge(k):
cnt = sum(max((a+k+1)//(N+1),0) for a in A)
return cnt <= k
if judge(0):
print(0)
exit(0)
low = 0
high = 10**18
while low + 1 < high:
mid = (low+high)//2
if judge(mid):
high = mid
else:
low = mid
r = high
for i in range(max(r-N*N,0),r):
if judge(i):
r = i
break
print(r)
``` | instruction | 0 | 67,102 | 5 | 134,204 |
Yes | output | 1 | 67,102 | 5 | 134,205 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller. (The operation is the same as the one in Problem D.)
* Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1.
It can be proved that the largest element in the sequence becomes N-1 or smaller after a finite number of operations.
You are given the sequence a_i. Find the number of times we will perform the above operation.
Constraints
* 2 ≤ N ≤ 50
* 0 ≤ a_i ≤ 10^{16} + 1000
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N
Output
Print the number of times the operation will be performed.
Examples
Input
4
3 3 3 3
Output
0
Input
3
1 0 3
Output
1
Input
2
2 2
Output
2
Input
7
27 0 0 0 0 0 0
Output
3
Input
10
1000 193 256 777 0 1 1192 1234567891011 48 425
Output
1234567894848
Submitted Solution:
```
N = int(input())
A = list(map(int, input().split()))
ans = 0
while True:
if all(map(lambda x: x < N, A)):
break
temp = 0
num = [0] * N
for i in range(N):
temp += A[i] // N
num[i] = A[i] // N
A[i] %= N
ans += temp
A = [a + temp - n for a, n in zip(A, num)]
print(ans)
``` | instruction | 0 | 67,103 | 5 | 134,206 |
Yes | output | 1 | 67,103 | 5 | 134,207 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller. (The operation is the same as the one in Problem D.)
* Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1.
It can be proved that the largest element in the sequence becomes N-1 or smaller after a finite number of operations.
You are given the sequence a_i. Find the number of times we will perform the above operation.
Constraints
* 2 ≤ N ≤ 50
* 0 ≤ a_i ≤ 10^{16} + 1000
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N
Output
Print the number of times the operation will be performed.
Examples
Input
4
3 3 3 3
Output
0
Input
3
1 0 3
Output
1
Input
2
2 2
Output
2
Input
7
27 0 0 0 0 0 0
Output
3
Input
10
1000 193 256 777 0 1 1192 1234567891011 48 425
Output
1234567894848
Submitted Solution:
```
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
if max(a) < N:
print(0)
exit(0)
ng = 0
ok = max(a) * N
def check(x):
c = 0
for i in range(N):
c += max(-(-(a[i] + x - N + 1) // (N + 1)), 0)
return x >= c
while ok - ng > 1:
m = (ok + ng) // 2
if check(m): ok = m
else: ng = m
res = ok + 0
ok = 0
ng = -(-res // N)
while ng - ok > 1:
m = (ok + ng) // 2
if check(res - m * N): ok = m
else: ng = m
res -= ok * N
print(res)
``` | instruction | 0 | 67,104 | 5 | 134,208 |
No | output | 1 | 67,104 | 5 | 134,209 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller. (The operation is the same as the one in Problem D.)
* Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1.
It can be proved that the largest element in the sequence becomes N-1 or smaller after a finite number of operations.
You are given the sequence a_i. Find the number of times we will perform the above operation.
Constraints
* 2 ≤ N ≤ 50
* 0 ≤ a_i ≤ 10^{16} + 1000
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N
Output
Print the number of times the operation will be performed.
Examples
Input
4
3 3 3 3
Output
0
Input
3
1 0 3
Output
1
Input
2
2 2
Output
2
Input
7
27 0 0 0 0 0 0
Output
3
Input
10
1000 193 256 777 0 1 1192 1234567891011 48 425
Output
1234567894848
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
a = sorted(a, key=lambda x: -x)
x = (a[0] - a[1]) // (n + 1)
def check():
global a
global x
if max(a) <= n - 1:
print(x)
exit(0)
def operation():
global a
global x
x += 1
i = a.index(max(a))
for j in range(n):
if j != i:
a[j] += 1
a[i] -= n
check()
a[0] -= x * n
for i in range(1, n):
a[i] += x
check()
for i in range(1000):
operation()
save = a[:]
difs = [a[i] - a[i - 1] for i in range(1, n)]
#print('searching for cycles', max(difs))
c = 0
while True:
c += 1
operation()
d = [a[i] - a[i - 1] for i in range(1, n)]
#print(max(d))
if d == difs:
break
#print('cycle found')
i = a.index(min(a))
diff_by_c = save[i] - a[i] # svakih c se smanji za diff_by_c
diff = max(0, a[i] - n)
phases = diff // diff_by_c
x += c * phases
for i in range(n):
a[i] -= phases * diff_by_c
check()
while True:
operation()
``` | instruction | 0 | 67,105 | 5 | 134,210 |
No | output | 1 | 67,105 | 5 | 134,211 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller. (The operation is the same as the one in Problem D.)
* Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1.
It can be proved that the largest element in the sequence becomes N-1 or smaller after a finite number of operations.
You are given the sequence a_i. Find the number of times we will perform the above operation.
Constraints
* 2 ≤ N ≤ 50
* 0 ≤ a_i ≤ 10^{16} + 1000
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N
Output
Print the number of times the operation will be performed.
Examples
Input
4
3 3 3 3
Output
0
Input
3
1 0 3
Output
1
Input
2
2 2
Output
2
Input
7
27 0 0 0 0 0 0
Output
3
Input
10
1000 193 256 777 0 1 1192 1234567891011 48 425
Output
1234567894848
Submitted Solution:
```
N = int(input())
A = list(map(int,input().split()))
def check(x):
count = 0
for i in range(N):
a = max(A[i] + x - N + 1,0)
#print(a)
if a%(N+1)==0:
count += a//(N+1)
else:
count += a//(N+1) + 1
return count <= x
l = 0
r = 10**17
if check(l):
print(l)
else:
while r-l>1:
if check((l+r)//2):
r = (l+r)//2
else:
l = (l+r)//2
print(r)
``` | instruction | 0 | 67,106 | 5 | 134,212 |
No | output | 1 | 67,106 | 5 | 134,213 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller. (The operation is the same as the one in Problem D.)
* Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1.
It can be proved that the largest element in the sequence becomes N-1 or smaller after a finite number of operations.
You are given the sequence a_i. Find the number of times we will perform the above operation.
Constraints
* 2 ≤ N ≤ 50
* 0 ≤ a_i ≤ 10^{16} + 1000
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N
Output
Print the number of times the operation will be performed.
Examples
Input
4
3 3 3 3
Output
0
Input
3
1 0 3
Output
1
Input
2
2 2
Output
2
Input
7
27 0 0 0 0 0 0
Output
3
Input
10
1000 193 256 777 0 1 1192 1234567891011 48 425
Output
1234567894848
Submitted Solution:
```
import sys
def bisect_left_callable(fn, x, lo, hi):
"""
lo から hi-1 のうち、fn の結果が x 以上となる、最も左の値
bisect.bisect_left と同じ
https://docs.python.org/ja/3/library/bisect.html
:param callable fn:
:param x:
:param int lo: 最小値
:param int hi: 最大値 + 1
:return: lo <= ret <= hi
"""
while lo < hi:
mid = (lo + hi) // 2
if fn(mid) < x:
lo = mid + 1
else:
hi = mid
return lo
sys.setrecursionlimit(100000)
INF = float('inf')
N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
MAX = 10 ** 20
def check(k):
"""
:param int k:
:return: k 回操作して条件を満たせば 0、k が大きすぎたらプラス、小さすぎたらマイナス
"""
# k を全体に足す
# N + 1 をちょうど k 回引ければそれが答え
li = [a + k for a in A]
sub = 0
for a in li:
sub += (a + 1) // (N + 1)
return k - sub
if max(A) < N:
print(0)
exit()
# このへんに答えがある
ans = bisect_left_callable(check, 0, 1, MAX)
# このへん小さい順に全部調べる(あたまわるい)
ans = max(1, ans - 100)
for i in range(200):
if check(ans + i) == 0:
print(ans + i)
break
``` | instruction | 0 | 67,107 | 5 | 134,214 |
No | output | 1 | 67,107 | 5 | 134,215 |
Provide a correct Python 3 solution for this coding contest problem.
For a dynamic list $L$ of integers, perform a sequence of the following operations. $L$ has a special element called END at the end of the list and an element of $L$ is indicated by a cursor.
* insert($x$): Insert $x$ before the element indicated by the cursor. After this operation, the cursor points the inserted element.
* move($d$): Move the cursor to the end by $d$, if $d$ is positive. Move the cursor to the front by $d$, if $d$ is negative.
* erase(): Delete the element indicated by the cursor. After this operation, the cursor points the element next to the deleted element. In case there is no such element, the cursor should point END.
In the initial state, $L$ is empty and the cursor points END.
Constraints
* $1 \leq q \leq 500,000$
* The cursor indicates an element of $L$ or END during the operations
* Erase operation will not given when the cursor points END
* $-1,000,000,000 \leq x \leq 1,000,000,000$
* Moving distance of the cursor ($\sum{|d|}$) does not exceed 1,000,000
* $L$ is not empty after performing all operations
Input
The input is given in the following format.
$q$
$query_1$
$query_2$
:
$query_q$
Each query $query_i$ is given by
0 $x$
or
1 $d$
or
2
where the first digits 0, 1 and 2 represent insert, move and erase operations respectively.
Output
Print all elements of the list in order after performing given operations. Print an element in a line.
Example
Input
5
0 1
0 2
0 3
1 1
2
Output
3
1 | instruction | 0 | 67,235 | 5 | 134,470 |
"Correct Solution:
```
class Node:
def __init__(self, left, right, date):
self.left = left
self.right = right
self.date = date
root = Node(None, None, None)
cur = root.right = Node(root, None, None)
def insert(x, cur):
cur.left.right = cur.left = cur = Node(cur.left,cur, x)
return cur
def move(x, cur):
d = int(x[0])
if d > 0:
for _ in range(d):
cur = cur.right
else:
for _ in range(-d):
cur = cur.left
return cur
def erase(_,cur):
cur.right.left = cur.left
cur.left.right = cur.right
cur = cur.right
return cur
C = {'0':insert, '1':move, '2':erase}
n = int(input())
for _ in range(n):
query = input().split()
cur = C[query[0]](query[1:], cur)
ans = []
it = root.right
while it.right:
ans.append(it.date)
it = it.right
for i in range(len(ans)):
print(ans[i][0])
``` | output | 1 | 67,235 | 5 | 134,471 |
Provide a correct Python 3 solution for this coding contest problem.
For a dynamic list $L$ of integers, perform a sequence of the following operations. $L$ has a special element called END at the end of the list and an element of $L$ is indicated by a cursor.
* insert($x$): Insert $x$ before the element indicated by the cursor. After this operation, the cursor points the inserted element.
* move($d$): Move the cursor to the end by $d$, if $d$ is positive. Move the cursor to the front by $d$, if $d$ is negative.
* erase(): Delete the element indicated by the cursor. After this operation, the cursor points the element next to the deleted element. In case there is no such element, the cursor should point END.
In the initial state, $L$ is empty and the cursor points END.
Constraints
* $1 \leq q \leq 500,000$
* The cursor indicates an element of $L$ or END during the operations
* Erase operation will not given when the cursor points END
* $-1,000,000,000 \leq x \leq 1,000,000,000$
* Moving distance of the cursor ($\sum{|d|}$) does not exceed 1,000,000
* $L$ is not empty after performing all operations
Input
The input is given in the following format.
$q$
$query_1$
$query_2$
:
$query_q$
Each query $query_i$ is given by
0 $x$
or
1 $d$
or
2
where the first digits 0, 1 and 2 represent insert, move and erase operations respectively.
Output
Print all elements of the list in order after performing given operations. Print an element in a line.
Example
Input
5
0 1
0 2
0 3
1 1
2
Output
3
1 | instruction | 0 | 67,236 | 5 | 134,472 |
"Correct Solution:
```
def solve():
from sys import stdin
f_i = stdin
q = f_i.readline()
d = 0
from collections import deque
L = deque()
for l in f_i:
if l[0] == '0':
L.append(l[2:])
elif l[0] == '1':
r = int(l[2:])
L.rotate(r)
d -= r
else:
L.pop()
L.rotate(d)
L.reverse()
print(''.join(L), end='')
solve()
``` | output | 1 | 67,236 | 5 | 134,473 |
Provide a correct Python 3 solution for this coding contest problem.
For a dynamic list $L$ of integers, perform a sequence of the following operations. $L$ has a special element called END at the end of the list and an element of $L$ is indicated by a cursor.
* insert($x$): Insert $x$ before the element indicated by the cursor. After this operation, the cursor points the inserted element.
* move($d$): Move the cursor to the end by $d$, if $d$ is positive. Move the cursor to the front by $d$, if $d$ is negative.
* erase(): Delete the element indicated by the cursor. After this operation, the cursor points the element next to the deleted element. In case there is no such element, the cursor should point END.
In the initial state, $L$ is empty and the cursor points END.
Constraints
* $1 \leq q \leq 500,000$
* The cursor indicates an element of $L$ or END during the operations
* Erase operation will not given when the cursor points END
* $-1,000,000,000 \leq x \leq 1,000,000,000$
* Moving distance of the cursor ($\sum{|d|}$) does not exceed 1,000,000
* $L$ is not empty after performing all operations
Input
The input is given in the following format.
$q$
$query_1$
$query_2$
:
$query_q$
Each query $query_i$ is given by
0 $x$
or
1 $d$
or
2
where the first digits 0, 1 and 2 represent insert, move and erase operations respectively.
Output
Print all elements of the list in order after performing given operations. Print an element in a line.
Example
Input
5
0 1
0 2
0 3
1 1
2
Output
3
1 | instruction | 0 | 67,237 | 5 | 134,474 |
"Correct Solution:
```
from sys import stdin
class LinkedList():
def __init__(self):
self.head = [None, None, None]
self.head[1] = self.pos = self.tail = [self.head, None, None]
def insert(self, x):
temp = [self.pos[0], self.pos, x]
self.pos[0][1] = self.pos[0] = self.pos = [self.pos[0], self.pos, x]
def move_right(self, d):
for _ in range(d):
self.pos = self.pos[1]
def move_left(self, d):
for _ in range(d):
self.pos = self.pos[0]
def move(self, d):
if d > 0:
self.move_right(d)
else:
self.move_left(d * -1)
def erase(self):
self.pos[1][0] = self.pos[0]
self.pos = self.pos[0][1] = self.pos[1]
def to_list(self):
index = self.head[1]
out = []
while(index[1] is not None):
out.append(index[2])
index = index[1]
return out
n = stdin.readline()
queries = stdin.readlines()
ll = LinkedList()
#count = 0
for query in queries:
#print(count)
#count += 1
query = query.split()
if query[0] == '0':
ll.insert(query[1])
elif query[0] == '1':
ll.move(int(query[1]))
else:
ll.erase()
print('\n'.join(ll.to_list()))
``` | output | 1 | 67,237 | 5 | 134,475 |
Provide a correct Python 3 solution for this coding contest problem.
For a dynamic list $L$ of integers, perform a sequence of the following operations. $L$ has a special element called END at the end of the list and an element of $L$ is indicated by a cursor.
* insert($x$): Insert $x$ before the element indicated by the cursor. After this operation, the cursor points the inserted element.
* move($d$): Move the cursor to the end by $d$, if $d$ is positive. Move the cursor to the front by $d$, if $d$ is negative.
* erase(): Delete the element indicated by the cursor. After this operation, the cursor points the element next to the deleted element. In case there is no such element, the cursor should point END.
In the initial state, $L$ is empty and the cursor points END.
Constraints
* $1 \leq q \leq 500,000$
* The cursor indicates an element of $L$ or END during the operations
* Erase operation will not given when the cursor points END
* $-1,000,000,000 \leq x \leq 1,000,000,000$
* Moving distance of the cursor ($\sum{|d|}$) does not exceed 1,000,000
* $L$ is not empty after performing all operations
Input
The input is given in the following format.
$q$
$query_1$
$query_2$
:
$query_q$
Each query $query_i$ is given by
0 $x$
or
1 $d$
or
2
where the first digits 0, 1 and 2 represent insert, move and erase operations respectively.
Output
Print all elements of the list in order after performing given operations. Print an element in a line.
Example
Input
5
0 1
0 2
0 3
1 1
2
Output
3
1 | instruction | 0 | 67,238 | 5 | 134,476 |
"Correct Solution:
```
from collections import deque
import sys
n=int(input())
A=deque()
cur=0
for i in range(n):
S=input()
if S[0]=='0':
A.append(S[2:])
elif S[0]=='1':
A.rotate(int(S[2:]))
cur-=int(S[2:])
elif S[0]=='2':
A.pop()
A.rotate(cur)
A.reverse()
print(*A, sep="\n")
``` | output | 1 | 67,238 | 5 | 134,477 |
Provide a correct Python 3 solution for this coding contest problem.
For a dynamic list $L$ of integers, perform a sequence of the following operations. $L$ has a special element called END at the end of the list and an element of $L$ is indicated by a cursor.
* insert($x$): Insert $x$ before the element indicated by the cursor. After this operation, the cursor points the inserted element.
* move($d$): Move the cursor to the end by $d$, if $d$ is positive. Move the cursor to the front by $d$, if $d$ is negative.
* erase(): Delete the element indicated by the cursor. After this operation, the cursor points the element next to the deleted element. In case there is no such element, the cursor should point END.
In the initial state, $L$ is empty and the cursor points END.
Constraints
* $1 \leq q \leq 500,000$
* The cursor indicates an element of $L$ or END during the operations
* Erase operation will not given when the cursor points END
* $-1,000,000,000 \leq x \leq 1,000,000,000$
* Moving distance of the cursor ($\sum{|d|}$) does not exceed 1,000,000
* $L$ is not empty after performing all operations
Input
The input is given in the following format.
$q$
$query_1$
$query_2$
:
$query_q$
Each query $query_i$ is given by
0 $x$
or
1 $d$
or
2
where the first digits 0, 1 and 2 represent insert, move and erase operations respectively.
Output
Print all elements of the list in order after performing given operations. Print an element in a line.
Example
Input
5
0 1
0 2
0 3
1 1
2
Output
3
1 | instruction | 0 | 67,239 | 5 | 134,478 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
"""
Dynamic Arrays and List - List
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_1_C&lang=jp
"""
class Node:
def __init__(self, value=0):
self.key = value
self.prev, self.next = None, None
class Lst:
def __init__(self):
self.nil = Node('END')
self.nil.next = self.nil
self.nil.prev = self.nil
self.cur = self.nil
def insert(self, value):
x = Node(value)
x.prev = self.cur.prev
self.cur.prev.next = x
self.cur.prev = x
x.next = self.cur
self.cur = x
def move(self, d):
if d >= 0:
for _ in range(d):
self.cur = self.cur.next
else:
for _ in range(abs(d)):
self.cur = self.cur.prev
def erase(self):
if self.cur == self.nil:
return
p = self.cur.next
self.cur.prev.next = self.cur.next
self.cur.next.prev = self.cur.prev
self.cur = p
lst = Lst()
for _ in range(int(input())):
op, n = (input() + ' 1').split()[:2]
if op == '0':
lst.insert(int(n))
elif op == '1':
lst.move(int(n))
else:
lst.erase()
cur = lst.nil
while cur.next != lst.nil:
cur = cur.next
print(cur.key)
``` | output | 1 | 67,239 | 5 | 134,479 |
Provide a correct Python 3 solution for this coding contest problem.
For a dynamic list $L$ of integers, perform a sequence of the following operations. $L$ has a special element called END at the end of the list and an element of $L$ is indicated by a cursor.
* insert($x$): Insert $x$ before the element indicated by the cursor. After this operation, the cursor points the inserted element.
* move($d$): Move the cursor to the end by $d$, if $d$ is positive. Move the cursor to the front by $d$, if $d$ is negative.
* erase(): Delete the element indicated by the cursor. After this operation, the cursor points the element next to the deleted element. In case there is no such element, the cursor should point END.
In the initial state, $L$ is empty and the cursor points END.
Constraints
* $1 \leq q \leq 500,000$
* The cursor indicates an element of $L$ or END during the operations
* Erase operation will not given when the cursor points END
* $-1,000,000,000 \leq x \leq 1,000,000,000$
* Moving distance of the cursor ($\sum{|d|}$) does not exceed 1,000,000
* $L$ is not empty after performing all operations
Input
The input is given in the following format.
$q$
$query_1$
$query_2$
:
$query_q$
Each query $query_i$ is given by
0 $x$
or
1 $d$
or
2
where the first digits 0, 1 and 2 represent insert, move and erase operations respectively.
Output
Print all elements of the list in order after performing given operations. Print an element in a line.
Example
Input
5
0 1
0 2
0 3
1 1
2
Output
3
1 | instruction | 0 | 67,241 | 5 | 134,482 |
"Correct Solution:
```
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_1_C&lang=jp
# List
from collections import deque
#import cProfile
#import time
import sys
input = sys.stdin.readline
def loop_proc():
q1 = deque()
q2 = deque()
l2 = []
cur = 0
rflag = True
n = int(input())
cnt = 0
while (cnt < n):
cnt += 1
if (rflag == True):
l = list(map(int,input().split()))
else:
l = l2
c = l[0]
rflag =True
#追加する場合
if ( c == 0 ):
d = l[1]
#APPEND() & POP()は読み飛ばす
if (cnt < n ):
l2 = list(map(int,input().split()))
if (l2[0] == 2 ):
cnt += 1
continue
rflag =False
q1.append(d)
#カーソル移動の場合
elif(c == 1):
cur = l[1]
if cur < 0 :
for i in range(abs(cur)):
q1.append(q2.pop())
else:
for i in range(abs(cur)):
q2.append(q1.pop())
# print (q1,q2)
#要素削除の場合
elif(c == 2):
q1.pop()
while len(q2) != 0 :
print (q2.popleft())
while len(q1) != 0 :
print (q1.pop())
# for i in wl:
# print (i)
loop_proc()
#pr = cProfile.Profile()
#pr.enable()
#pr.runcall(loop_proc)
#pr.print_stats()
``` | output | 1 | 67,241 | 5 | 134,483 |
Provide a correct Python 3 solution for this coding contest problem.
For a dynamic list $L$ of integers, perform a sequence of the following operations. $L$ has a special element called END at the end of the list and an element of $L$ is indicated by a cursor.
* insert($x$): Insert $x$ before the element indicated by the cursor. After this operation, the cursor points the inserted element.
* move($d$): Move the cursor to the end by $d$, if $d$ is positive. Move the cursor to the front by $d$, if $d$ is negative.
* erase(): Delete the element indicated by the cursor. After this operation, the cursor points the element next to the deleted element. In case there is no such element, the cursor should point END.
In the initial state, $L$ is empty and the cursor points END.
Constraints
* $1 \leq q \leq 500,000$
* The cursor indicates an element of $L$ or END during the operations
* Erase operation will not given when the cursor points END
* $-1,000,000,000 \leq x \leq 1,000,000,000$
* Moving distance of the cursor ($\sum{|d|}$) does not exceed 1,000,000
* $L$ is not empty after performing all operations
Input
The input is given in the following format.
$q$
$query_1$
$query_2$
:
$query_q$
Each query $query_i$ is given by
0 $x$
or
1 $d$
or
2
where the first digits 0, 1 and 2 represent insert, move and erase operations respectively.
Output
Print all elements of the list in order after performing given operations. Print an element in a line.
Example
Input
5
0 1
0 2
0 3
1 1
2
Output
3
1 | instruction | 0 | 67,242 | 5 | 134,484 |
"Correct Solution:
```
import sys
class DLLNode:
__slots__ = ['prev', 'next', 'data']
def __init__(self, prev, next, data):
self.prev = prev
self.next = next
self.data = data
root = DLLNode(None, None, None)
cur = root.next = DLLNode(root, None, None)
def insert(x, cur):
cur.prev.next = cur.prev = cur = DLLNode(cur.prev, cur, x)
return cur
def move(x, cur):
d = int(x)
if d > 0:
for _ in range(d):
cur = cur.next
else:
for _ in range(-d):
cur = cur.prev
return cur
def erase(_, cur):
cur.next.prev = cur.prev
cur.prev.next = cur = cur.next
return cur
C = {'0': insert, '1': move, '2': erase}
sys.stdin.readline()
for query in sys.stdin:
cur = C[query[0]](query[2:], cur)
ans = []
it = root.next
while it.next:
ans.append(it.data)
it = it.next
sys.stdout.writelines(ans)
``` | output | 1 | 67,242 | 5 | 134,485 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For a dynamic list $L$ of integers, perform a sequence of the following operations. $L$ has a special element called END at the end of the list and an element of $L$ is indicated by a cursor.
* insert($x$): Insert $x$ before the element indicated by the cursor. After this operation, the cursor points the inserted element.
* move($d$): Move the cursor to the end by $d$, if $d$ is positive. Move the cursor to the front by $d$, if $d$ is negative.
* erase(): Delete the element indicated by the cursor. After this operation, the cursor points the element next to the deleted element. In case there is no such element, the cursor should point END.
In the initial state, $L$ is empty and the cursor points END.
Constraints
* $1 \leq q \leq 500,000$
* The cursor indicates an element of $L$ or END during the operations
* Erase operation will not given when the cursor points END
* $-1,000,000,000 \leq x \leq 1,000,000,000$
* Moving distance of the cursor ($\sum{|d|}$) does not exceed 1,000,000
* $L$ is not empty after performing all operations
Input
The input is given in the following format.
$q$
$query_1$
$query_2$
:
$query_q$
Each query $query_i$ is given by
0 $x$
or
1 $d$
or
2
where the first digits 0, 1 and 2 represent insert, move and erase operations respectively.
Output
Print all elements of the list in order after performing given operations. Print an element in a line.
Example
Input
5
0 1
0 2
0 3
1 1
2
Output
3
1
Submitted Solution:
```
from collections import deque
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def main():
n=int(input())
sum_d=0
aa=deque()
for _ in range(n):
qq=list(map(int, input().split()))
if qq[0]==0:
aa.appendleft(qq[1])
elif qq[0]==1:
aa.rotate(-qq[1])
sum_d+=qq[1]
else:
aa.popleft()
aa.rotate(sum_d)
for a in aa:
print(a)
main()
``` | instruction | 0 | 67,243 | 5 | 134,486 |
Yes | output | 1 | 67,243 | 5 | 134,487 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For a dynamic list $L$ of integers, perform a sequence of the following operations. $L$ has a special element called END at the end of the list and an element of $L$ is indicated by a cursor.
* insert($x$): Insert $x$ before the element indicated by the cursor. After this operation, the cursor points the inserted element.
* move($d$): Move the cursor to the end by $d$, if $d$ is positive. Move the cursor to the front by $d$, if $d$ is negative.
* erase(): Delete the element indicated by the cursor. After this operation, the cursor points the element next to the deleted element. In case there is no such element, the cursor should point END.
In the initial state, $L$ is empty and the cursor points END.
Constraints
* $1 \leq q \leq 500,000$
* The cursor indicates an element of $L$ or END during the operations
* Erase operation will not given when the cursor points END
* $-1,000,000,000 \leq x \leq 1,000,000,000$
* Moving distance of the cursor ($\sum{|d|}$) does not exceed 1,000,000
* $L$ is not empty after performing all operations
Input
The input is given in the following format.
$q$
$query_1$
$query_2$
:
$query_q$
Each query $query_i$ is given by
0 $x$
or
1 $d$
or
2
where the first digits 0, 1 and 2 represent insert, move and erase operations respectively.
Output
Print all elements of the list in order after performing given operations. Print an element in a line.
Example
Input
5
0 1
0 2
0 3
1 1
2
Output
3
1
Submitted Solution:
```
readline = open(0).readline
writelines = open(1, 'w').writelines
Q = int(readline())
root = [None, None, None]
cursor = root[1] = [root, None, None]
def insert(x):
global cursor
cursor[0][1] = cursor[0] = cursor = [cursor[0], cursor, x]
def move(d):
global cursor
if d > 0:
for _ in range(d):
cursor = cursor[1]
else:
for _ in range(-d):
cursor = cursor[0]
def erase():
global cursor
cursor[1][0] = cursor[0]
cursor[0][1] = cursor = cursor[1]
C = [insert, move, erase].__getitem__
for q in range(Q):
t, *a = map(int, readline().split())
C(t)(*a)
root = root[1]
ans = []
while root[1]:
ans.append("%d\n" % root[2])
root = root[1]
writelines(ans)
``` | instruction | 0 | 67,244 | 5 | 134,488 |
Yes | output | 1 | 67,244 | 5 | 134,489 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For a dynamic list $L$ of integers, perform a sequence of the following operations. $L$ has a special element called END at the end of the list and an element of $L$ is indicated by a cursor.
* insert($x$): Insert $x$ before the element indicated by the cursor. After this operation, the cursor points the inserted element.
* move($d$): Move the cursor to the end by $d$, if $d$ is positive. Move the cursor to the front by $d$, if $d$ is negative.
* erase(): Delete the element indicated by the cursor. After this operation, the cursor points the element next to the deleted element. In case there is no such element, the cursor should point END.
In the initial state, $L$ is empty and the cursor points END.
Constraints
* $1 \leq q \leq 500,000$
* The cursor indicates an element of $L$ or END during the operations
* Erase operation will not given when the cursor points END
* $-1,000,000,000 \leq x \leq 1,000,000,000$
* Moving distance of the cursor ($\sum{|d|}$) does not exceed 1,000,000
* $L$ is not empty after performing all operations
Input
The input is given in the following format.
$q$
$query_1$
$query_2$
:
$query_q$
Each query $query_i$ is given by
0 $x$
or
1 $d$
or
2
where the first digits 0, 1 and 2 represent insert, move and erase operations respectively.
Output
Print all elements of the list in order after performing given operations. Print an element in a line.
Example
Input
5
0 1
0 2
0 3
1 1
2
Output
3
1
Submitted Solution:
```
import sys
from collections import deque
input = sys.stdin.readline
q = int(input())
ans = deque()
cursor = 0
for _ in range(q):
query = [int(i) for i in input().split()]
if query[0] == 0:
ans.appendleft(query[1])
elif query[0] == 1:
ans.rotate(-1 * query[1])
cursor += query[1]
else:
ans.popleft()
ans.rotate(cursor)
print(*ans, sep="\n")
``` | instruction | 0 | 67,245 | 5 | 134,490 |
Yes | output | 1 | 67,245 | 5 | 134,491 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For a dynamic list $L$ of integers, perform a sequence of the following operations. $L$ has a special element called END at the end of the list and an element of $L$ is indicated by a cursor.
* insert($x$): Insert $x$ before the element indicated by the cursor. After this operation, the cursor points the inserted element.
* move($d$): Move the cursor to the end by $d$, if $d$ is positive. Move the cursor to the front by $d$, if $d$ is negative.
* erase(): Delete the element indicated by the cursor. After this operation, the cursor points the element next to the deleted element. In case there is no such element, the cursor should point END.
In the initial state, $L$ is empty and the cursor points END.
Constraints
* $1 \leq q \leq 500,000$
* The cursor indicates an element of $L$ or END during the operations
* Erase operation will not given when the cursor points END
* $-1,000,000,000 \leq x \leq 1,000,000,000$
* Moving distance of the cursor ($\sum{|d|}$) does not exceed 1,000,000
* $L$ is not empty after performing all operations
Input
The input is given in the following format.
$q$
$query_1$
$query_2$
:
$query_q$
Each query $query_i$ is given by
0 $x$
or
1 $d$
or
2
where the first digits 0, 1 and 2 represent insert, move and erase operations respectively.
Output
Print all elements of the list in order after performing given operations. Print an element in a line.
Example
Input
5
0 1
0 2
0 3
1 1
2
Output
3
1
Submitted Solution:
```
from collections import deque
def main():
m = int(input())
c = 0
dq = deque()
for _ in range(m):
q = list(map(int,input().split()))
if q[0] == 0:dq.appendleft(q[1])
elif q[0] == 1:
dq.rotate(-q[1])
c+=q[1]
else :dq.popleft()
dq.rotate(c)
for e in dq:print(e)
if __name__ == '__main__':
main()
``` | instruction | 0 | 67,246 | 5 | 134,492 |
Yes | output | 1 | 67,246 | 5 | 134,493 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For a dynamic list $L$ of integers, perform a sequence of the following operations. $L$ has a special element called END at the end of the list and an element of $L$ is indicated by a cursor.
* insert($x$): Insert $x$ before the element indicated by the cursor. After this operation, the cursor points the inserted element.
* move($d$): Move the cursor to the end by $d$, if $d$ is positive. Move the cursor to the front by $d$, if $d$ is negative.
* erase(): Delete the element indicated by the cursor. After this operation, the cursor points the element next to the deleted element. In case there is no such element, the cursor should point END.
In the initial state, $L$ is empty and the cursor points END.
Constraints
* $1 \leq q \leq 500,000$
* The cursor indicates an element of $L$ or END during the operations
* Erase operation will not given when the cursor points END
* $-1,000,000,000 \leq x \leq 1,000,000,000$
* Moving distance of the cursor ($\sum{|d|}$) does not exceed 1,000,000
* $L$ is not empty after performing all operations
Input
The input is given in the following format.
$q$
$query_1$
$query_2$
:
$query_q$
Each query $query_i$ is given by
0 $x$
or
1 $d$
or
2
where the first digits 0, 1 and 2 represent insert, move and erase operations respectively.
Output
Print all elements of the list in order after performing given operations. Print an element in a line.
Example
Input
5
0 1
0 2
0 3
1 1
2
Output
3
1
Submitted Solution:
```
from sys import stdin
from collections import deque
num = int(input())
list2 = deque()
list2.appendleft("END")
cur = 0
for i in range(num):
cmd = stdin.readline().strip()
if cmd[0:1] == "0":
if cur == 0:
list2.appendleft(cmd[2:])
else:
list2.insert(cur,cmd[2:])
elif cmd[0:1] == "1":
cur += int(cmd[2:])
else:
list2.remove(list2[cur])
list2.remove("END")
print(*list2,sep='\n')
``` | instruction | 0 | 67,247 | 5 | 134,494 |
No | output | 1 | 67,247 | 5 | 134,495 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For a dynamic list $L$ of integers, perform a sequence of the following operations. $L$ has a special element called END at the end of the list and an element of $L$ is indicated by a cursor.
* insert($x$): Insert $x$ before the element indicated by the cursor. After this operation, the cursor points the inserted element.
* move($d$): Move the cursor to the end by $d$, if $d$ is positive. Move the cursor to the front by $d$, if $d$ is negative.
* erase(): Delete the element indicated by the cursor. After this operation, the cursor points the element next to the deleted element. In case there is no such element, the cursor should point END.
In the initial state, $L$ is empty and the cursor points END.
Constraints
* $1 \leq q \leq 500,000$
* The cursor indicates an element of $L$ or END during the operations
* Erase operation will not given when the cursor points END
* $-1,000,000,000 \leq x \leq 1,000,000,000$
* Moving distance of the cursor ($\sum{|d|}$) does not exceed 1,000,000
* $L$ is not empty after performing all operations
Input
The input is given in the following format.
$q$
$query_1$
$query_2$
:
$query_q$
Each query $query_i$ is given by
0 $x$
or
1 $d$
or
2
where the first digits 0, 1 and 2 represent insert, move and erase operations respectively.
Output
Print all elements of the list in order after performing given operations. Print an element in a line.
Example
Input
5
0 1
0 2
0 3
1 1
2
Output
3
1
Submitted Solution:
```
arr = []
cur = 0
q = int(input())
for i in range(q):
op = list(map(int, input().split(' ')))
if op[0] == 0:
arr.insert(cur, op[1])
elif op[0] == 1:
cur += op[1]
elif op[0] == 2:
arr.pop(cur)
if len(arr) >= cur: cur = len(arr)-1
for ele in arr:
print(ele)
``` | instruction | 0 | 67,248 | 5 | 134,496 |
No | output | 1 | 67,248 | 5 | 134,497 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For a dynamic list $L$ of integers, perform a sequence of the following operations. $L$ has a special element called END at the end of the list and an element of $L$ is indicated by a cursor.
* insert($x$): Insert $x$ before the element indicated by the cursor. After this operation, the cursor points the inserted element.
* move($d$): Move the cursor to the end by $d$, if $d$ is positive. Move the cursor to the front by $d$, if $d$ is negative.
* erase(): Delete the element indicated by the cursor. After this operation, the cursor points the element next to the deleted element. In case there is no such element, the cursor should point END.
In the initial state, $L$ is empty and the cursor points END.
Constraints
* $1 \leq q \leq 500,000$
* The cursor indicates an element of $L$ or END during the operations
* Erase operation will not given when the cursor points END
* $-1,000,000,000 \leq x \leq 1,000,000,000$
* Moving distance of the cursor ($\sum{|d|}$) does not exceed 1,000,000
* $L$ is not empty after performing all operations
Input
The input is given in the following format.
$q$
$query_1$
$query_2$
:
$query_q$
Each query $query_i$ is given by
0 $x$
or
1 $d$
or
2
where the first digits 0, 1 and 2 represent insert, move and erase operations respectively.
Output
Print all elements of the list in order after performing given operations. Print an element in a line.
Example
Input
5
0 1
0 2
0 3
1 1
2
Output
3
1
Submitted Solution:
```
from sys import stdin
num = int(input())
list2 = ["END"]
cur = list2.index("END")
for i in range(num):
cmd = stdin.readline().strip().split()
if cmd[0] == "0":
if cur == 0:
list2.insert(0,cmd[1])
cur = 0
else:
list2.insert(cur,cmd[1])
elif cmd[0] == "1":
cur += int(cmd[1])
else:
tmp = cur
list2.pop(cur)
cur1 = list2.index("END")
if tmp == cur1 - 1:
cur = list2.index("END")
list2.remove("END")
print(*list2,sep='\n')
``` | instruction | 0 | 67,249 | 5 | 134,498 |
No | output | 1 | 67,249 | 5 | 134,499 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For a dynamic list $L$ of integers, perform a sequence of the following operations. $L$ has a special element called END at the end of the list and an element of $L$ is indicated by a cursor.
* insert($x$): Insert $x$ before the element indicated by the cursor. After this operation, the cursor points the inserted element.
* move($d$): Move the cursor to the end by $d$, if $d$ is positive. Move the cursor to the front by $d$, if $d$ is negative.
* erase(): Delete the element indicated by the cursor. After this operation, the cursor points the element next to the deleted element. In case there is no such element, the cursor should point END.
In the initial state, $L$ is empty and the cursor points END.
Constraints
* $1 \leq q \leq 500,000$
* The cursor indicates an element of $L$ or END during the operations
* Erase operation will not given when the cursor points END
* $-1,000,000,000 \leq x \leq 1,000,000,000$
* Moving distance of the cursor ($\sum{|d|}$) does not exceed 1,000,000
* $L$ is not empty after performing all operations
Input
The input is given in the following format.
$q$
$query_1$
$query_2$
:
$query_q$
Each query $query_i$ is given by
0 $x$
or
1 $d$
or
2
where the first digits 0, 1 and 2 represent insert, move and erase operations respectively.
Output
Print all elements of the list in order after performing given operations. Print an element in a line.
Example
Input
5
0 1
0 2
0 3
1 1
2
Output
3
1
Submitted Solution:
```
import numpy as np
if __name__ == '__main__':
n = int(input())
npls = np.array(['END'])
c = 0
count = 0
for i in range(n):
q = input().split()
a, b = (q[0], q[1]) if len(q) == 2 else (q[0], None)
if a == '0':
npls = np.insert(npls, c, b)
count += 1
elif a == '1':
c += int(b)
else:
npls = np.delete(npls, c)
count -= 1
if c == count:
c -= 1
for i in npls:
if i != 'END':
print(i)
else:
break
``` | instruction | 0 | 67,250 | 5 | 134,500 |
No | output | 1 | 67,250 | 5 | 134,501 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she always gives her students large and difficult homework. Despite that Valera is one of the best students, he failed to manage with the new homework. That's why he asks for your help. He has the following task. A sequence of n numbers is given. A prefix of a sequence is the part of the sequence (possibly empty), taken from the start of the sequence. A suffix of a sequence is the part of the sequence (possibly empty), taken from the end of the sequence. It is allowed to sequentially make two operations with the sequence. The first operation is to take some prefix of the sequence and multiply all numbers in this prefix by - 1. The second operation is to take some suffix and multiply all numbers in it by - 1. The chosen prefix and suffix may intersect. What is the maximum total sum of the sequence that can be obtained by applying the described operations?
Input
The first line contains integer n (1 ≤ n ≤ 105) — amount of elements in the sequence. The second line contains n integers ai ( - 104 ≤ ai ≤ 104) — the sequence itself.
Output
The first and the only line of the output should contain the answer to the problem.
Examples
Input
3
-1 -2 -3
Output
6
Input
5
-4 2 0 5 0
Output
11
Input
5
-1 10 -5 10 -2
Output
18
Submitted Solution:
```
n = int(input())
summ = 0
mx = 0
l = [*map(int ,input().split())]
for i in l:
summ += i
if summ < 0:
summ = 0
mx = max(summ , mx)
summ = 0
for i in l:
summ += i
print(2*mx-summ)
``` | instruction | 0 | 67,589 | 5 | 135,178 |
Yes | output | 1 | 67,589 | 5 | 135,179 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she always gives her students large and difficult homework. Despite that Valera is one of the best students, he failed to manage with the new homework. That's why he asks for your help. He has the following task. A sequence of n numbers is given. A prefix of a sequence is the part of the sequence (possibly empty), taken from the start of the sequence. A suffix of a sequence is the part of the sequence (possibly empty), taken from the end of the sequence. It is allowed to sequentially make two operations with the sequence. The first operation is to take some prefix of the sequence and multiply all numbers in this prefix by - 1. The second operation is to take some suffix and multiply all numbers in it by - 1. The chosen prefix and suffix may intersect. What is the maximum total sum of the sequence that can be obtained by applying the described operations?
Input
The first line contains integer n (1 ≤ n ≤ 105) — amount of elements in the sequence. The second line contains n integers ai ( - 104 ≤ ai ≤ 104) — the sequence itself.
Output
The first and the only line of the output should contain the answer to the problem.
Examples
Input
3
-1 -2 -3
Output
6
Input
5
-4 2 0 5 0
Output
11
Input
5
-1 10 -5 10 -2
Output
18
Submitted Solution:
```
n = int(input())
s = input().split()
c = []
for i in range(n):
c.append(int(s[i]))
lsum= []
rsum = []
sum = 0
for i in range(n):
if(i==0):
lsum.append(c[0])
else:
lsum.append(lsum[i-1]+c[i])
for i in reversed(range(n)):
if(i==n-1):
rsum.append(c[n-1])
else:
rsum.append(rsum[n-i-2]+c[i])
rsum.reverse()
for i in range(n):
sum += c[i]
minval = 0
minrsum = 0
for i in reversed(range(n)):
if(i<n-1):
minrsum = min(rsum[i+1],minrsum)
minval = min(min(rsum[i+1],minrsum)+lsum[i],lsum[i],minval)
else:
minval = min(lsum[i],minval)
for i in range(n):
minval = min(rsum[i],minval)
'''lsum.sort()
rsum.sort()
print(lsum)
print(rsum)
print(sum)'''
print(max(sum-2*minval,sum))
``` | instruction | 0 | 67,590 | 5 | 135,180 |
Yes | output | 1 | 67,590 | 5 | 135,181 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she always gives her students large and difficult homework. Despite that Valera is one of the best students, he failed to manage with the new homework. That's why he asks for your help. He has the following task. A sequence of n numbers is given. A prefix of a sequence is the part of the sequence (possibly empty), taken from the start of the sequence. A suffix of a sequence is the part of the sequence (possibly empty), taken from the end of the sequence. It is allowed to sequentially make two operations with the sequence. The first operation is to take some prefix of the sequence and multiply all numbers in this prefix by - 1. The second operation is to take some suffix and multiply all numbers in it by - 1. The chosen prefix and suffix may intersect. What is the maximum total sum of the sequence that can be obtained by applying the described operations?
Input
The first line contains integer n (1 ≤ n ≤ 105) — amount of elements in the sequence. The second line contains n integers ai ( - 104 ≤ ai ≤ 104) — the sequence itself.
Output
The first and the only line of the output should contain the answer to the problem.
Examples
Input
3
-1 -2 -3
Output
6
Input
5
-4 2 0 5 0
Output
11
Input
5
-1 10 -5 10 -2
Output
18
Submitted Solution:
```
n = int(input())
values = list(map(int, input().split()))
best_infix = infix = 0
for x in values:
infix = max(0, infix + x)
best_infix = max(best_infix, infix)
print(2 * best_infix - sum(values))
# Made By Mostafa_Khaled
``` | instruction | 0 | 67,591 | 5 | 135,182 |
Yes | output | 1 | 67,591 | 5 | 135,183 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she always gives her students large and difficult homework. Despite that Valera is one of the best students, he failed to manage with the new homework. That's why he asks for your help. He has the following task. A sequence of n numbers is given. A prefix of a sequence is the part of the sequence (possibly empty), taken from the start of the sequence. A suffix of a sequence is the part of the sequence (possibly empty), taken from the end of the sequence. It is allowed to sequentially make two operations with the sequence. The first operation is to take some prefix of the sequence and multiply all numbers in this prefix by - 1. The second operation is to take some suffix and multiply all numbers in it by - 1. The chosen prefix and suffix may intersect. What is the maximum total sum of the sequence that can be obtained by applying the described operations?
Input
The first line contains integer n (1 ≤ n ≤ 105) — amount of elements in the sequence. The second line contains n integers ai ( - 104 ≤ ai ≤ 104) — the sequence itself.
Output
The first and the only line of the output should contain the answer to the problem.
Examples
Input
3
-1 -2 -3
Output
6
Input
5
-4 2 0 5 0
Output
11
Input
5
-1 10 -5 10 -2
Output
18
Submitted Solution:
```
from sys import stdin
n = int(stdin.readline())
nums = [int(x) for x in stdin.readline().split()]
total = sum(nums)*-1
best = 0
left = 0
right = 0
current = 0
while right < n:
while current >= 0 and right < n:
current += nums[right]
best = max(best,current)
right += 1
while current < 0:
current -= nums[left]
left += 1
best = max(best,current)
print(total+best*2)
``` | instruction | 0 | 67,592 | 5 | 135,184 |
Yes | output | 1 | 67,592 | 5 | 135,185 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she always gives her students large and difficult homework. Despite that Valera is one of the best students, he failed to manage with the new homework. That's why he asks for your help. He has the following task. A sequence of n numbers is given. A prefix of a sequence is the part of the sequence (possibly empty), taken from the start of the sequence. A suffix of a sequence is the part of the sequence (possibly empty), taken from the end of the sequence. It is allowed to sequentially make two operations with the sequence. The first operation is to take some prefix of the sequence and multiply all numbers in this prefix by - 1. The second operation is to take some suffix and multiply all numbers in it by - 1. The chosen prefix and suffix may intersect. What is the maximum total sum of the sequence that can be obtained by applying the described operations?
Input
The first line contains integer n (1 ≤ n ≤ 105) — amount of elements in the sequence. The second line contains n integers ai ( - 104 ≤ ai ≤ 104) — the sequence itself.
Output
The first and the only line of the output should contain the answer to the problem.
Examples
Input
3
-1 -2 -3
Output
6
Input
5
-4 2 0 5 0
Output
11
Input
5
-1 10 -5 10 -2
Output
18
Submitted Solution:
```
def sumMax(S):
tStart = 0
startPos = 0
endPos = 0
somaAtual = S[0]
maxSum = S[0]
if len(S) <= 0:
return 0
else:
for i in range(1, len(S)):
somaAtual = (somaAtual + S[i])
if (S[i]) > somaAtual:
somaAtual = (S[i])
tStart = i
if somaAtual >= maxSum:
maxSum = somaAtual
startPos = tStart
endPos = i
return maxSum
def presa(x):
return x * -1
x = int(input())
opa = list(map(int,input().split()))
pre = list(map(presa,opa))
print(max(sumMax(opa), sumMax(pre)))
``` | instruction | 0 | 67,593 | 5 | 135,186 |
No | output | 1 | 67,593 | 5 | 135,187 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she always gives her students large and difficult homework. Despite that Valera is one of the best students, he failed to manage with the new homework. That's why he asks for your help. He has the following task. A sequence of n numbers is given. A prefix of a sequence is the part of the sequence (possibly empty), taken from the start of the sequence. A suffix of a sequence is the part of the sequence (possibly empty), taken from the end of the sequence. It is allowed to sequentially make two operations with the sequence. The first operation is to take some prefix of the sequence and multiply all numbers in this prefix by - 1. The second operation is to take some suffix and multiply all numbers in it by - 1. The chosen prefix and suffix may intersect. What is the maximum total sum of the sequence that can be obtained by applying the described operations?
Input
The first line contains integer n (1 ≤ n ≤ 105) — amount of elements in the sequence. The second line contains n integers ai ( - 104 ≤ ai ≤ 104) — the sequence itself.
Output
The first and the only line of the output should contain the answer to the problem.
Examples
Input
3
-1 -2 -3
Output
6
Input
5
-4 2 0 5 0
Output
11
Input
5
-1 10 -5 10 -2
Output
18
Submitted Solution:
```
n = int(input())
seq = list(map(int, input().split()))
original = [i for i in seq]
#----------------------------
# CASO 1: Direta --> Esquerda
#----------------------------
sums = []
s = sum(seq)
for i, j in enumerate(seq):
if i > 0:
sums.append(sums[i-1]+(j*-1))
else:
sums.append(s+(j*-1))
if s > max(sums):
pass
else:
ind_left_right = sums.index(max(sums))
# print(ind_left_right)
for i in range(ind_left_right+1):
seq[i] *= -1
sums = []
# s = sum(seq)
for i, j in enumerate(reversed(seq)):
if i > 0:
sums.append(sums[i-1]+(j*-1))
else:
sums.append(s+(j*-1))
if s > max(sums):
pass
else:
ind_right_left = list(reversed(sums)).index(max(sums))
for i in range(ind_right_left, len(seq)):
seq[i] *= -1
soma1 = sum(seq)
#----------------------------
# CASO 2: Esqueda --> Direita
#----------------------------
seq = original
sums = []
for i, j in enumerate(reversed(seq)):
if i > 0:
sums.append(sums[i-1]+(j*-1))
else:
sums.append(s+(j*-1))
if s > max(sums):
pass
else:
ind_right_left = list(reversed(sums)).index(max(sums))
for i in range(ind_right_left, len(seq)):
seq[i] *= -1
sums = []
s = sum(seq)
for i, j in enumerate(seq):
if i > 0:
sums.append(sums[i-1]+(j*-1))
else:
sums.append(s+(j*-1))
if s > max(sums):
pass
else:
ind_left_right = sums.index(max(sums))
# print(ind_left_right)
for i in range(ind_left_right+1):
seq[i] *= -1
soma2 = sum(seq)
print(max([soma1, soma2]))
``` | instruction | 0 | 67,594 | 5 | 135,188 |
No | output | 1 | 67,594 | 5 | 135,189 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she always gives her students large and difficult homework. Despite that Valera is one of the best students, he failed to manage with the new homework. That's why he asks for your help. He has the following task. A sequence of n numbers is given. A prefix of a sequence is the part of the sequence (possibly empty), taken from the start of the sequence. A suffix of a sequence is the part of the sequence (possibly empty), taken from the end of the sequence. It is allowed to sequentially make two operations with the sequence. The first operation is to take some prefix of the sequence and multiply all numbers in this prefix by - 1. The second operation is to take some suffix and multiply all numbers in it by - 1. The chosen prefix and suffix may intersect. What is the maximum total sum of the sequence that can be obtained by applying the described operations?
Input
The first line contains integer n (1 ≤ n ≤ 105) — amount of elements in the sequence. The second line contains n integers ai ( - 104 ≤ ai ≤ 104) — the sequence itself.
Output
The first and the only line of the output should contain the answer to the problem.
Examples
Input
3
-1 -2 -3
Output
6
Input
5
-4 2 0 5 0
Output
11
Input
5
-1 10 -5 10 -2
Output
18
Submitted Solution:
```
n = int(input())
s = input().split()
c = []
for i in range(n):
c.append(int(s[i]))
lsum= []
rsum = []
sum = 0
for i in range(n):
if(i==0):
lsum.append(c[0])
else:
lsum.append(lsum[i-1]+c[i])
for i in reversed(range(n)):
if(i==n-1):
rsum.append(c[n-1])
else:
rsum.append(lsum[i+1]+c[i])
rsum.reverse()
for i in range(n):
sum += c[i]
minval = 0
for i in reversed(range(n)):
if(i<n-1):
minval = min(min(rsum[i+1:n])+lsum[i],lsum[i],minval)
else:
minval = min(lsum[i],minval)
for i in range(n):
minval = min(rsum[i],minval)
'''lsum.sort()
rsum.sort()
print(lsum)
print(rsum)
print(sum)'''
print(max(sum-2*minval,sum))
``` | instruction | 0 | 67,595 | 5 | 135,190 |
No | output | 1 | 67,595 | 5 | 135,191 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she always gives her students large and difficult homework. Despite that Valera is one of the best students, he failed to manage with the new homework. That's why he asks for your help. He has the following task. A sequence of n numbers is given. A prefix of a sequence is the part of the sequence (possibly empty), taken from the start of the sequence. A suffix of a sequence is the part of the sequence (possibly empty), taken from the end of the sequence. It is allowed to sequentially make two operations with the sequence. The first operation is to take some prefix of the sequence and multiply all numbers in this prefix by - 1. The second operation is to take some suffix and multiply all numbers in it by - 1. The chosen prefix and suffix may intersect. What is the maximum total sum of the sequence that can be obtained by applying the described operations?
Input
The first line contains integer n (1 ≤ n ≤ 105) — amount of elements in the sequence. The second line contains n integers ai ( - 104 ≤ ai ≤ 104) — the sequence itself.
Output
The first and the only line of the output should contain the answer to the problem.
Examples
Input
3
-1 -2 -3
Output
6
Input
5
-4 2 0 5 0
Output
11
Input
5
-1 10 -5 10 -2
Output
18
Submitted Solution:
```
def maxmax(vetor,tam):
pre=list()
sux=list()
maxmaxmax=list()
prepara=1
suxpara=tam-1
maiorpre = (vetor[0]*-2) + sum(vetor)
maiorsux = (vetor[tam-1]*-2) + sum(vetor)
for i in range(len(vetor)):
pre.append(vetor[i]*(-2))
sux.append(vetor[tam-i-1]*(-2))
if maiorpre < sum(pre)+sum(vetor):
maiorpre = sum(pre)+sum(vetor)
prepara = i+1
if maiorsux < sum(sux)+sum(vetor):
maiorsux = sum(sux)+sum(vetor)
suxpara = tam-1-i
for i in range(tam):
if i < prepara:
maxmaxmax.append(vetor[i]*-1)
elif i < suxpara:
maxmaxmax.append(vetor[i])
else:
maxmaxmax.append(vetor[i]*-1)
return sum(maxmaxmax)
x = int(input())
opa = list(map(int,input().split()))
print(maxmax(opa,x))
``` | instruction | 0 | 67,596 | 5 | 135,192 |
No | output | 1 | 67,596 | 5 | 135,193 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n numbers a1, a2, ..., an. You can perform at most k operations. For each operation you can multiply one of the numbers by x. We want to make <image> as large as possible, where <image> denotes the bitwise OR.
Find the maximum possible value of <image> after performing at most k operations optimally.
Input
The first line contains three integers n, k and x (1 ≤ n ≤ 200 000, 1 ≤ k ≤ 10, 2 ≤ x ≤ 8).
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).
Output
Output the maximum value of a bitwise OR of sequence elements after performing operations.
Examples
Input
3 1 2
1 1 1
Output
3
Input
4 2 3
1 2 4 8
Output
79
Note
For the first sample, any possible choice of doing one operation will result the same three numbers 1, 1, 2 so the result is <image>.
For the second sample if we multiply 8 by 3 two times we'll get 72. In this case the numbers will become 1, 2, 4, 72 so the OR value will be 79 and is the largest possible result. | instruction | 0 | 67,691 | 5 | 135,382 |
Tags: brute force, greedy
Correct Solution:
```
n,k,x = map(int, input().split())
a = list(map(int, input().split()))
maxi = 0
moc = x**k
p = [0] * (n+2)
s = [0] * (n+2)
for i in range(1,len(a)+1):
p[i] = p[i-1] | a[i-1]
for i in range(len(a), 0, -1):
s[i] = s[i+1] | a[i-1]
for t in range(1, len(a)+1):
maxi = max(maxi, p[t-1] | (a[t-1]*moc) | s[t+1])
print(maxi)
``` | output | 1 | 67,691 | 5 | 135,383 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n numbers a1, a2, ..., an. You can perform at most k operations. For each operation you can multiply one of the numbers by x. We want to make <image> as large as possible, where <image> denotes the bitwise OR.
Find the maximum possible value of <image> after performing at most k operations optimally.
Input
The first line contains three integers n, k and x (1 ≤ n ≤ 200 000, 1 ≤ k ≤ 10, 2 ≤ x ≤ 8).
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).
Output
Output the maximum value of a bitwise OR of sequence elements after performing operations.
Examples
Input
3 1 2
1 1 1
Output
3
Input
4 2 3
1 2 4 8
Output
79
Note
For the first sample, any possible choice of doing one operation will result the same three numbers 1, 1, 2 so the result is <image>.
For the second sample if we multiply 8 by 3 two times we'll get 72. In this case the numbers will become 1, 2, 4, 72 so the OR value will be 79 and is the largest possible result. | instruction | 0 | 67,692 | 5 | 135,384 |
Tags: brute force, greedy
Correct Solution:
```
n, k, l = map(int, input().split())
li = [int(x) for x in input().split()]
front = [0]*(n+2)
back = [0]*(n+2)
front[0] = 0|li[0]
back[n-1] = 0|li[n-1]
for i in range(1,n):
front[i] = front[i-1]|li[i]
for i in range(n-2,-1,-1):
back[i] = back[i+1]|li[i]
p = 1
for _ in range(k):
p*=l
max = -1
for i in range(n):
c = front[i-1]|(li[i]*p)|back[i+1]
if c > max:
max = c
print(max)
``` | output | 1 | 67,692 | 5 | 135,385 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n numbers a1, a2, ..., an. You can perform at most k operations. For each operation you can multiply one of the numbers by x. We want to make <image> as large as possible, where <image> denotes the bitwise OR.
Find the maximum possible value of <image> after performing at most k operations optimally.
Input
The first line contains three integers n, k and x (1 ≤ n ≤ 200 000, 1 ≤ k ≤ 10, 2 ≤ x ≤ 8).
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).
Output
Output the maximum value of a bitwise OR of sequence elements after performing operations.
Examples
Input
3 1 2
1 1 1
Output
3
Input
4 2 3
1 2 4 8
Output
79
Note
For the first sample, any possible choice of doing one operation will result the same three numbers 1, 1, 2 so the result is <image>.
For the second sample if we multiply 8 by 3 two times we'll get 72. In this case the numbers will become 1, 2, 4, 72 so the OR value will be 79 and is the largest possible result. | instruction | 0 | 67,693 | 5 | 135,386 |
Tags: brute force, greedy
Correct Solution:
```
import sys
#sys.stdin = open("input.txt")
#sys.stdout = open("output.txt", "w")
n, k, x = (int(x) for x in input().split())
l = [int(x) for x in input().split()]
pref = [0] * n
suff = [0] * n
pref[0] = l[0]
for i in range(1, n):
pref[i] = pref[i - 1] | l[i]
suff[n - 1] = l[n - 1]
for i in range(n - 2, -1, -1):
suff[i] = suff[i + 1] | l[i]
def get_pref(index):
if (index < 0):
return 0
else:
return pref[index]
def get_suff(index):
if (index >= n):
return 0
else:
return suff[index]
power = x ** k
ans = 0
for i in range(n):
contender = get_pref(i - 1) | (l[i] * power) | get_suff(i + 1)
if (contender > ans):
ans = contender
print(ans)
``` | output | 1 | 67,693 | 5 | 135,387 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n numbers a1, a2, ..., an. You can perform at most k operations. For each operation you can multiply one of the numbers by x. We want to make <image> as large as possible, where <image> denotes the bitwise OR.
Find the maximum possible value of <image> after performing at most k operations optimally.
Input
The first line contains three integers n, k and x (1 ≤ n ≤ 200 000, 1 ≤ k ≤ 10, 2 ≤ x ≤ 8).
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).
Output
Output the maximum value of a bitwise OR of sequence elements after performing operations.
Examples
Input
3 1 2
1 1 1
Output
3
Input
4 2 3
1 2 4 8
Output
79
Note
For the first sample, any possible choice of doing one operation will result the same three numbers 1, 1, 2 so the result is <image>.
For the second sample if we multiply 8 by 3 two times we'll get 72. In this case the numbers will become 1, 2, 4, 72 so the OR value will be 79 and is the largest possible result. | instruction | 0 | 67,694 | 5 | 135,388 |
Tags: brute force, greedy
Correct Solution:
```
n,k,x=map(int,input().split())
l=list(map(int,input().split()))
a=[0]*n
b=[0]*n
for i in range(1,n): a[i]=a[i-1]|l[i-1]
for i in range(1,n): b[n-i-1]=b[-i]|l[-i]
nom=0
for i in range(1,n):
if l[nom]*(x**k)|a[nom]|b[nom]<l[i]*(x**k)|a[i]|b[i]: nom=i
l[nom]*=x**k
print(l[nom]|a[nom]|b[nom])
``` | output | 1 | 67,694 | 5 | 135,389 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n numbers a1, a2, ..., an. You can perform at most k operations. For each operation you can multiply one of the numbers by x. We want to make <image> as large as possible, where <image> denotes the bitwise OR.
Find the maximum possible value of <image> after performing at most k operations optimally.
Input
The first line contains three integers n, k and x (1 ≤ n ≤ 200 000, 1 ≤ k ≤ 10, 2 ≤ x ≤ 8).
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).
Output
Output the maximum value of a bitwise OR of sequence elements after performing operations.
Examples
Input
3 1 2
1 1 1
Output
3
Input
4 2 3
1 2 4 8
Output
79
Note
For the first sample, any possible choice of doing one operation will result the same three numbers 1, 1, 2 so the result is <image>.
For the second sample if we multiply 8 by 3 two times we'll get 72. In this case the numbers will become 1, 2, 4, 72 so the OR value will be 79 and is the largest possible result. | instruction | 0 | 67,695 | 5 | 135,390 |
Tags: brute force, greedy
Correct Solution:
```
n, k, x = map(int, input().split())
a = list(map(int, input().split()))
L = [0] * (n + 1)
R = [0] * (n + 1)
for i in range(1, n + 1):
L[i] = a[i - 1] | L[i - 1]
for i in range(n - 1, -1, -1):
R[i] = a[i] | R[i + 1]
ans = max(L[i] | (a[i] * x ** k) | R[i + 1] for i in range(n))
print(ans)
``` | output | 1 | 67,695 | 5 | 135,391 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n numbers a1, a2, ..., an. You can perform at most k operations. For each operation you can multiply one of the numbers by x. We want to make <image> as large as possible, where <image> denotes the bitwise OR.
Find the maximum possible value of <image> after performing at most k operations optimally.
Input
The first line contains three integers n, k and x (1 ≤ n ≤ 200 000, 1 ≤ k ≤ 10, 2 ≤ x ≤ 8).
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).
Output
Output the maximum value of a bitwise OR of sequence elements after performing operations.
Examples
Input
3 1 2
1 1 1
Output
3
Input
4 2 3
1 2 4 8
Output
79
Note
For the first sample, any possible choice of doing one operation will result the same three numbers 1, 1, 2 so the result is <image>.
For the second sample if we multiply 8 by 3 two times we'll get 72. In this case the numbers will become 1, 2, 4, 72 so the OR value will be 79 and is the largest possible result. | instruction | 0 | 67,696 | 5 | 135,392 |
Tags: brute force, greedy
Correct Solution:
```
n, k, x = map(int, input().split())
A = list(map(int, input().split()))
L, R = [0]*(n+1), [0]*(n+1)
for i in range(n):
L[i+1] = A[i] | L[i]
for i in range(n-1, -1, -1):
R[i] = A[i] | R[i+1]
x = x**k
ans = 0
for i in range(n):
ans = max(ans, L[i] | (A[i]*x) | R[i+1])
print(ans)
``` | output | 1 | 67,696 | 5 | 135,393 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n numbers a1, a2, ..., an. You can perform at most k operations. For each operation you can multiply one of the numbers by x. We want to make <image> as large as possible, where <image> denotes the bitwise OR.
Find the maximum possible value of <image> after performing at most k operations optimally.
Input
The first line contains three integers n, k and x (1 ≤ n ≤ 200 000, 1 ≤ k ≤ 10, 2 ≤ x ≤ 8).
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).
Output
Output the maximum value of a bitwise OR of sequence elements after performing operations.
Examples
Input
3 1 2
1 1 1
Output
3
Input
4 2 3
1 2 4 8
Output
79
Note
For the first sample, any possible choice of doing one operation will result the same three numbers 1, 1, 2 so the result is <image>.
For the second sample if we multiply 8 by 3 two times we'll get 72. In this case the numbers will become 1, 2, 4, 72 so the OR value will be 79 and is the largest possible result.
Submitted Solution:
```
n,k,x=map(int,input().split())
l=list(map(int,input().split()))
for j in range(k):
nom=0
for i in range(n):
if l[nom]*x<l[i]*x: nom=i
l[nom]*=x
s=0
for x in l: s|=x
print(s)
``` | instruction | 0 | 67,697 | 5 | 135,394 |
No | output | 1 | 67,697 | 5 | 135,395 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n numbers a1, a2, ..., an. You can perform at most k operations. For each operation you can multiply one of the numbers by x. We want to make <image> as large as possible, where <image> denotes the bitwise OR.
Find the maximum possible value of <image> after performing at most k operations optimally.
Input
The first line contains three integers n, k and x (1 ≤ n ≤ 200 000, 1 ≤ k ≤ 10, 2 ≤ x ≤ 8).
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).
Output
Output the maximum value of a bitwise OR of sequence elements after performing operations.
Examples
Input
3 1 2
1 1 1
Output
3
Input
4 2 3
1 2 4 8
Output
79
Note
For the first sample, any possible choice of doing one operation will result the same three numbers 1, 1, 2 so the result is <image>.
For the second sample if we multiply 8 by 3 two times we'll get 72. In this case the numbers will become 1, 2, 4, 72 so the OR value will be 79 and is the largest possible result.
Submitted Solution:
```
n, k, x = map(int, input().split())
x **= k
prefix = [0] * n
sufix = [0] * n
arr = list(map(int, input().split()))
for i, val in enumerate(arr):
prefix[i] = prefix[i - 1] | val
arr.reverse()
sufix[0] = arr[0]
for i, val in enumerate(arr):
sufix[i] = sufix[i - 1] | val
arr.reverse()
ans = max((arr[0] * x) | sufix[n-1], (arr[n-1] * x) | prefix[n-2] )
for i in range(1, n-1):
ans = max(ans, prefix[i - 1] | sufix[n - i - 1] | (arr[i] * x))
print(ans)
``` | instruction | 0 | 67,698 | 5 | 135,396 |
No | output | 1 | 67,698 | 5 | 135,397 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n numbers a1, a2, ..., an. You can perform at most k operations. For each operation you can multiply one of the numbers by x. We want to make <image> as large as possible, where <image> denotes the bitwise OR.
Find the maximum possible value of <image> after performing at most k operations optimally.
Input
The first line contains three integers n, k and x (1 ≤ n ≤ 200 000, 1 ≤ k ≤ 10, 2 ≤ x ≤ 8).
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).
Output
Output the maximum value of a bitwise OR of sequence elements after performing operations.
Examples
Input
3 1 2
1 1 1
Output
3
Input
4 2 3
1 2 4 8
Output
79
Note
For the first sample, any possible choice of doing one operation will result the same three numbers 1, 1, 2 so the result is <image>.
For the second sample if we multiply 8 by 3 two times we'll get 72. In this case the numbers will become 1, 2, 4, 72 so the OR value will be 79 and is the largest possible result.
Submitted Solution:
```
n, k, x = map(int, input().split())
x **= k
prefix = [0] * n
sufix = [0] * n
arr = list(map(int, input().split()))
prefix[0] = arr[0]
for i, val in enumerate(arr):
prefix[i] = prefix[i - 1] | val
arr.reverse()
sufix[0] = arr[0]
for i, val in enumerate(arr):
sufix[i] = sufix[i - 1] | val
ans = -1e9
arr.reverse()
for i in range(n):
ans = max(ans, prefix[i - 1] | sufix[n - i - 1] | (arr[i] * x))
print(ans)
``` | instruction | 0 | 67,699 | 5 | 135,398 |
No | output | 1 | 67,699 | 5 | 135,399 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n numbers a1, a2, ..., an. You can perform at most k operations. For each operation you can multiply one of the numbers by x. We want to make <image> as large as possible, where <image> denotes the bitwise OR.
Find the maximum possible value of <image> after performing at most k operations optimally.
Input
The first line contains three integers n, k and x (1 ≤ n ≤ 200 000, 1 ≤ k ≤ 10, 2 ≤ x ≤ 8).
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).
Output
Output the maximum value of a bitwise OR of sequence elements after performing operations.
Examples
Input
3 1 2
1 1 1
Output
3
Input
4 2 3
1 2 4 8
Output
79
Note
For the first sample, any possible choice of doing one operation will result the same three numbers 1, 1, 2 so the result is <image>.
For the second sample if we multiply 8 by 3 two times we'll get 72. In this case the numbers will become 1, 2, 4, 72 so the OR value will be 79 and is the largest possible result.
Submitted Solution:
```
n,k,x=map(int,input().split())
l=list(map(int,input().split()))
a=[0]*n
b=[0]*n
for i in range(1,n): a[i]=a[i-1]|l[i-1]
for i in range(1,n): b[n-i-1]=b[-i]|l[-i]
print(a)
print(b)
nom=0
for i in range(1,n):
if (l[nom]*(x**k))|a[i]|b[i]<(l[i]*(x**k))|a[i]|b[i]: nom=i
l[nom]*=x**k
print(l[nom]|a[nom]|b[nom])
``` | instruction | 0 | 67,700 | 5 | 135,400 |
No | output | 1 | 67,700 | 5 | 135,401 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are well-known formulas: <image>, <image>, <image>. Also mathematicians found similar formulas for higher degrees.
Find the value of the sum <image> modulo 109 + 7 (so you should find the remainder after dividing the answer by the value 109 + 7).
Input
The only line contains two integers n, k (1 ≤ n ≤ 109, 0 ≤ k ≤ 106).
Output
Print the only integer a — the remainder after dividing the value of the sum by the value 109 + 7.
Examples
Input
4 1
Output
10
Input
4 2
Output
30
Input
4 3
Output
100
Input
4 0
Output
4
Submitted Solution:
```
a,b=map(int,input().split())
s=0
for i in range(a+1):
s=s+pow(i,b)
print(s)
``` | instruction | 0 | 67,720 | 5 | 135,440 |
No | output | 1 | 67,720 | 5 | 135,441 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are well-known formulas: <image>, <image>, <image>. Also mathematicians found similar formulas for higher degrees.
Find the value of the sum <image> modulo 109 + 7 (so you should find the remainder after dividing the answer by the value 109 + 7).
Input
The only line contains two integers n, k (1 ≤ n ≤ 109, 0 ≤ k ≤ 106).
Output
Print the only integer a — the remainder after dividing the value of the sum by the value 109 + 7.
Examples
Input
4 1
Output
10
Input
4 2
Output
30
Input
4 3
Output
100
Input
4 0
Output
4
Submitted Solution:
```
n, k = input().split()
n=int(n)
k=int(k)
s=0
s=int(s)
if k ==0:
s=n
elif k==1:
s=int((n*(n+1))/2)
elif k==2:
s=int((n*(2*n+1)*(n+1))/6)
elif k==3:
s=int(pow((n*(n+1))/2,2))
else:
for i in range(1,n+1):
s=s+pow(i,k)
print(i)
s=s%(pow(10,9)+7)
print(s)
``` | instruction | 0 | 67,721 | 5 | 135,442 |
No | output | 1 | 67,721 | 5 | 135,443 |
Provide a correct Python 3 solution for this coding contest problem.
Compute A \times B, truncate its fractional part, and print the result as an integer.
Constraints
* 0 \leq A \leq 10^{15}
* 0 \leq B < 10
* A is an integer.
* B is a number with two digits after the decimal point.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the answer as an integer.
Examples
Input
198 1.10
Output
217
Input
1 0.01
Output
0
Input
1000000000000000 9.99
Output
9990000000000000 | instruction | 0 | 67,894 | 5 | 135,788 |
"Correct Solution:
```
a, b = map(float, input().split())
print(round(a) * round(b*100) // 100)
``` | output | 1 | 67,894 | 5 | 135,789 |
Provide a correct Python 3 solution for this coding contest problem.
Compute A \times B, truncate its fractional part, and print the result as an integer.
Constraints
* 0 \leq A \leq 10^{15}
* 0 \leq B < 10
* A is an integer.
* B is a number with two digits after the decimal point.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the answer as an integer.
Examples
Input
198 1.10
Output
217
Input
1 0.01
Output
0
Input
1000000000000000 9.99
Output
9990000000000000 | instruction | 0 | 67,895 | 5 | 135,790 |
"Correct Solution:
```
A, B = input().split()
print(int((int(A)*int(float(B)*1000))//1000))
``` | output | 1 | 67,895 | 5 | 135,791 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.