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

Fixed submission:
import sys
from collections import defaultdict


sys.setrecursionlimit(10**6)


def pair2index(i, j, N):
    return N * i + j


def main():
    N = int(input())
    adj = defaultdict(list)
    for i in range(N):
        A = list(map(lambda x: int(x) - 1, input().split(' ')))
        for j in range(1, N - 1):
            a = A[j - 1]
            from_index = pair2index(min(i, a), max(i, a), N)
            a = A[j]
            to_index = pair2index(min(i, a), max(i, a), N)
            adj[from_index].append(to_index)

    temp_visited = [0 for _ in range(N**2)]
    max_depth = [0 for _ in range(N**2)]

    def dfs(n):
        if temp_visited[n] == 1:
            # 閉路あり
            max_depth[n] = -1
            return -1
        elif max_depth[n] != 0:
            return max_depth[n]
        else:   # max_depth[n] == 0 (未探索)
            temp_visited[n] = 1
            max_d = 0
            for next_n in adj[n]:
                d = dfs(next_n)
                if d == -1:
                    return d
                max_d = max(max_d, d)
            temp_visited[n] = 0
            max_depth[n] = max_d + 1
            return max_d + 1

    ans = 0
    for i in range(N - 1):
        for j in range(i + 1, N):
            node = pair2index(i, j, N)
            depth = dfs(node)
            if depth == -1:
                print(-1)
                return
            ans = max(ans, depth)
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from collections import defaultdict


def pair2index(i, j, N):
    return N * i + j


def main():
    N = int(input())
    adj = defaultdict(list)
    for i in range(N):
        A = list(map(lambda x: int(x) - 1, input().split(' ')))
        for j in range(1, N - 1):
            a = A[j - 1]
            from_index = pair2index(min(i, a), max(i, a), N)
            a = A[j]
            to_index = pair2index(min(i, a), max(i, a), N)
            adj[from_index].append(to_index)

    temp_visited = [0 for _ in range(N**2)]
    max_depth = [0 for _ in range(N**2)]

    def dfs(n):
        if temp_visited[n] == 1:
            # 閉路あり
            max_depth[n] = -1
            return -1
        elif max_depth[n] != 0:
            return max_depth[n]
        else:   # max_depth[n] == 0 (未探索)
            temp_visited[n] = 1
            max_d = 0
            for next_n in adj[n]:
                d = dfs(next_n)
                if d == -1:
                    return d
                max_d = max(max_d, d)
            temp_visited[n] = 0
            max_depth[n] = max_d + 1
            return max_d + 1

    ans = 0
    for i in range(N - 1):
        for j in range(i + 1, N):
            node = pair2index(i, j, N)
            depth = dfs(node)
            if depth == -1:
                print(-1)
                return
            ans = max(ans, depth)
    print(ans)


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

Fixed submission:
N, X, M = map(int, input().split())
a = [0 for i in range(M+1)]
b = [X]
a[X-1] = 1

for i in range(min(N-1, M)):
  X = X**2%M
  a[X-1] += 1
  b.append(X)
  if a[X-1] > 1:
    break

if len(b) == N:
  print(sum(b))

else:
  ls = b.index(b[-1])
  bloop = b[ls:-1]
  ans = 0
  if ls > 0:
    for i in range(ls):
      ans += b[i]
  loop = (N-ls)//len(bloop)
  ans += sum(bloop) * loop
  if (N-ls)%len(bloop) != 0:
    for i in range((N-ls)%len(bloop)):
      ans += bloop[i]
  print(ans)

Buggy submission (verdict: Runtime Error):
N, X, M = map(int, input().split())
a = [0 for i in range(M+1)]
b = [X]
a[X-1] = 1

for i in range(min(N, M)):
  X = X**2%M
  a[X-1] += 1
  b.append(X)
  if a[X-1] > 1:
    break

if len(b) == N:
  print(sum(b))

else:
  ls = b.index(b[-1])
  bloop = b[ls:-1]
  ans = 0
  if ls > 0:
    for i in range(ls):
      ans += b[i]
  loop = (N-ls)//len(bloop)
  ans += sum(bloop) * loop
  if (N-ls)%len(bloop) != 0:
    for i in range((N-ls)%len(bloop)):
      ans += bloop[i]
  print(ans)

Buggy submission (verdict: Runtime Error):
N, X, M = map(int, input().split())
a = [0 for i in range(M)]
b = [X]
a[X-1] = 1

for i in range(min(N, M)):
  X = X**2%M
  a[X-1] += 1
  b.append(X)
  if a[X-1] > 1:
    break

if len(b) == N:
  print(sum(b))

else:
  ls = b.index(b[-1])
  bloop = b[ls:-1]
  ans = 0
  if ls > 0:
    for i in range(ls):
      ans += b[i]
  loop = (N-ls)//len(bloop)
  ans += sum(bloop) * loop
  if (N-ls)%len(bloop) != 0:
    for i in range((N-ls)%len(bloop)):
      ans += bloop[i]
  print(ans)
Problem p02598 (python)

Fixed submission:
def round_up_division(num1, num2):
# 切り上げ除算
  div = -(-num1 // num2)
  return div

def binary_search(search_range, max_num, logs):
  search_min = 1
  search_max = search_range
  # 二分探索
  while True:
    # max_numを超えない最大回数にする
    count_a = 0
    # count_aより1短い長さ
    count_b = 0
    # 最小値と最大値の中間の値を出す
    half_num = (search_min + search_max - 1) // 2 + 1
    for i in range(logs):
      # 木を切る回数は(⌈(木の長さ)//(切りたい長さ)⌉-1)回
      count_a += round_up_division(A[i], half_num) - 1
      if half_num != 1:
        count_b += round_up_division(A[i], half_num - 1) - 1
    if count_a > K:
      # 多ければ長い半分で探索
      search_min = round_up_division(search_min + search_max, 2)
    elif half_num != 1 and count_b <= K:
      # 少なければ短い半分で探索
      search_max = half_num - 1
    else:
      # count_aが最大になれば終了
      return half_num
      break

N, K = map(int, input().split())
A = list(map(int, input().split()))
length_max = binary_search(max(A), K, N)
print(length_max)

Buggy submission (verdict: Runtime Error):
def round_up_division(num1, num2):
# 切り上げ除算
  div = -(-num1 // num2)
  return div

def binary_search(search_range, max_num, logs):
  search_min = 1
  search_max = search_range
  # 二分探索
  while True:
    # max_numを超えない最大回数にする
    count_a = 0
    # count_aより1短い長さ
    count_b = 0
    # 最小値と最大値の中間の値を出す
    half_num = (search_min + search_max - 1) // 2 + 1
    for i in range(logs):
      # 木を切る回数は(⌈(木の長さ)//(切りたい長さ)⌉-1)回
      count_a += round_up_division(A[i], half_num) - 1
      count_b += round_up_division(A[i], half_num - 1) - 1
    if count_a <= K and count_b > K:
      # count_aが最大になれば終了
      return half_num
      break
    elif count_b <= K:
      # 少なければ短い半分で探索
      search_max = half_num - 1
    else:
      # 多ければ長い半分で探索
      search_min = round_up_division(search_min + search_max, 2) + 1



N, K = map(int, input().split())
A = list(map(int, input().split()))
length_max = binary_search(max(A), K, N)
print(length_max)

Buggy submission (verdict: Runtime Error):
def round_up_division(num1, num2):
# 切り上げ除算
  div = -(-num1 // num2)
  return div

def binary_search(search_range, max_num):
  search_min = 1
  search_max = search_range
  # 二分探索
  while True:
    # max_numを超えない最大回数にする
    count_a = 0
    # count_aより1短い長さ
    count_b = 0
    # 最小値と最大値の中間の値を出す
    half_num = (search_min + search_max - 1) // 2 + 1
    for i in range(len(A)):
      # 木を切る回数は(⌈(木の長さ)//(切りたい長さ)⌉-1)回
      count_a += round_up_division(A[i], half_num) - 1
      count_b += round_up_division(A[i], half_num - 1) - 1
    if count_a <= K and count_b > K:
      # count_aが最大になれば終了
      return half_num
      break
    elif count_b <= K:
      # 少なければ短い半分で探索
      search_max = half_num - 1
    else:
      # 多ければ長い半分で探索
      search_min = round_up_division(search_min + search_max, 2) + 1



N, K = map(int, input().split())
A = list(map(int, input().split()))
length_max = binary_search(max(A), K)
print(length_max)
Problem p02623 (python)

Fixed submission:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
time_of_A = [A[0]]
for i in range(1, N):
  time_of_A.append(time_of_A[i-1]+A[i])
B = list(map(int, input().split()))
time_of_B = [B[0]]
for i in range(1, M):
  time_of_B.append(time_of_B[i-1]+B[i])

book = [0]
for i in range(N):
  if time_of_A[i] <= K:
    book.append(i+1)
for i in range(M):
  if time_of_B[i] <= K:
    book.append(i+1)


start = M-1
for i in range(N):
  j = start
  time = 10 ** 9 + 1
  while time > K and j >= 0:
    time = time_of_A[i] + time_of_B[j]
    j -= 1
  if time <= K:
    book.append(i+j+3)
    j +=1
    start = j
  else:
    break
print(max(book))

Buggy submission (verdict: Runtime Error):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
time_of_A = [A[0]]
for i in range(1, N):
  time_of_A.append(time_of_A[i-1]+A[i])
B = list(map(int, input().split()))
time_of_B = [B[0]]
for i in range(1, M):
  time_of_B.append(time_of_B[i-1]+B[i])

book = []
for i in range(N):
  if time_of_A[i] <= K:
    book.append(i+1)

start = M-1
for i in range(N):
  j = start
  time = 10 ** 9 + 1
  while time > K and j >= 0:
    time = time_of_A[i] + time_of_B[j]
    j -= 1
  if time <= K:
    book.append(i+j+3)
    j +=1
    start = j
  else:
    break
print(max(book))
Problem p02577 (python)

Fixed submission:
N = int(input())
if N%9 == 0:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
N = input()
N_list = []
for i in range(N):
  N_list.append(N[i])
if sum(N_list) %9 == 0:
  print("Yes")
else:
  print("No")
Problem p02578 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
x = [0 for _ in range(N)]
for i in range(1,N):
  if A[i] < A[i-1] + x[i-1]:
    x[i] = A[i-1] + x[i-1] - A[i]
print(sum(x))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
x = [0 for _ in range(N)]
for i in range(1,N):
  if A[i] < A[i-1] + x[i-1]:
    x[i] = A[i-1] + x[i-1] - A[i]
print(sum(x_list))
Problem p02594 (python)

Fixed submission:
X = int(input())
if X >= 30:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
a = int(input())
if a >= 30:
  return "Yes"
else:
  return "No"
Problem p02623 (python)

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

total = 0
count = 0
flag = n-1
for i in range(n):
    total += a[i]
    if total > k:
        total -= a[i]
        flag = i-1
        break
    count += 1
ans = count
for i in range(m):
    if b[i] > k:
        break
    total += b[i]
    count += 1
    while total > k:
        if flag == -1:
            break
        else:
            total -= a[flag]
            flag -= 1
            count -= 1
    if total > k: 
        break
    ans = max(ans, count)

total = 0
count = 0
flag = m-1
for i in range(m):
    total += b[i]
    if total > k:
        total -= b[i]
        flag = i-1
        break
    count += 1
for i in range(n):
    if a[i] > k:
        break
    total += a[i]
    count += 1
    while total > k:
        if flag == -1:
            break
        else:
            total -= b[flag]
            flag -= 1
            count -= 1
    if total > k: 
        break
    ans = max(ans, count)


print(ans)

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

total = 0
count = 0
flag = len(a) - 1
for i in range(n):
    total += a[i]
    if total > k:
        total -= a[i]
        flag = i
        break
    count += 1
ans = count
for i in range(m):
    if b[i] > k:
        break
    total += b[i]
    count += 1
    while total > k:
        total -= a[flag]
        flag -= 1
        count -= 1
    ans = max(ans, count)

print(ans)
Problem p03013 (python)

Fixed submission:
n, m = map(int,input().split())
hole = [int(input()) for _ in range(m)]
k = 0
a, b = 0, 0
x = (10 ** 9 + 7)
for i in range(n):
    if m >= 1:
        if i + 1 == hole[k]:
            a, b = 0, a
        else:
            if i == 0:
                a = 1
            elif i == 1:
                a, b = (a + 1) % x, a % x
            else:
                a, b = (a + b) % x, a % x
        if i + 1 >= hole[k] and k < m - 1:
            k += 1
    else:
        if i == 0:
                a = 1
        elif i == 1:
            a, b = (a + 1) % x, a % x
        else:
            a, b = (a + b) % x, a % x
    
print(a)

Buggy submission (verdict: Runtime Error):
n, m = map(int,input().split())
hole = [int(input()) for _ in range(m)]
k = 0
a, b = 0, 0
x = (10 ** 9 + 7)
for i in range(n):
    if i + 1 == hole[k]:
        a, b = 0, a
    else:
        if i == 0:
            a = 1
        elif i == 1:
            a, b = (a + 1) % x, a % x
        else:
            a, b = (a + b) % x, a % x
    if i + 1 >= hole[k] and k < m - 1:
        k += 1

    
print(a)
Problem p03745 (python)

Fixed submission:
n = int(input())
nums = list(map(int,input().split()))
ans = 0
i = 0

while i < n:
    j, k = i, i
    while j < n - 1 and nums[j] <= nums[j+1]:
        j += 1
    while k < n - 1 and nums[k] >= nums[k+1]:
        k += 1
    i = max(j , k) + 1
    ans += 1
print(ans)

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

if nums[1] >= nums[0]:
    flag = 1
else:
    flag = 2

i = 1
while i < n:
    if flag == 0:
        if nums[i] > nums[i-1]:
            flag = 1
            ans += 1
        else:
            flag = 2
            ans += 1

    elif flag == 1:
        if nums[i] < nums[i-1]:
            flag = 0
            if i == n-1:
                ans += 1
    elif flag == 2:
        if nums[i] > nums[i-1]:
            flag = 0
            if i == n-1:
                ans += 1

    i += 1

print(ans)
Problem p03835 (python)

Fixed submission:
K, S = map(int,input().split())
ans = 0
for i in range(K+1):
    for j in range(K+1):
            if 0 <= S - i - j <= K:
                ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
K, S = map(int,input())
print(S//K)
Problem p02571 (python)

Fixed submission:
S = input()
T = input()
list_a = []
if len(S) - len(T) ==0:
    cnt = 0
    for j in range(len(T)):
        if T[j] != S[j]:
            cnt += 1
    list_a.append(cnt)
else:
    for i in range(len(S) - len(T)):
        cnt = 0
        for j in range(len(T)):
            if T[j] != S[i + j]:
                cnt += 1
        list_a.append(cnt)
print(min(list_a))

Buggy submission (verdict: Runtime Error):
import sys
list_a = []
S = input()
T = input()
if T in S:
    print(0)
    sys.exit()
for i in range(len(S) - len(T)):
    cnt = 0
    for j in range(len(T)):
        if T[j] != S[i + j]:
            cnt += 1
    list_a.append(cnt)
print(min(list_a))

Buggy submission (verdict: Runtime Error):
list_ = []
S = input()
T = input()
for i in range(len(S) - len(T)):
    cnt = 0
    for j in range(len(T)):
        if T[j] != S[i + j]:
            cnt += 1
    list_.append(cnt)
print(min(list_))
Problem p02701 (python)

Fixed submission:
N = int(input())
S = []
for j in range(N):
    S.append(input())
print(len(set(S)))

Buggy submission (verdict: Runtime Error):
N = int(input())
S = []
for j in range(N):
    S[j]= input()
print(len(set(S)))
Problem p02771 (python)

Fixed submission:
# https://atcoder.jp/contests/abc155/tasks/abc155_a

A,B,C = map(int,input().split())

S = set([A,B,C])

if len(S) == 2:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
N = int(input())
S_list = []
for _ in range(N):
    S_list.append(input())

S_dict = {}
for s in S_list:
    S_dict[s]=0
for s in S_list:
    S_dict[s]+=1

max_kv = max(S_dict.values())

max_k_list = [kv[0] for kv in S_dict.items() if kv[1] == max_kv]
max_k_list.sort()
for k in max_k_list:
    print(k)
Problem p02773 (python)

Fixed submission:
def main():
    N = int(input())
    S_list = []
    for _ in range(N):
        S_list.append(input())

    S_dict = {}
    for s in S_list:
        S_dict[s]=0
    for s in S_list:
        S_dict[s]+=1

    max_v = max(S_dict.values())

    max_k_list = [kv[0] for kv in S_dict.items() if kv[1] == max_v]
    max_k_list.sort()
    for k in max_k_list:
        print(k)

if __name__ == '__main__':
     main()

Buggy submission (verdict: Runtime Error):
# https://atcoder.jp/contests/abc155/tasks/abc155_c

def main():
    N = int(input())
    S_list = []
    for _ in range(N):
        S_list.append(input())

    S_dict = {}
    for s in S_list:
        S_dict[s]=0
    for s in S_list:
        S_dict[s]+=1



    max_k_list = [kv[0] for kv in S_dict.items() if kv[1] == max(S_dict.values())]
    max_k_list.sort()
    for k in max_k_list:
        print(k)

if __name__ == '__main__'
     main()

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input())
    S_list = []
    for _ in range(N):
        S_list.append(input())

    S_dict = {}
    for s in S_list:
        S_dict[s]=0
    for s in S_list:
        S_dict[s]+=1

    max_kv = max(S_dict.values())

    max_k_list = [kv[0] for kv in S_dict.items() if kv[1] == max_kv]
    max_k_list.sort()
    for k in max_k_list:
        print(k)

if __name__ == '__main__'
     main()
Problem p02549 (python)

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

D = [list(map(int,input().split())) for _ in range(K)]
D.sort()

dp = [0]*N
dp[0] = 1
if D[0][0]<N:
    dp[D[0][0]] = 1

    for n in range(D[0][0],N-1):
        dp[n+1] = dp[n]
        for i in range(K):
            L,R = D[i]
            if n-L+1>=0:
                dp[n+1] += dp[n-L+1]
            if n-R+1>0:
                dp[n+1] -= dp[n-R]
            dp[n+1] %= mod
print(dp[N-1])

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

D = [list(map(int,input().split())) for _ in range(K)]
D.sort()

dp = [0]*N
dp[0] = 1
dp[D[0][0]] = 1

for n in range(D[0][0],N-1):
    dp[n+1] = dp[n]
    for i in range(K):
        L,R = D[i]
        if n-L+1>=0:
            dp[n+1] += dp[n-L+1]
        if n-R+1>0:
            dp[n+1] -= dp[n-R]
        dp[n+1] %= mod
print(dp[N-1])
Problem p02550 (python)

Fixed submission:
from collections import defaultdict
N,X,M = map(int,input().split())
ans = 0
d = defaultdict(lambda:-1)
x = X%M
for n in range(M+100):
    if x in d:
        T = n-d[x]
        break
    else:
        d[x] = n
    x *= x
    x %= M
p = 0
y = x
for m in range(d[x],n):
    p += y
    y *= y
    y %= M

ans = 0
n = N
z = X%M
while n:
    ans += z
    n -= 1
    z *= z
    z %= M
    if z==x:
        ans += n//T*p
        n %= T
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
N,X,M = map(int,input().split())
ans = 0
d = defaultdict(lambda:-1)
x = X%M
for n in range(M):
    if x in d:
        T = n-d[x]
        break
    else:
        d[x] = n
    x *= x
    x %= M
p = 0
y = x
for m in range(d[x],n):
    p += y
    y *= y
    y %= M

ans = 0
n = N
z = X%M
while n:
    ans += z
    n -= 1
    z *= z
    z %= M
    if z==x:
        ans += n//T*p
        n %= T
print(ans)
Problem p02590 (python)

Fixed submission:
import numpy as np
from numpy.fft import rfft,irfft

p = 200003
N = int(input())
A = list(map(int,input().split()))
a = np.zeros(p-1)

g = 1
d = {}
p2 = [1]*(p-1)
for i in range(p-1):
    d[g] = i
    p2[i] = g
    g *= 2
    g %= p

for i in range(N):
    if A[i]==0:
        continue
    a[d[A[i]]] += 1

b = rfft(a,2*p-2)
b = irfft(b*b,2*p-2)
b = np.rint(b).astype(np.int64)

ans = 0
for i in range(p-1):
    ans += (b[i]+b[i+p-1])*p2[i]

for i in range(N):
    ans -= A[i]**2%p
ans //= 2
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
from numpy.fft import rfft,irfft

p = 200003
N = int(input())
A = list(map(int,input().split()))
a = np.zeros(p-1)

g = 1
d = {}
p2 = [1]*p
for i in range(p):
    d[g] = i
    p2[i] = g
    g *= 2
    g %= p

for i in range(N):
    if A[i]==0:
        continue
    a[d[A[i]]] += 1

b = rfft(a,2*p-2)
b = irfft(b*b,2*p-2)
b = np.rint(b).astype(np.int64)

ans = 0
for i in range(p-1):
    ans += (b[i]+b[i+p-1])*p2[i]

for i in range(N):
    ans -= A[i]**2%p
ans //= 2
print(ans)
Problem p02598 (python)

Fixed submission:
from math import ceil
N,K = map(int,input().split())
A = list(map(int,input().split()))

def possible(l):
    if l==0:
        return False
    c = 0
    for i in range(N):
        if A[i]%l==0:
            n = A[i]//l-1
        else:
            n = A[i]//l
        c += n
    return c<=K

l = 0
r = max(A)
m = (l+r)/2
for i in range(32):
    pos = possible(m)
    if pos:
        r = m
    else:
        l = m
    m = (l+r)/2

if possible(int(m)):
    print(int(m))
else:
    print(ceil(m))

Buggy submission (verdict: Runtime Error):
from math import ceil
N,K = map(int,input().split())
A = list(map(int,input().split()))

def possible(l):
    c = 0
    for i in range(N):
        n = A[i]//l
        c += n
    return c<=K

l = 0
r = max(A)
m = (l+r)/2
for i in range(32):
    pos = possible(m)
    if pos:
        r = m
    else:
        l = m
    m = (l+r)/2

ans = ceil(m)
if possible(ans-1):
    ans -= 1
print(ans)
Problem p02623 (python)

Fixed submission:
from bisect import bisect
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

a = [0]*N
for i in range(N):
    a[i] = A[i]+a[i-1]
b = [0]*M
for i in range(M):
    b[i] = B[i]+b[i-1]
a = [0]+a
b = [0]+b
ans = 0
for i in range(N+1):
    c = a[i]
    if K-c>=0:
        j = bisect(b,K-c)
        ans = max(ans,i+j-1)
print(ans)

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

a = [0]*N
for i in range(N):
    a[i] = A[i]+a[i-1]
b = [0]*M
for i in range(M):
    b[i] = B[i]+b[i-1]
a = [0]+a
b = [0]+b
ans = 0
for i in range(N+1):
    c = a[i]
    if K-c>=0:
        j = bisect(b,K-c)
        ans = max(ans,i+j-1)
print(ans)
Problem p02679 (python)

Fixed submission:
mod = 1000000007
from collections import defaultdict
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]
d1 = defaultdict(lambda:0)
d2 = defaultdict(lambda:0)
ca = 0
cb = 0
cc = 0
for i in range(N):
    a,b = AB[i]
    if a==0 and b!=0:
        ca += 1
        continue
    elif a!=0 and b==0:
        cb += 1
        continue
    elif a==0 and b==0:
        cc += 1
        continue
    a_ = abs(a)
    b_ = abs(b)
    d = gcd(a,b)
    if d != 0:
        a //= d
        b //= d
    if a < 0:
        a *= -1
        b *= -1
    if b>0:
        d1[(a,b)] += 1
    else:
        d2[(a,b)] += 1
        d1[(-b,a)] += 0

ans = pow(2,ca)+pow(2,cb)-1
for a,b in d1:
    x = d1[(a,b)]
    y = d2[(b,-a)]
    ans *= pow(2,x,mod)+pow(2,y,mod)-1
    ans %= mod
ans -= 1
ans += cc
ans %= mod
print(ans)

Buggy submission (verdict: Runtime Error):
mod = 1000000007
from collections import defaultdict
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]
d1 = defaultdict(lambda:0)
d2 = defaultdict(lambda:0)
for i in range(N):
    a,b = AB[i]
    a_ = abs(a)
    b_ = abs(b)
    d = gcd(a,b)
    a //= d
    b //= d
    if a < 0:
        a *= -1
        b *= -1
    if b>=0:
        d1[(a,b)] += 1
    else:
        d2[(a,b)] += 1
        d1[(-b,a)] += 0

ans = 1
for a,b in d1:
    x = d1[(a,b)]
    y = d2[(b,-a)]
    ans *= pow(2,x,mod)+pow(2,y,mod)-1
    ans %= mod
ans -= 1
print(ans)

Buggy submission (verdict: Runtime Error):
mod = 1000000007
from collections import defaultdict

N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]
d1 = defaultdict(lambda:0)
d2 = defaultdict(lambda:0)
for i in range(N):
    a,b = AB[i]
    a_ = abs(a)
    b_ = abs(b)
    d = gcd(a,b)
    a //= d
    b //= d
    if a < 0:
        a *= -1
        b *= -1
    if b>=0:
        d1[(a,b)] += 1
    else:
        d2[(a,b)] += 1
        d1[(-b,a)] += 0

ans = 1
for a,b in d1:
    x = d1[(a,b)]
    y = d2[(b,-a)]
    ans *= pow(2,x,mod)+pow(2,y,mod)-1
    ans %= mod
ans -= 1
print(ans)