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 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:
        pair_k = (sign(k[0]) * (-1) * k[1], abs(k[0]))
        if pair_k not in d:
            answer *= 2 ** d[k]
            answer = answer % mod
            done_list += [k]
        else:
            answer *= (2 ** d[k]) + (2 ** d[pair_k]) - 1
            answer = answer % mod
            done_list += [k, pair_k]

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

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

print(d)

done_list = []

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

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

Submission status: Wrong Answer

Solution code:
import math
import collections

n = int(input())
iwashi = []
sub_ans = 0
for i in range(n):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        sub_ans += 1
    else:
        if b == 0:
            iwashi.append('1/0')
        elif b > 0:
            c = math.gcd(a, b)
            iwashi.append('{}/{}'.format(a//c, b//c))
        else:
            c = math.gcd(a, b)
            iwashi.append('{}/{}'.format(-a//c, -b//c))
# print(iwashi)
iwashi = collections.Counter(iwashi)
k_list = list(iwashi.keys())
v = list(iwashi.values())
# k_list.sort(key=lambda x: -x)

mod = 1000000007
ans = 1
for k in k_list:
    a = iwashi[k]
    if k == '1/0':
        anti_k = '0/1'
    elif k == '0/1':
        anti_k = '1/0'
    else:
        c, d = k.split('/')
        if int(c) < 0:
            anti_k = '{}/{}'.format(d, -int(c))
        else:
            anti_k = '{}/{}'.format(-int(d), c)

    b = iwashi[anti_k]
    if a*b != 0:
        ans *= (pow(2, a, mod) + pow(2, b, mod) -1)
    else:
        ans *= pow(2, a, mod)
    iwashi[k] = 0
    iwashi[anti_k] = 0
    # print(k, anti_k ,a, b, ans)
    ans %= mod
print(ans+sub_ans-1)

Submission status: Wrong Answer

Solution code:
from math import gcd
mod_val = 1000000007
def simplify(A, B):
  a = A//gcd(A,B)
  b = B//gcd(A,B)
  if b<0:
    return (-a, -b)
  return (a, b)
n = int(input())
count_simple_fish = dict()
bad_fish = 0
for _ in range(n):
  A, B = map(int, input().split())
  if A == B == 0:
    bad_fish = (bad_fish + 1)%mod_val
    continue
  if B == 0:
    if (1, 0) in count_simple_fish:
      count_simple_fish[(1, 0)][1] += 1
    else:
      count_simple_fish[(1, 0)] = [0, 1]
  elif A == 0:
    if (1, 0) in count_simple_fish:
      count_simple_fish[(1, 0)][0] += 1
    else:
      count_simple_fish[(1, 0)] = [1, 0]
  else:
    a, b = simplify(A, B)
    if a>0:
      if (a, b) in count_simple_fish:
        count_simple_fish[(a, b)][1] += 1
      else:
        count_simple_fish[(a, b)] = [0, 1]
    else:
      if (b, -a) in count_simple_fish:
        count_simple_fish[(b, -a)][0] += 1
      else:
        count_simple_fish[(b, -a)] = [1, 0]
big_total = 1
for simple_fish, count_leftright in count_simple_fish.items():
  group_pair_combos = 1
  group_pair_combos = (group_pair_combos + pow(2, count_leftright[1], mod_val) - 1)%mod_val
  group_pair_combos = (group_pair_combos + pow(2, count_leftright[0], mod_val) - 1)%mod_val
  big_total = (big_total * group_pair_combos)%mod_val
print(count_simple_fish)
big_total = (big_total + bad_fish - 1)%mod_val
print(big_total)

Submission status: Wrong Answer

Solution code:
mod=10**9+7
n=int(input())
d={}
x0=0
y0=0
z=0
from math import gcd 
for i in range(n):
    x,y=map(int,input().split())
    if x==y==0:z+=1
    else:
        f=gcd(x,y)
        x//=f;y//=f
        if x<0:x*=-1;y*=-1
        if (x,y)in d:d[(x,y)]+=1
        else:d[(x,y)]=1
ans=1
for (a,s) in d:
    if d[(a,s)]==0:continue
    ng=0
    if (s,-a)in d:ng+=d[(s,-a)];d[(s,-a)]=0
    if (-s,a)in d:ng+=d[(-s,a)];d[(-s,a)]=0
    ans*=(pow(2,d[(a,s)],mod)+(pow(2,ng,mod)-1 if ng else 0))%mod
    ans%=mod
    d[(a,s)]=0
print((ans+z-1)%mod)

Submission status: Wrong Answer

Solution code:
mod=10**9+7
n=int(input())
d={}
x0=0
y0=0
z=0
from math import gcd 
for i in range(n):
    x,y=map(int,input().split())
    if x==y==0:z+=1
    else:
        f=gcd(x,y)
        x//=f;y//=f
        if x<0:x*=-1;y*=-1
        if (x,y)in d:d[(x,y)]+=1
        else:d[(x,y)]=1
ans=1
for (a,s) in d:
    if d[(a,s)]==0:continue
    ng=0
    if (s,-a)in d:ng+=d[(s,-a)];d[(s,-a)]=0
    if (-s,a)in d:ng+=d[(-s,a)];d[(-s,a)]=0
    ans*=(pow(2,d[(a,s)],mod)+(pow(2,ng,mod)-1 if ng else 0))%mod
    ans%=mod
print((ans+z-1)%mod)

Submission status: Wrong Answer

Solution code:
mod=10**9+7
n=int(input())
d={}
x0=0
y0=0
z=0
from math import gcd 
for i in range(n):
    x,y=map(int,input().split())
    if x==y==0:z+=1
    else:
        f=gcd(x,y)
        x//=f;y//=f
        if x<0:x*=-1;y*=-1
        if (x,y)in d:d[(x,y)]+=1
        else:d[(x,y)]=1
ans=1
if x0 and y0:ans=(pow(2,x0,mod)+pow(2,y0,mod)-1)%mod
elif x0 or y0:ans=pow(2,x0+y0,mod)

for (a,s) in d:
    if d[(a,s)]==0:continue
    ng=0
    if (s,-a)in d:ng+=d[(s,-a)];d[(s,-a)]=0
    if (-s,a)in d:ng+=d[(-s,a)];d[(-s,a)]=0
    ans*=(pow(2,d[(a,s)],mod)+(pow(2,ng,mod)-1 if ng else 0))%mod
    ans%=mod
print((ans+z-1)%mod)

Submission status: Wrong Answer

Solution code:
mod=10**9+7
n=int(input())
d={}
x0=0
y0=0
z=0
from math import gcd 
for i in range(n):
    x,y=map(int,input().split())
    if x==y==0:z+=1
    elif x==0:x0+=1
    elif y==0:y0+=1
    else:
        f=gcd(x,y)
        x//=f;y//=f
        if (x,y)in d:d[(x,y)]+=1
        else:d[(x,y)]=1
ans=1
if x0 and y0:ans=(pow(2,x0,mod)+pow(2,y0,mod)-1)%mod
elif x0 or y0:ans=pow(2,x0+y0,mod)

for (a,s) in d:
    if d[(a,s)]==0:continue
    ng=0
    if (s,-a)in d:ng+=d[(s,-a)];d[(s,-a)]=0
    if (-s,a)in d:ng+=d[(-s,a)];d[(-s,a)]=0
    ans*=(pow(2,d[(a,s)],mod)+(pow(2,ng,mod)-1 if ng else 0))%mod
    ans%=mod
print((ans+z-1)%mod)

Submission status: Wrong Answer

Solution code:
mod=10**9+7
n=int(input())
d={}
x0=0
y0=0
z=0
from math import gcd 
for i in range(n):
    x,y=map(int,input().split())
    if x==y==0:z+=1
    elif x==0:x0+=1
    elif y==0:y0+=1
    else:
        f=gcd(x,y)
        x//=f;y//=f
        if (x,y)in d:d[(x,y)]+=1;d[(x,y)]%=(mod-1)
        else:d[(x,y)]=1
ans=1
if x0 and y0:ans=(pow(2,x0,mod)+pow(2,y0,mod)-1)%mod
elif x0 or y0:ans=pow(2,x0+y0,mod)

for (a,s) in d:
    if d[(a,s)]==0:continue
    ng=0
    if (s,-a)in d:ng+=d[(s,-a)];d[(s,-a)]=0
    if (-s,a)in d:ng+=d[(-s,a)];d[(-s,a)]=0
    ng%=mod-1
    ans*=(pow(2,d[(a,s)]%(mod-1),mod)+(pow(2,ng,mod)-1 if ng else 0))%mod
    ans%=mod
print((ans+z-1)%mod)

Submission status: Wrong Answer

Solution code:
mod=10**9+7
n=int(input())
d={}
x0=0
y0=0
z=0
from math import gcd 
for i in range(n):
    x,y=map(int,input().split())
    if x==y==0:z+=1
    elif x==0:x0+=1
    elif y==0:y0+=1
    else:
        f=gcd(x,y)
        x//=f;y//=f
        if (x,y)in d:d[(x,y)]+=1;d[(x,y)]%=(mod-1)
        else:d[(x,y)]=1
ans=1
if x0 and y0:ans=(pow(2,x0,mod)+pow(2,y0,mod)-1)%mod
elif x0 or y0:ans=pow(2,x0+y0,mod)
print(d)
for (a,s) in d:
    if d[(a,s)]==0:continue
    ng=0
    if (s,-a)in d:ng+=d[(s,-a)];d[(s,-a)]=0
    if (-s,a)in d:ng+=d[(-s,a)];d[(-s,a)]=0
    ng%=mod-1
    ans*=(pow(2,d[(a,s)]%(mod-1),mod)+(pow(2,ng,mod)-1 if ng else 0))%mod
    ans%=mod
print((ans+z-1)%mod)

Submission status: Wrong Answer

Solution code:
import sys
import math
mod = 1000000007
 
n = int(sys.stdin.readline().rstrip())
ab = {}
for i in range(n):
    a,b = map(int,sys.stdin.readline().rstrip().split())
    if a == 0 and b == 0:
        pass
    elif a == 0:
        b = 1
    else:
        gcd = math.gcd(a,b)
        a //= gcd
        b //= gcd
        if a < 0:
            a = -a
            b = -b
    ab.setdefault((a,b),0)
    ab[(a,b)]+=1
ans = 0
pairs=[]
s = list(set(ab.keys()))
for i in ab.keys():
    a = i[0];b = i[1]
    if a == 0 and b == 0:
        ans = ab[(0,0)]
        n -= ans
    else:
        if (-b, a) in s:
            pairs.append([ab[(a,b)],ab[(-b,a)]])
select = 1
for pair in pairs:
    select*= (pow(2,pair[0],mod) + pow(2,pair[1],mod) -1)
    n -= (pair[0]+pair[1])
    select %= mod #TLE出ないように
select *= pow(2,n,mod) + ans -1
all_ans = select + ans -1
all_ans %= mod
print(all_ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import defaultdict
from math import gcd


def main():
    MOD = 1000000007

    # N, *AB = map(int, stdin.buffer.read().split())
    N = int(input())
    AB = (map(int, input().split()) for _ in range(N))

    d = defaultdict(int)
    n_zeros = 0

    for a, b in AB:
        if a == 0 and b == 0:
            n_zeros += 1
            continue

        g = gcd(a, b)
        a, b = a // g, b // g

        if a * b > 0 or b == 0:
            c = abs(a) + abs(b) * 1j
        else:  # a * b < 0 or a == 0
            c = - abs(b) - abs(a) * 1j

        d[c] += 1

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

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import defaultdict
from math import gcd


def main():
    MOD = 1000000007

    # N, *AB = map(int, stdin.buffer.read().split())
    N = int(input())
    AB = (map(int, input().split()) for _ in range(N))

    d = defaultdict(int)
    n_zeros = 0

    for a, b in AB:
        if a == 0 and b == 0:
            n_zeros += 1
            continue

        g = gcd(a, b)
        a, b = a // g, b // g

        if a * b > 0 or b == 0:
            c = abs(a) + abs(b) * 1j
        else:  # a * b < 0 or a == 0
            c = - abs(b) - abs(a) * 1j

        d[c] += 1

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

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import defaultdict
from math import gcd


def main():
    MOD = 1000000007

    # N, *AB = map(int, stdin.buffer.read().split())
    N = int(input())
    AB = (map(int, input().split()) for _ in range(N))

    d = defaultdict(int)
    n_zeros = 0

    for a, b in AB:
        if a == 0 and b == 0:
            n_zeros += 1
            continue

        g = gcd(a, b)
        a, b = a // g, b // g

        if a * b > 0 or b == 0:
            c = abs(a) + abs(b) * 1j
        else:  # a * b < 0 or a == 0
            c = - abs(b) - abs(a) * 1j

        d[c] += 1

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

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd

N=int(input())
d={}
#l=[]
MOD = 1000000007
nz=0
for _ in range(N):
    a,b=map(int,input().split())
    if a==0 and b==0:
        nz+=1
        #p=(0,0)
        continue
    elif a==0:
        p=(0,1)
    elif b==0:
        p=(1,0)
    else:
        c=gcd(a,b)
        if b > 0:
            p=(a//c,b//c)
        else: # b < 0
            p=(-a//c,-b//c)
    
    #l.append(p)
    if p in d:
        d[p]+=1
    else:
        d[p] = 1

ans=1
#for p in l:
while len(d) > 0:
    p,np=d.popitem()
    if p==(1,0):
        q=(0,1)
    elif p==(0,1):
        q=(1,0)
    else:
        pa,pb=p
        if pa > 0:
            q=(-pb,pa)
        else: #pa < 0
            q=(pb,-pa)
    if q in d:
        nq=d.pop(q)
    else:
        nq=0
    
    ans *= ((2**np + 2**nq - 1) % MOD)
    ans %= MOD

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

Submission status: Wrong Answer

Solution code:
import sys
from math import gcd
from collections import Counter
MOD = 10**9 + 7
def main():
    input = sys.stdin.readline
    N = int(input())
    V = []
    z = 0
    for _ in range(N):
        A, B = map(int, input().split())
        g = gcd(A, B)
        if g == 0:
            z += 1
            continue
        A, B = A // g, B // g
        if A == 0: V.append((0, 1))
        elif A < 0: V.append((-A, -B))
        else: V.append((A, B))
    C = Counter(V)
    ans = Mint(1)
    used = set()
    for k, V in C.items():
        a, b = k
        v = (b, -a) if b >= 0 else (-b, a)
        if v in used: continue
        t = Mint(1)
        t += pow(2, V, MOD) - 1
        t += pow(2, C[v], MOD) - 1
        ans *= t
        used.add(k)
        used.add(v)
    print(ans - 1 + z)

class Mint:
    def __init__(self, value=0):
        self.value = value % MOD
        if self.value < 0: self.value += MOD

    @staticmethod
    def get_value(x): return x.value if isinstance(x, Mint) else x

    def inverse(self):
        a, b = self.value, MOD
        u, v = 1, 0
        while b:
            t = a // b
            b, a = a - t * b, b
            v, u = u - t * v, v
        if u < 0: u += MOD
        return u

    def __repr__(self): return str(self.value)
    def __eq__(self, other): return self.value == other.value
    def __neg__(self): return Mint(-self.value)
    def __hash__(self): return hash(self.value)
    def __bool__(self): return self.value != 0

    def __iadd__(self, other):
        self.value = (self.value + Mint.get_value(other)) % MOD
        return self

    def __add__(self, other):
        new_obj = Mint(self.value)
        new_obj += other
        return new_obj
    __radd__ = __add__

    def __isub__(self, other):
        self.value = (self.value - Mint.get_value(other)) % MOD
        if self.value < 0: self.value += MOD
        return self

    def __sub__(self, other):
        new_obj = Mint(self.value)
        new_obj -= other
        return new_obj

    def __rsub__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj -= self
        return new_obj

    def __imul__(self, other):
        self.value = self.value * Mint.get_value(other) % MOD
        return self

    def __mul__(self, other):
        new_obj = Mint(self.value)
        new_obj *= other
        return new_obj
    __rmul__ = __mul__

    def __ifloordiv__(self, other):
        other = other if isinstance(other, Mint) else Mint(other)
        self *= other.inverse()
        return self

    def __floordiv__(self, other):
        new_obj = Mint(self.value)
        new_obj //= other
        return new_obj

    def __rfloordiv__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj //= self
        return new_obj


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from math import gcd
from collections import Counter
MOD = 10**9 + 7
def main():
    input = sys.stdin.readline
    N = int(input())
    V = []
    z = 0
    for _ in range(N):
        A, B = map(int, input().split())
        g = gcd(A, B)
        if g == 0:
            z += 1
            continue
        A, B = A // g, B // g
        if A == 0: V.append((0, 1))
        elif A < 0: V.append((-A, -B))
        else: V.append((A, B))
    C = Counter(V)
    ans = Mint(1)
    used = set()
    for k, V in C.items():
        a, b = k
        v = (b, -a) if b >= 0 else (-b, a)
        if v in used: continue
        t = Mint(1)
        t += pow(2, V, MOD) - 1
        t += pow(2, C[v], MOD) - 1
        ans *= t
        used.add(k)
    print(ans - 1 + z)

class Mint:
    def __init__(self, value=0):
        self.value = value % MOD
        if self.value < 0: self.value += MOD

    @staticmethod
    def get_value(x): return x.value if isinstance(x, Mint) else x

    def inverse(self):
        a, b = self.value, MOD
        u, v = 1, 0
        while b:
            t = a // b
            b, a = a - t * b, b
            v, u = u - t * v, v
        if u < 0: u += MOD
        return u

    def __repr__(self): return str(self.value)
    def __eq__(self, other): return self.value == other.value
    def __neg__(self): return Mint(-self.value)
    def __hash__(self): return hash(self.value)
    def __bool__(self): return self.value != 0

    def __iadd__(self, other):
        self.value = (self.value + Mint.get_value(other)) % MOD
        return self

    def __add__(self, other):
        new_obj = Mint(self.value)
        new_obj += other
        return new_obj
    __radd__ = __add__

    def __isub__(self, other):
        self.value = (self.value - Mint.get_value(other)) % MOD
        if self.value < 0: self.value += MOD
        return self

    def __sub__(self, other):
        new_obj = Mint(self.value)
        new_obj -= other
        return new_obj

    def __rsub__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj -= self
        return new_obj

    def __imul__(self, other):
        self.value = self.value * Mint.get_value(other) % MOD
        return self

    def __mul__(self, other):
        new_obj = Mint(self.value)
        new_obj *= other
        return new_obj
    __rmul__ = __mul__

    def __ifloordiv__(self, other):
        other = other if isinstance(other, Mint) else Mint(other)
        self *= other.inverse()
        return self

    def __floordiv__(self, other):
        new_obj = Mint(self.value)
        new_obj //= other
        return new_obj

    def __rfloordiv__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj //= self
        return new_obj


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math


n = int(input())
mod = 1000000007
ab = [list(map(int,input().split())) for _ in range(n)]
dic = {}
z = 0
nz,zn = 0,0
for a,b in ab:
    if a == 0 and b == 0:
        z += 1
        continue
    elif a == 0:
        zn += 1
        continue
    elif b == 0:
        nz += 1
    if a< 0:
        a = -a
        b = -b
    g = math.gcd(a,b)
    tp = (a//g,b//g)
    if tp not in dic:
        dic[tp] = 1
    else:
        dic[tp] += 1
    
ans = 1
nn = n - z - zn - nz
for tp,v in dic.items():
    if v == 0:
        continue
    vt = (tp[1],-1*tp[0])
    if vt in dic:
        w = dic[vt]
        #print(tp)
        e = pow(2,v,mod) + pow(2,w,mod) - 1
        ans *= e
        ans %= mod
        nn -= v + w 
        dic[tp] = 0
        dic[vt] = 0
ans *= pow(2,nn,mod)
ans += z - 1
if zn == 0:
    ans *= pow(2,nz,mod)
elif nz == 0:
    ans *= pow(2,zn,mod)
else:
    ans *= pow(2,nz,mod) + pow(2,zn,mod) - 1
print(ans%mod)
#print(dic)

Submission status: Wrong Answer

Solution code:
import sys
import  math
from heapq import *
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

mod=10**9+7
zero=0
counter0=defaultdict(int)
counter1=defaultdict(int)
N=int(input())
for i in range(N):
    x,y=nm()
    if(x==0 and y==0):
        zero+=1
        continue
    g=fractions.gcd(x,y)
    x/=g
    y/=g
    if(y<0):
        x=-x
        y=-y
    if(y==0 and x<0):
        x=-x
        y=-y
    rot90=False
    if(x<0):
        rot90=True
    if(rot90):
        tmp = x
        x=y
        y=-tmp
    if(rot90):
        counter0[(x,y)]+=1
    else:
        counter1[(x,y)]+=1
        counter0[(x,y)]+=0

ans=1
for key,cnt0 in counter0.items():
    cnt1=counter1[key]
    now=1
    now+=2**cnt0-1
    now+=2**cnt1-1
    now%=mod
    ans*=now
    ans%=mod
        
ans+=zero
ans-=1

print(ans%mod)

Submission status: Wrong Answer

Solution code:
import math


n = int(input())
mod = 1000000007
ab = [list(map(int,input().split())) for _ in range(n)]
dic = {}
z = 0
nz,zn = 0,0
for a,b in ab:
    if a == 0 and b == 0:
        z += 1
        continue
    elif a == 0:
        zn += 1
        continue
    elif b == 0:
        nz += 1
    if a< 0:
        a = -a
        b = -b
    g = math.gcd(a,b)
    tp = (a//g,b//g)
    if tp not in dic:
        dic[tp] = 1
    else:
        dic[tp] += 1
    
ans = 1
nn = n - z - zn - nz
for tp,v in dic.items():
    if v == 0:
        continue
    vt = (tp[1],-1*tp[0])
    if vt in dic:
        w = dic[vt]
        #print(tp)
        e = pow(2,v,mod) + pow(2,w,mod) - 1
        ans *= e
        ans %= mod
        nn -= v + w 
        dic[tp] = 0
        dic[vt] = 0
ans *= pow(2,nn,mod)
ans += z
if zn == 0:
    ans *= pow(2,nz,mod)
elif nz == 0:
    ans *= pow(2,zn,mod)
else:
    ans *= pow(2,nz,mod) + pow(2,zn,mod) - 1
print(ans%mod)
#print(dic)

Submission status: Wrong Answer

Solution code:
import sys
import  math
from heapq import *
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

mod=10**9+7
zero=0
counter0=defaultdict(int)
counter1=defaultdict(int)
N=int(input())
for i in range(N):
    x,y=nm()
    if(x==0 and y==0):
        zero+=1
        continue
    g=fractions.gcd(x,y)
    x/=g
    y/=g
    if(y<0):
        x=-x
        y=-y
    if(y==0 and x<0):
        x=-x
        y=-y
    rot90=False
    if(x<0):
        rot90=True
    if(rot90):
        tmp = x
        x=y
        y=-tmp
    if(rot90):
        counter0[(x,y)]+=1
    else:
        counter1[(x,y)]+=1
        counter0[(x,y)]+=0

ans=1
for key,cnt0 in counter0.items():
    cnt1=counter1[key]
    now=1
    now+=2**cnt0-1
    now+=2**cnt1-1
    now%=mod
    ans*=now
    ans%mod
        
ans+=zero
ans-=1

print(ans%mod)

Submission status: Wrong Answer

Solution code:
import sys
import  math
from heapq import *
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

mod=10**9+7
zero=0
counter0=defaultdict(int)
counter1=defaultdict(int)
N=int(input())
for i in range(N):
    x,y=nm()
    if(x==0 and y==0):
        zero+=1
        continue
    g=fractions.gcd(x,y)
    x/=g
    y/=g
    if(y<0):
        x=-x
        y=-y
    if(y==0 and x<0):
        x=-x
        y=-y
    rot90=False
    if(x<0):
        rot90=True
    if(rot90):
        tmp = x
        x=y
        y=-tmp
    if(rot90):
        counter0[(x,y)]+=1
    else:
        counter1[(x,y)]+=1
        counter0[(x,y)]+=0

ans=1
for key,cnt0 in counter0.items():
    cnt1=counter1[key]
    now=1
    now+=2**cnt0-1
    now+=2**cnt1-1
    now%=mod
    ans*=now
        
ans+=zero
ans-=1

print(ans%mod)

Submission status: Wrong Answer

Solution code:
import sys
import  math
from heapq import *
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

mod=10**9+7
zero=0
counter0=defaultdict(int)
counter1=defaultdict(int)
N=int(input())
for i in range(N):
    x,y=nm()
    if(x==0 and y==0):
        zero+=1
        continue
    g=fractions.gcd(x,y)
    x/=g
    y/=g
    if(y<0):
        x=-x
        y=-y
    if(y==0 and x<0):
        x=-x
        y=-y
    rot90=False
    if(x<0):
        rot90=True
    if(rot90):
        tmp = x
        x=y
        y=-tmp
    if(rot90):
        counter0[(x,y)]+=1
    else:
        counter1[(x,y)]+=1
        counter0[(x,y)]+=0

ans=1
for key,cnt0 in counter0.items():
    cnt1=counter1[key]
    now=1
    now+=2**cnt0-1
    now+=2**cnt1-1
    now%=mod
    ans*=now
        
ans+=zero
ans-=1

print(ans)

Submission status: Wrong Answer

Solution code:
import math


n = int(input())
mod = 1000000007
ab = [list(map(int,input().split())) for _ in range(n)]
dic = {}
z = 0
nz,zn = 0,0
for a,b in ab:
    if a == 0 and b == 0:
        z += 1
        continue
    if a< 0:
        a = -a
        b = -b
    elif a == 0:
        zn += 1
        continue
    elif b == 0:
        nz += 1
    g = math.gcd(a,b)
    tp = (a//g,b//g)
    if tp not in dic:
        dic[tp] = 1
    else:
        dic[tp] += 1
    
ans = 1
nn = n - z - zn - nz
for tp,v in dic.items():
    if v == 0:
        continue
    vt = (tp[1],-1*tp[0])
    if vt in dic:
        w = dic[vt]
        #print(tp)
        e = pow(2,v,mod) + pow(2,w,mod) - 1
        ans *= e
        ans %= mod
        nn -= v + w 
        dic[tp] = 0
        dic[vt] = 0
ans *= pow(2,nn,mod)
ans += z-1
if zn == 0:
    ans *= pow(2,nz,mod)
elif nz == 0:
    ans *= pow(2,zn,mod)
else:
    ans *= pow(2,nz,mod) + pow(2,zn,mod) - 1
print(ans%mod)
#print(dic)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
mod = 10 ** 9 + 7
zero = 0
d = {}
for i in range(N):
    x, y = map(int, input().split())
    if x == 0 and y == 0:
        zero += 1
        continue
    g = math.gcd(x, y)
    x /= g
    y /= g
    if y < 0:
        x = - x
        y = - y
    if y == 0 and x < 0:
        x = - x
        y = - y
    rot90 = x <= 0
    if rot90:
        tmp = x
        x = y
        y = - tmp
    if rot90:
        if (x, y) not in d:
            d[(x, y)] = [0, 0]
        d[(x, y)][0] += 1
    else:
        if (x, y) not in d:
            d[(x, y)] = [0, 0]
        d[(x, y)][1] += 1
ans = 1
for p in d.values():
    s = p[0]
    t = p[1]
    now = 1
    now += pow(2, s, mod) - 1
    now %= mod
    now += pow(2, t, mod) - 1
    now %= mod
    ans *= now
    ans %= mod
ans -= 1
ans += zero
print(ans % mod)

Submission status: Wrong Answer

Solution code:
import sys
import  math
from heapq import *
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

mod=10**9+7
zero=0
counter0=defaultdict(int)
counter1=defaultdict(int)
N=int(input())
for i in range(N):
    x,y=nm()
    if(x==0 and y==0):
        zero+=1
        continue
    g=fractions.gcd(x,y)
    x/=g
    y/=g
    if(y<0):
        x=-x
        y=-y
    if(y==0 and x<0):
        x=-x
        y=-y
    rot90=False
    if(x<0):
        rot90=True
    if(rot90):
        tmp = x
        x=y
        y=-tmp
    if(rot90):
        counter0[(x,y)]+=1
    else:
        counter1[(x,y)]+=1

ans=1
for key,cnt0 in counter0.items():
    cnt1=counter1[key]
    now=1
    now+=2**cnt0-1
    now+=2**cnt1-1
    now%=mod
    ans*=now
        
ans+=zero
ans-=1

print(ans)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
mod = 10 ** 9 + 7
zero = 0
d = {}
for i in range(N):
    x, y = map(int, input().split())
    if x == 0 and y == 0:
        zero += 1
        continue
    g = math.gcd(x, y)
    x /= g
    y /= g
    if y < 0:
        x = - x
        y = - y
    if y == 0 and x < 0:
        x = - x
        y = - y
    rot90 = x <= 0
    if rot90:
        tmp = x
        x = y
        y = - tmp
    if rot90:
        if (x, y) not in d:
            d[(x, y)] = [0, 0]
        d[(x, y)][0] += 1
    else:
        if (x, y) not in d:
            d[(x, y)] = [0, 0]
        d[(x, y)][1] += 1
ans = 1
for p in d.values():
    s = p[0]
    t = p[1]
    now = 1
    now += pow(2, s, mod) - 1
    now += pow(2, t, mod) - 1
    ans *= now
    ans %= mod
ans -= 1
ans += zero
print(ans % mod)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
mod = 10 ** 9 + 7
zero = 0
d = {}
for i in range(N):
    x, y = map(int, input().split())
    if x == 0 and y == 0:
        zero += 1
        continue
    g = math.gcd(x, y)
    x /= g
    y /= g
    if y < 0:
        x = - x
        y = - y
    if y == 0 and x < 0:
        x = - x
        y = - y
    rot90 = x <= 0
    if rot90:
        tmp = x
        x = y
        y = - tmp
    if rot90:
        if (x, y) not in d:
            d[(x, y)] = [0, 0]
        d[(x, y)][0] += 1
    else:
        if (x, y) not in d:
            d[(x, y)] = [0, 0]
        d[(x, y)][1] += 1
ans = 1
for p in d.values():
    s = p[0]
    t = p[1]
    now = 1
    now += pow(2, s, mod) - 1
    now += pow(2, t, mod) - 1
    ans *= now
    ans %= mod
ans -= 1
ans += zero
print(ans)