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: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;
using ll=long long int;
ll mod=1e9+7;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int main()
{
    
    vector<ll> powe(1e6,0);
    powe[0]=1;
    for(int i=1;i<1e6;i++)
    {
        powe[i]=(powe[i-1]*2)%mod;
    }
    int n;
    cin>>n;
    vector<pair<ll,ll> > a(n);
    map<pair<ll,ll>,int> m;
    cout<<gcd(0,0)<<endl;
    int ct1=0;
    int ct2=0;
    int ct3=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i].first>>a[i].second;
        if(a[i].first==0&&a[i].second==0)
        {
            ct1++;
            continue;
        }
        else if(a[i].first==0||a[i].second==0)
        {
            ct2++;
            continue;
        }
        ll p=gcd(a[i].first,a[i].second);
        a[i].first/=p;
        a[i].second/=p;
         if(a[i].first>0&&a[i].second<0)
        {
            a[i].first=-a[i].first;
            a[i].second=-a[i].second;
        }
        if(a[i].second<0&&a[i].first<0)
        {
            a[i].second=-a[i].second;
            a[i].first=-a[i].first;
        }
        m[a[i]]++;
    }
    ll ans=1;
    for(auto it:m)
    {
        if(it.first.first<0)
        {
            if(m.find({it.first.second,-it.first.first})==m.end())
            ans=(ans*(it.second+1))%mod;
            continue;
        }
        ll p=it.second;
        ll q=0;
        if(m.find({-it.first.second,it.first.first})!=m.end());
        {
            q=m[{-it.first.second,it.first.first}];
        }
       
        ll res=(powe[p]-1+powe[q]-1+mod)%mod;
        ans=(ans*(res+1))%mod;
    }
    ans=(ans*(ct2+1))%mod;
    if(ct1>0)
    ans++;
    cout<<(ans-1+mod)%mod;
    
}

Submission status: Runtime Error

Solution code:
N=int(input())
mod=10**9+7
Azero=0
Bzero=0
both=0
plus={}
minus={}
import math
for i in range(N):
  A,B=map(int,input().split())
  if A==0 and B==0:
    both+=1
  elif A==0 and B!=0:
    Azero+=1
  elif A!=0 and B==0:
    Bzero+=1
  else:
    K=math.gcd(A,B)
    A=int(A/K)
    B=int(B/K)
    if A/B>0:
      if A<0:
        A,B=-A,-B
      if (A,B) in plus:
        plus[(A,B)]+=1
      else:
        plus[(A,B)]=1
    else:
      if A<0:
        A,B=-A,-B
      if (A,B) in minus:
        minus[(a,b)]+=1
      else:
        minus[(A,B)]=1

L=[]
if Azero>0 and Bzero>0:
  L.append((Azero,Bzero))
for k,v in plus.items():
  if (k[1],-k[0]) in minus:
    L.append((v,minus[(k[1],-k[0])]))
ans=0
for i in range(len(L)):
  N-=L[i][0]+L[i][1]
N-=both
c=1

for i in range(len(L)):
  c*=(pow(2,L[i][0],mod)+pow(2,L[i][1],mod)-1)
  c%=mod

ans=(c*pow(2,N,mod)-1)%mod
print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd
import math
import numpy as np
import decimal
import collections
import itertools
import sys
import random
#Union-Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.par = [-1 for i in range(self.n)]
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def unite(self, x, y):
        p = self.find(x)
        q = self.find(y)
        if p == q:
            return None
        if p > q:
            p, q = q, p
        self.par[p] += self.par[q]
        self.par[q] = p
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def size(self, x):
        return -self.par[self.find(x)]

#素数関連
def prime_numbers(x):
    if x < 2:
        return []
    prime_numbers = [i for i in range(x)]
    prime_numbers[1] = 0
    for prime_number in prime_numbers:
        if prime_number > math.sqrt(x):
            break
        if prime_number == 0:
            continue
        for composite_number in range(2 * prime_number, x, prime_number):
            prime_numbers[composite_number] = 0
    return [prime_number for prime_number in prime_numbers if prime_number != 0]
def is_prime(x):
    if x < 2:
        return False
    if x == 2 or x == 3 or x == 5:
        return True
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0:
        return False
    prime_number = 7
    difference = 4
    while prime_number <= math.sqrt(x):
        if x % prime_number == 0:
            return False
        prime_number += difference
        difference = 6 - difference
    return True
#Prime-Factorize
def prime_factorize(n):
    res = []
    while n % 2 == 0:
        res.append(2)
        n //= 2
    f = 3
    while f ** 2 <= n:
        if n % f == 0:
            res.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        res.append(n)
    return res
#nCr
mod = 10 ** 9 + 7
class nCr():
    def __init__(self, n):
        self.n = n
        self.fa = [1] * (self.n + 1)
        self.fi = [1] * (self.n + 1)
        for i in range(1, self.n + 1):
            self.fa[i] = self.fa[i - 1] * i % mod
            self.fi[i] = pow(self.fa[i], mod - 2, mod)
    def comb(self, n, r):
        if n < r:return 0
        if n < 0 or r < 0:return 0
        return self.fa[n] * self.fi[r] % mod * self.fi[n - r] % mod
#拡張Euclidの互除法
def extgcd(a, b, d = 0):
    g = a
    if b == 0:
        x, y = 1, 0
    else:
        x, y, g = extgcd(b, a % b)
        x, y = y, x - a // b * y
    return x, y, g
#BIT
class BinaryIndexedTree():
    def __init__(self, n):
        self.n = n
        self.BIT = [0] * (self.n + 1)
    def add(self, i, x):
        while i <= self.n:
            self.BIT[i] += x
            i += i & -i
    def query(self, i):
        res = 0
        while i > 0:
            res += self.BIT[i]
            i -= i & -i
        return res
#Associative Array
class AssociativeArray():
    def __init__(self, q):
        self.dic = dict()
        self.q = q
    def solve(self):
        for i in range(self.q):
            Query = list(map(int, input().split()))
            if Query[0] == 0:
                x, y, z = Query
                self.dic[y] = z
            else:
                x, y = Query
                if y in self.dic:
                    print(self.dic[y])
                else:
                    print(0)
#Floor Sum
def floor_sum(n, m, a, b):
    res = 0
    if a >= m:
        res += (n - 1) * n * (a // m) // 2
        a %= m
    if b >= m:
        res += n * (b // m)
        b %= m
    y_max = (a * n + b) // m
    x_max = y_max * m - b
    if y_max == 0:
        return res
    res += y_max * (n + (-x_max // a))
    res += floor_sum(y_max, a, m, (a - x_max % a) % a)
    return res
#Z-Algorithm
def z_algorithm(s):
    str_len = len(s)
    res = [0] * str_len
    res[str_len - 1] = str_len
    i, j = 1, 0
    while i < str_len:
        while i + j < str_len and s[i + j] == s[j]:
            j += 1
        res[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i + k < str_len and j > res[k] + k:
            res[i + k] = res[k]
            k += 1
        i += k
        j -= k
    return res
class Manacher():
    def __init__(self, s):
        self.s = s
    def coustruct(self):
        i, j = 0, 0 
        s_len = len(self.s)
        res = [0] * s_len
        while i < s_len:
            while i - j >= 0 and i + j < s_len and self.s[i - j] == self.s[i + j]:
                j += 1
            res[i] = j
            k = 1
            while i - k >= 0 and k + res[i - k] < j:
                k += 1
            i += k
            j -= k
#mod-sqrt
def mod_sqrt(a, p):
    if a == 0:
        return 0
    if p == 2:
        return 1
    k = (p - 1) // 2
    if pow(a, k, p) != 1:
        return -1
    while True:
        n = random.randint(2, p - 1)
        r = (n ** 2 - a) % p
        if r == 0:
            return n
        if pow(r, k, p) == p - 1:
            break
    k += 1
    w, x, y, z = n, 1, 1, 0
    while k:
        if k % 2:
            y, z = w * y + r * x * z, x * y + w * z
        w, x = w * w + r * x * x, 2 * w * x
        w %= p
        x %= p
        y %= p
        z %= p
        k >>= 1
    return y
mod = 10 ** 9 + 7
n = int(input())
zeros = 0
count = dict()
for i in range(n):
    a, b = map(int, input().split())
    if (a, b) == [0, 0]:
        zeros += 1
        continue
    g = gcd(abs(a), abs(b))
    a //= g
    b //= g
    cnt = 0
    while a < 0 or b <= 0:
        a, b = -1 * b, a
        cnt += 1
    if not (a, b) in count:
        count[(a, b)] = [0, 0]
    count[(a, b)][cnt % 2] += 1
ans = 1
for i in count:
    a, b = count[i]
    ans *= (pow(2, a, mod) + pow(2, b, mod) - 1) % mod
    ans %= mod
print((ans + zeros - 1) % mod)

Submission status: Runtime Error

Solution code:
from math import gcd
import math
import numpy as np
import decimal
import collections
import itertools
import sys
import random
#Union-Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.par = [-1 for i in range(self.n)]
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def unite(self, x, y):
        p = self.find(x)
        q = self.find(y)
        if p == q:
            return None
        if p > q:
            p, q = q, p
        self.par[p] += self.par[q]
        self.par[q] = p
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def size(self, x):
        return -self.par[self.find(x)]

#素数関連
def prime_numbers(x):
    if x < 2:
        return []
    prime_numbers = [i for i in range(x)]
    prime_numbers[1] = 0
    for prime_number in prime_numbers:
        if prime_number > math.sqrt(x):
            break
        if prime_number == 0:
            continue
        for composite_number in range(2 * prime_number, x, prime_number):
            prime_numbers[composite_number] = 0
    return [prime_number for prime_number in prime_numbers if prime_number != 0]
def is_prime(x):
    if x < 2:
        return False
    if x == 2 or x == 3 or x == 5:
        return True
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0:
        return False
    prime_number = 7
    difference = 4
    while prime_number <= math.sqrt(x):
        if x % prime_number == 0:
            return False
        prime_number += difference
        difference = 6 - difference
    return True
#Prime-Factorize
def prime_factorize(n):
    res = []
    while n % 2 == 0:
        res.append(2)
        n //= 2
    f = 3
    while f ** 2 <= n:
        if n % f == 0:
            res.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        res.append(n)
    return res
#nCr
mod = 10 ** 9 + 7
class nCr():
    def __init__(self, n):
        self.n = n
        self.fa = [1] * (self.n + 1)
        self.fi = [1] * (self.n + 1)
        for i in range(1, self.n + 1):
            self.fa[i] = self.fa[i - 1] * i % mod
            self.fi[i] = pow(self.fa[i], mod - 2, mod)
    def comb(self, n, r):
        if n < r:return 0
        if n < 0 or r < 0:return 0
        return self.fa[n] * self.fi[r] % mod * self.fi[n - r] % mod
#拡張Euclidの互除法
def extgcd(a, b, d = 0):
    g = a
    if b == 0:
        x, y = 1, 0
    else:
        x, y, g = extgcd(b, a % b)
        x, y = y, x - a // b * y
    return x, y, g
#BIT
class BinaryIndexedTree():
    def __init__(self, n):
        self.n = n
        self.BIT = [0] * (self.n + 1)
    def add(self, i, x):
        while i <= self.n:
            self.BIT[i] += x
            i += i & -i
    def query(self, i):
        res = 0
        while i > 0:
            res += self.BIT[i]
            i -= i & -i
        return res
#Associative Array
class AssociativeArray():
    def __init__(self, q):
        self.dic = dict()
        self.q = q
    def solve(self):
        for i in range(self.q):
            Query = list(map(int, input().split()))
            if Query[0] == 0:
                x, y, z = Query
                self.dic[y] = z
            else:
                x, y = Query
                if y in self.dic:
                    print(self.dic[y])
                else:
                    print(0)
#Floor Sum
def floor_sum(n, m, a, b):
    res = 0
    if a >= m:
        res += (n - 1) * n * (a // m) // 2
        a %= m
    if b >= m:
        res += n * (b // m)
        b %= m
    y_max = (a * n + b) // m
    x_max = y_max * m - b
    if y_max == 0:
        return res
    res += y_max * (n + (-x_max // a))
    res += floor_sum(y_max, a, m, (a - x_max % a) % a)
    return res
#Z-Algorithm
def z_algorithm(s):
    str_len = len(s)
    res = [0] * str_len
    res[str_len - 1] = str_len
    i, j = 1, 0
    while i < str_len:
        while i + j < str_len and s[i + j] == s[j]:
            j += 1
        res[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i + k < str_len and j > res[k] + k:
            res[i + k] = res[k]
            k += 1
        i += k
        j -= k
    return res
class Manacher():
    def __init__(self, s):
        self.s = s
    def coustruct(self):
        i, j = 0, 0 
        s_len = len(self.s)
        res = [0] * s_len
        while i < s_len:
            while i - j >= 0 and i + j < s_len and self.s[i - j] == self.s[i + j]:
                j += 1
            res[i] = j
            k = 1
            while i - k >= 0 and k + res[i - k] < j:
                k += 1
            i += k
            j -= k
#mod-sqrt
def mod_sqrt(a, p):
    if a == 0:
        return 0
    if p == 2:
        return 1
    k = (p - 1) // 2
    if pow(a, k, p) != 1:
        return -1
    while True:
        n = random.randint(2, p - 1)
        r = (n ** 2 - a) % p
        if r == 0:
            return n
        if pow(r, k, p) == p - 1:
            break
    k += 1
    w, x, y, z = n, 1, 1, 0
    while k:
        if k % 2:
            y, z = w * y + r * x * z, x * y + w * z
        w, x = w * w + r * x * x, 2 * w * x
        w %= p
        x %= p
        y %= p
        z %= p
        k >>= 1
    return y
mod = 10 ** 9 + 7
n = int(input())
zeros = 0
count = dict()
for i in range(n):
    a, b = map(int, input().split())
    if (a, b) == [0, 0]:
        zeros += 1
        continue
    g = gcd(abs(a), abs(b))
    a //= g
    b //= g
    cnt = 0
    while a < 0 or b <= 0:
        a, b = -1 * b, a
        cnt += 1
    if not (a, b) in count:
        count[(a, b)] = [0, 0]
    count[(a, b)][cnt % 2] += 1
ans = 1
for i in count:
    a, b = count[i]
    ans *= pow(2, a, mod) + pow(2, b, mod) - 1
print((ans + zeros - 1) % mod)

Submission status: Runtime Error

Solution code:
import math

N=int(input())


f=[]
for i in range(N):
    A, B =map(int,input().split())
    if A==0 and B==0:
        pass
    elif B==0:
        f.append([-1,0])
    elif B>0:
        f.append([int(A/math.gcd(A,B)),int(B/math.gcd(A,B))])
    else:
        f.append([int(-A/math.gcd(A,B)),int(-B/math.gcd(A,B))])

d=[]
ans=1
for i in range(N):
    same=1
    cros=0
    if f[i] != None:
        for j in range(i+1,N):
            if f[j]==None:
                pass
            elif f[i]==f[j]:
                same+=1
                f[j]=None
            elif f[i][0]==f[j][1] and f[i][1]==-f[j][0]:
                cros+=1
                f[j]=None
            elif f[i][0]==-f[j][1] and f[i][1]==f[j][0]:
                cros+=1
                f[j]=None            
        d.append([same,cros]) 

mod=1000000007
  
for i in range(len(d)):
    ans*=(2**d[i][0]+2**d[i][1]-1)

print((ans-1)%mod)

Submission status: Runtime Error

Solution code:
import math

N=int(input())

# xy = [map(int, input().split()) for _ in range(5)]
# A, B = [list(i) for i in zip(*xy)]

f=[]
for i in range(N):
    A, B =map(int,input().split())
    if A==0 and B==0:
        pass
    elif B==0:
        f.append([-1,0])
    elif B>0:
        f.append([int(A/math.gcd(A,B)),int(B/math.gcd(A,B))])
    else:
        f.append([int(-A/math.gcd(A,B)),int(-B/math.gcd(A,B))])

d=[]
ans=1
for i in range(N):
    same=1
    cros=0
    if f[i] != None:
        for j in range(i+1,N):
            if f[j]==None:
                pass
            elif f[i]==f[j]:
                same+=1
                f[j]=None
            elif f[i][0]==f[j][1] and f[i][1]==-f[j][0]:
                cros+=1
                f[j]=None
            elif f[i][0]==-f[j][1] and f[i][1]==f[j][0]:
                cros+=1
                f[j]=None            
        d.append([same,cros]) 
        if cros==0:
            ans*=(2**same)
        else:
            ans*=(2**same+2*cros)
            
        # d.append(same)
        # d.append(cros)
# ans=1
mod=1000000007
  
# for i in range(len(d)):
#     ans*=(2**d[i][0]+2**d[i][1])

print((ans-1)%mod)

Submission status: Runtime Error

Solution code:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
import sys
gcd = math.gcd
co = collections.Counter()
n = ni()
mod=10**9+7
for i in range(n):
    a,b = ma()
    d = gcd(a,b)
    a//=d
    b//=d
    co[(a,b)]+=1
d = collections.defaultdict(lambda:False)
ans=1
for t,cnt in co.items():
    a,b = t
    if t==(0,0) or d[t]:
        continue
    d[(a,b)]=True;d[(-a,-b)]=True;d[(b,-a)]=True;d[(-b,a)]=True
    l1 = co[(a,b)]+co[(-a,-b)]
    l2 = co[(b,-a)]+co[(-b,a)]
    ans=ans*(pow(2,l1,mod)+pow(2,l2,mod) -1)%mod
    ans%=mod
print((ans-1)%mod)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from math import gcd

mod = 10 ** 9 + 7

n = int(input())
ab = [tuple(map(int, input().split())) for _ in range(n)]

d = defaultdict(int)
for a, b in ab:
    # a[i]が絶対に非負になるように
    if a < 0:
        a *= -1
        b *= -1
    g = gcd(a, b)
    d[(a // g, b // g)] += 1

all = n
ans = 1
for k1, v in d.items():
    k2 = (k1[1], -k1[0])
    if k2 in d.keys():
        all -= v
        all -= d[k2]
        ans = ans * (pow(2, v, mod) + pow(2, d[k2], mod) - 1) % mod

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

Submission status: Runtime Error

Solution code:
MOD = 10 ** 9 + 7
from math import gcd
from collections import defaultdict

n = int(input())
plus = defaultdict(int)
minus = defaultdict(int)
zero = [0, 0, 0]
for _ in range(n):
    a, b = map(int, input().split())
    g = gcd(a, b)
    a //= g
    b //= g
    if a < 0:
        a *= -1
        b *= -1
    if a * b == 0:
        if a == b == 0:
            zero[0] += 1
        elif a == 0:
            zero[1] += 1
        else:
            zero[2] += 1
    elif b >= 0:
        s = str(a) + "-" + str(b)
        plus[s] += 1
    else:
        s = str(-b) + "-" + str(a)
        minus[s] += 1

pm = [[zero[1], zero[2]]]
cnt = sum(zero)
for key, value in plus.items():
    if minus[key] != 0:
        pm.append([value, minus[key]])
        cnt += value + minus[key]
        
ans = pow(2, n - cnt, MOD)

for p, m in pm:
    ans *= (pow(2, p, MOD) + pow(2, m, MOD) - 1)
    ans %= MOD
ans -= 1
ans %= MOD
print(ans)

Submission status: Runtime Error

Solution code:
from collections import defaultdict, deque
import math

kMod = 10**9 + 7

N = int(input())
key2count = defaultdict(lambda: [0, 0])

for _ in range(N):
    a, b = map(int, input().split())
    if abs(a * b) > 0:
        g = math.gcd(abs(a), abs(b))
    else:
        g = max(abs(a), abs(b))
    a, b = a//g, b//g
    if a < 0:
        a, b = -a, -b
    idx = 0
    if b < 0:
        idx = 1
        a, b = -b, a
    key2count[(a, b)][idx] += 1

ans = 1
for key, val in key2count.items():
    plus, minus = val
    ans *= (pow(2, plus, kMod) + pow(2, minus, kMod)-1)
    ans %= kMod

print((ans + kMod-1) % kMod)

Submission status: Runtime Error

Solution code:
from collections import defaultdict, deque
import math

kMod = 10**9 + 7

N = int(input())
key2count = defaultdict(lambda: [0, 0])

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

ans = 1
for key, val in key2count.items():
    plus, minus = val
    ans *= (pow(2, plus, kMod) + pow(2, minus, kMod)-1)
    ans %= kMod

print((ans + kMod-1) % kMod)

Submission status: Runtime Error

Solution code:
from collections import defaultdict, deque
import math

kMod = 10**9 + 7

N = int(input())
key2count = defaultdict(lambda: [0, 0])

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

print(key2count)
ans = 1
for key, val in key2count.items():
    plus, minus = val
    ans *= (pow(2, plus, kMod) + pow(2, minus, kMod)-1)
    ans %= kMod

print((ans + kMod-1) % kMod)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
from collections import defaultdict
d = defaultdict(list)
s = set()
for i in range(n):
    a,b = map(int, input().split())
    g = math.gcd(a,b)
    a //= g; b //= g
    if a<0:
        a,b = -a, -b
    d[a,b].append(i)
v = 1
s = set()
M = 10**9+7
for (a,b),val in d.items():
    aa,bb = b,-a
    if aa<0:
        aa,bb = -aa, -bb
    if (a,b) in s or (aa,bb) in s:
        continue
    if (aa,bb) in d.keys():
        v *= (pow(2, len(val), M) + pow(2, len(d[aa,bb]), M) - 1)
    else:
        v *= pow(2, len(val), M)
    v %= M
    s.add((a,b))
    s.add((aa,bb))
v -= 1
print(v%M)

Submission status: Runtime Error

Solution code:
N = int(input())
mod = 10 **9 + 7

def equal(item0, item1, delta = 10 ** (-24)):
    if abs(item0 - item1) < delta:
        return True
    else:
        return False
def bigger(item0, item1, delta = 10** (-24)):
    if item0 -item1 > delta:
        return True
    else:
        return False

ab = []
ba = []
zero = 0
from bisect import insort
from math import gcd
for _ in range(N):
    A, B = map(int, input().split())
    if A*B == 0:
        if A == 0 and B == 0:
            zero += 1
        elif A == 0 and B != 0:
            ab = [0] + ab
        else:
            ba = [0] + ba
    elif A*B > 0:
        d = gcd(A,B)
        insort(ab, (A//d)/(B//d))
    else:
        insort(ba, -(B//d)/(A//d))
print(ab,ba)
def make_count(list):
    k = 0
    lis = []
    while k < len(list):
        cnt = 1
        while k+1 < len(list):
            if list[k] == list[k+1]:
                cnt += 1
                k += 1
                continue
            else:
                break
        lis.append([list[k], cnt])
        k += 1
    return lis

ab = make_count(ab)
ba = make_count(ba)
from collections import deque
ab = deque(ab)
ba = deque(ba)
ans = 1 #all pattern
flag = True
pair = []
if len(ab) == 0:
    print(pow(2, N-zero, mod)+zero-1)
    exit()
if len(ba) == 0:
    print(pow(2, N-zero, mod)+ zero -1)
    exit()


while True:
    if flag:
        a = ab.popleft()
        b = ba.popleft()
    flag = False
    if a[0] == b[0]:
        pair.append([a[1], b[1]])
        if ab:
            a = ab.popleft()
        else:
            a = [-1, 0]
        if ba:
            b = ba.popleft()
        else:
            b = [-1, 0]
        if a[0] == b[0] == -1:
            break
    elif a[0] >b[0]:
        if ba:
            pair.append([0,b[1]])
            b = ba.popleft()
            continue
        elif ab:
            pair.append([a[1],0])
            a = ab.popleft()
            b = [-1, 0]
            continue
        else:
            if a[0] != -1:
                pair.append([a[1], 0])
            if b[0]!= -1:
                pair.append([0, b[1]])
            break
    else:
        if ab:
            pair.append([a[1], 0])
            a = ab.popleft()
            continue
        elif ba:
            pair.append([0, b[1]])
            b = ba.popleft()
            a = [-1, 0]
        else:
            if a[0] != -1:
                pair.append([a[1], 0])
            if b[0]!= -1:
                pair.append([0, b[1]])
            break
ans = 1
for item in pair:
    ans *= pow(2, item[0], mod) + pow(2, item[1], mod) -1
    ans %= mod
ans += zero-1
ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
mod = 10 **9 + 7

def equal(item0, item1, delta = 10 ** (-20)):
    if abs(item0 - item1) < delta:
        return True
    else:
        return False
def bigger(item0, item1, delta = 10** (-20)):
    if item0 -item1 > delta:
        return True
    else:
        return False
bit = [1]
for k in range(N):
    bit.append(bit[-1]*2%mod)


AB = []
BA = []
zero = 0
from bisect import insort
for _ in range(N):
    A, B = map(int, input().split())
    if A*B == 0:
        if A == 0 and B == 0:
            zero += 1
        elif A == 0 and B != 0:
            AB = [0] + AB
        else:
            BA = [0] + BA
    elif A*B > 0:
        insort(AB, A/B)
    else:
        insort(BA, -B/A)
def make_count(list):
    k = 0
    lis = []
    while k < len(list):
        cnt = 1
        while k+1 < len(list):
            if list[k]==list[k+1]:
                cnt += 1
                k += 1
                continue
            else:
                break
        lis.append([list[k], cnt])
        k += 1
    return lis

AB = make_count(AB)
BA = make_count(BA)
from collections import deque
AB = deque(AB)
BA = deque(BA)
ans = 1 #all pattern
flag = True
pair = []
if len(AB) == 0:
    print(bit[N-zero]+zero-1)
    exit()
if len(BA) == 0:
    print(bit[N-zero]+ zero -1)
    exit()


while True:
    if flag:
        a = AB.popleft()
        b = BA.popleft()
    flag = False
    if a[0]== b[0]:
        pair.append([a[1], b[1]])
        if AB:
            a = AB.popleft()
        if BA:
            b = BA.popleft()
    elif a[0]>b[0]:
        if BA:
          	pair.append([0,b[1]])
            b = BA.popleft()
            continue
        elif AB:
          	pair.append([a[1],0])
            a = AB.popleft()
            continue
        else:
            break
    else:
        if AB:
          	pair.append([a[1], 0])
            a = AB.popleft()
            continue
        elif BA:
          	pair.append([0, b[1]])
            b = BA.popleft()
        else:
            break
ans = 1
for item in pair:
    ans *= pow(2, item[0], mod) + pow(2, item[1], mod) -1
    ans %= mod
ans += zero-1
ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
mod = 10 **9 + 7

def equal(item0, item1, delta = 10 ** (-20)):
    if abs(item0 - item1) < delta:
        return True
    else:
        return False
def bigger(item0, item1, delta = 10** (-20)):
    if item0 -item1 > delta:
        return True
    else:
        return False
bit = [1]
for k in range(N):
    bit.append(bit[-1]*2%mod)


AB = []
BA = []
zero = 0
from bisect import insort
for _ in range(N):
    A, B = map(int, input().split())
    if A*B == 0:
        if A == 0 and B == 0:
            zero += 1
        elif A == 0 and B != 0:
            AB = [0] + AB
        else:
            BA = [0] + BA
    elif A*B > 0:
        insort(AB, A/B)
    else:
        insort(BA, -B/A)
def make_count(list):
    k = 0
    lis = []
    while k < len(list):
        cnt = 1
        while k+1 < len(list):
            if list[k]==list[k+1]:
                cnt += 1
                k += 1
                continue
            else:
                break
        lis.append([list[k], cnt])
        k += 1
    return lis

AB = make_count(AB)
BA = make_count(BA)
from collections import deque
AB = deque(AB)
BA = deque(BA)
ans = 1 #all pattern
flag = True
pair = []
if len(AB) == 0:
    print(bit[N-zero]+zero-1)
    exit()
if len(BA) == 0:
    print(bit[N-zero]+ zero -1)
    exit()


while True:
    if flag:
        a = AB.popleft()
        b = BA.popleft()
    flag = False
    if a[0]== b[0]:
        pair.append([a[1], b[1]])
        if AB:
            a = AB.popleft()
        if BA:
            b = BA.popleft()
    elif a[0]>b[0]:
        if BA:
          	pair.append([0,b[1]])
            b = BA.popleft()
            continue
        elif AB:
          	pair.append([a[1],0])
            a = AB.popleft()
            continue
        else:
            break
    else:
        if AB:
          	pair.append([a[1], 0])
            a = AB.popleft()
            continue
        elif BA:
          	pair.append([0, b[1])
            b = BA.popleft()
        else:
            break
ans = 1
for item in pair:
    ans *= pow(2, item[0], mod) + pow(2, item[1], mod) -1
    ans %= mod
ans += zero-1
ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd
from bisect import bisect_left, bisect_right

MOD = 10 ** 9 + 7
pow2 = [1] * (2 * 10 ** 5 + 1)
for i in range(1, 2 * 10 ** 5 + 1):
	pow2[i] = (pow2[i - 1] * 2) % MOD

N = int(input())

iwasies = []
for i in range(N):
	A, B = map(int, input().split())
	if A == 0 and B == 0:
		continue
	elif A == 0:
		iwasies.append((0, 1))
	elif B == 0:
		iwasies.append((1, 0))
	else:
		g = gcd(A, B)
		A //= g
		B //= g
		if A < 0:
			iwasies.append((-A, -B))
		else:
			iwasies.append((A, B))

iwasies.sort()
badpairs = set()
for i in range(N):
	A, B = iwasies[i]
	abcount = bisect_right(iwasies, (A, B)) - bisect_left(iwasies, (A, B))
	
	Ao, Bo = B, -A
	if Ao < 0:
		Ao, Bo = -Ao, -Bo
	
	aobocount = bisect_right(iwasies, (Ao, Bo)) - bisect_left(iwasies, (Ao, Bo))
	
	if aobocount > 0:
		if (A, B) < (Ao, Bo):
			badpairs.add(((A, B, abcount), (Ao, Bo, aobocount)))
		else:
			badpairs.add(((Ao, Bo, aobocount), (A, B, abcount)))

numiwasi = len(iwasies)
sociable = numiwasi
ans = 1

for bp in badpairs:
	count1 = bp[0][2]
	count2 = bp[1][2]
	sociable -= (count1 + count2)
	ans = (ans * (pow2[count1] + pow2[count2] - 1)) % MOD
ans = (ans * pow2[sociable]) % MOD

print(ans - 1)