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

Solution (Python):
def modpow(a,n,p):
    if n==0:
        return 1
    x=modpow(a,n//2,p)
    x=(x*x)%p
    if (n%2)==1:
        x=(x*a)%p
    return x%p
def modinv(a,p):
    return modpow(a,p-2,p)
def ggcd(a,b):
    if(b==0):
        return a
    return ggcd(b,a%b)
import math
import fractions
import collections
import itertools
import pprint
N=int(input())
l1=[]
adivb=[]
bis0=0
bdiva=[]
ais0=0
both0=0
p=10**9+7
fish=[list(map(int,input().split())) for _ in range(N)]
fishcomp=[]
d={}
for i in range(N):
    a=fish[i][0]
    b=fish[i][1]
    g=ggcd(a,b)
    if g!=0:
        a=a//g
        b=b//g
    if b<0:
        a=-a
        b=-b
    if (a!=0)or(b!=0):
        if d.get(a)==None:
            d[a]={}
            d[a][b]=1
        else:
            if d[a].get(b)==None:
                d[a][b]=1
            else:
                val=d[a].get(b)
                d[a][b]=val+1
        fishcomp.append([a, b])
    else:
        both0=both0+1


fishcomp=list(map(list,set(map(tuple,fishcomp))))

length=N-both0
sets=[]
for i in fishcomp:
    a=i[0]
    b=i[1]
    val1=d[a][b]
    
    if d.get(-b)!=None:
        if d[-b].get(a)!=None:
            val2=d[-b][a]
            sets.append([val1,val2])
            length=length-(val2+val1)

pro=1
for i in sets:
    pro=(pro*(pow(2,i[0],p)+pow(2,i[1],p)-1))%p

print((pow(2,length,p)*pro-1+both0)%p)

Solution (Python):
import math
n = int(input())
mod = 10**9 + 7
cou = 0
pdic = {}
kan = []
betu = [0,0,0]

for i in range(n):
    a , b = map(int,input().split())
    if a*b != 0:
        g = math.gcd(abs(a),abs(b))
        if a*b > 0:
            m = 1
        elif a*b < 0:
            m = -1
        p = (m*abs(a)//g,abs(b)//g)
        q = ((-m)*abs(b)//g,abs(a)//g)
        if pdic.get(q,-1) != -1:
            kan[pdic[q]][1] += 1
        elif pdic.get(p,-1) == -1:
            pdic[p] = cou
            kan.append([1,0])
            cou += 1
        elif pdic.get(p,-1) != -1:
            kan[pdic[p]][0] += 1
    elif a*b == 0:
        if a == 0 and b == 0:
            betu[2] += 1
        elif a == 0:
            betu[0] += 1
        elif b == 0:
            betu[1] += 1
        
        
ans = 1
for i in range(len(kan)):
    ans *= (pow(2,kan[i][0],mod) + pow(2,kan[i][1],mod) - 1) % mod
    ans %= mod
ans *= (pow(2,betu[0],mod) + pow(2,betu[1],mod) - 1) % mod
print((ans-1+betu[2])%mod)

Solution (Python):
import collections
n=int(input())
A=[]
AA=[]
B=[]
C=[]
X=[]
mod=10**9+7
p=137053438808121949
for i in range(n):
  a,b=map(int,input().split())
  if a<0:
    a=a*-1
    b=b*-1
  if a*b>0:
    A.append(b*pow(a,p-2,p)%p)
  elif a*b<0:
    AA.append(a*pow((-b),p-2,p)%p)
  else:
    if a==0 and b==0:
      X.append(i)
    elif a==0:
      B.append(i)
    else:
      C.append(i)
D=collections.Counter(A)
DD=collections.Counter(AA)
E=set(list(D)+list(DD))
a=1
for i in E:
  a=(a*(2**D[i]+2**DD[i]-1))%mod
a=(a*(2**len(B)+2**len(C)-1)-1)%mod
print((a+len(X))%mod)

Solution (Python):
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

    flip = 0
    while not (a >= 0 and b > 0):
        a, b = -b, a
        flip ^= 1

    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)

Solution (Python):
def modpow(a,n,p):
    if n==0:
        return 1
    x=modpow(a,n//2,p)
    x=(x*x)%p
    if (n%2)==1:
        x=(x*a)%p
    return x%p
def modinv(a,p):
    return modpow(a,p-2,p)
def ggcd(a,b):
    if(b==0):
        return a
    return ggcd(b,a%b)
import math
import fractions
import collections
import itertools
import pprint
N=int(input())
l1=[]
adivb=[]
bis0=0
bdiva=[]
ais0=0
both0=0
p=10**9+7
fish=[list(map(int,input().split())) for _ in range(N)]
fishcomp=[]
d={}
for i in range(N):
    
    
    a=fish[i][0]
    b=fish[i][1]
    g=ggcd(abs(a),abs(b))
    if g!=0:        
        a=a//g
        b=b//g
    
    if b<0:
        a=-a
        b=-b
    
    if (a!=0)or(b!=0):
        if d.get(a)==None:
            d[a]={}
            d[a][b]=1
        else:
            if d[a].get(b)==None:
                d[a][b]=1
            else:
                val=d[a].get(b)
                d[a][b]=val+1
        fishcomp.append([a, b])
    else:
        both0=both0+1


fishcomp=list(map(list,set(map(tuple,fishcomp))))   

length=N-both0
sets=[]




for i in fishcomp:
    a=i[0]
    b=i[1]
    val1=d[a][b]
    
    if d.get(-b)!=None:
        if d[-b].get(a)!=None:
            val2=d[-b][a]
            sets.append([val1,val2])
            length=length-(val2+val1)

pro=1
for i in sets:
    pro=(pro*(pow(2,i[0],p)+pow(2,i[1],p)-1))%p

print((pow(2,length,p)*pro-1+both0)%p)

Solution (Python):
import sys
import math
input = sys.stdin.buffer.readline

def main():
    N = int(input())
    MOD = 1000000007
    d = {}
    
    pd = [1]
    for _ in range(N):
        pd.append((pd[-1]*2)%MOD)

    zero = 0
    ab = [0,0]
    for i in range(N):
        a,b = map(int,input().split())
        if a == b == 0:
            zero += 1
        elif a*b == 0:
            if a == 0:
                ab[0] += 1
            else:
                ab[1] += 1
        else:
            gcd = math.gcd(abs(a),abs(b))
            a //= gcd
            b //= gcd
            if a < 0 and b < 0:
                a *= -1
                b *= -1
            elif a < 0 and b > 0:
                a,b = b,a
            elif a > 0 and b < 0:
                a *= -1
                b *= -1
                a,b = b,a
            if (a,b) not in d:
                d[(a,b)] = 1
            else:
                d[(a,b)] += 1

    ans = 1
    use = {}
    
    for k,v in d.items():
        a,b = k
        if (a,-b) in d:
            if (a,-b) in use:
                continue
            ret = pd[d[(a,b)]]+pd[d[(a,-b)]]-1
            ans *= ret
            use[(a,b)] = 1
            use[(a,-b)] = 1
        else:
            ret = pd[d[(a,b)]]
            ans *= ret
            use[(a,b)] = 1
        ans %= MOD

    ret = pd[ab[0]]+pd[ab[1]]-1
    ans *= ret
    ans += zero
    
    print((ans-1)%MOD)
    
if __name__ == "__main__":
    main()

Solution (Python):
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

    flip = 0
    while not (a > 0 and b >= 0):
        a, b = -b, a
        flip ^= 1

    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)

Solution (Python):
from collections import defaultdict
from math import gcd

N = int(input())

MOD = 1000000007
d_plus = defaultdict(int)  
d_minus = defaultdict(int)  
ans = 1
ans_00 = 0
for i in range(N):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        ans_00 += 1
    elif a == 0:
        d_minus[0] += 1
    elif b == 0:
        d_plus[float('inf')] += 1
    else:
        g = gcd(a, b)
        if (a > 0) ^ (b > 0):
            d_plus[(abs(a // g), abs(b // g))] += 1
        else:
            d_minus[(abs(a // g), -abs(b // g))] += 1


def pair(p):
    if p == 0:
        return float('inf')
    elif p == float('inf'):
        return 0
    else:
        a, b = -p[1], p[0]
        if a < 0:
            a, b = -a, -b
        return a, b


for m in d_minus:
    d_plus[pair(m)]
for p in d_plus:
    ans *= (pow(2, d_plus[p], MOD) + pow(2, d_minus[pair(p)], MOD) - 1)
    ans %= MOD
print((ans - 1 + ans_00) % MOD)

Solution (Python):
import collections
import math

n = int(input())
m = 0
mod = 10 ** 9 + 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
    if a == 0:
        frac.append('0/1')
    elif b == 0:
        frac.append(('1/0'))
    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.append('{}/{}'.format(a, b))

frac = collections.Counter(frac)

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[0] == '-' or key[0] == '0': continue
    if frac[inverse(key)] > 0:
        c.append(value)
        d.append(frac[inverse(key)])

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) % mod
    ans = ans * tmp % mod
ans = (ans - 1 + m) % mod

print(ans)

Solution (Python):
def main():
    import sys
    input = sys.stdin.buffer.readline
    from collections import Counter as cc
    from fractions import gcd
    n = int(input())
    mod = 10**9 + 7
    C_p,C_n = cc(),cc()
    count= 0
    count_zero_a = count_zero_b = 0
    ans = 1
    for i in range(n):
        a,b = map(int, input().split())
        if a == 0 and b== 0:
            count += 1
        else:
            gcd_ab = gcd(a,b)
            a //= gcd_ab
            b //= gcd_ab
            if b == 0:
                count_zero_b += 1
            elif a == 0: 
                count_zero_a += 1
            else:
                if a/b>0:
                    C_p[a,b] += 1
                else:
                    C_n[a,b] += 1
    count_zero = count
    ans *= (2**count_zero_a + 2**count_zero_b -1)%mod
    count += count_zero_a + count_zero_b    
    for a,b in C_p:
        if (-b,a) in C_n:
            count += C_n[-b,a] + C_p[a,b]
            ans *= (2**C_n[-b,a] + 2**C_p[a,b] -1)%mod
    ans *= pow(2,n-count,mod)%mod
    ans = (ans +count_zero -1) % mod
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from math import gcd
def to_standard_form(a, b):
    if a == 0:
        return (0, 1)
    g = gcd(a, b)
    a //= g
    b //= g
    if a < 0:
        return (-a, -b)
    return (a, b)

N, = map(int, input().split())
d = dict()
X = []
cc = 0
for _ in range(N):
    a, b = map(int, input().split())
    if a == 0 and b==0:
        cc += 1
        continue
    f = to_standard_form(a, b)
    if f not in d:
        d[f] = 0
    d[f] += 1
    X.append(f)

vs = dict()
for a, b in X:
    f1 = (a, b)
    f2 = to_standard_form(-b, a)
    if f2 not in d:
        d[f2] = 0
    if f1 in vs or f2 in vs:
        continue
    vs[f1] = (d[f1], d[f2])

mod = 10**9+7
r = 1
for k in vs:
    a, b = vs[k]
    r = r * (pow(2, a, mod) + pow(2, b, mod)-1) % mod
print((r-1+cc)%mod)

Solution (Python):
import collections
n=int(input())
A=[]
AA=[]
B=[]
C=[]
X=[]
mod=277078100995604201
for i in range(n):
  a,b=map(int,input().split())
  if a<0:
    a=a*-1
    b=b*-1
  if a*b>0:
    A.append(b*pow(a,mod-2,mod)%mod)
  elif a*b<0:
    AA.append(a*pow((-b),mod-2,mod)%mod)
  else:
    if a==0 and b==0:
      X.append(i)
    elif a==0:
      B.append(i)
    else:
      C.append(i)
mod = 10**9+7
D=collections.Counter(A)
DD=collections.Counter(AA)
E=set(list(D)+list(DD))
a=1
for i in E:
  a=(a*(2**D[i]+2**DD[i]-1))%mod
a=(a*(2**len(B)+2**len(C)-1)-1)%mod
print((a+len(X))%mod)

Solution (Python):
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 + non_count) % mod)


if __name__ == '__main__':
    main()

Solution (Python):
from sys import stdin, setrecursionlimit
from collections import defaultdict
from math import gcd

setrecursionlimit(10 ** 9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


MOD = 1000000007
N, *AB = map(int, stdin.buffer.read().split())

d = defaultdict(int)
zeros = 0
for a, b in zip(*[iter(AB)] * 2):
    if a == 0 and b == 0:
        zeros += 1
    else:
        g = gcd(a, b)
        a //= g
        b //= g
        if a < 0:
            a *= -1
            b *= -1
        if a == 0 and b == -1:
            b = 1
        d[(a, b)] += 1

ans = 1
free = 0
for (a, b), n in d.items():
    if b > 0:
        if (b, -a) in d:
            m = d[(b, -a)]
            ans = ans * (pow(2, n, MOD) + pow(2, m, MOD) - 1) % MOD
        else:
            free += n
    else:
        if (-b, a) not in d:
            free += n

ans = (ans * pow(2, free, MOD) + zeros - 1) % MOD
print(ans)

Solution (Python):
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(x, y)
  x //= g
  y //= g
  d[(x, y)] += 1

res = 1
itr = list(d.keys())

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 - 1 + z) % mod)

Solution (Python):
from sys import stdin, setrecursionlimit
from collections import defaultdict
from math import gcd

setrecursionlimit(10 ** 9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


MOD = 1000000007
N, *AB = map(int, stdin.buffer.read().split())

d = defaultdict(int)
zeros = 0
for a, b in zip(*[iter(AB)] * 2):
    if a == 0 and b == 0:
        zeros += 1
    else:
        g = gcd(a, b)
        a //= g
        b //= g
        if a < 0:
            a *= -1
            b *= -1
        if a == 0 and b == -1:
            b = 1
        d[(a, b)] += 1

ans = 1
free = 0
for (a, b), n in d.items():
    if b > 0:
        if (b, -a) in d:
            m = d[(b, -a)]
            ans = ans * (pow(2, n, MOD) + pow(2, m, MOD) - 1) % MOD
        else:
            free += n
    else:
        if (-b, a) not in d:
            free += n

ans = (ans * pow(2, free, MOD) + zeros - 1) % MOD
print(ans)

Solution (Python):
def modpow(a,n,p):
    if n==0:
        return 1
    x=modpow(a,n//2,p)
    x=(x*x)%p
    if (n%2)==1:
        x=(x*a)%p
    return x%p
def modinv(a,p):
    return modpow(a,p-2,p)
def ggcd(a,b):
    if(b==0):
        return a
    return ggcd(b,a%b)
import math
import fractions
import collections
import itertools
import pprint
N=int(input())
l1=[]
adivb=[]
bis0=0
bdiva=[]
ais0=0
both0=0
p=10**9+7
fish=[list(map(int,input().split())) for _ in range(N)]
fishcomp=[]
d={}
for i in range(N):
    a=fish[i][0]
    b=fish[i][1]
    g=ggcd(abs(a),abs(b))
    if g!=0:
        a=a//g
        b=b//g
    if (b==0)and(a>0):
        a=1
    elif b<0:
        a=-a
        b=-b
    if (a!=0)or(b!=0):
        if d.get(a)==None:
            d[a]={}
            d[a][b]=1
        else:
            if d[a].get(b)==None:
                d[a][b]=1
            else:
                val=d[a].get(b)
                d[a][b]=val+1
        fishcomp.append([a, b])
    else:
        both0=both0+1


fishcomp=list(map(list,set(map(tuple,fishcomp))))

length=N-both0
sets=[]
for i in fishcomp:
    a=i[0]
    b=i[1]
    val1=d[a][b]
    
    if d.get(-b)!=None:
        if d[-b].get(a)!=None:
            val2=d[-b][a]
            sets.append([val1,val2])
            length=length-(val2+val1)

pro=1
for i in sets:
    pro=(pro*(pow(2,i[0],p)+pow(2,i[1],p)-1))%p

print((pow(2,length,p)*pro-1+both0)%p)

Solution (Python):
from sys import stdin, setrecursionlimit
from collections import defaultdict
from math import gcd

setrecursionlimit(10 ** 9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


MOD = 1000000007
N = int(input())

d = defaultdict(int)
zeros = 0
for i in range(N):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        zeros += 1
    else:
        g = gcd(a, b)
        a //= g
        b //= g
        if a < 0:
            a *= -1
            b *= -1
        if a == 0 and b == -1:
            b = 1
        d[(a, b)] += 1

ans = 1
free = 0
for (a, b), n in d.items():
    if b > 0:
        if (b, -a) in d:
            m = d[(b, -a)]
            ans = ans * (pow(2, n, MOD) + pow(2, m, MOD) - 1) % MOD
        else:
            free += n
    else:
        if (-b, a) not in d:
            free += n

ans = (ans * pow(2, free, MOD) + zeros - 1) % MOD
print(ans)

Solution (Python):
from sys import stdin, setrecursionlimit
from collections import defaultdict
from math import gcd

setrecursionlimit(10 ** 9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


MOD = 1000000007
N = int(input())

d = defaultdict(int)
zeros = 0
for i in range(N):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        zeros += 1
    else:
        g = gcd(a, b)
        a //= g
        b //= g
        if a < 0:
            a *= -1
            b *= -1
        if a == 0 and b == -1:
            b = 1
        d[(a, b)] += 1

ans = 1
free = 0
for (a, b), n in d.items():
    if b > 0:
        if (b, -a) in d:
            m = d[(b, -a)]
            ans = ans * (pow(2, n, MOD) + pow(2, m, MOD) - 1) % MOD
        else:
            free += n
    else:
        if (-b, a) not in d:
            free += n

ans = (ans * pow(2, free, MOD) + zeros - 1) % MOD
print(ans)

Solution (Python):
from sys import stdin, setrecursionlimit
from collections import defaultdict
from math import gcd

setrecursionlimit(10 ** 9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


MOD = 1000000007
N, *AB = map(int, stdin.buffer.read().split())
it = iter(AB)

d = defaultdict(int)
zeros = 0
for a, b in zip(it, it):
    if a == 0 and b == 0:
        zeros += 1
    else:
        g = gcd(a, b)
        a //= g
        b //= g
        if a < 0:
            a *= -1
            b *= -1
        if a == 0 and b == -1:
            b = 1
        d[(a, b)] += 1

ans = 1
free = 0
for (a, b), n in d.items():
    if b > 0:
        if (b, -a) in d:
            m = d[(b, -a)]
            ans = ans * (pow(2, n, MOD) + pow(2, m, MOD) - 1) % MOD
        else:
            free += n
    else:
        if (-b, a) not in d:
            free += n

ans = (ans * pow(2, free, MOD) + zeros - 1) % MOD
print(ans)

Solution (Python):
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 or a == 0 and b < 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)

Solution (Python):
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
result += d[0][0] - 1
result %= 1000000007
print(result)

Solution (Python):
import sys
from collections import Counter
from math import gcd


MOD = 10 ** 9 + 7


def prepare(n):
    global MOD
    modFacts = [0] * (n + 1)
    modFacts[0] = 1
    for i in range(n):
        modFacts[i + 1] = (modFacts[i] * (i + 1)) % MOD

    invs = [1] * (n + 1)
    invs[n] = pow(modFacts[n], MOD - 2, MOD)
    for i in range(n, 1, -1):
        invs[i - 1] = (invs[i] * i) % MOD

    return modFacts, invs


def profile(fish):
    x, y = fish
    GCD = gcd(abs(x), abs(y))

    return (abs(x // GCD), abs(y // GCD), int((x >= 0) ^ (y >= 0)))


N = int(input())
F = [tuple(map(int, s.split())) for s in sys.stdin.readlines()]
modFacts, invs = prepare(N)

C0 = Counter()
C1 = Counter()
zero = 0
for f in F:
    if f == (0, 0):
        zero += 1
    else:
        x, y, flag = profile(f)
        if x == 0:
            C0[(0, 1, 0)] += 1
            C1[(0, 1, 0)] += 1
        elif y == 0:
            C0[(0, 1, 0)] += 1
            C1[(1, 0, 1)] += 1
        else:
            C1[(x, y, flag)] += 1
            if flag:
                x, y = y, x
                flag = 0
            C0[(x, y, flag)] += 1

ans = 1
for x, y, flag in C0.keys():
    b = C1[(y, x, flag ^ 1)]
    a = C0[(x, y, flag)] - b
    cnt = (pow(2, a, MOD) - 1) + (pow(2, b, MOD) - 1) + 1
    ans *= cnt
    ans %= MOD
ans -= 1
ans += zero
print(ans % MOD)

Solution (Python):
from sys import stdin, setrecursionlimit
from collections import defaultdict
from math import gcd

setrecursionlimit(10 ** 9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


MOD = 1000000007
N, *AB = map(int, stdin.buffer.read().split())
d = defaultdict(int)
zeros = 0
for a, b in zip(AB[::2], AB[1::2]):
    if a == 0 and b == 0:
        zeros += 1
    else:
        g = gcd(a, b)
        a //= g
        b //= g
        if a < 0:
            a *= -1
            b *= -1
        if a == 0 and b == -1:
            b = 1
        d[(a, b)] += 1

ans = 1
free = 0
for (a, b), n in d.items():
    if b > 0:
        if (b, -a) in d:
            m = d[(b, -a)]
            ans = ans * (pow(2, n, MOD) + pow(2, m, MOD) - 1) % MOD
        else:
            free += n
    else:
        if (-b, a) not in d:
            free += n

ans = (ans * pow(2, free, MOD) + zeros - 1) % MOD
print(ans)

Solution (Python):
from sys import stdin, setrecursionlimit
from collections import defaultdict
from math import gcd

setrecursionlimit(10 ** 9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


MOD = 1000000007
N, *AB = map(int, stdin.buffer.read().split())
d = defaultdict(int)
zeros = 0
for a, b in zip(AB[::2], AB[1::2]):
    if a == 0 and b == 0:
        zeros += 1
    else:
        g = gcd(a, b)
        a //= g
        b //= g
        if a < 0:
            a *= -1
            b *= -1
        if a == 0 and b == -1:
            b = 1
        d[(a, b)] += 1

ans = 1
free = 0
for (a, b), n in d.items():
    if b > 0:
        if (b, -a) in d:
            m = d[(b, -a)]
            ans = ans * (pow(2, n, MOD) + pow(2, m, MOD) - 1) % MOD
        else:
            free += n
    else:
        if (-b, a) not in d:
            free += n

ans = (ans * pow(2, free, MOD) + zeros - 1) % MOD
print(ans)

Solution (Python):
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())
    if a == 0 and b == 0:
        zero_cases += 1
    elif a * b >= 0 and b != 0:
        irr = to_irreducible(abs(a), abs(b))
        quadrant1[irr] += 1
    else:
        irr = to_irreducible(abs(b), abs(a))
        quadrant2[irr] += 1
        quadrant1[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)

Solution (Python):
from sys import stdin, setrecursionlimit
from collections import defaultdict
from math import gcd

setrecursionlimit(10 ** 9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


MOD = 1000000007
N, *AB = map(int, stdin.buffer.read().split())
d = defaultdict(int)
zeros = 0
for a, b in zip(AB[::2], AB[1::2]):
    if a == 0 and b == 0:
        zeros += 1
    else:
        g = gcd(a, b)
        a //= g
        b //= g
        if a < 0:
            a *= -1
            b *= -1
        if a == 0 and b == -1:
            b = 1
        d[(a, b)] += 1

ans = 1
free = 0
keys = sorted(d.keys())
for a, b in keys:
    n = d[(a, b)]
    if b > 0:
        if (b, -a) in d:
            m = d[(b, -a)]
            ans = ans * (pow(2, n, MOD) + pow(2, m, MOD) - 1) % MOD
        else:
            free += n
    else:
        if (-b, a) not in d:
            free += n

ans = (ans * pow(2, free, MOD) + zeros - 1) % MOD
print(ans)

Solution (Python):

import math
from collections import defaultdict
p = 10 ** 9 + 7

n = int(input())
dict = defaultdict(int)
for i in range(n):
    a, b = [int(x) for x in input().split()]
    if a == 0 and b == 0:
        pass
    elif a == 0:
        b = -1
    else:
        d = (a // abs(a)) * math.gcd(a, b)
        a = a // d
        b = b // d
    dict[(a, b)] += 1

bad = []    
others = []  
zeros = 0  
for (a, b) in dict:
    if dict[(a, b)] == 0: continue
    if a == 0 and b == 0:
        zeros += dict[(a, b)]
        dict[(a, b)] = 0
    elif (b, -a) in dict:
        bad.append((dict[(a, b)], dict[(b, -a)]))
    elif (-b, a) in dict:
        pass    
    else:
        others.append(dict[(a, b)])

ans = 1
for (x, y) in bad:
    ans = ans * (pow(2, x, p) + pow(2, y, p) - 1) % p
for z in others:
    ans = ans * pow(2, z, p) % p
ans = (ans + zeros - 1) % p
print(ans)

Solution (Python):
import math
N = int(input())
A = 0
B = 0
Z = 0
C = {}
m = 1000000007

def mypow(dummy, num):
    ans = 1
    for i in range(num):
        ans = (ans*2)%1000000007
    return ans

def rNum(a, b):
    g = math.gcd(a, b)
    if a <0 and b<0:
        a *= -1
        b *= -1
    if a >0 and b <0:
        return (-1*(a//g), -1*(b//g))
    else:
        return (a//g, b//g)


for i in range(N):
    a, b = map(int, input().split())
    
    if a == 0 and b==0:
        Z += 1
        continue
    elif a==0:
        A += 1
        continue
    elif b==0:
        B +=1
        continue
    
    r = rNum(a, b)
    if r in C.keys():
        C[r] +=1
    else: C[r] = 1


used = set()
ans = 1
ans *= (mypow(2, A) + mypow(2, B) -1)%m


for c in C.keys():
    if c in used: continue
    a, b = c
    r = rNum(b, -1*a)
    if r in C.keys():
        if c == r: continue
        used.add(r)
        score = (mypow(2, C[c]) + mypow(2, C[r])- 1)
        ans *= score

    else:
        ans *= mypow(2, C[c])

ans += Z

print((ans-1)%m)

Solution (Python):
from collections import defaultdict
import math
MOD = 10 ** 9 + 7

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N = Z()
    AB = [ZZ() for _ in range(N)]
    AB = [[a, b] for a, b in AB if a != 0 or b != 0] 
    cnt_0 = N - len(AB) 
    vec = defaultdict(int) 

    
    for i in range(len(AB)):
        a, b = AB[i]
        if a < 0: a, b = -a, -b
        if a == 0: b = abs(b)
        g = math.gcd(a, b)
        a //= g
        b //= g
        vec[(a, b)] += 1

    output = 1
    used = set()
    for v in vec.keys():
        if v in used: continue
        a, b = v
        inv = (-b, a) if b < 0 else (b, -a)
        if b == 0: inv = (b, abs(a))
        if inv in vec.keys():
            output *= (pow(2, vec[v], MOD) + pow(2, vec[inv], MOD) - 1)
        else: output *= pow(2, vec[v], MOD)
        output %= MOD
        used.add(v)
        used.add(inv)

    output += cnt_0 - 1
    output %= MOD
    print(output)
    return

if __name__ == '__main__':
    main()

Solution (Python):
from math import gcd
from collections import defaultdict
N=int(input())
mod = 10**9+7
d_1 = defaultdict(int)
d_2 = defaultdict(int)
zeros = 0

def to_irreducible(a,b):
    GCD = gcd(a,b)
    return list(map(lambda x:x//GCD,[a,b]))
for i in range(N):
    a,b=map(int,input().split(' '))
    if a==b==0:
        zeros += 1
    elif a*b >= 0 and b!=0:
        a,b = to_irreducible(abs(a),abs(b))
        d_1[(a,b)] +=1
    else:
        a,b = to_irreducible(abs(b),abs(a))
        d_1[(a,b)] +=0
        d_2[(a,b)] +=1

ans =  1

for k,v_1 in d_1.items():
    v_2 = d_2[k]
    ans *= (pow(2,v_1,mod) + pow(2,v_2,mod) -1)
    ans %= mod

print((ans+zeros-1)%mod)

Solution (Python):
from sys import stdin, setrecursionlimit
from collections import defaultdict
from math import gcd

setrecursionlimit(10 ** 9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


MOD = 1000000007
N = int(input())
d = defaultdict(int)
zeros = 0
for i in range(N):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        zeros += 1
    else:
        g = gcd(a, b)
        a //= g
        b //= g
        if a < 0:
            a *= -1
            b *= -1
        if a == 0 and b == -1:
            b = 1
        d[(a, b)] += 1

ans = 1
free = 0
keys = sorted(d.keys())
for a, b in keys:
    n = d[(a, b)]
    if b > 0:
        if (b, -a) in d:
            m = d[(b, -a)]
            ans = ans * (pow(2, n, MOD) + pow(2, m, MOD) - 1) % MOD
        else:
            free += n
    else:
        if (-b, a) not in d:
            free += n

ans = (ans * pow(2, free, MOD) + zeros - 1) % MOD
print(ans)