Problem:


Score: 500 points

Problem Statement

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

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

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

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

Constraints

All values in input are integers.

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

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

Input

Input is given from Standard Input in the following format:

N
A_1 B_1
:
A_N B_N

Output

Print the count modulo 1000000007.

Sample Input 1

3
1 2
-1 1
2 -1

Sample Output 1

5

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

The 1-st

The 1-st and 2-nd

The 2-nd

The 2-nd and 3-rd

The 3-rd

Sample Input 2

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

Sample Output 2

479



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


Sample output:
5

Submission status: Wrong Answer

Solution code:
from math import gcd
from collections import Counter
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

MOD = 10**9+7

def main():
    N,*ab = map(int, read().split())

    ab_zero = 0
    ratio = []
    for a, b in zip(*[iter(ab)]*2):
        if a == 0 and b == 0:
            ab_zero += 1
        else:
            g = gcd(a, b)
            a //= g
            b //= g
            ratio.append((a, b))
    ab_zero %= MOD
    
    s = Counter(ratio)

    bad = 1
    for k, v in s.items():
        if v == 0:
            continue
        a, b = k
        if (-b, a) in s:
            bad *= (pow(2, v, MOD) + pow(2, s[(-b, a)], MOD) -1) % MOD
            bad %= MOD
            s[(-b, a)] = 0
            s[k] = 0
        elif (b, -a) in s:
            bad *= (pow(2, v, MOD) + pow(2, s[(b, -a)], MOD) -1) % MOD
            bad %= MOD
            s[(b, -a)] = 0
            s[k] = 0
        else:
            bad *= pow(2, v, MOD)
            bad %= MOD

    ans = (bad + ab_zero -1) % MOD
    print(ans)
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math
import numpy as np
def main():
    mod = 1000000007
    N = int(input())
    mp = {}
    zero = 0
    for _ in range(N):
        x , y = map(int, input().split())
        if x == 0 and y == 0:
            zero += 1
        else:
            g = math.gcd(x, y)
            x /= g
            y /= g
            rot = 0
            if x == 0:
                y = 1
            else:
                if y == 0:
                    rot = 1
                    x = 0
                    y = 1
                else:
                    if x < 0 and y < 0:
                        #rot = 1
                        x *= -1
                        y *= -1
                        #c = x
                        #x = y
                        #y = c
                    elif x < 0:
                        rot = 1
                        x *= -1
                        c = x
                        x = y
                        y = c
                    elif y < 0:
                        rot = 1
                        y *= -1
                        c = x
                        x = y
                        y = c
            if (x, y) not in mp.keys():
                mp[x, y] = [0, 0]
                mp[x, y][rot] = 1
            else:
                mp[x, y][rot] += 1
        #print(mp)    
    #print(mp)
    ans = 1
    for (a, b) in mp.keys():
        now = 1
        #now += np.power(2, mp[a, b][0]) -1 
        #now += np.power(2, mp[a, b][1]) -1
        now += pow(2, mp[a, b][0], mod) -1 
        now += pow(2, mp[a, b][1], mod) -1
        ans *= now % mod
    ans += zero - 1
    print(ans % mod)
            
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# 既約分数を直接計算する
from math import gcd
from collections import Counter
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

MOD = 10**9+7

def main():
    N,*ab = map(int, read().split())

    ab_zero = 0
    ratio = []
    for a, b in zip(*[iter(ab)]*2):
        if a == 0 and b == 0:
            ab_zero += 1
        else:
            g = gcd(a, b)
            a //= g
            b //= g
            ratio.append((a, b))
    ab_zero %= MOD
    
    s = Counter(ratio)

    bad = 1
    for k, v in s.items():
        if v == 0:
            continue
        a, b = k
        inv = 0
        if (-b, a) in s:
            inv += s[(-b, a)]
            s[(-b, a)] = 0
        if (b, -a) in s:
            inv += s[(b, -a)]
            s[(b, -a)] = 0
        if inv:
            bad *= (pow(2, v, MOD) + pow(2, inv, MOD) -1) % MOD
            bad %= MOD
        else:
            bad *= pow(2, v, MOD)
            bad %= MOD

    ans = (bad + ab_zero -1) % MOD
    print(ans)
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math
import numpy as np
def main():
    mod = 1000000007
    N = int(input())
    mp = {}
    zero = 0
    for _ in range(N):
        x , y = map(int, input().split())
        if x == 0 and y == 0:
            zero += 1
        else:
            g = math.gcd(x, y)
            x /= g
            y /= g
            rot = 0
            if x == 0:
                y = 1
            else:
                if y == 0:
                    rot = 1
                    x = 0
                    y = 1
                else:
                    if x < 0 and y < 0:
                        #rot = 1
                        x *= -1
                        y *= -1
                        c = x
                        x = y
                        y = c
                    elif x < 0:
                        rot = 1
                        x *= -1
                        c = x
                        x = y
                        y = c
                    elif y < 0:
                        rot = 1
                        y *= -1
                        c = x
                        x = y
                        y = c
            if (x, y) not in mp.keys():
                mp[x, y] = [0, 0]
                mp[x, y][rot] = 1
            else:
                mp[x, y][rot] += 1
        #print(mp)    
    #print(mp)
    ans = 1
    for (a, b) in mp.keys():
        now = 1
        #now += np.power(2, mp[a, b][0]) -1 
        #now += np.power(2, mp[a, b][1]) -1
        now += pow(2, mp[a, b][0], mod) -1 
        now += pow(2, mp[a, b][1], mod) -1
        ans *= now % mod
    ans += zero - 1
    print(ans % mod)
            
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
import numpy as np
def main():
    mod = 1000000007
    N = int(input())
    mp = {}
    zero = 0
    for _ in range(N):
        x , y = map(int, input().split())
        if x == 0 and y == 0:
            zero += 1
        else:
            g = math.gcd(x, y)
            x /= g
            y /= g
            rot = 0
            if x == 0:
                y = 1
            else:
                if y == 0:
                    rot = 1
                    x = 0
                    y = 1
                else:
                    if x < 0 and y < 0:
                        rot = 1
                        x *= -1
                        y *= -1
                        c = x
                        x = y
                        y = c
                    elif x < 0:
                        rot = 1
                        x *= -1
                        c = x
                        x = y
                        y = c
                    elif y < 0:
                        rot = 1
                        y *= -1
                        c = x
                        x = y
                        y = c
            if (x, y) not in mp.keys():
                mp[x, y] = [0, 0]
                mp[x, y][rot] = 1
            else:
                mp[x, y][rot] += 1
        #print(mp)    
    #print(mp)
    ans = 1
    for (a, b) in mp.keys():
        now = 1
        #now += np.power(2, mp[a, b][0]) -1 
        #now += np.power(2, mp[a, b][1]) -1
        now += pow(2, mp[a, b][0], mod) -1 
        now += pow(2, mp[a, b][1], mod) -1
        ans *= now % mod
    ans += zero - 1
    print(ans % mod)
            
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
T = []
for i in range(N):
    a = list(map(int, input().split()))
    T.append(a)

mod = 10**9+7

A = {}
c_zero = 0
a_zero = 0
b_zero = 0
for i in range(N):
    if T[i][0] == 0 and T[i][1] == 0:
        c_zero += 0
    elif T[i][0] == 0:
        a_zero += 1
    elif T[i][1] == 0:
        b_zero += 1
    else:
        t = math.gcd(abs(T[i][0]),abs(T[i][1]))
        c = 0
        if T[i][0] < 0:
            T[i][0] *= -1
            c += 1
        if T[i][1] < 0:
            T[i][1] *= -1
            c += 1
        if (T[i][0]//t,T[i][1]//t,c%2) in A:
            A[T[i][0]//t,T[i][1]//t,c%2] += 1
        else:
            A[T[i][0]//t,T[i][1]//t,c%2] = 1

used = {}
for i in A.keys():
    used[i] = 0

ans = 1
for k,v in A.items():
    if used[k] == 0:
        if k[2] == 1:
            p = A.get((k[1],k[0],0),0)
            if p != 0:
                used[(k[1],k[0],0)] = 1
        else:
            p = A.get((k[1],k[0],1),0)
            if p != 0:
                used[(k[1],k[0],1)] = 1
        ans *= ( pow(2,v,mod)+pow(2,p,mod) - 1 + mod)
        ans %= mod

ans *= ( pow(2,a_zero,mod)+pow(2,b_zero,mod) - 1 + mod)
ans += c_zero
ans -= 1
print(ans%mod)

Submission status: Wrong Answer

Solution code:
from math import gcd
from collections import Counter
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

MOD = 10**9+7

def main():
    N,*ab = map(int, read().split())

    ab_zero = 0
    ratio = []
    for a, b in zip(*[iter(ab)]*2):
        if a == 0 and b == 0:
            ab_zero += 1
        else:
            g = gcd(a, b)
            a //= g
            b //= g
            ratio.append((a, b))
    
    s = Counter(ratio)

    bad = 1
    for k, v in s.items():
        if v == 0:
            continue
        a, b = k
        inv = 0
        if (-b, a) in s:
            inv += s[(-b, a)]
            s[(-b, a)] = 0
        if (b, -a) in s:
            inv += s[(b, -a)]
            s[(b, -a)] = 0
        if inv:
            bad *= (pow(2, v, MOD) + pow(2, inv, MOD) -1) % MOD
            bad %= MOD
        else:
            bad *= pow(2, v, MOD)
            bad %= MOD

    ans = (bad + ab_zero -1) % MOD
    print(ans)
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
T = []
for i in range(N):
    a = list(map(int, input().split()))
    T.append(a)

mod = 10**9+7

A = {}
c_zero = 0
a_zero = 0
b_zero = 0
for i in range(N):
    if T[i][0] == 0 and T[i][1] == 0:
        c_zero += 0
    elif T[i][0] == 0:
        a_zero += 1
    elif T[i][1] == 0:
        b_zero += 1
    else:
        t = math.gcd(abs(T[i][0]),abs(T[i][1]))
        c = 0
        if T[i][0] < 0:
            T[i][0] *= -1
            c += 1
        if T[i][1] < 0:
            T[i][1] *= -1
            c += 1
        if (T[i][0]//t,T[i][1]//t,c%2) in A:
            A[T[i][0]//t,T[i][1]//t,c%2] += 1
        else:
            A[T[i][0]//t,T[i][1]//t,c%2] = 1

used = {}
for i in A.keys():
    used[i] = 0

ans = 1
for k,v in A.items():
    if used[k] == 0:
        if k[2] == 1:
            p = A.get((k[1],k[0],0),0)
            if p != 0:
                used[(k[1],k[0],0)] = 1
        else:
            p = A.get((k[1],k[0],1),0)
            if p != 0:
                used[(k[1],k[0],1)] = 1
        ans *= ( pow(2,v,mod)+pow(2,p,mod) - 1 )
        ans %= mod

ans *= ( pow(2,a_zero,mod)+pow(2,b_zero,mod) - 1 )
ans += c_zero
ans -= 1
print(ans%mod)

Submission status: Wrong Answer

Solution code:
from math import gcd
from collections import Counter
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

MOD = 10**9+7

def main():
    N,*ab = map(int, read().split())

    ab_zero = 0
    ratio = []
    for a, b in zip(*[iter(ab)]*2):
        if a == 0 and b == 0:
            ab_zero += 1
        else:
            g = gcd(a, b)
            a //= g
            b //= g
            ratio.append((a, b))
    
    s = Counter(ratio)

    bad = 1
    for k, v in s.items():
        if v == 0:
            continue
        a, b = k
        inv = 0
        if (-b, a) in s:
            inv += s[(-b, a)]
            s[(-b, a)] = 0
        if (b, -a) in s:
            inv += s[(b, -a)]
            s[(b, -a)] = 0
        if inv:
            bad *= (pow(2, v, MOD) + pow(2, inv, MOD) -1) % MOD
            bad %= MOD
        else:
            bad *= pow(2, v, MOD)
            bad %= MOD

    ans = bad - 1 + ab_zero
    print(ans)
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from math import gcd
from collections import Counter
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

MOD = 10**9+7

def main():
    N,*ab = map(int, read().split())

    ab_zero = 0
    a_zero = 0
    b_zero = 0
    ratio = []
    for a, b in zip(*[iter(ab)]*2):
        if a == 0 and b == 0:
            ab_zero += 1
        elif a == 0:
            a_zero += 1
        elif b == 0:
            b_zero += 1
        else:
            g = gcd(a, b)
            a //= g
            b //= g
            ratio.append((a, b))
    
    s = Counter(ratio)

    bad = pow(2, a_zero, MOD) + pow(2, b_zero, MOD) - 1
    bad %= MOD
    for k, v in s.items():
        if v == 0:
            continue
        a, b = k
        inv = 0
        if (-b, a) in s:
            inv += s[(-b, a)]
            s[(-b, a)] = 0
        if (b, -a) in s:
            inv += s[(b, -a)]
            s[(b, -a)] = 0
        if inv:
            bad *= (pow(2, v, MOD) + pow(2, inv, MOD) -1) % MOD
            bad %= MOD
        else:
            bad *= pow(2, v, MOD)
            bad %= MOD

    ans = bad - 1 + ab_zero
    print(ans)
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math
import numpy as np
def main():
    mod = 1000000007
    N = int(input())
    mp = {}
    zero = 0
    for _ in range(N):
        x , y = map(int, input().split())
        if x == 0 and y == 0:
            zero += 1
        else:
            g = math.gcd(x, y)
            x /= g
            y /= g
            rot = 0
            if x == 0:
                y = 1
            else:
                if y == 0:
                    x = 0
                    y = 1
                else:
                    if x < 0 and y < 0:
                        rot = 1
                        x *= -1
                        y *= -1
                        c = x
                        x = y
                        y = c
                    elif x < 0:
                        rot = 1
                        x *= -1
                        c = x
                        x = y
                        y = c
                    elif y < 0:
                        rot = 1
                        y *= -1
                        c = x
                        x = y
                        y = c
            if (x, y) not in mp.keys():
                mp[x, y] = [0, 0]
                mp[x, y][rot] = 1
            else:
                mp[x, y][rot] += 1
        #print(mp)    
    #print(mp)
    ans = 1
    for (a, b) in mp.keys():
        now = 1
        #now += np.power(2, mp[a, b][0]) -1 
        #now += np.power(2, mp[a, b][1]) -1
        now += pow(2, mp[a, b][0], mod) -1 
        now += pow(2, mp[a, b][1], mod) -1
        ans *= now % mod
    ans += zero - 1
    print(ans % mod)
            
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
import numpy as np
def main():
    mod = 1000000007
    N = int(input())
    mp = {}
    zero = 0
    for _ in range(N):
        x , y = map(int, input().split())
        if x == 0 and y == 0:
            zero += 1
        else:
            g = math.gcd(x, y)
            x /= g
            y /= g
            rot = 0
            if x == 0:
                y = 1
            else:
                if y == 0:
                    x = 0
                    y = 1
                else:
                    if x < 0 and y < 0:
                        rot = 1
                        x *= -1
                        y *= -1
                        c = x
                        x = y
                        y = c
                    elif x < 0:
                        rot = 1
                        x *= -1
                        c = x
                        x = y
                        y = c
                    elif y < 0:
                        rot = 1
                        y *= -1
                        c = x
                        x = y
                        y = c
            if (x, y) not in mp.keys():
                mp[x, y] = [0, 0]
                mp[x, y][rot] = 1
            else:
                mp[x, y][rot] += 1
        #print(mp)    
    #print(mp)
    ans = 1
    for (a, b) in mp.keys():
        now = 1
        #now += np.power(2, mp[a, b][0]) -1 
        #now += np.power(2, mp[a, b][1]) -1
        now += pow(2, mp[a, b][0], mod) -1 
        now += pow(2, mp[a, b][1], mod) -1
        ans *= now
    ans += zero - 1
    print(ans % mod)
            
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
import numpy as np
def main():
    mod = 1000000007
    N = int(input())
    mp = {}
    zero = 0
    for _ in range(N):
        x , y = map(int, input().split())
        if x == 0 and y == 0:
            zero += 1
        else:
            g = math.gcd(x, y)
            x /= g
            y /= g
            rot = 0
            if x == 0:
                y = 1
            else:
                if y == 0:
                    x = 0
                    y = 1
                else:
                    if x < 0 and y < 0:
                        rot = 1
                        x *= -1
                        y *= -1
                        c = x
                        x = y
                        y = c
                    elif x < 0:
                        rot = 1
                        x *= -1
                        c = x
                        x = y
                        y = c
                    elif y < 0:
                        rot = 1
                        y *= -1
                        c = x
                        x = y
                        y = c
            if (x, y) not in mp.keys():
                mp[x, y] = [0, 0]
                mp[x, y][rot] = 1
            else:
                mp[x, y][rot] += 1
        #print(mp)    
    #print(mp)
    ans = 1
    for (a, b) in mp.keys():
        now = 1
        now += np.power(2, mp[a, b][0]) -1 
        now += np.power(2, mp[a, b][1]) -1
        ans *= now % mod
    ans += zero - 1
    print(ans % mod)
            
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
import numpy as np
def main():
    mod = 1000000007
    N = int(input())
    mp = {}
    zero = 0
    for _ in range(N):
        x , y = map(int, input().split())
        if x == 0 and y == 0:
            zero += 1
        else:
            g = math.gcd(x, y)
            x /= g
            y /= g
            rot = 0
            if x == 0:
                y = 1
            else:
                if y == 0:
                    x = 0
                    y = 1
                else:
                    if x < 0 and y < 0:
                        rot = 1
                        x *= -1
                        y *= -1
                        c = x
                        x = y
                        y = c
                    elif x < 0:
                        rot = 1
                        x *= -1
                        c = x
                        x = y
                        y = c
                    elif y < 0:
                        rot = 1
                        y *= -1
                        c = x
                        x = y
                        y = c
            if (x, y) not in mp.keys():
                mp[x, y] = [0, 0]
                mp[x, y][rot] = 1
            else:
                mp[x, y][rot] += 1
        #print(mp)    
    #print(mp)
    ans = 1
    for (a, b) in mp.keys():
        now = 1
        now += np.power(2, mp[a, b][0]) -1 
        now += np.power(2, mp[a, b][1]) -1
        ans *= now
    ans += zero - 1
    print(ans % mod)
            
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import math

N = int(input())
d_ab = defaultdict(int)
d_ba = defaultdict(int)
mod = 1000000007
a0 = 0
b0 = 0
all0 = 0

for i in range(N):
    A,B = map(int,input().split())
    if A == 0 and B == 0:
        all0 += 1
    elif A == 0:
        a0 += 1
    elif B == 0:
        b0 += 1
    else:
        gcd = math.gcd(A,B)
        if (A < 0 and B > 0) or (A > 0 and B < 0):
            minus_f = True
        else:
            minus_f = False
        A //= gcd
        B //= gcd
        A = abs(A)
        B = abs(B)
        if minus_f:
            d_ab[(-A,B)] += 1
            d_ba[(B,A)] += 1
        else:
            d_ab[(A,B)] += 1
            d_ba[(-B,A)] += 1
        

ans = 1

#print(d_ab)
#print(d_ba)

pairs = list(map(list,d_ab.keys()))
visited = defaultdict(int)
#print(pairs)

for pair in pairs:
    ab = d_ab[tuple(pair)]
    ba = d_ba[tuple(pair)]
    r_pair = list(reversed(pair))
    if r_pair[0] > 0 and r_pair[1] > 0:
        r_pair[0] *= -1
    elif r_pair[1] < 0:
        r_pair[1] *= -1
    r_pair = tuple(r_pair)
    if ba != 0 and visited[tuple(pair)] == 0:
        visited[r_pair] = 1
        ans *= (pow(2,ab)+pow(2,ba)-1)
        ans %= mod
    if ba == 0 and visited[tuple(pair)] == 0:
        ans *= (pow(2,ab))
        ans %= mod
#    print(ans)

#print(visited)
ans *= (pow(2,a0)+pow(2,b0)-1)
ans %= mod

ans += all0
ans %= mod

print(ans-1)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

MOD = (10 ** 9) + 7
assert MOD == 1000000007

def gcd(a, b):
    if a % b == 0:
        return b
    return gcd(b, a % b)

n = int(raw_input())

ns = []
d = defaultdict(int)

for i in xrange(n):
    a, b = map(int, raw_input().split())
    ns.append((a, b))
    if a and b:
        s = 1 if a * b >= 0 else -1
        g = gcd(abs(a), abs(b))
        m1 = (s * abs(a) / g, abs(b) / g)
        m2 = (-s * abs(b) / g, abs(a) / g)
    elif a == 0 and b == 0:
        continue
    elif a == 0:
        m1 = (1, 0)
        m2 = (0, 1)
    elif b == 0:
        m1 = (0, 1)
        m2 = (1, 0)

    d[m1] += 1
    d[m2] += 0

'''
res = 0
for i in xrange(1 << n):
    fs = []
    flag = True
    for j in xrange(n):
        if i & (1 << j):
            fs.append(ns[j])
    for f1 in fs:
        for f2 in fs:
            (a1, b1) = f1
            (a2, b2) = f2
            if a1 * a2 + b1 * b2 == 0:
                flag = False
                break
        if not flag:
            break
    if flag:
        res += 1
print res - 1
'''

pre = 1
for k in d.keys():
    if k[0] <= 0:
        assert (k[1], -k[0]) in d
        continue
    else:
        k1 = k
        k2 = (-k[1], k[0])

        tot = pow(2, d[k1], MOD) + pow(2, d[k2], MOD) - 1
        pre = pre * tot % MOD
print (pre - 1 + MOD) % MOD

Submission status: Wrong Answer

Solution code:





from collections import defaultdict
import math

N = int(input())
d_ab = defaultdict(int)
d_ba = defaultdict(int)
mod = 1000000007
a0 = 0
b0 = 0
all0 = 0

for i in range(N):
    A,B = map(int,input().split())
    if A == 0 and B == 0:
        all0 += 1
    elif A == 0:
        a0 += 1
    elif B == 0:
        b0 += 1
    else:
        gcd = math.gcd(A,B)
        if (A < 0 and B > 0) or (A > 0 and B < 0):
            minus_f = True
        else:
            minus_f = False
        A //= gcd
        B //= gcd
        A = abs(A)
        B = abs(B)
        if minus_f:
            d_ab[(-A,B)] += 1
            d_ba[(B,A)] += 1
        else:
            d_ab[(A,B)] += 1
            d_ba[(-B,A)] += 1
        

ans = 1

#print(d_ab)
#print(d_ba)

pairs = list(map(list,d_ab.keys()))
visited = defaultdict(int)
#print(pairs)

for pair in pairs:
    ab = d_ab[tuple(pair)]
    ba = d_ba[tuple(pair)]
    r_pair = list(reversed(pair))
    if r_pair[0] > 0 and r_pair[1] > 0:
        r_pair[0] *= -1
    elif r_pair[1] < 0:
        r_pair[1] *= -1
    r_pair = tuple(r_pair)
    if ba != 0 and visited[tuple(pair)] == 0:
        visited[r_pair] = 1
        visited[tuple(pair)] = 1
        ans *= (pow(2,ab)+pow(2,ba)-1)
    if ba == 0 and visited[tuple(pair)] == 0:
        ans *= (pow(2,ab))
#    print(ans)

#print(visited)
ans *= (pow(2,a0)+pow(2,b0)-1)

ans += all0

print(ans-1)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

MOD = (10 ** 9) + 7
assert MOD == 1000000007

def gcd(a, b):
    if a % b == 0:
        return b
    return gcd(b, a % b)

n = int(raw_input())

ns = []
d = defaultdict(int)

for i in xrange(n):
    a, b = map(int, raw_input().split())
    ns.append((a, b))
    if a and b:
        s = 1 if a * b >= 0 else -1
        g = gcd(abs(a), abs(b))
        m1 = (s * abs(a) / g, abs(b) / g)
        m2 = (-s * abs(b) / g, abs(a) / g)
    elif a == 0 and b == 0:
        continue
    elif a == 0:
        m1 = (1, 0)
        m2 = (0, 1)
    elif b == 0:
        m1 = (0, 1)
        m2 = (1, 0)

    d[m1] += 1
    d[m2] += 0

'''
res = 0
for i in xrange(1 << n):
    fs = []
    flag = True
    for j in xrange(n):
        if i & (1 << j):
            fs.append(ns[j])
    for f1 in fs:
        for f2 in fs:
            (a1, b1) = f1
            (a2, b2) = f2
            if a1 * a2 + b1 * b2 == 0:
                flag = False
                break
        if not flag:
            break
    if flag:
        res += 1
print res - 1
'''

pre = 1
for k in d.keys():
    if k[0] < 0:
        assert (k[1], -k[0]) in d
        continue
    else:
        k1 = k
        k2 = (-k[1], k[0])

        tot = pow(2, d[k1], MOD) + pow(2, d[k2], MOD) - 1
        pre = pre * tot % MOD
print (pre - 1 + MOD) % MOD

Submission status: Wrong Answer

Solution code:
from math import gcd
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
mod = 1000000007

#%%

kai = [1]*(n+1)
gyaku = [1]*(n+1)

for i in range(2, n+1):
    kai[i] = kai[i-1]*i % mod
    gyaku[i] = gyaku[i-1]*pow(i, mod-2, mod) %mod

azero = 0
bzero = 0
zerozero = 0
dict_patterns = {}
dict_patterns_minus = {}
all_effective = 0
answer = 0
dict_patterns["1,0"] = 0
dict_patterns["0,-1"] = 0

for i in range(n):
    minus = False
    a, b = ab[i]
    if a == 0 and b == 0:
        zerozero += 1
        continue
    elif b == 0:
        dict_patterns["1,0"] += 1
        continue
    elif a == 0:
        dict_patterns["0,-1"] += 1
        continue
    common = gcd(a,b)
    a, b = int(a/common), int(b/common)
    if a < 0 and b < 0:
        a,b = -a,-b
    elif a < 0:
        a,b = -a,-b
        minus = True
    elif b<0:
        minus = True
    
    to_str = str(a)+","+str(b)
    if to_str not in dict_patterns:
        if minus == False:
            dict_patterns[to_str] = 1
        else:
            dict_patterns[to_str] = 1
    else:
        if minus == False:
            dict_patterns[to_str] += 1
        else:
            dict_patterns[to_str] += 1

#%%

keys = list(dict_patterns.keys())
patterns = []
test = []
for i in range(len(keys)):
    pattern_A = dict_patterns[keys[i]]
    dict_patterns[keys[i]] = 0
    pattern_B = 0
    a, b = map(int, keys[i].split(","))
    if str(b)+","+str(-a) in dict_patterns:
        pattern_B += dict_patterns[str(b)+","+str(-a)]
        dict_patterns[str(b)+","+str(-a)] = 0
    elif str(-b)+","+str(a) in dict_patterns:
        pattern_B += dict_patterns[str(-b)+","+str(a)]
        dict_patterns[str(-b)+","+str(a)] = 0
    if pattern_A != 0 or pattern_B != 0:
        patterns.append(max(2**pattern_A-1,0) + max(2**pattern_B-1,0) + 1)  
    test.append([pattern_A, pattern_B])
#%%
answer = 1
for i in range(len(patterns)):
    answer = answer*patterns[i] % mod

print((answer-1+zerozero)%mod)

Submission status: Wrong Answer

Solution code:
from math import gcd
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
mod = 1000000007

#%%

kai = [1]*(n+1)
gyaku = [1]*(n+1)

for i in range(2, n+1):
    kai[i] = kai[i-1]*i % mod
    gyaku[i] = gyaku[i-1]*pow(i, mod-2, mod) %mod

azero = 0
bzero = 0
zerozero = 0
dict_patterns = {}
dict_patterns_minus = {}
all_effective = 0
answer = 0
dict_patterns["1,0"] = 0
dict_patterns["0,-1"] = 0

for i in range(n):
    minus = False
    a, b = ab[i]
    if a == 0 and b == 0:
        zerozero += 1
        continue
    elif b == 0:
        dict_patterns["1,0"] += 1
        continue
    elif a == 0:
        dict_patterns["0,-1"] += 1
        continue
    common = gcd(a,b)
    a, b = int(a/common), int(b/common)
    if a < 0 and b < 0:
        a,b = -a,-b
    elif a < 0:
        a,b = -a,-b
        minus = True
    elif b<0:
        minus = True
    
    to_str = str(a)+","+str(b)
    if to_str not in dict_patterns:
        if minus == False:
            dict_patterns[to_str] = 1
        else:
            dict_patterns[to_str] = 1
    else:
        if minus == False:
            dict_patterns[to_str] += 1
        else:
            dict_patterns[to_str] += 1

#%%

keys = list(dict_patterns.keys())
patterns = []
test = []
for i in range(len(keys)):
    pattern_A = dict_patterns[keys[i]]
    dict_patterns[keys[i]] = 0
    pattern_B = 0
    a, b = map(int, keys[i].split(","))
    if str(b)+","+str(-a) in dict_patterns:
        pattern_B += dict_patterns[str(b)+","+str(-a)]
        dict_patterns[str(b)+","+str(-a)] = 0
    elif str(-b)+","+str(a) in dict_patterns:
        pattern_B += dict_patterns[str(-b)+","+str(a)]
        dict_patterns[str(-b)+","+str(a)] = 0
    if pattern_A != 0 or pattern_B != 0:
        patterns.append(max(2**pattern_A-1,0) + max(2**pattern_B-1,0) + 1)  
    test.append([pattern_A, pattern_B])
#%%
answer = 1
for i in range(len(patterns)):
    answer = answer*patterns[i] % mod

print(answer-1+zerozero)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

MOD = (10 ** 9) + 7

def gcd(a, b):
    if a % b == 0:
        return b
    return gcd(b, a % b)

n = int(raw_input())

ns = []
d = defaultdict(int)

for i in xrange(n):
    a, b = map(int, raw_input().split())
    ns.append((a, b))
    if a and b:
        s = 1 if a * b >= 0 else -1
        g = gcd(abs(a), abs(b))
        m1 = (s * abs(a) / g, abs(b) / g)
        m2 = (-s * abs(b) / g, abs(a) / g)
    elif a == 0 and b == 0:
        continue
    elif a == 0:
        m1 = (1, 0)
        m2 = (0, 1)
    elif b == 0:
        m1 = (0, 1)
        m2 = (1, 0)

    d[m1] += 1
    d[m2] += 0

pre = 1
for k in d.keys():
    if k[0] < 0:
        assert (k[1], -k[0]) in d
        continue
    elif k[0] == 0:
        pre = pre * d[k] % MOD
    else:
        k1 = k
        k2 = (-k[1], k[0])

        tot = pow(2, d[k1], MOD) + pow(2, d[k2], MOD) - 1
        pre = pre * tot % MOD
print (pre - 1 + MOD) % MOD