Problem:


Score: 500 points

Problem Statement

We have caught N sardines. The deliciousness and fragrantness of the i-th sardine is A_i and B_i, respectively.

We will choose one or more of these sardines and put them into a cooler. However, two sardines on bad terms cannot be chosen at the same time.

The i-th and j-th sardines (i \neq j) are on bad terms if and only if A_i \cdot A_j + B_i \cdot B_j = 0.

In how many ways can we choose the set of sardines to put into the cooler? Since the count can be enormous, print it modulo 1000000007.

Constraints

All values in input are integers.

1 \leq N \leq 2 \times 10^5

-10^{18} \leq A_i, B_i \leq 10^{18}

Input

Input is given from Standard Input in the following format:

N
A_1 B_1
:
A_N B_N

Output

Print the count modulo 1000000007.

Sample Input 1

3
1 2
-1 1
2 -1

Sample Output 1

5

There are five ways to choose the set of sardines, as follows:

The 1-st

The 1-st and 2-nd

The 2-nd

The 2-nd and 3-rd

The 3-rd

Sample Input 2

10
3 2
3 2
-1 1
2 -1
-3 -9
-8 12
7 7
8 1
8 2
8 4

Sample Output 2

479



Sample input:
3
1 2
-1 1
2 -1


Sample output:
5

Submission status: Wrong Answer

Solution code:
from fractions import Fraction
import math

n = int(input())


ab = []
ba = []

a0 = 0
b0 = 0
ab0 = 0

for i in range(n):
    a, b = map(int, input().split())
    if a != 0 and b != 0:
        ab.append(Fraction(a, b))
        ba.append(Fraction(-b, a))
    elif a == 0 and b == 0:
        ab0 += 1
    elif a == 0 and b != 0:
        a0 += 1
    elif a != 0 and b == 0:
        b0 += 1


d_ab = dict()
d_ba = dict()

d_done = dict()

for i in range(len(ab)):
    cur = ab[i]
    if cur in d_ab:
        d_ab[cur] += 1
    else:
        d_ab[cur] = 1

    cur = ba[i]
    if cur in d_ba:
        d_ba[cur] += 1
    else:
        d_ba[cur] = 1

mod = 1000000007
ans = 1

for k, v in d_ab.items():
    x = v
    if k in d_ba:
        if k in d_done:
            continue
        else:
            y = d_ba[k]
            kake = 0
            kake += ((2**x) % mod + (2**y) % mod - 1)
            ans *= kake
            ans %= mod
            d_done[Fraction(-k.denominator, k.numerator)] = 1
    else:
        kake = (2**x) % mod
        ans *= kake
        ans %= mod

ans *= ((2**a0) % mod+(2**b0) % mod-1)
ans %= mod

ans += ab0

print(ans-1)

Submission status: Wrong Answer

Solution code:
import bisect
import collections
import functools
import heapq
import math
from collections import deque
from collections import defaultdict
MOD = 10**9+7

N = int(input())
A = [0]*N
B = [0]*N
C = [[0]*2 for _ in range(N)]
zero = 0
for i in range(N):
    A[i],B[i] = map(int,(input().split()))
    if A[i] == 0 and B[i] == 0:
        C[i] = (0,0)
        zero += 1
    elif B[i] == 0:
        C[i] = (A[i],B[i])
    elif B[i] > 0:
        g = math.gcd(A[i],B[i])
        C[i] = (A[i]//g,B[i]//g)
    else:
        g = math.gcd(A[i],B[i])
        C[i] = (-A[i]//g,-B[i]//g)

d = defaultdict(int)

for i in range(N):
    if C[i] != (0,0):
        d[C[i]] += 1

ans = 1
for k in d.keys():
    if k[0] >= 0:
        if (-k[1],k[0]) in d:
            ans *= pow(2,d[k],MOD) + pow(2,d[(-k[1],k[0])],MOD) - 1
            d[k],d[(-k[1],k[0])] = 0,0
        else:
            ans *= pow(2,d[k],MOD)
    else:
        if (k[1],-k[0]) in d:
            ans *= pow(2,d[k],MOD) + pow(2,d[(k[1],-k[0])],MOD) -1
            d[k],d[(k[1],-k[0])] = 0,0
        else:
            ans *= pow(2,d[k],MOD)

print((ans*(zero+1)-1)%MOD)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
from math import gcd
input = sys.stdin.readline
N = int(input())
mod = 10 ** 9 + 7
d = Counter()
a = [tuple(map(int, input().split())) for _ in range(N)]
z = 0
for x, y in a:
  if (x, y) == (0, 0):
    z += 1
    continue
  if y < 0:
    x *= -1
    y *= -1
  if x == 0:
    x = 0
    y = 1
  elif y == 0:
    x = 1
    y = 0
  g = gcd(abs(x), abs(y))
  x //= g
  y //= g
  d[(x, y)] += 1

res = 1
itr = list(d.keys())
#print(itr, d)
for x, y in itr:
  t = 0
  if x <= 0 and (d[(y, -x)] > 0): continue
  if (x, y) == (1, 0):
    t = d[(0, 1)]
  else:
    t = d[(-y, x)]
  v = 0
  v += pow(2, d[(x, y)], mod) - 1
  v %= mod
  v += pow(2, t, mod) - 1
  v %= mod
  v += 1
  v %= mod
  res *= v
  res %= mod
  #print(res, d, d[(x, y)], t)
#print(itr, u, res, z)
print(res - 1 + z % mod)

Submission status: Wrong Answer

Solution code:
mod = 10 ** 9 + 7
def gcd(a, b):
    return gcd(b, a%b) if b else a
N = int(input())
from collections import defaultdict
X = defaultdict(lambda: [0, 0])
x = 0
y = 0
z = 0
for i in range(N):
    a, b = map(int, input().split())
    g = abs(gcd(a, b))
    if a * b > 0:
        X[(abs(a) // g, abs(b) // g)][0] += 1
    elif a * b < 0:
        X[(abs(b) // g, abs(a) // g)][1] += 1
    else:
        if a:
            x += 1
        elif b:
            y += 1
        else:
            z += 1
print(X)
print(X.values())
ans = 1
pow2 = [1]
for i in range(N):
    pow2 += [pow2[-1] * 2 % mod]
for i in X.values():
    
    ans *= pow2[i[0]] + pow2[i[1]]- 1
    ans %= mod
ans *= pow2[x] + pow2[y] - 1
ans += z
ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
import collections
import functools
import heapq
import math
from collections import deque
from collections import defaultdict
MOD = 10**9+7

N = int(input())
A = [0]*N
B = [0]*N
C = [[0]*2 for _ in range(N)]
zero = 0
for i in range(N):
    A[i],B[i] = map(int,(input().split()))
    if A[i] == 0 and B[i] == 0:
        C[i] = (0,0)
        zero += 1
    elif B[i] == 0:
        C[i] = (A[i],B[i])
    elif B[i] > 0:
        g = math.gcd(A[i],B[i])
        C[i] = (A[i]//g,B[i]//g)
    else:
        g = math.gcd(A[i],B[i])
        C[i] = (-A[i]//g,-B[i]//g)

d = defaultdict(int)

for i in range(N):
    if C[i] != (0,0):
        d[C[i]] += 1

ans = 1
for k in d.keys():
    if k[0] >= 0:
        if (-k[1],k[0]) in d:
            ans *= pow(2,d[k],MOD) + pow(2,d[(-k[1],k[0])],MOD) - 1
            d[k],d[(-k[1],k[0])] = 0,0
        else:
            ans *= pow(2,d[k],MOD)
    else:
        if (k[1],-k[0]) in d:
            ans *= pow(2,d[k],MOD) + pow(2,d[(k[1],-k[0])],MOD) -1
            d[k],d[(k[1],-k[0])] = 0,0
        else:
            ans *= pow(2,d[k],MOD)

print(ans*(zero+1)-1%MOD)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
# import time
import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = ii()
    theta = []
    zero_zero_cnt = 0
    for i in range(n):
        a, b = mi()
        if a == 0 and b == 0:
            zero_zero_cnt += 1
        else:
            theta.append(math.degrees(math.atan2(b, a)))
    theta.sort()
    # print(theta)

    eps = 10 ** (-7)
    compressed_theta = []
    cnt_theta = []
    prev = -inf
    for i in range(len(theta)):
        if theta[i] <= prev + eps:
            cnt_theta[-1] += 1
        else:
            compressed_theta.append(theta[i])
            cnt_theta.append(1)
            prev = theta[i]

    # print(compressed_theta)
    pairs = []
    no_pair_ind = set(range(len(compressed_theta)))
    for i, dg in enumerate(compressed_theta):
        l_ind = bisect_left(compressed_theta, dg - 90 - eps)
        r_ind = bisect_right(compressed_theta, dg - 90 + eps)
        if l_ind != r_ind:
            # assert(l_ind + 1 == r_ind)
            # if l_ind + 1 != r_ind:
                # print(f"{dg}")
                # print(f"{l_ind} {r_ind} {compressed_theta[l_ind]} {compressed_theta[r_ind-1]}")
            pairs.append((cnt_theta[l_ind], cnt_theta[i]))
            if l_ind in no_pair_ind:
                no_pair_ind.remove(l_ind)
            if i in no_pair_ind:
                no_pair_ind.remove(i)
    
    num_of_no_pairs = sum([cnt_theta[ind] for ind in no_pair_ind])

    ans = pow(2, num_of_no_pairs, mod)
    for k, l in pairs:
        ans = (ans * (1 + pow(2, k, mod) - 1 + pow(2, l, mod) - 1)) % mod
    ans -= 1

    ans += zero_zero_cnt
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math
import itertools

n = int(input())
mod = 1000000007

def Is_Positive(n):
    return n > 0

allZeros = 0
vectors = dict()


def add_positive(_):
    if _ not in vectors:
        vectors[_] = (1, 0)
    else:
        vectors[_] = (vectors[_][0] + 1, vectors[_][1])


def add_negative(_):
    if _ not in vectors:
        vectors[_] = (0, 1)
    else:
        vectors[_] = (vectors[_][0], vectors[_][1] + 1)


for i in range(n):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        allZeros += 1
        continue
    gcd = math.gcd(a, b)

    key = (0, 0)
    if a == 0:
        key = (1, 0)
        add_negative(key)
    elif b == 0:
        key = (1, 0)
        add_positive(key)

    elif Is_Positive(a) and Is_Positive(b):
        key = (abs(a) // gcd, abs(b) // gcd)
        add_positive(key)
    else:
        key = (abs(b) // gcd, abs(a) // gcd)
        add_negative(key)



total = 1
for vec in vectors.values():

    total *= ((2**(vec[0]))
              + (2**(vec[1])) - 1) % mod

print(total- 1 + allZeros)

Submission status: Wrong Answer

Solution code:
import collections
import math

n = int(input())
m = 0
mod = 10 ** 6 + 7
c = []
d = []
frac = {}

for _ in range(n):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        n -= 1
        m += 1
        continue
    try:
        if a == 0:
            frac['0/1'] += 1
        elif b == 0:
            frac['1/0'] += 1
        else:
            gcd = abs(math.gcd(a, b))
            sign = 1 if a * b > 0 else -1
            a = sign * abs(a) // gcd
            b = abs(b) // gcd
            frac['{}/{}'.format(a, b)] += 1
    except KeyError:
        if a == 0:
            frac['0/1'] = 1
        elif b == 0:
            frac['1/0'] = 1
        else:
            gcd = abs(math.gcd(a, b))
            sign = a * b // abs(a * b)
            a = sign * abs(a) // gcd
            b = abs(b) // gcd
            frac['{}/{}'.format(a, b)] = 1

def inverse(key):
    if key == '0/1':
        return '1/0'
    elif key == '1/0':
        return '0/1'
    elif key[0] != '-':
        a, b = key.split('/')
        return '-{}/{}'.format(b, a)
    else:
        a, b = key[1:].split('/')
        return '{}/{}'.format(b, a)

for key, value in frac.items():
    if key == '1/0': continue
    if key[0] == '-': continue
    try:
        d.append(frac[inverse(key)])
        c.append(value)
    except KeyError:
        continue

ans = pow(2, n - sum(c) - sum(d), mod)
for i, j in zip(c, d):
    tmp = (pow(2, i, mod) + pow(2, j, mod) - 1)
    ans = (ans * (pow(2, i, mod) + pow(2, j, mod) - 1)) % mod
ans = (ans - 1 + m) % mod

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
import math

n = int(input())
m = 0
mod = 10 ** 6 + 7
c = []
d = []
frac = {}

for _ in range(n):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        n -= 1
        m += 1
        continue
    try:
        if a == 0:
            frac['0/1'] += 1
        elif b == 0:
            frac['1/0'] += 1
        else:
            gcd = abs(math.gcd(a, b))
            sign = 1 if a * b > 0 else -1
            a = sign * abs(a) // gcd
            b = abs(b) // gcd
            frac['{}/{}'.format(a, b)] += 1
    except KeyError:
        if a == 0:
            frac['0/1'] = 1
        elif b == 0:
            frac['1/0'] = 1
        else:
            gcd = abs(math.gcd(a, b))
            sign = a * b // abs(a * b)
            a = sign * abs(a) // gcd
            b = abs(b) // gcd
            frac['{}/{}'.format(a, b)] = 1

def inverse(key):
    if key == '0/1':
        return '1/0'
    elif key == '1/0':
        return '0/1'
    elif key[0] != '-':
        a, b = key.split('/')
        return '-{}/{}'.format(b, a)
    else:
        a, b = key[1:].split('/')
        return '{}/{}'.format(b, a)

for key, value in frac.items():
    if key == 'b0': continue
    if key[0] == '-': continue
    try:
        d.append(frac[inverse(key)])
        c.append(value)
    except KeyError:
        continue

ans = pow(2, n - sum(c) - sum(d), mod)
for i, j in zip(c, d):
    tmp = (pow(2, i, mod) + pow(2, j, mod) - 1)
    ans = (ans * (pow(2, i, mod) + pow(2, j, mod) - 1)) % mod
ans = (ans - 1 + m) % mod

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
from math import gcd
input = sys.stdin.readline
N = int(input())
mod = 10 ** 9 + 7
d = Counter()
a = [tuple(map(int, input().split())) for _ in range(N)]
z = 0
for x, y in a:
  if (x, y) == (0, 0):
    z += 1
    continue
  if y < 0:
    x *= -1
    y *= -1
  if x == 0:
    x = 0
    y = 1
  elif y == 0:
    x = 1
    y = 0
  g = gcd(abs(x), abs(y))
  x //= g
  y //= g
  d[(x, y)] += 1

res = 1
itr = list(d.keys())
#print(itr, d)
for x, y in itr:
  t = 0
  if x <= 0 and (d[(y, -x)] > 0): continue
  if (x, y) == (0, 1):
    t = d[(1, 0)]
    d[(1, 0)] = 0
  elif (x, y) == (1, 0):
    t = d[(0, 1)]
    d[(0, 1)] = 0
  else:
    t = d[(y * pow(-1, int(x < 0) + 1), abs(x))]
    d[(y * pow(-1, int(x < 0) + 1), abs(x))] = 0
  v = 0
  v += pow(2, d[(x, y)], mod) - 1
  v %= mod
  v += pow(2, t, mod) - 1
  v %= mod
  v += 1
  v %= mod
  res *= v
  res %= mod
  #print(res, d, d[(x, y)], t)
  d[(x, y)] = 0


#print(itr, u, res, z)
print(res - 1 + z % mod)

Submission status: Wrong Answer

Solution code:
from math import gcd

MOD = 10**9+7
N = int(input())
d = {}
zero = 0
for i in range(N):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        zero += 1
        continue

    if a < 0:
        a, b = -a, -b
    if b < 0:
        a, b = -b, a
        flip = 1
    else:
        flip = 0

    g = gcd(a, b)
    a //= g
    b //= g
    if not (a, b) in d:
        d[(a, b)] = [0, 0]
    d[(a, b)][flip] += 1

ans = 1
for (v1, v2) in d.values():
    ans *= pow(2, v1, MOD) + pow(2, v2, MOD)-1
    ans %= MOD
ans -= 1
ans += zero
ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
import math

n = int(input())
m = 0
mod = 10 ** 6 + 7
c = []
d = []
frac = {}

for _ in range(n):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        n -= 1
        m += 1
        continue
    try:
        if a == 0:
            frac['0'] += 1
        elif b == 0:
            frac['inf'] += 1
        else:
            gcd = abs(math.gcd(a, b))
            sign = 1 if a * b > 0 else -1
            a = sign * abs(a) // gcd
            b = abs(b) // gcd
            frac['{}/{}'.format(a, b)] += 1
    except KeyError:
        if a == 0:
            frac['a0'] = 1
        elif b == 0:
            frac['b0'] = 1
        else:
            gcd = abs(math.gcd(a, b))
            sign = a * b // abs(a * b)
            a = sign * abs(a) // gcd
            b = abs(b) // gcd
            frac['{}/{}'.format(a, b)] = 1

def inverse(key):
    if key == 'a0':
        return 'b0'
    elif key == 'b0':
        return 'a0'
    elif key[0] != '-':
        a, b = key.split('/')
        return '-{}/{}'.format(b, a)
    else:
        a, b = key[1:].split('/')
        return '{}/{}'.format(b, a)

for key, value in frac.items():
    if key == 'b0': continue
    if key[0] == '-': continue
    try:
        d.append(frac[inverse(key)])
        c.append(value)
    except KeyError:
        continue

ans = pow(2, n - sum(c) - sum(d), mod)
for i, j in zip(c, d):
    tmp = (pow(2, i, mod) + pow(2, j, mod) - 1)
    ans = (ans * (pow(2, i, mod) + pow(2, j, mod) - 1)) % mod
ans = (ans - 1 + m) % mod

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
from math import gcd
input = sys.stdin.readline
N = int(input())
mod = 10 ** 9 + 7
d = Counter()
a = [tuple(map(int, input().split())) for _ in range(N)]
z = 0
for x, y in a:
  if (x, y) == (0, 0):
    z += 1
    continue
  if y < 0:
    x *= -1
    y *= -1
  if x == 0:
    x = 0
    y = 1
  elif y == 0:
    x = 1
    y = 0
  g = gcd(abs(x), abs(y))
  x //= g
  y //= g
  d[(x, y)] += 1

res = 1
itr = list(d.keys())
#print(itr, d)
for x, y in itr:
  t = 0
  #if x <= 0 and (d[(y, -x)] > 0): continue
  if (x, y) == (0, 1):
    t = d[(1, 0)]
    d[(1, 0)] = 0
  elif (x, y) == (1, 0):
    t = d[(0, 1)]
    d[(0, 1)] = 0
  else:
    t = d[(y * pow(-1, int(x < 0) + 1), abs(x))]
    d[(y * pow(-1, int(x < 0) + 1), abs(x))] = 0
  v = 0
  v += pow(2, d[(x, y)], mod) - 1
  v %= mod
  v += pow(2, t, mod) - 1
  v %= mod
  v += 1
  v %= mod
  res *= v
  res %= mod
  #print(res, d, d[(x, y)], t)
  d[(x, y)] = 0


#print(itr, u, res, z)
print(res - 1 + z % mod)

Submission status: Wrong Answer

Solution code:
import math
import itertools

n = int(input())
mod = 1000000007

def Is_Positive(n):
    return n > 0

allZeros = 0
vectors = dict()


def add_positive(_):
    if _ not in vectors:
        vectors[_] = (1, 0)
    else:
        vectors[_] = (vectors[_][0] + 1, vectors[_][1])


def add_negative(_):
    if _ not in vectors:
        vectors[_] = (0, 1)
    else:
        vectors[_] = (vectors[_][0], vectors[_][1] + 1)


for i in range(n):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        allZeros += 1
        continue
    gcd = math.gcd(a, b)

    key = (0, 0)
    if a == 0:
        key = (0, b // abs(b))
        if Is_Positive(b):
            add_positive(key)
        else:
            add_negative(key)
    elif b == 0:
        key = (a // abs(a), 0)
        if Is_Positive(a):
            add_positive(key)
        else:
            add_negative(key)

    elif Is_Positive(a) and Is_Positive(b):
        key = (abs(a) // gcd, abs(b) // gcd)
        add_positive(key)
    else:
        key = (abs(b) // gcd, abs(a) // gcd)
        add_negative(key)



total = 1
for vec in vectors.values():

    total *= ((2**(vec[0]))
              + (2**(vec[1])) - 1) % mod

print(total- 1 + allZeros)

Submission status: Wrong Answer

Solution code:
from math import gcd

N = int(input())
AB = [map(int, input().split()) for _ in range(N)]

t = []
d = {}
d[0] = {}
d[0][0] = 0
for a, b in AB:
    i = gcd(a, b)
    if i != 0:
        a //= i
        b //= i
    t.append((a, b))
    d.setdefault(a, {})
    d[a].setdefault(b, 0)
    d[a][b] += 1

used = set()
result = 1
for a, b in t:
    if (a, b) in used:
        continue
    used.add((a, b))
    if a == 0 and b == 0:
        continue
    i = d[a][b]
    j, k, l = 0, 0, 0
    if -a in d and -b in d[-a]:
        j = d[-a][-b]
        used.add((-a, -b))
    if -b in d and a in d[-b]:
        k = d[-b][a]
        used.add((-b, a))
    if b in d and -a in d[b]:
        l = d[b][-a]
        used.add((b, -a))
    result *= pow(2, i + j, 1000000007) + pow(2, k + l, 1000000007) - 1
    result %= 1000000007
print(result + d[0][0] - 1)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
from math import gcd
input = sys.stdin.readline
N = int(input())
mod = 10 ** 9 + 7
d = Counter()
a = [tuple(map(int, input().split())) for _ in range(N)]
z = 0
for x, y in a:
  if (x, y) == (0, 0):
    z += 1
    continue
  g = gcd(abs(x), abs(y))
  x //= g
  y //= g
  if y < 0:
    x *= -1
    y *= -1
  if x == 0:
    x = 0
    y = 1
  elif y == 0:
    x = 1
    y = 0
  d[(x, y)] += 1

res = 1
itr = list(d.keys())
#print(itr, d)
for x, y in itr:
  t = 0
  if (x, y) == (0, 1):
    t = d[(1, 0)]
    d[(1, 0)] = 0
  elif (x, y) == (1, 0):
    t = d[(0, 1)]
    d[(0, 1)] = 0
  else:
    t = d[(y * pow(-1, int(x < 0) + 1), abs(x))]
    d[(y * pow(-1, int(x < 0) + 1), abs(x))] = 0
  v = 0
  v += pow(2, d[(x, y)], mod) - 1
  v %= mod
  v += pow(2, t, mod) - 1
  v %= mod
  v += 1
  v %= mod
  res *= v
  res %= mod
  #print(res, d, d[(x, y)], t)
  d[(x, y)] = 0


#print(itr, u, res, z)
print(res - 1 + z % mod)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9
    N=I()
    from math import gcd
    from collections import defaultdict
    dd = defaultdict(int)

    for i in range(N):
        a,b=MI()
        if a*b!=0:
            g=gcd(abs(a),abs(b))
            a=a//g
            b=b//g
        elif (a,b)!=(0,0):
            #assert 0
            if a==0:
                b=1
            else:
                a=1
                
        if a<0:
            a*=-1
            b*=-1
            
        dd[(a,b)]+=1
        
    ans=1
    L=[]
    for k in dd.keys():
        L.append((k))

    temp0=0
    for i in range(len(L)):
        k=L[i]
        v=dd[k]
        a,b=k
        dd[k]=0
        temp=pow(2,v)
        if a*b!=0:
            if (-b,a) in dd:
                v2=dd[(-b,a)]
                temp+=pow(2,v2)-1
                dd[(-b,a)]=0
            if (b,-a) in dd:
                v2=dd[(b,-a)]
                temp+=pow(2,v2)-1
                dd[(b,-a)]=0
                    
        elif (a,b)==(1,0) or (a,b)==(0,1):
            if (b,a) in dd:
                v2=dd[(b,a)]
                if v2!=0:
                    temp+=pow(2,v2)-1
                    dd[(b,a)]=0
        else:
            temp0=v
            temp=1
            
        #print(k,v,temp)
        ans=(ans*temp)%mod
        
        


    ans=(ans-1+temp0)%mod
    print(ans)
        
        
            
            
    #せんぶ０の組みをひく
        
    

main()

Submission status: Wrong Answer

Solution code:
import math


def main():

    mod = 1000000007
    N = int(input())

    A = [0]
    B = [0]

    for n in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)

    calc = dict()
    non_count = 0

    for i in range(1, N + 1):

        if A[i] == 0 and B[i] == 0:
            non_count += 1
        elif A[i] == 0:
            k = (0, 1)
            if calc.get(k):
                calc[k][0] += 1
            else:
                calc[k] = [1, 0]
        elif B[i] == 0:
            k = (0, 1)
            if calc.get(k):
                calc[k][1] += 1
            else:
                calc[k] = [0, 1]
        else:
            r = math.gcd(A[i], B[i])
            m = 1
            if A[i] * B[i] < 0:
                m = -1
            k1 = (m * abs(A[i] // r), abs(B[i] // r))
            k2 = (-m * abs(B[i] // r), abs(A[i] // r))
            if calc.get(k1):
                calc[k1][0] += 1
            elif not calc.get(k2):
                calc[k1] = [1, 0]
            else:
                calc[k2][1] += 1

    N = N - non_count

    count = 0
    for k, v in calc.items():
        if not v[0] * v[1] == 0:
            count += v[0] + v[1]

    ans = pow(2, N - count, mod)
    for k, v in calc.items():
        if not v[0] * v[1] == 0:
            comb = (pow(2, v[0]) + pow(2, v[1]) - 1)
            ans = (ans * comb) % mod

    print(ans - 1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
import math

n = int(input())
m = 0
mod = 10 ** 6 + 7
c = []
d = []
frac = {}

for _ in range(n):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        n -= 1
        m += 1
        continue
    try:
        if a == 0:
            frac['0'] += 1
        elif b == 0:
            frac['inf'] += 1
        else:
            gcd = abs(math.gcd(a, b))
            sign = 1 if a * b > 0 else -1
            a = sign * abs(a) // gcd
            b = abs(b) // gcd
            frac['{}/{}'.format(a, b)] += 1
    except KeyError:
        if a == 0:
            frac['a0'] = 1
        elif b == 0:
            frac['b0'] = 1
        else:
            gcd = abs(math.gcd(a, b))
            sign = a * b // abs(a * b)
            a = sign * abs(a) // gcd
            b = abs(b) // gcd
            frac['{}/{}'.format(a, b)] = 1

def inverse(key):
    if key[0] != '-':
        a, b = key.split('/')
        return '-{}/{}'.format(b, a)
    else:
        a, b = key[1:].split('/')
        return '{}/{}'.format(b, a)

for key, value in frac.items():
    if key == 'b0': continue
    if key[0] == '-': continue
    try:
        if key == 'a0':
            d.append(frac['b0'])
        else:
            d.append(frac[inverse(key)])
        c.append(value)
    except KeyError:
        continue

ans = pow(2, n - sum(c) - sum(d), mod)
for i, j in zip(c, d):
    tmp = (pow(2, i, mod) + pow(2, j, mod) - 1)
    ans = (ans * (pow(2, i, mod) + pow(2, j, mod) - 1)) % mod
ans = (ans * (m + 1) - 1) % mod

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
pp = []
a0 = 0
b0 = 0
z = 0
for i in range(n):
  a,b = map(int,input().split())
  if a*b == 0:
    if a==0 and b==0:
      z += 1
    elif a==0:
      a0 += 1
    else:
      b0 += 1
  else:
    pp.append(a/b)
    
mod = 10**9+7
a0 %= mod
b0 %= mod
z %= mod
p = Counter(pp)
r = 1
s = set()

for i in p.keys():
  if i in s:
    continue
  ans = p[i]
  chk = p[-1/i]
  r *= (pow(2,ans,mod)+pow(2,chk,mod)-1)%mod
  r %= mod
  s.add(-1/i)
  
r *= (pow(2,a0,mod)+pow(2,b0,mod)-1)%mod
r %= mod
print((r+z-1)%mod)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9
    N=I()
    from math import gcd
    from collections import defaultdict
    dd = defaultdict(int)

    for i in range(N):
        a,b=MI()
        if a*b!=0:
            g=gcd(abs(a),abs(b))
            a=a//g
            b=b//g
        elif (a,b)!=(0,0):
            #assert 0
            if a==0:
                b=1
            else:
                a=1
            
        dd[(a,b)]+=1
        dd[(b,-a)]+=0
        dd[(-b,a)]+=0
        
    ans=1
    L=[]
    for k in dd.keys():
        L.append((k))

    temp0=0
    for i in range(len(L)):
        k=L[i]
        v=dd[k]
        a,b=k
        if a<0:
            continue
        dd[k]=0
        temp=pow(2,v)
        if a*b!=0:
            if (-b,a) in dd:
                v2=dd[(-b,a)]
                temp+=pow(2,v2)-1
                dd[(-b,a)]=0
            if (b,-a) in dd:
                v2=dd[(b,-a)]
                temp+=pow(2,v2)-1
                dd[(b,-a)]=0
                    
        elif (a,b)==(1,0) or (a,b)==(0,1):
            if (b,a) in dd:
                v2=dd[(b,a)]
                if v2!=0:
                    temp+=pow(2,v2)-1
                    dd[(b,a)]=0
        else:
            temp0=v
            temp=1
            
        #print(k,v,temp)
        ans=(ans*temp)%mod
        
        


    ans=(ans-1+temp0)%mod
    print(ans)
        
        
            
            
    #せんぶ０の組みをひく
        
    

main()

Submission status: Wrong Answer

Solution code:
from math import gcd 
from collections import defaultdict

def to_irreducible(a, b):
    if a == 0:
        return (0, 1)
    GCD = gcd(a, b)
    return (a//GCD, b//GCD)

MOD = 10**9 + 7
N = int(input())
quadrant1 = defaultdict(int)
quadrant2 = defaultdict(int)
zero_cases = 0

for i in range(N):
    a, b = map(int, input().split())
    irr = to_irreducible(abs(a), abs(b))
    if a == 0 and b == 0:
        zero_cases += 1
    elif a * b >= 0 and b != 0:
        quadrant1[irr] += 1
    else:
        quadrant2[reversed(irr)] += 1
        quadrant1[reversed(irr)] += 0

ans = 1 
for key, v1 in quadrant1.items():
    v2 = quadrant2[key]
    ans *= (2**v1 + 2**v2 -1)
    ans %= MOD
print((ans+zero_cases-1) % MOD)