Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02946 (python)

Fixed submission:
k, x = map(int, input().split())
ans = [x]
for i in range(1, k):
    ans.append(x - i)
    ans.append(x + i)
print(*sorted(ans))

Buggy submission (verdict: Runtime Error):
k, x = map(int, input().split())
ans = [i - 1 for i in range(1, k)]
cache = [i + 1 for i in range(1, k)]
print(*sorted((ans + cache).append(x)))
Problem p02958 (python)

Fixed submission:
n = input()
n = int(n)
ps = list(map(int, input().split()))
pp = sorted(ps)
remaind = 2
pt = False
for s,p in zip(ps,pp):
    if s != p:
        remaind -= 1

if remaind >= 0:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
n = int(input())
ps = map(int, input().split())
p2 = ps[0] - 1
for p in ps:
    if p > p2:
        p2 = p

    else:
        print("NO")
if p2 == p[-1]:
    print("YES")
Problem p02969 (python)

Fixed submission:
r = input()
print(int(r)**2 * 3)

Buggy submission (verdict: Runtime Error):
n = int(input())
nums = []
for i in range(n):
  nums.append(int(input()))
cache = sorted(nums)
maximum = nums[0]
second = nums[1]
if maximum == second:
  flag = True
else:
  flag = False
for i in nums:
  if i == maximum && !flag:
    print(second)
  else:
    print(maximum)

Buggy submission (verdict: Runtime Error):
n = int(input())
nums = []
for i in range(n):
    nums.insert(i,int(input()))
for i in range(n):
    print(max(max(nums[0:i],nums[i+1:n+1])))
Problem p03035 (python)

Fixed submission:
a, b = map(int, input().split())
if a <= 5:
    ans = 0
elif a <= 12:
    ans = b // 2
else:
    ans = b
print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
ans = 0
b = []
while m != 0:
    l, r = map(int, input().split())
    if not b:
        for a in range(1, n + 1):
            c = a
            print(b)
            while True:
                if a >= l:
                    if a <= r:
                        b.append(c)
                        break
                    else:
                        break
                else:
                    break
    elif m != 1:
        for a in b:
            print(b)
            c = a
            while True:
                if a >= l:
                    if a <= r:
                        ans += 1
                        break
                    else:
                        b.remove(c)
                        break
                else:
                    b.remove(c)
                    break
    else:
        for a in b:
            print(b)
            c = a
            while True:
                if a == n:
                    ans += 1
                    break
                if a >= l:
                    if a <= r:
                        a += 1
                    else:
                        break
                else:
                    break
    m -= 1

print(ans)
Problem p03067 (python)

Fixed submission:
a, b, c = map(int, input().split())
if b > a:
    if b > c and a < c:
        print("Yes")
    else:
        print("No")
elif a > b:
    if a > c and b < c:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
k = int(input())
sa = s[k: k + 1]
sl = len(s)
sli = list(s)
hey = []
for sli in sli:
    if sli == sa:
        hey.append(sli)
    else:
        hey.append("*")
hey = "".join(hey)
print(hey)
Problem p03076 (python)

Fixed submission:
import math
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
if a >= 100:
    a1 = a % 10
else:
    a2 = a - 100
    a1 = a2 % 10
if b >= 100:
    b1 = b % 10
else:
    b2 = b - 100
    b1 = b2 % 10
if c >= 100:
    c1 = c % 10
else:
    c2 = c - 100
    c1 = c2 % 10
if d >= 100:
    d1 = d % 10
else:
    d2 = d - 100
    d1 = d2 % 10
if e >= 100:
    e1 = e % 10
else:
    e2 = e - 100
    e1 = e2 % 10
if a1 == 0:
    a1 = 9
if b1 == 0:
    b1 = 9
if c1 == 0:
    c1 = 9
if d1 == 0:
    a1 = 9
if e1 == 0:
    e1 = 9
lis = [a1,b1,c1,d1,e1]
if a1 == min(lis) :
    answer = math.ceil(b / 10) * 10 + math.ceil(c/ 10) * 10 + math.ceil(e/ 10)* 10+ math.ceil(d/ 10) * 10 + a
if b1 == min(lis):
    answer = math.ceil(a/ 10)* 10 + math.ceil(c/ 10)* 10 + math.ceil(e/ 10)* 10 + math.ceil(d/ 10)* 10 + b
if c1 == min(lis):
    answer = math.ceil(b/ 10)* 10 + math.ceil(a/ 10)* 10 + math.ceil(e/ 10)* 10 + math.ceil(d/ 10)* 10 + c
if d1 == min(lis):
    answer = math.ceil(b/ 10)* 10 + math.ceil(c/ 10)* 10 + math.ceil(e/ 10)* 10 + math.ceil(a/ 10)* 10 + d
if e1 == min(lis):
    answer = math.ceil(b/ 10)* 10 + math.ceil(c/ 10)* 10 + math.ceil(a/ 10)* 10 + math.ceil(d/ 10)* 10 + e
print(answer)

Buggy submission (verdict: Runtime Error):
import math
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
if a >= 100:
    a1 = a % 10
else:
    a2 = a - 100
    a1 = a2 % 10
if b >= 100:
    b1 = b % 10
else:
    b2 = b - 100
    b1 = b2 % 10
if c >= 100:
    c1 = c % 10
else:
    c2 = c - 100
    c1 = c2 % 10
if d >= 100:
    d1 = d % 10
else:
    d2 = d - 100
    d1 = d2 % 10
if e >= 100:
    e1 = e % 10
else:
    e2 = e - 100
    e1 = e2 % 10
if a1 == 0:
    a1 = 9
if b1 == 0:
    b1 = 9
if c1 == 0:
    c1 = 9
if d1 == 0:
    a1 = 9
if e1 == 0:
    e1 = 9
lis = [a1,b1,c1,d1,e1]
if a1 == min(lis) :
    answer = math.ceil(b / 10) * 10 + math.ceil(c/ 10) * 10 + math.ceil(e/ 10* 10+ math.ceil(d/ 10 * 10 + a
if b1 == min(lis):
    answer = math.ceil(a/ 10)* 10 + math.ceil(c/ 10)* 10 + math.ceil(e/ 10)* 10 + math.ceil(d/ 10)* 10 + b
if c1 == min(lis):
    answer = math.ceil(b/ 10)* 10 + math.ceil(a/ 10)* 10 + math.ceil(e/ 10)* 10 + math.ceil(d/ 10)* 10 + c
if d1 == min(lis):
    answer = math.ceil(b/ 10)* 10 + math.ceil(c/ 10)* 10 + math.ceil(e/ 10)* 10 + math.ceil(a/ 10)* 10 + d
if e1 == min(lis):
    answer = math.ceil(b/ 10)* 10 + math.ceil(c/ 10)* 10 + math.ceil(e/ 10)* 10 + math.ceil(a/ 10)* 10 + e
print(answer)
Problem p03105 (python)

Fixed submission:
import math
a, b, c = map(int, input().split())
D = b / a
if a > b:
    print(0)
elif D == c:
    print(c)
elif D > c:
    if c > D:
        print(math.floor(D))
    else:
        print(c)
else:
    print(math.floor(D))

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
flag = True
count = 0
while flag:
  if c <= count || b - a < 0:
    break
  b -= a
  count += 1
print(count)
Problem p03308 (python)

Fixed submission:
_ = int(input())
nums = list(map(int, input().split()))
max_n = 0
min_n = 100000000000000000000000
for i in nums:
	if max_n < i:
		max_n = i
	if min_n > i:
		min_n =i
print(max_n - min_n)

Buggy submission (verdict: Runtime Error):
_ = int(input())
nums = list(map(int, input().split())
max_n = 0
min_n = 0
for i in nums:
	if max_n < i:
        max_n = i
    if min_n > i:
        min_n =i
print(max_n - min_n)
Problem p03386 (python)

Fixed submission:
a, b, k = map(int, input().split())
for i in range(a, a + k):
    if i > b:
        break
    print(i)
for i in range(b - k + 1, b + 1):
    if i < a + k:
        continue
    if i > b:
        break
    print(i)

Buggy submission (verdict: Runtime Error):
	a, b, k = map(int, input().split())
for i in range(a, a + k):
    if i > b:
        break
    print(i)
for i in range(b - k + 1, b + 1):
    if i < a + k:
        continue
    if i > b:
        break
    print(i)
Problem p02747 (python)

Fixed submission:
s = input()
for i in range(len(s)):
  if i & 1 == 0:
    if s[i] != 'h':
      break
  else:
    if s[i] != 'i':
      break
else:
  if len(s) & 1 == 0:
    print('Yes')
    exit()
print('No')

Buggy submission (verdict: Runtime Error):
s = input()
for i in range(len(s)):
  if i & 1 == 0:
    if s[i] != 'h':
      break
  else:
    if s[i] != 'i':
      break
else:
  if len(s) & 1 == 0:
    print('Yes')
  	exit()
print('No')
Problem p02748 (python)

Fixed submission:
A, B, M = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

ans = min(a) + min(b)

for i in range(M):
  x, y, c = map(int, input().split())
  val = a[x-1] + b[y-1] - c
  ans = min(ans, val)
print(ans)

Buggy submission (verdict: Runtime Error):
A, B, M = map(int, input().split())
a = [int(i) for i in input().split]
b = [int(i) for i in input().split]

ans = min(a) + min(b)

for i in range(M):
  x, y, c = map(int, input().split())
  val = a[x-1] + b[y-1] - c
  ans = min(ans, val)
print(ans)

Buggy submission (verdict: Runtime Error):
A, B, M = map(int, input().split())
a = [int(i) for i in input().split]
b = [int(i) for i in input().split]

ans = min(a) + min(b)

for i in range(m):
  x, y, c = map(int, input().split())
  val = a[x-1] + b[y-1] - c
  ans = min(ans, val)
print(ans)
Problem p02755 (python)

Fixed submission:
import math

a, b = map(int, input().split())

for i in range(b+1,1001):
    if math.floor(i * 0.08) == a and math.floor(i * 0.1) == b:
        ans = i
        break
else:
    ans = -1
print(ans)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
if b * 10 <= ((a  * 25 + 24) // 2 and -(-a * 25 // 2) < (b + 1) * 10:
    print(max(-(-a*25//2), b * 10))
else:
    print(-1)
Problem p02903 (python)

Fixed submission:
h,w,a,b = map(int,input().split())
s = [['0' for i in range(w)] for j in range(h)]
for i in range(h):
    for j in range(w):
        if (i < b and j >= a) or (i >= b and j < a):
            s[i][j] = '1'
    print(''.join(map(str,s[i])))

Buggy submission (verdict: Runtime Error):
h,w,a,b = map(int,input().split())
s = [['0' for i in range(w)] for j in range(h)]
if (2*a > w and b != 0) or (2*b > h and a != 0):
    print('No')
    exit(0)
else:
    for i in range(h):
        cnt = i*a
        for _ in range(a):
            if cnt > w:
                cnt = 0
            s[i][cnt] = '1'
            cnt += 1
        print(''.join(map(str,s[i])))
Problem p02995 (python)

Fixed submission:
a,b,c,d = map(int,input().split())
ans = b - a + 1
x = c * d
e = c
f = d
if e < f:
    e = f
    f = c
r = e % f
while r != 0:
    e = f
    f = r
    r = e % f
x //= f
ans -= b // c - (a-1) // c + b // d - (a-1) // d
ans += b // x - (a-1) // x
print(ans)

Buggy submission (verdict: Runtime Error):
import fraction
a,b,c,d = map(int,input().split())
lcm = c*d // fraction.gcd(c,d)
A = ((a-1) // c) + ((a-1) // d) - ((a-1) // lcm)
B = (b // c) + (b // d) - (b // lcm)
total = B - A
print(b - a + 1 - total)

Buggy submission (verdict: Runtime Error):
import math
a,b,c,d = map(int,input().split())
lcm = c*d // math.gcd(c,d)
A = ((a-1) // c) + ((a-1) // d) - ((a-1) // lcm)
B = (b // c) + (b // d) - (b // lcm)
total = B - A
print(b - a + 1 - total)
Problem p03061 (python)

Fixed submission:
from fractions import gcd

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

l = [0]*(n+1)
r = [0]*(n+1)

for i in range(n):
    l[i+1] = gcd(l[i], a[i])
    r[n-i-1] = gcd(r[n-i], a[n-i-1])

m = [0]*n

for i in range(n):
    m[i] = gcd(l[i], r[i+1])

print(max(m))

Buggy submission (verdict: Runtime Error):
from math import gcd

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

l = [0]*(n+1)
r = [0]*(n+1)

for i in range(n):
    l[i+1] = gcd(l[i], a[i])
    r[n-i-1] = gcd(r[n-i], a[n-i-1])

m = [0]*n

for i in range(n):
    m[i] = gcd(l[i], r[i+1])

print(max(m))
Problem p03076 (python)

Fixed submission:
n = [input() for i in range(5)]
flag = 1
ans = 0
l = []
while flag:
    flag = 0
    for i in range(len(n)-1,0,-1):
        if n[i][-1] < n[i-1][-1]:
            n[i],n[i-1] = n[i-1],n[i]
            flag = 1
for i in range(len(n)):
    if n[i][-1] != '0':
        n[i] = int(n[i])
        l = n.pop(i)
        break
for i in range(len(n)):
    n[i] = int(n[i])
for i in range(len(n)):
    while n[i]%10 != 0:
        n[i] += 1
    ans += n[i]
if l:
    ans += l
print(ans)

Buggy submission (verdict: Runtime Error):
n = [input() for i in range(5)]
flag = 1
ans = 0
while flag:
    flag = 0
    for i in range(len(n)-1,0,-1):
        if n[i][-1] < n[i-1][-1]:
            n[i],n[i-1] = n[i-1],n[i]
            flag = 1
for i in range(len(n)):
    if n[i][-1] != '0':
        n[i] = int(n[i])
        l = n.pop(i)
        break
for i in range(len(n)):
    n[i] = int(n[i])
for i in range(len(n)):
    while n[i]%10 != 0:
        n[i] += 1
    ans += n[i]
ans += l
print(ans)
Problem p03220 (python)

Fixed submission:
n = int(input())
t,a = map(int,input().split())
h = list(map(int,input().split()))
deg = 11451419
for i in range(n):
  if deg > abs(a - (t - h[i]*0.006)):
    deg = abs(a - (t - h[i]*0.006))
    ans = i+1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
t,a = map(int(input().split()))
h = list(map(int,input().split()))
deg = 11451419
for i in range(n):
  if deg > abs(a - h[i]*0.006):
    deg = abs(a - h[i]*0.006)
    ans = i+1
print(ans)
Problem p03239 (python)

Fixed submission:
N,T = map(int,input().split())
c = []
t = []
for i in range(N):
    c1,t1 = [int(i) for i in input().split()]
    c.append(c1)
    t.append(t1)
ans = 10000
for i in range(N):
  if t[i] <= T:
    ans = min(ans,c[i])
if ans == 10000:
  print('TLE')
else:
  print(ans)

Buggy submission (verdict: Runtime Error):
N,T = map(int,input().split())
c = []
t = []
c1,t1 = [int(i) for i in input().split()]
for i in range(N):
  c.append(n1)
  t.append(t1)
ans = 10000
for i in range(N):
  if t[i] <= T:
    ans = min(ans,c[i])
if ans == 10000:
  print('TLE')
else:
  print(ans)
Problem p03323 (python)

Fixed submission:
a,b=map(int,input().split())
if a <= 8 and b <= 8:
    print('Yay!')
else:
    print(':(')

Buggy submission (verdict: Runtime Error):
a,b = map(int,input())
if a <= 8 and b <= 8:
    print('Yay!')
else:
    print(':(')
Problem p03352 (python)

Fixed submission:
x = int(input())
ans = 1
if x < 4:
    print(1)
else:
    for i in range(2,int(x**(1/2)+1)):
        j = 2
        a = -1
        while a <= x:
            ans = max(ans,a)
            a = i**j
            j += 1
    print(ans)

Buggy submission (verdict: Runtime Error):
x = int(input())
ans = []
for i in range(1,x):
    for j in range(2,10):
        if i**j > x:
            break
        else:
            ans.append(i**j)
print(max(ans))
Problem p03486 (python)

Fixed submission:
s = input()
t = input()
min_s = sorted(s)
max_t = sorted(t, reverse=True)
if min_s < max_t:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
s = sorted(input())
t = sorted(input(), reverse=True)

for i in range(len(s)):
    if ord(s[i]) < ord(t[i]):
        print('Yes')
        exit()
    elif ord(s[i]) > ord(t[i]):
        print('No')
        exit()
if len(s) < len(t):
    print('Yes')
else:
    print('No')
Problem p03632 (python)

Fixed submission:
a,b,c,d = map(int,input().split());print(max(0, min(b,d) - max(a,c)))

Buggy submission (verdict: Runtime Error):
a,b,c,d=int(open(0));print(max(0,min(b,d)-max(a,c)))
Problem p03657 (python)

Fixed submission:
a,b = map(int,input().split())
if a % 3 == 0 or b % 3 == 0 or (a+b) % 3 == 0:
    print("Possible")
else:
    print("Impossible")

Buggy submission (verdict: Runtime Error):
a,b = map(int,input())
if a%3==0 or b%3==0 or (a+b)%3==0:
    print('Possible')
else:
    print('Impossible')
Problem p03779 (python)

Fixed submission:
x = int(input())
'''
if x == 1:
    ans = 1
elif x == 2:
    ans = 2
elif x == 3:
    ans = 2
elif x == 4:
    ans = 3
elif x == 5:
    ans = 3
elif x == 6:
    ans = 3
elif x == 7:
    ans = 4
elif x == 8:
    ans = 4
elif x == 9:
    ans = 4
elif x == 10:
    ans = 4
11から15までは5
122333444455555...の群数列
'''
for i in range(1,x+1):
    if i*(i-1)/2 < x <= i*(i+1)/2:
        ans = i
        break
print(ans)

Buggy submission (verdict: Runtime Error):
x = int(input())
'''
if x == 1:
    ans = 1
elif x == 2:
    ans = 2
elif x == 3:
    ans = 2
elif x == 4:
    ans = 3
elif x == 5:
    ans = 3
elif x == 6:
    ans = 3
elif x == 7:
    ans = 4
elif x == 8:
    ans = 4
elif x == 9:
    ans = 4
elif x == 10:
    ans = 4
11から15までは5
122333444455555...の群数列
'''
for i in range(1,x):
    if i*(i-1)/2 < x <= i*(i+1)/2:
        ans = i
        break
print(ans)
Problem p03852 (python)

Fixed submission:
c = input()
v = ['a','i','u','e','o']
if c in v:
  print('vowel')
else:
  print('consonant')

Buggy submission (verdict: Runtime Error):
c = input()
v = [a,i,u,e,o]
if c in v:
  print('vowel')
else:
  print('consonant')
Problem p02678 (python)

Fixed submission:
n,m = map(int, input().split())
d = {}
for i in range(m):
  a,b = map(int, input().split())
  if a in d:
    l = d[a]
    l.append(b)
    d[a] = l
  else:
    d[a] = [b]
  if b in d:
    l = d[b]
    l.append(a)
    d[b] = l
  else:
    d[b] = [a]
dpth = {}
dpth[1] = 0
l = [1]
ans = [0]*(n-1)
while(len(l)>0):
  l_ = []
  for i in l:
    dpth_ = dpth[i]
    for j in d[i]:
      if j not in dpth:
        ans[j-2] = i
        dpth[j] = dpth_+1
        l_.append(j)
  l = l_
print("Yes")
for i in ans:
  print(i)

Buggy submission (verdict: Runtime Error):
n,m = map(int, input().split())
d = {}
for i in range(m):
  a,b = map(int, input().split())
  if a in d:
    l = d[a]
    l.append(b)
    d[a] = l
  else:
    d[a] = [b]
  if b in d:
    l = d[b]
    l.append(a)
    d[b] = l
  else:
n,m = map(int, input().split())
d = {}
for i in range(m):
  a,b = map(int, input().split())
  if a in d:
    l = d[a]
    l.append(b)
    d[a] = l
  else:
    d[a] = [b]
  if b in d:
    l = d[b]
    l.append(a)
    d[b] = l
  else:
    d[b] = [a]
clear = [1]
ans_ = [1]
ans = [0]*(n-1)
while(0 in ans):
  for i in ans_:
    ans__ = []
    for j in d[i]:
      if j in clear:
        continue
      else:
        clear.append(j)
        ans__.append(j)
        ans[j-2] = i
  ans_ = ans__
  if len(ans_) == 0:
    break
if 0 in ans:
  print("No")
else:
  print("Yes")
  for i in ans:
    print(i)
Problem p02702 (python)

Fixed submission:
s = input()
MOD = 2019
a =[0]*MOD
a[0] = 1
c_ = 0
ans = 0
t = 1
for i in reversed(s):
  c = (c_+int(i)*t)%MOD
  a[c] += 1
  t *= 10
  t %= MOD
  c_ = c
for i in a:
  ans += i*(i-1)//2
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
s.reverse()
MOD = 2019
a =[0]*MOD
a[0] = 1
c_ = 0
ans = 0
t = 1
for i in s:
  c = (c_+int(i)*t)%MOD
  a[c] += 1
  t *= 10
  t %= MOD
  c_ = c
for i in a:
  ans += i*(i-1)//2
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
s.reverse()
MOD = 2019
b = {}
a =[0]*MOD
a[0] = 1
c_ = 0
ans = 0
t = 1
for i in s:
  c = (c_+int(i)*t)%MOD
  b[c] += 1
  t *= 10
  t %= MOD
  c_ = c
for i in a:
  ans += i*(i-1)//2
print(ans)

Buggy submission (verdict: Runtime Error):
s = list(str(input()))
b = {}
b[0] = 1
c_ = 0
ans = 0
s.reverse()
for i in s:
  c = (c_+int(i))%2019
  if c in b:
    ans += b[c]
    b[c] += 1
    ans += 
  else:
    b[c] = 1
  c_ = c
print(ans)

Buggy submission (verdict: Runtime Error):
s = list(str(input()))
b = {}
b[0] = 1
c_ = 0
s = s.reverse()
for i in s:
  c = (c_+int(i)*10**num)%2019
  if c in b:
    b[c] += 1
  else:
    b[c] = 1
  c_ = c
ans = 0
for i in b.values():
  ans += i*(i-1)//2
print(ans)
Problem p02705 (python)

Fixed submission:
r = int(input())
import math
print(math.pi*2*r)

Buggy submission (verdict: Runtime Error):
r = int(input())
inport math
print(r*2*math.pi)
Problem p02804 (python)

Fixed submission:
n,k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0

from operator import mul
from functools import reduce
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 5
fact = [1, 1]  
factinv = [1, 1]
inv = [0, 1]  

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

if k == 1:
  print(0)
else:
  for i in range(1,n):
    if n-i < k-1:
      break
    ans += a[n-i]*cmb(n-i,k-1,p)
    ans -= a[i-1]*cmb(n-i,k-1,p)
  print(ans%1000000007)

Buggy submission (verdict: Runtime Error):
n,k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0

nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

if k == 1:
  print(0)
else:
  for i in range(1,n+1):
    if n-i < k-1:
      break
    ans += a[n-i]*cmb(n-i,k-1)
    ans -= a[i-1]*cmb(n-i,k-1)
  print(ans%1000000007)

Buggy submission (verdict: Runtime Error):
n,k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0

nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

if k == 1:
  print(0)
else:
  for i in range(1,n):
    if n-i < k-1:
      break
    ans += a[n-i]*cmb(n-i,k-1)
    ans -= a[i-1]*cmb(n-i,k-1)
print(ans%1000000007)
Problem p02837 (python)

Fixed submission:
n = int(input())
x = [0]*(n)
y = [0]*(n)
for i in range(n):
  a = int(input())
  x[i] = [0]*a
  y[i] = [0]*a
  for j in range(a):
    x[i][j], y[i][j] = map(int, input().split())

A = 0
for i in range(2**n):
  flag = 0
  ans = 0
  num = list(format(i, '0{}b'.format(n)))
  for j, k in enumerate(num):
    if k == "1":
      ans += 1
      for l, m in zip(x[j], y[j]):
        if num[l-1] != "{}".format(m):
          flag = 1
          break
    if flag == 1:
      break
  if flag == 0:
  	A = max(A,ans)
print(A)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = [0]*(n+1)
y = [0]*(n+1)
for i in range(n):
  a = int(input())
  x[i+1] = [0]*a
  y[i+1] = [0]*a
  for j in range(a):
    x[i+1][j], y[i+1][j] = map(int, input().split())

t = []
l = []
ans = 0
flag = 0
f = 1
for i in range(n):
  t.append(i+1)
  t_ = [i+1]
  flag = 1
  while(flag == 1):
    flag = 0
    t__ = [z for z in t_]
    t_ = []
    for m in t__:
      for j, k in zip(x[m],y[m]):
        if k == 0:
          if j in t or j in t_:
            f = 0
            t = []
            l = []
            t_ = []
            break
          l.append(j)
        if k == 1:
          if j in l:
            f = 0
            t = []
            l = []
            t_ = []
            break
          if j not in t and j not in t_:
            t_.append(j)
            flag = 1
      if f == 0:
        flag = 0
        t_ = []
        break
    t.extend(t_)
  if f != 0:
    ans = max(ans,len(t))
  remain = list(set(range(1,n+1))-set(t)-set(l))
  if len(remain)>0:
    T = [z for z in t]
    L = [z for z in l]
    for u in remain:
      t.append(u)
      t_ = [u]
      flag = 1
      while(flag == 1):
        flag = 0
        t__ = [z for z in t_]
        t_ = []
        for m in t__:
          for j, k in zip(x[m],y[m]):
            if k == 0:
              if j in t or j in t_:
                f = 0
                t = []
                l = []
                t_ = []
                break
              l.append(j)
            if k == 1:
              if j in l:
                f = 0
                t = []
                l = []
                t_ = []
                break
              if j not in t and j not in t_:
                t_.append(j)
                flag = 1
          if f == 0:
            flag = 0
            t_ = []
            t = [z for z in T]
            l = [z for z in L]
            break
        t.extend(t_) 
      if f != 0:
        ans = max(ans,len(t))
        T = [z for z in t]
    	L = [z for z in l]
print(ans)
Problem p02947 (python)

Fixed submission:
n = int(input())
s = []
cnt = {}
ans = 0
for i in range(n):
  s_ = list(str(input()))
  s_.sort()
  s_ = "".join(s_)
  if s_ in cnt:
    ans += cnt[s_]
    cnt[s_] += 1
  else:
    cnt[s_] = 1

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = []
cnt = {}
ans = 0
for i in range(n):
  s_ = list(str(input()))
  s_.sort()
  if s_ in s:
    ans += cnt[s_]
    cnt[s_] += 1
  else:
    s.append(s_)
    cnt[s_] = 1

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
ans = 0
s = []
cnt = []
for i in range(n):
  s_ = list(str(input()))
  s_.sort()
  if s_ in s:
    cnt[s.index(s_)] += 1
  else:
    s.append(s_)
    cnt.appned(1)

print(sum(cnt))

Buggy submission (verdict: Runtime Error):
n = int(input())
s = list(ranege(n))
for i in range(n):
  s[i] = list(str(input()))
  s[i].sort()

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