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:
import sys
sys.setrecursionlimit(2147483647)


n=int(input())

mod=10**9+7

#初期値が0の辞書
from collections import defaultdict
pp = defaultdict(lambda: 0) 
pm = defaultdict(lambda: 0) 

from fractions import gcd
zero=0
for _ in range(n):
    a,b=map(int,input().split())

    if a*b!=0:
        tmp=gcd(a,b)
        a=a//tmp
        b=b//tmp

        if a*b>0:
            pp[(a,b)]+=1
        else:
            pm[(a,b)]+=1
    elif a==0 and b==0:
        zero+=1
    else:
        pp[(a,b)]+=1
            
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 = mod #割る数
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
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)

#print(pp_k,pm_k)
result=1
for key in pp.keys():
    pp_v=pp[key]
    a,b=key[0],key[1]
    pm_v=pm[(-1*b,a)]+pm[(b,-1*a)]
    if pm_v>0:
        result=result*((2**pp_v-1)+(2**pm_v-1)+1)
    else:
        result=result*(2**pp_v)

for key in pm.keys():
    pm_v=pm[key]
    a,b=key[0],key[1]
    pp_v=pp[(-1*b,a)]+pp[(b,-1*a)]

    if pp_v==0:
        result=result*(2**pm_v)

print(result-1+zero)

Submission status: Wrong Answer

Solution code:
import sys
from math import gcd
from collections import Counter
MOD = 10**9 + 7
def main():
    input = sys.stdin.readline
    N = int(input())
    V = []
    z = 0
    for _ in range(N):
        A, B = map(int, input().split())
        g = gcd(A, B)
        if g == 0: z += 1
        elif A < 0: V.append((-A // g, -B // g))
        else: V.append((A // g, B // g))
    C = Counter(V)
    ans = Mint(1)
    used = set()
    for k, V in C.items():
        a, b = k
        v = (b, -a) if b >= 0 else (-b, a)
        if v in used: continue
        t = Mint(1)
        t += pow(2, V, MOD) - 1
        t += pow(2, C[v], MOD) - 1
        ans *= t
        used.add(k)
    print(ans - 1 + z)

class Mint:
    def __init__(self, value=0):
        self.value = value % MOD
        if self.value < 0: self.value += MOD

    @staticmethod
    def get_value(x): return x.value if isinstance(x, Mint) else x

    def inverse(self):
        a, b = self.value, MOD
        u, v = 1, 0
        while b:
            t = a // b
            b, a = a - t * b, b
            v, u = u - t * v, v
        if u < 0: u += MOD
        return u

    def __repr__(self): return str(self.value)
    def __eq__(self, other): return self.value == other.value
    def __neg__(self): return Mint(-self.value)
    def __hash__(self): return hash(self.value)
    def __bool__(self): return self.value != 0

    def __iadd__(self, other):
        self.value = (self.value + Mint.get_value(other)) % MOD
        return self

    def __add__(self, other):
        new_obj = Mint(self.value)
        new_obj += other
        return new_obj
    __radd__ = __add__

    def __isub__(self, other):
        self.value = (self.value - Mint.get_value(other)) % MOD
        if self.value < 0: self.value += MOD
        return self

    def __sub__(self, other):
        new_obj = Mint(self.value)
        new_obj -= other
        return new_obj

    def __rsub__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj -= self
        return new_obj

    def __imul__(self, other):
        self.value = self.value * Mint.get_value(other) % MOD
        return self

    def __mul__(self, other):
        new_obj = Mint(self.value)
        new_obj *= other
        return new_obj
    __rmul__ = __mul__

    def __ifloordiv__(self, other):
        other = other if isinstance(other, Mint) else Mint(other)
        self *= other.inverse()
        return self

    def __floordiv__(self, other):
        new_obj = Mint(self.value)
        new_obj //= other
        return new_obj

    def __rfloordiv__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj //= self
        return new_obj


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from math import gcd
from collections import Counter
MOD = 10**9 + 7
def main():
    input = sys.stdin.readline
    N = int(input())
    V = []
    z = 0
    for _ in range(N):
        A, B = map(int, input().split())
        g = gcd(A, B)
        if g == 0: z += 1
        elif A < 0: V.append((-A // g, -B // g))
        else: V.append((A // g, B // g))
    C = Counter(V)
    ans = Mint(1)
    used = set()
    for k, V in C.items():
        a, b = k
        v = (b, -a) if b >= 0 else (-b, a)
        if v in used: continue
        t = Mint(1)
        t += pow(2, V, MOD) - 1
        t += pow(2, C[v], MOD) - 1
        ans *= t
        used.add(k)
    print(ans - 1)

class Mint:
    def __init__(self, value=0):
        self.value = value % MOD
        if self.value < 0: self.value += MOD

    @staticmethod
    def get_value(x): return x.value if isinstance(x, Mint) else x

    def inverse(self):
        a, b = self.value, MOD
        u, v = 1, 0
        while b:
            t = a // b
            b, a = a - t * b, b
            v, u = u - t * v, v
        if u < 0: u += MOD
        return u

    def __repr__(self): return str(self.value)
    def __eq__(self, other): return self.value == other.value
    def __neg__(self): return Mint(-self.value)
    def __hash__(self): return hash(self.value)
    def __bool__(self): return self.value != 0

    def __iadd__(self, other):
        self.value = (self.value + Mint.get_value(other)) % MOD
        return self

    def __add__(self, other):
        new_obj = Mint(self.value)
        new_obj += other
        return new_obj
    __radd__ = __add__

    def __isub__(self, other):
        self.value = (self.value - Mint.get_value(other)) % MOD
        if self.value < 0: self.value += MOD
        return self

    def __sub__(self, other):
        new_obj = Mint(self.value)
        new_obj -= other
        return new_obj

    def __rsub__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj -= self
        return new_obj

    def __imul__(self, other):
        self.value = self.value * Mint.get_value(other) % MOD
        return self

    def __mul__(self, other):
        new_obj = Mint(self.value)
        new_obj *= other
        return new_obj
    __rmul__ = __mul__

    def __ifloordiv__(self, other):
        other = other if isinstance(other, Mint) else Mint(other)
        self *= other.inverse()
        return self

    def __floordiv__(self, other):
        new_obj = Mint(self.value)
        new_obj //= other
        return new_obj

    def __rfloordiv__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj //= self
        return new_obj


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)


n=int(input())

mod=10**9+7

#初期値が0の辞書
from collections import defaultdict
pp = defaultdict(lambda: 0) 
pm = defaultdict(lambda: 0) 

from fractions import gcd

for _ in range(n):
    a,b=map(int,input().split())

    if a*b!=0:
        tmp=gcd(a,b)
        a=a//tmp
        b=b//tmp

        if a*b>0:
            pp[(a,b)]+=1
        else:
            pm[(a,b)]+=1
    else:
        pp[(a,b)]+=1
            
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 = mod #割る数
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
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)

#print(pp_k,pm_k)
result=1
for key in pp.keys():
    pp_v=pp[key]
    a,b=key[0],key[1]
    pm_v=pm[(-1*b,a)]+pm[(b,-1*a)]
    if pm_v>0:
        result=result*((2**pp_v-1)+(2**pm_v-1)+1)
    else:
        result=result*(2**pp_v)

for key in pm.keys():
    pm_v=pm[key]
    a,b=key[0],key[1]
    pp_v=pp[(-1*b,a)]+pp[(b,-1*a)]

    if pp_v==0:
        result=result*(2**pm_v)

print(result-1)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
from collections import defaultdict
from math import gcd

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 0除算、グループ分け
MOD = 10 ** 9 + 7
N = ir()
AB = [lr() for _ in range(N)]  # 0-indexed
dic = defaultdict(set)
zero = [set() for _ in range(3)]
for i, (a, b) in enumerate(AB, 1):
    g = gcd(a, b)
    if g != 0:
        a //= g; b //= g
        if a < 0:
            a *= -1; b *= -1
        dic[(a, b)].add(i)
    elif a == 0:
        if b == 0:
            zero[0].add(i)
        else:
            zero[1].add(i)
    elif b == 0:
        zero[2].add(i)

answer = 1
used = set()
for k, v in dic.items():
    a, b = k
    k2 = (-b, a)
    if -b < 0:
        k2 = (b, -a)
    if k in used:
        continue
    if k2 in dic:
        v2 = dic[k2]
        answer *= (-1 + pow(2, len(v), MOD) + pow(2, len(v2), MOD))
        used.add((k2))
    else:
        answer *= pow(2, len(v), MOD)
    used.add(k)

# zero
answer *= -1 + pow(2, len(zero[1]), MOD) + pow(2, len(zero[2]), MOD)
answer += len(zero[0])
answer -= 1  # 何も選ばなかった場合
print(answer % MOD)
# np.int64とint型の違いに注意
# 07

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
from collections import defaultdict
from math import gcd

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 0除算、グループ分け
MOD = 10 ** 9 + 7
N = ir()
AB = [lr() for _ in range(N)]  # 0-indexed
dic = defaultdict(set)
zero = [set() for _ in range(3)]
for i, (a, b) in enumerate(AB, 1):
    g = gcd(a, b)
    if g != 0:
        a //= g; b //= g
        if a < 0:
            a *= -1; b *= -1
        dic[(a, b)].add(i)
    elif a == 0:
        if b == 0:
            zero[0].add(i)
        else:
            zero[1].add(i)
    elif b == 0:
        zero[2].add(i)

answer = 1
used = set()
for k, v in dic.items():
    a, b = k
    k2 = (-b, a)
    if -b < 0:
        k2 = (b, -a)
    if k in used:
        continue
    if k2 in dic:
        v2 = dic[k2]
        answer *= (-1 + pow(2, len(v), MOD) + pow(2, len(v2), MOD))
        used.add((k2))
    else:
        answer *= pow(2, len(v), MOD)
    used.add(k)

# zero
answer *= pow(2, len(zero[0]), MOD)
answer *= -1 + pow(2, len(zero[1]), MOD) + pow(2, len(zero[2]), MOD)
answer -= 1  # 何も選ばなかった場合
print(answer % MOD)
# np.int64とint型の違いに注意
# 07

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
from collections import defaultdict
from math import gcd

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 0除算、グループ分け
MOD = 10 ** 9 + 7
N = ir()
AB = [lr() for _ in range(N)]  # 0-indexed
dic = defaultdict(set)
zero = [set() for _ in range(3)]
for i, (a, b) in enumerate(AB, 1):
    g = gcd(a, b)
    if g != 0:
        a //= g; b //= g
        if a < 0:
            a *= -1; b *= -1
        dic[(a, b)].add(i)
    elif a == 0:
        if b == 0:
            zero[0].add(i)
        else:
            zero[1].add(i)
    elif b == 0:
        zero[2].add(i)

answer = 1
used = set()
for k, v in dic.items():
    a, b = k
    k2 = (-b, a)
    if -b < 0:
        k2 = (b, -a)
    if k in used:
        continue
    if k2 in dic:
        v2 = dic[k2]
        answer *= (-1 + pow(2, len(v), MOD) + pow(2, len(v2), MOD))
        used.add((k2))
    else:
        answer *= pow(2, len(v), MOD)
    used.add(k)

answer -= 1  # 何も選ばなかった場合
print(answer % MOD)
# np.int64とint型の違いに注意
# 07

Submission status: Wrong Answer

Solution code:
import math
import bisect
N = int(input())
atans =  [0 for _ in range(N)]

count00 = 0
for i in range(N):
  A, B = map(int, input().split())
  if A == 0:
    if B == 0:
      count00 += 1
    else:
      atans[i] = 90
  else:
    atans[i] = math.degrees(math.atan(B/A))

N2 = N - count00
if N2 == 0:
  print(count00)
  exit()

atans.sort()
index0 = bisect.bisect_left(atans, 0)
if (index0==0) or (index0==N2):
  print((pow(2, N2, 1000000007) +count00 -1)%1000000007)
  exit()

left = atans[:index0]
right = atans[index0:]
ans = 1

lenleft = index0
lenright = N2 - index0
now = -90
for i in range(index0):
  if left[i]==now:
    continue
  now = left[i]
  target = now+90
  same1 = bisect.bisect_right(right, target) - bisect.bisect_left(right, target)
  
  if same1 >= 1:
    lenright -= same1
    same2 = bisect.bisect_right(left, now) - bisect.bisect_left(left, now)
    ans = ans * (pow(2,same1,1000000007)+pow(2,same2,1000000007)-1) %1000000007
  else:
    ans = ans * 2 %1000000007

ans = (ans * pow(2, lenright, 1000000007) +count00 -1) % 1000000007
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import bisect
N = int(input())
atans =  [0 for _ in range(N)]

count00 = 0
for i in range(N):
  A, B = map(int, input().split())
  if A == 0:
    if B == 0:
      count00 += 1
    else:
      atans[i] = 90
  else:
    atans[i] = math.degrees(math.atan(B/A))

N2 = N - count00
if N2 == 0:
  print(count00)
  exit()

atans.sort()
index0 = bisect.bisect_left(atans, 0)
if (index0==0) or (index0==N2):
  print((pow(2, N2, 1000000007) +count00 -1)%1000000007)
  exit()

left = atans[:index0]
right = atans[index0:]
ans = 1

lenleft = index0
lenright = N2 - index0
now = -90
for i in range(index0):
  if left[i]==now:
    continue
  now = left[i]
  target = now+90
  same1 = bisect.bisect_right(right, target) - bisect.bisect_left(right, target)
  
  if same1 >= 1:
    lenright -= same1
    same2 = bisect.bisect_right(left, now) - bisect.bisect_left(left, now)
    ans = ans * (pow(2,same1,1000000007)+pow(2,same2,1000000007)-1) %1000000007
  else:
    ans = ans * 2 %1000000007

ans = (ans * pow(2, lenright, 1000000007) -1) % 1000000007
print(ans)

Submission status: Wrong Answer

Solution code:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**19
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    N = NI()
    AB = [LI() for _ in range(N)]
    d = {}

    ans = 0
    for i in range(N):
        a,b = AB[i]
        if a == 0:
            if b == 0: continue
            b = 1
            s = 1
        elif b == 0:
            a = 1
            s = -1
        else:
            s = (a*b>0) - (a*b<0)
            a = abs(a); b = abs(b)
            x = math.gcd(a,b)
            a = a // x; b = b // x
        if (a,b,s) in d:
            d[(a,b,s)] += 1
        else:
            d[(a,b,s)] = 1

    ans = 1
    for (a,b,s),data in d.items():
        if data == 0: continue
        if (b, a, -s) in d:
            m = d[(b,a,-s)]
            d[(b, a, -s)] = 0
        else:
            m = 0
        x = pow(2,data,MOD) + pow(2,m,MOD) - 1
        ans = (ans * x) % MOD

    print((ans-1)%MOD)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,cos,radians,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7



def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
n=I()
bekit=[0 for i in range(n+1)]
bekit[0]=1
for i in range(n):
    bekit[i+1]=(bekit[i]*2)%mod
#print(bekit)
countz=0
countx=0
county=0
nump=[]
numm=[]
for i in range(n):
    a,b=MI()
    if a==0 and b==0:
        countz+=1
    elif a==0:
        if b<0:
            b*=(-1)
        countx+=1
    elif b==0:
        if a<0:
            a*=(-1)
        county+=1
    elif (a>0 and b<0) or (a<0 and b>0):
        #print(a,b)
        if b<0:
            a*=(-1)
            b*=(-1)
        g=gcd(abs(a),b)
        a=a//g
        b=b//g
        #print(a,b)
        numm.append([a,b])
    else:
        g=gcd(abs(a),abs(b))
        a//=g
        b//=g
        nump.append([abs(a),abs(b)])
#print(nump)
#print(numm)
nump=list(map(tuple,nump))
numm=list(map(tuple,numm))
u=Counter(nump)
v=Counter(numm)
#print(u)
#print(v)
nums=[]
pairs=[]
for k in u.keys():
    vz=((-1)*k[1],k[0])
    s=u[k]
    t=v[vz]
    #print(vz)
    #print(s)
    #print(t)
    if t>0:
        nums.append([s,t])
        pairs.append(s+t)
#print(nums)
#print(nums)
#print(n-sum(pairs)-countx-county-countz)
#print(pairs)
#print(n-sum(pairs)-countx-county-countz)
if countx>0 and county>0:
    cou=countx+county
else:
    cou=0
ans=bekit[n-sum(pairs)-cou-countz]
#print(ans)
for j in range(len(nums)):
    q=bekit[nums[j][0]]
    p=bekit[nums[j][1]]
    #print(q)
    #print(p)
    ans=(ans*(q+p-1))%mod
if countx>0 and county>0:
    ans=(ans*(bekit[countx]+bekit[county]-1))%mod
ans-=1
if countz>0:
    ans+=bekit[(countz-1)]
print(ans%mod)

Submission status: Wrong Answer

Solution code:
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,cos,radians,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7



def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
n=I()
bekit=[0 for i in range(n+1)]
bekit[0]=1
for i in range(n):
    bekit[i+1]=(bekit[i]*2)%mod
#print(bekit)
countz=0
countx=0
county=0
nump=[]
numm=[]
for i in range(n):
    a,b=MI()
    if a==0 and b==0:
        countz+=1
    elif a==0:
        if b<0:
            b*=(-1)
        countx+=1
    elif b==0:
        if a<0:
            a*=(-1)
        county+=1
    elif a*b<0:
        #print(a,b)
        if b<0:
            a*=(-1)
            b*=(-1)
        g=gcd(abs(a),b)
        a=a//g
        b=b//g
        #print(a,b)
        numm.append([a,b])
    else:
        g=gcd(abs(a),abs(b))
        a//=g
        b//=g
        nump.append([abs(a),abs(b)])
#print(nump)
#print(numm)
nump=list(map(tuple,nump))
numm=list(map(tuple,numm))
u=Counter(nump)
v=Counter(numm)
#print(u)
#print(v)
nums=[]
pairs=[]
for k in u.keys():
    vz=((-1)*k[1],k[0])
    s=u[k]
    t=v[vz]
    #print(vz)
    #print(s)
    #print(t)
    if t>0:
        nums.append([s,t])
        pairs.append(s+t)
#print(nums)
#print(nums)
#print(n-sum(pairs)-countx-county-countz)
#print(pairs)
#print(n-sum(pairs)-countx-county-countz)
if countx>0 and county>0:
    cou=countx+county
else:
    cou=0
ans=bekit[n-sum(pairs)-cou-countz]
#print(ans)
for j in range(len(nums)):
    q=bekit[nums[j][0]]
    p=bekit[nums[j][1]]
    #print(q)
    #print(p)
    ans=(ans*(q+p-1))%mod
if countx>0 and county>0:
    ans=(ans*(bekit[countx]+bekit[county]-1))%mod
ans-=1
if countz>0:
    ans+=bekit[(countz-1)]
print(ans%mod)

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(IN())
mod=1000000007

#+++++

def mk(a,b):
	if a == 0:
		return 0,1
	if b==0:
		return 1,0
		
	c = -1 if a < 0 else 1
	r = math.gcd(abs(a),abs(b))
	ra = (a //r)*c
	rb = (b //r)*c
	
	return ra, rb
	
def mh(a,b):
	return str(a)+'_'+str(b)
	
def mv(s):
	a,b = map(int, s.split('_'))
	return a,b
	
def ty(s):
	a, b = mv(s)
	sign = 1 if b > 0 else -1
	return mh(b*sign, -a*sign)
	

def main():
	n = int(input())
	dd = defaultdict(lambda : 0)
	is_zero=False
	for _ in range(n):
		a,b=tin()
		if a== 0 and b == 0:
			is_zero=True
			continue
		a,b = mk(a,b)
		dd[mh(a,b)] += 1
		
	cc = set()
	ret = 1
	for k in dd:
		if k in cc:
			continue
		v = dd[k]
		if ty(k) in dd:
			tv = dd[ty(k)]
			r = pow(2,v,mod)+pow(2,tv,mod)-1
			#pa((r,k, ty(k)))
			ret *= r
			ret %= mod
			cc.add(ty(k))
		else:
			#pa(('v',v,k, ty(k)))
			ret *= pow(2,v,mod)
			ret %= mod
			
	ret -= 1
	ret += 1 if is_zero else 0
	ret %= mod
	print(ret) 
			
		
		
	#b , c = tin()
	#s = input()
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Wrong Answer

Solution code:
import sys

def main():
    input = sys.stdin.readline
    mod = pow(10,9)+7
    
    n = int(input())
    key1 = dict()
    key2 = dict()
    
    a_0 = 0
    b_0 = 0
    ab_0 = 0
    
    for i in range(n):
        a, b = map(int, input().split())
        if a == 0 and b == 0:
            ab_0 += 1
            continue
        if a == 0:
            a_0 += 1
            continue
        if b == 0:
            b_0 += 1
            continue
        k1, k2 = abs(a), abs(b)
        if k2 < k1:
            k1, k2 = k2, k1
        while k2%k1:
            k2, k1 = k1, k2%k1
        a //= k1
        b //= k1
        if a*b > 0:
            if a/b in key1:
                key1[a/b] += 1
            else:
                key1[a/b] = 1
        else:
            if abs(b/a) in key2:
                key2[abs(b/a)] += 1
            else:
                key2[abs(b/a)] = 1
    
    
    left = n-a_0-b_0-ab_0
    key = [(a_0, b_0)]
    for k, v in key1.items():
        if k in key2:
            v2 = key2[k]
            key.append((v, v2))
            left -= v+v2
    
    ans = pow(2, left, mod)
    for a, b in key:
        ans *= pow(2, a, mod)+pow(2, b, mod)-1
        ans %= mod
    ans += mod-1
    ans += ab_0
    ans %= mod
    
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,cos,radians,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7



def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
n=I()
bekit=[0 for i in range(n+1)]
bekit[0]=1
for i in range(n):
    bekit[i+1]=(bekit[i]*2)%mod
#print(bekit)
countz=0
countx=0
county=0
nump=[]
numm=[]
for i in range(n):
    a,b=MI()
    if a==0 and b==0:
        countz+=1
    elif a==0:
        if b<0:
            b*=(-1)
        countx+=1
    elif b==0:
        if a<0:
            a*=(-1)
        county+=1
    elif a*b<0:
        #print(a,b)
        if b<0:
            a*=(-1)
            b*=(-1)
        g=gcd(abs(a),b)
        a=a//g
        b=b//g
        #print(a,b)
        numm.append([a,b])
    else:
        g=gcd(abs(a),abs(b))
        a//=g
        b//=g
        nump.append([abs(a),abs(b)])
#print(nump)
#print(numm)
nump=list(map(tuple,nump))
numm=list(map(tuple,numm))
u=Counter(nump)
v=Counter(numm)
#print(u)
#print(v)
nums=[]
pairs=[]
for k in u.keys():
    vz=((-1)*k[1],k[0])
    s=u[k]
    t=v[vz]
    #print(vz)
    #print(s)
    #print(t)
    if t>0:
        nums.append([s,t])
        pairs.append(s+t)
#print(nums)
#print(nums)
#print(n-sum(pairs)-countx-county-countz)
#print(pairs)
#print(n-sum(pairs)-countx-county-countz)
ans=bekit[n-sum(pairs)-countx-county-countz]
for j in range(len(nums)):
    q=bekit[nums[j][0]]
    p=bekit[nums[j][1]]
    #print(q)
    #print(p)
    ans=(ans*(q+p-1))%mod
if countx>0 and county>0:
    ans=(ans*(bekit[countx]+bekit[county]-1))%mod
ans-=1
if countz>0:
    ans+=bekit[(countz-1)]
print(ans%mod)

Submission status: Wrong Answer

Solution code:
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,cos,radians,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7



def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
n=I()
bekit=[0 for i in range(n+1)]
bekit[0]=1
for i in range(n):
    bekit[i+1]=(bekit[i]*2)%mod
#print(bekit)
countz=0
countx=0
county=0
nump=[]
numm=[]
for i in range(n):
    a,b=MI()
    if a==0 and b==0:
        countz+=1
    elif a==0:
        if b<0:
            b*=(-1)
        countx+=1
    elif b==0:
        if a<0:
            a*=(-1)
        county+=1
    elif a*b<0:
        #print(a,b)
        if b<0:
            a*=(-1)
            b*=(-1)
        g=gcd(abs(a),b)
        a=a//g
        b=b//g
        #print(a,b)
        numm.append([a,b])
    else:
        g=gcd(abs(a),abs(b))
        a//=g
        b//=g
        nump.append([abs(a),abs(b)])
#print(nump)
#print(numm)
nump=list(map(tuple,nump))
numm=list(map(tuple,numm))
u=Counter(nump)
v=Counter(numm)
#print(u)
#print(v)
nums=[]
pairs=[]
for k in u.keys():
    vz=((-1)*k[1],k[0])
    s=u[k]
    t=v[vz]
    #print(vz)
    #print(s)
    #print(t)
    if t>0:
        nums.append([s,t])
        pairs.append(s+t)
#print(nums)
#print(nums)
#print(n-sum(pairs)-countx-county-countz)
#print(pairs)
#print(n-sum(pairs)-countx-county-countz)
ans=bekit[n-sum(pairs)-countx-county-countz]
for j in range(len(nums)):
    q=bekit[nums[j][0]]
    p=bekit[nums[j][1]]
    #print(q)
    #print(p)
    ans=(ans*(q+p-1))%mod
if countx>0 and county>0:
    ans=(ans*(bekit[countx]+bekit[county]-1))%mod
ans-=1
if countz>0:
    ans+=2**(countz-1)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

def main():
    input = sys.stdin.readline
    mod = pow(10,9)+7
    
    n = int(input())
    key1 = dict()
    key2 = dict()
    
    a_0 = 0
    b_0 = 0
    ab_0 = 0
    
    for i in range(n):
        a, b = map(int, input().split())
        if a == 0 and b == 0:
            ab_0 += 1
            continue
        if a == 0:
            a_0 += 1
            continue
        if b == 0:
            b_0 += 1
            continue
        k1, k2 = abs(a), abs(b)
        if k2 > k1:
            k1, k2 = k2, k1
        while k2%k1:
            k2, k1 = k1, k2%k1
        a //= k1
        b //= k1
        if a*b > 0:
            if a/b in key1:
                key1[a/b] += 1
            else:
                key1[a/b] = 1
        else:
            if abs(b/a) in key2:
                key2[abs(b/a)] += 1
            else:
                key2[abs(b/a)] = 1
    
    
    left = n-a_0-b_0-ab_0
    key = [(a_0, b_0)]
    for k, v in key1.items():
        if k in key2:
            v2 = key2[k]
            key.append((v, v2))
            left -= v+v2
    
    ans = pow(2, left, mod)
    for a, b in key:
        ans *= pow(2, a, mod)+pow(2, b, mod)-1
        ans %= mod
    ans += mod-1
    ans += ab_0
    ans %= mod
    
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

def main():
    input = sys.stdin.readline
    mod = pow(10,9)+7
    
    n = int(input())
    key1 = dict()
    key2 = dict()
    
    a_0 = 0
    b_0 = 0
    ab_0 = 0
    
    for i in range(n):
        a, b = map(int, input().split())
        if a == 0 and b == 0:
            ab_0 += 1
            continue
        if a == 0:
            a_0 += 1
            continue
        if b == 0:
            b_0 += 1
            continue
        k1, k2 = abs(a), abs(b)
        if k2 > k1:
            k1, k2 = k2, k1
        while k2%k1:
            k2, k1 = k1, k2%k1
        a //= k1
        b //= k1
        if a*b > 0:
            if a/b in key1:
                key1[a/b] += 1
            else:
                key1[a/b] = 1
        else:
            if abs(b/a) in key2:
                key2[abs(b/a)] += 1
            else:
                key2[abs(b/a)] = 1
    
    
    left = n-a_0-b_0-ab_0
    key = [(a_0, b_0)]
    for k, v in key1.items():
        if k in key2:
            v2 = key2[k]
            key.append((v, v2))
            left -= v+v2
    
    ans = pow(2, left, mod)
    for a, b in key:
        ans *= pow(2, a, mod)+pow(2, b, mod)-1
        ans %= mod
    ans -= 1
    ans += ab_0
    ans %= mod
    
    print(ans)


if __name__ == "__main__":
    main()