Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input().strip())
    a = list(map(int, input().strip().split()))
    min_v = float("inf")
    for i in range(1, N):
        x = sum(a[:i])
        y = sum(a[i:])
        min_v = min(min_v, abs(x - y))
    print(min_v)

if __name__ == '__main__':
    main()


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

    solve(N,A)

def solve(N,A):
    ans = float("inf")

    # ans = TLE(N,A,ans)
    ans = AC(N,A,ans)

    print(ans)

def TLE(N,A, ans):
    for i in range(1, N):
        snk = sum(A[:i])
        ari = sum(A[i:])

        ans = min(ans, abs(snk - ari))

    return ans

def AC(N,A,ans):
    cum_A = [None] * N
    cum_A[0] = A[0]
    for i in range(1, N):
        cum_A[i] = cum_A[i-1] + A[i]

    for i in range(N-1):
        snk = cum_A[i]
        ari = cum_A[-1] - snk

        ans = min(ans, abs(snk - ari))

    return ans

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    N, P = map(int, input().split())
    *A, = map(int, input().split())

    editorial(N, P, A)

def editorial(N, P, A):
    odds = [a for a in A if a % 2 == 1]
    odd = len(odds)
    even = N - odd

    if odd == 0:
        if P = 1:
            print(0)
        else:
            print(2 ** N)
        return
    
    # ある奇数袋を取り除いて、残りでの組み合わせ(選ぶ選ばないの2通りがN-1)
    ans = 2 ** (N - 1)
    # s = 組み合わせのビスケット枚数
    # P=0,s:奇数であるとき、加えるのは1通り
    # P=0,s:奇数でないとき、加えないのは1通り
    # P=1,s:奇数であるとき、加えないのは１通り
    # P=1,s:奇数でないとき、加えるのは1通り
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    N, P = map(int, input().split())
    *A, = map(int, input().split())

    odd = sum(a % 2 for a in A)
    even = N - odd
    o, e = 0, 0
    # 奇数枚の袋の選び方
    # P=0: 奇数個含まれる袋から足して２の倍数になる袋の組合せ(袋0でもよい)
    # P=1: 奇数なので奇数枚の袋を奇数個
    for i in range(P, odd+1, 2):
        o += ncr(odd, i)

    for i in range(even+1):
        e += ncr(even, i)
    ans = o * e

    print(ans)


def _factorial(n):
    if n < 0:
        raise ValueError("factorial() not defined for negative values")
    a = 1
    for i in range(1, n + 1):
        a *= i
    return a


def npr(n, r):
    if n < r:
        return 0
    a = 1
    for i in range(r):
        a *= n - i
    return a


def ncr(n, r):
    _npr = npr(n, r)
    if _npr == 0:
        return 0
    return _npr // _factorial(r)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    # not use N
    _ = int(input().strip())

    n_399 = 0
    n_799 = 0
    n_1199 = 0
    n_1599 = 0
    n_1999 = 0
    n_2399 = 0
    n_2799 = 0
    n_3199 = 0
    n_free = 0
    rates = list(map(int, input().strip().split()))
    for r in rates:
        if r <= 399:
            n_399 = 1
        elif r <= 799:
            n_799 = 1
        elif r <= 1199:
            n_1199 = 1
        elif r <= 1599:
            n_1599 = 1
        elif r <= 1999:
            n_1999 = 1
        elif r <= 2399:
            n_2399 = 1
        elif r <= 2799:
            n_2799 = 1
        elif r <= 3199:
            n_3199 = 1
        else:
            n_free += 1

    n_min = n_399 + n_799 + n_1199 + n_1599 + n_1999 + n_2399 + n_2799 + n_3199
    if n_min == 0 and n_free > 0:
        n_min = 1

    if n_min + n_free >= 8:
        n_max = 8
    else:
        n_max = n_min + n_free

    print(n_min, n_max)

if __name__ == '__main__':
    main()


Fixed submission:
def main():
    r, g, b = list(map(int, input().strip().split()))
    v = r * 100 + g * 10 + b
    if v % 4 == 0:
        print("YES")
    else:
        print("NO")

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())

    p = 1
    for i in range(1, N + 1):
        p *= i

    ans = p % (10 ** 9 + 7)
    print(ans)

if __name__ == '__main__':
    main()


Fixed submission:
def main():
    N = int(input())

    p = 1
    for i in range(1, N + 1):
        # TLE
        # p *= i
        p = (p * i) % (10 ** 9 + 7)

    ans = p % (10 ** 9 + 7)
    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    S = input()

    dfs(S)


def dfs(S):
    l = len(S)
    if _dfs(S, l, 0):
        print("YES")
    else:
        print("NO")


def _dfs(S, l, idx, pattern=0):
    # print(l, idx, pattern)
    if idx == l:
        return True

    if S[idx:idx + 7] == "dreamer":
        ok = _dfs(S, l, idx + 7, 1)
        if ok:
            return True
    if S[idx:idx + 6] == "eraser":
        ok = _dfs(S, l, idx + 6, 2)
        if ok:
            return True
    if S[idx:idx + 5] == "dream" or \
            S[idx:idx + 5] == "erase":
        ok = _dfs(S, l, idx + 5, 3)
        if ok:
            return True

    return False


def WA(S):
    l = len(S)
    idx = 0
    ok = True
    while idx < l:
        if S[idx:idx + 7] == "dreamer":
            idx += 7
        elif S[idx:idx + 6] == "eraser":
            idx += 6
        elif S[idx:idx + 5] == "dream" or \
                S[idx:idx + 5] == "erase":
            # 評価順番注意
            idx += 5
        else:
            ok = False
            break

    if ok:
        print("YES")
    else:
        print("NO")

if __name__ == '__main__':
    main()


Fixed submission:
def main():
    S = input()

    editorial(S)


def editorial(S):
    """
    それぞれがそれ以外のprefixにならなければ良い
    """
    l = len(S)
    idx = 0
    ok = True
    rs = S[::-1]
    r7 = "dreamer"[::-1]
    r6 = "eraser"[::-1]
    r5_1 = "dream"[::-1]
    r5_2 = "erase"[::-1]

    while idx < l:
        if rs[idx:idx + 7] == r7:
            idx += 7
        elif rs[idx:idx + 6] == r6:
            idx += 6
        elif rs[idx:idx + 5] == r5_1 or \
                rs[idx:idx + 5] == r5_2:
            idx += 5
        else:
            ok = False
            break

    if ok:
        print("YES")
    else:
        print("NO")


def RE(S):
    l = len(S)
    if _dfs(S, l, 0):
        print("YES")
    else:
        print("NO")


def _dfs(S, l, idx, pattern=0):
    # print(l, idx, pattern)
    if idx == l:
        return True

    if S[idx:idx + 7] == "dreamer":
        ok = _dfs(S, l, idx + 7, 1)
        if ok:
            return True
    if S[idx:idx + 6] == "eraser":
        ok = _dfs(S, l, idx + 6, 2)
        if ok:
            return True
    if S[idx:idx + 5] == "dream" or \
            S[idx:idx + 5] == "erase":
        ok = _dfs(S, l, idx + 5, 3)
        if ok:
            return True

    return False


def WA(S):
    l = len(S)
    idx = 0
    ok = True
    while idx < l:
        if S[idx:idx + 7] == "dreamer":
            idx += 7
        elif S[idx:idx + 6] == "eraser":
            idx += 6
        elif S[idx:idx + 5] == "dream" or \
                S[idx:idx + 5] == "erase":
            # 評価順番注意
            idx += 5
        else:
            ok = False
            break

    if ok:
        print("YES")
    else:
        print("NO")

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main(): 
    """
    カレンダーらしいもの: 7列…
    """
    n, k = map(int, input().split())

    part1(n, k)


def part1(n, k):
    ans = 0

    for i in range(1, n-3+2):
        for j in range(1, 5+1):
            s = 0
            for y in range(3):
                for x in range(3):
                    s += 7*(i+y) + (j+x) - 7
            # print(i, j, s, sep="\t")
            if s % 11 == k:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    """
    カレンダーらしいもの: 7列…

    3x3の和: 2列目x3
    2列目の平均: (2,2)
    より,(2,2)*9

    11で割った余り
    9............13
    16...........20
    ...

    9,10,0,1,2
    5,6, 7,8,9

    [以下、解説の(自分用の)補完]
    9x ≡  k mod 11
     x ≡ 5k mod 11 ?

    わからんーとTweetしたら, 引用で解説されてた(感謝)
    1. https://twitter.com/hogeover30/status/995618880830636032
    2. https://mathtrain.jp/mod

        45x     ≡ 5k mod 11 (両辺等倍しても剰余は変わらない, 性質3)
        44x + x ≡ 5k mod 11 (求めたいxと 11で割り切れる倍数に分解, 性質1)
              x ≡ 5k mod 11

    範囲の変更
        7i + j - 7 (2<=i<=n-1, 2<=j<=6)
        7i + j + 9 (0<=i<=n-3, 0<=j<=4)
            7*2 + 1*2 = 16
            16 - 7 = 9

    7i に着目(入力例4, n=100, k=8)
        j=0: 7i+9  ≡ 5k ≡ 40 (mod 11) => 7i ≡ 9 (mod 11) ※1
        j=1: 7i+10 ≡ 5k ≡ 40 (mod 11) => 7i ≡ 8 (mod 11) ※2
            ※1: 40-9 (31) mod 11 = 9 より (性質2)
            ※2: 40-10(30) mod 11 = 8 より

            i={6,17,28,39,50,61,72,83,94}
            i={9,20,31,42,53,64,75,86,97}

    j固定: i = 11q + r
        1: r=6
        2: r=9
    結局、規則はなんとなく分かるが証明しろと言われると説明できない
    """
    n, k = map(int, input().split())

    # part1(n, k)
    # f2(n, k)
    editorial(n, k)


def f2(n, k):
    """規則をなんとなく見つけた場合
    """
    table = []
    for i in range(2, 2+11):
        table.append(
            [(7*i + j - 7) * 9 % 11 for j in range(2, 6+1)]
        )

    # 最初と最後の1行ずつ不要
    n -= 2
    # 11ごとに1つ解が存在し5列分
    ans = n // 11 * 5
    # 余った行ごとに残りの判定
    x = n % 11
    for i in range(x):
        for j in range(5):
            if table[i][j] == k:
                ans += 1

    print(ans)


def editorial(n, k):
    ans = 0
    # 列ごと: 2行目2-6列目
    for j in range(2, 6+1):
        rownum = 0
        for i in range(2, n):
            s = (i * 7 + j - 7) * 9
            if s % 11 == k:
                rownum = i
                break

        if rownum == 0:
            continue

        # 11行ごとに余りkになるため、見つかった基準の分の+1
        # 最後の1行不要, rownumずらしておく
        ans += 1
        ans += (n - 1 - rownum) // 11

    print(ans)


def part1(n, k):
    ans = 0

    for i in range(1, n-3+2):
        for j in range(1, 5+1):
            s = 0
            for y in range(3):
                for x in range(3):
                    s += 7*(i+y) + (j+x) - 7
            # print(i, j, s, sep="\t")
            if s % 11 == k:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    X = input()

    ans = part(X)
    print(ans)


def test_ans():
    X_ans = [
        ("TSTTSS", 4),
        ("SSTTST", 0),
        ("TSSTTTSS", 4),
    ]
    for X, ans in X_ans:
        assert part(X) == editorial(X) == ans


def editorial(X):
    stack = [X[0]]
    ans = len(X)
    for c in X[1:]:
        if stack and stack[-1] == "S" and c == "T":
            ans -= 2
            stack.pop()
        else:
            stack.append(c)

    return ans


def part(X):
    while True:
        n = len(X)
        for i in range(n-1):
            if X[i:i+2] == "ST":
                X = X[:i] + X[i+2:]
                break

        if n == len(X):
            break

    return len(X)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    X = input()

    #ans = part(X)
    ans = editorial(X)
    print(ans)


def test_ans():
    X_ans = [
        ("TSTTSS", 4),
        ("SSTTST", 0),
        ("TSSTTTSS", 4),
    ]
    for X, ans in X_ans:
        assert part(X) == editorial(X) == ans


def editorial(X):
    stack = [X[0]]
    ans = len(X)
    for c in X[1:]:
        if stack and stack[-1] == "S" and c == "T":
            ans -= 2
            stack.pop()
        else:
            stack.append(c)

    return ans


def part(X):
    while True:
        n = len(X)
        for i in range(n-1):
            if X[i:i+2] == "ST":
                X = X[:i] + X[i+2:]
                break

        if n == len(X):
            break

    return len(X)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    X = input()

    ans = part(X)
    print(ans)


def part(X):
    while True:
        n = len(X)
        for i in range(n-1):
            if X[i:i+2] == "ST":
                X = X[:i] + X[i+2:]
                break

        if n == len(X):
            break

    return len(X)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    X = input()

    #ans = part(X)
    ans = editorial(X)
    print(ans)


def test_ans():
    X_ans = [
        ("TSTTSS", 4),
        ("SSTTST", 0),
        ("TSSTTTSS", 4),
    ]
    for X, ans in X_ans:
        assert part(X) == editorial(X) == ans


def editorial(X):
    stack = [X[0]]
    ans = len(X)
    for c in X[1:]:
        if stack and stack[-1] == "S" and c == "T":
            ans -= 2
            stack.pop()
        else:
            stack.append(c)

    return ans


def part(X):
    while True:
        n = len(X)
        for i in range(n-1):
            if X[i:i+2] == "ST":
                X = X[:i] + X[i+2:]
                break

        if n == len(X):
            break

    return len(X)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
#-*- coding: utf-8 -*-

from collections import defaultdict
from math import factorial as f
from fractions import gcd as g

n, m = [int (i) for i in raw_input ().split ()]
s = raw_input ()
t = raw_input ()
L = n * m / g (n, m)
l = [''] * (L + 5)
cnt = 0
ok = True
for i in range (n):
    l [i * L / n] = s [i]
for i in range (m):
    ok &= (l [i * L / m] == '' or l [i * L / m] == t [i])
    l [i * L / m] = t [i]
if not ok: L = -1
print L


Fixed submission:
#!/usr/bin/env python
#-*- coding: utf-8 -*-

from collections import defaultdict
from math import factorial as f
from fractions import gcd as g

n, m = [int (i) for i in raw_input ().split ()]
s = raw_input ()
t = raw_input ()
L = n * m / g (n, m)
d = defaultdict (str)
cnt = 0
ok = True
for i in range (n):
    d [i * L / n] = s [i]
for i in range (m):
    ok &= (d [i * L / m] == '' or d [i * L / m] == t [i])
    d [i * L / m] = t [i]
if not ok: L = -1
print L

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
#-*- coding: utf-8 -*-

from collections import defaultdict
from math import factorial as f
from fractions import gcd as g

n, m = [int (i) for i in raw_input ().split ()]
s = raw_input ()
t = raw_input ()
L = n * m / g (n, m)
l = [''] * (n * m + 5)
cnt = 0
ok = True
for i in range (n):
    l [i * L / n] = s [i]
for i in range (m):
    ok &= (l [i * L / m] == '' or l [i * L / m] == t [i])
    l [i * L / m] = t [i]
if not ok: L = -1
print L


Fixed submission:
#!/usr/bin/env python
#-*- coding: utf-8 -*-

from collections import defaultdict
from math import factorial as f
from fractions import gcd as g

n, m = [int (i) for i in raw_input ().split ()]
s = raw_input ()
t = raw_input ()
L = n * m / g (n, m)
d = defaultdict (str)
cnt = 0
ok = True
for i in range (n):
    d [i * L / n] = s [i]
for i in range (m):
    ok &= (d [i * L / m] == '' or d [i * L / m] == t [i])
    d [i * L / m] = t [i]
if not ok: L = -1
print L

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
#-*- coding: utf-8 -*-

from collections import defaultdict
from math import factorial as f
from fractions import gcd as g

n, m = [int (i) for i in raw_input ().split ()]
s = raw_input ()
t = raw_input ()
L = n * m / g (n, m)
l = [''] * L
cnt = 0
ok = True
for i in range (n):
    l [i * L / n] = s [i]
for i in range (m):
    ok &= (l [i * L / m] == '' or l [i * L / m] == t [i])
    l [i * L / m] = t [i]
if not ok: L = -1
print L


Fixed submission:
#!/usr/bin/env python
#-*- coding: utf-8 -*-

from collections import defaultdict
from math import factorial as f
from fractions import gcd as g

n, m = [int (i) for i in raw_input ().split ()]
s = raw_input ()
t = raw_input ()
L = n * m / g (n, m)
d = defaultdict (str)
cnt = 0
ok = True
for i in range (n):
    d [i * L / n] = s [i]
for i in range (m):
    ok &= (d [i * L / m] == '' or d [i * L / m] == t [i])
    d [i * L / m] = t [i]
if not ok: L = -1
print L
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
a, b = map(int, input().split())
A = [0] * a
A = np.array(A)

for i in range(b):
    c, d = map(int , input().split())
    A[c-1 : d]  += 1

print(np.sum(A == b))



Fixed submission:
a, b = map(int, input().split())

maxf = 1
minf = a

for i in range(b):
    c, d = map(int, input().split())
    if(maxf < c):
        maxf = c
    if(minf > d):
        minf = d

if(minf-maxf < 0):
    print(0)
else:
    print(minf -maxf + 1)
Buggy python submission (verdict: Runtime Error):
import functools
import math

values = [290021904, 927964716, 826824516, 817140688]
gcd = functools.reduce(math.gcd, values)
print(gcd)

Fixed submission:
n = input()

if(n == 'A'):
    print('T')
elif(n == 'T'):
    print('A')
elif(n == 'C'):
    print("G")
elif(n == 'G'):
    print('C')
Buggy python submission (verdict: Time Limit Exceeded):
a, b = map(int, input().split())

A = []
B = []
for i in range(a):
    c, d = map(int, input().split())
    A.append(c)
    B.append(d)

ans = 0

for i in range(a*b + 1):
    j = A.index(min(A))
    if(b - B[j] >=0):
        ans += A[j] * B[j]
        b -= B[j]
        A[j] = 1000000
    else:
        ans += A[j] * b
        b = 0
    if(b == 0):
        break
    
print(ans)

Fixed submission:
a, b = map(int, input().split())

A = []

for i in range(a):
    c= list(map(int, input().split()))
    A.append(c)

ans = 0

A.sort(key=lambda x:x[0])


for j in range(a+1):
    if(b - A[j][1] >=0):
        ans += A[j][0] * A[j][1]
        b -= A[j][1]
    else:
        ans += A[j][0] * b
        b = 0
    if(b == 0):
        break
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
a, b = map(int, input().split())

A = []
B = []
for i in range(a):
    c, d = map(int, input().split())
    A.append(c)
    B.append(d)

ans = 0

for i in range(a*b + 1):
    j = A.index(min(A))
    ans += A[j]
    B[j] -= 1
    b -= 1
    if(b == 0):
        print(ans)
        break
    if(B[j] == 0):
        A[j] = 1000000


Fixed submission:
a, b = map(int, input().split())

A = []

for i in range(a):
    c= list(map(int, input().split()))
    A.append(c)

ans = 0

A.sort(key=lambda x:x[0])


for j in range(a+1):
    if(b - A[j][1] >=0):
        ans += A[j][0] * A[j][1]
        b -= A[j][1]
    else:
        ans += A[j][0] * b
        b = 0
    if(b == 0):
        break
    
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
a, b = map(int, input().split())

A = list(input().split())
B = []
ans = abs(int(A[0])-b)
for i in A:
    aa = abs(int(i) - b)
    ans = math.gcd(ans, aa)

print(ans)

Fixed submission:
a, b = map(int, input().split())


def gcd(x, y):
    if(y == 0):
        return x
    else:
        return gcd(y, x%y)

A = list(input().split())
B = []
ans = abs(int(A[0])-b)
for i in A:
    aa = abs(int(i) - b)
    ans = gcd(ans, aa)

print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())

X = list(input().split())
X.append(1000000)
ans = 0

for i in range(1, n):
    if(X[i-1] == X[i]):
        ans+=1
        X[i] = X[i-1] + X[i+1]
print(ans)

Fixed submission:
n = int(input())

X = list(map(int, input().split()))
X.append(1000000)
ans = 0

for i in range(1, n):
    if(X[i-1] == X[i]):
        ans+=1
        X[i] = X[i-1] + X[i+1]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
S = list(input())
min = n+1
for i in range(0, n):
    ans = S[:i].count('W')
    ans2 = S[i:].count('E')
    answer = ans + ans2
    if(answer < min):
        min = answer
print(min)

Fixed submission:
n = int(input())
S = input()
w_num = S.count('W')
e_num = S.count('E')
a = 0
b = e_num
amin = n+1
if(len(set(S)) == 1):
    print(0)
else:
    for i in S:
        if(i == 'E'):
            b -= 1
        else:
            a+=1
        if(a+b < amin):
            amin = a+b
    print(min(amin, w_num, e_num))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = []
X = list(map(int, input().split()))
for i in range(n):
    a = X[i]
    s.append(a)
    s.reverse()
for i in s:
    print(i, end = '')
    if(i!= n - 1):
        print(' ', end='')
print()

Fixed submission:
n = int(input())
s = ''
X = list(map(int, input().split()))
if(len(X) % 2 == 0):
    for i in range(0, n, 2):
        s += str(X[n - 1 - i])
        s += ' '
    for i in range(0, n, 2):
        s += str(X[i])
        s += ' '
else:
    for i in range(0, n, 2):
        s += str(X[n - i - 1])
        s += ' '
    for i in range(1, n, 2):
        s += str(X[i])
        s += ' '
print(s[:-1])
Buggy python submission (verdict: Runtime Error):
n=int(input())
xu=dict(map(str,input().split()) for i in range(n) )
s=[]
b=[]
for key,val in xu.items():
    if val=="JPY":
        s.append(float(key))
    else:
        b.append(float(key))
print(sum(s)+(sum(b)*380000.0))n=int(input())

Fixed submission:
n=int(input())
ans=0
rate=380000.0
for i in range(n):
    x,u=input().split()
    x=float(x)
    ans+=x*rate if u=="BTC" else x
print(ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
xu=dict(map(str,input().split()) for i in range(n) )
s=[]
b=[]
for key,val in xu.items():
    if val=="JPY":
        s.append(float(key))
    else:
        b.append(float(key))
print(sum(s)+(sum(b)*380000))n=int(input())
xu=dict(map(str,input().split()) for i in range(n) )
s=[]
b=[]
for key,val in xu.items():
    if val=="JPY":
        s.append(int(key))
    else:
        b.append(float(key))
print(sum(s)+(sum(b)*380000.0))

Fixed submission:
n=int(input())
ans=0
rate=380000.0
for i in range(n):
    x,u=input().split()
    x=float(x)
    ans+=x*rate if u=="BTC" else x
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
h=[int(input()) for i in range(n)]
h.sort()
ans=[h[k+i]-h[i] for i in range(n-k+1)]
print(min(ans))

Fixed submission:
n,k=map(int,input().split())
h=[int(input()) for i in range(n)]
h.sort()

print(min(h[i+k-1] - h[i] for i in range(n-k+1)))

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
h=[int(input()) for i in range(n)]
h.sort()
def get_(h,k):
    for i in range(n-k+1):
        yield h[i:k+i]
a=list(get_(h,k))
ans=min(map(lambda x:max(x)-min(x),a))
print(ans)

Fixed submission:
n,k=map(int,input().split())
h=[int(input()) for i in range(n)]
h.sort()

print(min(h[i+k-1] - h[i] for i in range(n-k+1)))

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
h=[int(input()) for i in range(n)]
h.sort()
def get_(h,k):
    for i in range(n-k+1):
        yield h[i:k+i]
a=list(get_(h,k))
ans=10**9+1
for i in a:
    if max(i)-min(i)<ans:
        ans=max(i)-min(i)
print(ans)

Fixed submission:
n,k=map(int,input().split())
h=[int(input()) for i in range(n)]
h.sort()

print(min(h[i+k-1] - h[i] for i in range(n-k+1)))
Buggy python submission (verdict: Runtime Error):
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
if a>=0:
    h=list(map(lambda x:abs(t-x*0.006-a),h))
else:
    h=list(map(lambda x:t-x*0.006-a),h)

print(h.index(min(h))+1)

Fixed submission:
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
h=list(map(lambda x:t-x*0.006,h))
tmp=[abs(i-a) for i in h]
print(tmp.index(min(tmp))+1)
Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)

n,x=map(int,input().split())
x_lst=list(map(int,input().split()))
x_lst=list(map(lambda a:abs(a-x),x_lst))
print(gcd_list(x_lst))

Fixed submission:
import fractions
from functools import reduce
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

n,x=map(int,input().split())
x_lst=list(map(int,input().split()))
x_lst=list(map(lambda a:abs(a-x),x_lst))
print(gcd_list(x_lst))