module Main where

import Control.Applicative
import Control.Monad
import Control.Monad.State
import Data.List
import qualified Data.ByteString.Lazy.Char8 as L

type Tokenizer = State [L.ByteString]

expand0 :: [Int] -> [Int]
expand0 [] = [1]
expand0 [1] = [-1, 1]
expand0 (x:xs) = (-x:2 * x:xs)

gen0, gen1 :: Int -> [Int]
gen0 n = (iterate expand0 []) !! n

gen1 1 = [1]
gen1 n = map negate $ gen0 n

solve_01 :: [Int] -> (Int -> [Int]) -> Int
solve_01 vs gen = sum $ zipWith (*) vs' cs'
    where vs' = sort vs
          cs' = sort . gen $ length vs

solve :: [Int] -> Int
solve vs = max (solve_01 vs gen0) (solve_01 vs gen1)

nextInt :: Tokenizer Int
nextInt = state $ \(s:ss) -> case L.readInt s of
                               Just (x, _) -> (x, ss)
                               Nothing -> error $ "Can't parse Int from " ++ L.unpack s

go :: Tokenizer Int
go = do
  n <- nextInt
  vs <- replicateM n nextInt
  return $ solve vs
  

main :: IO ()
main = do
  input <- L.words <$> L.getContents
  let answer = evalState go input
  print answer
