Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
#from collections import defaultdict, deque, Counter
#from bisect import bisect_left
#import heapq
#import math
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

#n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
L,R = map(int, stdin.readline().rstrip().split())
#S = [list(stdin.buffer.readline().decode().rstrip()) for _ in range(h)]

lsho, lmod = divmod(L,2019)
rsho, rmod = divmod(R,2019)

if rsho - lsho == 0:
    print(int((lmod*(lmod+1))%2019))
    exit()

u = [0]*2019
for l in range(lsho,2019):
    u[l] += 1
for r in range(rsho):
    u[r] += 1

for i,v in enumerate(u):
    if v == 0:
        pass
    if v == 1:
        if u[i+1] != 0:
            print(int((i*(i+1))%2019))
            exit()
        else:
            for j in range(i+1,2019):
                if u[j] == 1:
                    print(int((i*j%2019)))
                    exit()
    if v == 2:
        print(int((i*i)%2019))
        exit()


Fixed submission:
import sys
#from collections import defaultdict, deque, Counter
#from bisect import bisect_left
#import heapq
#import math
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

#n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
L,R = map(int, stdin.readline().rstrip().split())
#S = [list(stdin.buffer.readline().decode().rstrip()) for _ in range(h)]

if R-L > 2019:
    print(0)
    exit()

ans = 2018
for i in range(L,R):
    for j in range(L+1,R+1):
        ans = min(ans, (i*j)%2019)

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
#from collections import defaultdict, deque, Counter
#from bisect import bisect_left
#import heapq
import math
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

#n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
a,b,c,d = map(int, stdin.readline().rstrip().split())
#S = [list(stdin.buffer.readline().decode().rstrip()) for _ in range(h)]

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

# 最小公倍数
cd = lcm(c,d)

# b以下
cwari = b//c
dwari = b//d
cdwari = b//cd
ub = b-cwari-dwari+cdwari

# a以下
cwari = a//c
dwari = a//d
cdwari = a//cd
ua = a-cwari-dwari+cdwari

if a%c != 0 and a%d !=0:
    print(ub-ua+1)
else:
    print(ub-ua)


Fixed submission:
import sys
#from collections import defaultdict, deque, Counter
#from bisect import bisect_left
#import heapq
#import math
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

#n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
a,b,c,d = map(int, stdin.readline().rstrip().split())
#S = [list(stdin.buffer.readline().decode().rstrip()) for _ in range(h)]

def gcd(a,b):
  while b:
    a,b = b,a%b
  return a

def lcm(x, y):
    return (x * y) // gcd(x, y)


cd = lcm(c,d)

# b以下
cwari = b//c
dwari = b//d
cdwari = b//cd
ub = b-cwari-dwari+cdwari

# a以下
cwari = (a-1)//c
dwari = (a-1)//d
cdwari = (a-1)//cd
ua = (a-1)-cwari-dwari+cdwari

print(ub-ua)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
#from collections import defaultdict, deque, Counter
#from bisect import bisect_left
#import heapq
#import math
#from itertools import groupby as gb
#from itertools import permutations as perm
#from itertools import combinations as comb
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
#A, B, C = map(int, stdin.readline().rstrip().split())
#S = [list(stdin.buffer.readline().decode().rstrip()) for _ in range(h)]
A = []
B = []
for i in range(n):
    a,b = map(int, stdin.readline().rstrip().split())
    A.append(a)
    B.append(b)

now = 0

for i in range(n):
    small = B.index(min(B))
    now += A[small]
    if now > min(B):
        print("No")
        exit()
    else:
        B[small] = INF

print("Yes")


Fixed submission:
import sys
#from collections import defaultdict, deque, Counter
#from bisect import bisect_left
#import heapq
#import math
#from itertools import groupby as gb
#from itertools import permutations as perm
#from itertools import combinations as comb
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
#A, B, C = map(int, stdin.readline().rstrip().split())
#w = [list(stdin.buffer.readline().decode().rstrip()) for _ in range(n)]
ab = [list(map(int, stdin.readline().rstrip().split())) for _ in range(n)]
ab.sort(key=lambda x: x[1])
now = 0

for i in range(n):
    now += ab[i][0]
    if now > ab[i][1]:
        print("No")
        exit()

print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
import sys
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

#n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))

#numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
#word = [stdin.readline().rstrip() for _ in range(n)]
#number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
#zeros = [[0] * w for i in range(h)]


R,G,B,N = map(int, stdin.readline().rstrip().split())
ans = 0
for r in range(N//R+1):
    for g in range((N-(r*R))//G + 1):
        b = (N - R*r - G*g) / B
        if b%1==0 and b>=0:
            ans += 1
print(ans)


Fixed submission:
import sys
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

#n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))

#numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
#word = [stdin.readline().rstrip() for _ in range(n)]
#number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
#zeros = [[0] * w for i in range(h)]


def main():
    R,G,B,N = map(int, stdin.readline().rstrip().split())
    ans = 0
    for r in range(N//R+1):
        for g in range((N-(r*R))//G + 1):
            b = (N - R*r - G*g) / B
            if b%1==0 and b>=0:
                ans += 1
    print(ans)

main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def main():
    n = int(stdin.readline().rstrip())
    s = str(stdin.readline().rstrip())
    #n,m = map(int, stdin.readline().rstrip().split())
    #l = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    ans = n
    for i in range(n):
        left = s[:i]
        right = s[i+1:]
        l = left.count("W")
        r = right.count("E")
        ans = min(ans, r+l)
    print(ans)


main()


Fixed submission:
import sys
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def main():
    n = int(stdin.readline().rstrip())
    s = str(stdin.readline().rstrip())
    #n,m = map(int, stdin.readline().rstrip().split())
    #l = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    ans = n
    dp = [0 for j in range(n+1)]
    for i in range(n):
        if s[i] == "W":
            dp[i+1] = dp[i] + 1
        else:
            dp[i+1] = dp[i]
    for i in range(n):
        ans = min (ans, dp[i] + ( (n-i-1) - (dp[n] - dp[i+1]) ))
    print(ans)


main()
Buggy python submission (verdict: Runtime Error):
from sys import stdin
r, g, b = stdin.readline().rstrip().split()
a = 100*r+10*g+b
if a%4 == 0:
    print("YES")
else:
    print("NO")


Fixed submission:
from sys import stdin
r,g,b = [int(x) for x in stdin.readline().rstrip().split()]
a = 100*r+10*g+b
if a%4 == 0:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())

xy = []
for _ in range(N):
  x,y=map(int,input().split())
  xy.append((x,y))
M,m = 3*(10**9), -3*(10**9)
x_max, x_min, y_max, y_min, t_max, t_min = m,M,m,M,m,M
cand = [xy[0] for _ in range(6)]
for x,y in xy[1:]:
  if x > x_max: x_max = x; cand[0]=(x,y);
  if x < x_min: x_min = x; cand[1]=(x,y);
  if y > y_max: y_max = y; cand[2]=(x,y);
  if y < y_min: y_min = y; cand[3]=(x,y);
  if x+y > t_max: t_max = x+y; cand[4]=(x,y);
  if x+y < t_min: t_min = x+y; cand[5]=(x,y);

ans = 0
for i in range(N-1):
  x1,y1 = xy[i]
  for j in range(i+1,N):
    x2,y2 = xy[j]
    ans = max(ans, abs(x1-x2)+abs(y1-y2))
print(ans)

Fixed submission:
N=int(input())

xy = []
d0, d1 = [],[]
for _ in range(N):
  x,y=map(int,input().split())
  d0.append(x-y)
  d1.append(x+y)
print(max(max(d0)-min(d0), max(d1)-min(d1)))
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
P=list(map(lambda x:int(x)-1,input().split()))
C=list(map(int,input().split()))

dp = []
init = 0

if K<=N:
  ans = set()
  for i in range(N):
    tmp,now,last = [0],i,0
    for _ in range(K):
      last += C[P[now]]
      ans.add(last)
      now=P[now]
  print(max(ans))
  exit()
ans = -10**9
for i in range(N):
  tmp,now,done = [0],i,set()
  for _ in range(N+1):
  #while now not in done:
    tmp.append(tmp[-1]+C[P[now]])
    if P[now] == i:
      break
    now = P[now]
  tmp = tmp[1:]
  cnt = len(tmp)
  m = max(tmp)
  ans = max(ans,m,tmp[-1]*(K//cnt-1)+m)
  if K%cnt != 0:
    ans = max(ans, tmp[-1]*(K//cnt)+max(tmp[:K%cnt]))
    #print(i,ans,tmp)
print(ans)




Fixed submission:
N,K=map(int,input().split())
P=list(map(lambda x:int(x)-1,input().split()))
C=list(map(int,input().split()))

if K<=N:
  ans = -10**9
  for i in range(N):
    now,last = i,0
    for _ in range(K):
      last += C[P[now]]
      ans = max(ans,last)
      now=P[now]
  print(ans)
  exit()
ans = -10**9
for i in range(N):
  tmp,now,done = [0],i,set()
  for _ in range(N+1):
  #while now not in done:
    tmp.append(tmp[-1]+C[P[now]])
    if P[now] == i:
      break
    now = P[now]
  tmp = tmp[1:]
  cnt = len(tmp)
  m = max(tmp)
  ans = max(ans,m,tmp[-1]*(K//cnt-1)+m)
  if K%cnt != 0:
    ans = max(ans, tmp[-1]*(K//cnt)+max(tmp[:K%cnt]))
    #print(i,ans,tmp)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
P=list(map(lambda x:int(x)-1,input().split()))
C=list(map(int,input().split()))

dp = []
init = 0

if K<=N:
  ans = set()
  for i in range(N):
    tmp,now,last = [0],i,0
    for _ in range(K):
      last += C[P[now]]
      ans.add(last)
      now=P[now]
  print(max(ans))
  exit()
ans = -10**9
for i in range(N):
  tmp,now,done = [0],i,set()
  while now not in done:
    done.add(now)
    tmp.append(tmp[-1]+C[now])
    now = P[now]
  cnt = len(done)
  tmp = tmp[1:]
  ans = max(ans,max(tmp))
  if K%cnt == 0:
    ans = max(ans, tmp[-1]*(K//cnt-1)+max(tmp))
  else:
    ans = max(ans, tmp[-1]*(K//cnt-1)+max(tmp), tmp[-1]*(K//cnt)+max(tmp[:K%cnt]))
    #print(i,ans,tmp)
print(ans)




Fixed submission:
N,K=map(int,input().split())
P=list(map(lambda x:int(x)-1,input().split()))
C=list(map(int,input().split()))

if K<=N:
  ans = -10**9
  for i in range(N):
    now,last = i,0
    for _ in range(K):
      last += C[P[now]]
      ans = max(ans,last)
      now=P[now]
  print(ans)
  exit()
ans = -10**9
for i in range(N):
  tmp,now,done = [0],i,set()
  for _ in range(N+1):
  #while now not in done:
    tmp.append(tmp[-1]+C[P[now]])
    if P[now] == i:
      break
    now = P[now]
  tmp = tmp[1:]
  cnt = len(tmp)
  m = max(tmp)
  ans = max(ans,m,tmp[-1]*(K//cnt-1)+m)
  if K%cnt != 0:
    ans = max(ans, tmp[-1]*(K//cnt)+max(tmp[:K%cnt]))
    #print(i,ans,tmp)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
A=list(map(int,input().split()))

score = 1
for i in range(K):
  score *= A[i]
last = score
for i in range(K,N):
  score //=A[i-K]
  score *= A[i]
  #print(score)
  if score > last:
    print('Yes')
  else:
    print('No')
  last = score


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

score = 1
for i in range(K,N):
  if A[i] > A[i-K]:
    print('Yes')
  else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
for n in range(1,N+1):
  n2 = int(n**0.5)+1
  cnt = 0
  for x in range(1,n2):
    for y in range(x,n2):
      for z in range(y,n2):
        #if n == 18:
          #print(x,y,z,x**2+y**2+z**2+x*y+y*z+z*x)
        if x**2+y**2+z**2+x*y+y*z+z*x != n:
          continue
        if x==y and y==z:
          cnt += 1
        elif x==y or y==z or z==x:
          cnt += 3
        else:
          cnt += 6
  print(cnt)

Fixed submission:
N=int(input())
S = set([s**2 for s in range(2,int(N**0.5)+1)])
ans = [0]*(N+1)
for x in range(1,100):
  for y in range(1,100):
    for z in range(1,100):
      n = x*x+y*y+z*z+x*y+y*z+z*x
      if n<=N:
        ans[n]+=1
for v in ans[1:]:
  print(v)
Buggy python submission (verdict: Runtime Error):
k = ['AC','WA','TLE','RE']
n=int(input())
ans = {}
for _ in range(n):
  r = input()
  ans[r]=ans.get(r,0)+1
for r in k:
  print(r,'x',ans[r].get(r,0))


Fixed submission:
k = ['AC','WA','TLE','RE']
n=int(input())
ans = {}
for _ in range(n):
  r = input()
  ans[r]=ans.get(r,0)+1
for r in k:
  print(r,'x',ans.get(r,0))
Buggy python submission (verdict: Runtime Error):
from collections import deque
n,m,k=map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

a,b=[0],[0]
for i in range(n):
  a.append(a[i]+A[i])
for i in range(m):
  b.append(b[i]+B[i])
ans, j = 0,m
for i in range(N+1):
  if a[i]>k: break
  while b[j] > k-a[i]:
    j -= 1
  ans = max(ans,i+j)
print(ans)

Fixed submission:
from collections import deque
n,m,k=map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

a,b=[0],[0]
for i in range(n):
  a.append(a[i]+A[i])
for i in range(m):
  b.append(b[i]+B[i])
ans, j = 0,m
for i in range(n+1):
  if a[i]>k: break
  while b[j] > k-a[i]:
    j -= 1
  ans = max(ans,i+j)
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
from math import log, floor
  
def ten_to_n(X,n):
  if X//n:
    ans = ten_to_n(X//n,n)
    ans.append(X%n)
    return ans
  else:
    return [X%n]
  
dic = {}
l = ten_to_n(n-1,26)
l[-1]+=1
for i in range(len(l)-1,0,-1):
  if l[i] > 25:
    t = l[i]
    l[i-1] += t//26
    l[i] = t%26
#print(l)
    
for v1,v2 in zip(range(1,27),'abcdefghijklmnopqrstuvwxyz'):
  dic[v1]=v2
ans = ''.join([dic[v] for v in l])
print(ans)  



Fixed submission:
n=int(input())
from math import log, floor
dic = {}    
for v1,v2 in zip(range(26),'abcdefghijklmnopqrstuvwxyz'):
  dic[v1]=v2
ans = ''
for i in range(1,99):
  if n <= 26**i:
    n-=1
    for j in range(i):
      ans += dic[n%26]
      n //= 26
    break
  else:
    n -= 26**i

print(ans[::-1])
Buggy python submission (verdict: Runtime Error):
from statistics import median
import math
n=int(input())
A,B = [],[]
for _ in range(n):
  a,b=map(int,input().split())
  A.append(a)
  B.append(b)
a1,b2 = int(median(A)),math.ceil(median(B))
b1 = max([B[i] for i,v in enumerate(A) if v == a1])
a2 = max([A[i] for i,v in enumerate(B) if v == b2])
#print(a1,b1,a2,b2)
if b1<a2:
  print(b1-a1+b2-a2+1)
  exit()
print(b2-a1+1)


Fixed submission:
from statistics import median
n=int(input())
A,B=[],[]
for _ in range(n):
  a,b=map(int,input().split())
  A.append(a*2)
  B.append(b*2)
ma,mb = int(median(A)),int(median(B))
#print(ma,mb)
if n%2 == 0:
  print(mb-ma+1)
else:
  print((mb-ma)//2+1)
Buggy python submission (verdict: Runtime Error):
from math import gcd
mod=1000000007

n=int(input())
zeros = 0
vec = {}
for _ in range(n):
  a,b=map(int,input().split())
  if a==0 and b==0:
    zeros+=1
    continue
  elif a==0:
    vec[(0,1)]=vec.get((0,1),0)+1
  elif b==0:
    vec[(1,0)]=vec.get((1,0),0)+1
  else:
    g = gcd(a,b)
    a,b= a//g,b//g
    vec[(a,b)]=vec.get((a,b),0)+1
done = set()
total=1
for (a,b),v in vec.items():
  if (-b,a) in done or (b,-a) in done: continue
  done.add((a,b))
  w=vec[(-b,a)]+vec[(b,-a)]
  total *= (pow(2,v,mod)+pow(2,w,mod)-1)
  total %= mod
print((total+zeros-1+mod)%mod)


Fixed submission:
from math import gcd
mod = 10**9+7
n=int(input())
r = dict()
zeros = 0
for _ in range(n):
  a,b=map(int,input().split())
  if not any((a,b)):
    zeros+=1
    continue
  if all((a,b)):
    g = gcd(a,b)*(a//abs(a))
  elif a:
    g = a
  else:
    g = b
  p = a//g,b//g
  r[p] = r.get(p,0)+1
ans = 1
done = set()
for (a,b), v in r.items():
  if (b,-a) in done or (-b,a) in done:
    continue
  done.add((a,b))
  w = r.get((b,-a),0)+r.get((-b,a),0)
  ans = ans*(pow(2,v,mod)+pow(2,w,mod)-1)%mod
  
print((ans+zeros+mod-1)%mod)
Buggy python submission (verdict: Runtime Error):
n=int(input())
A=list(map(int,input().split()))
L,R={},{}
for i,a in enumerate(A):
  l,r = i-a,i+a
  if l in L: L[l]=0
  if r in R: R[r]=0
  L[l]+=1
  R[r]+=1

count = 0
for x in L:
  if x not in R: continue
  count += L[x]*R[x]
print(count)

Fixed submission:
N = int(input())
A = [int(v) for v in input().split()]
L, R = {}, {}
for i,a in enumerate(A):
  l,r = i+a,i-a
  if l not in L: L[l]=0
  if r not in R: R[r]=0
  L[l]+=1
  R[r]+=1

count = 0
for X in L:
  if X not in R: continue
  count += L[X]*R[X]
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
A = list(map(int,input().split()))
#t = {}
#for i,a in enumerate(A):
#  if a not in t: t[a]=0
#  t[a]+=1
ans = 0
for k in range(1,n):
  for i in range(k,n):
    if A[i] + A[i-k] == k:
      ans += 1
print(ans)
  

Fixed submission:
N = int(input())
A = [int(v) for v in input().split()]
L, R = {}, {}
for i,a in enumerate(A):
  l,r = i+a,i-a
  if l not in L: L[l]=0
  if r not in R: R[r]=0
  L[l]+=1
  R[r]+=1

count = 0
for X in L:
  if X not in R: continue
  count += L[X]*R[X]
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(v) for v in input().split()]
count = 0
for i in range(len(A)-1):
  for j in range(i+1,len(A)):
    a1,a2 = A[i],A[j]
    diff = j-i
    if diff == a1+a2:
      count += 1
print(count)

Fixed submission:
N = int(input())
A = [int(v) for v in input().split()]
L, R = {}, {}
for i,a in enumerate(A):
  l,r = i+a,i-a
  if l not in L: L[l]=0
  if r not in R: R[r]=0
  L[l]+=1
  R[r]+=1

count = 0
for X in L:
  if X not in R: continue
  count += L[X]*R[X]
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
import collections

S=input()
S_int = int(S)
mods = [int(S[i:])%2019 for i in range(len(S))]
mods.append(0)
mods_count = collections.Counter(mods)
count = 0
for mod in mods_count:
  c = mods_count[mod]
  count += c*(c-1)//2
#print(mods)
#print(mods_count)
print(count)

Fixed submission:
S=input()
dp = {0:1}

p=0
q=1

for i in range(len(S)-1,-1,-1):
  p += (int(S[i])*q)
  p = p%2019
  q *= 10
  q = q%2019
  if p not in dp:
    dp[p]=0
  dp[p]+=1

#print(dp)
c = 0
for v in dp:
  c += dp[v]*(dp[v]-1)//2
print(c)

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

S=input()
S_int = int(S)
interval = 2019
current = 2019
#A=[]
count = 0
for i in range(len(S)):
  for j in range(i+4,len(S)+1):
    if int(S[i:j])%2019 == 0:
      #A.append([i+1,j])
      count += 1
#print(len(A))
print(count)

Fixed submission:
S=input()
dp = {0:1}

p=0
q=1

for i in range(len(S)-1,-1,-1):
  p += (int(S[i])*q)
  p = p%2019
  q *= 10
  q = q%2019
  if p not in dp:
    dp[p]=0
  dp[p]+=1

#print(dp)
c = 0
for v in dp:
  c += dp[v]*(dp[v]-1)//2
print(c)

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

S=input()
S_int = int(S)
interval = 2019
current = 2019
A=[]
for i in range(len(S)):
  for j in range(i+4,len(S)+1):
    if int(S[i:j])%2019 == 0:
      A.append([i+1,j])
print(len(A))

Fixed submission:
S=input()
dp = {0:1}

p=0
q=1

for i in range(len(S)-1,-1,-1):
  p += (int(S[i])*q)
  p = p%2019
  q *= 10
  q = q%2019
  if p not in dp:
    dp[p]=0
  dp[p]+=1

#print(dp)
c = 0
for v in dp:
  c += dp[v]*(dp[v]-1)//2
print(c)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
A=sum(list(map(int,input().split())))
print(max(-1,N-A))

Fixed submission:
n,m=map(int,input().split())
A=list(map(int,input().split()))
print(max(-1,n-sum(A)))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()

count = 0
for i in range(len(S)):
  for j in range(i,len(S)):
    if S[i] == S[j]: continue
    for k in range(j,len(S)):
      if k-j == j-i: continue
      if S[i] == S[k] or S[j] == S[k]:continue
      count+=1
print(count)
      

Fixed submission:
N=int(input())
S=input()
r,g,b = S.count('R'),S.count('G'),S.count('B')
total = r*g*b

count = 0
for d in range(1,N):
  for i in range(N-2*d):
    if S[i]!=S[i+d] and S[i+d]!=S[i+2*d] and S[i+2*d] != S[i]:
      count+=1

print(total-count)
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
while abs(N-K) < N:
  N = abs(N-K)
print(N)

Fixed submission:
N,K=map(int,input().split())
if N > K:
  N = N%K
print(min(N,abs(N-K)))
Buggy python submission (verdict: Time Limit Exceeded):
N,X,Y=map(int,input().split())
def dist(i,j):
  return min([j-i,abs(X-1-i)+1+abs(Y-1-j),abs(Y-1-i)+1+abs(X-1-j)])
dists = []
for i in range(N-1):
  for j in range(i+1,N):
    dists.append(dist(i,j))
for i in range(1,N):
  print(len([str(v) for v in dists if v == i]))
  
    

Fixed submission:
N,X,Y=map(int,input().split())
def dist(i,j):
  return min([j-i,abs(X-1-i)+1+abs(Y-1-j),abs(Y-1-i)+1+abs(X-1-j)])
dists = {v:0 for v in range(1,N)}
for i in range(N-1):
  for j in range(i+1,N):
    d = dist(i,j)
    dists[d]+=1
for i in range(1,N):
  print(dists[i])