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
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

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:
        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)

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())
    s = 1 if a * b >= 0 else -1
    if a and b:
        g = gcd(abs(a), abs(b))
        m1 = (s * abs(a) / g, abs(b) / g)
        m2 = (-s * abs(b) / g, abs(a) / g)
    else:
        m1 = (0, 0)
        m2 = (0, 0)

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

pre = 1
for k in d.keys():
    if k[0] < 0:
        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

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

dict_patterns = {}
all_effective = 0
answer = 0
for i in range(n):
    a, b = ab[i]
    if a == 0 and b == 0:
        continue
    elif a == 0:
        azero += 1
        continue
    elif b == 0:
        bzero += 1
        continue
    common = gcd(a,b)
    a, b = int(a/common), int(b/common)
    minus = 0
    to_str = str(a)+","+str(b)
    if to_str not in dict_patterns:
        dict_patterns[to_str] = 1
    else:
        dict_patterns[to_str] += 1

keys = list(dict_patterns.keys())
patterns = []
for i in range(len(keys)):
    pattern_A = dict_patterns[keys[i]]
    if pattern_A == 0:
        continue
    dict_patterns[keys[i]] = 0
    pattern_B = 0
    a, b = map(int, keys[i].split(","))
    if str(-a)+","+str(-b) in keys:
        pattern_A += dict_patterns[str(-a)+","+str(-b)]
        dict_patterns[str(-a)+","+str(-b)] = 0
    if str(-b)+","+str(a) in keys:
        pattern_B += dict_patterns[str(-b)+","+str(a)]
        dict_patterns[str(-b)+","+str(a)] = 0
    if str(b)+","+str(-a) in keys:
        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)

patterns.append(max(2**azero-1,0) + max(2**bzero-1,0) + 1)
        
answer = 1
for i in range(len(patterns)):
    answer = answer*patterns[i] % mod

print(answer-1)

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

dict_patterns = {}
all_effective = 0
answer = 0
for i in range(n):
    a, b = ab[i]
    if a == 0 and b == 0:
        continue
    elif a == 0:
        azero += 1
        continue
    elif b == 0:
        bzero += 1
        continue
    
    common = gcd(a,b)
    a, b = int(a/common), int(b/common)
    minus = 0
    
    to_str = str(a)+","+str(b)
    
    if to_str not in dict_patterns:
        dict_patterns[to_str] = 1
    else:
        dict_patterns[to_str] += 1

keys = list(dict_patterns.keys())
patterns = []
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(-a)+","+str(-b) in keys:
        pattern_A += dict_patterns[str(-a)+","+str(-b)]
        dict_patterns[str(-a)+","+str(-b)] = 0
    if str(-b)+","+str(a) in keys:
        pattern_B += dict_patterns[str(-b)+","+str(a)]
        dict_patterns[str(-b)+","+str(a)] = 0
    if str(b)+","+str(-a) in keys:
        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)

patterns.append(max(2**azero-1,0) + max(2**bzero-1,0) + 1)
        
answer = 1
for i in range(len(patterns)):
    answer = answer*patterns[i]%mod

print(answer-1)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from math import gcd
N,*L = map(int, open(0).read().split())
dic = defaultdict(int)
ans = 0
MOD = 10**9+7
S = set()
for a,b in zip(*[iter(L)]*2):
  if a==0 and b==0:
    ans += 1
    continue
  g = gcd(a,b)
  if b>0:
    dic[(a/g,b/g)] += 1
    S.add((a/g,b/g))
  elif b<0:
    dic[(-a/g,-b/g)] += 1
    S.add((-a/g,-b/g))
  else:
    dic[(1,0)] += 1
    S.add((1,0))
m = 1
for a,b in S:
  if a<=0:
    if dic[(b,-a)]==0:
      m *= pow(2,dic[(a,b)],MOD)
      m %= MOD
      continue
  else:
    if dic[(-b,a)]==0:
      m *= pow(2,dic[(a,b)],MOD)
      m %= MOD
      continue
    c = pow(2,dic[(a,b)],MOD)+pow(2,dic[(-b,a)],MOD)-1
    m *= c
    m %= MOD
ans = (m-1+ans)%MOD
print(ans)

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

dict_patterns = {}
all_effective = 0
answer = 0
for i in range(n):
    a, b = ab[i]
    if a == 0 and b == 0:
        continue
    elif a == 0:
        azero += 1
        continue
    elif b == 0:
        bzero += 1
        continue
    
    common = gcd(a,b)
    a, b = int(a/common), int(b/common)
    minus = 0
    
    to_str = str(a)+","+str(b)
    
    if to_str not in dict_patterns:
        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(-a)+","+str(-b) in keys:
        pattern_A += dict_patterns[str(-a)+","+str(-b)]
        dict_patterns[str(-a)+","+str(-b)] = 0
    if str(-b)+","+str(a) in keys:
        pattern_B += dict_patterns[str(-b)+","+str(a)]
        dict_patterns[str(-b)+","+str(a)] = 0
    if str(b)+","+str(-a) in keys:
        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)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())

N = 1000000007

def rate(a,b):
    if a==0:
        return (0,1)
    elif b==0:
        return (1,0)
    elif a==0 and b==0:
        return (0,0)
    r=1
    a1=a
    b1=b
    while r!=0:
        r=a1%b1
        a1=b1
        b1=r
    return (a//a1 , b//a1)

z =[]

for i in range(n):
    b , c = map(int, input().split())
    z.append(rate(b,c))

c = Counter(z)

k = list(c.keys())

d=[]
e=0

for i in k:
    x,y=i
    if x<=0:
        x*=-1
        y*=-1
    if (y*(-1),x) in k:
        t = (y*(-1),x)
        if not (c[t],c[i]) in d:
            d.append((c[i],c[t]))
    else:
        e+=c[i]
e-=c[(0,0)]
ans = 1
for i in d:
    x,y=i
    ans *= pow(2,x,N) + pow(2,y,N)-1
ans*=pow(2,e,N)
print(ans%N-1)

Submission status: Wrong Answer

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())

d = {}
zeros = 0

def gcd(a, b):
    while b != 0:
        a, b = b, a % b

    return a

MOD = int(1e9) + 7
p = [1] * (N + 1)
for i in range(N):
    p[i + 1] = p[i] * 2 % MOD
    a, b = map(int, input().split())
    if a == b == 0:
        zeros += 1
        continue
    a, b = a // abs(gcd(a, b)), b // abs(gcd(a, b))

    if a == 0:
        f, s = d.get((a, abs(b)), (0, 0))
        d[(a, abs(b))] = (f + 1, s)

    elif b == 0:
        f, s = d.get((b, abs(a)), (0, 0))
        d[(b, abs(a))] = (f, s + 1)

    elif (a < 0) ^ (b < 0):
        if a < 0:
            a, b = -a, -b
        f, s = d.get((abs(b), a), (0, 0))
        d[(abs(b), a)] = (f, s + 1)
    else:
        f, s = d.get((abs(a), abs(b)), (0, 0))
        d[(abs(a), abs(b))] = (f + 1, s)

ans = 1
for _, (f, s) in d.items():
    cnt = p[f] - 1
    cnt += p[s] - 1
    cnt += 1
    cnt %= MOD
    ans *= cnt
    ans %= MOD

ans -= 1
ans += zeros
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())

d = {}
zeros = 0

def gcd(a, b):
    while b != 0:
        a, b = b, a % b

    return a

MOD = int(1e9) + 7
p = [1] * (N + 1)
for i in range(N):
    p[i + 1] = p[i] * 2 % MOD
    a, b = map(int, input().split())
    if a == b == 0:
        zeros += 1
        continue
    a, b = a // gcd(a, b), b // gcd(a, b)

    if a == 0:
        f, s = d.get((a, abs(b)), (0, 0))
        d[(a, abs(b))] = (f + 1, s)

    elif b == 0:
        f, s = d.get((b, abs(a)), (0, 0))
        d[(b, abs(a))] = (f, s + 1)

    elif a < 0 ^ b < 0:
        if a < 0:
            a, b = -a, -b
        f, s = d.get((abs(b), a), (0, 0))
        d[(abs(b), a)] = (f, s + 1)
    else:
        f, s = d.get((abs(a), abs(b)), (0, 0))
        d[(abs(a), abs(b))] = (f + 1, s)

ans = 1
for _, (f, s) in d.items():
    cnt = p[f] - 1
    cnt += p[s] - 1
    cnt += 1
    cnt %= MOD
    ans *= cnt
    ans %= MOD

ans -= 1
ans += zeros
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())

d = {}
zeros = 0

def gcd(a, b):
    while b != 0:
        a, b = b, a % b

    return a

MOD = int(1e9) + 7
p = [1] * (N + 1)
for i in range(N):
    p[i + 1] = p[i] * 2 % MOD
    a, b = map(int, input().split())
    if a == b == 0:
        zeros += 1
        continue
    a, b = a // gcd(a, b), b // gcd(a, b)

    if a == 0:
        f, s = d.get((a, abs(b)), (0, 0))
        d[(a, abs(b))] = (f + 1, s)

    elif b == 0:
        f, s = d.get((b, abs(a)), (0, 0))
        d[(b, abs(a))] = (f, s + 1)

    elif a < 0 or b < 0:
        if a < 0:
            a, b = -a, -b
        f, s = d.get((abs(b), a), (0, 0))
        d[(abs(b), a)] = (f, s + 1)
    else:
        f, s = d.get((abs(a), abs(b)), (0, 0))
        d[(abs(a), abs(b))] = (f + 1, s)

ans = 1
for _, (f, s) in d.items():
    cnt = p[f] - 1
    cnt += p[s] - 1
    cnt += 1
    cnt %= MOD
    ans *= cnt
    ans %= MOD

ans -= 1
ans += zeros
print(ans)

Submission status: Wrong Answer

Solution code:
import functools
MOD=10**9+7

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

def gcd(nums):
  return functools.reduce(euclid, nums)

n=int(input())
t=[]
for i in range(n):
    a,b=map(int,input().split())
    t.append((a,b))
z=0
y={}
for i in range(n):
    if t[i][0]==0 and t[i][1]==0:
        z+=1
    else:
        g=abs(gcd([t[i][0],t[i][1]]))
        if t[i][1]==0:
            a=(1,0)
        elif t[i][1]>0:
            a=(t[i][0]//g , t[i][1]//g)
        else:
            a=(-t[i][0]//g , -t[i][1]//g)
        if a not in y:
            y[a]=1
        else:
            y[a]+=1

cnt=0
x=1
for i in y:
    if (-i[1],i[0]) in y:
        x  *= pow(2,y[(-i[1],i[0])],MOD) + pow(2,y[(i[0],i[1])],MOD)-1
        cnt+= y[(-i[1],i[0])] + y[(i[0],i[1])]

ans = pow(2,n-z-cnt,MOD) *x -1
print(x+z)

Submission status: Wrong Answer

Solution code:
import functools
MOD=10**9+7

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

def gcd(nums):
  return functools.reduce(euclid, nums)

n=int(input())
t=[]
for i in range(n):
    a,b=map(int,input().split())
    t.append((a,b))
z=0
y={}
for i in range(n):
    if t[i][0]==0 and t[i][1]==0:
        z+=1
    else:
        g=abs(gcd([t[i][0],t[i][1]]))
        if t[i][1]==0:
            a=(1,0)
        elif t[i][1]>0:
            a=(t[i][0]//g , t[i][1]//g)
        else:
            a=(-t[i][0]//g , -t[i][1]//g)
        if a not in y:
            y[a]=1
        else:
            y[a]+=1

cnt=0
x=1
for i in y:
    if (-i[1],i[0]) in y:
        x  *= pow(2,y[(-i[1],i[0])],MOD) + pow(2,y[(i[0],i[1])],MOD)-1
        cnt+= y[(-i[1],i[0])] + y[(i[0],i[1])]

ans = pow(2,n-z-cnt,MOD) *x -1
print(ans)

Submission status: Wrong Answer

Solution code:
import math
from collections import defaultdict

def INP(): return int(input())
def LINP(): return list(map(int,input().split()))

MOD = 10 ** 9 + 7
d = defaultdict(int)
zero = 0
N = INP()
for _ in range(N):
    A,B = LINP()
    if A == 0 and B == 0:
        zero += 1
        continue
    A = int(A/math.gcd(A,B))
    B = int(B/math.gcd(A,B))
    minus = (-1) ** ((A < 0) + (B < 0))
    d[(minus * abs(A), abs(B))] += 1
ans = 1
seen = set()
for a, b in d:
    if (a, b) not in seen:
        if(a, b) in [(0, 1), (1, 0)]:
            ainv, binv = b, a
        else:
            ainv, binv = b * (1 if a < 0 else -1), abs(a)
        new_ans = (2 ** d[(a, b)] - 1)
        new_ans += (2 ** d[(ainv, binv)] -1) if d.get((ainv, binv)) is not None else 0
        new_ans += 1
        ans = ans * new_ans % MOD
        seen.add((a, b))
        seen.add((ainv, binv))
ans = (ans + zero) & MOD
print((ans + MOD - 1) % MOD)

Submission status: Wrong Answer

Solution code:
import math
from collections import defaultdict

def INP(): return int(input())
def LINP(): return list(map(int,input().split()))

MOD = 10 ** 9 + 7
d = defaultdict(int)
zero = 0
N = INP()
for _ in range(N):
    A,B = LINP()
    if A == 0 and B == 0:
        zero += 1
        continue
    A = int(A/math.gcd(A,B))
    B = int(B/math.gcd(A,B))
    minus = (-1) ** ((A < 0) + (B < 0))
    d[(minus * abs(A), abs(B))] += 1
print(d)
ans = 1
seen = set()
for a, b in d:
    if (a, b) not in seen:
        if(a, b) in [(0, 1), (1, 0)]:
            ainv, binv = b, a
        else:
            ainv, binv = b * (1 if a < 0 else -1), abs(a)
        new_ans = (2 ** d[(a, b)] - 1)
        new_ans += (2 ** d[(ainv, binv)] -1) if d.get((ainv, binv)) is not None else 0
        new_ans += 1
        ans = ans * new_ans % MOD
        seen.add((a, b))
        seen.add((ainv, binv))
ans = (ans + zero) & MOD
print((ans + MOD -1) % MOD)

Submission status: Wrong Answer

Solution code:
import math
from collections import defaultdict

def INP(): return int(input())
def LINP(): return list(map(int,input().split()))

MOD = 10 ** 9 + 7
d = defaultdict(int)
zero = 0
N = INP()
for _ in range(N):
    A,B = LINP()
    if A == 0 and B == 0:
        zero += 1
        continue
    A = int(A/math.gcd(A,B))
    B = int(B/math.gcd(A,B))
    minus = (-1) ** ((A < 0) + (B < 0))
    d[(minus * abs(A), abs(B))] += 1
print(d)
ans = 1
seen = set()
for a, b in d:
    if (a, b) not in seen:
        if(a, b) in [(0, 1), (1, 0)]:
            ainv, binv = b, a
        else:
            ainv, binv = b * (1 if a < 0 else -1), abs(a)
        new_ans = (2 ** d[(a, b)] - 1)
        new_ans += (2 ** d[(ainv, binv)] -1) if d.get((ainv, binv)) is not None else 0
        new_ans += 1
        ans *= new_ans % MOD
        seen.add((a, b))
        seen.add((ainv, binv))
ans = (ans + zero) & MOD
print((ans + MOD -1) % MOD)

Submission status: Wrong Answer

Solution code:
import math
from collections import defaultdict

def INP(): return int(input())
def LINP(): return list(map(int,input().split()))

MOD = 10 ** 9 + 7
d = defaultdict(int)
zero = 0
N = INP()
for _ in range(N):
    A,B = LINP()
    if A == 0 and B == 0:
        zero += 1
        continue
    A = int(A/math.gcd(A,B))
    B = int(B/math.gcd(A,B))
    minus = (-1) ** ((A < 0) + (B < 0))
    d[(minus * abs(A), abs(B))] += 1
print(d)
ans = 1
seen = set()
for a, b in d:
    if (a, b) not in seen:
        if(a, b) in [(0, 1), (1, 0)]:
            ainv, binv = b, a
        else:
            ainv, binv = b * (1 if a < 0 else -1), abs(a)
        new_ans = (2 ** d[(a, b)] - 1)
        new_ans *= (2 ** d[(ainv, binv)] -1) if d.get((ainv, binv)) is not None else 0
        new_ans += 1
        ans *= new_ans % MOD
        seen.add((a, b))
        seen.add((ainv, binv))
ans = (ans + zero) & MOD
print((ans + MOD -1) % MOD)

Submission status: Wrong Answer

Solution code:
import math
from collections import defaultdict

def INP(): return int(input())
def LINP(): return list(map(int,input().split()))

MOD = 10 ** 9 + 7
d = defaultdict(int)
zero = 0
N = INP()
for _ in range(N):
    A,B = LINP()
    if A == 0 and B == 0:
        zero += 1
        continue
    A = int(A/math.gcd(A,B))
    B = int(B/math.gcd(A,B))
    minus = (-1) ** ((A < 0) + (B < 0))
    d[(minus * abs(A), abs(B))] += 1
print(d)
ans = 1
seen = set()
for a, b in d:
    if (a, b) not in seen:
        if(a, b) in [(0, 1), (1, 0)]:
            ainv, binv = b, a
        else:
            ainv, binv = b * (1 if a < 0 else -1), abs(a)
        new_ans = (2 ** d[(a, b)] - 1)
        new_ans *= (2 ** d[(ainv, binv)] -1) if d.get((ainv, binv)) is not None else 0
        new_ans += 1
        ans *= new_ans % MOD
        seen.add((a, b))
        seen.add((ainv, binv))
ans = (ans + zero) & MOD
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import Fraction
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:
            ratio.append(Fraction(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 - 1 / k in s:
            if s[k] != 0:
                bad *= (pow(2, v, MOD) + pow(2, s[-1/k], MOD) -1) % MOD
                bad %= MOD
                s[- 1 / k] = 0
        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 sys import stdin
from math import gcd
def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    a=[0]*n
    b=[0]*n
    for i in range(n):
        a[i],b[i]=map(int,readline().split())

    mod=1000000007
    d=dict()
    ans=1
    zeros=0
    for i in range(n):
        up=a[i]
        down=b[i]
        if up==0 and down==0:
            zeros+=1
        else:
            g=gcd(up,down)
            up//=g
            down//=g
            if up==0:
                down=1
            elif down==0:
                up==1
            elif down<0:
                down*=-1
                up*=-1

            d[(1,0)]=[0,0]
            if up==1 and down==0:
                d[(1,0)][0]+=1
            elif up==0 and down==1:
                d[(1,0)][1]+=1
            elif up>0:
                if (up,down) not in d and (-down,up) not in d:
                    d[(up,down)]=[1,0]
                elif (up,down) in d:
                    d[(up,down)][0]+=1
                else:
                    d[(-down,up)][1]+=1
            elif up<0:
                if (up,down) not in d and (down,-up) not in d:
                    d[(up,down)]=[1,0]
                elif (up,down) in d:
                    d[(up,down)][0]+=1
                else:
                    d[(down,-up)][1]+=1

    for v in d.values():
        ans*=pow(2,v[0])+pow(2,v[1])-1
        ans%=mod
    ans-=1
    ans+=zeros
    ans%=mod
    print(ans)

if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
from fractions import Fraction
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
    r = {}
    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:
            f = Fraction(a, b)
            if f in r:
                r[f] += 1
            else:
                r[f] = 1

    bad = pow(2, a_zero, MOD) * pow(2, b_zero, MOD)
    bad %= MOD
    for k, v in r.items():
        if - 1 / k in r:
            if r[k] != 0:
                bad *= (pow(2, v, MOD) + pow(2, r[-1/k], MOD) -1) % MOD
                bad %= MOD
                r[- 1 / k] = 0
        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 fractions import Fraction
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:
            ratio.append(Fraction(a, b))
    
    s = Counter(ratio)

    bad = pow(2, a_zero, MOD) * pow(2, b_zero, MOD)
    bad %= MOD
    for k, v in s.items():
        if - 1 / k in s:
            if s[k] != 0:
                bad *= (pow(2, v, MOD) + pow(2, s[-1/k], MOD) -1) % MOD
                bad %= MOD
                s[- 1 / k] = 0
        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 collections import Counter

n = int(input())
ab = []
mod = 10**9+7

num_ab0 = 0
num_a0 = 0
num_b0 = 0

for i in range(n):
    A, B = map(int, input().split())
    if A == 0 and B == 0:
        num_ab0 += 1
    elif A == 0:
        num_a0 += 1
    elif B == 0:
        num_b0 += 1
    else:
        C = -B / A
        ab.append(-B / A)

c = Counter(ab)

total = 2 ** num_a0 + 2 ** num_b0 - 1
considered = 0
for k, v in c.items():
    num = c.get(-1 / k)
    if num:
        if k > 0:
            total *= (2 ** v + 2 ** num - 1)
    else:
        total *= 2 ** v

print(total - 1 + num_ab0)

Submission status: Wrong Answer

Solution code:
import numpy as np
from collections import Counter

mod = 10**9 + 7

N = int(input())

A = np.array([0] * N)
B = np.array([0] * N)

for i in range(N):
    A[i], B[i] = map(int, input().split())

A_B = A / B
c_ab = Counter(A_B)
keys = list(c_ab.keys())
found = [False] * len(keys)

ans = 1

ans = ans * pow(2,(c_ab[0] + c_ab[np.inf]), mod) 

for i in range(len(keys)):
    if keys[i] == 0 or keys[i] == np.inf:
        found[i] == True

    for j in range(i+1, len(keys)):
        if keys[i] * keys[j] == -1:
            found[i], found[j] = True, True
            tmp = pow(2, c_ab[keys[i]], mod) + pow(2, c_ab[keys[j]], mod) - 1
            ans = ans * tmp % mod

r = 0
for i in range(len(keys)):
    if not found[i]:
        r += c_ab[keys[i]]

ans = ans * pow(2,r,mod) % mod - 1

print(ans)

Submission status: Wrong Answer

Solution code:
#!python3

import sys
from collections import defaultdict
from math import gcd

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N = input()
    it = map(int, sys.stdin.read().split())
    mod = 10**9 + 7

    d1 = [defaultdict(int), defaultdict(int)]
    z0 = 0
    for ai, bi in zip(it, it):
        if ai == 0 and bi == 0:
            z0 += 1
            continue

        ci = gcd(ai, bi)
        ai, bi = ai // ci, bi // ci

        t = ai * bi < 0
        if ai < 0:
            ai, bi = -ai ,-bi
        elif ai == 0 and bi > 0:
            bi = -1
            t = 1

        d1[t][(ai, bi)] += 1


    a1, a2 = d1
    ans = 1
    for (ai, bi), v in a1.items():
        k2 = (bi, -ai)
        if k2 in a2:
            v2 = a2[k2]
            ans *= pow(2, v, mod) + pow(2, v2, mod) - 1
        else:
            ans *= pow(2, v, mod)
        ans %= mod

    for (ai, bi), v in a2.items():
        k2 = (-bi, ai)

        if k2 in a1: continue

        ans *= pow(2, v, mod)
        ans %= mod

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



if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
n = int(input())
zeros = 0
ab = {}
for _ in range(n):
    a, b = [int(i) for i in input().split()]
    if a == b == 0:
        zeros += 1
    elif a == 0 or b == 0:
        if None not in ab:
            ab[None] = [0, 0]
        if a == 0:
            ab[None][0] += 1
        else:
            ab[None][1] += 1
    else:
        x = 1 if a * b > 0 else -1
        c = max(abs(a) * 10 ** 100 // abs(b) * x, -abs(b) * 10 ** 100 // abs(a) * x)
        if c not in ab:
            ab[c] = [0, 0]
        if a * b > 0:
            ab[c][0] += 1
        else:
            ab[c][1] += 1
ans = 1
mod = 10 ** 9 + 7
for _, v in ab.items():
    ans *= pow(2, v[0], mod) + pow(2, v[1], mod) - 1
    ans %= mod
ans += zeros - 1
print(ans % mod)

Submission status: Wrong Answer

Solution code:
#!python3

import sys
from collections import defaultdict
from math import gcd

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N = input()
    it = map(int, sys.stdin.read().split())
    mod = 10**9 + 7

    d1 = [defaultdict(int), defaultdict(int)]
    z0 = 0
    for ai, bi in zip(it, it):
        if ai == 0 and bi == 0:
            z0 += 1
            continue

        ci = gcd(ai, bi)
        ai, bi = ai // ci, bi // ci

        t = ai * bi < 0
        if ai < 0:
            ai, bi = -ai ,-bi
        elif ai == 0 and bi > 0:
            bi = -1
            t = 1

        d1[t][(ai, bi)] += 1


    a1, a2 = d1
    ans = 1
    for (ai, bi), v in a1.items():
        k2 = (bi, -ai)
        if k2 in a2:
            v2 = a2[k2]
            ans *= pow(2, v+v2, mod) - (pow(2, v, mod)-1)*(pow(2, v2, mod)-1)
        else:
            ans *= pow(2, v, mod)
        ans %= mod

    for (ai, bi), v in a2.items():
        k2 = (-bi, ai)

        if k2 in a1: continue

        ans *= pow(2, v, mod)
        ans %= mod

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



if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
from math import gcd
from numpy import sign
mod = 1000000007
N = int(input())

if N == 1:
    print(1)
    
d = {}


for _ in range(N):
    a, b = list(map(int, input().split()))
    if a == b == 0:
        if (0, 0) not in d:
            d[(0, 0)] = 1
        else:
            d[(0, 0)] += 1
    else:
        g = gcd(a, b)
        a, b =  a / g, b /g
        if b < 0:
            a, b = -a, -b
        if b == 0:
            a, b =  1, 0
        if (a, b) not in d:
            d[(a, b)] =1
        else:
            d[(a, b)] +=1

answer = 1

done_list = []


for k in list(d.keys()):
    if k not in done_list and k != (0, 0):
        pair_k = (sign(k[0]) * (-1) * k[1], abs(k[0]))
        if pair_k not in d:
            answer *= (2 ** d[k]) % mod
            answer = answer % mod
            done_list += [k]
        else:
            answer *= ((2 ** d[k]) + (2 ** d[pair_k]) - 1) % mod
            answer = answer % mod
            done_list += [k, pair_k]

if (0, 0) in d:
    answer += d[(0, 0)]
    
print((answer - 1) % mod)