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

Fixed submission:
sample = input()
sample_list = sample.split(" ")
count = 0
flag = 0
i = 0
j = 1
for i in range(len(sample_list)):
  for j in range(i):
    if sample_list[i] == sample_list[j]:
      flag = 1
  if flag == 0:
    count += 1
  flag = 0
print(count)

Buggy submission (verdict: Runtime Error):
sample = input()
sample_list = sample.split(" ")
count = 0
flag = 0
for i in range(len(sample_list)):
  for j in range(1, i):
    if sample_list[i] == sample_list[j]:
      flag = 1
    if flag == 0:
      count += 1
    flag = 0
  return count

Buggy submission (verdict: Runtime Error):
sample = input()
sample_list = sample.split(" ")
count = 0
flag = 0
for i in range(len(sample_list)):
  for j in range(1, i):
    if L1[i] == L1[j]:
      flag = 1
    if flag == 0:
      count += 1
    flag = 0
  return count
Problem p03963 (python)

Fixed submission:
sample = input() # two numbers in a string
new_sample = sample.split(" ")

ball = int(new_sample[0]) # number of balls
color = int(new_sample[1]) # number of colors
if ball > 1 and color == 1:
  print(0)
else:
  product = color
  for i in range(1, ball):
    product *= (color-1)
  print(product)

  
# 3 balls, 10 colors
# 1st spot, 10 choices
# 2nd spot, 9 choices
# 3rd spot, 9 choices

Buggy submission (verdict: Runtime Error):
sample = input() # two numbers in a string
new_sample = sample.split(" ")

ball = int(new_sample[0]) # number of balls
color = int(new_sample[1]) # number of colors
if color == 1 and ball > 1:
  print(0)
else:
	product = color


# for i in range(1, ball):
  for i in range(1, ball):
    product *= (color-1)
  print(product)

  
# 3 balls, 10 colors
# 1st spot, 10 choices
# 2nd spot, 9 choices
# 3rd spot, 9 choices

Buggy submission (verdict: Runtime Error):
sample = input() # two numbers in a string
new_sample = sample.split(" ")
ball = new_sample[0] # number of balls
color = new_sample[1] # number of colors
product = color


# for i in range(1, ball):
for i in range(1, ball):
  product *= product-1
print(product)
  
  
# 3 balls, 10 colors
# 1st spot, 10 choices
# 2nd spot, 9 choices
# 3rd spot, 9 choices

Buggy submission (verdict: Runtime Error):
sample = input() # two numbers in a string
new_sample = sample.split(" ")
ball = new_sample[0] # number of balls
color = new_sample[1] # number of colors
product = color

for i in range(1, ball+1):
  product *= color-1
print(product)
  
  
# 2 balls, 10 colors
# 1st spot, 10 choices
# 2nd spot, 9 choices

Buggy submission (verdict: Runtime Error):
sample = input() # two numbers in a string
new_sample = sample.split(" ")
ball = new_sample[0]
color = new_sample[1]
product = color

for i in range(1, ball):
  product *= color-1
print(product)
Problem p03998 (python)

Fixed submission:
a = list(input())
b = list(input())
c = list(input())

win = False # if win == True, someone will win
run = a

while win != True:
  if run[0] == "a":
    run.pop(0)
    run = a # reset run
    if len(a) == 0:
      print("A")
      win = True
  elif run[0] == "b":
    run.pop(0)
    run = b
    if len(b) == 0:
      print("B")
      win = True
  else:
    run.pop(0)
    run = c
    if len(c) == 0:
      print("C")
      win = True

Buggy submission (verdict: Runtime Error):
alice = input()
bob = input()
charlie = input()

for i in range(len(alice)):
  if alice[i] == "a":
    while alice[i] == "a":
    	alice.pop(i)
    
  elif alice[i] == "b":
    alice.pop(i)
    if bob[i] == "b":
      while bob[i] == "b":
      	bob.pop(i)
    elif bob[i] == "a":
      while bob[i] == "a":
        alice.pop(i)
    elif bob[i] == "c":
       while bob[i] == "c":
        charlie.pop(i)
      
  elif alice[i] == "c":
    alice.pop(i)
    if charlie[i] == "c":
      while charlie[i] == "c":
        charlie.pop(i)
    elif charlie[i] == "b":
      while charlie[i] == "b":
        bob.pop(i)
    elif charlie[i] == "a":
      while charlie[i] == "a":
        alice.pop(i)

for i in range(len(alice)):
	if len(alice) == 0 and alice[
Problem p03997 (python)

Fixed submission:
a = int(input())
b = int(input())
h = int(input())
 
print(int(a+b)*h//2 )

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

print((a+b)*h/2)
Problem p03815 (python)

Fixed submission:
x = int(raw_input())
 
a = x // 11
 
if   0 <  x % 11  <= 6:
    
      print 2*a +1
 
elif x%11==0 :
      print 2*a
else :
      print 2*a +2

Buggy submission (verdict: Runtime Error):
# 整数の入力
x = int(raw_input())
 
a = x // 11
 
if  x % 11  < 6:
    
      print 2*a +1 
else :
      print 2*a +2

Buggy submission (verdict: Runtime Error):
# 整数の入力
x = int(raw_input())
 
a = x // 11
 
if  x % 11  < 6:
    
      print 2*a +1 
else :
      print 2*a +2
Problem p03814 (python)

Fixed submission:
s = raw_input()

s_long = len(s)
first_a_adress = -1
end_z_adress = -1
for var in range(0,s_long):
	if s[var] == 'A':
		first_a_adress = var
		break
				
for var in reversed(range(0,s_long)):
	if s[var] == 'Z':
		end_z_adress = var
		break
print end_z_adress - first_a_adress + 1

Buggy submission (verdict: Runtime Error):
s = input()

s_long = len(s)
first_a_adress = -1
end_z_adress = -1
for var in range(0,s_long):
	if s[var] == 'a':
		first_a_adress = var
		break
				
for var in reversed(range(0,s_long)):
	if s[var] == 'z':
		end_z_adress = var
		break
print end_z_adress - first_a_adress + 1
Problem p04044 (python)

Fixed submission:
N,L = map(int,input().split())
list1 = []
for l in range(N):
    list1.append(str(input()))
list1.sort()
print(''.join(list1))

Buggy submission (verdict: Runtime Error):
L,N = map(int,input().split())
S = []
for _ in range(N):
    S.append(str(input()))
S.sort()
print(''.join(S))

Buggy submission (verdict: Runtime Error):
L,N = map(int,input().split())
list1 = []
for l in range(N):
    list1.append(str(input()))
list1.sort()
print(''.join(list1))

Buggy submission (verdict: Runtime Error):
L,N = map(int,input().split())
list1 = []
for _ in range(N):
    list1.append(str(input()))
list1.sort()
print(''.join(list1))

Buggy submission (verdict: Runtime Error):
L,N = map(int,input().split())
list1 = []
for _ in range(N):
    list1.append(input())
list1.sort()
print(''.join(list1))
Problem p03962 (python)

Fixed submission:
a, b, c = map(int, raw_input().split())
print(len(set([a,b,c])))

Buggy submission (verdict: Runtime Error):
n, k = map(int, raw_input().split())

Buggy submission (verdict: Runtime Error):
n, k = map(int, raw_input().split())
print(k * (k-1)**(n-1))

Buggy submission (verdict: Runtime Error):
n, k = map(int, raw_input().split())
print(k * (k-1)**(n-1))

Buggy submission (verdict: Runtime Error):
n, k = map(int, raw_input().split())
print(k * (k-1)**(n-1))

Buggy submission (verdict: Runtime Error):
n, k = map(int, raw_input().split())
print(k * (k-1)**(n-1))

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, raw_input())
print(len(set([a,b,c])))
Problem p03826 (python)

Fixed submission:
a, b, c, d = map(int, raw_input().split())
print a*b if a*b > c*d else c*d

Buggy submission (verdict: Runtime Error):
n = int(raw_input())
s = str(raw_input())
x = 0
xs = [x]
for si in s:
    if si == 'I': x += 1
    else: x -= 1
    xs.append(x)
print max(xs)

Buggy submission (verdict: Runtime Error):
a, b, c, d = map(int, raw_input().split())
print(a*b if a*b > c*d else c*d)
Problem p04011 (python)

Fixed submission:
N = input()
K = input()
X = input()
Y = input()

if N > K:
    res = K*X + (N-K)*Y 
else:
    res = N*X

print(res)

Buggy submission (verdict: Runtime Error):
N = input()
K = input()
X = input()
Y = input()

if N > K:
    res = K*X + (N-K)*Y 
else
    res = N*X

print(res)
Problem p03831 (python)

Fixed submission:

def main():
    [n, a, b] = list(map(int,input().split()))
    m = list(map(int,input().split()))
    cost = 0
    for i in range(1, n):
        cost += min([a*(m[i]-m[i-1]), b])
    print(cost)


if __name__ == "__main__":
    import sys
    import os
    if len(sys.argv) > 1:
        if sys.argv[1] == "-d":
            filename = "input1.txt"
            fd = os.open(filename, os.O_RDONLY)
            os.dup2(fd, sys.stdin.fileno())
            main()
    else:
        main()

Buggy submission (verdict: Runtime Error):

def main():
    [n,a,b] = list(map(int,input().split()))
    m = list(map(int,input().split()))
    cost = 0
    for i in range(1,n+1):
        cost += min(a*(m[i]-m[i-1]), b)
    print(cost)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):

def main():
    [n,a,b] = list(map(int,input().split()))
    m = list(map(int,input().split()))
    cost = 0
    for i in range(1,n+1):
        cost += min(a*(m[i]-m[i-1]), b)
    print(cost)


if __name__ == "__main__":
    import sys
    import os
    if len(sys.argv) > 1:
        if sys.argv[1] == "-d":
            filename = "input1.txt"
            fd = os.open(filename, os.O_RDONLY)
            os.dup2(fd, sys.stdin.fileno())
            main()
    else:
        main()
Problem p03994 (python)

Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Sat Sep 24 21:28:20 2016

@author: dotha
"""

#aまでいけそうなら動かす。駄目そうならその項は終わり

def move(s, k):
    if len(s) == 1:
        return chr(97+(ord(s) + k - 97)%26)
    if s[0] == 'a' or 123-ord(s[0]) > k:
        return s[0] + move(s[1:], k)
    else:
        return 'a' + move(s[1:], k-(123-ord(s[0])))

def move_(l,k):
    if l =='a' or 123-ord(l) > k:
        return (l,k)
    else:
        return ('a', k-(123-ord(l)))

s = input()
K = int(input())
answer=[]
#print(move(s,K))

for l in s:
    (x,K) = move_(l,K)
    answer.append(x)

answer[-1] = chr(97++(ord(answer[-1]) + K - 97)%26)
    
print(''.join(answer))

Buggy submission (verdict: Runtime Error):
def move(s, k):
    if len(s) == 1:
        return chr(97+(ord(s) + k - 97)%26)
    if s[0] == 'a' or 123-ord(s[0]) > k:
        return s[0] + move(s[1:], k)
    else:
        return 'a' + move(s[1:], k-(123-ord(s[0])))






s = input()
K = int(input())
print(move(s,K))
Problem p03830 (python)

Fixed submission:
primes = [2,3,5,7,11,13,17,19,23,29,31]

memo1 = {}
def factorization(n):
    result = []
    for prime in primes:
        while n % prime == 0:
            n = n / prime
            result.append(prime)
    if n != 1:
        result.append(n)
    return result

def num_of_factors(l):
    if l == []:
        return 1
    if len(l) == 1:
        return 2
    p2num = {}
    for prime in l:
        if prime not in p2num:
            p2num[prime] = 2
        else:
            p2num[prime] += 1
    return reduce(lambda x,y: x * y,p2num.values())

def factors_of_factorials(n):
    l = []
    for i in range(1,n+1):
        l += factorization(i)
    return num_of_factors(l) % (10**9 + 7)


n = int(raw_input())
print factors_of_factorials(n)

Buggy submission (verdict: Runtime Error):
primes = [2,3,5,7,11,13,17,19,23,29,31]

memo1 = {}
def factorization(n):
    result = []
    for prime in primes:
        while n % prime == 0:
            n = n / prime
            result.append(prime)
    if n != 1:
        result.append(n)
    return result

def num_of_factors(l):

    if len(l) == 1:
        return 2
    p2num = {}
    for prime in l:
        if prime not in p2num:
            p2num[prime] = 2
        else:
            p2num[prime] += 1
    return reduce(lambda x,y: x * y,p2num.values())

def factors_of_factorials(n):
    l = []
    for i in range(1,n+1):
        l += factorization(i)
    return num_of_factors(l) % (10**9 + 7)


n = int(raw_input())
print factors_of_factorials(n)

Buggy submission (verdict: Runtime Error):
primes = [2,3,5,7,11,13,17,19,23,29,31]

memo1 = {}
def factorization(n):
    result = []
    for prime in primes:
        while n % prime == 0:
            n = n / prime
            result.append(prime)
    if n != 1:
        result.append(n)
    return result

def factors(l):
    p2num = {}
    for prime in l:
        if prime not in p2num:
            p2num[prime] = 2
        else:
            p2num[prime] += 1
    return reduce(lambda x,y: x * y,p2num.values())

def factors_of_factorials(n):
    l = []
    for i in range(1,n+1):
        l += factorization(i)
    return factors(l) % (10**9 + 7)


n = int(raw_input())
print factors_of_factorials(n)
Problem p03997 (python)

Fixed submission:
a, b, h= (int(input()) for _ in range(3))
print((a+b)*h // 2)

Buggy submission (verdict: Runtime Error):
  a, b, h = [int(input()) for _ in range(3)]
  print((a+b)*h / 2)

Buggy submission (verdict: Runtime Error):
  a, b, h = map(int(input().split())
  print((a+b)*h / 2)

Buggy submission (verdict: Runtime Error):
  a, b, h = (int(input()) for i in range(3))
  print((a+b)*h / 2)
Problem p04011 (python)

Fixed submission:
n, k, x, y = (int(input()) for i in range(4))
if k >= n:
  print(n*x)
else:
  print(k*x + (n-k)*y)

Buggy submission (verdict: Runtime Error):
n, k, x, y = map(int(input()) for i in range(4))
if k <= n:
  print(k*x)
else:
  print(k*x + (n-k)*y)

Buggy submission (verdict: Runtime Error):
n, k, x, y = map(int, input().split())
if k <= n:
  print(k*x)
else:
  print(k*x + (n-k)*y)

Buggy submission (verdict: Runtime Error):
n, k, x, y = map(int, input().split())
if k >= n:
  print(k*x)
else:
  print(k*x + (n-k)*y)
Problem p04029 (python)

Fixed submission:
n = int(input())
total = 0
for num in range(n+1):
  total = total + num
print(total)

Buggy submission (verdict: Runtime Error):
n = int(input())
num = 0
for num in range(n+1):
  total = total + num
print(total)

Buggy submission (verdict: Runtime Error):
n = int(input())
for num in range(n+1):
  total = total + num
print(total)

Buggy submission (verdict: Runtime Error):
n = input()
for num in range(n+1):
  total = total + num
print(total)

Buggy submission (verdict: Runtime Error):
n = int(input().split())
for num in range(n+1):
  total = total + num
print(total)
Problem p04043 (python)

Fixed submission:

s = input().split()
if s.count('7') == 1 and s.count('5') == 2:
  print('YES')
else:
  print('NO')

Buggy submission (verdict: Runtime Error):
s = map(int(input().split()))
if s.count('7') == 1 and s.count('5') == 2:
  print('YES')
else:
  print('NO')

Buggy submission (verdict: Runtime Error):
a, b, c = map(int(input().split()))
if count(7) == 1 and count(5) == 2:
  print('YES')
else:
  print('NO')
Problem p04043 (python)

Fixed submission:
A = input()

if A.count('5') == 2 and A.count('7') == 1:
    print('YES')
else:
    print('NO')

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

if A.count(5) == 2 and A.count(7) == 1:
    print("YES")
else:
    print("NO")

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

if A.count(5) == 2 and A.count(7) == 1:
    print("YES")
else:
    print("NO")
Problem p03845 (python)

Fixed submission:
import sys
in1 = sys.stdin.readlines()

#in1 = ['5','7 2 3 8 5','3','4 2','1 7','4 13']

N = int(in1[0])
T_N = list(map(int, in1[1].split()))
M = int(in1[2])
P_M = [None] * M
X_M = [None] * M
idx1 = 0
for PX in in1[3:]:
    P_M[idx1], X_M[idx1] = map(int, PX.split())
    idx1 += 1

sumT = sum(T_N)
for idx1 in range(M):
    print(sumT - T_N[P_M[idx1] - 1] + X_M[idx1])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readlines()

N = int(input[0])
T_N = list(map(int, input[1].split()))
M = int(input[2])
P_M = [None] * M
P_X = [None] * M
for PX in input[3:]:
    P_M, X_M = map(int, PX.split())

sumT = sum(T_N)
for idx1 in range(M):
    print(sumT - T_N[P_M[idx1] - 1] + X_M[idx1])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
"""
in1 = '5'
in2 = '7 2 3 8 5'
in3 = '3'
in4 = ['4 2', '1 7', '4 13']

N = int(in1)
T_N = list(map(int, in2.split()))
M = int(in3)
P_M = [None] * M
X_M = [None] * M
for i in range(M):
    P_M[i], X_M[i] = (int(x) for x in in4[i].split())
"""
N = int(input())
T_N = list(map(int, input().split()))
M = int(input())
P_M = [None] * M
P_X = [None] * M
for i in range(M):
    P_M[i], X_M[i] = (int(x) for x in input().split())

sumT = sum(T_N)
for idx1 in range(M):
    print(sumT - T_N[P_M[idx1] - 1] + X_M[idx1])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N = int(input())
T_N = [int(input()) for _ in range(N)]
M = int(input())
for i in range(M):
    P_M, X_M = map(int, input().split())

sumT = sum(T_N)
for idx1 in range(M):
    print(sumT - T_N[P_M[idx1] - 1] + X_M[idx1])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N = int(input())
T_N = [int(input()) for _ in range(N)]
M = int(input())
for _ in range(M):
    P_M, X_M = map(int, input().split())

sumT = sum(T_N)
for idx1 in range(M):
    print(sumT - T_N[P_M[idx1] - 1] + X_M[idx1])
Problem p03847 (python)

Fixed submission:
import sys

in1 = sys.stdin.readlines()
N = int(in1[0])
#N = 10 ** 18
#N = 2
"""
0 + 0 = 0
0 x 0 = 0

1 + 0 = 1
1 x 0 = 1

2 + 0 = 2
2 x 0 = 2
1 + 1 = 2
1 x 1 = 0

3 + 0 = 3
3 x 0 = 3
2 + 1 = 3
2 x 1 = 3
"""
p = 10 ** 9 + 7

def f(n):
    if n in d:
        return d[n]
    d[n] = f(n // 2) + f((n - 1) // 2) + f((n - 2) // 2)
    return d[n]

d = {0: 1, 1: 2}
print(f(N) % p)

Buggy submission (verdict: Runtime Error):
import sys

in1 = sys.stdin.readlines()
N = in1[0]
#N = 10 ** 18
#N = 2
"""
0 + 0 = 0
0 x 0 = 0

1 + 0 = 1
1 x 0 = 1

2 + 0 = 2
2 x 0 = 2
1 + 1 = 2
1 x 1 = 0

3 + 0 = 3
3 x 0 = 3
2 + 1 = 3
2 x 1 = 3
"""
p = 10 ** 9 + 7

def f(n):
    if n in d:
        return d[n]
    d[n] = f(n // 2) + f((n - 1) // 2) + f((n - 2) // 2)
    return d[n]

d = {0: 1, 1: 2}
print(f(N) % p)
Problem p03943 (python)

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

if a + b + c == max(a, b, c) * 2:
    print('Yes')
else:
    print('No')

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

if sum(a, b, c) == max(a, b, c) * 2:
    print('Yes')
else:
    print('No')
Problem p03962 (python)

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

print(len(list(set(a))))

Buggy submission (verdict: Runtime Error):
a = int(input().split())

print(len(list(set(a)))
Problem p04046 (python)

Fixed submission:
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 ** 6
fact    = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
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)

#kari1 = '2 3 1 1'                   #2
#kari1 = '10 7 3 4'                  #3570
#kari1 = '100000 100000 99999 99999' #1
#kari1 = '100000 100000 44444 55555' #738162020

"""
in1 = kari1.split()
"""
in1 = input().split()

H = int(in1[0])
W = int(in1[1])
A = int(in1[2])
B = int(in1[3])

allCNT = 0
for idx1 in range(W - B):
    beforeCNT = cmb(H - A + B - 1 + idx1, H - A - 1, p)
    afterCNT  = cmb(W + A - B - 2 - idx1, A - 1, p)
    allCNT    = (allCNT + (beforeCNT * afterCNT) % p) % p

print(allCNT)

Buggy submission (verdict: Runtime Error):
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]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
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)

#kari1 = '2 3 1 1'                   #2
#kari1 = '10 7 3 4'                  #3570
#kari1 = '100000 100000 99999 99999' #1
#kari1 = '100000 100000 44444 55555' #738162020

"""
in1 = kari1.split()
"""
in1 = input().split()

H = int(in1[0])
W = int(in1[1])
A = int(in1[2])
B = int(in1[3])

allCNT = 0
for idx1 in range(W - B):
    beforeCNT = cmb(H - A + B - 1 + idx1, H - A - 1, p)
    afterCNT  = cmb(W + A - B - 2 - idx1, A - 1, p)
    allCNT    = (allCNT + (beforeCNT * afterCNT) % p) % p

print(allCNT)
Problem p03943 (python)

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

if a==b+c or b==c+a or c==a+b:
  print('Yes')
else:
  print('No')

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

if a=b+c or b=c+a or c= a+b:
  print('Yes')
else:
  prine('No')
Problem p04013 (python)

Fixed submission:
N,A=map(int,input().split())
x=sorted(list(map(int,input().split())))

xn=[x[i]-A for i in range(len(x)) if x[i]<A]
xn.reverse()
x0=[0 for i in range(len(xn),len(x)) if x[i]==A]
xp=[x[i]-A for i in range(len(xn)+len(x0),len(x)) if x[i]>A]

sxn=[0]
sxn_n=[1]
for x in xn:
  sxn_add=[]
  sxn_n_i=[]
  for j in range(len(sxn)):
    sxn_tmp=sxn[j]+x
    for k in range(len(sxn)):
      if sxn[k]==sxn_tmp or k==len(sxn)-1:
        if sxn[k]==sxn_tmp:
          sxn_n_i.append([k,sxn_n[j]])
        else:
          sxn_add.append([sxn_tmp,sxn_n[j]])
        break
  for l in sxn_n_i:
    sxn_n[l[0]]+=l[1]  
  for k in sxn_add:
    sxn.append(k[0])
    sxn_n.append(k[1])
  

sxp=[0]
sxp_n=[1]
for x in xp:
  sxp_add=[]
  sxp_n_i=[]
  for j in range(len(sxp)):

    sxp_tmp=sxp[j]+x

    for k in range(j,len(sxp)):
      if sxp[k]==sxp_tmp or k==len(sxp)-1:

        if sxp[k]==sxp_tmp:
          sxp_n_i.append([k,sxp_n[j]])
        else:
          sxp_add.append([sxp_tmp,sxp_n[j]])
        break
  for l in sxp_n_i:
    sxp_n[l[0]]+=l[1]
  for k in sxp_add:
    sxp.append(k[0])
    sxp_n.append(k[1])




an=0
for i in range(1,len(sxp)):
  for j in range(1,len(sxn)):

    if sxp[i]==-sxn[j]:
      an+=sxp_n[i]*sxn_n[j]
      break


print(2**len(x0)-1+an*2**(len(x0)))

Buggy submission (verdict: Runtime Error):
N,A=map(int,input().split())
x=sorted(list(map(int,input().split())))

xn=[x[i]-A for i in range(len(x)) if x[i]<A]
xn.reverse()
x0=[0 for i in range(len(xn),len(x)) if x[i]==A]
xp=[x[i]-A for i in range(len(xn)+len(x0),len(x)) if x[i]>A]

sxn=[0]
sxn_n=[1]
for x in xn:
  sxn_add=[]
  sxn_n_i=[]
  for j in range(len(sxn)):
    sxn_tmp=sxn[j]+x
    for k in range(j,len(sxn)):
      if sxn[k]<=sxn_tmp or k==len(sxn)-1:
        if sxn[k]==sxn_tmp:
          sxn_n_i.append([k,sxn_n[j]])
        elif sxn[k]<sxn_tmp:
          sxn_add.append([k,sxn_tmp,sxn_n[j]])
        else:
          sxn_add.append([k+1,sxn_tmp,sxn_n[j]])
        break
  for k in range(len(sxn_add)):
    sxn.insert(k+sxn_add[k][0],sxn_add[k][1])
    sxn_n.insert(k+sxn_add[k][0],1)
  for l in sxn_n_i:
    sxp_n[l[0]]+=l[1]    

sxp=[0]
sxp_n=[1]
for x in xp:
  sxp_add=[]
  sxp_n_i=[]
  for j in range(len(sxp)):

    sxp_tmp=sxp[j]+x

    for k in range(j,len(sxp)):
      if sxp[k]>=sxp_tmp or k==len(sxp)-1:

        if sxp[k]==sxp_tmp:
          sxp_n_i.append([k,sxp_n[j]])
        elif sxp[k]>sxp_tmp:
          sxp_add.append([k,sxp_tmp,sxp_n[j]])
        else:
          sxp_add.append([k+1,sxp_tmp,sxp_n[j]])
        break

  for k in range(len(sxp_add)):
    sxp.insert(k+sxp_add[k][0],sxp_add[k][1])
    sxp_n.insert(k+sxp_add[k][0],sxp_add[k][2])
  for l in sxp_n_i:
    sxp_n[l[0]]+=l[1]



an=0
for i in range(1,len(sxp)):
  for j in range(1,len(sxn)):

    if sxp[i]==-sxn[j]:
      an+=sxp_n[i]*sxn_n[j]
      break


print(2**len(x0)-1+an*2**(len(x0)))
Problem p04014 (python)

Fixed submission:
n=int(input())
s=int(input())

b_ans=1



if n==s:
  b_ans=n+1
if b_ans==1:
  for b in range(2,int(n**0.5)+1):
    nn=n
    st=[]
    while(nn>0):
      st.append(nn%b)
      nn=(nn-st[-1])/b
  
    if sum(st)==s:
      b_ans=b
      break

if b_ans==1:
  for p in range(int(n**0.5),0,-1):
    b=(n-s+p)/p

    if b.is_integer() and 0<=s-p<b and b>n**0.5:
      b_ans=int(b)
      break

if b_ans!=1:
  print(b_ans)
else:
  print(-1)

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

b_ans=1
for b in range(2,int(n**0.5)+1):
  nn=n
  st=[]
  while(nn>0):
    st.append(nn%b)
    nn=(nn-st[-1])/b
  
  if sum(st)==s:
    b_ans=b
    break


if b_ans==1:
  for p in range(int(n**0.5)):
    b=int(n/p)
    q=n-p*b
    if s==p+q:
      b_ans=b
      break

if b_ans!=1:
  print(b_ans)
else:
  print(-1)
Problem p04029 (python)

Fixed submission:
N=int(input())

out=0
for i in range(N):
  out+=i+1
print(out)

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

out=0
for i in range(N):
  out+=i+1
return out