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:
## coding: UTF-8
import math
MOD = 10**9+7
N = int(input())
A = []
for i in range(N):
    A.append(list(map(int,input().split()))) 
d = dict()
'''
def bisection(a, n, p):
    #二分累乗法によるO(log p)計算
    bin_str = format(n, 'b')
    res = 1
    tmp = a
    for i in range(1, len(bin_str)+1):
        if(bin_str[(-1)*i] == '1'):
            res = res * tmp % p
        tmp = tmp * tmp % p
    return res
'''
d['a'] = 0
d['b'] = 0
d['c'] = 0

for i in range(N):
    #l = list(map(int,input().split()))
    l = A[i]
    if(l[0] == 0):
        if(l[1] == 0):
            d['c'] += 1
        else:
            d['b'] += 1
    elif(l[1] == 0):
        d['a'] += 1
    else:
        g = math.gcd(l[0], l[1])
        a = int(l[0]/g)
        b = int(l[1]/g)
        if(a<0):
            p = (-1*a, -1*b)
        else:
            p = (a, b)
        if p in d:
            d[p] += 1
        else:
            d[p] = 1
    #print('i:{}, l[0]:{}, l[1]:{}, d:{}'.format(i, l[0], l[1], d))

#res = 1
a = d.pop('a')
b = d.pop('b')
#あとで二分累乗法に変換する4 
#if(a > 0 and b > 0):
    #a, b>=0 より、a+b>=0, よってa==0 and b == 0でなければ、a >0 or b> 0
    #ma = bisection(2, a, MOD)
    #mb = bisection(2, b, MOD)
    #res *= ma + mb -1
res *= pow(2, a, MOD) + pow(2, b, MOD) - 1
res %= MOD

#elif(a == 0 and b > 0):
    #mb = bisection(2, b, MOD)
    #res *= mb
    #res %= MOD
#elif(a > 0 and b == 0):
    #ma = bisection(2, a, MOD)
    #res *= ma
    #res %= MOD
c = d.pop('c')

#print('a:{}, b:{}, c:{}'.format(a,b,c))
#print('d:{}, len(d):{}'.format(d, len(d)))
#print('res', res)

while len(d) > 0:
    s, v = d.popitem()
    if(s[1] < 0):
        opposite = (-1*s[1], s[0])
    else:
        opposite = (s[1], -1*s[0])
    if opposite in d:
        t = d.pop(opposite)
        #print('s:{}, v:{}, opposite:{}, t:{}, d:{}, len(d):{}'.format(s, v, opposite, t, d, len(d)))
        #mv = bisection(2, v, MOD)
        #mt = bisection(2, t, MOD)        
        #res *= mv + mt - 1
        res *= pow(2, v, MOD) + pow(2, t, MOD) - 1
        res %= MOD
    else:
        #print('s:{}, v:{}, opposite:{},       d:{}, len(d):{}'.format(s, v, opposite, d, len(d)))
        #mv = bisection(2, v, MOD)        
        #res *= mv
        res *= pow(2, v, MOD)
        res %= MOD
    #print('res', res)


res += c
res %= MOD
res = (res + MOD - 1) % MOD

print(res)

Submission status: Runtime Error

Solution code:
from collections import Counter
from math import gcd
n = int(input())
lst = []
cnt = 0

for i in range(n):
    a,b = map(int,input().split())
    if a == b == 0:
        cnt += 1
    elif b > 0:
        lst.append((a/gcd(a,b),b/gcd(a,b)))
    elif b < 0:
        lst.append((-a/gcd(a,b),-b/gcd(a,b)))
    else:
        lst.append(1,0)

c = Counter(lst)
ans = 1
for k,v in c.items():
    if k[0] <= 0 or k == (1,0):
        continue
    j = c[(-k[1],k[0])]
    ans *= 2**j+2**v-1
    c[k] = 0
    if c[(-k[1],k[0])]:
        c[(-k[1],k[0])] = 0
for k,v in c.items():
    if k[0] == 0 or v == 0:
        continue
    ans *= 2**v
ans *= 2**c[(0,1)]+2**c[(1,0)]-1
print(ans-1)

Submission status: Runtime Error

Solution code:
from collections import Counter
from math import gcd
n = int(input())
lst = []
cnt = 0

for i in range(n):
    a,b = map(int,input().split())
    if a == b == 0:
        cnt += 1
    elif b > 0:
        lst.append((a/gcd(a,b),b/gcd(a,b)))
    elif b < 0:
        lst.append((-a/gcd(a,b),-b/gcd(a,b)))
    else:
        lst.append(1,0)

c = Counter(lst)
ans = 1
for k,v in c.items():
    if k[0] < 0:
        continue
    j = c[(-k[1],k[0])]
    ans *= 2**j+2**v-1
    c[k] = 0
    if c[(-k[1],k[0])]:
        c[(-k[1],k[0])] = 0
for k,v in c.items():
    if v == 0:
        continue
    ans *= 2**v

print(ans-1)

Submission status: Runtime Error

Solution code:
import math
import fractions
#fractions.gcd(x,y)
def lcm(a,b): return a*b//fractions.gcd(a,b)

n=int(input())
w={}
for i in range(n):
    a,b=map(int,input().split())
    x=fractions.gcd(abs(a),abs(b))
    #if x==1:
    #    print(a,b)
    #else:
    #    print(a//x,b//x)
    if (a//x,b//x) in w:
        w[(a//x,b//x)]+=1
    else:
        w[(a//x,b//x)]=1
#print(w)
print(0)

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
from collections import defaultdict

MOD = 1000000007

def factorial(n, mod=None, memo=False):
    if memo:
        factorial.memo = [1] * (n + 1)
        for i in range(1, n + 1):
            if mod is None:
                factorial.memo[i] = i * factorial.memo[i - 1]
            else:
                factorial.memo[i] = i * factorial.memo[i - 1] % mod
    return factorial.memo[n]

def choose(n, r, mod=None):
    a = factorial(n)
    b = factorial(r)
    c = factorial(n - r)
    if mod is None:
        res = a // b // c
    else:
        # fermat's little theorem
        res = a * pow(b, mod - 2, mod) * pow(c, mod - 2, mod) % mod
    return res

class Sardine:
    def __init__(self, a, b):
        if a == 0 and b == 0:
            self.type_ = 0
        elif a == 0:
            self.type_ = 'a'
        elif b == 0:
            self.type_ = 'b'
        else:
            self.type_ = Fraction(a, b)

def sigma_choose(v):
    ans = 0
    i = 1
    while i <= v:
        ans += choose(v, i, MOD)
        ans %= MOD
        # for next
        i += 1
    return ans

def combi(x, y):
    res = sigma_choose(x) + sigma_choose(y) + 1
    #print('res') # debug
    #print(res) # debug
    return res

def calc_cross_type(frac):
    cross = Fraction(-1 * frac.denominator, frac.numerator)
    #print('cross', frac, cross) # debug
    return cross

def count_up(types):
    ans = 0
    seed = 1
    seed *= combi(types['a'], types['b'])
    keys = list(types.keys())
    for type_ in keys:
        if not (type(type_) == Fraction and type_ > 0):
            continue
        count = types[type_]
        cross_type = calc_cross_type(type_)
        cross_count = types[cross_type]
        seed = (seed * combi(count, cross_count)) % MOD
    ans += seed
    ans += types[0]
    return ans - 1 # remove no sellect

if __name__ == '__main__':
    factorial(2 * 10 ** 5, MOD, True)
    n = int(input())
    types = defaultdict(lambda: 0)
    for _ in range(n):
        a, b = list(map(int, input().split()))
        sardine = Sardine(a, b)
        types[sardine.type_] += 1
        cross_type = calc_cross_type(sardine.type_)
        types[cross_type]
    #print('types') # debug
    #pp(types) # debug
    ans = count_up(types)
    #print('ans') # debug
    print(ans)




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

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from math import gcd

n = int(input())
L = []
for i in range(n):
    l = list(map(int, input().split()))
    L.append(l)

Mod = 10 ** 9 + 7

Pow2 = [1]
for i in range(n):
    Pow2.append(Pow2[-1]*2)

def kikaku(a, b):
    g = gcd(a, b)
    a //= g
    b //= g
    if a < 0:
        return - a, -b
    return a, b

Dpos = defaultdict(int)
Dneg = defaultdict(int)

c = 0
for l in L:
    a, b = kikaku(l[0], l[1])
    if a == b == 0:
        c += 1
    elif b > 0:
        Dpos[(b, -a)] += 1
        Dneg[(b, -a)] += 0
    else:
        Dpos[(a, b)] += 0
        Dneg[(a, b)] += 1

r = 1
for k, v in Dpos.items():
    j = Dneg[k]
    if v > 0 and j > 0:
        r = r * (Pow2[v] + Pow2[j] - 1) % Mod
#    elif v == 0 and j == 0:
#        pass
    else:
        r = r * 2 % Mod 
ans = (r + c - 1) % Mod
print(ans)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from math import gcd

n = int(input())
L = []
for i in range(n):
    l = list(map(int, input().split()))
    L.append(l)

Mod = 10 ** 9 + 7

Pow2 = [1]
for i in range(n):
    Pow2.append(Pow2[-1]*2)

def kikaku(a, b):
    g = gcd(a, b)
    a //= g
    b //= g
    if a < 0:
        return - a, -b
    return a, b

Dpos = defaultdict(int)
Dneg = defaultdict(int)

c = 0
for l in L:
    a, b = kikaku(l[0], l[1])
    if a == b == 0:
        c += 1
    elif b > 0:
        Dpos[(b, -a)] += 1
        Dneg[(b, -a)] += 0
    else:
        Dpos[(a, b)] += 0
        Dneg[(a, b)] += 1

r = 1
for k, v in Dpos.items():
    j = Dneg[k]
    if v > 0 and j > 0:
        r = r * (Pow2[v] + Pow2[j] - 1) % Mod
    elif v == 0 and j == 0:
        pass
    else:
        r = r * 2 % Mod 
ans = (r + c - 1) % Mod
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

l = []

for i in range(n):
  ll = map(int, input().split())
  l.append(ll)
  
c = 0

for i in range(m):
  for j in range(m-i+1):
    if not i == j:
      if l[i][0] *l[j][0] + l[i][1] *l[j][1] == 0:
        c = 1 + c % 1000000007
        
mm = m % 1000000007

print(mm-c)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
#E

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def comb(n, r):
    return fact[n]*pow(fact[n-r], mod-2, mod)*pow(fact[r], mod-2, mod) % mod
n = I()
ab = [LI() for _ in range(n)]
ans = pow(2, n, mod) - 1
fact = [1]*(n+1)
for i in range(1, n+1):
    fact[i] = i * fact[i-1]
    fact[i] %= mod

x = []
y = []
for a, b in ab:
    if a == 0 and b == 0:
        ans -= pow(2, n-1, mod) - 1
        ans %= mod
        n -= 1
    elif a == 0:
        x.append(0)
        y.append(-inf)
    elif b == 0:
        x.append(inf)
        y.append(0)
    else:
        x.append(a/b)
        y.append(-b/a)
lst = defaultdict(lambda : 0)
z = defaultdict(lambda : 0)
for i,j in enumerate(x):
    if z[j]:
        lst[j] = max(lst[j], z[j]+1)
    z[y[i]] += 1

for i in lst.values():
    j = 0
    while j + 1 < i:
        ans -= comb(i, j+2) * pow(2, n - (i-(j+2)) - (j+2), mod)
        ans %= mod
        j += 1
    n -= i
print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd

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

zero = 0
for _ in range(N):
    a,b = map(int, input().split())
    if  a ==0 and b == 0:
        zero += 1
        continue
    elif a == 0:
        key = (0,1)
    elif b == 0:
        key = (1,0)
    else:
        if a<0:
            a=-a 
            b=-b
        g = gcd(a,abs(b))
        key = (a//g,b//g)
    
    if key not in dic:
        dic[key]=0

    dic[key] +=1

ans = 1
for k1, v1 in dic.items():
    if v1 ==0:
        continue

    if k1[1] >0:
        k2 = (k1[1],-k1[0])
    else:
        k2 = (-k1[1],k1[0])

    if k2 not in dic:
        ans *= 2**v1
        ans %= mod
    else:
        ans *= ((2**v1-1)) %mod) + ((2**dic[k2]-1)) %mod) +1
        ans %= mod
        dic[k2]=0

ans = (ans + zero -1 )%mod
print(ans)

Submission status: Runtime Error

Solution code:
import collections

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

mod=10**9+7
n=int(input())
dic=collections.defaultdict(int)
cnt=0
for _ in range(n):
  a,b=map(int,input().split())
  if a!=0 and b!=0:
    g=gcd(abs(a),abs(b))
    if a*b>0:
      dic[(abs(a)//g,abs(b)//g)]+=1
    else:
      dic[(-abs(a)//g,abs(b)//g)]+=1
  else:
    if a==0 and b==0:
      cnt+=1
    elif a==0:
      dic[(0,1)]+=1
    elif b==0:
      dic[(1,0)]+=1
ans=1
s=set()
for a,b in dic.keys():
  if (a,b) in s:
    continue
  s.add((a,b))
  if a!=0 and b!=0:
    if a>0:
      s.add((-b,a))
      cnt1=dic[(a,b)]
      cnt2=dic[(-b,a)]
      ans*=(pow(2,cnt1,mod)+pow(2,cnt2,mod)-1)%mod
      ans%=mod
    elif a<0:
      s.add((b,-a))
      cnt1=dic[(a,b)]
      cnt2=dic[(b,-a)]
      ans*=(pow(2,cnt1,mod)+pow(2,cnt2,mod)-1)%mod
      ans%=mod
  else:
    s.add((b,a))
    cnt1=dic[(a,b)]
    cnt2=dic[(b,a)]
    ans*=(pow(2,cnt1,mod)+pow(2,cnt2,mod)-1)%mod
    ans%=mod
print((ans+cnt-1)%mod)

Submission status: Runtime Error

Solution code:
import sys
def input(itr=iter(sys.stdin.readlines())):  # pylint: disable= redefined-builtin
    return next(itr).rstrip('\n\r')
###############################################################################

import collections
import math as m
from fractions import Fraction

MOD = 1000000007

N = int(input())
Sardine = collections.namedtuple("Sardine", "A B")
sardines = [Sardine(*map(int, input().split())) for _ in range(N)]

def slope(sardine):
    if sardine.A == sardine.B == 0:
        return None
    elif sardine.B == 0:
        return m.inf
    else:
        return Fraction(sardine.A, sardine.B)

def perpendicular(slope):
    if slope == 0:
        return m.inf
    elif slope == m.inf:
        return 0
    else:
        return -1 / slope

groups = collections.Counter(slope(s) for s in sardines)
if groups[None]:
    zeroes = groups[None]
    del groups[None]

ways = 1
while groups:
    slope, count = groups.popitem()
    perp_slope = perpendicular(slope)
    perp_count = groups[perp_slope]

    ways *= ((1<<count) + (1<<perp_count) - 1) % MOD
    ways %= MOD

    del groups[perp_slope]

output = (ways-1 + zeroes) % MOD
print(output)

Submission status: Runtime Error

Solution code:
import sys
def input(itr=iter(sys.stdin.readlines())):  # pylint: disable= redefined-builtin
    return next(itr).rstrip('\n\r')
###############################################################################

import collections
import math as m
from fractions import Fraction

MOD = 1000000007

N = int(input())
Sardine = collections.namedtuple("Sardine", "A B")
sardines = [Sardine(*map(int, input().split())) for _ in range(N)]

def slope(sardine):
    if sardine.A == sardine.B == 0:
        return None
    elif sardine.B == 0:
        return m.inf
    else:
        return Fraction(sardine.A, sardine.B)

def perpendicular(slope):
    if slope == 0:
        return m.inf
    elif slope == m.inf:
        return 0
    else:
        return -1 / slope

groups = collections.Counter(slope(s) for s in sardines)
del groups[None]

ways = 1
while groups:
    slope, count = groups.popitem()
    perp_slope = perpendicular(slope)
    perp_count = groups[perp_slope]

    ways *= (1<<count + 1<<perp_count - 1) % MOD
    ways %= MOD

    del groups[perp_slope]

print((ways-1)%MOD)

Submission status: Runtime Error

Solution code:
import sys
def input(itr=iter(sys.stdin.readlines())):  # pylint: disable= redefined-builtin
    return next(itr).rstrip('\n\r')
###############################################################################

import collections
import math as m
from fractions import Fraction

MOD = 1000000007

N = int(input())
Sardine = collections.namedtuple("Sardine", "A B")
sardines = [Sardine(*map(int, input().split())) for _ in range(N)]

def slope(sardine):
    if sardine.A == 0:
        return m.inf
    else:
        return Fraction(sardine.A, sardine.B)

def perpendicular(slope):
    if slope == 0:
        return m.inf
    elif slope == m.inf:
        return 0
    else:
        return -1 / slope

groups = collections.Counter()
for s in sardines:
    groups[slope(s)] += 1

ways = 1
while groups:
    slope, count = groups.popitem()
    perp_slope = perpendicular(slope)
    perp_count = groups[perp_slope]

    ways *= (2**count + 2**perp_count - 1) % MOD
    ways %= MOD

    del groups[perp_slope]

print((ways-1)%MOD)

Submission status: Runtime Error

Solution code:
import sys
def input(itr=iter(sys.stdin.readlines())):  # pylint: disable= redefined-builtin
    return next(itr).rstrip('\n\r')
###############################################################################

import collections
import math as m
from fractions import Fraction

MOD = 1000000007

N = int(input())
Sardine = collections.namedtuple("Sardine", "A B")
sardines = [Sardine(*map(int, input().split())) for _ in range(N)]

def slope(sardine):
    if sardine.A == 0:
        return m.inf
    else:
        return Fraction(sardine.A, sardine.B)

def perpendicular(slope):
    if slope == 0:
        return m.inf
    elif slope == m.inf:
        return 0
    else:
        return -1 / slope

groups = collections.defaultdict(list)
for s in sardines:
    groups[slope(s)].append(s)

ways = 1
while groups:
    slope, sardines = groups.popitem()
    perp_slope = perpendicular(slope)
    perp_sardines = groups[perp_slope]

    ways *= (2**len(sardines) + 2**len(perp_sardines) - 1) % MOD
    ways %= MOD

    del groups[perp_slope]

print(ways-1)

Submission status: Runtime Error

Solution code:
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード
    #input
    import numpy as np
    N = int(input())
    C = np.zeros([N, 2], int)

    for i in range(N):
        A, B = map(int, input().split())
        C[i] = [A, B]

    #output
    #A_i * A_j + B_i * B_j = 0
    mod = 1000000007
    #制限なく1匹以上を選ぶ選び方はpow(2, N) - 1通り
    #iに対して内積が0になるものがa通りとする。

    answer = pow(2, N) - 1
    answer %= mod
    for i in range(N):
        D = C[i]
        E = np.dot(C, D)
        a = N - np.count_nonzero(E)
        if a == 1:
            answer -= pow(2, N-2)//2
        elif a > 1:
            answer -= pow(2, N-a-1)//pow(2, a)

    print(answer)
    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

N = int(input())
A = dict()
ngs = 0
zi = 0
for i in range(N):
    a,b = map(int,input().split())
    if a == 0 and b != 0:
        a,b = 0,1
    elif b == 0 and a != 0:
        a,b = 1,0
    elif b == 0 and a == 0:
        zi += 1
    else:
        x = gcd(a,b)
        a = a // x
        b = b // x
        if b < 0:
            a,b = -a,-b
    if (a,b) not in A.keys():
        A[(a,b)] = 1
    else:
        A[(a,b)] += 1
    if (b,-a) in A.keys():
        ngs += A[(b,-a)]
 
 
fac = [1,1]
inv = [1,1]
finv = [1,1]
 
MOD = 100000007
for i in range(2,N+1):
    tmp = fac[-1] * i % MOD
    fac.append(tmp)
    tmp = MOD - inv[MOD % i] * (MOD // i) % MOD
    inv.append(tmp)
    tmp = finv[-1] * inv[i] % MOD
    finv.append(tmp)

    ret = 0
N -= zi
# n = 1
ret += N
retlist = [1,N]
ret += ((fac[N] * finv[2] % MOD) * finv[N-2] % MOD - ngs) % MOD
for n in range(3,N+1):
    tmp = (fac[N] * finv[n] % MOD) * finv[N-n] % MOD
    tmp2 = (fac[N-2] * finv[n-2] % MOD) * finv[max(N-n-2,1)] % MOD * ngs % MOD
    debug = (tmp - tmp2) % MOD
    retlist.append(tmp)
    ret += debug 
    ret = ret % MOD
print(ret)

Submission status: Runtime Error

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

N = int(input())
A = dict()
ngs = 0
zi = 0
for i in range(N):
  a,b = map(int,input().split())
  if a == 0 and b != 0:
    a,b = 0,1
  elif b == 0 and a != 0:
    a,b = 1,0
  elif b == 0 and a == 0:
    zi += 1
  else:
  	x_= gcd(a,b)
  	a,b = a//x_,b//x_
    if b < 0:
      a,b = -a,-b
  if (a,b) not in A.keys():
    A[(a,b)] = 1
  else:
    A[(a,b)] += 1
  if (b,-a) in A.keys():
    ngs += A[(b,-a)]


fac = [1,1]
inv = [1,1]
finv = [1,1]

MOD = 100000007
for i in range(2,N+1):
    tmp = fac[-1] * i % MOD
    fac.append(tmp)
    tmp = MOD - inv[MOD % i] * (MOD // i) % MOD
    inv.append(tmp)
    tmp = finv[-1] * inv[i] % MOD
    finv.append(tmp)

ret = 0
N -= zi
# n = 1
ret += N
retlist = [1,N]
for n in range(2,N+1):
  tmp = (fac[N] * finv[n] % MOD) * finv[N-n] % MOD
  retlist.append(tmp)
  ret += tmp - retlist[n-2] * ngs
print(ret)

Submission status: Runtime Error

Solution code:
_, *e = [[*map(int, t.split())] for t in open(0)]
ans = 1
mod = 10 ** 9 + 7
slope_dict = {}
zeros = 0
vect_x = 0
for x, y in e:
    if x == y == 0:
        zeros += 1
    elif y == 0:
        vect_x += 1
    else:
        slope_dict[x/y] = slope_dict.get(x/y, 0) + 1
ans = ans * (pow(2, vect_x, mod) + pow(2, slope_dict.get(0, 0), mod) - 1) % mod
slope_dict.pop(0)
for k in slope_dict:
    if -1/k in slope_dict:
        if k >= 1:
            ans = ans * (pow(2, slope_dict[k], mod) +
                         pow(2, slope_dict[-1/k], mod) - 1) % mod
    else:
        ans = ans * (pow(2, slope_dict[k], mod)) % mod
print(ans + zeros - 1 % mod)

Submission status: Runtime Error

Solution code:
_, *e = [[*map(int, t.split())] for t in open(0)]
ans = 1
mod = 10 ** 9 + 7
slope_dict = {}
zeros = 0
vect_x = 0
for x, y in e:
    if x == y == 0:
        zeros += 1
    elif y == 0:
        vect_x += 1
    else:
        slope_dict[x/y] = slope_dict.get(x/y, 0) + 1
ans = ans * (pow(2, vect_x, mod) + pow(2, slope_dict.get(0, 0), mod) - 1) % mod
slope_dict.popitem(0)
for k in slope_dict:
    if -1/k in slope_dict:
        if k >= 1:
            ans = ans * (pow(2, slope_dict[k], mod) +
                         pow(2, slope_dict[-1/k], mod) - 1) % mod
    else:
        ans = ans * (pow(2, slope_dict[k], mod)) % mod
print(ans + zeros - 1 % mod)

Submission status: Runtime Error

Solution code:
[n], *e = [[*map(int, t.split())] for t in open(0)]
ans = 0
mod = 10 ** 9 + 7
slope_dict = {}
for x, y in e:
    a = 2**slope_dict.get(x/y, 0)
    b = 2**slope_dict.get(-y/x, 0)
    ans = ((ans * (2 * a + b - 1) + a)/(a + b - 1))  # % mod
    slope_dict[x/y] = slope_dict.get(x/y, 0) + 1

print(int(ans % mod))

Submission status: Runtime Error

Solution code:
[n], *e = [[*map(int, t.split())] for t in open(0)]
ans = 0
mod = 10 ** 9 + 7
slope_dict = {}
for x, y in e:
    a = 2**slope_dict.get(x/y, 0)
    b = 2**slope_dict.get(-y/x, 0)
    ans = ((ans * (2 * a + b - 1) + a)/(a + b - 1)) % mod
    slope_dict[x/y] = slope_dict.get(x/y, 0) + 1

print(int(ans))

Submission status: Runtime Error

Solution code:
from math import gcd 
n=int(input())
mod = 10**9+7
count = {}

num=0
for _ in range(n):
    a,b = map(int,input().split())
    if a==0 and b==0:
        num+=1
        continue
    if a*b != 0:
        g=gcd(a,b)*(b//abs(b))
    elif a != 0:
        g=a
    else:
        g=b
        
    l=a//g,b//g
    count[l]=count.get(l,0)+1
        
mem=set()
ans=1
for (x,y),z in count.items():
    k=(-1*x//abs(x)*y,abs(x))
    if k in mem:
        continue
    mem.add((x,y))
    ans*=(pow(2,z)+pow(2,count.get(k,0))-1)
    ans%=mod

print((ans+num-1)%mod)

Submission status: Runtime Error

Solution code:
from math import gcd 
n=int(input())
mod = 10**9+7
count = {}

num=0
for _ in range(n):
    a,b = map(int,input().split())
    if a==0 and b==0:
        num+=1
        continue
    if a*b != 0:
        g=gcd(a,b)*(b//abs(b))
    elif a != 0:
        g=a
    else:
        g=b
        
    x=a//g,b//g
    count[x]=count.get(x,0)+1
        
mem=set()
ans=1
for (x,y),z in count.items():
    k=(-1*x//abs(x)*y,abs(x))
    if k in mem:
        continue
    mem.add((x,y))
    ans*=(pow(2,z)+pow(2,count.get(k,0))-1)
    ans%=mod

print((ans+num-1)%mod)

Submission status: Runtime Error

Solution code:
from math import gcd 
n=int(input())
mod = 10**9+7
count = {}

num=0
for _ in range(n):
    a,b = map(int,input().split())
    if a==0 and b==0:
        num+=1
        continue
    if a*b != 0:
        g=gcd(a,b)*(b//abs(b))
    elif a != 0:
        g=a
    else:
        g=b
        
    x=a//g,b//g
    count[x]=count.get(x,0)+1
        
mem=set()
ans=1
for (x,y),z in count.items():
    k=(-1*x//abs(x)*y,abs(x))
    if k in mem:
        continue
    mem.add((x,y))
    ans*=pow(2,z)+pow(2,count.get(k,0))-1
    ans%=mod

print((ans+num-1)%mod)

Submission status: Runtime Error

Solution code:
from math import gcd 
n=int(input())
mod = 10**9+7
count = {}

num=0
for _ in range(n):
    a,b = map(int,input().split())
    if a==0 and b==0:
        num+=1
        continue
    if a*b != 0:
        g=gcd(a,b)*(b//abs(b))
    elif a != 0:
        g=a
    else:
        g=b
        
    x=a//g,b//g
    count[x]=count.get(x,0)+1
        
mem=set()
ans=1
for (x,y),z in count.items():
    if (-1*x//abs(x)*y,abs(x)) in mem:
        continue
    mem.add((x,y))
    ans*=pow(2,z)+pow(2,count.get((-1*x//abs(x)*y,abs(x)),0))-1
    ans%=mod

print((ans+num-1)%mod)

Submission status: Runtime Error

Solution code:
from math import gcd 
n=int(input())
mod = 10**9+7
count = {}

for _ in range(n):
    a,b = map(int,input().split())
    if a==0 and b==0:
        continue
    if a*b != 0:
        g=gcd(a,b)*b//abs(b)
    elif a != 0:
        g=a
    else:
        g=b
        
    x=a//g,b//g
    count[x]=count.get(x,0)+1
        
mem=set()
ans=1
for (x,y),z in count.items():
    if (-1*x//abs(x)*y,abs(x)) in mem:
        continue
    mem.add((x,y))
    ans*=pow(2,z)+pow(2,count.get((-1*x//abs(x)*y,abs(x)),0))-1
    ans%=mod

print((ans-1)%mod)

Submission status: Runtime Error

Solution code:
from math import gcd 
n=int(input())
mod = 10**9+7
count = {}

for _ in range(n):
    a,b = map(int,input().split())
    if a==0 and b==0:
        continue
    if a*b != 0:
        g=gcd(a,b)*b//abs(b)
    elif a != 0:
        g=a
    else:
        g=b
        
    x=a//g,b//g
    count[x]=count.get(x,0)+1
        
mem=set()
ans=1
for (x,y),z in count.items():
    if (-1*x//abs(x)*y,abs(x)) in mem:
        continue
    mem.add((x,y))
    ans*=pow(2,z)+pow(2,count.get((-1*x//abs(x)*y,abs(x))),0)-1
    ans%=mod

print((ans-1)%mod)

Submission status: Runtime Error

Solution code:
from math import gcd 
n=int(input())
mod = 10**9+7
count = {}

for _ in range(n):
    a,b = map(int,input().split())
    if a==0 and b==0:
        continue
    if a*b != 0:
        g=gcd(a,b)*b//abs(b)
    elif a != 0:
        g=a
    else:
        g=b
        
    x=a//g,b//g
    count[x]=count.get(x,0)+1
        
mem=set()
ans=1
for (x,y),z in count.items():
    if (-1*x//abs(x)*y,abs(x)) in mem:
        continue
    mem.add((x,y))
    ans*=pow(2,z)+pow(2,count.get((-1*x//abs(x)*y,abs(x)),0)-1
    ans%=mod

print((ans-1)%mod)

Submission status: Runtime Error

Solution code:
from math import gcd 
n=int(input())
mod = 10**9+7
count = {}

for _ in range(n):
    a,b = map(int,input().split())
    if a==0 and b==0:
        continue
    if a*b != 0:
        g=gcd(a,b)*b//abs(b)
    elif a != 0:
        g=a
    else:
        g=b
        
    x=a//g,b//g
    count[x]=count.get(x,0)+1
        
mem=set()
ans=1
for (x,y),z in count.items():
    if (-1*x//abs(x)*y,abs(x)) in mem:
        continue
    mem.add((x,y))
    ans*=2**z+2**count.get((-1*x//abs(x)*y,abs(x)),0)-1
    ans%=mod

print((ans-1)%mod)

Submission status: Runtime Error

Solution code:
from collections import Counter
n=int(input())
mod = 10**9+7
mem = set()
count = []
def gcd(a,b):
    a_=abs(a)
    b_=abs(b)
    if a == 0 and b == 0:
        return 1
    elif a == 0 or b == 0:
        return max(a_,b_)
    else:
        k=max(a_,b_)%min(a_,b_)
        if k==0:
            return min(a_,b_)
        else:
            return gcd(min(a_,b_),k)

for _ in range(n):
    a,b = map(int,input().split())
    g=gcd(a,b)
    a_=abs(a//g)
    b_=abs(b//g)
    if a*b>=0:
        mem.add((a_,b_))
        count.append(str(a_)+"/"+str(b_))
    else:
        mem.add((-a_,b_))
        count.append(str(-a_)+"/"+str(b_))
        
c=Counter(count)
ans=1
num=0
while mem:
    p,q = mem.pop()
    if p>=0:
        p_=p
        q_=-q
    else:
        p_=abs(p)
        q_=q
    k=str(q_)+"/"+str(p_)
    l=str(p)+"/"+str(q)
    if k in c:
        ans*=2**c[k]+2**c[l]-1
        ans%=mod
        mem.remove((q_,p_))
    else:
        num+=c[l]
ans*=2**num
ans%=mod
print(ans-1)

Submission status: Runtime Error

Solution code:
[n], *e = [[*map(int, t.split())] for t in open(0)]
ans = 0
count = 0
slope_dict = {}
for x, y in e:
    count += 1
    if x/y in slope_dict:
        slope_dict[x/y] += 1
    else:
        slope_dict[x/y] = 1
    ans = ans + \
        2**(count - 1 - (0 if -y/x not in slope_dict else slope_dict[-y/x]))
print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd
from sys import setrecursionlimit
setrecursionlimit(4100000)
mod = 10 ** 9 + 7
n = int(input())

zeros = 0
d = {}
for i in range(n):
    x, y = map(int, input().split())
    if x == 0 and y == 0:
        zeros += 1
    else:
        g = gcd(x, y)
        x, y = x / g, y / g
        if (y < 0) or (y == 0 and x < 0): 
            x, y = -x, -y
        else: 
            pass
        if x <= 0:
            sq = True   #second quadrant
            x, y = y, -x
        else:
            sq = False
        if sq == True:
            if (x, y) in d:
                d[(x, y)][1] += 1
            else:
                d[(x, y)] = [0, 1]
        else:
            if (x, y) in d:
                d[(x, y)][0] += 1
            else:
                d[(x, y)] =[1, 0] 

#繰り返し2乗法
def  mod_pow(a:int, b:int, mod:int)->int:
    if b == 0:
        return 1 % mod
    elif b % 2 == 0:
        return (mod_pow(a, b//2, mod) ** 2) % mod
    elif b == 1:
        return a % mod
    else:
        return ((mod_pow(a, b//2, mod) ** 2) * a) % mod
#print(d)

ans = 1
for (i, j) in tuple(d.values()):
    now = 1
    now = (now + mod_pow(2, i, mod) - 1) % mod
    now = (mow + mod_pow(2, j, mod) - 1) % mod
    ans = (ans * now) % mod
    
ans -= 1
ans += zeros % mod
ans = ans % mod
print(ans)