Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools

def main():
    n = int(input())
    s = input()
    l = list(itertools.combinations(list(range(n)),3))
    a = set()
    for i in l:
        k = s[i[0]]+s[i[1]]+s[i[2]]
        a.add(k)
    print(len(a))

if __name__=="__main__":
    main()


Fixed submission:
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools

def main():
    n = int(input())
    s = input()

    ans = 0
    for i in range(10):
        a = s.find(str(i))
        if a == -1:
            continue
        for j in range(10):
            b = s.find(str(j),a+1)
            if b == -1:
                continue
            for k in range(10):
                c = s.find(str(k),b+1)
                if c == -1:
                    continue
                else:
                    ans += 1
    print(ans)

if __name__=="__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

def main():
    n = i_input()
    l = i_list()
    l.sort()
    ans = 0
    for i in range(len(l)):
        for k in range(i+1,len(l)):
            for u in range(k+1,len(l)):
                a = l[i]
                b = l[k]
                c = l[u]
                if b < a+c and c < a+b:
                    ans += 1
                if a+b < c:
                    break
    print(ans)

if __name__=="__main__":
    main()


Fixed submission:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

def main():
    import bisect
    n = i_input()
    l = sorted(i_list())
    ans = 0
    for a in range(n-2):
        for b in range(a+1,n-1):
            ans += bisect.bisect(l, l[a]+l[b]-1) -b-1
    print(ans)

if __name__=="__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    a,b = i_map()

    def make_divisors(n,m):
        lower_divisors , upper_divisors = [], []
        i = 1
        while i*i <= n:
            if n % i == 0 and m % i == 0:
                lower_divisors.append(i)
                if n%(n//i)==0 and m%(n//i)==0:
                    upper_divisors.append(n//i)
            i += 1
        return lower_divisors + upper_divisors[::-1]

    l = set(make_divisors(a,b))

    def primes(n):
        is_prime = [True] * (n + 1)
        is_prime[0], is_prime[1] = False, False
        for i in range(2, int(n**0.5) + 1):
            if not is_prime[i]:
                continue
            for j in range(i * 2, n + 1, i):
                is_prime[j] = False
        return [i for i in range(n + 1) if is_prime[i]]

    L = set(primes(a+b))
    L.add(1)
    print(len(L&l))










if __name__=="__main__":
    main()


Fixed submission:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    a,b = i_map()

    def prime_decomposition(n):
        i = 2
        table = []
        while i * i <= n: # sqrt(n)で計算が済む
            while n % i == 0:
                n //= i
                table.append(i)
            i += 1
        if n > 1:
            table.append(n)
        return table

    a = set(prime_decomposition(a))
    b = set(prime_decomposition(b))
    print(len(a&b)+1)



if __name__=="__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)

n, q = map(int, input().split())
g=[[] for _ in range(n)]

for i in range(n-1): # 行列の作成
    a, b = map(int, input().split())
    g[a - 1].append(b - 1)
    g[b - 1].append(a - 1)

costs = [0]*n # 答えの格納

for i in range(q): # コスト初期値の入力
    p, x = map(int, input().split())
    costs[p-1]+=x

visited = [0]*n # 訪問スタンプ

def dfs(idx):
    visited[idx]=1
    for i in g[idx]:
        if visited[i]==1:
            continue
        costs[i]+=costs[idx] # 累積和をとる
        dfs(i) # 再帰処理
    return

dfs(0)
print(*costs)


Fixed submission:
import sys
sys.setrecursionlimit(10**6)

n, q = map(int, input().split())
g=[[] for _ in range(n)]

for i in range(n-1): # 行列の作成
    a, b = map(int, input().split())
    g[a - 1].append(b - 1)
    g[b - 1].append(a - 1)

costs = [0]*n # 答えの格納

for i in range(q): # コスト初期値の入力
    p, x = map(int, input().split())
    costs[p-1]+=x

visited = [0]*n # 訪問スタンプ

def dfs(idx):
    visited[idx]=1
    for i in g[idx]:
        if visited[i]==1:
            continue
        costs[i]+=costs[idx] # 累積和をとる
        dfs(i) # 再帰処理
    return

dfs(0)
print(*costs)
Buggy python submission (verdict: Time Limit Exceeded):
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n,M = i_map()
    l = [i_list() for _ in range(n)]
    l.sort(reverse = True)

    dp = [0]*(M+1)
    for i,k in l:
        if i > M:
            continue
        m = min(dp[:(-i)])
        d = dp.index(m)
        if k > m:
            dp[d] = k
    print(sum(dp))





if __name__=="__main__":
    main()


Fixed submission:
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    import heapq
    n,m = i_map()
    t = [[] for _ in range(m+1)]
    for i in range(n):
        a,b = i_map()
        if a> m:
            continue
        t[a].append(b)

    ans = 0
    h = []
    for l in t:
        for i in l:
            heapq.heappush(h, -i)
        if h:
            ans -= heapq.heappop(h)
    print(ans)






if __name__=="__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import math
from math import gcd,pi,sqrt,factorial
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n,k = i_map()

    p = n - k + 1
    b = k - 1

    for i in range(1,k+1):
        pci = factorial(p)//factorial(p-i)//factorial(i)
        bci1 = factorial(b)//factorial(b-(i-1))//factorial(i-1)
        print(pci*bci1%MOD)



if __name__=="__main__":
    main()


Fixed submission:
import math
from math import gcd,pi,sqrt,factorial
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n,k = i_map()

    p = n - k + 1
    b = k - 1

    def comb(n, r):
      if n-r>=0:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
      else:
        return 0

    for i in range(1,k+1):
        pci = comb(p,i)
        bci1 = comb(b,i-1)
        print((pci*bci1)%MOD)

if __name__=="__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
sys.setrecursionlimit(500*500)
import itertools
from collections import Counter,deque

def main():
    n,q = map(int, input().split())
    s = input().rstrip()
    t = [0]*(n+1)
    for _ in range(n):
        if s[i:i+2] == "AC":
            t[i+1] = t[i] + 1

    for i in range(q):
        l,r = map(int, input().split())
        prin(t[r-1] - t[l-1])

if __name__=="__main__":
    main()


Fixed submission:
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
sys.setrecursionlimit(500*500)
import itertools
from collections import Counter,deque

def main():
    n,q = map(int, input().split())
    s = input().rstrip()
    t = [0]*(n+1)
    for i in range(n):
        if s[i:i+2] == "AC":
            t[i+1] = t[i] + 1
        else:
            t[i+1] = t[i]

    for i in range(q):
        l,r = map(int, input().split())
        print(t[r-1] - t[l-1])

if __name__=="__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
sys.setrecursionlimit(500*500)
import itertools
from collections import Counter,deque

def main():

    def de(l,i):
        if len(l) == 0:
            return
        if len(l) == 2:
            if l[0] != l[1]:
                l = []
            return
        if l[i] != l[i-1]:
            l.pop(i)
            l.pop(i-1)
            de(l,i-1)
        elif len(l) >= i+1:
            if l[i] != l[i+1]:
                l.pop(i+1)
                l.pop(i)
                de(l,i)
        else:
            pass

    s = list(input().rstrip())
    l = len(s)
    for i in range(1,len(s)):
        de(s,i)
    print(l - len(s))

if __name__=="__main__":
    main()


Fixed submission:
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
sys.setrecursionlimit(500*500)
import itertools
from collections import Counter,deque

def main():

    s = list(input().rstrip())
    zero = 0
    one = 0
    for i in s:
        if i == "0":
            zero += 1
        else:
            one += 1
    print(2*min(zero,one))

if __name__=="__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
sys.setrecursionlimit(500*500)
import itertools
from collections import Counter,deque

def main():
    n,m = map(int, input().split())
    l = list(map(int, input().split()))
    l.sort()

    ans = 0
    if n<m:
        L = []
        for i in range(m-1):
            l.append(l[i+1] - l[i])
        L.sort()
        for i in range(m-n):
            ans += L[i]
    print(ans)


if __name__=="__main__":
    main(
    )


Fixed submission:
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
sys.setrecursionlimit(500*500)
import itertools
from collections import Counter,deque

def main():
    n,m = map(int, input().split())
    l = list(map(int, input().split()))
    l.sort()

    ans = 0
    if n<m:
        L = []
        for i in range(m-1):
            L.append(l[i+1] - l[i])
        L.sort()
        for i in range(m-n):
            ans += L[i]
    print(ans)

if __name__=="__main__":
    main(
    )
Buggy python submission (verdict: Runtime Error):
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

def main():
    n = i_input()
    l = [i_list() for i in range(n)]

    for x in range(101):
        for y in range(101):
            H = l[0][2] + abs(x-l[0][0]) + abs(y-l[0][1])
            flg = True
            for x1, y1, h1 in l[1:]:
                if H != h1 + abs(x-x1) + abs(y-y1):
                    flg = False
                    break
            if flg == True:
                ans = [x,y]
    H = l[0][2] + abs(ans[0]-l[0][0]) + abs(ans[1]-l[0][1])
    print(" ".join(map(str, ans)) +" "+str(H))



if __name__=="__main__":
    main()


Fixed submission:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

def main():
    n = i_input()
    l = [i_list() for i in range(n)]

    L = []

    for i in l:
        if i[2] != 0:
            L.append(i)
    if len(L) == 1:
        print(" ".join(map(str, L[0])))
        exit()

    for x in range(101):
        for y in range(101):
            H = L[0][2] + abs(x-L[0][0]) + abs(y-L[0][1])
            flg = True
            for x1, y1, h1 in L[1:]:
                if h1 == 0:
                    pass
                if H != h1 + abs(x-x1) + abs(y-y1):
                    flg = False
                    break
            if flg == True:
                ans = [x,y]
    H = L[0][2] + abs(ans[0]-L[0][0]) + abs(ans[1]-L[0][1])
    print(" ".join(map(str, ans)) +" "+str(H))


if __name__=="__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools
from collections import Counter

def main():
    def isPrime(n):
        if n == 2:
            return True
        if n%2 == 0 or n == 1:
            return False
        m = math.floor(math.sqrt(n))+1
        for p in range(3,m,2):
            if n%p == 0:
                return False
        return True

    q = int(input())
    list = []
    for i in range(q):
        cnt = 0
        l,r = map(int, input().split())
        for k in range(l,r+1):
            if k != 2 and k%2==0:
                pass
            else:
                if isPrime(k) and isPrime((k+1)//2):
                    cnt += 1
        list.append(cnt)
    print("\n".join(map(str, list)))

if __name__=="__main__":
    main()


Fixed submission:
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools
from collections import Counter

def main():
    def primes(n):
        is_prime = [True] * (n + 1)
        is_prime[0], is_prime[1] = False, False
        for i in range(2, int(n**0.5) + 1):
            if not is_prime[i]:
                continue
            for j in range(i * 2, n + 1, i):
                is_prime[j] = False
        return [i for i in range(n + 1) if is_prime[i]], is_prime

    q = int(input())
    primes_num, is_primes = primes(10**5+5)
    sums = []
    cnt = 0

    for i in range(0, 10**5+4):
        if i%2!=0:
            a = (i+1)//2
            if is_primes[i] and is_primes[a]:
                cnt += 1
        sums.append(cnt)

    for i in range(q):
        l,r = map(int, input().split())
        print(sums[r] - sums[l-1])

if __name__=="__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    a,b,c,d,e,f = i_map()
    W = set()
    for i in range(0,f+1,a**100):
        for j in range(0,f+1, b*100):
            W.add(i+j)

    S = set()
    for i in range(0,f+1, c):
        for j in range(0, f+1, d):
            S.add(i+j)

    rate = -1

    for w in W:
        for s in S:
            if 0 < w+s <= f and s <= w*e//100:
                if s/(w+s) > rate:
                    rate = s/(w+s)
                    ans = w+s,s
    print(ans[0], ans[1])






if __name__=="__main__":
    main()


Fixed submission:
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    a,b,c,d,e,f = i_map()
    W = set()
    for i in range(0,f+1,a*100):
        for j in range(0,f+1, b*100):
            W.add(i+j)

    S = set()
    for i in range(0,f+1, c):
        for j in range(0, f+1, d):
            S.add(i+j)

    rate = -1

    for w in W:
        for s in S:
            if 0 < w+s <= f and s <= w*e//100:
                if s/(w+s) > rate:
                    rate = s/(w+s)
                    ans = (w+s,s)
    print(ans[0], ans[1])





if __name__=="__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

def main():
    n,m,R = i_map()
    r = i_list()
    c = [[INF]*n for i in range(n)]
    for i in range(n):
        c[i][i] = 0

    for _ in range(m):
        a,b,d = i_map()
        a -= 1
        b -= 1
        c[a][b] = c[b][a] = d

    for k in range(n): # 経由
        for i in range(n): # 始点
            for j in range(n): # 終点
                c[i][j] = min(c[i][j], c[i][k] + c[k][j])

    r = list(itertools.permutations(r, R))

    ans = INF
    for i in r:
        trial = 0
        for k in range(len(i)-1):
            a = i[k] - 1
            b = i[k+1] - 1
            trial += c[a][b]
        ans = min(ans,trial)
    print(ans)




if __name__=="__main__":
    main()


Fixed submission:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

def main():
    n,m,R = i_map()
    r = i_list()
    c = [[INF]*n for i in range(n)]
    for i in range(n):
        c[i][i] = 0

    for _ in range(m):
        a,b,d = i_map()
        a -= 1
        b -= 1
        c[a][b] = c[b][a] = d

    for k in range(n): # 経由
        for i in range(n): # 始点
            for j in range(n): # 終点
                c[i][j] = min(c[i][j], c[i][k] + c[k][j])

    r = list(itertools.permutations(r, R))

    ans = INF
    for i in r:
        trial = 0
        for k in range(len(i)-1):
            a = i[k] - 1
            b = i[k+1] - 1
            trial += c[a][b]
        ans = min(ans,trial)
    print(ans)




if __name__=="__main__":
    main()