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.
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None | instruction | 0 | 9,820 | 5 | 19,640 |
"Correct Solution:
```
while True:
n,k = map(int,input().split())
if n==0 and k==0:
break
a = [int(input()) for i in range(n)]
b = 0
s = [0]*(n+1)
for i in range(n):
s[i+1]=s[i]+a[i]
for i in range(n-k+1):
tmp = s[k+i]-s[i]
if tmp>b:
b = tmp
print(b)
``` | output | 1 | 9,820 | 5 | 19,641 |
Provide a correct Python 3 solution for this coding contest problem.
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None | instruction | 0 | 9,821 | 5 | 19,642 |
"Correct Solution:
```
import itertools
while True:
N, K = map(int, input().split())
if N==K==0:
break
S = [int(input()) for _ in range(N)]
Scum = [0] + list(itertools.accumulate(S))
reg = -10**9
for i in range(N-K+1):
partial_sum = Scum[i+K] - Scum[i]
reg = max(reg, partial_sum)
print(reg)
``` | output | 1 | 9,821 | 5 | 19,643 |
Provide a correct Python 3 solution for this coding contest problem.
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None | instruction | 0 | 9,822 | 5 | 19,644 |
"Correct Solution:
```
import queue
while 1:
n,k=map(int,input().split())
if n==0:break
a=queue.deque(int(input()) for _ in range(k))
m=b=sum(a)
for i in range(n-k):
c=a.popleft()
d=int(input())
a.append(d)
b+=d-c
m=max(b,m)
print(m)
``` | output | 1 | 9,822 | 5 | 19,645 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
Submitted Solution:
```
from queue import deque
while True:
n, k = map(int, input().split())
if not n:
break
q = deque(int(input()) for _ in range(k))
ans = cur = sum(q)
for _ in range(n - k):
new = int(input())
q.append(new)
old = q.popleft()
cur += new - old
ans = ans if ans > cur else cur
print(ans)
``` | instruction | 0 | 9,823 | 5 | 19,646 |
Yes | output | 1 | 9,823 | 5 | 19,647 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
Submitted Solution:
```
def solve():
while 1:
n, k = [int(_) for _ in input().split()]
if n == 0: return
A = [int(input()) for _ in range(n)]
s = [0] * (len(A) + 1)
for i in range(n):
s[i + 1] = s[i] + A[i]
ans = -1
for l in range(n):
r = l + k
if r > n: break
ans = max(ans, s[r] - s[l])
print(ans)
if __name__ == '__main__':
solve()
``` | instruction | 0 | 9,824 | 5 | 19,648 |
Yes | output | 1 | 9,824 | 5 | 19,649 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
Submitted Solution:
```
for v in range(5):
n, k = map(int, input().split())
if n == 0 and k == 0:
break
a = [int(input()) for i in range(n)]
sum = []
s = [0] * (n+1)
for i in range(n):
s[i+1] = s[i] + a[i]
for i in range(n-k):
sum.append(s[i+k] - s[i])
print(max(sum))
``` | instruction | 0 | 9,825 | 5 | 19,650 |
Yes | output | 1 | 9,825 | 5 | 19,651 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
Submitted Solution:
```
a, s = [0]*100003, [0]*100003
while True:
n, k = map(int, input().split())
if n == 0: break
s[0] = a[0] = int(input())
for i in range(1, n):
a[i] = int(input())
s[i] = s[i-1] + a[i]
if i >= k: s[i] -= a[i-k]
ans = s[k-1]
for i in range(k, n):
if s[i] > ans: ans = s[i]
print(ans)
``` | instruction | 0 | 9,826 | 5 | 19,652 |
Yes | output | 1 | 9,826 | 5 | 19,653 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
Submitted Solution:
```
n,k = map(int,input().split())
a = [int(input()) for i in range(n)]
unko = [0]
for i in range(n):
unko.append(unko[i]+a[i])
Inf = float("inf")*(-1)
mvl = Inf
for i in range(n-k+1):
if unko[i+k]-unko[i] >= mvl:
mvl = unko[i+k]-unko[i]
print(mvl)
``` | instruction | 0 | 9,827 | 5 | 19,654 |
No | output | 1 | 9,827 | 5 | 19,655 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
Submitted Solution:
```
def func(n,k):
A = []
ans = 0
SUM = 0
for i in range(n):
A.append(int(input()))
for i in range(k-1):
SUM += A[i]
for i in range(k,len(a)):
ans = max(ans,SUM+a[i]-a[i-k])
print(ans)
for i in range(100):
n,k = [int(s) for s in input().split()]
if n == 0 and k ==0:
break
else:
func(n,k)
``` | instruction | 0 | 9,828 | 5 | 19,656 |
No | output | 1 | 9,828 | 5 | 19,657 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
Submitted Solution:
```
from itertools import accumulate
# 区間[N-k, N) の総和の最大値
n, k = map(int, input().split(" "))
a_n = [int(input()) for _ in range(n)]
_ = input()
a_n = list(accumulate(a_n))
# print(a_n)
result = -99999999999999
for i in range(n-k):
val = a_n[k+i] - a_n[i]
if result < val:
result = val
print(result)
``` | instruction | 0 | 9,829 | 5 | 19,658 |
No | output | 1 | 9,829 | 5 | 19,659 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
Submitted Solution:
```
def func(n,k):
SUM = 0
ans = 0
A = [int(input()) for _ in range(n)]
for i in range(k-1):
SUM += A[i]
for i in range(k,len(A)):
ans = max(ans,SUM+A[i]-A[i-k])
SUM = SUM+A[i]-A[i-k]
print(ans)
for _ in range(10)
n,k = [int(s) for s in input().split()]
if n == 0 and k ==0:
break
else:
func(n,k)
``` | instruction | 0 | 9,830 | 5 | 19,660 |
No | output | 1 | 9,830 | 5 | 19,661 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers a and b. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by 1; during the second operation you choose one of these numbers and increase it by 2, and so on. You choose the number of these operations yourself.
For example, if a = 1 and b = 3, you can perform the following sequence of three operations:
1. add 1 to a, then a = 2 and b = 3;
2. add 2 to b, then a = 2 and b = 5;
3. add 3 to a, then a = 5 and b = 5.
Calculate the minimum number of operations required to make a and b equal.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The only line of each test case contains two integers a and b (1 ≤ a, b ≤ 10^9).
Output
For each test case print one integer — the minimum numbers of operations required to make a and b equal.
Example
Input
3
1 3
11 11
30 20
Output
3
0
4
Note
First test case considered in the statement.
In the second test case integers a and b are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to b (b turns into 20 + 1 + 2 + 3 + 4 = 30). | instruction | 0 | 10,059 | 5 | 20,118 |
Tags: greedy, math
Correct Solution:
```
l=[]
curr=0
while(1):
x=(curr*(curr+1))//2
if(x>10**10):
break
l.append(x)
curr+=1
t=int(input())
for you in range(t):
lo=input().split()
a=int(lo[0])
b=int(lo[1])
diff=max(a,b)-min(a,b)
for i in range(len(l)):
if(l[i]>=diff and (l[i]-diff)%2==0):
ans=i
break
print(ans)
``` | output | 1 | 10,059 | 5 | 20,119 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers a and b. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by 1; during the second operation you choose one of these numbers and increase it by 2, and so on. You choose the number of these operations yourself.
For example, if a = 1 and b = 3, you can perform the following sequence of three operations:
1. add 1 to a, then a = 2 and b = 3;
2. add 2 to b, then a = 2 and b = 5;
3. add 3 to a, then a = 5 and b = 5.
Calculate the minimum number of operations required to make a and b equal.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The only line of each test case contains two integers a and b (1 ≤ a, b ≤ 10^9).
Output
For each test case print one integer — the minimum numbers of operations required to make a and b equal.
Example
Input
3
1 3
11 11
30 20
Output
3
0
4
Note
First test case considered in the statement.
In the second test case integers a and b are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to b (b turns into 20 + 1 + 2 + 3 + 4 = 30). | instruction | 0 | 10,060 | 5 | 20,120 |
Tags: greedy, math
Correct Solution:
```
for tc in range(int(input())):
a,b=map(int,input().split())
d=abs(a-b)
tt=int((2*d)**0.5)
if a==b:
print(0)
elif abs(a-b)==1:
print(1)
elif 2*d==tt**2+tt:
print(tt)
elif abs(a-b)>1:
i=tt
while i<d+d:
t=(i*(i+1))//2
if t>d:
#print(t,d)
if (t+d)%2==0:
#print(t+d)
print(i)
break
i+=1
``` | output | 1 | 10,060 | 5 | 20,121 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers a and b. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by 1; during the second operation you choose one of these numbers and increase it by 2, and so on. You choose the number of these operations yourself.
For example, if a = 1 and b = 3, you can perform the following sequence of three operations:
1. add 1 to a, then a = 2 and b = 3;
2. add 2 to b, then a = 2 and b = 5;
3. add 3 to a, then a = 5 and b = 5.
Calculate the minimum number of operations required to make a and b equal.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The only line of each test case contains two integers a and b (1 ≤ a, b ≤ 10^9).
Output
For each test case print one integer — the minimum numbers of operations required to make a and b equal.
Example
Input
3
1 3
11 11
30 20
Output
3
0
4
Note
First test case considered in the statement.
In the second test case integers a and b are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to b (b turns into 20 + 1 + 2 + 3 + 4 = 30). | instruction | 0 | 10,061 | 5 | 20,122 |
Tags: greedy, math
Correct Solution:
```
# -*- coding: utf-8 -*-
# @Author: patan
# @Date: 2019-12-19 19:55:11
# @Last Modified by: patan
# @Last Modified time: 2019-12-19 22:03:48
import math
t=int(input())
for i in range(t):
a,b = list(map(int,input().split()))
x = abs(a-b)
diff = x
x = math.sqrt(1+(8*x))-1
if(x%2!=0):
x=(int(x)//2)+1
else:
x=(int(x)//2)
# print(x)
# x = math.ceil(x/2)
val = (x*(x+1))//2
# print(val)
if(val%2!=0 and diff%2==0):
y1=x+1
val1 = (y1*(y1+1))//2
y2=x+2
val2 = (y2*(y2+1))//2
if(val1%2==0):
x=y1
else:
x=y2
if(val%2==0 and diff%2!=0):
y1=x+1
val1 = (y1*(y1+1))//2
y2=x+2
val2 = (y2*(y2+1))//2
if(val1%2!=0):
x=y1
else:
x=y2
print(int(x))
``` | output | 1 | 10,061 | 5 | 20,123 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers a and b. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by 1; during the second operation you choose one of these numbers and increase it by 2, and so on. You choose the number of these operations yourself.
For example, if a = 1 and b = 3, you can perform the following sequence of three operations:
1. add 1 to a, then a = 2 and b = 3;
2. add 2 to b, then a = 2 and b = 5;
3. add 3 to a, then a = 5 and b = 5.
Calculate the minimum number of operations required to make a and b equal.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The only line of each test case contains two integers a and b (1 ≤ a, b ≤ 10^9).
Output
For each test case print one integer — the minimum numbers of operations required to make a and b equal.
Example
Input
3
1 3
11 11
30 20
Output
3
0
4
Note
First test case considered in the statement.
In the second test case integers a and b are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to b (b turns into 20 + 1 + 2 + 3 + 4 = 30). | instruction | 0 | 10,064 | 5 | 20,128 |
Tags: greedy, math
Correct Solution:
```
import math
t=int(input())
l=[]
for i in range(50000):
l.append((i*(i+1))//2)
while t:
a,b=map(int,input().split())
a1=max(a,b)
b1=min(a,b)
a1=a1-b1
for i in range(50000):
if l[i]==a1:
ans=i
break
elif l[i]>a1:
if (l[i]%2==0 and a1%2==0):
ans=i
break
if (l[i]%2!=0 and a1%2!=0):
ans=i
break
print(ans)
t-=1
``` | output | 1 | 10,064 | 5 | 20,129 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers a and b. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by 1; during the second operation you choose one of these numbers and increase it by 2, and so on. You choose the number of these operations yourself.
For example, if a = 1 and b = 3, you can perform the following sequence of three operations:
1. add 1 to a, then a = 2 and b = 3;
2. add 2 to b, then a = 2 and b = 5;
3. add 3 to a, then a = 5 and b = 5.
Calculate the minimum number of operations required to make a and b equal.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The only line of each test case contains two integers a and b (1 ≤ a, b ≤ 10^9).
Output
For each test case print one integer — the minimum numbers of operations required to make a and b equal.
Example
Input
3
1 3
11 11
30 20
Output
3
0
4
Note
First test case considered in the statement.
In the second test case integers a and b are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to b (b turns into 20 + 1 + 2 + 3 + 4 = 30). | instruction | 0 | 10,065 | 5 | 20,130 |
Tags: greedy, math
Correct Solution:
```
for _ in range(int(input())):
a,b=map(int,input().split())
aa,bb=min(a,b),max(a,b)
c=bb-aa
i=0
ans=0
if c==0:print(0)
else:
while 1:
i+=1
ans+=i
if ans>=c and (ans-c)%2==0:
print(i);break
``` | output | 1 | 10,065 | 5 | 20,131 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers a and b. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by 1; during the second operation you choose one of these numbers and increase it by 2, and so on. You choose the number of these operations yourself.
For example, if a = 1 and b = 3, you can perform the following sequence of three operations:
1. add 1 to a, then a = 2 and b = 3;
2. add 2 to b, then a = 2 and b = 5;
3. add 3 to a, then a = 5 and b = 5.
Calculate the minimum number of operations required to make a and b equal.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The only line of each test case contains two integers a and b (1 ≤ a, b ≤ 10^9).
Output
For each test case print one integer — the minimum numbers of operations required to make a and b equal.
Example
Input
3
1 3
11 11
30 20
Output
3
0
4
Note
First test case considered in the statement.
In the second test case integers a and b are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to b (b turns into 20 + 1 + 2 + 3 + 4 = 30).
Submitted Solution:
```
t=int(input())
for i in range(t):
a,b=map(int,input().split())
m=abs(a-b)
n=int((m*2)**(1/2))
while n*(n+1)/2<m or (n*(n+1)/2-m)%2==1:
n+=1
print(n)
``` | instruction | 0 | 10,067 | 5 | 20,134 |
Yes | output | 1 | 10,067 | 5 | 20,135 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers a and b. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by 1; during the second operation you choose one of these numbers and increase it by 2, and so on. You choose the number of these operations yourself.
For example, if a = 1 and b = 3, you can perform the following sequence of three operations:
1. add 1 to a, then a = 2 and b = 3;
2. add 2 to b, then a = 2 and b = 5;
3. add 3 to a, then a = 5 and b = 5.
Calculate the minimum number of operations required to make a and b equal.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The only line of each test case contains two integers a and b (1 ≤ a, b ≤ 10^9).
Output
For each test case print one integer — the minimum numbers of operations required to make a and b equal.
Example
Input
3
1 3
11 11
30 20
Output
3
0
4
Note
First test case considered in the statement.
In the second test case integers a and b are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to b (b turns into 20 + 1 + 2 + 3 + 4 = 30).
Submitted Solution:
```
v=[0]
for i in range (1,10**5):
v.append(v[-1]+i)
c=int(input())
for casos in range (c):
a,b=map(int,input().split())
sw=0
if a==b:
print(0)
elif a<b:
while sw==0:
l=a+b
for i in range (len(v)):
p=(l+v[i])
if p%2==0:
p=p//2
if p>=a and p>=b:
print(i)
sw=1
break
else:
while sw==0:
l=a+b
for i in range (len(v)):
p=(l+v[i])
if p%2==0:
p=p//2
if p>=a and p>=b:
print(i)
sw=1
break
``` | instruction | 0 | 10,068 | 5 | 20,136 |
Yes | output | 1 | 10,068 | 5 | 20,137 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers a and b. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by 1; during the second operation you choose one of these numbers and increase it by 2, and so on. You choose the number of these operations yourself.
For example, if a = 1 and b = 3, you can perform the following sequence of three operations:
1. add 1 to a, then a = 2 and b = 3;
2. add 2 to b, then a = 2 and b = 5;
3. add 3 to a, then a = 5 and b = 5.
Calculate the minimum number of operations required to make a and b equal.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The only line of each test case contains two integers a and b (1 ≤ a, b ≤ 10^9).
Output
For each test case print one integer — the minimum numbers of operations required to make a and b equal.
Example
Input
3
1 3
11 11
30 20
Output
3
0
4
Note
First test case considered in the statement.
In the second test case integers a and b are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to b (b turns into 20 + 1 + 2 + 3 + 4 = 30).
Submitted Solution:
```
from math import sqrt
t=int(input())
for _ in range(t):
a,b=map(int,input().split())
d=b-a
n=0
while(1):
#print(n,(n**2+n+2*a-2*b)//4,n*(n+1)/2)
if (n**2+n+2*a-2*b)%4==0 and (n**2+n+2*a-2*b)//4>=0 and (n**2+n+2*a-2*b)//4<=n*(n+1)//2:
print(n)
break
#print(str(n)+"***")
n+=1
``` | instruction | 0 | 10,069 | 5 | 20,138 |
Yes | output | 1 | 10,069 | 5 | 20,139 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers a and b. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by 1; during the second operation you choose one of these numbers and increase it by 2, and so on. You choose the number of these operations yourself.
For example, if a = 1 and b = 3, you can perform the following sequence of three operations:
1. add 1 to a, then a = 2 and b = 3;
2. add 2 to b, then a = 2 and b = 5;
3. add 3 to a, then a = 5 and b = 5.
Calculate the minimum number of operations required to make a and b equal.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The only line of each test case contains two integers a and b (1 ≤ a, b ≤ 10^9).
Output
For each test case print one integer — the minimum numbers of operations required to make a and b equal.
Example
Input
3
1 3
11 11
30 20
Output
3
0
4
Note
First test case considered in the statement.
In the second test case integers a and b are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to b (b turns into 20 + 1 + 2 + 3 + 4 = 30).
Submitted Solution:
```
for _ in range(int(input())):
a,b = map(int,input().split())
diff = abs(a-b)
sums = 0
ans = 0
while sums < diff or sums%2 != diff%2 :
ans+=1
sums+=ans
print(ans)
``` | instruction | 0 | 10,070 | 5 | 20,140 |
Yes | output | 1 | 10,070 | 5 | 20,141 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers a and b. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by 1; during the second operation you choose one of these numbers and increase it by 2, and so on. You choose the number of these operations yourself.
For example, if a = 1 and b = 3, you can perform the following sequence of three operations:
1. add 1 to a, then a = 2 and b = 3;
2. add 2 to b, then a = 2 and b = 5;
3. add 3 to a, then a = 5 and b = 5.
Calculate the minimum number of operations required to make a and b equal.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The only line of each test case contains two integers a and b (1 ≤ a, b ≤ 10^9).
Output
For each test case print one integer — the minimum numbers of operations required to make a and b equal.
Example
Input
3
1 3
11 11
30 20
Output
3
0
4
Note
First test case considered in the statement.
In the second test case integers a and b are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to b (b turns into 20 + 1 + 2 + 3 + 4 = 30).
Submitted Solution:
```
from sys import stdin,stdout,setrecursionlimit
stdin.readline
def mp(): return list(map(int, stdin.readline().strip().split()))
def it():return int(stdin.readline().strip())
from collections import defaultdict as dd,Counter as C,deque
from math import ceil,gcd,sqrt,factorial,log2,floor
from bisect import bisect_right as br,bisect_left as bl
import heapq
def solve(a,b):
if a == b:
return 0
if a > b:
a,b = b,a
i = 1
ans = 0
while(ans < b-a):
ans = (i*(i+1))//2
i += 1
if (ans+a==b):
return i-1
if (b-a)&1 and ans&1:
return i-1
while ans&1:
ans += i
i += 1
return i-1
for _ in range(it()):
a,b = mp()
print(solve(a,b))
``` | instruction | 0 | 10,071 | 5 | 20,142 |
No | output | 1 | 10,071 | 5 | 20,143 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers a and b. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by 1; during the second operation you choose one of these numbers and increase it by 2, and so on. You choose the number of these operations yourself.
For example, if a = 1 and b = 3, you can perform the following sequence of three operations:
1. add 1 to a, then a = 2 and b = 3;
2. add 2 to b, then a = 2 and b = 5;
3. add 3 to a, then a = 5 and b = 5.
Calculate the minimum number of operations required to make a and b equal.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The only line of each test case contains two integers a and b (1 ≤ a, b ≤ 10^9).
Output
For each test case print one integer — the minimum numbers of operations required to make a and b equal.
Example
Input
3
1 3
11 11
30 20
Output
3
0
4
Note
First test case considered in the statement.
In the second test case integers a and b are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to b (b turns into 20 + 1 + 2 + 3 + 4 = 30).
Submitted Solution:
```
N = int(input())
for i in range(N):
a, b = map(int, input().split())
count = 0
while a != b:
count += 1
if abs(a - b) >= count:
if (a < b):
a += count
else:
b += count
else:
if (a > b):
a += count
else:
b += count
print(count)
``` | instruction | 0 | 10,072 | 5 | 20,144 |
No | output | 1 | 10,072 | 5 | 20,145 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers a and b. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by 1; during the second operation you choose one of these numbers and increase it by 2, and so on. You choose the number of these operations yourself.
For example, if a = 1 and b = 3, you can perform the following sequence of three operations:
1. add 1 to a, then a = 2 and b = 3;
2. add 2 to b, then a = 2 and b = 5;
3. add 3 to a, then a = 5 and b = 5.
Calculate the minimum number of operations required to make a and b equal.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The only line of each test case contains two integers a and b (1 ≤ a, b ≤ 10^9).
Output
For each test case print one integer — the minimum numbers of operations required to make a and b equal.
Example
Input
3
1 3
11 11
30 20
Output
3
0
4
Note
First test case considered in the statement.
In the second test case integers a and b are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to b (b turns into 20 + 1 + 2 + 3 + 4 = 30).
Submitted Solution:
```
from sys import stdin,stdout,setrecursionlimit
stdin.readline
def mp(): return list(map(int, stdin.readline().strip().split()))
def it():return int(stdin.readline().strip())
from collections import defaultdict as dd,Counter as C,deque
from math import ceil,gcd,sqrt,factorial,log2,floor
from bisect import bisect_right as br,bisect_left as bl
import heapq
def solve(a,b):
if a == b:
return 0
if a > b:
a,b = b,a
i = 1
while(b-a >= i):
a += i
i += 1
if (a==b):
return i-1
ans = 0
i = 1
while ans < b:
ans = (i*(i+1))//2
i += 1
if a&1 and ans&1:
return i-1
while ans&1:
ans += i
i += 1
return i-1
for _ in range(it()):
a,b = mp()
print(solve(a,b))
``` | instruction | 0 | 10,073 | 5 | 20,146 |
No | output | 1 | 10,073 | 5 | 20,147 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers a and b. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by 1; during the second operation you choose one of these numbers and increase it by 2, and so on. You choose the number of these operations yourself.
For example, if a = 1 and b = 3, you can perform the following sequence of three operations:
1. add 1 to a, then a = 2 and b = 3;
2. add 2 to b, then a = 2 and b = 5;
3. add 3 to a, then a = 5 and b = 5.
Calculate the minimum number of operations required to make a and b equal.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The only line of each test case contains two integers a and b (1 ≤ a, b ≤ 10^9).
Output
For each test case print one integer — the minimum numbers of operations required to make a and b equal.
Example
Input
3
1 3
11 11
30 20
Output
3
0
4
Note
First test case considered in the statement.
In the second test case integers a and b are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to b (b turns into 20 + 1 + 2 + 3 + 4 = 30).
Submitted Solution:
```
def bin(x):
l = 0
r = 1000000000
while l + 1 < r:
m = (l + r) // 2
tc = m * 4
if (tc + 1) * (tc // 2) >= x:
r = m
else:
l = m
return m * 4
def bin1(x):
l = 1
r = 1000000000
while l + 1 < r:
m = (l + r) // 2 + (l + r) % 2
tc = m * 2
if (tc + 1) * (tc // 2) >= x:
r = m
else:
l = m
return m * 2
for i in range(int(input())):
x, y = map(int, input().split())
if x == y:
print(0)
continue
x, y = min(x, y), max(x, y)
d = y - x
if d % 2 == 0:
k = bin(d)
kk = k - 1
if (kk + 1) * (kk // 2) + (kk - 1) // 2>= d:
print(kk)
else:
print(k)
else:
k = bin1(d)
if k // 2 % 2 == 1:
kk = k - 1
if (kk + 1) * (kk // 2) + (kk - 1) // 2>= d:
print(kk)
else:
print(k)
else:
kk = k - 2
if (kk + 1) * (kk // 2) + (kk - 1) // 2 >= d:
kkk = kk - 1
if (kkk + 1) * (kk // 2) + kkk // 2 + 1 >= d:
print(kkk)
else:
print(kk)
else:
print(k + 1)
``` | instruction | 0 | 10,074 | 5 | 20,148 |
No | output | 1 | 10,074 | 5 | 20,149 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Professor GukiZ was playing with arrays again and accidentally discovered new function, which he called GukiZiana. For given array a, indexed with integers from 1 to n, and number y, GukiZiana(a, y) represents maximum value of j - i, such that aj = ai = y. If there is no y as an element in a, then GukiZiana(a, y) is equal to - 1. GukiZ also prepared a problem for you. This time, you have two types of queries:
1. First type has form 1 l r x and asks you to increase values of all ai such that l ≤ i ≤ r by the non-negative integer x.
2. Second type has form 2 y and asks you to find value of GukiZiana(a, y).
For each query of type 2, print the answer and make GukiZ happy!
Input
The first line contains two integers n, q (1 ≤ n ≤ 5 * 105, 1 ≤ q ≤ 5 * 104), size of array a, and the number of queries.
The second line contains n integers a1, a2, ... an (1 ≤ ai ≤ 109), forming an array a.
Each of next q lines contain either four or two numbers, as described in statement:
If line starts with 1, then the query looks like 1 l r x (1 ≤ l ≤ r ≤ n, 0 ≤ x ≤ 109), first type query.
If line starts with 2, then th query looks like 2 y (1 ≤ y ≤ 109), second type query.
Output
For each query of type 2, print the value of GukiZiana(a, y), for y value for that query.
Examples
Input
4 3
1 2 3 4
1 1 2 1
1 1 1 1
2 3
Output
2
Input
2 3
1 2
1 2 2 1
2 3
2 4
Output
0
-1
Submitted Solution:
```
from collections import defaultdict
SQRT = 800
#Unrolled Linked List
class sqrt_table():
def __init__(self, numbers):
self.numbers = numbers
self.N = len(numbers)
self.SQRT = int(self.N / SQRT) + 1
self.add_tag = [0 for i in range(SQRT+20)]
self.groups = [defaultdict(int) for i in range(SQRT+20)]
self.belong_group = [0 for i in range(self.N+SQRT)]
self.low = [0 for i in range(self.N+10)]
self.high = [0 for i in range(self.N+10)]
for (i, num) in enumerate(self.numbers):
group = int(i/SQRT)
self.belong_group[i] = group
self.groups[group][num] += 1
self.low[i] = i*SQRT
self.high[i] = min((i+1)*SQRT, self.N)
def gao(self, l, r, v):
if r > self.N:
r = self.N
group = self.belong_group[l]
for i in range(l, r):
num = self.numbers[i]
self.groups[group][num] -= 1
self.groups[group][num+v] += 1
self.numbers[i] += v
def addv(self, l, r, v):
lgroup = self.belong_group[l]
rgroup = self.belong_group[r]
if lgroup == rgroup:
self.gao(l, r+1, v)
return
self.gao(l, (lgroup+1)*SQRT, v)
self.gao(rgroup*SQRT, r+1, v)
for i in range(lgroup+1, rgroup):
self.add_tag[i] += v
def search_low(self, v):
for i in range(self.SQRT):
target = v - self.add_tag[i]
if target in self.groups[i] and self.groups[i][target] > 0:
low = self.low[i]
high = self.high[i]
for j in range(low, high):
if self.numbers[j] == target:
return j
return -1
def search_high(self, v):
for i in range(self.SQRT-1, -1, -1):
target = v - self.add_tag[i]
if target in self.groups[i] and self.groups[i][target] > 0:
low = self.low[i]
high = self.high[i]
for j in range(high-1, low-1, -1):
if self.numbers[j] == target:
return j
return -2
def print_info(self):
print(self.numbers)
print(self.groups[0])
N, Q = map(int, input().split())
Ns = list(map(int, input().split()))
ST = sqrt_table(Ns)
for qs in range(Q):
query = list(map(int, input().split()))
if query[0] == 1 and ST.SQRT <= 10:
tmp, l, r, v = query
ST.addv(l-1, r-1, v)
if query[0] == 2:
v = query[1]
low = ST.search_low(v)
if low == -1:
print(-1)
else:
high = ST.search_high(v)
print(high-low)
``` | instruction | 0 | 10,350 | 5 | 20,700 |
No | output | 1 | 10,350 | 5 | 20,701 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Professor GukiZ was playing with arrays again and accidentally discovered new function, which he called GukiZiana. For given array a, indexed with integers from 1 to n, and number y, GukiZiana(a, y) represents maximum value of j - i, such that aj = ai = y. If there is no y as an element in a, then GukiZiana(a, y) is equal to - 1. GukiZ also prepared a problem for you. This time, you have two types of queries:
1. First type has form 1 l r x and asks you to increase values of all ai such that l ≤ i ≤ r by the non-negative integer x.
2. Second type has form 2 y and asks you to find value of GukiZiana(a, y).
For each query of type 2, print the answer and make GukiZ happy!
Input
The first line contains two integers n, q (1 ≤ n ≤ 5 * 105, 1 ≤ q ≤ 5 * 104), size of array a, and the number of queries.
The second line contains n integers a1, a2, ... an (1 ≤ ai ≤ 109), forming an array a.
Each of next q lines contain either four or two numbers, as described in statement:
If line starts with 1, then the query looks like 1 l r x (1 ≤ l ≤ r ≤ n, 0 ≤ x ≤ 109), first type query.
If line starts with 2, then th query looks like 2 y (1 ≤ y ≤ 109), second type query.
Output
For each query of type 2, print the value of GukiZiana(a, y), for y value for that query.
Examples
Input
4 3
1 2 3 4
1 1 2 1
1 1 1 1
2 3
Output
2
Input
2 3
1 2
1 2 2 1
2 3
2 4
Output
0
-1
Submitted Solution:
```
import sys
if sys.version[0] == "3":
raw_input = input
n, q = map(int, raw_input().split())
a = list(map(int, raw_input().split()))
otr_size = max(1, int(n ** 0.5 / 2))
otr_cnt = (n + otr_size - 1) // otr_size
def get_otr_boundaries(i):
return (i * otr_size, min(n, (i + 1) * otr_size))
def get_otr_by_index(i):
return i // otr_size
otr_delta = [0] * otr_cnt
otr_dict = [{} for i in range(otr_cnt)]
for i in range(n):
otr_dict[get_otr_by_index(i)][a[i]] = otr_dict[get_otr_by_index(i)].get(a[i], 0) + 1
def change_item(i, otr_index, x):
otr_dict[otr_index][a[i]] -= 1
a[i] += x
otr_dict[otr_index][a[i]] = otr_dict[otr_index].get(a[i], 0) + 1
def get_item(i, otr_index):
return a[i] + otr_delta[otr_index]
def has_item(val, otr_index):
return otr_dict[otr_index].get(val - otr_delta[otr_index])
big_test = q > 10000
for q_num in range(q):
query = list(map(int, raw_input().split()))
if query[0] == 1:
l, r, x = query[1:]
l -= 1
r -= 1
l_otr = get_otr_by_index(l)
r_otr = get_otr_by_index(r)
if l_otr == r_otr:
for i in range(l, r + 1):
change_item(i, l_otr, x)
else:
gr1 = get_otr_boundaries(l_otr)[1]
gr2 = get_otr_boundaries(r_otr)[0]
for i in range(l, gr1):
change_item(i, l_otr, x)
for i in range(gr2, r + 1):
change_item(i, r_otr, x)
if not big_test:
for i in range(l_otr + 1, r_otr):
otr_delta[i] += x
else:
y = query[1]
first = 0
while first < otr_cnt and not has_item(y, first):
first += 1
if first == otr_cnt:
print(-1)
else:
second = otr_cnt - 1
while not has_item(y, second):
second -= 1
for ind_first in range(*get_otr_boundaries(first)):
if get_item(ind_first, first) == y:
break
for ind_second in reversed(range(*get_otr_boundaries(second))):
if get_item(ind_second, second) == y:
break
print(ind_second - ind_first)
# print("DEBUG", a, otr_dict, otr_delta)
``` | instruction | 0 | 10,351 | 5 | 20,702 |
No | output | 1 | 10,351 | 5 | 20,703 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Professor GukiZ was playing with arrays again and accidentally discovered new function, which he called GukiZiana. For given array a, indexed with integers from 1 to n, and number y, GukiZiana(a, y) represents maximum value of j - i, such that aj = ai = y. If there is no y as an element in a, then GukiZiana(a, y) is equal to - 1. GukiZ also prepared a problem for you. This time, you have two types of queries:
1. First type has form 1 l r x and asks you to increase values of all ai such that l ≤ i ≤ r by the non-negative integer x.
2. Second type has form 2 y and asks you to find value of GukiZiana(a, y).
For each query of type 2, print the answer and make GukiZ happy!
Input
The first line contains two integers n, q (1 ≤ n ≤ 5 * 105, 1 ≤ q ≤ 5 * 104), size of array a, and the number of queries.
The second line contains n integers a1, a2, ... an (1 ≤ ai ≤ 109), forming an array a.
Each of next q lines contain either four or two numbers, as described in statement:
If line starts with 1, then the query looks like 1 l r x (1 ≤ l ≤ r ≤ n, 0 ≤ x ≤ 109), first type query.
If line starts with 2, then th query looks like 2 y (1 ≤ y ≤ 109), second type query.
Output
For each query of type 2, print the value of GukiZiana(a, y), for y value for that query.
Examples
Input
4 3
1 2 3 4
1 1 2 1
1 1 1 1
2 3
Output
2
Input
2 3
1 2
1 2 2 1
2 3
2 4
Output
0
-1
Submitted Solution:
```
import sys, array
if sys.version[0] == "3":
raw_input = input
n, q = map(int, raw_input().split())
a = list(map(int, raw_input().split()))
otr_size = max(1, int(n ** 0.5))
otr_cnt = (n + otr_size - 1) // otr_size
def get_otr_boundaries(i):
return (i * otr_size, min(n, (i + 1) * otr_size))
def get_otr_by_index(i):
return i // otr_size
otr_delta = [0] * otr_cnt # array.array("L", [0] * otr_cnt)
otr_dict = [{} for i in range(otr_cnt)]
for i in range(n):
otr_dict[get_otr_by_index(i)][a[i]] = otr_dict[get_otr_by_index(i)].get(a[i], 0) + 1
def change_item(i, otr_index, x):
otr_dict[otr_index][a[i]] -= 1
a[i] += x
otr_dict[otr_index][a[i]] = otr_dict[otr_index].get(a[i], 0) + 1
def get_item(i, otr_index):
return a[i] + otr_delta[otr_index]
def has_item(val, otr_index):
return otr_dict[otr_index].get(val - otr_delta[otr_index])
big_test = q > 10000
for q_num in range(q):
query = list(map(int, raw_input().split()))
if query[0] == 1:
l, r, x = query[1:]
l -= 1
r -= 1
l_otr = get_otr_by_index(l)
r_otr = get_otr_by_index(r)
if l_otr == r_otr:
for i in range(l, r + 1):
change_item(i, l_otr, x)
else:
gr1 = get_otr_boundaries(l_otr)[1]
gr2 = get_otr_boundaries(r_otr)[0]
for i in range(l, gr1):
change_item(i, l_otr, x)
for i in range(gr2, r + 1):
change_item(i, r_otr, x)
if not big_test:
for i in range(l_otr + 1, r_otr):
otr_delta[i] += x
else:
y = query[1]
first = 0
while first < otr_cnt and not has_item(y, first):
first += 1
if first == otr_cnt:
print(-1)
else:
second = otr_cnt - 1
while not has_item(y, second):
second -= 1
for ind_first in range(*get_otr_boundaries(first)):
if get_item(ind_first, first) == y:
break
for ind_second in reversed(range(*get_otr_boundaries(second))):
if get_item(ind_second, second) == y:
break
print(ind_second - ind_first)
# print("DEBUG", a, otr_dict, otr_delta)
``` | instruction | 0 | 10,352 | 5 | 20,704 |
No | output | 1 | 10,352 | 5 | 20,705 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Professor GukiZ was playing with arrays again and accidentally discovered new function, which he called GukiZiana. For given array a, indexed with integers from 1 to n, and number y, GukiZiana(a, y) represents maximum value of j - i, such that aj = ai = y. If there is no y as an element in a, then GukiZiana(a, y) is equal to - 1. GukiZ also prepared a problem for you. This time, you have two types of queries:
1. First type has form 1 l r x and asks you to increase values of all ai such that l ≤ i ≤ r by the non-negative integer x.
2. Second type has form 2 y and asks you to find value of GukiZiana(a, y).
For each query of type 2, print the answer and make GukiZ happy!
Input
The first line contains two integers n, q (1 ≤ n ≤ 5 * 105, 1 ≤ q ≤ 5 * 104), size of array a, and the number of queries.
The second line contains n integers a1, a2, ... an (1 ≤ ai ≤ 109), forming an array a.
Each of next q lines contain either four or two numbers, as described in statement:
If line starts with 1, then the query looks like 1 l r x (1 ≤ l ≤ r ≤ n, 0 ≤ x ≤ 109), first type query.
If line starts with 2, then th query looks like 2 y (1 ≤ y ≤ 109), second type query.
Output
For each query of type 2, print the value of GukiZiana(a, y), for y value for that query.
Examples
Input
4 3
1 2 3 4
1 1 2 1
1 1 1 1
2 3
Output
2
Input
2 3
1 2
1 2 2 1
2 3
2 4
Output
0
-1
Submitted Solution:
```
n, q = map(int, input().split())
a = list(map(int, input().split()))
for _ in range(q):
inpt = list(map(int, input().split()))
if inpt[0] == 1:
for i in range(inpt[1], inpt[2] + 1):
a[i] += inpt[3]
else:
i = 0
j = len(a) - 1
while (a[i] != inpt[1]) and (i < len(a) - 1):
i += 1
while (a[j] != inpt[1]) and (j > 0):
j -= 1
if i > j:
print(-1)
else:
print(j - i)
``` | instruction | 0 | 10,353 | 5 | 20,706 |
No | output | 1 | 10,353 | 5 | 20,707 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
<image>
Input
The input consists of four lines, each line containing a single digit 0 or 1.
Output
Output a single digit, 0 or 1.
Example
Input
0
1
1
0
Output
0
Submitted Solution:
```
a=int(input())
b=int(input())
c=int(input())
d=int(input())
out=(((a ^ b) and (c or d)) ^ ((b and c) or (a ^ d)))
print(out)
``` | instruction | 0 | 10,453 | 5 | 20,906 |
Yes | output | 1 | 10,453 | 5 | 20,907 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
<image>
Input
The input consists of four lines, each line containing a single digit 0 or 1.
Output
Output a single digit, 0 or 1.
Example
Input
0
1
1
0
Output
0
Submitted Solution:
```
def pegaInput():
oi = input()
if(oi == '0'): return False
else: return True
a = [pegaInput() for i in range(4)]
#Possibilidades testadas:
# e, ou, xor
# ou, e, xor
# xor, ou, e
# e, xor, ou
# ou, xor, e
# xor, e, ou
def xor(x, y):
return x & y
def e(x, y):
return x | y
def ou(x, y):
return x ^ y
p1 = ou(a[0],a[1])
p2 = e(a[2],a[3])
p3 = xor(a[1],a[2])
p4 = ou(a[0],a[3])
p5 = xor(p1,p2)
p6 = e(p3, p4)
p7 = ou(p5, p6)
if(p7 == False): print(0)
else: print(1)
``` | instruction | 0 | 10,455 | 5 | 20,910 |
Yes | output | 1 | 10,455 | 5 | 20,911 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
<image>
Input
The input consists of four lines, each line containing a single digit 0 or 1.
Output
Output a single digit, 0 or 1.
Example
Input
0
1
1
0
Output
0
Submitted Solution:
```
a, b, c, d = int(input()), int(input()), int(input()), int(input())
x = a ^ b
y = c or d
z = b and c
t = a ^ c
print((x and y) ^ (z or t))
``` | instruction | 0 | 10,457 | 5 | 20,914 |
No | output | 1 | 10,457 | 5 | 20,915 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
<image>
Input
The input consists of four lines, each line containing a single digit 0 or 1.
Output
Output a single digit, 0 or 1.
Example
Input
0
1
1
0
Output
0
Submitted Solution:
```
a = int(input())
b = int(input())
c = int(input())
d = int(input())
n = a*8+b*4+c*2+d
# 0123456789012345
# ! ! !
a = "0000000000001111"
print(a[n])
``` | instruction | 0 | 10,458 | 5 | 20,916 |
No | output | 1 | 10,458 | 5 | 20,917 |
Provide a correct Python 3 solution for this coding contest problem.
Given is a permutation P of \\{1, 2, \ldots, N\\}.
For a pair (L, R) (1 \le L \lt R \le N), let X_{L, R} be the second largest value among P_L, P_{L+1}, \ldots, P_R.
Find \displaystyle \sum_{L=1}^{N-1} \sum_{R=L+1}^{N} X_{L,R}.
Constraints
* 2 \le N \le 10^5
* 1 \le P_i \le N
* P_i \neq P_j (i \neq j)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
P_1 P_2 \ldots P_N
Output
Print \displaystyle \sum_{L=1}^{N-1} \sum_{R=L+1}^{N} X_{L,R}.
Examples
Input
3
2 3 1
Output
5
Input
5
1 2 3 4 5
Output
30
Input
8
8 2 7 3 4 5 6 1
Output
136 | instruction | 0 | 10,569 | 5 | 21,138 |
"Correct Solution:
```
import sys
stdin = sys.stdin
ni = lambda: int(ns())
nl = lambda: list(map(int, stdin.readline().split()))
nm = lambda: map(int, stdin.readline().split())
ns = lambda: stdin.readline().rstrip()
n = ni()
p = nl()
q = [0]*(n+1)
for i in range(n):
q[p[i]] = i+1
ans = 0
l = [0] + [i for i in range(n+1)]
r = [i+1 for i in range(n+1)] + [n+1]
for i in range(1,n+1):
v = q[i]
l1,r1 = l[v],r[v]
l2,r2 = l[l1],r[r1]
ans += i*((v-l1)*(r2-r1) + (r1-v)*(l1-l2))
l[r1] = l1
r[l1] = r1
print(ans)
``` | output | 1 | 10,569 | 5 | 21,139 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a permutation P of \\{1, 2, \ldots, N\\}.
For a pair (L, R) (1 \le L \lt R \le N), let X_{L, R} be the second largest value among P_L, P_{L+1}, \ldots, P_R.
Find \displaystyle \sum_{L=1}^{N-1} \sum_{R=L+1}^{N} X_{L,R}.
Constraints
* 2 \le N \le 10^5
* 1 \le P_i \le N
* P_i \neq P_j (i \neq j)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
P_1 P_2 \ldots P_N
Output
Print \displaystyle \sum_{L=1}^{N-1} \sum_{R=L+1}^{N} X_{L,R}.
Examples
Input
3
2 3 1
Output
5
Input
5
1 2 3 4 5
Output
30
Input
8
8 2 7 3 4 5 6 1
Output
136
Submitted Solution:
```
# -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
class BIT:
def __init__(self, n):
# 0-indexed
nv = 1
while nv < n:
nv *= 2
self.size = nv
self.tree = [0] * nv
def sum(self, i):
""" [0, i]を合計する """
s = 0
i += 1
while i > 0:
s += self.tree[i-1]
i -= i & -i
return s
def add(self, i, x):
""" 値の追加:添字i, 値x """
i += 1
while i <= self.size:
self.tree[i-1] += x
i += i & -i
def get(self, l, r=None):
""" 区間和の取得 [l, r) """
# 引数が1つなら一点の値を取得
if r is None: r = l + 1
res = 0
if r: res += self.sum(r-1)
if l: res -= self.sum(l-1)
return res
def bisearch_left(self, l, r, x):
""" 区間[l,r]で左からx番目の値がある位置 """
l_sm = self.sum(l-1)
ok = r + 1
ng = l - 1
while ng+1 < ok:
mid = (ok+ng) // 2
if self.sum(mid) - l_sm >= x:
ok = mid
else:
ng = mid
if ok != r + 1:
return ok
else:
return -1
def bisearch_right(self, l, r, x):
""" 区間[l,r]で右からx番目の値がある位置 """
r_sm = self.sum(r)
ok = l - 1
ng = r + 1
while ok+1 < ng:
mid = (ok+ng) // 2
if r_sm - self.sum(mid-1) >= x:
ok = mid
else:
ng = mid
if ok != l - 1:
return ok
else:
return -1
N = INT()
A = LIST()
# aの昇順に処理できるようにindexで並べておく
idxs = [0] * (N+1)
for i, a in enumerate(A):
idxs[a] = i + 1
bit = BIT(N+2)
# 先頭と末尾に番兵を仕込む
bit.add(0, 2)
bit.add(N+1, 2)
ans = [0] * (N+1)
# 大きいaから見ていく
for a in range(N, 0, -1):
# a(N~1)が格納されているindex
idx = idxs[a]
# 自分より小さいindexで2回目に自分より大きい値がある直前の場所
p = bit.bisearch_right(0, idx, 2) + 1
# 自分より小さいindexで最初に自分より大きい値がある直前の場所
q = bit.bisearch_right(0, idx, 1) + 1
# 自分より大きいindexで最初に自分より大きい値がある直前の場所
r = bit.bisearch_left(idx, N+1, 1) - 1
# 自分より大きいindexで2回目に自分より大きい値がある直前の場所
s = bit.bisearch_left(idx, N+1, 2) - 1
# aを使う回数 * a = (左に自分より大きい値がある時の通り数 + 右に自分より大きい値がある時の通り数) * a
ans[a] = ((q-p)*(r-idx+1) + (idx-q+1)*(s-r)) * a
# aを出現済とする
bit.add(idx, 1)
# 全てのaについての合計
print(sum(ans))
``` | instruction | 0 | 10,574 | 5 | 21,148 |
Yes | output | 1 | 10,574 | 5 | 21,149 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a permutation P of \\{1, 2, \ldots, N\\}.
For a pair (L, R) (1 \le L \lt R \le N), let X_{L, R} be the second largest value among P_L, P_{L+1}, \ldots, P_R.
Find \displaystyle \sum_{L=1}^{N-1} \sum_{R=L+1}^{N} X_{L,R}.
Constraints
* 2 \le N \le 10^5
* 1 \le P_i \le N
* P_i \neq P_j (i \neq j)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
P_1 P_2 \ldots P_N
Output
Print \displaystyle \sum_{L=1}^{N-1} \sum_{R=L+1}^{N} X_{L,R}.
Examples
Input
3
2 3 1
Output
5
Input
5
1 2 3 4 5
Output
30
Input
8
8 2 7 3 4 5 6 1
Output
136
Submitted Solution:
```
N = int(input())
P = [0]+list(map(int,input().split()))+[N+1]
ans = 0
b = [0]*(N+2)
for i in range(N+2):
b[P[i]] = i
l1 = [max(0,i-1) for i in range(N+2)]
l2 = [max(0,i-2) for i in range(N+2)]
r1 = [min(N+1,i+1) for i in range(N+2)]
r2 = [min(N+1,i+2) for i in range(N+2)]
for i in range(N+1):
m = b[i]
x2,x1,y1,y2 = l2[m],l1[m],r1[m],r2[m]
hoge= i*(abs((m-x1)*(y2-y1)) + abs((y1-m)*(x1-x2)))
ans += hoge
#x1
r1[x1] = y1
r2[x1] = y2
#y1
l1[y1] = x1
l2[y1] = x2
#x2
r1[x2] = x1
r2[x2] = y1
#y2
l1[y2] = y1
l2[y2] = x1
print(ans)
``` | instruction | 0 | 10,575 | 5 | 21,150 |
Yes | output | 1 | 10,575 | 5 | 21,151 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a permutation P of \\{1, 2, \ldots, N\\}.
For a pair (L, R) (1 \le L \lt R \le N), let X_{L, R} be the second largest value among P_L, P_{L+1}, \ldots, P_R.
Find \displaystyle \sum_{L=1}^{N-1} \sum_{R=L+1}^{N} X_{L,R}.
Constraints
* 2 \le N \le 10^5
* 1 \le P_i \le N
* P_i \neq P_j (i \neq j)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
P_1 P_2 \ldots P_N
Output
Print \displaystyle \sum_{L=1}^{N-1} \sum_{R=L+1}^{N} X_{L,R}.
Examples
Input
3
2 3 1
Output
5
Input
5
1 2 3 4 5
Output
30
Input
8
8 2 7 3 4 5 6 1
Output
136
Submitted Solution:
```
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
n = ni()
a = na()
st = []
ans = 0
gans = 0
for i in range(n):
v = a[i]
l = 0
bst = []
while len(st) > 0 and st[-1][1] < v:
h = st.pop(-1)
ans -= h[1] * h[2]
if h[0] < v:
h[0], h[1] = v, h[0]
else:
h[1] = v
ans += h[1]*h[2]
if len(bst) > 0 and bst[-1][0] == h[0] and bst[-1][1] == h[1]:
bst[-1][2] += h[2]
else:
bst.append(h)
st.extend(bst[::-1])
st.append([v, 0, 1])
gans += ans
print(gans)
``` | instruction | 0 | 10,577 | 5 | 21,154 |
Yes | output | 1 | 10,577 | 5 | 21,155 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a permutation P of \\{1, 2, \ldots, N\\}.
For a pair (L, R) (1 \le L \lt R \le N), let X_{L, R} be the second largest value among P_L, P_{L+1}, \ldots, P_R.
Find \displaystyle \sum_{L=1}^{N-1} \sum_{R=L+1}^{N} X_{L,R}.
Constraints
* 2 \le N \le 10^5
* 1 \le P_i \le N
* P_i \neq P_j (i \neq j)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
P_1 P_2 \ldots P_N
Output
Print \displaystyle \sum_{L=1}^{N-1} \sum_{R=L+1}^{N} X_{L,R}.
Examples
Input
3
2 3 1
Output
5
Input
5
1 2 3 4 5
Output
30
Input
8
8 2 7 3 4 5 6 1
Output
136
Submitted Solution:
```
N = int(input())
P = list(map(int,input().split()))
sum = 0
for L in range(N-1):
S = sorted([P[L],P[L+1]])
sum += S[0]
for R in range(L+2,N):
if P[R] > S[1]:
S[0] = S[1]
S[1] = P[R]
elif P[R] > S[0]:
S[0] = P[R]
sum += S[0]
print(sum)
``` | instruction | 0 | 10,579 | 5 | 21,158 |
No | output | 1 | 10,579 | 5 | 21,159 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a permutation P of \\{1, 2, \ldots, N\\}.
For a pair (L, R) (1 \le L \lt R \le N), let X_{L, R} be the second largest value among P_L, P_{L+1}, \ldots, P_R.
Find \displaystyle \sum_{L=1}^{N-1} \sum_{R=L+1}^{N} X_{L,R}.
Constraints
* 2 \le N \le 10^5
* 1 \le P_i \le N
* P_i \neq P_j (i \neq j)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
P_1 P_2 \ldots P_N
Output
Print \displaystyle \sum_{L=1}^{N-1} \sum_{R=L+1}^{N} X_{L,R}.
Examples
Input
3
2 3 1
Output
5
Input
5
1 2 3 4 5
Output
30
Input
8
8 2 7 3 4 5 6 1
Output
136
Submitted Solution:
```
class B():
def __init__(self,N):
self.N = N
self.node = [0]*(self.N+1)
self.cnt = 0
def add(self,x): # 要素 x を追加
self.cnt += 1
while x <= self.N:
self.node[x] += 1
x += x & -x
def delete(self,x): # 要素 x を削除
self.cnt -= 1
while x <= self.N:
self.node[x] -= 1
x += x & -x
def count(self,x): # x以下の要素数
tmp = 0
while x > 0:
tmp += self.node[x]
x -= x & -x
return tmp
def get_max(self):
return self.get_ith(self.cnt)
def get_ith(self,i): # i 番目に小さい要素を取得
NG = -1
OK = self.N+1
while OK-NG > 1:
mid = (OK+NG)//2
#print(OK,NG,self.count(mid))
if self.count(mid) >= i:
OK = mid
else:
NG = mid
return OK
def search_low(self,x): # x より小さい最大の要素
xcn = self.count(x)
NG = -1
OK = x
while OK-NG > 1:
mid = (OK+NG)//2
#print(OK,NG,self.count(mid))
if self.count(mid) >= xcn:
OK = mid
else:
NG = mid
return OK
def search_high(self,x): # x より大きい最小の要素
xcn = self.count(x)
NG = x
OK = self.N + 1
while OK-NG > 1:
mid = (OK+NG)//2
#print(OK,NG,self.count(mid))
if self.count(mid) > xcn:
OK = mid
else:
NG = mid
return OK
import sys
stdin = sys.stdin
ni = lambda: int(ns())
nl = lambda: list(map(int, stdin.readline().split()))
nm = lambda: map(int, stdin.readline().split())
ns = lambda: stdin.readline().rstrip()
n = ni()
p = nl()
q = [0]*(n+1)
for i in range(n):
q[p[i]] = i+1
ans = 0
b = B(n)
b.add(q[-1])
for i in range(n-1,0,-1):
v = q[i]
l1 = b.search_low(v)
r1 = b.search_high(v)
l2 = b.search_low(l1)
r2 = b.search_high(r1)
ans += i*((r1-v)*(l1-l2) + (v-l1)*(r2-r1))
b.add(v)
print(ans)
``` | instruction | 0 | 10,580 | 5 | 21,160 |
No | output | 1 | 10,580 | 5 | 21,161 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a permutation P of \\{1, 2, \ldots, N\\}.
For a pair (L, R) (1 \le L \lt R \le N), let X_{L, R} be the second largest value among P_L, P_{L+1}, \ldots, P_R.
Find \displaystyle \sum_{L=1}^{N-1} \sum_{R=L+1}^{N} X_{L,R}.
Constraints
* 2 \le N \le 10^5
* 1 \le P_i \le N
* P_i \neq P_j (i \neq j)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
P_1 P_2 \ldots P_N
Output
Print \displaystyle \sum_{L=1}^{N-1} \sum_{R=L+1}^{N} X_{L,R}.
Examples
Input
3
2 3 1
Output
5
Input
5
1 2 3 4 5
Output
30
Input
8
8 2 7 3 4 5 6 1
Output
136
Submitted Solution:
```
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
N = int(input())
P = list(map(int, input().split()))
s = 0
for i in range(N):
count = 0
a1 = i
a2 = i
a3 = i
a4 = i
while a2 > 0:
a2 -= 1
if (P[i] < P[a2]):
a1 = a2
if a1 == 0:
count = 1
else:
while a1 > 0:
a1 -= 1
if (P[i] < P[a1]):
count += (a2 - a1)
while a3 < N-1:
a3 += 1
if (P[i] < P[a3]):
a4 = a3
if a4 == 0:
count = 1
else:
while a4 > 0:
a4 += 1
if (P[i] < P[a4]):
count += (a4 - a3)
sum += P[i] * count
print(str(sum))
``` | instruction | 0 | 10,581 | 5 | 21,162 |
No | output | 1 | 10,581 | 5 | 21,163 |
Provide a correct Python 3 solution for this coding contest problem.
Compute A + B.
Constraints
* -1000 ≤ A, B ≤ 1000
Input
The input will consist of a series of pairs of integers A and B separated by a space, one pair of integers per line. The input will be terminated by EOF.
Output
For each pair of input integers A and B, you must output the sum of A and B in one line.
Example
Input
1 2
10 5
100 20
Output
3
15
120 | instruction | 0 | 10,698 | 5 | 21,396 |
"Correct Solution:
```
import sys
for line in sys.stdin:
line = line.split(' ')
print(sum(map(int, line)))
``` | output | 1 | 10,698 | 5 | 21,397 |
Provide a correct Python 3 solution for this coding contest problem.
Compute A + B.
Constraints
* -1000 ≤ A, B ≤ 1000
Input
The input will consist of a series of pairs of integers A and B separated by a space, one pair of integers per line. The input will be terminated by EOF.
Output
For each pair of input integers A and B, you must output the sum of A and B in one line.
Example
Input
1 2
10 5
100 20
Output
3
15
120 | instruction | 0 | 10,699 | 5 | 21,398 |
"Correct Solution:
```
while True:
try:
a, b = map(int, input().split())
print(a+b)
except EOFError as e:
break
``` | output | 1 | 10,699 | 5 | 21,399 |
Provide a correct Python 3 solution for this coding contest problem.
Compute A + B.
Constraints
* -1000 ≤ A, B ≤ 1000
Input
The input will consist of a series of pairs of integers A and B separated by a space, one pair of integers per line. The input will be terminated by EOF.
Output
For each pair of input integers A and B, you must output the sum of A and B in one line.
Example
Input
1 2
10 5
100 20
Output
3
15
120 | instruction | 0 | 10,700 | 5 | 21,400 |
"Correct Solution:
```
import sys
for line in sys.stdin:
a, b = map(int, line.split())
print(a + b)
``` | output | 1 | 10,700 | 5 | 21,401 |
Provide a correct Python 3 solution for this coding contest problem.
Compute A + B.
Constraints
* -1000 ≤ A, B ≤ 1000
Input
The input will consist of a series of pairs of integers A and B separated by a space, one pair of integers per line. The input will be terminated by EOF.
Output
For each pair of input integers A and B, you must output the sum of A and B in one line.
Example
Input
1 2
10 5
100 20
Output
3
15
120 | instruction | 0 | 10,701 | 5 | 21,402 |
"Correct Solution:
```
import sys
for s in sys.stdin:
A, B = map(int, s.split())
print(A + B)
``` | output | 1 | 10,701 | 5 | 21,403 |
Provide a correct Python 3 solution for this coding contest problem.
Compute A + B.
Constraints
* -1000 ≤ A, B ≤ 1000
Input
The input will consist of a series of pairs of integers A and B separated by a space, one pair of integers per line. The input will be terminated by EOF.
Output
For each pair of input integers A and B, you must output the sum of A and B in one line.
Example
Input
1 2
10 5
100 20
Output
3
15
120 | instruction | 0 | 10,702 | 5 | 21,404 |
"Correct Solution:
```
import sys
val = []
result = []
count = 0
for line in sys.stdin:
if line != '\n':
for word in line.split():
val.append(int(word))
result.append(sum(val))
val = []
count = count + 1
else:
break
for x in result:
print(x)
``` | output | 1 | 10,702 | 5 | 21,405 |
Provide a correct Python 3 solution for this coding contest problem.
Compute A + B.
Constraints
* -1000 ≤ A, B ≤ 1000
Input
The input will consist of a series of pairs of integers A and B separated by a space, one pair of integers per line. The input will be terminated by EOF.
Output
For each pair of input integers A and B, you must output the sum of A and B in one line.
Example
Input
1 2
10 5
100 20
Output
3
15
120 | instruction | 0 | 10,703 | 5 | 21,406 |
"Correct Solution:
```
while True:
try:
x,y=map(int,input().split())
print(x+y)
except EOFError:
break
``` | output | 1 | 10,703 | 5 | 21,407 |
Provide a correct Python 3 solution for this coding contest problem.
Compute A + B.
Constraints
* -1000 ≤ A, B ≤ 1000
Input
The input will consist of a series of pairs of integers A and B separated by a space, one pair of integers per line. The input will be terminated by EOF.
Output
For each pair of input integers A and B, you must output the sum of A and B in one line.
Example
Input
1 2
10 5
100 20
Output
3
15
120 | instruction | 0 | 10,704 | 5 | 21,408 |
"Correct Solution:
```
import sys
for line in sys.stdin:
items = line.split()
print( int(items[0]) + int(items[1]) )
``` | output | 1 | 10,704 | 5 | 21,409 |
Provide a correct Python 3 solution for this coding contest problem.
Compute A + B.
Constraints
* -1000 ≤ A, B ≤ 1000
Input
The input will consist of a series of pairs of integers A and B separated by a space, one pair of integers per line. The input will be terminated by EOF.
Output
For each pair of input integers A and B, you must output the sum of A and B in one line.
Example
Input
1 2
10 5
100 20
Output
3
15
120 | instruction | 0 | 10,705 | 5 | 21,410 |
"Correct Solution:
```
while 1:
try:
n,m=map(int,input().split())
except EOFError:
break
print(n+m)
``` | output | 1 | 10,705 | 5 | 21,411 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Compute A + B.
Constraints
* -1000 ≤ A, B ≤ 1000
Input
The input will consist of a series of pairs of integers A and B separated by a space, one pair of integers per line. The input will be terminated by EOF.
Output
For each pair of input integers A and B, you must output the sum of A and B in one line.
Example
Input
1 2
10 5
100 20
Output
3
15
120
Submitted Solution:
```
while True:
try:
s=input()
a = s.split(' ')
print(int(a[0]) + int(a[1]))
#do something
except EOFError:
break
``` | instruction | 0 | 10,706 | 5 | 21,412 |
Yes | output | 1 | 10,706 | 5 | 21,413 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Compute A + B.
Constraints
* -1000 ≤ A, B ≤ 1000
Input
The input will consist of a series of pairs of integers A and B separated by a space, one pair of integers per line. The input will be terminated by EOF.
Output
For each pair of input integers A and B, you must output the sum of A and B in one line.
Example
Input
1 2
10 5
100 20
Output
3
15
120
Submitted Solution:
```
try:
while 1:print(sum(map(int,input().split())))
except:1
``` | instruction | 0 | 10,707 | 5 | 21,414 |
Yes | output | 1 | 10,707 | 5 | 21,415 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Compute A + B.
Constraints
* -1000 ≤ A, B ≤ 1000
Input
The input will consist of a series of pairs of integers A and B separated by a space, one pair of integers per line. The input will be terminated by EOF.
Output
For each pair of input integers A and B, you must output the sum of A and B in one line.
Example
Input
1 2
10 5
100 20
Output
3
15
120
Submitted Solution:
```
# AOJ 1000: A + B Problem
# Python3 2018.7.4 bal4u
while True:
try: print(sum(map(int, input().split())))
except: break
``` | instruction | 0 | 10,708 | 5 | 21,416 |
Yes | output | 1 | 10,708 | 5 | 21,417 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.