Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def gcd(n,m):
    while n:
        m,n = [n,m%n]
    return m

def prime(N):
    se = [0,0,1]+[1]*(N-2)
    n = 2
    while n ** 2 <= N:
        if se[n]:
            nn = 2*n
            while nn <= N:
                se[nn] = 0
                nn += n
        n += 1

    return [x for x in range(0,N+1) if se[x]]

A,B = map(int,input().split())

S = gcd(A,B)

s = 1
for i in prime(S):
    hoge = 0
    while S % i == 0:
        hoge += 1
        S //= i
    if hoge:
        s += 1

print(s)

Fixed submission:
def gcd(n,m):
    while n:
        m,n = [n,m%n]
    return m

A,B = map(int,input().split())

S = gcd(A,B)

s = 1
i = 2
while True:
    if S == 1:
        break
    if i ** 2 >= S:
        break
    hoge = 0
    while S % i == 0:
        hoge += 1
        S //= i
    if hoge:
        s += 1
    i += 1

print(s + (S != 1))

Buggy python submission (verdict: Time Limit Exceeded):
def gcd(n,m):
    while n:
        m,n = [n,m%n]
    return m

A,B = map(int,input().split())

S = gcd(A,B)

s = 1
i = 2
while S != 1:
    hoge = 0
    while S % i == 0:
        hoge += 1
        S //= i
    if hoge:
        s += 1
    i += 1

print(s)

Fixed submission:
def gcd(n,m):
    while n:
        m,n = [n,m%n]
    return m

A,B = map(int,input().split())

S = gcd(A,B)

s = 1
i = 2
while True:
    if S == 1:
        break
    if i ** 2 >= S:
        break
    hoge = 0
    while S % i == 0:
        hoge += 1
        S //= i
    if hoge:
        s += 1
    i += 1

print(s + (S != 1))

Buggy python submission (verdict: Time Limit Exceeded):
def gcd(n,m):
    while n:
        m,n = [n,m%n]
    return m

A,B = map(int,input().split())

S = gcd(A,B)

s = {1}
i = 2
while S != 1:
    while S % i == 0:
        S //= i
        s |= {i}
    i += 1

print(len(s))

Fixed submission:
def gcd(n,m):
    while n:
        m,n = [n,m%n]
    return m

A,B = map(int,input().split())

S = gcd(A,B)

s = 1
i = 2
while True:
    if S == 1:
        break
    if i ** 2 >= S:
        break
    hoge = 0
    while S % i == 0:
        hoge += 1
        S //= i
    if hoge:
        s += 1
    i += 1

print(s + (S != 1))
Buggy python submission (verdict: Runtime Error):
N,K,Q= map(int,input().split())
score = [K-Q]*N
A = [0]*Q
for i in range(Q):
    A[i] = int(input())

for a in A:
    score[a] += 1

print(*map(lambda x:['No','Yes'][x>0],score),sep='\n')

Fixed submission:
N,K,Q = map(int,input().split())
score = [K-Q]*N
A = [0]*Q
for i in range(Q):
    A[i] = int(input())

for a in A:
    score[a-1] += 1

for i in map(lambda x:['No','Yes'][x>0],score):
    print(i)
Buggy python submission (verdict: Runtime Error):
import heapq

N , M = map(int,input().split())
A = list(map(lambda x:-int(x),input().split()))

heapq.heapify(A)
for _ in range(M):
    largest = heapq.heappop(A)
    largest = -((-largest)//2)
    if largest != 0:
        heapq.heappush(A, largest)

print(-sum(A))

Fixed submission:
import heapq

N , M = map(int,input().split())
A = list(map(lambda x:-int(x),input().split()))

heapq.heapify(A)
for _ in range(M):
    largest = heapq.heappop(A)
    largest = -((-largest)//2)
    heapq.heappush(A, largest)

print(-sum(A))
Buggy python submission (verdict: Runtime Error):
import itertools
from collections import Counter
from collections import defaultdict

d = defaultdict(lambda:-1)
N = int(input())
X = [0]*N
Y = [0]*N
for i in range(N):
    X[i],Y[i] = map(int,input().split())
    d[(X[i],Y[i])] = i

o = []
for i,j in itertools.product(range(N),range(N)):
    if i == j:
        continue
    x = X[i] - X[j]
    y = Y[i] - Y[j]
    o.append((x,y))

p,q = Counter(o).most_common()[0][0]
o = []
for i in range(N):
    a = i
    while True:
        b = d[(X[a]+p,Y[a]+q)]
        if b == -1:
            o.append(a)
            break
        a = b

print(len(set(o)))

Fixed submission:
import itertools
from collections import Counter
from collections import defaultdict

d = defaultdict(lambda:-1)
N = int(input())
X = [0]*N
Y = [0]*N
for i in range(N):
    X[i],Y[i] = map(int,input().split())
    d[(X[i],Y[i])] = i

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

o = []
for i,j in itertools.product(range(N),range(N)):
    if i == j:
        continue
    x = X[i] - X[j]
    y = Y[i] - Y[j]
    o.append((x,y))

p,q = Counter(o).most_common()[0][0]
o = []
for i in range(N):
    a = i
    while True:
        b = d[(X[a]+p,Y[a]+q)]
        if b == -1:
            o.append(a)
            break
        a = b

print(len(set(o)))
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
a = [0]*M
for i in range(M):
    a[i] = int(input())

b = [(-1 if x in a else 0) for x in range(N+1)]

b[0] = 1

mod = 10**9+7
for i in range(1,N+1):
    if b[i] == -1:
        continue
    if i == 1:
        b[i] = b[0]
    else:
        b[i] = max(b[i-1],0) + max(b[i-2],0)
    b[i] %= mod

print(b[N])

Fixed submission:
from collections import Counter

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

c = Counter(a).keys()

b = [(-1 if x in c else 0) for x in range(N+1)]

b[0] = 1

mod = 10**9+7
for i in range(1,N+1):
    if b[i] == -1:
        continue
    if i == 1:
        b[i] = b[0]
    else:
        b[i] = max(b[i-1],0) + max(b[i-2],0)
    b[i] %= mod

print(b[N])
Buggy python submission (verdict: Runtime Error):
from math import gcd

R,G,B,N = map(int,input().split(" "))

C = G * B // gcd(G,B)

s = 0
b = 0
while b <= N:
    bb = b
    while bb <= N:
        if (N - bb) % B == 0:
            s += (N - bb) // C + 1
            bb = N + 1
        else:
            bb += G
    b += R

print(s)

Fixed submission:
def gcd(n,m):
    while n > 0:
        a = n
        n = m % n
        m = a
    return m

R,G,B,N = map(int,input().split(" "))

C = G * B // gcd(G,B)

s = 0
b = 0
while b <= N:
    bb = b
    while bb <= N:
        if (N - bb) % B == 0:
            s += (N - bb) // C + 1
            bb = N + 1
        else:
            bb += G
    b += R

print(s)

Buggy python submission (verdict: Runtime Error):
R,G,B,N = map(int,input().split(" "))

from math import gcd

C = G * B // gcd(G,B)

s = 0
b = 0
while b <= N:
    bb = b
    while bb <= N:
        if (N - bb) % B == 0:
            s += (N - bb) // C + 1
            bb = N + 1
        else:
            bb += G
    b += R

print(s)

Fixed submission:
def gcd(n,m):
    while n > 0:
        a = n
        n = m % n
        m = a
    return m

R,G,B,N = map(int,input().split(" "))

C = G * B // gcd(G,B)

s = 0
b = 0
while b <= N:
    bb = b
    while bb <= N:
        if (N - bb) % B == 0:
            s += (N - bb) // C + 1
            bb = N + 1
        else:
            bb += G
    b += R

print(s)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split(" ")))

def gcd(m,n):
    while n != 0:
        a = n
        n = m % n
        m = a
    return m

l = [0]*N
r = [0]*N

l[0] = A[0]
r[-1] = A[-1]

for x in range(1,N):
    y = N - 1 - x
    l[x] = gcd(A[x],l[x-1])
    r[y] = gcd(A[y],r[y+1])

l.insert(0,0)
l.append(0)
r.insert(0,0)
r.append(0)

o = 1

for x in range(N):
    x += 1
    o = max(o,gcd(l[x-1],r[x+1]))

print(max(o))

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

def gcd(m,n):
    while n != 0:
        a = n
        n = m % n
        m = a
    return m

l = [0]*N
r = [0]*N

l[0] = A[0]
r[-1] = A[-1]

for x in range(1,N):
    y = N - 1 - x
    l[x] = gcd(A[x],l[x-1])
    r[y] = gcd(A[y],r[y+1])

l.insert(0,0)
l.append(0)
r.insert(0,0)
r.append(0)

o = 1

for x in range(N):
    o = max(o,gcd(l[x],r[x+2]))

print(o)

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

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

gcd = math.gcd

l = [0]*N
r = [0]*N

l[0] = A[0]
r[-1] = A[-1]

for x in range(1,N):
    l[x] = gcd(A[x],l[x-1])

for x in range(N-2,-1,-1):
    r[x] = gcd(A[x],r[x+1])

l.insert(0,0)
l.append(0)
r.insert(0,0)
r.append(0)

o = []

for x in range(N):
    o.append(gcd(l[x-1],r[x+1]))

print(max(o))

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

def gcd(m,n):
    while n != 0:
        a = n
        n = m % n
        m = a
    return m

l = [0]*N
r = [0]*N

l[0] = A[0]
r[-1] = A[-1]

for x in range(1,N):
    y = N - 1 - x
    l[x] = gcd(A[x],l[x-1])
    r[y] = gcd(A[y],r[y+1])

l.insert(0,0)
l.append(0)
r.insert(0,0)
r.append(0)

o = 1

for x in range(N):
    o = max(o,gcd(l[x],r[x+2]))

print(o)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
P = list(map(lambda x: int(x)-1,input().split()))
tree = list(range(N))

def root(n):
    while True:
        if tree[n] == n:
            return n
        n = tree[n]

for i in range(M):
    x,y = map(lambda x: int(x)-1,input().split())
    rx = root(x)
    ry = root(y)
    if rx == ry:
        continue
    tree[rx] = ry

print(sum(map(lambda x: root(x)==root(P[x]),range(N))))


Fixed submission:
N,M = map(int,input().split())
P = list(map(lambda x: int(x)-1,input().split()))
tree = list(range(N))

def root(n):
    O = {n}
    while True:
        if tree[n] == n:
            for o in O:
                tree[o] = n
            return n
        n = tree[n]
        O.add(n)

for i in range(M):
    x,y = map(lambda x: int(x)-1,input().split())
    rx = root(x)
    ry = root(y)
    if rx == ry:
        continue
    tree[rx] = ry

print(sum(map(lambda x: root(x)==root(P[x]),range(N))))
Buggy python submission (verdict: Runtime Error):
a,b = map(int, raw_input().split())
print("Odd" if a*b % 2 else "Even")


Fixed submission:
a,b = map(int, input().split())
print("Odd" if a*b % 2 else "Even")

Buggy python submission (verdict: Runtime Error):
a,b = map(int, raw_input().split())
print "Odd" if a*b % 2 else "Even"

Fixed submission:
a,b = map(int, input().split())
print("Odd" if a*b % 2 else "Even")
Buggy python submission (verdict: Runtime Error):
a,b = input().split()
c = math.ceil(math.sqrt(int(a+b)))
print("Yes" if c * 2 == int(a+b) else "No")


Fixed submission:
a,b = input().split()
c = int(a+b)
i = 0
txt = "No"
while i * i <= c:
  if i * i == c:
    txt = "Yes"
    break
  i = i + 1
print(txt)

Buggy python submission (verdict: Runtime Error):
a,b = raw_input().split()
c = math.ceil(math.sqrt(int(a+b)))
print("Yes" if c * 2 == int(a+b) else "No")

Fixed submission:
a,b = input().split()
c = int(a+b)
i = 0
txt = "No"
while i * i <= c:
  if i * i == c:
    txt = "Yes"
    break
  i = i + 1
print(txt)
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
D = [9999]*K
D[1] = 1
H = []
H.append(1)
while len(H) != 0:
    h = H.pop()
    if D[(h*10)%K] > D[h]:
        D[(h*10)%K] = D[h]
        H.append((h*10)%K)
    if D[(h+1)%K] > D[h] + 1:
        D[(h+1)%K] = D[h] + 1
        H.append((h+1)%K)

print(D[0])

Fixed submission:
from collections import deque

K = int(input())
D = [-1]*K
Q = deque()
Q.append([1,0])
while D[0] == -1:
    k,v = Q.popleft()
    D[k] = v
    j = (k*10)%K
    if D[j] == -1:
        Q.appendleft([j,v])
    l = (k+1)%K
    if D[l] == -1:
        Q.append([l,v+1])

print(D[0]+1)

Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
INF = float('inf')
D = [-1]*K
C = [1]*K
D[1] = 0
while C[0]:
    m = min(filter(lambda x:C[x] and D[x] != -1,range(K)),key=lambda x:D[x])
    j = (10*m)%K
    D[j] = D[m] if D[j]==-1 else min(D[j],D[m])
    l = (m+1)%K
    D[l] = D[m]+1 if D[l]==-1 else min(D[l],D[m]+1)
    C[m] = 0

print(D[0]+1)

Fixed submission:
from collections import deque

K = int(input())
D = [-1]*K
Q = deque()
Q.append([1,0])
while D[0] == -1:
    k,v = Q.popleft()
    D[k] = v
    j = (k*10)%K
    if D[j] == -1:
        Q.appendleft([j,v])
    l = (k+1)%K
    if D[l] == -1:
        Q.append([l,v+1])

print(D[0]+1)
Buggy python submission (verdict: Runtime Error):
A,B=input().split(" ")
print("Impossible" if A*B*(A+B)%3 else "Possible")

Fixed submission:
A,B=map(int,input().split(" "))
print("Impossible" if A*B*(A+B)%3 else "Possible")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split(" ")))

o = []
for i in range(n):
    if i % 2:
        o.insert(0,a[i])
    else:
        o.append(a[i])

print(' '.join(map(str,o[::-1] if n%2 else o)))

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

o = [0] * n
c = n//2
r = c
l = c - 1
for i in range(n):
    if i % 2:
        o[l] = a[i]
        l -= 1
    else:
        o[r] = a[i]
        r += 1

if n % 2:
    for i in range(n):
        if i:
            print(' ',end='')
        print(o[n-1-i],end='')
else:
    for i in range(n):
        if i:
            print(' ',end='')
        print(o[i],end='')
Buggy python submission (verdict: Runtime Error):
input()
a = map(int,input().split(" "))
print(max(a)-min(a))

Fixed submission:
N = int(input())
a = list(map(int,input().split(" ")))
print(max(a)-min(a))
Buggy python submission (verdict: Runtime Error):
A,B = input().split(" ")

def compare(A,B):
    if A == B:
        return 'EQUAL'
    if len(A) > len(B):
        return 'GREATER'
    if len(B) > len(A):
        return 'LESS'
    for i in range(len(A)):
        a = int(A[i])
        b = int(B[i])
        if a > b:
            return 'GREATER'
        if b > a:
            return 'LESS'

print(compare(A,B))

Fixed submission:
A = input()
B = input()

def compare(A,B):
    if A == B:
        return 'EQUAL'
    if len(A) > len(B):
        return 'GREATER'
    if len(B) > len(A):
        return 'LESS'
    for i in range(len(A)):
        a = int(A[i])
        b = int(B[i])
        if a > b:
            return 'GREATER'
        if b > a:
            return 'LESS'

print(compare(A,B))
Buggy python submission (verdict: Time Limit Exceeded):
#create date: 2020-09-19 21:14

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n, x, m = na()
    ans = x
    l = [x]
    a = x
    for i in range(n-1):
        a = a**2
        a %= m
        if a == 0:
            ans += a
            print(ans)
            quit()
        if a in l:
            #print(a, l)
            j = l.index(a)
            r = i - j + 1
            res = sum(l[j:])
            k = ((n-i-1)%r)
            #print(k, n-i-1, r, l[j:(j+k)])
            ans += (n-i-1)//r * res + sum(l[j:(j+k)])
            break
        l.append(a)
        ans += a
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
#create date: 2020-09-19 21:14

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n, x, m = na()
    ans = x
    l = [x]
    a = x
    for i in range(n-1):
        a = a**2
        a %= m
        if a == 0:
            ans += a
            print(ans)
            quit()
        if a in l:
            #print(a, l)
            j = l.index(a)
            r = i - j + 1
            res = sum(l[j:])
            k = ((n-i-1)%r)
            #print(k, n-i-1, r, l[j:(j+k)])
            ans += (n-i-1)//r * res + sum(l[j:(j+k)])
            break
        l.append(a)
        ans += a
    print(ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#create date: 2020-06-29 09:42

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    a = na()
    alist = [0] * (10**5 + 1)
    for ai in a:
        alist[ai] += 1
    q = ni()
    for i in range(q):
        b, c = na()
        alist[c] += alist[b]
        alist[b] = 0
        ans = 0
        
        for i, num in enumerate(alist):
            ans += i*num
        print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
#create date: 2020-06-29 09:42

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    a = na()
    alist = [0] * (10**5 + 1)
    for ai in a:
        alist[ai] += 1
    asum = 0
    for i, num in enumerate(alist):
            asum += i*num

    q = ni()
    for i in range(q):
        b, c = na()
        asum += alist[b] * (c-b)
        alist[c] += alist[b]
        alist[b] = 0
        print(asum)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

import numpy as np

x = na()
for i, xi in enumerate(x):
    if xi==0:
        print(i+1)

Fixed submission:
import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

import numpy as np

x = na()
for i, xi in enumerate(x):
    if xi==0:
        print(i+1)
Buggy python submission (verdict: Runtime Error):

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

import numpy as np

x, y = na()
if y % 2 == 0 and y / x <= 4:
    print("Yes")
else:
    print("No")

Fixed submission:

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

x, y = na()
for t in range(100):
    for k in range(100):
        if x == (t + k) and y == 2*t + 4*k:
            print("Yes")
            quit()
print("No")
Buggy python submission (verdict: Runtime Error):

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

x, n =na()
p = na()
notp = list()
for i in range(1, 101):
    if i in p:
        continue
    notp.append(i)
ans = notp[0]

for i in notp:
    if abs(ans - x) > abs(i - x):
        ans = i
print(ans)
    

Fixed submission:

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

x, n =na()
p = na()

ans = x
for i in range(100):
    temp = x - i
    if not temp in p:
        print(temp)
        quit()
    temp = x + i
    if not temp in p:
        print(temp)
        quit()
Buggy python submission (verdict: Time Limit Exceeded):
#create date: 2020-06-14 10:29

import sys
stdin = sys.stdin
from itertools import accumulate

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n, k = na()
    a = na()
    def step():
        b = [0] * n
        for i, ai in enumerate(a):
            start, stop = i - ai, i + ai + 1
            if start > 0:
                b[start] += 1
            else:
                b[0] += 1
            if stop < n:
                b[stop] -= 1
        return list(accumulate(b))

    for i in range(k):
        anext = step()
        if sum(a) == sum(anext):
            print(*a)
            quit()
        a = anext
    print(*a)


if __name__ == "__main__":
    main()

Fixed submission:
#create date: 2020-06-14 10:29

import sys
stdin = sys.stdin
from itertools import accumulate

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n, k = na()
    a = na()
    def step():
        b = [0] * n
        for i, ai in enumerate(a):
            start, stop = i - ai, i + ai + 1
            if start > 0:
                b[start] += 1
            else:
                b[0] += 1
            if stop < n:
                b[stop] -= 1
        return list(accumulate(b))

    for i in range(k):
        anext = step()
        if sum(a) == sum(anext):
            print(*a)
            quit()
        a = anext
    print(*a)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#create date: 2020-05-03 21:37

import sys
stdin = sys.stdin

import numpy as np

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    a = np.array(na())
    b = np.arange(1, n+1)
    #print(a, b)
    ans = 0
    for i in range(n):
        anow = a[i]
        j = i+anow+1
        if j < n:
            ans += sum(a[j:]== b[:n-j])
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
#create date: 2020-05-03 21:37

import sys
stdin = sys.stdin
from collections import defaultdict

import numpy as np

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    a = np.array(na())
    b = np.arange(1, n+1)
    c = a + b
    d = b - a
    l = defaultdict(lambda: 0)
    ans = 0
    for ci in c:
        l[ci] += 1
    for di in d:
        ans += l[di]
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
#create date: 2020-05-03 21:37

import sys
stdin = sys.stdin

import numpy as np

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    a = np.array(na())
    b = np.arange(1, n+1)
    #print(a, b)
    ans = 0
    for i in range(n):
        anow = a[i]
        j = i+anow+1
        if j < n:
            ans += sum(a[j:]== b[:n-j])
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
#create date: 2020-05-03 21:37

import sys
stdin = sys.stdin
from collections import defaultdict

import numpy as np

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    a = np.array(na())
    b = np.arange(1, n+1)
    c = a + b
    d = b - a
    l = defaultdict(lambda: 0)
    ans = 0
    for ci in c:
        l[ci] += 1
    for di in d:
        ans += l[di]
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#create date: 2020-05-02 21:28

import sys
stdin = sys.stdin
from itertools import product

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n, m, q = na()
    l = list()
    for i in range(q):
        l.append(na())
    ans = 0
    for switch in product(range(1, m+1), repeat=n):
        switch = list(switch)
        switch.sort()
        s = switch
        cnt = 0
        for a, b, c, d in l:
            a -= 1
            b -= 1
            if s[b] - s[a] ==c:
                cnt += d
        ans = max(cnt, ans)
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
#create date: 2020-06-30 14:42

import sys
stdin = sys.stdin
from itertools import combinations_with_replacement

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n, m, q = na()
    matrix = list()
    for i in range(q):
        matrix.append(na())
    l = list(combinations_with_replacement(range(1, m+1), n))
    ans = 0
    for li in l:
        res = 0
        for q in matrix:
            a, b, c, d = q
            if li[b-1] - li[a-1] == c:
                res += d
        ans = max(ans, res)
    print(ans)

if __name__ == "__main__":
    main()