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
from collections import defaultdict
from bisect import bisect_left
from collections import Counter
sys.setrecursionlimit(10**8)
INF = float("inf")

MOD = 1000000007  # type: int


class UnionFind(object):
    def __init__(self, N):
        self.tree = list(range(N))

    def root(self, i):
        if self.tree[i] == i:
            return i
        else:
            self.tree[i] = self.root(self.tree[i])
            return self.tree[i]

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            self.tree[x] = y


def solve(N: int, A: "List[int]", B: "List[int]"):
    # 直交するイワシは選べない
    # イワシをソートする
    theta = [0]*N
    for i, (a, b) in enumerate(zip(A, B)):
        if a != 0:
            theta[i] = math.degrees(math.atan2(b, a))
        elif b > 0:
            theta[i] = math.pi/2
        else:
            theta[i] = -math.pi/2
    # print(theta)

    abtheta = sorted(zip(theta, A, B))
    # print(*abtheta, sep="\n")
    # 順にイワシを見てグループを探す。二分探索で探す。
    uf = UnionFind(N)

    nisyu = [th for th, _, _ in abtheta]*2
    nisyuni = abtheta*2

    start, end = 0, 0
    end2 = None
    for i in range(N):
        # イワシiと90度、180度、270度角度が異なるものはありますか
        # しゃくとりで
        th, a, b = abtheta[i]

        # print("A")
        # 90度の関係にあるもの
        while end <= N+i:
            thi, ai, bi = nisyuni[end]
            if ai*a+bi*b <= 0:
                break
            end += 1

        while ai*a+bi*b == 0:
            uf.unite(i, end % N)
            end += 1
            if end >= N:
                break
            thi, ai, bi = nisyuni[end]

        if end2 == None:
            end2 = end

        # print("B")
        # 270度の関係にあるもの
        while end2 <= N+i:
            thi, ai, bi = nisyuni[end2]
            if ai*a+bi*b >= 0:
                break
            end2 += 1

        # print("C")
        while ai*a+bi*b == 0:
            uf.unite(i, end2 % N)
            end2 += 1
            if end2 >= N:
                break
            thi, ai, bi = nisyuni[end2]

        if end == start + 1:
            end += 1

    # UFにグループ情報が格納されたので計算していく
    # print(uf.tree)

    # for i in range(N):
    #     _, ai, bi = abtheta[i]
    #     for j in range(i+1, N):
    #         _, aj, bj = abtheta[j]
    #         if ai*aj+bi*bj == 0:
    #             print("あるやん")
    #             print((ai, bi), (aj, bj))

    # return
    # デフォルトディクトに変換する
    d = defaultdict(list)
    for i in range(N):
        d[uf.root(i)].append(abtheta[i])

    ans = 1
    for key in d:
        # 各グループをさらに二つに分類
        maru = 1
        batu = 0
        th0, a0, b0 = d[key][0]
        for th, a, b in d[key][1:]:
            if a0 * a + b0*b == 0:
                batu += 1
            else:
                maru += 1
        buf = pow(2, maru, MOD)
        buf += pow(2, batu, MOD)
        buf -= 1
        buf %= MOD
        ans *= buf

    # print(d)
    print(ans-1)

    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:
PRIME = 1000000007
n = int(input())

fish = {}
taste_0 = 0
flavor_0 = 0

for i in range(n):
  a, b = map(int, input().split())
  if a != 0 and b != 0:
    if a / b in fish:
      fish[a / b] = fish[a / b] + 1
    else:
      fish[a / b] = 1
  elif a == 0:
    taste_0 += 1
  else:
    flavor_0 += 1

ans = pow(2, taste_0, PRIME)
ans += pow(2, flavor_0, PRIME) - 1
ans %= PRIME

cnt = 0
for f in fish:
  if - 1 / f in fish and fish[f] > 0:
    ans1 = pow(2, fish[f], PRIME)
    ans1 += pow(2, fish[-1 / f], PRIME) - 1
    ans *= ans1
    ans %= PRIME
    fish[f] = 0
    fish[-1 / f] = 0
  elif -1 / f not in fish:
    cnt += fish[f]

ans *= pow(2, cnt, PRIME)
ans %= PRIME

ans += PRIME - 1
ans %= PRIME

print(ans)

Submission status: Wrong Answer

Solution code:
import math
MOD = 10**9 + 7


def pow_k(x, n):
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K * x

n = int(input())

a_b_d = {}
# b_a_d = {}

zero_cnt = 0

for i in range(n):
    a, b = map(int, input().split()) 
    if a==0 or b==0:
        zero_cnt += 1
    else:
        gcd_ab = math.gcd(a,b)
        a = a//gcd_ab
        b = b//gcd_ab
        if a > 0 and b < 0:
            a *= -1
            b *= -1
        elif a < 0 and b < 0:
            a *= -1
            b *=-1
        a_b_d.setdefault((a,b),0)
        a_b_d[(a,b)] += 1


done_list = []
pair_cnt = []
uniq_cnt = 0
for k,v in a_b_d.items():
    comp_pair1 = (-k[1], k[0])
    comp_pair2 = (k[1], -k[0])
    if k in done_list:
        continue
    if comp_pair1 in a_b_d:
        # print(k, comp_pair)
        done_list.append(comp_pair1)
        pair_cnt.append((v,a_b_d[comp_pair1]))
    elif comp_pair2 in a_b_d:
        # print(k, comp_pair)
        done_list.append(comp_pair2)
        pair_cnt.append((v,a_b_d[comp_pair2]))
    else:
        uniq_cnt += 1


ans = pow_k(2,uniq_cnt) % MOD
for pair in pair_cnt:
    ans *= (pow_k(2,pair[0]) + pow_k(2,pair[1]) -1 )
    ans%=MOD

ans *= (zero_cnt+1)
ans -= 1
print(ans%MOD)

Submission status: Wrong Answer

Solution code:
import sys; input = sys.stdin.buffer.readline
from collections import defaultdict
from fractions import gcd
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	AB = []
	D = defaultdict(int)
	DJ = defaultdict(int)
	d0x = 0
	dx0 = 0
	for i in range(N):
		A, B = getlist()
		if A == 0 and B == 0:
			pass
		elif A == 0:
			dx0 += 1
		elif B == 0:
			d0x += 1
		else:
			GCD = gcd(A, B)
			a = int(A // GCD)
			b = int(B // GCD)
			if a < 0:
				a = -a
				b = -b
			AB.append([a, b])
			D[a * (10 ** 19) + b] += 1
			DJ[a * (10 ** 19) + b] = 1

	ans = 1

	for a, b in AB:
		a2 = b; b2 = -a
		if a2 < 0:
			a2 = -a2; b2 = -b2
		if DJ[a * (10 ** 19) + b] >= 0 and DJ[a2 * (10 ** 19) + b2] >= 0:
			DJ[a * (10 ** 19) + b] = -1
			DJ[a2 * (10 ** 19) + b2] = -1
			X = D[a * (10 ** 19) + b]
			Y = D[a2 * (10 ** 19) + b2]
			ans *= pow(2, X, con) + pow(2, Y, con) - 1

	ans *= (pow(2, d0x, con) + pow(2, dx0, con)) - 1

	print(ans - 1)

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
MOD = 10**9+7
class mint:
    def __init__(self, x):
        self.x = x % MOD if isinstance(x, int) else int(x) % MOD
    def __str__(self):
        return str(self.x)
    __repr__ = __str__
    def __iadd__(self, other):
        self.x += other.x if isinstance(other, mint) else other
        self.x -= MOD if self.x >= MOD else 0
        return self
    def __isub__(self, other):
        self.x += MOD-other.x if isinstance(other, mint) else MOD-other
        self.x -= MOD if self.x >= MOD else 0
        return self
    def __imul__(self, other):
        self.x *= other.x if isinstance(other, mint) else other
        self.x %= MOD
        return self
    def __imod__(self, other):
        self.x %= other.x if isinstance(other, mint) else other
        self.x %= MOD
        return self
    def __add__(self, other):
        return (
            mint(self.x + other.x) if isinstance(other, mint) else
            mint(self.x + other)
        )
    def __sub__(self, other):
        return (
            mint(self.x - other.x) if isinstance(other, mint) else
            mint(self.x - other)
        )
    def __mul__(self, other):
        return (
            mint(self.x * other.x) if isinstance(other, mint) else
            mint(self.x * other)
        )
    def __mod__(self, other):
        return (
            mint(self.x % other.x) if isinstance(other, mint) else
            mint(self.x % other)
        )
    def __truediv__(self, other):
        return (
            mint(
                self.x * pow(other.x, MOD - 2, MOD)
            ) if isinstance(other, mint) else
            mint(self.x * pow(other, MOD - 2, MOD))
        )
    def __pow__(self, other):
        return (
            mint(pow(self.x, other.x, MOD)) if isinstance(other, mint) else
            mint(pow(self.x, other, MOD))
        )
    __radd__ = __add__
    def __rsub__(self, other):
        return (
            mint(other.x - self.x) if isinstance(other, mint) else
            mint(other - self.x)
        )
    __rmul__ = __mul__
    def __rmod__(self, other):
        return (
            mint(other.x % self.x) if isinstance(other, mint) else
            mint(other % self.x)
        )
    def __rtruediv__(self, other):
        return (
            mint(
                other.x * pow(self.x, MOD - 2, MOD)
            ) if isinstance(other, mint) else
            mint(other * pow(self.x, MOD - 2, MOD))
        )
    def __rpow__(self, other):
        return (
            mint(pow(other.x, self.x, MOD)) if isinstance(other, mint) else
            mint(pow(other, self.x, MOD))
        )
import math

n = int(input())
a=[0]*n
b = [0]*n
for i in range(n):
    a[i],b[i] = map(int, input().split())

d=dict()
for i in range(n):
    g=math.gcd(a[i],b[i])
    if g>1:
        a[i]//=g
        b[i]//=g
    if b[i]<0:
        a[i]*=-1
        b[i]*=-1
    if a[i]==0 or b[i]==0:
        a[i]=0
        b[i]=0
    try:
        d[(a[i],b[i])]+=1
    except:
        d[(a[i],b[i])]=1
ok=n
ls=[]
for ap,bp in d.keys():
    try:
        now = d[ap,bp]
        if now==0:
            continue
    except:
        continue
    try:
        anow = ap
        bnow = bp
        if ap<0:
            anow*=-1
            bnow*=-1
        if ap!=0:
            ok = ok-now-d[(-bnow,anow)]
            ng = d[(-bnow,anow)]
            ls.append(mint(pow(2,now,MOD))+mint(pow(2,ng,MOD)-1))
            d[ap,bp]=0
            d[(-bnow,anow)]=0
        else:
            ok = ok - now
            ng = now
            ls.append(mint(now+1))
            d[ap,bp]=0
    except:
        pass

ans=mint(pow(2,ok,MOD))
for i in ls:
    ans*= i

ans-=mint(1)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
zeros = 0
m = {}

mod = 10**9 + 7

def pmod(a, x) :
	if x == 0 :
		return 1
	sq = pmod(a,x//2)
	sq = (sq * sq) % mod
	if x%2 == 0 :
		return sq
	return (sq * a) % mod

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

def norm(x) :
	a, b = x[0], x[1]
	if a < 0 :
		return (-a,-b)
	if a == 0 :
		return (0,1)
	return (a,b)

for _ in range(n):
	a,b = map(int, input().split())
	if a == 0 and b == 0:
		zeros += 1
		continue
	d = gcd(abs(a), abs(b))
	a, b = a/d, b/d;
	x = norm((a,b))
	if x in m :
		m[x] += 1;
	else :
		m[x] = 1

ans = 1
for u in m:
	ile = m[u]
	a, b = u[0], u[1]
	m[u] = 0
	ile2 = 0
	inv = norm((b, -a))
	if inv in m:
		ile2 = m[inv]
		m[inv] = 0
	ans = (ans * (pmod(2, ile) + pmod(2, ile2) - 1)) % mod;

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

Submission status: Wrong Answer

Solution code:
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def init_dp1(init, N): return [init for _ in range(N)]
def init_dp2(init, N, M): return [[init for _ in range(M)] for _ in range(N)]


def f(v, k, L, K, A):
    p = v[0]
    t = -1 / k
    i = bisect.bisect_right(L, t)
    if i != len(L):
        q = K[L[i]][0]
        if A[p][0] * A[q][0] + A[p][1] * A[q][1] == 0:
            return L[i]

    if i + 1 < len(L):
        q = K[L[i + 1]][0]
        if A[p][0] * A[q][0] + A[p][1] * A[q][1] == 0:
            return L[i + 1]
    
    if i > 0:
        q = K[L[i - 1]][0]
        if A[p][0] * A[q][0] + A[p][1] * A[q][1] == 0:
            return L[i - 1]

    return t


def main():
    N = int(input())
    A = read_lists(N)    

    K = {}
    for i, a in enumerate(A):
        if a[0] == 0:
            r = 10 ** 20
        else:
            r = a[1] / a[0]
        K.setdefault(r, []).append(i)

    L = sorted(list(K.keys()))    

    S = set()
    res = 1
    for k, v in K.items():
        if k in S:
            continue
        S.add(k)

        if k == 0:
            t = 10 ** 20
        elif k == 10 ** 20:
            t = 0
        else:
            t = f(v, k, L, K, A)

        if t in K:
            S.add(t)
            v2 = K[t]
            res *= (pow(2, len(v), mod) + pow(2, len(v2), mod) - 1)
            res %= mod
        else:
            res *= 2
            res %= mod

    print((res - 1) % mod)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
freq = {}
ans = 1
add = -1
for i in range(n):
    a,b=map(int, input().strip().split())
    if not (a or b):
        add += 1
        continue
    if not a:
        b = 1
    elif not b:
        a = 1
    else:
        if b < 0: a,b=-a,-b
        c = math.gcd(abs(a),b)
        a //= c
        b //= c
        t = (a,b)
        if t not in freq:
            freq[t] = 1
        else:
            freq[t] += 1
mod = 1000000007
vis = set()
for i in freq:
    if i in vis: continue
    vis.add(i)
    a,b=i
    t = (b,-a) if a<=0 else (-b,a)
    if t in freq:
        vis.add(t)
        ans = ans*(pow(2,freq[t],mod)+pow(2,freq[i],mod)-1)%mod
    else:
        ans = ans*pow(2,freq[i],mod)%mod
print((ans+add)%mod)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
from functools import cmp_to_key
 
def main():
    n = int(readline())
    x, y  = [], []
    add = 0
    for i in range(n):
        a, b = map(int, readline().split())
        if a == 0 and b == 0:
            add += 1
            continue
        x.append(a)
        y.append(b)

    p = []
    index = 0
    for a, b in zip(x, y):
        cx = a
        cy = b
        if (-cx, -cy) > (cx, cy):
            cx = -cx
            cy = -cy
        p.append((cx, cy, 1, index))
        
        cx = b
        cy = -a
        if (-cx, -cy) > (cx, cy):
            cx = -cx
            cy = -cy
        p.append((cx, cy, 2, index))

        index += 1

    def compare(p1, p2):
        x1, y1, _, __ = p1
        x2, y2, _, __ = p2
        return x1 * y2 - x2 * y1

    p = sorted(p, key=cmp_to_key(compare))
    #print p

    mod = 1000000007

    def GetValue(group):
        min1 = 10 ** 10
        min2 = 10 ** 10
        pow1 = 1
        pow2 = 1
        for g in group:
            _, __, t, i = g
            if t == 1:
                min1 = min(min1, i)
                pow1 = pow1 * 2 % mod
            else:
                min2 = min(min2, i)
                pow2 = pow2 * 2 % mod
        result = (pow1 + pow2 - 1 + mod) % mod
        if min1 > min2:
            result = 1
        #print group, result
        return result
        

    group = []
    result = 1
    for i in range(len(p) + 1):
        if i == len(p) or (len(group) > 0 and compare(group[-1], p[i]) != 0):
            result = result * GetValue(group) % mod 
            group = []
        if i < len(p):
            group.append(p[i])

    result = max(0, result - 1)

    print(result + add)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from math import gcd
MOD = 10 ** 9 + 7
N = int(input())
d = dict()
for _ in range(N):
    a, b = tuple(map(int, input().split()))
    g = gcd(a, b) * (a // abs(a) if a else 1)
    p = (a // g, b // g) if g else (a, b)
    d[p] = d.get(p, 0) + 1
counts = dict()
for k, v in d.items():
    a, b = k
    if counts.get((b, -a), False) or counts.get((-b, a), False):
        continue
    counts[k] = v, d.get((b, -a), 0) + d.get((-b, a), 0)
total = 1
for k, v in counts.items():
    if not any(k):
        total = (total * (v[0] + 1)) % MOD
        continue
    a, b = v
    total = (total * (pow(2, a, MOD) + pow(2, b, MOD) - 1)) % MOD
print((total + MOD - 1) % MOD)

Submission status: Wrong Answer

Solution code:
n=int(input())
mod = 1000000007
gp = []
gm = []
ga0  =0
gb0 = 0
ans = 1
cnt = 0
for _ in range(n):
    a,b= map(int,input().split())
    #a,b = 1,1
    if a == 0 and b == 0:
        cnt += 1
    elif  a == 0:
        ga0 += 1
    elif b == 0:
        gb0 += 1
    elif b/a > 0:
        gp.append(b/a)
    else:
        gm.append(b/a)
gp.sort()
gm.sort()

lp,lm=0,0
cntall = 0
while lp < len(gp) and lm < len(gm):
    cal = gp[lp]*gm[lm]
    if cal == -1:
        cntp,cntm = 1,1
        while lp +1 < len(gp) and  gp[lp] == gp[lp+1]:
            cntp += 1
            lp+=1
        while lm +1 < len(gm) and  gm[lm] == gm[lm+1]:
            cntm += 1
            lm+=1
        ans *= (pow(2,cntp,mod)+pow(2,cntm,mod))%mod-1
        ans %= mod
        lp+=1
        lm+=1
        cntall += cntp+cntm
    elif cal > -1:
        lp += 1
    else:
        lm += 1

ans *= (pow(2,ga0,mod)+pow(2,gb0,mod))%mod-1
ans %= mod
n -= ga0+gb0+cntall+cnt
ans *= pow(2,n,mod)
ans %= mod
ans += cnt - 1
ans %= mod
print(ans)

Submission status: Wrong Answer

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

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

S=[tuple(map(int,input().split())) for i in range(N)]

from collections import Counter
from fractions import Fraction
C=Counter()

for a,b in S:
    if a==0 and b==0:
        continue
    if b!=0:
        C[Fraction(a,b)]+=1
    else:
        C[float("inf")]+=1
    
ANS=0

#print(C)
P=[]

for x in list(C.keys()):
    if x!=float("inf") and x!=Fraction(0,1):
        n=x.numerator
        d=x.denominator

        P.append((C[x],C[Fraction(-d,n)]))
        C[x]=0
        C[Fraction(-d,n)]=0
    else:
        P.append((C[float("inf")],C[Fraction(0,1)]))
        C[float("inf")]=0
        C[Fraction(0,1)]=0

ANS=1
for x,y in P:
    if x==0 and y==0:
        continue
    else:
        #print(x,y,pow(2,x,mod)+pow(2,y,mod)-1)
        ANS=ANS*(pow(2,x,mod)+pow(2,y,mod)-1)%mod

print((ANS-1)%mod)

Submission status: Wrong Answer

Solution code:
import math
def heikatu(A,B):
    if A % abs(B) ==0:
        return (A//abs(B),B//abs(B))
    if abs(B) % A == 0:
        return (1,B//A)
    
    c = 2
    while c <=math.sqrt(max(A,abs(B))):
        while A % c ==0 and B% c ==0:
            A //=c
            B//=c
        c+=1

    return (A,B)


def pow_r(x, n,mod=10**9+7):
    """
    O(log n)
    """
    if n == 0:  # exit case
        return 1
    if n % 2 == 0:  # standard case ① n is even
        return pow_r((x ** 2)%1000000007 , n // 2) % mod
    else:  # standard case ② n is odd
        return (x * pow_r((x ** 2)%1000000007, (n - 1) // 2) % mod) % mod



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

    kp = dict()
    km = dict()
    zero = [0,0]
    for i in range(N):
        A,B = map(int,input().split())
        if A <0:
            A *= -1
            B *= -1

        if A == 0:
            zero[0]+=1
            continue
        if B == 0:
            zero[1]+=1
            continue

        xx = heikatu(A,B)



        if B < 0:
            if not xx in km:
                km[xx]=0
            km[xx]+=1
        else:
            if not xx in kp:
                kp[xx]=0
            kp[xx]+=1

    tx = []
    if zero != [0,0]:
        tx.append(zero)

    for key in kp:
        A,B = key
        cou = kp[key]    
        if (B,-A) in km:
            tx.append([cou,km[(B,-A)]])
            km.pop((B,-A))
        else:
            tx.append([cou,0])
    for key in km:
        tx.append([0,km[key]])

    ans = 1
    mod = 1000000007
    for a,b in tx:
        xxx = 0
        if a != 0:
            xxx+=pow_r(2,a)
        if b != 0:
            xxx+=pow_r(2,b)
        if a !=0 and b!=0:
            xxx-=1
        ans = (ans*xxx) % mod

    ans = (ans+mod-1) % mod 

    print(ans)       


        







resolve()

Submission status: Wrong Answer

Solution code:
from decimal import *
MOD = 1000000007

def solve(N, ABs):
    groups = {}
    L = 10**18
    zero_count = 0
    for a, b in ABs:
        if a == 0 and b == 0:
            zero_count += 1
            continue
        if b == 0:
            k = "INF"
        else:
            k = Decimal(a) / Decimal(b)
        groups.setdefault(k, 0)
        groups[k] += 1

    visited = set()
    possibles = []
    for k, v in groups.items():
        if k in visited:
            continue
        p = 0
        p += pow(2, v, MOD)
        if k == "INF":
            m = 0
        elif k == 0:
            m = "INF"
        else:
            m = - (Decimal(1) / Decimal(k))
        if m in groups.keys():
            p += pow(2, groups[m], MOD)
            visited.add(m)
            p -= 1
        possibles.append(p % MOD)

    ans = 1
    for p in possibles:
        ans *= p
        ans %= MOD

    if zero_count:
        ans += zero_count
        ans %= MOD
    return ans - 1


def slow_solve(N, ABs):
    import itertools
    ans = 0
    for k in range(1, 2**N):
        b = ("{:0" + str(N) + "b}").format(k)
        taken = []
        for i, c in enumerate(b):
            if c == "1":
                taken.append(ABs[i])

        if len(taken) == 1:
            ans += 1
        elif all(comb[0][0] * comb[1][0] + comb[0][1] * comb[1][1] != 0
                 for comb in itertools.combinations(taken, 2)):
            ans += 1
    return ans

# print(slow_solve(3,
#       [(1, 2), (-1, 1), (2, -1)]))
#
# print(slow_solve(10,
#       [(3, 2), (3, 2), (-1, 1), (2, -1), (-3, -9), (-8, 12), (7, 7), (8, 1), (8, 2), (8, 4)]))

# print(slow_solve(3, [(7, 9), (-9, 7), (-4, -2)]))
# print(solve(3, [(7, 9), (-9, 7), (-4, -2)]))
# input()
#
# def create(N):
#     import random
#     ABs = []
#     MM = 1000
#     for _ in range(N):
#         ABs.append( (random.randint(-MM, MM), random.randint(-MM, MM)))
#     return ABs
#
# for _ in range(100):
#     for N in range(1, 10):
#         ABs = create(N)
#         if solve(N, ABs) != slow_solve(N, ABs):
#             print("ERROR")
#             print(N)
#             print(ABs)
#             break
#
# print("OK")


if __name__ == "__main__":
    N = int(input())
    ABs = [tuple(map(int, input().split(" "))) for _ in range(N)]
    print(solve(N, ABs))

Submission status: Wrong Answer

Solution code:
import math 

MOD = 10**9 + 7
N = int(input())
ABC = []
for i in range(N):
    a, b = map(int, input().split())
    if a * b >=0 and a > 0:
        ABC.append([ math.atan2(abs(b),abs(a)), abs(a), abs(b),1])
    else:
        ABC.append([math.atan2(abs(a),abs(b)), abs(b), abs(a), -1])
ABC.sort()
print(ABC)
current_arg = ABC[-1][0]
group = []
daiich = 0
daini = 0
while ABC:
    current = ABC.pop()
    if current[0] == current_arg:
        if current[3]==1:
            daiich += 1
        else:
            daini += 1
    else:
        group += [[daiich, daini]]
        daiich = 0
        daini = 0
        if current[3]==1:
            daiich += 1
        else:
            daini += 1
        if ABC:
            current_arg = ABC[-1][0]
else:
    group += [[daiich, daini]]
    daiich = 0
    daini = 0

ans = -1
for u, v in group:
    ans *= (2**u + 2**v -1)
    ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from math import gcd
input = sys.stdin.readline
n = int(input())
fish = dict()
zero = 0
for i in range(n):
    a, b = map(int, input().split())
    if a == 0:
        if b == 0:
            zero += 1
            continue
        else:
            b = -1
    elif b == 0:
        a = 1
    else:
        g = gcd(a, b)
        a //= g
        b //= g
        if a < 0 and b < 0:
            a = -a
            b = -b
        elif b < 0:
            a = -a
            b = -b

    if (a, b) not in fish:
        fish[(a, b)] = 1
    else:
        fish[(a, b)] += 1

ans = 1
pair = []
mod = 10**9+7
while fish:
    key, value = fish.popitem()
    a, b = key
    if a < 0:
        if (b, -a) in fish:
            pair.append((value, fish[(b, -a)]))
            fish.pop((b, -a))
        else:
            ans *= pow(2, value, mod)
    elif b == 0:
        if (0, -1) in fish:
            pair.append((value, fish[(0, -1)]))
            fish.pop((0, -1))

    else:
        if (-b, a) in fish:
            pair.append((value, fish[(-b, a)]))
            fish.pop((-b, a))
        else:
            ans *= pow(2, value, mod)

for a, b in pair:
    temp = 1
    temp += pow(2, a, mod)-1
    temp += pow(2, b, mod)-1
    ans *= temp
    ans %= mod


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

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = []
b_list = []
mod = 10 ** 9 + 7
for _ in range(n):
    a, b = map(int, input().split())
    a_list.append((a * pow(b, mod - 2, mod)) % mod)
    b_list.append((b * pow(a, mod - 2, mod)) % mod)
count = n
out = 0
for aa in a_list:
    num = b_list.count((aa * (-1)) % mod)
    out += pow(2, count - num - 1, mod)
    out = out % mod
    count -= 1
    b_list.pop(0)
print(out)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import math
mod=1000000007
n=int(input())
dic=defaultdict(int)
x=[]
zerozero,azero,bzero=0,0,0
two=[1]

for i in range(n):
    two.append(two[-1]*2%mod)

for _ in range(n):
        
    a,b=map(int,input().split())
    if a==0 and b==0: zerozero+=1
    elif a==0: azero+=1
    elif b==0: bzero+=1
    else:
        k=math.gcd(a,b)
        a//=k;b//=k
        if a<0: a*=-1;b*=-1
        dic[(a,b)]+=1
        if a*b>0: dic[(b,-a)]+=0
        else: dic[(-b,a)]+=0

for (a,b) in dic:
    if a*b>0:
        x.append([ dic[(a,b)], dic[(b,-a)] ])
x.append([azero,bzero])
ans=1
for [p,q] in x:
    ans*=(two[p]+two[q]-1)
    ans%=mod

print(ans-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
B = []
for i in range(N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
cou = 0

for i in range(N):
    if A[i]>1000000000:
        x1 = A[i]/1000000000
    else:
        x1 = A[i]
    if B[i]>1000000000:
        y1 = B[i]/1000000000
    else:
        y1 = B[i]
        
    for j in range(N):
        if A[j]>1000000000:
            x2 = A[j]/1000000000
        else:
            x2 = A[j]
        if B[i]>1000000000:
            y2 = B[j]/1000000000
        else:
            y2 = B[j]
        
        if not x1*x2+y1+y2 ==0:
            cou+=1

print(cou/1000000007)

Submission status: Wrong Answer

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

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
        else:
            C[a/b] += 1
    D = tuple(C.items())
    used = {0}
    for c, v in D:
        if c in used:
            continue
        ans *= (pow(2, v, MOD)+pow(2, C[-(1/c)], MOD)-1)
        ans %= MOD
        used.add(-(1/c))
    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:
from collections import defaultdict
import math
mod=1000000007
n=int(input())
dic=defaultdict(int)
x=[]
zerozero,azero,bzero=0,0,0
two=[1]

for i in range(n):
    two.append(two[-1]*2%mod)

for _ in range(n):
        
    a,b=map(int,input().split())
    if a==0 and b==0: zerozero+=1
    elif a==0: azero+=1
    elif b==0: bzero+=1
    else:
        k=math.gcd(a,b)
        a//=k;b//=k
        if a<0: a*=-1;b*=-1
        dic[(a,b)]+=1
        if a*b>0: dic[(b,-a)]+=0
        else: dic[(-b,a)]+=0

for (a,b) in dic:
    if a*b>0:
        x.append([ dic[(a,b)], dic[(b,-a)] ])
x.append([azero,bzero])
ans=1
for [p,q] in x:
    ans*=(two[p]+two[q]-1)
    ans%=mod
print(x)

print(ans-1)

Submission status: Wrong Answer

Solution code:
def main():
    #from fractions import Fraction
    n = int(input())
    ab = [list(map(int, input().split())) for _ in [0]*n]
    adb = dict()
    ans = 0
    mod = 10**9+7
    for a, b in ab:
        if a == b == 0:
            ans += 1
            continue
        if b != 0:
            adb[a/b] = adb.get(a/b, 0)+1
        else:
            adb[None] = adb.get(None, 0)+1
    ans2 = 1
    for i, j in adb.items():
        if i == None:
            k = 0
        elif i == 0:
            k = None
        else:
            k = -1/i
        if k not in adb:
            ans2 = ans2*pow(2, j, mod) % mod
        else:
            if i is None:
                continue
            if i >= 0:
                ans2 = ans2*(pow(2, j, mod)+pow(2, adb[k], mod)-1) % mod
    ans2 = (ans2-1) % mod
    print((ans+ans2) % mod)


main()

Submission status: Wrong Answer

Solution code:
from math import gcd
import random
n = int(input())
mod = 10**9 + 7
d1 = dict()
d2 = dict()
a_zero,b_zero = 0,0

# サンプル入力
#n = 2*10**5
#data = [[random.randint(-10**18,10**18),random.randint(-10**18,10**18)] for _ in range(n)]
for i in range(n):
    a,b = map(int, input().split())
    #a,b = data[i]
    if a == 0 and b == 0:
        continue
    if a == 0:
        a_zero += 1
        continue
    if b == 0:
        b_zero += 1
        continue
    a,b = a//gcd(a,b),b//gcd(a,b)
    if a < 0:
        a *= -1
        b *= -1

    if (a,b) in d1:
        d1[(a,b)] += 1
    else:
        d1[(a,b)] = 1

ans =  1
ans *= pow(2,a_zero,mod)+pow(2,b_zero,mod)-1
ans %= mod
for a,b in d1:
    if b > 0 and (b,-a) in d1:
        ans *= pow(2,d1[(a,b)],mod)+pow(2,d1[(b,-a)],mod)-1
        d1[(a,b)] = 0
        d1[(b,-a)] = 0
    elif b < 0 and (-b,a) in d1:
        ans *= pow(2,d1[(a,b)],mod)+pow(2,d1[(-b,a)],mod)-1
        d1[(a,b)] = 0
        d1[(-b,a)] = 0
    else:
        ans *= pow(2,d1[(a,b)],mod)
    ans %= mod
    #print(a,b,d1)
print(ans-1)