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

Fixed submission:
n = int(input())
st = []
for i in range(n):
    x, l = map(int, input().split())
    st.append([x + l, x - l])

st.sort()
cnt = 1
right = st[0][0]
for i in range(1, n):
    if right <= st[i][1]:
        right = st[i][0]
        cnt += 1

print(cnt)

Buggy submission (verdict: Runtime Error):
n = int(input())
xl = []
for i in range(n):
    x1, l1 = map(int, input().split())
    xl.append([x1, x1 + l1, 2 * l1])
xl.sort()
ans = n
for i in range(n - 1):
    if xl[i][1] > xl[i + 1][0]:
        if xl[i][2] >= xl[i + 1][2]:
            ans -= 1
        else:
            ans -= 1
            xl[i + 1][0] = [i][0]
            xl[i + 1][1] = [i][1]
            xl[i + 1][2] = [i][2]

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = []
l = []
xl = []
for i in range(n):
    x1, l1 = map(int, input().split())
    xl.append([x1, x1 + l1, 2 * l1])
xl.sort()
ans = n
for i in range(n - 1):
    if xl[i][1] > xl[i + 1][0]:
        if xl[i][2] >= xl[i + 1][2]:
            ans -= 1
        else:
            ans -= 1
            xl[i + 1] = [i]
print(ans)
Problem p02952 (python)

Fixed submission:
n = int(input())
ans = 0
for i in range(1, n + 1):
  cnt = 0
  while i > 0:
    i //= 10
    cnt += 1
  if cnt % 2 != 0:
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
ans = 0
for i in range(1, n + 1):
	cnt = 1
    while True:
  		n //= 10
  		cnt += 1
  		if n < 10:
    		break
	if n % 2 != 0:
      ans += 1
print(ans)
Problem p02972 (python)

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

input_num = [0 for _ in range(n)]

for i in range(n-1, -1, -1):
    tmp = 0
    j = i+i+1
    while j < n:
        tmp += input_num[j]
        j += i+1

    if tmp % 2 != a[i]:
        input_num[i] = 1

print(sum((input_num)))
for i, j in enumerate(input_num):
    if j:
        print(i+1, end=' ')

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
b = [0 for _ in range(n)]
ans = []
for i in range(n, 0, -1):
    if a[i-1] == 0:
        tmp = 0
        j = i * 2
        while j < n:
            # print(j)
            tmp += b[j-1]
            j += i
        if tmp % 2 == 0:
            b[i-1] = 0
        else:
            b[i-1] = 1
    else:
        tmp = 0
        j = i * 2
        while j < n:
            # print(j-1)
            tmp += b[j-1]
            j += i
        if tmp % 2 == 1:
            b[i-1] = 0
        else:
            b[i-1] = 1

for i in range(n):
    if b[i] % 2 != 0:
        # print(b[i]%2)
        ans.append(a[i+1])
# print(b)
print(len(ans))
for i in ans:
    print(i)
Problem p02983 (python)

Fixed submission:
l, r = map(int, input().split())
ans = 10**10
for i in range(l, r+1):
    for j in range(i+1, r+1):
        ans = min(ans, (i*j)%(2019))
        if i*j%2019==0:
            break
    if i*j%2019==0:
        break
print(ans)

Buggy submission (verdict: Runtime Error):
l, r = map(int, input().split())
ans = 10**10
for i in range(l, r):
    for j in range(i+1, r):
        ans = min(ans, (i*j)%(2019))
        if i*j%2019==0:
            break
    if i*j%2019==0:
        break
print(ans)
Problem p02997 (python)

Fixed submission:
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n, k = map(int, input().split())
ans = 0
if n == 2:
    if k == 0:
        print(1)
        print(1, 2)
    else:
        ans = -1
else:
    if k > combinations_count(n - 1, 2):
        ans = -1
    else:
        print(combinations_count(n - 1, 2) - k + n - 1)
        delcnt = combinations_count(n - 1, 2) - k
        cnt = 0
        # print(combinations_count(n - 1, 2), delcnt)
        for i in range(2, n + 1):
            if cnt >= delcnt:
                break
            for j in range(i + 1, n + 1):
                print(i, j)
                cnt += 1
                if cnt >= delcnt:
                    break
            if cnt >= delcnt:
                break
        for i in range(1, n):
            print(1, i + 1)

if ans == -1:
    print(ans)

Buggy submission (verdict: Runtime Error):
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n, k = map(int, input().split())
ans = 0
if 1:
    if k > combinations_count(n - 1, 2):
        ans = -1
    else:
        print(combinations_count(n - 1, 2) - k + n - 1)
        for i in range(combinations_count(n - 1, 2) - k):
            # print(i, combinations_count(n - 1, 2), k)
            print(i + 2, i + 3)
        for i in range(1, n):
            print(1, i + 1)

if ans == -1:
    print(ans)
Problem p03005 (python)

Fixed submission:
n, k = map(int, input().split())
a = 1
b = 1 + (n - k)
if k == 1:
    print(0)
else:
    print(b - a)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = 1
b = 1 + (n - k)
if k == 1:
    print(0)
else:
    print(b - a)
Problem p03007 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
a.sort()
anslist = []
for i in range(1, n - 1):
    if a[i] >= 0:
        anslist.append([a[0], a[i]])
        a[0] -= a[i]
    else:
        anslist.append([a[-1], a[i]])
        a[-1] -= a[i]

anslist.append([a[-1], a[0]])
ans = a[-1] - a[0]
print(ans)
for i, j in anslist:
    print(i, j)
#
# a.sort()
# ans = a[0]
# for i in range(1, n - 1):
#     ans += a[i] * (-1)
#
# print(a[-1] - ans)
# key = a[0]
# for i in range(1, n - 1):
#     print(key, a[i])
#     key = key - a[i]
# print(a[-1], key)

# a.sort()
# plusa = []
# minusa = []
# for i in a[1:-1]:
#     if i < 0:
#         minusa.append(i)
#     else:
#         plusa.append(i)
# #
# # print(minusa, plusa)
# anslist = []
# # if len(a) == 2:
# #     print(max(a) - min(a))
# #     print(max(a), min(a))
# # if min(a) >= 0:
# #     for i in range(1, n - 1):
# #         anslist.append([a[0], a[i]])
# #         a[0] -= a[i]
# #     anslist.append([a[-1], a[0]])
# #     print(a[-1] - a[0])
# #     for i, j in anslist:
# #         print(i, j)
# # else:
# #     if len(plusa) == 0:
# #         plusa.append(minusa[-1])
# #         del minusa[-1]
# #
# #     for i in minusa:
# #         # print(plusa[0], i)
# #         anslist.append([plusa[0], i])
# #         plusa[0] -= i
# #
# #     for i in plusa:
# #         # print(a[0], i)
# #         anslist.append([a[0], i])
# #         a[0] -= i
# #     # print(a[0])
# #     print(a[-1] - a[0])
# #     for i, j in anslist:
# #         print(i, j)
# #     # print(anslist)
# #     print(a[-1], a[0])

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
#
# a.sort()
# ans = a[0]
# for i in range(1, n - 1):
#     ans += a[i] * (-1)
#
# print(a[-1] - ans)
# key = a[0]
# for i in range(1, n - 1):
#     print(key, a[i])
#     key = key - a[i]
# print(a[-1], key)

a.sort()
plusa = []
minusa = []
for i in a[1:-1]:
    if i < 0:
        minusa.append(i)
    else:
        plusa.append(i)
#
# print(minusa, plusa)
anslist = []
if len(plusa) == 0:
    plusa.append(minusa[-1])
    del minusa[-1]

for i in minusa:
    # print(plusa[0], i)
    anslist.append([plusa[0], i])
    plusa[0] -= i

for i in plusa:
    # print(a[0], i)
    anslist.append([a[0], i])
    a[0] -= i
# print(a[0])
print(a[-1] - a[0])
for i, j in anslist:
    print(i, j)
# print(anslist)
print(a[-1], a[0])
Problem p03050 (python)

Fixed submission:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

while True:
    N = int(input())
    ans_list = sorted(make_divisors(N))
    ans = 0
    #print(ans_list)
    for i in ans_list:
        m = N // i - 1
        if N < m * m:
            #print(i)
            #print(N // i - 1)
            ans += (N // i - 1)

    print(ans)
    break

Buggy submission (verdict: Runtime Error):
n = int(input())
i = 1
ans = 0
while i * i <= n:
    m = n / i - 1
    if m == int(m) and n // m == n % m:
        ans += int(m)
    i += 1
print(ans)
Problem p03061 (python)

Fixed submission:
import fractions
n = int(input())
a = list(map(int, input().split()))
if n <= 2:
    print(max(a))
else:
    gcd_left = [a[0]]
    gcd_right = [a[-1]]
    for i in range(1, n):
        gcd_left.append(fractions.gcd(a[i], gcd_left[-1]))
        gcd_right.append(fractions.gcd(a[n-i-1], gcd_right[-1]))
    gcd_right = gcd_right[::-1]
    # print(gcd_left, gcd_right)
    ans = max(gcd_left[-2], gcd_right[1])
    for i in range(n-2):
        ans = max(ans, fractions.gcd(gcd_right[i+2], gcd_left[i]))
    print(ans)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
a = list(map(int, input().split()))
if n <= 2:
    print(max(a))
else:
    gcd_left = [a[0]]
    gcd_right = [a[-1]]
    for i in range(1, n):
        gcd_left.append(math.gcd(a[i], gcd_left[-1]))
        gcd_right.append(math.gcd(a[n-i-1], gcd_right[-1]))
    gcd_right = gcd_right[::-1]
    print(gcd_left, gcd_right)
    ans = max(gcd_left[-2], gcd_right[1])
    for i in range(n-2):
        ans = max(ans, math.gcd(gcd_right[i+2], gcd_left[i]))
    print(ans)

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

this_gcd = max(a)
gcd_list = []

for i in a:
    this_gcd = fractions.gcd(this_gcd, i)

for I in range(len(a)):
    i = a[I]
    tmp = i // this_gcd
    key = 1
    for j in range(2, int(fractions.sqrt(tmp)) + 1):
        if tmp % j == 0:
            key = 0

    if key:
        del a[I]
        break

this_gcd = max(a)
for i in a:
    this_gcd = fractions.gcd(this_gcd, i)

print(this_gcd)

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

this_gcd = max(a)
gcd_list = []

for i in a:
    this_gcd = math.gcd(this_gcd, i)

for I in range(len(a)):
    i = a[I]
    tmp = i // this_gcd
    key = 1
    for j in range(2, int(math.sqrt(tmp)) + 1):
        if tmp % j == 0:
            key = 0

    if key:
        del a[I]
        break

this_gcd = max(a)
for i in a:
    this_gcd = math.gcd(this_gcd, i)

print(this_gcd)
Problem p03074 (python)

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

cnt_list = []
i = 0
if s[0] == "0":
    key = "0"
else:
    key = "1"
last = 0
while i < N:
    j = i
    tmp = 1
    for j in range(i + 1, N):
        if s[j] == key:
            tmp += 1
            if j == N - 1:
                last = 1
        else:
            break

    cnt_list.append([int(key), tmp])

    if key == "0":
        key = "1"
    else:
        key = "0"
    i = max(j, i + 1)
    if last:
        break

cnt = K
i = 0
tmp = 0
while cnt > 0 and i < len(cnt_list):
    tmp += cnt_list[i][1]
    if cnt_list[i][0] == 0:
        cnt -= 1
    i += 1

if i < len(cnt_list):
    tmp += cnt_list[i][1]
    i += 1

anslist = []
anslist.append(tmp)

start = 0
while i < len(cnt_list) and start < len(cnt_list):
    if cnt_list[start][0] == 1:
        tmp -= cnt_list[start][1]
        if start + 1 < len(cnt_list):
            tmp -= cnt_list[start + 1][1]
        start += 2
    else:
        tmp -= cnt_list[start][1]
        start += 1

    if cnt_list[i][0] == 0:
        tmp += cnt_list[i][1]
        if i + 1 < len(cnt_list):
            tmp += cnt_list[i + 1][1]
        i += 2
    else:
        tmp += cnt_list[i][1]
        i += 1
    anslist.append(tmp)

print(max(anslist))

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

cnt = 1
cntlist = []
for i in range(1, N):
    if s[i - 1] != s[i]:
        cntlist.append(cnt)
        cnt = 1
    else:
        cnt += 1

cntlist.append(cnt)
if s[0] == "0":
    cntlist = [0] + cntlist

ans = 0
for i in range(2 * K + 1):
    if i >= len(cntlist):
        break
    ans += cntlist[i]
anslist = [ans]
s = 0
g = 2 * K + 1
while g < len(cntlist):
    ans -= cntlist[s]
    ans -= cntlist[s + 1]
    s += 2
    ans += cntlist[g]
    g += 1

    ans += cntlist[g]
    if g >= len(cntlist):
        break
    g += 1
    anslist.append(ans)

print(max(anslist))
Problem p03129 (python)

Fixed submission:
def a():
    n, k = map(int, input().split())
    if int(n / 2 + 0.5) >= k:
        print("YES")
    else:
        print("NO")
a()

Buggy submission (verdict: Runtime Error):
def a():
    n, k = map(int, input().split())
    if n - 1 >= K:
        print("YES")
    else:
        print("NO")
a()
Problem p03212 (python)

Fixed submission:
def C3():
    tmp = []
    import  copy

    for i in range(9):
        tmp.append([])
        tmp[i].append(3 * pow(10, i))
        tmp[i].append(5 * pow(10, i))
        tmp[i].append(7 * pow(10, i))

    tmp2 = [copy.copy(tmp[0])]
    for i in range(1, 9):
        tmp2.append([])
        for j in range(3):
            k = 0
            while True:
                if len(tmp2[i - 1]) <= k:
                    break
                tmp2[i].append(tmp[i][j] + tmp2[i - 1][k])
                k += 1
    N = int(input())
    tmp3 = []
    for i in range(2, 9):
        for j in range(len(tmp2[i])):
            tmp3.append(tmp2[i][j])
    ans = 0
    for i in tmp3:
        s = 0
        f = 0
        t = 0
        for j in list(str(i)):
            if j == "7":
                s += 1
            if j == "5":
                f += 1
            if j == "3":
                t += 1
        if s != 0 and t != 0 and f != 0 and int(i) <= N:
            ans += 1
    print(ans)

C3()

Buggy submission (verdict: Runtime Error):
def C3():
    tmp = []
    import  copy

    for i in range(9):
        tmp.append([])
        tmp[i].append(3 * pow(10, i))
        tmp[i].append(5 * pow(10, i))
        tmp[i].append(7 * pow(10, i))

    tmp2 = [copy.copy(tmp[0])]
    for i in range(1, 9):
        tmp2.append([])
        for j in range(3):
            k = 0
            while True:
                if len(tmp2[i - 1]) <= k:
                    break
                tmp2[i].append(tmp[i][j] + tmp2[i - 1][k])
                k += 1
    tmp3 =
Problem p03231 (python)

Fixed submission:
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

def AGC028A():
    N, M = map(int, input().split())
    S = input()
    T = input()

    key = lcm(N, M)
    n = key // N
    m = key // M
    n_list = []
    for i in range(0, key, n):
        n_list.append(i)
    m_list = []
    for j in range(0, key, m):
        m_list.append(j)

    #print(n_list, m_list)
    i = 0
    j = 0
    while True:
        if i >= len(n_list) or j >= len(m_list):
            break
        if i >= len(S) or j >= len(T):
            break
        if n_list[i] == m_list[j]:
            if S[i] != T[j]:
                print(-1)
                return 0
        if n_list[i] > m_list[j]:
            j += 1
        elif n_list[i] < m_list[j]:
            i += 1
        else:
            i += 1
            j += 1
    print(key)

AGC028A()

Buggy submission (verdict: Runtime Error):
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

def AGC028A():
    N, M = map(int, input().split())
    S = input()
    T = input()
    if len(S) < len(T):
        S, T = T, S
    if lcm(N, M) == max(N, M) and S[0:len(T)] == T:
        print(-1)
        return 0
    key = lcm(N, M)
    n = key // N
    m = key // M
    n_list = []
    for i in range(0, key, n):
        n_list.append(i)
    m_list = []
    for j in range(0, key, m):
        m_list.append(j)
    i = 0
    j = 0
    while True:
        if i >= len(n_list) or j >= len(m_list):
            break
        if n_list[i] == m_list[j]:
            if S[i] != T[j]:
                print(-1)
                return 0
        if n_list[i] > m_list[j]:
            j += 1
        elif n_list[i] < m_list[j]:
            i += 1
        else:
            i += 1
            j += 1
    print(key)

AGC028A()
Problem p03240 (python)

Fixed submission:
N = int(input())
xyh = [list(map(int, input().split())) for i in range(N)]
key = False
for CX in range(101):
    for CY in range(101):
        ans = True
        H = -1
        for x, y, h in xyh:
            if h > 0:
                tmp = h + abs(x - CX) + abs(y - CY)
                if H == -1:
                    H = tmp
                else:
                    if H != tmp:
                        H = -2
                        break

        if H == -2:
            continue

        for x, y, h in xyh:
            if h == 0:
                dist = abs(x - CX) + abs(y - CY)
                if H > dist:
                    H = -2
                    break
                
        if H == -2:
            continue
        
        print(CX, CY, H)
        key = True
        break
        
    if key:
        break

Buggy submission (verdict: Runtime Error):
N = int(input())
xyh = [list(map(int, input().split())) for i in range(N)]

for CX in range(101):
    for CY in range(101):
        ans = True
        i = 0
        for x, y, h in xyh:
            if h != 0:
                if i == 0:
                    H = h + abs(x - CX) + abs(y - CY)
                if H != h + abs(x - CX) + abs(y - CY):
                    ans = False
                    break
            i += 1
            if not ans:
                break
        for x, y, h in xyh:
            if not ans:
                break
            if h == 0:
                if h != max(H - abs(x - CX) + abs(y - CY), 0):
                    ans = False
        if ans:
            print(CX, CY, H)
    if ans:
        break
Problem p03241 (python)

Fixed submission:
N, M = map(int, input().split())
ans = 1

S = M / N
S = int(S)
#print(S)
import math
if N == 1:
    ans = M
else:
    not_sosu = -1
    for i in range(2, int(math.sqrt(M)) + 1):
        if M % i == 0:
            not_sosu = 1
            if M / i >= N and M % i == 0:
                ans = max(ans, i)
            j = M // i
            if M / j >= N and M % j == 0:
                ans = max(ans, j)
            #print(i)
    if not_sosu == -1:
        ans = 1


if N == 1:
    ans = M

print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
for i in range(1, M):
    if M / i < N:
        break
    if M % i == 0:
        ans = i
print(ans)
Problem p03262 (python)

Fixed submission:
import fractions
N, X = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
if N > 1:
    mini = x[1] - x[0]
    if mini > abs(X - x[0]) and abs(X - x[0]) != 0:
        mini = abs(X - x[0])
elif N == 1:
    mini = abs(x[0] - X)
for i in range(1, N):
    if mini > x[i] - x[i - 1]:
        mini = x[i] - x[i - 1]
    if mini> abs(X - x[i]) and abs(X - x[i]) != 0:
        mini = abs(X - x[i])
    if (x[i] - x[i - 1]) % mini != 0:
        #break
        mini = fractions.gcd(mini, x[i] - x[i - 1])
    if abs(X - x[i]) % mini != 0:
        #break
        mini = fractions.gcd(mini, X - x[i])
        

print(mini)

Buggy submission (verdict: Runtime Error):
import fraction
N, X = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
if N > 1:
    mini = x[1] - x[0]
    if mini > abs(X - x[0]) and abs(X - x[0]) != 0:
        mini = abs(X - x[0])
elif N == 1:
    mini = abs(x[0] - X)
for i in range(1, N):
    if mini > x[i] - x[i - 1]:
        mini = x[i] - x[i - 1]
    if mini> abs(X - x[i]) and abs(X - x[i]) != 0:
        mini = abs(X - x[i])
    if (x[i] - x[i - 1]) % mini != 0:
        #break
        mini = fraction.gcd(mini, x[i] - x[i - 1])
    if abs(X - x[i]) % mini != 0:
        #break
        mini = fraction.gcd(mini, X - x[i])
        

print(mini)

Buggy submission (verdict: Runtime Error):
import math
N, X = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
if N > 1:
    mini = x[1] - x[0]
    if mini > abs(X - x[0]) and abs(X - x[0]) != 0:
        mini = abs(X - x[0])
elif N == 1:
    mini = abs(x[0] - X)
for i in range(1, N):
    if mini > x[i] - x[i - 1]:
        mini = x[i] - x[i - 1]
    if mini> abs(X - x[i]) and abs(X - x[i]) != 0:
        mini = abs(X - x[i])
    if (x[i] - x[i - 1]) % mini != 0:
        #break
        mini = math.gcd(mini, x[i] - x[i - 1])
    if abs(X - x[i]) % mini != 0:
        #break
        mini = math.gcd(mini, X - x[i])
        

print(mini)

Buggy submission (verdict: Runtime Error):
import math
N, X = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
if N > 1:
    mini = min([x[1] - x[0],  abs(X - x[0])])
elif N == 1:
    mini = abs(x[0] - X)
for i in range(1, N):
    if mini > min([x[i] - x[i - 1], abs(X - x[i])]):
        mini = min([x[i] - x[i - 1], abs(X - x[i])])
    if (x[i] - x[i - 1]) % mini != 0:
        mini = math.gcd(mini, x[i] - x[i - 1])
    if abs(X - x[i]) % mini != 0:
        mini = math.gcd(mini, X - x[i])
        

print(mini)
Problem p03274 (python)

Fixed submission:
N, K = map(int, input().split())
x = list(map(int, input().split()))
dis = []
for i in range(N - K + 1):
    dis.append(abs(x[i] - x[i + K - 1]) + abs(x[i]))
    dis.append(abs(x[i] - x[i + K - 1]) + abs(x[i + K - 1]))
print(min(dis))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
x = list(map(int, input().split()))
dis = []
for i in range(N - K + 1):
    dis.append(abs(x[i] - x[i + K - 1]) + abs(x[i]))
    dis.append(abs(x[i] - x[i + K - 1]) + abs(x[i + k - 1]))
print(min(dis))
Problem p03282 (python)

Fixed submission:
S = input()
K = int(input())
key = 0
i = 0
while True:
    if i >= K:
        break
    if i >= len(S):
        break
    if int(S[i]) != 1:
        print(S[i])
        key = 1
        break
    i += 1

if key == 0:
    print(S[0])

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
key = 1
i = 0
while True:
    if i > 100:
        break
    if int(S[i]) != 1:
        print(S[i])
        key = 1
        break
    i += 1

if key == 0:
    print(S[0])

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
key = 1
i = 0
while True:
    if int(S[i]) != 1:
        print(S[i])
        key = 1
        break
    i += 1

if key == 0:
    print(S[0])
Problem p03287 (python)

Fixed submission:
import math
def PC(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def ncr(n, r):
    r = min(r, n - r)
    if r == 0: return 1;
    if r == 1: return n;
    numerator = [n - r + i + 1 for i in range(r)]
    denominator  = [i + 1 for i in range(r)]
    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1: 
            result *= numerator[k]
    return int(result)

#kaijou = [0, 1]
#for i in range(2, 1000):
 #   kaijou.append(kaijou[i - 1] * i)

#print(kaijou[0:10])

N, M = map(int, input().split())
A = list(map(int, input().split()))
B = []
j = 0
for i in A:
    if j == 0:
        B.append(i)
    else:
        B.append(B[j - 1] + i)
    j += 1
for i in range(len(B)):
    B[i] = B[i] % M
C = sorted(B)
anscnt = 0
samecnt = 1
for i in range(len(C)):
    if C[i] == 0:
        anscnt += 1
    if i != 0:
        if C[i] == C[i - 1]:
            samecnt += 1
        elif samecnt != 1:
            anscnt += ncr(samecnt, 2)
            samecnt = 1
        if i == len(C) - 1 and samecnt != 1:
            anscnt += ncr(samecnt, 2)
            samecnt = 1
print(anscnt)

Buggy submission (verdict: Runtime Error):
import math
def PC(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = []
j = 0
for i in A:
    if j == 0:
        B.append(i)
    else:
        B.append(B[j - 1] + i)
    j += 1
for i in range(len(B)):
    B[i] = B[i] % M
C = sorted(B)
anscnt = 0
samecnt = 1
for i in range(len(C)):
    if C[i] == 0:
        anscnt += 1
    if i != 0:
        if C[i] == C[i - 1]:
            samecnt += 1
        elif samecnt != 1:
            anscnt += PC(samecnt, 2)
            samecnt = 1
        if i == len(C) - 1:
            anscnt += PC(samecnt, 2)
            samecnt = 1
print(anscnt)