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:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

#from math import gcd
from fractions import Fraction as Fc

mod = int(1e9+7)
n = ii()
cnd = {}
azero = 0
bzero = 0
allzero = 0
for _ in range(n):
    a,b = iim()
    if a == 0:
        if b != 0:
            azero += 1
        else:
            allzero += 1
    elif b == 0:
        bzero += 1            
    else:
        f = Fc(a,b)
        cnd[f] = cnd.get(f,0)+1


noreg = 0
if azero == 0 or bzero == 0:
    noreg += max(azero,bzero)
    ans = 1
else:
    ans = (2**azero%mod + 2**bzero%mod - 1)%mod

for k,item in cnd.items():
    if k>0:
        m = cnd.get(-f,False)
        if m:
            ans *= (2**item%mod+2**m%mod-1)%mod
        else:
            noreg += item
    else:
        m = cnd.get(-f,False)
        if not m:
            noreg += item
print(int((ans*((2**noreg)%mod)-1+allzero)%mod))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

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

MOD = 1000000007

def mod_add(a, b):
  return (a+b)%MOD

def mod_sub(a, b):
  return (a+MOD-b)%MOD

def mod_mul(a, b):
  return a*b%MOD

#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = (1,0,a)
    w = (0,1,b)
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return (w[0],w[1])

def mod_inv(a):
    x,_  = extgcd(a, MOD)
    return (MOD+x%MOD)%MOD

def mod_div(a, b):
    return a*mod_inv(b)%MOD

def mod_pow(a, b):
    res = 1
    while b > 0:
        if b & 1:
            res = res * a % MOD
        a = a * a % MOD
        b >>= 1
    return res

from collections import Counter
from fractions import Fraction

n = n_in()
c = Counter()
iab = []
for i, _ in enumerate(range(n)):
    a,b=l_in()
    if a == 0 and b == 0:
        c[(0,0)] += 1
        continue
    if b == 0:
        c[(1,0)] += 1
        continue
    if a == 0:
        c[(0,1)] += 1
        continue

    f = Fraction(a,b)
    c[(f.numerator, f.denominator)] += 1

res = 1
vis = set()

for (a,b),s in c.items():
    if (a,b) in vis:
        continue
    if (a,b) == (0,0):
        continue

    tupl = (0,0)
    if b == 0:
        tupl = (0,1)
    elif a == 0:
        tupl = (1,0)
    else:
        f = Fraction(-b,a)            
        tupl = (f.numerator, f.denominator)

    vis.add(tupl)
    t = c[tupl]


    tmp = mod_add(mod_sub(mod_pow(2,s),1), mod_sub(mod_pow(2,t),1))
    tmp = mod_add(tmp,1)

    res = mod_mul(res, tmp)

res = mod_sub(res,1)
res = mod_add(res, c[(0,0)] > 0)
print(res)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

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

MOD = 1000000007

def mod_add(a, b):
  return (a+b)%MOD

def mod_sub(a, b):
  return (a+MOD-b)%MOD

def mod_mul(a, b):
  return a*b%MOD

#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = (1,0,a)
    w = (0,1,b)
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return (w[0],w[1])

def mod_inv(a):
    x,_  = extgcd(a, MOD)
    return (MOD+x%MOD)%MOD

def mod_div(a, b):
    return a*mod_inv(b)%MOD

def mod_pow(a, b):
    res = 1
    while b > 0:
        if b & 1:
            res = res * a % MOD
        a = a * a % MOD
        b >>= 1
    return res

from collections import Counter
from fractions import Fraction

n = n_in()
c = Counter()
iab = []
for i, _ in enumerate(range(n)):
    a,b=l_in()
    if a == 0 and b == 0:
        c[(0,0)] += 1
        continue
    if b == 0:
        c[(1,0)] += 1
        continue
    if a == 0:
        c[(0,1)] += 1
        continue

    f = Fraction(a,b)
    c[(f.numerator, f.denominator)] += 1

res = 1
vis = set()

for (a,b),s in c.items():
    if (a,b) in vis:
        continue
    if (a,b) == (0,0):
        continue

    tupl = (0,0)
    if b == 0:
        tupl = (0,1)
    elif a == 0:
        tupl = (1,0)
    else:
        f = Fraction(-b,a)            
        tupl = (f.numerator, f.denominator)

    vis.add(tupl)
    t = c[tupl]


    tmp = mod_add(mod_sub(mod_pow(2,s),1), mod_sub(mod_pow(2,t),1))
    tmp = mod_add(tmp,1)

    res = mod_mul(res, tmp)

res = mod_sub(res,1)
res = mod_add(res, int(c[(0,0)] > 0))
print(res)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): 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)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
import bisect #bisect.bisect_left(B, a)
from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

N = ii()
ab = li2(N)
mod = 10**9+7

d = defaultdict(int)

for i in range(N):
    if ab[i][1] != 0:
        d[ab[i][0] / ab[i][1]] += 1
    else:
        d[0.0] += 1

d_l = sorted(d.items(), key=lambda x:x[0])

cnt = 1
for k, v in d_l:
    #print(cnt, k, v, 1/k)
    if k > 0:
        if not d[-1/k]:
            cnt = ((v+1) * cnt) % mod
    elif k == 0:
        cnt = (cnt * (2**v-1)*2 + 1) % mod
    elif d[-1/k]:
        cnt = (cnt * ((2**v-1) + (2**d[-1/k]-1) + 1)) % mod
    else:
        cnt = ((v+1) * cnt) % mod

print(cnt - 1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter, defaultdict, deque
import math

import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def f(a, b):
    if a == 0 and b == 0:
        return (1, 0, 0)
    if b == 0:
        return (1, 1, 0)
    g = math.gcd(a, b)
    a //= g
    b //= g
    if a == 0 and b < 0:
        s = 1
    else:
        s = 1 if a * b >= 0 else -1
    a = abs(a)
    b = abs(b)
    return s, a, b


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)


@mt
def slv(N, AB):
    adb = Counter()
    for a, b in AB:
        s, a, b = f(a, b)
        adb[(s*a, b)] += 1
    error_print(adb)
    M = Mod(1000000007)
    ans = 1
    done = set()
    for k, v in adb.items():
        if k in done:
            continue
        if k == (0, 0):
            continue
        a, b = k
        if a < 0:
            s = 1
            a = abs(a)
        else:
            s = -1
        n = adb[(s*b, a)]
        done.add(k)
        done.add((s*b, a))
        t = M.sub(M.pow(2, v) + M.pow(2, n), 1)
        ans = M.mul(ans, t)

    return M.add(M.sub(ans, 1), adb[(0, 0)])


def main():
    N = read_int()
    AB = [read_int_n() for _ in range(N)]
    print(slv(N, AB))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from math import gcd
import sys
input = sys.stdin.readline
N=int(input())
mod=10**9+7
dic=defaultdict(lambda: [0,0])
c=0
d=0
e=0
for i in [0]*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:
  g=gcd(A,B)
  A//=g
  B//g
  if A*B>0:
   dic[(abs(A),abs(B))][0]+=1
  else:
   dic[(abs(B),abs(A))][1]+=1
ans=1
for k in dic:
 ans=ans*(pow(2,dic[k][0],mod)+pow(2,dic[k][1],mod) -1)
ans=ans*(pow(2,c,mod)+pow(2,d,mod)-1)
print((ans-1+e)%mod)

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
m=[]
groups=[]
INF=10**27
a0only=0
b0only=0
both0=0
negativecounter=0
for i in range(n):
  a,b=map(int,sys.stdin.readline().split())
  if b==0:
    if a==0:
      both0+=1
    else:
      b0only+=1
  elif a==0:
    a0only+=1
  else:
    m.append([a,b,'{0:0.60f}'.format(a/b),'{0:0.60f}'.format(-b/a)])
  if a*b<0:
    negativecounter+=1
m1=sorted(m, key=lambda student: student[2])
m2=sorted(m, key=lambda student: student[3])
backcounter=0
done=set()
for i in range(len(m)):
  a=m1[i][0]
  b=m1[i][1]
  if len(groups)>0:
    if groups[-1][0]*b==a*groups[-1][1]:
      groups[-1][2]+=1
    else:
      if i in done:
        groups.append([a,b,1,0,0])
      else:
       	groups.append([a,b,1,0,-1])
  else:
    if i in done:
      groups.append([a,b,1,0,0])
    else:
      groups.append([a,b,1,0,-1])
  while backcounter<len(m) and a/b>=-m2[backcounter][1]/m2[backcounter][0]:
    if m2[backcounter][0]*m1[i][0]+m2[backcounter][1]*m1[i][1]==0:
      groups[-1][3]+=1
      groups[-1][4]=0
    backcounter+=1
ans=1
donenumbers=[0]*len(groups)
for i in range(len(groups)):
  a=groups[i][0]
  b=groups[i][1]
  c=groups[i][2]
  d=groups[i][3]
  if groups[i][4]==0 and a*b<0:
    continue
  ans=(ans*((2**c+2**d)-1))%(10**9+7)
ans=(ans*(((2**a0only+2**b0only)-1+both0))%(10**9+7))
print(ans-1)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from math import gcd
import sys
input = sys.stdin.readline
N=int(input())
mod=10**9+7
dic=defaultdict(lambda: [0,0])
c=0
d=0
e=0
for i in [0]*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:
  g=gcd(A,B)
  A//=g
  B//g
  if A*B>0:
   dic[(A,B)][0]+=1
  else:
   dic[(-B,A)][1]+=1
ans=1
for k in dic:
 ans=ans*(pow(2,dic[k][0],mod)+pow(2,dic[k][1],mod) -1)
ans=ans*(pow(2,c,mod)+pow(2,d,mod)-1)
print((ans-1+e)%mod)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter, defaultdict, deque
import math

import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def f(a, b):
    if a == 0 and b == 0:
        return (1, 0, 0)
    g = math.gcd(a, b)
    a //= g
    b //= g
    if a == 0 and b < 0:
        s = -1
    elif b == 0 and a < 0:
        s = 1
    else:
        s = 1 if a * b >= 0 else -1
    a = abs(a)
    b = abs(b)
    return s, a, b


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)


@mt
def slv(N, AB):
    adb = Counter()
    for a, b in AB:
        s, a, b = f(a, b)
        adb[(s*a, b)] += 1
    error_print(adb)
    M = Mod(1000000007)
    ans = 1
    done = set()
    for k, v in adb.items():
        if k in done:
            continue
        if k == (0, 0):
            continue
        a, b = k
        if a < 0:
            s = 1
            a = abs(a)
        else:
            s = -1
        n = adb[(s*b, a)]
        done.add(k)
        done.add((s*b, a))
        t = M.sub(M.pow(2, v) + M.pow(2, n), 1)
        ans = M.mul(ans, t)

    return M.add(M.sub(ans, 1), adb[(0, 0)])


def main():
    N = read_int()
    AB = [read_int_n() for _ in range(N)]
    print(slv(N, AB))


if __name__ == '__main__':
    main()

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 and b == 0:
        continue
    if a == 0:
        b = 1
        g = 1
    elif b == 0:
        a = 1
        g = 1
    else:
        g = math.gcd(abs(a),abs(b))
    if a < 0 :
        a = -a
        b = -b
    p1 = str(a//g)+" "+str(b//g)
    if p1 in d:
        d[p1] += 1
    else:
        d[p1] = 1

for i in d.keys():
    if d[i] == 0:
        continue
    i0, i1 = map(int,i.split())
    if i1 < 0:
        i0 = -i0
        i1 = -i1
    if str(i1)+" "+str(-i0) in d:
        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(0)
    exit()
ans = (ans-1)%mod
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

def gcd(a, b):
    return gcd(b, a%b) if b else a

mod = 10 ** 9 + 7
N = int(input())
X = defaultdict(lambda: [0, 0])
# X = dict()
x = 0
y = 0
z = 0
for i in range(N):
    a, b = map(int, input().split())
    if a * b != 0:
        g = abs(gcd(a, b))
    if a * b > 0:
        X[(abs(a) / g, abs(b) / g)][0] += 1
    elif a * b < 0:
        X[(abs(b) / g, abs(a) / g)][1] += 1
    else:
        if a:
            x += 1
        elif b:
            y += 1
        else:
            z += 1
# suppose we have a super head point which can put togother with every point.
ans = 1
pow2 = [1]
for i in range(N):
    pow2 += [pow2[-1] * 2 % mod]
for i in X.values():
    ans *= pow2[i[0]] + pow2[i[1]]- 1
    ans %= mod
ans *= pow2[x] + pow2[y] - 1
print((ans+z-1)%mod)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


def fraction(a, b):
    """a/b を既約分数 numer/denom として求める
    denom は必ず非負整数
    numer = denom = 0 のときは numer/denom = 0/0
    numer = 0 のときは numer/denom = 0/1
    denom = 0 のときは numer/denom = 1/0
    """
    numer, denom = a, b
    if numer == denom == 0:
        return 0, 0
    elif numer == 0:
        return 0, 1
    elif denom == 0:
        return 1, 0

    # GCD(a, b) を計算して約分する
    while b:
        a, b = b, a % b
    gcd_ab = a
    numer = numer // gcd_ab
    denom = denom // gcd_ab

    if denom < 0:  # denom は必ず非負整数
       numer, denom = -numer, -denom
    return numer, denom
  

n = int(input())
info = [list(map(int, input().split())) for i in range(n)]
MOD = 10 ** 9 + 7

memo = defaultdict(int)
for i in range(n):
    a, b = info[i]
    memo[fraction(a, b)] += 1

cnt_00 = 0
cnt_n0 = 0 
cnt_d0 = 0
ans = 1
used = set()
for frac in memo:
    numer, denom = frac
    if numer == 0 and denom == 0:
        cnt_00 += memo[frac]
        continue
    elif numer == 0:
        cnt_n0 += memo[frac]
        continue
    elif denom == 0:
        cnt_d0 += memo[frac]
        continue
    
    if frac in used:
        continue
    rev_num, rev_den = -denom, numer
    if rev_den < 0:
        rev_num, rev_den = -rev_num, -rev_den

    cnt1 = memo[frac]
    cnt2 = 0
    if (rev_num, rev_den) in memo:
        cnt2 = memo[(rev_num, rev_den)]
    tmp = pow(2, cnt1, MOD) + pow(2, cnt2, MOD) - 1
    ans *= tmp
    ans %= MOD
    used.add((rev_num, rev_den))

ans = ans + cnt_00 + cnt_n0 * ans + cnt_d0 * ans + cnt_n0 * cnt_d0 * ans
print((ans - 1) % MOD)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

def gcd(a, b):
    return gcd(b, a%b) if b else a

mod = 10 ** 9 + 7
N = int(input())
X = defaultdict(lambda: [0, 0])
# X = dict()
x = 0
y = 0
z = 0
for i in range(N):
    a, b = map(int, input().split())
    g = abs(gcd(a, b))
    if a * b > 0:
        X[(abs(a) / g, abs(b) / g)][0] += 1
    elif a * b < 0:
        X[(abs(b) / g, abs(a) / g)][1] += 1
    else:
        if a:
            x += 1
        elif b:
            y += 1
        else:
            z += 1
# suppose we have a super head point which can put togother with every point.
ans = 1
pow2 = [1]
for i in range(N):
    pow2 += [pow2[-1] * 2 % mod]
for i in X.values():
    ans *= pow2[i[0]] + pow2[i[1]]- 1
    ans %= mod
ans *= pow2[x] + pow2[y] - 1
print((ans+z-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
    ans2 = 0
    for a, b in AB:
        if a == 0 and b == 0:
            N -= 1
            ans2 += 1
            continue
        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)])
        if l1:
            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 += ans2
    ans -= 1
    print(ans % mod)


main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter, defaultdict, deque
import math

import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def f(a, b):
    if a == 0 and b == 0:
        return (1, 0, 0)
    g = math.gcd(a, b)
    a //= g
    b //= g
    if a == 0 and b < 0:
        s = -1
    elif b == 0 and a < 0:
        s = -1
    else:
        s = 1 if a * b >= 0 else -1
    a = abs(a)
    b = abs(b)
    return s, a, b


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)


@mt
def slv(N, AB):
    adb = Counter()
    for a, b in AB:
        s, a, b = f(a, b)
        adb[(s*a, b)] += 1
    error_print(adb)
    M = Mod(1000000007)
    ans = 1
    done = set()
    for k, v in adb.items():
        if k in done:
            continue
        if k == (0, 0):
            continue
        a, b = k
        if a < 0:
            s = 1
            a = abs(a)
        else:
            s = -1
        n = adb[(s*b, a)]
        done.add(k)
        done.add((s*b, a))
        t = M.sub(M.pow(2, v) + M.pow(2, n), 1)
        ans = M.mul(ans, t)

    return M.add(M.sub(ans, 1), adb[(0, 0)])


def main():
    N = read_int()
    AB = [read_int_n() for _ in range(N)]
    print(slv(N, AB))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

N = int(input())
zero1 = 0
zero2 = 0
zero3 = 0
cnt = defaultdict(int)
MOD = 10**9+7

for _ in range(N):
    A, B = map(int, input().split())
    
    if A==0 and B==0:
        zero1 += 1
    elif A>0 and B>0:
        G = gcd(A, B)
        A //= G
        B //= G
        cnt[(A, B)] += 1
    elif A>0 and B<0:
        B *= -1
        G = gcd(A, B)
        A //= G
        B //= G
        cnt[(-A, B)] += 1
    elif A<0 and B>0:
        A *= -1
        G = gcd(A, B)
        A //= G
        B //= G
        cnt[(-A, B)] += 1
    elif A<0 and B<0:
        A *= -1
        B *= -1
        G = gcd(A, B)
        A //= G
        B //= G
        cnt[(A, B)] += 1
    elif A==0:
        zero2 += 1
    elif B==0:
        zero3 += 1

s = set()
ans = 1

for k in cnt.keys():
    if k in s:
        continue
    
    k2 = (-k[1], k[0])
    
    if k2[0]<0 and k2[1]<0:
        k2 = (-k2[0], -k2[1])
        
    a = cnt[k]
    
    if k2 not in cnt:
        ans *= pow(2, a, MOD)
        ans %= MOD
    else:
        b = cnt[k2]
        ans *= pow(2, a, MOD)+pow(2, b, MOD)-1
        ans %= MOD
        s.add(k2)

ans += zero1
ans *= pow(2, zero2, MOD)+pow(2, zero3, MOD)-1
ans %= MOD
ans -= 1
ans %= MOD

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

def gcd(a, b):
    return gcd(b, a%b) if b else a

mod = 10 ** 9 + 7
N = int(input())
X = defaultdict(lambda: [0, 0])
print(X[(1, 1)])
# X = dict()
x = 0
y = 0
z = 0
for i in range(N):
    a, b = map(int, input().split())
    g = abs(gcd(a, b))
    if a * b > 0:
        X[(abs(a) / g, abs(b) / g)][0] += 1
    elif a * b < 0:
        X[(abs(b) / g, abs(a) / g)][1] += 1
    else:
        if a:
            x += 1
        elif b:
            y += 1
        else:
            z += 1
# suppose we have a super head point which can put togother with every point.
ans = 1
pow2 = [1]
for i in range(N):
    pow2 += [pow2[-1] * 2 % mod]
for i in X.values():
    ans *= pow2[i[0]] + pow2[i[1]]- 1
    ans %= mod
ans *= pow2[x] + pow2[y] - 1
print((ans+z-1)%mod)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

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

MOD = 1000000007

def mod_add(a, b):
  return (a+b)%MOD

def mod_sub(a, b):
  return (a+MOD-b)%MOD

def mod_mul(a, b):
  return a*b%MOD

#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = (1,0,a)
    w = (0,1,b)
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return (w[0],w[1])

def mod_inv(a):
    x,_  = extgcd(a, MOD)
    return (MOD+x%MOD)%MOD

def mod_div(a, b):
    return a*mod_inv(b)%MOD

def mod_pow(a, b):
    res = 1
    while b > 0:
        if b & 1:
            res = res * a % MOD
        a = a * a % MOD
        b >>= 1
    return res

n = n_in()
zerocheck = 0

iab = []
for i, _ in enumerate(range(n)):
    a,b=l_in()
    if a == 0 and b == 0:
        zerocheck += 1
        continue
    iab.append((i,a,b))

n = len(iab)

from collections import Counter
from fractions import Fraction
import bisect

adivb = Counter()
bzero = 0

for i,a,b in iab:
    if b == 0:
        bzero += 1
    else:
        f = Fraction(a,b)
        adivb[(f.numerator, f.denominator)] += 1

res = 1
vis = set()

for (a,b),s in adivb.items():
    if (a,b) in vis:
        continue

    t = 0
    if a == 0:
        t = bzero
    else:
        f = Fraction(-b,a)    
        t = adivb[(f.numerator, f.denominator)]
        vis.add((f.numerator, f.denominator))
        
    tmp = mod_add(mod_sub(mod_pow(2,s),1), mod_sub(mod_pow(2,t),1))
    tmp = mod_add(tmp,1)

    res = mod_mul(res, tmp)

res = mod_sub(res,1)
res = mod_add(res, zerocheck)
print(res)

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
m=[]
groups=[]
a0only=0
b0only=0
both0=0
negativecounter=0
for i in range(n):
  a,b=map(int,sys.stdin.readline().split())
  if b==0:
    if a==0:
      both0+=1
    else:
      b0only+=1
  elif a==0:
    a0only+=1
  else:
    m.append([a,b,a/b,-b/a])
  if a*b<0:
    negativecounter+=1
m1=sorted(m, key=lambda student: student[2])
m2=sorted(m, key=lambda student: student[3])
backcounter=0
done=set()
for i in range(len(m)):
  a=m1[i][0]
  b=m1[i][1]
  if len(groups)>0:
    if groups[-1][0]*b==a*groups[-1][1]:
      groups[-1][2]+=1
    else:
      if i in done:
        groups.append([a,b,1,0,0])
      else:
       	groups.append([a,b,1,0,-1])
  else:
    if i in done:
      groups.append([a,b,1,0,0])
    else:
      groups.append([a,b,1,0,-1])
  while backcounter<len(m) and a/b>=-m2[backcounter][1]/m2[backcounter][0]:
    if m2[backcounter][0]*m1[i][0]+m2[backcounter][1]*m1[i][1]==0:
      groups[-1][3]+=1
      groups[-1][4]=0
    backcounter+=1
ans=1
donenumbers=[0]*len(groups)
for i in range(len(groups)):
  a=groups[i][0]
  b=groups[i][1]
  c=groups[i][2]
  d=groups[i][3]
  if groups[i][4]==0 and a*b<0:
    continue
  ans=(ans*((2**c+2**d)-1))%(10**9+7)

print(ans-1)

Submission status: Wrong Answer

Solution code:
import bisect
import collections
import functools
import heapq
import math
from collections import deque
from collections import defaultdict
MOD = 10**9+7

N = int(input())
A = [0]*N
B = [0]*N
C = [[0]*2 for _ in range(N)]
zero = 0
inf = 0
for i in range(N):
    A[i],B[i] = map(int,(input().split()))
    if A[i] == 0 and B[i] == 0:
        C[i] = (0,0)
        zero += 1
    elif B[i] == 0:
        C[i] = (0,0)
        inf += 1
    elif B[i] > 0:
        g = math.gcd(A[i],B[i])
        C[i] = (A[i]//g,B[i]//g)
    else:
        g = math.gcd(A[i],B[i])
        C[i] = (-A[i]//g,-B[i]//g)

d = defaultdict(int)

for i in range(N):
    if C[i] != (0,0):
        d[C[i]] += 1

no_inf = 0
ans = 1
for k in d.keys():
    if k[0] == 0:
        no_inf += 1
    elif k[0] > 0:
        if (-k[1],k[0]) in d:
            ans *= pow(2,d[k],MOD) + pow(2,d[(-k[1],k[0])],MOD) -1
            d[k],d[(-k[1],k[0])] = 0,0
        else:
            ans *= pow(2,d[k],MOD)
    else:
        if (k[1],-k[0]) in d:
            ans *= pow(2,d[k],MOD) + pow(2,d[(k[1],-k[0])],MOD) -1
            d[k],d[(k[1],-k[0])] = 0,0
        else:
            ans *= pow(2,d[k],MOD)

ans *= pow(2,no_inf,MOD) + pow(2,inf,MOD) -1
print((ans+zero-1)%MOD)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter, defaultdict, deque
import math

import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def f(a, b):
    if a == 0 and b == 0:
        return (1, 0, 0)
    g = math.gcd(a, b)
    a //= g
    b //= g
    if a == 0 and b < 0:
        s = -1
    elif b == 0 and a < 0:
        s = -1
    else:
        s = 1 if a * b >= 0 else -1
    if b == 0:
        a = 1
    a = abs(a)
    b = abs(b)
    return s, a, b


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)


@mt
def slv(N, AB):
    adb = Counter()
    for a, b in AB:
        s, a, b = f(a, b)
        adb[(s*a, b)] += 1
    error_print(adb)
    M = Mod(1000000007)
    ans = 1
    done = set()
    for k, v in adb.items():
        if k in done:
            continue
        if k == (0, 0):
            continue
        a, b = k
        if a < 0:
            s = 1
            a = abs(a)
        else:
            s = -1
        n = adb[(s*b, a)]
        done.add(k)
        done.add((s*b, a))
        t = M.sub(M.pow(2, v) + M.pow(2, n), 1)
        ans = M.mul(ans, t)

    return M.add(M.sub(ans, 1), adb[(0, 0)])


def main():
    N = read_int()
    AB = [read_int_n() for _ in range(N)]
    print(slv(N, AB))


if __name__ == '__main__':
    main()