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:
#!/usr/bin/env python3
import sys
import math

MOD = 1000000007  # type: int


def pow2(x):
    res = 1
    a = 2
    while x > 0:
        if x & 1:
            res = (res * a) % MOD
        a = a * a % MOD
        x >>= 1
    return res

def solve(N: int, A: "List[int]", B: "List[int]"):
    m = {}
    m_0_0 = 0

    for i in range(N):
        if A[i] == 0 and B[i] == 0:
            m_0_0 += 1
            continue
        if A[i] == 0:
            if "0" in m:
                m["0"][0] += 1
            else:
                m["0"] = [1, 0]
            continue
        if B[i] == 0:
            if "0" in m:
                m["0"][1] += 1
            else:
                m["0"] = [0,1]
            continue


        gcd = math.gcd(A[i],B[i])

        a = A[i] // gcd
        b = B[i] // gcd
        if (a < 0 and b < 0 ) or (a > 0 and b > 0):
            key = str(abs(a)) + "/" + str(abs(b))
            if key in m:
                m[key][0] += 1
            else:
                m[key] = [1, 0]
        else:
            key =str(abs(b)) + "/" + str(abs(a))
            if key in m:
                m[key][1] += 1
            else:
                m[key] = [0, 1]

    ans = 1
    for v in m.values():
        ans = (ans * (pow2(v[0]) + pow2(v[1]) - 1)) % MOD
    ans = (ans + m_0_0) % MOD
    print(ans-1)
            
        

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, A, B)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
MOD = 1000000007
s, AB0, A0, B0 = {}, 0, 0, 0

for _ in range(N):
    A, B = map(int, input().split())
    if A == 0 and B == 0:
        AB0 += 1
    elif A == 0:
        A0 += 1
    elif B == 0:
        B0 += 1
    else:
        GCD = math.gcd(A, B)
        A //= GCD
        B //= GCD
        if s.get(A/B) == None:
            s[A/B] = 1
        else:
            s[A/B] += 1

f, ans = 0, 1
while len(s) > 0:
    k1, v1 = s.popitem()
    key = -1/k1
    if key in s.keys():
        v2 = s.pop(key)
        Cv1, Cv2 = pow(2, v1, MOD), pow(2, v2, MOD)     # pow(2, n, MOD) は二項定理による組み合わせの総和
        C = ((Cv1 + Cv2) % MOD + (MOD - 1)) % MOD
        ans = (ans * C) % MOD
    else:
        f += v1

if A0 == 0 or B0 == 0:
    f += A0 + B0
else:
    Cv1, Cv2 = pow(2, A0, MOD), pow(2, B0, MOD)     # pow(2, n, MOD) は二項定理による組み合わせの総和
    C = ((Cv1 + Cv2) % MOD + (MOD - 1)) % MOD
    ans = (ans * C) % MOD

ans = ((ans * pow(2, f, MOD)) % MOD  + (MOD - 1)) % MOD
ans = (ans + AB0) % MOD
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

def f(a,b):
    f = math.gcd(a,b)
    return a//f, b//f

N = I()
A,B = LIR(N,2)

beki = [1]*(N+1)
for i in range(1,N+1):
    beki[i] = beki[i-1]*2
    beki[i] %= mod


dplus = defaultdict(int)
dplus2 = defaultdict(int)
dminus = defaultdict(int)
dminus2 = defaultdict(int)
zero = 0
both_zero = 0
for i in range(N):
    if A[i] == 0 and B[i] == 0:
        both_zero += 1
    elif A[i] == 0 or B[i] == 0:
        zero += 1
    else:
        if A[i]*B[i] > 0:
            a,b = f(abs(A[i]),abs(B[i]))
            dplus[(a,b)] += 1
            dplus2[(a,b)] += 1
        else:
            a,b = f(abs(A[i]),abs(B[i]))
            dminus[(b,a)] += 1
            dminus2[(b,a)] += 1

ans = zero+1
count = 0

for k in dplus.keys():
    if dminus[k]:
        temp = beki[dplus[k]] + beki[dminus[k]] - 1
        ans *= temp
        ans %= mod
    else:
        count += dplus[k]

for k in dminus2.keys():
    if dplus2[k]:
        continue
    else:
        count += dminus2[k]

ans *= beki[count]
ans += both_zero-1
ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
mod = 1000000007
x = []
y = []
ex = [0,0]
ex2 = 0
for i in range(n):
    if (a[i][0]==0 and a[i][1]==0):
        ex2 += 1
    elif (a[i][0]*a[i][1]>0):
        if (a[i][0]!=0):
            x.append(a[i][1]/a[i][0])
        else:
            ex[0] += 1
    else:
        if (a[i][1]!=0):
            y.append(-a[i][0]/a[i][1])
        else:
            ex[1] += 1
x.sort()
y.sort()
#print(x,y)
xl = 0
yl = 0
xu = []
yu = []
xn = 0
yn = 0
while (xl<len(x) and yl<len(y)):
    if (x[xl] > y[yl]):
        yl += 1
    elif (x[xl] < y[yl]):
        xl += 1
    else:
        #print(xl,yl,x,y)
        p = bisect.bisect_right(x,x[xl])
        q = bisect.bisect_right(y,y[yl])
        xn += (p-xl)
        yn += (q-yl)
        xu.append(p-xl)
        yu.append(q-yl)
        xl = p
        yl = q
xu.append(ex[0])
yu.append(ex[1])
#print(xn,yn,xu,yu)
ans = pow(2,n-xn-yn-ex2,mod)
#if (n-xn-yn>0):
    #t = 1
    #for i in range(1,n-xn-yn+1):
        #t *= i
        #t %= mod
    #ans += t
for i in range(len(xu)):
    ans *= (pow(2,xu[i],mod)+pow(2,yu[i],mod)-1)
    ans %= mod
if (ex2==0):
    print((ans-1)%mod)
else:
    f = 1
    for i in range(1,ex2+1):
        f *= i
        f %= mod
    print((ans-1+f)%mod)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
dic1 = defaultdict(int)
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
mod = 10**9+7
def pow(n,p,mod=10**9+7): #繰り返し二乗法(nのp乗)
    res = 1
    while p > 0:
        if p % 2 == 0:
            n = n ** 2 % mod
            p //= 2
        else:
            res = res * n % mod
            p -= 1
    return res % mod
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
def lcm(a,b):
    return (a//gcd(a,b)*b)
n = int(readline())
#dic1
#[正負,比率1(小),比率2(大)]
for i in range(n):
    a,b= map(int,readline().split())
    plamai = 1 if a*b > 0 else 0
    if a < 0:a = -a
    if b < 0:b = -b
    res = gcd(a,b)
    if res == 0:
        dic1["0 0 0"] += 1
        continue
    dic1[str(plamai)+" "+str(a//res)+" "+str(b//res)] += 1

ans = 1
dic2 = dict()
for i in dic1.keys():
    res = 0
    if not i in dic2:
        a = dic1[i]
        g,d,e = i.split()
        if g == "1":
            res2 = "0"+" "+e+" "+d
        else:
            res2 = "1"+" "+e+" "+d
        if res2 in dic1:
            b = dic1[res2]
        else:b = 0
        if a > 0:
            res += pow(2,a)
        if b > 0:
            res += pow(2,b)
        if a != 0 and b != 0:
            res -= 1
        ans *= res
        ans %= mod
        dic2[res2] = 1

print(ans-1)

Submission status: Wrong Answer

Solution code:
from math import gcd
from collections import Counter

mod = 1000000007

N = int(input())
F = []

alone = 0

for i in range(N):
    A,B = map(int,input().split())
    if A == 0 and B == 0:
        alone += 1
        continue
    fugou = 1
    if A < 0:
        fugou *= -1
        A *= -1
    if B < 0:
        fugou *= -1
        B *= -1
    if A == 0:
        F.append((0,0,1))
    elif B == 0:
        F.append((0,1,0))
    else:
        C = gcd(A,B)
        F.append((fugou,A//C,B//C))

C = Counter(F)
G = []
for f in F:
    ff,fa,fb = f
    g = (-ff,fb,fa)
    a,b = 1,1
    for i in range(C[f]):
        a *= 2
        a %= mod
    for i in range(C[g]):
        b *= 2
        b %= mod
    c = a + b + mod - 1
    c %= mod
    if c > 1:
        G.append(c)
    C[f] = 0
    C[g] = 0

ans = 1
for g in G:
    ans *= g
    ans %= mod

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

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

def f(a,b):
    f = math.gcd(a,b)
    return a//f, b//f

N = I()
A,B = LIR(N,2)

beki = [1]*(N+1)
for i in range(1,N+1):
    beki[i] = beki[i-1]*2
    beki[i] %= mod


dplus = defaultdict(int)
dplus2 = defaultdict(int)
dminus = defaultdict(int)
dminus2 = defaultdict(int)
zero = 0
for i in range(N):
    if A[i] == 0 and B[i] == 0:
        continue
    if A[i] == 0 or B[i] == 0:
        zero += 1
    else:
        if A[i]*B[i] > 0:
            a,b = f(abs(A[i]),abs(B[i]))
            dplus[(a,b)] += 1
            dplus2[(a,b)] += 1
        else:
            a,b = f(abs(A[i]),abs(B[i]))
            dminus[(b,a)] += 1
            dminus2[(b,a)] += 1

ans = zero+1
count = 0

for k in dplus.keys():
    if dminus[k]:
        temp = beki[dplus[k]] + beki[dminus[k]] - 1
        ans *= temp
        ans %= mod
    else:
        count += dplus[k]

for k in dminus2.keys():
    if dplus2[k]:
        continue
    else:
        count += dminus2[k]

ans *= beki[count]
ans -= 1
ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict 
import sys
input = sys.stdin.readline
from math import gcd

MOD = 10 ** 9 + 7

dic1 = defaultdict(int)
dic2 = defaultdict(int)
dic3 = defaultdict(int)

All_zero = 0

S = set()
N = int(input())
ans = 0 #仲が悪い数を数える
for i in range(N):
    a, b = map(int, input().split())
    if a == 0 and b == 0: #なんでもOK
        All_zero += 1
    elif a == 0:
        S.add((0, 1))
        dic1[(0, 1)] += 1
        dic2[(0, 1)] += 1
        dic3[(0, 1)] += 1
    elif b == 0:
        S.add((1, 0))
        dic1[(1, 0)] += 1
        dic2[(1, 0)] += 1
        dic3[(1, 0)] += 1
    else:
        GCD = gcd(a, b)
        a //= GCD
        b //= GCD
        if a < 0: #aを必ず正にする
            a *= -1
            b *= -1
        S.add((a, b))
        dic1[(a, b)] += 1
        dic2[(a, b)] += 1
        dic3[(a, b)] += 1
        

lst = []
for a, b in S:
    tmp11 = dic1[(a, b)]
    tmp12 = dic2[(a, b)]
    tmp13 = dic3[(a, b)]
    if not (tmp11 == tmp12 and tmp12 ==  tmp13):
        print (tmp11, tmp12, tmp13)
        print (error)
    A = a
    B = b
    if B < 0:
        B *= -1
        A *= -1
    tmp2 = dic1[(B, -A)]
    dic1[(B, -A)] = 0
    dic2[(B, -A)] = 0
    dic3[(B, -A)] = 0
    
    if tmp11 > 0:
        lst.append((tmp11, tmp2))

# print (lst)

ans = 1
for a, b in lst:
    tmp = (pow(2, a, MOD) - 1) + (pow(2, b, MOD) - 1) + 1 #左側を入れる、右側を入れる、両方入れない
    ans *= tmp
    ans %= MOD

ans = (ans - 1 + All_zero) % MOD
print (ans % MOD)

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 = 1
        a=0
        b=0
    elif b==0:
        n_sign = 0
        a=0
        b=0  


    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)

    

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

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:
#!/usr/bin/env python3
import sys
import math

MOD = 1000000007  # type: int


def pow2(x):
    res = 1
    a = 2
    while x > 0:
        if x & 1:
            res = (res * a) % MOD
        a = a * a % MOD
        x >>= 1
    return res

def solve(N: int, A: "List[int]", B: "List[int]"):
    m = {}
    m_0_0 = 0

    for i in range(N):
        if A[i] == 0 and B[i] == 0:
            m_0_0 += 1
            continue
        if A[i] == 0:
            if "0" in m:
                m["0"][0] += 1
            else:
                m["0"] = [1, 0]
            continue
        if B[i] == 0:
            if "0" in m:
                m["0"][1] += 1
            else:
                m["0"] = [0,1]
            continue


        gcd = math.gcd(A[i],B[i])

        a = A[i] // gcd
        b = B[i] // gcd
        if (a < 0 and b < 0 ) or (a > 0 and b > 0):
            key = str(abs(a)) + "/" + str(abs(b))
            if key in m:
                m[key][0] += 1
            else:
                m[key] = [1, 0]
        else:
            key =str(abs(b)) + "/" + str(abs(a))
            if key in m:
                m[key][1] += 1
            else:
                m[key] = [0, 1]

    ans = 1
    for v in m.values():
        ans = (ans * (pow2(v[0]) + pow2(v[1]) - 1)) % MOD
    ans = ans + m_0_0 % MOD
    print(ans-1)
            
        

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, A, B)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
MOD = 1000000007
s, AB0, A0, B0 = {}, 0, 0, 0

for _ in range(N):
    A, B = map(int, input().split())
    if A == 0 and B == 0:
        AB0 += 1
    elif A == 0:
        A0 += 1
    elif B == 0:
        B0 += 1
    else:
        if s.get(A/B) == None:
            s[A/B] = 1
        else:
            s[A/B] += 1

f, ans = 0, 1
while len(s) > 0:
    k1, v1 = s.popitem()
    key = -1/k1
    if key in s.keys():
        v2 = s.pop(key)
        Cv1, Cv2 = pow(2, v1, MOD), pow(2, v2, MOD)     # pow(2, n, MOD) は二項定理による組み合わせの総和
        C = ((Cv1 + Cv2) % MOD + (MOD - 1)) % MOD
        ans = (ans * C) % MOD
    else:
        f += v1

if A0 == 0 or B0 == 0:
    f += A0 + B0
else:
    Cv1, Cv2 = pow(2, A0, MOD), pow(2, B0, MOD)     # pow(2, n, MOD) は二項定理による組み合わせの総和
    C = ((Cv1 + Cv2) % MOD + (MOD - 1)) % MOD
    ans = (ans * C) % MOD

ans = ((ans * pow(2, f, MOD)) % MOD  + (MOD - 1)) % MOD
ans = (ans + AB0) % MOD
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
mod = 1000000007

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

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

Submission status: Wrong Answer

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

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

adivb = [float('inf') if ab[i][1] == 0 else ab[i][0] / ab[i][1]
         for i in range(n)]
bdiva = [-float('inf') if ab[i][0] == 0 else -ab[i][1] / ab[i][0]
         for i in range(n)]

adb, bda = Counter(adivb), Counter(bdiva)
cntadb, cnt = defaultdict(int), 0
for i in adb:
    if (i in bda) and (i >= 0):
        cntadb[i] += bda[i] + adb[i] + 1
        cnt += bda[i] + adb[i]
ans = 1
for i in cntadb:
    ans *= cntadb[i]
print((ans * 2 ** (n - cnt) - 1) % mod)

Submission status: Wrong Answer

Solution code:
N = int(input())
MOD = 1000000007
s, AB0, A0, B0 = {}, 0, 0, 0

for _ in range(N):
    A, B = map(int, input().split())
    if A == 0 and B == 0:
        AB0 += 1
    elif A == 0:
        A0 += 1
    elif B == 0:
        B0 += 1
    else:
        if s.get(A/B) == None:
            s[A/B] = 1
        else:
            s[A/B] += 1

f, ans = 0, 1
while len(s) > 0:
    k1, v1 = s.popitem()
    if k1 == 0:
        key = float('inf')
    else:
        key = -1/k1
    if key in s.keys():
        v2 = s.pop(key)
        Cv1, Cv2 = pow(2, v1, MOD), pow(2, v2, MOD)     # pow(2, n, MOD) は二項定理による組み合わせの総和
        C = ((Cv1 + Cv2) % MOD + (MOD - 1)) % MOD
        ans = (ans * C) % MOD
    else:
        f += v1

if A0 == 0 or B0 == 0:
    f += A0 + B0
else:
    Cv1, Cv2 = pow(2, A0, MOD), pow(2, B0, MOD)     # pow(2, n, MOD) は二項定理による組み合わせの総和
    C = ((Cv1 + Cv2) % MOD + (MOD - 1)) % MOD
    ans = (ans * C) % MOD

ans = ((ans * pow(2, f, MOD)) % MOD  + (MOD - 1)) % MOD
ans = (ans + AB0) % MOD
print(ans)

Submission status: Wrong Answer

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

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

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

    print(ans-1)
        

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import math

MOD = 1000000007  # type: int


def pow2(x):
    res = 1
    a = 2
    while x > 0:
        if x & 1:
            res = (res * a) % MOD
        a = a * a % MOD
        x >>= 1
    return res

def solve(N: int, A: "List[int]", B: "List[int]"):
    m = {}
    m_0_0 = 0

    for i in range(N):
        if A[i] == 0 and B[i] == 0:
            m_0_0 += 1
            continue
        if A[i] == 0:
            if "0" in m:
                m["0"][1] += 1
            else:
                m["0"] = [0, 1, 0]
            continue
        if B[i] == 0:
            if "0" in m:
                m["0"][2] += 1
            else:
                m["0"] = [0, 0,1]
            continue


        gcd = math.gcd(A[i],B[i])

        a = A[i] // gcd
        b = B[i] // gcd
        if (a < 0 and b < 0 ) or (a > 0 and b > 0):
            key = str(abs(a)) + "/" + str(abs(b))
            if key in m:
                m[key][0] += 1
            else:
                m[key] = [1, 0]
        else:
            key =str(abs(b)) + "/" + str(abs(a))
            if key in m:
                m[key][1] += 1
            else:
                m[key] = [0, 1]

    ans = 1
    for v in m.values():
        ans = (ans * (pow2(v[0]) + pow2(v[1]) - 1)) % MOD
    ans = ans + m_0_0 % MOD
    print(ans-1)
            
        

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, A, B)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,cos,radians,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7



def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
n=I()
bekit=[0 for i in range(n+1)]
bekit[0]=1
for i in range(n):
    bekit[i+1]=(bekit[i]*2)%mod
#print(bekit)
countz=0
countx=0
county=0
nump=[]
numm=[]
for i in range(n):
    a,b=MI()
    if a==0 and b==0:
        countz+=1
    elif a==0:
        if b<0:
            b*=(-1)
        countx+=1
    elif b==0:
        if a<0:
            a*=(-1)
        county+=1
    elif a*b<0:
        #print(a,b)
        if b<0:
            a*=(-1)
            b*=(-1)
        g=gcd(abs(a),b)
        a=a//g
        b=b//g
        #print(a,b)
        numm.append([a,b])
    else:
        g=gcd(abs(a),abs(b))
        a//=g
        b//=g
        nump.append([abs(a),abs(b)])
#print(nump)
#print(numm)
nump=list(map(tuple,nump))
numm=list(map(tuple,numm))
u=Counter(nump)
v=Counter(numm)
#print(u)
#print(v)
nums=[]
pairs=[]
for k in u.keys():
    vz=((-1)*k[1],k[0])
    s=u[k]
    t=v[vz]
    #print(vz)
    #print(s)
    #print(t)
    if t>0:
        nums.append([s,t])
        pairs.append(s+t)
#print(nums)
#print(nums)
#print(n-sum(pairs)-countx-county-countz)
#print(pairs)
#print(n-sum(pairs)-countx-county-countz)
ans=bekit[n-sum(pairs)-countx-county-countz]
for j in range(len(nums)):
    q=bekit[nums[j][0]]
    p=bekit[nums[j][1]]
    #print(q)
    #print(p)
    ans=(ans*(q+p-1))%mod
if countx>0 and county>0:
    ans=(ans*(bekit[countx]+bekit[county]-1))%mod
ans-=1
if countz>0:
    ans+=1
print(ans)

Submission status: Wrong Answer

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

  if t:
    v = 0
    v += pow(2, d[(x, y)], mod) - 1
    v %= mod
    v += pow(2, t, mod) - 1
    v %= mod
    v += 1
    v %= mod
    res *= v
    res %= mod
    #print(res, v)
  d[(x, y)] = 0
#print(itr, u, res)
print(res * pow(2, u, mod) - 1 + z % mod)

Submission status: Wrong Answer

Solution code:
n = int(input())
mod = 10**9 + 7
cou = 0
pdic = {}
kan = []
betu = [0,0,0]

for i in range(n):
    a , b = map(int,input().split())
    if a*b != 0:
        p = a/b
        q = -b/a
        if pdic.get(q,-1) != -1:
            kan[pdic[q]][1] += 1
        elif pdic.get(p,-1) == -1:
            pdic[p] = cou
            kan.append([1,0])
            cou += 1
        elif pdic.get(p,-1) != -1:
            kan[pdic[p]][0] += 1
    elif a*b == 0:
        if a == 0 and b == 0:
            betu[2] += 1
        elif a == 0:
            betu[0] += 1
        elif b == 0:
            betu[1] += 1
        
        
ans = 1
for i in range(len(kan)):
    if kan[i][1] == 0:
        ans *= pow(2,kan[i][0],mod)
    elif kan[i][1] != 0:
        ans *= (pow(2,kan[i][0],mod) + pow(2,kan[i][1],mod) - 1) % mod
    ans %= mod
ans *= (pow(2,betu[0],mod) + pow(2,betu[1],mod) - 1) % mod
print((ans-1+betu[2])%mod)

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:
            g=gcd(abs(a),abs(b))
            a=a//g
            b=b//g
        elif (a,b)!=(0,0):
            if a==0:
                b=1
            else:
                a=1
            
        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]))

    temp0=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,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
        else:
            temp0=v
        
        


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

main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import math

MOD = 1000000007  # type: int


def pow2(x):
    res = 1
    a = 2
    while x > 0:
        if x & 1:
            res = (res * a) % MOD
        a = a * a % MOD
        x >>= 1
    return res

def solve(N: int, A: "List[int]", B: "List[int]"):
    m = {}
    m_0_0 = 0

    for i in range(N):
        if A[i] == 0 and B[i] == 0:
            m_0_0 += 1
        if A[i] == 0:
            if "0" in m:
                m["0"][1] += 1
            else:
                m["0"] = [0, 1, 0]
            continue
        if B[i] == 0:
            if "0" in m:
                m["0"][2] += 1
            else:
                m["0"] = [0, 0,1]
            continue


        gcd = math.gcd(A[i],B[i])

        a = A[i] // gcd
        b = B[i] // gcd
        if (a < 0 and b < 0 ) or (a > 0 and b > 0):
            key = str(abs(a)) + "/" + str(abs(b))
            if key in m:
                m[key][0] += 1
            else:
                m[key] = [1, 0]
        else:
            key =str(abs(b)) + "/" + str(abs(a))
            if key in m:
                m[key][1] += 1
            else:
                m[key] = [0, 1]

    ans = 1
    for v in m.values():
        ans = (ans * (pow2(v[0]) + pow2(v[1]) - 1)) % MOD
    ans = ans + m_0_0 % MOD
    print(ans-1)
            
        

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, A, B)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

def gcd(x, y):
    if x < y:
        x = x ^ y
        y = x ^ y
        x = x ^ y
    div = x % y
    while div != 0:
        x = y
        y = div
        div = x % y
    return y


N=II()
MP1={}
A0 = 0
B0 = 0
AB0 = 0
RES=1
for i in range(N):
    A, B = LI()
    if A*B != 0:
        G = gcd(abs(A),abs(B))
        A //= G
        B //= G
        v = (abs(A), abs(B), A*B > 0)
        if not v in MP1:
            MP1[v] = 1
        else:
            MP1[v] += 1

    if A == 0 and B != 0: A0 += 1
    if A != 0 and B == 0: B0 += 1

# print(MP1)

VIS = set()
for (vv, n) in MP1.items():
    (A, B, isPos) = vv
    v = (B, A, not isPos)
    if not v in VIS and not vv in VIS:
        VIS.add(v)
        VIS.add(vv)
        if v in MP1:
            m = MP1[v]
            RES = (RES*POW(2, n))%DVSR + (RES*POW(2, m))%DVSR - RES
            RES %= DVSR
        else:
            RES *= POW(2, n)
            RES %= DVSR

if A0 and B0:
    RES = (RES*POW(2, A0))%DVSR + (RES*POW(2, B0))%DVSR - RES
elif A0:
    RES = RES*POW(2, A0)%DVSR
elif B0:
    RES = RES*POW(2, B0)%DVSR

print((RES-1)%DVSR)