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

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

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[0]*N
B=[0]*N
for _ in range(N):
	A[_],B[_]=map(int,input().split())
S=0
for i in range(N):
	k=0
	l=0
	for j in range(i+1,N):
		if A[i]*A[j]+B[i]*B[j]==0:
			k=k+1
	S=S+2**(N-k-1-i)
S=S//2
ans=S%1000000007
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def rev(a,b):
    if b<0:
        return (-b,a)
    else:
        return (b,-a)

import math
n = inn()
ab = []
h = defaultdict(int)
badpairs = {}
ab0 = a0 = b0 = 0
for i in range(n):
    a,b = inm()
    if a==b==0:
        ab0 += 1
    elif a==0:
        a0 += 1
    elif b==0:
        b0 += 1
    else:
        g = math.gcd(a,b)
        a //= g
        b //= g
        if a<0:
            a = -a
            b = -b
        h[(a,b)] += 1
        ra,rb = rev(a,b)
        if (ra,rb) in h:
            badpairs[(a,b)] = badpairs[(ra,rb)] = 1
#ddprint(h)
#ddprint(f"a0 {a0} b0 {b0} ab0 {ab0}")
grps = []
g0 = 0
if a0>0 and b0>0:
    grps.append(pow(2,a0,R)+pow(2,b0,R)-1)
done = {}
for a,b in h:
    if (a,b) in badpairs:
        if (a,b) not in done:
            ra,rb = rev(a,b)
            grps.append(pow(2,h[(a,b)],R)+pow(2,h[(ra,rb)],R)-1)
            done[(a,b)] = done[(ra,rb)] = 1
    else:
        g0 = (g0 + h[(a,b)]) % R
prod = pow(2,g0,R)
for x in grps:
    prod = (prod * x)%R
print((ab0+prod-1)%R)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
# RE
import math
n = int(input())
a = [0] * n;  b = [0] * n;
for i in range(n):
    a[i], b[i] = [int(x) for x in input().split()]
p = 10 ** 9 + 7

# d = [0] * n
dict = {}
for i in range(n):
    d = math.gcd(a[i], b[i])
    if d > 0:
        aa = a[i] // d
        bb = b[i] // d
    else:
        aa = a[i]
        bb = b[i]
    if aa < 0: # 非負数にする
        aa = -aa
        bb = -bb
    if (aa, bb) in dict:
        dict[(aa, bb)] += 1
    else:
        dict[(aa, bb)] = 1

bad = []
others = []
zeros = 0
# while dict:
#     aa, bb = list(dict.keys())[0]
#     if bb >= 0 and (bb, -aa) in dict:
#         bad.append((dict[(aa, bb)], dict[(bb, -aa)]))
#         del dict[(bb, -aa)]
#     elif (-bb, aa) in dict:
#         bad.append((dict[(aa, bb)], dict[(-bb, aa)]))
#         del dict[(-bb, aa)]
#     else:
#         others.append(dict[(aa, bb)])
#     del dict[(aa, bb)]

for (aa, bb) in dict:
    if dict[(aa, bb)] == 0: continue
    if aa == 0 and bb == 0:
        zeros += dict[(aa, bb)]
        dict[(aa, bb)] = 0
    elif (bb, -aa) in dict:
        bad.append((dict[(aa, bb)], dict[(bb, -aa)]))
        dict[(bb, -aa)] = 0
    elif (-bb, aa) in dict:
        bad.append((dict[(aa, bb)], dict[(-bb, aa)]))
        dict[(-bb, aa)] = 0
    else:
        others.append(dict[(aa, bb)])
    dict[(aa, bb)] = 0

ans = 1
for (x, y) in bad:
    ans = ans * (pow(2, x, p) + pow(2, y, p) - 1) % p
for z in others:
    ans = ans * pow(2, z, p) % p
ans -= 1
if zeros > 0:
    ans = (ans + zeros) % p
print(ans)

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())
    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 -= 1
    ans %= MOD
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

read = sys.stdin.read
MOD = 10**9 + 7

n = int(input())
ab = np.array(read().split(), dtype=np.float64).reshape([-1,2])
ans = 0
for i in range(n-1):
    ans += pow(2,np.count_nonzero((np.sum(ab*ab[i], 1) != 0)[i+1:]), MOD)
    ans %= MOD
ans += 1
ans %= MOD
print(ans)

Submission status: Wrong Answer

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

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

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

    L2=[0,0,0,0]

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

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

main()

Submission status: Wrong Answer

Solution code:
import math
MOD =1000000007


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
        # print(K,x)
        x%=MOD
    return K * x


n = int(input())

a_b_d = {}
# b_a_d = {}

a_zero_cnt = 0
b_zero_cnt = 0
ab_zero_cnt = 0

for i in range(n):
    a, b = map(int, input().split()) 
    if a==0 and b!=0:
        a_zero_cnt += 1
    elif  a!=0 and b==0:
        b_zero_cnt += 1
    elif a == 0 and b == 0:
        ab_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 = set()
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.add(comp_pair1)
        pair_cnt.append((v,a_b_d[comp_pair1]))
    elif comp_pair2 in a_b_d:
        # print(k, comp_pair)
        done_list.add(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

zero_m = max(pow_k(2,a_zero_cnt) + pow_k(2,b_zero_cnt) -1, 1)
print(ans)
ans *= zero_m
# ans *= (zero_cnt+1)
ans -= 1
print(ans%MOD)

Submission status: Wrong Answer

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

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

mod = 10**9 + 7

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

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

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

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

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


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

ans = 1
count = 0

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

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

ans *= beki[count]
temp = ans-1
temp2 = ans*zero
ans = temp+temp2
ans %= mod
print(ans)

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)
        if a > 0:
            a = -a
            b = -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:
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
zcount = 0
for i,item in enumerate(l):
    if seen[i]:
        continue
    elif item==(0,0):
        zcount += 1
        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)

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 = ans*(c[0] + 1)
for i in ans_list:
  ans *= i
ans -= 1  
print(ans)

Submission status: Wrong Answer

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

mod = 10**9+7

N = int(input())
AB = []
Empty = 0
for _ in range(N):
    x, y = map(int, input().split())
    if x == 0 and y == 0:
        Empty += 1
    elif y < 0 or (y==0 and x < 0):
        AB.append((math.atan2(-y, -x), -x, -y))
    else:
        AB.append((math.atan2(y, x), x, y))

M = N-Empty
AB.sort()
ind1 = 0
ind2 = 0
ans = 1
while ind1 < M and AB[ind1][1] > 0:
    ind1 += 1
Checked = [False]*M
for i, (t, x, y) in enumerate(AB):
    if x <= 0: break
    if Checked[i]: continue
    just = False
    while ind1 < M:
        update = False
        t1, x1, y1 = AB[ind1]
        ind2 = ind1+1
        while ind2 < M and AB[ind2][1]*y1 == AB[ind2][2]*x1:
            ind2 += 1
        
        if x1*x + y1*y > 0:
            ans = (ans * pow(2, ind2-ind1, mod)) % mod
            ind1 = ind2
        else:
            just = (x1*x + y1*y == 0)
            break
        
    tmp = i
    while tmp < M and not Checked[tmp] and AB[tmp][1]*y == AB[tmp][2]*x:
        Checked[tmp] = True
        tmp += 1
    if just:
        ans = (ans * (pow(2, ind2-ind1, mod) + pow(2, tmp-i, mod) - 1)) % mod
        ind1 += 1
    else:
        ans = (ans * (pow(2, tmp-i, mod))) % mod

print((ans-1)%mod)

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)-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:
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

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:
# RE
import math
n = int(input())
a = [0] * n;  b = [0] * n;
for i in range(n):
    a[i], b[i] = [int(x) for x in input().split()]
p = 10 ** 9 + 7

# d = [0] * n
dict = {}
for i in range(n):
    d = math.gcd(a[i], b[i])
    if d > 0:
        aa = a[i] // d
        bb = b[i] // d
    else:
        aa = a[i]
        bb = b[i]
    if aa < 0: # 非負数にする
        aa = -aa
        bb = -bb
    if (aa, bb) in dict:
        dict[(aa, bb)] += 1
    else:
        dict[(aa, bb)] = 1

bad = []
others = []
zeros = 0
# while dict:
#     aa, bb = list(dict.keys())[0]
#     if bb >= 0 and (bb, -aa) in dict:
#         bad.append((dict[(aa, bb)], dict[(bb, -aa)]))
#         del dict[(bb, -aa)]
#     elif (-bb, aa) in dict:
#         bad.append((dict[(aa, bb)], dict[(-bb, aa)]))
#         del dict[(-bb, aa)]
#     else:
#         others.append(dict[(aa, bb)])
#     del dict[(aa, bb)]

for (aa, bb) in dict:
    if dict[(aa, bb)] == 0: continue
    if aa == 0 and bb == 0:
        zeros += dict[(aa, bb)]
        dict[(aa, bb)] = 0
    elif (bb, -aa) in dict:
        bad.append((dict[(aa, bb)], dict[(bb, -aa)]))
        dict[(bb, -aa)] = 0
    elif (-bb, aa) in dict:
        bad.append((dict[(aa, bb)], dict[(-bb, aa)]))
        dict[(-bb, aa)] = 0
    else:
        others.append(dict[(aa, bb)])
    dict[(aa, bb)] = 0

ans = 1
for (x, y) in bad:
    ans = ans * (pow(2, x, p) + pow(2, y, p) - 1) % p
for z in others:
    ans = ans * pow(2, z, p) % p
ans -= 1
if zeros > 0:
    ans = (ans + pow(2, zeros, p) - 1) % p
print(ans)

Submission status: Wrong Answer

Solution code:

from collections import Counter
mod = 1000000007

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

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

Submission status: Wrong Answer

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

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

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

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

print(max(1,ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]

mod = 1000000007

from fractions import gcd

ratios = []
for a, b in ab:
    if a != 0 and b != 0:
        g = gcd(a, b)
        if g < 0:
            g *= -1
        ratios.append((a // g, b // g))
    elif a == 0 and b == 0:
        ratios.append((0, 0))
    elif a == 0:
        ratios.append((0, 1))
    else:
        ratios.append((1, 0))

twos = [1]
for i in range(2 * 10 ** 5):
    tmp = twos[-1] * 2
    tmp %= mod
    twos.append(tmp)


from collections import Counter, defaultdict
c = Counter(ratios)
seen = Counter()

targets = []
for key in c:
    x, y = key
    xx = c[key]
    yy = seen[(-y, x)] + seen[(y, -x)]
    if xx != 0 and yy != 0:
        targets.append((xx, yy))
    seen[key] = c[key]

n_frees = 0
for i, (x, y) in enumerate(ratios):
    n_bads = c[(-y, x)] + c[(y, -x)]
    if n_bads == 0:
        n_frees += 1

ans = twos[n_frees]

for x, y in targets:
    ans *= (twos[x] + twos[y] - 1) % mod

print((ans - 1) % mod)

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

cnt = 0
if taste_0 != 0 and flavor_0 != 0:
  ans = pow(2, taste_0, PRIME)
  ans += pow(2, flavor_0, PRIME) - 1
  ans %= PRIME
else:
  cnt += taste_0
  cnt += flavor_0
  ans = 1

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:
N = int(input())
sin_dic = {}
import math
mod = 1000000007
INF = 10 ** 15

for i in range(N):
    a, b = list(map(int, input().split()))
    if a == 0 and b == 0:
        continue
    #sin = b/ math.sqrt(a**2 + b**2)
    if a == 0:
        asin = INF
    else:
        asin = b/a
    if asin in sin_dic:
        sin_dic[asin].append(i)
    else:
        sin_dic[asin] = [i]

ans = 1
half_pi = math.pi / 2
skip_dic = {}
#sin_tup = sorted(sin_dic.items(), key=lambda x:x[0])
for key, values in sin_dic.items():
    if key in skip_dic:
        continue
    elif key == 0:
        if INF in sin_dic:
            p = pow(2, len(sin_dic[key]), mod) - 1 + pow(2, len(sin_dic[INF]), mod)
            ans = (ans * p) % mod
            skip_dic[INF] = True
        else:
            ans = (ans * pow(2, len(sin_dic[key]), mod)) % mod 
    elif key == INF:
        if 0 in sin_dic:
            p = pow(2, len(sin_dic[key]), mod) - 1 + pow(2, len(sin_dic[0]), mod)
            ans = (ans * p) % mod
            skip_dic[0] = True
        else:
            ans = (ans * pow(2, len(sin_dic[key]), mod)) % mod 

    elif (- 1/ key) in sin_dic:
        p = pow(2, len(sin_dic[key]), mod) - 1 + pow(2, len(sin_dic[-1/key]), mod)
        ans = (ans * p) % mod
        skip_dic[-1/key] = True
    else:
        ans = (ans * pow(2, len(sin_dic[key]), mod)) % mod 

print( (ans-1) % mod)

Submission status: Wrong Answer

Solution code:
N = int(input())
iwashi = []
for i in range(N):
    iwashi.append(list(map(int, input().split())))

lst = [[0]*N]*N
for i in range(N):
    for j in range(i,N):
        if iwashi[i][0]*iwashi[j][0]+iwashi[i][1]*iwashi[j][1] == 0:
            pass
        else:
            lst[i][j] += 1

print(sum(sum(lst,[]))//1000000007)

Submission status: Wrong Answer

Solution code:
import math
import sys
input = sys.stdin.readline
n = int(input())
x = [[0,0] for _ in range(n)]
h = 3600
c = 0
y = [[] for _ in range(h)]
mod = 10**9+7
for i in range(n):
  ai,bi = map(int,input().split())
  if ai == 0 and bi == 0:
    c += 1
  else:
    j = int((math.degrees(math.atan2(ai, bi))+180)*10)%3600
    flag = True
    for ca in y[j]:
      if ai*ca[0][1] == bi*ca[0][0]:
        x[ca[1]][0] += 1
        flag = False
        break
    for ca in y[(j+1800)%h]:
      if ai*ca[0][1] == bi*ca[0][0]:
        x[ca[1]][0] += 1
        flag = False
        break
    for ca in y[(j+900)%h]:
      if ai*ca[0][0]+bi*ca[0][1] == 0:
        x[ca[1]][1] += 1
        flag = False
        break
    for ca in y[(j-900)%h]:
      if ai*ca[0][0]+bi*ca[0][1] == 0:
        x[ca[1]][1] += 1
        flag = False
        break
    if flag:
      y[j].append([(ai,bi),i])
      x[i][0] = 1
ans = 1
for xi in x:
  if xi[0] == 0:
    if xi[1] != 0:
      ans = (ans*2**(xi[1]))%mod
  else:
    if xi[1] == 0:
      ans = (ans*2**(xi[0]))%mod
    else:
      ans = (ans*(2**(xi[0])+2**(xi[1])-1))%mod
ans = (ans+c-1)%mod
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N = ri()
info = []
for i in range(N):
	a, b = rl()
	info.append((a, b))

import collections

h = collections.defaultdict(int)
zeros = 0
for a, b in info:
	if a == 0 and b == 0:
		zeros += 1
	elif a == 0:
		h[0] += 1
	elif b == 0:
		h[float('inf')] += 1
	else:
		h[a/b] += 1
ans = 1
visited = {}
for r, c in h.items():
	if r in visited:
		continue
	rr = None
	if r == 0:
		rr = float('inf')
	elif r == float('inf'):
		rr = 0
	else:
		rr = -1/r
	if rr in h:
		cnt = pow(2, c, mod)-1 + pow(2, h[rr], mod)-1 + 1
		ans = (ans * cnt) % mod
		visited[rr] = 1
	else:
		cnt = pow(2, c, mod)
		ans = (ans * cnt) % mod
ans = (ans-1+zeros) % mod
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
import fractions
def f(x,y):
    if x!=0:
        return fractions.Fraction(y,x)
    else:
        return 'inf'
def g(x):
    if x!=0 and x!='inf':
        return (-1)*fractions.Fraction(1,x)
    elif x==0:
        return 'inf'
    else:
        return 0
A=[1]*n #傾きの個数
B=[1]*n #傾きの対立の個数
C=[0]*n #傾きの値
D=[0]*n #傾きの対立の値
for i in range(n):
    a,b=map(int,input().split())
    t=f(a,b)
    if t in C:
        k=C.index(t)
        A[k]=A[k]*2%1000000007
    elif t in D:
        k=D.index(t)
        B[k]=B[k]*2%1000000007
    else:
        k=A.index(1)
        C[k]=t
        D[k]=g(t)
        A[k]=A[k]*2%1000000007
s=0
j=1
for i in range(n):
    s=(s+j*(A[i]+B[i]-2))%1000000007
    j=j*(A[i]+B[i]-1)%1000000007
print(s)

Submission status: Wrong Answer

Solution code:
def nasu(a, b):
  c = a / b
  return c  

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

MOD = 10 ** 9 + 7
R = {}

cnt = 0
ze = 0
for a, b in AB:
  if a == 0 and b == 0: 
    ze += 1
    continue
  if b == 0:
    s = "na"
  elif a == 0:
    s = "su"
  else:
    s = nasu(a, b)
  if s in R:
    R[s] += 1
  else:
    R[s] = 1
  cnt += 1

L = []
for i in R.keys():
  if i == "na":
    s = "su"
  elif i == "su":
    s = "na"
  else:
    s = - 1 / i
  t = R[i]
  if s not in R:
    L.append(pow(2, t, MOD))
    continue
  k = R[s]
  L.append((pow(2, t) + pow(2, k) - 1) % MOD)
  R[i] = 0
  R[s] = 0

ans = 1
for i in L:
  ans = ans * i % MOD

ans = (ans + ze) % MOD

ans -= 1
if ans < 0:
  ans += MOD
print(ans)