Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())
freq = [True]*M
for i in range(N):
    a,b = map(int,input().split())
    a-=1
    b-=1
    if freq[a]:
        freq[a] = False
    else:
        freq[a] = True

    if freq[b]:
        freq[b] = False
    else:
        freq[b] = True

ans = all(freq)
if ans:
    print('YES')
else:
    print('NO')


Fixed submission:
N, M = map(int,input().split())
freq = [True]*N
for i in range(M):
    a,b = map(int,input().split())
    a-=1
    b-=1
    if freq[a]:
        freq[a] = False
    else:
        freq[a] = True

    if freq[b]:
        freq[b] = False
    else:
        freq[b] = True

ans = all(freq)
if ans:
    print('YES')
else:
    print('NO')

Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())
freq = [True]*M
for i in range(M):
    a,b = map(int,input().split())
    a-=1
    b-=1
    if freq[a]:
        freq[a] = False
    else:
        freq[a] = True

    if freq[b]:
        freq[b] = False
    else:
        freq[b] = True

ans = all(freq)
if ans:
    print('YES')
else:
    print('NO')


Fixed submission:
N, M = map(int,input().split())
freq = [True]*N
for i in range(M):
    a,b = map(int,input().split())
    a-=1
    b-=1
    if freq[a]:
        freq[a] = False
    else:
        freq[a] = True

    if freq[b]:
        freq[b] = False
    else:
        freq[b] = True

ans = all(freq)
if ans:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
N,W = map(int,input().split())
weights = N*[0]
values = N*[0]
for i in range(N):
    weights[i], values[i] = map(int,input().split())

inf = float("inf")
dp = [[-inf for i in range(W+1)] for j in range(N+1)]
for i in range(W+1):
    dp[0][i] = 0

for i in range(N):
    for w in range(W+1):
        if weights[i] <= w:
            dp[i+1][w]=max(dp[i][w-weights[i]]+values[i], dp[i][w])
        else:
            dp[i+1][w] = dp[i][w]

print(dp[N][W])
#print(dp)

Fixed submission:
N,W = map(int,input().split())
v1 = []
v2 = []
v3 = []
v4 = []
w1,v = map(int,input().split())
v1.append(v)
for i in range(N-1):
    w,v = map(int,input().split())
    if w == w1:
        v1.append(v)
    elif w == w1 + 1:
        v2.append(v)
    elif w == w1 + 2:
        v3.append(v)
    elif w == w1 + 3:
        v4.append(v)
v1.sort(reverse=True)
v2.sort(reverse=True)
v3.sort(reverse=True)
v4.sort(reverse=True)

l1 = len(v1)
l2 = len(v2)
l3 = len(v3)
l4 = len(v4)
ans = 0
for i in range(l1+1):
    for j in range(l2+1):
        for k in range(l3+1):
            for l in range(l4+1):

                if i*w1 + j*(w1+1) + k*(w1+2) + l*(w1+3) <= W:
                    temp = sum(v1[:i]) + sum(v2[:j]) + sum(v3[:k]) + sum(v4[:l])
                    ans = max(ans,temp)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
power = 1
BIGNUM = 10**9+7
for i in range(1,N+1):
    power *= i

ans = power%BIGNUM
print(ans)

Fixed submission:
N = int(input())
power = 1
BIGNUM = 10**9+7
for i in range(1,N+1):
    power *= i
    power = power%BIGNUM

ans = power
print(ans)
Buggy python submission (verdict: Runtime Error):
N, ma, mb = map(int, input().split())
a = [0]*N
b = [0]*N
c = [0]*N
NMAX = 10
ABMAX = 10
INF = 100000
for i in range(N):
    a[i], b[i], c[i] = map(int, input().split())
dp = [[[INF]*(NMAX*ABMAX+1)for _ in range(NMAX*ABMAX+1)]for _ in range(N+1)]
dp[0][0][0] = 0
for i in range(N):
    for ca in range(NMAX*ABMAX+1):
        for cb in range(NMAX*ABMAX+1):
            if dp[i][ca][cb] == INF:
                continue
            dp[i+1][ca][cb] = min(dp[i+1][ca][cb], dp[i][ca][cb])
            dp[i+1][ca+a[i]][cb+b[i]
                             ] = min(dp[i+1][ca+a[i]][cb+b[i]], dp[i][ca][cb]+c[i])
ans = INF
for ca in range(1, NMAX*ABMAX+1):
    for cb in range(1, NMAX*ABMAX+1):
        if ca * mb == cb * ma:
            ans = min(ans, dp[N][ca][cb])
print(ans if ans != INF else -1)


Fixed submission:
N, ma, mb = map(int, input().split())
a = [0]*N
b = [0]*N
c = [0]*N
NMAX = 40
ABMAX = 10
INF = 1000000
for i in range(N):
    a[i], b[i], c[i] = map(int, input().split())
dp = [[[INF]*(NMAX*ABMAX+1)for _ in range(NMAX*ABMAX+1)]for _ in range(N+1)]
dp[0][0][0] = 0
for i in range(N):
    for ca in range(NMAX*ABMAX+1):
        for cb in range(NMAX*ABMAX+1):
            if dp[i][ca][cb] == INF:
                continue
            dp[i+1][ca][cb] = min(dp[i+1][ca][cb], dp[i][ca][cb])
            dp[i+1][ca+a[i]][cb+b[i]
                             ] = min(dp[i+1][ca+a[i]][cb+b[i]], dp[i][ca][cb]+c[i])
ans = INF
for ca in range(1, NMAX*ABMAX+1):
    for cb in range(1, NMAX*ABMAX+1):
        if ca * mb == cb * ma:
            ans = min(ans, dp[N][ca][cb])
print(ans if ans != INF else -1)
Buggy python submission (verdict: Time Limit Exceeded):
a,b,x = map(int,input().split())
cnt = 0
for i in range(a,b+1):
    if i%x ==0:
        cnt += 1
print(cnt)

Fixed submission:
a,b,x = map(int,input().split())
import math
def func(n):
    if n >=0:
        return n//x+1
    if n ==-1:
        return 0
print(func(b)-func(a-1))
Buggy python submission (verdict: Time Limit Exceeded):
xs, ys, xt, yt = map(int, input().split())
n = int(input())
p = [(xs, ys, 0), (xt, yt, 0)]
for i in range(n):
    p.append(tuple(map(int, input().split())))
edge = [[0] * (n + 2) for _ in range(n + 2)]
for i in range(n + 2):
    for j in range(i, n + 2):
        edge[i][j] = max(0, ((p[i][0] - p[j][0])**2 + (p[i][1] - p[j][1])**2)**0.5 - p[i][2] - p[j][2])
        edge[j][i] = max(0, ((p[i][0] - p[j][0])**2 + (p[i][1] - p[j][1])**2)**0.5 - p[i][2] - p[j][2])


def dijkstra(s, n, edges):
    INF = float('inf')
    d = [INF] * n
    d[s] = 0
    import heapq
    pq = [(0, s)]
    while len(pq):
        c, v = heapq.heappop(pq)
        if d[v] < c:
            continue
        # for v2nvcost, nv in edges[v]:
        for nv, v2nvcost in enumerate(edges[v]):
            if c + v2nvcost < d[nv]:
                d[nv] = c + v2nvcost
                heapq.heappush(pq, (d[nv], nv))
    return d


dist = dijkstra(0, n + 2, edge)
print(dist[1])


Fixed submission:
xs, ys, xt, yt = map(int, input().split())
n = int(input())
p = [(xs, ys, 0), (xt, yt, 0)]
for i in range(n):
    p.append(tuple(map(int, input().split())))
edge = [[0] * (n + 2) for _ in range(n + 2)]
for i in range(n + 2):
    for j in range(i, n + 2):
        edge[i][j] = max(0, ((p[i][0] - p[j][0])**2 + (p[i][1] - p[j][1])**2)**0.5 - p[i][2] - p[j][2])
        edge[j][i] = max(0, ((p[i][0] - p[j][0])**2 + (p[i][1] - p[j][1])**2)**0.5 - p[i][2] - p[j][2])


def dijkstra(s, n, edges):
    INF = float('inf')
    d = [INF] * n
    d[s] = 0
    import heapq
    pq = [(0, s)]
    while len(pq):
        c, v = heapq.heappop(pq)
        if d[v] < c:
            continue
        # for v2nvcost, nv in edges[v]:
        for nv, v2nvcost in enumerate(edges[v]):
            if c + v2nvcost < d[nv]:
                d[nv] = c + v2nvcost
                heapq.heappush(pq, (d[nv], nv))
    return d


dist = dijkstra(0, n + 2, edge)
print(dist[1])
Buggy python submission (verdict: Runtime Error):
H,W,N = map(int,input().split())
g = [[0]*(W+2) for _ in range(H+2)] # 0:white 1:black
a = [0]*N
b = [0]*N
seen = [[False]*(W+2) for _ in range(H+2)]
ans = [0]*10
for i in range(N):
    a[i], b[i] = map(int,input().split())
    g[a[i]][b[i]] = 1
# 黒マスの周り9領域を探索する
for y,x in zip(a,b):
    for dy in range(-1,2):
        for dx in range(-1,2):
            if 2 <= x + dx <= W-1 and 2 <= y + dy <= H-1:
                cy = y+dy # 中心を決める
                cx = x+dx
                if seen[cy][cx]:
                    continue
                seen[cy][cx] = True
                black_cnt = 0
                for ddx in range(-1,2):
                    for ddy in range(-1,2):
                        black_cnt += g[cy+ddy][cx+ddx]
                ans[black_cnt] += 1
ans[0] = (H-2)*(W-2) - sum(ans[1:])

# for i in range(H+2):
#     print(g[i])
for i in range(10):
    print(ans[i])

Fixed submission:
H,W,N = map(int,input().split())
d = {}
for _ in range(N):
    a,b = list(map(int,input().split()))
    for dy in range(-1,2):
        for dx in range(-1,2):
            cy = a + dy
            cx = b + dx
            if 2 <= cy <= H-1 and 2 <= cx <= W-1:
                if (cy,cx) not in d:
                    d[(cy,cx)] = 1
                else:
                    d[(cy, cx)] += 1
ans = [0]*10
for v in d.values():
    ans[v] += 1
ans[0] = (H-2)*(W-2) - sum(ans[1:])

for i in range(10):
    print(ans[i])

Buggy python submission (verdict: Runtime Error):
H,W,N = map(int,input().split())
g = [[0]*(W+2) for _ in range(H+2)] # 0:white 1:black
a = [0]*N
b = [0]*N
seen = [[False]*(W+2) for _ in range(H+2)]
ans = [0]*10
for i in range(N):
    a[i], b[i] = map(int,input().split())
    g[a[i]][b[i]] = 1
# 黒マスの周り9領域を探索する
for y,x in zip(a,b):
    for dy in range(-1,2):
        for dx in range(-1,2):
            if 2 <= x + dx <= W-1 and 2 <= y + dy <= H-1:
                cy = y+dy # 中心を決める
                cx = x+dx
                if seen[cy][cx]:
                    continue
                seen[cy][cx] = True
                black_cnt = 0
                for ddx in range(-1,2):
                    for ddy in range(-1,2):
                        black_cnt += g[cy+ddy][cx+ddx]
                ans[black_cnt] += 1
ans[0] = (H-2)*(W-2) - sum(ans[1:])

# for i in range(H+2):
#     print(g[i])
for i in range(10):
    print(ans[i])

Fixed submission:
H,W,N = map(int,input().split())
d = {}
for _ in range(N):
    a,b = list(map(int,input().split()))
    for dy in range(-1,2):
        for dx in range(-1,2):
            cy = a + dy
            cx = b + dx
            if 2 <= cy <= H-1 and 2 <= cx <= W-1:
                if (cy,cx) not in d:
                    d[(cy,cx)] = 1
                else:
                    d[(cy, cx)] += 1
ans = [0]*10
for v in d.values():
    ans[v] += 1
ans[0] = (H-2)*(W-2) - sum(ans[1:])

for i in range(10):
    print(ans[i])
Buggy python submission (verdict: Runtime Error):
s = list(input())
w =[]
for i in s:
    if i == "B":
        w.pop(-1)
    else:
        w.append(i)
print("".join(w))


Fixed submission:
s = list(input())
w =[]
for i in s:
    if i == "B":
        if len(w) !=0:
            w.pop(-1)
    else:
        w.append(i)
print("".join(w))
Buggy python submission (verdict: Runtime Error):
#wlist = list(map(int,input().split()))
nlist = list(input().split())
if nlist.couunt("5") ==2 and nlist.count("7")==1:
    print("YES")
else:
    print("NO")

Fixed submission:
#wlist = list(map(int,input().split()))
nlist = list(input().split())
if nlist.count("5") ==2 and nlist.count("7")==1:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))

ac = 1
for i in range(K):
    ac *= A[i]

for i in range(K, N):
    if A[i-K] < A[i]: print('Yes')
    else: print('No')



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

for i in range(K, N):
    if A[i-K] < A[i]: print('Yes')
    else: print('No')

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

ac = 1
for i in range(K):
    ac *= A[i]

pre = ac
for i in range(K, N):
    ac = (ac // A[i - K]) * A[i]
    if pre < ac: print('Yes')
    else: print('No')
    pre = ac





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

for i in range(K, N):
    if A[i-K] < A[i]: print('Yes')
    else: print('No')
Buggy python submission (verdict: Runtime Error):
import math
A, B = input().split()
a = int(A)
b = int(B*1000)
print(a*b//1000)


Fixed submission:
import math
A, B = input().split()
a = int(A)
b = int(float(B)*1000)
print(a*b//1000)
Buggy python submission (verdict: Runtime Error):
a = map(int, input())
if sum(a) >= 22:
  print('bust')
else:
  print('win')

Fixed submission:
a, b, c = map(int, input().split())
if a + b + c >= 22:
  print('bust')
else:
  print('win')
Buggy python submission (verdict: Runtime Error):
import numpy as np
AB = np.prod(np.array(list(map(int,input()))))
print(AB)

Fixed submission:
A, B = map(int, input().split())
print(A*B-A-B+1)
Buggy python submission (verdict: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

int main(void)
{
  int a,b,c;
  cin >>a >> b >> c;
  swap(a, b);
  swap(a, c);
  cout << a << " " << b << " " << c << endl;
}


Fixed submission:
a,b,c=map(int,input().split())
print(c,a,b)
Buggy python submission (verdict: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  // ll N; cin >> N;
  // ll N, K; cin >> N >> K;
  // ll x, y, z; cin >> x >> y >> z;
  // ll a, b, c; cin >> a >> b >> c;
  // string s; cin >> s;
  // vector<ll> a(N); rep(i, N) cin >> a[i];
  
  // ll ans = 0;
  // bool ok = false;

  // cout << ans << endl;
  // cout << (ok?"Yes":"No") << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Fixed submission:
h,a=map(int, input().split())
print((h-1)//a+1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))

for i in range(N):
    print(A.count(i+1))


Fixed submission:
n = int(input())

l = [0] * n
nums = input().split()
for i in range(n - 1):
    l[int(nums[i]) - 1] += 1
    
for i in range(n):
    print(l[i])
Buggy python submission (verdict: Runtime Error):
import sys

import numba as nb
import numpy as np

input = sys.stdin.readline


@nb.njit("i8[:](i8,unicode_type,i8)", cache=True)
def solve(N, X, X_int):
    popcount_X = X.count("1")
    if popcount_X == 0:
        ans = np.ones(N, dtype=np.int64)
    elif popcount_X == 1:
        ans = np.ones(N, dtype=np.int64)
        ans[-1] = 2
        ans[int(X.index("1"))] = 0
    else:
        X_mod_popcount_X_p = X_int % (popcount_X + 1)
        X_mod_popcount_X_m = X_int % (popcount_X - 1)
        ans = np.zeros(N, dtype=np.int64)
        for i in range(N):
            if X[i] == "0":
                Y = X_mod_popcount_X_p + (2 ** (N - 1 - i)) % (popcount_X + 1)
                Y = Y % (popcount_X + 1)
            else:
                Y = X_mod_popcount_X_m - (2 ** (N - 1 - i)) % (popcount_X - 1)
                Y = Y + (popcount_X - 1)
                Y = Y % (popcount_X - 1)
            count = 1
            while Y > 0:
                popcount = 0
                tmp = Y
                while tmp > 0:
                    if tmp & 1:
                        popcount += 1
                    tmp >>= 1
                Y = Y % popcount
                count += 1
            ans[i] = count

    return ans


def main():
    N = int(input())
    X = input()

    ans = solve(N, X, int(X, 2))
    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()


Fixed submission:
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    X = input()

    popcount_X = X.count("1")
    if popcount_X == 0:
        ans = [1] * N
    elif popcount_X == 1:
        ans = [1] * N
        ans[-1] = 2
        ans[X.index("1")] = 0
    else:
        X_mod_popcount_X_p = int(X, 2) % (popcount_X + 1)
        X_mod_popcount_X_m = int(X, 2) % (popcount_X - 1)
        ans = [0] * N
        for i in range(N):
            if X[i] == "0":
                Y = X_mod_popcount_X_p + pow(2, N - 1 - i, mod=popcount_X + 1)
                Y = Y % (popcount_X + 1)
            else:
                Y = X_mod_popcount_X_m - pow(2, N - 1 - i, mod=popcount_X - 1)
                Y = Y + (popcount_X - 1)
                Y = Y % (popcount_X - 1)
            count = 1
            while Y > 0:
                popcount = bin(Y).count("1")
                Y = Y % popcount
                count += 1
            ans[i] = count

    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from itertools import accumulate

input = sys.stdin.readline


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    for _ in range(min(41, K)):
        A_cumsum = [0] * N
        for i in range(N):
            a = i - A[i]
            b = i + A[i] + 1
            if a < 0:
                A_cumsum[0] += 1
            else:
                A_cumsum[a] += 1
            if N - 1 < b:
                pass
            else:
                A_cumsum[b] -= 1
        A = list(accumulate(A_cumsum))

    print(" ".join(map(str, A)))


if __name__ == "__main__":
    main()


Fixed submission:
import sys

import numba as nb
import numpy as np

input = sys.stdin.readline


@nb.njit("i8[:](i8,i8,i8[:])", cache=True)
def solve(N, K, A):
    for _ in range(min(41, K)):
        A_cumsum = np.zeros(shape=N, dtype=np.int64)
        for i in range(N):
            A_cumsum[max(0, i - A[i])] += 1
            b = i + A[i] + 1
            if N - 1 < b:
                pass
            else:
                A_cumsum[b] -= 1
        A = np.cumsum(A_cumsum)
    return A


def main():
    N, K = map(int, input().split())
    A = np.array(input().split(), dtype=np.int64)

    ans = solve(N, K, A)

    print(" ".join(map(str, ans)))


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline


def main():
    X = int(input())

    B = 0
    while True:
        A = (X + B**5)**(1/5)
        if not isinstance(A, complex) and A.is_integer():
            A = int(A)
            break
        B *= -1
        A = (X + B**5)**(1/5)
        if not isinstance(A, complex) and A.is_integer():
            A = int(A)
            break
        B *= -1
        B += 1

    print(f"{A} {B}")


if __name__ == "__main__":
    main()


Fixed submission:
import sys

input = sys.stdin.readline


def main():
    X = int(input())

    for A in range(-200, 201):
        for B in range(-200, 201):
            if A ** 5 - B ** 5 == X:
                print(A, B)
                exit()


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys

input = sys.stdin.readline


def main():
    S = input().rstrip()

    n = len(S)
    counts = [0] * 2019
    counts[0] += 1
    T = [0] * (n+1)
    for i in reversed(range(n)):
        T[i] = (10**(n-1-i) * int(S[i]) + T[i+1]) % 2019
        counts[T[i]] += 1

    ans = 0
    for c in counts:
        ans += c*(c-1)//2  # cC2
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys

input = sys.stdin.readline

P = 2019

def main():
    S = input().rstrip()

    n = len(S)
    counts = [0] * P
    counts[0] += 1
    T = 0
    d = 1
    for s in reversed(S):
        T = (T + (d * int(s)) % P) % P
        d = (d * 10) % P
        counts[T] += 1

    ans = 0
    for c in counts:
        ans += c*(c-1)//2  # cC2
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import Counter

input = sys.stdin.readline


def main():
    S = input().rstrip()

    n = len(S)
    T = [0] * (n+1)
    for i in reversed(range(n)):
        T[i] = (10**(n-1-i) * int(S[i]) + T[i+1]) % 2019

    c = Counter(T)
    ans = 0
    for v in c.values():
        ans += v*(v-1)//2  # vC2
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys

input = sys.stdin.readline

P = 2019

def main():
    S = input().rstrip()

    n = len(S)
    counts = [0] * P
    counts[0] += 1
    T = 0
    d = 1
    for s in reversed(S):
        T = (T + (d * int(s)) % P) % P
        d = (d * 10) % P
        counts[T] += 1

    ans = 0
    for c in counts:
        ans += c*(c-1)//2  # cC2
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import Counter

input = sys.stdin.readline

P = 2019


def main():
    S = input().rstrip()

    n = len(S)
    T = [int(S[k:]) % P for k in range(n)]
    T.append(0)  # T_{n+1} = 0

    c = Counter(T)
    ans = 0
    for v in c.values():
        ans += v*(v-1)//2  # vC2
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys

input = sys.stdin.readline

P = 2019

def main():
    S = input().rstrip()

    n = len(S)
    counts = [0] * P
    counts[0] += 1
    T = 0
    d = 1
    for s in reversed(S):
        T = (T + (d * int(s)) % P) % P
        d = (d * 10) % P
        counts[T] += 1

    ans = 0
    for c in counts:
        ans += c*(c-1)//2  # cC2
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import collections

N = int(input())
A = [int(i) for i in input().split()]

c = collections.Counter(A)

def count(c, x):
    ret = 0
    for k, v in c.items():
        if k == x:
            v -= 1
        ret += v*(v-1)//2
    return ret

def count_list(c):
    keys = c.keys()
    ret = {}
    for key in keys:
        ret[key] = count(c, key)
    return ret

counts = count_list(c)
for i in range(N):
    print(counts[A[i]])


Fixed submission:
import collections

N = int(input())
A = [int(i) for i in input().split()]

c = collections.Counter(A)

def count_list(c):
    modify = {}
    ret = 0
    for k, v in c.items():
        a = v*(v-1)//2
        b = (v-1)*(v-2)//2
        ret += a
        modify[k] = -a + b
    return ret, modify

counts, modify = count_list(c)
for a in A:
    print(counts + modify[a])

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

N = int(input())
A = [int(i) for i in input().split()]

c = collections.Counter(A)

def count(c, x):
    c[x] -= 1
    ret = 0
    for v in c.values():
        ret += v*(v-1)//2
    return ret

N = len(A)
for i in range(N):
    print(count(c.copy(), A[i]))


Fixed submission:
import collections

N = int(input())
A = [int(i) for i in input().split()]

c = collections.Counter(A)

def count_list(c):
    modify = {}
    ret = 0
    for k, v in c.items():
        a = v*(v-1)//2
        b = (v-1)*(v-2)//2
        ret += a
        modify[k] = -a + b
    return ret, modify

counts, modify = count_list(c)
for a in A:
    print(counts + modify[a])