Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,input().split())
S=input()
lr=[list(map(int,input().split())) for _ in range(Q)]

for i in range(Q):
  s=S[lr[i][0]-1 : lr[i][1]]
  print(s.count('AC'))

Fixed submission:
N,Q=map(int,input().split())
S=input()

t=[0]*(N+1)
for i in range(N):
  t[i+1]=t[i]+(1 if S[i:i+2] == 'AC' else 0)
for i in range(Q):
  l,r=map(int,input().split())
  print(t[r-1]-t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,input().split())
S=input()
for i in range(Q):
  l,r=map(int,input().split())
  A=S[l-1:r]
  ans=A.count('AC')
  print(ans)

Fixed submission:
N,Q=map(int,input().split())
S=input()

t=[0]*(N+1)
for i in range(N):
  t[i+1]=t[i]+(1 if S[i:i+2] == 'AC' else 0)
for i in range(Q):
  l,r=map(int,input().split())
  print(t[r-1]-t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,input().split())
S=input()
l=[0]*Q
r=[0]*Q
for i in range(Q):
  l[i],r[i]=map(int,input().split())
for i in range(Q):
  A=S[(l[i]-1):r[i]]
  ans=A.count('AC')
  print(ans)

Fixed submission:
N,Q=map(int,input().split())
S=input()

t=[0]*(N+1)
for i in range(N):
  t[i+1]=t[i]+(1 if S[i:i+2] == 'AC' else 0)
for i in range(Q):
  l,r=map(int,input().split())
  print(t[r-1]-t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,input().split())
S=input()
l=[0]*Q
r=[0]*Q

for i in range(Q):
  l[i],r[i]=map(int,input().split())

for i in range(Q):
  s=S[l[i]-1:r[i]]
  s=s.replace('AC','1')
  print(s.count('1'))

Fixed submission:
N,Q=map(int,input().split())
S=input()

t=[0]*(N+1)
for i in range(N):
  t[i+1]=t[i]+(1 if S[i:i+2] == 'AC' else 0)
for i in range(Q):
  l,r=map(int,input().split())
  print(t[r-1]-t[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
h=[int(input()) for i in range(N)]
h.sort()
s=[]
for i in range(N-K+1):
  a=h[i:i+K]
  s.append(a)
cost=[]
for i in range(N-K+1):
  cost.append(max(s[i])-min(s[i]))
print(min(cost))

Fixed submission:
N,K=map(int,input().split())
H=[int(input()) for i in range(N)]
H.sort()

ans=float('inf')
for i in range(N-K+1):
  ans=min(ans,H[i+K-1]-H[i])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
h=[0]*N
s=[0]*K
d=[0]*(N-K+1)

for i in range(N):
  h[i]=int(input())
h=sorted(h)

for i in range(N-K+1):
  for j in range(K):
    s[j]=h[i+j]
  d[i]=s[K-1]-s[0]
  if d[i] == 0:
    print(0)
    exit()

print(min(d))

Fixed submission:
N,K=map(int,input().split())
H=[int(input()) for i in range(N)]
H.sort()

ans=float('inf')
for i in range(N-K+1):
  ans=min(ans,H[i+K-1]-H[i])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
h=[0]*N
s=[0]*K
d=[0]*(N-K+1)

for i in range(N):
  h[i]=int(input())
h=sorted(h)

for i in range(N-K+1):
  for j in range(K):
    s[j]=h[i+j]
  d[i]=s[K-1]-s[0]

print(min(d))

Fixed submission:
N,K=map(int,input().split())
H=[int(input()) for i in range(N)]
H.sort()

ans=float('inf')
for i in range(N-K+1):
  ans=min(ans,H[i+K-1]-H[i])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
PY=[list(map(int,input().split())) for i in range(M)]
ans_1=0
ans_2=0
ans=0
num_1=0
num_2=0
for i in range(M):
  ans_1=10**12+PY[i][0]*10**6
  num_1=PY[i][0]
  num_2=PY[i][1]
  for i in range(M):
    if num_1==PY[i][0] and num_2>=PY[i][1]:
      ans_2+=1
  ans=ans_1+ans_2
  ans=str(ans)
  print(ans.lstrip('1'))
  ans_2=0

Fixed submission:
N,M=map(int,input().split())
li=[]

for i in range(M):
  P,Y=map(int,input().split())
  li.append([P,Y,i])
li.sort(key=lambda x:x[1])
li.sort(key=lambda x:x[0])
pre=li[0][0]
cnt=1
ans=[]

for p,y,i in li:
  if p==pre:
    ans.append([str(p).zfill(6)+str(cnt).zfill(6),i])
    cnt+=1
  else:
    pre=p
    ans.append([str(p).zfill(6)+str(1).zfill(6),i])
    cnt=2
ans.sort(key=lambda x:x[1])

for a,i in ans:
  print(a)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
v=list(map(int,input().split()))

v1=v[::2]
V1=list(set(v1))
n1=len(V1)
v2=v[1::2]
V2=list(set(v2))
n2=len(V2)

cnt1={}
cnt2={}

for i in range(n1):
  cnt1[V1[i]]=v1.count(V1[i])
for i in range(n2):
  cnt2[V2[i]]=v2.count(V2[i])

max1_k=max(cnt1,key=cnt1.get)
max2_k=max(cnt2,key=cnt2.get)
if max1_k!=max2_k:
  print(N-cnt1[max1_k]-cnt2[max2_k])
else:
  if cnt1[max1_k]>=cnt2[max2_k]:
    if n2==1:
      print(N-cnt1[max1_k])
    else:
      cnt2.pop(max2_k)
      max2_k=max(cnt2,key=cnt2.get)
      print(N-cnt1[max1_k]-cnt2[max2_k])
  else:
    if n1==1:
      print(N-cnt2[max2_k])
    else:
      cnt1.pop(max1_k)
      max1_k=max(cnt1,key=cnt.get)
      print(N-cnt1[max1_k]-cnt2[max2_k])

Fixed submission:
from collections import Counter

N=int(input())
v=list(map(int,input().split()))

v1=v[::2]
n1=len(set(v1))
v2=v[1::2]
n2=len(set(v2))

cnt1=Counter(v1)
cnt2=Counter(v2)

cnt1=cnt1.most_common()
cnt2=cnt2.most_common()

if cnt1[0][0]!=cnt2[0][0]:
  print(N-cnt1[0][1]-cnt2[0][1])
else:
  if n1==1 and n2==1:
    print(N-cnt1[0][1])
  elif n1==1:
    print(N-cnt1[0][1]-cnt2[1][1])
  elif n2==1:
    print(N-cnt1[1][1]-cnt2[0][1])
  else:
    print(N-max(cnt1[0][1]+cnt2[1][1],cnt1[1][1]+cnt2[0][1]))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np

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

x=np.zeros((N+1,N+1),dtype=np.int32)
for _ in range(M):
    l,r=map(int,input().split())
    x[l,r]+=1

x=np.cumsum(x,axis=0)
x=np.cumsum(x,axis=1)
for _ in range(Q):
    p,q=map(int,input().split())
    print(x[N,q]-x[p-1,q])

Fixed submission:
import sys
import numpy as np

input=sys.stdin.readline

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

x=np.zeros((N+1,N+1),dtype=np.int32)
for _ in range(M):
    l,r=map(int,input().split())
    x[l,r]+=1

x=np.cumsum(x,axis=0)
x=np.cumsum(x,axis=1)
for _ in range(Q):
    p,q=map(int,input().split())
    print(x[N,q]-x[p-1,q])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np

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

x=np.zeros((N+1,N+1),dtype=np.int32)
for _ in range(M):
    l,r=map(int,input().split())
    x[l][r]+=1

x=np.cumsum(x,axis=0)
x=np.cumsum(x,axis=1)
for _ in range(Q):
    p,q=map(int,input().split())
    print(x[N][q]-x[p-1][q])

Fixed submission:
import sys
import numpy as np

input=sys.stdin.readline

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

x=np.zeros((N+1,N+1),dtype=np.int32)
for _ in range(M):
    l,r=map(int,input().split())
    x[l,r]+=1

x=np.cumsum(x,axis=0)
x=np.cumsum(x,axis=1)
for _ in range(Q):
    p,q=map(int,input().split())
    print(x[N,q]-x[p-1,q])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np

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

x=np.zeros((N+1,N+1),dtype=np.int32)
for _ in range(M):
    l,r=map(int,input().split())
    x[l][r]+=1

x=np.cumsum(x,axis=0)
x=np.cumsum(x,axis=1)
for _ in range(Q):
    p,q=map(int,input().split())
    print(x[q][q]-x[q][p-1]-x[p-1][q]+x[p-1][p-1])

Fixed submission:
import sys
import numpy as np

input=sys.stdin.readline

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

x=np.zeros((N+1,N+1),dtype=np.int32)
for _ in range(M):
    l,r=map(int,input().split())
    x[l,r]+=1

x=np.cumsum(x,axis=0)
x=np.cumsum(x,axis=1)
for _ in range(Q):
    p,q=map(int,input().split())
    print(x[N,q]-x[p-1,q])

Buggy python submission (verdict: Time Limit Exceeded):
N,M,Q=map(int,input().split())
x=[[0]*N for _ in range(N)]
for i in range(M):
    L,R=map(int,input().split())
    L,R=L-1,R-1
    x[L][R]+=1

c=[[0]*N for _ in range(N)]
for i in range(N):
    for j in range(i,N):
        if j==0:
            c[i][0]=x[i][0]
        else:
            c[i][j]=c[i][j-1]+x[i][j]

for i in range(Q):
    p,q=map(int,input().split())
    ans=0
    for i in range(p-1,q):
        if p==1:
            ans+=c[i][q-1]
        else:
            ans+=c[i][q-1]-c[i][p-2]
    print(ans)

Fixed submission:
import sys
import numpy as np

input=sys.stdin.readline

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

x=np.zeros((N+1,N+1),dtype=np.int32)
for _ in range(M):
    l,r=map(int,input().split())
    x[l,r]+=1

x=np.cumsum(x,axis=0)
x=np.cumsum(x,axis=1)
for _ in range(Q):
    p,q=map(int,input().split())
    print(x[N,q]-x[p-1,q])
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
A=[0]+list(map(int,input().split()))

a=0
m=[0]*N
for i in range(N):
    a+=A[i]%M
    a%=M
    m[i]=a

m.sort()
ans=0
cnt=0
for i in range(N):
    if m[i]==m[i+1]:
        cnt+=1
    else:
        ans+=cnt*(cnt-1)//2
        cnt=1
ans+=cnt*(cnt-1)//2
print(ans)

Fixed submission:
N,M=map(int,input().split())
A=[0]+list(map(int,input().split()))

a=0
m=[0]*(N+1)
for i in range(N+1):
    a+=A[i]%M
    a%=M
    m[i]=a

m.sort()
ans=0
cnt=1
for i in range(N):
    if m[i+1]==m[i]:
        cnt+=1
    else:
        ans+=cnt*(cnt-1)//2
        cnt=1
ans+=cnt*(cnt-1)//2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
B=[A[i]-(i+1) for i in range(N)]

B.sort()
ans=float('inf')
for i in range(B[0],B[N-1]+1):
  val=0
  for j in range(N):
    val+=abs(B[j]-i)
  ans=min(ans,val)
print(ans)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
B=[A[i]-(i+1) for i in range(N)]

B.sort()
b=B[N//2]
ans=0
for i in range(N):
  ans+=abs(B[i]-b)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()

ans=float('inf')
for i in range(N):
  cnt=0
  S1=S[:i]
  S2=S[i+1:]
  cnt+=S1.count('W')+S2.count('E')
  ans=min(ans,cnt)
print(ans)

Fixed submission:
N=int(input())
S=input()

acc_e=[0]
acc_w=[0]
for i in S:
  acc_e.append(acc_e[-1])
  acc_w.append(acc_w[-1])
  if i=='E':
    acc_e[-1]+=1
  else:
    acc_w[-1]+=1

ans=N
for i in range(N):
  turn=acc_w[i]+acc_e[-1]-acc_e[i+1]
  ans=min(ans,turn)
print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()
K=int(input())

S=[]
n=len(s)
for i in range(n):
  for j in range(i+1,n+1):
    S.append(s[i:j])
S=list(set(S))
S.sort()
print(S[K-1])

Fixed submission:
s=input()
K=int(input())

S=[]
n=len(s)
for i in range(n):
  for j in range(i+1,i+K+1):
    S.append(s[i:j])
S=list(set(S))
S.sort()
print(S[K-1])
Buggy python submission (verdict: Runtime Error):
H,W=map(int,input().split())
s=[input() for _ in range(H)]

for i in range(H):
  h=i
  for j in range(W):
    w=s[h][j]
    if w=='#':
      cnt=0
      for j,k in ([1,0], [-1,0], [0,1], [0,-1]):
        new_h, new_w=h+j, w+k
        if new_h<0 or new_h>=H or new_w<0 or new_w>=W:
          continue
        elif s[new_h][new_w] == '#':
          cnt+=1
          break
      if cnt==0:
        print('No')
        exit()
print('Yes')

Fixed submission:
H,W=map(int,input().split())
s=[input() for _ in range(H)]

for i in range(H):
  h=i
  for j in range(W):
    if s[h][j]=='#':
      w=j
      cnt=0
      for k,l in ([1,0], [-1,0], [0,1], [0,-1]):
        new_h, new_w=h+k, w+l
        if new_h<0 or new_h>=H or new_w<0 or new_w>=W:
          continue
        elif s[new_h][new_w] == '#':
          cnt+=1
          break
      if cnt==0:
        print('No')
        exit()
print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

N=int(input())
X=list(map(int,input().split()))

for i in range(N):
  d=deque(X)
  d.remove(X[i])
  d=list(d)
  d.sort()
  print(d[N//2-1])

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

x=[]
for i in range(N):
  x.append(X[i])
x.sort()

for i in range(N):
  if X[i]<x[N//2]:
    print(x[N//2])
  else:
    print(x[N//2-1])
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input()))

if N > 2:
    A.sort()
    num_total = A[-1]
    A.pop()
    def isOK(index, key, l):
        if l[index] >= key:
            return True
        else:
            return False
    
    def meguru_search(l,key): # key以上の値を持つ最小のインデックスを返す
        left = -1
        right = len(l)

        while (right - left) > 1: # 二分探索
            mid = left + (right - left)//2
            if isOK(mid,key,l):
                right = mid
            else:
                left = mid
        
        return right
    
    if num_total%2 == 0:
        Max = num_total//2 
    else:
        Max = num_total//2 + 1
    
    Maxind1 = meguru_search(A,Max) # Max以上の値を持つインデックス
    Maxind2 = Maxind1 - 1 # Max未満の最大の値を持つインデックス
    abs_1 = abs(Max - A[Maxind1])
    abs_2 = abs(Max - A[Maxind2])
    if abs_1 > abs_2: # Maxに近いほどnCrが大きくなる
        r = A[Maxind2]
    else:
        r = A[Maxind1]
    print(num_total,r)

else:
    print(max(A),min(A))

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

if N > 2:
    A.sort()
    num_total = A[-1]
    A.pop()
    def isOK(index, key, l):
        if l[index] >= key:
            return True
        else:
            return False
    
    def meguru_search(l,key): # key以上の値を持つ最小のインデックスを返す
        left = -1
        right = len(l)

        while (right - left) > 1: # 二分探索
            mid = left + (right - left)//2
            if isOK(mid,key,l):
                right = mid
            else:
                left = mid
        
        return right
    
    if num_total%2 == 0:
        Max = num_total//2 
    else:
        Max = num_total//2 + 1
    
    Maxind1 = meguru_search(A,Max) # Max以上の値を持つインデックス
    Maxind2 = Maxind1 - 1 # Max未満の最大の値を持つインデックス
    abs_1 = abs(Max - A[Maxind1])
    abs_2 = abs(Max - A[Maxind2])
    if abs_1 > abs_2: # Maxに近いほどnCrが大きい
        r = A[Maxind2]
    else:
        r = A[Maxind1]
    print(num_total,r)

else:
    print(max(A),min(A))
Buggy python submission (verdict: Time Limit Exceeded):
H,W,D=map(int,input().split())
A=[list(map(int,input().split())) for _ in range(H)]

def find(x):
    for i in range(H):
        for j in range(W):
            if A[i][j]==x:
                return i,j

Q=int(input())
for i in range(Q):
    L,R=map(int,input().split())
    cost=0
    x,y=find(L)
    for j in range(L+D,R+D,D):
        new_x,new_y=find(j)
        cost+=abs(x-new_x)+abs(y-new_y)
        x,y=new_x,new_y
    print(cost)

Fixed submission:
from collections import defaultdict

H,W,D=map(int,input().split())
A=[list(map(int,input().split())) for _ in range(H)]
M=defaultdict(list)
for h in range(H):
    for w in range(W):
        M[A[h][w]]=[h,w]

P=defaultdict(list)
for d in range(1,D+1):
    a=d
    while a+D<=H*W:
        p=abs(M[a][0]-M[a+D][0])+abs(M[a][1]-M[a+D][1])
        if P[d]:
            P[d].append(P[d][-1]+p)
        else:
            P[d]=[0,p]
        a+=D

Q=int(input())
for i in range(Q):
    L,R=map(int,input().split())
    d=L%D
    l=L//D
    r=R//D
    if d==0:
        d=D
        if len(P[d])>0:
            print(P[d][r-1]-P[d][l-1])
        else:
            print(0)
    else:
        if len(P[d])>0:
            print(P[d][r]-P[d][l])
        else:
            print(0)
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())

ans=[0]*N
D=[[0]*N for _ in range(N)]
graph=[[] for _ in range(N)]
for i in range(M):
  L,R,d=map(int,input().split())
  L,R=L-1,R-1
  ans[R]=ans[L]+d
  graph[L].append([R,d])
  graph[R].append([L,-d])

for i in range(N):
  for j,d in graph[i]:
    if ans[j]-ans[i]!=d:
      print("No")
      exit()
    else:
      continue

print("Yes")

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

N,M=map(int,input().split())
graph=[[] for _ in range(N)]

for _ in range(M):
  l,r,d=map(int,input().split())
  l,r=l-1,r-1
  graph[l].append([r,d])
  graph[r].append([l,-d])

def BFD(x):
  global checked,answer,graph
  checked[x]=1
  for i,distance in graph[x]:
    if answer[i]=="first":
      answer[i]=answer[x]+distance
    else:
      if answer[i]!=answer[x]+distance:
        print("No")
        exit()
    
    if checked[i]==0:
      BFD(i)

checked=[0]*N
answer=["first"]*N

for i in range(N):
  if checked[i]==0:
    answer[i]=0
    BFD(i)

print("Yes")

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())

ans=[0]*N
D=[[0]*N for _ in range(N)]
graph=[[] for _ in range(N)]
for i in range(M):
  L,R,d=map(int,input().split())
  L,R=L-1,R-1
  D[L][R]=d
  D[R][L]=-d
  ans[R]=ans[L]+D[L][R]
  graph[L].append(R)
  graph[R].append(L)
  for j in graph[R]:
    if ans[R]-ans[j]!=D[j][R]:
      print("No")
      exit()
    else:
      continue
print("Yes")

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

N,M=map(int,input().split())
graph=[[] for _ in range(N)]

for _ in range(M):
  l,r,d=map(int,input().split())
  l,r=l-1,r-1
  graph[l].append([r,d])
  graph[r].append([l,-d])

def BFD(x):
  global checked,answer,graph
  checked[x]=1
  for i,distance in graph[x]:
    if answer[i]=="first":
      answer[i]=answer[x]+distance
    else:
      if answer[i]!=answer[x]+distance:
        print("No")
        exit()
    
    if checked[i]==0:
      BFD(i)

checked=[0]*N
answer=["first"]*N

for i in range(N):
  if checked[i]==0:
    answer[i]=0
    BFD(i)

print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
N,H=map(int,input().split())
a,b=[0]*N,[0]*N
for i in range(N):
    a[i],b[i]=map(int,input().split())

a.sort(reverse=True)
b.sort(reverse=True)

def count(n):
    damage=0
    cnt=0
    for i in range(n):
        cnt+=1
        damage+=b[i]
        if damage>=H:
            return cnt
    
    cnt -= (-(H-damage))//a[0]
    return cnt

ans=float("inf")
for i in range(N+1):
    cnt=count(i)
    if cnt<=ans:
        ans=cnt
    else:
        print(ans)
        exit()
print(ans)

Fixed submission:
N,H=map(int,input().split())
a,b=[0]*N,[0]*N
for i in range(N):
    a[i],b[i]=map(int,input().split())

a.sort(reverse=True)
b.sort(reverse=True)

def count(n):
    damage=0
    cnt=0
    for i in range(n):
        cnt+=1
        damage+=b[i]
        if damage>=H:
            return cnt
    
    cnt -= (-(H-damage))//a[0]
    return cnt

for i in range(N):
    if b[i]>a[0]:
        continue
    else:
        print(count(i))
        exit()
print(count(N))
Buggy python submission (verdict: Time Limit Exceeded):
def primes(n):
	is_prime = [True] * (n+1)
	is_prime[0] = False
	is_prime[1] = False
	for i in range(2, int(n**0.5)+1):
		if not is_prime[i]:
			continue
		for j in range(i*2, n+1, i):
			is_prime[j] = False
	return [i for i in range(n+1) if is_prime[i]]

Primes=primes(100000)
Q=int(input())
for i in range(Q):
    l,r=map(int,input().split())
    ans=0
    for j in range(l,r+1,2):
        if j in Primes and (j+1)//2 in Primes:
            ans+=1
    print(ans)

Fixed submission:
def primes(n):
	is_prime = [True] * (n+1)
	is_prime[0] = False
	is_prime[1] = False
	for i in range(2, int(n**0.5)+1):
		if not is_prime[i]:
			continue
		for j in range(i*2, n+1, i):
			is_prime[j] = False
	return is_prime

is_Prime=primes(10**5)
count=[]
cnt=0
for i in range(10**5+1):
  if is_Prime[i] and is_Prime[(i+1)//2]:
    cnt+=1
  count.append(cnt)

Q=int(input())
for i in range(Q):
  l,r=map(int,input().split())
  print(count[r]-count[l-1])
Buggy python submission (verdict: Runtime Error):
N=int(input())
a=list(map(int,input().split()))

MAX=max(a)
MIN=min(a)
m=0
operation=[]
if abs(MAX)>=abs(MIN):
    n=a.index(MAX)
    for i in range(N):
        a[i]+=MAX
        m+=1
        operation.append([n+1,i+1])
    for i in range(N-1):
        a[i+1]+=a[i]
        m+=1
        operation.append([i+1,i+2])
else:
    n=a.index(MIN)
    for i in range(N):
        a[i]+=MIN
        m+=1
        operation.append([n+1,i+1])
    for i in range(N,0,-1):
        a[i-1]+=a[i]
        m+=1
        operation.append([i+1,i])

print(m)
for i in range(m):
    print(*operation[i])

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

MAX=max(a)
MIN=min(a)
m=0
operation=[]
if abs(MAX)>=abs(MIN):
    n=a.index(MAX)
    for i in range(N):
        a[i]+=MAX
        m+=1
        operation.append([n+1,i+1])
    for i in range(N-1):
        a[i+1]+=a[i]
        m+=1
        operation.append([i+1,i+2])
else:
    n=a.index(MIN)
    for i in range(N):
        a[i]+=MIN
        m+=1
        operation.append([n+1,i+1])
    for i in range(N-1,0,-1):
        a[i-1]+=a[i]
        m+=1
        operation.append([i+1,i])

print(m)
for i in range(m):
    print(*operation[i])

Buggy python submission (verdict: Runtime Error):
N=int(input())
a=list(map(int,input().split()))

MAX=max(a)
MIN=min(a)
m=0
operation=[]
if abs(MAX)>=abs(MIN):
    n=a.index(MAX)
    for i in range(N):
        a[i]+=MAX
        m+=1
        operation.append([n+1,i+1])
    for i in range(N-1):
        a[i+1]+=a[i]
        m+=1
        operation.append([i+2,i+1])
else:
    n=a.index(MIN)
    for i in range(N):
        a[i]+=MIN
        m+=1
        operation.append([n+1,i+1])
    for i in range(N,0,-1):
        a[i-1]+=a[i]
        m+=1
        operation.append([i+1,i])

print(m)
for i in range(m):
    print(*operation[i])

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

MAX=max(a)
MIN=min(a)
m=0
operation=[]
if abs(MAX)>=abs(MIN):
    n=a.index(MAX)
    for i in range(N):
        a[i]+=MAX
        m+=1
        operation.append([n+1,i+1])
    for i in range(N-1):
        a[i+1]+=a[i]
        m+=1
        operation.append([i+1,i+2])
else:
    n=a.index(MIN)
    for i in range(N):
        a[i]+=MIN
        m+=1
        operation.append([n+1,i+1])
    for i in range(N-1,0,-1):
        a[i-1]+=a[i]
        m+=1
        operation.append([i+1,i])

print(m)
for i in range(m):
    print(*operation[i])
Buggy python submission (verdict: Runtime Error):
A,B,C,D,E,F=map(int,input().split())
n=F//(100+E)
max_water=100*n

ans=[0,0]
concentration=0.0
for i in range(max_water//(100*B)+1):
    tmp_water=100*B*i
    tmp_water+=100*A*((max_water-tmp_water)//(100*A))
    max_suger=(tmp_water//100)*E
    for j in range(max_suger//D+1):
        tmp_suger=D*j
        tmp_suger+=C*((max_suger-tmp_suger)//C)
        if tmp_suger/(tmp_water+tmp_suger)>concentration:
            concentration=tmp_suger/(tmp_water+tmp_suger)
            ans=[tmp_water+tmp_suger,tmp_suger]

print(*ans)

Fixed submission:
A,B,C,D,E,F=map(int,input().split())

ans=[0,0]
concentration=0.0
for i in range(F//(100*B)+1):
    tmp_water=100*B*i
    for j in range((F-tmp_water)//(100*A)+1):
        tmp_water+=100*A*j
        max_suger=min((tmp_water//100)*E,F-tmp_water)
        for k in range((max_suger)//D+1):
            tmp_suger=D*k
            tmp_suger+=C*((max_suger-tmp_suger)//C)
            if tmp_water+tmp_suger==0:
                continue
            elif tmp_suger/(tmp_water+tmp_suger)>=concentration:
                concentration=tmp_suger/(tmp_water+tmp_suger)
                ans[0]=tmp_water+tmp_suger
                ans[1]=tmp_suger

print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
MIN=min(A)
MAX=max(A)

ans=0
for val in range(MIN,MAX+1):
    tmp=0
    for i in range(N):
        if val-1<=A[i]<=val+1:
            tmp+=1
    ans=max(ans,tmp)
print(ans)

Fixed submission:
from collections import defaultdict

N=int(input())
A=list(map(int,input().split()))
d=defaultdict(int)

for i in range(N):
    d[A[i]]+=1

MIN=min(A)
MAX=max(A)

ans=0
for i in range(MIN,MAX+1):
    ans=max(ans,d[i-1]+d[i]+d[i+1])
print(ans)
Buggy python submission (verdict: Runtime Error):
import math

N=int(input())
T=[int(input()) for _ in range(N)]
ans=1
for i in range(N):
    ans=ans*T[i]//(math.gcd(ans,T[i]))
print(ans)

Fixed submission:
import fractions

N=int(input())
T=[int(input()) for _ in range(N)]
ans=1
for i in range(N):
    ans=ans*T[i]//(fractions.gcd(ans,T[i]))
print(ans)

Buggy python submission (verdict: Runtime Error):
import math

N=int(input())
T=[int(input()) for _ in range(N)]
ans=T[0]
for i in range(N):
    ans=ans*T[i]//(math.gcd(ans,T[i]))
print(ans)

Fixed submission:
import fractions

N=int(input())
T=[int(input()) for _ in range(N)]
ans=1
for i in range(N):
    ans=ans*T[i]//(fractions.gcd(ans,T[i]))
print(ans)