{-# LANGUAGE TypeApplications #-}
module Main where
import qualified Data.ByteString.Char8         as BS
import qualified Data.ByteString.Lazy.Char8    as BSL
import qualified Data.ByteString.Builder       as BSB
import           Data.Char                      ( isSpace )
import           Data.List
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM
import qualified Data.Vector.Generic           as VG
import qualified Data.Vector.Generic.Mutable   as VGM
import           Data.Ratio

import           Data.Map.Strict            ( Map )
import qualified Data.Map.Strict           as Map

main :: IO ()
main = do
  n <- readLn @ Int
  abs <- V.replicateM n $ (\[x, y] -> (x, y)) . unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  let abs' = V.map f abs
  let h = Map.fromListWith (+) [ (x, 1) | x <- V.toList abs' ]
  print $ go h 1 - 1
 where
  go h ans
    | Map.null h = ans
    | otherwise = 
      let 
        ((r, c), h') = Map.deleteFindMin h
        r' = (-1) / r :: Ratio Int
      in case h' Map.!? r' of
        Nothing -> go h' (2^c * ans)
        Just c' -> go (Map.delete r' h') ((2^c-1 + 2^c'-1 + 1) * ans)

f :: (Int, Int) -> Ratio Int
f (a, b) = a % b
