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

Fixed submission:
n = int(input())
li = [int(input()) for _ in range(n)]

mi = li.index(max(li))
m = max(li)

for a, b in enumerate(li):
  if a != mi:
    print(m)
  else:
    print(max(li[a+1:]+li[:a]))

Buggy submission (verdict: Runtime Error):
n = int(input())
li = [int(input()) for _ in range(n)]

mi = li.index(max(li))
m = max(li)

for a, b in enumerate(li):
  if a != mi:
    print(m)
  else:
    print(max(l[a+1:]+l[:a]))
Problem p02972 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
t=[0]*n
p=[]
g=0
for i in range(n-1,-1,-1):
    if sum(t[i::i+1])%2!=a[i]:
        t[i]=1
        p.append(i+1)
        g+=1
print(g)
print(*p[::-1])

Buggy submission (verdict: Runtime Error):
    n=int(input())
    a=list(map(int,input().split()))
    t=[0]*n
    p=[]
    g=0
    for i in range(n-1,-1,-1):
        if sum(t[i::i+1])%2!=a[i]:
            t[i]=1
            p.append(i+1)
            g+=1
    print(g)
    print(*p[::-1])
Problem p03030 (python)

Fixed submission:
n = int(input())
li = [[a+1, input().split()] for a in range(n)]
li = sorted(li, key=lambda x:(x[1][0],-1 * int(x[1][1])))
for l in li:
  print(l[0])

Buggy submission (verdict: Runtime Error):
n = int(input())
li = [list(map(input().split())) for _ in range(n)]
print(li)
Problem p02848 (python)

Fixed submission:
n = int(input())
s = input()
s = list(s)
l = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
for i in range(0,len(s)):
  for j in range (0,26):
    if s[i] == l[j]:
      s[i] = l[(j+n)%26]
      break
s = ''.join(s)
print(s)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
l = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
for i in range(0,len(s)):
  for j in range (0,26):
    if s[i] == l[j]:
      s[i] = l[(j+n)%26]
      break
print(s)
Problem p02921 (python)

Fixed submission:
l = input()
t = input()
c = 0
for i in range(0,3):
  if l[i] == t[i]:
    c = c+1
  else:
    continue

print(c)

Buggy submission (verdict: Runtime Error):
l = input()
t = input().sprit()
c = 0
for i in range(0,3):
  if l[i] == t[i]:
    c = c+1
  else:
    continue

print(c)

Buggy submission (verdict: Runtime Error):
l = list(input().sprit())
t = list(input().sprit())
c = 0
for i in range(0,2):
  if l[i] == t[i]:
    c = c+1
  else:
    continue

print(c)
Problem p02922 (python)

Fixed submission:
l = list(map(int,input().split()))
a = l[0]
b = l[1]
if b == 1:
    print(0)
else:
    if (b-1)%(a-1) == 0:
        print((b-1)//(a-1))
    else:
        print((b-1)//(a-1)+1)

Buggy submission (verdict: Runtime Error):
l = list(map(int,input().sprit()))
a = l[0]
b = l[1]
if b == 1:
    print(0)
else:
    print((b-1//a)+1)

Buggy submission (verdict: Runtime Error):
l = list(map(int,input().sprit()))
a = l[0]
b = l[1]
if b == 1:
    print(0)
else:
    print((b+1) // a+1)
Problem p02923 (python)

Fixed submission:
n = int(input())
l = list(map(int,input().split()))
i = 0
c = 0
l2 = []
while i < n-1:
    if l[i] >= l[i+1]:
        c = c+1
        i = i+1
    else :
        l2.append(c)
        c = 0
        i = i+1
l2.append(c)
print(max(l2))

Buggy submission (verdict: Runtime Error):
n = int(input())
l = list(map(int,input().split()))
i = 0
c = 0
l2 = []
while i < n-1:
    if l[i] >= l[i+1]:
        c = c+1
        i = i+1
    else :
        l2.append(c)
        c = 0
        i = i+1
print(max(l2))
Problem p02945 (python)

Fixed submission:
l = list(map(int,input().split()))
A = l[0]
B = l[1]
print(max(A+B,A-B,A*B))

Buggy submission (verdict: Runtime Error):
l = list(map(int,input().split))
A = l[0]
B = l[1]
print(max(A+B,A-B,A*B))
Problem p02946 (python)

Fixed submission:
l = list(map(int,input().split()))
k = l[0]
x = l[1]
for i in range(x-k+1,x+k):
    print(i )

Buggy submission (verdict: Runtime Error):
l = list(map(int,input().split()))
k = l[0]
x = l[1]
for i in range(x-k+1,x+k)
print(i )
Problem p02953 (python)

Fixed submission:
n = int(input())
l = list(map(int,input().split()))
l.append(1000000000)
m = 'Yes'
for i in range(0,n-1):
  if l[n-i-1] <= l[n-i]:
    continue
  elif l[n-i-1] > l[n-i] + 1:
    m = 'No'
    break
  else:
    l[n-i-1] = l[n-i-1] - 1

print(m)

Buggy submission (verdict: Runtime Error):
n = int(input())
l = list(map(int,input().split()))
l.append(10**9)
m = 'Yes'
for i in range(0,n-1)
  if l[n-i-1] <= l[n-i]:
    continue
  elif l[n-i-1] > l[n-i] + 1:
    m = 'No'
    break
  else:
    l[n-i-1] = l[n-i-1] - 1

print(m)

Buggy submission (verdict: Runtime Error):
n = int(input())
l = list(map(int,input().split()))
l.append(10**9)
m = 'Yes'
for i in range(0,n-1)
  if l[n-i-1] <= l[n-i]:
    Continue
  elif l[n-i-1] > l[n-i] + 1:
    m = 'No'
    Break
  else:
    l[n-i-1] = l[n-i-1] - 1

print(m)

Buggy submission (verdict: Runtime Error):
n = int(input())
l = list(map(int,input().split()))
l.append(10**9)
m = 'Yes'
for i in range(0,n)
  if l[n-i-1] <= l[n-i]:
    Continue
  elif l[n-i-1] > l[n-i] + 1:
    m = 'No'
    Break
  else:
    l[n-i-1] = l[n-i-1] - 1

print(m)
Problem p02969 (python)

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

Buggy submission (verdict: Runtime Error):
r = map(int,input())
print(3*r**2)

Buggy submission (verdict: Runtime Error):
r = map(int, input())
print(3 * (r ** 2))

Buggy submission (verdict: Runtime Error):
r = map(int,input())
print(3*(r**2))
Problem p02995 (python)

Fixed submission:
import fractions
a, b, c, d = map(int,input().split())
e = c*d//fractions.gcd(c,d)
l = [c,d,e]
l2 = [0,0,0]
for i in range(0,3):
    if a%l[i] == 0:
        l2[i] = b//l[i] - a//l[i] +1
    else:
        l2[i] = b//l[i] - a//l[i]
print(b-a+1 -l2[0] -l2[1] + l2[2])

Buggy submission (verdict: Runtime Error):
import math
a, b, c, d = map(int,input().split())
e = (c*d)//(math.gcd(c,d))
l = [c,d,e]
l2 = [0,0,0]
for i in range(0,3):
    if a%l[i] == 0:
        l2[i] = b//l[i] - a//l[i] +1
    else:
        l2[i] = b//l[i] - a//l[i]
print(b-a+1 -l2[0] -l2[1] + l2[2])

Buggy submission (verdict: Runtime Error):
import math
a, b, c, d = map(int,input().split())
e = c*d//math.gcd(c,d)
l = [c,d,e]
l2 = [0,0,0]
for i in range(0,3):
    if a%l[i] == 0:
        l2[i] = b//l[i] - a//l[i] +1
    else:
        l2[i] = b//l[i] - a//l[i]
print(b-a+1 -l2[0] -l2[1] + l2[2])
Problem p02996 (python)

Fixed submission:
n = int(input())
l = []
c = 0
d = 0
for _ in range(n):
    a,b = map(int,input().split())
    l.append([b,a])
l = sorted(l)


for i in range(0,n):
    if l[i][0] < d + l[i][1]:
        c = 1
        break
    else:
        d = d+ l[i][1]
        continue
if c == 0:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
n = int(input())
l = {}
lb = []
la = []
c = 0
for _ in range(n):
    a,b = map(int,input().split())
    l[b] = a
l = sorted(l.items())
for i in range(0,n):
    lb.append(l[i][0])
    la.append(l[i][1])

for i in range(0,n):
    if lb[i] < sum(la[:i+1]):
        c = 1
        break
    else:
        continue
if c == 0:
    print('Yes')
else:
    print('No')
Problem p02999 (python)

Fixed submission:
l = list(map(int, input().split()))
x = l[0]
a = l[1]
if x < a:
  print('0')
else:
  print('10')

Buggy submission (verdict: Runtime Error):
l = list(map(input().split()))
x = l[0]
a = l[1]
if x < a:
  print('0')
else:
  print('10')
Problem p03060 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = 0

for i in range(0,n):
  if a[i] > b[i]:
    c = c + a[i] - b[i]
  else:
    continue
    
print(c)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split))
b = list(map(int,input().split))
c = 0

for i in range(0,n):
  if a[i] > b[i]:
    c = c + a[i] - b[i]
  else:
    continue
    
print(c)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = []
b = []
c = 0
for _ in range(n):
  a.append(int(input()))
for _ in range(n):
  b.append(int(input()))
for i in range(0,n):
  if a[i] > b[i]:
    c = c + a[i] - b[i]
  else:
    continue
    
print(c)
Problem p04043 (python)

Fixed submission:
lis = list(map(int,input().split()))
lis.sort()
if lis == [5,5,7]:
  print('YES')
else:
  print('NO')

Buggy submission (verdict: Runtime Error):
lis = map(int,list(input().split()))
lis.sort()
if lis == [5,5,7]:
  print('YES')
else:
  print('NO')

Buggy submission (verdict: Runtime Error):
lis = list(input().split())
lis.sort()
if lis = [5,5,7]:
  print('YES')
else:
  print('NO')
Problem p02924 (python)

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

Buggy submission (verdict: Runtime Error):
n=int(intput())
print(int((n**2-n)//2))
Problem p02780 (python)

Fixed submission:
nk = list(map(int,input().split()))
p = list(map(int,input().split()))
ans = [0] * (nk[0] + nk[1])
 
zeros = [0] * nk[1]
 
seq4search = zeros + p
 
for i in range(nk[1], nk[0] + nk[1]):
    seq4search[i] = (seq4search[i] + 1) / 2
    ans[i] = ans[i-1] + seq4search[i] - seq4search[i - nk[1]] 
 
print(max(ans))

Buggy submission (verdict: Runtime Error):
nk = list(map(int,input().split()))
p = list(map(int,input().split()))
ans = [0] * (nk[0] + nk[1])
 
zeros = [0] * nk[1]
 
seq4search = zeros + p
 
for i in range(nk[1], nk[0] + nk[1]):
    seq4search[i] = (seq4search[i] + 1) / 2
    ans[i] = ans[i-1] + seq4search[i] - seq4search[i - k] 
 
print(max(ans))

Buggy submission (verdict: Runtime Error):
nk = list(map(int,input().split()))
p = list(map(int,input().split()))
ans = [0] * (nk[0] + nk[1])
 
zeros = [0] * nk[1]
 
seq4search = zeros + p
 
for i in range(nk[1] + 1, nk[0] + nk[1]):
    seq4search[i] = (seq4search[i] + 1) / 2
    ans[i] = ans[i-1] + seq4search[i] - seq4search[i - k] 
 
print(max(ans))
Problem p02783 (python)

Fixed submission:
H, A = map(int, input().split())
print((H+A-1)//A)

Buggy submission (verdict: Runtime Error):
H, A = map(int, input.split())
print((H+A-1)//A)
Problem p02802 (python)

Fixed submission:
[n,m] = [int(x) for x in input().split()]
ac=[0]*(n+1)
wa=[0]*(n+1)
cnt_ac=0
cnt_wa=0
for i in range(m):
	p,s=input().split()
	p=int(p)
	if s=="AC":
		if ac[p]==0:
			cnt_ac+=1
			cnt_wa+=wa[p]
			ac[p]=1
	else: 
		wa[p]+=1

print(int(cnt_ac),int(cnt_wa))

Buggy submission (verdict: Runtime Error):
[n,m] = [int(x) for x in input().split()]
ac=[0]*(n+1)
wa=[0]*(n+1)
cnt_ac=0
cnt_wa=0
for i in range(m):
	p,s=input().split()
	p=int(p)
	if s=="AC":
		if	fac[p]==0:
			cnt_ac+=1
			cnt_wa+=wa[p]
			ac[p]=1
		
	else: 
		wa[p]+=1

print(int(cnt_ac),int(cnt_wa))
Problem p02811 (python)

Fixed submission:
[s,t] = [int(x) for x in input().split()]
if 500*s >= t:
	print("Yes")
else:
	print("No")

Buggy submission (verdict: Runtime Error):
def lcm (a,b):
	if a<b:
		t=a
		a=b
		b=t
	x=a*b
	r=a%b
	while r!=0:
		a=b
		b=r
		r=a%b
	return x/b

[n, m]=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
i=0
a_lcm=a[0]
for i in range(n-1):
	a_lcm = lcm(a_lcm,a[i+1])

print(int(((m*2/a_lcm)+1)/2))
Problem p02848 (python)

Fixed submission:
num = int(input())
str = list(input())
alp = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
out=""
for i in range(len(str)):
	for l in range(len(alp)):
		if str[i]==alp[l]:
			out+=alp[(l+num)%26]
			break
print(out)

Buggy submission (verdict: Runtime Error):
num = int(input())
str = list(input())
alp = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
out=""
for i in range(len(str)):
	for l in range(len(alp)):
		if str[i]==alp[l]:
			out+=alp[l+num]
			break
print(out)
Problem p02900 (python)

Fixed submission:
import math
import fractions
from collections import Counter

def read():
    return int(input())

def readmap():
    return map(int, input().split())

def readlist():
    return list(map(int, input().split()))

def cf(x1,x2):
    cf=[]
    for i in range(1,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    return cf

def root_cf(x1,x2):
    cf=[]
    for i in range(1,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    return cf

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    
    return True


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


if __name__ == "__main__":
    a, b = readmap()
    g = fractions.gcd(a, b)

    c = Counter(prime_factorize(g))

    print(len(c) + 1)

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

def read():
    return int(input())

def readmap():
    return map(int, input().split())

def readlist():
    return list(map(int, input().split()))

def cf(x1,x2):
    cf=[]
    for i in range(1,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    return cf

def root_cf(x1,x2):
    cf=[]
    for i in range(1,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    return cf

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    
    return True


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


if __name__ == "__main__":
    a, b = readmap()
    g = math.gcd(a, b)

    c = Counter(prime_factorize(g))

    print(len(c) + 1)
Problem p02917 (python)

Fixed submission:
from copy import deepcopy
import itertools
from bisect import bisect_left
from bisect import bisect_right
import math
from collections import deque
from collections import Counter


def read():
    return int(input())


def readmap():
    return map(int, input().split())


def readlist():
    return list(map(int, input().split()))


INT_MAX = 10 ** 10


if __name__ == "__main__":
    N = read()
    B = [INT_MAX]
    B.extend(readlist())
    B.append(INT_MAX)

    print(sum([min(B[i], B[i-1]) for i in range(1, N+1)]))

Buggy submission (verdict: Runtime Error):
from copy import deepcopy
import itertools
from bisect import bisect_left
from bisect import bisect_right
import math
from collections import deque
from collections import Counter


def read():
    return int(input())


def readmap():
    return map(int, input().split())


def readlist():
    return list(map(int, input().split()))


if __name__ == "__main__":
    N = read()
    B = [math.inf]
    B.extend(readlist())
    B.append(math.inf)

    print(sum([min(B[i], B[i-1]) for i in range(1, N+1)]))

Buggy submission (verdict: Runtime Error):
from copy import deepcopy
import itertools
from bisect import bisect_left
from bisect import bisect_right
import math
from collections import deque
from collections import Counter


def read():
    return int(input())


def readmap():
    return map(int, input().split())


def readlist():
    return list(map(int, input().split()))


if __name__ == "__main__":
    N = read()
    B = [math.inf]
    B.extend(readlist())
    B.append(math.inf)

    print(sum([min(B[i], B[i-1]) for i in range(1, N+1)]))
Problem p03138 (python)

Fixed submission:
def read():
    return int(input())


def readlist():
    return list(map(int, input().split()))


def readmap():
    return map(int, input().split())


N, K = readmap()
A = readlist()

cnt = [0] * 50  # cnt[i] は 2^i の桁の 1 の数

for a in A:
    i = 0
    while a:
        if a % 2:
            cnt[i] += 1
        i += 1
        a = a // 2

is_zero = [False] * 50

for i in range(50):
    if 2 * cnt[i] >= N:
        is_zero[i] = True

candidate = [0]

for i in range(49):
    if 2**i <= K:
        c = 0
        for j in reversed(range(i+1)):
            if (not is_zero[j]) and c + 2 ** j <= K:
                c += 2 ** j
        candidate.append(c)

can = [sum([c ^ a for a in A]) for c in candidate]

print(max(can))

Buggy submission (verdict: Runtime Error):
def read():
    return int(input())


def readlist():
    return list(map(int, input().split()))


def readmap():
    return map(int, input().split())


N, K = readmap()
A = readlist()

cnt = [0] * 50  # cnt[i] は 2^i の桁の 1 の数

for a in A:
    i = 0
    while a:
        if a % 2:
            cnt[i] += 1
        i += 1
        a = a // 2

is_zero = [False] * 50

for i in range(50):
    if 2 * cnt[i] >= N:
        is_zero[i] = True

candidate = []

for i in range(50):
    if 2**i <= K:
        c = 0
        for j in reversed(range(i+1)):
            if (not is_zero[j]) and c + 2 ** j <= K:
                c += 2 ** j
        candidate.append(c)

can = [sum([c ^ a for a in A]) for c in candidate]

print(max(can))
Problem p03241 (python)

Fixed submission:
import math


def read():
    return int(input())


def readlist():
    return list(map(int, input().split()))


def readmap():
    return map(int, input().split())


def usage(n):
    fct = factorize(n)
    ret = []
    for div in divisorize(fct):
        ret.append(num(div))
    return ret

def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct


def divisorize(fct):
    b, e = fct.pop()  # base, exponent
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b, k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]


def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base ** exponent
    return a


N, M = readmap()
if M == 1:
    print(1)
    quit()
div = usage(M)
ans = 0
for d in div:
    if N * d <= M:
        ans = max(ans, d)
print(ans)

Buggy submission (verdict: Runtime Error):
import math


def read():
    return int(input())


def readlist():
    return list(map(int, input().split()))


def readmap():
    return map(int, input().split())


def usage(n):
    fct = factorize(n)
    ret = []
    for div in divisorize(fct):
        ret.append(num(div))
    return ret

def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct


def divisorize(fct):
    b, e = fct.pop()  # base, exponent
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b, k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]


def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base ** exponent
    return a


N, M = readmap()
div = usage(M)
ans = 0
for d in div:
    if N * d <= M:
        ans = max(ans, d)
print(ans)
Problem p02886 (python)

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

d_sum = sum(d)

m = 0
for k in d:
    m += k **2
    
print((d_sum**2 - m)//2)

Buggy submission (verdict: Runtime Error):
n = int(input())
d = list(map(int, input().split()))

d_sum = sum(d)

m = 0
for k in d:
    m += k **2
    
print((d_sum**2 - m)　//　2)
Problem p02797 (python)

Fixed submission:
N, K, S = map(int,input().split())


ans = [S for a in range(K)]
if S == 10**9:
    ain = [1 for a in range(N-K)]
else:
    ain = [S+1 for a in range(N-K)]
ans = ans + ain
print(*ans)

Buggy submission (verdict: Runtime Error):
N, K, S = map(int,input().split())

if K=0:
    print(1 for i in range(N))

else:
    ans = [S for a in range(K)]
    ain = [S+1 for a in range(N-K)]
    ans = ans + ain
    print(*ans)
Problem p02804 (python)

Fixed submission:
import math
N, K = map(int, input().split())
A = [int(a) for a in input().split()]

A.sort()

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 #出力の制限
Ne = 10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

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



maxi = 0
for i in range(K-1,N):
    maxi += A[i]*cmb(i, K-1, mod)

mini = 0
A.sort(reverse=True)
for j in range(K-1,N):
    mini += A[j]*cmb(j, K-1, mod)

print((maxi-mini)%mod)

Buggy submission (verdict: Runtime Error):
import math
N, K = map(int, input().split())
A = [int(a) for a in input().split()]

A.sort()

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 #出力の制限
Ne = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

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



maxi = 0
for i in range(K-1,N):
    maxi += A[i]*cmb(i, K-1, mod)

mini = 0
A.sort(reverse=True)
for j in range(K-1,N):
    mini += A[j]*cmb(j,K-1,mod)

print(maxi-mini)
Problem p03152 (python)

Fixed submission:
def solve():
    MOD = 10 ** 9 + 7
    N, M = map(int, input().split())
    A = set(map(int, input().split()))
    B = set(map(int, input().split()))
    
    row, columun = 0, 0
    ans = 1
    for i in range(N * M, 0, -1):
        in_A = i in A
        in_B = i in B
        if in_A and in_B:
            row += 1
            columun += 1
        elif in_A:
            row += 1
            ans *= columun
        elif in_B:
            columun += 1
            ans *= row
        else:
            ans *= row * columun - (N * M - i)
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    solve()

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

A.sort(reverse=True)
B.sort(reverse=True)

if len(set(A))!=len(A) or len(set(B))!=len(B):
    print(0)
    sys.exit()

ans = 1
rows, columna = 0,0
mod = 10**9+7
for x in range(N*M, 0, -1):

    if x in A and x in B:
        rows += 1
        columna += 1

    elif x in A and not x in B:
        rows += 1
        ans = ans * (columna)

    elif x in B and not x in A:
        columna += 1
        ans = ans *(rows)

    else:
        ans = ans * (rows * columna -(N*M-x

    ans %= mod    

print(ans%(10**9+7))
Problem p03739 (python)

Fixed submission:
n = int(input())

a = list(map(int,input().split()))
b = [i for i in a]


def solve(cnt,A,N):
    sumA=A[0]
    for i in range(1, N):
        if sumA>0:
            if sumA+A[i]>=0:
                r = A[i]
                A[i]=-sumA-1
                cnt+=abs(r-A[i])
        else:
            if sumA+A[i]<=0:
                r = A[i]
                A[i]=-sumA+1
                cnt+=abs(r-A[i])

        sumA+=A[i]
    return cnt

cnt1=0
if b[0]<=0:
    ini=b[0]
    b[0]=1
    cnt1=abs(1-ini)


ans1=solve(cnt1,b,n)
cnt2=0
if a[0]>=0:
    ini=a[0]
    a[0]=-1
    cnt2=abs(-1-ini)


ans2=solve(cnt2,a,n)

print(min(ans1,ans2))

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

a = list(int(i) for i in input().split())
b = []
for i in range(0,len(a)):
    b.append(a[i])


def solve(cnt,A,N):
    for i in xrange(1, N):
        if sum(A[0:i])>0:
            if sum(A[0:i+1])>=0:
                r = A[i]
                A[i]=-sum(A[0:i])-1
                cnt+=abs(r-A[i])
        else:
            if sum(A[0:i+1])<=0:
                r = A[i]
                A[i]=-sum(A[0:i])+1
                cnt+=abs(r-A[i])
    return cnt

cnt1=0
if b[0]<=0:
    ini=b[0]
    b[0]=1
    cnt1=abs(1-ini)


ans1=solve(cnt1,b,n)
cnt2=0
if a[0]>=0:
    ini=a[0]
    a[0]=-1
    cnt2=abs(-1-ini)


ans2=solve(cnt2,a,n)
print(min(ans1,ans2))
Problem p02921 (python)

Fixed submission:
S = input()
T = input()
ans = 0
for i in range(3):
    if S[i] == T[i]:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
N -= 1
ans = N * (1 + N) / 2
print(ans)