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:
import math
def heikatu(A,B):
    if A % abs(B) ==0:
        return (A//abs(B),B//abs(B))
    if abs(B) % A == 0:
        return (1,B//A)
    
    c = math.gcd(A,B)

    return (A//c,B//c)
 
 
def pow_r(x, n,mod=10**9+7):
    """
    O(log n)
    """
    if n == 0:  # exit case
        return 1
    if n % 2 == 0:  # standard case ① n is even
        return pow_r((x ** 2)%1000000007 , n // 2) % mod
    else:  # standard case ② n is odd
        return (x * pow_r((x ** 2)%1000000007, (n - 1) // 2) % mod) % mod
 
 
 
def resolve():
    N = int(input())
 
    kp = dict()
    km = dict()
    zero = [0,0]
    zerozero = 0
    for i in range(N):
        A,B = map(int,input().split())
 
        if A == 0 and B == 0:
            zerozero+=1
            continue
 
        if A == 0:
            zero[0]+=1
            continue
        if B == 0:
            zero[1]+=1
            continue
 
        if A <0:
            A *= -1
            B *= -1
        xx = heikatu(A,B)
 
 
 
        if B < 0:
            if not xx in km:
                km[xx]=0
            km[xx]+=1
        else:
            if not xx in kp:
                kp[xx]=0
            kp[xx]+=1
 
    tx = dict()
    if zero != [0,0]:
        zero.sort()
        tx[tuple(zero)] = 1
 
    for key in kp:
        A,B = key
        cou = kp[key]    
        if (B,-A) in km:
            tmp = (cou,km[(B,-A)])
            km.pop((B,-A))
        else:
            tmp = ((cou,0))
        
        tmp = tuple(sorted(tmp))
        if not tmp in tx:
            tx[tmp] = 0
        tx[tmp]+=1
 
    for key in km:
        if not (km[key],0) in tx:
            tx[(km[key],0)]=0    
        tx[(km[key],0)]+=1
 
    ans = 1
    mod = 1000000007
 
    for a,b in tx:
        xxx = 0
        if a != 0:
            xxx=(xxx+pow_r(2,a)) %mod
        if b != 0:
            xxx=(xxx+pow_r(2,b)) %mod
        if a !=0 and b!=0:
            xxx-=1
        xxx = pow_r(xxx,tx[(a,b)]) 
        ans = (ans*xxx) % mod
 
 
    ans = (ans+mod-1) % mod 
 
    print(ans)       

resolve()

Submission status: Wrong Answer

Solution code:
from collections import Counter

def gcd(a, b):
    while b: a, b = b, a % b
    return abs(a)

MOD = 1000000007

def main():
    N = int(input())
    d = {}
    d[(1,0)] = (0,0)
    z = 0
    for i in range(N):
      a,b = (int(x) for x in input().split())
      g = gcd(a,b)
      if g != 0:
        a = a//g
        b = b//g
        if a*b<0: a = -abs(a)
        elif a*b>0: a = abs(a)
      b = abs(b)
      
      if a*b==0:
        if a==0 and b==0 :z+=1
        elif b==0: d[(1,0)] = (d[(1,0)][0]+1,d[(1,0)][1])
        elif a==0: d[(1,0)] = (d[(1,0)][0],  d[(1,0)][1]+1)
      else:
        if (a,b) in d: d[(a,b)] = (d[(a,b)][0]+1,d[(a,b)][1])
        elif (b, -a) in d: d[(b,-a)] = (d[(b,-a)][0], d[(b,-a)][1]+1)
        elif (-b, a) in d: d[(-b,a)] = (d[(-b,a)][0], d[(-b,a)][1]+1)
        else: d[(a,b)] = (1,0)
    
    ans = 1
    for i, j in d.values():
      ans *= (pow(2,i,MOD) + pow(2,j,MOD) - 1)
      ans %= MOD

    print(ans-1+z)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

def gcd(a, b):
    while b: a, b = b, a % b
    return abs(a)

MOD = 1000000007

def main():
    N = int(input())
    d = {}
    d[(1,0)] = (0,0)
    z = 0
    for i in range(N):
      a,b = (int(x) for x in input().split())
      g = gcd(a,b)
      if g != 0:
        a = a//g
        b = b//g
        if a*b<0: a = -abs(a)
        elif a*b>0: a = abs(a)
      b = abs(b)
      
      if a*b==0:
        if a==b==0:z+=1
        elif b==0: d[(1,0)] = (d[(1,0)][0]+1,d[(1,0)][1])
        elif a==0: d[(1,0)] = (d[(1,0)][0],  d[(1,0)][1]+1)
      else:
        if (a,b) in d: d[(a,b)] = (d[(a,b)][0]+1,d[(a,b)][1])
        elif (b, -a) in d: d[(b,-a)] = (d[(b,-a)][0], d[(b,-a)][1]+1)
        elif (-b, a) in d: d[(-b,a)] = (d[(-b,a)][0], d[(-b,a)][1]+1)
        else: d[(a,b)] = (1,0)
    
    ans = 1
    for i, j in d.values():
      ans *= (pow(2,i,MOD) + pow(2,j,MOD) - 1)
      ans %= MOD

    print(ans-1+z)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin
from math import gcd
from numba import njit

@njit
def f(v):
    return pow(2,v[0])+pow(2,v[1])-1

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()
    d[(1,0)]=[0,0]
    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

            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*=f(v)
        ans%=mod
    ans-=1
    ans+=zeros
    ans%=mod
    print(ans)
    
if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input()) 
Group = {}
zero = 0
import math
for _ in range(N): 
    a,b = list(map(int,input().split())) 
    if a*a + b*b == 0:
        zero += 1
        continue

    if b < 0: 
        a = -1*a 
        b = -1*b 
    elif (b == 0)*(a < 0):
        a = -1*a 
        
    if (a <= 0)*(b > 0): 
        ratio = -a/b
        if ratio in Group:
            Group[ratio][0] += 1
        else:
            Group[ratio] = [1,0]
    else: 
        ratio = b/a
        if ratio in Group:
            Group[ratio][1] += 1
        else:
            Group[ratio] = [0,1]
            
ans = 1
for i in Group:
    n,p = Group[i]
    now = 1
    tmp = 1
    for j in range(n):
        tmp *= 2
        if tmp > 1000000007:
            tmp = tmp%1000000007
    
    now = (now +tmp - 1)%1000000007
    tmp = 1
    for j in range(p):
        tmp *= 2
        if tmp > 1000000007:
            tmp = tmp%1000000007
    now = (now +tmp - 1)%1000000007
    ans = ans*now%1000000007
ans += zero -1
print(int(ans))

Submission status: Wrong Answer

Solution code:
N = int(input()) 
Group = {}
zero = 0
import math
for _ in range(N): 
    a,b = list(map(int,input().split())) 
    if a*a + b*b == 0:
        zero += 1
        continue

    if b < 0: 
        a = -1*a 
        b = -1*b 
    elif (b == 0)*(a < 0):
        a = -1*a 
        
    if (a <= 0)*(b > 0): 
        ratio = -a/b
        if ratio in Group:
            Group[ratio][0] += 1
        else:
            Group[ratio] = [1,0]
    else: 
        ratio = b/a
        if ratio in Group:
            Group[ratio][1] += 1
        else:
            Group[ratio] = [0,1]
            
ans = 1
for i in Group:
    n,p = Group[i]
    now = 1
    tmp = 1
    for j in range(n):
        tmp *= 2
        if tmp > 1000000007:
            tmp = tmp%1000000007
    
    now += tmp - 1
    tmp = 1
    for j in range(p):
        tmp *= 2
        if tmp > 1000000007:
            tmp = tmp%1000000007
    now += tmp - 1
    ans *= now
    if ans > 1000000007:
        ans = ans % 1000000007
ans += zero -1
print(int(ans))

Submission status: Wrong Answer

Solution code:
N = int(input()) 
Group = {}
zero = 0
import math
for _ in range(N): 
    a,b = list(map(int,input().split())) 
    if a*a + b*b == 0:
        zero += 1
        continue
    g = math.gcd(a,b)
    a //= g
    b //= g
    if b < 0: 
        a = -1*a 
        b = -1*b 
    elif (b == 0)*(a < 0):
        a = -1*a 
        
    if (a <= 0)*(b > 0): 
        ratio = -a/b
        if ratio in Group:
            Group[ratio][0] += 1
        else:
            Group[ratio] = [1,0]
    else: 
        ratio = b/a
        if ratio in Group:
            Group[ratio][1] += 1
        else:
            Group[ratio] = [0,1]
            
ans = 1
for i in Group:
    n,p = Group[i]
    now = 1
    tmp = 1
    for j in range(n):
        tmp *= 2
        if tmp > 1000000007:
            tmp = tmp%1000000007
    
    now += tmp - 1
    tmp = 1
    for j in range(p):
        tmp *= 2
        if tmp > 1000000007:
            tmp = tmp%1000000007
    now += tmp - 1
    ans *= now
    if ans > 1000000007:
        ans = ans % 1000000007
ans += zero -1
print(int(ans))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
mod_num = 1000000007

vList = []
cList = []
num_zero = 0
num_b_zero = 0
num_free = 0


for i in range(n):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        num_zero += 1
    else:
        g = math.gcd(a, b)
        a, b = a/g, b/g
        if b == 0:
            num_b_zero += 1
        else:
            K_value = a/b
            # already exist
            if vList.count(K_value):
                index = vList.index(K_value)
                cList[index] += 1
            # new value
            else:
                vList.append(K_value)
                cList.append(1)
# print(vList)
# print(cList)
counter = 0
para = 0
oList = []
# (0,0)
counter += num_zero % mod_num
# (a,0) and (0,b)
# both
if vList.count(0) and num_b_zero:
    # print("both half zero")
    index = vList.index(0)
    # print('(0,b) has ', cList[index])
    para += (2**cList[index] + 2**num_b_zero) % mod_num - 1
    oList.append(para)
# free (a,0) or (0,b)
elif num_b_zero:
    # print("(0,b)")
    num_free += num_b_zero
elif vList.count(0):
    # print("(a,0))")
    index = vList.index(0)
    num_free += cList[index]

# normal
solved = []
for value, count in zip(vList, cList):
    if (value not in solved) and value:
        upside = -1/value
        # anti exist
        if vList.count(upside):
            solved.append(upside)
            index = vList.index(upside)
            # print(value, 'has anti ', upside, 'number', count, '-', cList[index])
            para = 2**count + 2**cList[index]-1
            oList.append(para)
        # free value
        else:
            num_free += count
            # print(value, 'is free,now has free fish :', num_free)
if num_free:
    oList.append(2**num_free)
# print('count:')
# print('olist:', oList)
result = 1
for i in oList:
    result *= i
result += counter
result -= 1
print(result % mod_num)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
mod_num = 1000000007

vList = []
cList = []
num_zero = 0
num_b_zero = 0
num_free = 0


for i in range(n):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        num_zero += 1
    else:
        g = math.gcd(a, b)
        a, b = a/g, b/g
        if b == 0:
            num_b_zero += 1
        else:
            K_value = a/b
            # already exist
            if vList.count(K_value):
                index = vList.index(K_value)
                cList[index] += 1
            # new value
            else:
                vList.append(K_value)
                cList.append(1)
print(vList)
print(cList)
counter = 0
para = 0
oList = []
# (0,0)
counter += num_zero % mod_num
# (a,0) and (0,b)
# both
if vList.count(0) and num_b_zero:
    print("both half zero")
    index = vList.index(0)
    # print('(0,b) has ', cList[index])
    para += (2**cList[index] + 2**num_b_zero) % mod_num - 1
    oList.append(para)
# free (a,0) or (0,b)
elif num_b_zero:
    print("(0,b)")
    num_free += num_b_zero
elif vList.count(0):
    print("(a,0))")
    index = vList.index(0)
    num_free += cList[index]

# normal
solved = []
for value, count in zip(vList, cList):
    if (value not in solved) and value:
        upside = -1/value
        # anti exist
        if vList.count(upside):
            solved.append(upside)
            index = vList.index(upside)
            print(value, 'has anti ', upside, 'number', count, '-', cList[index])
            para = 2**count + 2**cList[index]-1
            oList.append(para)
        # free value
        else:
            num_free += count
            print(value, 'is free,now has free fish :', num_free)
if num_free:
    oList.append(2**num_free)
# print('count:')
print('olist:', oList)
result = 1
for i in oList:
    result *= i
result += counter
result -= 1
print(result % mod_num)

Submission status: Wrong Answer

Solution code:
import sys
from decimal import *
#read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def read():
  return int(readline())
def reads():
  return map(str, input().split())
n=read()
mod=1000000007
dic={}
multi=1
for i in range(n):
  a,b=reads()
  a=Decimal(a)
  b=Decimal(b)
  try :
    sum=a/b
    comp=-b/a
  except:sum=comp=0
  if sum>0:
      try:
        dic[(sum,comp)][0]+=1
      except:
        try:
            dic[(comp,sum)][0]+=1
        except:
            dic[(sum,comp)]=[1,0]
  elif sum<0:
      try:
        dic[(sum,comp)][1]+=1
      except:
        try:
            dic[(comp,sum)][1]+=1
        except:
            dic[(sum,comp)]=[0,1]
  else:
      multi=2
ans=1
#print(dic)
for ls in dic:
    p=2**dic[ls][0]-1
    q=2**dic[ls][1]-1
    ans*=p+q+1
    ans%=mod

print((ans*multi-1)%mod)

Submission status: Wrong Answer

Solution code:
import sys
from functools import lru_cache
from decimal import *
#read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
inf = float('inf')
def read():
  return int(readline())
def reads():
  return map(int, readline().split())
n=int(input())
mod=1000000007
dic={}
multi=1
for i in range(n):
  a,b=map(str,input().split())
  a=Decimal(a)
  b=Decimal(b)
  try :
    sum=a/b
    comp=-b/a
  except:sum=comp=0
  if sum>0:
      try:
        dic[(sum,comp)][0]+=1
      except:
        try:
            dic[(comp,sum)][0]+=1
        except:
            dic[(sum,comp)]=[1,0]
  elif sum<0:
      try:
        dic[(sum,comp)][1]+=1
      except:
        try:
            dic[(comp,sum)][1]+=1
        except:
            dic[(sum,comp)]=[0,1]
  else:
      multi=2
ans=1
#print(dic)
for ls in dic:
    p=2**dic[ls][0]-1
    q=2**dic[ls][1]-1
    ans*=p+q+1
    ans%=mod

print((ans*multi-1)%mod)

Submission status: Wrong Answer

Solution code:
import sys
from functools import lru_cache
from decimal import *
#read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
inf = float('inf')
def read():
  return int(readline())
def reads():
  return map(int, readline().split())
n=int(input())
mod=1000000007
dic={}
multi=1
for i in range(n):
  a,b=map(str,input().split())
  a=Decimal(a)
  b=Decimal(b)
  try :
    sum=a/b
    comp=-b/a
  except:sum=comp=0
  if sum>0:
      try:
        dic[(sum,comp)][0]+=1
      except:
         try:
            dic[(comp,sum)][0]+=1
         except:
            dic[(sum,comp)]=[1,0]
  elif sum<0:
      try:
        dic[(sum,comp)][1]+=1
      except:
        try:
            dic[(comp,sum)][1]+=1
        except:
            dic[(sum,comp)]=[0,1]
  else:
      multi=2
ans=1
print(dic)
for ls in dic:
    p=2**dic[ls][0]-1
    q=2**dic[ls][1]-1
    ans*=p+q+1
    ans%=mod

print((ans*multi-1)%mod)

Submission status: Wrong Answer

Solution code:
import sys
from functools import lru_cache
 
#read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
inf = float('inf')
def read():
  return int(readline())
def reads():
  return map(int, readline().split())
n=read()
a,b=[0]*n,[0]*n
sum=[0.0]*n
mod=1000000007
dic={}
multi=1
combo=[]
for i in range(n):
  a[i],b[i]=reads()
  try :
    sum=a[i]/b[i]
    comp=-b[i]/a[i]
  except:sum=comp=0
  if sum>0:
      try:
        dic[(sum,comp)][0]+=1
      except:
         try:
            dic[(comp,sum)][0]+=1
         except:
            dic[(sum,comp)]=[1,0]
  elif sum<0:
      try:
        dic[(sum,comp)][1]+=1
      except:
        try:
            dic[(comp,sum)][1]+=1
        except:
            dic[(sum,comp)]=[0,1]
  else:
      multi=2
check=[]
ans=1
dp=[0]*n
for ls in dic:
    p=2**dic[ls][0]-1
    q=2**dic[ls][1]-1
    ans*=p+q+1
    ans%=mod

print((ans*multi-1)%mod)

Submission status: Wrong Answer

Solution code:
from math import gcd

MOD = 1000000007

def inv(a, b):
    if a < 0:
        a, b = -a, -b
    return (-b, a)

def solve(n, a, b):
    zero = 0
    D = {}
    for i in range(n):
        p, q = a[i], b[i]
        if (p == 0) and (q == 0):
            zero += 1
        else:
            if p == 0:
                r = abs(q)
            elif q == 0:
                r = abs(p)
            else:
                r = gcd(p, q)
            p, q = (p // r, q // r)
            if q < 0:
                p, q = -p, -q
            k = (p, q)
            if not k in D:
                D[k] = 0
            D[k] += 1
    group = set()
    for (p, q), v in D.items():
        if not inv(p,q) in group:
            group.add((p,q))
    pow2 = [0] * (n+1)
    pow2[0] = 1
    for i in range(n):
        pow2[i+1] = (pow2[i] * 2) % MOD
    ans = 1
    for p, q in group:
        t = pow2[D[p,q]]
        if inv(p, q) in D:
            t += pow2[D[inv(p, q)]] - 1
        ans = (ans * t) % MOD
    return (ans + zero - 1) % MOD

n = int(input())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
print(solve(n, a, b))

Submission status: Wrong Answer

Solution code:
from math import gcd

MOD = 1000000007

def solve(n, a, b):
    zero = 0
    D = {}
    for i in range(n):
        p, q = a[i], b[i]
        if (p == 0) and (q == 0):
            zero += 1
        else:
            if p < 0 and q < 0:
                p, q = -p, -q
            if p == 0:
                r = abs(q)
            elif q == 0:
                r = abs(p)
            else:
                r = gcd(p, q)
            k = (p // r, q // r)
            if not k in D:
                D[k] = 0
            D[k] += 1
    group = {}
    for (p, q), v in D.items():
        if (q, -p) in group:
            group[q, -p] += v
        elif (-q, p) in group:
            group[-q, p] += v
        else:
            group[p, q] = v
    pow2 = [0] * (n+1)
    pow2[0] = 1
    for i in range(n):
        pow2[i+1] = (pow2[i] * 2) % MOD
    ans = 1
    for (p, q), v in group.items():
        t = pow2[D[p,q]]
        hit = False
        if (q, -p) in D:
            hit = True
            t += pow2[D[q, -p]]
        if (-q, p) in D:
            hit = True
            t += pow2[D[-q, p]]
        ans = (ans * (t-hit)) % MOD
    return (ans + zero - 1) % MOD

n = int(input())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
print(solve(n, a, b))

Submission status: Wrong Answer

Solution code:
from math import gcd

MOD = 1000000007

def solve(n, a, b):
    zero = 0
    D = {}
    for i in range(n):
        p, q = a[i], b[i]
        if (p == 0) and (q == 0):
            zero += 1
        else:
            if p == 0:
                r = abs(q)
            elif q == 0:
                r = abs(p)
            else:
                r = gcd(p, q)
            k = (p // r, q // r)
            if not k in D:
                D[k] = 0
            D[k] += 1
    group = {}
    for (p, q), v in D.items():
        if (q, -p) in group:
            group[q, -p] += v
        elif (-q, p) in group:
            group[-q, p] += v
        else:
            group[p, q] = v
    pow2 = [0] * (n+1)
    pow2[0] = 1
    for i in range(n):
        pow2[i+1] = (pow2[i] * 2) % MOD
    ans = 1
    for (p, q), v in group.items():
        t = pow2[D[p,q]]
        hit = False
        if (q, -p) in D:
            hit = True
            t += pow2[D[q, -p]]
        if (-q, p) in D:
            hit = True
            t += pow2[D[-q, p]]
        ans = (ans * (t-hit)) % MOD
    return (ans + zero - 1) % MOD

n = int(input())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
print(solve(n, a, b))

Submission status: Wrong Answer

Solution code:
from math import gcd

MOD = 1000000007

def solve(n, a, b):
    zero = 0
    D = {}
    for i in range(n):
        p, q = a[i], b[i]
        if (p == 0) and (q == 0):
            zero += 1
        else:
            if p == 0:
                r = abs(q)
            elif q == 0:
                r = abs(p)
            else:
                r = gcd(p, q)
            k = (p // r, q // r)
            if not k in D:
                D[k] = 0
            D[k] += 1
    group = {}
    for (p, q), v in D.items():
        if (q, -p) in group:
            group[q, -p] += v
        elif (-q, p) in group:
            group[-q, p] += v
        else:
            group[p, q] = v
    pow2 = [0] * (n+1)
    pow2[0] = 1
    for i in range(n):
        pow2[i+1] = (pow2[i] * 2) % MOD
    ans = 1
    for (p, q), v in group.items():
        t = pow2[D[p,q]]
        if (q, -p) in D:
            t += pow2[D[q,-p]] - 1
        elif (-q, p) in D:
            t += pow2[D[-q, p]] - 1
        ans = (ans * t) % MOD
    return (ans + zero - 1) % MOD

n = int(input())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
print(solve(n, a, b))

Submission status: Wrong Answer

Solution code:
MOD = 1000000007
def gcd(a, b):
    if a < b:
        b, a = a, b
    return b if a % b == 0 else gcd(b, a % b)

def solve(n, a, b):
    zero = 0
    D = {}
    for i in range(n):
        p, q = a[i], b[i]
        if (p == 0) and (q == 0):
            zero += 1
        else:
            if p == 0:
                r = abs(q)
            elif q == 0:
                r = abs(p)
            else:
                r = gcd(abs(p), abs(q))
            k = tuple((p // r, q // r))
            if not k in D:
                D[k] = 0
            D[k] += 1
    group = {}
    for (p, q), v in D.items():
        if (q, -p) in group:
            group[q, -p] += v
        elif (-q, p) in group:
            group[-q, p] += v
        else:
            group[p, q] = v
    pow2 = [0] * (n+1)
    pow2[0] = 1
    for i in range(n):
        pow2[i+1] = (pow2[i] * 2) % MOD
    ans = 1
    for (p, q), v in group.items():
        t = pow2[D[p,q]]
        if (q, -p) in D:
            t += pow2[D[q,-p]] - 1
        elif (-q, p) in D:
            t += pow2[D[-q, p]] - 1
        ans = (ans * t) % MOD
    return ans + zero - 1

n = int(input())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
print(solve(n, a, b))

Submission status: Wrong Answer

Solution code:
import sys
from collections import namedtuple, defaultdict
from math import gcd
input = sys.stdin.readline

class Point:
    def __init__(self, x, y):
        g = gcd(abs(x), abs(y))

        x //= g
        y //= g

        if x < 0:
            x *= -1
            y *= -1

        self.x = x
        self.y = y

    def __eq__(self, other):
        return self.x == other.x and self.y == other.y

    def __hash__(self):
        return hash((self.x, self.y))

    def __repr__(self):
        return f'({self.x}, {self.y})'

def main():
    n = int(input())
    
    p = []
    d = defaultdict(lambda: 0)
    zeros = 0

    for _ in range(n):
        x, y = map(int, input().split())

        if x == 0 and y == 0:
            n -= 1
            zeros += 1
            continue

        p.append(Point(x, y))
        d[p[-1]] += 1

    MOD = 10 ** 9 + 7

    pw = [ pow(2, i, MOD) for i in range(n + 1) ]

    ans = 1
    tot = 0

    for x in d.keys():
        if x.x > 0 and x.y >= 0 and x in d and Point(-x.y, x.x) in d:
            s = d[x]
            t = d[Point(-x.y, x.x)]

            tot += s + t
            value = (pw[s] + pw[t] - 1 + MOD) % MOD
            ans = ans * value % MOD

    ans = ans * pw[n - tot] % MOD
    ans = (ans - 1 + MOD + zeros) % MOD

    print(ans)
main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import namedtuple, defaultdict
from math import gcd
input = sys.stdin.readline

class Point:
    def __init__(self, x, y):
        g = gcd(abs(x), abs(y))

        x //= g
        y //= g

        if x < 0:
            x *= -1
            y *= -1

        self.x = x
        self.y = y

    def __eq__(self, other):
        return self.x == other.x and self.y == other.y

    def __hash__(self):
        return hash((self.x, self.y))

    def __repr__(self):
        return f'({self.x}, {self.y})'

def main():
    n = int(input())
    
    p = []
    d = defaultdict(lambda: 0)

    for _ in range(n):
        x, y = map(int, input().split())

        if x == 0 and y == 0:
            n -= 1
            continue

        p.append(Point(x, y))
        d[p[-1]] += 1

    # print(d)

    MOD = 10 ** 9 + 7

    pw = [ pow(2, i, MOD) for i in range(n + 1) ]

    ans = 1
    tot = 0

    # pair = 0
    # for x in range(n):
    #     for y in range(x + 1, n):
    #         if p[x].x * p[y].x + p[x].y * p[y].y == 0:
    #             pair += 1

    # print(f'pairs = {pair}')

    for x in d.keys():
        if x.x > 0 and x.y >= 0 and x in d and Point(-x.y, x.x) in d:
            s = d[x]
            t = d[Point(-x.y, x.x)]

            # print(s, t)

            tot += s + t
            value = (pw[s] + pw[t] - 1 + MOD) % MOD
            ans = ans * value % MOD

    # print(f'tot={tot}, n={n}')

    ans = ans * pw[n - tot] % MOD
    ans = (ans - 1 + MOD) % MOD

    print(ans)
main()

Submission status: Wrong Answer

Solution code:
n = int(input())
ab=[list(map(int,input().split())) for i in range(n)]
import math
from collections import defaultdict
d = defaultdict(int)
zerozero=0
azero=0
bzero=0
for tmp in ab:
    a,b=tmp

    if a==0 and b==0:
        zerozero+=1
        continue
    if a==0:
        azero+=1
        continue
    if b==0:
        bzero+=1
        continue

    absa=abs(a)
    absb=abs(b)
    gcd = math.gcd(absa,absb)

    absa//=gcd
    absb//=gcd

    if a*b >0:
        d[(absa,absb)]+=1
    else:
        d[(absa,-absb)]+=1

found = defaultdict(int)


ans=1
mod=1000000007
for k in list(d.keys()):
    num = d[k]
    a,b=k

    if b>0:
        bad_ab = (b,-a)
    else:
        bad_ab = (-b,a)

    if found[k]!=0:
        continue
    found[bad_ab] = 1

    bm=d[bad_ab]

    if bm == 0:
        mul = pow(2,num,mod)
    if k==bad_ab:
        mul = num+1
    else:
        mul = pow(2,num,mod) + pow(2,bm,mod) -1
    ans*=mul

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

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True

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


def main():
    N = I()
    zero = 0
    plus_Ai_Bi = defaultdict(int)
    minus_Bj_Aj = defaultdict(int)
    zero_cnt = 0
    used = set()

    for i in range(N):
        a, b = MI()

        if a == 0 and b == 0:
            zero_cnt += 1
            continue

        gcdab = gcd(abs(a), abs(b))
        a = a // gcdab
        b = b // gcdab

        if a > 0 and b > 0:
            # pos
            plus_Ai_Bi[(a, b)] += 1
            # neg
            minus_Bj_Aj[(-b, a)] += 1
        elif a > 0 and b < 0:
            # neg
            plus_Ai_Bi[(-a, -b)] += 1
            # pos
            minus_Bj_Aj[(-b, a)] += 1
        elif a < 0 and b > 0:
            # neg
            plus_Ai_Bi[(a, b)] += 1
            # pos
            minus_Bj_Aj[(b, -a)] += 1
        else:
            # pos
            plus_Ai_Bi[(-a, -b)] += 1
            # neg
            minus_Bj_Aj[(b, -a)] += 1

    # print(plus_Ai_Bi)
    # print(minus_Bj_Aj)
    ans = 1

    for pair, cnt1 in plus_Ai_Bi.items():
        a, b = pair
        if pair in used:
            continue

        if pair in minus_Bj_Aj:
            cnt2 = minus_Bj_Aj[pair]
            group1 = pow(2, cnt1, MOD) - 1
            group2 = pow(2, cnt2, MOD) - 1
            ans *= group1 + group2 + 1
            ans %= MOD

            if a > 0 and b > 0:
                # minus_Bj_Aj[(-b, a)] += 1
                used.add((-b, a))
            elif a > 0 and b < 0:
                # minus_Bj_Aj[(-b, a)] += 1
                used.add((-b, a))
            elif a < 0 and b > 0:
                # minus_Bj_Aj[(b, -a)] += 1
                used.add((b, -a))
            else:
                # minus_Bj_Aj[(b, -a)] += 1
                used.add((b, -a))
        else:
            ans *= pow(2, cnt1, MOD)
            ans %= MOD

    print((ans - 1 + zero_cnt) % MOD)


if __name__ == '__main__':
    main()