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 collections

N=int(input())
posi=[]
nega=[]
m=N
mod=1000000007
power=[1]*(N+1)
zero=0

for i in range(1,N+1):
    power[i]=power[i-1]*2%mod
    
for i in range(N):
    a,b=map(int,input().split())
    if a==0 and b==0:
        zero+=1
    elif b==0:
        nega.append(0)
    elif a/b>=0:
        posi.append(a/b)
    else:
        nega.append((-1)*b/a)

cp=collections.Counter(posi)
cn=collections.Counter(nega)

x=1
y=1

for pp in cp.keys():
    if pp in cn.keys():
        p=cp[pp]
        n=cn[pp]
        powp=power[p]
        pown=power[n]
        e=(powp-1)*(pown-1)%mod
        f=(powp+pown-1)%mod
        x=x*(e+f)%mod
        y=y*f%mod
        m-=(p+n)

ans=power[N-zero]-1-power[m]*(x-y)%mod
print((ans+zero)%mod)

Submission status: Wrong Answer

Solution code:
def main():
    import math
    import collections
    N = int(input())

    mod = 10**9+7
    AB = [tuple(map(int, input().split())) for i in range(N)]

    d = collections.defaultdict(set)
    i = 0
    for a, b in AB:
        if a != 0 and b != 0:
            g = math.gcd(a, b)
            a = a // g
            b = b // g

        d[(a, b)].add(i)
        i += 1

    ans = 0
    r = set()

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

    r = set()
    ans = 1
    for a, b in d:
        if (a, b) in r:
            continue
        l1 = len(d[(a, b)])
        s = set()
        if (-b, a) in d:
            s |= d[(-b, a)]
        if (b, -a) in d:
            s |= d[(b, -a)]
        s -= d[(a, b)]
        l2 = len(s)
        if l2:
            ans *= dd[l1] + dd[l2] - 1
            N -= l1 + l2
            ans %= mod
            r.add((-b, a))
            r.add((b, -a))
        else:
            continue
    if N:
        ans *= dd[N]
    ans -= 1
    print(ans % mod)


main()

Submission status: Wrong Answer

Solution code:
import math
from collections import Counter

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

for _ in range(n):
    a, b = map(int, input().split())
    if b < 0:
        a = -a
        b = -b
    if a == 0 and b == 0:
        c[-1] += 1
        continue

    a, b = a//math.gcd(a, b), b//math.gcd(a, b)

    c[(a, b)] += 1
    cc[(a, b)] += 1

l = []

for r in cc.keys():
    if r == -1:
        continue
    ra = c[r]

    a, b = r
    if a >= 0:
        r_inv = (-b, a)
    else:
        r_inv = (b, -a)
    rb = c[r_inv]

    if ra >= 0 and rb >= 0:
        l.append([ra, rb])
        c[r] -= 10**9
        c[r_inv] -= 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)

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
    if a == 0:
        b = -1
        #asin = INF
    elif b == 0:
        a = 1
    else:
        c = math.gcd(a, b)
        a, b = a//c, b//c
        if a < 0 and b < 0:
            a, b = -a, -b
        elif a < 0 and b > 0:
            a, b = -a, -b
    if (a,b) in sin_dic:
        sin_dic[(a, b)].append(i)
    else:
        sin_dic[(a, b)] = [i]

ans = 1
skip_dic = {}
#sin_tup = sorted(sin_dic.items(), key=lambda x:x[0])
for (key, _key) , value_dic in sin_dic.items():
    if (key, _key) in skip_dic:
        continue
    elif (_key, -key) in sin_dic:
        p = pow(2, len(sin_dic[(key,_key)]), mod) - 1 + pow(2, len(sin_dic[(_key, -key)]), mod)
        ans = (ans * p) % mod
        skip_dic[(_key, -key)] = True
    elif (- _key, key) in sin_dic:
        p = pow(2, len(sin_dic[(key,_key)]), mod) - 1 + pow(2, len(sin_dic[(-_key, key)]), mod)
        ans = (ans * p) % mod
        skip_dic[(-_key, key)] = True
    else:
        ans = (ans * pow(2, len(sin_dic[(key, _key)]), mod)) % mod 
#import IPython;IPython.embed()
    #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
    #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:
import collections
import fractions

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(fractions.Fraction(a, b))
    if a == 0: atan.append(float('inf'))
    else: atan.append(fractions.Fraction(-1 * b, a))

print('yes')

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
dic1 = defaultdict(int)
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
mod = 10**9+7
def pow(n,p,mod=10**9+7): #繰り返し二乗法(nのp乗)
    res = 1
    while p > 0:
        if p % 2 == 0:
            n = n ** 2 % mod
            p //= 2
        else:
            res = res * n % mod
            p -= 1
    return res % mod
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
def lcm(a,b):
    return (a//gcd(a,b)*b)
n = int(readline())
zero = 0
#dic1
#[正負,比率1(小),比率2(大)]
for i in range(n):
    a,b= map(int,readline().split())
    plamai = 1 if a*b > 0 else 0
    if a < 0:a = -a
    if b < 0:b = -b
    res = gcd(a,b)
    if a == b == 0:
        zero += 1
    elif a == 0: #1とか-1とか関係ない
        dic1[str(0)+" "+str(0)+" "+str(1)] += 1
    elif b == 0:
        dic1[str(1)+" "+str(1)+" "+str(0)] += 1
    else:
        dic1[str(plamai)+" "+str(a//res)+" "+str(b//res)] += 1

ans = 1
dic2 = dict()
for i in dic1.keys():
    res = 0
    if not i in dic2:
        a = dic1[i]
        g,d,e = i.split()
        if g == "1":
            res2 = "0"+" "+e+" "+d
        else:
            res2 = "1"+" "+e+" "+d
        if res2 in dic1:
            b = dic1[res2]
        else:b = 0
        if a > 0:
            res += pow(2,a)
        if b > 0:
            res += pow(2,b)
        if a != 0 and b != 0:
            res -= 1
        ans *= res
        ans %= mod
        dic2[res2] = 1
print(ans-1+zero)

Submission status: Wrong Answer

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

n=int(input())
a= [list(map(int, input().split())) for i in range(n)]
b=defaultdict(int)
c=defaultdict(int)
b0=0
c0=0
mod=1000000007
ans=1
cnt=0
for i,j in a:
    if i!=0 and j!=0:
        b[i/j]+=1
        c[j/i]+=1
    elif i==0 and j!=0:
        b0+=1
    elif i!=0 and j==0:
        c0+=1
    else:
        cnt+=1
w=[]
if c0!=0 or b0!=0:
    ans*=pow(2,c0+b0)-((pow(2,c0)-1)*(pow(2,b0)-1))



for k,v in b.items():
    if c[-k]!=0:
        ans*=(pow(2,c[-k]+v)-(pow(2,c[-k])-1)*(pow(2,v)-1))
        w.append(pow(2,c[-k]+v)-(pow(2,c[-k])-1)*(pow(2,v)-1))
        ans%=mod
    else:
        ans*=pow(2,v)
        ans%=mod

w=collections.Counter(w)
w=list(w.most_common())

for i,j in w:
    for k in range(j//2):
        ans*=pow(i,mod-2,mod)
ans+=cnt-1
print(ans%mod)

Submission status: Wrong Answer

Solution code:
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
import sys

# sys.stdout.write(str(n)+"\n")
MODULO = 1000000007
INF = 1e18+10

n = int(input())
a = [0 for i in range(n)]
b = [0 for i in range(n)]

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

graph = [[] for _ in range(n)]
value_indices = {} # a_b values
for i in range(n):
	if a[i] == 0 and b[i] == 0:
		for j in range(n):
			graph[i].append(j)
			graph[j].append(i)
	else:
		if a[i] == 0:
			a_b = 0
			m_b_a = INF
		elif b[i] == 0:
			a_b = INF
			m_b_a = 0
		else:
			a_b = a[i] / b[i]
			m_b_a = -b[i] / a[i]

		if m_b_a in value_indices:
			for j in value_indices[m_b_a]:
				graph[i].append(j)
				graph[j].append(i)
		value_indices[a_b] = value_indices.get(a_b, []) + [i]

# print("value_indices", value_indices)
# print("graph", graph)

def comb(i):
	# layers = []
	cur_layer = [i]
	next_layer = []
	used[i] = True

	chet = 0
	nechet = 0
	is_chet = True
	while len(cur_layer) > 0:
		if is_chet:
			chet += len(cur_layer)
		else:
			nechet += len(cur_layer)
		is_chet = not is_chet
		# layers.append(cur_layer)
		next_layer = []
		for item in cur_layer:
			for child in graph[item]:
				if not used[child]:
					next_layer.append(child)
					used[child] = True
		cur_layer = next_layer.copy()
	# print(layers)
	# for i in range(len(layers)):
	# 	if i % 2 == 0:
	# 		chet += len(layers[i])
	# 	else:
	# 		nechet += len(layers[i])
	return pow(2, chet, MODULO) + pow(2, nechet, MODULO) -1


ans = 1
used = [False for _ in range(n)]
for i in range(n):
	if not used[i]:
		if len(graph[i]) == 0:
			used[i]
			ans *= 2
			ans %= MODULO
		else:
			ans *= comb(i)
			ans %= MODULO
print(ans-1)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
dic1 = defaultdict(int)
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
mod = 10**9+7
def pow(n,p,mod=10**9+7): #繰り返し二乗法(nのp乗)
    res = 1
    while p > 0:
        if p % 2 == 0:
            n = n ** 2 % mod
            p //= 2
        else:
            res = res * n % mod
            p -= 1
    return res % mod
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
def lcm(a,b):
    return (a//gcd(a,b)*b)
n = int(readline())
zero = 0
#dic1
#[正負,比率1(小),比率2(大)]
for i in range(n):
    a,b= map(int,readline().split())
    plamai = 1 if a*b > 0 else 0
    if a < 0:a = -a
    if b < 0:b = -b
    res = gcd(a,b)
    if a == b == 0:
        zero += 1
    elif a == 0:
        dic1[str(plamai)+" "+str(0)+" "+str(1)] += 1
    elif b == 0:
        dic1[str(plamai)+" "+str(1)+" "+str(0)] += 1
    else:
        dic1[str(plamai)+" "+str(a//res)+" "+str(b//res)] += 1

ans = 1
dic2 = dict()
for i in dic1.keys():
    res = 0
    if not i in dic2:
        a = dic1[i]
        g,d,e = i.split()
        if g == "1":
            res2 = "0"+" "+e+" "+d
        else:
            res2 = "1"+" "+e+" "+d
        if res2 in dic1:
            b = dic1[res2]
        else:b = 0
        if a > 0:
            res += pow(2,a)
        if b > 0:
            res += pow(2,b)
        if a != 0 and b != 0:
            res -= 1
        ans *= res
        ans %= mod
        dic2[res2] = 1
print(ans-1+zero)

Submission status: Wrong Answer

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

n=int(input())
a= [list(map(int, input().split())) for i in range(n)]
b=defaultdict(int)
c=defaultdict(int)
b0=0
c0=0
mod=1000000007
ans=1
cnt=0
for i,j in a:
    if i!=0 and j!=0:
        b[i/j]+=1
        c[j/i]+=1
    elif i==0 and j!=0:
        b0+=1
    elif i!=0 and j==0:
        c0+=1
    else:
        cnt+=1
w=[]
if c0!=0 or b0!=0:
    ans*=pow(2,c0+b0)-((pow(2,c0)-1)*(pow(2,b0)-1))



for k,v in b.items():
    if c[-k]!=0:
        ans*=(pow(2,c[-k]+v)-(pow(2,c[-k])-1)*(pow(2,v)-1))
        w.append(pow(2,c[-k]+v)-(pow(2,c[-k])-1)*(pow(2,v)-1))
        ans%=mod
    else:
        ans*=pow(2,v)
        ans%=mod

w=collections.Counter(w)
w=list(w.most_common())

for i,j in w:
    for k in range(j//2):
        ans*=pow(i,mod-2,mod)
ans%=mod
ans+=cnt-1
print(ans%mod)

Submission status: Wrong Answer

Solution code:
def main():
    import math
    import collections
    N = int(input())

    mod = 10**9+7
    AB = [tuple(map(int, input().split())) for i in range(N)]

    d = collections.defaultdict(set)
    i = 0
    for a, b in AB:
        g = math.gcd(a, b)
        if g != 0:
            a = a // g
            b = b // g

        d[(a, b)].add(i)
        i += 1

    ans = 0
    r = set()

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

    r = set()
    ans = 1
    for a, b in d:
        if (a, b) in r:
            continue
        l1 = len(d[(a, b)])
        s = set()
        if (-b, a) in d:
            s |= d[(-b, a)]
        if (b, -a) in d:
            s |= d[(b, -a)]
        s -= d[(a, b)]
        l2 = len(s)
        if l2:
            ans *= dd[l1] + dd[l2] - 1
            N -= l1 + l2
            ans %= mod
            r.add((-b, a))
            r.add((b, -a))
        else:
            continue
    if N:
        ans *= dd[N]
    ans -= 1

    print(ans % mod)


main()

Submission status: Wrong Answer

Solution code:
import math
from collections import Counter

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

for _ in range(n):
    a, b = map(int, input().split())
    if b < 0:
        a = -a
        b = -b
    if a == 0 and b == 0:
        c[-1] += 1
        continue

    a, b = a//math.gcd(a, b), b//math.gcd(a, b)

    key = a*(10**19)+b
    c[key] += 1
    cc[key] += 1

l = []

for r in cc.keys():
    if r == -1:
        continue
    ra = c[r]
    
    a, b = r//(10**19), r % (10**19)
    if a >= 0:
        r_inv = (-b)*10**19 + a
    else:
        r_inv = b*(10**19) - a
    rb = c[r_inv]

    if ra >= 0 and rb >= 0:
        l.append([ra, rb])
        c[r] -= 10**9
        c[r_inv] -= 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)

Submission status: Wrong Answer

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

mod = 10**9+7

N = int(input())
As = {}
for _ in range(N):
    x, y = map(int, input().split())
    g = math.gcd(x, y)
    if g == 0: continue
    x, y = x//g, y//g
    if x != 0 or y != 0:
        if y < 0 or (y==0 and x < 0):
            y = -y
            x = -x
        if (x, y) in As:
            As[(x, y)] += 1
        else:
            As[(x, y)] = 1

ans = 1
for (x, y), num in As.items():
    if (-y, x) in As:
        if x > 0:
            ans = (ans * (pow(2, num, mod) + pow(2, As[(-y, x)], mod) - 1)) % mod
    elif not (y, -x) in As:
        ans = (ans * pow(2, num, mod)) % mod

print((ans-1)%mod)

Submission status: Wrong Answer

Solution code:
def main():
    import math
    import collections
    N = int(input())

    mod = 10**9+7
    AB = [tuple(map(int, input().split())) for i in range(N)]

    d = collections.defaultdict(set)
    i = 0
    for a, b in AB:
        g = math.gcd(a, b)
        if g != 0:
            a = a // g
            b = b // g

        d[(a, b)].add(i)
        i += 1

    ans = 0
    r = set()

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

    r = set()
    ans = 1
    for a, b in d:
        if (a, b) in r:
            continue
        l1 = len(d[(a, b)])
        s = set()
        if (-b, a) in d:
            s |= d[(-b, a)]
        if (b, -a) in d:
            s |= d[(b, -a)]
        l2 = len(s)
        if l2:
            ans *= dd[l1] + dd[l2] - 1
            N -= l1 + l2
            ans %= mod
            r.add((-b, a))
            r.add((b, -a))
        else:
            continue
    if N:
        ans *= dd[N]
    ans -= 1

    print(ans % mod)


main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    
    input = sys.stdin.readline
    n = int(input())
    mod = 10**9+7
    d = {}
    l1 = []
    l2 = []
    zero = [0]*3
    for i in range(n):
        a,b = map(int,input().split())
        if a == 0 and b == 0:
            zero[0] += 1
        elif a == 0:
            zero[1] += 1
        elif b == 0:
            zero[2] += 1
        else:
            s1 = -b/a
            s2 = a/b
            if s2 in d:
                d[s2] += 1
            else:
                l1.append(s2)
                l2.append(-1)
                d[s2] = 1
                if s1 in d:
                    ind = l1.index(s1)
                    l2[-1] = ind
                    l2[ind] = len(l1)-1

    done = set()
    ans = 1
    for i in range(len(l2)):
        if l2[i] < 0:
            ans *= 2
            ans %= mod
        else:
            if l2[i] in done:
                continue
            c1 = d[l1[i]]
            c2 = d[l1[l2[i]]]
            count = (pow(2,c1,mod)+pow(2,c2,mod)-1)%mod
            ans *= count
            ans %= mod
            done.add(i)
            done.add(l2[i])
    c = 0
    if zero[0] > 0:
        c = zero[0]
    if zero[1] *zero[2] > 0:
        count = (pow(2,zero[1],mod)+pow(2,zero[2],mod)-1)%mod
        ans *= count
        ans %= mod
    elif zero[1] > 0:
        ans *= pow(2,zero[1],mod)
        ans %= mod
    elif zero[2] > 0:
        ans *= pow(2,zero[2],mod)
        ans %= mod
    print(ans+-1)
            
if __name__ =="__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
dic1 = defaultdict(int)
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
mod = 10**9+7
def pow(n,p,mod=10**9+7): #繰り返し二乗法(nのp乗)
    res = 1
    while p > 0:
        if p % 2 == 0:
            n = n ** 2 % mod
            p //= 2
        else:
            res = res * n % mod
            p -= 1
    return res % mod
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
def lcm(a,b):
    return (a//gcd(a,b)*b)
n = int(readline())
zero = 0
#dic1
#[正負,比率1(小),比率2(大)]
for i in range(n):
    a,b= map(int,readline().split())
    plamai = 1 if a*b > 0 else 0
    if a < 0:a = -a
    if b < 0:b = -b
    res = gcd(a,b)
    try:
        dic1[str(plamai)+" "+str(a//res)+" "+str(b//res)] += 1
    except:
        zero += 1

ans = 1
dic2 = dict()
for i in dic1.keys():
    res = 0
    if not i in dic2:
        a = dic1[i]
        g,d,e = i.split()
        if g == "1":
            res2 = "0"+" "+e+" "+d
        else:
            res2 = "1"+" "+e+" "+d
        if res2 in dic1:
            b = dic1[res2]
        else:b = 0
        if a > 0:
            res += pow(2,a)
        if b > 0:
            res += pow(2,b)
        if a != 0 and b != 0:
            res -= 1
        ans *= res
        ans %= mod
        dic2[res2] = 1
print(ans-1+zero)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    
    input = sys.stdin.readline
    n = int(input())
    mod = 10**9+7
    d = {}
    l1 = []
    l2 = []
    zero = [0]*3
    for i in range(n):
        a,b = map(int,input().split())
        if a == 0 and b == 0:
            zero[0] += 1
        elif a == 0:
            zero[1] += 1
        elif b == 0:
            zero[2] += 1
        else:
            s1 = -b/a
            s2 = a/b
            if s2 in d:
                d[s2] += 1
            else:
                l1.append(s2)
                l2.append(-1)
                d[s2] = 1
                if s1 in d:
                    ind = l1.index(s1)
                    l2[-1] = ind
                    l2[ind] = len(l1)-1

    done = set()
    ans = 1
    for i in range(len(l2)):
        if l2[i] < 0:
            ans *= 2
            ans %= mod
        else:
            if l2[i] in done:
                continue
            c1 = d[l1[i]]
            c2 = d[l1[l2[i]]]
            count = (pow(2,c1,mod)+pow(2,c2,mod)-1)%mod
            ans *= count
            ans %= mod
            done.add(i)
            done.add(l2[i])
    c = 0
    if zero[0] > 0:
        c = zero[0]+1
    if zero[1] *zero[2] > 0:
        count = (pow(2,zero[1],mod)+pow(2,zero[2],mod)-1)%mod
        ans *= count
        ans %= mod
    elif zero[1] > 0:
        ans *= pow(2,zero[1],mod)
        ans %= mod
    elif zero[2] > 0:
        ans *= pow(2,zero[2],mod)
        ans %= mod
    print(ans+-1)
            
if __name__ =="__main__":
    main()

Submission status: Wrong Answer

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

n=int(input())
a= [list(map(int, input().split())) for i in range(n)]
b=defaultdict(int)
c=defaultdict(int)
b0=0
c0=0
mod=1000000007
ans=1
cnt=0
for i,j in a:
    if i!=0 and j!=0:
        b[i/j]+=1
        c[j/i]+=1
    elif i==0 and j!=0:
        b0+=1
    elif i!=0 and j==0:
        c0+=1
    else:
        cnt+=1
w=[]
if c0!=0 or b0!=0:
    ans*=pow(2,c0+b0)-((pow(2,c0)-1)*(pow(2,b0)-1))



for k,v in b.items():
    if c[-k]!=0:
        ans*=(pow(2,c[-k]+v)-(pow(2,c[-k])-1)*(pow(2,v)-1))
        w.append(pow(2,c[-k]+v)-(pow(2,c[-k])-1)*(pow(2,v)-1))
        ans%=mod
    else:
        ans*=pow(2,v)
        ans%=mod

w=collections.Counter(w)
w=list(w.most_common())
for i,j in w:
    ans*=pow(i*j//2,mod-2,mod)
ans%=mod
ans+=cnt-1
print(ans%mod)

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
mod = 1000000007
x = []
y = []
ex = [0,0]
ex2 = 0
for i in range(n):
    if (a[i][0]==0 and a[i][1]==0):
        ex2 += 1
    elif (a[i][0]==0):
        ex[0] +=1
    elif (a[i][1]==0):
        ex[1] += 1
    elif (a[i][0]*a[i][1]>0):
        x.append(a[i][1]/a[i][0])
    else:
        y.append(-a[i][0]/a[i][1])
     
x.sort()
y.sort()
#print(x,y)
xl = 0
yl = 0
xu = []
yu = []
xn = 0
yn = 0
while (xl<len(x) and yl<len(y)):
    if (x[xl] > y[yl]):
        yl += 1
    elif (x[xl] < y[yl]):
        xl += 1
    else:
        #print(xl,yl,x,y)
        p = bisect.bisect_right(x,x[xl])
        q = bisect.bisect_right(y,y[yl])
        xn += (p-xl)
        yn += (q-yl)
        xu.append(p-xl)
        yu.append(q-yl)
        xl = p
        yl = q
xu.append(ex[0])
yu.append(ex[1])
#print(xn,yn,xu,yu)
ans = pow(2,n-xn-yn-ex2,mod)
#if (n-xn-yn>0):
    #t = 1
    #for i in range(1,n-xn-yn+1):
        #t *= i
        #t %= mod
    #ans += t
for i in range(len(xu)):
    ans *= (pow(2,xu[i],mod)+pow(2,yu[i],mod)-1)
    ans %= mod
if (ex2==0):
    print((ans-1)%mod)
else:
    print((ans-1+ex2)%mod)

Submission status: Wrong Answer

Solution code:
import math
mod = 10**9 + 7
n = int(input())
d = {}
d0 = 0
for _ in range(n):
    a, b = map(int, input().split())
    g = math.gcd(a, b)
    if g == 0:
        d0 += 1
    else:
        a //= g
        b //= g
        if a < 0:
            a = -a
            b = -b
        elif a == 0 and b < 0:
            b = -b
        if (a,b) in d:
            d[(a,b)] += 1
        else:
            d[(a,b)] = 1
ans = 1
for (a,b) in d.keys():
    if d[(a,b)] > 0:
        t = 2**d[(a,b)]
        if b < 0:
            a = -a
            b = -b
        if (b,-a) in d:
            t += 2**d[(b,-a)] - 1
            d[(b,-a)] = 0
        ans *= t
        ans %= mod
print(ans+d0-1)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
dic1 = defaultdict(int)
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
mod = 10**9+7
def pow(n,p,mod=10**9+7): #繰り返し二乗法(nのp乗)
    res = 1
    while p > 0:
        if p % 2 == 0:
            n = n ** 2 % mod
            p //= 2
        else:
            res = res * n % mod
            p -= 1
    return res % mod
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
def lcm(a,b):
    return (a//gcd(a,b)*b)
n = int(readline())
zero = 0
#dic1
#[正負,比率1(小),比率2(大)]
for i in range(n):
    a,b= map(int,readline().split())
    plamai = 1 if a*b > 0 else 0
    if a < 0:a = -a
    if b < 0:b = -b
    res = gcd(a,b)
    if res == 0:
        zero += 1
        continue
    dic1[str(plamai)+" "+str(a//res)+" "+str(b//res)] += 1

ans = 1
dic2 = dict()
for i in dic1.keys():
    res = 0
    if not i in dic2:
        a = dic1[i]
        g,d,e = i.split()
        if g == "1":
            res2 = "0"+" "+e+" "+d
        else:
            res2 = "1"+" "+e+" "+d
        if res2 in dic1:
            b = dic1[res2]
        else:b = 0
        if a > 0:
            res += pow(2,a)
        if b > 0:
            res += pow(2,b)
        if a != 0 and b != 0:
            res -= 1
        ans *= res
        ans %= mod
        dic2[res2] = 1
print(ans-1+zero)

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:
        if a == 0:
            b = 1
            g = 1
        elif b == 0:
            a = 1
            g = 1
        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

if len(d.keys()) == 0:
    print(1)
    exit()
ans = (ans-1)%mod
print(ans)

Submission status: Wrong Answer

Solution code:
from math import gcd
from collections import Counter

mod = 1000000007

N = int(input())
F = []

alone = 0

for i in range(N):
    A,B = map(int,input().split())
    if A == 0 and B == 0:
        alone += 1
        continue
    if A == 0:
        F.append((0,0,1))
    elif B == 0:
        F.append((0,1,0))
    else:
        fugou = 1
        if A < 0:
            fugou *= -1
            A *= -1
        if B < 0:
            fugou *= -1
            B *= -1
        C = gcd(A,B)
        F.append((fugou,A//C,B//C))

C = Counter(F)
G = []
for f in F:
    ff,fa,fb = f
    g = (-ff,fb,fa)
    a,b = 1,1
    for i in range(C[f]):
        a *= 2
        a %= mod
    for i in range(C[g]):
        b *= 2
        b %= mod
    c = a + b + mod - 1
    c %= mod
    if c > 1:
        G.append(c)
    C[f] = 0
    C[g] = 0

ans = 1
for g in G:
    ans *= g
    ans %= mod

ans = ans + alone + mod - 1
ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
dic1 = defaultdict(int)
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
mod = 10**9+7
def pow(n,p,mod=10**9+7): #繰り返し二乗法(nのp乗)
    res = 1
    while p > 0:
        if p % 2 == 0:
            n = n ** 2 % mod
            p //= 2
        else:
            res = res * n % mod
            p -= 1
    return res % mod
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
def lcm(a,b):
    return (a//gcd(a,b)*b)
n = int(readline())
zero = 0
#dic1
#[正負,比率1(小),比率2(大)]
for i in range(n):
    a,b= map(int,readline().split())
    plamai = 1 if a*b > 0 else 0
    if a < 0:a = -a
    if b < 0:b = -b
    res = gcd(a,b)
    if res == 0:
        zero += 1
        continue
    dic1[str(plamai)+" "+str(a//res)+" "+str(b//res)] += 1

ans = 1
dic2 = dict()
for i in dic1.keys():
    res = 0
    if not i in dic2:
        a = dic1[i]
        g,d,e = i.split()
        if g == "1":
            res2 = "0"+" "+e+" "+d
        else:
            res2 = "1"+" "+e+" "+d
        if res2 in dic1:
            b = dic1[res2]
        else:b = 0
        if a > 0:
            res += pow(2,a)
        if b > 0:
            res += pow(2,b)
        if a != 0 and b != 0:
            res -= 1
        ans *= res
        ans %= mod
        dic2[res2] = 1
if not zero:
    print(ans-1)
else:
    print(ans+pow(2,zero)-2)

Submission status: Wrong Answer

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

    if a==0 and b==0:
        zz += 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      
    
print (d_p,d_m)

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

Submission status: Wrong Answer

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

n=int(input())
a= [list(map(int, input().split())) for i in range(n)]
b=defaultdict(int)
c=defaultdict(int)
b0=0
c0=0
mod=1000000007
ans=1
cnt=0
for i,j in a:
    if i!=0 and j!=0:
        b[i/j]+=1
        c[j/i]+=1
    elif i==0 and j!=0:
        b0+=1
    elif i!=0 and j==0:
        c0+=1
    else:
        cnt+=1
w=[]
if c0!=0 or b0!=0:
    ans*=pow(2,c0+b0,mod)-((pow(2,c0,mod)-1)*(pow(2,b0,mod)-1))



for k,v in b.items():
    if c[-k]!=0:
        ans*=(pow(2,c[-k]+v,mod)-(pow(2,c[-k],mod)-1)*(pow(2,v,mod)-1))
        w.append((pow(2,c[-k]+v,mod)-(pow(2,c[-k],mod)-1)*(pow(2,v,mod)-1)))
        ans%=mod
    else:
        ans*=pow(2,v)
        ans%=mod

w=collections.Counter(w)
w=list(w.most_common())
for i,j in w:
    ans*=pow(i*j//2,mod-2,mod)
ans%=mod
ans+=cnt-1
print(ans%mod)