Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq

n,p = list(map(int, input().split()))
s = input()

ans = 0

if p == 2 or p == 5:
    for i in range(n):
        a = int(s[n-1-i])
        if a % p == 0: ans += n-i

else:
    d = {0: 1}
    for i in range(n):
        if int(s[n-1-i:]) % p not in d:
            d[int(s[n-1-i:]) % p] = 1
        else:
            d[int(s[n - 1 - i:]) % p] += 1

    for dd in d.values():
        ans += dd*(dd-1)//2

print(ans)











Fixed submission:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq

n,p = list(map(int, input().split()))
s = input()

ans = 0

if p == 2 or p == 5:
    for i in range(n):
        a = int(s[n-1-i])
        if a % p == 0: ans += n-i

else:
    d = {0: 1}
    c = 0
    for i in range(n):
        c += (pow(10, i, p)*int(s[n-1-i])) % p
        c %= p
        if c not in d:
            d[c] = 1
        else:
            d[c] += 1

    for dd in d.values():
        ans += dd*(dd-1)//2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq

n,p = list(map(int, input().split()))
s = input()

ans = 0

if p == 2 or p == 5:
    for i in range(n):
        a = int(s[n-1-i])
        if a % p == 0: ans += n-i

else:
    b = [int(s[n-1-i:]) % p for i in range(n)] + [0]
    d = Counter(b)

    for dd in d.values():
        ans += dd*(dd-1)//2

print(ans)











Fixed submission:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq

n,p = list(map(int, input().split()))
s = input()

ans = 0

if p == 2 or p == 5:
    for i in range(n):
        a = int(s[n-1-i])
        if a % p == 0: ans += n-i

else:
    d = {0: 1}
    c = 0
    for i in range(n):
        c += (pow(10, i, p)*int(s[n-1-i])) % p
        c %= p
        if c not in d:
            d[c] = 1
        else:
            d[c] += 1

    for dd in d.values():
        ans += dd*(dd-1)//2

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

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

al = [[] for i in range(N+1)]
for i in range(M):
    a, b = map(int, input().split())
    al[a].append(b)
    al[b].append(a)

block = [[] for i in range(N+1)]
for i in range(K):
    c, d = map(int, input().split())
    block[c].append(d)
    block[d].append(c)

seen = [0 for i in range(N+1)]
num_connect = [0 for i in range(N+1)]
cluster = [0 for i in range(N+1)]

def bfs(u, c):
    visited = [0 for i in range(N+1)]
    stack = deque([u])
    seen[u] = 1
    count = 1

    while len(stack) > 0:
        v = stack.popleft()
        visited[v] = 1
        cluster[v] = c
        for w in al[v]:
            if seen[w] == 0:
                stack.append(w)
                count += 1
                seen[w] = 1

    for i in range(1,N+1):
        if visited[i] == 1:
            num_connect[i] = count

c = 1
for i in range(1,N+1):
    if seen[i] == 0:
        bfs(i, c)
        c += 1

for i in range(1,N+1):
    bl = 0
    for d in block[i]:
        if cluster[i] == cluster[d]:
            bl += 1
    print(num_connect[i] - 1 - len(al[i]) - bl, end=" ")
print()


Fixed submission:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

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

al = [[] for i in range(N+1)]
for i in range(M):
    a, b = map(int, input().split())
    al[a].append(b)
    al[b].append(a)

block = [[] for i in range(N+1)]
for i in range(K):
    c, d = map(int, input().split())
    block[c].append(d)
    block[d].append(c)

seen = [0 for i in range(N+1)]
num_connect = [0 for i in range(N+1)]
cluster = [0 for i in range(N+1)]

def bfs(u, c):
    visited = []
    stack = deque([u])
    seen[u] = 1
    count = 1

    while len(stack) > 0:
        v = stack.popleft()
        visited.append(v)
        cluster[v] = c
        for w in al[v]:
            if seen[w] == 0:
                stack.append(w)
                count += 1
                seen[w] = 1

    for v in visited:
        num_connect[v] = count

c = 1
for i in range(1,N+1):
    if seen[i] == 0:
        bfs(i, c)
        c += 1

for i in range(1,N+1):
    bl = 0
    for d in block[i]:
        if cluster[i] == cluster[d]:
            bl += 1
    print(num_connect[i] - 1 - len(al[i]) - bl, end=" ")
print()
Buggy python submission (verdict: Runtime Error):
from sys import stdin
import sys
import math
from functools import reduce
import itertools

n = int(stdin.readline().rstrip())

d = {}

for i in range(n):
    s = stdin.readline().rstrip()

    if s in d:
        d[s] += 1
    else:
        d[s] = 1

d = sorted(d.items(), key=lambda x:x[1], reverse=True)

m = d[0][1]
a = []
for i in range(n):
    if d[i][1] == m:
        a.append(d[i][0])
    else:
        break

a.sort()

for aa in a:
    print(aa)

Fixed submission:
from sys import stdin
import sys
import math
from functools import reduce
import itertools

n = int(stdin.readline().rstrip())

d = {}
for i in range(n):
    s = stdin.readline().rstrip()

    if s in d:
        d[s] += 1
    else:
        d[s] = 1

d = sorted(d.items(), key=lambda x:x[1], reverse=True)

m = d[0][1]
a = []
i = 0
for i in range(len(d)):
    if d[i][1] == m:
        a.append(d[i][0])
    else:
        break

a.sort()

for aa in a:
    print(aa)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import sys
import math
from functools import reduce
import itertools

n = int(stdin.readline().rstrip())

c = []
a = []

for i in range(n):
    s = stdin.readline().rstrip()

    if s not in a:
        a.append(s)
        c.append(1)
    else:
        idx = a.index(s)
        c[idx] = c[idx] + 1

b = [i for i, v in enumerate(c) if v == max(c)]
d = [a[i] for i in b]
d.sort()

for dd in d:
    print(dd)


Fixed submission:
from sys import stdin
import sys
import math
from functools import reduce
import itertools

n = int(stdin.readline().rstrip())

d = {}
for i in range(n):
    s = stdin.readline().rstrip()

    if s in d:
        d[s] += 1
    else:
        d[s] = 1

d = sorted(d.items(), key=lambda x:x[1], reverse=True)

m = d[0][1]
a = []
i = 0
for i in range(len(d)):
    if d[i][1] == m:
        a.append(d[i][0])
    else:
        break

a.sort()

for aa in a:
    print(aa)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque

n,k = [int(x) for x in stdin.readline().rstrip().split()]
p = [(int(x)+1)/2 for x in stdin.readline().rstrip().split()]

m = 0
for i in range(n-k+1):
    m = max([sum(p[i:i+k]), m])

print(m)




Fixed submission:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque

n,k = [int(x) for x in stdin.readline().rstrip().split()]
p = [(int(x)+1)/2 for x in stdin.readline().rstrip().split()]

m = sum(p[0:k])
maxm = m

for i in range(1,n-k+1):
    m = m - p[i-1] + p[i+k-1]
    maxm = max([maxm,m])

print(maxm)
Buggy python submission (verdict: Runtime Error):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)


H, N = list(map(int, input().split()))
a = []
for i in range(N):
    a.append(list(map(int, input().split())))


dp = [0 for i in range(H+1)]

for h in range(1, H+1):
    dp[h] = min([dp[h-a[i][0]] + a[i][1] for i in range(N)])

print(dp[H])





Fixed submission:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)


H, N = list(map(int, input().split()))
a = []
for i in range(N):
    a.append(list(map(int, input().split())))


dp = [0 for i in range(H+1)]

for h in range(1, H+1):
    dp[h] = min([dp[max(0, h-a[i][0])] + a[i][1] for i in range(N)])

print(dp[H])
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
if N-M == 0:
  print("Yes")
 else:
  print("No")

Fixed submission:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

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

if N-M == 0:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
INF =  float("inf")
import bisect

N, M = list(map(int, input().split()))
a = list(map(int, input().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 素因数分解に基づくlcm
def fact_lcm(numbers):
    d = defaultdict(int)
    for a in numbers:
        b = factorization(a)
        for bb in b:
            d[bb[0]] = max(d[bb[0]],bb[1])
    return(dict(d))

d = fact_lcm(a)
c = 1

for dd in d.items():
    c *= dd[0]**dd[1]

cc = c // 2

for aa in a:
    if cc % aa == 0:
        print(0)
        sys.exit()

print((M-cc) // c + 1)



Fixed submission:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
INF =  float("inf")
import bisect

N, M = list(map(int, input().split()))
a = list(map(int, input().split()))

# """nを素因数分解"""
# """2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""
# def factorization(n):
#     arr = []
#     temp = n
#     for i in range(2, int(-(-n**0.5//1))+1):
#         if temp%i==0:
#             cnt=0
#             while temp%i==0:
#                 cnt+=1
#                 temp //= i
#             arr.append([i, cnt])
#
#     if temp!=1:
#         arr.append([temp, 1])
#
#     if arr==[]:
#         arr.append([n, 1])
#
#     return arr
#
# # 素因数分解に基づくlcm
# def fact_lcm(numbers):
#     d = defaultdict(int)
#     for a in numbers:
#         b = factorization(a)
#         for bb in b:
#             d[bb[0]] = max(d[bb[0]],bb[1])
#     return(dict(d))
#
# d = fact_lcm(a)
# c = 1
#
# for dd in d.items():
#     c *= dd[0]**dd[1]

# リストのlcm
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

c = lcm_list(a)

cc = c // 2

for aa in a:
    if cc % aa == 0:
        print(0)
        sys.exit()

print((M-cc) // c + 1)
Buggy python submission (verdict: Runtime Error):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353
import numpy

S  = input()

for i in range(len(S)):
    if i % 2 == 0:
        if S[i] != 'R' and S[i] != 'U' and S[i] != 'D':
            print("No")
            sys.exit()
    else:
        if S[i] != 'L' and S[i] != 'U' and S[i] != 'D':
            print("No")
            sys.exit()

print("Yes")



Fixed submission:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

S  = input()

for i in range(len(S)):
    if i % 2 == 0:
        if S[i] != 'R' and S[i] != 'U' and S[i] != 'D':
            print("No")
            sys.exit()
    else:
        if S[i] != 'L' and S[i] != 'U' and S[i] != 'D':
            print("No")
            sys.exit()

print("Yes")
Buggy python submission (verdict: Runtime Error):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353
import numpy

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

g = [0 for i in range(N)]

for i in range(Q):
    A = int(input())
    g[A-1] += 1

for i in range(N):
    if Q - g[i] >= K:
        print("No")
    else:
        print("Yes")



Fixed submission:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

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

g = [0 for i in range(N)]

for i in range(Q):
    A = int(input())
    g[A-1] += 1

for i in range(N):
    if Q - g[i] >= K:
        print("No")
    else:
        print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

## a, bを無向辺として，隣接リストを作成
N, Q = list(map(int, input().split()))
al = [[] for i in range(N)]

for i in range(N-1):
    a, b = list(map(int, input().split()))

    al[a-1].append(b-1)
    al[b-1].append(a-1)

visited = [0 for i in range(N)]
seen = [0 for i in range(N)]
score = [0 for i in range(N)]

for i in range(Q):
    p, x = map(int, input().split())
    score[p-1] += x

@functools.lru_cache(None)
def dfs_rec(u):
    visited[u] = 1
    for v in al[u]:
        if visited[v] == 0:
            score[v] += score[u]
            dfs_rec(v)

dfs_rec(0)

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

Fixed submission:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

## a, bを無向辺として，隣接リストを作成
N, Q = list(map(int, input().split()))
al = [[] for i in range(N)]

for i in range(N-1):
    a, b = list(map(int, input().split()))

    al[a-1].append(b-1)
    al[b-1].append(a-1)

visited = [0 for i in range(N)]
seen = [0 for i in range(N)]
score = [0 for i in range(N)]

for i in range(Q):
    p, x = map(int, input().split())
    score[p-1] += x

@functools.lru_cache(None)
def dfs_rec(u):
    visited[u] = 1
    for v in al[u]:
        if visited[v] == 0:
            score[v] += score[u]
            dfs_rec(v)

dfs_rec(0)

print(" ".join(map(str, score)))
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq

N, W = list(map(int, input().split()))
INF = 10**10

dp = [[0]*(W+1) for i in range(N+1)]

for i in range(1,N+1):
    w, v = list(map(int, input().split()))
    for j in range(1,W+1):
        if j-w < 0:
            p = -INF
        else:
            p = dp[i-1][j - w]

        dp[i][j] = max(p + v, dp[i-1][j])

print(dp[N][W])


Fixed submission:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq

N, W = list(map(int, input().split()))
INF = 10**10

dp = [[0]*(W+1) for i in range(N+1)]

for i in range(1,N+1):
    w, v = list(map(int, input().split()))
    for j in range(1,W+1):
        if j-w < 0:
            p = -INF
        else:
            p = dp[i-1][j - w]

        dp[i][j] = max(p + v, dp[i-1][j])

print(dp[N][W])
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)

N = int(input())
a = [0] + list(map(int, input().split()))

# @functools.lru_cache(None)
# def dp(i,j):
#     if i == j: return 0
#     if (N % 2 == 0 and (j - i) % 2 == 0) or (N % 2 == 1 and (j - i) % 2 == 1):
#         return max(dp(i+1,j) + a[i], dp(i,j-1) + a[j-1])
#     else:
#         return min(dp(i+1,j) - a[i], dp(i,j-1) - a[j-1])
#
# print(dp(1,N+1))

@functools.lru_cache(None)
def f(l,r):
    if l==r: return a[l]
    return max(a[l] - f(l+1,r), a[r]-f(l,r-1))

print(f(1,N))

Fixed submission:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)

N = int(input())
a = [0] + list(map(int, input().split()))

dp = [[0]*(N+5) for i in range(N+5)]

for k in range(1,N+1):
    for l in range(1,N+2-k):
        r = l + k
        if (N-k) % 2 == 0:
            dp[l][r] = max(dp[l+1][r] + a[l], dp[l][r-1] + a[r-1])
        else:
            dp[l][r] = min(dp[l + 1][r] - a[l], dp[l][r - 1] - a[r - 1])

print(dp[1][N+1])

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)

N = int(input())
a = [0] + list(map(int, input().split()))

@functools.lru_cache(None)
def dp(i,j):
    if i == j: return 0
    if (N % 2 == 0 and (j - i) % 2 == 0) or (N % 2 == 1 and (j - i) % 2 == 1):
        return max(dp(i+1,j) + a[i], dp(i,j-1) + a[j-1])
    else:
        return min(dp(i+1,j) - a[i], dp(i,j-1) - a[j-1])

print(dp(1,N+1))

Fixed submission:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)

N = int(input())
a = [0] + list(map(int, input().split()))

dp = [[0]*(N+5) for i in range(N+5)]

for k in range(1,N+1):
    for l in range(1,N+2-k):
        r = l + k
        if (N-k) % 2 == 0:
            dp[l][r] = max(dp[l+1][r] + a[l], dp[l][r-1] + a[r-1])
        else:
            dp[l][r] = min(dp[l + 1][r] - a[l], dp[l][r - 1] - a[r - 1])

print(dp[1][N+1])