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:
N = int(input())
mod = 10 **9 + 7

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


liABplus = []
liBAplus = []
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:
            liABplus.leftappend(0)
        else:
            liBAplus.leftappend(0)
    elif A*B > 0:
        insort(liABplus, A/B)
    else:
        insort(liBAplus, -B/A)
def make_count(list):
    k = 0
    lis = []
    while k < len(list):
        cnt = 1
        while k+1 < len(list):
            if equal(list[k], list[k+1]):
                cnt += 1
                k += 1
                continue
            else:
                break
        lis.append([list[k], cnt])
        k += 1
    return lis

liABplus = make_count(liABplus)
liBAplus = make_count(liBAplus)
N -= zero
from collections import deque
liABplus = deque(liABplus)
liBAplus = deque(liBAplus)
ans = bitlist[N]-1 #all pattern
flag = True
eqpair = []
while liABplus and liBAplus:
    if flag:
        AB = liABplus.popleft()
        BA = liBAplus.popleft()
    if equal(AB[0], BA[0]):
        eqpair.append([AB[1], BA[1]])
        if liABplus and liBAplus:
            flag = True
            continue
        else:
            break
    elif bigger(AB[0], BA[0]):
        if liBAplus:
            BA = liBAplus.popleft()
            flag = False
            continue
        else:
            break
    else:
        if liABplus:
            AB = liABplus.popleft()
            flag = False
            continue
        else:
            break

minus = 0
from itertools import combinations
for k in range(1, len(eqpair)+1):
    for item in combinations(eqpair, k):
        sgn = (-1)**k
        ideal = 1
        cnt = 0
        for i in item:
            cnt += i[0] + i[1]
            ideal *= bitlist[i[0]]-1
            ideal %= mod
            ideal *= bitlist[i[1]]-1
            ideal %= mod
        ideal *= bitlist[N-cnt]
        ideal %= mod
        ans += sgn*ideal
        ans %= mod
print(ans)

Submission status: Runtime Error

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

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


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

liABplus = make_count(liABplus)
liBAplus = make_count(liBAplus)

from collections import deque
liABplus = deque(liABplus)
liBAplus = deque(liBAplus)
ans = bitlist[N]-1 #all pattern
flag = True
eqpair = []
while liABplus and liBAplus:
    if flag:
        AB = liABplus.popleft()
        BA = liBAplus.popleft()
    if equal(AB[0], BA[0]):
        eqpair.append([AB[1], BA[1]])
        if liABplus and liBAplus:
            flag = True
            continue
        else:
            break
    elif bigger(AB[0], BA[0]):
        if liBAplus:
            BA = liBAplus.popleft()
            flag = False
            continue
        else:
            break
    else:
        if liABplus:
            AB = liABplus.popleft()
            flag = False
            continue
        else:
            break

minus = 0
from itertools import combinations
for k in range(1, len(eqpair)+1):
    for item in combinations(eqpair, k):
        sgn = (-1)**k
        ideal = 1
        cnt = 0
        for i in item:
            cnt += i[0] + i[1]
            ideal *= bitlist[i[0]]-1
            ideal %= mod
            ideal *= bitlist[i[1]]-1
            ideal %= mod
        ideal *= bitlist[N-cnt]
        ideal %= mod
        ans += sgn*ideal
        ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from math import gcd
N = int(input())
MOD = 10**9 + 7
L = defaultdict(lambda: [0,0])
for _ in range(N):
    A, B = map(int, input().split())
    d = gcd(A,B)
    A, B = A//d, B//d
    if A<0:
        A, B = -A, -B
    if B>=0:
        L[(A,B)][0] += 1
    else:
        L[(-B,A)][1] += 1
res = 1
for x,y in L.values():
    res *= pow(2,x,MOD) + pow(2,y,MOD) -1
    res %= MOD
print(res-1)

Submission status: Runtime Error

Solution code:
n=int(input())
# a/b:x
group = dict()
for _ in range(n):
  a,b=map(int,input().split())
  if a==0 and b==0:
    continue
  else:
    k_1 = 'x' if b==0 else a/b
    if k_1 in group:
      group[k_1][0] += 1
    else:
      group[k_1] = [1, 0]
    k_2 = 'x' if a==0 else - b/a
    if k_2 in group:
      group[k_2][1] += 1
    else:
      group[k_2] = [0, 1]

new_group = list()
p = 10**9+7
M = 0
for k, v in group.items():
  if group[k][0]* group[k][1] == 0:
    M = (M + group[k][0]) % p
  elif group[k][1] < 0:
    continue
  else:
    new_group.append(tuple(group[k]))
    if isinstance(k, str):
      k_r = 0
    elif k==0:
      k_r = 'x'
    else:
      k_r = -1/k
    group[k_r][1] = -1

# 選び方の計算
"""
条件付けに入らないイワシM
条件付けがされるイワシ(X_1, Y_1), (X_2, Y_2), ...
について
条件数Gとしたとき
(2**X_1+2**Y_1) * ... * M - 2*G
"""
ans = pow(2, M, p)
for g in new_group:
  ans = ans * ((pow(2, g[0], p) + pow(2, g[1], p)-1) % p) % p
ans = (ans - 1)%p
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
# a/b:x
group = dict()
for _ in range(n):
  a,b=map(int,input().split())
  if a==0 and b==0:
    continue
  else:
    k_1 = 'x' if b==0 else a/b
    if k_1 in group:
      group[k_1][0] += 1
    else:
      group[k_1] = [1, 0]
    k_2 = 'x' if a==0 else - b/a
    if k_2 in group:
      group[k_2][1] += 1
    else:
      group[k_2] = [0, 1]

new_group = list()
p = 10**9+7
M = 0
for k, v in group.items():
  if group[k][0]* group[k][1] == 0:
    M = (M + group[k][0]) % p
  elif group[k][1] < 0:
    continue
  else:
    new_group.append(tuple(group[k]))
    group[-1/k][1] = -1

# 選び方の計算
"""
条件付けに入らないイワシM
条件付けがされるイワシ(X_1, Y_1), (X_2, Y_2), ...
について
条件数Gとしたとき
(2**X_1+2**Y_1) * ... * M - 2*G
"""
ans = pow(2, M, p)
for g in new_group:
  ans = ans * ((pow(2, g[0], p) + pow(2, g[1], p)-1) % p) % p
ans = (ans - 1)%p
print(ans)

Submission status: Runtime Error

Solution code:
import sys
from fractions import Fraction
from collections import Counter

def solve(N, m):
    AB_fr = []
    for a, b in zip(m, m):
        if (a, b) != (0, 0):
            AB_fr.append(Fraction(a, b))
    if len(AB_fr) == 0:
        return 1
    ans = 1
    mod = 10**9+7
    Cnt = Counter(AB_fr)
    for ab_fr, cnt in Cnt.items():
        cnt2 = Cnt[-1/ab_fr]
        if ab_fr < 0 and cnt2 > 0:
            continue
        p = pow(2, cnt, mod)
        p2 = pow(2, cnt2, mod)
        ans = ans * (p + p2 - 1) % mod
    return (ans - 1) % mod

def main():
    N = int(sys.stdin.buffer.readline())
    m = map(int, sys.stdin.buffer.read().split())
    ans = solve(N, m)
    print(ans)

main()

Submission status: Runtime Error

Solution code:
import sys
from fractions import Fraction
from collections import Counter
def solve(N, m):
    AB_fr = []
    for a, b in zip(m, m):
        if (a, b) != (0, 0):
            AB_fr.append(Fraction(a, b))
    ans = 1
    mod = 10**9+7
    Cnt = Counter(AB_fr)
    for ab_fr, cnt in Cnt.items():
        cnt2 = Cnt[-1/ab_fr]
        if ab_fr < 0 and cnt2 > 0:
            continue
        p = pow(2, cnt, mod)
        p2 = pow(2, cnt2, mod)
        ans = ans * (p + p2 - 1) % mod
    return ans - 1

N = int(sys.stdin.buffer.readline())
m = map(int, sys.stdin.buffer.read().split())
ans = solve(N, m)
print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
from fractions import Fraction
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


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


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


MOD = 1000000007


def func(v1, v2):
    ans = 1
    ans += pow(2, v1, MOD) - 1
    ans += pow(2, v2, MOD) - 1

    return ans % MOD


def solve():
    N = int(input())

    num_zero = 0

    d = defaultdict(int)
    for _ in range(N):
        A, B = map(int, input().split())
        if A == 0 and B == 0:
            num_zero += 1
        else:
            if A == 0:
                k = Fraction(1, INF)
            elif B == 0:
                k = Fraction(INF, 1)
            else:
                k = Fraction(A, B)
            d[k] += 1

    ans = 1
    used = set()
    for k, v in d.items():
        if -(1 / k) in used:
            continue
        ans *= func(v, d.get(-(1 / k), 0))
        ans %= MOD
        used.add(k)

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


def main():
    solve()


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys, io, os, re
import bisect
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor, ceil
from copy import copy, deepcopy
from collections import deque, defaultdict
from fractions import gcd
from functools import reduce

def array1(n): return [0] * n
def array2(n, m): return [[0] * m for x in range(n)]
def array3(n, m, l): return [[[0] * l for y in xrange(m)] for x in xrange(n)]

n1 = lambda: int(sys.stdin.readline().strip())
nn = lambda: list(map(int, sys.stdin.readline().strip().split()))
f1 = lambda: float(sys.stdin.readline().strip())
fn = lambda: list(map(float, sys.stdin.readline().strip().split()))
s1 = lambda: sys.stdin.readline().strip()
sn = lambda: list(sys.stdin.readline().strip().split())
nl = lambda n: [n1() for _ in range(n)]
fl = lambda n: [f1() for _ in range(n)]
sl = lambda n: [s1() for _ in range(n)]
nm = lambda n: [nn() for _ in range(n)]
fm = lambda n: [fn() for _ in range(n)]
sm = lambda n: [sn() for _ in range(n)]

mod = 1000000007

N = n1()
(A, B) = ([], [])
for i in range(N):
    a, b = nn()
    if a < 0: a *= -1; b *= -1
    g = gcd(a, b)
    if g < 0: g *= -1
    if g != 0: a //= g; b //=g
    A.append(a)
    B.append(b)

d = defaultdict(int)
for i in range(N):
    d[(A[i], B[i])] += 1

ans = 1
while len(d) > 0:
    print(d, ans)
    (x, y), n1 = list(d.items())[0]
    d.pop((x, y))
    if y < 0: x *= -1; y *= -1

    n2 = 0
    if (y, -x) in d:
        n2 += d.pop((y, -x))
    if (-y, x) in d:
        n2 += d.pop((-y, x))

    ans = (ans * ((pow(2,n1,mod) -1 + pow(2,n2,mod) - 1) % mod + 1)) % mod

print(ans-1)

Submission status: Runtime Error

Solution code:
import sys, io, os, re
import bisect
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor, ceil
from copy import copy, deepcopy
from collections import deque, defaultdict
from fractions import gcd
from functools import reduce

def array1(n): return [0] * n
def array2(n, m): return [[0] * m for x in range(n)]
def array3(n, m, l): return [[[0] * l for y in xrange(m)] for x in xrange(n)]

n1 = lambda: int(sys.stdin.readline().strip())
nn = lambda: list(map(int, sys.stdin.readline().strip().split()))
f1 = lambda: float(sys.stdin.readline().strip())
fn = lambda: list(map(float, sys.stdin.readline().strip().split()))
s1 = lambda: sys.stdin.readline().strip()
sn = lambda: list(sys.stdin.readline().strip().split())
nl = lambda n: [n1() for _ in range(n)]
fl = lambda n: [f1() for _ in range(n)]
sl = lambda n: [s1() for _ in range(n)]
nm = lambda n: [nn() for _ in range(n)]
fm = lambda n: [fn() for _ in range(n)]
sm = lambda n: [sn() for _ in range(n)]

mod = 1000000007

N = n1()
(A, B) = ([], [])
for i in range(N):
    a, b = nn()
    if a < 0: a *= -1; b *= -1
    g = gcd(a, b)
    if g < 0: g *= -1
    A.append(a // g)
    B.append(b // g)

d = defaultdict(int)
for i in range(N):
    d[(A[i], B[i])] += 1

ans = 1
while len(d) > 0:
    #print(d, ans)
    (x, y), n1 = list(d.items())[0]
    d.pop((x, y))
    if y < 0: x *= -1; y *= -1
    if (y, -x) in d:
        n2 = d.pop((y, -x))
        ans = (ans * ((2**n1 -1 + 2**n2 - 1) % mod + 1)) % mod
    else:
        ans = (ans * (2**n1 % mod)) % mod

print(ans-1)

Submission status: Runtime Error

Solution code:

import sys, io, os, re
import bisect
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor, ceil
from copy import copy, deepcopy
from collections import deque, defaultdict
from fractions import gcd
from functools import reduce

def array1(n): return [0] * n
def array2(n, m): return [[0] * m for x in range(n)]
def array3(n, m, l): return [[[0] * l for y in xrange(m)] for x in xrange(n)]

n1 = lambda: int(sys.stdin.readline().strip())
nn = lambda: list(map(int, sys.stdin.readline().strip().split()))
f1 = lambda: float(sys.stdin.readline().strip())
fn = lambda: list(map(float, sys.stdin.readline().strip().split()))
s1 = lambda: sys.stdin.readline().strip()
sn = lambda: list(sys.stdin.readline().strip().split())
nl = lambda n: [n1() for _ in range(n)]
fl = lambda n: [f1() for _ in range(n)]
sl = lambda n: [s1() for _ in range(n)]
nm = lambda n: [nn() for _ in range(n)]
fm = lambda n: [fn() for _ in range(n)]
sm = lambda n: [sn() for _ in range(n)]

mod = 1000000007

N = n1()
(A, B) = ([], [])
for i in range(N):
    a, b = nn()
    if a < 0: a *= -1; b *= -1
    g = gcd(a, b)
    if g < 0: g *= -1
    A.append(a // g)
    B.append(b // g)

d = defaultdict(int)
for i in range(N):
    d[(A[i], B[i])] += 1

ans = 1
while len(d) > 0:
    #print(d, ans)
    (x, y), n1 = d.items()[0]
    d.pop((x, y))
    if y < 0: x *= -1; y *= -1
    if (y, -x) in d:
        n2 = d.pop((y, -x))
        ans = (ans * ((2**n1 -1 + 2**n2 - 1) % mod + 1)) % mod
    else:
        ans = (ans * (2**n1 % mod)) % mod

print(ans-1)

Submission status: Runtime Error

Solution code:
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

import math, bisect
mod = 10**9 + 7
n = int(input())
a = [0] *n
b = [0] * n
oo = 0
ao = 0
bo = 0
ab = [0] * n
ba = [0] * n
cnt = []
for i in range(n):
  A,B = map(int, input().split())
  g = math.gcd(A,B)
  a[i] = A//g
  b[i] = B//g
  if A == 0 & B == 0:
    oo += 1
  elif A == 0:
    ao += 1
  elif B == 0:
    bo += 1
  else:
    ab[i] = A/B
    ba[i] = -B/A

na = 0
np = 0
bba = ba.copy()
bba.sort()
cntl = []
for i in range(n):
  A = ab[i]
  j = bisect.bisect_left(bba, A)
  if j < n:
    if bba[j] == A and not A in cntl:
      np += ab.count(A)
      cnt.append(ab.count(A) + ba.count(A))
      cntl.append(A)
      cntl.append(ba[i])

np += ao * bo + na
np += oo*(n-1)
print(np,cnt)
ans = n
for k in range(2,n+1):
  ans += cmb(n, k)
  ans -= cmb(n-2, k-2) * np

print(ans)

Submission status: Runtime Error

Solution code:
from collections import deque
import math
mod = 10**9 + 7
n = int(input())
a = [0] *n
b = [0] * n
que = deque()
for i in range(n):
  A,B = map(int, input().split())
  g = math.gcd(A,B)
  a[i] = A//g
  b[i] = B//g

t = set()
for i in range(n):
  x,y = a[i],b[i]
  for j in range(i,n):
    if x*a[j] + y*b[j] == 0:
      que.append([i,j])
      t.add(i)
      t.add(j)

ans = 1
for k in range(1,n):
  ans += (math.factorial(n) / (math.factorial(k) * math.factorial(n-k))) % mod

while que:
  na = que.pop()
  m = len(na)
  for k in range(m,n+1):
    ans -= (math.factorial(n-m) / (math.factorial(k-m) *  math.factorial(n-k))) % mod

for d in range(3,len(t)+1):
  for k in range(d,n+1):
    ans += (math.factorial(n-d) / (math.factorial(k-d) *  math.factorial(n-k))) % mod

print(int(ans))

Submission status: Runtime Error

Solution code:
import bisect
import math
mod = 10**9 + 7
n = int(input())
a = [0] *n
b = [0] * n
oo = 0
ao = 0
bo = 0
ab = [0] * n
ba = [0] * n

for i in range(n):
  A,B = map(int, input().split())
  a[i] = A
  b[i] = B
  if A == 0 & B == 0:
    oo += 1
  elif A == 0:
    ao += 1
  elif B == 0:
    bo += 1
  else:
    ab[i] = A/B
    ba[i] = -B/A

na = 0
np = 0
ab.sort()
ba.sort()
for i in range(n):
  j = bisect.bisect_left(ba, ab[i])
  if j < n:
    if ba[j] == ab[i]: na += 1
    if j+1 >= n:continue
    j += 1
    while ba[j] == ab[i]:
      np = na + 1
      if j > n:break
      j += 1

na += ao + bo + oo
np += ao * bo
np += oo*(n-1)

ans = 1
for k in range(1,n):
  ans += (math.factorial(n) / (math.factorial(k) * math.factorial(n-k))) % mod

for _ in range(np):
  m = 2
  for k in range(m,n+1):
    ans -= (math.factorial(n-m) / (math.factorial(k-m) *  math.factorial(n-k))) % mod

for d in range(3,na+1):
  for k in range(d,n+1):
    ans += (math.factorial(n-d) / (math.factorial(k-d) *  math.factorial(n-k))) % mod

print(int(ans))

Submission status: Runtime Error

Solution code:
from collections import defaultdict

def gcd(x, y):
    if x < 0:
        x, y = y, x
    r = x % y
    while r:
        x, y, r = y, r, y%r
    return y
    
def main():
    n = int(input())
    mod = 1000000007
    p = defaultdict(lambda: 0)
    bad = dict()
    zeros = 0
    for _ in range(n):
        a, b = map(int, input().split())
        if a == 0 and b == 0:
            zeros += 1
        else:
            if a == 0:
                p["0"] += 1
                bad["0"] = "INF"
            elif b == 0:
                p["INF"] += 1
                bad["INF"] = "0"
            else:
                g = gcd(a, b)
                a //= g
                b //= g
                sp = f"{a}_{b}"
                if b < 0:
                    b *= -1
                    a *= -1
                sm = f"{b}_{-a}"
                p[sp] += 1
                bad[sp] = sm
    done = set()
    good = 0
    for key, num in p.items():
        if key in done:
            continue
        b = a[bad[key]]
        done.add(bad[key])
        if b > 0:
            ans *= pow(2, b, mod)*pow(2, num, mod)-1
            ans %= mod
        else:
            good += num
    ans *= pow(2, good, mod)
    ans += zeros
    ans -= 1
    ans %= mod
    print(ans)
        
        

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1000000007;
const ll inv2 = (mod + 1) / 2;
int n;
ll a, b;
ll c0, ans = 1;
typedef pair<ll, ll>pii;
map<pii, pii>mp;
ll Pow(ll a, ll b) {
	ll res = 1ll;
	while (b) {
		if (b & 1)res = res * a%mod;
		a = a * a%mod;
		b >>= 1;
	}
	return res;
}
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%lld%lld", &a, &b);
		if (a == 0 && b == 0)c0++;
		else {
			if (b < 0)a = -a, b = -b;
			ll g = abs(gcd(a, b));
			a /= g; b /= g;
			if (a > 0)mp[pii(a, b)].first++;
			else mp[pii(b, -a)].second++;
		}
	}
	for (auto p : mp) {
		ll tmp = (Pow(2, p.second.first) + Pow(2, p.second.second) + mod - 1) % mod;
		ans = ans * tmp%mod;
	}
	printf("%lld\n", (ans + mod - 1 + c0) % mod);
	return 0;
}

Submission status: Runtime Error

Solution code:
import sys, math

input = sys.stdin.readline
N = int(input())
scores = []
for _ in range(N):
    a, b = map(int, input().split())
    flg = 0
    if b == 0:
        score = 0
        flg = 1
    else:
        score = a/b
        if score<0:
            score = -1/score
            flg = 1
    scores.append((score, flg))

scores = sorted(scores)
ans = 1
pre = -1
pre_cnt = [0, 0]
for i, (score, flg) in enumerate(scores):
    if pre==score:
        rate = (2**pre_cnt[flg])/(2**pre_cnt[0]+2**pre_cnt[1]-1)
        ans += int(ans*rate)
        pre_cnt[flg] += 1
    else:
        ans += ans
        pre = score
        pre_cnt = [0, 0]
        pre_cnt[flg] += 1

print((ans-1)%1000000007)

Submission status: Runtime Error

Solution code:
N=int(input())
from collections import defaultdict
dic=defaultdict(int)
import math
mod=1000000007
for _ in range(N):
    A,B=map(int,input().split())
    if A<0:
        A,B=-A,-B
    if A==0:
        if B==0:
            dic[(0,0)]+=1
        else:
            dic[(0,1)]+=1
    elif B==0:
        dic[(1,0)]+=1
    else:
        gcd=math.gcd(A,B)
        A,B=A//gcd,B//gcd
        dic[(A,B)]+=1

ans=1
N-=dic[(0,0)]
for k,v in dic.items():
    if k==(0,0) or k==(0,1):
        continue
    if k==(1,0):
        v_dash=dic[(0,1)]
        ans*=((pow(2,v,mod)-1)+(pow(2,v_dash,mod)-1)+1)
        ans%=mod
        N-=v+v_dash
        continue
    a,b=k
    if not (b,-a) in dic:
        continue
    v_dash=dic[(b,-a)]
    ans*=((pow(2,v,mod)-1)+(pow(2,v_dash,mod)-1)+1)
    ans%=mod
    N-=v+v_dash
ans*=pow(2,N,mod)
ans+=dic[(0,0)]-1
ans%=mod
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
from collections import defaultdict
dic=defaultdict(int)
dic[(0,0)]=0
import math
mod=1000000007
for _ in range(N):
    A,B=map(int,input().split())
    if A<0:
        A,B=-A,-B
    if A==0:
        if B==0:
            dic[(0,0)]+=1
        else:
            dic[(0,1)]+=1
    elif B==0:
        dic[(1,0)]+=1
    else:
        gcd=math.gcd(A,B)
        A,B=A//gcd,B//gcd
        dic[(A,B)]+=1

ans=1
N-=dic[(0,0)]
for k,v in dic.items():
    if k==(0,0) or k==(0,1):
        continue
    if k==(1,0):
        v_dash=dic[(0,1)]
        ans*=((pow(2,v,mod)-1)+(pow(2,v_dash,mod)-1)+1)
        ans%=mod
        N-=v+v_dash
        continue
    a,b=k
    if not (b,-a) in dic:
        continue
    v_dash=dic[(b,-a)]
    ans*=((pow(2,v,mod)-1)+(pow(2,v_dash,mod)-1)+1)
    ans%=mod
    N-=v+v_dash
ans*=pow(2,N,mod)
ans+=dic[(0,0)]
ans%=mod
print(ans-1)

Submission status: Runtime Error

Solution code:
N=int(input())
from collections import defaultdict
dic=defaultdict(int)
import math
mod=1000000007
for _ in range(N):
    A,B=map(int,input().split())
    if A<0:
        A,B=-A,-B
    if A==0:
        if B==0:
            dic[(0,0)]+=1
        else:
            dic[(0,1)]+=1
    elif B==0:
        dic[(1,0)]+=1
    else:
        gcd=math.gcd(A,B)
        A,B=A//gcd,B//gcd
        dic[(A,B)]+=1

ans=1
N-=dic[(0,0)]
for k,v in dic.items():
    if k==(0,0) or k==(0,1):
        continue
    if k==(1,0):
        v_dash=dic[(0,1)]
        ans*=((pow(2,v,mod)-1)+(pow(2,v_dash,mod)-1)+1)
        ans%=mod
        N-=v+v_dash
        continue
    a,b=k
    if not (b,-a) in dic:
        continue
    v_dash=dic[(b,-a)]
    ans*=((pow(2,v,mod)-1)+(pow(2,v_dash,mod)-1)+1)
    ans%=mod
    N-=v+v_dash
ans*=pow(2,N,mod)
ans+=dic[(0,0)]
ans%=mod
print(ans-1)

Submission status: Runtime Error

Solution code:
from math import gcd
import collections

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

data = []

def yakubun(x, y):
	x, y = abs(x), abs(y)
	y_targ = gcd(x, y)
	return x//y_targ, y//y_targ

"""
ここから本題
"""

for i in range(n):
	a, b = map(int,input().split())
	if a == 0 and b == 0:
		data.append((0, 0))
	elif a == 0:
		data.append((0, 1))
	elif b == 0:
		data.append((1, 0))
	else:
		tmpa, tmpb = yakubun(a, b)
		if a * b < 0:
			data.append((-tmpa, tmpb))
		else:
			data.append((tmpa, tmpb))

print(data)
datacnt = collections.Counter(data)
ans = (pow(2, n, mod)-1) % mod
settansaku = set([])

for i, j in datacnt.most_common():
	out = 0
	if (i, j) in settansaku:
		continue
	if i * j < 0:
		out += datacnt[(j, -i)]
		settansaku.add((j, -i))
	elif i * j == 0:
		out += datacnt[(j, i)]
		settansaku.add((j, i))
	else:
		out += datacnt[(-j, i)]
		settansaku.add((-j, i))
	if out != 0:
		pass

print(ans)

Submission status: Runtime Error

Solution code:
from collections import defaultdict

mod=1000000007
def mpow2(n):
    ret=1
    while n>0:
        ret*=2
        ret%=mod
        n-=1
    return ret

def gcd(a,b):
    if a<0:
        a*=-1
    if b<0:
        b*=-1
    if a<b:
        a,b=b,a
    if a%b:
        return gcd(b,a%b)
    return b

shift=2**64
d=defaultdict(int)
n=int(input())
l=[]
cnt0=0
for i in range(n):
    a,b=map(int,input().split())
    if a==b==0:
        cnt0+=1
        continue
    g=gcd(a,b)
    a//=g
    b//=g
    l.append((a,b))
    d[a*shift+b]+=1
res=1
for p in l:
    a=p[0]
    b=p[1]
    c=d[a*shift+b]+d[-a*shift-b]
    if c==0:
        continue
    d[a*shift+b]=0
    d[-a*shift-b]=0
    a=-p[1]
    b=p[0]
    cc=d[a*shift+b]+d[-a*shift-b]
    d[a*shift+b]=0
    d[-a*shift-b]=0
    if cc==0:
        res*=mpow2(c)
        res%=mod
    else:
        res*=mpow2(c)+mpow2(cc)-1
        res%=mod
print((res+cnt0+mod-1)%mod)

Submission status: Runtime Error

Solution code:
import math
import sys
from collections import defaultdict

input = sys.stdin.readline
mod = 1000000007

n = int(input())

n2 = [1]
for _ in range(n):
    n2.append(n2[-1] * 2 % mod)

zero = 0
plus = defaultdict(int)
minus = defaultdict(int)

for _ in range(n):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        zero += 1
        continue
    p = math.gcd(a, b)
    a //= p
    b //= p
    if a * b > 0:
        plus[(abs(a), abs(b))] += 1
    else:
        minus[(abs(b), abs(a))] += 1

n -= zero

for k, v in plus.items():
    if minus[k] > 0:
        ans *= (n2[v] + n2[minus[k]] - 1)
        ans %= mod
        n -= v + minus[k]

ans *= n2[n]
ans = ans + zero - 1
ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
import math
import sys
from collections import defaultdict

input = sys.stdin.readline
mod = 1000000007

n = int(input())

n2 = [1]
for _ in range(n):
    n2.append(n2[-1] * 2 % mod)

zero = 0
plus = defaultdict(int)
minus = defaultdict(int)

for _ in range(n):
    a, b = map(int, input().split())
    if a * b == 0:
        zero += 1
    p = math.gcd(a, b)
    a //= p
    b //= p
    if a * b > 0:
        plus[(abs(a), abs(b))] += 1
    else:
        minus[(abs(b), abs(a))] += 1


ans = zero + 1
ans %= mod
n -= zero

for k, v in plus.items():
    if minus[k] > 0:
        ans *= (n2[v] + n2[minus[k]] - 1)
        ans %= mod
        n -= v + minus[k]

ans *= n2[n]
ans %= mod
print(ans - 1)

Submission status: Runtime Error

Solution code:
import math
import sys
from collections import defaultdict

input = sys.stdin.readline
mod = 1000000007

n = int(input())

n2 = [1]
for _ in range(n):
    n2.append(n2[-1] * 2 % mod)

zero = 0
plus = defaultdict(int)
minus = defaultdict(int)

for _ in range(n):
    a, b = map(int, input().split())
    if a * b == 0:
        zero += 1
    p = math.gcd(a, b)
    a //= p
    b //= p
    if a * b > 0:
        plus[(abs(a), abs(b))] += 1
    else:
        minus[(abs(b), abs(a))] += 1


ans = zero + 1
ans %= mod
n -= zero

for k, v in plus.items():
    if minus[k] > 0:
        ans *= (n2[v] + n2[minus[k]] - 1)
        ans %= mod
        n -= v + minus[k]

ans *= n2[n]
print(ans - 1)

Submission status: Runtime Error

Solution code:
from collections import Counter
import math
MOD=10**9+7
N=int(input())
li=[]
for i in range(N):
    A,B=map(int,input().split())
    g=math.gcd(A,B)
    li.append((A//g,B//g))
c=Counter(li)
dic={}
ans=1
for a,b in c.keys():
    if (a,b) in dic:
        continue
    l,r=(-b,a),(b,-a)
    s=c.get(l,0)+c.get(r,0)
    dic[l],dic[r]=1,1
    res=(pow(2,c[(a,b)],MOD)+pow(2,s,MOD)-1)%MOD
    ans=(ans*res)%MOD
print(ans-1)

Submission status: Runtime Error

Solution code:
import sys
import math


stdin = sys.stdin


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


def ns(): return stdin.readline().rstrip()  # ignore trailing spaces


N = ni()

AB_array = [na() for _ in range(N)]

# print(AB_array)

plus_dic = {}
minus_dic = {}
ans = 1
fish_count = 0
mod = 10 ** 9 + 7
for ab in AB_array:
    a, b = ab
    if a == 0 and b == 0:
        continue
    fish_count += 1
    if a == 0:
        vec = (0, 1)
        if vec in plus_dic:
            plus_dic[vec] += 1
        else:
            plus_dic[vec] = 1
    elif b == 0:
        vec = (1, 0)
        if vec in minus_dic:
            minus_dic[vec] += 1
        else:
            minus_dic[vec] = 1
    c = math.gcd(a, b)
    a = a // c
    b = b // c
    if a < 0:
        a *= -1
        b *= -1
    if b > 0:
        vec = (a, b)
        if vec in plus_dic:
            plus_dic[vec] += 1
        else:
            plus_dic[vec] = 1
    else:
        vec = (a, b)
        if vec in minus_dic:
            minus_dic[vec] += 1
        else:
            minus_dic[vec] = 1


# print(plus_dic, minus_dic, fish_count)

for k, vp in plus_dic.items():
    x, y = k
    if (y, -x) in minus_dic:
        vm = minus_dic[(y, -x)]
        ans = ans * (pow(2, vp, mod) + pow(2, vm, mod) - 1) % mod
        fish_count -= (vp + vm)

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

print((ans - 1) % mod)

Submission status: Runtime Error

Solution code:
from math import gcd
from collections import defaultdict

N = int(input())
d = {}
MOD = 10**9+7

for _ in range(N):
    A, B = map(int, input().split())
    g = gcd(A, B)
    A//=g
    B//=g
    if (A, B) in d:
        d[(A, B)] += 1
    else:
        d[(A, B)] = 1

b = 1
used = defaultdict(int)

for (i, j), v in d.items():
    if used[(i, j)]:continue
    buf = 0
    if (-j, i) in d or (j, -i) in d:
        if (-j, i) in d:
            used[(-j, i)] = 1
            buf += pow(2, d[(-j, i)], MOD)+pow(2, v, MOD)-1
        if (j, -i) in d:
            used[(j, -i)] = 1
            buf += pow(2, d[(j, -i)], MOD)+pow(2, v, MOD)-1
        b *= buf
    else:
        b *= pow(2, v, MOD)
    b %= MOD
b -= 1
b %= MOD
print(b)