Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(N):
  k = A[i]
  ans += len([0 for j in range(i + k, N) if j - i == A[i] + A[j]])
else:
  print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
L = {}
R = {}
ans = 0
for i in range(N):
  t = i + 1 + A[i]
  if t in L:
    L[t] += 1
  else:
    L[t] = 1
  t = i + 1 - A[i]
  if t > 0:
    if t in R:
      R[t] += 1
    else:
      R[t] = 1
for i in R:
  if i in L:
    ans += R[i] * L[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(N):
  #print(i, "------------------------------")
  k = A[i]
  for j in range(i + k, N):
    #print(j - i, A[i] + A[j])
    if j - i == A[i] + A[j]:
      #print(i, j, A[i], A[j])
      ans += 1
else:
  print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
L = {}
R = {}
ans = 0
for i in range(N):
  t = i + 1 + A[i]
  if t in L:
    L[t] += 1
  else:
    L[t] = 1
  t = i + 1 - A[i]
  if t > 0:
    if t in R:
      R[t] += 1
    else:
      R[t] = 1
for i in R:
  if i in L:
    ans += R[i] * L[i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
K = int(input()) + 1
A = 0
for a in range(1, K):
    for b in range(1, K):
        for c in range(1, K):
            A += math.gcd(math.gcd(a, b), c)
print(A)

Fixed submission:
import math
import itertools

K = int(input()) + 1
L = list(itertools.combinations_with_replacement(list(range(1, K)), 3))
a = 1
A = 0
for i in L:
  if len(set(i)) == 3:
    a = 6
  elif len(set(i)) == 2:
    a = 3
  else:
    a = 1
  A += math.gcd(math.gcd(i[0], i[1]), i[2]) * a
print(A)
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
c = 1
i = 1
while c != K:
  i += 1
  S = str(i)
  l = len(S) - 1
  for j in range(l):
    if abs(int(S[j]) - int(S[j+1])) > 1:
      break
  else:
    c += 1    
print(i)

Fixed submission:
K = int(input())
A = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in range(K):
  x = A[i]
  if x % 10 != 0:
    A.append(10 * x + (x % 10) - 1)
  A.append(10 * x + (x % 10))
  if x % 10 != 9:
    A.append(10 * x + (x % 10) + 1)
else:
  print(A[i])
Buggy python submission (verdict: Runtime Error):
N, A, B = map(int, input().split())
if A == :
  print(0)
else:
  print(N) if A > N else print(A if N < (A + B) else N - B)

Fixed submission:
N, A, B = map(int, input().split())
if A == 0:
  print(0)
elif A > N or B == 0:
  print(N)
else:
  M = N // (A + B)
  if N - M * (A + B) > A:
    print(A * M + A)
  else:
    print(N - M * B)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = [-1] * N
for i in range(M):
  t = list(map(int, input().split()))
  if t == [1, 0] and N != 1:
    print(-1)
    exit()
  elif A[t[0] - 1] == -1:
    A[t[0] - 1] = t[1]
  elif A[t[0] - 1] != t[1]:
    print(-1)
    exit()
B = [A[k] * (10 ** (M - 1 - k)) for k in range(M) if A[k] > 0]
print(sum(B))

Fixed submission:
N, M = map(int, input().split())
A  = [-1] * N
for i in range(M):
  t = list(map(int, input().split()))
  if A[t[0] - 1] == -1:
    A[t[0] - 1] = t[1]
  elif A[t[0] - 1] != t[1]:
    print(-1)
    exit()
if N != 1 and A[0] == 0:
  print(-1)
  exit()
elif A.count(-1) == N and N != 1:
  print(1 * 10 ** (N - 1))
  exit()
elif A[0] == -1:
  if N == 1:
    A[0] = 0
  else:
    A[0] = 1
B = [A[j] * 10 ** (N - 1 - j) for j in range(N) if A[j] > 0]
print(sum(B))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = list(map(int, input().split()))
A = [1 for i in range(1, N) if P[i] <= min(P[:i])]
print(sum(A) + 1)

Fixed submission:
N = int(input())
P = list(map(int, input().split()))
A = 1
M = P[0]
for i in range(1, N):
  M = min(M, P[i])
  if P[i] <= M:
    A += 1
print(A)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = list(map(int, input().split()))
A = 1
for i in range(1, N):
  if P[i] <= min(P[:i]):
    A += 1
print(A)

Fixed submission:
N = int(input())
P = list(map(int, input().split()))
A = 1
M = P[0]
for i in range(1, N):
  M = min(M, P[i])
  if P[i] <= M:
    A += 1
print(A)
Buggy python submission (verdict: Runtime Error):
A=input().split()
if int(A[0])*500 => int(A[1]):
  print('Yes')
else:
  print('No')

Fixed submission:
A = input().split()
if 500 * int(A[0]) >= int(A[1]):
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
import math
N = int(input())
if N % 2 == 1:
  print(0)
else:
  print(sum([int(math.log10(i)) for i in range(1, N + 1) if i % 10 == 0]))

Fixed submission:
L = [10, 50, 250, 1250, 6250, 31250, 156250, 781250, 3906250, 19531250, 97656250, \
     488281250, 2441406250, 12207031250, 61035156250, 305175781250, 1525878906250, \
     7629394531250, 38146972656250, 190734863281250, 953674316406250, \
     4768371582031250, 23841857910156250, 119209289550781250, 596046447753906250]
N = int(input())
A = 0
if N % 2 == 0:
  for i in L:
    A += N // i
print(A)

Buggy python submission (verdict: Runtime Error):
N = int(input())
if N % 2 == 0:
else:
  print(0)

Fixed submission:
L = [10, 50, 250, 1250, 6250, 31250, 156250, 781250, 3906250, 19531250, 97656250, \
     488281250, 2441406250, 12207031250, 61035156250, 305175781250, 1525878906250, \
     7629394531250, 38146972656250, 190734863281250, 953674316406250, \
     4768371582031250, 23841857910156250, 119209289550781250, 596046447753906250]
N = int(input())
A = 0
if N % 2 == 0:
  for i in L:
    A += N // i
print(A)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = [i for i in range(1, N + 1)]
print(sum(P) - max(P))

Fixed submission:
N = int(input())
print(N * (N - 1) // 2)
Buggy python submission (verdict: Time Limit Exceeded):
import collections
N = int(input())
L = []
C = 0
for i in range(N):
  L.append(input())
for j in range(N):
  for k in range(N):
    if k > j:
      if collections.Counter(L[j]) == collections.Counter(L[k]):
        C += 1
print(C)

Fixed submission:
from collections import Counter as CC
N = int(input())
L = [str(sorted(list(input()))) for i in range(N)]
C = CC(L)
print(sum([C[i] * (C[i] - 1) // 2 for i in C if C[i] > 1]))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = []
M = []
C = 0
for i in range(N):
  M0 = input()
  M1 = [M1 for M1 in M0]
  M.append(M1)
for i in range(N):
  M[i].sort()
for l in range(N):
  for m in range(N):
    if m > l:
      if M[m] == M[l]:
        C += 1
print(C)

Fixed submission:
from collections import Counter as CC
N = int(input())
L = [str(sorted(list(input()))) for i in range(N)]
C = CC(L)
print(sum([C[i] * (C[i] - 1) // 2 for i in C if C[i] > 1]))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = []
M0 = []
M = []
C = 0
for i in range(N):
  L.append(input())
for j1 in range(N):
  for j2 in range(10):
    M0.append(L[j1][j2])
  M.append(M0)
  M0 = []
for i in range(N):
  M[i].sort()
for l in range(N):
  for m in range(N):
    if m > l:
      if M[m] == M[l]:
        C += 1
print(C)

Fixed submission:
from collections import Counter as CC
N = int(input())
L = [str(sorted(list(input()))) for i in range(N)]
C = CC(L)
print(sum([C[i] * (C[i] - 1) // 2 for i in C if C[i] > 1]))
Buggy python submission (verdict: Runtime Error):
import sys

N = int(input())
H = input().split()
S = 0
M = H.index(max(H))
for i in range(M):
  if int(H[i]) - int(H[i + 1]) > 0:
    if int(H[i]) - int(H[i + 1]) > 1:
      print('No')
      exit()
    S.append(i)
for j in range(M, N - 1):
  if int(H[M]) - int(H[j]) > 1:
    print('No')
print('Yes')

Fixed submission:
import sys
N = int(input())
H = input().split()
S = 0
for i in range(N):
  if int(H[i]) > S:
    S = int(H[i])
  elif S - int(H[i]) >= 2:
    print('No')
    exit()
print('Yes')

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

N = int(input())
H = input().split()
S = 0

for i in range(H.index(max(H))):
  if int(H[i]) - int(H[i + 1]) > 0:
    if int(H[i]) - int(H[i + 1]) > 1:
      print('No')
      exit()
    S.append(i)
for i in range(H.index(max(H)), N):
  if int(H[i]) - int(H[i + 1]) > 0:
    S += 1
    if int(H[i]) - int(H[i + 1]) > 1 or S == 2:
      print('No')
      exit()

Fixed submission:
import sys
N = int(input())
H = input().split()
S = 0
for i in range(N):
  if int(H[i]) > S:
    S = int(H[i])
  elif S - int(H[i]) >= 2:
    print('No')
    exit()
print('Yes')
Buggy python submission (verdict: Runtime Error):
a = input().split()

N = int(a[1])
A = int(a[2])
B = int(a[3])

if A * N  >= B * N:
  print B * N
else:
  print A * N


Fixed submission:
a = input().split()
 
N = int(a[0])
A = int(a[1])
B = int(a[2])
 
if A * N  >= B:
  print (B)
else:
  print (A * N)
Buggy python submission (verdict: Time Limit Exceeded):
a = input().split()

L = int(a[0])
R = int(a[1])

mm = 2018

for i in range(L , R + 1):
  for j in range(L , R + 1):
    if i < j:
      n = (i * j) % 2019
      if n < mm:
        mm = n
print (mm)

Fixed submission:
import sys
a = input().split()

L = int(a[0])
R = int(a[1])
if R - L == 2019:
  print(0)
  sys.exit()

mm = 2018

for i in range(L , R + 1):
  for j in range(L , R + 1):
    if i < j:
      n = (i * j) % 2019
      if n == 0:
        print(0)
        sys.exit()
      elif n < mm:
        mm = n
print (mm)
Buggy python submission (verdict: Runtime Error):
A = 0
B = []
for i in range(5):
  I = int(input())
  A += I
  T = I % 10
  if T != 0:
    B.append(10 - T)
print(A + sum(B) - max(B))

Fixed submission:
A = 0
B = []
B.append(0)
for i in range(5):
  I = int(input())
  A += I
  T = I % 10
  if T != 0:
    B.append(10 - T)
print(A + sum(B) - max(B))
Buggy python submission (verdict: Runtime Error):
N, M, X, Y = map(int, input().split())
x = max(list(map(int, input().split())))
y = min(list(map(int, input().split())))
print('No War' if x < y and X < y else and x < Y 'War')

Fixed submission:
N, M, X, Y = map(int, input().split())
x = max(list(map(int, input().split())))
y = min(list(map(int, input().split())))
print('No War' if x < y and X < y and x < Y else 'War')
Buggy python submission (verdict: Runtime Error):
I = input().split()

N = int(I[0])
K = int(I[1])

if K != N:
  print(1)
elif K = N:
  print(0)

Fixed submission:
I = input().split()

N = int(I[0])
K = int(I[1])

if N % K == 0:
  print(0)
else:
  print(1)
Buggy python submission (verdict: Runtime Error):
N=int(input)
print(sum(list(map(int, input().split())))-N)

Fixed submission:
N=int(input())
print(sum(list(map(int, input().split())))-N)
Buggy python submission (verdict: Time Limit Exceeded):
A, B, K = map(int, input().split())
[print(i) for i in range(A, B + 1) if i <= A + K - 1 or i >= B - K + 1]

Fixed submission:
A, B, K = map(int, input().split())
ans = []
for i in range(K):
  if A + i <= B:
    ans.append(A + i)
  if B - i >= A:
    ans.append(B - i)
ANS = list(set(ans))
ANS.sort()
[print(j) for j in ANS]
Buggy python submission (verdict: Time Limit Exceeded):
N, K, *A = map(int, open(0).read().split())

A = [a + 1 for a in A]
M = max(A)

N0 = 2 ** (M - 1).bit_length()
data = [0] * (2 * N0)

def update(k, x):
    k += N0 - 1
    data[k] = x
    while k >= 0:
        k = (k - 1) // 2
        data[k] = max(data[2 * k + 1], data[2 * k + 2])

def query(l, r):
    L = l + N0; R = r + N0
    s = 0
    while L < R:
        if R & 1:
            R -= 1
            s = max(s, data[R-1])

        if L & 1:
            s = max(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s

for a in A:
    x = query(max(1, a - K), min(a + K + 1, M + 1))
    update(a, x + 1)

print(query(1, M))

Fixed submission:
N, K, *A = map(int, open(0).read().split())

A = [a + 1 for a in A]
M = max(A)

N0 = 2 ** (M - 1).bit_length()
data = [0] * (2 * N0)

def update(k, x):
    k += N0 - 1
    data[k] = x
    while k >= 0:
        k = (k - 1) // 2
        data[k] = max(data[2 * k + 1], data[2 * k + 2])

def query(l, r):
    L = l + N0; R = r + N0
    s = 0
    while L < R:
        if R & 1:
            R -= 1
            s = max(s, data[R-1])

        if L & 1:
            s = max(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s

for a in A:
    x = query(max(1, a - K), min(a + K + 1, M + 1))
    update(a, x + 1)

print(query(1, M))
Buggy python submission (verdict: Time Limit Exceeded):
mod = 998244353

N, K, *LR = map(int, open(0).read().split())

S = set()
for l, r in zip(*[iter(LR)] * 2):
    for i in range(l, r + 1):
        S.add(i)

S = sorted(S)

dp = [0] * N
dp[0] = 1
for i in range(N):
    for s in S:
        if i + s >= N:
            break
        dp[i + s] += dp[i]
        dp[i + s] %= mod

print(dp[-1])

Fixed submission:
# https://ikatakos.com/pot/programming_algorithm/data_structure/binary_indexed_tree

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

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

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

class RangeUpdate:
    def __init__(self, n):
        self.p = Bit(n + 1)
        self.q = Bit(n + 1)

    def add(self, s, t, x):
        t += 1
        self.p.add(s, -x * s)
        self.p.add(t, x * t)
        self.q.add(s, x)
        self.q.add(t, -x)

    def sum(self, s, t):
        t += 1
        return (self.p.sum(t) + self.q.sum(t) * t - \
               self.p.sum(s) - self.q.sum(s) * s) % mod


mod = 998244353

N, K, *LR = map(int, open(0).read().split())

LR = list(zip(*[iter(LR)] * 2))

dp = RangeUpdate(N)
dp.add(1, 1, 1)
for i in range(1, N + 1):
    for l, r in LR:
        dp.add(i + l, i + r, dp.sum(i, i))

print(dp.sum(N, N))
Buggy python submission (verdict: Time Limit Exceeded):
H, W, M, *HW = map(int, open(0).read().split())

R = HW[::2]
C = HW[1::2]

A = [0] * (H + 1)
B = [0] * (W + 1)
for h, w in zip(*[iter(HW)] * 2):
    A[h] += 1
    B[w] += 1

S = set(zip(*[iter(HW)] * 2))

ans = 0
for r in R:
    for c in C:
        ans = max(ans, A[r] + B[c] - ((r, c) in S))

print(ans)

Fixed submission:
H, W, M, *HW = map(int, open(0).read().split())
HW = list(zip(*[iter(HW)] * 2))

A = [0] * (H + 1)
B = [0] * (W + 1)
for h, w in HW:
    A[h] += 1
    B[w] += 1

a = max(A)
b = max(B)

cnt = A.count(a) * B.count(b) - len([0 for h, w in HW if A[h] == a and B[w] == b])

print(a + b - (cnt == 0))
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate

N, K, *PC = map(int, open(0).read().split())
P, C = [0] + PC[:N], [0] + PC[N:]

ans = float("-inf")
for start in range(1, N + 1):
    path = []

    cur = P[start]
    path = [C[start]]
    while cur != start:
        path.append(C[cur])
        cur = P[cur]

    A = list(accumulate(path))
    q, r = divmod(K, len(path))
    res = 0
    if A[-1] >= 0:
        if r == 0:
            q -= 1
            r += len(path)
        res += A[-1] * q
    elif q >= 1:
        r = len(path)

    ans = max(ans, res + max(A[:r]))

print(ans)

Fixed submission:
from itertools import accumulate

N, K, *PC = map(int, open(0).read().split())
P, C = [0] + PC[:N], [0] + PC[N:]

ans = float("-inf")
for start in range(1, N + 1):
    path = []

    cur = P[start]
    path = [C[start]]
    while cur != start:
        path.append(C[cur])
        cur = P[cur]

    A = list(accumulate(path))
    q, r = divmod(K, len(path))
    res = 0
    if A[-1] >= 0:
        if r == 0:
            q -= 1
            r += len(path)
        res += A[-1] * q
    elif q >= 1:
        r = len(path)

    ans = max(ans, res + max(A[:r]))

print(ans)

Buggy python submission (verdict: Runtime Error):
N, K, *PC = map(int, open(0).read().split())
P, C = [0] + PC[:N], [0] + PC[N:]

ans = float("-inf")
for start in range(1, N + 1):
    acc = 0
    cur = start
    cycle = 0
    for l in range(K):
        cur = P[cur]
        acc += C[cur]
        ans = max(ans, acc)
        if cur == start:
            cycle = l + 1
            break

    q, r = divmod(K, cycle)
    if r == 0 and q > 1:
        r = cycle
        q -= 1

    res = acc * q
    ans = max(ans, res)
    for l in range(r):
        cur = P[cur]
        res += C[cur]
        ans = max(ans, res)

print(ans)

Fixed submission:
from itertools import accumulate

N, K, *PC = map(int, open(0).read().split())
P, C = [0] + PC[:N], [0] + PC[N:]

ans = float("-inf")
for start in range(1, N + 1):
    path = []

    cur = P[start]
    path = [C[start]]
    while cur != start:
        path.append(C[cur])
        cur = P[cur]

    A = list(accumulate(path))
    q, r = divmod(K, len(path))
    res = 0
    if A[-1] >= 0:
        if r == 0:
            q -= 1
            r += len(path)
        res += A[-1] * q
    elif q >= 1:
        r = len(path)

    ans = max(ans, res + max(A[:r]))

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from numpy import zeros

def main():
    R, C, K, *RCV = map(int, open(0).read().split())

    V = zeros((R + 1, C + 1), int)
    for r, c, v in zip(*[iter(RCV)] * 3):
        V[r][c] = v

    dp = zeros((R + 1, C + 1, 4), int)
    for i in range(1, R + 1):
        for j in range(1, C + 1):

            vij = V[i][j]

            for k in range(4):
                dp[i][j][k] = max(
                    dp[i][j - 1][k],
                    dp[i - 1][j][3]
                )
            for k in reversed(range(1, 4)):
                dp[i][j][k] = max(
                    dp[i][j][k],
                    vij + dp[i][j][k - 1]
                )

    print(dp[R][C][3])

main()

Fixed submission:
from numpy import zeros, int64
from numba import njit

R, C, K, *RCV = map(int64, open(0).read().split())
V = zeros((R + 1, C + 1), int64)
for r, c, v in zip(*[iter(RCV)] * 3):
    V[r][c] = v

@njit
def main():
    dp = zeros((R + 1, C + 1, 4), int64)
    for i in range(1, R + 1):
        for j in range(1, C + 1):

            vij = V[i][j]

            for k in range(4):
                dp[i][j][k] = max(
                    dp[i][j - 1][k],
                    dp[i - 1][j][3]
                )
            for k in range(3, 0, -1):
                dp[i][j][k] = max(
                    dp[i][j][k],
                    vij + dp[i][j][k - 1]
                )

    print(dp[R][C][3])

main()

Buggy python submission (verdict: Time Limit Exceeded):
from numpy import zeros

R, C, K, *RCV = map(int, open(0).read().split())

V = zeros((R + 1, C + 1), int)
for r, c, v in zip(*[iter(RCV)] * 3):
    V[r][c] = v

dp = zeros((R + 1, C + 1, 4), int)
for i in range(1, R + 1):
    for j in range(1, C + 1):

        vij = V[i][j]

        for k in range(4):
            dp[i][j][k] = max(
                dp[i][j - 1][k],
                dp[i - 1][j][3]
            )
        for k in reversed(range(1, 4)):
            dp[i][j][k] = max(
                dp[i][j][k],
                vij + dp[i][j][k - 1]
            )

print(dp[R][C][3])

Fixed submission:
from numpy import zeros, int64
from numba import njit

R, C, K, *RCV = map(int64, open(0).read().split())
V = zeros((R + 1, C + 1), int64)
for r, c, v in zip(*[iter(RCV)] * 3):
    V[r][c] = v

@njit
def main():
    dp = zeros((R + 1, C + 1, 4), int64)
    for i in range(1, R + 1):
        for j in range(1, C + 1):

            vij = V[i][j]

            for k in range(4):
                dp[i][j][k] = max(
                    dp[i][j - 1][k],
                    dp[i - 1][j][3]
                )
            for k in range(3, 0, -1):
                dp[i][j][k] = max(
                    dp[i][j][k],
                    vij + dp[i][j][k - 1]
                )

    print(dp[R][C][3])

main()
Buggy python submission (verdict: Runtime Error):
N, *A = open(0).read().split()

S = [[0] * 21 for _ in range(21)]

ans = 0
for a in A:
    if (idx := a.find(".")) == -1:
        c2 = c5 = 0
    else:
        c2 = c5 = -(len(a) - idx - 1)

    a = int(a.replace(".", ""))
    while a % 2 == 0:
        c2 += 1
        a //= 2
    while a % 5 == 0:
        c5 += 1
        a //= 5
    c2 = min(c2, 10)
    c5 = min(c5, 10)
    ans += sum(S[i][j] for i in range(10 - c2, 21) for j in range(10 - c5, 21))

    S[c2 + 10][c5 + 10] += 1

print(ans)

Fixed submission:
N, *A = open(0).read().split()

S = [[0] * 21 for _ in range(21)]

ans = 0
for a in A:
    idx = a.find(".")
    if idx == -1:
        c2 = c5 = 0
    else:
        c2 = c5 = -(len(a) - idx - 1)

    a = int(a.replace(".", ""))
    while a % 2 == 0:
        c2 += 1
        a //= 2
    while a % 5 == 0:
        c5 += 1
        a //= 5
    c2 = min(c2, 10)
    c5 = min(c5, 10)
    ans += sum(S[i][j] for i in range(10 - c2, 21) for j in range(10 - c5, 21))

    S[c2 + 10][c5 + 10] += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, *A = open(0).read().split()

S = [[0] * 21 for _ in range(21)]

ans = 0
for a in A:
    if (idx := a.find(".")) == -1:
        c2 = c5 = 0
    else:
        c2 = c5 = -(len(a) - idx - 1)

    a = int(a.replace(".", ""))
    while a % 2 == 0:
        c2 += 1
        a //= 2
    while a % 5 == 0:
        c5 += 1
        a //= 5
    c2 = min(c2, 10)
    c5 = min(c5, 10)
    ans += sum(S[i][j] for i in range(10 - c2, 21) for j in range(10 - c5, 21))

    S[c2 + 10][c5 + 10] += 1

print(ans)

Fixed submission:
N, *A = open(0).read().split()

S = [[0] * 21 for _ in range(21)]

ans = 0
for a in A:
    idx = a.find(".")
    if idx == -1:
        c2 = c5 = 0
    else:
        c2 = c5 = -(len(a) - idx - 1)

    a = int(a.replace(".", ""))
    while a % 2 == 0:
        c2 += 1
        a //= 2
    while a % 5 == 0:
        c5 += 1
        a //= 5
    c2 = min(c2, 10)
    c5 = min(c5, 10)
    ans += sum(S[i][j] for i in range(10 - c2, 21) for j in range(10 - c5, 21))

    S[c2 + 10][c5 + 10] += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
INF = float("inf")

N, *XYP = map(int, open(0).read().split())
XYP = list(zip(*[iter(XYP)] * 3))

def solve(XP):
    M = len(XP)
    XP.sort()

    dp = [[INF] * (M + 1) for _ in range(M + 1)]
    dp[0][0] = 0

    for i, (x, p) in enumerate(XP):
        dp[i + 1][0] = dp[i][0] + abs(x) * p

    for l, dpl in enumerate(dp[:M]):
        for r in range(l + 1, M + 1):
            val = INF
            for lx, _ in XP[l:r]:
                cur = 0
                for x, p in XP[l:r]:
                    cur += p * min(abs(x - lx), abs(x))
                val = min(val, cur)

            for i in range(1, M + 1):
                dp[r][i] = min(
                    dp[r][i],
                    val + dpl[i - 1]
                )

    res = [INF] * (N + 1)
    res[:M + 1] = dp[M]
    return res


A = [INF] * (N + 1)
for state in range(1 << N):
    XP, YP = [], []
    for i, (x, y, p) in enumerate(XYP):
        if (state >> i) & 1:
            XP.append((x, p))
        else:
            YP.append((y, p))

    X, Y = solve(XP), solve(YP)
    for i in range(N + 1):
        for j in range(N + 1 - i):
            A[i + j] = min(A[i + j], X[i] + Y[j])

for a in A:
    print(a)

Fixed submission:
INF = float("inf")

N, *XYP = map(int, open(0).read().split())
XYP = list(zip(*[iter(XYP)] * 3))

def solve(XP):
    M = len(XP)
    XP.sort()

    dp = [[INF] * (M + 1) for _ in range(M + 1)]
    dp[0][0] = 0

    for i, (x, p) in enumerate(XP):
        dp[i + 1][0] = dp[i][0] + abs(x) * p

    for l, dpl in enumerate(dp[:M]):
        for r in range(l + 1, M + 1):
            val = INF
            for lx, _ in XP[l:r]:
                cur = 0
                for x, p in XP[l:r]:
                    cur += p * min(abs(x - lx), abs(x))
                val = min(val, cur)

            for i in range(1, M + 1):
                dp[r][i] = min(
                    dp[r][i],
                    val + dpl[i - 1]
                )

    res = [INF] * (N + 1)
    res[:M + 1] = dp[M]
    return res


A = [INF] * (N + 1)
for state in range(1 << N):
    XP, YP = [], []
    for i, (x, y, p) in enumerate(XYP):
        if (state >> i) & 1:
            XP.append((x, p))
        else:
            YP.append((y, p))

    X, Y = solve(XP), solve(YP)
    for i in range(N + 1):
        for j in range(N + 1 - i):
            A[i + j] = min(A[i + j], X[i] + Y[j])

for a in A:
    print(a)