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

Fixed submission:
#! /usr/bin/python3
# こだわり者いろはちゃん / Iroha's Obsession
# 参考 : https://abc042.contest.atcoder.jp/submissions/3419872

"""
    1≦N<10000
    1≦K<10
    0≦D1<D2<…<DK≦9
    {D1,D2,…,DK}≠{1,2,3,4,5,6,7,8,9}
"""

N, K = map(int, input().split())
D = set(list(input().split()))

test_mode = False


def check_num(x, d):
    """
    金額xの中に中の文字があるか確認する関数。
    x : 現在の金額（N, x+1 を想定）
    d : 嫌いな数字のリスト（D を想定）
    文字列 x にリスト d 中の要素が含まれているか、d の要素 num を順に確認し、
    含まれていたら1円足して再試行する。
    """
    if test_mode:
        print('x =', x)
    while len(set(list(str(x))) & d) != 0:
        x += 1
    return x


def main():
    """
    金額を算出して出力
    """
    amount = check_num(N, D)
    print(amount)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#! /usr/bin/python3
# こだわり者いろはちゃん / Iroha's Obsession

"""
    1≦N<10000
    1≦K<10
    0≦D1<D2<…<DK≦9
    {D1,D2,…,DK}≠{1,2,3,4,5,6,7,8,9}
"""

N, K = map(int, input().split())
D = list(map(int, input().split()))

test_mode = False


def check_num(x, d):
    """
    金額xの中に中の文字があるか確認する関数。
    x : 現在の金額（N, x+1 を想定）
    d : 嫌いな数字のリスト（D を想定）
    文字列 x にリスト d 中の要素が含まれているか、d の要素 num を順に確認し、
    含まれていたら1円足して再試行する。
    """
    if test_mode:
        print('x =', x)
    for num in d:
        str_x = str(x)
        str_num = str(num)
        if str_num in str_x:
            return check_num(x+1, d)
    return x

  
amount = check_num(N, D)
print(amount)

Buggy submission (verdict: Runtime Error):
#! /usr/bin/python3
# こだわり者いろはちゃん / Iroha's Obsession

"""
    1≦N<10000
    1≦K<10
    0≦D1<D2<…<DK≦9
    {D1,D2,…,DK}≠{1,2,3,4,5,6,7,8,9}
"""

N, K = map(int, input().split())
D = list(map(int, input().split()))

test_mode = False


def check_num(x, d):
    """
    金額xの中に中の文字があるか確認する関数。
    x : 現在の金額（N, x+1 を想定）
    d : 嫌いな数字のリスト（D を想定）
    文字列 x にリスト d 中の要素が含まれているか、d の要素 num を順に確認し、
    含まれていたら1円足して再試行する。
    """
    if test_mode:
        print('x =', x)
    for num in d:
        str_x = str(x)
        str_num = str(num)
        if str_num in str_x:
            return check_num(x+1, d)
    return x


def main():
    """
    金額を算出して出力
    """
    amount = check_num(N, D)
    print(amount)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#! /usr/bin/python3
# こだわり者いろはちゃん / Iroha's Obsession

"""
    1≦N<10000
    1≦K<10
    0≦D1<D2<…<DK≦9
    {D1,D2,…,DK}≠{1,2,3,4,5,6,7,8,9}
"""

N, K = map(int, input().split())
D = list(map(int, input().split()))

test_mode = False


def check_num(x, d, n):
    """
    金額xの中に中の文字があるか確認する関数。
    x : 現在の金額（N, x+n を想定）
    d : 嫌いな数字のリスト（D を想定）
    n : 元の金額（N を想定）
    文字列 x にリスト d 中の要素が含まれているか、d の要素 num を順に確認し、
    含まれていたら元の金額 n を足して再試行する。
    """
    if test_mode:
        print('x =', x)
    for num in d:
        if test_mode:
            print('num =', num)
        str_x = str(x)
        str_num = str(num)
        if str_num in str_x:
            return check_num(x+n, d, n)
    return x


def main():
    """
    金額を算出して出力
    """
    amount = check_num(N, D, N)
    print(amount)


if __name__ == '__main__':
    main()
Problem p03238 (python)

Fixed submission:
n = int(input())

if n == 1:
	print('Hello World')
else:
	A = int(input())
	B = int(input())
	print(A + B)

Buggy submission (verdict: Runtime Error):
N, M = list(map(int,input().split()))
 
d = int(M/N)
 
if M%N == 0:
	print(d)
else: 
    ans = 1
    for i in range(m//n+1, 0, -1):
        if m % i == 0:
            if (m // i) >= n:
                print(i)
                break
	# i = 0
	# while True:
	# 	if M%(N+i+1) == 0:
	# 		print(int(M/(N+i+1)))
	# 		break
	# 	i += 1
Problem p03241 (python)

Fixed submission:
import math, sys, random

N, M = list(map(int,input().split()))
# N, M = 1111, 1000000000

def is_prime(n):
    if n == 2: return True
    if n == 1 or n & 1 == 0: return False

    d = (n - 1) >> 1
    while d & 1 == 0:
        d >>= 1

    for k in range(100):
        a = random.randint(1, n - 1)
        t = d
        y = pow(a, t, n)

        while t != n - 1 and y != 1 and y != n - 1:
            y = (y * y) % n
            t <<= 1

        if y != n - 1 and t & 1 == 0:
            return False

    return True

d = int(math.floor(M/N))

if M%N == 0:
	print(d)
	sys.exit()

i = 0
f = False
while True:
	if M%(N+i+1) == 0:
		print(int(M/(N+i+1)))
		sys.exit()
	i += 1
	if i == 100000 and is_prime(M):
		print(1)
		sys.exit()

Buggy submission (verdict: Runtime Error):
N, M = list(map(int,input().split()))
 
d = int(M/N)
 
if M%N == 0:
	print(d)
else: 
    ans = 1
    for i in range(m//n+1, 0, -1):
        if m % i == 0:
            if (m // i) >= n:
                print(i)
                break
	# i = 0
	# while True:
	# 	if M%(N+i+1) == 0:
	# 		print(int(M/(N+i+1)))
	# 		break
	# 	i += 1
Problem p03243 (python)

Fixed submission:
import sys

n = input()

if n[0] == '9':
	m = ''.join(['9']*len(n))
	if int(n) > int(m):
		print(''.join(['1']*(len(n)+1)))
		sys.exit()
	else:
		print(m)
		sys.exit()
else:
	s = n[0]
	m = ''.join([s]*len(n))
	if int(n) > int(m):
		print(''.join([str(int(s)+1)]*len(n)))
		sys.exit()
	else:
		print(m)
		sys.exit()

Buggy submission (verdict: Runtime Error):
import sys

n = input()

if n[0] == '9':
	m = ''.join(['9']*len(n))
	if int(n) > int(m):
		print(''.join(['1']*(len(n)+1)))
		sys.exit()
	else:
		print(m)
		sys.exit()
else:
	s = n[0]
	m = ''.join([s]*len(n))
	if int(n) > int(m):
		print(''.join([s+1]*len(n)))
		sys.exit()
	else:
		print(m)
		sys.exit()
Problem p03369 (python)

Fixed submission:
order = input()
order = list(order)
price = 700
for x in order:
	if x == 'o':
		price = price + 100
print(price)

Buggy submission (verdict: Runtime Error):
order = list(raw_input())
price = 700
for x in order:
	if x == 'o':
		price = price + 100
print(price)
Problem p03370 (python)

Fixed submission:
import math

d = list(map(int,input().split(' ')))
N = d[0]
X = d[1]
min_m = 0

for i in range(N):
	mi = int(input())
	X = X - mi
	if min_m == 0 or min_m > mi:
		min_m = mi

print(N + math.floor(X/min_m))

Buggy submission (verdict: Runtime Error):
import math

d = list(map(int,input().split(' ')))
N = d[0]
X = d[1]
min_m = 0

n = int(input())
for i in range(n):
	mi = input()
	X = X - mi
	if min_m == 0 or min_m > mi:
		min_m = mi

print(N + math.floor(X/mi))

Buggy submission (verdict: Runtime Error):
import math

d = input()
m = []
itr = 0
cnt = 0
N = 0
X = 0
min_m = 0
for i in range(d):
	if itr == 0:
		e = input().split()
		N = e[0]
		X = e[1]
	else:
		X = X - input()
		mi = input()
		if min_m == 0 or min_m > mi
			min_m = mi
	itr = itr + 1
print(N + math.floor(X/mi))
Problem p02761 (python)

Fixed submission:
from sys import exit

N,M = map(int, input().split())

S = [0]*M
C = [0]*M
for i in range(M):
    S[i],C[i] = map(int,input().split())

k = [-1]*N
for i in range(M):
    s,c = S[i],C[i]
    if k[s-1]==-1:
        k[s-1] = c
    else:
        if k[s-1]!=c:
            print(-1)
            exit()

ans = [0]*N
for i in range(N):
    if k[i]==-1:
        ans[i] = 0
    else:
        ans[i] = k[i]


if N==1:
    print(ans[0])
    exit()

if ans[0]==0:
    f=True
    for i,j in zip(S,C):
        if i==1 and j==0:
            f = False
            break
    if f:
        ans[0] = 1
    else:
        print(-1)
        exit()

print(*ans,sep='')

Buggy submission (verdict: Runtime Error):
from sys import exit

N,M = map(int, input().split())
S = [0]*M
C = [0]*M
for i in range(M):
    S[i],C[i] = map(int,input().split())

k = [-1]*N
for i in range(M):
    s,c = S[i],C[i]
    if k[s-1]==-1:
        k[s-1] = c
    else:
        if k[s-1]!=c:
            print(-1)
            exit()

ans = [0]*N
for i in range(N):
    if k[i]==-1:
        ans[i] = 0
    else:
        ans[i] = k[i]


if N==1:
    if mask[0]==1:
        print(ans[0])
    else:
        print(-1)
    exit()

if ans[0]==0:
    print(-1)
    exit()

print(*ans,sep='')
Problem p02850 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

N=int(input())

G = [[] for i in range(N)]
for i in range(N-1):
    a,b = map(lambda x:int(x)-1, input().split())
    G[a].append([b,i])
    G[b].append([a,i])

def bfs(x, c, b):
    if seen[x]:
        return
    seen[x] = True
    if b!=-1:
        global k
        color[b] = c
        k = max(k,c)
    t = 1
    for i,b in G[x]:
        if t==c:
            t+=1
        if not(seen[i]):
            bfs(i,t,b)
            t+=1

seen = [False]*N
color = [0]*N
k=0
bfs(0, 0, -1)


print(k)
print(*color[:-1],sep='\n')

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

G = [[] for i in range(N)]
for i in range(N-1):
    a,b = map(lambda x:int(x)-1, input().split())
    G[a].append([b,i])
    G[b].append([a,i])

def bfs(x, c, b):
    if seen[x]:
        return
    seen[x] = True
    if b!=-1:
        global k
        color[b] = c
        k = max(k,c)
    t = 1
    for i,b in G[x]:
        if t==c:
            t+=1
        if not(seen[i]):
            bfs(i,t,b)
            t+=1

seen = [False]*N
color = [0]*N
k=0
bfs(0, 0, -1)


print(k)
print(*color[:-1],sep='\n')
Problem p02882 (python)

Fixed submission:
import math

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


if a*a*b>2*x:
	print(90- math.atan2(2*x, a*b*b) *360/(2*math.pi))
else:
	print(90- math.atan2(a**3, 2*(a*a*b-x)) *360/(2*math.pi))

Buggy submission (verdict: Runtime Error):
import math

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


if a*a*b>2*x:
	print(90- math.atan(2*x/(a*b*b) *360/(2*math.pi)))
else:
	print(90- math.atan(a**3/(2*(a*a*b-x))) *360/(2*math.pi))
Problem p02947 (python)

Fixed submission:
N=int(input())
d={}
for i in range(N):
    l=[0]*26
    for s in input():
        l[ord(s)-97]+=1
    l=tuple(l)
    if l in d:d[l]+=1
    else:d[l]=1

ans=0
for c in d:
    if d[c]==2:ans+=1
    elif d[c]!=1:ans+=d[c]*(d[c]-1)//2
print(ans)

Buggy submission (verdict: Runtime Error):
A = []
B = []
N = int(input())

for i in range(N):
	t = input()
	t = sorted(t)
	
	flag = True
	for i in range(len(A)):
		if A[i] == t:
			B[i] += 1
			flag = False
			break
	
	if flag:
		A.append(t)
		B.append(1)
		
ans = 0
for b in B:
	if b==2:
		ans += 1
	elif b!=1:
		t = 1
		for i in range(2,b+1):
			t*=i
		ans += int(t/2)
		
print(ans)
Problem p02993 (python)

Fixed submission:
N = input()

ans = 'Good'
for i in range(len(N)-1):
	if N[i] == N[i+1]:
		ans='Bad'
print(ans)

Buggy submission (verdict: Runtime Error):
import fractions

A, B, C, D = [int(i) for i in input().split()]

lcm = (C*D)//fractions.gcd(C,D)
A = A-1
t1 = A - (A//C + A//D - A//lcm)
t2 = B - (B//C + B//D - B//lcm)
print(int(t2 - t1))
Problem p02995 (python)

Fixed submission:
import fractions

A, B, C, D = [int(i) for i in input().split()]

lcm = (C*D)//fractions.gcd(C,D)
A = A-1
t1 = A - (A//C + A//D - A//lcm)
t2 = B - (B//C + B//D - B//lcm)
print(int(t2 - t1))

Buggy submission (verdict: Runtime Error):
import math

A, B, C, D = [int(i) for i in input().split()]

lcm = (C*D)/math.gcd(A, D)
A = A-1

if A == 0:
	t1 = 0
else:
	t1 = A - (A/C + A/D - A/lcm)

t2 = B - (B/C + B/D - B/lcm)
print(int(t2 - t1))

Buggy submission (verdict: Runtime Error):
import math

A, B, C, D = [int(i) for i in input().split()]

lcm = (C*D)//math.gcd(A, D)
A = A-1

if A == 0:
	t1 = 0
else:
	t1 = A - (A//C + A//D - A//lcm)

t2 = B - (B//C + B//D - B//lcm)
print(t2 - t1)

Buggy submission (verdict: Runtime Error):
import math

A, B, C, D = [int(i) for i in input().split()]

lcm = (C*D)//math.gcd(A, D)
A = A-1
t1 = A - (A//C + A//D - A//lcm)
t2 = B - (B//C + B//D - B//lcm)
print(t2 - t1)
Problem p02996 (python)

Fixed submission:
import numpy as np

N = int(input())
A = np.zeros((N,2))

for i in range(N):
	A[i, 0], A[i, 1] = [int(j) for j in input().split()]

A = A[np.argsort(A[:,1]), :]

for i in range(N-1):
	A[i+1, 0] = A[i, 0]+A[i+1, 0]

ans = ['Yes', 'No']
t = np.sum((A[:,1]-A[:,0])<0)

print(ans[t>0])

Buggy submission (verdict: Runtime Error):
import numpy as np

N = int(input())
A = np.zeros((N,2))

for i in range(N):
	A[i, 0], A[i, 1] = [int(j) for j in input().split()]

A = A[np.argsort(A[:,1]), :]

for i in range(N-1):
	A[i+1, 0] = A[i, 0]+A[i+1, 0]

ans = ['Yes', 'No']
print(ans[np.sum((A[:,1]-A[:,0])<0)])
Problem p03074 (python)

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

A=[]

if s[0]!='1':A.append(0)

cnt=1
pre=s[0]
for i in s[1:]:
	if pre!=i:
		A.append(cnt)
		cnt=1
		pre=i
	else:
		cnt+=1

if (s[-1]=='1' and len(A)%2==0) or (s[-1]=='0' and len(A)%2!=0):
	A.append(cnt)


if s[-1]!='0':
	A.append(0)
A.append(0)

dp=[0]*(len(A)//2-K+1)

if (2*K+1)>=len(A):print(sum(A))
else:
	for i in range(2*K+1):dp[0]+=A[i]
	
	i=1
	idx=0
	while len(dp)>i:
		dp[i]=dp[i-1]-A[idx]-A[idx+1]+A[idx+2*(K+1)]+A[idx-1+2*(K+1)]
		idx+=2
		i+=1
	
	print(max(dp))

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

A=[]

if s[0]!='1':A.append(0)

cnt=1
pre=s[0]
for i in s[1:]:
	if pre!=i:
		A.append(cnt)
		cnt=1
		pre=i
	else:
		cnt+=1

if (s[-1]=='1' and len(A)%2==0) or (s[-1]=='0' and len(A)%2!=0):
	A.append(cnt)


if s[-1]!='0':
	A.append(0)
A.append(0)

dp=[0]*(len(A)//2-K+1)

for i in range(2*K+1):dp[0]+=A[i]

i=1
idx=0
while len(dp)>i:
	dp[i]=dp[i-1]-A[idx]-A[idx+1]+A[idx+2*(K+1)]+A[idx-1+2*(K+1)]
	idx+=2
	i+=1

print(max(dp))
Problem p03274 (python)

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

ans = 3*10**8 + 1
for i in range(N-K+1):
  l = A[i]
  r = A[i+K-1]
  a = abs(l) + r-l
  b = abs(r) + r-l
  ans = min(ans, min(a,b))
print(ans)

Buggy submission (verdict: Runtime Error):
import bisect

N, K =map(int,input().split())
X = [int(x) for x in input().split()]

l = []
r = []
for x in X:
  if x<0:
    l.append(-x)
  else:
    r.append(x)
l = l[::-1]


sl = 2*10**8
sr = 2*10**8
sa = 2*10**8

if len(l)>=K:
  sl = l[K-1]
if len(r)>=K:
  sr = r[K-1]

if len(l)!=0 and len(r)!=0:
  il = 0
  ir = 0
  while not(il+ir+2>=K):
    if il>=len(l)-1:
      ir += 1
    elif ir>=len(r)-1:
      il += 1
    else:
      if l[il+1]<l[ir+1]:
        il+=1
      else:
        ir+=1
  sa = l[il] + r[ir] +min(l[il],r[ir])

print(min([sl, sr, sa]))
Problem p03361 (python)

Fixed submission:
H,W=map(int,input().split())
A=[input() for i in range(H)]

f=True
for i in range(H):
	for j in range(W):
		if A[i][j]=='#':
			g=False
			for a,b in [(-1,0),(1,0),(0,1),(0,-1)]:
				if 0<=i+a<H and 0<=j+b<W:
					if A[i+a][j+b]=='#':g=True
			if not(g):f=False

print('Yes' if f else 'No')

Buggy submission (verdict: Runtime Error):
H,W=map(int,input().split())
A=[input() for i in range(H)]

for i in range(H):
	for j in range(W):
		if A[i][j]=='#':
			f=False
			for a,b in [(-1,0),(1,0),(0,1),(0,-1)]:
				if 0<=i+a<H and 0<=j+b<W:
					if A[i+a][j+b]=='#':f=True
			if not(f):break

print('Yes' if f else 'No')
Problem p03549 (python)

Fixed submission:
N, M = map(int,input().split())
t = (N-M)*100 + M*1900
print(2**M*t)

Buggy submission (verdict: Runtime Error):
from sys import exit

N = int(input())
A = [int(x) for x in input().split()]

m1 = 0
m2 = 0
m4 = 0

for a in A:
	if a%4==0:
		m4 += 1
	elif a%2==0:
		m2 += 1
	else:
		m1 += 1


m1 = m1 + (m2>0)
if m4>=m1-1:
	print('Yes')
else:
	print('No')
Problem p03660 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

import math

N=int(input())

G=[[] for i in range(N)]
for _ in range(N-1):
	a,b=map(lambda x:int(x)-1,input().split())
	G[a].append(b)
	G[b].append(a)

depth=[[0]*N for i in range(2)]

def dfs(d, i, p, k=0):
	for t in G[i]:
		if t!=p:
			depth[k][t]=d
			dfs(d+1, t, i,k)


dfs(1,0,-1, 0)
dfs(1,N-1,-1, 1)

cnt=0
for i,j in zip(depth[0], depth[1]):
	if i<=j:
		cnt+=1

print('Fennec' if cnt*2>N else 'Snuke')

Buggy submission (verdict: Runtime Error):
import math

N=int(input())

G=[[] for i in range(N)]
for _ in range(N-1):
	a,b=map(lambda x:int(x)-1,input().split())
	G[a].append(b)
	G[b].append(a)

depth=[[0]*N for i in range(2)]

def dfs(d, i, p, k=0):
	for t in G[i]:
		if t!=p:
			depth[k][t]=d
			dfs(d+1, t, i,k)
			


dfs(1,0,-1, 0)
dfs(1,N-1,-1, 1)

cnt=0
for i,j in zip(depth[0], depth[1]):
	if i<=j:
		cnt+=1

print('Fennec' if cnt*2>N else 'Snuke')

Buggy submission (verdict: Runtime Error):
import math

N=int(input())

G=[[] for i in range(N)]
for _ in range(N-1):
	a,b=map(lambda x:int(x)-1,input().split())
	G[a].append(b)
	G[b].append(a)


seen=[False]*N
seen[0]=True
depth=[0]*N
sub_tree=[1]*N
ne=[0]


def dfs(d, i, p):
	for t in G[i]:
		if t!=p:
			depth[t]=d
			dfs(d+1, t, i)
			
			sub_tree[i]+=sub_tree[t]



dfs(1,0,-1)

d=depth[-1]
a=sub_tree[0]-sub_tree[-1]-d
b=sub_tree[-1]-1

a+=math.ceil(d/2)
b+=d//2

print('Fennec' if a>b else 'Snuke')
Problem p02721 (python)

Fixed submission:
n,k,c = list(map(int, input().split()))
s = input()
ls = list(s)

ortho = [0]*k
rever = [0]*k

a = 0
skip = []
for i in range(len(ls)):
    if a >= k: break
    if ls[i] == "o" and i not in skip:
        ortho[a] = i
        a += 1
        skip = [i+j for j in range(1, c+1)]

a = 0
skip = []
ls.reverse()
for i in range(len(ls)):
    if a >= k: break
    if ls[i] == "o" and i not in skip:
        rever[a] = i
        a += 1
        skip = [i+j for j in range(1, c+1)]

rever.reverse()
rever = [len(ls)-1-i for i in rever]

for i in range(k):
    if ortho[i] == rever[i]:
        print(ortho[i]+1)

Buggy submission (verdict: Runtime Error):
n,k,c = list(map(int, input().split()))
s = input()
ls = list(s)

ortho = [0]*k
rever = [0]*k

a = 0
skip = []
for i in range(len(ls)):
    if ls[i] == "o" and i not in skip:
        ortho[a] = i
        a += 1
        skip = [i+j for j in range(1, c+1)]

a = 0
skip = []
ls.reverse()
for i in range(len(ls)):
    if ls[i] == "o" and i not in skip:
        rever[a] = i
        a += 1
        skip = [i+j for j in range(1, c+1)]

rever.reverse()
rever = [len(ls)-1-i for i in rever]

for i in range(k):
    if ortho[i] == rever[i]:
        print(ortho[i])
Problem p02780 (python)

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

p1 = (sum(p[:k]) + k)/2

ansum = [p1]
for i  in range(len(p)-k):
    p1 = p1 - (p[i]+1)/2 + (p[i+k]+1)/2
    ansum.append(p1)

print(max(ansum))

Buggy submission (verdict: Runtime Error):
import numpy as np
n,k = list(map(int, input().split()))
p = list(map(int, input().split()))

pk = np.array([])
ansum = np.array([])
for i,name  in enumerate(p):
    pk = np.append(pk, (name+1)/2)
    if i >= 2:
        ansum = np.append(ansum, np.sum(pk[-k:]))

print(np.max(ansum))
Problem p02789 (python)

Fixed submission:
n,m = list(map(int, input().split()))
ans = "Yes"
if m <n:
    ans = "No"
print(ans)

Buggy submission (verdict: Runtime Error):
n,m = list(map(int, input()))
ans = "Yes"
if m <n:
    ans = "No"
print(ans)
Problem p02804 (python)

Fixed submission:

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**5
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 )

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

a.sort()
ans1 = 0
ans2 = 0
for h in range(m-k+1):

    n = (m-h-1)
    r = (k-1)
    cmb1 = cmb(n, r, mod)
    ans1 += (a[m - h - 1]) * cmb1 % mod
    ans2 += (a[h]) * cmb1 % mod

ans = (ans1 - ans2) % mod

print(ans)

Buggy submission (verdict: Runtime Error):

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 )

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

a.sort()
ans1 = 0
ans2 = 0
for h in range(m-k+1):

    n = (m-h-1)
    r = (k-1)
    cmb1 = cmb(n, r, mod)
    ans1 += (a[m - h - 1]) * cmb1 % mod
    ans2 += (a[h]) * cmb1 % mod

ans = (ans1 - ans2) % mod

print(ans)

Buggy submission (verdict: Runtime Error):

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

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

a.sort()
ans1 = 0
ans2 = 0
for h in range(m-k+1):
    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 = (m-h-1)
    r = (k-1)
    cmb1 = cmb(n, r, mod)
    ans1 += (a[m - h - 1]) * cmb1 % mod
    ans2 += (a[h]) * cmb1 % mod

ans = (ans1 - ans2) % mod

print(ans)

Buggy submission (verdict: Runtime Error):
m,k = list(map(int, input().split()))
a = list(map(int, input().split()))

a.sort()
ans1 = 0
ans2 = 0
for h in range(m-k+1):
    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 = (m-h-1)
    r = (k-1)
    cmb1 = cmb(n, r, mod)
    ans1 += (a[m - h - 1]) * cmb1 % mod
    ans2 += (a[h]) * cmb1 % mod

ans = (ans1 - ans2) % mod

print(ans)
Problem p02843 (python)

Fixed submission:
import numpy as np
A = int(input())

if A >= 3000:
    print(1)
else:
    a = [100,101,102,103,104,105]
    N = A//100
    dp = np.array([np.array([0 for i in range(A+1)]) for j in range(N+1)])
    dp[0][0] = 1

    for i in range(N):
        for j in np.where(dp[i] == 1)[0]:
        #for j in range(A+1):
           # if dp[i][j] == 1:
            dp[i+1][j+100:j+106] = 1
    print(dp[N][A])

Buggy submission (verdict: Runtime Error):

import numpy as np
A = int(input())

if A >= 3000:
    print(1)
else:
    a = [100,101,102,103,104,105]  
    N = A//100
    dp = np.array([np.array([0 for i in range(A+1)]) for j in range(N+1)])
    dp[0][0] = 1
        
    for i in range(N):
        for j in np.where(dp[i] == 1)[0]:
        #for j in range(A+1):
           # if dp[i][j] == 1:
            dp[i+1][j+100:j+106] = 1
    
    print(dp[N][A])
    
    
    dp = [[0 for i in range(A+1)] for j in range(N+1)]
    dp[0][0] = 1
    
    for i in range(N):
        for j in range(A+1):
            if a[i] <= j:
                dp[i+1][j] = dp[i][j-a[i]] or dp[i][j]
            else:
                dp[i+1][j] = dp[i][j]
    
    print(dp[N][A])

Buggy submission (verdict: Runtime Error):
import numpy as np
A = int(input())
a = [100,101,102,103,104,105]

N = A//100
dp = np.array([np.array([0 for i in range(A+1)]) for j in range(N+1)])
dp[0][0] = 1

for i in range(N):
    for j in range(A+1):
        if dp[i][j] == 1:
            dp[i+1][j+100:j+106] = 1

print(dp[N][A])
Problem p02844 (python)

Fixed submission:
N = int(input())
S = str(input())

a = []
for i in range(10):
    for j in range(10):
        for z in range(10):
            a.append([i,j,z])

s = list(S)
s = [int(i) for i in s]
ans = 0
for n in a:
    flag = 0
    for i,name in enumerate(s):
        if name == n[0]:
            n = n[1:]
            flag += 1
        if flag == 3:
            ans += 1
            break

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = str(input())

import itertools as it
x = list(it.combinations(list(S), 3))
y = ["".join(i) for i in x]
z = len(np.unique(y))
print(z)