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:
## 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 += 1
res -= 1

print(res)

Submission status: Wrong Answer

Solution code:
## coding: UTF-8
import math
MOD = 1000000007
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 += 1
res -= 1

print(res)

Submission status: Wrong Answer

Solution code:
## coding: UTF-8
import math
MOD = 1000000007
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 
        tmp = tmp * tmp 
    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 %= 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 %= MOD
    else:
        #print('s:{}, v:{}, opposite:{},       d:{}, len(d):{}'.format(s, v, opposite, d, len(d)))
        mv = bisection(2, v, MOD)        
        res *= mv
        res %= MOD
    #print('res', res)

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

print(res)

Submission status: Wrong Answer

Solution code:
## coding: UTF-8
import math
MOD = 1000000007
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 %= 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 %= MOD
    else:
        #print('s:{}, v:{}, opposite:{},       d:{}, len(d):{}'.format(s, v, opposite, d, len(d)))
        mv = bisection(2, v, MOD)        
        res *= mv
        res %= MOD
    #print('res', res)

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

print(res)

Submission status: Wrong Answer

Solution code:
## coding: UTF-8
import math
MOD = 1000000007
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+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 %= 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 %= MOD
    else:
        #print('s:{}, v:{}, opposite:{},       d:{}, len(d):{}'.format(s, v, opposite, d, len(d)))
        mv = bisection(2, v, MOD)        
        res *= mv
        res %= MOD
    #print('res', res)

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

print(res)

Submission status: Wrong Answer

Solution code:
N=int(input())
ls=[list(map(int,input().split())) for _ in range(N)]
s=0
t=0
for i in range(0,N):
    for j in range(i+1,N):
        if ls[i][0]*ls[j][0]+ls[i][1]*ls[j][1]!=0:
            s=s+1
print((s+N)%1000000007)

Submission status: Wrong Answer

Solution code:
N=int(input())
ls=[list(map(int,input().split())) for _ in range(N)]
s=0
for i in range(0,N):
    x=ls[i][0]+ls[i][1]
    if x!=0:
        s=s+1
for j in range(0,N):
    for k in range(j+1,N):
        y=ls[j][0]*ls[k][0]+ls[j][1]*ls[k][1]
        if y!=0:
            s=s+1
print(s%1000000007)

Submission status: Wrong Answer

Solution code:
from math import gcd
n=int(input())
mod=10**9+7
d1=dict()
d2=dict()
zero=0
zeroa=0
zerob=0
for _ in range(n):
    a,b=map(int,input().split())
    if a==0 and b==0:
        zero+=1
    elif a==0 and b!=0:
        zeroa+=1
    elif a!=0 and b==0:
        zerob+=1
    else:
        g=gcd(abs(a),abs(b))
        na=a//g
        nb=b//g
        if (na,nb) not in d1 and (na,nb) not in d2:
            d1[(na,nb)]=1
            d2[(-nb,na)]=0
            d2[(nb,-na)]=0
        elif (na,nb) in d1:
            d1[(na,nb)]+=1
        elif (-na,-nb) in d1:
            d1[(-na,-nb)]+=1
        elif (na,nb) in d2:
            d2[(na,nb)]+=1
        else:
            d2[(-na,-nb)]+=1
#print(d1)
#print(d2)
d1=list(d1.items())
ans=pow(2,zeroa,mod)+pow(2,zerob,mod)-1
ans%=mod
for (a,b),cnt1 in d1:
  cnt2=0
  cnt2+=d2[(-b,a)]
  cnt2+=d2[(b,-a)]
  ans*=pow(2,cnt1,mod)+pow(2,cnt2,mod)-1
  ans%=mod
ans+=zero
ans=(ans+mod-1)%mod
print(ans)
#print(zeroa,zerob)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from math import gcd
n = int(input())
lst = []
cnt = 0

for i in range(n):
    a,b = map(int,input().split())
    if a == b == 0:
        cnt += 1
    elif b > 0:
        lst.append((a/gcd(a,b),b/gcd(a,b)))
    elif b < 0:
        lst.append((-a/gcd(a,b),-b/gcd(a,b)))
    else:
        lst.append((1,0))

c = Counter(lst)
ans = 1
for k,v in c.items():
    if k[0] <= 0 or k[1]==0:
        continue
    j = c[(-k[1],k[0])]
    ans *= 2**j+2**v-1
    c[k] = 0
    if c[(-k[1],k[0])]:
        c[(-k[1],k[0])] = 0
for k,v in c.items():
    if k[0] == 0 or v == 0 or k[1] == 0:
        continue
    ans *= 2**v
ans *= 2**c[(0,1)]+2**c[(1,0)]-1
ans += cnt
print(ans-1)

Submission status: Wrong Answer

Solution code:
from math import gcd
n=int(input())
mod=10**9+7
d1=dict()
d2=dict()
zero=0
zeroa=0
zerob=0
for _ in range(n):
    a,b=map(int,input().split())
    if a==0 and b==0:
        zero+=1
    elif a==0 and b!=0:
        zeroa+=1
    elif a!=0 and b==0:
        zerob+=1
    else:
        g=gcd(abs(a),abs(b))
        na=a//g
        nb=b//g
        if (na,nb) not in d1 and (na,nb) not in d2:
            d1[(na,nb)]=1
            d2[(-nb,na)]=0
            d2[(nb,-na)]=0
        elif (na,nb) in d1:
            d1[(na,nb)]+=1
        else:
            d2[(na,nb)]+=1
#print(d1)
#print(d2)
d1=list(d1.items())
ans=pow(2,zeroa,mod)+pow(2,zerob,mod)-1
ans%=mod
for (a,b),cnt1 in d1:
  cnt2=0
  cnt2+=d2[(-b,a)]
  cnt2+=d2[(b,-a)]
  ans*=pow(2,cnt1,mod)+pow(2,cnt2,mod)-1
  ans%=mod
ans+=zero
ans=(ans+mod-1)%mod
print(ans)

Submission status: Wrong Answer

Solution code:
from math import gcd
n=int(input())
mod=10**9+7
d1=dict()
d2=dict()
zero=0
zeroa=0
zerob=0
for _ in range(n):
    a,b=map(int,input().split())
    if a==0 and b==0:
        zero+=1
    elif a==0 and b!=0:
        zeroa+=1
    elif a!=0 and b==0:
        zerob+=1
    else:
        g=gcd(abs(a),abs(b))
        na=a//g
        nb=b//g
        if (na,nb) not in d1 and (na,nb) not in d2:
            d1[(na,nb)]=1
            d2[(-nb,na)]=0
            d2[(nb,-na)]=0
        elif (na,nb) in d1:
            d1[(na,nb)]+=1
        else:
            d2[(na,nb)]+=1
#print(d1)
#print(d2)
d1=list(d1.items())
ans=pow(2,zeroa,mod)+pow(2,zerob,mod)-1
for (a,b),cnt1 in d1:
  cnt2=0
  cnt2+=d2[(-b,a)]
  cnt2+=d2[(b,-a)]
  ans*=pow(2,cnt1,mod)+pow(2,cnt2,mod)-1
  ans%=mod
ans+=zero
ans=(ans+mod-1)%mod
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
lst=[list(map(int,input().split())) for i in range(n)]
count=0
for x in lst:
  for y in lst:
    if x!=y:
      if (x[0]*y[0]+x[1]*y[1])==0:
        count+=1
print((2**n-(count//2)*2**(n-2))%1000000007)

Submission status: Wrong Answer

Solution code:
n=int(input())
lst=[list(map(int,input().split())) for i in range(n)]
count=0
for x in lst:
  for y in lst:
    if x!=y:
      if (x[0]*y[0]+x[1]*y[1])==0:
        count+=1
print((2**n-count//2)%1000000007)

Submission status: Wrong Answer

Solution code:
n=int(input())
lst=[list(map(int,input().split())) for i in range(n)]
count=0
for x in lst:
  for y in lst:
    if x!=y:
      if (x[0]*y[0]+x[1]+y[1])==0:
        count+=1
print((2**n-count//2)%1000000007)

Submission status: Wrong Answer

Solution code:
from math import gcd
n=int(input())
mod=10**9+7
d1=dict()
d2=dict()
zero=0
zeroa=0
zerob=0
for _ in range(n):
    a,b=map(int,input().split())
    if a==0 and b==0:
        zero+=1
    elif a==0 and b!=0:
        zeroa+=1
    elif a!=0 and b==0:
        zerob+=1
    else:
        g=gcd(abs(a),abs(b))
        na=a//g
        nb=b//g
        if (na,nb) not in d1 and (na,nb) not in d2:
            d1[(na,nb)]=1
            d2[(-nb,na)]=0
            d2[(nb,-na)]=0
        elif (na,nb) in d1:
            d1[(na,nb)]+=1
        else:
            d2[(na,nb)]+=1
#print(d1)
#print(d2)
d1=list(d1.items())
ans=pow(2,zeroa,mod)+pow(2,zerob,mod)-1
for (a,b),cnt1 in d1:
  cnt2=0
  if (-b,a) in d2:
      cnt2+=d2[(-b,a)]
  if (b,-a) in d2:
      cnt2+=d2[(b,-a)]
  if cnt2>0:
      ans*=pow(2,cnt1,mod)+pow(2,cnt2,mod)-1+mod
  else:
      ans*=pow(2,cnt1,mod)
  ans%=mod
if zero>0:
    ans+=zero
ans=(ans+mod-1)%mod
print(ans)

Submission status: Wrong Answer

Solution code:
from math import gcd
n=int(input())
mod=10**9+7
d1=dict()
d2=dict()
zero=0
zeroa=0
zerob=0
for _ in range(n):
    a,b=map(int,input().split())
    if a==0 and b==0:
        zero+=1
    elif a==0 and b!=0:
        zeroa+=1
    elif a!=0 and b==0:
        zerob+=1
    else:
        g=gcd(abs(a),abs(b))
        na=a//g
        nb=b//g
        if (na,nb) not in d1 and (na,nb) not in d2:
            d1[(na,nb)]=1
            d2[(-nb,na)]=0
            d2[(nb,-na)]=0
        elif (na,nb) in d1:
            d1[(na,nb)]+=1
        else:
            d2[(na,nb)]+=1
#print(d1)
#print(d2)
d1=list(d1.items())
ans=pow(2,zeroa,mod)+pow(2,zerob,mod)-1
for (a,b),cnt1 in d1:
  cnt2=0
  if (-b,a) in d2:
      cnt2+=d2[(-b,a)]
  if (b,-a) in d2:
      cnt2+=d2[(b,-a)]
  if cnt2>0:
      ans*=pow(2,cnt1,mod)+pow(2,cnt2,mod)-1+mod
  else:
      ans*=pow(2,cnt1,mod)
  ans%=mod
if zero>0:
    ans+=pow(2,zero,mod)-1
ans=(ans+mod-1)%mod
print(ans)

Submission status: Wrong Answer

Solution code:
from math import gcd
n=int(input())
mod=10**9+7
d1=dict()
d2=dict()
zero=0
for _ in range(n):
    a,b=map(int,input().split())
    if a==0 or b==0:
        zero+=1  
    else:
        g=gcd(abs(a),abs(b))
        na=a//g
        nb=b//g
        if (na,nb) not in d1 and (na,nb) not in d2:
            d1[(na,nb)]=1
            d2[(-nb,na)]=0
            d2[(nb,-na)]=0
        elif (na,nb) in d1:
            d1[(na,nb)]+=1
        else:
            d2[(na,nb)]+=1
#print(d1)
#print(d2)
d1=list(d1.items())
ans=pow(2,zero,mod)
for (a,b),cnt1 in d1:
  cnt2=0
  if (-b,a) in d2:
      cnt2+=d2[(-b,a)]
  if (b,-a) in d2:
      cnt2+=d2[(b,-a)]
  if cnt2>0:
      ans*=pow(2,cnt1,mod)+pow(2,cnt2,mod)-1+mod
  else:
      ans*=pow(2,cnt1,mod)
  ans%=mod
ans=(ans+mod-1)%mod
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf
# @pysnooper.snoop()
#import pysnooper # debug

import math
#from sortedcontainers import SortedList, SortedDict, SortedSet # no in atcoder
import bisect
from fractions import Fraction
from collections import defaultdict

MOD = 1000000007

class Sardine:
    def __init__(self, a, b):
        if a == 0 and b == 0:
            self.type_ = 0
        elif a == 0:
            self.type_ = 'a'
        elif b == 0:
            self.type_ = 'b'
        else:
            self.type_ = Fraction(a, b)

def combi(x, y):
    res = pow(2, x, MOD) - 1 + pow(2, y, MOD) - 1 + 1
    #print('res', x, y) # debug
    #print(res) # debug
    return res

def calc_cross_type(frac):
    cross = Fraction(-1 * frac.denominator, frac.numerator)
    #print('cross', frac, cross) # debug
    return cross

def count_up(types):
    ans = 0
    seed = 1
    seed *= combi(types['a'], types['b'])
    keys = list(types.keys())
    for type_ in keys:
        if not (type(type_) == Fraction and type_ > 0):
            continue
        count = types[type_]
        cross_type = calc_cross_type(type_)
        cross_count = types[cross_type]
        seed = (seed * combi(count, cross_count)) % MOD
    ans += seed
    ans += types[0]
    return ans - 1 # remove no sellect

if __name__ == '__main__':
    n = int(input())
    types = defaultdict(lambda: 0)
    for _ in range(n):
        a, b = list(map(int, input().split()))
        sardine = Sardine(a, b)
        types[sardine.type_] += 1
        if type(sardine.type_) is Fraction:
            cross_type = calc_cross_type(sardine.type_)
            types[cross_type]
    #print('types') # debug
    #pp(types) # debug
    ans = count_up(types)
    #print('ans') # debug
    print(ans)




    #print('\33[32m' + 'end' + '\033[0m') # debug

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from math import gcd

n = int(input())
L = []
for i in range(n):
    l = list(map(int, input().split()))
    L.append(l)

Mod = 10 ** 9 + 7

Pow2 = [1]
for i in range(n):
    Pow2.append(Pow2[-1] * 2 % Mod)

def kikaku(a, b):
    g = gcd(a, b)
    a //= g
    b //= g
    if a < 0:
        return - a, -b
    return a, b

Dpos = defaultdict(int)
Dneg = defaultdict(int)

c = 0
for l in L:
    a = l[0]
    b = l[1]
    if a == b == 0:
        c += 1
    else:
        a, b = kikaku(a, b)
        if b > 0:
            Dpos[(b, -a)] += 1
            Dneg[(b, -a)] += 0
        else:
            Dpos[(a, b)] += 0
            Dneg[(a, b)] += 1

r = 1
for k, v in Dpos.items():
    j = Dneg[k]
    x = Pow2[v] + Pow2[j] - 1
    r = r * x % Mod
ans = (r + c - 1) % Mod
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from math import gcd

n = int(input())
L = []
for i in range(n):
    l = list(map(int, input().split()))
    L.append(l)

Mod = 10 ** 9 + 7

Pow2 = [1]
for i in range(n):
    Pow2.append(Pow2[-1] * 2 % Mod)

def kikaku(a, b):
    g = gcd(a, b)
    a //= g
    b //= g
    if a < 0:
        return - a, -b
    return a, b

Dpos = defaultdict(int)
Dneg = defaultdict(int)

c = 0
for l in L:
    a = l[0]
    b = l[1]
    if a == b == 0:
        c += 1
    else:
        a, b = kikaku(a, b)
        if b == 0:
            Dpos[(0, 1)] += 1
            Dneg[(0, 1)] += 0
        elif a == 0:
            Dpos[(0, 1)] += 0
            Dneg[(0, 1)] += 1
        elif b > 0:
            Dpos[(b, -a)] += 1
            Dneg[(b, -a)] += 0
        else:
            Dpos[(a, b)] += 0
            Dneg[(a, b)] += 1

r = 1
for k, v in Dpos.items():
    j = Dneg[k]
    if v > 0 and j > 0:
        r = r * (Pow2[v] + Pow2[j] - 1) % Mod
    elif v == 0 and j == 0:
        pass
    else:
        r = r * 2 % Mod 
ans = (r + c - 1) % Mod
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf
# @pysnooper.snoop()
#import pysnooper # debug

import math
#from sortedcontainers import SortedList, SortedDict, SortedSet # no in atcoder
import bisect
from fractions import Fraction
from collections import defaultdict

MOD = 1000000007

def factorial(n, mod=None, memo=False):
    if memo:
        factorial.memo = [1] * (n + 1)
        for i in range(1, n + 1):
            if mod is None:
                factorial.memo[i] = i * factorial.memo[i - 1]
            else:
                factorial.memo[i] = i * factorial.memo[i - 1] % mod
    return factorial.memo[n]

def choose(n, r, mod=None):
    a = factorial(n)
    b = factorial(r)
    c = factorial(n - r)
    if mod is None:
        res = a // b // c
    else:
        # fermat's little theorem
        res = a * pow(b, mod - 2, mod) * pow(c, mod - 2, mod) % mod
    return res

class Sardine:
    def __init__(self, a, b):
        if a == 0 and b == 0:
            self.type_ = 0
        elif a == 0:
            self.type_ = 'a'
        elif b == 0:
            self.type_ = 'b'
        else:
            self.type_ = Fraction(a, b)

def sigma_choose(v):
    ans = 0
    i = 1
    while i <= v:
        ans += choose(v, i, MOD)
        ans %= MOD
        # for next
        i += 1
    return ans

def combi(x, y):
    res = sigma_choose(x) + sigma_choose(y) + 1
    #print('res') # debug
    #print(res) # debug
    return res

def calc_cross_type(frac):
    cross = Fraction(-1 * frac.denominator, frac.numerator)
    #print('cross', frac, cross) # debug
    return cross

def count_up(types):
    ans = 0
    seed = 1
    seed *= combi(types['a'], types['b'])
    keys = list(types.keys())
    for type_ in keys:
        if not (type(type_) == Fraction and type_ > 0):
            continue
        count = types[type_]
        cross_type = calc_cross_type(type_)
        cross_count = types[cross_type]
        seed = (seed * combi(count, cross_count)) % MOD
    ans += seed
    ans += types[0]
    return ans - 1 # remove no sellect

if __name__ == '__main__':
    factorial(2 * 10 ** 5, MOD, True)
    n = int(input())
    types = defaultdict(lambda: 0)
    for _ in range(n):
        a, b = list(map(int, input().split()))
        sardine = Sardine(a, b)
        types[sardine.type_] += 1
        if type(sardine.type_) is Fraction:
            cross_type = calc_cross_type(sardine.type_)
            types[cross_type]
    #print('types') # debug
    #pp(types) # debug
    ans = count_up(types)
    #print('ans') # debug
    print(ans)




    #print('\33[32m' + 'end' + '\033[0m') # debug

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from math import gcd

n = int(input())
L = []
for i in range(n):
    l = list(map(int, input().split()))
    L.append(l)

Mod = 10 ** 9 + 7

Pow2 = [1]
for i in range(n):
    Pow2.append(Pow2[-1] * 2 % Mod)

def kikaku(a, b):
    g = gcd(a, b)
    a //= g
    b //= g
    if a < 0:
        return - a, -b
    return a, b

Dpos = defaultdict(int)
Dneg = defaultdict(int)

c = 0
for l in L:
    a = l[0]
    b = l[1]
    if a == b == 0:
        c += 1
    else:
        a, b = kikaku(a, b)

        if b > 0:
            Dpos[(b, -a)] += 1
            Dneg[(b, -a)] += 0
        else:
            Dpos[(a, b)] += 0
            Dneg[(a, b)] += 1

r = 1
for k, v in Dpos.items():
    j = Dneg[k]
    if v > 0 and j > 0:
        r = r * (Pow2[v] + Pow2[j] - 1) % Mod
    elif v == 0 and j == 0:
        pass
    else:
        r = r * 2 % Mod 
ans = (r + c - 1) % Mod
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from math import gcd

n = int(input())
L = []
for i in range(n):
    l = list(map(int, input().split()))
    L.append(l)

Mod = 10 ** 9 + 7

Pow2 = [1]
for i in range(n):
    Pow2.append(Pow2[-1] * 2 % Mod)

def kikaku(a, b):
    g = gcd(a, b)
    a //= g
    b //= g
    if a < 0:
        return - a, -b
    return a, b

Dpos = defaultdict(int)
Dneg = defaultdict(int)

c = 0
for l in L:
    a = l[0]
    b = l[1]
    if a == b == 0:
        c += 1
    else:
        a, b = kikaku(a, b)

        if b > 0:
            Dpos[(b, -a)] += 1
            Dneg[(b, -a)] += 0
        else:
            Dpos[(a, b)] += 0
            Dneg[(a, b)] += 1

r = 1
for k, v in Dpos.items():
    j = Dneg[k]
    if v > 0 and j > 0:
        r = r * (Pow2[v] + Pow2[j] - 1) % Mod
#    elif v == 0 and j == 0:
#        pass
    else:
        r = r * 2 % Mod 
ans = (r + c - 1) % Mod
print(ans)

Submission status: Wrong Answer

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def comb(n, r):
    return fact[n]*pow(fact[n-r], mod-2, mod)*pow(fact[r], mod-2, mod) % mod
n = I()
ab = [LI() for _ in range(n)]

fact = [1]*(n+1)
for i in range(1, n+1):
    fact[i] = i * fact[i-1]
    fact[i] %= mod

x = defaultdict(lambda : 0)
y = defaultdict(lambda : 0)
z = defaultdict(lambda : 0)
tmp = 0
for a, b in ab:
    if a == 0 and b == 0:
        tmp += 1
    elif a == 0:
        x[0] += 1
        z[0] = 1
    elif b == 0:
        y[0] += 1
        z[0] = 1
    else:
        if a * b > 0:
            g = math.gcd(a, b)
            a //= g
            b //= g
            x[(abs(a), abs(b))] += 1
            z[(abs(a), abs(b))] = 1
        else:
            g = math.gcd(a, b)
            a //= g
            b //= g
            y[(abs(b), abs(a))] += 1
            z[(abs(b), abs(a))] = 1

ans = 1
for i in z.keys():
    ans *= (2**x[i] + 2**y[i] - 1)
    ans %= mod
ans -= 1
ans += tmp
print(ans)

Submission status: Wrong Answer

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def comb(n, r):
    return fact[n]*pow(fact[n-r], mod-2, mod)*pow(fact[r], mod-2, mod) % mod
n = I()
ab = [LI() for _ in range(n)]

fact = [1]*(n+1)
for i in range(1, n+1):
    fact[i] = i * fact[i-1]
    fact[i] %= mod

x = []
y = []
tmp = 0
for a, b in ab:
    if a == 0 and b == 0:
        tmp += 1
    elif a == 0:
        x.append(0)
        y.append(-inf)
    elif b == 0:
        x.append(inf)
        y.append(0)
    else:
        x.append(a/b)
        y.append(-b/a)


z = defaultdict(lambda : 0)
w = defaultdict(lambda : 0)
ans = 0
for i,j in enumerate(x):
    if z[j]:
        w[j] += 1
        if j == y[i]:
            z[y[i]] += 1
        continue
    z[y[i]] += 1

ans = 1
for i, j in z.items():
    ans *= (2**j + 2**w[i] - 1)
    ans %= mod
ans -= 1
ans += tmp
print(ans)