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:
n=int(input())
dic={}
sus_a=0
sus_b=0
for i in range(n):
  a,b=map(int,input().split())
  if a==0 and b==0:
    continue
  elif a==0:
    sus_a+=1
    continue
  elif b==0:
    sus_b+=1
    continue
  x=a*1.0/b
  if x in dic.keys():
    dic[x] += 1
  else:
    dic[x] = 1
ans=1
for k,v in dic.items():
  if v==0:
    continue
  if -1.0/k not in dic:
    ans *= 2
  else:
    ans *= (2**v+2**(dic[-1.0/k])-1)
    dic[-1.0/k]=0

print(ans-1)
if sus_a * sus_b >0:
  ans *= (2**sus_a + 2**sus_b-1)
elif sus_a >0:
  ans *= 2**sus_a
elif sus_b>0:
  ans *= 2**sus_b
print((ans-1) % 1000000007)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
mod = 1000000007
degs = {}
ans = 1
for i in range(N):
    A,B = map(int,input().split())
    if(A!=0):
        ab = B/A
    else:
        ab = "mugen"
    if(ab==0):
        nakawaru = "mugen"
    elif(ab == "mugen"):
        nakawaru = 0
    else:
        nakawaru = -1/ab
    if(ab not in degs.keys()):
        degs[ab] = 1
    else:
        degs[ab] += 1
    if(nakawaru not in degs.keys()):
        ans = ans*2%mod
    else:
        waru = pow(2,degs[nakawaru],mod)
        ans = (ans + ans*pow(waru,mod-2,mod)%mod)%mod
    
print((ans-1)%mod)

Submission status: Wrong Answer

Solution code:
# --*- coding: utf-8 -*-
# 標準入力の取得
N = int(input())
A, B = [], []
for n in range(N):
    A_n, B_n = list(map(int, input().split()))
    A.append(A_n)
    B.append(B_n)

# 求解処理
sardines = list(range(N))
result = 1
while len(sardines) >= 0:
    if len(sardines) == 1:
        result *= 2
        break
    i = sardines[0]
    A_i = A[i]
    B_i = B[i]
    group = [i]
    for j in sardines[1:]:
        A_j = A[j]
        B_j = B[j]
        if (A_i*A_j + B_i*B_j == 0) or (A_i*B_j == A_j*B_i):
            group.append(j)
    result *= len(group) + 1
    print(group)
    for g in group:
        sardines.remove(g)

print((result - 1) % 1000000007)

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
ans += betu[2]
ans %= mod

print(ans-1)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from fractions import Fraction

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

MOD = 1000000007
d_plus = defaultdict(int)  # + or ∞
d_minus = defaultdict(int)  # - or 0
ans = 1

for i, (a, b) in enumerate(X):
    if a == 0 and b == 0:
        continue
    elif a == 0:
        d_minus[0] += 1
    elif b == 0:
        d_plus[float('inf')] += 1
    elif a * b > 0:
        d_plus[Fraction(a, b)] += 1
    else:
        d_minus[Fraction(a, b)] += 1


def pair(p):
    if p == 0:
        return float('inf')
    elif p == float('inf'):
        return 0
    else:
        return -1 / p


for m in d_minus:
    d_plus[pair(m)] += 0
for p in d_plus:
    ans = ans * (pow(2, d_plus[p], MOD) + pow(2, d_minus[pair(p)], MOD) - 1)
    ans %= MOD
print((ans - 1) % MOD)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



import bisect
from math import gcd
n = int(input())
l = [None] * n
for i in range(n):
    a,b = map(int, input().split())
    g = gcd(a,b)
    if g==0:
        g = 1
    l[i] = (a//g, b//g)

l.sort()
M = 1000000007
seen = [False] * n
vals = []

def sub(item):
    item1 = (item[1], -item[0])
    item2 = (-item[1], item[0])
    tmp = None
    count = 0
    li = bisect.bisect_left(l, item1)
    ri = bisect.bisect_right(l, item1)
    count += (ri-li)
    for v in range(li, ri):
        seen[v] = True
    if ri>li:
        tmp = l[li]
        
    li = bisect.bisect_left(l, item2)
    ri = bisect.bisect_right(l, item2)
    count += (ri-li)
    for v in range(li, ri):
        seen[v] = True
    if ri>li:
        tmp = l[li]
    
    return count, tmp

for i,item in enumerate(l):
    if seen[i]:
        continue
    elif item==(0,0):
        continue
    count,tmp = sub(item)
    if count>0:
        count2, tmp = sub(tmp)
        vals.append((pow(2,count,M)+pow(2,count2,M)-1)%M)
    else:
        vals.append(2)
ans = 1
for v in vals:
    ans *= v
    ans %= M
ans -= 1
print(ans-1)

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 = {}

    for i in range(N):
        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]


        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
    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:
from collections import defaultdict 
import sys
input = sys.stdin.readline
from math import gcd

MOD = 10 ** 9 + 7

dic = 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))
        dic[(0, 1)] += 1
    elif b == 0:
        S.add((1, 0))
        dic[(1, 0)] += 1
    else:
        GCD = gcd(a, b)
        a //= GCD
        b //= GCD
        if a < 0: #aを必ず正にする
            a *= -1
            b *= -1
        S.add((a, b))
        dic[(a, b)] += 1
        

lst = []
for a, b in S:
    tmp1 = dic[(a, b)]
    A = a
    B = b
    if B < 0:
        B *= -1
        A *= -1
    tmp2 = dic[(B, -A)]
    dic[(B, -A)] = 0
    if tmp1 > 0:
        lst.append((tmp1, 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)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
import sys
sys.setrecursionlimit(10**9)
from collections import deque,defaultdict
import heapq
from itertools import combinations
import bisect


mod=10**9+7

n=int(input())

dp=defaultdict(int)
dm=defaultdict(int)
z=0
ans=0
cp=[]
cm=[]
az=0
bz=0
cz=0
for i in range(n):
    a,b=map(int,input().split())
    if a*b>0:
        p=(abs(a)*pow(abs(b),mod-2,mod))%mod
        pp=(abs(b)*pow(abs(a),mod-2,mod))%mod
        if dp[p]==0:
            cp.append([p,pp])
        dp[p]+=1
    elif a*b<0:
        p=(abs(a)*pow(abs(b),mod-2,mod))%mod
        dm[p]+=1
    elif a==b==0:
        cz+=1
    elif a==0:
        az+=1
    elif b==0:
        bz+=1

kk=pow(2,az,mod)+pow(2,bz,mod)+cz-1
if kk>0:
    ans=kk
else:
    ans=1
z=n-(az+bz+cz)
for a,b in cp:
    ans*=pow(2,dp[a],mod)+pow(2,dm[b],mod)-1
    ans%=mod
    z-=(dp[a]+dm[b])
# print(z)
ans*=pow(2,z,mod)

print((ans-1)%mod)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf
# @pysnooper.snoop()
#import pysnooper # debug

import math
#from sortedcontainers import SortedList, SortedDict, SortedSet # no in atcoder
import bisect
from fractions import Fraction

# NG: ai / bi (atk) = - bj / aj (agi)

mod = 1000000007

class Solver:

    def __init__(self, n):
        self.n = n
        self.atk = []
        self.agi = {}
        self.ans = 0

    def fishing(self, id_, a, b):
        if a == 0:
            a = 10 ** 19
        if b == 0:
            b = 10 ** 19
        atk = Fraction(a, b)
        self.atk.append(atk)
        agi = Fraction(-1 * b / a)
        if agi not in self.agi:
            self.agi[agi] = []
        self.agi[agi].append(id_)

    def check(self, i):
        atk = self.atk[i]
        if atk in self.agi:
            #print(self.agi[atk]) # debug
            return self.agi[atk]
        else:
            return []

    def run(self):
        ng = [False] * self.n
        free = 0
        self.f(0, ng[:], free)
        return self.ans - 1

    def f(self, i, ng, free):
        #print('f') # debug
        #print('ng') # debug
        #print(ng) # debug
        while i < self.n:
            #print('i') # debug
            #print(i) # debug
            if ng[i]:
                i += 1
                continue
            enemy = self.check(i)
            #print('enemy') # debug
            #print(enemy) # debug
            if len(enemy) == 0:
                free += 1
            else:
                #print('else') # debug
                self.f(i + 1, ng[:], free)
                for e in enemy:
                    ng[e] = True
            i += 1
        self.ans += 2 ** free % mod
        #print('f end', free) # debug





if __name__ == '__main__':
    n = int(input())
    solver = Solver(n)
    for i in range(n):
        a, b = list(map(int, input().split()))
        solver.fishing(i, a, b)

    ans = solver.run()
    #print('ans') # debug
    print(ans)


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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
MOD = 1000000007
s = {}

for _ in range(N):
    A, B = map(int, input().split())
    if B == 0:
        key = float('inf')
    else:
        key = A/B
    if s.get(key) == None:
        s[key] = 1
    else:
        s[key] += 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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
AB = [list(map(int,input().split())) for _ in range (N)]
MOD = 10**9+7

from collections import defaultdict
dnums = defaultdict(int)
dnums2 = defaultdict(int)
num_zero = 0
num_az = 0
num_bz = 0
keys = set()
for a,b in AB:
    if a!=0 and b!=0:
        dnums[b/a] += 1
        keys.add(b/a)
        dnums2[-a/b] += 1
    elif a==0 and b==0:
        num_zero += 1
    elif a == 0 and b!=0:
        num_az += 1
    elif a != 0 and b==0:
        num_bz += 1

mydict = dict()
for key in list(keys):
    mydict[key] = False

ans = 1
for key in list(keys):
    if mydict[key]:
        continue
    if -1/key in keys:
        mydict[-1/key] = True
        mydict[key] = True

    if dnums2[key] != 0:
        ans *= pow(2, dnums[key], MOD) + pow(2, dnums2[key], MOD) - 1
    else:
        ans *= 2

ans *= pow(2, num_az, MOD) + pow(2, num_bz, MOD) - 1
ans += num_zero
ans += MOD - 1
print(ans%MOD)

Submission status: Wrong Answer

Solution code:
from math import gcd

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

t = []
d = {}
for a, b in AB:
    i = gcd(a, b)
    if i != 0:
        a //= i
        b //= i
    t.append((a, b))
    d.setdefault(a, {})
    d[a].setdefault(b, 0)
    d[a][b] += 1

used = set()
result = 1
for a, b in t:
    if (a, b) in used:
        continue
    used.add((a, b))
    if a == 0 and b == 0:
        i = d[a][b]
        result *= pow(2, i, 1000000007) - 1
        result %= 1000000007
    else:
        i = d[a][b]
        j, k, l = 0, 0, 0
        if -a in d and -b in d[-a]:
            j = d[-a][-b]
            used.add((-a, -b))
        if -b in d and a in d[-b]:
            k = d[-b][a]
            used.add((-b, a))
        if b in d and -a in d[b]:
            l = d[b][-a]
            used.add((b, -a))
        result *= pow(2, i + j, 1000000007) + pow(2, k + l, 1000000007) - 1
        result %= 1000000007
print(result - 1)

Submission status: Wrong Answer

Solution code:
n = int(input())
import collections
number_list = []
for i in range(n):
  a, b = map(int, input().split())
  if a!=0 and b!= 0:
    number_list.append(a/b)
  else:
    number_list.append(0)
c = collections.Counter(number_list)
keys = c.keys()
number = c.values()
ans_list = []
num = 0
z = []
for i in keys:
  if i < 0:
    if (-1)/i in keys:
      x = c[i]
      y = c[(-1)/i]
      ans_list.append(2**(x + y) - (2**x - 1)*(2**y - 1))
      num += x + y
if c[0] >= 2:
  num += c[0]
ans =2**(n - num)
if c[0] >= 2:
  ans *= 2
for i in ans_list:
  ans *= i
ans -= 1  
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import Fraction
import sys
input = sys.stdin.readline
def powmod(x, n,mod):
  if n == 0:
   return 1
  K = 1
  while n > 1:
   if n % 2 != 0:
    K = K * x%mod
    x = x ** 2%mod
    n = (n - 1) // 2
   else:
    x = x ** 2%mod
    n = n // 2%mod

  return K * x # 指数を割り続け n が 1 に至ったら終了
N=int(input())
mod=10**9+7
dic={}
dica={}
c=0
d=0
for i in range(N):
 A,B = map(int,input().split())
 if A==0 and B==0:
  continue
 elif A==0:
  c+=1
 elif B==0:
  d+=1
 else:
   x=Fraction(A,B)
   if x>0:
    if x in dic:
     dic[x]+=1
    else:
     dic[x]=1
   else:
    if x in dic:
     dica[x]+=1
    else:
     dica[x]=1
ans=1
for k in dic:
 if -1/k in dica:
   ans*=(powmod(2,dic[k],mod)+powmod(2,dica.pop(-1/k),mod) -1)
   ans%=mod
 else:
   ans*=powmod(2,dic[k],mod)
   ans%=mod
for k in dica:
 ans*=powmod(2,dica[k],mod)
 ans%=mod
ans*=(powmod(2,c,mod)+powmod(2,d,mod)-1)
ans%=mod
print(ans-1)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd, atan2
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
AB = [LIST() for _ in range(N)]

dic = defaultdict(int)

tmp = []
for A, B in AB:
	if A == 0 and B == 0:
		N -= 1
		continue
	tmp.append([A, B])

AB = deepcopy(tmp)

for A, B in AB:
	dic[atan2(B, A)] += 1

cnt = 0
kumi = 0
cnt_rad = defaultdict(int)

for A, B in AB:
	rad = atan2(B, A)
	if dic[rad+pi/2]:
		if cnt_rad[rad+pi/2]:
			N -= 1
			cnt_rad[rad+pi/2] += 1
		else:
			cnt_rad[rad+pi/2] = 1
			N -= 2

ans = pow(2, N, mod)
tmp = 0
for v in cnt_rad.values():
	ans *= (2+(pow(2, v, mod)-1))
	ans %= mod
print((ans-1)%mod)

Submission status: Wrong Answer

Solution code:
import math
import collections

n = int(input())
iwashi = [None for _ in range(n)]
for i in range(n):
    a, b = map(int, input().split())
    iwashi[i] = (math.degrees(math.atan2(a, b)) + 180) % 180
# print(iwashi)
iwashi = collections.Counter(iwashi)
k_list = list(iwashi.keys())
v = list(iwashi.values())
# k_list.sort(key=lambda x: -x)

mod = 1000000007
ans = 1
for k in k_list:
    a = iwashi[k]
    b = iwashi[k+90] + iwashi[k-90]
    if a*b != 0:
        ans *= (pow(2, a, mod) + pow(2, b, mod) -1)
    else:
        ans *= pow(2, a, mod)
    iwashi[k] = 0
    iwashi[k+90] = 0
    iwashi[k-90] = 0
    # print(a, b, ans)
    ans %= mod
print(ans-1)

Submission status: Wrong Answer

Solution code:
import os
from collections import Counter

import math
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N = int(sys.stdin.buffer.readline())
AB = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N)]

zeros_cnt = 0
A = []
B = []
for a, b in AB:
    if a == 0 or b == 0:
        zeros_cnt += 1
    else:
        g = math.gcd(a, b)
        A.append(a // g)
        B.append(b // g)

ab = [(a, b) for a, b in zip(A, B)]
ba = [(b, a) for a, b in zip(A, B)]

counts = Counter(ba)
ans = 1
nandemo = 0
seen = set()
for (a, b), cnt in Counter(ab).items():
    cc = counts[-a, b] + counts[a, -b]
    if cc == 0:
        nandemo += cnt
    else:
        if not ((a, -b) in seen or (-a, b) in seen):
            seen.add((b, a))
            ans *= pow(2, cnt, MOD) + pow(2, cc, MOD) - 1
            ans %= MOD
ans *= zeros_cnt + 1
ans %= MOD
ans *= pow(2, nandemo, MOD)
ans -= 1
ans %= MOD
print(ans)

Submission status: Wrong Answer

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

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

mod = 10 ** 9 + 7

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

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

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

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

print((ret - 1) % mod)

Submission status: Wrong Answer

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

MOD = 1000000007  # type: int

def func(b, w):
    return (pow(2, b, MOD) + pow(2, w, MOD) + MOD - 1) % MOD 

def solve(N: int, A: "List[int]", B: "List[int]"):
    from fractions import Fraction
    from collections import Counter
    C = [Fraction(a, b) for a, b in zip(A, B) if 0 not in (a, b)]
    D = [-Fraction(b, a) for a, b in zip(A, B) if 0 not in (a, b)]
    E = Counter(C)
    F = Counter(D)
    G = []
    used = set()
    for e, f in zip(E, F):
        if e in used or f in used:
            continue
        G.append((e, E[e], F[e]))
        used.add(e)
        used.add(f)
    ans = 1
    # print(G)
    for e, b, w in G:
        # print(b, w, func(b, w))
        ans = (ans * func(b, w)) % MOD
    H = sum(1 if 0 in (a, b) else 0 for a, b in zip(A, B))
    ans = (ans * func(H, 0)) % MOD
    return (ans-1+MOD)%MOD
        

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
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))
    print(solve(N, A, B))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


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


def main():
    N = int(input())
    A = []
    B = []
    kinds = defaultdict(int)

    for _ in range(N):
        a, b = map(int, input().split())

        if b == 0:
            kinds[INF] += 1
        else:
            kinds[a / b] += 1

    # i番目のグループを使うときとそうでない時の総数
    data = list(kinds.items())
    n_groups = len(data)
    ans = 1
    used = set()
    cnt = 0
    for i in range(n_groups):
        k, v = data[i - 1]
        if k == INF:
            rev = 0
        elif k == 0:
            rev = INF
        else:
            rev = -1 / k

        if k in used or rev in used:
            continue

        ng = kinds[rev]

        if ng == 0:
            used.add(rev)
            used.add(k)
            cnt += 1
            continue

        ans *= modpow(2, v, MOD) - 1 + modpow(2, ng, MOD) - 1 + 1
        ans %= MOD
        used.add(rev)
        used.add(k)

    ans *= modpow(2, cnt, MOD)
    ans %= MOD
    ans -= 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math
N=int(input())
A=[0]*N
B=[0]*N
x=0
y=0
plus={}
ans=1
for i in range(N):
  a,b=map(int,input().split())
  A[i]=a
  B[i]=b
  if(a==0 and b!=0):
    x+=1
  elif(a!=0 and b==0):
    y+=1
  elif(a!=0 and b!=0):
    c=math.gcd(a**2-b**2,a*b)
    d=(a**2-b**2)//c
    e=(a*b)//c
    if(e<0):
      d*=-1
      e*=-1
    if((d,e) in plus):
      plus[(d,e)]+=1
    else:
      plus[(d,e)]=1
#print(plus)
#print(x)
#print(y)
for z in plus.values():
  ans*=(z+1)%(10**9+7)
ans*=(2**x+2**y-1)%(10**9+7)
print((ans-1)%(10**9+7))

Submission status: Wrong Answer

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

MOD = 10 ** 9 + 7

dic = 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))
        dic[(0, 1)] += 1
    elif b == 0:
        S.add((1, 0))
        dic[(1, 0)] += 1
    else:
        GCD = gcd(a, b)
        a //= GCD
        b //= GCD
        if a < 0: #aを必ず正にする
            a *= -1
            b *= -1
        S.add((a, b))
        dic[(a, b)] += 1
        

lst = []
for a, b in S:
    tmp1 = dic[(a, b)]
    A = a
    B = b
    if B < 0:
        B *= -1
        A *= -1
    tmp2 = dic[(B, -A)]
    dic[(B, -A)] = 0
    if tmp1 > 0:
        lst.append((tmp1, tmp2))

# print (lst)

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

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import math
import sys
MOD = 1000000007  # type: int


def powm(a, n, m):
    if a == 1 or n == 0:
        return 1
    if n % 2 == 0:
        s = powm(a, n // 2, m)
        return s * s % m
    else:
        return a * powm(a, n - 1, m) % m

def solve(N: int, A: "List[int]", B: "List[int]"):
    # fishes = {}
    # zeroFishesB = 0
    # zeroFishesA = 0
    # valueFishes = N
    #
    # def getFishC(a):
    #     return fishes[a] if a in fishes else 0
    # for i in range(N):
    #     if A[i] == 0 and B[i] == 0: # 両方0,0ならばどの魚とも仲良くなれないので消す
    #         valueFishes -= 1
    #         continue
    #     if A[i] == 0:
    #         zeroFishesA += 1
    #     if B[i] == 0:
    #         zeroFishesB += 1
    #     fishes[(A[i],B[i])] = getFishC((A[i],B[i]))+1
    # def countWithZero(a): # aと中の悪い魚の数を返す
    #     if a[0] != 0 or a[1] != 0:
    #         return getFishC((-a[1],a[0]))+getFishC((a[1],-a[0]))
    #     else:
    #         if a[0] == 0:
    #             return zeroFishesB
    #         else:
    #             return zeroFishesA
    #
    # allCandidate = powm(2,valueFishes,MOD)-1
    # print(allCandidate)
    # for k in fishes:
    #     print(f"{k}->{countWithZero(k)}")
    fishes = []
    validFishes = N
    fishRads = dict()
    for i in range(N):
        if A[i] == 0 or B[i] == 0:
            validFishes-=1
            continue
        fishes.append((A[i],B[i]))
        cur = (0,0)
        gg = math.gcd(abs(A[i]), abs(B[i]))
        if (A[i] > 0 and B[i] >= 0) or (A[i] < 0 and B[i] <= 0):
            normalRad = (abs(A[i])//gg,abs(B[i])//gg)
            if normalRad in fishRads:
                cur = fishRads[normalRad]
            fishRads[normalRad] = (cur[0]+1,cur[1])
        else:
            rotRad = (abs(B[i]) // gg, abs(A[i]) // gg)
            if rotRad in fishRads:
                cur = fishRads[rotRad]
            fishRads[rotRad] = (cur[0], cur[1]+1)
    current = 1
    for k in fishRads:
        groups = fishRads[k]
        stage= (powm(2,groups[0],MOD) + powm(2,groups[1],MOD)-1)%MOD
        current = current*stage%MOD
    print(current-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:
from collections import defaultdict
from math import atan2, gcd

N = int(input())
MOD = 1000000007

d = defaultdict(lambda: [0, 0])

zero = 0
pos = []
neg = []
for _ in range(N):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        zero += 1
        continue
    if a < 0:
        a = -a
        b = -b
    elif a == 0 and b > 0:
        b = -b
    if b >= 0:
        pos.append((a, b))
    else:
        neg.append((a, b))
# for a, b in pos:
#     d[atan2(a, b)][0] += 1
# for a, b in neg:
#     d[atan2(-b, a)][1] += 1

for a, b in pos:
    g = gcd(a, b)
    d[(a // g, b // g)][0] += 1
for a, b in neg:
    g = gcd(a, -b)
    d[(-b // g, a // g)][1] += 1

ans = zero + 1
for p, n in d.values():
    ans *= pow(2, p, MOD) + pow(2, n, MOD) - 1
    ans %= MOD

ans -= 1
ans %= MOD
print(ans)
pass