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 math

MOD = int(1e9 + 7)
n = int(input())
mp = {}
ans1 = 0
for _ in range(n):
	a, b = map(int, input().split())
	if a == 0 and b == 0:
		ans1 = 1
		continue
	gcd = math.gcd(a, b)
	a //= gcd
	b //= gcd
	if b < 0:
		a *= -1
		b *= -1
	a = abs(a) if b == 0 else a
	b = abs(b) if a == 0 else b
	mp.setdefault((a, b), 0)
	mp[(a, b)] += 1

	b *= -1
	if a < 0:
		a *= -1
		b *= -1
	a = abs(a) if b == 0 else a
	b = abs(b) if a == 0 else b
	y = mp.setdefault( (b, a), 0)

ans = 1

for a, b in mp:
	x = mp.get( (a, b), 0)

	# print(a, b, x, end=" + ")
	b *= -1
	if a < 0:
		a *= -1
		b *= -1
	a = abs(a) if b == 0 else a
	b = abs(b) if a == 0 else b
	y = mp.get( (b, a), 0)

	# print(b, a, y)
	ans = (ans * ( pow(2, x, MOD) + pow(2, y, MOD) - 1  ) ) % MOD
	# print(ans)


ans = int(math.sqrt(ans))

ans = ( ans - 1 + ans1 + MOD ) % MOD
print(ans)

Submission status: Wrong Answer

Solution code:
import math

MOD = int(1e9 + 7)
n = int(input())
mp = {}
ans1 = 0
for _ in range(n):
	a, b = map(int, input().split())
	if a == 0 and b == 0:
		ans1 = 1
		continue
	gcd = math.gcd(a, b)
	a //= gcd
	b //= gcd
	if b < 0:
		a *= -1
		b *= -1
	mp.setdefault((a, b), 0)
	mp[(a, b)] += 1

	b *= -1
	if a < 0:
		a *= -1
		b *= -1
	y = mp.setdefault( (b, a), 0)

ans = 1

for a, b in mp:
	x = mp.get( (a, b), 0)

	# print(a, b, x, end=" + ")
	b *= -1
	if a < 0:
		a *= -1
		b *= -1
	y = mp.get( (b, a), 0)

	# print(b, a, y)
	ans = (ans * ( pow(2, x, MOD) + pow(2, y, MOD) - 1  ) ) % MOD
	# print(ans)


ans = int(math.sqrt(ans))

ans = ( ans - 1 + ans1 + MOD ) % MOD
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
from collections import defaultdict
import math
d = defaultdict(int)
MOD=10**9+7
M=0
for i in range(N):
  a,b=map(int,input().split())
  x=math.gcd(abs(a),abs(b))
  if x==0:
    if a>b:
      k=(1,0)
    elif b>a:
      k=(0,1)
    else:
      k=(0,0)
  else:
    a,b=a//x,b//x
    if a<0:
      a,b=-a,-b
    k=(a,b)
  d[k]+=1
  M=max(M,d[k])
ans=0
'''
def C(x):
  #X=math.factorial(x)
  _=0
  __=1
  for i in range(1,x+1):
    __=__*(x+1-i)//i
    _+=__
    #_+=X//math.factorial(i)//math.factorial(x-i)
  return _
'''
def cmb(n, r, mod):
  if ( r<0 or r>n ):
    return 0
  r = min(r, n-r)
  return g1[n] * g2[r] * g2[n-r] % mod

#N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, M + 1 ):
  g1.append( ( g1[-1] * i ) % MOD )
  inverse.append( ( -inverse[MOD % i] * (MOD//i) ) % MOD )
  g2.append( (g2[-1] * inverse[-1]) % MOD )

def C(x):
  _=0
  for i in range(1,x+1):
    _+=cmb(x,i,MOD)
  return _%MOD

if d[(0,0)]>0:
  ans+=d[(0,0)]
ind=defaultdict(int)
index=1
_ans=[1]
for a,b in list(d.keys()):
  if b<0:
    _k=(-b,a)
  else:
    _k=(b,-a)
  if d[_k]==0:
    _ans.append(C(d[(a,b)])+1)
    index+=1
  else:
    if ind[_k]==0:
      _ans.append(C(d[(a,b)]))
      ind[(a,b)]=index
      index+=1
    else:
      _ans[ind[_k]]+=C(d[(a,b)])+1
_=1
for a in _ans:
  _*=a
print((ans+_-1)%MOD)

Submission status: Wrong Answer

Solution code:
N=int(input())
from collections import defaultdict
import math
d = defaultdict(int)
MOD=10**9+7
M=0
for i in range(N):
  a,b=map(int,input().split())
  x=math.gcd(a,b)
  if x==0:
    if a>b:
      k=(1,0)
    elif b>a:
      k=(0,1)
    else:
      k=(0,0)
  else:
    a,b=a//x,b//x
    if a<0:
      a,b=-a,-b
    k=(a,b)
  d[k]+=1
  M=max(M,d[k])
ans=0
'''
def C(x):
  #X=math.factorial(x)
  _=0
  __=1
  for i in range(1,x+1):
    __=__*(x+1-i)//i
    _+=__
    #_+=X//math.factorial(i)//math.factorial(x-i)
  return _
'''
def cmb(n, r, mod):
  if ( r<0 or r>n ):
    return 0
  r = min(r, n-r)
  return g1[n] * g2[r] * g2[n-r] % mod

#N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, M + 1 ):
  g1.append( ( g1[-1] * i ) % MOD )
  inverse.append( ( -inverse[MOD % i] * (MOD//i) ) % MOD )
  g2.append( (g2[-1] * inverse[-1]) % MOD )

def C(x):
  _=0
  for i in range(1,x+1):
    _+=cmb(x,i,MOD)
  return _%MOD

if d[(0,0)]>0:
  ans+=d[(0,0)]
ind=defaultdict(int)
index=1
_ans=[1]
for a,b in list(d.keys()):
  if b<0:
    _k=(-b,a)
  else:
    _k=(b,-a)
  if d[_k]==0:
    _ans.append(C(d[(a,b)])+1)
    index+=1
  else:
    if ind[_k]==0:
      _ans.append(C(d[(a,b)]))
      ind[(a,b)]=index
      index+=1
    else:
      _ans[ind[_k]]+=C(d[(a,b)])+1
_=1
for a in _ans:
  _*=a
print((ans+_-1)%MOD)

Submission status: Wrong Answer

Solution code:
N=int(input())
from collections import defaultdict
import math
d = defaultdict(int)
MOD=10**9+7
M=0
for i in range(N):
  a,b=map(int,input().split())
  x=math.gcd(a,b)
  if x==0:
    if a>b:
      k=(1,0)
    elif b>a:
      k=(0,1)
    else:
      k=(0,0)
  else:
    a,b=a//x,b//x
    if a<0:
      a,b=-a,-b
    k=(a,b)
  d[k]+=1
  M=max(M,d[k])
ans=0
'''
def C(x):
  #X=math.factorial(x)
  _=0
  __=1
  for i in range(1,x+1):
    __=__*(x+1-i)//i
    _+=__
    #_+=X//math.factorial(i)//math.factorial(x-i)
  return _
'''
def cmb(n, r, mod):
  if ( r<0 or r>n ):
    return 0
  r = min(r, n-r)
  return g1[n] * g2[r] * g2[n-r] % mod

#N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, M + 1 ):
  g1.append( ( g1[-1] * i ) % MOD )
  inverse.append( ( -inverse[MOD % i] * (MOD//i) ) % MOD )
  g2.append( (g2[-1] * inverse[-1]) % MOD )

def C(x):
  _=0
  for i in range(1,x+1):
    _+=cmb(x,i,MOD)
  return _%MOD

if d[(0,0)]>0:
  x=d[(0,0)]
  for i in range(1,x+1):
    ans+=cmb(x,i,MOD)
ind=defaultdict(int)
index=1
_ans=[1]
for a,b in list(d.keys()):
  if b<0:
    _k=(-b,a)
  else:
    _k=(b,-a)
  if d[_k]==0:
    _ans.append(C(d[(a,b)])+1)
    index+=1
  else:
    if ind[_k]==0:
      _ans.append(C(d[(a,b)]))
      ind[(a,b)]=index
      index+=1
    else:
      _ans[ind[_k]]+=C(d[(a,b)])+1
_=1
for a in _ans:
  _*=a
print((ans+_-1)%MOD)

Submission status: Wrong Answer

Solution code:
N=int(input())
from collections import defaultdict
import math
d = defaultdict(int)
MOD=10**9+7
for i in range(N):
  a,b=map(int,input().split())
  x=math.gcd(a,b)
  if x==0:
    if a>b:
      d[(1,0)]+=1
    elif b>a:
      d[(0,1)]+=1
    else:
      d[(0,0)]+=1
  else:
    a,b=a//x,b//x
    if a<0:
      a,b=-a,-b
    d[(a,b)]+=1
ans=0
def C(x):
  #X=math.factorial(x)
  _=0
  __=1
  for i in range(1,x+1):
    __=__*(x+1-i)//i
    _+=__
    #_+=X//math.factorial(i)//math.factorial(x-i)
  return _
if d[(0,0)]>0:
  x=d[(0,0)]
  X=math.factorial(x)
  for i in range(1,x+1):
    ans+=X//math.factorial(i)//math.factorial(x-i)
ind=defaultdict(int)
index=1
_ans=[1]
for a,b in list(d.keys()):
  if b<0:
    _k=(-b,a)
  else:
    _k=(b,-a)
  if d[_k]==0:
    _ans.append(C(d[(a,b)])+1)
    index+=1
  else:
    if ind[_k]==0:
      _ans.append(C(d[(a,b)]))
      ind[(a,b)]=index
      index+=1
    else:
      _ans[ind[_k]]+=C(d[(a,b)])+1
_=1
for a in _ans:
  _*=a
print((ans+_-1)%MOD)

Submission status: Wrong Answer

Solution code:
mod = 1000000007
n = int(input())

ab00 = 0
abx0 = 0
ab0x = 0
p = []
m = []

from math import gcd
for _ in range(n):
    i, j = map(int, input().split())
    if i == 0:
        if j == 0:
            ab00 += 1
        else:
            ab0x += 1
        continue
    elif j == 0:
        abx0 += 1
        continue
    k = gcd(i, j)
    i //= k
    j //= k
    if i > 0:
        if j > 0:
            p.append((i, j))
        else:
            m.append((-j, i))
    elif j > 0:
        m.append((j, -i))
    else:
        p.append((-i, -j))

m.sort()
p.sort()

ans = pow(2, ab00, mod)
ans *= pow(2, ab0x, mod) + pow(2, abx0, mod) - 1
ans %= mod

mi = 0
pi = 0
while mi < len(m) and pi < len(p):
    if m[mi] == p[pi]:
        mi += 1
        mnum = 1
        while mi < len(m) and m[mi] == m[mi-1]:
            mi += 1
            mnum += 1
        pi += 1
        pnum = 1
        while pi < len(p) and p[pi] == p[pi-1]:
            pi += 1
            pnum += 1
        ans *= pow(2, mnum, mod) + pow(2, pnum, mod) - 1
        ans %= mod

    elif m[mi] < p[pi]:
        mi += 1
        mnum = 1
        while mi < len(m) and m[mi] < p[pi]:
            mi += 1
            mnum += 1
        ans *= pow(2, mnum, mod)
        ans %= mod
    
    else:
        pi += 1
        pnum = 1
        while pi < len(p) and p[pi] < m[mi]:
            pi += 1
            pnum += 1
        ans *= pow(2, pnum, mod)
        ans %= mod

ans *= pow(2, len(p) - pi, mod)
ans %= mod
ans *= pow(2, len(m) - mi, mod)
ans %= mod
ans = (ans-1) % mod
print(ans)

Submission status: Wrong Answer

Solution code:
mod = 1000000007
n = int(input())

ab00 = 0
abx0 = 0
ab0x = 0
p = []
m = []

from math import gcd
for _ in range(n):
    i, j = map(int, input().split())
    if i == 0:
        if j == 0:
            ab00 += 1
        else:
            ab0x += 1
        continue
    elif j == 0:
        abx0 += 1
        continue
    k = gcd(i, j)
    i //= k
    j //= k
    if i > 0:
        if j > 0:
            p.append((i, j))
        else:
            m.append((-j, i))
    elif j > 0:
        m.append((j, -i))
    else:
        p.append((-i, -j))

m.sort()
p.sort()

ans = pow(2, ab00, mod)
ans *= pow(2, ab0x, mod) + pow(2, abx0, mod) - 1
ans %= mod

mi = 0
pi = 0
while mi < len(m) and pi < len(p):
    if m[mi] == p[pi]:
        mi += 1
        mnum = 1
        while mi < len(m) and m[mi] == m[mi-1]:
            mi += 1
            mnum += 1
        pi += 1
        pnum = 1
        while pi < len(p) and p[pi] == p[pi-1]:
            pi += 1
            pnum += 1
        ans *= pow(2, mnum, mod) + pow(2, pnum, mod) - 1
        ans %= mod

    elif m[mi] < p[pi]:
        mi += 1
        mnum = 1
        while mi < len(m) and m[mi] < p[pi]:
            mi += 1
            mnum += 1
        ans *= pow(2, mnum, mod)
        ans %= mod
    
    else:
        pi += 1
        pnum = 1
        while pi < len(p) and p[pi] < m[mi]:
            pi += 1
            pnum += 1
        ans *= pow(2, pnum, mod)
        ans %= mod

ans *= pow(2, len(p) - pi, mod)
ans %= mod
ans *= pow(2, len(m) - mi, mod)
ans %= mod
print(ans - 1)

Submission status: Wrong Answer

Solution code:
import math
from collections import deque

N = int(input())

a = []
b = []
for i in range(N):
    i1, i2 = map(int, input().split())
    g = math.gcd(i1,i2)
    if g == 0:
        a.append(i1)
        b.append(i2)
        continue
    x = i1 // g
    y = i2 // g
    if x < 0:
        x = - x
        y = - y 
    a.append(x)
    b.append(y)

P = {}
for i in range(N):
    if b[i] < 0:
        tmp = b[i]
        b[i] = a[i]
        a[i] = - tmp
        sgn = 1
    elif a[i] == 0:
        a[i] = b[i]
        b[i] = 0
        sgn = 1
    else :
        sgn = 0

    if (a[i],b[i]) in P:
        P[(a[i],b[i])][sgn]=P[(a[i],b[i])][sgn] + 1
    elif sgn == 0 :
        P[(a[i],b[i])]=[1,0]
    else :
        P[(a[i],b[i])]=[0,1]
        

MOD = 1000000007
a1 = 1 
ans0=0
for k in P:
    if k == (0,0):
        ans0 = P[k][0]
    else:
        a1 = a1*(pow(2,P[k][0],MOD)+pow(2,P[k][1],MOD) - 1) % MOD

if ans0 != 0:
    ans = ans0 + a1 -1
else:
    ans = a1 -1
print(ans%MOD)

Submission status: Wrong Answer

Solution code:
import math
from collections import deque

N = int(input())

a = []
b = []
for i in range(N):
    i1, i2 = map(int, input().split())
    g = math.gcd(i1,i2)
    if g == 0:
        a.append(i1)
        b.append(i2)
        continue
    x = i1 // g
    y = i2 // g
    if x < 0:
        x = - x
        y = - y 
    a.append(x)
    b.append(y)

P = {}
for i in range(N):
    if b[i] <= 0:
        tmp = b[i]
        b[i] = a[i]
        a[i] = - tmp
        sgn = 1
    else :
        sgn = 0

    if (a[i],b[i]) in P:
        P[(a[i],b[i])][sgn]=P[(a[i],b[i])][sgn] + 1
    elif sgn == 0 :
        P[(a[i],b[i])]=[1,0]
    else :
        P[(a[i],b[i])]=[0,1]

MOD = 1000000007
a1 = 1 
ans0=0
for k in P:
    if k == (0,0):
        ans0 = P[k][0]
    else:
        a1 = a1*(pow(2,P[k][0],MOD)+pow(2,P[k][1],MOD) - 1) % MOD

if ans0 != 0:
    ans = ans0 + a1 -1
else:
    ans = a1 -1
print(ans%MOD)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
import bisect
import numpy as np
import math
from collections import deque
from collections import defaultdict
from math import gcd

MOD = 10**9 + 7

N = int(input())

zero = 0
counter0 = defaultdict(int)
counter1 = defaultdict(int)
for i in range(N):
    A, B = map(int, input().split())
    if A == B == 0:
        zero += 1
        continue
    g = gcd(A, B)
    A //= g  # 既約分数に
    B //= g

    if A < 0:
        A *= -1
        B *= -1
    if A == 0 and B > 0:  # A, B = 0, -1に
        B *= -1
    
    if B <= 0:  # 分数A/Bが負になる場合はcounter0でカウント
        counter0[(A, -B)] += 1
        counter1[(-B, A)] += 0  # 初期化
    else:
        counter1[(A, B)] += 1

ans = 1
for k, v in counter1.items():
    A, B = k
    j = counter0[(B, A)]
    ans *= pow(2, v, MOD) + pow(2, j, MOD) - 1

    ans %= MOD

ans += zero
ans -= 1
ans %= MOD

print(ans)

Submission status: Wrong Answer

Solution code:
import math
from collections import deque

N = int(input())

a = []
b = []
for i in range(N):
    i1, i2 = map(int, input().split())
    g = math.gcd(i1,i2)
    if g == 0:
        a.append(i1)
        b.append(i2)
        continue
    x = i1 // g
    y = i2 // g
    if x < 0:
        x = - x
        y = - y 
    a.append(x)
    b.append(y)

P = {}
for i in range(N):
    if b[i] < 0:
        tmp = b[i]
        b[i] = a[i]
        a[i] = - tmp
        sgn = 1
    else :
        sgn = 0

    if (a[i],b[i]) in P:
        P[(a[i],b[i])][sgn]=P[(a[i],b[i])][sgn] + 1
    elif sgn == 0 :
        P[(a[i],b[i])]=[1,0]
    else :
        P[(a[i],b[i])]=[0,1]

MOD = 1000000007
a1 = 1 
ans0=0
for k in P:
    if k == (0,0):
        ans0 = P[k][0]
    else:
        a1 = a1*(pow(2,P[k][0],MOD)+pow(2,P[k][1],MOD) - 1) % MOD

if ans0 != 0:
    ans = ans0 + a1 -1
else:
    ans = a1 -1
print(ans%MOD)

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
    a = abs(a)
    b = abs(b)
    if b<a:
        a,b = b,a
    
    if b%a==0:
        return a
    
    
    
    return gcd(a,b%a)





def find(pairs):
    MOD = 10**9+7
    rel_pairs = []
    for (x,y) in pairs:
        if x == 0 and y == 0:
            rel_pairs+= [(0,0)]
        elif x == 0:
            rel_pairs+=[(0,-1)]
        elif y == 0:
            rel_pairs+=[(1,0)]
        else:
            temp = gcd(x,y)
            x0,y0 = x//temp,y//temp
            if x0<0:
                x0 = -x0
                y0 = -y0
                
            rel_pairs+=[(x0,y0)]
        
    from collections import Counter
    all_pairs_count = Counter(rel_pairs)
    #print(all_pairs_count)
    want = 1
    dic_counted = {}
    for (x,y) in all_pairs_count:
        if (x,y) == (0,0):
            continue
        if (x,y) in dic_counted:
            continue
        flag = 0
        temp1 = all_pairs_count[(x,y)]
        temp1 = pow(2,temp1,MOD)
        dic_counted[(x,y)] = 1
        temp2 = 1
        if (y,-x) in all_pairs_count:
            temp2 = all_pairs_count[(y,-x)]
            dic_counted[(y,-x)] = 1
            temp2 = pow(2,temp2,MOD)
        elif (-y,x) in all_pairs_count:
            tmep2 = all_pairs_count[(-y,x)]
            dic_counted[(-y,x)] = 1
            temp2 = pow(2,temp2,MOD)
        
        #print(temp1,temp2)
        want *= (temp1+temp2-1)
        want %= MOD
    want -= 1
    #print(all_pairs_count)
    
    if (0,0) in all_pairs_count:
        want += all_pairs_count[(0,0)]
        want %= MOD
    return (want)%MOD
            
        
N = int(input())
pairs = []

for _ in range(N):
    a,b = list(map(int,input().strip().split()))
    pairs += [(a,b)]

print(find(pairs))

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
    a = abs(a)
    b = abs(b)
    if b<a:
        a,b = b,a
    
    if b%a==0:
        return a
    
    
    
    return gcd(a,b%a)





def find(pairs):
    MOD = 10**9+7
    rel_pairs = []
    for (x,y) in pairs:
        if x == 0 and y == 0:
            rel_pairs+= [(0,0)]
        elif x == 0:
            rel_pairs+=[(0,-1)]
        elif y == 0:
            rel_pairs+=[(1,0)]
        else:
            temp = gcd(x,y)
            x0,y0 = x//temp,y//temp
            if x0<0:
                x0 = -x0
                y0 = -y0
                
            rel_pairs+=[(x0,y0)]
        
    from collections import Counter
    all_pairs_count = Counter(rel_pairs)
    #print(all_pairs_count)
    want = 1
    dic_counted = {}
    for (x,y) in all_pairs_count:
        if (x,y) == (0,0):
            continue
        if (x,y) in dic_counted:
            continue
        flag = 0
        temp1 = all_pairs_count[(x,y)]
        temp1 = pow(2,temp1,MOD)
        dic_counted[(x,y)] = 1
        temp2 = 1
        if (y,-x) in all_pairs_count:
            temp2 = all_pairs_count[(y,-x)]
            dic_counted[(y,-x)] = 1
            temp2 = pow(2,temp2,MOD)
        elif (-y,x) in all_pairs_count:
            tmep2 = all_pairs_count[(-y,x)]
            dic_counted[(-y,x)] = 1
            temp2 = pow(2,temp2,MOD)
        
        #print(temp1,temp2)
        want *= (temp1+temp2-1)
        want %= MOD
    #print(all_pairs_count)
    
    if (0,0) in all_pairs_count:
        want += pow(2,all_pairs_count[(0,0)],MOD)-1
        want %= MOD
    return (want-1)%MOD
            
        
N = int(input())
pairs = []

for _ in range(N):
    a,b = list(map(int,input().strip().split()))
    pairs += [(a,b)]

print(find(pairs))

Submission status: Wrong Answer

Solution code:
## coding: UTF-8
import math
MOD = 10**9+7
N = int(input())
A = []
for i in range(N):
    A.append(list(map(int,input().split()))) 
d = dict()
'''
def bisection(a, n, p):
    #二分累乗法によるO(log p)計算
    bin_str = format(n, 'b')
    res = 1
    tmp = a
    for i in range(1, len(bin_str)+1):
        if(bin_str[(-1)*i] == '1'):
            res = res * tmp % p
        tmp = tmp * tmp % p
    return res
'''
d['a'] = 0
d['b'] = 0
d['c'] = 0

for i in range(N):
    #l = list(map(int,input().split()))
    l = A[i]
    if(l[0] == 0):
        if(l[1] == 0):
            d['c'] += 1
        else:
            d['b'] += 1
    elif(l[1] == 0):
        d['a'] += 1
    else:
        g = math.gcd(l[0], l[1])
        a = int(l[0]/g)
        b = int(l[1]/g)
        if(a<0):
            p = (-1*a, -1*b)
        else:
            p = (a, b)
        if p in d:
            d[p] += 1
        else:
            d[p] = 1
    #print('i:{}, l[0]:{}, l[1]:{}, d:{}'.format(i, l[0], l[1], d))

#res = 1
a = d.pop('a')
b = d.pop('b')
#あとで二分累乗法に変換する4 
#if(a > 0 and b > 0):
    #a, b>=0 より、a+b>=0, よってa==0 and b == 0でなければ、a >0 or b> 0
    #ma = bisection(2, a, MOD)
    #mb = bisection(2, b, MOD)
    #res *= ma + mb -1
res = pow(2, a, MOD) + pow(2, b, MOD) - 1
res %= MOD

#elif(a == 0 and b > 0):
    #mb = bisection(2, b, MOD)
    #res *= mb
    #res %= MOD
#elif(a > 0 and b == 0):
    #ma = bisection(2, a, MOD)
    #res *= ma
    #res %= MOD
c = d.pop('c')

#print('a:{}, b:{}, c:{}'.format(a,b,c))
#print('d:{}, len(d):{}'.format(d, len(d)))
#print('res', res)

while len(d) > 0:
    s, v = d.popitem()
    if(s[1] < 0):
        opposite = (-1*s[1], s[0])
    else:
        opposite = (s[1], -1*s[0])
    if opposite in d:
        t = d.pop(opposite)
        #print('s:{}, v:{}, opposite:{}, t:{}, d:{}, len(d):{}'.format(s, v, opposite, t, d, len(d)))
        #mv = bisection(2, v, MOD)
        #mt = bisection(2, t, MOD)        
        #res *= mv + mt - 1
        res *= pow(2, v, MOD) + pow(2, t, MOD) - 1
        res %= MOD
    else:
        #print('s:{}, v:{}, opposite:{},       d:{}, len(d):{}'.format(s, v, opposite, d, len(d)))
        #mv = bisection(2, v, MOD)        
        #res *= mv
        res *= pow(2, v, MOD)
        res %= MOD
    #print('res', res)


res += c
res = (res + MOD - 1) % MOD

print(res)

Submission status: Wrong Answer

Solution code:
## coding: UTF-8
import math
MOD = 10**9+7
N = int(input())
A = []
for i in range(N):
    A.append(list(map(int,input().split()))) 
d = dict()
'''
def bisection(a, n, p):
    #二分累乗法によるO(log p)計算
    bin_str = format(n, 'b')
    res = 1
    tmp = a
    for i in range(1, len(bin_str)+1):
        if(bin_str[(-1)*i] == '1'):
            res = res * tmp % p
        tmp = tmp * tmp % p
    return res
'''
d['a'] = 0
d['b'] = 0
d['c'] = 0

for i in range(N):
    #l = list(map(int,input().split()))
    l = A[i]
    if(l[0] == 0):
        if(l[1] == 0):
            d['c'] += 1
        else:
            d['b'] += 1
    elif(l[1] == 0):
        d['a'] += 1
    else:
        g = math.gcd(l[0], l[1])
        a = int(l[0]/g)
        b = int(l[1]/g)
        if(a<0):
            p = (-1*a, -1*b)
        else:
            p = (a, b)
        if p in d:
            d[p] += 1
        else:
            d[p] = 1
    #print('i:{}, l[0]:{}, l[1]:{}, d:{}'.format(i, l[0], l[1], d))

#res = 1
a = d.pop('a')
b = d.pop('b')
#あとで二分累乗法に変換する4 
#if(a > 0 and b > 0):
    #a, b>=0 より、a+b>=0, よってa==0 and b == 0でなければ、a >0 or b> 0
    #ma = bisection(2, a, MOD)
    #mb = bisection(2, b, MOD)
    #res *= ma + mb -1
res = pow(2, a, MOD) + pow(2, b, MOD) - 1
res %= MOD

#elif(a == 0 and b > 0):
    #mb = bisection(2, b, MOD)
    #res *= mb
    #res %= MOD
#elif(a > 0 and b == 0):
    #ma = bisection(2, a, MOD)
    #res *= ma
    #res %= MOD
c = d.pop('c')

#print('a:{}, b:{}, c:{}'.format(a,b,c))
#print('d:{}, len(d):{}'.format(d, len(d)))
#print('res', res)

while len(d) > 0:
    s, v = d.popitem()
    if(s[1] < 0):
        opposite = (-1*s[1], s[0])
    else:
        opposite = (s[1], -1*s[0])
    if opposite in d:
        t = d.pop(opposite)
        #print('s:{}, v:{}, opposite:{}, t:{}, d:{}, len(d):{}'.format(s, v, opposite, t, d, len(d)))
        #mv = bisection(2, v, MOD)
        #mt = bisection(2, t, MOD)        
        #res *= mv + mt - 1
        res *= pow(2, v, MOD) + pow(2, t, MOD) - 1
        res %= MOD
    else:
        #print('s:{}, v:{}, opposite:{},       d:{}, len(d):{}'.format(s, v, opposite, d, len(d)))
        #mv = bisection(2, v, MOD)        
        #res *= mv
        res *= pow(2, v, MOD)
        res %= MOD
    #print('res', res)


res += c
res = (res + MOD - 1) % MOD

print(res)

Submission status: Wrong Answer

Solution code:
## coding: UTF-8
import math
MOD = 10**9+7
N = int(input())
A = []
for i in range(N):
    A.append(list(map(int,input().split()))) 
d = dict()
'''
def bisection(a, n, p):
    #二分累乗法によるO(log p)計算
    bin_str = format(n, 'b')
    res = 1
    tmp = a
    for i in range(1, len(bin_str)+1):
        if(bin_str[(-1)*i] == '1'):
            res = res * tmp % p
        tmp = tmp * tmp % p
    return res
'''
d['a'] = 0
d['b'] = 0
d['c'] = 0

for i in range(N):
    #l = list(map(int,input().split()))
    l = A[i]
    if(l[0] == 0):
        if(l[1] == 0):
            d['c'] += 1
        else:
            d['b'] += 1
    elif(l[1] == 0):
        d['a'] += 1
    else:
        g = math.gcd(l[0], l[1])
        a = int(l[0]/g)
        b = int(l[1]/g)
        if(a<0):
            p = (-1*a, -1*b)
        else:
            p = (a, b)
        if p in d:
            d[p] += 1
        else:
            d[p] = 1
    #print('i:{}, l[0]:{}, l[1]:{}, d:{}'.format(i, l[0], l[1], d))

#res = 1
a = d.pop('a')
b = d.pop('b')
#あとで二分累乗法に変換する4 
#if(a > 0 and b > 0):
    #a, b>=0 より、a+b>=0, よってa==0 and b == 0でなければ、a >0 or b> 0
    #ma = bisection(2, a, MOD)
    #mb = bisection(2, b, MOD)
    #res *= ma + mb -1
res = pow(2, a, MOD) + pow(2, b, MOD) - 1
res %= MOD

#elif(a == 0 and b > 0):
    #mb = bisection(2, b, MOD)
    #res *= mb
    #res %= MOD
#elif(a > 0 and b == 0):
    #ma = bisection(2, a, MOD)
    #res *= ma
    #res %= MOD
c = d.pop('c')

#print('a:{}, b:{}, c:{}'.format(a,b,c))
#print('d:{}, len(d):{}'.format(d, len(d)))
#print('res', res)

while len(d) > 0:
    s, v = d.popitem()
    if(s[1] < 0):
        opposite = (-1*s[1], s[0])
    else:
        opposite = (s[1], -1*s[0])
    if opposite in d:
        t = d.pop(opposite)
        #print('s:{}, v:{}, opposite:{}, t:{}, d:{}, len(d):{}'.format(s, v, opposite, t, d, len(d)))
        #mv = bisection(2, v, MOD)
        #mt = bisection(2, t, MOD)        
        #res *= mv + mt - 1
        res *= pow(2, v, MOD) + pow(2, t, MOD) - 1
        res %= MOD
    else:
        #print('s:{}, v:{}, opposite:{},       d:{}, len(d):{}'.format(s, v, opposite, d, len(d)))
        #mv = bisection(2, v, MOD)        
        #res *= mv
        res *= pow(2, v, MOD)
        res %= MOD
    #print('res', res)


res += c
res %= MOD
res = (res + MOD - 1) % MOD

print(res)

Submission status: Wrong Answer

Solution code:
## coding: UTF-8
import math
MOD = 10**9+7
N = int(input())
A = []
for i in range(N):
    A.append(list(map(int,input().split()))) 
d = dict()
'''
def bisection(a, n, p):
    #二分累乗法によるO(log p)計算
    bin_str = format(n, 'b')
    res = 1
    tmp = a
    for i in range(1, len(bin_str)+1):
        if(bin_str[(-1)*i] == '1'):
            res = res * tmp % p
        tmp = tmp * tmp % p
    return res
'''
d['a'] = 0
d['b'] = 0
d['c'] = 0

for i in range(N):
    #l = list(map(int,input().split()))
    l = A[i]
    if(l[0] == 0):
        if(l[1] == 0):
            d['c'] += 1
        else:
            d['b'] += 1
    elif(l[1] == 0):
        d['a'] += 1
    else:
        g = math.gcd(l[0], l[1])
        a = int(l[0]/g)
        b = int(l[1]/g)
        if(a<0):
            p = (-1*a, -1*b)
        else:
            p = (a, b)
        if p in d:
            d[p] += 1
        else:
            d[p] = 1
    #print('i:{}, l[0]:{}, l[1]:{}, d:{}'.format(i, l[0], l[1], d))

res = 1
a = d.pop('a')
b = d.pop('b')
#あとで二分累乗法に変換する4 
#if(a > 0 and b > 0):
    #a, b>=0 より、a+b>=0, よってa==0 and b == 0でなければ、a >0 or b> 0
    #ma = bisection(2, a, MOD)
    #mb = bisection(2, b, MOD)
    #res *= ma + mb -1
res *= pow(2, a, MOD) + pow(2, b, MOD) - 1
res %= MOD

#elif(a == 0 and b > 0):
    #mb = bisection(2, b, MOD)
    #res *= mb
    #res %= MOD
#elif(a > 0 and b == 0):
    #ma = bisection(2, a, MOD)
    #res *= ma
    #res %= MOD
c = d.pop('c')

#print('a:{}, b:{}, c:{}'.format(a,b,c))
#print('d:{}, len(d):{}'.format(d, len(d)))
#print('res', res)

while len(d) > 0:
    s, v = d.popitem()
    if(s[1] < 0):
        opposite = (-1*s[1], s[0])
    else:
        opposite = (s[1], -1*s[0])
    if opposite in d:
        t = d.pop(opposite)
        #print('s:{}, v:{}, opposite:{}, t:{}, d:{}, len(d):{}'.format(s, v, opposite, t, d, len(d)))
        #mv = bisection(2, v, MOD)
        #mt = bisection(2, t, MOD)        
        #res *= mv + mt - 1
        res *= pow(2, v, MOD) + pow(2, t, MOD) - 1
        res %= MOD
    else:
        #print('s:{}, v:{}, opposite:{},       d:{}, len(d):{}'.format(s, v, opposite, d, len(d)))
        #mv = bisection(2, v, MOD)        
        #res *= mv
        res *= pow(2, v, MOD)
        res %= MOD
    #print('res', res)


res += c
res %= MOD
res = (res + MOD - 1) % MOD

print(res)

Submission status: Wrong Answer

Solution code:
## coding: UTF-8
import math
MOD = 10**9+7
N = int(input())
A = []
for i in range(N):
    A.append(list(map(int,input().split()))) 
d = dict()
'''
def bisection(a, n, p):
    #二分累乗法によるO(log p)計算
    bin_str = format(n, 'b')
    res = 1
    tmp = a
    for i in range(1, len(bin_str)+1):
        if(bin_str[(-1)*i] == '1'):
            res = res * tmp % p
        tmp = tmp * tmp % p
    return res
'''
d['a'] = 0
d['b'] = 0
d['c'] = 0

for i in range(N):
    #l = list(map(int,input().split()))
    l = A[i]
    if(l[0] == 0):
        if(l[1] == 0):
            d['c'] += 1
        else:
            d['b'] += 1
    elif(l[1] == 0):
        d['a'] += 1
    else:
        g = math.gcd(l[0], l[1])
        a = int(l[0]/g)
        b = int(l[1]/g)
        if(a<0):
            p = (-1*a, -1*b)
        else:
            p = (a, b)
        if p in d:
            d[p] += 1
        else:
            d[p] = 1
    #print('i:{}, l[0]:{}, l[1]:{}, d:{}'.format(i, l[0], l[1], d))

res = 1
a = d.pop('a')
b = d.pop('b')
#あとで二分累乗法に変換する
#if(a > 0 and b > 0):
    #a, b>=0 より、a+b>=0, よってa==0 and b == 0でなければ、a >0 or b> 0
    #ma = bisection(2, a, MOD)
    #mb = bisection(2, b, MOD)
    #res *= ma + mb -1
res *= pow(2, a, MOD) + pow(2, b, MOD) - 1
res %= MOD

#elif(a == 0 and b > 0):
    #mb = bisection(2, b, MOD)
    #res *= mb
    #res %= MOD
#elif(a > 0 and b == 0):
    #ma = bisection(2, a, MOD)
    #res *= ma
    #res %= MOD
c = d.pop('c')

#print('a:{}, b:{}, c:{}'.format(a,b,c))
#print('d:{}, len(d):{}'.format(d, len(d)))
#print('res', res)

while len(d) > 0:
    s, v = d.popitem()
    if(s[1] < 0):
        opposite = (-1*s[1], s[0])
    else:
        opposite = (s[1], -1*s[0])
    if opposite in d:
        t = d.pop(opposite)
        #print('s:{}, v:{}, opposite:{}, t:{}, d:{}, len(d):{}'.format(s, v, opposite, t, d, len(d)))
        #mv = bisection(2, v, MOD)
        #mt = bisection(2, t, MOD)        
        #res *= mv + mt - 1
        res *= pow(2, v, MOD) + pow(2, t, MOD) - 1
        res %= MOD
    else:
        #print('s:{}, v:{}, opposite:{},       d:{}, len(d):{}'.format(s, v, opposite, d, len(d)))
        #mv = bisection(2, v, MOD)        
        #res *= mv
        res *= pow(2, v, MOD)
        res %= MOD
    #print('res', res)

if(c>0):
    res += c
res %= MOD
res = (res + MOD - 1) % MOD

print(res)