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:
from collections import defaultdict
import math
import sys
input=sys.stdin.readline
MOD=10**9+7
N=int(input())

def powmod(a,p):
  if p==0:
    return 1
  else:
    pow2=powmod(a,p//2)
    if p%2==0:
      return (pow2**2)%MOD
    else:
      return (a*pow2**2)%MOD

ratio_dic=defaultdict(int)
zero2_num=0

for i in range(N):
  A,B=map(int,input().split())
  if A==0 and B==0:
    zero2_num+=1
  elif A==0:
    ratio_dic[(0,1)]+=1
  elif B==0:
    ratio_dic[(1,0)]+=1
  elif B>0:
    AB_gcd=math.gcd(A,B)
    Arat=A//AB_gcd
    Brat=B//AB_gcd
    #print(A,B,Arat,Brat)
    ratio_dic[(Arat,Brat)]+=1
  else:
    AB_gcd=math.gcd(A,B)
    Arat=-A//AB_gcd
    Brat=-B//AB_gcd    
    #print(A,B,Arat,Brat)
    ratio_dic[(Arat,Brat)]+=1
#print(ratio_dic)

answer=1
checked_set=set()
for k,v in list(ratio_dic.items()):
  if k in checked_set:
    continue
  
  a,b=k
  #(a,b)<=>(ainv,binv)
  if a>=0:
    ainv,binv=-b,a
  else:
    ainv,binv=b,-a
    
  num_k1=ratio_dic[(a,b)]
  num_k2=ratio_dic[(ainv,binv)]
  answer*=powmod(2,num_k1)+powmod(2,num_k2)-1
  answer%=MOD
  #print(k,(ainv,binv),num_k1,num_k2)
  
  checked_set.add((a,b))
  checked_set.add((ainv,binv))
  
print((zero2_num+answer-1)%MOD)

Submission status: Wrong Answer

Solution code:


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

def main():
    mod=10**9
    N=I()
    from math import gcd
    from collections import defaultdict
    dd = defaultdict(int)
    temp0=0

    for i in range(N):
        a,b=MI()
        if (a,b)==(0,0):
            temp0+=1
            continue
        
        if a<0:
            a*=-1
            b*=-1
        
        #(+,+)と(+,-)だけにする
        if a*b!=0:
            g=gcd(abs(a),abs(b))
            a=a//g
            b=b//g
            if a*b>0:#(+,+)
                dd[(a,b)]+=1
                dd[b,-a]+=0
                
            else:#(+,-)
                dd[(a,b)]+=1
                dd[(-b,a)]+=0
            
        elif (a,b)!=(0,0):
            #assert 0
            if a==0:
                b=1
            else:
                a=1
                
            dd[(a,b)]+=1
            dd[(b,a)]+=0
        

    ans=1
    
    for k,v in dd.items():
        a,b=k
        if b<=0:
            continue
        #+,+だけ見る
        
        if a*b!=0:
            v=dd[k]
            v2=dd[(b,-a)]
        else:
            v=dd[k]
            v2=dd[(b,a)]
        temp=pow(2,v,mod)+pow(2,v2,mod)-1
        
        ans=(ans*temp)%mod

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

main()

Submission status: Wrong Answer

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

def main():
  p = 1000000007
  N = int(readline().strip())
  A = {}
  ans = 0
  for i in range(N):
    s = ''
    ai, bi = map(int, readline().split())
    if ai == 0 and bi == 0:
      ans += 1
      ans %= p
      continue
    gi = math.gcd(ai, bi)
    ai = int(ai / gi)
    bi = int(bi / gi)
    if ai != 0 and bi != 0:
      if ai < 0 and bi < 0:
        ai = -ai
        bi = -bi
      elif ai < 0:
        ai = -ai
        s = '-'
      elif bi < 0:
        bi = -bi
        s = '-'
    elif ai == 0 and bi != 0:
      ai = 0
      bi = 1
    elif bi == 0 and ai != 0:
      ai = 1
      bi = 0
      s = '-'
    xi = s + str(ai) + '/' + str(bi)
    if s == '':
      s = '-'
    else:
      s = ''
    yi = s + str(bi) + '/' + str(ai)
    if xi in A:
      A[xi][0] += 1
      A[xi][0] %= p
    elif yi in A:
      A[yi][1] += 1
      A[yi][1] %= p
    else:
      A[xi] = [1, 0]
  r = 1
  for i in A:
    r = r * (pow(2, A[i][0], p) + pow(2, A[i][1], p) -1) % p
  r -= 1
  r %= p
  ans += r
  ans %= p
  print(ans)

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

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

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

def main():
    mod=10**9
    N=I()
    from math import gcd
    from collections import defaultdict
    dd = defaultdict(int)
    temp0=0

    for i in range(N):
        a,b=MI()
        if (a,b)==(0,0):
            temp0+=1
            continue
        
        if a<0:
            a*=-1
            b*=-1
        
        #(+,+)と(+,-)だけにする
        if a*b!=0:
            g=gcd(abs(a),abs(b))
            a=a//g
            b=b//g
            if a*b>0:#(+,+)
                dd[(a,b)]+=1
                dd[b,-a]+=0
                
            else:#(+,-)
                dd[(a,b)]+=1
                dd[(-b,a)]+=0
            
        elif (a,b)!=(0,0):
            #assert 0
            if a==0:
                b=1
            else:
                a=1
                
            dd[(a,b)]+=1
            dd[(b,a)]+=0
        

    ans=1
    
    for k,v in dd.items():
        a,b=k
        if b<=0:
            continue
        #+,+だけ見る
        
        if a*b!=0:
            v=dd[k]
            v2=dd[(b,-a)]
        else:
            v=dd[k]
            v2=dd[(b,a)]
        temp=pow(2,v,mod)+pow(2,v2,mod)-1
        
        ans=(ans*temp)%mod

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

main()

Submission status: Wrong Answer

Solution code:
import math, collections
N = int(input())
AB = [[int(_) for _ in input().split()] for _ in range(N)]
mod = 10**9 + 7
C = collections.Counter()
gcd = math.gcd
for a, b in AB:
    if a == b == 0:
        continue
    elif a == 0:
        C[0, -1] += 1
    else:
        g = gcd(a, b)
        a //= g
        b //= g
        if a < 0:
            a *= -1
            b *= -1
        C[a, b] += 1
ans = 1
for a, b in C:
    if C[b, -a]:
        continue
    elif C[-b, a]:
        ans *= (pow(2, C[a, b], mod) + pow(2, C[-b, a], mod) - 1) % mod
        ans %= mod
    else:
        ans *= pow(2, C[a, b], mod)
        ans %= mod
ans -= 1
ans %= mod
print(ans)

Submission status: Wrong Answer

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

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

def main():
    mod=10**9
    N=I()
    from math import gcd
    from collections import defaultdict
    dd = defaultdict(int)

    for i in range(N):
        a,b=MI()
        if a*b!=0:
            g=gcd(abs(a),abs(b))
            a=a//g
            b=b//g
        elif (a,b)!=(0,0):
            #assert 0
            if a==0:
                b=1
            else:
                a=1
                
        if a<0:
            a*=-1
            b*=-1
            
        dd[(a,b)]+=1
        
    ans=1
    L=[]
    for k in dd.keys():
        L.append((k))

    temp0=0
    for i in range(len(L)):
        k=L[i]
        v=dd[k]
        if v==0:
            continue
        a,b=k
        dd[k]=0
        temp=pow(2,v,mod)
        if a*b!=0:
            if (-b,a) in dd:
                v2=dd[(-b,a)]
                temp+=pow(2,v2,mod)-1
                dd[(-b,a)]=0
            if (b,-a) in dd:
                v2=dd[(b,-a)]
                temp+=pow(2,v2,mod)-1
                dd[(b,-a)]=0
                    
        elif (a,b)==(1,0) or (a,b)==(0,1):
            if (b,a) in dd:
                v2=dd[(b,a)]
                if v2!=0:
                    temp+=pow(2,v2,mod)-1
                    dd[(b,a)]=0
        else:
            temp0=v
            temp=1
            
        #print(k,v,temp)
        ans=(ans*temp)%mod
        
        


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

main()

Submission status: Wrong Answer

Solution code:
import math, collections
N = int(input())
AB = [[int(_) for _ in input().split()] for _ in range(N)]
mod = 10**9 + 7
C = collections.Counter()
gcd = math.gcd
for a, b in AB:
    if a == b == 0:
        continue
    elif a == 0:
        C[0, -1] += 1
    else:
        g = gcd(a, b)
        a //= g
        b //= g
        if a < 0:
            a *= -1
            b *= -1
        C[a, b] += 1
ans = 1
for a, b in C:
    c = None
    if C[b, -a]:
        continue
    elif C[-b, a]:
        ans *= pow(2, C[a, b], mod) + pow(2, C[-b, a], mod) - 1
        ans %= mod
    else:
        ans *= pow(2, C[a, b], mod)
        ans %= mod
ans -= 1
ans %= mod
print(ans)

Submission status: Wrong Answer

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

def main():
  p = 1000000007
  N = int(readline().strip())
  A = {}
  ans = 0
  for i in range(N):
    s = ''
    ai, bi = map(int, readline().split())
    if ai == 0 and bi == 0:
      ans += 1
      ans %= p
      continue
    gi = math.gcd(ai, bi)
    ai = int(ai / gi)
    bi = int(bi / gi)
    if ai != 0 and bi != 0:
      if ai < 0 and bi < 0:
        ai = -ai
        bi = -bi
      elif ai < 0:
        ai = -ai
        s = '-'
      elif bi < 0:
        bi = -bi
        s = '-'
    elif ai == 0 and bi != 0:
      ai = 0
      bi = 1
    elif bi == 0 and ai != 0:
      ai = 1
      bi = 0
      s = '-'
    xi = s + str(ai) + '/' + str(bi)
    if s == '':
      s = '-'
    else:
      s = ''
    yi = s + str(bi) + '/' + str(ai)
    if xi in A:
      A[xi][0] += 1
    elif yi in A:
      A[yi][1] += 1
    else:
      A[xi] = [1, 0]
  r = 1
  for i in A:
    r = r * (pow(2, A[i][0], p) + pow(2, A[i][1], p) -1) % p
  r -= 1
  r %= p
  ans += r
  ans %= p
  print(ans)

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

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

def main():
  p = 1000000007
  N = int(readline().strip())
  A = {}
  ans = 0
  for i in range(N):
    s = ''
    ai, bi = map(int, readline().split())
    if ai == 0 and bi == 0:
      ans += 1
      continue
    gi = math.gcd(ai, bi)
    ai = int(ai / gi)
    bi = int(bi / gi)
    if ai != 0 and bi != 0:
      if ai < 0 and bi < 0:
        ai = -ai
        bi = -bi
      elif ai < 0:
        ai = -ai
        s = '-'
      elif bi < 0:
        bi = -bi
        s = '-'
    elif ai == 0 and bi != 0:
      ai = 0
      bi = 1
    elif bi == 0 and ai != 0:
      ai = 1
      bi = 0
      s = '-'
    xi = s + str(ai) + '/' + str(bi)
    if s == '':
      s = '-'
    else:
      s = ''
    yi = s + str(bi) + '/' + str(ai)
    if xi in A:
      A[xi][0] += 1
    elif yi in A:
      A[yi][1] += 1
    else:
      A[xi] = [1, 0]
  r = 1
  for i in A:
    r = r * (pow(2, A[i][0], p) + pow(2, A[i][1], p) -1) % p
  r -= 1
  ans += r
  ans %= p
  print(ans)

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
import math, collections
N = int(input())
AB = [[int(_) for _ in input().split()] for _ in range(N)]
mod = 10**9 + 7
Cp = collections.Counter()
Cm = collections.Counter()
gcd = math.gcd
for a, b in AB:
    if a == b == 0:
        continue
    elif a == 0:
        Cm[0, -1] += 1
    else:
        g = gcd(a, b)
        a //= g
        b //= g
        if a < 0:
            a *= -1
            b *= -1
        if b < 0:
            Cm[a, b] += 1
        else:
            Cp[a, b] += 1
ans = 1
for a, b in Cp:
    if Cm[b, -a]:
        ans *= pow(2, Cp[a, b], mod) + pow(2, Cm[b, -a], mod) - 1
        ans %= mod
    else:
        ans *= pow(2, Cp[a, b], mod)
        ans %= mod
for a, b in Cm:
    if Cp[-b, a]:
        continue
    else:
        ans *= pow(2, Cm[a, b], mod)
        ans %= mod
ans -= 1
ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
import math, collections
N = int(input())
AB = [[int(_) for _ in input().split()] for _ in range(N)]
mod = 10**9 + 7
Cp = collections.Counter()
Cm = collections.Counter()
gcd = lambda x, y: gcd(y, x % y) if x % y else y
for a, b in AB:
    if a == b == 0:
        continue
    elif b == 0:
        Cp[1, 0] += 1
    elif a == 0:
        Cm[0, -1] += 1
    else:
        g = gcd(a, b)
        a //= g
        b //= g
        if a < 0:
            a *= -1
            b *= -1
        if b > 0:
            Cp[a, b] += 1
        else:
            Cm[a, b] += 1
ans = 1
for a, b in Cp:
    if Cm[b, -a] > 0:
        ans *= pow(2, Cp[a, b], mod) + pow(2, Cm[b, -a], mod) - 1
        ans %= mod
    else:
        ans *= pow(2, Cp[a, b], mod)
        ans %= mod
for a, b in Cm:
    if Cm[a, b] == 0 or Cp[-b, a] > 0:
        continue
    else:
        ans *= pow(2, Cm[a, b], mod)
        ans %= mod
ans -= 1
print(ans % mod)

Submission status: Wrong Answer

Solution code:
import math
from collections import defaultdict
n = int(input())
p = defaultdict(int)
mod = 10 ** 9 + 7
ori = 0
for _ in range(n):
    a,b = map(int,input().split())
    if a == b == 0:
        ori += 1
        continue
    elif b < 0:
        a *= -1
        b *= -1
    elif b == 0 and a < 0:
        a *= -1
    if a == 0:
        p[(0,1)] += 1
    elif b == 0:
        p[(1,0)] += 1
    else:
        g = math.gcd(a,b)
        p[(a//g, b//g)] += 1

k = n - ori
ans = ori-1
tmp = 1
l = k
for q,num in sorted(p.items(), reverse=True):
    x,y = q
    if x <= 0:
        break
    if p[(-y, x)] >= 1:
        a,b = p[(x,y)], p[(-y, x)]
        tmp *= pow(2,a,mod) + pow(2,b,mod) - 1
        l -= a+b
tmp *= pow(2,l,mod)
print(ans+tmp)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 10**9 + 7
P = 2 ** 127 - 1

N = int(readline())
m = map(int, read().split())
A, B = zip(*zip(m, m))

pow2 = [1] * (N + 10)
for n in range(1, N + 10):
    pow2[n] = pow2[n - 1] * 2 % MOD

def mod_P(x):
    if x < 0:
        x += P
    high = x >> 127
    low = x & P
    x = low + high
    if x >= P:
        x -= P
    return x

def inv_mod(a):
    b = P
    u, v = 1, 0
    while a:
        q, r = divmod(b, a)
        a, b = r, a
        u, v = v - q * u, u
    if b < 0:
        v = -v
    if v < 0:
        v += P
    return v

pair_key = {0:-1, -1:0}

def to_key(a, b):
    if a == 0:
        return -1
    if b == 0:
        return 0
    x = mod_P(inv_mod(a) * b)
    y = P - mod_P(inv_mod(b) * a)
    pair_key[x] = y
    return x

  
counter = defaultdict(int)
origin = 0
for a, b in zip(A, B):
    if a == b == 0:
        origin += 1
        continue
    key = to_key(a, b)
    counter[key] += 1

answer = origin
k = 1
for key, cnt in counter.items():
    key1 = pair_key[key]
    if key1 not in counter:
        k *= pow2[cnt]
    elif key < key1:
        x, y = cnt, counter[key1]
        k *= pow2[x] + pow2[y] - 1
    k %= MOD
answer += k - 1
answer %= MOD
print(answer)

Submission status: Wrong Answer

Solution code:
import math, collections
N = int(input())
AB = [[int(_) for _ in input().split()] for _ in range(N)]
mod = 10**9 + 7
Cp = collections.Counter()
Cm = collections.Counter()
gcd = math.gcd
for a, b in AB:
    if a == b == 0:
        continue
    elif b == 0:
        Cp[1, 0] += 1
    elif a == 0:
        Cm[0, -1] += 1
    else:
        g = gcd(a, b)
        a //= g
        b //= g
        if a < 0:
            a *= -1
            b *= -1
        if b > 0:
            Cp[a, b] += 1
        else:
            Cm[a, b] += 1
ans = 1
for a, b in Cp:
    if Cm[b, -a] > 0:
        ans *= pow(2, Cp[a, b], mod) + pow(2, Cm[b, -a], mod) - 1
        ans %= mod
    else:
        ans *= pow(2, Cp[a, b], mod)
        ans %= mod
for a, b in Cm:
    if Cm[a, b] == 0 or Cp[-b, a] > 0:
        continue
    else:
        ans *= pow(2, Cm[a, b], mod)
        ans %= mod
ans -= 1
print(ans % mod)

Submission status: Wrong Answer

Solution code:
import math, collections
N = int(input())
AB = [[int(_) for _ in input().split()] for _ in range(N)]
mod = 10**9 + 7
Cp = collections.Counter()
Cm = collections.Counter()
gcd = math.gcd
for a, b in AB:
    if a == b == 0:
        continue
    elif b == 0:
        Cp[1, 0] += 1
    elif a == 0:
        Cm[0, -1] += 1
    else:
        g = gcd(a, b)
        if g > 1:
            a //= g
            b //= g
        if a < 0:
            a *= -1
            b *= -1
        if b > 0:
            Cp[a, b] += 1
        else:
            Cm[a, b] += 1
ans = 1
for a, b in Cp:
    if Cm[b, -a] > 0:
        ans *= pow(2, Cp[a, b], mod) + pow(2, Cm[b, -a], mod) - 1
        ans %= mod
    else:
        ans *= pow(2, Cp[a, b], mod)
        ans %= mod
for a, b in Cm:
    if Cm[a, b] == 0 or Cp[-b, a] > 0:
        continue
    else:
        ans *= pow(2, Cm[a, b], mod)
        ans %= mod
ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 10**9 + 7
P = 2 ** 127 - 1

N = int(readline())
m = map(int, read().split())
A, B = zip(*zip(m, m))

pow2 = [1] * (N + 10)
for n in range(1, N + 10):
    pow2[n] = pow2[n - 1] * 2 % MOD

def inv_mod(a):
    b = P
    u, v = 1, 0
    while a:
        q, r = divmod(b, a)
        a, b = r, a
        u, v = v - q * u, u
    if b < 0:
        v = -v
    if v < 0:
        v += P
    return v

def to_key(a, b):
    if a == 0:
        return -1
    x = inv_mod(a) * b % P
    return x

def pair_key(key):
    if key == -1:
        return 0
    if key == 0:
        return -1
    return P - inv_mod(key)
  
counter = defaultdict(int)
origin = 0
for a, b in zip(A, B):
    if a == b == 0:
        origin += 1
        continue
    key = to_key(a, b)
    counter[key] += 1

Submission status: Wrong Answer

Solution code:
import math, collections
N = int(input())
AB = [[int(_) for _ in input().split()] for _ in range(N)]
mod = 10**9 + 7
Cp = collections.Counter()
Cm = collections.Counter()
gcd = math.gcd
for a, b in AB:
    if a == b == 0:
        continue
    elif a == 0:
        Cp[0, 1] += 1
    elif b == 0:
        Cm[1, 0] += 1
    else:
        g = gcd(a, b)
        if g > 1:
            a //= g
            b //= g
        if a < 0:
            a *= -1
            b *= -1
        if b > 0:
            Cp[a, b] += 1
        else:
            Cm[a, b] += 1
ans = 1
for a, b in Cp:
    if Cm[b, -a] > 0:
        ans *= pow(2, Cp[a, b], mod) + pow(2, Cm[b, -a], mod) - 1
        ans %= mod
    else:
        ans *= pow(2, Cp[a, b], mod)
        ans %= mod
for a, b in Cm:
    if Cm[a, b] == 0 or Cp[-b, a] > 0:
        continue
    else:
        ans *= pow(2, Cm[a, b], mod)
        ans %= mod
ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 10**9 + 7
P = 2 ** 127 - 1

N = int(readline())
m = map(int, read().split())
A, B = zip(*zip(m, m))

pow2 = [1] * (N + 10)
for n in range(1, N + 10):
    pow2[n] = pow2[n - 1] * 2 % MOD

def inv_mod(a):
    b = P
    u, v = 1, 0
    while a:
        q, r = divmod(b, a)
        a, b = r, a
        u, v = v - q * u, u
    if b < 0:
        v = -v
    if v < 0:
        v += P
    return v

def to_key(a, b):
    if a == 0:
        return -1
    x = inv_mod(a) * b % P
    return x

def pair_key(key):
    if key == -1:
        return 0
    if key == 0:
        return -1
    return P - inv_mod(key)
  
counter = defaultdict(int)
origin = 0
for a, b in zip(A, B):
    if a == b == 0:
        origin += 1
        continue
    key = to_key(a, b)
    counter[key] += 1

answer = origin
k = 1
for key, cnt in counter.items():
    key1 = pair_key(key)

Submission status: Wrong Answer

Solution code:
import math, collections
N = int(input())
AB = [[int(_) for _ in input().split()] for _ in range(N)]
mod = 10**9 + 7
Cp = collections.Counter()
Cm = collections.Counter()
gcd = math.gcd
for a, b in AB:
    if a == b == 0:
        continue
    elif a == 0:
        Cp[0, 1] += 1
    elif b == 0:
        Cm[-1, 0] += 1
    else:
        g = gcd(a, b)
        if g > 1:
            a //= g
            b //= g
        if a < 0:
            a *= -1
            b *= -1
        if b > 0:
            Cp[a, b] += 1
        else:
            Cm[a, b] += 1
ans = 1
for a, b in Cp:
    if Cm[b, -a] > 0:
        ans *= pow(2, Cp[a, b], mod) + pow(2, Cm[b, -a], mod) - 1
        ans %= mod
    else:
        ans *= pow(2, Cp[a, b], mod)
        ans %= mod
for a, b in Cm:
    if Cm[a, b] == 0 or Cp[-b, a] > 0:
        continue
    else:
        ans *= pow(2, Cm[a, b], mod)
        ans %= mod
ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
import math, collections
N = int(input())
AB = [[int(_) for _ in input().split()] for _ in range(N)]
mod = 10**9 + 7
Cp = collections.Counter()
Cm = collections.Counter()
gcd = math.gcd
for a, b in AB:
    if a == b == 0:
        continue
    elif a == 0:
        Cp[0, 1] += 1
    elif b == 0:
        Cp[1, 0] += 1
    else:
        g = gcd(a, b)
        if g > 1:
            a //= g
            b //= g
        if a < 0:
            a *= -1
            b *= -1
        if b > 0:
            Cp[a, b] += 1
        else:
            Cm[a, b] += 1
ans = 1
for a, b in Cp:
    if Cm[b, -a] > 0:
        ans *= pow(2, Cp[a, b], mod) + pow(2, Cm[b, -a], mod) - 1
        ans %= mod
    else:
        ans *= pow(2, Cp[a, b], mod)
        ans %= mod
for a, b in Cm:
    if Cm[a, b] == 0 or Cp[-b, a] > 0:
        continue
    else:
        ans *= pow(2, Cm[a, b], mod)
        ans %= mod
ans -= 1
print(ans)

Submission status: Wrong Answer

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

MOD = 1000000007

dic1 = defaultdict(int)

All_zero = 0

S = set()
N = int(input())
ans = 0 #仲が悪い数を数える
for i in range(N):
    a, b = map(int, input().split())
    if a == 0 and b == 0: #なんでもOK
        All_zero += 1
    elif a == 0:
        S.add((0, 1))
        dic1[(0, 1)] += 1
    elif b == 0:
        S.add((1, 0))
        dic1[(1, 0)] += 1
    else:
        GCD = gcd(a, b)
        a //= GCD
        b //= GCD
        if a < 0: #aを必ず正にする
            a *= -1
            b *= -1
        S.add((a, b))
        dic1[(a, b)] += 1
        
lst = []
for a, b in S:
    tmp11 = dic1[(a, b)]
    A = a
    B = b
    if B < 0:
        B *= -1
        A *= -1
    tmp2 = dic1[(B, -A)]
    dic1[(B, -A)] = 0
    if tmp11 > 0:
        lst.append((tmp11, tmp2))

# print (lst)

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

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

Submission status: Wrong Answer

Solution code:
import math, collections
N = int(input())
AB = [[int(_) for _ in input().split()] for _ in range(N)]
mod = 10**9 + 7
Cp = collections.Counter()
Cm = collections.Counter()
gcd = math.gcd
for a, b in AB:
    g = gcd(a, b)
    if g == 0:
        continue
    elif g > 1:
        a //= g
        b //= g
    if a < 0:
        a *= -1
        b *= -1
    if (a, b) == (0, -1):
        b = 1
    if b > 0:
        Cp[a, b] += 1
    else:
        Cm[a, b] += 1
ans = 1
for a, b in Cp:
    if (b, -a) in Cm:
        ans *= pow(2, Cp[a, b], mod) + pow(2, Cm[b, -a], mod) - 1
        ans %= mod
    else:
        ans *= pow(2, Cp[a, b], mod)
        ans %= mod
for a, b in Cm:
    if (-b, a) in Cp:
        continue
    else:
        ans *= pow(2, Cm[a, b], mod)
        ans %= mod
ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
import math

mod = 1000000007
n = int(input())
zero = 0
dic = {}
dic[(0, 1.5)] = 0
dic[(1.5, 0)] = 0
for i in range(n):
    ai, bi = map(int, input().split())
    idx = (ai, bi)
    if ai < 0:
        ai, bi = -ai, -bi
    if idx == (0, 0):
        zero += 1
    elif idx[0] == 0:
        dic[(0, 1.5)] += 1
    elif idx[1] == 0:
        dic[(1.5, 0)] += 1
    else:
        g = math.gcd(abs(ai), abs(bi))
        ai = ai // g
        bi = bi // g
        idx = (ai, bi)
        if idx in dic:
            dic[idx] += 1
        else:
            dic[idx] = 1

ans = 1
already = set([])
for key, value in dic.items():
    if key in already: continue
    a, b = key
    if a == 1.5 or b == 1.5:
        pair1 = dic[(0, 1.5)]
        pair2 = dic[(1.5, 0)]
        ans = (ans * (pow(2, pair1, mod)+pow(2, pair2, mod)-1)) % mod
        already.add((0, 1.5))
        already.add((1.5, 0))
    else:
        if b > 0: idx = (b, -a)
        else: idx = (-b, a)
        if idx in dic:
            pair1 = dic[key]
            pair2 = dic[idx]
            ans = (ans * (pow(2, pair1, mod)+pow(2, pair2, mod)-1)) % mod
            already.add(key)
            already.add(idx)
        else:
            pair1 = dic[key]
            ans = (ans * pow(2, pair1, mod)) % mod
            already.add(key)

ans = ans + zero - 1
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys,pprint, math
from fractions import Fraction
from collections import defaultdict

MOD = 1000000007
N = int(input())
params =[]
hatemasks = []
tilts = defaultdict(lambda: [0,0])
zerozero = 0
zerodiv = 0
for i in range(N):
    (ai, bi) = map(int,input().split())
    if ai == 0 and bi == 0:
        zerozero += 1
        continue
    elif (ai <= 0) or (ai == 0 and bi < 0):
        ai *= -1
        bi *= -1
    g = math.gcd(ai,bi)
    ai = ai // g
    bi = bi // g
    if bi > 0:
        tilts[(ai,bi)][0] += 1
    else:
        tilts[(-bi,ai)][1] += 1
print(tilts,file=sys.stderr)

#sys.exit()
ans = 1
for(v1,v2) in tilts.values():
    ans *= 1 +pow(2,v1,MOD)-1 +pow(2,v2,MOD)-1
    ans %= MOD
ans = (ans+zerozero-1) % MOD
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys,pprint, math
from fractions import Fraction
from collections import defaultdict

MOD = 1000000007
N = int(input())
params =[]
hatemasks = []
tilts = defaultdict(lambda: [0,0])
zerozero = 0
zerodiv = 0
for i in range(N):
    (ai, bi) = map(int,input().split())
    if ai == 0 and bi == 0:
        zerozero += 1
        continue
    elif ai <= 0:
        ai *= -1
        bi *= -1
    g = math.gcd(ai,bi)
    ai = ai // g
    bi = bi // g
    if bi > 0:
        tilts[(ai,bi)][0] += 1
    else:
        tilts[(-bi,ai)][1] += 1
print(tilts,file=sys.stderr)

#sys.exit()
ans = 1
for(v1,v2) in tilts.values():
    ans *= 1 +pow(2,v1,MOD)-1 +pow(2,v2,MOD)-1
    ans %= MOD
ans = (ans+zerozero-1) % MOD
print(ans)

Submission status: Wrong Answer

Solution code:
# 解説AC
from math import gcd
from collections import defaultdict
import sys

input = sys.stdin.buffer.readline

mod = 10 ** 9 + 7
n = int(input())
cnt = 0
cnt += n
zerocnt = 0
kumi = defaultdict(int)
for i in range(n):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        zerocnt += 1
        continue
    elif b == 0:
        kumi[(1, 0)] += 1
        kumi[(0, -1)] += 0
        continue
    elif a == 0:
        kumi[(0, -1)] += 1
        kumi[(1, 0)] += 0
        continue
    g = gcd(a, b)
    a //= g
    b //= g
    if a < 0:
        a *= -1
        b *= -1
    kumi[(a, b)] += 1
    kumi[(b, -a)] += 0
ans = 1
cnt -= zerocnt
for a, b in kumi.keys():
    if b <= 0:
        continue
    s = kumi[(a, b)]
    t = kumi[(b, -a)]
    ans *= pow(2, (s + t), mod) - (pow(2, s, mod) - 1) * (pow(2, t, mod) - 1)
    ans %= mod
    cnt -= s + t
if cnt > 0:
    ans *= pow(2, cnt, mod)
    ans %= mod
print((ans - 1 + zerocnt) % mod)

Submission status: Wrong Answer

Solution code:
# 解説AC
from math import gcd
from collections import defaultdict
import sys

input = sys.stdin.buffer.readline

mod = 10 ** 9 + 7
n = int(input())
cnt = 0
cnt += n
zerocnt = 0
kumi = defaultdict(int)
for i in range(n):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        zerocnt += 1
        continue
    elif b == 0:
        kumi[(1, 0)] += 1
        kumi[(0, -1)] += 0
        continue
    elif a == 0:
        kumi[(0, -1)] += 1
        kumi[(1, 0)] += 0
        continue
    g = gcd(a, b)
    a //= g
    b //= g
    if a < 0:
        a *= -1
        b *= -1
    kumi[(a, b)] += 1
    kumi[(b, -a)] += 0
ans = 1
cnt -= zerocnt
for a, b in kumi.keys():
    if b <= 0:
        continue
    s = kumi[(a, b)]
    t = kumi[(b, -a)]
    ans *= pow(2, (s + t), mod) - (pow(2, s, mod) - 1) * (pow(2, t, mod) - 1)
    ans %= mod
    cnt -= s + t
if cnt > 0:
    ans *= pow(2, cnt, mod)
    ans %= mod
print((ans - 1 + pow(2,zerocnt,mod)-1) % mod)

Submission status: Wrong Answer

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

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

def main():
    mod=10**9
    N=I()
    from math import gcd
    from collections import defaultdict
    dd = defaultdict(int)

    for i in range(N):
        a,b=MI()
        if a*b!=0:
            g=gcd(abs(a),abs(b))
            a=a//g
            b=b//g
        elif (a,b)!=(0,0):
            #assert 0
            if a==0:
                b=1
            else:
                a=1
                
        if a<0:
            a*=-1
            b*=-1
            
        dd[(a,b)]+=1
        
    ans=1
    L=[]
    for k in dd.keys():
        L.append((k))

    temp0=0
    for i in range(len(L)):
        k=L[i]
        v=dd[k]
        a,b=k
        dd[k]=0
        temp=pow(2,v,mod)
        if a*b!=0:
            if (-b,a) in dd:
                v2=dd[(-b,a)]
                temp+=pow(2,v2,mod)-1
                dd[(-b,a)]=0
            if (b,-a) in dd:
                v2=dd[(b,-a)]
                temp+=pow(2,v2,mod)-1
                dd[(b,-a)]=0
                    
        elif (a,b)==(1,0) or (a,b)==(0,1):
            if (b,a) in dd:
                v2=dd[(b,a)]
                if v2!=0:
                    temp+=pow(2,v2,mod)-1
                    dd[(b,a)]=0
        else:
            temp0=v
            temp=1
            
        #print(k,v,temp)
        ans=(ans*temp)%mod
        
        


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

main()