import           Control.Monad
import           Control.Monad.ST
import           Data.Array
import           Data.Array.ST.Safe
import           Data.List
import           Data.Ord
import           Data.STRef
import           Numeric

(|>) = flip (.)

int :: (Eq a, Num a) => String -> a
int x = fst $ readDec x !! 0

ints :: (Eq a, Num a) => String -> [a]
ints = map int . words

main = interact $
  lines
  |> solverLoop
  |> unlines

data Node = Node {
  parent  :: Int,
  inMST   :: Bool,
  nodeNum :: Int,
  cost    :: Integer
} deriving (Show)

solverLoop :: [String] -> [String]
solverLoop (ts:xs) = [
    showInt totalCost "",
    showInt (length buildPlants) "",
    unwords $ map ((\i -> showInt i "") . nodeNum) buildPlants,
    showInt (length buildWires) ""
  ] ++ map (\(Node p _ v _) -> showInt p (" " ++ showInt v "")) buildWires
    where
      t = int ts
      coords = array (1, t) [(i, (x, y)) | (i, (x:y:_)) <- zip [1..t] (map ints xs) ]
      (cs:ks:_) = drop t xs
      wires = array (1, t) $ zip [1..t] (ints ks)
      costf v w = (wires ! v + wires ! w) * dist (coords ! v) (coords ! w)
      nodes = mst t (map (uncurry $ Node 0 False) $ zip [1..t] (ints cs)) costf
      totalCost = sum $ map cost nodes
      (buildPlants, buildWires) = partition ((== 0) . parent) nodes

mst t initial costf = runST $ do
  nodes <- newListArray (1, t) initial :: ST s (STArray s Int Node)
  replicateM_ t $ do
    elems <- getElems nodes
    let node@(Node u _ v w) = minimumBy (comparing cost) $ filter (not . inMST) elems
    writeArray nodes v node {inMST = True}
    forM_ [1..t] $ \vn -> do
      let w = costf v vn
      node@(Node p inMst vn w2) <- readArray nodes vn
      when (not inMst && w < w2) $
        writeArray nodes vn node {parent = v, cost = w}
  getElems nodes

dist (x1,y1) (x2,y2) = abs (x1 - x2) + abs (y1 - y2)

import           Control.Monad
import           Control.Monad.ST
import           Data.Array
import           Data.Array.ST.Safe
import           Data.List
import           Data.Ord
import           Data.STRef
import           Numeric

(|>) = flip (.)

int :: (Eq a, Num a) => String -> a
int x = fst $ readDec x !! 0

ints :: (Eq a, Num a) => String -> [a]
ints = map int . words

main = interact $
  lines
  |> solverLoop
  |> unlines

data Node = Node {
  parent  :: Int,
  inMST   :: Bool,
  nodeNum :: Int,
  cost    :: Integer
} deriving (Show)

solverLoop :: [String] -> [String]
solverLoop (ts:xs) = map (unwords) $ [
    [show totalCost],
    [show $ length buildPlants],
    map (show . nodeNum) buildPlants,
    [show $ length buildWires]
  ] ++ map (\(Node p _ v _) -> [show p, show v]) buildWires
    where
      t = int ts
      coords = array (1, t) [(i, (x, y)) | (i, (x:y:_)) <- zip [1..t] (map ints xs) ]
      (cs:ks:_) = drop t xs
      wires = array (1, t) $ zip [1..t] (ints ks)
      costf v w = (wires ! v + wires ! w) * dist (coords ! v) (coords ! w)
      nodes = mst t (map (uncurry $ Node 0 False) $ zip [1..t] (ints cs)) costf
      totalCost = sum $ map cost nodes
      (buildPlants, buildWires) = partition ((== 0) . parent) nodes

mst t initial costf = runST $ do
  nodes <- newListArray (1, t) initial :: ST s (STArray s Int Node)
  replicateM_ t $ do
    elems <- getElems nodes
    let node@(Node u _ v w) = minimumBy (comparing cost) $ filter (not . inMST) elems
    writeArray nodes v node {inMST = True}
    forM_ [1..t] $ \vn -> do
      let w = costf v vn
      node@(Node p inMst vn w2) <- readArray nodes vn
      when (not inMst && w < w2) $
        writeArray nodes vn node {parent = v, cost = w}
  getElems nodes

dist (x1,y1) (x2,y2) = abs (x1 - x2) + abs (y1 - y2)

import           Control.Monad
import           Control.Monad.ST
import           Data.Array
import           Data.Array.ST.Safe
import           Data.List
import           Data.Ord
import           Data.STRef
import           Numeric

(|>) = flip (.)

int :: (Eq a, Num a) => String -> a
int x = fst $ readDec x !! 0

ints :: (Eq a, Num a) => String -> [a]
ints = map int . words

main = interact $
  lines
  |> solverLoop
  |> unlines

data Node = Node {
  parent  :: Int,
  inMST   :: Bool,
  nodeNum :: Int,
  cost    :: Integer
} deriving (Show)

solverLoop :: [String] -> [String]
solverLoop (ts:xs) = map (unwords) $ [
    [show totalCost],
    [show $ length buildPlants],
    map (show . nodeNum) buildPlants,
    [show $ length buildWires]
  ] ++ map (\(Node p _ v _) -> [show p, show v]) buildWires
    where
      t = int ts
      coords = array (1, t) [(i, (x, y)) | (i, (x:y:_)) <- zip [1..t] (map ints xs) ]
      (cs:ks:_) = drop t xs
      wires = array (1, t) $ zip [1..t] (ints ks)
      costf v w = (wires ! v + wires ! w) * dist (coords ! v) (coords ! w)
      nodes = mst t (map (uncurry $ Node 0 False) $ zip [1..t] (ints cs)) costf
      totalCost = sum $ map cost nodes
      (buildPlants, buildWires) = partition ((== 0) . parent) nodes

mst t initial costf = runST $ do
  nodes <- newListArray (1, t) initial :: ST s (STArray s Int Node)
  forM_ [1..t] $ \_ -> do
    elems <- getElems nodes
    let node@(Node u _ v w) = minimumBy (comparing cost) $ filter (not . inMST) elems
    writeArray nodes v node {inMST = True}
    forM_ [1..t] $ \vn -> do
      let w = costf v vn
      node@(Node p inMst vn w2) <- readArray nodes vn
      when (not inMst && w < w2) $
        writeArray nodes vn node {parent = v, cost = w}
  getElems nodes

dist (x1,y1) (x2,y2) = abs (x1 - x2) + abs (y1 - y2)

import Control.Monad
import           Control.Monad.ST
import           Data.Array
import Data.Array.ST.Safe
import           Data.List
import           Numeric
import Data.Tuple
import Data.STRef

(|>) = flip (.)

int :: (Eq a, Num a) => String -> a
int x = fst $ readDec x !! 0

ints :: (Eq a, Num a) => String -> [a]
ints = map int . words

count x = length . filter (== x)

main = interact $
  lines
  |> solverLoop
  |> unlines

solverLoop :: [String] -> [String]
solverLoop (ts:xs) = map (unwords) $ [
    [show totalCost],
    [show $ length buildPlants],
    map show buildPlants,
    [show $ length buildWires]
  ] ++ map (map show) buildWires
    where
      t = int ts
      coords = array (1, t) [(i, (x, y)) | (i, (x:y:_)) <- zip [1..t] (map ints xs) ]
      (cs:ks:_) = drop t xs
      wires = array (1, t) $ zip [1..t] (ints ks)
      (totalCost, buildPlants, buildWires) = runST $ do
        plantsRef <- newSTRef []
        wiresRef <- newSTRef []
        totalCost <- newSTRef 0
        nodes <- newListArray (1, t) (map (\i -> (i, 0, False)) $ ints cs) :: ST s (STArray s Int (Integer, Int, Bool))
        forM_ [1..t] $ \_ -> do
          ascs <- getAssocs nodes
          let ((w,u,_), v) = minimum $ map swap $ filter (\(_,(_,_,c)) -> not c) ascs
          if u == 0
            then modifySTRef plantsRef (\ps -> v:ps)
            else modifySTRef wiresRef (\ws -> [u,v]:ws)
          modifySTRef totalCost (+ w)
          writeArray nodes v (w,u,True)
          forM_ [1..t] $ \vn -> do
            let cost = (wires ! v + wires ! vn) * dist (coords ! v) (coords ! vn)
            (cost2,_,inMst) <- readArray nodes vn
            if not inMst && cost < cost2
              then writeArray nodes vn (cost,v,inMst)
              else return ()
        (,,) <$> readSTRef totalCost <*> readSTRef plantsRef <*> readSTRef wiresRef

dist (x1,y1) (x2,y2) = abs (x1 - x2) + abs (y1 - y2)

import           Control.Monad
import           Control.Monad.ST
import           Data.Array
import           Data.Array.ST.Safe
import           Data.List
import           Data.Ord
import           Data.STRef
import           Numeric

(|>) = flip (.)

int :: (Eq a, Num a) => String -> a
int x = fst $ readDec x !! 0

ints :: (Eq a, Num a) => String -> [a]
ints = map int . words

main = interact $
  lines
  |> solverLoop
  |> unlines

data Node = Node {
  parent  :: Int,
  inMST   :: Bool,
  nodeNum :: Int,
  cost    :: Integer
} deriving (Show)

solverLoop :: [String] -> [String]
solverLoop (ts:xs) = map (unwords) $ [
    [show totalCost],
    [show $ length buildPlants],
    map (show . nodeNum) buildPlants,
    [show $ length buildWires]
  ] ++ map (\(Node p _ v _) -> [show p, show v]) buildWires
    where
      t = int ts
      coords = array (1, t) [(i, (x, y)) | (i, (x:y:_)) <- zip [1..t] (map ints xs) ]
      (cs:ks:_) = drop t xs
      wires = array (1, t) $ zip [1..t] (ints ks)
      costf v w = (wires ! v + wires ! w) * dist (coords ! v) (coords ! w)
      nodes = mst t (map (uncurry $ Node 0 False) $ zip [1..t] (ints cs)) costf
      totalCost = sum $ map cost nodes
      (buildPlants, buildWires) = partition ((== 0) . parent) nodes

mst t initial costf = runST $ do
  nodes <- newListArray (1, t) initial :: ST s (STArray s Int Node)
  forM_ [1..t] $ \_ -> do
    elems <- getElems nodes
    let node@(Node u _ v w) = minimumBy (comparing cost) $ filter (not . inMST) elems
    writeArray nodes v node {inMST = True}
    let updateKey node@(Node p inMst vn w2) = if (not inMst && costf v vn < w2)
        then Just node { parent = v, cost = costf v vn }
        else Nothing
    mapArrayInPlace updateKey nodes
  getElems nodes

mapArrayInPlace :: (MArray a e m, Ix i) => (e -> Maybe e) -> a i e -> m ()
mapArrayInPlace f array = do
  assocs <- getAssocs array
  forM_ assocs $ \(i, e) ->
    case f e of
      Just x  -> writeArray array i x
      Nothing -> return ()

dist (x1,y1) (x2,y2) = abs (x1 - x2) + abs (y1 - y2)

import Control.Monad
import           Control.Monad.ST
import           Data.Array
import Data.Array.ST.Safe
import           Data.List
import           Numeric
import Data.Tuple

(|>) = flip (.)

int :: (Eq a, Num a) => String -> a
int x = fst $ readDec x !! 0

ints :: (Eq a, Num a) => String -> [a]
ints = map int . words

count x = length . filter (== x)

main = interact $
  lines
  |> solverLoop
  |> unlines

solverLoop :: [String] -> [String]
solverLoop (ts:xs) = map (unwords) $ [
    [show totalCost],
    [show $ length buildPlants],
    map show buildPlants,
    [show $ length buildWires]
  ] ++ map (map show) buildWires
    where
      t = int ts
      coords = array (1, t) [(i, (x, y)) | (i, (x:y:_)) <- zip [1..t] (map ints xs) ]
      (cs:ks:_) = drop t xs
      wires = array (1, t) $ zip [1..t] (ints ks)
      edges = runST $ do
        nodes <- newListArray (1, t) (map (\i -> (i, 0, False)) $ ints cs) :: ST s (STArray s Int (Integer, Int, Bool))
        forM_ [1..t] $ \_ -> do
          a <- getAssocs nodes
          let ((w,u,_), v) = minimum $ map swap $ filter (\(_,(_,_,c)) -> not c) a
          writeArray nodes v (w,u,True)
          forM_ [1..t] $ \vn -> do
            let cost = (wires ! v + wires ! vn) * dist (coords ! v) (coords ! vn)
            (cost2,_,inMst) <- readArray nodes vn
            if not inMst && cost < cost2
              then writeArray nodes vn (cost,v,inMst)
              else return ()
        getElems nodes
      totalCost = sum $ map (\(a,_,_) -> a) edges
      (buildPlants, buildWires) = detail $ zip [1..t] edges

detail :: [(Int, (Integer, Int, Bool))] -> ([Int], [[Int]])
detail [] = ([],[])
detail ((u, (w, v, _)):xs)
  | v == 0 = (u:ps', ws')
  | otherwise = (ps', [u,v]:ws')
  where
    (ps', ws') = detail xs

dist (x1,y1) (x2,y2) = abs (x1 - x2) + abs (y1 - y2)

import           Control.Monad
import           Control.Monad.ST
import           Data.Array
import           Data.Array.ST.Safe
import           Data.List
import           Data.Ord
import           Data.STRef
import           Numeric

(|>) = flip (.)

int :: (Eq a, Num a) => String -> a
int x = fst $ readDec x !! 0

ints :: (Eq a, Num a) => String -> [a]
ints = map int . words

main = interact $
  lines
  |> solverLoop
  |> unlines

data Node = Node {
  parent  :: Int,
  inMST   :: Bool,
  nodeNum :: Int,
  cost    :: Integer
} deriving (Show)

solverLoop :: [String] -> [String]
solverLoop (ts:xs) = [
    showInt totalCost "",
    showInt (length buildWires) "",
    unwords $ map ((\i -> showInt i "") . nodeNum) buildPlants,
    showInt (length buildWires) ""
  ] ++ map (\(Node p _ v _) -> showInt p (" " ++ showInt v "")) buildWires
    where
      t = int ts
      coords = array (1, t) [(i, (x, y)) | (i, (x:y:_)) <- zip [1..t] (map ints xs) ]
      (cs:ks:_) = drop t xs
      wires = array (1, t) $ zip [1..t] (ints ks)
      costf v w = (wires ! v + wires ! w) * dist (coords ! v) (coords ! w)
      nodes = mst t (map (uncurry $ Node 0 False) $ zip [1..t] (ints cs)) costf
      totalCost = sum $ map cost nodes
      (buildPlants, buildWires) = partition ((== 0) . parent) nodes

mst t initial costf = runST $ do
  nodes <- newListArray (1, t) initial :: ST s (STArray s Int Node)
  replicateM_ t $ do
    elems <- getElems nodes
    let node@(Node u _ v w) = minimumBy (comparing cost) $ filter (not . inMST) elems
    writeArray nodes v node {inMST = True}
    forM_ [1..t] $ \vn -> do
      let w = costf v vn
      node@(Node p inMst vn w2) <- readArray nodes vn
      when (not inMst && w < w2) $
        writeArray nodes vn node {parent = v, cost = w}
  getElems nodes

dist (x1,y1) (x2,y2) = abs (x1 - x2) + abs (y1 - y2)

import Control.Monad
import           Control.Monad.ST
import           Data.Array
import Data.Array.ST.Safe
import           Data.List
import           Numeric
import Data.Tuple

(|>) = flip (.)

int :: (Eq a, Num a) => String -> a
int x = fst $ readDec x !! 0

ints :: (Eq a, Num a) => String -> [a]
ints = map int . words

count x = length . filter (== x)

main = interact $
  lines
  |> solverLoop
  |> unlines

solverLoop :: [String] -> [String]
solverLoop (ts:xs) = map (unwords . map show) $ [
    [totalCost],
    [length buildPlants],
    buildPlants,
    [length buildWires]
  ] ++ buildWires
    where
      t = int ts
      coords = array (1, t) [(i, (x, y)) | (i, (x:y:_)) <- zip [1..t] (map ints xs) ]
      (cs:ks:_) = drop t xs
      wires = array (1, t) $ zip [1..t] (ints ks)
      edges = runST $ do
        nodes <- newListArray (1, t) (map (\i -> (i, 0, False)) $ ints cs) :: ST s (STArray s Int (Int, Int, Bool))
        forM_ [1..t] $ \_ -> do
          a <- getAssocs nodes
          let ((w,u,_), v) = minimum $ map swap $ filter (\(_,(_,_,c)) -> not c) a
          writeArray nodes v (w,u,True)
          forM_ [1..t] $ \vn -> do
            let cost = (wires ! v + wires ! vn) * dist (coords ! v) (coords ! vn)
            (cost2,_,inMst) <- readArray nodes vn
            if not inMst && cost < cost2
              then writeArray nodes vn (cost,v,inMst)
              else return ()
        getElems nodes
      totalCost = sum $ map (\(a,_,_) -> a) edges
      (buildPlants, buildWires) = detail $ zip [1..t] edges

detail [] = ([],[])
detail ((u, (w, v, _)):xs)
  | v == 0 = (u:ps', ws')
  | otherwise = (ps', [u,v]:ws')
  where
    (ps', ws') = detail xs

dist (x1,y1) (x2,y2) = abs (x1 - x2) + abs (y1 - y2)


import Control.Monad

getA = fmap (map read . words) getLine
hypot x y = sqrt . fromIntegral $ x ^ 2 + y ^ 2

main = do
	[n] <- getA
	[k, e] <- getA
	[x, y] <- getA
	p <- replicateM n getA
	putStr $ show $ gao n k (1 - fromIntegral e/1000) $ map (\[i, j] -> hypot (i - x) (j - y)) p

gao n k e d = gao' 0 3000 where
	gao' l r = if r - l < 0.1 ^ 8 then m else if q > e then gao' l m else gao' m r where
		m = (l + r) / 2
		p = map (\i -> if i <= m then 1 else exp $ 1 - (i / m) ^ 2) d
		q = sum $ drop k $ go p

go [] = [1]
go (p:ps) = let q = go ps in zipWith (\i j -> p * i + (1 - p) * j) (0:q) (q ++ [0])

import Control.Monad

getA = fmap (map read . words) getLine
hypot x y = sqrt . fromIntegral $ x ^ 2 + y ^ 2

main = do
	[n] <- getA
	[k, e] <- getA
	[x, y] <- getA
	p <- replicateM n getA
	putStr $ show $ gao n k (1 - fromIntegral e/1000) $ map (\[i, j] -> hypot (i - x) (j - y)) p

gao n k e d = gao' 0 2000 where
	gao' l r = if r-l<0.1^8 then m else if q > e then gao' l m else gao' m r where
		m = (l + r) / 2
		p = map (\i -> if i <= m then 1 else exp $ 1 - (i / m) ^ 2) d
		q = sum $ drop k $ go p

go [] = [1]
go (p:ps) = let q = go ps in zipWith (\i j -> p * i + (1 - p) * j) (0:q) (q ++ [0])

import Control.Monad

getA = fmap (map read . words) getLine
hypot x y = sqrt . fromIntegral $ x ^ 2 + y ^ 2

main = do
	[n] <- getA
	[k, e] <- getA
	[x, y] <- getA
	p <- replicateM n getA
	putStr $ show $ gao n k (1 - fromIntegral e/1000) $ map (\[i, j] -> hypot (i - x) (j - y)) p

gao n k e d = gao' 0 2000 where
	gao' l r = if abs(l-r)<0.0000001 then m else if q > e then gao' l m else gao' m r where
		m = (l + r) / 2
		p = map (\i -> if i <= m then 1 else exp $ 1 - (i / m) ^ 2) d
		q = sum $ drop k $ go p

go [] = [1]
go (p:ps) = let q = go ps in zipWith (\i j -> p * i + (1 - p) * j) (0:q) (q ++ [0])


{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
{-# LANGUAGE OverloadedStrings #-}
-- {-# LANGUAGE BangPatterns #-}
-- {-# LANGUAGE ViewPatterns #-}
-- {-# LANGUAGE TupleSections #-}

import           System.IO hiding (char8)
import           Control.Applicative
import           Control.Monad
import           Data.List
import           Data.Tuple
import           Data.Int
import           Data.Char
import           Data.Function (on)
import           Data.Array
-- import           Data.UArray
-- import           Data.Array.IArray
-- import           Data.Array.ST
-- import           Data.Array.MArray
-- import           Data.Array.Unsafe
import           Data.Ix
import           Data.Maybe
import           Data.Monoid hiding ((<>))
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as BL
import           Data.ByteString.Builder
-- import           Data.Vector.Unboxed ((//), (++), (!), (!?))
-- import qualified Data.Vector.Unboxed as U
-- import           Data.IntSet (IntSet)
-- import qualified Data.IntSet as S
import           Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as M
-- import           Data.Sequence ((|>), (<|), (><),ViewR((:>)), ViewL((:<)))
-- import qualified Data.Sequence as S
-- import           Debug.Trace

main = do
  _ <- readInt1 <$> BS.getLine
  as <- readIntN <$> BS.getLine
  _ <- readInt1 <$> BS.getLine
  bs <- readIntN <$> BS.getLine
  cs <- readIntN <$> BS.getLine
  print $ solve as $ zip bs cs

solve as bcs = fst . maximumBy (compare `on` snd) . zip [1..] $ map score bcs where
  score :: (Int,Int) -> Int64
  score (b,c) = (fromIntegral $ cnt b) * 200000 + (fromIntegral $ cnt c)
  cnt x = M.findWithDefault 0 x m
  m = loop as M.empty where
    loop [] m' = m'
    loop (a:as) m' = loop as (M.insertWith (+) a 1 m')

--  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --

readInt1 :: BS.ByteString -> Int
readInt1 = fst . fromJust . BS.readInt

readInt2 :: BS.ByteString -> (Int,Int)
readInt2 = toTuple . readIntN

readInt3 :: BS.ByteString -> (Int,Int,Int)
readInt3 = toTriple . readIntN

readIntN :: BS.ByteString -> [Int]
readIntN =  map readInt1 . BS.words

readInt641 :: BS.ByteString -> Int64
readInt641 = fromIntegral . fst . fromJust . BS.readInteger

readInt642 :: BS.ByteString -> (Int64,Int64)
readInt642 = toTuple . readInt64N

readInt643 :: BS.ByteString -> (Int64,Int64,Int64)
readInt643 = toTriple . readInt64N

readInt64N :: BS.ByteString -> [Int64]
readInt64N =  map readInt641 . BS.words

readInteger1 :: BS.ByteString -> Integer
readInteger1 = fst . fromJust . BS.readInteger

readInteger2 :: BS.ByteString -> (Integer,Integer)
readInteger2 = toTuple . readIntegerN

readInteger3 :: BS.ByteString -> (Integer,Integer,Integer)
readInteger3 = toTriple . readIntegerN

readIntegerN :: BS.ByteString -> [Integer]
readIntegerN =  map readInteger1 . BS.words

toTuple :: [a] -> (a, a)
toTuple [x, y] = (x, y)

toTriple :: [a] -> (a, a, a)
toTriple [x, y, z] =(x, y, z)

fromTuple :: (a, a) -> [a]
fromTuple (x, y) = [x, y]

fromTriple :: (a, a, a) -> [a]
fromTriple (x, y, z) = [x, y, z]

-- if not applying, use "const"

applyTuple :: (a -> a') -> (b -> b') -> (a, b) -> (a', b')
applyTuple f g (x, y) = (f x, g y)

applyTriple :: (a -> a') -> (b -> b') -> (c -> c') -> (a, b, c) -> (a', b', c')
applyTriple f g h (x, y, z) = (f x, g y, h z)

import Data.Maybe
import Control.Applicative
import qualified Data.List as L
import           Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as Map
import qualified Data.ByteString.Char8 as BS

readInt1 :: BS.ByteString -> Int
readInt1 = fst . fromJust . BS.readInt

readIntN :: BS.ByteString -> [Int]
readIntN =  map readInt1 . BS.words

build_map :: [Int] -> (IntMap Int) -> (IntMap Int)
build_map [] mp = mp
build_map (x:xs) mp = build_map xs $ Map.insertWith (+) x 1 mp

f :: (IntMap Int) -> (Int, Int) -> (Int, Int)
f mp (a,b) = (Map.findWithDefault 0 a mp, Map.findWithDefault 0 b mp)

main :: IO ()
main = do
  n <- readLn :: IO Int
  -- la <- getLine
  -- let a = map read (words la) :: [Int]
  a <- readIntN <$> BS.getLine
  m <- readLn :: IO Int
  -- lb <- getLine
  -- lc <- getLine
  -- let b = map read (words lb) :: [Int]
  -- let c = map read (words lc) :: [Int]
  b <- readIntN <$> BS.getLine
  c <- readIntN <$> BS.getLine
  let bc = zip b c
  let ma = build_map a Map.empty
  print . snd $ L.maximumBy compare $ zip (map  (f ma) bc) [1..]

import qualified Data.Map as M
import Control.Applicative
import Control.Monad

import qualified Data.Text as T
import qualified Data.Text.IO as TIO
import Data.Text.Read (decimal)
import System.IO (stdin)

tread s = case decimal s of
  Right (v,_) -> v
  Left e -> error e

count xs = foldr (\a m -> M.insertWith (\new old -> old + 1) a 1 m) M.empty xs

m ! v = case M.lookup v m of
  Just v -> v
  Nothing -> 0

aux [] [] i ans res freq = ans
aux (x:xs) (y:ys) i ans res@(a,b) freq
  | res < (freq ! x, freq ! y) = aux xs ys (i+1) i (freq ! x, freq ! y) freq
  | otherwise = aux xs ys (i+1) ans res freq

main = do
  n <- readLn :: IO Int
  as <- map tread . T.words <$> (TIO.hGetLine stdin) :: IO [Int]
  m <- readLn :: IO Int
  bs <- map tread . T.words <$> (TIO.hGetLine stdin) :: IO [Int]
  cs <- map tread . T.words <$> (TIO.hGetLine stdin) :: IO [Int]
  let freq = count as
  let ans = aux bs cs 0 0 (0,0) freq
  print $ ans + 1

import Data.List
import Control.Arrow
import Control.Applicative
import Control.Monad
import qualified Data.Text as T
import qualified Data.Text.IO as TIO
import Data.Text.Read (decimal)
import System.IO (stdin)
import qualified Data.Map as Map

tread s = case decimal s of
    Right (v, _) -> v
    Left e -> error e

main :: IO()
main = do
    _ <- getLine
    a <- map tread . T.words <$> TIO.hGetLine stdin :: IO [Int]
    _ <- getLine
    b <- map tread . T.words <$> TIO.hGetLine stdin :: IO [Int]
    c <- map tread . T.words <$> TIO.hGetLine stdin :: IO [Int]
    let f = Map.fromList $ frequency a
    print $ solve b c 1 0 0 1 f

frequency :: Ord a => [a] -> [(a, Int)]
frequency = map (head &&& length) . group . sort

removeMaybe :: Maybe Int -> Int
removeMaybe (Just a) = a
removeMaybe Nothing = 0

solve :: [Int] -> [Int] -> Int -> Int -> Int -> Int -> Map.Map Int Int -> Int
solve [] [] _ _ _ maxIdx _ = maxIdx
solve (b:bs) (c:cs) idx maxVal1 maxVal2 maxIdx fre =
    let newVal1 = removeMaybe $ Map.lookup b fre
        newVal2 = removeMaybe $ Map.lookup c fre
    in if newVal1 > maxVal1 || (newVal1 == maxVal1 && newVal2 > maxVal2)
       then solve bs cs (idx + 1) newVal1 newVal2 idx fre
       else solve bs cs (idx + 1) maxVal1 maxVal2 maxIdx fre

import Data.Map.Strict (empty, insertWith, findWithDefault)
import Data.Ord (comparing)
import Data.List (maximumBy)

--
-- UTILITIES
--
import qualified Data.ByteString.Char8 as C
import           Data.Maybe (fromJust)

readInt :: IO Int
readInt = read <$> getLine

readInts :: IO [Int]
readInts = fmap (fst . fromJust . C.readInt) . C.words <$> C.getLine

--
-- MAIN
--

main :: IO ()
main = do
  n      <- readInt
  lang   <- readInts
  m      <- readInt
  sounds <- readInts
  subs   <- readInts
  let langmap = foldl (\mp k -> insertWith (+) k 1 mp) empty lang
      happy   = getHappy <$> zip sounds subs
      getHappy (snd, sbt) = (findWithDefault 0 snd langmap, findWithDefault 0 sbt langmap)
      (_, ans) = maximumBy (comparing fst) $ zip happy [1..]
  print ans

import Control.Monad
import Control.Applicative

import qualified Data.Map as M
import Data.Ord (comparing)
import Data.List (maximumBy)

maxAux [] [] i freq aMax subV subI = subI
maxAux (x:xs) (y:ys) i freq aMax subV subI
  | freq !!! x == aMax = if freq !!! y > subV
                         then maxAux xs ys (i+1) freq aMax (freq !!! y) i
                         else maxAux xs ys (y+1) freq aMax subV subI
  | otherwise = maxAux xs ys (i+1) freq aMax subV subI

(!!!) ::   M.Map Int Int -> Int -> Int
m !!! v = case M.lookup v m of
    Just v -> v
    Nothing -> 0

main = do
  n <- readLn :: IO Int
  ls <- map read . words <$> getLine :: IO [Int]
  m <- readLn :: IO Int
  aud <- map read . words <$> getLine :: IO [Int]
  sub <- map read . words <$> getLine :: IO [Int]

  let freq = foldr (\a m -> M.insertWith (\new old -> old + 1) a 1 m) M.empty ls

  let subMax = maximumBy (comparing (freq !!!)) sub
  let audMax = maximumBy (comparing (freq !!!)) aud

  let ans = maxAux aud sub 0 freq audMax 0 0

  print (ans+1)


{-# LANGUAGE Safe #-}

import safe Control.Arrow ((>>>))
--import safe Data.List (sort)
import Data.List
import Data.Function

main :: IO ()
main =  interact $  lines >>> drop 1 >>> tcio >>> unlines where
  tcio :: [String] -> [String]
  tcio [] = []
  tcio (_ : l : rest) = (itoline . solve . linetois) l : tcio rest
  linetoi = read; linetois = (map linetoi) . words; linestoiss = map linetois
  itoline = show; istoline = unwords . (map itoline); isstolines = map istoline

solve :: [Int] -> Int
solve xs = if null u then (-1) else (snd.head.head) u  where u = dropWhile (not.null.drop 1) $ groupBy ((==) `on` fst) $ sort $ zip xs [1..]

{-# LANGUAGE GADTs, TemplateHaskell, DeriveFunctor, OverloadedStrings #-}

import Data.List
import qualified Data.ByteString.Char8 as B8
import Data.Maybe
import Data.Int
import Text.Printf
import Data.Function ( (&), on )
import Data.Functor
import Control.Arrow ((>>>))
import Control.Monad (forM_)
import Data.Char (isAlpha)

readIntB8 :: B8.ByteString -> Maybe Int
readIntB8 = B8.readInt >>> fmap fst

solve :: [Int] -> Maybe Int
solve as = do
    let uniqueAs = sort as & group & filter (\x -> length x == 1) & concat
    result <- listToMaybe uniqueAs
    index <- elemIndex result as
    return $ index + 1

mainCase :: IO ()
mainCase = do
    Just n <- B8.getLine <&> readIntB8
    as <- B8.getLine <&> B8.words <&> map (readIntB8 >>> fromJust)
    let answer = fromMaybe (-1) $ solve as
    printf "%d\n" answer

main :: IO ()
main = do
    Just t <- B8.getLine <&> readIntB8
    forM_ [1 .. t] $ const mainCase

{-
n participants
i-th participant chose number ai
participant that chooses the smallest unique number wins

find index of the participant who won, or -1 if no winner
index is 1-based (1 to n)
answer t independent test cases

input:
t, number of test cases
first line number participants
second line n integers
-}

import qualified Data.Map.Strict as Map
import Data.List
import Data.Maybe
import Control.Monad

main = do
  cases <- read <$> getLine
  replicateM cases $ do
    _ <- getLine
    participantNumbers <- ((fmap . fmap) read) $ words <$> getLine
    putStrLn $ show $ minUniqueIndex participantNumbers

minUniqueIndex :: [Int] -> Int
minUniqueIndex xs =
  if null uniques
     then -1
     else 1 + (fromJust $ findIndex (== head uniques) xs)
  where
    uniques = Map.keys $ Map.filter (<2) $ Map.fromListWith (+) $ map (flip (,) 1) xs

import Control.Arrow ((>>>))
import Data.List (groupBy, sort)

main =
  interact $
  lines >>>
  drop 1 >>> map (words >>> map read) >>> process >>> map show >>> unlines

process :: [[Int]] -> [Int]
process [] = []
process (_:xs:xss) = solve xs : process xss

solve :: [Int] -> Int
solve xs
  | null ys = -1
  | otherwise = snd . head . head $ ys
  where
    ys = filter ((== 1) . length) . groupBy (eq fst) . sort $ zip xs [1 ..]
    eq p x y = p x == p y

import Data.List
main :: IO ()
main = interact $ unlines . map show . solve . map read . tail . words

solve :: [Int] -> [Int]
solve [] = []
solve (n:rs) = findMin cn :(solve rest)
    where (an,rest) = splitAt n rs
          bn = zip [1..n] an
          cn = sortBy (\(_,vi) (_,vj) -> compare vi vj) bn

findMin :: [(Int,Int)] -> Int
findMin [] = -1
findMin [(i,vi)] = i
findMin ((i,vi):(j,vj):rs)
    | (vi /= vj) = i
    | otherwise = findMin $ dropWhile (\(a,va) -> va == vi) rs

import Data.List

solve :: [Int] -> Int
solve a
  | null b = -1
  | otherwise = snd . head . head $ b
  where
    b = filter ((==1) . length). groupBy (\x y -> fst x == fst y) . sort $ zip a [1..]

f [] = []
f (_:x:xs) = solve x : f xs

main = interact $
  unlines . map show . f . tail . map (map read) . map words . lines

import Data.List

solve [] = -1
solve (x:xs) = if (length $ takeWhile (==x) xs) >= 1
  then solve $ dropWhile (==x) xs
  else x

f [] = []
f (_:x:xs) = solve (sort x) : f xs

main = interact $
  unlines . map show . f . tail . map (map read) . map words . lines


import Control.Monad
import Control.Applicative
import Control.Arrow

import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as B

readInt :: B.ByteString -> Int
readInt = fromJust . fmap fst . B.readInt
readInts :: IO [Int]
readInts = map readInt . B.words <$> B.getLine

ifTE :: Bool -> a -> a -> a
ifTE x y z = if x then y else z

boolean :: a -> a -> Bool -> a
boolean x y z = ifTE z x y

main :: IO ()
main = do
    [n,m,k] <- readInts
    l <- ifTE (m <= n) id transpose <$> replicateM n readInts
    let w = min n m
        cost = curry $ sum . uncurry (zipWith ((boolean 0 1.) . (==)))
        f = sum . flip map l . (uncurry min.) . ((id &&& (w-)).) . cost
        res = minimum $ map f $ ifTE (w <= k) (replicateM w [0,1]) l
    print $ if res <= k then res else -1

import Control.Arrow
import Data.Bits
import Data.List

solve ([n, m, k] : a)
	| n < m     = solve ([m, n, k] : transpose a)
	| ans <= k  = ans
	| otherwise = -1
	where
		xs = map (foldl (\x b -> 2 * x + b) 0) a
		work y = sum $ map (uncurry min . (id &&& (m-)) . toInteger . popCount . xor y) xs
		ans = minimum . map work $ if m > k then xs else [0 .. 2^m-1]

main = interact $ show . solve . map (map read . words) . lines

import Control.Arrow
import Data.Bits
import Data.List

solve ([n, m, k] : a) = if n < m then solve ([m, n, k] : transpose a) else
	let
		xs = map (foldl (\x b -> 2 * x + b) 0) a
		ys = if m > k then xs else [0 .. 2 ^ m - 1]
		work y = sum $ map (uncurry min . (id &&& (m-)) . toInteger . popCount . (y `xor`)) xs
		cost = minimum $ map work ys
	in if cost <= k then cost else -1

main = interact $ show . solve . map (map read . words) . lines

{-# LANGUAGE MultiParamTypeClasses,FlexibleContexts,FlexibleInstances,TypeSynonymInstances,BangPatterns,RankNTypes,TupleSections #-}
import Control.Monad
import Control.Monad.ST
import Control.Applicative
import Control.Arrow
import Debug.Trace
import Text.Printf

import Data.List
import Data.Int
import Data.Bits
import Data.Maybe
import Data.Array.Unboxed
import Data.Array.ST
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.ByteString.Char8 as B

readInt = fromJust . fmap fst . B.readInt
readInts = map readInt . B.words <$> B.getLine
readIntPair = l2p . map readInt . take 2 . B.words <$> B.getLine
readLns :: Read a => IO [a]
readLns = map read . words <$> getLine
cmpFst (a,_) (b,_) = compare a b
cmpSnd (_,a) (_,b) = compare a b
cmpLen a b = length a `compare` length b
swap (a,b) = (b,a)
l2p (a:b:_) = (a,b)
p2l (a,b) = [a,b]
itof :: Int -> Double
itof = fromIntegral
defaultArray :: (IArray a e,Ix i) => e -> (i,i) -> [(i,e)] -> a i e
defaultArray = accumArray $ curry snd
flatten :: [(a,[(b,c)])] -> [((a,b),c)]
flatten = (=<<) $ uncurry $ fmap . first . (,)
stepM_ :: Monad m => a -> (a -> Bool) -> (a -> a) -> (a -> m ()) -> m ()
stepM_ i judge incr step = sub i
    where
    sub i | judge i = step i >> sub (incr i) | otherwise = return ()
inf = maxBound `div` 2 :: Int

main = do
    [n,m,k] <- readInts
    l <- replicateM n readInts
    let l1 = if m <= n then l else transpose l
    let w = min n m
    let res = minimum $ do
        xs <- if w <= k then replicateM w [0,1] else l1
        return $ sum [ min (cost xs r) (cost (neg xs) r) | r <- l1 ]
    print $ if res <= k then res else -1

neg :: [Int] -> [Int]
neg = map (1-)

cost :: [Int] -> [Int] -> Int
cost xs ys = sum $ zipWith (\a b -> if a == b then 0 else 1) xs ys
{-
 - w <= hとする
 - w <= k ならば
 -  xs <- [0,1]^w
 - w > k ならば
 -  xs <- rows
 - とするこのときの最小コストは
 - sum [ min (popcount $ xs `xor` ri) (popcount $ not xs `xor` ri) | ri <- rs]
 -
 - -}


import Data.List

rl = ((map read . words) <$> getLine) :: IO [Int]

fld :: Int -> [Int] -> Int -> [Int]
fld k acc v = if length acc < k then if v `elem` acc then acc else v:acc
                              else if v `elem` acc then acc else v:init acc

main = do
  [n, k] <- rl
  b      <- rl

  let l = foldl' (fld k) [] b
  print $ length l
  putStr $ foldl' (\a v -> a ++ ' ' : show v) (show $ head l) (tail l)

import Data.Set (Set)
import qualified Data.Set as Set

inputArr = do
  line <- getLine
  let ar = map read (words line) :: [Int]
  return ar

sim cur cur2 st [] rem = cur ++ (reverse cur2)
sim [] [] st (x:xs) rem = sim [] [x] (Set.insert x st) xs (rem-1)
sim (c:cs) [] st xs rem = sim [] (reverse (c:cs)) st xs rem
sim cur (c:cs) st (x:xs) rem
  | Set.member x st = sim cur (c:cs) st xs rem
  | rem > 0 = sim (x:cur) (c:cs) (Set.insert x st) xs (rem-1)
  | otherwise = sim (x:cur) cs newSt xs rem
      where newSt = Set.insert x (Set.delete c st)

main = do
  [n,k] <- inputArr
  a <- inputArr
  let res = sim [] [] Set.empty a k
  putStrLn (show (length res))
  putStrLn (concat (map ((++ " ") . show) res))

import Data.List
main = do
  [n,k] <- map read . words <$> getLine
  ids <- map read . words <$> getLine :: IO [Int]
  let ids' = foldl' (incoming k) [] ids
  print (length ids')
  putStrLn $ unwords $ map show ids'
incoming k q i | i `elem` q = q
               | otherwise = take k (i : q)

import Data.Foldable
import Data.Set hiding (map, deleteAt, toList)
import Data.Sequence
import Control.Monad

solve :: Int -> Int -> [Int] -> (Int, [Int])
solve n k ids =
	let
		helper :: Set Int -> Seq Int -> Int -> [Int] -> (Int, [Int])
		helper set seq m [] = (m, toList seq)
		helper set seq m (id:ids)
			| id `member` set = helper set seq m ids
			| otherwise =
			if m < k
			then helper (id `insert` set) (id <| seq) (m + 1) ids
			else let
				Just toDel = seq !? (k - 1)
			in
				helper (id `insert` (toDel `delete` set)) (id <| (deleteAt (k - 1) seq)) m ids
	in
		helper Data.Set.empty Data.Sequence.empty 0 ids
main = do
	firstStr <- getLine
	let n : k : [] = map read $ words firstStr
	secondStr <- getLine
	let ids = map read $ words secondStr
	let (m, finalIds) = solve n k ids
	putStrLn $ show m
	mapM_ (\x -> putStr $ (show x) ++ " ") finalIds

import Data.List
import qualified Data.Sequence as Q
import qualified Data.IntSet as S
import Data.Foldable
main = do
  [n,k] <- map read . words <$> getLine
  ids <- map read . words <$> getLine :: IO [Int]
  let (ids',_) = foldl' (incoming k) (Q.empty,S.empty) ids
  print (length ids')
  putStrLn $ unwords $ map show $ toList ids'
incoming k (q,s) i | i `S.member` s = (q,s)
                   | Q.length q < k = (i Q.<| q,S.insert i s)
                   | (q' Q.:> i') <- Q.viewr q =
                       (i Q.<| q',S.insert i (S.delete i' s))

import Data.List

rl = ((map read . words) <$> getLine) :: IO [Int]

fld :: Int -> [Int] -> Int -> [Int]
fld k acc v = if length acc < k then if v `elem` acc then acc else v:acc
                              else if v `elem` acc then acc else v:(tail acc)

main = do
  [n, k] <- rl
  b      <- rl

  let l = foldl' (fld k) [] b
  print $ length l
  putStr $ foldl' (\a v -> a ++ ' ' : (show v)) (show $ head l) (tail l)

import Data.List

rl = ((map read . words) <$> getLine) :: IO [Int]

fld :: Int -> [Int] -> Int -> [Int]
fld k acc v = if length acc < k then if v `elem` acc then acc else acc ++ [v]
                              else if v `elem` acc then acc else init acc ++ [v]

main = do
  [n, k] <- rl
  b      <- rl

  let l = foldl' (fld k) [] b
  print $ length l
  putStr $ foldl' (\a v -> show v ++ ' ' : a) (show $ head l) (tail l)

import Data.List

rl = ((map read . words) <$> getLine) :: IO [Int]

fld :: Int -> [Int] -> Int -> [Int]
fld k acc v = if length acc < k then if v `elem` acc then acc else acc ++ [v]
                              else if v `elem` acc then acc else v:init acc

main = do
  [n, k] <- rl
  b      <- rl

  let l = foldl' (fld k) [] b
  print $ length l
  putStr $ foldl' (\a v -> show v ++ ' ' : a) (show $ head l) (tail l)


{- <ღ> Haskell -}
{-# LANGUAGE MultiWayIf #-}
module Main where

main :: IO ()
main = interact $! solve

solve :: String -> String
solve s = check (map words (tail (lines s))) 1000000000

check :: [[String]] -> Int -> String
check [] pre = "YES"
check (x:xs) pre
      | max w h <= pre = check xs (max w h)
      | min w h <= pre = check xs (min w h)
      | otherwise = "NO"
    where
        [ws, hs] = x
        w = read ws :: Int
        h = read hs :: Int

import Data.List

toint s = (read s) :: Integer

doit [] k = True
doit (x:(y:xs)) k =
    if max x y <= k then
        doit xs $ max x y
    else
        if min x y <= k then
            doit xs $ min x y
        else
            False

solve::String -> String
solve ss =
    let s = map toint (tail (words ss)) in
    let r = doit s (2^30) in
    if r then
        "YES\n"
    else
        "NO\n"

main = do
  interact $ solve

import Data.Maybe

main = interact foo

foo :: String -> String
foo inp =
    let _:(n1, n2):ns = map (\n -> (n!!0, n!!1)) . map (map read . words) . lines $ inp :: [(Int, Int)]
    in if isNothing $ foldl check (Just $ max n1 n2) ns then "NO" else "YES"

check :: Maybe Int -> (Int, Int) -> Maybe Int
check Nothing _ = Nothing
check (Just l) (n1, n2)
    | l >= man = Just man
    | l >= mn = Just mn
    | otherwise = Nothing
        where mn = min n1 n2
              man = max n1 n2

module Main where

import Control.Monad
import Data.List
import Data.Maybe

pr :: String -> (Int, Int)
pr str = (read f :: Int, read s :: Int)
  where
    [f, s] = words str

f :: (Int, Bool) -> (Int, Int) -> (Int, Bool)
f (lv, r) (cw, ch)
  | not r = (lv, r)
  | max cw ch <= lv = (max cw ch, r)
  | min cw ch <= lv = (min cw ch, r)
  | otherwise = (lv, False)

solve :: String -> String
solve s
  | ans = "YES"
  | not ans = "NO"
  where
    r = map pr (tail (lines s))
    (_, ans) = foldl f (maxBound :: Int, True) r

main = interact $! solve

{- <ღ> Haskell -}
{-# LANGUAGE MultiWayIf #-}
module Main where

main :: IO ()
main = interact $! solve

toInt :: String -> Int
toInt s = read s :: Int

solve :: String -> String
solve s = check (tail (map words (lines s))) 1000000000

check :: [[String]] -> Int -> String
check [] pre = "YES"
check (x:xs) pre =
    if | max w h <= pre -> check xs (max w h)
       | min w h <= pre -> check xs (min w h)
       | otherwise -> "NO"
    where
        [ws, hs] = x
        w = toInt ws
        h = toInt hs

{- <ღ> Haskell -}
{-# LANGUAGE MultiWayIf #-}
module Main where

main :: IO ()
main = interact $ solve

toInt :: String -> Int
toInt s = read s :: Int

solve :: String -> String
solve s = check (tail (map words (lines s))) 1000000000

check :: [[String]] -> Int -> String
check [] pre = "YES"
check (x:xs) pre =
    if | max w h <= pre -> check xs (max w h)
       | min w h <= pre -> check xs (min w h)
       | otherwise -> "NO"
    where
        [ws, hs] = x
        w = toInt ws
        h = toInt hs


import Control.Monad (replicateM_)

getList :: Read b => IO [b]
getList = map read . words <$> getLine

maybeTake :: (Eq i, Num i) => i -> [a] -> Maybe [a]
maybeTake 0 _ = Just []
maybeTake _ [] = Nothing
maybeTake n (x:xs) = (x:) <$> maybeTake (n-1) xs

slices :: (Eq i, Num i) => i -> [a] -> [[a]]
slices n xs = case maybeTake n xs of
    Nothing -> []
    Just p -> p : slices n (tail xs)

main = readLn >>= flip replicateM_ solveIO

solveIO = do
    n <- readLn
    arr <- getList
    putStrLn . (\x -> show (head x) ++ "\n" ++ (unwords $ map show x)) $ solve n arr

solve ::  Int -> [Int] -> [Int]
solve n xs | all (== head xs) xs = replicate n 1
           | even n = take n $ cycle [2,1]
           | repIndex /= [] = let p = head repIndex; arr2 = if even p then [1,2] else [2,1]
                in take p (cycle [2,1]) ++ take (n-p) (cycle arr2)
           | otherwise = 3 : (take (n-1) $ cycle [2,1])
           where
                repIndex :: [Int]
                repIndex = map snd . filter (\([a,b], c) -> a == b) $ zip (slices 2 (xs++[head xs])) [1..]

{-# LANGUAGE Safe #-}

import safe Control.Arrow ((>>>))
import safe Data.Bool (bool)
import safe Data.Maybe (fromMaybe)

main :: IO ()
main =
  interact $
    lines
      >>> drop 1
      >>> map (words >>> map read)
      >>> process
      >>> map (map show >>> unwords)
      >>> unlines

process :: [[Integer]] -> [[Integer]]
process [] = []
process ([n] : a : rest) = solve n a ++ process rest

solve :: Integer -> [Integer] -> [[Integer]]
solve n a = [[maximum fin], fin]
  where
    nn = fromIntegral n
    fin
      | all (== head a) a = replicate nn 1
      | head cols == last cols && head a /= last a =
        fromMaybe (3 : tail cols) (update cols)
      | otherwise = cols

    cols = colour 1 a

    update :: [Integer] -> Maybe [Integer]
    update [] = Nothing
    update [_] = Nothing
    update (x : x' : xs)
      | x == x' = Just (x : map (pick True) (x' : xs))
      | otherwise = (x :) <$> update (x' : xs)

    colour :: Integer -> [Integer] -> [Integer]
    colour _ [] = []
    colour cur [_] = [cur]
    colour cur (x : x' : xs) = cur : colour (pick (x /= x') cur) (x' : xs)

    pick :: Bool -> Integer -> Integer
    pick fl x = bool x (3 - x) fl

{-# LANGUAGE Safe #-}

import safe Control.Arrow ((>>>))
import safe Data.Bool (bool)
import safe Data.Maybe (fromMaybe)

main :: IO ()
main =
  interact $
    lines
      >>> drop 1
      >>> map (words >>> map read)
      >>> process
      >>> map (map show >>> unwords)
      >>> unlines

process :: [[Int]] -> [[Int]]
process [] = []
process ([n] : a : rest) = solve n a ++ process rest

solve :: Int -> [Int] -> [[Int]]
solve n a = [[maximum fin], fin]
  where
    fin
      | all (== head a) a = replicate n 1
      | head cols == last cols && head a /= last a =
        fromMaybe (3 : tail cols) (update cols)
      | otherwise = cols

    cols = colour 1 a

    update :: [Int] -> Maybe [Int]
    update [] = Nothing
    update [_] = Nothing
    update (x : xs)
      | x == head xs = Just (x : map (pick True) xs)
      | otherwise = (x :) <$> update xs

    colour :: Int -> [Int] -> [Int]
    colour _ [] = []
    colour cur [_] = [cur]
    colour cur (x : x' : xs) = cur : colour (pick (x /= x') cur) (x' : xs)

    pick :: Bool -> Int -> Int
    pick fl x = bool x (3 - x) fl

{-# LANGUAGE Safe #-}

import safe Control.Arrow ((>>>))
import safe Data.Bool (bool)
import safe Data.Maybe (fromMaybe)

main :: IO ()
main =
  interact $
    lines
      >>> drop 1
      >>> map (words >>> map read)
      >>> process
      >>> map (map show >>> unwords)
      >>> unlines

process :: [[Int]] -> [[Int]]
process [] = []
process ([n] : a : rest) = solve n a ++ process rest

solve :: Int -> [Int] -> [[Int]]
solve n a = [[maximum fin], fin]
  where
    nn = fromIntegral n
    fin
      | all (== head a) a = replicate nn 1
      | head cols == last cols && head a /= last a =
        fromMaybe (3 : tail cols) (update cols)
      | otherwise = cols

    cols = colour 1 a

    update :: [Int] -> Maybe [Int]
    update [] = Nothing
    update [_] = Nothing
    update (x : x' : xs)
      | x == x' = Just (x : map (pick True) (x' : xs))
      | otherwise = (x :) <$> update (x' : xs)

    colour :: Int -> [Int] -> [Int]
    colour _ [] = []
    colour cur [_] = [cur]
    colour cur (x : x' : xs) = cur : colour (pick (x /= x') cur) (x' : xs)

    pick :: Bool -> Int -> Int
    pick fl x = bool x (3 - x) fl

import Control.Monad (replicateM_)
import Data.List (nub)

main = do
    numTests <- read <$> getLine
    replicateM_ numTests $ do
        n <- read <$> getLine
        ts <- words <$> getLine
        if same ts then do
            print 1
            putStrLn $ unwords $ replicate n "1"
        else if n `mod` 2 == 0 then do
            print 2
            putStrLn $ unwords $ concat $ replicate (div n 2) ["1", "2"]
        else case consec 0 (head ts) ts of
            Just i -> do
                print 2
                putStrLn $ unwords $ repeatNth i $ concat $
                    replicate (div n 2) ["1", "2"]
            Nothing -> do
                print 3
                putStrLn $ unwords $ ("3" :) $ concat $
                    replicate (div n 2) ["1", "2"]

same (x:xs@(y:_)) = x == y && same xs
same _ = True

consec _ _ [] = Nothing
consec i x [y] = if x == y then Just i else Nothing
consec i s (x:y:zs) = if x == y then Just i else consec (i + 1) s (y:zs)

repeatNth n (x:xs) =
    if n == length xs + 1
    then (x:xs) ++ [x]
    else repeatNth' n (x:xs)

repeatNth' 0 (x:xs) = x:x:xs
repeatNth' n (x:xs) = x : repeatNth' (n-1) xs

import Control.Arrow

main = interact $
  lines >>> drop 1 >>> map (words >>> map read)
  >>> process
  >>> map (map show >>> unwords) >>> unlines

process :: [[Integer]] -> [[Integer]]
process [] = []
process ([n]:a:rest) = solve n a ++ process rest

solve :: Integer -> [Integer] -> [[Integer]]
solve n a = [[foldl1 max fin], fin]
  where
    nn = fromIntegral n
    fin
      | a == (take nn $ repeat (head a)) = take nn $ repeat 1
      | head cols == head (reverse cols)
          && head a /= head (reverse a) =
            case newcols of Nothing -> 3 : tail cols
                            (Just a) -> a
      | otherwise = cols
          where newcols = update cols

    cols = colour 1 a

    update :: [Integer] -> Maybe [Integer]
    update [] = Nothing
    update [_] = Nothing
    update (x:y:rest)
      | x == y = Just (x : map (pick True) (y : rest))
      | otherwise = case rec of (Just a) -> Just (x : a)
                                Nothing -> Nothing
        where rec = update (y : rest)

    colour :: Integer -> [Integer] -> [Integer]
    colour _ [] = []
    colour cur [x] = [cur]
    colour cur (x:y:rest) = cur : colour (pick (x /= y) cur) (y : rest)

    pick :: Bool -> Integer -> Integer
    pick fl x
      | fl = 3 - x
      | otherwise = x

import Control.Arrow

main = interact $
  lines >>> drop 1 >>> map (words >>> map read)
  >>> process
  >>> map (map show >>> unwords) >>> unlines

process :: [[Integer]] -> [[Integer]]
process [] = []
process ([n]:a:rest) = solve n a ++ process rest

solve :: Integer -> [Integer] -> [[Integer]]
solve n a = [[foldl1 max fin], fin]
  where
    fin
      | head cols == head (reverse cols)
          && head a /= head (reverse a) = 3 : tail cols
      | otherwise = cols
    cols = colour 1 a
    colour :: Integer -> [Integer] -> [Integer]
    colour _ [] = []
    colour cur [x] = [cur]
    colour cur (x:y:rest)
      | x == y = cur : colour cur (y : rest)
      | otherwise = cur : colour (3 - cur) (y : rest)

import Control.Monad (replicateM_)

getList :: Read b => IO [b]
getList = map read . words <$> getLine

maybeTake :: (Eq i, Num i) => i -> [a] -> Maybe [a]
maybeTake 0 _ = Just []
maybeTake _ [] = Nothing
maybeTake n (x:xs) = (x:) <$> maybeTake (n-1) xs

slices :: (Eq i, Num i) => i -> [a] -> [[a]]
slices n xs = case maybeTake n xs of
    Nothing -> []
    Just p -> p : slices n (tail xs)

main = readLn >>= flip replicateM_ solveIO

solveIO = do
    n <- readLn
    arr <- getList
    putStrLn . (\x -> show (head x) ++ "\n" ++ (unwords $ map show x)) $ solve n arr

solve ::  Int -> [Int] -> [Int]
solve n xs | all (== head xs) xs = replicate n 1
           | even n = take n $ cycle [2,1]
           | repIndex /= [] = let p = head repIndex; arr2 = if even p then [1,2] else [2,1]
                in take p (cycle [2,1]) ++ take (n-p) (cycle arr2)
           | otherwise = 3 : (take (n-1) $ cycle [2,1])
           where
                repIndex :: [Int]
                repIndex = map snd . filter (\([a,b], c) -> a == b) $ zip (slices 2 xs) [1..]

import Control.Monad (replicateM_)

getList :: Read b => IO [b]
getList = map read . words <$> getLine

maybeTake :: (Eq i, Num i) => i -> [a] -> Maybe [a]
maybeTake 0 _ = Just []
maybeTake _ [] = Nothing
maybeTake n (x:xs) = (x:) <$> maybeTake (n-1) xs

slices :: (Eq i, Num i) => i -> [a] -> [[a]]
slices n xs = case maybeTake n xs of
    Nothing -> []
    Just p -> p : slices n (tail xs)

main = readLn >>= flip replicateM_ solveIO

solveIO = do
    n <- readLn
    arr <- getList
    putStrLn . (\x -> show (head x) ++ "\n" ++ (unwords $ map show x)) $ solve n arr

solve ::  Int -> [Int] -> [Int]
solve n xs | all (== head xs) xs = replicate n 1
           | even n = take n $ cycle [2,1]
           | repIndex /= [] = let p = head repIndex in take p (cycle [2,1]) ++ take (n-p) (cycle [1,2])
           | otherwise = 3 : (take (n-1) $ cycle [2,1])
           where
                repIndex = map snd . filter (\([a,b], c) -> a == b) $ zip (slices 2 xs) [1..]


{-# LANGUAGE MultiParamTypeClasses,FlexibleContexts,FlexibleInstances,TypeSynonymInstances,BangPatterns,RankNTypes #-}

import Control.Monad
import Control.Monad.ST
import Control.Applicative
import Control.Arrow
import Debug.Trace

import Data.List
import Data.Int
import Data.Maybe
import Data.Array.Unboxed
import Data.Array.ST
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.ByteString.Char8 as B

type Array1 a = Array Int a
type Array2 a = Array (Int,Int) a
type UArray1 a = UArray Int a
type UArray2 a = UArray (Int,Int) a
type RecFun m a b = (a -> m b) -> a -> m b

newtype State s a = State { runState :: s -> (a,s) }
newtype Identity a = Identity { runIdentity :: a }

instance Functor (State s) where
    fmap f m = State $ runState m >>> first f

instance Monad (State s) where
    return x = State $ \s -> (x,s)
    x >>= f  = State $ \s ->
        let (a,s') = runState x s in runState (f a) s'

instance Applicative (State s) where
    pure = return
    (<*>) = ap

instance Functor Identity where
    fmap f = runIdentity >>> f >>> Identity

instance Monad Identity where
    return = Identity
    x >>= f = f (runIdentity x)

instance Applicative Identity where
    pure = return
    (<*>) = ap

class IArray UArray e => Unboxable e where
    newSTUArray_ :: forall s i. Ix i => (i, i) -> ST s (STUArray s i e)
    readSTUArray :: forall s i. Ix i => STUArray s i e -> i -> ST s e
    writeSTUArray :: forall s i. Ix i => STUArray s i e -> i -> e -> ST s ()

instance Unboxable Int where
    newSTUArray_ = newArray_
    readSTUArray = readArray
    writeSTUArray = writeArray

instance Unboxable Char where
    newSTUArray_ = newArray_
    readSTUArray = readArray
    writeSTUArray = writeArray

instance Unboxable Double where
    newSTUArray_ = newArray_
    readSTUArray = readArray
    writeSTUArray = writeArray
readInt = B.readInt >>> fmap fst >>> fromMaybe 0
readLine :: Read a => IO a
readLine = read <$> getLine
readsLine :: Read a => IO [a]
readsLine = map read . words <$> getLine

cmpFst (a,_) (b,_) = compare a b
cmpSnd (_,a) (_,b) = compare a b
cmpLen a b = length a `compare` length b

swap (a,b) = (b,a)
rect a b = rect2 0 0 a b
rect2 i j a b = ((i,j),(a,b))

itof :: Int -> Double
itof = fromIntegral

maximize f l = snd $ maximumBy cmpFst [(f x,x) | x <- l]
minimize f l = snd $ minimumBy cmpFst [(f x,x) | x <- l]

fibs = 1:1:zipWith (+) fibs (tail fibs)

primeArray :: Int -> UArray1 Bool
primeArray n = runSTUArray $ do
    arr <- newArray (0,n) True
    writeArray arr 0 False
    writeArray arr 1 False
    forM_ (2:[3,5..n]) $ \i -> do
        b <- readArray arr i
        when b $ forM_ [2*i,3*i..n] $ \j -> writeArray arr j False
    return arr

binSearch f a b = go a b
    where
    go i j | i + 1 == j = i
           | f m        = go m j
           | otherwise  = go i m
        where m = div (i+j) 2

fixMemoArray :: (Ix a) => (a,a) -> RecFun Identity a b -> Array a b
fixMemoArray b f = arr
    where
    g y = Identity $ arr ! y
    arr = listArray b [ runIdentity $ f g x | x <- range b ]

fixMemoUArray :: (Ix a,Unboxable b) => (a,a) -> (forall s . RecFun (ST s) a b) -> UArray a b
fixMemoUArray b f = runSTUArray $ do
    arr <- newSTUArray_ b
    forM_ (range b) $ \x -> f (\y -> readSTUArray arr y) x >>= writeSTUArray arr x
    return arr

solve :: Int -> Double -> Double
solve m r = r * (sum [memo ! i +  memo ! (m-i-1) - 2| i <- [0..m-1]] / (itof m)^2)
    where
    memo :: UArray Int Double
    memo = fixMemoUArray (0,m-1) $ \f i -> case i of
        0 -> pure $ 2
        1 -> pure $ 4+sqrt 2
        i -> ((+) $ 2* itof (i-1) + 2*sqrt 2) <$> f (i-1)

main = do
    [m,r] <- readsLine
    print $ solve m (itof r)

{-# OPTIONS_GHC -O2 -optc-O2 #-}
module Main where

import Control.Monad (forM, liftM)
import Text.Printf (printf)

toDouble :: Int -> Double
toDouble = fromIntegral

main = do
  [m, r] <- liftM (map read . words) getContents
  let radius    = toDouble r
      near      = 2.0 * radius
      neighbour = 2.0 * radius + radius * (sqrt 2.0)
      far       = radius + radius * 2.0 * (sqrt 2.0)

  distances <- forM [1 .. m] $ \i -> do
    let numNear  = 1.0
        numNeighbour | m == 1           = 0.0
                     | i == 1 || i == m = 1.0
                     | otherwise        = 2.0
        farLeft  = toDouble $ max (i - 2) 0
        farRight = toDouble $ max (m - i - 1) 0
        distance = numNear * near +
                   numNeighbour * neighbour +
                   (far * farLeft + radius * farLeft * farLeft) +
                   (far * farRight + radius * farRight * farRight)
    return (distance / (toDouble m))
  let result = (sum distances) / (toDouble m)
  printf "%.9f\n" result

import Text.Printf

solve :: Int -> Int -> Int -> Double
solve m r i
	| (i<=m) = 2.0  +
		(if (i>1) then (2+sqrt 2) else 0) +
		(if (i>2) then (((fromIntegral (i-1))*(fromIntegral (i-2))) + (fromIntegral (i-2))*2.0*sqrt 2) else 0) +
		(if (i<m-1) then ((fromIntegral (m-i))*(fromIntegral (m-i-1))) + (fromIntegral (m-i-1))*2.0*sqrt 2 else 0) +
		(if (i<m) then 2 + sqrt 2 else 0) +
		(solve m r (i+1))
	| otherwise = 0.0

solution :: Int -> Int -> Double
solution m r =
	(solve m r 1) * (fromIntegral r) / (fromIntegral m)**2

main :: IO ()
main = do
	nStr <- getLine
	let [m, r] = map read $ words nStr
	printf "%.10f\n" $ solution m r

{-# OPTIONS_GHC -O2 -optc-O2 #-}
module Main where

import Control.Monad (forM, liftM)
import Text.Printf (printf)

toDouble :: Int -> Double
toDouble = fromIntegral

main = do
  [m, r] <- liftM (map read . words) getContents
  let radius    = toDouble r
      near      = 2.0 * radius
      neighbour = 2.0 * radius + radius * (sqrt 2.0)
      far       = 2.0 * radius + radius * 2.0 * (sqrt 2.0)

  distances <- forM [1 .. m] $ \i -> do
    let numNear  = 1.0
        numNeighbour | m == 1           = 0.0
                     | i == 1 || i == m = 1.0
                     | otherwise        = 2.0
        farLeft  = toDouble $ max (i - 2) 0
        farRight = toDouble $ max (m - i - 1) 0
        distance = numNear * near +
                   numNeighbour * neighbour +
                   (far * farLeft + radius * farLeft * farLeft) +
                   (far * farRight + radius * farRight * farRight)
    return (distance / (toDouble m))
  let result = (sum distances) / (toDouble m)
  printf "%.9f\n" result

{-# LANGUAGE MultiParamTypeClasses,FlexibleContexts,FlexibleInstances,TypeSynonymInstances,BangPatterns,RankNTypes #-}

import Control.Monad
import Control.Monad.ST
import Control.Applicative
import Control.Arrow
import Debug.Trace

import Data.List
import Data.Int
import Data.Maybe
import Data.Array.Unboxed
import Data.Array.ST
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.ByteString.Char8 as B

type Array1 a = Array Int a
type Array2 a = Array (Int,Int) a
type UArray1 a = UArray Int a
type UArray2 a = UArray (Int,Int) a
type RecFun m a b = (a -> m b) -> a -> m b

newtype State s a = State { runState :: s -> (a,s) }
newtype Identity a = Identity { runIdentity :: a }

instance Functor (State s) where
    fmap f m = State $ runState m >>> first f

instance Monad (State s) where
    return x = State $ \s -> (x,s)
    x >>= f  = State $ \s ->
        let (a,s') = runState x s in runState (f a) s'

instance Applicative (State s) where
    pure = return
    (<*>) = ap

instance Functor Identity where
    fmap f = runIdentity >>> f >>> Identity

instance Monad Identity where
    return = Identity
    x >>= f = f (runIdentity x)

instance Applicative Identity where
    pure = return
    (<*>) = ap

class IArray UArray e => Unboxable e where
    newSTUArray_ :: forall s i. Ix i => (i, i) -> ST s (STUArray s i e)
    readSTUArray :: forall s i. Ix i => STUArray s i e -> i -> ST s e
    writeSTUArray :: forall s i. Ix i => STUArray s i e -> i -> e -> ST s ()

instance Unboxable Int where
    newSTUArray_ = newArray_
    readSTUArray = readArray
    writeSTUArray = writeArray

instance Unboxable Char where
    newSTUArray_ = newArray_
    readSTUArray = readArray
    writeSTUArray = writeArray

instance Unboxable Double where
    newSTUArray_ = newArray_
    readSTUArray = readArray
    writeSTUArray = writeArray
readInt = B.readInt >>> fmap fst >>> fromMaybe 0
readLine :: Read a => IO a
readLine = read <$> getLine
readsLine :: Read a => IO [a]
readsLine = map read . words <$> getLine

cmpFst (a,_) (b,_) = compare a b
cmpSnd (_,a) (_,b) = compare a b
cmpLen a b = length a `compare` length b

swap (a,b) = (b,a)
rect a b = rect2 0 0 a b
rect2 i j a b = ((i,j),(a,b))

itof :: Int -> Double
itof = fromIntegral

maximize f l = snd $ maximumBy cmpFst [(f x,x) | x <- l]
minimize f l = snd $ minimumBy cmpFst [(f x,x) | x <- l]

fibs = 1:1:zipWith (+) fibs (tail fibs)

primeArray :: Int -> UArray1 Bool
primeArray n = runSTUArray $ do
    arr <- newArray (0,n) True
    writeArray arr 0 False
    writeArray arr 1 False
    forM_ (2:[3,5..n]) $ \i -> do
        b <- readArray arr i
        when b $ forM_ [2*i,3*i..n] $ \j -> writeArray arr j False
    return arr

binSearch f a b = go a b
    where
    go i j | i + 1 == j = i
           | f m        = go m j
           | otherwise  = go i m
        where m = div (i+j) 2

fixMemoArray :: (Ix a) => (a,a) -> RecFun Identity a b -> Array a b
fixMemoArray b f = arr
    where
    g y = Identity $ arr ! y
    arr = listArray b [ runIdentity $ f g x | x <- range b ]

fixMemoUArray :: (Ix a,Unboxable b) => (a,a) -> (forall s . RecFun (ST s) a b) -> UArray a b
fixMemoUArray b f = runSTUArray $ do
    arr <- newSTUArray_ b
    forM_ (range b) $ \x -> f (\y -> readSTUArray arr y) x >>= writeSTUArray arr x
    return arr

solve :: Int -> Double -> Double
solve m r = sum [ memo ! i +  memo ! (m-i-1) - memo ! 0 | i <- [0..m-1]] / (itof m)^2
    where
    memo :: UArray Int Double
    memo = fixMemoUArray (0,m-1) $ \f i -> case i of
        0 -> pure $ 2*r
        i -> (\a -> a + 2*(itof i)*r + r*sqrt 2) <$> f (i-1)

main = do
    [m,r] <- readsLine
    print $ solve m (itof r)

{-# LANGUAGE MultiParamTypeClasses,FlexibleContexts,FlexibleInstances,TypeSynonymInstances,BangPatterns,RankNTypes #-}

import Control.Monad
import Control.Monad.ST
import Control.Applicative
import Control.Arrow
import Debug.Trace

import Data.List
import Data.Int
import Data.Maybe
import Data.Array.Unboxed
import Data.Array.ST
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.ByteString.Char8 as B

type Array1 a = Array Int a
type Array2 a = Array (Int,Int) a
type UArray1 a = UArray Int a
type UArray2 a = UArray (Int,Int) a
type RecFun m a b = (a -> m b) -> a -> m b

newtype State s a = State { runState :: s -> (a,s) }
newtype Identity a = Identity { runIdentity :: a }

instance Functor (State s) where
    fmap f m = State $ runState m >>> first f

instance Monad (State s) where
    return x = State $ \s -> (x,s)
    x >>= f  = State $ \s ->
        let (a,s') = runState x s in runState (f a) s'

instance Applicative (State s) where
    pure = return
    (<*>) = ap

instance Functor Identity where
    fmap f = runIdentity >>> f >>> Identity

instance Monad Identity where
    return = Identity
    x >>= f = f (runIdentity x)

instance Applicative Identity where
    pure = return
    (<*>) = ap

class IArray UArray e => Unboxable e where
    newSTUArray_ :: forall s i. Ix i => (i, i) -> ST s (STUArray s i e)
    readSTUArray :: forall s i. Ix i => STUArray s i e -> i -> ST s e
    writeSTUArray :: forall s i. Ix i => STUArray s i e -> i -> e -> ST s ()

instance Unboxable Int where
    newSTUArray_ = newArray_
    readSTUArray = readArray
    writeSTUArray = writeArray

instance Unboxable Char where
    newSTUArray_ = newArray_
    readSTUArray = readArray
    writeSTUArray = writeArray

readInt = B.readInt >>> fmap fst >>> fromMaybe 0
readLine :: Read a => IO a
readLine = read <$> getLine
readsLine :: Read a => IO [a]
readsLine = map read . words <$> getLine

cmpFst (a,_) (b,_) = compare a b
cmpSnd (_,a) (_,b) = compare a b
cmpLen a b = length a `compare` length b

swap (a,b) = (b,a)
rect a b = rect2 0 0 a b
rect2 i j a b = ((i,j),(a,b))

itof :: Int -> Double
itof = fromIntegral

maximize f l = snd $ maximumBy cmpFst [(f x,x) | x <- l]
minimize f l = snd $ minimumBy cmpFst [(f x,x) | x <- l]

fibs = 1:1:zipWith (+) fibs (tail fibs)

primeArray :: Int -> UArray1 Bool
primeArray n = runSTUArray $ do
    arr <- newArray (0,n) True
    writeArray arr 0 False
    writeArray arr 1 False
    forM_ (2:[3,5..n]) $ \i -> do
        b <- readArray arr i
        when b $ forM_ [2*i,3*i..n] $ \j -> writeArray arr j False
    return arr

binSearch f a b = go a b
    where
    go i j | i + 1 == j = i
           | f m        = go m j
           | otherwise  = go i m
        where m = div (i+j) 2

fixMemoArray :: (Ix a) => (a,a) -> RecFun Identity a b -> Array a b
fixMemoArray b f = arr
    where
    g y = Identity $ arr ! y
    arr = listArray b [ runIdentity $ f g x | x <- range b ]

fixMemoUArray :: (Ix a,Unboxable b) => (a,a) -> (forall s . RecFun (ST s) a b) -> UArray a b
fixMemoUArray b f = runSTUArray $ do
    arr <- newSTUArray_ b
    forM_ (range b) $ \x -> f (\y -> readSTUArray arr y) x >>= writeSTUArray arr x
    return arr

distance :: Double -> Double -> Double
distance m r = sum [ 2 * r + i * 2 * r - if i == 0 then 0 else (2*r - r* sqrt 2) | i <- [0..m-1]] / m

main = do
    [m,r] <- readsLine
    print $ distance m r

{-# LANGUAGE MultiParamTypeClasses,FlexibleContexts,FlexibleInstances,TypeSynonymInstances,BangPatterns,RankNTypes #-}

import Control.Monad
import Control.Monad.ST
import Control.Applicative
import Control.Arrow
import Debug.Trace

import Data.List
import Data.Int
import Data.Maybe
import Data.Array.Unboxed
import Data.Array.ST
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.ByteString.Char8 as B

type Array1 a = Array Int a
type Array2 a = Array (Int,Int) a
type UArray1 a = UArray Int a
type UArray2 a = UArray (Int,Int) a
type RecFun m a b = (a -> m b) -> a -> m b

newtype State s a = State { runState :: s -> (a,s) }
newtype Identity a = Identity { runIdentity :: a }

instance Functor (State s) where
    fmap f m = State $ runState m >>> first f

instance Monad (State s) where
    return x = State $ \s -> (x,s)
    x >>= f  = State $ \s ->
        let (a,s') = runState x s in runState (f a) s'

instance Applicative (State s) where
    pure = return
    (<*>) = ap

instance Functor Identity where
    fmap f = runIdentity >>> f >>> Identity

instance Monad Identity where
    return = Identity
    x >>= f = f (runIdentity x)

instance Applicative Identity where
    pure = return
    (<*>) = ap

class IArray UArray e => Unboxable e where
    newSTUArray_ :: forall s i. Ix i => (i, i) -> ST s (STUArray s i e)
    readSTUArray :: forall s i. Ix i => STUArray s i e -> i -> ST s e
    writeSTUArray :: forall s i. Ix i => STUArray s i e -> i -> e -> ST s ()

instance Unboxable Int where
    newSTUArray_ = newArray_
    readSTUArray = readArray
    writeSTUArray = writeArray

instance Unboxable Char where
    newSTUArray_ = newArray_
    readSTUArray = readArray
    writeSTUArray = writeArray

instance Unboxable Double where
    newSTUArray_ = newArray_
    readSTUArray = readArray
    writeSTUArray = writeArray
readInt = B.readInt >>> fmap fst >>> fromMaybe 0
readLine :: Read a => IO a
readLine = read <$> getLine
readsLine :: Read a => IO [a]
readsLine = map read . words <$> getLine

cmpFst (a,_) (b,_) = compare a b
cmpSnd (_,a) (_,b) = compare a b
cmpLen a b = length a `compare` length b

swap (a,b) = (b,a)
rect a b = rect2 0 0 a b
rect2 i j a b = ((i,j),(a,b))

itof :: Int -> Double
itof = fromIntegral

maximize f l = snd $ maximumBy cmpFst [(f x,x) | x <- l]
minimize f l = snd $ minimumBy cmpFst [(f x,x) | x <- l]

fibs = 1:1:zipWith (+) fibs (tail fibs)

primeArray :: Int -> UArray1 Bool
primeArray n = runSTUArray $ do
    arr <- newArray (0,n) True
    writeArray arr 0 False
    writeArray arr 1 False
    forM_ (2:[3,5..n]) $ \i -> do
        b <- readArray arr i
        when b $ forM_ [2*i,3*i..n] $ \j -> writeArray arr j False
    return arr

binSearch f a b = go a b
    where
    go i j | i + 1 == j = i
           | f m        = go m j
           | otherwise  = go i m
        where m = div (i+j) 2

fixMemoArray :: (Ix a) => (a,a) -> RecFun Identity a b -> Array a b
fixMemoArray b f = arr
    where
    g y = Identity $ arr ! y
    arr = listArray b [ runIdentity $ f g x | x <- range b ]

fixMemoUArray :: (Ix a,Unboxable b) => (a,a) -> (forall s . RecFun (ST s) a b) -> UArray a b
fixMemoUArray b f = runSTUArray $ do
    arr <- newSTUArray_ b
    forM_ (range b) $ \x -> f (\y -> readSTUArray arr y) x >>= writeSTUArray arr x
    return arr

solve :: Int -> Double -> Double
solve m r = sum [ memo ! i +  memo ! (m-i-1) - memo ! 0 | i <- [0..m-1]] / (itof m)^2
    where
    memo :: UArray Int Double
    memo = fixMemoUArray (0,m-1) $ \f i -> case i of
        0 -> pure $ 2*r
        i -> (\a -> a + (2*(itof i)*r + r*sqrt 2)) <$> f (i-1)

main = do
    [m,r] <- readsLine
    print $ solve m (itof r)

import Control.Monad (liftM)
import Prelude hiding (reads)

reads :: Read a => IO [a]
reads  =  liftM (map read . words) getLine

reads' :: Read a => IO [a]
reads'  =  liftM (map read . words) (readFile "input.txt")

solve :: [Double] -> Double
solve [1, r]  =  2 * r
solve [n, r]  =  k * r / (n^2)
  where
    k  =  2 * n + (2 * (n - 1) * (2 + sqrt 2)) + sum [2 * (n - i) * (2 * (i - 2) + 2 * sqrt 2) | i <- [3..n]]

main :: IO ()
main  =  reads >>= print . solve


{-# LANGUAGE Strict  #-}

import Control.Monad (replicateM, replicateM_)

main :: IO ()
main = do
  t <- readLn :: IO Int
  replicateM_ t run

run :: IO ()
run = do
  n <- readLn :: IO Int
  ps <- map read . words <$> getLine :: IO [Int]
  print $ solve 0 ps

solve :: Int -> [Int] -> Int
solve n []  = n
solve n [p] = n
solve n (p:pp:ps) = if p > pp then solve (n+1) ps else solve n (pp:ps)

-- solve !n []  = n
-- solve !n [p] = n
-- solve !n (p:pp:ps) = if p > pp then solve (n+1) ps else solve n (pp:ps)

import Control.Monad (replicateM_)
main = read <$> getLine >>= flip replicateM_ scase
scase = read <$> getLine >>=
        \n -> map read . words <$> getLine >>=
        print . maxOdd n

maxOdd :: Int -> [Int] -> Int
maxOdd n ps = m ps 0

m :: [Int] -> Int -> Int
m [] acc = acc
m [_] acc = acc
m (p1:p2:ps) acc | p1 < p2 = m (p2:ps) acc
                 | p1 >= p2 = m ps (acc+1)

-- https://codeforces.com/contest/1679/problem/D
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DatatypeContexts #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE Safe #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE Strict #-}
{-# LANGUAGE TupleSections #-}

import Control.Arrow ((>>>))
import Control.Monad (
    MonadPlus (mplus),
    foldM_,
    forM_,
    guard,
    join,
    replicateM,
    replicateM_,
 )
import qualified Control.Monad.ST.Strict as ST
import qualified Control.Monad.State.Strict as S

import qualified Data.Array as A
import qualified Data.Array.MArray.Safe as MA
import qualified Data.Array.ST.Safe as STA
import qualified Data.Array.Unboxed as UA

import Data.Bits
import qualified Data.ByteString.Char8 as B8
import Data.Char
import Data.Int

import Data.Function (on)
import Data.Functor ((<&>))
import Data.Maybe (fromJust, fromMaybe, isJust)

import qualified Data.IntMap as IM
import qualified Data.IntSet as IS
import qualified Data.List   as L
import Data.List (
    elemIndices,
    find,
    findIndices,
    intersect,
    isPrefixOf,
    nub,
    sort,
    sortOn,
 )
import qualified Data.Map as M
import qualified Data.Set as S

import Control.Monad.Cont (MonadIO (liftIO))
import Data.IORef (modifyIORef, newIORef, readIORef)
import GHC.IO.Handle (hDuplicateTo)
import System.IO (
    IOMode (ReadMode, WriteMode),
    openFile,
    stdin,
    stdout,
 )
import System.Posix.Internals (puts)
import Text.Printf (printf)

-- import Debug.Trace (trace, traceM, traceShowM)
-- debug = flip trace

readIntB8 :: B8.ByteString -> Int
readIntB8 = B8.readInt >>> (fst . fromJust)

readIntB8s :: B8.ByteString -> [Int]
readIntB8s = B8.words >>> map (B8.readInt >>> (fst . fromJust))

readIntegerB8 :: B8.ByteString -> Integer
readIntegerB8 = B8.readInteger >>> (fst . fromJust)

readIntegerB8s :: B8.ByteString -> [Integer]
readIntegerB8s = B8.words >>> map (B8.readInteger >>> (fst . fromJust))

modifyArray :: (MA.MArray a e m, MA.Ix i) => a i e -> i -> (e -> e) -> m ()
modifyArray arr ix f = do
    value <- MA.readArray arr ix
    MA.writeArray arr ix $ f value

putsYesNo :: Bool -> IO ()
putsYesNo value = do
    let result :: String =
            if value
                then "Yes"
                else "No"
    printf "%s\n" result

{- END OF GENERAL -}

solve :: Int -> [Int] -> Int
solve 0 _ = 0
solve 1 _ = 0
solve n as@(a1:a2:otherAs) | a1 > a2 = 1 + solve (n - 2) otherAs
solve n as@(_:otherAs) = solve (n - 1) otherAs

main :: IO ()
main = do
    t <- B8.getLine <&> readIntB8
    replicateM_ t $ do
        n <- B8.getLine <&> readIntB8
        as <- B8.getLine <&> readIntB8s
        let answer = solve n as
        printf "%d\n" answer

{-# LANGUAGE Strict  #-}

import Control.Monad (replicateM, replicateM_)
import qualified Data.ByteString.Char8 as B8
import Data.Maybe (fromJust)

readInt :: B8.ByteString -> Int
readInt = fst . fromJust . B8.readInt

readInts :: B8.ByteString -> [Int]
readInts = map readInt . B8.words

main :: IO ()
main = do
  t <- readLn :: IO Int
  replicateM_ t run

run :: IO ()
run = do
  n <- readInt <$> B8.getLine :: IO Int
  ps <- readInts <$> B8.getLine :: IO [Int]
  print $ solve ps

solve :: [Int] -> Int
solve []  = 0
solve [p] = 0
solve (p:pp:ps) = if p > pp then 1 + solve ps else solve (pp:ps)

-- solve !n []  = n
-- solve !n [p] = n
-- solve !n (p:pp:ps) = if p > pp then solve (n+1) ps else solve n (pp:ps)

{-# LANGUAGE Strict  #-}

import Control.Monad (replicateM, replicateM_)

main :: IO ()
main = do
  t <- readLn :: IO Int
  replicateM_ t run

run :: IO ()
run = do
  n <- readLn :: IO Int
  ps <- map read . words <$> getLine :: IO [Int]
  print $ solve ps

solve :: [Int] -> Int
solve []  = 0
solve [p] = 0
solve (p:pp:ps) = if p > pp then 1 + solve ps else solve (pp:ps)

-- solve !n []  = n
-- solve !n [p] = n
-- solve !n (p:pp:ps) = if p > pp then solve (n+1) ps else solve n (pp:ps)

{-# LANGUAGE BangPatterns  #-}

import Control.Monad (replicateM, replicateM_)

main :: IO ()
main = do
  t <- readLn :: IO Int
  replicateM_ t run

run :: IO ()
run = do
  n <- readLn :: IO Int
  ps <- seq () $  map read . words <$> getLine :: IO [Int]
  print $ solve 0 ps

solve :: Int -> [Int] -> Int
solve !n []  = n
solve !n [p] = n
solve !n (p:pp:ps) = if p > pp then solve (n+1) ps else solve n (pp:ps)

{-# LANGUAGE BangPatterns  #-}

import Control.Monad (replicateM, replicateM_)

main :: IO ()
main = do
  t <- readLn :: IO Int
  replicateM_ t run

run :: IO ()
run = do
  n <- readLn :: IO Int
  ps <-  map read . words <$> getLine :: IO [Int]
  print $ solve 0 ps

solve :: Int -> [Int] -> Int
solve !n []  = n
solve !n [p] = n
solve !n (p:pp:ps) = if p > pp then solve (n+1) ps else solve n (pp:ps)

{-# LANGUAGE BangPatterns  #-}

import Control.Monad (replicateM)

main :: IO ()
main = do
  t <- readLn :: IO Int
  res <- replicateM t run
  putStrLn . unlines $ res

run :: IO String
run = do
  n <- readLn :: IO Int
  ps <-  map read . words <$> getLine :: IO [Int]
  return . show $ solve 0 ps

solve :: Int -> [Int] -> Int
solve !n []  = n
solve !n [p] = n
solve !n (p:pp:ps) = if p > pp then solve (n+1) ps else solve n (pp:ps)

import Control.Monad (replicateM)

main :: IO ()
main = do
  t <- readLn :: IO Int
  res <- replicateM t run
  putStrLn . unlines $ res

run :: IO String
run = do
  n <- readLn :: IO Int
  ps <-  map read . words <$> getLine :: IO [Int]
  return . show $ solve ps

solve :: [Int] -> Int
solve []  = 0
solve [p] = 0
solve (p:pp:ps) = if p > pp then 1 + solve ps else solve (pp:ps)

{-# LANGUAGE BangPatterns  #-}

import Control.Monad (replicateM)

main :: IO ()
main = do
  t <- readLn :: IO Int
  res <- replicateM t run
  putStrLn . unlines $ res

run :: IO String
run = do
  n <- readLn :: IO Int
  ps <-  map read . words <$> getLine :: IO [Int]
  return . show $ solve 0 ps

solve :: Int -> [Int] -> Int
solve !n []  = n
solve !n [p] = n
solve !n (p:pp:ps) = if p > pp then solve (n+1) ps else solve (n+1) (pp:ps)