ZhenlongDai/ACPR huggingface dataset:
Problem: p03164
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
def 解():
    input = sys.stdin.readline

    N,W=[int(_) for _ in input().split()]
    dp={0:0}
    for i in range(N):
        w,v=[int(_) for _ in input().split()]
        for j in dp.copy():
            if dp[j]+w <= W:
                if j+v in dp:
                    dp[j+v] = min(dp[j+v],dp[j]+w)
                else:
                    dp[j+v] = dp[j]+w

    print(max(dp.keys()))
解()


Failing test case input:
6 15
6 3
9 6
0 4
4 20
3 10
1 4

Expected output:
41


Actual output:
44


Fixed submission (verdict: Accepted):
import sys
def 解():
    input = sys.stdin.readline

    N,W=[int(_) for _ in input().split()]
    dp={0:0}
    for _ in range(N):
        w,v=[int(_) for _ in input().split()]
        
        for j in sorted(dp.keys(),reverse=True):
            nw = dp[j]+w
            nv = j+v
            if nw <= W :
                if nv in dp:
                    if nw < dp[nv]:
                        dp[nv] = nw
                else:
                    dp[nv] = nw

    print(max(dp.keys()))
解()

Problem: p03164
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):


N,W=map(int,input().split())

w,v=[0],[0]

for _ in range(N):
    wi,vi=map(int,input().split())
    w.append(wi)
    v.append(vi)

dp=[[10**12 for _ in range(N*max(v)+1)] for _ in range(N+1)]
dp[0][0]=0

for i in range(N):
    for sum_v in range(N*max(v)+1):
        if sum_v-v[i]>=0:
            dp[i+1][sum_v]=min(dp[i][sum_v-v[i]]+w[i],dp[i][sum_v])
        else:
            dp[i+1][sum_v]=dp[i][sum_v]


ans=0

for sum_v in range(N*max(v)+1):
    if dp[N][sum_v]<=W:
        ans=max(ans,sum_v)
print(ans)   


Failing test case input:
3 3
6 9
5 5
0 4
6 5
3 5
0 3

Expected output:
4


Actual output:
0


Fixed submission (verdict: Accepted):


N,W=map(int,input().split())

w,v=[0],[0]

for _ in range(N):
    wi,vi=map(int,input().split())
    w.append(wi)
    v.append(vi)

dp=[[10**12 for _ in range(N*max(v)+1)] for _ in range(N+1)]
dp[0][0]=0

for i in range(N):
    for sum_v in range(N*max(v)+1):
        if sum_v-v[i+1]>=0:
            dp[i+1][sum_v]=min(dp[i][sum_v-v[i+1]]+w[i+1],dp[i][sum_v])
        else:
            dp[i+1][sum_v]=dp[i][sum_v]

ans=0

for sum_v in range(N*max(v)+1):
    if dp[N][sum_v]<=W:
        ans=max(ans,sum_v)
print(ans)
Problem: p03164
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,W = map(int,input().split())
dp = [[10**12] * (10**5+1) for i in range(n+1)]
dp[0][0] = 0
ma = 0
for i in range(1,n+1):
  w,v = map(int,input().split())
  ma += v
  for j in range(v,ma+1):
    dp[i][j] = min(dp[i-1][j-v]+w,dp[i-1][j])
m = 0
for i in range(ma+1):
  if dp[-1][i] <= W:
    m = i
print(m)

Failing test case input:
3 8
3 30
4 35
5 60

Expected output:
90


Actual output:
65


Fixed submission (verdict: Accepted):
n,W = map(int,input().split())
dp = [[10**12] * (10**5+1) for i in range(n+1)]
dp[0][0] = 0
ma = 0
for i in range(1,n+1):
  w,v = map(int,input().split())
  ma += v
  for j in range(v):
    dp[i][j] = dp[i-1][j]
  for j in range(v,ma+1):
    dp[i][j] = min(dp[i-1][j-v]+w,dp[i-1][j])
m = 0
for i in range(ma+1):
  if dp[-1][i] <= W:
    m = i
print(m)

Problem: p03164
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, W = map(int, input().split())
MV = (10**3)*N+1
MV = 100
dp = [[0] + [10**18]*(MV-1) for _ in range(N+1)]
dp[0][0] = 0
for i in range(1, N+1):
    w, v = map(int, input().split())
    for j in range(1, MV):
        dp[i][j] = min(dp[i-1][j], dp[i-1][max(0, j-v)]+w)
for i in range(MV):
    if dp[N][MV-i-1] <= W:
        print(MV-i-1)
        break



Failing test case input:
3 10
3 35
1 14
5 78

Expected output:
127


Actual output:
99


Fixed submission (verdict: Accepted):
N, W = map(int, input().split())
MV = (10**3)*N+1
dp = [[0] + [10**18]*(MV-1) for _ in range(N+1)]
dp[0][0] = 0
for i in range(1, N+1):
    w, v = map(int, input().split())
    for j in range(1, MV):
        dp[i][j] = min(dp[i-1][j], dp[i-1][max(0, j-v)]+w)
for i in range(MV):
    if dp[N][MV-i-1] <= W:
        print(MV-i-1)
        break
Problem: p03689
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
H,W,h,w=map(int,input().split())
if H%h==0 and W%w==0:
    print("No")
else:
    ans=[[1 for i in range(W)] for j in range(H)]
    for i in range(H):
        for j in range(W):
            if (i+1)%h==0 and (j+1)%w==0:
                ans[i][j]=-h*w
    if sum(ans[i][j] for i in range(H) for j in range(W))>0:
        print("Yes")
        for i in range(H):
            print(*ans[i])
    else:
        print("No")


Failing test case input:
3 6 2 3

Expected output:
Yes
1000 1000 1000 1000 1000 1000
1000 1000 -5001 1000 1000 -5001
1000 1000 1000 1000 1000 1000


Actual output:
Yes
1 1 1 1 1 1
1 1 -6 1 1 -6
1 1 1 1 1 1


Fixed submission (verdict: Accepted):
H,W,h,w=map(int,input().split())
if H%h==0 and W%w==0:
    print("No")
else:
    c=10**9
    ans=[[(c-1)
    for i in range(H):
        for j in range(W):
            if (i+1)%h==0 and (j+1)%w==0:
                ans[i][j]=-c
    if sum(ans[i][j] for i in range(H) for j in range(W))>0:
        print("Yes")
        for i in range(H):
            print(*ans[i])
    else:
        print("No")

Problem: p03689
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
H,W,h,w=map(int,input().split())
if H%h==0 and W%w==0:
    print("No")
else:
    print("Yes")
    ans=[[1 for i in range(W)] for j in range(H)]
    for i in range(H):
        for j in range(W):
            if (i+1)%h==0 and (j+1)%w==0:
                ans[i][j]=-h*w
    for i in range(H):
        print(*ans[i])

Failing test case input:
2 8 4 1

Expected output:
Yes
1000 1000 1000 1000 1000 1000 1000 1000
1000 1000 1000 1000 1000 1000 1000 1000


Actual output:
Yes
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1


Fixed submission (verdict: Accepted):
H,W,h,w=map(int,input().split())
if H%h==0 and W%w==0:
    print("No")
else:
    c=10**9
    ans=[[(c-1)
    for i in range(H):
        for j in range(W):
            if (i+1)%h==0 and (j+1)%w==0:
                ans[i][j]=-c
    if sum(ans[i][j] for i in range(H) for j in range(W))>0:
        print("Yes")
        for i in range(H):
            print(*ans[i])
    else:
        print("No")

Problem: p03689
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
H, W, h, w = map(int, input().split())
if H % h == 0 and W % h == 0:
    print('No')
    exit()
print('Yes')
a = [[1] * W for _ in range(H)]
for i in range(h-1, H, h):
    for j in range(w-1, W, w):
        a[i][j] = -h * w
for row in a:
    print(*row)


Failing test case input:
1 11 4 3

Expected output:
Yes
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000


Actual output:
Yes
1 1 1 1 1 1 1 1 1 1 1


Fixed submission (verdict: Accepted):
H, W, h, w = map(int, input().split())
rem = H * W - (H - H % h) * (W - W % w)
if rem == 0:
    print('No')
    exit()
x = (H 
if abs(x) > 10**9 or abs(-(h * w - 1) * x - 1) > 10**9:
    print('No')
    exit()
print('Yes')
a = [[x] * W for _ in range(H)]
for i in range(h-1, H, h):
    for j in range(w-1, W, w):
        a[i][j] = -(h * w - 1) * x - 1
for row in a:
    print(*row)
Problem: p03689
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
input = sys.stdin.readline
H, W, h, w = map(int, input().split())
res = [[1] * W for _ in range(H)]
for i in range(h - 1, H, h):
  for j in range(w - 1, W, w): res[i][j] = -h * w
if sum([sum(r) for r in res]) > 0:
  print("Yes")
  for r in res: print(*r)
else: print("No")

Failing test case input:
2 11 2 2

Expected output:
Yes
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000
1000 -3001 1000 -3001 1000 -3001 1000 -3001 1000 -3001 1000


Actual output:
No


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline
H, W, h, w = map(int, input().split())
unit = 10 ** 9 - 1
c = H * W
for i in range(h - 1, H, h):
  for j in range(w - 1, W, w): c -= 1
if c == 0:
  print("No")
  exit(0)
res = [[unit 
for i in range(h - 1, H, h):
  for j in range(w - 1, W, w): res[i][j] = -(unit 
if sum([sum(r) for r in res]) > 0:
  print("Yes")
  for r in res: print(*r)
else: print("No")
Problem: p03380
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=list(map(int, input().split()))
ans=[]
x=max(a)
ans.append(x)
y=x
b=10**9
d=10**9
for i in range(n):
    c=abs(a[i]-y)
    if b>c:
        d=a[i]
    b=min(b,c)
ans.append(d)
print(*ans)

    



Failing test case input:
5
1 9 0 8 16

Expected output:
16 8


Actual output:
16 16


Fixed submission (verdict: Accepted):
n=int(input())
a=list(map(int, input().split()))
ans=[]
x=max(a)
ans.append(x)
a.remove(max(a))
y=x/2
b=10**10
d=10**10

for i in range(n-1):
    c=abs(a[i]-y)
    if b>c:
        d=a[i]
    b=min(b,c)
ans.append(d)
print(*ans)

Problem: p03380
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))
ans1=max(a)
m=10**9+1
temp=ans1/2
i=0
for index,val in enumerate(a):
    if abs(val-temp)<m:
        m=abs(val-temp)
        i=index
ans2=a[i]
print(ans1,ans2)

Failing test case input:
2
011 0

Expected output:
11 0


Actual output:
11 11


Fixed submission (verdict: Accepted):
n=int(input())
a=list(map(int,input().split()))
ans1=max(a)
m=10**9+1
temp=ans1/2
i=0
for index,val in enumerate(a):
    if val==ans1: continue
    if abs(val-temp)<m:
        m=abs(val-temp)
        i=index
ans2=a[i]
print(ans1,ans2)

Problem: p03380
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
a = tuple(int(x) for x in input().split())

def hoge(n, r):
 return n * (min(n-r, r))

n = max(a)
ans = (n, a[0])
for i in a[1:]:
 ans = (n, i) if hoge(*ans) < hoge(n, i) else ans
print(*ans)

Failing test case input:
2
011 0

Expected output:
11 0


Actual output:
11 11


Fixed submission (verdict: Accepted):
N = int(input())
a = sorted(int(x) for x in input().split())

def hoge(n, r):
 return n * (min(n-r, r))

n = max(a)
ans = (n, a[0])
for i in a[1:]:
 ans = (n, i) if hoge(*ans) < hoge(n, i) else ans
print(*ans)

Problem: p03380
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = sorted(list(map(int,input().split())))
x = a.pop()
y = a[0]
m = abs(x/2 - a[0])
for i in range(1,n-1):
    if abs(x/2-a[i]) < m:
        y = a[i]
print(x,y)
    

Failing test case input:
5
2 11 1 12 15

Expected output:
15 11


Actual output:
15 12


Fixed submission (verdict: Accepted):
n = int(input())
a = sorted(list(map(int,input().split())))
x = a.pop()
y = a[0]
m = abs(x/2 - a[0])
for i in range(1,n-1):
    if abs(x/2-a[i]) < m:
        y = a[i]
        m = abs(x/2-a[i])
print(x,y)
Problem: p03380
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a_n = list(map(int, input().split()))
result1 = max(a_n)
min_delta = max(a_n)
result2 = max(a_n)
for num in a_n:
    if abs(num-n/2)<min_delta:
        result2 = num
print('{} {}'.format(result1, result2))

Failing test case input:
5
5 9 4 -1 11

Expected output:
11 5


Actual output:
11 11


Fixed submission (verdict: Accepted):
n = int(input())
a_n = list(map(int, input().split()))
result1 = max(a_n)
min_delta = max(a_n)
result2 = max(a_n)
for num in a_n:
    if num == result1:
        pass
    elif abs(num-result1/2)<=min_delta:
        min_delta = abs(num-result1/2)
        result2 = num
print('{} {}'.format(result1, result2))

Problem: p03380
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
an = [int(i) for i in input().split()]
ai = max(an)
print("%d %d"%(ai, min(an, key=lambda i:abs(ai-i**2))))

Failing test case input:
5
10 9 1 4 20

Expected output:
20 10


Actual output:
20 4


Fixed submission (verdict: Accepted):
n = int(input())
an = [int(i) for i in input().split()]
an.sort()
ai = an[-1]
print("%d %d"%(ai, min(an, key=lambda i:abs(ai-i*2))))

Problem: p03380
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))

MAX=max(a)
Harf=MAX/2

cnt=10**20
ans=0
for i in range(n):
    if abs(Harf-a[i])<cnt:
        ans=a[i]
        cnt=abs(Harf-a[i])
print(MAX,ans)

Failing test case input:
2
011 0

Expected output:
11 0


Actual output:
11 11


Fixed submission (verdict: Accepted):
n=int(input())
a=list(map(int,input().split()))

MAX=max(a)
Harf=MAX/2

cnt=10**20
ans=0
for i in range(n):
    if MAX==a[i]:
        continue
    elif abs(Harf-a[i])<cnt:
        ans=a[i]
        cnt=abs(Harf-a[i])
print(MAX,ans)

Problem: p03380
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))

ai = max(a)
aj = min(a)

for i in a:
    if aj < min(i, ai - i):
        aj = i
    
print(ai, aj)

Failing test case input:
5
8 1 1 -1 1

Expected output:
8 1


Actual output:
8 8


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))

ai = max(a)
aj = min(a)

for i in a:
    if min(aj, ai -aj) < min(i, ai - i):
        aj = i
    
print(ai, aj)

Problem: p03380
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int,input().split()))
a = sorted(a, reverse = True)

ai = a[0] 
aj = 0
comb = 10 ** 10
for i in range(n):
    temp = abs(a[i] - ai)
    if comb >= temp:
        comb = temp
        aj = a[i]
print(a[0], aj)

Failing test case input:
5
2 0 0 4 1

Expected output:
4 2


Actual output:
4 4


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int,input().split()))
a = sorted(a, reverse = True)

ai = a[0] / 2
aj = 0
comb = 10 ** 10
for i in range(n):
    temp = abs(a[i] - ai)
    if comb >= temp:
        comb = temp
        aj = a[i]
print(a[0], aj)
Problem: p03380
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))
m=max(a)
h=m/2
d=abs(a[0]-h)
x=0
for i in range(1,n):
  if abs(a[i]-h)<d:
    x=i
print(m,a[x])

Failing test case input:
5
20 13 1 4 20

Expected output:
20 13


Actual output:
20 4


Fixed submission (verdict: Accepted):
n=int(input())
a=sorted(list(map(int,input().split())))
m=a[n-1]
a=a[:n]
h=m/2
d=abs(a[0]-h)
x=0
for i in range(1,n-1):
  if abs(a[i]-h)<d:
    x=i
    d=abs(a[i]-h)
print(m,a[x])
Problem: p03945
Buggy submission (Python (3.4.3), verdict: Wrong Answer):





s = list(input())

cnt = 0

for i in range(len(s)):
    if s[i-1] != s[i]:
        cnt += 1

print(cnt)



Failing test case input:
DVBYB

Expected output:
4


Actual output:
5


Fixed submission (verdict: Accepted):





s = list(input())

cnt = 0

for i in range(1,len(s)):
    if s[i-1] != s[i]:
        cnt += 1

print(cnt)

Problem: p03945
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
p = S[0]
ans = 0
for i in range(1, len(S)):
  if S[i] != p: ans += 1
print (ans)


Failing test case input:
WVWWWY

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
S = input()
p = S[0]
ans = 0
for i in range(1, len(S)):
  if S[i] != p: ans += 1
  p = S[i]
print (ans)

Problem: p03945
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
count = 0
temp = S[-1]
for s in S[-2::-1]:
    if s != temp:
        count += 1
    temp = s
print(0 if count == 0 else count-1)

Failing test case input:
BABAXWWDVZ

Expected output:
8


Actual output:
7


Fixed submission (verdict: Accepted):
S = input()
count = 0
temp = S[-1]
for s in S[-2::-1]:
    if s != temp:
        count += 1
    temp = s
print(0 if count == 0 else count)

Problem: p03945
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
ans = 0
for i in range(1,len(S)):
  if S[i-1] != S[i]:
    ans += 1

Failing test case input:
WVWWWZ

Expected output:
3


Actual output:

Fixed submission (verdict: Accepted):
S = input()
ans = 0
for i in range(1,len(S)):
  if S[i-1] != S[i]:
    ans += 1
print(ans)

Problem: p03945
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()

count = 0
check = S[0]

for i in S[1:]:
    if check != S:
        count+=1
        check = i
        
print(count)

Failing test case input:
XWVUWW

Expected output:
4


Actual output:
5


Fixed submission (verdict: Accepted):
S = input()
count = 0
check = S[0]

for i in S[1:]:
    if check != i:
        count+=1
        check = i
        
print(count)

Problem: p03945
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input().strip()

prev = None
ans1, ans2 = 0, 0
for _s in s:
  if prev is None:
    prev = _s
  elif prev != _s:
    ans1 += 1
    prev = _s
prev = None
for _s in s[::-1]:
  if prev is None:
    prev = _s
  elif prev != _s:
    ans1 += 1
    prev = _s
print(min(ans1, ans2))

Failing test case input:
WWXUXW

Expected output:
4


Actual output:
0


Fixed submission (verdict: Accepted):
s = input().strip()

prev = None
ans1, ans2 = 0, 0
for _s in s:
  if prev is None:
    prev = _s
  elif prev != _s:
    ans1 += 1
    prev = _s
prev = None
for _s in s[::-1]:
  if prev is None:
    prev = _s
  elif prev != _s:
    ans2 += 1
    prev = _s
print(min(ans1, ans2))
Problem: p03945
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
s = S[0:1]
ans = 0

for i in range(1,len(S)):
    if s != S[i:i+1]:
        ans += 1
        s = S[i:i+1]
        print(s)

print(ans)
    

Failing test case input:
ZVXXBDABWB

Expected output:
8


Actual output:
V
X
B
D
A
B
W
B
8


Fixed submission (verdict: Accepted):
S = input()
s = S[0:1]
ans = 0

for i in range(1,len(S)):
    if s != S[i:i+1]:
        ans += 1
        s = S[i:i+1]

print(ans)

Problem: p03945
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
b = input()
d = []
isWhite = False
cnt = 0
for i in range(len(b)-1):
  if b[i] != b[i+1]:
    d.append(cnt)
  else:
    cnt+=1

print(len(d)-1)
  
  


Failing test case input:
XWCADWAXWB

Expected output:
9


Actual output:
8


Fixed submission (verdict: Accepted):
b = input()
d = []
isWhite = False
cnt = 0
for i in range(len(b)-1):
  if b[i] != b[i+1]:
    d.append(cnt)
  else:
    cnt+=1

print(len(d))

Problem: p03945
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()

count = 0
for i in range(len(s)):
  now = s[i]
  if now != s[i]:
    count += 1
print(count)

Failing test case input:
BCWAWCAVWX

Expected output:
9


Actual output:
0


Fixed submission (verdict: Accepted):
s = input()
 
count = 0
now = s[0]
for i in range(len(s)):
  if now != s[i]:
    count += 1
    now = s[i]
print(count)

Problem: p03945
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys

s = input()

before = s[0]
ans = 0
for cx in range(1, len(s)):
    if before != s[cx]:
        ans += 1
        before = s[cx]

print(abs)


Failing test case input:
BBBWW

Expected output:
1

Actual output:
<built-in function abs>


Fixed submission (verdict: Accepted):
import sys

s = input()

before = s[0]
ans = 0
for cx in range(1, len(s)):
    if before != s[cx]:
        ans += 1
        before = s[cx]

print(ans)
Problem: p02559
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


class BinaryIndexTree:
    def __init__(self, n):
        self.size = n
        self._container = [0] * (n + 1)
        self.depth = n.bit_length()

    def sum(self, i):
        if i == 0:
            return 0
        s = 0
        while i > 0:
            s += self._container[i]
            i -= i & (-i)
        return s

    def add(self, i, x):
        if i == 0:
            return
        while i <= self.size:
            self._container[i] += x
            i += i & (-i)

    def lower_bound(self, x):
        if x == 0:
            return 0

        s = 0
        idx = 0
        for i in range(self.depth, -1, -1):
            k = idx + (1 << i)
            if k <= self.size and s + self._container[k] < x:
                s += self._container[k]
                idx += 1 << i
        return idx + 1

    def __repr__(self):
        return str(self._container)


def main():
    N, Q = map(int, readline().split())
    a = list(map(int, readline().split()))
    bit = BinaryIndexTree(N + 1)

    for i, x in enumerate(a, 1):
        bit.add(i, x)

    for _ in range(Q):
        a, b, c = map(int, readline().split())
        if a == 0:
            bit.add(b, c)
        else:
            b += 1
            c += 1
            print(bit.sum(c - 1) - bit.sum(b - 1))


if __name__ == '__main__':
    main()


Failing test case input:
5 5
1 0 5 4 5
1 1 2
1 2 4
0 3 10
1 0 5
1 0 3

Expected output:
0
9
25
6


Actual output:
0
9
25
16


Fixed submission (verdict: Accepted):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


class BinaryIndexTree:
    def __init__(self, n):
        self.size = n
        self._container = [0] * (n + 1)
        self.depth = n.bit_length()

    def sum(self, i):
        if i == 0:
            return 0
        s = 0
        while i > 0:
            s += self._container[i]
            i -= i & (-i)
        return s

    def add(self, i, x):
        if i == 0:
            return
        while i <= self.size:
            self._container[i] += x
            i += i & (-i)

    def lower_bound(self, x):
        if x == 0:
            return 0

        s = 0
        idx = 0
        for i in range(self.depth, -1, -1):
            k = idx + (1 << i)
            if k <= self.size and s + self._container[k] < x:
                s += self._container[k]
                idx += 1 << i
        return idx + 1

    def __repr__(self):
        return str(self._container)


def main():
    N, Q = map(int, readline().split())
    a = list(map(int, readline().split()))
    bit = BinaryIndexTree(N + 1)

    for i, x in enumerate(a, 1):
        bit.add(i, x)

    for _ in range(Q):
        a, b, c = map(int, readline().split())
        if a == 0:
            b += 1
            bit.add(b, c)
        else:
            b += 1
            c += 1
            print(bit.sum(c - 1) - bit.sum(b - 1))


if __name__ == '__main__':
    main()
Problem: p02616
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N,K=map(int, input().split())
A=list(map(int, input().split()))
D=[]
zcnt,scnt,fcnt=0,0,0
for i in A:
  if i==0:
    zcnt+=1
    D.append((i,0))
  elif i>0:
    D.append((i,0))
    scnt+=1
  else:
    D.append((-i,1))
    fcnt+=1
D=D[::-1]
mod=10**9+7
ans=1
seihu=0
f,s,z=fcnt,scnt,zcnt
X,Y,Z=[],[],[]
for i in range(K):
  ans*=D[i][0]
  ans%=mod
  seihu+=D[i][1]
  if D[i][0]!=0 and D[i][1]==1:
    fcnt-=1
    Y.append(-D[i][0])
  elif D[i][0]!=0 and D[i][1]==0:
    scnt-=1
    X.append(D[i][0])
  else:
    zcnt-=1
F=D[K:]
if seihu%2==0:
  print(ans)
else:
  C=[]
  if len(X)>0 and fcnt>0:
    
    for a,b in F:
      if b==1:
        g=-a
        break
    h=(ans*(pow(X[-1],mod-2,mod))*g)%mod
    C.append(h)
  if len(Y)>0 and scnt>0:
    
    for a,b in F:
      if b==0:
        g=a
        break
    h=(ans*(pow(Y[-1],mod-2,mod))*g)%mod
    C.append(h)
  if zcnt>0:
    C.append(0)
  if len(C)==0:
    ans=1
    D=D[::-1]
    for i in range(K):
      ans*=(-D[i][0])
      ans%=mod
    print(ans)
  else:
    print(max(C))

Failing test case input:
10 2
1000000000 100001000 10000000 1000000 100000 10000 1000 100 10 1

Expected output:
299993007


Actual output:
10


Fixed submission (verdict: Accepted):
N,K=map(int, input().split())
A=list(map(int, input().split()))
D,E=[],[]
zcnt,scnt,fcnt=0,0,0
for i in A:
  if i==0:
    zcnt+=1
    D.append(0)
  elif i>0:
    D.append(i)
    scnt+=1
  else:
    E.append(i)
    fcnt+=1
mod=10**9+7
ans=1

if K==N:
  for i in A:
    ans*=i
    ans%=mod
  print(ans)
  exit()

if K%2==1 and max(A)<0:
  A=sorted(A)[::-1]
  for i in range(K):
    ans*=A[i]
    ans%=mod
  print(ans)
  exit()

if K>scnt+fcnt:
  print(0)
  exit()
D,E=sorted(D)[::-1],sorted(E)

ans=1
cnt=0
a,b=0,0
while K-cnt>1:
  if a+1<=len(D)-1 and b+1<=len(E)-1:
    d,e=D[a]*D[a+1],E[b]*E[b+1]
    if d>e:
      ans*=D[a]
      a+=1
      cnt+=1
      ans%=mod
    else:
      ans*=e
      b+=2    
      ans%=mod
      cnt+=2
  elif a+1<=len(D)-1:
    d=D[a]*D[a+1]
    ans*=D[a]
    a+=1
    cnt+=1
    ans%=mod
  elif b+1<=len(E)-1:
    e=E[b]*E[b+1]
    ans*=e
    b+=2
    cnt+=2
    ans%=mod

if K-cnt==1:
  Z=[]
  if a!=scnt:
    Z.append(D[a])
  if b!=fcnt:
    Z.append(E[-1])
  if 0 in A:
    Z.append(0)
  ans*=max(Z)
  ans%=mod
print(ans)
Problem: p02616
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()
N,K=map(int,input().split())

A=list(map(int,input().split()))
mod=10**9+7
Am=[-i for i in A if i<0]
Ap=[i for i in A if i>=0]

Am.sort()
Ap.sort()
Am=deque(Am)
Ap=deque(Ap)



if N-K==0 and len(Am)%2==0 or len(Ap)==0 and K%2:
    c=1
    while K and (Am or Ap) :
        if Am and Ap:
            if Am[0]<Ap[0]:
                c*=Am.popleft()
            else:
                c*=Ap.popleft()
        elif Am:
            c*=Am.popleft()
        elif Ap:
            c*=Ap.popleft()
        K-=1
        c=-c
        c%=mod
    

else:
    c=1
    h=0
    w=0
    a="unko"
    b="unko"
    while K and (Am or Ap) :
        if K==1 and len(Ap)==0:
            break
        while K and (Am or Ap) :
            if Am and Ap:
                if Am[0]>Ap[0]:

                    a=Am.pop()
                    c*=a
                    h+=1
                else:

                    b=Ap.pop()
                    c*=b

            elif Am:
                a=Am.pop()
                c*=a
                h+=1
            elif Ap:
                b=Ap.pop()
                c*=b
            K-=1
            c%=mod
    


print(c%mod)


Failing test case input:
4 2
1 2 -4 -1

Expected output:
4


Actual output:
2


Fixed submission (verdict: Accepted):
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()
N,K=map(int,input().split())

A=list(map(int,input().split()))
mod=10**9+7
Am=[-i for i in A if i<0]
Ap=[i for i in A if i>=0]

Am.sort()
Ap.sort()
Am=deque(Am)
Ap=deque(Ap)



if N==K:
    c=1
    for a in A:
        c*=a
        c%=mod

elif len(Ap)==0 and K%2:
    c=1
    while K :
        c*=Am.popleft()

        K-=1

        c%=mod
    c=-c
    c%=mod
    

else:
    
    c=1
    h=0
    a="unko"
    b="unko"
    while K and (Am or Ap) :
        if Am and Ap:
            if Am[-1]>Ap[-1]:

                a=Am.pop()
                c*=a
                h+=1
            else:

                b=Ap.pop()
                c*=b

        elif Am:
            a=Am.pop()
            c*=a
            h+=1
        elif Ap:
            b=Ap.pop()
            c*=b
        K-=1
        c%=mod

    if h%2:
        if Am and Ap and a!="unko" and b!="unko":
            if Am[-1]*a>Ap[-1]*b:
                a=Am.pop()
                c*=a
                c*=pow(b,mod-2,mod)
            else:
                b=Ap.pop()
                c*=b
                c*=pow(a,mod-2,mod)
        elif Am and b!="unko":
            a=Am.pop()
            c*=a
            c*=pow(b,mod-2,mod)
        else:
            b=Ap.pop()
            c*=b
            c*=pow(a,mod-2,mod)


print(c%mod)
Problem: p02616
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from collections import deque

N, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
MOD = 10 ** 9 + 7
A_p = []
A_n = []
for a in A:
  if a >= 0:
    A_p.append(a)
  else:
    A_n.append(-a)

A_p.sort(reverse=True)
A_n.sort(reverse=True)
A_p = deque(A_p)
A_n = deque(A_n)

p_top = 0
n_top = 0
ans_p = deque([])
ans_n = deque([])
for i in range(K):
  if len(A_p) == 0:
    ans_n.append(A_n.popleft())
  elif len(A_n) == 0:
    ans_p.append(A_p.popleft())
  elif A_p[0] >= A_n[0]:
    ans_p.append(A_p.popleft())
  else:
    ans_n.append(A_n.popleft())
if 0 in ans_p:
  ans = 0
elif len(ans_n) % 2 == 1:
  if len(ans_p) == 0 and len(A_p) > 0:
    ans_n.pop()
    ans_p.append(A_p.popleft())
  elif len(ans_n) == 0 and len(A_n) > 0:
    ans_p.pop()
    ans_n.append(A_n.popleft())
  elif len(ans_p) > 0 and len(ans_n) > 0 and len(A_p) > 0 and len(A_n) > 0 and ans_p[-1] * A_p[0] >= ans_n[-1] * A_n[0]:
    ans_n.pop()
    ans_p.append(A_p.popleft())
  elif len(ans_p) > 0 and len(A_n) > 0:
    ans_p.pop()
    ans_n.append(A_n.popleft())
ans = 1
for a in ans_p:
  ans = (a * ans) % MOD
for a in ans_n:
  ans = (-a * ans) % MOD
if ans != 0 and len(ans_n) % 2 == 1:
  ans = 1
  A_abs = [abs(a) for a in A]
  A_abs.sort()
  for i in range(K):
    ans = (ans * A_abs[i]) % MOD
  ans = (-ans) % MOD
print(ans)




Failing test case input:
4 2
1 2 -3 0

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):
from collections import deque

N, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
MOD = 10 ** 9 + 7
A_p = []
A_n = []
for a in A:
  if a >= 0:
    A_p.append(a)
  else:
    A_n.append(-a)

A_p.sort(reverse=True)
A_n.sort(reverse=True)
A_p = deque(A_p)
A_n = deque(A_n)

p_top = 0
n_top = 0
ans_p = deque([])
ans_n = deque([])
for i in range(K):
  if len(A_p) == 0:
    ans_n.append(A_n.popleft())
  elif len(A_n) == 0:
    ans_p.append(A_p.popleft())
  elif A_p[0] >= A_n[0]:
    ans_p.append(A_p.popleft())
  else:
    ans_n.append(A_n.popleft())
if len(ans_n) % 2 == 1:
  if len(ans_p) == 0 and len(A_p) > 0:
    ans_n.pop()
    ans_p.append(A_p.popleft())
  elif len(ans_n) == 0 and len(A_n) > 0:
    ans_p.pop()
    ans_n.append(A_n.popleft())
  elif len(ans_p) > 0 and len(ans_n) > 0 and len(A_p) > 0 and len(A_n) > 0 and ans_p[-1] * A_p[0] >= ans_n[-1] * A_n[0]:
    ans_n.pop()
    ans_p.append(A_p.popleft())
  elif len(ans_p) > 0 and len(A_n) > 0:
    ans_p.pop()
    ans_n.append(A_n.popleft())
  elif len(ans_n) > 0 and len(A_p) > 0:
    ans_n.pop()
    ans_p.append(A_p.popleft())
ans = 1
for a in ans_p:
  ans = (a * ans) % MOD
for a in ans_n:
  ans = (-a * ans) % MOD
if ans != 0 and len(ans_n) % 2 == 1:
  ans = 1
  A_abs = [abs(a) for a in A]
  A_abs.sort()
  for i in range(K):
    ans = (ans * A_abs[i]) % MOD
  ans = (-ans) % MOD
print(ans)
Problem: p02616
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n, k = map(int,input().split())
a = list(map(int,input().split()))
mod = 10**9 + 7

plus = []
minus = []

for i in a:
	if i >= 0:
		plus.append(i)
	else:
		minus.append(i)

plus.sort()
minus.sort(key=lambda x:-x)




numplus = k
numminus = 0


while numplus > len(plus):
	numplus -= 2
	numminus += 2

tmpminus = -1



while numplus-2 >= 0 and numminus+1 < len(minus):
	if plus[numplus-1] * plus[numplus-2] <= minus[numminus] * minus[numminus+1]:
		numplus -= 2
		numminus += 2
		tmpminus = numminus
	else:
		break



ans = 1
if tmpminus != -1:
	for i in range(numplus):
		ans = ans * plus[i] % mod
	for i in range(numminus):
		ans = ans * minus[i] % mod
else:
	
	
	tmp = sorted(a, key=lambda x:-x)
	for i in range(k):
		ans = ans * tmp[i]%mod

print(ans)

Failing test case input:
4 2
-1 -2 -2 -4

Expected output:
8


Actual output:
2


Fixed submission (verdict: Accepted):
n, k = map(int,input().split())
a = list(map(int,input().split()))
mod = 10**9 + 7

plus = []
minus = []

for i in a:
	if i >= 0:
		plus.append(i)
	else:
		minus.append(i)

plus.sort(key = lambda x:-x)
minus.sort()





numplus = k
numminus = 0


while numplus > len(plus):
	numplus -= 2
	numminus += 2



while numplus-2 >= 0 and numminus+1 < len(minus):
	if plus[numplus-1] * plus[numplus-2] <= minus[numminus] * minus[numminus+1]:
		numplus -= 2
		numminus += 2
	else:
		break



ans = 1

if numplus >= 0 and numminus >= 0 and numminus <= len(minus) and numplus <= len(plus):
	for i in range(numplus):
		ans = ans * plus[i] % mod
	for i in range(numminus):
		ans = ans * minus[i] % mod
else:
	
	
	tmp = sorted(a, key=lambda x:-x)
	for i in range(k):
		ans = ans * tmp[i]%mod

print(ans)
Problem: p02616
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N, K = map(int, input().split(' '))
A = sorted(list(map(int, input().split(' '))))
mod = 10 ** 9 + 7
p = 0
for i in range(N):
    if A[i] >= 0:
        break
p = i
if (p==N-1 and K%2 != 0) or (N==K and p%2 == 0):
    ans = 1
    for i in range(K):
        ans *= A[-1-i]
        ans %= mod
    print(ans)
    exit()
minus = A[:p]
plus = A[p:]
len_m = len(minus)
len_p = len(plus)
m = 0
p = 0
ans = 1
while K > 0:
    if K >= 2 and m <= len_m - 2 and p <= len_p - 2:
        if minus[m] * minus[m] >= plus[p] * plus[p + 1]:
            ans *= minus[m] * minus[m+1]
            ans %= mod
            m += 2
        else:
            ans *= plus[p] * plus[p + 1]
            ans %= mod
            p += 2
        K -= 2
    elif K >= 2 and m <= len_m-2:
        ans *= minus[m] * minus[m+1]
        ans %= mod
        m += 2
        K -= 2
    elif K >= 2 and p <= len_p-2:
        ans *= plus[p] * plus[p + 1]
        ans %= mod
        p += 2
        K -= 2
    elif p <= len_p -1:
        ans *= plus[p]
        ans %= mod
        p += 1
        K -= 1
    else:
        ans *= minus[m]
        ans %= mod
        m += 1
        K -= 1
print(ans)

Failing test case input:
4 2
1 2 -3 0

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):
N, K = map(int, input().split(' '))
A = sorted(list(map(int, input().split(' '))))
mod = 10 ** 9 + 7
p = 0
for i in range(N):
    if A[i] >= 0:
        break
p = i
if (p == N - 1 and K % 2 != 0):
    ans = 1
    for i in range(K):
        ans *= A[-1 - i]
        ans %= mod
    print(ans%mod)
    exit()
minus = A[:p]
plus = sorted(A[p:],reverse=True)
len_m = len(minus)
len_p = len(plus)
m = 0
p = 0
ans = 1
while K > 0:
    if K >= 2 and m <= len_m - 2 and p <= len_p - 2:
        if minus[m] * minus[m+1] >= plus[p] * plus[p + 1]:
            ans *= minus[m] * minus[m + 1]
            ans %= mod
            m += 2
        else:
            ans *= plus[p] * plus[p + 1]
            ans %= mod
            p += 2
        K -= 2
    elif K >= 2 and m <= len_m - 2:
        ans *= minus[m] * minus[m + 1]
        ans %= mod
        m += 2
        K -= 2
    elif K >= 2 and p <= len_p - 2:
        ans *= plus[p] * plus[p + 1]
        ans %= mod
        p += 2
        K -= 2
    elif p <= len_p - 1:
        ans *= plus[p]
        ans %= mod
        p += 1
        K -= 1
    else:
        ans *= minus[m]
        ans %= mod
        m += 1
        K -= 1
print(ans%mod)
Problem: p02616
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
A.sort(key=lambda x:-abs(x))
mod=10**9+7


ans=1
flg=1
flgcnt=0
save=1

if k==1:
    print(max(A)%mod)
elif max(A)<0:
    ans=1
    for i in range(k):
        ans=ans*A[n-1-i]%mod
    print(ans)
else:
    
    for i in range(k-2):
        now=A[i]
        if now <0:
            flg*=-1
            flgcnt+=1
        ans=ans*now%mod
        if i==k-3:
            save=ans
            
    pl=[]
    mi=[]
    for i in range(k-2,n):
        now=A[i]
        if now<0:
            if len(mi)<2:
                mi.append(now)
        else:
            if len(pl)<2:
                pl.append(now)
        if len(pl)==2 and len(mi)==2:
            break
    
    ck=pl+mi
    can=[]
    for i in range(len(ck)-1):
        for q in range(i+1,len(ck)):
            can.append(ck[i]*ck[q])
    can.sort()
    
    if flg>0:
        print(save*can[-1]%mod)
    else:
        print(save*can[0]%mod)
            
    
    


Failing test case input:
4 2
-1 -2 -2 -4

Expected output:
8


Actual output:
2


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
A.sort(key=lambda x:-abs(x))
mod=10**9+7

ans=1
if (max(A)<=0 and k%2==1) or n==k:
    for i in range(k):
        ans=ans*A[n-1-i]%mod
else:
    mi=0
    pl=0
    flg=1
    for i in range(k):
        ans=ans*A[i]%mod
        if A[i]>0:
            pl=A[i]
        if A[i]<0:
            mi=A[i]
            flg*=-1
    if ans==0:
        pass
    elif flg==-1:
        mi2=None
        pl2=None
        for i in range(k,n):
            if A[i]>=0:
                pl2=A[i]
                break
        for i in range(k,n):
            if A[i]<=0:
                mi2=A[i]
                break
        can=0
        if mi!=0 and pl2 is not None and pl!=0 and mi2 is not None:
            if pl2*pl > mi2*mi:
                can = pow(mi,-1,mod)*pl2%mod
            else:
                can = pow(pl,-1,mod)*mi2%mod
        elif mi!=0 and pl2 is not None:
            can = pow(mi,-1,mod)*pl2%mod
        elif pl!=0 and mi2 is not None:
            can = pow(pl,-1,mod)*mi2%mod 
        ans=ans*can%mod

print(ans)
Problem: p02697
Buggy submission (Python (3.8.2), verdict: Wrong Answer):

N, M = map(int, input().split())


ans = []
t = 1
for i in range(M):
    ans.append((t, N-t))
    t += 1


[print(a, b) for a, b in ans]


Failing test case input:
20 9

Expected output:
1 10
2 9
3 8
4 7
5 6
11 19
12 18
13 17
14 16


Actual output:
1 19
2 18
3 17
4 16
5 15
6 14
7 13
8 12
9 11


Fixed submission (verdict: Accepted):

N, M = map(int, input().split())


ans = []

t = 1
for _ in range(M
    ans.append((t, M-t+1))
    t += 1

t = M+1
for _ in range(-(-M
    ans.append((t, M*3+2-t))
    t += 1


[print(a, b) for a, b in ans]

Problem: p02697
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from collections import defaultdict,deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
    
    return int(input())
def inpl():
    
    return list(map(int, input().split()))


n, m = inpl()
j_list = [1]
i=3
while len(j_list) < m:
    if n%i!=0:
        j_list.append(i)
    i += 2

for i in range(m):
    print("{} {}".format(i+1,i+j_list[-i-1]+1))


Failing test case input:
12 5

Expected output:
1 6
2 5
3 4
7 11
8 10


Actual output:
1 12
2 11
3 10
4 9
5 6


Fixed submission (verdict: Accepted):
from collections import defaultdict,deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
    
    return int(input())
def inpl():
    
    return list(map(int, input().split()))


n, m = inpl()
n = 2 * m + 1

for i in range(m
    print(i + 1, m - i)

base=m+1
for i in range((n-m)
    print(base + i, n - i)

Problem: p02697
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n,m = map(int,input().split())
ANS = [[0] * 2 for i in range(m)]

a = 0
b = 1
for i in range(m):
    if i*4 == n:
        b = (b+1) % n
    ANS[i] = [a, b]
    a = (a-1) % n
    b = (b+1) % n
    

for i in range(m):
    print(ANS[i][0]+1, ANS[i][1]+1)

Failing test case input:
19 9

Expected output:
1 10
2 9
3 8
4 7
5 6
11 19
12 18
13 17
14 16


Actual output:
1 2
19 3
18 4
17 5
16 6
15 7
14 8
13 9
12 10


Fixed submission (verdict: Accepted):
n,m = map(int,input().split())
ANS = [[0] * 2 for i in range(m)]

a = 0
b = 1
c = 0
f = 1
for i in range(m):
    if n%2 == 0 and (c+2) > n
        b = (b+1) % n
        f = 0
    ANS[i] = [a, b]
    c += 2
    a = (a-1) % n
    b = (b+1) % n
    

for i in range(m):
    print(ANS[i][0]+1, ANS[i][1]+1)
Problem: p02697
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import deque
from itertools import product
import sys
import math

sys.setrecursionlimit(200000)
input = sys.stdin.readline


def read():
    N, M = map(int, input().strip().split())
    return N, M


def solve(N, M):
    pairs = []
    n = N 
    for m in range(M):
        pairs.append((m+1, n-m))
    
    for a, b in pairs:
        print(a, b)

if __name__ == '__main__':
    inputs = read()
    solve(*inputs)


Failing test case input:
20 9

Expected output:
1 10
2 9
3 8
4 7
5 6
11 19
12 18
13 17
14 16


Actual output:
1 20
2 19
3 18
4 17
5 16
6 15
7 14
8 13
9 12


Fixed submission (verdict: Accepted):
from collections import deque
from itertools import product
import sys
import math

sys.setrecursionlimit(200000)
input = sys.stdin.readline


def read():
    N, M = map(int, input().strip().split())
    return N, M


def solve(N, M):
    H = (N-1) 
    LL = 0
    LR = (H 
    RL = N - (H - H
    RR = N
    pairs = []
    while LR - LL > 1:
        pairs.append((LL+1, LR))
        LL += 1
        LR -= 1
    while RR - RL > 1:
        pairs.append((RL+1, RR))
        RL += 1
        RR -= 1
    for i in range(M):
        print(*pairs[i])


if __name__ == '__main__':
    inputs = read()
    solve(*inputs)

Problem: p02697
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N, M = map(int, input().split())

for m in range(1, M + 1):
    if N % 2 is 1:
        print(m, N - m + 1)
    else:
        start = m
        end = N / 2 - m
        if start >= end:
            start = N / 2 + 1
            end = N - m + 1
        print(start, end)


Failing test case input:
12 5

Expected output:
1 6
2 5
3 4
7 11
8 10


Actual output:
1 5.0
2 4.0
7.0 10
7.0 9
7.0 8


Fixed submission (verdict: Accepted):
N, M = map(int, input().split())

if N % 2 == 1:
    for m in range(1, M + 1):
        print(m, N - m + 1)

count = 1
if N % 2 == 0:
    for m in range(1, M + 1):

        if m <= (N 
            start = m
            end = N 
            print(start, end)
        else:
            start = N 
            end = N - count + 1
            print(start, end)
            count += 1
Problem: p02697
Buggy submission (Python (3.8.2), verdict: Wrong Answer):



import sys


sys.setrecursionlimit(10 ** 9)


mod = 10**9+7


N, M = map(int,input().split())







odd = (N % 2 != 0)
ans = []
if odd:
    x = N - 1
else:
    x = N

for i in range(M):
    ans.append([i+1,x])
    x -= 1

for a in ans:
    print(' '.join(map(str,a)))
    

Failing test case input:
24 11

Expected output:
1 12
2 11
3 10
4 9
5 8
6 7
13 23
14 22
15 21
16 20
17 19


Actual output:
1 24
2 23
3 22
4 21
5 20
6 19
7 18
8 17
9 16
10 15
11 14


Fixed submission (verdict: Accepted):



import sys


sys.setrecursionlimit(10 ** 9)


mod = 10**9+7


N, M = map(int,input().split())







odd = (N % 2 != 0)
ans = []
if odd:
    x = N - 1
    for i in range(M):
        ans.append([i+1,x])
        x -= 1
else:
    x = N
    flg = True
    for i in range(M):
        if flg and x - (i+1) <= N
            x -= 1
            flg = False
        ans.append([i+1,x])
        x -= 1





for a in ans:
    print(' '.join(map(str,a)))

Problem: p02697
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n,m=map(int,input().split())
g=m
k=m-g
for i in range(m):
    if i%2==1:
        print(n-g-i-1,n-g+i+1)
    else:
        print(k-i,k+i+1)


Failing test case input:
15 7

Expected output:
1 8
2 7
3 6
4 5
9 15
10 14
11 13


Actual output:
0 1
6 10
-2 3
4 12
-4 5
2 14
-6 7


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
g=m
k=m-g
for i in range(m):
    if i%2==1:
        a=n-g-((i+1)
        b=a+i+1
        print(a,b)
    else:
        a=k-(i
        b=a+i+1
        print(a,b)

Problem: p02697
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N, M = map(int, input().split())
l = N
r = 1
d = 1
for i in range(M):
    print(l, r)
    l-=1
    r+=1
    if min(l-r, N-l+r)==d: 
        r+=1
    d = min(l-r, N-l+r)


Failing test case input:
20 9

Expected output:
1 10
2 9
3 8
4 7
5 6
11 19
12 18
13 17
14 16


Actual output:
20 1
19 2
18 3
17 4
16 5
15 7
14 8
13 9
12 10


Fixed submission (verdict: Accepted):
N, M = map(int, input().split())
l = N
r = 1
for i in range(M):
    if N%4==0 and i*4==N: r+=1
    if N%2==0 and l-r==N
    print(l, r)
    l-=1
    r+=1

Problem: p02697
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N, M = [int(_) for _ in input().split()]
se = set()
ans = []
d = 1
for i in range(1, N + 1):
    if i in se:
        continue
    j = (i + d) % N
    ans += [i, j]
    se.add(i)
    se.add(j)
    d += 1
ans = ans[:2 * M]
print('\n'.join(f'{i} {j}' for i, j in zip(ans[::2], ans[1::2])))


Failing test case input:
15 7

Expected output:
1 8
2 7
3 6
4 5
9 15
10 14
11 13


Actual output:
1 2
3 5
4 7
6 10
8 13
9 0
11 3


Fixed submission (verdict: Accepted):
N, M = [int(_) for _ in input().split()]
l = 1
r = N
ans = []
for _ in range(M - M 
    ans += [l, r]
    l += 1
    r -= 1
if (r - l) % 2 == (l + N - r) % 2:
    r -= 1
for _ in range(M 
    ans += [l, r]
    l += 1
    r -= 1
ans = ans[:2 * M]
print('\n'.join(f'{a} {b}' for a, b in zip(ans[::2], ans[1::2])))
Problem: p02697
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
inf = 10**15
mod = 10**9+7
n,m = map(int, input().split())
if n % 2 == 0:
    tmp = n
    for i in range(m):
        print('{} {}'.format(tmp-i, tmp+1+i))
else:
    tmp = n
    for i in range(m):
        print('{} {}'.format(tmp-i, tmp+1+i))

Failing test case input:
24 11

Expected output:
1 12
2 11
3 10
4 9
5 8
6 7
13 23
14 22
15 21
16 20
17 19


Actual output:
24 25
23 26
22 27
21 28
20 29
19 30
18 31
17 32
16 33
15 34
14 35


Fixed submission (verdict: Accepted):
inf = 10**15
mod = 10**9+7
n,m = map(int, input().split())
tmp = n
for i in range(m):
    if i % 2 == 0:
        print('{} {}'.format(tmp-i
    else:
        print('{} {}'.format(1+i
Problem: p04014
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
s=int(input())

b_ans=1

if n==s:
  b_ans=n+1
if b_ans==1:
  for b in range(2,int(n**0.5)+1):
    nn=n
    st=[]
    while(nn>0):
      st.append(nn%b)
      nn=(nn-st[-1])/b
  
    if sum(st)==s:
      b_ans=b
      break


if b_ans==1:
  for p in range(1,int(n**0.5)):
    b=int(n/p)
    q=n-p*b
    if s==p+q and q<b:
      b_ans=b
      break

if b_ans!=1:
  print(b_ans)
else:
  print(-1)

Failing test case input:
87654
4

Expected output:
43826


Actual output:
-1


Fixed submission (verdict: Accepted):
n=int(input())
s=int(input())

b_ans=1



if n==s:
  b_ans=n+1
if b_ans==1:
  for b in range(2,int(n**0.5)+1):
    nn=n
    st=[]
    while(nn>0):
      st.append(nn%b)
      nn=(nn-st[-1])/b
  
    if sum(st)==s:
      b_ans=b
      break

if b_ans==1:
  for p in range(int(n**0.5),0,-1):
    b=(n-s+p)/p

    if b.is_integer() and 0<=s-p<b and b>n**0.5:
      b_ans=int(b)
      break

if b_ans!=1:
  print(b_ans)
else:
  print(-1)

Problem: p04014
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
s=int(input())

b_ans=1



if n==s:
  b_ans=n+1
if b_ans==1:
  for b in range(2,int(n**0.5)+1):
    nn=n
    st=[]
    while(nn>0):
      st.append(nn%b)
      nn=(nn-st[-1])/b
  
    if sum(st)==s:
      b_ans=b
      break


if b_ans==1:
  for p in range(int(n**0.5),0,-1):
    b=(n-s+p)/p

    if b.is_integer():
      b_ans=int(b)
      break

if b_ans!=1:
  print(b_ans)
else:
  print(-1)

Failing test case input:
31415926535
3

Expected output:
15707963267


Actual output:
7853981634


Fixed submission (verdict: Accepted):
n=int(input())
s=int(input())

b_ans=1



if n==s:
  b_ans=n+1
if b_ans==1:
  for b in range(2,int(n**0.5)+1):
    nn=n
    st=[]
    while(nn>0):
      st.append(nn%b)
      nn=(nn-st[-1])/b
  
    if sum(st)==s:
      b_ans=b
      break

if b_ans==1:
  for p in range(int(n**0.5),0,-1):
    b=(n-s+p)/p

    if b.is_integer() and 0<=s-p<b and b>n**0.5:
      b_ans=int(b)
      break

if b_ans!=1:
  print(b_ans)
else:
  print(-1)