Problem:


Score: 500 points

Problem Statement

We have caught N sardines. The deliciousness and fragrantness of the i-th sardine is A_i and B_i, respectively.

We will choose one or more of these sardines and put them into a cooler. However, two sardines on bad terms cannot be chosen at the same time.

The i-th and j-th sardines (i \neq j) are on bad terms if and only if A_i \cdot A_j + B_i \cdot B_j = 0.

In how many ways can we choose the set of sardines to put into the cooler? Since the count can be enormous, print it modulo 1000000007.

Constraints

All values in input are integers.

1 \leq N \leq 2 \times 10^5

-10^{18} \leq A_i, B_i \leq 10^{18}

Input

Input is given from Standard Input in the following format:

N
A_1 B_1
:
A_N B_N

Output

Print the count modulo 1000000007.

Sample Input 1

3
1 2
-1 1
2 -1

Sample Output 1

5

There are five ways to choose the set of sardines, as follows:

The 1-st

The 1-st and 2-nd

The 2-nd

The 2-nd and 3-rd

The 3-rd

Sample Input 2

10
3 2
3 2
-1 1
2 -1
-3 -9
-8 12
7 7
8 1
8 2
8 4

Sample Output 2

479



Sample input:
3
1 2
-1 1
2 -1


Sample output:
5

Submission status: Wrong Answer

Solution code:
import 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)
        if a == b == 0:
            if (0, 0) in d:
                d[(0, 0)] += 1
            else:
                d[(0, 0)] = 1
            continue

        if a != 0 and b != 0:
            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
        elif a == 0:
            ai, bi = 0, 1
            aj, bj = 1, 0
        elif b == 0:
            ai, bi = 1, 0
            aj, bj = 0, 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:
        if k != (0, 0):
            n = modpow(2, d[k][0], mod)
            m = modpow(2, d[k][1], mod)

            ans = ans * (n + m - 1) % mod
    ans -= 1
    if (0, 0) in d:
        ans = (ans + d[(0, 0)]) % mod

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
input = sys.stdin.buffer.readline

N = int(input())

def gcd(n, m):
    if m == 0:
        return n
    return gcd(m, n % m)

def make(a, b):
    if a == b == 0:
        return (0, 0, 0)

    s = 1 if a * b >= 0 else -1
    a, b = abs(a), abs(b)

    g = gcd(a, b)
    a //= g
    b //= g

    return (a, b, s)

ABS = Counter([make(*map(int, input().split())) for _ in range(N)])
K = list(ABS.keys())

ans = 1
MOD = 10**9 + 7

for a, b, s in K:
    if s == 0:
        ans = (ans * (ABS[(0, 0, 0)] + 1)) % MOD
        continue
    p = ABS[(a, b, s)]
    n = ABS[(b, a, -s)]

    ABS[(a, b, s)] = 0
    ABS[(b, a, -s)] = 0

    cnt = pow(2, p, MOD) + pow(2, n, MOD) - 1
    ans = (ans * cnt) % MOD

print((ans - 1) % MOD)

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations, combinations_with_replacement
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    n = inp()
    dic = defaultdict(int)
    dic1 = defaultdict(int)
    for _ in range(n):
        a,b = inpm()
        if a != 0 and b == 0:
            a = 1
        elif a == 0 and b != 0:
            b = 1
        else:
            if not (a==0 and b==0):
                m = gcd(a,b)
                a //= m
                b //= m
        if a < 0 and b < 0:
            a = -a
            b = -b
        if a < 0 and b > 0:
            a = -a
            b = -b
        index = ' '.join([str(a),str(b)])
        dic[index] += 1
        dic1[index] += 1
    ans = 1
    dic2 = defaultdict(int)
    for e in dic:
        a,b = map(int,e.split())
        if a == 0 or b == 0:
            continue
        flag = 0
        if a > 0 and b > 0:
            rev = ' '.join([str(b),str(-a)])
        else:
            rev = ' '.join([str(-b),str(a)])
        if dic1[rev] > 0 and dic2[rev] == 0:
            dic2[rev] = 1
            dic2[e] = 1
            flag = 1
        if flag:
            continue
        n1 = pow(2,dic[e],mod)
        n2 = pow(2,dic1[rev],mod)
        if n1 == 0:
            ans *= n2
        elif n2 == 0:
            ans *= n1
        else:
            ans *= (n1+n2-1)
        ans %= mod
    num = 0
    if dic['1 0'] and dic['0 1']:
        num = (pow(2,dic['1 0'],mod)+pow(2,dic['0 1'],mod)-1)
        num %= mod
    elif dic['1 0']:
        num = pow(2,dic['1 0'],mod)
        num %= mod
    elif dic['0 1']:
        num = pow(2,dic['0 1'],mod)
        num %= mod
    if num != 0:
        ans *= num
        ans %= mod
    print(ans-1+dic['0 0'])
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
input = sys.stdin.buffer.readline

N = int(input())

def gcd(n, m):
    if m == 0:
        return n
    return gcd(m, n % m)

def make(a, b):
    if a == b == 0:
        return (0, 0, 0)

    s = 1 if a * b >= 0 else -1
    a, b = abs(a), abs(b)

    g = gcd(a, b)
    a //= g
    b //= g

    return (a, b, s)

ABS = Counter([make(*map(int, input().split())) for _ in range(N)])
K = list(ABS.keys())

ans = 1
MOD = 10**9 + 7

for a, b, s in K:
    if s == 0:
        ans = (ans * pow(2, ABS[(0, 0, 0)], MOD)) % MOD
        continue
    p = ABS[(a, b, s)]
    n = ABS[(b, a, -s)]

    ABS[(a, b, s)] = 0
    ABS[(b, a, -s)] = 0

    cnt = pow(2, p, MOD) + pow(2, n, MOD) - 1
    ans = (ans * cnt) % MOD

print((ans - 1) % MOD)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
d = {}
r = 0
for i in range(n):
    if a[i][0] == 0 and a[i][1]:
        r += 1
    elif a[i][0] == 0:
        if 0 in d:
            d[0][0] = d[0][0] +1
        else:
            d[0] = [1, 0]
    elif a[i][1] == 1:
        if 0 in d:
            d[0][1] = d[0][1] +1
        else:
            d[0] = [0, 1]
    else:
        if a[i][0] * a[i][1] > 0:
            s = a[i][0] / a[i][1]
            if s in d:
                d[s][0] = d[s][0] +1
            else:
                d[s] = [1, 0]
        else:
            s = -a[i][1] / a[i][0]
            if s in d:
                d[s][1] = d[s][1] +1
            else:
                d[s] = [0, 1]
ans = 1
m = 0
for i in d:
    m += 1
    ans *= 2**d[i][0] + 2**d[i][1] - 1
    if m != 1:
        ans -= 1
    #print(ans)
ans += r
ans = ans%1000000007
#print(d)
print(ans)

Submission status: Wrong Answer

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
e=0
for i in range(N):
 A,B = map(int,input().split())
 if A==0 and B==0:
  e+=1
 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.pop(-1/k),mod) -1)
   ans%=mod
 else:
   ans*=powmod(2,dic[k],mod)
   ans%=mod
for k in dica:
 ans*=powmod(2,dica[k],mod)
 ans%=mod
ans*=(powmod(2,c,mod)+powmod(2,d,mod)-1)
print((ans-1+e)%mod)

Submission status: Wrong Answer

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


n = int(input())
ans = 1
C = defaultdict(int)
z = 0
for i in range(n):
    a, b = map(int, input().split())
    if b == 0:
        z += 1
    elif a == 0:
        C[0] += 1
    else:
        g = gcd(abs(a), abs(b))
        a //= g
        b //= g
        if a < 0:
            a, b = -a, -b
        C[(a, b)] += 1
D = tuple(C.items())
used = {0}
for c, v in D:
    if c in used:
        continue
    a, b = c
    if b > 0:
        d, e = b, -a
    else:
        d, e = -b, a
    ans *= pow(2, v, MOD)+pow(2, C[(d, e)], MOD)-1
    ans %= MOD
    used.add((d, e))
ans *= pow(2, C[0], MOD)+pow(2, z, MOD)-1
ans -= 1
ans %= MOD
print(ans)

Submission status: Wrong Answer

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9
    N=I()
    from math import gcd
    d={}
    for i in range(N):
        a,b=MI()
        if (a,b)!=(0,0):
            g=gcd(abs(a),abs(b))
            a=a//g
            b=b//g
        if (a,b) in d:
            d[(a,b)]+=1
        else:
            d[(a,b)]=1
        
    ans=1
    L=[]
    for k in d.keys():
        L.append((k,d[k]))

    L2=[0,0,0,0]

    for i in range(len(L)):
        k=L[i][0]
        v=d[k]
        d[k]=0
        temp=pow(2,v)
        a,b=k
        if a*b!=0:
            if (-b,a) in d:
                v2=d[(-b,a)]
                if v2!=0:
                    temp+=pow(2,v2)-1
                    d[(-b,a)]=0
            if (b,-a) in d:
                v2=d[(b,-a)]
                if v2!=0:
                    temp+=pow(2,v2)-1
                    d[(b,-a)]=0
            ans=(ans*temp)%mod
                    
        if (a,b)==(0,1):
            L2[0]=v
        elif (a,b)==(0,-1):
            L2[1]=v
        elif (a,b)==(1,0):
            L2[2]=v
        elif (a,b)==(-1,0):
            L2[3]=v
        
        
    v1=pow(2,L2[0])
    v2=pow(2,L2[1])
    v3=pow(2,L2[2])
    v4=pow(2,L2[3])
        
    v5=v1*v2
    v6=v3*v4
    
    ans=(ans*(v5+v6-1))%mod
        
    if (0,0) in d:
        #他の選び方と共存しない
        v=d[(0,0)]
        ans=(ans+v+1)%mod

    ans=(ans-1)%mod
    print(ans)
        
        
            
            
    #せんぶ０の組みをひく
        
    

main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
d = {}
r = 0
for i in range(n):
    if a[i][0] == 0 and a[i][1]:
        r += 1
    elif a[i][0] == 0:
        if 0 in d:
            d[0][0] = d[0][0] +1
        else:
            d[0] = [1, 0]
    elif a[i][1] == 1:
        if 0 in d:
            d[0][1] = d[0][1] +1
        else:
            d[0] = [0, 1]
    else:
        if a[i][0] * a[i][1] > 0:
            s = a[i][0] / a[i][1]
            if s in d:
                d[s][0] = d[s][0] +1
            else:
                d[s] = [1, 0]
        else:
            s = -a[i][1] / a[i][0]
            if s in d:
                d[s][1] = d[s][1] +1
            else:
                d[s] = [0, 1]
ans = 1
m = 0
for i in d:
    m += 1
    ans *= 2**d[i][0] + 2**d[i][1] - 1
    if m != 1:
        ans -= 1
    #print(ans)
    ans = ans%1000000007
ans += r
#print(d)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
b=[]
for i in range(n):
    ai,bi=map(int,input().split())
    a.append(ai)
    b.append(bi)

c=[]
for i in range(n):
    for j in range(n):
        if a[i]*a[j]+b[i]*b[j]==0:
            ij=[i,j]
            c.append(ij)

s=0
for i in range(2**n):
    d=[]
    for j in range(n):
        if ((i>>j) & 1):
            d.append(j)
    t=0
    for j in range(len(c)):
        e=0
        if c[j][0] in d:
            e+=1
        if c[j][1] in d:
            e+=1
        if e==2:
            t+=1
    if t==0:
        s+=1

print((s-1)%1000000007)

Submission status: Wrong Answer

Solution code:
import math
import numpy as np
import queue
from collections import deque
import heapq
mod = 10**9+7
ans = 1

def twoxxn(t,mod):
    ni = t
    an = 1
    n2 = 2
    while ni > 0:
        if ni%2 == 1:
            an = (an*n2)%mod
        n2 = (n2**2)%mod
        ni //= 2
    return an

n = int(input())
d = dict()
for i in range(n):
    a,b = map(int,input().split())
    if a < 0 :
        a = -a
        b = -b
    if a == 0:
        b = 1
        g = 1
    elif b == 0:
        a = 1
        g = 1
    else:
        g = math.gcd(abs(a),abs(b))
    if a == 0 and b == 0:
        continue
    else:
        p1 = str(a//g)+" "+str(b//g)
        if p1 in d:
            d[p1] += 1
        else:
            d[p1] = 1

for i in d.keys():
    i0, i1 = map(int,i.split())
    if str(i1)+" "+str(-i0) in d:
        if d[i] == 0:
            continue
        aaa = (twoxxn(d[str(i1)+" "+str(-i0)],mod)+twoxxn(d[i],mod)-1)%mod
        ans = (ans*aaa)%mod
        d[str(i1)+" "+str(-i0)] = 0
    elif str(-i1)+" "+str(i0) in d:
        if d[i] == 0:
            continue
        aaa = (twoxxn(d[str(-i1)+" "+str(i0)],mod)+twoxxn(d[i],mod)-1)%mod
        ans = (ans*aaa)%mod
        d[str(-i1)+" "+str(i0)] = 0
    else:
        ans = (ans*twoxxn(d[i],mod))%mod

if ans == 1:
    print(1)
    exit()
ans = (ans-1)%mod
print(ans)

Submission status: Wrong Answer

Solution code:
import math
MOD = 1000000007
N = int(input())
d_p = dict()
d_m = dict()
zz = 0
for n in range(N):
    a,b = map(int,input().split())

    if a==0 and b==0:
        zz += 1
        continue
    if a==0:
        n_sign = 0
    elif b==0:
        n_sign = 1
    
    else:    
        n_sign = ((a<0) + (b<0))%2
        a = abs(a)
        b = abs(b)
        # gcd = math.gcd(a,b)
        # a//=gcd
        # b//=gcd
        

        #print(n_sign,a,b)
    # print(n_sign,a,b)


    if n_sign==1:
        s =str(b/a)
        d_m[s] = d_m.get(s,0) + 1
    elif n_sign==0:
        s =str(a/b)
        d_p[s] = d_p.get(s,0) + 1      
    
#print (d_p,d_m)

ans = 1
for k,v in d_m.items():
    if k in d_p:
        ans *= (2**v + 2**d_p[k] - 1)
        
        d_p.pop(k)
    else:
        ans *= 2**v
    ans %= MOD

for k,v in d_p.items():
    ans *= 2**v
    ans %= MOD
ans -= 1
ans += zz
ans %= MOD
print (ans)

Submission status: Wrong Answer

Solution code:
n = int(input(''))
sardines = []
count = 0

for i in range (0, n):
    x = input("").split()
    x = [int(i) for i in x]
    sardines.append([x[0], x[1]])


for k in range(0, n):
    for l in range(k, n):
        if sardines[k][0] * sardines[l][0] + sardines[k][1] * sardines[l][1] != 0:
            count += 1
            
print(count % 1000000007)

Submission status: Wrong Answer

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

def main():
    n = int(input())
    ans = 1
    C = defaultdict(int)
    z = 0
    for i in range(n):
        a, b = map(int, input().split())
        if b == 0:
            z += 1
        elif a == 0:
            C[0] += 1
        else:
            g = gcd(abs(a), abs(b))
            a //= g
            b //= g
            if a < 0:
                a, b = -a, -b
            C[(a, b)] += 1
    D = tuple(C.items())
    used = {0}
    for c, v in D:
        if c in used:
            continue
        a, b = c
        if b > 0:
            d, e = b, -a
        else:
            d, e = -b, a
        ans *= pow(2, v, MOD)+pow(2, C[(d, e)], MOD)-1
        ans %= MOD
        used.add((d, e))
    ans *= pow(2, C[0], MOD)+pow(2, z, MOD)-1
    ans -= 1
    ans %= MOD
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import defaultdict
MOD = 10**9+7
from math import gcd

def main():
    n = int(input())
    ans = 1
    C = defaultdict(int)
    z = 0
    for i in range(n):
        a, b = map(int, input().split())
        if b == 0:
            z += 1
        elif a == 0:
            C[0] += 1
        else:
            g = gcd(abs(a), abs(b))
            a //= g
            b //= g
            if a < 0:
                a, b = -a, -b
            C[(a, b)] += 1
    D = tuple(C.items())
    used = {0}
    for c, v in D:
        if c in used:
            continue
        a, b = c
        if b > 0:
            d, e = b, -a
        else:
            d, e = -b, a
        ans *= pow(2, v, MOD)+pow(2, C[(d, e)], MOD)-1
        ans %= MOD
        used.add((d, e))
    ans *= pow(2, C[0], MOD)+pow(2, z, MOD)-1
    ans -= 1
    ans %= MOD
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input(''))
sardines = []
count = 0

for i in range (0, n):
    x = input("").split()
    x = [int(i) for i in x]
    sardines.append([x[0], x[1]])


for k in range(0, n):
    for l in range(k + 1, n):
        if sardines[k][0] * sardines[l][0] + sardines[k][1] * sardines[l][1] != 0:
            count += 1
count += n
print(count % 1000000007)

Submission status: Wrong Answer

Solution code:
import math
import itertools
import numpy as np
def main():
    N = int(input())
    AB = []
    for _ in range(N):
        AB.append(list(map(int, input().split())))
    mod = 1000000007
    total = math.factorial(N) % mod
    violate = []
    set_N = set({i for i in range(N)})
    for i, j in itertools.combinations([i for i in range(N)], 2):
        if AB[i][0] * AB[j][0] + AB[i][1] * AB[j][1] == 0:
            violate.append((i, j))
            set_N -= set((i, j))
    #print(set_N)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
AB = []
A0 = 0
B0 = 0
A0B0 = 0
for i in range(N):
    Atmp,Btmp = list(map(int,input().split()))
    if (Atmp!=0)and(Btmp!=0):
        AB.append(Atmp/Btmp)
    elif (Atmp==0)and(Btmp==0):
        A0B0 += 1
    elif (Atmp==0)and(Btmp!=0):
        A0 += 1
    elif (Atmp!=0)and(Btmp==0):
        B0 += 1

N += -1*A0B0

def power_func(a,n,p):
  bi=str(format(n,"b"))#2進表現に
  res=1
  for i in range(len(bi)):
    res=(res*res) %p
    if bi[i]=="1":
      res=(res*a) %p
  return res

from collections import Counter
import math
C = Counter(AB)

kaburi = []
forsum = []
for key in C:
    if key<0:
        if C[-1/key]!=0:
            kaburi.append([C[key],C[-1/key]])
            forsum.append(C[key]+C[-1/key])

if (A0>0)and(B0>0):
    kaburi.append([A0,B0])
    forsum.append(A0+B0)

p = 10**9+7

free = N-sum(forsum)
free2 = power_func(2,free,p)
L = len(kaburi)


out = 1
for i in range(len(kaburi)):
    X = kaburi[i][0]
    Y = kaburi[i][1]
    B = power_func(2,X,p)
    C = power_func(2,Y,p)
    out = out*((B+C-1)%p)
    out = out%p
if A0B0==0:
    print((out*free2-1)%p)
else:
    print((out*free2+A0B0)%p)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import collections
MOD = 1000000007
INF = 10 ** 100

n = int(input())
ratio = []
for i in range(n):
    a, b = map(int, input().split())
    if a == 0:
        ratio.append(INF)
    else:
        ratio.append(b/a)

ratio = collections.Counter(ratio)

ans = 1
done = set()
for key, value in ratio.items():
    if key == 0:
        key2 = INF
    elif key == INF:
        key2 = 0
    else:
        key2 = -1 / key
    if key2 in done:
        continue

    value2 = ratio[key2]
    if value2 == 0:
        ans *= pow(2, value, MOD)
    else:
        ans *= pow(2, value, MOD) + pow(2, value2, MOD) - 1
        done.add(key)
    ans %= MOD

print(ans - 1)

Submission status: Wrong Answer

Solution code:
import math

def make_key(a, b):
    if a==0 and b==0:
        return (0, 0)
    elif a == 0:
        return (0, 1)
    elif b == 0:
        return (1, 0)
    g = math.gcd(a, b)
    a //= g
    b //= g
    # make sure a is always positive
    if a < 0:
        a *= -1
        b *= -1
    return (a, b)


def main():
    MOD = 1000000007

    N = int(input())
    keys = [make_key(*[int(x) for x in input().split()]) for _ in range(N)]

    import collections
    count = collections.Counter(keys)
    seen = set()

    if (0, 0) in count:
        N -= count.pop((0, 0))

    # find pairs
    pairs = []
    for key in count.keys():
        if key in seen:
            continue
        okey = make_key(key[1], -key[0])
        if okey in count:
            seen.add(key)
            seen.add(okey)
            n1 = count[key]
            n2 = count[okey]

            N -= (n1+n2)
            pairs.append((n1, n2))

    ans = pow(2, N, MOD)
    for n1, n2 in pairs:
        num = ans
        ans += (pow(2, n1, MOD)-1) * num
        ans %= MOD
        ans += (pow(2, n2, MOD)-1) * num
        ans %= MOD
    ans -= 1
    ans %= MOD

    print(ans)
 
 
if __name__ == '__main__':
    import sys
    sys.setrecursionlimit(10000)
    main()

Submission status: Wrong Answer

Solution code:
import math
from collections import Counter

N = int(input())
A_B = []
mod = 1000000007
for _ in range(N):
    A, B = map(int, input().split())
    if (A == 0) and (B == 0):
        A_B.append((A, B))
    elif A == 0:
        A_B.append((0, -1))
    elif B == 0:
        A_B.append((1, 0))
    else:
        if A < 0:
            A = -A
            B = -B
        C = math.gcd(abs(A), abs(B))
        A_B.append((A // C, B // C))

A_B_C = Counter(A_B)


ans = 1
Done = set([])
Done.add((0, -1))
Done.add((0, 0))
Done.add((1, 0))

ans *= A_B_C[(0, 0)] + (pow(2, A_B_C[(0, -1)], mod) - 1) + (pow(2, A_B_C[(1, 0)], mod) - 1) + 1

for key, value in A_B_C.items():
    if key in Done:
        continue
    keya, keyb = key
    a = 0
    if keyb < 0:
        keya = -keya
        keyb = -keyb
    if (keyb, -keya) not in A_B_C:
        a = pow(2, value, mod)
    else:
        a = (pow(2, value, mod) - 1) + (pow(2, A_B_C[(keyb, -keya)], mod) - 1) + 1
        Done.add((keyb, -keya))
    ans *= a
    ans %= mod
    Done.add(key)

print((ans - 1) % mod)

Submission status: Wrong Answer

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)
        if a == b == 0:
            if (0, 0) in d:
                d[(0, 0)][0] += 1
            else:
                d[(0, 0)] = [1, 0]
            continue

        if a != 0 and b != 0:
            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
        elif a == 0:
            ai, bi = 0, 1
            aj, bj = 1, 0
        elif b == 0:
            ai, bi = 1, 0
            aj, bj = 0, 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:
        if k != (0, 0):
            n = modpow(2, d[k][0], mod)
            m = modpow(2, d[k][1], mod)

            ans = ans * (n + m - 1) % mod
    ans -= 1
    if (0, 0) in d:
        ans = (ans + d[(0, 0)][0]) % mod

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

a0,b0 = 0,0
count = {}

for _ in range(n):
  a,b = map(int,input().split())
  if a==b==0:
    n-=1
  elif a==0:
    a0 += 1
  elif b==0:
    b0 += 1
  elif (a,b) in count:
    count[(a,b)] +=1
  elif (-a,-b) in count:
    count[(-a,-b)] += 1
  else:
    count[(a,b)] = 1

queue = [(a0,b0)]
checked = set([])
free = 0
for a,b in count:
  if (a,b) in checked:
    continue
  if (-b,a) in count or (b,-a) in count:
    c = count[(-b,a)] if (-b,a) in count else count[(b,-a)]
    queue.append((count[(a,b)], c))
    checked.add((a,b))
    checked.add((-b,a))
    checked.add((b,-a))
  else:
    free += count[(a,b)]



div = []  
for i in range(n+1):
  div.append(pow(i,mod-2,mod))
hist = {}
def comb_all(i):
  if i in hist:
    return hist[i]
  else:
    res = 1
    cmb = 1
    for j in range(1,i+1):
      
      
      cmb *= (i-j+1) * div[j]
      cmb %= mod
      res += cmb
    hist[i] = res
    return res

ans = 1
while queue:
  c1,c2 = queue.pop(-1)
  if c1==c2==0:
    continue
  ans = ans * (comb_all(c1) + comb_all(c2)-1)
  ans %= mod
ans *= comb_all(free)
ans += mod-1
ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
from math import gcd
from collections import Counter
N, *A = map(int, open(0).read().split())
*A, = zip(*[iter(A)]*2)

mod = 10**9 + 7


def modpow(a, n, mod):
    ret = 1
    while n:
        if n & 1:
            ret = ret * a % mod
        a = a * a % mod
        n >>= 1
    return ret

col = []
row = []
zero = 0
for a, b in A:
    if a == b == 0:
        zero += 1
        continue
    if a == 0:
        col.append((1,0))
        continue
    elif b == 0:
        row.append((1,0))
        continue

    c = a/b
    if c > 0:
        col.append((c))
    else:
        row.append((-1/c))

C = Counter(col)
D = Counter(row)
S = set(col) | set(row)

ans = 1
for s in S:
    if s in C:
        if s in D:
            mul = modpow(2, C[s], mod) + modpow(2, D[s], mod) - 1
            mul %= mod
        else:
            mul = modpow(2, C[s], mod)
    elif s in D:
        mul = modpow(2, D[s], mod)

    ans *= mul
    ans %= mod

ans -= 1
if zero:
    ans += zero
ans %= mod

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
input = sys.stdin.readline

N = int(input())
AB = [[int(i) for i in input().split()] for _ in range(N)]

mod = 10 ** 9 + 7

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

p = []
both = 0
zeroa = 0
zerob = 0
for a, b in AB :
  if a == 0 and b == 0 :
    continue
  elif a == 0 :
    zeroa += 1
    continue
  elif b == 0 :
    zerob += 1
    continue
    
  g = gcd(abs(a), abs(b))
  a //= g
  b //= g
  if a < 0 :
    a *= -1
    b *= -1
  p.append((a, b))

ret = 1
visited = set()
cnt = Counter(p)
for k, v in cnt.items() :
  a, b = k
  c, d = b, -a
  if c < 0 :
    c *= -1
    d *= -1
  if cnt[(c, d)] == 0 :
    ret *= pow(2, v, mod)
  else :
    if not (c, d) in visited :
      u = cnt[(c, d)]
      ret *= (pow(2, u, mod) + pow(2, v, mod) - 1)
      visited.add((a, b))
      visited.add((c, d))
  ret %= mod

ret *= pow(2, zeroa, mod) + pow(2, zerob, mod) - 1
ret %= mod

print((ret - 1 + both) % mod)

Submission status: Wrong Answer

Solution code:
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

N = I()
cnt = {}
pair = {}
bothzero = 0
for i in range(N):
    A,B = MI()
    if A==0 and B==0:
        bothzero += 1
    elif B==0:
        pair[0]=pair.get(0,0)+1
    elif A == 0:
        cnt[0]=cnt.get(0,0)+1
    elif A/B>0:
        cnt[A/B]=cnt.get(A/B,0)+1
    else:
        pair[-B/A]=pair.get(-B/A,0)+1
res = N-bothzero
ans = 1
for v in cnt:
    if pair.get(v,0)==0:
        continue
    res -= (cnt[v]+pair[v])
    ans = ans*((pow(2,cnt[v],MOD)+pow(2,pair[v],MOD)-1)%MOD)
    ans = ans%MOD
ans = (ans*pow(2,res,MOD)-1)%MOD
ans = (ans+bothzero)%MOD
print(ans)