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
sys.setrecursionlimit(2147483647)


n=int(input())

mod=10**9+7

#初期値が0の辞書

pp = {} 
pm = {} 

from fractions import gcd
zero=0
for _ in range(n):
    a,b=map(int,input().split())

    if a*b!=0:
        tmp=gcd(a,b)
        a=a//tmp
        b=b//tmp

        if a*b>0:
            if (a,b) in pp:
                pp[(a,b)]+=1
            else:
                pp[(a,b)]=1
        else:
            aa=abs(a)
            bb=abs(b)
            if (aa,bb) in pm:
                pm[(aa,bb)]+=1
            else:
                pm[(aa,bb)]=1

    elif a==0 and b==0:
        zero+=1
    else:
        if (a,b) in pp:
            pp[(a,b)]+=1
        else:
            pp[(a,b)]=1

            

#print(pp_k,pm_k)
result=1
for key in pp.keys():
    pp_v=pp[key]
    a,b=key[0],key[1]
    if (b,a) in pm:
        pm_v=pm[(b,a)]
        result=result*((pow(2,pp_v,mod)-1)+(pow(2,pm_v,mod)-1)+1)
    else:
        result=result*pow(2,pp_v,mod)

for key in pm.keys():
    pm_v=pm[key]
    a,b=key[0],key[1]
    if (b,a) not in pp:
        result=result*pow(2,pm_v,mod)

print(result-1+zero)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import deque, Counter, defaultdict
from fractions import gcd
import heapq

INF = int(1e10)
MOD = int(1e9 + 7)

def power(n, r, mod):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod

def input():
    return stdin.readline()[:-1]

def main():
    from builtins import int, map
    n = int(input())
    count = 0
    A, B = [], []
    mp = defaultdict(lambda: [0, 0])
    for i in range(n):
        ai, bi = map(int, input().split())
        if ai == 0 and bi == 0:
            count += 1
            continue

        gi = gcd(ai, bi)
        ai = ai // gi
        bi = bi // gi

        if bi < 0:
            ai = -ai
            bi = -bi
        if bi == 0 and ai < 0:
            ai = -ai
            bi = -bi
        rot90 = ai <= 0
        if rot90:
            ai, bi = bi, -ai

        if rot90:
            mp[(ai, bi)][0] += 1
        else:
            mp[(ai, bi)][1] += 1

    ans = 1
    for key in mp:
        s, t = mp[key]
        now = 1
        now = (now + power(2, s, MOD) - 1) % MOD
        now = (now + power(2, t, MOD) - 1) % MOD
        ans = (ans * now) % MOD
    ans -= 1
    ans += count
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import deque, Counter, defaultdict
from fractions import gcd
import heapq

INF = int(1e10)
MOD = int(1e9 + 7)

def power(n, r, mod):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod

def input():
    return stdin.readline()[:-1]

def main():
    from builtins import int, map
    n = int(input())
    count = 0
    A, B = [], []
    mp = {}
    for i in range(n):
        ai, bi = map(int, input().split())
        if ai == 0 and bi == 0:
            count += 1
            continue

        gi = gcd(ai, bi)
        ai = ai // gi
        bi = bi // gi

        if bi < 0:
            ai = -ai
            bi = -bi
        if bi == 0 and ai < 0:
            ai = -ai
            bi = -bi
        rot90 = ai <= 0
        if rot90:
            ai, bi = bi, -ai

        if (ai, bi) not in mp:
            mp[(ai, bi)] = [0, 0]
        if rot90:
            mp[(ai, bi)][0] += 1
        else:
            mp[(ai, bi)][1] += 1

    ans = 1
    for key in mp:
        s, t = mp[key]
        now = 1
        now = (now + power(2, s, MOD) - 1) % MOD
        now = (now + power(2, t, MOD) - 1) % MOD
        ans = (ans * now) % MOD
    ans -= 1
    ans += count
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import deque, Counter, defaultdict
from fractions import gcd
import heapq

INF = int(1e10)
MOD = int(1e9 + 7)

def input():
    return stdin.readline()[:-1]

def main():
    from builtins import int, map
    n = int(input())
    count = 0
    A, B = [], []
    mp = {}
    for i in range(n):
        ai, bi = map(int, input().split())
        if ai == 0 and bi == 0:
            count += 1
            continue

        gi = gcd(ai, bi)
        ai = ai // gi
        bi = bi // gi

        if bi < 0:
            ai = -ai
            bi = -bi
        if bi == 0 and ai < 0:
            ai = -ai
            bi = -bi
        rot90 = ai <= 0
        if rot90:
            tmp = ai
            ai = bi
            bi = -tmp

        if (ai, bi) not in mp:
            mp[(ai, bi)] = [0, 0]
        if rot90:
            mp[(ai, bi)][0] += 1
        else:
            mp[(ai, bi)][1] += 1

    ans = 1
    for key in mp:
        s, t = mp[key]
        now = 1
        now = (now + pow(2, s, MOD) - 1) % MOD
        now = (now + pow(2, t, MOD) - 1) % MOD
        ans = (ans * now) % MOD
    ans -= 1
    ans += count
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from math import gcd
mod = 10**9+7
n=int(input())
r = dict()
zeros = 0
for _ in range(n):
  a,b=map(int,input().split())
  if not any((a,b)):
    zeros+=1
    continue
  g = gcd(a,b)
  p = a//g,b//g
  r[p] = r.get(p,0)+1
ans = 1
done = set()
for (a,b), v in r.items():
  if (b,-a) in done or (-b,a) in done:
    continue
  done.add((a,b))
  w = r.get((b,-a),0)+r.get((-b,a),0)
  ans = ans*(pow(2,v,mod)+pow(2,w,mod)-1)%mod
  
print((ans+zeros+mod-1)%mod)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import math
mod = 1000000007

pos = defaultdict(int)
neg = defaultdict(int)
zero = 0

n = int(input())
for _ in range(n):
	a, b = list(map(int, input().split()))
	if a == b == 0:
		zero += 1
	elif a == 0:
		pos[(0, 1)] += 1
	elif b == 0:
		neg[(0, 1)] += 1
	else:
		c = a * b
		g = math.gcd(a, b)
		a, b = abs(a // g), abs(b // g)
		if c > 0:
			pos[(a, b)] += 1
		elif c < 0:
			neg[(b, a)] += 1

cnt = 1
for x in pos.keys():
	if x in neg.keys():
		cnt = (cnt * (pow(2, pos[x], mod) + pow(2, neg[x], mod) - 1)) % mod
		del neg[x]
	else:
		cnt = (cnt * pow(2, pos[x], mod)) % mod

for x in neg.keys():
	cnt = (cnt * pow(2, neg[x], mod)) % mod

print(zero + cnt - 1)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
mod = 1000000007

pos = defaultdict(int)
neg = defaultdict(int)
zero = 0

n = int(input())
for _ in range(n):
	a, b = list(map(int, input().split()))
	if a == b == 0:
		zero += 1
	elif a == 0:
		pos[0] += 1
	elif b == 0:
		neg[0] += 1
	else:
		c = a / b
		d = b / a
		if c > 0:
			pos[c] += 1
		elif c < 0:
			neg[-d] += 1

cnt = 1
for x in pos.keys():
	if x in neg.keys():
		cnt = (cnt * (pow(2, pos[x], mod) + pow(2, neg[x], mod) - 1)) % mod
		del neg[x]
	else:
		cnt = (cnt * pow(2, pos[x], mod)) % mod

for x in neg.keys():
	cnt = (cnt * pow(2, neg[x], mod)) % mod
	
print(zero + cnt - 1)

Submission status: Wrong Answer

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

MOD = 1000000007  # type: int


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


def solve(N: int, A: "List[int]", B: "List[int]"):
    # 直交するイワシは選べない
    # 順にイワシを見てグループを探す。
    d = Counter()
    kodokunaiwashi = 0
    for i, (a, b) in enumerate(zip(A, B)):
        if a == 0 and b == 0:
            kodokunaiwashi += 1
        elif b == 0:
            d[1, 0] += 1
        elif b > 0:
            g = GCD(b, a)
            aa = a//g
            bb = b//g
            d[aa, bb] += 1
        else:
            g = GCD(-b, -a)
            aa = -a//g
            bb = -b//g
            d[(aa, bb)] += 1
    ans = 1
    for a, b in d:
        x, y = -b, a
        if y < 0:
            x = -x
            y = -y

        if d[a, b] == None:
            continue
        if d[(x, y)] == 0:
            ans *= pow(2, d[(a, b)], MOD)
            ans %= MOD
            continue
        else:
            # print((a, b), (x, y), d[a, b], d[x, y])
            buf = pow(2, d[(a, b)], MOD)
            buf += pow(2, d[(x, y)], MOD)
            buf -= 1
            # print(buf)
            buf %= MOD
            # print(buf)
            ans *= buf
            ans %= MOD
            d[x, y] = None

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

    return


def main():

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import sys
from math import gcd
count = defaultdict(int)
N = int(sys.stdin.readline())

zeros = 0
for i in range(N):
    A, B = [int(x) for x in input().split()]
    if A == B == 0:
        zeros += 1
        continue
    if A == 0:
        angle = (0, 1)
    elif B == 0:
        angle = (1, 0)
    else:
        sgn = A / abs(A)
        g = gcd(A, B)
        angle = (A / sgn / g, B / sgn / g)

    count[angle] += 1
# print(count)

pairs = {}
solos = []
for k1 in count:
    if k1 in pairs:
        continue
    if k1 == (0, 1):
        if (1, 0) in count:
            pairs[(1, 0)] = k1
        else:
            solos.append(k1)
        continue

    A, B = k1
    if B:
        sgn = -B / abs(B)
        k2 = (-B / sgn, A / sgn)
    else:
        k2 = (0, 1)
    if k2 in count:
        pairs[k2] = k1
    else:
        solos.append(k1)
#print(pairs, solos)

P = 1000000007


def pow2(n):
    # if n < 30:
    #     return 2 ** n

    # p = pow2(n // 2)
    # pp = (p * p) % P
    # if n % 2 == 1:
    #     return (2 * pp) % P
    # else:
    #     return pp
    return pow(2, n, P)


result = 1
for p in pairs:
    # print("pair", p, count[p], pairs[p], count[pairs[p]])
    n = count[p]
    m = count[pairs[p]]
    result = result * ((pow2(n) - 1) + (pow2(m) - 1) + 1) % P
for k in solos:
    # print("solo", k, count[k])
    result = result * pow2(count[k]) % P

print((result + zeros - 1) % P)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import sys
from math import gcd
count = defaultdict(int)
N = int(sys.stdin.readline())

zeros = 0
for i in range(N):
    A, B = [int(x) for x in input().split()]
    if A == B == 0:
        zeros += 1
        continue
    if A == 0:
        angle = (0, 1)
    elif B == 0:
        angle = (1, 0)
    else:
        sgn = A / abs(A)
        g = gcd(A, B)
        angle = (A / sgn / g, B / sgn / g)

    count[angle] += 1
# print(count)

pairs = {}
solos = []
for k1 in count:
    if k1 in pairs:
        continue
    if k1 == (0, 1):
        if (1, 0) in count:
            pairs[(1, 0)] = k1
        else:
            solos.append(k1)
        continue

    A, B = k1
    if B:
        sgn = -B / abs(B)
        k2 = (-B / sgn, A / sgn)
    else:
        k2 = (0, 1)
    if k2 in count:
        pairs[k2] = k1
    else:
        solos.append(k1)
#print(pairs, solos)

P = 1000000007


def pow2(n):
    # if n < 30:
    #     return 2 ** n

    # p = pow2(n // 2)
    # pp = (p * p) % P
    # if n % 2 == 1:
    #     return (2 * pp) % P
    # else:
    #     return pp
    return pow(2, n, P)


result = 1
for p in pairs:
    # print("pair", p, count[p], pairs[p], count[pairs[p]])
    n = count[p]
    m = count[pairs[p]]
    result = result * ((pow2(n) - 1) + (pow2(m) - 1) + 1) % P
for k in solos:
    # print("solo", k, count[k])
    result = result * pow2(count[k]) % P

print(result + zeros - 1)

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 and b == 0:
            continue
        flag = 0
        if a == 0 and b == 1:
            rev = ' '.join([str(1),str(0)])
        elif a == 1 and b == 0:
            rev = ' '.join([str(0),str(1)])
        elif 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)
        ans *= (n1+n2-1)
        ans %= mod
    print(ans-1+dic['0 0'])
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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
a_zero = 0
b_zero = 0
AB = []
lst = []
for a, b in ab:
    if a == 0 and b == 0:
        ans -= pow(2, n-1, mod)
        ans %= mod
        n -= 1
    elif a == 0:
        a_zero += 1
    elif b == 0:
        if a_zero:
            lst.append(b_zero)
        b_zero += 1
    else:
        AB.append([a, b])
x = [a / b for a, b in AB]
y = [- b / a for a, b in AB]
j = 0
if a_zero:
    while j + 1 < b_zero:
        ans -= comb(b_zero, j + 2) * pow(2, n - (b_zero - (j+2)) - (j+2), mod)
        ans %= mod
        j += 1

z = defaultdict(lambda : 0)
for i,j in enumerate(x):
    if z[j]:
        lst.append(z[j]+1)
    z[y[i]] += 1
for i in lst:
    j = 0
    while j + 1 < i:
        if n - (i-(j+2)) - (j+2) >= 0:
            ans -= comb(i, j+2) * pow(2, n - (i-(j+2)) - (j+2), mod)
            ans %= mod
        j += 1
    n -= i
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict as dd

def ri():
    return int(input())

def rl():
    return map(int, input().split())

def rl2():
    return list(rl())

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

N = ri()
pairs = {'i': [0,0]}
for i in range(N):
    a, b = rl()
    if a == 0 and b == 0:
        continue
    elif a == 0:
        pairs['i'][0] += 1
    elif b == 0:
        pairs['i'][1] += 1
    else:
        g = gcd(abs(a), abs(b))
        a //= g
        b //= g
        if b >= 0 and a >= 0:
            slope = (a, b)
            opp   = (-b, a)
        elif b >= 0 and a < 0:
            slope = (a, b)
            opp   = (b, -a)
        elif b < 0 and a >= 0:
            slope = (-a, -b)
            opp   = (-b, a)
        else:
            slope = (-a, -b)
            opp   = (b, -a)

        if slope in pairs:
            pairs[slope][0] += 1
        elif opp in pairs:
            pairs[opp][1] += 1
        else:
            pairs[slope] = [1, 0]

tot = 1
mod = 10**9 + 7
for slope, pair in pairs.items():
    # print (slope, pair)
    tot *= (pow(2, pair[0], mod) + pow(2, pair[1], mod) - 1)
    tot %= mod
print (tot - 1)

Submission status: Wrong Answer

Solution code:
from math import gcd

mod = 1000000007

n = int(input())
counter = {}
zeros = 0
for i in range(n):
    a, b = map(int, input().split())
    if (a == 0 and b == 0):
        zeros += 1
        continue
    g = gcd(a, b)
    a //= g
    b //= g
    if (b < 0):
        a = -a
        b = -b
    if (b == 0 and a < 0):
        a = -a
    counter[(a, b)] = counter.get((a, b), 0)+1

counted = set()
ans = 1
for s, s_count in counter.items():
    if s not in counted:
        if s[0] >= 0 and s[1] >= 0:
            t = (-s[1], s[0])
        else:
            t = (s[1], -s[0])
        t_count = counter.get(t, 0)
        now = pow(2, s_count, mod)-1
        now += pow(2, t_count, mod)-1
        now += 1
        ans *= now
        ans %= mod
        counted.add(s)
        counted.add(t)
print((ans - 1 + zeros) % mod)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)


n=int(input())

mod=10**9+7

#初期値が0の辞書

pp = {} 
pm = {} 

from fractions import gcd
zero=0
for _ in range(n):
    a,b=map(int,input().split())

    if a*b!=0:
        tmp=gcd(a,b)
        a=a//tmp
        b=b//tmp

        if a*b>0:
            if (a,b) in pp:
                pp[(a,b)]+=1
            else:
                pp[(a,b)]=1
        else:
            aa=abs(a)
            bb=abs(b)
            if (aa,bb) in pm:
                pm[(aa,bb)]+=1
            else:
                pm[(aa,bb)]=1

    elif a==0 and b==0:
        zero+=1
    else:
        if (a,b) in pp:
            pp[(a,b)]+=1
        else:
            pp[(a,b)]=1

            

#print(pp_k,pm_k)
result=1
for key in pp.keys():
    pp_v=pp[key]
    a,b=key[0],key[1]
    if (b,a) in pm:
        pm_v=pm[(b,a)]
        result=result*((2**pp_v-1)+(2**pm_v-1)+1)
    else:
        result=result*(2**pp_v)

for key in pm.keys():
    pm_v=pm[key]
    a,b=key[0],key[1]
    if (b,a) not in pp:
        result=result*(2**pm_v)

print(result-1+zero)

Submission status: Wrong Answer

Solution code:
from fractions import Fraction
import sys
def input():
    return sys.stdin.readline().rstrip('\n')

ZERO = Fraction(0, 1)
Z = 1000000007

class Pow:
    def __init__(self, n):
        self.N = n
        self.e = [1] * (n + 1)
        for i in range(n):
            self.e[i + 1] = (self.e[i] * 2) % Z
    def get(self, n):
        if self.N >= n:
            return self.e[n]
        else:
            for i in range(self.N + 1, n + 1):
                self.e += [(self.e[i] * 2) % Z]
            return self.e[n]


def calc(N, G):
    zz = 0
    r = {}
    r_max = 0
    print(1)
    for a, b in G:
        if b == 0:
            if a == 0:
                zz += 1
            else:
                if 0 in r:
                    r[0][1][1] += 1
                else:
                    r[0] = {1: [0, 1]}
                r_max = max(r_max, r[0][1][1])
        else:
            if a == 0:
                if 0 in r:
                    r[0][1][0] += 1
                else:
                    r[0] = {1: [1, 0]}
                r_max = max(r_max, r[0][1][0])
            else:
                f = Fraction(a, b)
                if f > 0:
                    i = f.numerator
                    j = f.denominator
                    if i in r:
                        if j in r[i]:
                            r[i][j][0] += 1
                        else:
                            r[i][j] = [1, 0]
                    else:
                        r[i] = {j: [1, 0]}
                    r_max = max(r_max, r[i][j][0])
                else:
                    i = f.denominator
                    j = -f.numerator
                    if i in r:
                        if j in r[i]:
                            r[i][j][1] += 1
                        else:
                            r[i][j] = [0, 1]
                    else:
                        r[i] = {j: [0, 1]}
                    r_max = max(r_max, r[i][j][1])
    print(2)
    ans = 1
    pow = Pow(r_max)
    for i in r:
        for j in r[i]:
            ans = (ans * (pow.get(r[i][j][0]) + pow.get(r[i][j][1]) - 1)) % Z
    return (ans + zz - 1) % Z

    

N = int(input())
G = [tuple([int(s) for s in input().split()]) for _ in range(N)]
print(calc(N, G))

Submission status: Wrong Answer

Solution code:
from math import gcd

mod = 1000000007

n = int(input())
counter = {}
zeros = 0
for i in range(n):
    a, b = map(int, input().split())
    if (a == 0 and b == 0):
        zeros += 1
        continue
    g = gcd(a, b)
    a //= g
    b //= g
    if (b < 0):
        a = -a
        b = -b
    if (b == 0 and a < 0):
        a = -a
    counter[(a, b)] = counter.get((a, b), 0)+1

counted = set()
ans = 1
for s, s_count in counter.items():
    if s not in counted:
        if s[0] >= 0 and s[1] >= 0:
            t = (-s[1], s[0])
        else:
            t = (s[1], -s[0])
        t_count = counter.get(t, 0)
        now = pow(2, s_count, mod)-1
        now += pow(2, t_count, mod)-1
        now += 1
        ans *= now
        counted.add(s)
        counted.add(t)
print(ans - 1 + zeros)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
from math import gcd

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
C = Counter()
zero = 0
for i in range(N):
    a, b = MAP()
    if a == b == 0:
        zero += 1
    elif a == 0:
        C[(0, 1, 0)] += 1
    elif b == 0:
        C[(0, 0, 1)] += 1
    else:
        g = gcd(a, b)
        ga, gb = a // g, b // g
        C[((a < 0) ^ (b < 0), abs(ga), abs(gb))] += 1

ans = 1
for k, v in C.items():
    if v == 0:
        continue
    op, a, b = k
    ans *= pow(2, C[(op, a, b)], MOD) + pow(2, C[(1-op, b, a)], MOD) - 1
    ans %= MOD
    if (1-op, b, a) in C:
        C[(1-op, b, a)] = 0
print((zero+ans-1)%MOD)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)


n=int(input())

mod=10**9+7

#初期値が0の辞書
from collections import defaultdict
pp = defaultdict(lambda: 0) 
pm = defaultdict(lambda: 0) 

from fractions import gcd
zero=0
for _ in range(n):
    a,b=map(int,input().split())

    if a*b!=0:
        tmp=gcd(a,b)
        a=a//tmp
        b=b//tmp

        if a*b>0:
            pp[(a,b)]+=1
        else:
            pm[(a,b)]+=1
    elif a==0 and b==0:
        zero+=1
    else:
        pp[(a,b)]+=1
            

#print(pp_k,pm_k)
result=1
for key in pp.keys():
    pp_v=pp[key]
    a,b=key[0],key[1]
    pm_v=pm[(-1*b,a)]+pm[(b,-1*a)]
    if pm_v>0:
        result=result*((2**pp_v-1)+(2**pm_v-1)+1)
    else:
        result=result*(2**pp_v)

for key in pm.keys():
    pm_v=pm[key]
    a,b=key[0],key[1]
    pp_v=pp[(-1*b,a)]+pp[(b,-1*a)]

    if pp_v==0:
        result=result*(2**pm_v)

print(result-1+zero)

Submission status: Wrong Answer

Solution code:
from math import gcd

mod = 1000000007

n = int(input())
counter = {}
zeros = 0
for i in range(n):
    a, b = map(int, input().split())
    if (a == 0 and b == 0):
        zeros += 1
        continue
    g = gcd(a, b)
    a //= g
    b //= g
    if (b < 0):
        a = -a
        b = -b
    if (b == 0 and a < 0):
        a = -a
    counter[(a, b)] = counter.get((a, b), 0)+1

# print(counter)
counted = set()
ans = 1
for s, s_count in counter.items():
    if s not in counted:
        if s[0] >= 0 and s[1] >= 0:
            t = (-s[1], s[0])
        else:
            t = (s[1], -s[0])
        t_count = counter.get(t, 0)
        now = pow(2, s_count, mod)-1
        now += pow(2, t_count, mod)-1
        now += 1
        ans *= now
        print(now)
        counted.add(s)
        counted.add(t)
print(ans - 1 + zeros)

Submission status: Wrong Answer

Solution code:
from fractions import Fraction

mod = 1000000007

n = int(input())
b_a_counter = {}
zeros = 0
for i in range(n):
    a, b = map(int, input().split())
    if (a == 0 and b == 0):
        zeros += 1
        continue
    try:
        b_a = Fraction(b, a)
    except ZeroDivisionError:
        b_a = "INF"
    b_a_counter[b_a] = b_a_counter.get(b_a, 0)+1

counted = set()
ans = 1
for s, s_count in b_a_counter.items():
    if s not in counted:
        if type(s) == str:
            t = Fraction(0, 1)
        elif type(s) == Fraction:
            try:
                t = Fraction(-s.denominator, s.numerator)
            except ZeroDivisionError:
                t = "INF"
        t_count = b_a_counter.get(t, 0)
        now = pow(2, s_count, mod)-1
        now += pow(2, t_count, mod)-1
        now += 1
        ans *= now
        counted.add(s)
        counted.add(t)
print(ans - 1 + zeros)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
from math import gcd

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
C = Counter()
zero = 0
for i in range(N):
    a, b = MAP()
    if a == b == 0:
        zero += 1
    else:
        g = gcd(a, b)
        ga, gb = a // g, b // g
        C[((a < 0) ^ (b < 0), abs(ga), abs(gb))] += 1

ans = 1
for k, v in C.items():
    if v == 0:
        continue
    op, a, b = k
    ans *= pow(2, C[(op, a, b)], MOD) + pow(2, C[(1-op, b, a)], MOD) - 1
    ans %= MOD
    if (1-op, b, a) in C:
        C[(1-op, b, a)] = 0
print((zero+ans-1)%MOD)

Submission status: Wrong Answer

Solution code:
from fractions import Fraction
from collections import Counter

mod = 1000000007

n = int(input())
b_a_counter = {}
zeros = 0
for i in range(n):
    a, b = map(int, input().split())
    if (a == 0 and b == 0):
        zeros += 1
        continue
    try:
        b_a = Fraction(b, a)
    except ZeroDivisionError:
        b_a = "INF"
    b_a_counter[b_a] = b_a_counter.get(b_a, 0)+1

counted = set()
ans = 1
for s, s_count in b_a_counter.items():
    if s not in counted:
        if type(s) == str:
            t = Fraction(0, 1)
        elif type(s) == Fraction:
            try:
                t = Fraction(-s.denominator, s.numerator)
            except ZeroDivisionError:
                t = "INF"
        t_count = b_a_counter.get(t, 0)
        now = pow(2, s_count, mod)-1
        now += pow(2, t_count, mod)-1
        now += 1
        ans *= now
        counted.add(s)
        counted.add(t)
print(ans-1)

Submission status: Wrong Answer

Solution code:
import math 
n=int(input())
d=dict()
for i in range(n):
    a,b=map(int,input().split())
    if a==0 and b==0:
        pass
    elif a==0:
        a,b=0,1
    elif b==0:
        a,b=1,0
    else:
        x=math.gcd(abs(a),abs(b))
        #マイナスの除算か
        if a<0:
            a=-(-a//x)
        else:
            a=a//x
        if b<0:
            b=-(-b//x)
        else:
            b=b//x
        if a<0:
            a,b=-a,-b
    if (a,b) in d:
        d[(a,b)]+=1
    else:
        d[(a,b)]=1
#こっからは数え上げ
#print(d)
ans1,ans2=1,0
#print(d)
for i in d:
    if d[i]==0:
        continue
    if i==(0,0):
        ans2=d[i]
        d[i]=0
        continue
    a,b=i
    if (-b,a) in d:
        ans1*=(2**(d[i])+2**(d[(-b,a)])-1)
        d[(-b,a)]=0
        d[i]=0
    elif (b,-a) in d:
        ans1*=(2**(d[i])+2**(d[(b,-a)])-1)
        d[(b,-a)]=0
        d[i]=0
    else:
        ans1*=(2**(d[i]))
        d[i]=0
print(ans1+ans2-1)

Submission status: Wrong Answer

Solution code:
from fractions import Fraction
from collections import Counter

mod = 1000000007

n = int(input())
b_a = [None] * n
zeros = 0
for i in range(n):
    a, b = map(int, input().split())
    try:
        b_a[i] = Fraction(b, a)
    except ZeroDivisionError:
        b_a[i] = "INF"

b_a_counter = Counter(b_a)
counted = set()
ans = 1
for s, s_count in b_a_counter.items():
    if s not in counted:
        if type(s) == str:
            t = Fraction(0, 1)
        elif type(s) == Fraction:
            try:
                t = Fraction(-s.denominator, s.numerator)
            except ZeroDivisionError:
                t = "INF"
        t_count = b_a_counter[t]
        now = pow(2, s_count, mod)-1
        now += pow(2, t_count, mod)-1
        now += 1
        ans *= now
        counted.add(s)
        counted.add(t)
print(ans-1)