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:
def modpow(a, n, p):
  if n == 0:
    return 1
  if n == 1:
    return a % p 
  elif n % 2 == 1:
    return a * modpow(a, n-1, p) % p
  else:
    return modpow(a, n//2, p) **2 % p
MOD = 1000000007
n = input()
dct1 = {}
dct2 = {}
l = []
for i in range(n):
  a, b = map(int, input().split())
  l.append((a, b))
  if a == 0:
    dct1["a0"] = dct1.get("a0", 0) + 1
  elif b == 0:
    dct1["b0"] = dct1.get("b0", 0) + 1
  else:
    dct1[a/b] = dct1.get(a/b, 0) + 1
    dct2[-b/a] = dct2.get(-b/a, 0) + 1

count = 0
for i in range(n):
  a, b = l[i]
    l.append((a, b))
  if a == 0:
    count += modpow(2, n-1-i-dct1["b0"], MOD)
  elif b == 0:
    count += modpow(2, n-1-i-dct1["a0"], MOD)
  else:
    count += modpow(2, n-1-i-dct2[a/b], MOD)
print(count % MOD)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
import bisect
N=int(input())
L = [list(map(int,input().split())) for _ in range(N)]

MOD=10**9+7

L_non_zero=[[a,b] for a,b in L if a*b!=0]
L_zero=[[a,b] for a,b in L if a*b==0]

L_zero=0
D_AB=defaultdict(int)
D_BA=defaultdict(int)

for a,b in L:
    if a*b==0:
        L_zero+=1
    else:
        D_AB[a/b]+=1
        D_BA[b/a]+=1


ans=1
used_key=set()
for key,val in D_AB.items():
    if key in used_key:
        continue
    else:
        used_key.add(key)
        used_key.add(-1/key)
    val_other=D_BA[-key]

    if val_other==0:
        ans*=pow(2,val,MOD)
    else:
        ans*=((pow(2,val,MOD)-1)+(pow(2,val_other,MOD)-1)+1)
if L_zero>0:
    assert 0==1
print((ans-1+MOD)%MOD)

Submission status: Runtime Error

Solution code:
N = int(input())
A_list = []
B_list = []
for _ in range(N):
    A, B = input().split()
    A = int(A)
    B = int(B)
    A_list.append(A)
    B_list.append(B)

count = 0
for i in range(N):
    for j in range(N):
        if A[i]*A[j] + B[i]*B[j] == 0:
            count = count + 1

print(count%1000000007)

Submission status: Runtime Error

Solution code:
mod = 10**9 + 7
n = int(input())
d = {}
for _ in range(n):
    a, b = map(int, input().split())
    if a/b in d:
        d[a/b] += 1
    else:
        d[a/b] = 1
ans = 1
for k in d.keys():
    if d[k] > 0:
        t = 2**d[k]
        if -1/k in d:
            t += 2**d[-1/k] - 1
            d[-1/k] = 0
        ans *= t
        ans %= mod
print(ans-1)

Submission status: Runtime Error

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 1000000007

N = int(readline())
AB = [list(map(int, readline().split())) for _ in range(N)]

CNT = defaultdict(int)
GCD = []

for i in range(N):
    a, b = AB[i]
    d = math.gcd(a, b)
    GCD.append(d)
    a //= d
    b //= d

    CNT[(a, b)] += 1


ANS = pow(2, N, MOD) - 1

C = defaultdict(bool)
for i in range(N):
    a, b = AB[i]
    d = GCD[i]

    a //= d
    b //= d

    y = CNT[(a, b)]
    x = 0

    if C[(a, b)]:
        continue

    if not C[(b, -a)]:
        x += CNT[(b, -a)]

    if not C[(-b, a)]:
        x += CNT[(-b, a)]

    if x == 0:
        continue

    t = (pow(2, y, MOD) - 1) * (pow(2, x, MOD) - 1)
    t %= MOD
    t *= pow(2, N - x - y, MOD)
    t %= MOD

    ANS -= t
    ANS %= MOD
    C[(a, b)] = True


print(ANS)

Submission status: Runtime Error

Solution code:
import sys
from collections import defaultdict as dd
from math import gcd
input = sys.stdin.readline
N = int(input())
mod = 10 ** 9 + 7
d = dd(int)
a = [tuple(map(int, input().split())) for _ in range(N)]
for x, y in a:
  g = gcd(abs(x), abs(y))
  d[(x // g, y // g)] += 1
res = 1
u = 0
itr = list(d.keys())
#print(itr)
for x, y in itr:
  t = d[(y, -x)] + d[(-y, x)]
  if t == 0: u += d[(x, y)]
for x, y in itr:
  t = d[(y, -x)] + d[(-y, x)]
  if t:
    v = 0
    v += pow(2, d[(x, y)], mod) - 1
    v %= mod
    v += pow(2, t, mod) - 1
    v %= mod
    v += 1
    v %= mod
    res *= v
    res %= mod
    #print(res, v)
  d[(x, y)] = 0
print(res * pow(2, u, mod) - 1 % mod)

Submission status: Runtime Error

Solution code:
PRIME = 1000000007
n = int(input())

fish = {}
taste_0 = 0
flavor_0 = 0

for i in range(n):
  a, b = map(int, input().split())
  if a != 0 and b != 0:
    if a / b in fish:
      fish[a / b] = fish[a / b] + 1
    else:
      fish[a / b] = 1
  elif a == 0:
    taste_0 += 1
  else:
    flavor_0 += 1

cnt = 0
if taste_0 != 0 and flavor_0 != 0:
  ans = pow(2, taste_0, PRIME)
  ans += pow(2, flavor_0, PRIME) - 1
  ans %= PRIME
else:
  cnt += taste_0
  cnt += flavor_0

for f in fish:
  if - 1 / f in fish and fish[f] > 0:
    ans1 = pow(2, fish[f], PRIME)
    ans1 += pow(2, fish[-1 / f], PRIME) - 1
    ans *= ans1
    ans %= PRIME
    fish[f] = 0
    fish[-1 / f] = 0
  elif -1 / f not in fish:
    cnt += fish[f]

ans *= pow(2, cnt, PRIME)
ans %= PRIME

ans += PRIME - 1
ans %= PRIME

print(ans)

Submission status: Runtime Error

Solution code:
from collections import defaultdict as dd
MOD = 10**9+7
N=int(input())
ab = [tuple(map(int, input().split())) for i in range(N)]
res = 0
left_dic = dd(int)
center_dic = dd(int)
right_dic = dd(int)
for a,b in ab:
    if a==b or -a==b:
        center_dic[a/b] += 1
    elif a>b:
        left_dic[a/b] += 1
    elif a<b:
        right_dic[b/a] += 1
comp = []
# center
if center_dic[1.0]>0 and center_dic[-1.0]>0:
    comp.append((center_dic[1.0],center_dic[-1.0]))

# left,right
left = sorted(left_dic.keys(),reverse=True)
right = sorted(right_dic.keys())
idx_left = 0
idx_right = 0
S = len(left)
T = len(right)
# left:+, right:-
while 1:
    if idx_left>=S or idx_right>=T:
        break
    l = left[idx_left]
    r = -right[idx_right]
    if l<0 or r<0:
        break
    if l==r:
        comp.append((left_dic[l], right_dic[-r]))
        idx_left += 1
        idx_right += 1
    elif l>r:
        idx_left += 1
    else:
        idx_right += 1
if idx_right<N and idx_left<N:
    left = [-val for val in left if val < 0]
    # left = left[::-1]
    right = [val for val in right if val > 0]
    S = len(left)
    T = len(right)
    idx_left = 0
    idx_right = 0
    while 1:
        if idx_left >= S or idx_right >= T:
            break
        l = left[idx_left]
        r = right[idx_right]
        if l < 0 or r < 0:
            break
        if l == r:
            comp.append((left_dic[-l], right_dic[r]))
            idx_right += 1
            idx_left += 1
        elif l < r:
            idx_left += 1
        else:
            idx_right += 1
res2 = 0
rest = N
buff = 1
for s,t in comp:
    rest -= s+t
    # tmp = s*t
    tmp = (2**(s+t)-2**s-2**t+1)%MOD
    res2 = (res2 + buff*tmp*pow(2,rest,MOD))%MOD
    buff = (2**(s+t)-tmp)%MOD
res2 += 1
res = (pow(2,N,MOD)-res2)%MOD
print(res)

Submission status: Runtime Error

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

N = int(input())
d = {}
for i in range(N):
    A, B = map(int, input().split())
    g = gcd(abs(A), abs(B))
    
    if A*B > 0:
        key = (abs(A)//g, abs(B)//g)
        if key not in d:
            d[key] = [0, 0]
        d[key][0] += 1
    else:
        key = (abs(B)//g, abs(A)//g)
        if key not in d:
            d[key] = [0, 0]
        d[key][1] += 1

MOD = 10 ** 9 + 7
ans = 1
for k, v in d.items():
    temp = (pow(2, v[0], MOD) + pow(2, v[1], MOD) - 1) % MOD
#     print(temp)
#     if temp < 0:
#         temp += MOD
    ans = (ans * temp) % MOD
ans = ans - 1
if ans < 0:
    ans += MOD
print(ans)

Submission status: Runtime Error

Solution code:
def power_func(a, b, p=1000000007):
    if b == 0:
        return 1
    if b % 2 == 0:
        d = power_func(a, b // 2, p)
        return d * d % p
    if b % 2 == 1:
        return (a * power_func(a, b - 1, p)) % p
n = int(input())
A_B_dict = {}
for i in range(n):
    a, b = map(int,input().split())
    temp = a/b
    if temp in A_B_dict:
        A_B_dict[temp] += 1
    else:
        A_B_dict[temp] = 1
net_dict = {}
# if 0 in A_B_dict:
#     net_dict[0] = 2**A_B_dict[0]
for i in A_B_dict:
    temp = -1/i
    if temp in A_B_dict:
        if i not in net_dict:
            net_dict[temp] = power_func(2, A_B_dict[i]) + power_func(2, A_B_dict[temp]) - 1
        else:
            pass
    else:
        net_dict[temp] = power_func(2,A_B_dict[i])
ans = 1
for k in net_dict.values():
    ans = (ans*k)
print((ans-1)%1000000007)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from fractions import Fraction

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

MOD = 1000000007
d_plus = defaultdict(int)  # + or ∞
d_minus = defaultdict(int)  # - or 0
ans = 1

for i, (a, b) in enumerate(X):
    if a == 0 and b == 0:
        continue
    elif a == 0:
        d_minus[0] += 1
    elif b == 0:
        d_plus[float('inf')] += 1
    elif a * b > 0:
        d_plus[Fraction(a, b)] += 1
    else:
        d_minus[Fraction(a, b)] += 1

for m in d_minus:
    d_plus[-1 / m] += 0
for p in d_plus:
    ans = ans * (pow(2, d_plus[p], MOD) + pow(2, d_minus[-1 / p], MOD) - 1)
    ans %= MOD
print((ans - 1) % MOD)

Submission status: Runtime Error

Solution code:
import sys
from collections import defaultdict as dd
from math import gcd
input = sys.stdin.readline
N = int(input())
mod = 10 ** 9 + 7
d = dd(int)
a = [tuple(map(int, input().split())) for _ in range(N)]
table = [0] * N
table[1] = pow(2, N - 2, mod)
for x in range(2, N):
  table[x] = table[x - 1] * 2 % mod - pow(2, N - x - 1, mod)
for x, y in a:
  g = gcd(abs(x), abs(y))
  d[(x // g, y // g)] += 1
res = 1
u = 0
itr = list(d.keys())
#print(itr)
for x, y in itr:
  t = d[(y, -x)] + d[(-y, x)]
  if t == 0: u += d[(x, y)]
for x, y in itr:
  t = d[(y, -x)] + d[(-y, x)]
  if t:
    v = 0
    v += pow(2, d[(x, y)], mod) - 1
    v %= mod
    v += pow(2, t, mod) - 1
    v %= mod
    v += 1
    v %= mod
    res *= v
    res %= mod
    #print(res, v)
  d[(x, y)] = 0
print(res * pow(2, u, mod) - 1 % mod)

Submission status: Runtime Error

Solution code:
all_ = set([i for i in range(1,N)])
child = [[] for _ in range(N)]
ans = [[] for _ in range(N)]
for ab in AB:
    child[ab[0]-1].append(ab[1]-1)
    child[ab[1]-1].append(ab[0]-1)
child = list(map(set,child))
check = [0]
while len(all_ ) != 0:
    checkk = []
    for c in check:
        print(child[c])
        print(all_)
        a = list(child[c] & all_)
        print(a)
        ans[c] = a
        checkk += a
        all_ = all_ - child[c]
    check = list(set(checkk))
anss = [[] for i in range(N)]
for i in range(N):
    for a in ans[i]:
        anss[a] = i
print('Yes')
for a in anss[1:]:
    print(a + 1)

Submission status: Runtime Error

Solution code:
N = int(input())
katamuki = []
mod = 10**9+7
mugen = 0
gomi = 0
for i in range(N):
    a,b = [int(x) for x in input().split()]
    if a == 0 and b == 0:
        gomi += 1
        continue
    if b == 0:
        mugen += 1
        continue
    katamuki.append(a/b)
N -= gomi
from collections import defaultdict
d = defaultdict(int)
for i in range(N):
        d[katamuki[i]] += 1
ans = 0
katamuki.sort()
for i in range(N-mugen):
    if katamuki[i] < 0:
        ans += pow(2,N-i-1-d[-1/katamuki[i]],mod)
    elif katamuki[i] == 0:
        ans += pow(2,N-i-1-mugen,mod)
    else:
        ans += pow(2,N-i-1,mod)
ans += 2**mugen - 1
print(ans % mod)

Submission status: Runtime Error

Solution code:
import sys
from collections import Counter
from collections import deque
import math
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

mod=1000000007
n=int(input())
if n==1:
    print(1)
    exit()
l1=[]
l2=[]
l0=0
for i in range(n):
    a,b=mp()
    if a*b>0:
        l1.append(a/b)
    elif a*b==0:
        l0+=1
    else:
        l2.append(-b/a)
c1=sorted(list(Counter(l1).most_common()),key=lambda x: x[0])
c2=sorted(list(Counter(l2).most_common()),key=lambda x: x[0])
c1.append((10**10, 1))
c2.append((10**10, 1))


ans=1
i=0
k=0
while i<len(c1)-1 or k<len(c2)-1:



    if c1[i][0]<c2[k][0]:
        ans*=pow(2,c1[i][1],mod)
        i+=1
    elif c1[i][0]>c2[k][0]:
        ans*=pow(2,c2[k][1],mod)
        k+=1
    else:
        ans*=(pow(2,c1[i][1],mod)+pow(2,c2[k][1],mod)-1)
        i+=1
        k+=1
ans*=pow(2,l0,mod)
print((ans-1)%mod)

Submission status: Runtime Error

Solution code:
import sys,math,bisect
input = sys.stdin.readline

mod = 1000000007
eps = 0.000001

n = int(input())

ab = []
ang = []
for i in range(n):
    a,b = map(int,input().split())
    ab.append((a,b))
    if a == 0:
        ang.append((90.0,i))
    else:
        ang.append((math.degrees(math.atan(b/a)),i))
ang.sort()

res = 1
used = [False]*n


rest = n

for i in range(n):
    e,idx = ang[i]
    if used[idx]:
        continue
    used[idx] = True
    if e > eps:
        break
    
    cnt = 1
    k = i + 1
    while k < n:
        if abs(e-ang[k][0]) <= eps:
            p = ang[k][1]
            if ab[p][0]*ab[idx][1] == ab[p][1]*ab[idx][0]:
                cnt += 1
                used[p] = True
            k += 1
        else:
            break


    cnt2 = 0

    ok = n-1
    ng = i+1
    while ok-ng > 1:
        mid = (ok+ng)//2
        if ang[mid][0] >= e+90-eps:
            ok = mid
        else:
            ng = mid

    k = ok
    while k < n:
        if abs(e+90-ang[k][0]) <= 0.000002:
            p = ang[k][1]
            if ab[p][0]*ab[idx][0] + ab[p][1]*ab[idx][1] == 0:
                cnt2 += 1
                used[p] = True
            k += 1
        else:
            break

    if cnt2 != 0:
        res = res*(pow(2,cnt,mod) + pow(2,cnt2,mod) - 1)%mod
        rest -= cnt+cnt2

res = res*pow(2,rest,mod)%mod - 1
print(res)

Submission status: Runtime Error

Solution code:

from collections import Counter
mod = 1000000007

n = int(input())
a_div_b = []
a_0 = 0
b_0 = 0
a_b_0 = 0
for _ in range(n):
    a, b = map(int, input().split())
    if a == 0 or b == 0:
        if a == 0 and b == 0:
            a_b_0 += 1
        if a == 0:
            a_0 += 1
        if b == 0:
            b_0 += 1
        break
    if a * b < 0:
        a_div_b.append(a/b)
    else:
        a_div_b.append(b/a)

cnt = Counter(a_div_b)
cnt2 = sorted(cnt.items())
lst = []
total = 0
for num, _ in cnt2:
    if num > 0:
        break
    a1 = cnt[num]
    a2 = cnt[-num]
    if a1 * a2 != 0:
        total += a1 + a2
        lst.append([a1, a2])
if a_0 * b_0 != 0:
    total += a0 + b0
    lst.append([a0, b0])
n -= a_b_0
ans = pow(2, n - total, mod)
tmp = 1
for a, b in lst:
    tmp *= pow(2, a, mod) + pow(2, b, mod) - 1
ans = (ans * tmp - 1 + a_b_0) % mod
    
print(ans)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

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

S=[tuple(map(int,input().split())) for i in range(N)]

from collections import Counter
from fractions import Fraction
C=Counter()
MINUS=0
for a,b in S:
    if a==0 and b==0:
        MIUUS+=1
    if b!=0:
        C[Fraction(a,b)]+=1
    else:
        C[float("inf")]+=1
    
ANS=1
#print(C)
for x in list(C.keys()):
    if x!=float("inf") and x!=Fraction(0,1):
        n=x.numerator
        d=x.denominator

        ANS=ANS*(pow(2,C[x],mod)+pow(2,C[Fraction(-d,n)],mod)-1)%mod

        C[x]=0
        C[Fraction(-d,n)]=0
        
    else:
        ANS=ANS*(pow(2,C[float("inf")],mod)+pow(2,C[Fraction(0,1)],mod)-1)%mod

        C[float("inf")]=0
        C[Fraction(0,1)]=0

print((ANS-1-MINUS)%mod)

Submission status: Runtime Error

Solution code:
import sys
from collections import defaultdict
from queue import deque
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def egcd(a: int, b: int):
    """
    A solution of ax+by=gcd(a,b). Returns
    (gcd(a,b), (x, y)).
    """
    if a == 0:
        return b, 0, 1
    else:
        g, x, y = egcd(b % a, a)
        return g, y - (b // a) * x, x


def modinv(a: int, mod: int = 10**9 + 7):
    """
    Returns a^{-1} modulo m.
    """
    g, x, y = egcd(a, mod)
    if g > 1:
        raise Exception('{}^(-1) mod {} does not exist.'.format(a, mod))
    else:
        return x % mod


def modpow(a: int, n: int, mod: int = 10**9 + 7):
    """
    Returns a^n mod m. (-inf < n < inf)
    """
    if a in [-1, 0, 1]:
        if a == -1:
            return 1 if n & 1 == 0 else mod - 1
        else:
            return a

    x, k = (a % mod, n) if n >= 0 else (modinv(a, mod), -n)

    ret = 1
    while k > 0:
        if k & 1 == 1:
            ret = ret * x % mod
        x = (x**2) % mod
        k = k >> 1

    return ret


def main():
    N = gete(int)

    d = dict()

    for _ in range(N):
        a, b = geta(int)
        g, _, _ = egcd(a, b)
        ai, bi = a // g, b // g
        if ai < 0:
            ai *= -1
            bi *= -1

        aj, bj = bi, -ai
        if aj < 0:
            aj *= -1
            bj *= -1

        if (ai, bi) in d:
            d[(ai, bi)][0] += 1
        elif (aj, bj) in d:
            d[(aj, bj)][1] += 1
        else:
            d[(ai, bi)] = [1, 0]
    mod = 1000000007
    ans = 1
    for k in d:
        n = modpow(2, d[k][0], mod)
        m = modpow(2, d[k][1], mod)

        ans = ans * (n + m - 1) % mod
    print(ans - 1)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from fractions import Fraction
import sys
input = sys.stdin.readline
def powmod(x, n,mod):
  if n == 0:
   return 1
  K = 1
  while n > 1:
   if n % 2 != 0:
    K = K * x%mod
    x = x ** 2%mod
    n = (n - 1) // 2
   else:
    x = x ** 2%mod
    n = n // 2%mod

  return K * x # 指数を割り続け n が 1 に至ったら終了
N=int(input())
mod=10**9+7
dic={}
dica={}
c=0
d=0
for i in range(N):
 A,B = map(int,input().split())
 if A==0 and B==0:
  continue
 elif A==0:
  c+=1
 elif B==0:
  d+=1
 else:
   x=Fraction(A,B)
   if x>0:
    if x in dic:
     dic[x]+=1
    else:
     dic[x]=1
   else:
    if x in dic:
     dica[x]+=1
    else:
     dica[x]=1
 ans=1
for k in dic:
 if -1/k in dica:
   ans*=(powmod(2,dic[k],mod)+powmod(2,dica[-1/k],mod) -1)
   ans%=mod
 else:
   ans*=powmod(2,dic[k],mod)
   ans%=mod
for k in dica:
 if -1/k in dic:
  continue
 else:
  ans*=powmod(2,dica[k],mod)
  ans%=mod
ans*=(powmod(2,c,mod)+powmod(2,d,mod)-1)
ans%=mod
print(ans-1)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf
# @pysnooper.snoop()
#import pysnooper # debug

import math
#from sortedcontainers import SortedList, SortedDict, SortedSet # no in atcoder
import bisect
from fractions import Fraction

# NG: ai / bi (atk) = - bj / aj (agi)

mod = 1000000007

class Solver:

    def __init__(self, n):
        self.n = n
        self.atk = []
        self.agi = {}
        self.ans = 0

    def fishing(self, id_, a, b):
        atk = Fraction(a, b)
        self.atk.append(atk)
        agi = Fraction(-1 * b / a)
        if agi not in self.agi:
            self.agi[agi] = []
        self.agi[agi].append(id_)

    def check(self, i):
        atk = self.atk[i]
        if atk in self.agi:
            #print(self.agi[atk]) # debug
            return self.agi[atk]
        else:
            return []

    def run(self):
        ng = [False] * self.n
        free = 0
        self.f(0, ng[:], free)
        return self.ans - 1

    def f(self, i, ng, free):
        #print('f') # debug
        #print('ng') # debug
        #print(ng) # debug
        while i < self.n:
            #print('i') # debug
            #print(i) # debug
            if ng[i]:
                i += 1
                continue
            enemy = self.check(i)
            #print('enemy') # debug
            #print(enemy) # debug
            if len(enemy) == 0:
                free += 1
            else:
                #print('else') # debug
                self.f(i + 1, ng[:], free)
                for e in enemy:
                    ng[e] = True
            i += 1
        self.ans += 2 ** free % mod
        #print('f end', free) # debug





if __name__ == '__main__':
    n = int(input())
    solver = Solver(n)
    for i in range(n):
        a, b = list(map(int, input().split()))
        solver.fishing(i, a, b)

    ans = solver.run()
    #print('ans') # debug
    print(ans)


    #print('\33[32m' + 'end' + '\033[0m') # debug

Submission status: Runtime Error

Solution code:
N = int(input())
bad = 1
X = {}
Y = {}

for _ in range(N):
    a, b = map(int, input().split())
    if (a >= 0 and b >= 0) or (a < 0 and b < 0):
        a = abs(a)
        b = abs(b)
        test = str(a * b)
        if test in X:
            X[test] += 1
        else:
            X[test] = 1
        if test in Y:
            bad = bad * (Y[test] + 1) / (Y[test] + 2) * 2
    else:
        a = abs(a)
        b = abs(b)
        test = str(a * b)
        if test in Y:
            Y[test] += 1
        else:
            Y[test] = 1
        if test in X:
            bad = bad * (X[test] + 1) / (X[test] + 2) * 2
print(int((2 ** N / bad - 1) % 1000000007))

Submission status: Runtime Error

Solution code:
n = int(input())
MOD = 1000000007

ans = 1
x_sardines = []
ver_sardines = []
hor_sardines  = []
zero_sardines  = []

for _ in range(n):
  ai, bi = map(int, input().split())
  if ai == 0 and bi != 0:
    ver_sardines.append((ai, bi))
  elif ai != 0 and bi == 0:
    hor_sardines.append((ai, bi))
  elif ai == 0 and bi == 0:
    zero_sardines.append((ai, bi))
  elif bi / ai > 0:
    x_sardines.append((ai, bi, 1))
  elif bi / ai < 0:
    x_sardines.append((- 1 * bi, ai, -1))

x_sardines.sort(key = lambda x: x[1] / x[0])

pai, pbi, ps = x_sardines[0]
p = 1 if ps == 1 else 0
n = 1 if ps == -1 else 0
for i, (ai, bi, s) in enumerate(x_sardines[1:]):
  if pai * bi - pbi * ai != 0:
    ans *= pow(2, p, MOD) + pow(2, n, MOD) - 1
    p = 0
    n = 0
    
  if s == 1:
    p += 1
  elif s == -1:
    n += 1
  pai, pbi, ps = ai, bi, s

ans *= pow(2, p, MOD) + pow(2, n, MOD) - 1
  
v = len(ver_sardines)
h =  len(hor_sardines)
ans *= pow(2, v, MOD) + pow(2, h, MOD) - 1
ans %= MOD

z = len(zero_sardines)
ans += pow(2, v, MOD) - 1 
ans -= 1
ans %= MOD

print(ans)

Submission status: Runtime Error

Solution code:
import math
M = 10**9+7
def getRev(a,b):
    if -b>0:
        return (-b,a)
    else:
        return (b,-a)

def main():
    n = int(input())
    
    d = {}
    
    for _ in range(n):
        a,b = tuple(map(int,input().split()))
        if a<0:
            a,b = -a,-b
        g = math.gcd(abs(a),abs(b))
        e1,e2 = a//g,b//g
        k = e1,e2
        d.setdefault(k,0)
        d[k] += 1

    ans = 1
    for k,v in d.items():
        k_r = getRev(*k)
        if k_r in d:
            if d[k_r]!=-1:
                v2 = d[k_r]
                ans *= (pow(2,v,M)+pow(2,v2,M)-1)
                d[k] = -1
                d[k_r] = -1
        else:
            ans*=pow(2,v,M)
            ans %= M

    print(ans-1)



        

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



import bisect
from math import gcd
n = int(input())
l = [None] * n
for i in range(n):
    a,b = map(int, input().split())
    g = gcd(a,b)
    l[i] = (a//g, b//g)

l.sort()
M = 1000000007
seen = [False] * n
vals = []

def sub(item):
    item1 = (item[1], -item[0])
    item2 = (-item[1], item[0])
    tmp = None
    count = 0
    li = bisect.bisect_left(l, item1)
    ri = bisect.bisect_right(l, item1)
    count += (ri-li)
    for v in range(li, ri):
        seen[v] = True
    if ri>li:
        tmp = l[li]
        
    li = bisect.bisect_left(l, item2)
    ri = bisect.bisect_right(l, item2)
    count += (ri-li)
    for v in range(li, ri):
        seen[v] = True
    if ri>li:
        tmp = l[li]
    
    return count, tmp

for i,item in enumerate(l):
    if seen[i]:
        continue
    count,tmp = sub(item)
    if count>0:
        count2, tmp = sub(tmp)
        vals.append((pow(2,count,M)+pow(2,count2,M)-1)%M)
    else:
        vals.append(2)
ans = 1
for v in vals:
    ans *= v
    ans %= M
if len(vals)>=2:
    ans -= 1
print(ans%M)

Submission status: Runtime Error

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

N = int(input())
d = {}
for i in range(N):
    A, B = map(int, input().split())
    g = gcd(abs(A), abs(B))
    
    if A*B > 0:
        key = (abs(A)//g, abs(B)//g)
        if key not in d:
            d[key] = [0, 0]
        d[key][0] += 1
    else:
        key = (abs(B)//g, abs(A)//g)
        if key not in d:
            d[key] = [0, 0]
        d[key][1] += 1


MOD = 10 ** 9 + 7

ans = 1
for k, v in d.items():
#     print(2 ** v[0] + 2 ** v[1] - 1)
    temp = pow(2, v[0], MOD) + pow(2, v[1], MOD) - 1
    if temp < 0:
        temp += MOD
    ans = ans * temp % MOD
ans = ans - 1
if ans < 0:
    ans += MOD
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
st = {}
dz = 0
count = 0
for i in range(N):
    a, b = map(int,input().split())
    if a == 0 and b == 0:
        dz += 1
    elif b == 0:
        if 'inf' in st:
            st['inf'] += 1
        else:
            st['inf'] = 1
    else:
        c = a / b
        if c in st:
            st[c] += 1
        else:
            st[c] = 1
ans = 1
if 'inf' in st and 0 in st:
    ans *= (2**(st['inf'])+2**(st[0])-1)
    count += st['inf'] + st[0]
    del st['inf']
    del st[0]
alr = set()
for i, j in st.items():
    if i in alr:
        pass
    else:
        g = -1/i
        if g in st:
            ans *= (2**j+2**(st[g])-1)
            alr |= {g,i}
for i in alr:
    count += st[i]
    del st[i]
ans2 = pow(2,N-count,1000000007)
ans *= ans2
print((ans-1+dz)%1000000007)

Submission status: Runtime Error

Solution code:
N = int(input())
bad = 1
X = {}
Y = {}

for _ in range(N):
    a, b = map(int, input().split())
    if (a >= 0 and b >= 0) or (a < 0 and b < 0):
        a = abs(a)
        b = abs(b)
        test = str(a * b)
        if test in X:
            X[test] += 1
        else:
            X[test] = 1
        if test in Y:
            bad = bad * (Y[test] + 1) / (Y[test] + 2) * 2
    else:
        a = abs(a)
        b = abs(b)
        test = str(a * b)
        if test in Y:
            Y[test] += 1
        else:
            Y[test] = 1
        if test in X:
            bad = bad * (X[test] + 1) / (X[test] + 2) * 2
print((2 ** N / bad - 1) % 1000000007)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
import math
from collections import defaultdict
from bisect import bisect_left
from collections import Counter
sys.setrecursionlimit(10**8)
INF = float("inf")

MOD = 1000000007  # type: int


class UnionFind(object):
    def __init__(self, N):
        self.tree = list(range(N))

    def root(self, i):
        if self.tree[i] == i:
            return i
        else:
            self.tree[i] = self.root(self.tree[i])
            return self.tree[i]

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            self.tree[x] = y


def solve(N: int, A: "List[int]", B: "List[int]"):
    # 直交するイワシは選べない
    # イワシをソートする
    abtheta = sorted(zip(A, B), key=lambda x: math.atan2(x[1], x[0]))
    # 順にイワシを見てグループを探す。二分探索で探す。
    uf = UnionFind(N)

    nisyuni = abtheta*2

    end = 0
    end2 = None
    for i in range(N):
        # イワシiと90度、180度、270度角度が異なるものはありますか
        # しゃくとりで
        a, b = abtheta[i]

        # 90度の関係にあるもの
        while end <= N+i:
            ai, bi = nisyuni[end]
            if ai*a+bi*b <= 0:
                break
            end += 1

        while ai*a+bi*b == 0:
            uf.unite(i, end % N)
            end += 1
            if end >= 2*N:
                break
            ai, bi = nisyuni[end]

        if end2 == None:
            end2 = end

        # 270度の関係にあるもの
        while end2 <= N+i:
            ai, bi = nisyuni[end2]
            if ai*a+bi*b >= 0:
                break
            end2 += 1

        while ai*a+bi*b == 0:
            uf.unite(i, end2 % N)
            end2 += 1
            if end2 >= 2*N:
                break
            ai, bi = nisyuni[end2]

        if end == start + 1:
            end += 1

    # デフォルトディクトに変換する
    d = defaultdict(list)
    for i in range(N):
        d[uf.root(i)].append(abtheta[i])

    ans = 1
    for key in d:
        # 各グループをさらに二つに分類
        maru, batu = 1, 0
        a0, b0 = d[key][0]
        for a, b in d[key][1:]:
            if a0 * a + b0*b == 0:
                batu += 1
            else:
                maru += 1
        buf = pow(2, maru, MOD)
        buf += pow(2, batu, MOD)
        buf -= 1
        buf %= MOD
        ans *= buf

    # print(d)
    print((ans-1) % MOD)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, A, B)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from math import gcd
from collections import Counter
mod = 10**9+7
def f(aai, bbi):
    gc = gcd(aai, bbi)
    a, b = aai // gc, bbi // gc
    if a < 0:
        a = -a
        b = -b
    return a, b

n= int(input())
aa = [0] * n
for i in range(n):
    ai, bi = map(int, input().split())
    aa[i] = f(ai, bi)

dic_ = Counter(aa)

cnt = 1
while len(dic_) > 0:
    k, v = dic_.popitem()
    ka , kb = k[0], k[1]
    if kb < 0:
        ka = -ka
        kb = -kb
    t = dic_.get((kb, -ka), 0)
    if t > 0:
        try:
            del dic_[(kb, -ka)]
        except:
            pass
        cnt *= ((2**v) + (2**t) - 1) % mod
    else:
        cnt *= (2**v) % mod
print((cnt+mod-1)%mod)

Submission status: Runtime Error

Solution code:
n = int(input())
A_B_dict = {}
for i in range(n):
    a, b = map(int,input().split())
    temp = a/b
    if temp in A_B_dict:
        A_B_dict[temp] += 1
    else:
        A_B_dict[temp] = 1
net_dict = {}
# if 0 in A_B_dict:
#     net_dict[0] = 2**A_B_dict[0]
for i in A_B_dict:
    temp = -1/i
    if temp in A_B_dict:
        if i not in net_dict:
            net_dict[temp] = 2**A_B_dict[i] + 2**A_B_dict[temp] - 1
        else:
            pass
    else:
        net_dict[temp] = 2**A_B_dict[i]
ans = 1
for k in net_dict.values():
    ans = (ans*k)%1000000007
print((ans-1))