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 math

mod = 1000000007

N = int(input())
As = []
Ts = [] # <= 0
Ws = [] # > 0
e = 10 ** (-4)

for _ in range(N):
    a, b = map(int, input().split())
    s = (a**2 + b**2) ** (1/2)
    if a != 0:
        w = math.atan(b/a)
        if w > 0:
            Ws.append(w)
        else:
            Ts.append(w + math.pi / 2)
        As.append(w)
    else:
        w = math.pi / 2
        Ws.append(w)
        As.append(w)

Ts.sort()
Ws.sort()
As.sort()
l = 0
c = 0
Cs = []

Lt = len(Ts)
Lw = len(Ws)
it = 0
iw = 0
ct = 0
cw = 0
while l <= math.pi / 2:
    while it < Lt and l - e < Ts[it] and Ts[it] < l + e:
        ct += 1
        it += 1
    while iw < Lw and l - e < Ws[iw] and Ws[iw] < l + e:
        cw += 1
        iw += 1
    Cs.append((2**ct+2**cw-1)%mod)
    ct = 0
    cw = 0
    l += e
Cs.append((2**ct+2**cw-1)%mod)

counter = 1
for c in Cs:
    counter = (counter*c) % mod

print((counter - 1) % mod)

Submission status: Wrong Answer

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

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

if len(kan) == 0 and betu[0] == 0 and betu[1] == 0:
    print(ans)
else:
    print(ans-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 = ans*(c[0] + 1)
for i in ans_list:
  ans *= i
ans -= 1 
ans %= 1000000007
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(100000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from math import gcd

def main():
    N = int(input())
    minus_iwashi = {}
    iwashi = {}
    a0 = 0
    b0 = 0
    a0b0 = 0
    
    for _ in range(N):
        a,b = map(int,input().split())
        if a < 0 and b > 0:
            a = -a
            b = -b
        elif a < 0 and b < 0:
            a = -a
            b = -b
        if a == 0 and b == 0:
            a0b0 += 1
            continue
        if a == 0 and b != 0:
            a0 += 1
            continue
        if b == 0 and a != 0:
            b0 += 1
            continue
        #print(a,b)
        if b < 0:
            a,b = -b,a
            #print('mini{}{}'.format(a,b))
            x = gcd(a,b)
            a //= x
            b //= x
            if (a,b) in minus_iwashi:
                minus_iwashi[(a,b)] += 1
            else:
                minus_iwashi[(a,b)] = 1
        elif b > 0:
            x = gcd(a,b)
            a //= x
            b //= x
            if (a,b) in iwashi:
                iwashi[(a,b)] += 1
            else:
                iwashi[(a,b)] = 1
    
    power = [1]
    for _ in range(N):
        power.append(power[-1]*2%MOD)
    '''
    print(power)
    print(iwashi)
    print(minus_iwashi)
    print(a0,b0)
    '''
    
    if a0 > 0 and b0 > 0:
        ans = (power[a0] + power[b0] - 1)%MOD
    elif a0 > 0:
        ans = power[a0]
    elif b0 > 0:
        ans = power[b0]
    else:
        ans = 1

    for k,v in iwashi.items():
        if k in minus_iwashi:
            ans *= (power[v] + power[minus_iwashi[k]] - 1)%MOD
            ans %= MOD
        else:
            ans *= power[v]
            ans %= MOD
    
    for k,v in minus_iwashi.items():
        if k in iwashi:
            continue
        else:
            ans *= power[v]
            ans %= MOD
    ans += power[a0b0]
    print((ans - 1)%MOD)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import bisect
N=int(input())
L = [list(map(int,input().split())) for _ in range(N)]

MOD=10**9+7

L_non_zero=[[a,b] for a,b in L if a*b!=0]
L_zero=[[a,b] for a,b in L if a*b==0]

L_zero=0
D_AB=defaultdict(int)
D_BA=defaultdict(int)

for a,b in L:
    if a*b==0:
        L_zero+=1
    else:
        D_AB[a/b]+=1
        D_BA[b/a]+=1


ans=1
used_key=set()
for key,val in D_AB.items():
    if key in used_key:
        continue
    else:
        used_key.add(-1/key)
    val_other=D_BA[-key]

    if val_other==0:
        ans*=pow(2,val,MOD)
    else:
        ans*=((pow(2,val,MOD)-1)+(pow(2,val_other,MOD)-1)+1)
if L_zero>0:
    ans*=(L_zero)
print((ans-1+MOD)%MOD)

Submission status: Wrong Answer

Solution code:
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
from collections import deque

inf = 10 ** 15
mod = 10 ** 9 + 7

def power(a,n,mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


n = int(input())
zero = 0
aperb = []
bpera = []
for i in range(n):
    a,b = map(int, input().split())
    if a == 0 or b == 0:
        zero+=1
    else:
        aperb.append(a/b)
        bpera.append(-b/a)
badrelation = [] # 要素には仲悪いイワシのペア数
badnum = 0

aperb.sort()
bpera.sort()
length = len(aperb)
ind = 0
while ind < length:
    tmp = aperb[ind]
    if tmp > 0:
        break
    k = bisect.bisect_left(bpera, tmp)
    countb = 0
    while k < length and bpera[k] == tmp:
        countb+=1
        k+=1
    counta = 0
    while ind < length and aperb[ind] == tmp:
        counta+=1
        ind+=1
    if counta*countb != 0:
        badrelation.append([counta,countb])
        badnum += (counta+countb)

    if k == length or ind == length:
        break

nakayoshi = n-zero-badnum

ans = power(2,nakayoshi,mod)

ans = (ans*(zero+1))%mod
for ag,bg in badrelation:
    tmp = power(2,ag,mod)+power(2,bg,mod)-1
    ans = (ans*tmp)%mod

print(ans-1)

Submission status: Wrong Answer

Solution code:
from collections import deque

    
    
n = int(input())
a_list = []
b_list = deque()
mod = 10 ** 9 + 7
p = [1] * (n + 1)
for i in range(n):
    p[i + 1] = p[i] * 2 % mod

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 += p[count - num - 1]
    out = out % mod
    count -= 1
    b_list.pop()
print(out)

Submission status: Wrong Answer

Solution code:
n=int(input())
ablist=[]
slist=[]
zeros=[0,0,0]

for i in range(n):
    a, b = map(int,input().split())
    if a==0:
        if b==0:
            zeros[2]+=1
        else:
            zeros[1]+=1
    else:
        if b==0:
            zeros[0]+=1
        else:
            if a*b>0:
                slist.append([a/b, 1])
            else:
                slist.append([b/(-a), -1])
                #slist.append([abs(a/b), int(abs(a*b)/(a*b))])

slist=sorted(slist)
#print(slist)

zerok=2**(zeros[0]) + 2**(zeros[1]) - 1
#print(zerok)

mae=[0, 0]
onaji=[1, 0]

answer=1
#print(slist)

rev=0
swit=0
#print(slist)

for sl in slist:
    swit=0
    if sl[0]==mae[0]:
        if sl[1]==mae[1]:
            if rev==0:
                onaji[0]+=1
            else:
                onaji[1]+=1
        else:
            onaji[1]+=1
            rev=1
        
    else:
        if mae!=[0, 0]:
            answer*=(2**onaji[0]+2**onaji[1]-1)
            answer%=1000000007
            onaji=[1, 0]
            rev=0
            swit=1
    mae=sl
    #print(answer)

if len(slist)>0:
    answer*=(2**onaji[0]+2**onaji[1]-1)
    answer%=1000000007

#print(answer)

answer*=zerok
answer+=zeros[2]

print((answer-1)%1000000007)

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 %= con

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

	if ans == 0:
		print(10 ** 9  + 6)
	else:
		print(ans - 1)

if __name__ == '__main__':
	main()

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 = []
nzero = 0
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:
        nzero += 1
    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 + nzero) % mod)

Submission status: Wrong Answer

Solution code:
cnt = 0
aInt = []
bInt = []
xInt = int(input())
for i in range(xInt):    
    a, b = list(map(int, input().split()))
    aInt.append(a)
    bInt.append(b)

for i in range(xInt):
    for j in range(xInt):
        if(i==j):
            cnt = cnt +1
        elif (i>=j):
            if(((aInt[i]*aInt[j] + bInt[i]*bInt[j]) == 0) == False):
                cnt = cnt +1
       
print(str(cnt%1000000007))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import bisect
N=int(input())
L = [list(map(int,input().split())) for _ in range(N)]

MOD=10**9+7

L_non_zero=[[a,b] for a,b in L if a*b!=0]
L_zero=[[a,b] for a,b in L if a*b==0]

L_zero=0
D_AB=defaultdict(int)
D_BA=defaultdict(int)

for a,b in L:
    if a*b==0:
        L_zero+=1
    else:
        D_AB[a/b]+=1
        D_BA[b/a]+=1


ans=1
used_key=set()
for key,val in D_AB.items():
    if key in used_key:
        continue
    else:
        used_key.add(key)
        used_key.add(-1/key)
    val_other=D_BA[-key]

    if val_other==0:
        ans*=pow(2,val,MOD)
    else:
        ans*=((pow(2,val,MOD)-1)+(pow(2,val_other,MOD)-1)+1)
if L_zero>0:
    ans*=(L_zero)
print((ans-1+MOD)%MOD)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
d = {}
r = 0
for i in range(n):
    if a[i][0] == 0 and a[i][1]:
        r += 1
    elif a[i][0] == 0:
        if 0 in d:
            d[0][0] = d[0][0] +1
        else:
            d[0] = [1, 0]
    elif a[i][1] == 1:
        if 0 in d:
            d[0][1] = d[0][1] +1
        else:
            d[0] = [0, 1]
    else:
        if a[i][0] * a[i][1] > 0:
            s = a[i][0] / a[i][1]
            if s in d:
                d[s][0] = d[s][0] +1
            else:
                d[s] = [1, 0]
        else:
            s = -a[i][1] / a[i][0]
            if s in d:
                d[s][1] = d[s][1] +1
            else:
                d[s] = [0, 1]
ans = 1
m = 0
for i in d:
    m += 1
    ans *= 2**d[i][0] + 2**d[i][1] - 1
    if m != 1:
        ans -= 1
    print(ans)
ans += r
ans = ans%1000000007
#print(d)
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import Fraction as fra
P=10**9+7

n=int(input())
G=[]
for index1 in range(n):
    a,b=map(int,input().split())
    if a<0 and b>0:
        G.append((-a,-b))
    elif a<0 and b<0:
        G.append((-a,-b))
    else:
        G.append((a,b))

D={}
S=set()
for i in range(n):
    x=G[i][0]
    y=G[i][1]
    if x==0:
        if y==0:
            if 'XY' in S:
                D['XY'][2]+=1
                continue
            else:
                D['XY']=[0,0,1]
                S.add('XY')
                continue
        else:
            if 'XY' in S:
                D['XY'][0]+=1
                continue
            else:
                D['XY']=[1,0,0]
                S.add('XY')
                continue
    else:
        if y==0:
            if 'XY' in S:
                D['XY'][1]+=1
                continue
            else:
                D['XY']=[0,1,0]
                S.add('XY')
                continue

    temp=fra(x,y)
    if y>0:
        temp_over=fra(y,-x)
    else:
        temp_over=fra(-y,x)
    if temp in S:
        D[temp][0]+=1
    elif temp_over in S:
        D[temp_over][1]+=1
    else:
        D[temp]=[1,0]
        S.add(temp)



def culc(List):
    return (pow(2,List[0],P)+pow(2,List[1],P)-1)%P



ans=1
flag=0
if 'XY' in S:
    X=D['XY'][0]
    Y=D['XY'][1]
    XY=D['XY'][2]
    flag=1

    


while S:
    now=S.pop()
    obj=D[now]
    ans=(ans*culc(obj))%P

if flag==1:
    ans=(ans*culc([X,Y]))%P
    ans=(ans+XY)%P

print((ans-1)%P)

Submission status: Wrong Answer

Solution code:
from fractions import Fraction
 
 
 
a = int(input())
resab = dict()
resba = dict()
res0 = 0
res0a = 0
res0b = 0
 
for i in range(a):
    ai, bi = [int(i) for i in input().split()]
    if ai != 0 and bi != 0:
        s = Fraction(ai, bi)
        if Fraction(ai, bi) not in resab:
            resab[s] = 1
        else:
            resab[s] += 1
        b = Fraction(-s.denominator, s.numerator)
        if b not in resba:
            resba[b] = 1
        else:
            resba[b] += 1
    else:
        if ai == 0 and bi == 0:
            res0 += 1
        elif ai == 0:
            res0a += 1
        elif bi == 0:
            res0b += 1
 

ans = 1
for i in list(resab.keys()):
    k = Fraction(-i.denominator, i.numerator)
    if i in resba and i in resab:
        ans *= (2**resab[i] - 1 + 2**resba[i]) 
        #print(ans, i)
        del resab[i]
        del resab[k]
        del resba[i]
        del resba[k]
    elif i in resba:
        ans *= resba[i] + 1
        #print(ans, i)
        del resba[i]
        try:
            del resab[k]
        except:
            pass
    elif i in resab:
        ans *= resab[i] + 1
        #print(ans, i)
        del resab[i]
        try:
            del resba[k]
        except:
            pass
        
    ans %= 1000000007
 
ans *= (2 ** res0a)
ans *= (2 ** res0b)
ans *= (res0 + 1)
ans -= 1
ans %= 1000000007
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:
        if a < 0:
            a = -a
            b = -b
        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))
            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
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

N = I()
cnt = {}
pair = {}
bothzero = 0
for i in range(N):
    A,B = MI()
    if A==0 and B==0:
        bothzero += 1
    elif B==0:
        pair[0]=pair.get(0,0)+1
    elif A == 0:
        cnt[0]=cnt.get(0,0)+1
    elif A/B>0:
        cnt[A/B]=cnt.get(A/B,0)+1
    else:
        pair[-B/A]=pair.get(-B/A,0)+1
res = N-bothzero
ans = 1
for v in cnt:
    if pair.get(v,0)==0:
        continue
    res -= (cnt[v]+pair[v])
    ans *= (pow(2,cnt[v],MOD)+pow(2,pair[v],MOD)-1)
    ans = ans%MOD
ans = (ans*pow(2,res,MOD)-1)%MOD
ans = (ans+bothzero)%MOD
print(ans)

Submission status: Wrong Answer

Solution code:
import math
def comb_cnt(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n=int(input())
li=[]
l=len(li)
for i in range(n):
    a,b=map(int,input().split())
    if l>0:
        for j in range(l):
            if li[j][0]*a+li[j][1]*b==0:
                break
            if j==l-1:
                li.append([a,b])
    else:
        li.append([a,b])
ans=0
for i in range(1,l+1):
    ans+=comb_cnt(l,i)
print(ans%1000000007)

Submission status: Wrong Answer

Solution code:
import math
MOD = 1000000007
N = int(input())
d_p = dict()
d_m = dict()
for n in range(N):
    a,b = map(int,input().split())

    if a==0 and b==0:
        d_m['00'] = d_m.get('00',0) + 1
        continue
    if a==0:
        n_sign = 0
    elif b==0:
        n_sign = 1
    
    else:    
        n_sign = ((a<0) + (b<0))%2
        a = abs(a)
        b = abs(b)
        # gcd = math.gcd(a,b)
        # a//=gcd
        # b//=gcd
        

        #print(n_sign,a,b)
    # print(n_sign,a,b)


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


ans = 1
for k,v in d_m.items():
    if k in d_p:
        ans *= (2**v + 2**d_p[k] - 1)
        
        d_p.pop(k)
    else:
        ans *= 2**v
    ans %= MOD

for k,v in d_p.items():
    ans *= 2**v
    ans %= MOD
ans -= 1
ans %= MOD
print (ans)

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:
def ncr(n, r):
    r = min(r, n - r)
    if r == 0: return 1;
    if r == 1: return n;
    numerator = [n - r + i + 1 for i in range(r)]
    denominator  = [i + 1 for i in range(r)]
    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1: 
            result *= numerator[k]
    return result

N = int(input())
A = []
B = []
ans = 0
count = 0
INF = 10 ** 9 + 7
for i in range(N):
    in1, in2 = map(int, input().split())
    A.append(in1)
    B.append(in2)
for i in range(N):
    for j in range(i + 1, N):
        if A[i] * A[j] + B[i] * B[j] == 0:
            count += 1
            
for i in range(1, N - 1):
    ans = (ans + ncr(N, i) - count * ncr(N - 2, i)) % INF
ans -= count
ans = (ans + N + 1) % INF
print(int(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**20+9

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:
import math
import collections

n = int(input())
mod = 10 * 6 + 7
c = []
d = []

tan = []
atan = []

for _ in range(n):
    a, b = map(int, input().split())
    if b == 0: tan.append(float('inf'))
    else: tan.append(a / b)
    if a == 0: atan.append(float('inf'))
    else: atan.append(- b / a)

tan = collections.Counter(tan)
atan = collections.Counter(atan)

for key, value in tan.items():
    if abs(key) > 1: continue
    if atan[key] > 0:
        c.append(value)
        d.append(value)

ans = pow(2, n - sum(c) - sum(d), mod)
for i, j in zip(c, d):
    ans = (ans * (pow(2, i, mod) + pow(2, j, mod) - 1)) % mod
ans -= 1

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):
    x=(A[i]+B[i])%1000000007
    s=(s+j*(x-2))%1000000007
    j=j*(x-1)%1000000007
print(s)

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-1):
    for j in range(i+1,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,[])) + N //1000000007)

Submission status: Wrong Answer

Solution code:
mod = 1000000007
import collections
n = int(input())
dat1 = []
dat2 = []
for i in range(n):
    a,b = map(int, input().split())
    dat1.append(a)
    dat2.append(b)
ngfish = []
for i in range(n):
    #print(i)
    res = 0
    for j in range(i+1, n):
        #print("try j", j)
        if dat1[i] * dat1[j] + dat2[i] * dat2[j] == 0:
            #print("ng", j)
            res += 1
    ngfish.append(res)

print(ngfish)

res = 0
for i in range(len(ngfish)):
    res += pow(2, n - i - 1 - ngfish[i], mod)
    res %= mod

print(res)

Submission status: Wrong Answer

Solution code:
import decimal
decimal.getcontext().prec = 40

PRIME = 1000000007
n = int(input())

fish = {}
taste_0 = 0
flavor_0 = 0

for i in range(n):
  a, b = map(int, input().split())
  a = decimal.Decimal(a)
  b = decimal.Decimal(b)
  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:
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):
    if(a/b-b/a in plus):
      plus[a/b-b/a]+=1
    else:
      plus[a/b-b/a]=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:
import math
from collections import Counter

mod = 10**9+7
n = int(input())
c = Counter()
cc = Counter()

iwashi = []
for _ in range(n):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        c[-1] += 1
        continue
    elif a != 0 and b == 0:
        rad = 90
    elif a == 0 and b != 0:
        rad = 0
    else:
        d, e = (a/b).as_integer_ratio()
        rad = round(math.degrees(math.atan2(d/e, 1)), 20)
    if rad < 0:
        rad += 180
    iwashi.append([a, b, rad])
    c[rad] += 1
    cc[rad] += 1


l = []

for r in cc.keys():
    if r == -1:
        continue
    if 0 <= r < 90:
        ra = c[r]
        rb = c[r+90]
        if ra >= 0 and rb >= 0:
            l.append([ra, rb])
            c[r] -= 10**9
            c[r+90] -= 10**9
    else:
        ra = c[r-90]
        rb = c[r]
        if ra >= 0 and rb >= 0:
            l.append([ra, rb])
            c[r-90] -= 10**9
            c[r] -= 10**9

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

ans = (ans-1) + c[-1]
ans %= mod

print(ans)