Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
if(n>k):
    if(n%k==0):
        print(0)
    else:
        print(min((n%k),(n//k+1)*k-n))
elif(n==k):
    print(0)
else:
    if(k%n==0):
        print(n)
    else:
        if(k-n)<=n:
            print(k-n)
        else:
            print(n)


Fixed submission:
n,k=map(int,input().split())
if(n>k):
    if(n%k==0):
        print(0)
    else:
        print(min((n%k),(n//k+1)*k-n))
elif(n==k):
    print(0)
elif(n==0):
    print(0)
else:
    if(k%n==0):
        print(n)
    else:
        if(k-n)<=n:
            print(k-n)
        else:
            print(n)

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
if(n>k):
    if(n%k==0):
        print(0)
    else:
        print(min((n%k),(n//k+1)*k-n))
elif(n==k):
    print(0)
else:
    if(k%n==0):
        print(n)
    else:
        if(k-n)<n:
            print(k-n)
        else:
            print(n)



Fixed submission:
n,k=map(int,input().split())
if(n>k):
    if(n%k==0):
        print(0)
    else:
        print(min((n%k),(n//k+1)*k-n))
elif(n==k):
    print(0)
elif(n==0):
    print(0)
else:
    if(k%n==0):
        print(n)
    else:
        if(k-n)<=n:
            print(k-n)
        else:
            print(n)
Buggy python submission (verdict: Runtime Error):
s=str(input())
if(s[3]==s[4] and s[5]==s[6]):
  print("Yes")
else:
  print("No")
  

Fixed submission:
s=str(input())
if(len(s)<6):
  print("No")
else:
  if(s[3]==s[2] and s[4]==s[5]):
    print("Yes")
  else:
    print("No")
Buggy python submission (verdict: Runtime Error):
from collections import deque, Counter, defaultdict
from itertools import chain, combinations
import json
# import numpy as np
import bisect
import sys
import math
import bisect
from functools import lru_cache
import itertools

sys.setrecursionlimit(10 ** 8)

M = 10 ** 9 + 7
INF = 10 ** 17


def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    # N, K = [int(a) for a in input().split()]
    # A = [int(a) for a in input().split()]
    # T1, T2, T3 = [int(a) for a in input().split()]

    aa = []
    t = A[0]
    start = A[0]
    for ai in A[1:]:
        if t <= ai:
            t = ai
            if start is None:
                start = ai
            continue
        aa.append(
            (start, t)
        )
        t = ai
        start = None
    if start is not None:
        aa.append((start, A[-1]))

    m = 1000
    for a, b in aa:
        c = m // a
        m += (b - a) * c
    print(m)


if __name__ == "__main__":
    main()


Fixed submission:
from collections import deque, Counter, defaultdict
from itertools import chain, combinations
import json
# import numpy as np
import bisect
import sys
import math
import bisect
from functools import lru_cache
import itertools

sys.setrecursionlimit(10 ** 8)

M = 10 ** 9 + 7
INF = 10 ** 17


def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    # N, K = [int(a) for a in input().split()]
    # A = [int(a) for a in input().split()]
    # T1, T2, T3 = [int(a) for a in input().split()]

    aa = []
    t = A[0]
    start = A[0]
    for ai in A[1:]:
        if t <= ai:
            t = ai
            if start is None:
                start = ai
            continue
        aa.append(
            (start, t)
        )
        t = ai
        start = ai
    if start is not None:
        aa.append((start, A[-1]))

    m = 1000
    for a, b in aa:
        if a is None:
            continue
        c = m // a
        m += (b - a) * c
    print(m)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque, Counter, defaultdict
from itertools import chain, combinations
import json
# import numpy as np
import bisect
import sys
import math
import bisect
from functools import lru_cache
import itertools

sys.setrecursionlimit(10 ** 8)

M = 10 ** 9 + 7
INF = 10 ** 17


def main():
    N, K = [int(a) for a in input().split()]
    A = [int(a) for a in input().split()]
    # K = 200000
    # T = int(input())
    # A = [int(a) for a in input().split()]
    # T1, T2, T3 = [int(a) for a in input().split()]
    # A = [0] * 100000

    for _ in range(K):
        AA = [1] * len(A)
        for i, ai in enumerate(A):
            for ii in range(ai):
                ii += 1
                if i + ii < len(A):
                    AA[i + ii] += 1
                if i - ii >= 0:
                    AA[i - ii] += 1
        A = AA
    print(' '.join([str(a) for a in A]))


if __name__ == "__main__":
    main()


Fixed submission:
from collections import deque, Counter, defaultdict
from itertools import chain, combinations
import json
# import numpy as np
import bisect
import sys
import math
import bisect
from functools import lru_cache
import itertools

sys.setrecursionlimit(10 ** 8)

M = 10 ** 9 + 7
INF = 10 ** 17


def main():
    N, K = [int(a) for a in input().split()]
    A = [int(a) for a in input().split()]
    # T = int(input())
    # A = [int(a) for a in input().split()]
    # T1, T2, T3 = [int(a) for a in input().split()]

    for _ in range(K):
        AA = [0] * len(A)
        for i, ai in enumerate(A):
            l = max(0, i - ai)
            r = min(N - 1, i + ai)
            AA[l] += 1
            if r != N - 1:
                AA[r + 1] -= 1
        for i in range(len(AA) - 1):
            AA[i + 1] += AA[i]

        A = AA
        flag = True
        for a in AA:
            if a != len(A):
                flag = False
                break
        if flag:
            break
    print(' '.join([str(a) for a in A]))


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
from collections import deque, Counter
from itertools import chain, combinations
import json
import numpy as np
import bisect
import sys
import math

sys.setrecursionlimit(10 ** 8)
# mem = {}

M = 10 ** 9 + 7

mem = {}


def gcd(a, b, c):
    if (a, b, c) not in mem:
        mem[(a, b, c)] = math.gcd(math.gcd(a, b), c)
    return mem[(a, b, c)]


def main():
    K = int(input())
    t1 = 0
    for a in range(1, K + 1):
        for b in range(a + 1, K + 1):
            for c in range(b + 1, K + 1):
                t1 += gcd(a, b, c) * 6
    t2 = 0
    for ab in range(1, K + 1):
        for c in range(ab + 1, K + 1):
            t2 += math.gcd(ab, c) * 6
    t3 = 0
    for abc in range(1, K + 1):
        t3 += abc
    print(t1 + t2 + t3)


if __name__ == "__main__":
    main()


Fixed submission:
from collections import deque, Counter
from itertools import chain, combinations
import json
import bisect
import sys
import math

sys.setrecursionlimit(10 ** 8)
# mem = {}

M = 10 ** 9 + 7

mem = {}


def gcd(a, b, c):
    if (a, b, c) not in mem:
        mem[(a, b, c)] = math.gcd(math.gcd(a, b), c)
    return mem[(a, b, c)]


def main():
    K = int(input())
    t1 = 0
    for a in range(1, K + 1):
        for b in range(a + 1, K + 1):
            for c in range(b + 1, K + 1):
                t1 += gcd(a, b, c) * 6
    t2 = 0
    for ab in range(1, K + 1):
        for c in range(ab + 1, K + 1):
            t2 += math.gcd(ab, c) * 6
    t3 = 0
    for abc in range(1, K + 1):
        t3 += abc
    print(t1 + t2 + t3)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
from collections import deque
from itertools import chain, combinations
import json
from typing import List




def main():
    a = "abcdefghijklmnopqrstuvwxyz"
    c=input()
    print(a[a.index(c)+1])

    # N = int(input())
    # A = [int(a) for a in input().split()]
    # B = [
    #     [int(a) for a in input().split()]
    #     for _ in range(N)
    # ]
    print()


if __name__ == "__main__":
    main()


Fixed submission:
from collections import deque
from itertools import chain, combinations
import json




def main():
    a = "abcdefghijklmnopqrstuvwxyz"
    c=input()
    print(a[a.index(c)+1])

    # N = int(input())
    # A = [int(a) for a in input().split()]
    # B = [
    #     [int(a) for a in input().split()]
    #     for _ in range(N)
    # ]
    print()


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict, deque, Counter
import sys
import heapq
import math

# input = sys.stdin.readline

sys.setrecursionlimit(1000000000)

MIN = -10 ** 9
MOD = 10 ** 9 + 7


def main():
    N = int(input())
    # A,B = [int(a) for a in input().split()]
    L = sorted([int(a) for a in input().split()])
    # xy = [
    #     [int(a) for a in input().split()]
    #     for _ in range(N)
    # ]

    r = 0
    for a in range(N):
        for b in range(a + 1, N):
            for c in range(N-1,b,-1):
                if L[a] + L[b] > L[c]:
                    r += (c-b)
                    break

    print(r)


if __name__ == '__main__':
    main()


Fixed submission:
from collections import defaultdict, deque, Counter
import sys
import bisect
import heapq
import math

# input = sys.stdin.readline

sys.setrecursionlimit(1000000000)

MIN = -10 ** 9
MOD = 10 ** 9 + 7


def main():
    N = int(input())
    # A,B = [int(a) for a in input().split()]
    L = sorted([int(a) for a in input().split()])
    # xy = [
    #     [int(a) for a in input().split()]
    #     for _ in range(N)
    # ]

    r = 0
    for a in range(N):
        for b in range(a + 1, N):
            p = bisect.bisect_left(L, L[a] + L[b])
            r += (p - 1 - b)

            # for c in range(N-1,b,-1):
            #     if L[a] + L[b] > L[c]:
            #         r += (c-b)
            #         break

    print(r)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import math


def f(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)

    if temp != 1:
        arr.append(temp)

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

    return arr


def main():
    # return
    # N = int(input())
    # N,= [int(a) for a in input().split()]
    A, B = [int(a) for a in input().split()]

    gcd = math.gcd(A, B)

    if gcd == 1:
        print(1)
    else:
        print(len(f(gcd)) + 1)


if __name__ == "__main__":
    main()


Fixed submission:
import math


def gcdf(a, b):
    if a > b:
        a, b = b, a
    if b%a==0:
        return a
    return gcdf(a, b % a)


def f(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)

    if temp != 1:
        arr.append(temp)

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

    return arr


def main():
    # return
    # N = int(input())
    # N,= [int(a) for a in input().split()]
    A, B = [int(a) for a in input().split()]

    gcd = gcdf(A, B)

    if gcd == 1:
        print(1)
    else:
        print(len(f(gcd)) + 1)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict, deque, Counter
import sys
import heapq
import math

# input = sys.stdin.readline

sys.setrecursionlimit(1000000000)

MIN = -10 ** 9
MOD = 10 ** 9 + 7


def main():
    N = int(input())
    # A, B = [int(a) for a in input().split()]
    # H = [int(a) for a in input().split()]
    # A = [
    #     [int(a) for a in input().split()]
    #     for _ in range(N)
    # ]

    print(sum(a for a in range(1, N)))


if __name__ == '__main__':
    main()


Fixed submission:
from collections import defaultdict, deque, Counter
import sys
import heapq
import math

# input = sys.stdin.readline

sys.setrecursionlimit(1000000000)

MIN = -10 ** 9
MOD = 10 ** 9 + 7


def main():
    N = int(input())
    # A, B = [int(a) for a in input().split()]
    # H = [int(a) for a in input().split()]
    # A = [
    #     [int(a) for a in input().split()]
    #     for _ in range(N)
    # ]

    print((N*(N-1))//2)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter, defaultdict


def main():
    # n,m = [int(z) for z in input().split()]
    # table =[
    #     [int(z) for z in input().split()]
    #     for _ in range(n)
    # ]
    V = 10 ** 9 + 7
    n = int(input())
    c = [int(input()) for _ in range(n)]

    table = [0] * (n + 1)
    table[0] = 1

    D = defaultdict(lambda: [])

    for i in range(n):
        ci = c[i]
        if i != 0:
            if c[i - 1] == ci:
                table[i + 1] = table[i] % V
                continue

        pre = D[ci]
        res = table[i]
        for p_index in pre:
            res += table[p_index] % V
            res %= V
        table[i + 1] = res % V

        D[ci].append(i)

    print(table[-1])


if __name__ == '__main__':
    main()


Fixed submission:
from collections import Counter, defaultdict


def main():
    # n,m = [int(z) for z in input().split()]
    # table =[
    #     [int(z) for z in input().split()]
    #     for _ in range(n)
    # ]
    V = 10 ** 9 + 7
    n = int(input())
    c = [int(input()) for _ in range(n)]

    table = [0] * (n + 1)
    table[0] = 1

    D = defaultdict(lambda: 0)

    for i in range(n):
        ci = c[i]
        if i != 0:
            if c[i - 1] == ci:
                table[i + 1] = table[i] % V
                continue

        res = table[i]
        pre = D[ci]
        res += pre
        table[i + 1] = res % V

        D[ci] = D[ci] + table[i] % V

    print(table[-1])


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def solve(s):
    count = 0
    i = 0

    while True:
        if i >= len(s) - 1:
            break
        if s[i] != s[i + 1]:
            count += 1
            s = s[0:i] + s[i + 2:]
            i -= 1
            continue
        i += 1
    return count


def main():
    S = input()
    # a, b, k = [int(a) for a in input().split()]

    print(solve(S) * 2)


if __name__ == '__main__':
    main()


Fixed submission:
def solve(s):
    one = 0
    zero = 0
    for i in range(len(s)):
        if s[i] == "1":
            one += 1
        elif s[i] == "0":
            zero += 1
    return min(zero, one)


def main():
    S = input()
    # a, b, k = [int(a) for a in input().split()]

    print(solve(S) * 2)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def solve(start, s):
    for i in range(start, len(s) - 1):
        if s[i] != s[i + 1]:
            return 1 + solve(i - 1, s[:i] + s[i + 2:])
    return 0


def solve2(s):
    count = 0
    i = 0

    while True:
        if i == len(s) - 1:
            break
        if s[i] != s[i + 1]:
            count += 1
            s = s[:i] + s[i + 2:]
            i -= 1
            continue
        i += 1
    return count


def main():
    S = input()
    # a, b, k = [int(a) for a in input().split()]

    # print(solve(0, S) * 2)
    print(solve2(S) * 2)


if __name__ == '__main__':
    main()


Fixed submission:
def solve(s):
    one = 0
    zero = 0
    for i in range(len(s)):
        if s[i] == "1":
            one += 1
        elif s[i] == "0":
            zero += 1
    return min(zero, one)


def main():
    S = input()
    # a, b, k = [int(a) for a in input().split()]

    print(solve(S) * 2)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def solve(start, s):
    for i in range(start, len(s) - 1):
        if s[i] != s[i + 1]:
            return 1 + solve(i - 1, s[:i] + s[i + 2:])
    return 0


def main():
    S = input()
    # a, b, k = [int(a) for a in input().split()]

    print(solve(0, S) * 2)


if __name__ == '__main__':
    main()


Fixed submission:
def solve(s):
    one = 0
    zero = 0
    for i in range(len(s)):
        if s[i] == "1":
            one += 1
        elif s[i] == "0":
            zero += 1
    return min(zero, one)


def main():
    S = input()
    # a, b, k = [int(a) for a in input().split()]

    print(solve(S) * 2)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def comb(n):
    return (n * (n - 1)) // 2


def main():
    n, m = [int(a) for a in input().split()]

    AB = [
        [int(a) for a in input().split()]
        for _ in range(m)
    ]

    table = {i: (1, set([i])) for i in range(n)}  # (便利さ,行ける島集合)

    current_benrisa = 0
    max_hubensa = comb(n)

    reversed_benrisa = []
    for ai, bi in reversed(AB):
        reversed_benrisa.append(current_benrisa)
        s1_benrisa, s1_set = table[ai-1]
        s2_benrisa, s2_set = table[bi-1]
        if s1_set is s2_set:  # 変化なし
            continue

        new_benri = s1_benrisa + s2_benrisa
        new_set = s1_set.union(s2_set)
        for t in new_set:
            table[t] = (new_benri, new_set)

        inc = s1_benrisa * s2_benrisa
        current_benrisa += inc
        continue

    for a in reversed(reversed_benrisa):
        print(max_hubensa - a)


if __name__ == '__main__':
    main()


Fixed submission:
def comb(n):
    return (n * (n - 1)) // 2


def main():
    n, m = [int(a) for a in input().split()]

    AB = [
        [int(a) for a in input().split()]
        for _ in range(m)
    ]

    table = {i: {i} for i in range(n)}  # (便利さ,行ける島集合)

    current_benrisa = 0
    max_hubensa = comb(n)

    reversed_benrisa = []
    for ai, bi in reversed(AB):
        reversed_benrisa.append(current_benrisa)
        s1_set = table[ai - 1]
        s2_set = table[bi - 1]
        if s1_set is s2_set:  # 変化なし
            continue

        s1_benrisa = len(s1_set)
        s2_benrisa = len(s2_set)
        # new_benri = s1_benrisa + s2_benrisa
        if len(s1_set) > len(s2_set):
            s1_set.update(s2_set)
            for t in s2_set:
                table[t] = s1_set
        else:
            s2_set.update(s1_set)
            for t in s1_set:
                table[t] = s2_set

        # new_set = s1_set.union(s2_set)
        # for t in new_set:
        #     table[t] = (new_benri, new_set)

        inc = s1_benrisa * s2_benrisa
        current_benrisa += inc
        continue

    for a in reversed(reversed_benrisa):
        print(max_hubensa - a)


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

def gcd(a, b):
    if a < b:
        a, b = b, a

    if b == 1:
        return 1
    m = a % b
    if m == 0:
        return b
    return gcd(b, m)


def main():
    N, M = [int(a) for a in input().split()]

    S = input()
    T = input()
    L = N * M // gcd(N, M)
    a1 = L // N
    a2 = L // M
    cc = a1 * a2 // gcd(a1, a2)
    for i in range(L):
        if i % cc != 0:
            continue
        if S[i // a1] != T[i // a2]:
            print(-1)
            return
    print(L)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python

def gcd(a, b):
    if a < b:
        a, b = b, a

    if b == 1:
        return 1
    m = a % b
    if m == 0:
        return b
    return gcd(b, m)


def main():
    N, M = [int(a) for a in input().split()]

    S = input()
    T = input()
    L = N * M // gcd(N, M)
    a1 = L // N
    a2 = L // M
    cc = a1 * a2 // gcd(a1, a2)
    for i in range(0, L, cc):
        if S[i // a1] != T[i // a2]:
            print(-1)
            return
    print(L)


if __name__ == '__main__':
    main()

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

def gcd(a, b):
    if a < b:
        a, b = b, a

    m = a % b
    if m == 0:
        return b
    return gcd(b, m)


def main():
    N, M = [int(a) for a in input().split()]

    S = input()
    T = input()
    L = N * M // gcd(N, M)
    a1 = L // N
    a2 = L // M
    cc = a1 * a2 // gcd(a1, a2)
    for i in range(L):
        if i % cc != 0:
            continue
        if S[i // a1] != T[i // a2]:
            print(-1)
            return
    print(L)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python

def gcd(a, b):
    if a < b:
        a, b = b, a

    if b == 1:
        return 1
    m = a % b
    if m == 0:
        return b
    return gcd(b, m)


def main():
    N, M = [int(a) for a in input().split()]

    S = input()
    T = input()
    L = N * M // gcd(N, M)
    a1 = L // N
    a2 = L // M
    cc = a1 * a2 // gcd(a1, a2)
    for i in range(0, L, cc):
        if S[i // a1] != T[i // a2]:
            print(-1)
            return
    print(L)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import math


def main():
    N, = [int(a) for a in input()]
    W = [input() for _ in range(N)]

    if len(set(W)) != len(W):
        print("No")
        return
    W = [list(a) for a in W]

    for i in range(len(W) - 1):
        if W[i][-1] != W[i + 1][0]:
            print("No")
            return
    print("Yes")


if __name__ == '__main__':
    main()


Fixed submission:
import math


def main():
    N = int(input())
    W = [input() for _ in range(N)]

    if len(set(W)) != len(W):
        print("No")
        return
    W = [list(a) for a in W]

    for i in range(len(W) - 1):
        if W[i][-1] != W[i + 1][0]:
            print("No")
            return
    print("Yes")


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import math
from collections import defaultdict


def main():
    N, = [int(a) for a in input()]
    W = [input() for _ in range(N)]

    if len(set(W)) != len(W):
        print("No")
        return

    for i in range(len(W) - 1):
        if W[i][-1] != W[i + 1][0]:
            print("No")
            return
    print("Yes")


if __name__ == '__main__':
    main()


Fixed submission:
import math


def main():
    N = int(input())
    W = [input() for _ in range(N)]

    if len(set(W)) != len(W):
        print("No")
        return
    W = [list(a) for a in W]

    for i in range(len(W) - 1):
        if W[i][-1] != W[i + 1][0]:
            print("No")
            return
    print("Yes")


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import math
from collections import defaultdict


def main():
    N, = [int(a) for a in input()]
    W = [input() for _ in range(N)]

    a = []
    for w in W:
        if w in a:
            print("No")
            return
        a.append(w)
        if len(a) == 1:
            continue
        if a[-2][-1] != a[-1][0]:
            print("No")
            return
    print("Yes")


if __name__ == '__main__':
    main()


Fixed submission:
import math


def main():
    N = int(input())
    W = [input() for _ in range(N)]

    if len(set(W)) != len(W):
        print("No")
        return
    W = [list(a) for a in W]

    for i in range(len(W) - 1):
        if W[i][-1] != W[i + 1][0]:
            print("No")
            return
    print("Yes")


if __name__ == '__main__':
    main()