Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import math

n = int(input())+1
a = int(0)
for i in range(1, n):
  for j in range(1, n):
    for k in range(1, n):
      a = a + math.gcd(i,math.gcd(j,k))
print("{}".format(a))


Fixed submission:
# -*- coding: utf-8 -*-
import math

n = int(input())+1
a = int(0)
for i in range(1, n):
  for j in range(1, n):
    b = math.gcd(i,j)
    for k in range(1, n):
      a = a + math.gcd(b,k)
print("{}".format(a))
Buggy python submission (verdict: Time Limit Exceeded):
N, K  = map(int, input().split())

m = N

while m > abs (m - K):
  m = abs (m - K)
    
print(m)


Fixed submission:
import numpy as np
N, K  = map(int, input().split())

m = np.mod(N,K)

while m > abs (m-K):
  m = abs (m-K)

print(m)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
import math

def solve(A: int, B: int):
    print( (A*B) // math.gcd(A, B))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


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

def gcd(A,B):
    while B:
        A, B = B, A % B

    return A

def solve(A: int, B: int):
    print( (A*B) // gcd(A, B))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int,input().split())

h = list(map(int,input().split()))

# i-1番目の展望台と繋がっているかどうか
r = [[0] * n for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    r[a-1][b-1] = 1
    r[b-1][a-1] = 1

cnt=0
for x, t in enumerate(r):
    if h[x] > max([i * j for (i, j) in zip(t, h)]):
        cnt += 1

print(cnt)

Fixed submission:
n, m = map(int,input().split())

h = list(map(int,input().split()))

# 各展望台について(自分が一番高い1, 高くない時0)
t = [1] * n
for i in range(m):
    a, b = map(int, input().split())

    if h[a-1] <= h[b-1]:
        t[a-1] = 0

    if h[b-1] <= h[a-1]:
        t[b-1] = 0

print(sum(t))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
data = [i for i in range(1, n)]
print(sum(data))

Fixed submission:
n = int(input())
print(int((n-1)*(1+n-1)//2))

Buggy python submission (verdict: Runtime Error):
n = int(input())
print(sum(list(range(1, n))))

Fixed submission:
n = int(input())
print(int((n-1)*(1+n-1)//2))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
data = []
for i in range(N):
    data.append(''.join(sorted(list(input()))))

cnt = 0

for i in range(N):
    for j in range(i+1, N):
        if data[i] == data[j]:
            cnt += 1

print(cnt)


Fixed submission:
N = int(input())
dic = {}
cnt = 0

for i in range(N):
    k = ''.join(sorted(list(input())))
    if k in dic:
        cnt += dic[k]
        dic[k] += 1
    else:
        dic[k] = 1

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
#-*- coding: utf-8 -*-

n, k = map(int, raw_input().split())
src = []
for i in range(n):
    src.append(map(int, raw_input().split()))
src.sort(key=lambda x:x[0]) # 0番目の要素でソート

data = []
for a, b in src:
    for i in range(b):
        data.append(a)

print data[k-1]

Fixed submission:
#-*- coding: utf-8 -*-

def get_ans():
    n, k = map(int, raw_input().split())
    src = []
    for i in range(n):
        src.append(map(int, raw_input().split()))
    src.sort(key=lambda x:x[0]) # 0番目の要素でソート

    cnt = 0
    for a, b in src:
        cnt = cnt + b
        if cnt >= k:
            return a
            break
    return src[n-1][1]

if __name__ == '__main__':
    print get_ans()

Buggy python submission (verdict: Time Limit Exceeded):
#-*- coding: utf-8 -*-

n, k = map(int, raw_input().split())

data = []

for i in range(n):
    a, b = map(int, raw_input().split())
    for j in range(b):
        data.append(a)

data.sort()
print data[k-1]

Fixed submission:
#-*- coding: utf-8 -*-

def get_ans():
    n, k = map(int, raw_input().split())
    src = []
    for i in range(n):
        src.append(map(int, raw_input().split()))
    src.sort(key=lambda x:x[0]) # 0番目の要素でソート

    cnt = 0
    for a, b in src:
        cnt = cnt + b
        if cnt >= k:
            return a
            break
    return src[n-1][1]

if __name__ == '__main__':
    print get_ans()
Buggy python submission (verdict: Time Limit Exceeded):
[n, k] = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]

l = []
c = 1
for _ in range(n):
    c = a[c - 1]
    if len(l) + 1 == k:
        print(c)
        break
    elif c in l:
        i = l.index(c)
        l2 = l[i:]
        print(l2[(k - i) % len(l2) - 1])
        break
    else:
        l.append(c)

Fixed submission:
[n, k] = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]

l = []
c = 1
l2 = [0 for _ in range(n)]
for _ in range(n):
    c = a[c - 1]
    if len(l) + 1 == k:
        print(c)
        break
    elif l2[c - 1] == 1:
        i = l.index(c)
        l2 = l[i:]
        print(l2[(k - i) % len(l2) - 1])
        break
    else:
        l.append(c)
        l2[c - 1] = 1

Buggy python submission (verdict: Time Limit Exceeded):
[n, k] = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]

l = []
c = 1
while True:
    c = a[c - 1]
    if len(l) + 1 == k:
        print(c)
        break
    elif c in l:
        i = l.index(c)
        l2 = l[i:]
        print(l2[(k - i) % len(l2) - 1])
        break
    else:
        l.append(c)

Fixed submission:
[n, k] = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]

l = []
c = 1
l2 = [0 for _ in range(n)]
for _ in range(n):
    c = a[c - 1]
    if len(l) + 1 == k:
        print(c)
        break
    elif l2[c - 1] == 1:
        i = l.index(c)
        l2 = l[i:]
        print(l2[(k - i) % len(l2) - 1])
        break
    else:
        l.append(c)
        l2[c - 1] = 1
Buggy python submission (verdict: Time Limit Exceeded):
import math

x = int(input())
for a in range(1000000000):
    b = (x - (a**5))**0.2
    if isinstance(b, float) and b.is_integer():
        print(a, int(b) * -1)
        break

Fixed submission:
x = int(input())
a = 0
while True:
    n = (a**5)-x
    s2 = -1 if n < 0 else 1
    if s2 == -1:
        n = n * -1
    b = n**0.2
    if a**5-(int(b)*s2)**5==x:
        end = 1
        print(a, int(b) * s2)
        break
    a = a+1

Buggy python submission (verdict: Runtime Error):
import math

x = int(input())
for a in range(1000000000):
    b = (x - (a**5))**0.2
    if b.is_integer():
        print(a, int(b) * -1)
        break

Fixed submission:
x = int(input())
a = 0
while True:
    n = (a**5)-x
    s2 = -1 if n < 0 else 1
    if s2 == -1:
        n = n * -1
    b = n**0.2
    if a**5-(int(b)*s2)**5==x:
        end = 1
        print(a, int(b) * s2)
        break
    a = a+1
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

r = [i for i in range(n) if s[i] == 'R']
g = [i for i in range(n) if s[i] == 'G']
b = [i for i in range(n) if s[i] == 'B']
rgb = [sorted([ri, gi, bi]) for ri in r for gi in g for bi in b]

count = 0
for [i, j, k] in rgb:
    if j - i != k - j:
        count += 1
        
print(count)

Fixed submission:
input()
s = input()

r, g, b = map(s.count, 'RGB')

print(r * g * b - sum(1 for i, c1 in enumerate(s) for j, c2 in enumerate(s[i::2]) if c1 != c2 != s[i + j] != c1))
Buggy python submission (verdict: Runtime Error):
a, b = (int(i) for i in input().split())

if a % 2 == 0 && b % 2 == 0:
  print("Yes")
else:
  print("No")


Fixed submission:
a, b = (int(i) for i in input().split())
 
if a % 2 != 0 and b % 2 != 0:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
import sys

n = int(input())
l = []
p = None

for i in range(n):
  s = input()
  if s in l && (p == None || p[-1:] == s[1:]):
    l.append(s)
    p = s
  else:
    print("No")
    sys.exit()
print("Yes")

Fixed submission:
import sys
 
n = int(input())
l = []
p = None
 
for i in range(n):
  s = input()
  if s not in l and (p == None or p[-1:] == s[:1]):
    l.append(s)
    p = s
  else:
    print("No")
    sys.exit()
print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
num = int(input())
count = num
lists = []
for i in range(num):
    x = input()
    if x in lists:
        count -= 1
    lists.append(x)

print(count)

Fixed submission:
num = int(input())
count = num
lists = []
for i in range(num):
    lists.append(input())
print(len(set(lists)))

Buggy python submission (verdict: Time Limit Exceeded):
num = int(input())
lists = []
for i in range(num):
    x = input()
    if x not in lists:
        lists.append(x)
print(len(lists))

Fixed submission:
num = int(input())
count = num
lists = []
for i in range(num):
    lists.append(input())
print(len(set(lists)))

Buggy python submission (verdict: Time Limit Exceeded):
num = int(input())
lists = []
count = 0
for i in range(num):
    x = input()
    if x not in lists:
        lists.append(x)
        count += 1
print(count)


Fixed submission:
num = int(input())
count = num
lists = []
for i in range(num):
    lists.append(input())
print(len(set(lists)))
Buggy python submission (verdict: Runtime Error):
import math
num = int(input())
lst = sorted(list(map(int, input().split())))
result = math.inf
for i in range(lst[0], lst[-1] + 1):
    tmp = 0
    for v in lst:
        tmp += (v - i) ** 2
    if tmp < result:
        result = tmp
print(result)

Fixed submission:
num = int(input())
lst = sorted(list(map(int, input().split())))
result = float('inf')
for i in range(lst[0], lst[-1] + 1):
    tmp = 0
    for v in lst:
        tmp += (v - i) ** 2
    if tmp < result:
        result = tmp
print(result)

Buggy python submission (verdict: Runtime Error):
import math
num = int(input())
lst = sorted(list(map(int, input().split())))
result = math.inf
for i in range(lst[0], lst[-1] + 1):
    tmp = 0
    for v in lst:
        tmp += (v - i) ** 2
    if tmp < result:
        result = tmp
print(result)

Fixed submission:
num = int(input())
lst = sorted(list(map(int, input().split())))
result = float('inf')
for i in range(lst[0], lst[-1] + 1):
    tmp = 0
    for v in lst:
        tmp += (v - i) ** 2
    if tmp < result:
        result = tmp
print(result)
Buggy python submission (verdict: Runtime Error):
num = int(input())
str_ls = list(input().split())

ans_ls = []
for x in str_ls:
    i = lambda x: ord(x)
    ii = int(i)
    if ii >= 90:
        ans_ls.append(i)
    else:
        ans_ls.append(i - 26)
ls = []
for y in ans_ls:
    l = lambda y : chr(y)
    ls.append(i)

ans = join(ls)
print(ans)


Fixed submission:
num = int(input())
str = input()

ans_ls = []
for x in str:
    i = ord(x) + num
    if i <= 90:
        ans_ls.append(i)
    else:
        ans_ls.append(i - 26)
ls = []
for y in ans_ls:
    l = chr(y)
    ls.append(l)

ans = ''.join(ls)
print(ans)
Buggy python submission (verdict: Runtime Error):
num = int(input())
for i in range(1, 9):
    if num / i in lst:
        print('Yes')
    else:
        print('No')


Fixed submission:
num = int(input())
lst = list(range(1, 10))
count = 0
for i in lst:
    if num / i in lst:
        count += 1
if count > 0:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())

if a > b * 2:
    print(a - b * 2)
else:
    print(0)


Fixed submission:
list = input().split()

a = int(list[0])
b = int(list[1])

if a > b * 2:
    print(a - b * 2)
else:
    print(0)

Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())

if a < b * 2:
    print(a - b * 2)
else:
    print(0)


Fixed submission:
list = input().split()

a = int(list[0])
b = int(list[1])

if a > b * 2:
    print(a - b * 2)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
number = int(input())
list = list(map(int, input().split()))
ls = sorted(list)
print(ls)
count = 0

for a in range(0, number - 2):
    num_a = ls[a]
    for b in range(a + 1, number - 1):
        num_b = ls[b]
        for c in  range(b + 1, number):
            num_c = ls[c]
            if num_a + num_b > num_c:
                count += 1

print(count)


Fixed submission:
import re
count = input()
string = input()
result = 1
for num_word in range(0, len(string) - 1):
    if string[num_word] != string[num_word + 1]:
        result += 1
print(result)
Buggy python submission (verdict: Runtime Error):
number = int(input())
if number * 2 == 0:
	odd_num = number // 2
	percent = odd_num / number
    print(percent)
else:
	odd_num = number // 2 + 1
    percent = odd_num / number
	print(percent)  


Fixed submission:
number = int(input())
if number % 2 == 0:
	odd_num = number // 2
	percent = odd_num / number
else:
	odd_num = number // 2 + 1
	percent = odd_num / number

print(percent)

Buggy python submission (verdict: Runtime Error):
number = int(input())
if number * 2 = 0:
	odd_num = number // 2
	percent = odd_num / number
    print(percent)
else:
	odd_num = number // 2 + 1
    percent = odd_num / number
	print(percent)  



Fixed submission:
number = int(input())
if number % 2 == 0:
	odd_num = number // 2
	percent = odd_num / number
else:
	odd_num = number // 2 + 1
	percent = odd_num / number

print(percent)

Buggy python submission (verdict: Runtime Error):
number = int(input())
if number * 2 = 0:
	odd_num = number // 2
	percent = odd_num / number
else:
	odd_num = number // 2 + 1
    percent = odd_num / number
  
print(percent)


Fixed submission:
number = int(input())
if number % 2 == 0:
	odd_num = number // 2
	percent = odd_num / number
else:
	odd_num = number // 2 + 1
	percent = odd_num / number

print(percent)

Buggy python submission (verdict: Runtime Error):
number = int(input())
if number * 2 = 0:
	odd_num = number // 2
	percent = odd_num / number
else:
	odd_number = number // 2 + 1
    percent = odd_num / number
  
print(percent)


Fixed submission:
number = int(input())
if number % 2 == 0:
	odd_num = number // 2
	percent = odd_num / number
else:
	odd_num = number // 2 + 1
	percent = odd_num / number

print(percent)

Buggy python submission (verdict: Runtime Error):
number = int(imput())
odd_num = number // 2 + 1
percent = odd_num / number
print(percent)

Fixed submission:
number = int(input())
if number % 2 == 0:
	odd_num = number // 2
	percent = odd_num / number
else:
	odd_num = number // 2 + 1
	percent = odd_num / number

print(percent)
Buggy python submission (verdict: Runtime Error):
N = int(input())
print(N*2*math.pi)


Fixed submission:
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""
from collections import Counter
import math
import sys
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    """a,bの最小公倍数"""
    return a * b // gcd(a, b)


def main():
    N = int(input())
    print(N*2*math.pi)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
a = [i for i in range(N+1)]
# print(a)
ans = 0
for i in range(K, N+2):
    # print(a[N-i+1:])
    # print(a[:i])
    ans += sum(a[N-i+1:]) - sum(a[:i])+1
print(ans)


Fixed submission:
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""
from collections import deque, defaultdict, Counter
import math
import sys
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    """a,bの最小公倍数"""
    return a * b // gcd(a, b)


def main():
    N, K = wi()
    mod = 10 ** 9 + 7
    s = 0
    s_1 = 0
    a = []
    b = 0
    ans = 0
    for i in range(N+1):
        b += i
        a.append(b)
    for i in range(K, N+1):
        s = a[i-1]
        s_1 = a[N]-a[N-i]
        ans += s_1-s + 1
    print(ans % mod + 1)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


#print(gcd(8, 20))
K = int(input())

ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            a = gcd(i, j)
            ans += gcd(a, k)
print(ans)



Fixed submission:
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""
import sys
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def main():
    K = si()
    ans = 0
    q = [0]*201
    for i in range(1, K+1):
        for j in range(1, K+1):
            q[gcd(i, j)] += 1

    for k in range(1, K+1):
        for i in range(1, K+1):
            ans += gcd(i, k)*q[i]

    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int, input().split())
h = list(map(int, input().split()))

h.sort()
s = []
if k == 0:
    s = h
else:
    for i in range(k):
        s = h[:-k]

print(sum(s))

Fixed submission:
n,k = map(int, input().split())
h = list(map(int, input().split()))

h.sort()
s = []
if k == 0:
    s = h
else:
    s = h[:-k]

print(sum(s))
Buggy python submission (verdict: Runtime Error):
from collections import deque
import sys
sys.setrecursionlimit(1000000)

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


n,k = map(int,input().split())
a = list(map(int, input().split()))
a = sorted(a)

ans = 0
for i in range(n-k+1):
    ans += (-a[i] + a[-1-i]) * cmb(n-1-i, k-1,mod)
    ans %= mod
print(ans)

Fixed submission:
from collections import deque
import sys
sys.setrecursionlimit(1000000)

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


n,k = map(int,input().split())
a = list(map(int, input().split()))
a = sorted(a)

ans = 0
for i in range(n-k+1):
    ans += (-a[i] + a[-1-i]) * cmb(n-1-i, k-1,mod)
    ans %= mod
print(ans)
Buggy python submission (verdict: Runtime Error):
a=[]
a = list(map(int,input().split()))
if a[1] <= a[0]:
  b=(a[0]-a[1])*a[3]+a[1]*a[2]
else:
  b=a[0]*a[2]
print(b)

Fixed submission:
a=[int(input()) for i in range(4)]
if a[0]>a[1]:
  b=(a[0]-a[1])*a[3]+a[1]*a[2]
else:
  b=a[0]*a[2]
print(b)