Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys

def solve(H: int, W: int, s: "List[str]"):
    dp = [[0]*W for _ in range(H)]

    if s[0][0] == "#":
        dp[0][0] = 1

    for i in range(H):
        for j in range(W):
            if i == 0:
                if j == 0:
                    continue

                if s[i][j] == "#" and s[i][j-1] == ".":
                    dp[i][j] = dp[i][j-1]+1
                else:
                    dp[i][j] = dp[i][j-1] 
            else:
                if j == 0:
                    if s[i-1][j] == "." and s[i][j] == "#":
                        up = dp[i-1][j]+1
                    else:
                        up = dp[i-1][j]
                    dp[i][j] = up
                    continue
                else:
                    if s[i-1][j] == "." and s[i][j] == "#":
                        up = dp[i-1][j]+1
                    else:
                        up = dp[i-1][j]
                    
                    if s[i][j-1] == "." and s[i][j] == "#":
                        left = dp[i][j-1]+1
                    else:
                        left = dp[i][j-1]
                    
                    dp[i][j] = min(left,up)

    print(dp[H-1][W-1])
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(W)]  # type: "List[str]"
    solve(H, W, s)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
# input = sys.stdin.r/eadline
def INT(): return int(input())
def MAP(): return map(int,input().split())
def LI(): return list(map(int,input().split()))

def main():
    H,W = MAP()
    s = [input() for _ in range(H)]
    dp = [[0]*W for _ in range(H)]

    if s[0][0] == "#":
        dp[0][0] = 1

    for i in range(H):
        for j in range(W):
            if i == 0:
                if j == 0:
                    continue

                if s[i][j] == "#" and s[i][j-1] == ".":
                    dp[i][j] = dp[i][j-1]+1
                else:
                    dp[i][j] = dp[i][j-1] 
            else:
                if j == 0:
                    if s[i-1][j] == "." and s[i][j] == "#":
                        up = dp[i-1][j]+1
                    else:
                        up = dp[i-1][j]
                    dp[i][j] = up
                    continue
                else:
                    if s[i-1][j] == "." and s[i][j] == "#":
                        up = dp[i-1][j]+1
                    else:
                        up = dp[i-1][j]
                    
                    if s[i][j-1] == "." and s[i][j] == "#":
                        left = dp[i][j-1]+1
                    else:
                        left = dp[i][j-1]
                    
                    dp[i][j] = min(left,up)

    print(dp[H-1][W-1])

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys


def solve(N: int, a: str):
    # a = "11002102121200"
    # a = "210211"
    a = list(map(int,a))
    # new = []
    # for i in range(len(a)-1):
    #     new.append(abs(a[i]-a[i+1]))
    # a = new
    # print(a)
    while len(a) > 1:
        new = []
        for i in range(len(a)-1):
            new.append(abs(a[i]-a[i+1]))
        a = new
    print(a[0])

    return


def main():
    N = int(input())  # type: int
    a = input() 
    solve(N, a)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys

def solve(N: int, a: str):
    a = [int(a[i])-1 for i in range(N)]
    zeroone = [a[i]%2 for i in range(N)]

    SUM = 0
    comb = [0]*N
    comb[0] = 1

    for i in range(1, N):
        comb[i] = 1 if (N-1)&i == i else 0

    for i in range(N):
        SUM += zeroone[i]*comb[i]
    SUM %= 2

    if SUM == 1:
        print(1)
        return
    
    if 1 in a:
        print(0)
        return
    
    ## 0か2
    zerotwo = [a[i]//2 for i in range(N)]

    SUM = 0
    for i in range(N):
        SUM += zerotwo[i]*comb[i]
    SUM %= 2

    if SUM == 1:
        print(2)
        return
    
    print(0)
    return


def main():
    N = int(input())  # type: int
    a = input() 
    solve(N, a)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys
# input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return map(int,input().split())
def LI(): return list(map(int,input().split()))

def main():
    S = input()
    Q = INT()
    reverse_flag = False

    for _ in range(Q):
        query = list(input().split())
        if len(query) == 3:
            F = int(query[1])
            C = query[2]
            if F == 1:
                if reverse_flag:
                    S += C
                else:
                    S = C + S
            elif F == 2:
                if reverse_flag:
                    S = C + S
                else:
                    S += C
        else:
            if reverse_flag:
                reverse_flag = False
            else:
                reverse_flag = True
    
    if reverse_flag:
        S = S[::-1]
    print(S)
    return
        
if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
# input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return map(int,input().split())
def LI(): return list(map(int,input().split()))

from collections import deque
def main():
    S = input()
    queue = deque(list(S))
    Q = INT()
    reverse_flag = False

    for _ in range(Q):
        query = list(input().split())
        if len(query) == 3:
            F = int(query[1])
            C = query[2]
            if F == 1:
                if reverse_flag:
                    queue.append(C)
                else:
                    queue.appendleft(C)
            elif F == 2:
                if reverse_flag:
                    queue .appendleft(C)
                else:
                    queue.append(C)
        else:
            if reverse_flag:
                reverse_flag = False
            else:
                reverse_flag = True
    answer = ''.join(queue)
    if reverse_flag:
        answer = answer[::-1]
    print(answer)
    return
        
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys


def solve(N: int, P: int, S: str):
    if P == 2 or P ==5:
        answer = 0
        for i in range(N):
            if int(S[i])%P == 0:
                answer += i+1
        print(answer)

        return
    amari = [0]*N

    for i in range(N-1,-1,-1):
        num = int(S[i:N])
        amari[i]=num%P
    from collections import Counter
    counter = Counter(amari)
    answer = 0
    for _,value in counter.items():
        answer += (value*(value-1))//2
    answer += amari.count(0)
    print(answer)  
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    P = int(next(tokens))  # type: int
    S = next(tokens)  # type: int
    solve(N, P, S)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys


def solve(N: int, P: int, S: str):
    if P == 2 or P ==5:
        answer = 0
        for i in range(N):
            if int(S[i])%P == 0:
                answer += i+1
        print(answer)
        return

    amari = [0]*N
    amari[N-1] = int(S[N-1])%P
    keta = 1
    for i in range(N-2,-1,-1):
        num = pow(10,keta,P)*int(S[i])
        amari[i]=(amari[i+1]+num)%P
        keta += 1
    from collections import Counter
    counter = Counter(amari)
    answer = 0
    for _,value in counter.items():
        answer += (value*(value-1))//2
    answer += amari.count(0)
    print(answer)  
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    P = int(next(tokens))  # type: int
    S = next(tokens)  # type: int
    solve(N, P, S)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return map(int,input().split())
def LI(): return list(map(int,input().split()))

import numpy as np
def main():
    S,T = input().split()
    A,B = MAP()
    U = INT()

    if S == U:
        print(A-1,B)
    else:
        print(A,B-1)

    return

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
# input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return map(int,input().split())
def LI(): return list(map(int,input().split()))

def main():
    S,T = input().split()
    A,B = MAP()
    U = input()

    if S == U:
        print(A-1,B)
    else:
        print(A,B-1)

    return

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys


def solve(H: int, N: int, A: "List[int]", B: "List[int]"):
    # AB = sorted(list(zip(A,B)),key=lambda x: -x[0]/x[1])

    # dp[i][j] i番目までの技からいくつか選んで体力H以下にするときの最小MP

    dp = [[10**9]*(H+10**4+1) for _ in range(N+1)]
    for i in range(N+1):
        dp[i][0] = 0

    for i in range(N):
        for h in range(H+10**4+1):
            if h - A[i] >= 0:
                dp[i+1][h] = min(dp[i+1][h-A[i]]+B[i],dp[i][h])
            else:
                dp[i+1][h] = dp[i][h]
 

    answer = 10**9
    for i in range(H,H+10**4+1):
        answer = min(answer,dp[-1][i])
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(H, N, A, B)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys


def solve(H: int, N: int, A: "List[int]", B: "List[int]"):
    # AB = sorted(list(zip(A,B)),key=lambda x: -x[0]/x[1])

    # dp[i][j] i番目までの技からいくつか選んで体力H以下にするときの最小MP

    dp = [[10**9]*(H+10**4+1) for _ in range(N+1)]
    for i in range(N+1):
        dp[i][0] = 0

    for i in range(N):
        for h in range(H+10**4+1):
            if h - A[i] >= 0:
                dp[i+1][h] = min(dp[i+1][h-A[i]]+B[i],dp[i][h])
            else:
                dp[i+1][h] = dp[i][h]
 

    answer = 10**9
    for i in range(H,H+10**4+1):
        answer = min(answer,dp[-1][i])
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(H, N, A, B)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys

def solve(N: int, S: str):
    answer = 0
    for i in range(1000):
        target = str(i).zfill(3)
        index = 0
        for i in range(N):
            if S[i] == target[index]:
                index += 1
            
            if index == 3:
                answer += 1
                break
    
    print(answer)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys

def solve(N: int, S: str):
    answer = 0
    for i in range(0,1000):
        i = str(i).zfill(3)
        index = 0
        for ss in S:
            if ss == i[index]:
                index += 1
                if index >= 3:
                    answer += 1
                    break

    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: int
    solve(N, S)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from itertools import permutations

def main():
    N = int(input())
    xy = [tuple(map(int,input().split())) for _ in range(N)]
    answer = 0
    for perm in permutations(list(range(N))):
        all_distance = 0

        for i in range(N-1):
            all_distance += ((perm[i+1][1]-perm[i][1])**2 + (perm[i+1][0]-perm[i][0])**2)**(1/2)

        answer = min(answer,all_distance)
    print(answer)
    return


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
import itertools

def solve(N: int, x: "List[int]", y: "List[int]"):
    pattern = list(itertools.permutations(range(N)))
    sum_dist = 0
    for p in pattern:
        for i in range(1,N):
            sum_dist+=((x[p[i]]-x[p[i-1]])**2+(y[p[i]]-y[p[i-1]])**2)**(1/2)

    print(sum_dist/len(pattern))

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]"
    y = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, x, y)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys

def solve(N: int, L: "List[int]", R: "List[int]"):
    LR= list(zip(L,R))
    LR.sort(key=lambda x:x[0])

    answer = 0
    for i in range(1,N):
        a = 0
        mi = 0
        ma = 10**9
        for lr in LR[:i]:
            mi = max(lr[0],mi)
            ma = min(lr[1],ma)
        a += ma-mi+1
        
        mi = 0
        ma = 10**9
        for lr in LR[i:]:
            mi = max(lr[0],mi)
            ma = min(lr[1],ma)
        a += ma-mi+1

        answer = max(a,answer)
    print(answer)
        
  
        



    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = [int()] * (N)  # type: "List[int]"
    R = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        L[i] = int(next(tokens))
        R[i] = int(next(tokens))
    solve(N, L, R)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys

def solve(N: int, L: "List[int]", R: "List[int]"):
    LR= list(zip(L,R))
    LR.sort(key=lambda x:x[0])

    r_left_max = [] ##index 以下のrightのmin
    for lr in LR:
        if r_left_max:
            r_left_max.append(min(r_left_max[-1],lr[1]))
        else:
            r_left_max.append(lr[1])

    r_right_max = []
    for lr in LR[::-1]:
        if r_right_max:
            r_right_max.append(min(r_right_max[-1],lr[1]))
        else:
            r_right_max.append(lr[1])

    answer = 0
    for i in range(1,N):
        a = 0
        a += max(r_left_max[i-1]-LR[i-1][0]+1,0)
        a += max(r_right_max[N-i-1]-LR[-1][0]+1,0)
        answer = max(a,answer)

    ## 一つとその他の場合。indexがiのものを一つにする
    for i in range(N):
        a =0 
        a+= LR[i][1]-LR[i][0]+1
        if i == N-1:
            min_upper_limit = r_left_max[N-2]
            a+= max(min_upper_limit-LR[N-2][0]+1,0)
        elif i == 0:
            min_upper_limit = r_right_max[N-2]
            a+= max(min_upper_limit-LR[-1][0]+1,0)
        else:
            min_upper_limit = min(r_left_max[i-1],r_right_max[N-i-2])

            a+= max(min_upper_limit-LR[-1][0]+1,0)

        answer = max(a,answer)
    
    print(answer)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = [int()] * (N)  # type: "List[int]"
    R = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        L[i] = int(next(tokens))
        R[i] = int(next(tokens))
    solve(N, L, R)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys
import itertools
# 周長は三角形のうちの最大長の2倍よりも大きい

def solve(N: int, L: "List[int]"):
    # N = 5
    # L = [1,2,2,3,4]
    L.sort()
    answer = 0
    for i in range(N):
        for j in range(i+1,N):
            for k in range(j+1,N):
                if L[i]+L[j]>L[k]:
                    answer += 1
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, L)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
import bisect

def solve(N: int, L: "List[int]"):
    L.sort()
    answer = 0
    for i in range(N):
        for j in range(i+1,N):
            max_k = bisect.bisect_left(L,L[i]+L[j])
            answer += max_k-(j+1)
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, L)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys
import itertools

def solve(N: int, L: "List[int]"):
    combi = itertools.combinations(L,3)
    answer = 0
    for c in combi:
        if c[0]<c[1]+c[2] and c[1]<c[0]+c[2] and c[2]<c[1]+c[0]:
            answer += 1
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, L)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
import bisect

def solve(N: int, L: "List[int]"):
    L.sort()
    answer = 0
    for i in range(N):
        for j in range(i+1,N):
            max_k = bisect.bisect_left(L,L[i]+L[j])
            answer += max_k-(j+1)
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, L)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
k = int(input())
ss = ""
for _ in range(k):
    ss += s

ss_list = list(ss)
count = 0
answer = 0
prev = ""
for sss in ss_list:
    if prev == "" or sss == prev:
        count+=1
        if count == 2: 
            answer+=1
            count=0

    else:
        count=1
    prev = sss

print(answer)

Fixed submission:
import sys
s = list(input())
k = int(input())

if len(set(s))==1:
	print((len(s)*k)//2)
	sys.exit()
    
def counter(string):
    count = 0
    answer = 0
    prev = ""
    for index,sss in enumerate(string):
        if prev == "" or sss == prev:
            count+=1
            if count == 2: 
                answer+=1
                count=0
                string[index] = "1"
        else:
            count=1
        prev = sss
    return answer,string

answer, string = counter(s.copy())

if string[0] != string[-1]:
    print(answer*k)
else:
    count = 0
    l = len(s)
    for i in range(l):
        if s[i] == s[0]:
            count += 1
        else:
            break
    for i in range(l):
        if s[-1-i] == s[0]:
        	count += 1
        else:
        	break

    if count % 2 ==0:
        print(answer*k + k-1)
    else:
        print(answer*k)

Buggy python submission (verdict: Runtime Error):
s = input()
k = input()

ss = ""
for _ in range(k):
    ss += s

ss_list = list(ss)
count = 0
answer = 0
prev = ""
for sss in ss_list:
    if prev == "" or sss == prev:
        count+=1
        if count == 2: 
            answer+=1
            count=0

    else:
        count=1
    prev = sss

print(answer)

Fixed submission:
import sys
s = list(input())
k = int(input())

if len(set(s))==1:
	print((len(s)*k)//2)
	sys.exit()
    
def counter(string):
    count = 0
    answer = 0
    prev = ""
    for index,sss in enumerate(string):
        if prev == "" or sss == prev:
            count+=1
            if count == 2: 
                answer+=1
                count=0
                string[index] = "1"
        else:
            count=1
        prev = sss
    return answer,string

answer, string = counter(s.copy())

if string[0] != string[-1]:
    print(answer*k)
else:
    count = 0
    l = len(s)
    for i in range(l):
        if s[i] == s[0]:
            count += 1
        else:
            break
    for i in range(l):
        if s[-1-i] == s[0]:
        	count += 1
        else:
        	break

    if count % 2 ==0:
        print(answer*k + k-1)
    else:
        print(answer*k)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
h = [int(x) for x in input().split() if x>=k]
print(sum(h))

Fixed submission:
n, k = map(int, input().split())
h = [int(x) for x in input().split() if int(x)>=k]
print(len(h))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()] 

for i in range(1,n+1):
  print(a.index(i)+1)

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()] 
answer = [0 for _ in range(n)]
 
for index, aa in enumerate(a):
  answer[aa-1] = index+1

for an in answer:
  print(an)
Buggy python submission (verdict: Time Limit Exceeded):
a, b = map(int, input().split())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

def common_divisors(k,j):
  c = make_divisors(k) + make_divisors(j)
  return [x for x in set(c) if c.count(x) > 1]
  
kouyakusuu = common_divisors(a,b)
count = 0
for k in kouyakusuu:
  if len(make_divisors(k)) == 1 or make_divisors(k)==[1,k]:      
   	count+=1

print(count)


Fixed submission:
a, b = map(int, input().split())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

def common_divisors(k,j):
  c = make_divisors(k) + make_divisors(j)
  return [x for x in set(c) if c.count(x) > 1]

def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct
  
kouyakusuu = common_divisors(a,b)

aa=factorize(a)
bb=factorize(b)
l = list(set(aa))+list(set(bb))
ll = [x for x in set(l) if l.count(x) > 1]

print(len(ll)+1)