Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import math

N,K = map(int, input().split())
A = list(map(int, input().split()))
epsilon = 10**(-9)
#A = [a-epsilon for a in A]

_min = 0
_max = max(A)

while _max - _min > epsilon:
  new = (_min+_max)/2
  if _min < int(new):
    new = int(new)
  times = sum([math.ceil(a/new)-1 for a in A])
  #print(_min, new, _max, times, [math.ceil(a/new)-1 for a in A])
  
  if times <= K:
    _max = new
  else:
    _min = new
  #print(_min, _max)

if  sum([math.ceil(a/_max)-1 for a in A]) <= K:
  print(math.ceil(_max))
else:
  print(math.ceil(_min))

Fixed submission:
import math

N,K = map(int, input().split())
A = list(map(int, input().split()))
epsilon = 10**(-5)
#A = [a-epsilon for a in A]

_min = 0
_max = max(A)

while _max - _min > epsilon:
  new = (_min+_max)/2
  if _min < int(new):
    new = int(new)
  times = sum([math.ceil(a/new)-1 for a in A])
  #print(_min, new, _max, times, [math.ceil(a/new)-1 for a in A])
  
  if times <= K:
    _max = new
  else:
    _min = new
  #print(_min, _max)

if  sum([math.ceil(a/_max)-1 for a in A]) <= K:
  print(math.ceil(_max))
else:
  print(math.ceil(_min))

Buggy python submission (verdict: Time Limit Exceeded):
import math

N,K = map(int, input().split())
A = list(map(int, input().split()))
#epsilon = 10**(-9)
#A = [a-epsilon for a in A]

_min = 0
_max = max(A)

while int(_min)<int(_max):
  new = (_min+_max)/2
  if _min < int(new):
    new = int(new)
  times = sum([math.ceil(a/new)-1 for a in A])
  #print(_min, new, _max, times, [math.ceil(a/new)-1 for a in A])
  
  if times <= K:
    _max = new
  else:
    _min = new
  #print(_min, _max)

print(math.ceil(_max))

Fixed submission:
import math

N,K = map(int, input().split())
A = list(map(int, input().split()))
epsilon = 10**(-5)
#A = [a-epsilon for a in A]

_min = 0
_max = max(A)

while _max - _min > epsilon:
  new = (_min+_max)/2
  if _min < int(new):
    new = int(new)
  times = sum([math.ceil(a/new)-1 for a in A])
  #print(_min, new, _max, times, [math.ceil(a/new)-1 for a in A])
  
  if times <= K:
    _max = new
  else:
    _min = new
  #print(_min, _max)

if  sum([math.ceil(a/_max)-1 for a in A]) <= K:
  print(math.ceil(_max))
else:
  print(math.ceil(_min))
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
S = S[::-1]

dp = [[0]*13 for _ in range(len(S)+1)]

dp[0][0]=1

q=1
for i in range(1,len(S)+1): #i文字目，1-index
  s = S[i-1]
  if s=='?':
    for j in range(13):
      for n in range(10):
      	dp[i][(j+n*q)%13] += dp[i-1][j]
    for j in range(12):
      dp[i][j] %= 10**9+7
  else:
    n = int(s)
    for j in range(13):
      dp[i][(j+n*q)%13] = dp[i-1][j]
  q = (10*q)%13
  
print(dp[len(S)][5])

Fixed submission:
S = input()
S = S[::-1]

dp = [[0]*13 for _ in range(len(S)+1)]

dp[0][0]=1

q=1
for i in range(1,len(S)+1): #i文字目，1-index
  s = S[i-1]
  if s=='?':
    for j in range(13):
      for n in range(10):
      	dp[i][(j+n*q)%13] += dp[i-1][j]
    for j in range(12):
      dp[i][j] %= 10**9+7
  else:
    n = int(s)
    for j in range(13):
      dp[i][(j+n*q)%13] = dp[i-1][j]
  q = (10*q)%13
  
print(dp[len(S)][5])
Buggy python submission (verdict: Runtime Error):
N,K=list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N-1)]
MOD = 10**9+7

counted = [0]* (N+1) #counted[i]: ノードiはカウント済み

adjucent_dict = {}
for a,b in AB:
  adjucent_dict.setdefault(a, set()).add(b)
  adjucent_dict.setdefault(b, set()).add(a)
  
from collections import deque

dq = deque([])

for i in range(1,N+1):
  if len(adjucent_dict[i])==1:
    dq.append(i)
    
#print(dq)

ans = 1
while dq:
  v = dq.popleft()
  # assert(len(adjucent_dict[v])==1)
  parent = adjucent_dict[v].pop() #かならずlen(~)=1のはず
  adjucent_dict[parent].remove(v)
  #print(v, K - (len(adjucent_dict[parent])+1))
  ans *= K - (len(adjucent_dict[parent])+1)
  ans %= MOD
  
  if len(adjucent_dict[parent])==1:
    dq.append(parent)
  if len(adjucent_dict[parent])==0:
    ans *= K
    ans %= MOD
    break
  
print(ans)

Fixed submission:
N,K=list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N-1)]
MOD = 10**9+7

if N==1:
  print(K)
  exit()

counted = [0]* (N+1) #counted[i]: ノードiはカウント済み

adjucent_dict = {}
for a,b in AB:
  adjucent_dict.setdefault(a, set()).add(b)
  adjucent_dict.setdefault(b, set()).add(a)
  
from collections import deque

dq = deque([])

for i in range(1,N+1):
  if len(adjucent_dict[i])==1:
    dq.append(i)
    
#print(dq)

ans = K
while dq:
  v = dq.popleft()
  # assert(len(adjucent_dict[v])==1)
  parent = adjucent_dict[v].pop() #かならずlen(~)=1のはず
  adjucent_dict[parent].remove(v)
  #print(v, K - (len(adjucent_dict[parent])+1))
  ans *= max(0, K - (len(adjucent_dict[parent])+1))
  ans %= MOD
  
  if len(adjucent_dict[parent])==1:
    dq.append(parent)
  if len(adjucent_dict[parent])==0:
    break
  
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
AB = [tuple(map(int, input().split())) for _ in range(N)]
#A = [a for a,b in AB]
#B = [b for a,b in AB]
#C = list(range(N))

def merge(la, lb, key):
  na = len(la)
  nb = len(lb)
  ans = [None] * (na+nb)
  ia = 0
  ib = 0
  
  while ia<na and ib<nb:
    if key(la[ia]) < key(lb[ib]):
      ans[ia+ib] = la[ia]
      ia += 1
    else:
      ans[ia+ib] = lb[ib]
      ib += 1
      
  if ia<len(la):
    ans[ia+ib:] = la[ia:]
  if ib<len(lb):
    ans[ia+ib:] = lb[ib:]
  return ans
    
def mergeSort(x, key):
    l = len(x)
    if l <= 1:
        return x
    d = l // 2 
    left = mergeSort(x[:d], key)
    right = mergeSort(x[d:], key)
    return merge(left,right, key)

AB = mergeSort(AB, key=lambda x:x[1])

ans = "Yes"
t = 0
for a,b in AB:
    t += a
    if t > b:
        ans = "No"

print(ans)

Fixed submission:
N = int(input())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key = lambda x:x[1])

temp_total = 0
for a,b in AB:
  temp_total += a
  if temp_total<=b:
    continue
  else:
    print('No')
    break
else:
  print('Yes')

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
AB = [tuple(map(int, input().split())) for _ in range(N)]
A = [a for a,b in AB]
B = [b for a,b in AB]
C = list(range(N))

def val(x):
  return B[x]

def merge(la, lb):
  na = len(la)
  nb = len(lb)
  ans = [None] * (na+nb)
  ia = 0
  ib = 0
  
  while ia<na and ib<nb:
    if val(la[ia]) < val(lb[ib]):
      ans[ia+ib] = la[ia]
      ia += 1
    else:
      ans[ia+ib] = lb[ib]
      ib += 1
      
  if ia<len(la):
    ans[ia+ib:] = la[ia:]
  if ib<len(lb):
    ans[ia+ib:] = lb[ib:]
  return ans
    
def mergeSort(x):
    l = len(x)
    if l <= 1:
        return x
    d = l // 2 
    left = mergeSort(x[:d])
    right = mergeSort(x[d:])
    return merge(left,right)

C = mergeSort(C)

ans = "Yes"
t = 0
for i in range(N):
    t += A[C[i]]
    if t > B[C[i]]:
        ans = "No"

print(ans)



Fixed submission:
N = int(input())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key = lambda x:x[1])

temp_total = 0
for a,b in AB:
  temp_total += a
  if temp_total<=b:
    continue
  else:
    print('No')
    break
else:
  print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
N,M = list(map(int, input().split()))
S = list(map(int, input().split())) #N
T = list(map(int, input().split())) #M

MOD = 10**9+7

dp = [[0]*M for _ in range(N)]
# dp[n][m] Sのn文字目，Tのm文字目までの場合の数

dp[0][0] = 1 + int(S[0] == T[0])

for i in range(1,N):
  dp[i][0] = dp[i-1][0] + int(S[i]==T[0])
  
for j in range(1,M):
  dp[0][j] = dp[0][j-1] + int(T[j]==S[0])
  
for n in range(1,N):
  for m in range(1,M):
    dp[n][m] = (dp[n-1][m] + dp[n][m-1] - dp[n-1][m-1] + dp[n-1][m-1]*int(S[n]==T[m]))%MOD
    

#print(dp)
print(dp[N-1][M-1])

Fixed submission:
N,M = list(map(int, input().split()))
S = list(map(int, input().split())) #N
T = list(map(int, input().split())) #M

MOD = 10**9+7

dp = [[0]*M for _ in range(N)]
# dp[n][m] Sのn文字目，Tのm文字目までの場合の数

dp[0][0] = 1 + int(S[0] == T[0])

for i in range(1,N):
  dp[i][0] = dp[i-1][0] + int(S[i]==T[0])
  
for j in range(1,M):
  dp[0][j] = dp[0][j-1] + int(T[j]==S[0])
  
for n in range(1,N):
  for m in range(1,M):
    dp[n][m] = (dp[n-1][m] + dp[n][m-1] - dp[n-1][m-1] + dp[n-1][m-1]*int(S[n]==T[m]))%MOD
    

#print(dp)
print(dp[N-1][M-1])
Buggy python submission (verdict: Runtime Error):
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]

from itertools import permutations
from collections import Counter
l = [((A[0]-B[0]),(A[1]-B[1])) for A,B in permutations(XY,2)]
c = Counter(l)
print(N - c.most_common()[0][1] )

Fixed submission:
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]

if N==1:
  print(1)
  exit()

from itertools import permutations
from collections import Counter
l = [((A[0]-B[0]),(A[1]-B[1])) for A,B in permutations(XY,2)]
c = Counter(l)
print(N - c.most_common()[0][1] )
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
A.sort()

'''
Anega = [a for a in A if a<0]
Azero = [a for a in A if a==0]
Aposi = [a for a in A if a>0]

if len(A) == len(Anega):
  print(-sum(A[:-1]) + A[-1])
  a = A[-1]
  for i in range(2,N+1):
    print(*(a, A[-i]))
    a = a - A[-i]
    
if len(A) == len(Aposi):
  print(sum(A[1:]) - A[0])
  a = A[0]
  for i in range(1,N-1):
    print(*(a, A[i]))
    a = a-A[i]
  print(*(A[-1],a))
  
if Azero:
  print(sum(Aposi)-sum(Anega))
  for _ in range(len(Azero)-1):
    print(*(0,0))
  a = 0
  for i in range(0,len(Aposi)-1):
    print(*(a, Aposi[i]))
    a = a-Aposi[i]
  print(*(Aposi[-1],a))
  a = Aposi[-1] -a
  
  for b in Anega:
    print(*(a,b))
    a = a-b
'''
        

      
      
Anega = [a for a in A if a<=0]
Aposi = [a for a in A if a>0]

if Anega:
  print(sum(Aposi)-sum(Anega))
  temp = Anega[-1]
  for a in Aposi[:-1]:
    print(*(temp,a))
    temp = temp-a
  print(*(Aposi[-1],temp))
  temp = Aposi[-1]-temp
  for a in Anega[:-1]:
    print(*(temp,a))
    temp = temp-a
    
  
else:
  print(sum(A[1:]) - A[0])
  a = A[0]
  for i in range(1,N-1):
    print(*(a, A[i]))
    a = a-A[i]
  print(*(A[-1],a))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A.sort()

Anega = [a for a in A if a<=0]
Aposi = [a for a in A if a>0]

if Anega and Aposi:
  print(sum(Aposi)-sum(Anega))
  temp = Anega[-1]
  for a in Aposi[:-1]:
    print(*(temp,a))
    temp = temp-a
  print(*(Aposi[-1],temp))
  temp = Aposi[-1]-temp
  for a in Anega[:-1]:
    print(*(temp,a))
    temp = temp-a

elif Aposi:
  print(sum(A[1:]) - A[0])
  a = A[0]
  for i in range(1,N-1):
    print(*(a, A[i]))
    a = a-A[i]
  print(*(A[-1],a))

else:
  print(A[-1] - sum(A[:-1]))
  temp = A[-1]
  for a in A[:-1]:
    print(*(temp,a))
    temp = temp-a
Buggy python submission (verdict: Runtime Error):
H,W = list(map(int, input().split()))
S = [[1 if s=='.' else 0 for s in input()] for _ in range(H)] #S[h][w]

import numpy as np
S = np.array(S)
#print(S)

SH = np.zeros((H,W), dtype='int')
SH_ = np.zeros((H,W), dtype='int')

SV = np.zeros((H,W), dtype='int')
SV_ = np.zeros((H,W), dtype='int')

#horizontal
for h in range(H):
  SH[h][0] = S[h][0]
  for w in range(1,W):
    if S[h][w]:
      SH[h][w] = SH[h][w-1] + 1
  
  SH_[h][-1] = S[h][-1]
  for w in range(W-1)[::-1]:
    if S[h][w]:
      SH_[h][w] = SH_[h][w+1] + 1
  

#vertical
for w in range(W):
  SV[0][w] = S[0][w]
  for h in range(1,H):
    if S[h][w]:
      SV[h][w] = SV[h-1][w] + 1
  
  SV_[-1][w] = S[-1][w]
  for h in range(H-1)[::-1]:
    if S[h][w]:
      SV_[h][w] = SV_[h+1][w] + 1

#print(SH + SH_)
#print(SV + SV_)

print(np.max(SH+SH_+SV+SV_) -3)


Fixed submission:
P,Q,R = list(map(int, input().split()))
print(min([P+Q,Q+R,R+P]))
Buggy python submission (verdict: Time Limit Exceeded):
N,A,B,C,D = list(map(int, input().split()))
S = [0]+[0 if s=='.' else 1 for s in input()]

def Solution():
  for i in range(A,C):
    if S[i]*S[i+1]==1:
      return False
    for i in range(B,D):
      if S[i]*S[i+1]==1:
        return False
  if C<D:
    return True
  if C>D:
    for i in range(B,C-1):
      if S[i]+S[i+1]+S[i+2]==0:
        return True
    else:
      return False

if Solution():
  print('Yes')
else:
  print('No')

Fixed submission:
N,A,B,C,D = list(map(int, input().split()))
S = [0]+[0 if s=='.' else 1 for s in input()]
can_jump = [0] + [1-S[i]*S[i+1] for i in range(1,N-1)]
can_change = [0] + [(1-S[i])*(1-S[i+1])*(1-S[i+2]) for i in range(1,N-2)]

def Solution():
  if not all(can_jump[A:C]):
    return False
  if not all(can_jump[B:D]):
    return False
  
  if C<D:
    return True
  if C>D:
    if any(can_change[B-1:D]):
      return True
    else:
      return False

if Solution():
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Time Limit Exceeded):
N,A,B,C,D = list(map(int, input().split()))
S = [0]+[0 if s=='.' else 1 for s in input()]

def Solution():
  for i in range(A,C):
    if S[i]*S[i+1]==1:
      return False
    for i in range(B,D):
      if S[i]*S[i+1]==1:
        return False
  if C<D:
    return True
  if C>D:
    for i in range(B,C-1):
      if S[i]+S[i+1]+S[i+2]==0:
        return True
    else:
      return False

if Solution():
  print('Yes')
else:
  print('No')

Fixed submission:
N,A,B,C,D = list(map(int, input().split()))
S = [0]+[0 if s=='.' else 1 for s in input()]
can_jump = [0] + [1-S[i]*S[i+1] for i in range(1,N-1)]
can_change = [0] + [(1-S[i])*(1-S[i+1])*(1-S[i+2]) for i in range(1,N-2)]

def Solution():
  if not all(can_jump[A:C]):
    return False
  if not all(can_jump[B:D]):
    return False
  
  if C<D:
    return True
  if C>D:
    if any(can_change[B-1:D]):
      return True
    else:
      return False

if Solution():
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
N=int(input())
AB = [list(map(int, input().split())) for _ in range(N-1)] #N-1
C = list(map(int, input().split())) #N
C.sort()

M = sum(C[:-1])

adjacent_dict={}
for a,b in AB:
  adjacent_dict.setdefault(a, set()).add(b)
  adjacent_dict.setdefault(b, set()).add(a)
  

leafs = []
adjacents = [0] * (N+1) # a[i]: 頂点i
for k, v in adjacent_dict.items():
  adjacents[k] = len(v)
  if len(v)==1:
    leafs.append(k)

nodes = leafs.copy() #小さい値を入れたい順のノード
visited = [0] * (N+1) # visited[i]: 頂点i
for n in nodes:
  visited[n] = 1
  
stack = leafs.copy()
while stack:
  new_stack=[]
  for v in stack:
    for u in adjacent_dict[v]:
      adjacents[u] -= 1
      if visited[u]==0:
        visited[u]=1
        nodes.append(u)
        new_stack.append(u)
  stack = [v for v in new_stack if adjacents[v]==0]
  
ans = [0]*(N)
for i in range(N):
  ans[nodes[i]-1] = C[i]
  
print(M)
print(*ans)


Fixed submission:
N=int(input())
AB = [list(map(int, input().split())) for _ in range(N-1)] #N-1
C = list(map(int, input().split())) #N
C.sort()

M = sum(C[:-1])

adjacent_dict={}
for a,b in AB:
  adjacent_dict.setdefault(a, set()).add(b)
  adjacent_dict.setdefault(b, set()).add(a)
  

leafs = []
adjacents = [0] * (N+1) # a[i]: 頂点i
for k, v in adjacent_dict.items():
  adjacents[k] = len(v)
  if len(v)==1:
    leafs.append(k)

nodes = leafs.copy() #小さい値を入れたい順のノード
visited = [0] * (N+1) # visited[i]: 頂点i
for n in nodes:
  visited[n] = 1
  
#while leafs:
#  next_leafs = set()
#  for l in leafs:
#    for u in adjacent_dict[l]:
#      acjacents[u] -= 1
#      next_leafs.add(u)
  
  
while leafs:
  new_stack = []
  for v in leafs:
    for u in adjacent_dict[v]:
      adjacents[u] -= 1
      if visited[u]==0:
        visited[u]=1
        new_stack.append(u)
  leafs = [v for v in new_stack if adjacents[v]==1]
  nodes.extend(leafs)
  if not leafs:
    nodes.extend(new_stack) #最後に隣接0のノードが残ったとき
    break
  for u in [v for v in new_stack if adjacents[v]!=1]:
    visited[u] = 0
    
  
ans = [0]*(N)
for i in range(N):
  ans[nodes[i]-1] = C[i]
  
print(M)
print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,Q = list(map(int, input().split()))
STX = [list(map(int, input().split())) for _ in range(N)]
D = [int(input()) for _ in range(Q)]

L = [(s-x-0.5, t-x-0.5,x) for s,t,x in STX] + [(d,) for d in D]
L.sort()

import heapq
hp = [] # (x,t-x)を入れる

for l in L:
  if len(l)==1:
    while hp and l[0] > hp[0][1]:
      heapq.heappop(hp)
    if hp:
      print(hp[0][0])
    else:
      print(-1)
  else:
    heapq.heappush(hp, (l[2],l[1]))

Fixed submission:
N,Q = list(map(int, input().split()))
STX = [list(map(int, input().split())) for _ in range(N)]
D = [int(input()) for _ in range(Q)]

L = [(s-x-0.5, t-x-0.5,x) for s,t,x in STX] + [(d,) for d in D]
L.sort()

import heapq
hp = [] # xを入れる
memo = {} # x:t-x

for l in L:
  if len(l)==1:
    while hp and l[0] > memo[hp[0]]:
      heapq.heappop(hp)
    if hp:
      print(hp[0])
    else:
      print(-1)
  else:
    heapq.heappush(hp, l[2])
    memo[l[2]]=l[1]

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = list(map(int, input().split()))
STX = [list(map(int, input().split())) for _ in range(N)]
D = [int(input()) for _ in range(Q)]

L = [(max(-0.5,s-x-0.5),max(-0.5,t-x-0.5),x) for s,t,x in STX] + [(d,-1) for d in D]
L.sort()

import heapq
hp = [] # (x,t-x)を入れる

for l in L:
  if l[1] == -1:
    while hp and l[0] > hp[0][1]:
      heapq.heappop(hp)
    if hp:
      print(hp[0][0])
    else:
      print(-1)
  else:
    heapq.heappush(hp, (l[2],l[1]))

Fixed submission:
N,Q = list(map(int, input().split()))
STX = [list(map(int, input().split())) for _ in range(N)]
D = [int(input()) for _ in range(Q)]

L = [(s-x-0.5, t-x-0.5,x) for s,t,x in STX] + [(d,) for d in D]
L.sort()

import heapq
hp = [] # xを入れる
memo = {} # x:t-x

for l in L:
  if len(l)==1:
    while hp and l[0] > memo[hp[0]]:
      heapq.heappop(hp)
    if hp:
      print(hp[0])
    else:
      print(-1)
  else:
    heapq.heappush(hp, l[2])
    memo[l[2]]=l[1]

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = list(map(int, input().split()))
STX = [list(map(int, input().split())) for _ in range(N)]
D = [int(input()) for _ in range(Q)]

L = [(max(-0.5,s-x-0.5),max(-0.5,t-x-0.5),x) for s,t,x in STX] + [(d,-1) for d in D]
L.sort()

import heapq
hp = [] # (x,t-x)を入れる

for l in L:
  if l[1] == -1:
    while hp and l[0] > hp[0][1]:
      heapq.heappop(hp)
    if hp:
      print(hp[0][0])
    else:
      print(-1)
  else:
    heapq.heappush(hp, (l[2],l[1]))

Fixed submission:
N,Q = list(map(int, input().split()))
STX = [list(map(int, input().split())) for _ in range(N)]
D = [int(input()) for _ in range(Q)]

L = [(s-x-0.5, t-x-0.5,x) for s,t,x in STX] + [(d,) for d in D]
L.sort()

import heapq
hp = [] # xを入れる
memo = {} # x:t-x

for l in L:
  if len(l)==1:
    while hp and l[0] > memo[hp[0]]:
      heapq.heappop(hp)
    if hp:
      print(hp[0])
    else:
      print(-1)
  else:
    heapq.heappush(hp, l[2])
    memo[l[2]]=l[1]
Buggy python submission (verdict: Runtime Error):
Q = int(input())
Queries = [list(map(int, input().split())) for _ in range(Q)]

import heapq as hp
L = [10**9+1] # 最小ヒープなので負を入れる
R = [10**9+1] # そのまま
hp.heapify(L)
hp.heapify(R)
odd = False
sum_b = 0
sum_l = 0
sum_r = 0

flag = 1

for q in Queries:
  if len(q)==1 and q[0]==2:
    if flag ==0:
      print(*(-L[0], sum_b + abs(sum_l-sum_r)))
    else:
      print(*(-L[0], sum_b)
      flag = 1

  else:
    _, a, b = q
    sum_b += b

    l = -hp.heappop(L)
    r = hp.heappop(R)
    sum_l -= l
    sum_r -= r
    X = sorted([l, r, a])
    if odd==False:
      hp.heappush(L,-X[0])
      hp.heappush(L,-X[1])
      hp.heappush(R,X[2])
      sum_l += X[0]+X[1]
      sum_r += X[2]
      odd=True
    elif odd==True:
      hp.heappush(L,-X[0])
      hp.heappush(R,X[1])
      hp.heappush(R,X[2])
      sum_l += X[0]
      sum_r += X[1] + X[2]
      odd=False



Fixed submission:
Q = int(input())
Queries = [list(map(int, input().split())) for _ in range(Q)]

import heapq as hp
L = [-(-(10**9+1))] # 最小ヒープなので負を入れる
R = [10**9+1] # そのまま
hp.heapify(L)
hp.heapify(R)
odd = False
sum_b = 0
sum_l = 0
sum_r = 0

for q in Queries:
  if len(q)==1 and q[0]==2:
    print(*(-L[0], sum_b + abs(sum_l-sum_r)))
    
  else:
    _, a, b = q
    sum_b += b

    l = -hp.heappop(L)
    r = hp.heappop(R)
    
    X = sorted([l, r, a])
    if odd==False:
      sum_l -= l
      sum_r -= r
      hp.heappush(L,-X[0])
      hp.heappush(L,-X[1])
      hp.heappush(R,X[2])
      sum_l += X[0]
      sum_r += X[2]
      odd=True
    elif odd==True:
      sum_r -= r
      hp.heappush(L,-X[0])
      hp.heappush(R,X[1])
      hp.heappush(R,X[2])
      sum_l += X[0]
      sum_r += X[1] + X[2]
      odd=False
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

ans = 0
for r in range(1,N+1):
  if (N-r)%r != 0:
    continue
  else:
    m = (N-r)//r
    if m <= r:
      break
    else:
      ans += m
      
print(ans)

Fixed submission:
N = int(input())

ans = 0
for r in range(1,int(N**0.5)+2):
  if (N-r)%r != 0:
    continue
  else:
    m = (N-r)//r
    if m <= r:
      break
    else:
      ans += m
      
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [abs(int(input())) for _ in range(N)]
#A.sort()
s = sum(A)

def mulmod(p,q,mod):
  return ((p%mod)*(q%mod))%mod
def powermod(p,n,mod):
  if n==0: return 1
  if n==1: return p%mod
  else:    return powermod(p,n//2,mod)**2 * (p**(n%2)) %mod
def dividemod(p,q,mod):
  # modは素数
  return mulmod(p, powermod(q,mod-2,mod), mod)

mod = 998244353

dp = [[0]*(s+1) for _ in range(N)]
# dp[n][s] An-1(0-index)まで加えて、Rの和がsになるのが何通りか（残りのG,Bまで含めて）
dp[0][0] = 2
dp[0][A[0]] = 1
temp_sum = A[0]

for i in range(1,N):
  for j in range(A[i]):
    dp[i][j] = (dp[i-1][j]*2) %mod
  for j in range(A[i], temp_sum+1):
    dp[i][j] = (dp[i-1][j]*2 + dp[i-1][j-A[i]]) %mod
  for j in range(temp_sum+1, temp_sum+1 + A[i]):
    dp[i][j] = (dp[i-1][j-A[i]]) %mod
  temp_sum += A[i]


def part_sum(a,A):
  p=mod
  #初期化
  N=len(a)
  dp=[[0 for i in range(A+1)] for j in range(N+1)]
  dp[0][0]=1

  #DP
  for i in range(N):
    for j in range(A+1):
      if a[i]<=j: #i+1番目の数字a[i]を足せるかも
        dp[i+1][j]=dp[i][j-a[i]]+ dp[i][j]% p
      else: #入る可能性はない
        dp[i+1][j]=dp[i][j]%p
  return dp[N][A]

ps = part_sum(A, s//2)

if s%2 != 0:
    answer = (powermod(3, N, mod) - 3*sum(dp[N-1][(s+1)//2:]))%mod
else:
    answer = (powermod(3, N, mod) - 3*(sum(dp[N-1][(s+1)//2:]) - ps))%mod



print(answer)


Fixed submission:
N = int(input())
S = input()
answers = []

from itertools import accumulate

white_cumsum = list(accumulate([1 if s=='.' else 0 for s in S]))
black_cumsum = list(accumulate([1 if s=='#' else 0 for s in S]))

answers.append(white_cumsum[-1])
answers.append(black_cumsum[-1])

for i in range(N):
  answers.append(black_cumsum[i] + white_cumsum[-1] - white_cumsum[i])
    
answer = min(answers)
print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

answers = []

answers.append(S.count('.'))
answers.append(S.count('#'))

for i in range(1,N):
  answers.append(S[:i].count('#') + S[i:].count('.'))
  
answer = min(answers)
print(answer)


Fixed submission:
N = int(input())
S = input()
answers = []

from itertools import accumulate

white_cumsum = list(accumulate([1 if s=='.' else 0 for s in S]))
black_cumsum = list(accumulate([1 if s=='#' else 0 for s in S]))

answers.append(white_cumsum[-1])
answers.append(black_cumsum[-1])

for i in range(N):
  answers.append(black_cumsum[i] + white_cumsum[-1] - white_cumsum[i])
    
answer = min(answers)
print(answer)
Buggy python submission (verdict: Runtime Error):
A = [int(input()) for _ in range(5)]

y = min([x%10 for x in A if x%10])

print(sum([10*(x//10 + bool(x%10)) for x in A]) -10 + y)

Fixed submission:
A = [int(input()) for _ in range(5)]
 
y = min([10] + [x%10 for x in A if x%10])
 
print(sum([10*(x//10 + bool(x%10)) for x in A]) -10 + y)