let ( + ) : 'a -> 'a -> 'a = fun x y -> assert false

let ( * ) : 'a -> 'a -> 'a = fun x y -> assert false

let ( - ) : 'a -> 'a -> 'a = fun x y -> assert false

let ( / ) : 'a -> 'a -> 'a = fun x y -> assert false

let ( ~- ) : 'a -> 'a -> 'a = fun x y -> assert false

let pf = Printf.printf

let epf = Printf.eprintf

let sf = Scanf.scanf

let ( |> ) x f = f x

let ( @@ ) f x = f x

module Array = ArrayLabels

module List =
  struct
    include ListLabels

    let rec repeat n a =
      if n = 0 then [] else a :: (repeat (Pervasives.( - ) n 1) a)

    let rec drop n a =
      if n = 0
      then a
      else
        (match a with
         | [] -> failwith "cannot take"
         | x :: xs -> drop (Pervasives.( - ) n 1) xs)

  end

module H = Hashtbl

let solve n arr =
  (Array.sort ~cmp: compare arr;
   let prev = ref arr.(0) in
   let cnt = ref 1L in
   let ls = ref []
   in
     (for i = 1 to Pervasives.( - ) n 1 do
        if !prev = arr.(i)
        then cnt := Int64.add !cnt 1L
        else (ls := ((!prev), (!cnt)) :: !ls; prev := arr.(i); cnt := 1L)
      done;
      ls := ((!prev), (!cnt)) :: !ls;
      let arr = Array.of_list !ls in
      let n = Array.length arr
      in
        (Array.iter arr ~f: (fun (v, c) -> epf "(%Ld, %Ld), " v c);
         epf "\n";
         let mul (x, y) = Int64.mul (x : int64) y in
         let memo = H.create 10 in
         let rec iter i =
           if i = n
           then 0L
           else
             if i = (Pervasives.( - ) n 1)
             then mul arr.(i)
             else
               if H.mem memo i
               then H.find memo i
               else
                 if
                   (Int64.sub (fst arr.(i)) 1L) =
                     (fst arr.(Pervasives.( + ) i 1))
                 then
                   (let v =
                      max
                        (Int64.add (iter (Pervasives.( + ) i 2))
                           (mul arr.(i)))
                        (iter (Pervasives.( + ) i 1))
                    in (H.add memo i v; v))
                 else
                   (let v =
                      Int64.add (mul arr.(i)) (iter (Pervasives.( + ) i 1))
                    in (H.add memo i v; v))
         in (pf "%Ld\n") @@ (iter 0))))

let () =
  sf "%d "
    (fun n ->
       let arr = Array.init n ~f: (fun _ -> sf "%Ld " (fun x -> x))
       in solve n arr)

open Scanf;;
open String;;
open Printf;;
open Num;;

let n = bscanf Scanning.stdin "%d " (fun x -> x);;

let nn = 100000 + 5;;
let count = Array.make nn (num_of_int 0);;
let indx = Array.make nn 0;;
let score = Array.make nn (num_of_int 0);;

let p = Array.init n (fun x -> 0);;

for i=0 to n-1 do
  let  f = bscanf Scanning.stdin "%d " (fun x -> x)  in
  count.(f) <- count.(f) +/ (num_of_int f)
done;;

let l = ref 1;;

for i=1 to nn-1 do
  if count.(i) >/ num_of_int 0 then
    begin
      indx.(!l) <- i;
      l := !l + 1
    end
done;;

(*For testing
for i=1 to !l-1 do
  printf "%d %d\n" indx.(i) count.(indx.(i));
done;;*)

score.(0) <- num_of_int 0;;
score.(1) <- count.(indx.(1));;
let cur_indx = ref indx.(1) in
for i=2 to !l-1 do
  let x1 = !cur_indx in
  let x2 = indx.(i) in
  if x2 > x1 + 1 then
    begin
      score.(i)<-score.(i-1) +/  count.(x2);
      cur_indx := indx.(i)
    end
  else
    begin
      let tscore = score.(i-2) +/ count.(x2) in
      if tscore >/ score.(i-1) then
        begin
          score.(i) <- tscore;
          cur_indx := x2
        end
      else
        begin
          score.(i) <- score.(i-1);
          cur_indx := indx.(i-1)
        end
    end
done;;

print_endline (string_of_num (score.(!l-1)));;

let read () = Scanf.scanf "%d " (fun n -> n)
let print score = Printf.printf "%Ld\n" score

let list_init n f =
    let rec loop i list =
        if i < n
        then
            let element = f(i) in
            loop (i + 1) (element :: list)
        else
            List.rev list
    in loop 0 []

let count list =
    let rec loop count acc = function
        | a :: (b :: _ as tl) -> if a = b then loop (count + 1) acc tl
                                    else loop 0 ((a, count + 1) :: acc) tl
        | [x] -> (x, count + 1) :: acc
        | [] -> []
    in List.rev (loop 0 [] list)

let multiply list = List.map (fun (x, n) -> (x, Int64.mul (Int64.of_int x) (Int64.of_int n))) list

let score list =
    let rec loop prev sum_if_prev_taken sum_if_prev_skipped rest =
        let sum_if_unconstrained = Pervasives.max sum_if_prev_taken sum_if_prev_skipped in
        match rest with
        | [] -> sum_if_unconstrained
        | (a, v) :: tl ->
            let sum_if_a_taken =
                if a - 1 = prev
                then
                    Int64.add v sum_if_prev_skipped
                else
                    Int64.add v sum_if_unconstrained
            in
            let sum_if_a_skipped = sum_if_unconstrained in
            loop a sum_if_a_taken sum_if_a_skipped tl
    in loop (-1) 0L 0L list

let input () =
    let n = read () in
    let numbers = List.sort (Pervasives.compare) (list_init n (fun i -> read ())) in
    (numbers, n)

let solve (numbers, n) =
    let score = score (multiply (count numbers)) in
    score

let () = print (solve (input ()))

let ( + ) : 'a -> 'a -> 'a = fun x y -> assert false

let ( * ) : 'a -> 'a -> 'a = fun x y -> assert false

let ( - ) : 'a -> 'a -> 'a = fun x y -> assert false

let ( / ) : 'a -> 'a -> 'a = fun x y -> assert false

let ( ~- ) : 'a -> 'a -> 'a = fun x y -> assert false

let pf = Printf.printf

let epf = Printf.eprintf

let sf = Scanf.scanf

let ( |> ) x f = f x

let ( @@ ) f x = f x

module Array = ArrayLabels

module List =
  struct
    include ListLabels

    let rec repeat n a =
      if n = 0 then [] else a :: (repeat (Pervasives.( - ) n 1) a)

    let rec drop n a =
      if n = 0
      then a
      else
        (match a with
         | [] -> failwith "cannot take"
         | x :: xs -> drop (Pervasives.( - ) n 1) xs)

  end

module H = Hashtbl

let solve n arr =
  (Array.sort ~cmp: compare arr;
   let prev = ref arr.(0) in
   let cnt = ref 1L in
   let ls = ref []
   in
     (for i = 1 to Pervasives.( - ) n 1 do
        if !prev = arr.(i)
        then cnt := Int64.add !cnt 1L
        else (ls := ((!prev), (!cnt)) :: !ls; prev := arr.(i); cnt := 1L)
      done;
      ls := ((!prev), (!cnt)) :: !ls;
      let arr = Array.of_list !ls in
      let n = Array.length arr
      in
        (Array.iter arr ~f: (fun (v, c) -> epf "(%Ld, %Ld), " v c);
         epf "\n";
         let mul (x, y) = Int64.mul (x : int64) y in
         let memo = H.create 10 in
         let rec iter i =
           if i = n
           then 0L
           else
             if i = (Pervasives.( - ) n 1)
             then mul arr.(i)
             else
               if H.mem memo i
               then H.find memo i
               else
                 if
                   (Int64.sub (fst arr.(i)) 1L) =
                     (fst arr.(Pervasives.( + ) i 1))
                 then
                   (let v =
                      max
                        (Int64.add (iter (Pervasives.( + ) i 2))
                           (mul arr.(i)))
                        (iter (Pervasives.( + ) i 1))
                    in (H.add memo i v; v))
                 else
                   (let v =
                      Int64.add (mul arr.(i)) (iter (Pervasives.( + ) i 2))
                    in (H.add memo i v; v))
         in (pf "%Ld\n") @@ (iter 0))))

let () =
  sf "%d "
    (fun n ->
       let arr = Array.init n ~f: (fun _ -> sf "%Ld " (fun x -> x))
       in solve n arr)

let ( + ) : 'a -> 'a -> 'a = fun x y -> assert false

let ( * ) : 'a -> 'a -> 'a = fun x y -> assert false

let ( - ) : 'a -> 'a -> 'a = fun x y -> assert false

let ( / ) : 'a -> 'a -> 'a = fun x y -> assert false

let ( ~- ) : 'a -> 'a -> 'a = fun x y -> assert false

let pf = Printf.printf

let epf = Printf.eprintf

let sf = Scanf.scanf

let ( |> ) x f = f x

let ( @@ ) f x = f x

module Array = ArrayLabels

module List =
  struct
    include ListLabels

    let rec repeat n a =
      if n = 0 then [] else a :: (repeat (Pervasives.( - ) n 1) a)

    let rec drop n a =
      if n = 0
      then a
      else
        (match a with
         | [] -> failwith "cannot take"
         | x :: xs -> drop (Pervasives.( - ) n 1) xs)

  end

module H = Hashtbl

let solve n arr =
  (Array.sort ~cmp: compare arr;
   let prev = ref arr.(0) in
   let cnt = ref 1L in
   let ls = ref []
   in
     (for i = 1 to Pervasives.( - ) n 1 do
        if !prev = arr.(i)
        then cnt := Int64.add !cnt 1L
        else (ls := ((!prev), (!cnt)) :: !ls; prev := arr.(i); cnt := 1L)
      done;
      ls := ((!prev), (!cnt)) :: !ls;
      let arr = Array.of_list !ls in
      let n = Array.length arr
      in
        (Array.iter arr ~f: (fun (v, c) -> epf "(%Ld, %Ld), " v c);
         epf "\n";
         let mul (x, y) = Int64.mul (x : int64) y in
         let memo = H.create 10 in
         let rec iter i =
           if i = n
           then 0L
           else
             if i = (Pervasives.( - ) n 1)
             then mul arr.(i)
             else
               if H.mem memo i
               then H.find memo i
               else
                 if
                   (Int64.sub (fst arr.(i)) 1L) =
                     (fst arr.(Pervasives.( + ) i 1))
                 then
                   (let v =
                      max
                        (Int64.add (iter (Pervasives.( + ) i 2))
                           (mul arr.(i)))
                        (iter (Pervasives.( + ) i 1))
                    in (H.add memo i v; v))
                 else
                   (let v =
                      Int64.add
                        (Int64.add (mul arr.(i))
                           (mul arr.(Pervasives.( + ) i 1)))
                        (iter (Pervasives.( + ) i 2))
                    in (H.add memo i v; v))
         in (pf "%Ld\n") @@ (iter 0))))

let () =
  sf "%d "
    (fun n ->
       let arr = Array.init n ~f: (fun _ -> sf "%Ld " (fun x -> x))
       in solve n arr)

let read () = Scanf.scanf "%d " (fun n -> n)
let print score = Printf.printf "%d\n" score

let list_init n f =
    let rec loop i list =
        if i < n
        then
            let element = f(i) in
            loop (i + 1) (element :: list)
        else
            List.rev list
    in loop 0 []

let count list =
    let rec loop count acc = function
        | a :: (b :: _ as tl) -> if a = b then loop (count + 1) acc tl
                                    else loop 0 ((a, count + 1) :: acc) tl
        | [x] -> (x, count + 1) :: acc
        | [] -> []
    in List.rev (loop 0 [] list)

let multiply list = List.map (fun (x, n) -> (x, x * n)) list

let score list =
    let rec loop prev sum_if_prev_taken sum_if_prev_skipped rest =
        let sum_if_unconstrained = Pervasives.max sum_if_prev_taken sum_if_prev_skipped in
        match rest with
        | [] -> sum_if_unconstrained
        | (a, v) :: tl ->
            let sum_if_a_taken =
                if a - 1 = prev
                then
                    v + sum_if_prev_skipped
                else
                    v + sum_if_unconstrained
            in
            let sum_if_a_skipped = sum_if_unconstrained in
            loop a sum_if_a_taken sum_if_a_skipped tl
    in loop (-1) 0 0 list

let input () =
    let n = read () in
    let numbers = List.sort (Pervasives.compare) (list_init n (fun i -> read ())) in
    (numbers, n)

let solve (numbers, n) =
    let score = score (multiply (count numbers)) in
    score

let () = print (solve (input ()))

open Scanf;;
open String;;
open Printf;;

let n = bscanf Scanning.stdin "%d " (fun x -> x);;

let nn = 100000 + 2;;
let count = Array.make nn 0;;
let indx = Array.make nn 0;;
let score = Array.make nn 0;;

let p = Array.init n (fun x -> 0);;

for i=0 to n-1 do
  let  f = bscanf Scanning.stdin "%d " (fun x -> x)  in
  count.(f) <- count.(f) + f
done;;

let l = ref 1;;

for i=1 to nn-1 do
  if count.(i) > 0 then
    begin
      indx.(!l) <- i;
      l := !l + 1
    end
done;;

(* For testing
for i=1 to !l-1 do
  printf "%d %d\n" indx.(i) count.(indx.(i));
done;;
*)

score.(0) <- 0;;
score.(1) <- count.(indx.(1));;
for i=2 to !l-1 do
  let x1 = indx.(i-1) in
  let x2 = indx.(i) in
  if x2 > x1 + 1 then
    begin
      score.(i)<-score.(i+1)+count.(x2)
    end
  else
    begin
      let tscore = score.(i-2) + count.(x2) in
      if tscore > score.(i-1) then
        score.(i) <- tscore
      else
        score.(i) <- score.(i-1)
    end
done;;

print_int score.(!l-1); print_endline "";;

open Scanf;;
open String;;
open Printf;;
open Num;;

let n = bscanf Scanning.stdin "%d " (fun x -> x);;

let nn = 100000 + 2;;
let count = Array.make nn 0;;
let indx = Array.make nn 0;;
let score = Array.make nn (num_of_int 0);;

let p = Array.init n (fun x -> 0);;

for i=0 to n-1 do
  let  f = bscanf Scanning.stdin "%d " (fun x -> x)  in
  count.(f) <- count.(f) + f
done;;

let l = ref 1;;

for i=1 to nn-1 do
  if count.(i) > 0 then
    begin
      indx.(!l) <- i;
      l := !l + 1
    end
done;;

(*For testing
for i=1 to !l-1 do
  printf "%d %d\n" indx.(i) count.(indx.(i));
done;;*)

score.(0) <- num_of_int 0;;
score.(1) <- num_of_int count.(indx.(1));;
let cur_indx = ref indx.(1) in
for i=2 to !l-1 do
  let x1 = !cur_indx in
  let x2 = indx.(i) in
  if x2 > x1 + 1 then
    begin
      score.(i)<-score.(i-1)+/ (num_of_int count.(x2));
      cur_indx := indx.(i)
    end
  else
    begin
      let tscore = score.(i-2) +/ num_of_int (count.(x2)) in
      if tscore >/ score.(i-1) then
        begin
          score.(i) <- tscore;
          cur_indx := x2
        end
      else
        begin
          score.(i) <- score.(i-1);
          cur_indx := indx.(i-1)
        end
    end
done;;

print_endline (string_of_num (score.(!l-1)));;

open Scanf;;
open String;;
open Printf;;

let n = bscanf Scanning.stdin "%d " (fun x -> x);;

let nn = 100000 + 2;;
let count = Array.make nn 0;;
let indx = Array.make nn 0;;
let score = Array.make nn 0;;

let p = Array.init n (fun x -> 0);;

for i=0 to n-1 do
  let  f = bscanf Scanning.stdin "%d " (fun x -> x)  in
  count.(f) <- count.(f) + f
done;;

let l = ref 1;;

for i=1 to nn-1 do
  if count.(i) > 0 then
    begin
      indx.(!l) <- i;
      l := !l + 1
    end
done;;

(*For testing
for i=1 to !l-1 do
  printf "%d %d\n" indx.(i) count.(indx.(i));
done;;*)

score.(0) <- 0;;
score.(1) <- count.(indx.(1));;
let cur_indx = ref indx.(1) in
for i=2 to !l-1 do
  let x1 = !cur_indx in
  let x2 = indx.(i) in
  if x2 > x1 + 1 then
    begin
      score.(i)<-score.(i-1)+count.(x2);
      cur_indx := indx.(i)
    end
  else
    begin
      let tscore = score.(i-2) + count.(x2) in
      if tscore > score.(i-1) then
        begin
          score.(i) <- tscore;
          cur_indx := x2
        end
      else
        begin
          score.(i) <- score.(i-1);
          cur_indx := indx.(i-1)
        end
    end
done;;

print_int score.(!l-1); print_endline "";;


let read_int () = Scanf.bscanf Scanf.Scanning.stdib " %d " (fun x -> x)

let () =
  let n = read_int () in
  let data = Array.init n (fun i ->
      if i = 0 then read_int () mod 2
      else read_int ()
    )
  in
  let possible = ref "YES" in
  let reminder = ref 0 in
  for i = 0 to n - 1 do
    let r = data.(i) - !reminder in
    if r < 0 || i = n - 1 && r mod 2 != 0
    then possible := "NO"
    else reminder := r mod 2
  done;
  print_endline !possible

let read_nums () =
    let s = read_line () in
    let nums = List.map int_of_string (Str.split (Str.regexp " ") s) in
    nums

;;

let rec is_possible lst =
    match lst with
        | [] -> true
        | [a] -> (a mod 2 = 0)
        | a :: b :: tl -> if a < 0 then
                            false
                          else if a mod 2 = 0 then
                            is_possible (b::tl)
                          else
                            is_possible ((b-1)::tl)
;;

let main () =
    let _n = read_int () in
    let lst = read_nums () in
    if is_possible lst then
        print_string "YES\n"
    else
        print_string "NO\n"
;;

main () ;;

let read_int () = Scanf.bscanf Scanf.Scanning.stdib " %d " (fun x -> x)

let () =
  let n = read_int () in
  let data = Array.init n (fun i ->
      if i = 0 then read_int () mod 2
      else read_int ()
    )
  in
  let possible = ref "YES" in
  let init = data.(0) in
  let reminder = ref init in
  for i = 1 to n - 1 do
    let r = data.(i) - !reminder in
    if r < 0 || i = n - 1 && data.(i) mod 2 != 0
    then possible := "NO"
    else reminder := data.(i) mod 2
  done;
  print_endline !possible

let read_int () = Scanf.bscanf Scanf.Scanning.stdib " %d " (fun x -> x)

let () =
  let n = read_int () in
  let data = Array.init n (fun i ->
      if i = 0 then read_int () mod 2
      else read_int ()
    )
  in
  let possible = ref "YES" in
  let init = data.(0) in
  let reminder = ref init in
  for i = 1 to n - 1 do
    let r = data.(i) - !reminder in
    if r < 0 || i = n - 1 && data.(i) != 0
    then possible := "NO"
    else reminder := data.(i) mod 2
  done;
  print_endline !possible


open Printf
open Scanf

let rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)
let sum i j f = fold i j (fun i a -> (f i) + a) 0

let read_pair () = bscanf Scanning.stdib " %d %d " (fun x y -> (x,y))

let () =
  let (n,m) = read_pair () in

  let g = Array.make n [] in

  let add_edge u v =
    g.(u) <- v::g.(u);
    g.(v) <- u::g.(v)
  in

  for i=1 to m do
    let (u,v) = read_pair() in
    add_edge (u-1) (v-1)
  done;

  let color = Array.make n 0 in
  let bipartite = ref true in
  let visited = Array.make n false in

  let rec dfs u c =
    if visited.(u) then (
      if color.(u) <> c then bipartite := false
    ) else (
      visited.(u) <- true;
      color.(u) <- c;
      List.iter (fun v ->
	dfs v (1-c)
      ) g.(u)
    )
  in

  for u=0 to n-1 do
    if not visited.(u) then dfs u 0
  done;

  let color1 = sum 0 (n-1) (fun u -> color.(u)) in
  let color0 = n-color1 in

  if !bipartite then (

    printf "%d\n" color0;
    for i=0 to n-1 do
      if color.(i) = 0 then printf "%d " (i+1)
    done;
    print_newline();

    printf "%d\n" color1;
    for i=0 to n-1 do
      if color.(i) = 1 then printf "%d " (i+1)
    done;
    print_newline()
  ) else (
    printf "-1\n"
  )

exception GameOver

type owner = Nobody | Pari | Arya

let () =
  match read_line () |> Str.(split (regexp " ")) |> List.map int_of_string with
  | [n; m] -> (
    let adj = Array.make n [] in
    for i = 1 to m do
      match read_line () |> Str.(split (regexp " ")) |> List.map int_of_string with
      | [u; v] ->
         let u = u-1
         and v = v-1 in
         adj.(u) <- v :: adj.(u);
         adj.(v) <- u :: adj.(v)
      | _ -> assert false
    done;

    let own = Array.make n Nobody in
    let rec give who v =
      let other =
        match who with
        | Pari -> Arya
        | Arya -> Pari
        | Nobody -> assert false
      in
      if own.(v) == Nobody then (
        own.(v) <- who;
        List.iter (give other) adj.(v)
      )
      else if own.(v) == other then (
         raise GameOver
      )
    and print who =
      print_int (Array.fold_left (fun count x -> if x == who then count + 1 else count) 0 own);
      print_newline ();
      for i = 0 to n - 1 do
        if own.(i) == who then (
          print_int (i+1);
          print_char ' ';
        )
      done;
      print_newline ();
    in
    try
      for v = 0 to n - 1 do
        if own.(v) == Nobody then
          give Pari v;
      done;
      print Pari;
      print Arya
    with
      GameOver -> print_endline "-1"
  )
  | _ -> assert false

exception GameOver

type owner = Nobody | Pari | Arya

let () =
  match read_line () |> Str.(split (regexp " ")) |> List.map int_of_string with
  | [n; m] -> (
    let adj = Array.make n [] in
    for i = 1 to m do
      match read_line () |> Str.(split (regexp " ")) |> List.map int_of_string with
      | [u; v] ->
         let u = u-1
         and v = v-1 in
         adj.(u) <- v :: adj.(u);
         adj.(v) <- u :: adj.(v)
      | _ -> assert false
    done;

    let own = Array.make n Nobody in
    let rec give who v =
      let other =
        match who with
        | Pari -> Arya
        | Arya -> Pari
        | Nobody -> assert false
      in
      if own.(v) == Nobody then (
        own.(v) <- who;
        List.iter (give other) adj.(v)
      )
      else if own.(v) == other then (
         raise GameOver
      )
    and print who =
      print_int (Array.fold_left (fun count x -> if x == who then count + 1 else count) 0 own);
      print_newline ();
      for i = 0 to n - 1 do
        if own.(i) == who then (
          print_int (i+1);
          print_char ' ';
        )
      done;
      print_newline ();
    in
    try
      give Pari 0;
      print Pari;
      print Arya
    with
    | GameOver -> print_endline "-1"
  )
  | _ -> assert false


open Big_int;;

let (</) x y = compare_big_int x y < 0;;
let (+/) = add_big_int;;
let (-/) = sub_big_int;;
let ( */ ) = mult_big_int;;
let ( // ) = div_big_int;;

let dwa = big_int_of_int 2;;
let jeden = unit_big_int;;
let zero = zero_big_int;;

let rec potegi a x n =
if n </ x then a
else potegi (a+/x) ((big_int_of_int 2)*/x) n;;

let wynik n = Printf.printf "%s\n" ( string_of_big_int ( n */ (n +/ jeden) //dwa -/
  dwa */(potegi zero jeden n) ) );;

let rec licz n a =
if n = 0 then a
else licz (n-1) ( wynik ( big_int_of_int ( read_int () ) ) );;

let funkcja x = licz x (Printf.printf "");;

let test x = licz 0 (Printf.printf " 5");;

funkcja ( read_int () );;

open Big_int

let (+|) = add_big_int
let (-|) = sub_big_int
let ( *| ) = mult_big_int
let (/|) = div_big_int
let bmod = mod_big_int
let (=|) = eq_big_int
let (/=|) a b = not (a =| b)
let (>|) = gt_big_int
let (<|) = lt_big_int
let (>=|) = ge_big_int
let (<=|) = le_big_int

let n0 = zero_big_int
let n1 = unit_big_int
let n2 = big_int_of_int 2

let _ =
  let sb = Scanf.Scanning.stdib in
  let t = Scanf.bscanf sb "%d " (fun s -> s) in
    for ca = 1 to t do
      let n = Scanf.bscanf sb "%d " (fun s -> s) in
      let p =
	let p = ref 0 in
	let n = ref n in
	  while !n > 1 do
	    incr p;
	    n := !n / 2;
	  done;
	  !p
      in
      let nn = big_int_of_int n in
      let res = nn *| (nn +| n1) /| n2 in
      let res = res -| power_int_positive_int 2 (p + 2) +| n2 in
	Printf.printf "%s\n" (string_of_big_int res)
    done

let rec potegi a x n =
if n < x then a
else potegi (a+x) (2*x) n;;

let wynik n = n*(n+1)/2 - (potegi 0 1 n);;
let rec licz n =
if n > 0 then licz (n-1)
else Printf.printf "\n";
Printf.printf "%d\n" ( Scanf.bscanf Scanf.Scanning.stdin "%d" wynik );;

let rec potegi a x n =
if n < x then a
else potegi (a+x) (2*x) n;;

let wynik n = n*(n+1)/2 - (potegi 0 1 n);;
let rec licz n =
if n = 0 then Printf.printf "\n"
else
Printf.printf "%d\n" ( Scanf.bscanf Scanf.Scanning.stdin "%d" wynik ); licz(n-1);;

let rec potegi a x n =
if n < x then a
else potegi (a+x) (2*x) n;;

let wynik n = Printf.printf "%d\n" ( n*(n+1)/2 - (potegi 0 1 n) );;

let rec licz n a =
if n = 1 then a
else licz (n-1) ( wynik ( read_int () ) );;

let funkcja x = licz x (Printf.printf "");;

let test x = licz 0 (Printf.printf " 5");;

 funkcja ( read_int () );;

let rec potegi a x n =
if n < x then a
else potegi (a+x) (2*x) n;;

let wynik n = n*(n+1)/2 - (potegi 0 1 n);;

Printf.printf "%d" ( Scanf.bscanf Scanf.Scanning.stdin "%d" wynik );;

let rec potegi a x n =
if n < x then a
else potegi (a+x) (2*x) n;;

let wynik n = Printf.printf "%d\n" ( n*(n+1)/2 - (potegi 0 1 n) );;

let rec licz n a =
if n = 0 then a
else licz (n-1)
(Scanf.bscanf Scanf.Scanning.stdin "%d\n" wynik );;

let funkcja x = licz x (Printf.printf "");;

let test x = licz 0 (Printf.printf " 5");;

 test ( read_int () );;

let rec potegi a x n =
if n < x then a
else potegi (a+x) (2*x) n;;

let wynik n = Printf.printf "%d\n" ( n*(n+1)/2 - (potegi 0 1 n) );;

let rec licz n a =
if n = 0 then a
else licz (n-1)
(Scanf.bscanf Scanf.Scanning.stdin "%d" wynik );;

let funkcja x = licz x (Printf.printf "");;

Scanf.bscanf Scanf.Scanning.stdin "%d" licz;;

let rec potegi a x n =
if n < x then a
else potegi (a+x) (2*x) n;;

let wynik n = Printf.printf "%d\n" ( n*(n+1)/2 - (potegi 0 1 n) );;

let rec licz n a =
if n <= 0 then a
else licz (n-1)
(Scanf.bscanf Scanf.Scanning.stdin "%d" wynik );;

let funkcja x = licz x (Printf.printf "5");;

let test x = licz 0 (Printf.printf " 5");;

Scanf.bscanf Scanf.Scanning.stdin "%d" test;;


(* this is customized splay tree code for storing a set of disjoint intervals *)

type tree = Empty
  | Node of tree * (int * int) * tree * (int * int)
(*          left       item      right  (total length * depth *)
type direction = Left | Right
type path = Item of tree * direction

let size tree = match tree with Empty -> 0 | Node(_, _, _, (size,_)) -> size
let depth tree = match tree with Empty -> 0 | Node(_, _, _, (_,depth)) -> depth

let getroot = function
  | Node(left, k, right, _) -> (left, k, right)
  | _ -> failwith "called getroot on Empty"

let newNode (l, (lo,hi), r) = Node(l, (lo,hi), r,
				   ((size l) + (size r) + (hi-lo+1),
				    1 + max (depth l) (depth r)))

let splay t p =
  (* The following splay function takes as input the currently splayed
     tree (so far) t, and a path list.  It takes two steps up, and calls
     itself recursively.  *)
  let rec rsplay = function
    | (t,[]) -> t
    | (Node(tL,tK,tR,_), Item(Node(_, bK, bR,_), Left)::(Item(Node(_, cK, cR, _), Left)::tail)) ->
	rsplay (newNode(tL,tK,newNode(tR,bK,newNode(bR,cK,cR))), tail)

    | (Node(tL,tK,tR,_), Item(Node(bL, bK, _,_), Right)::(Item(Node(cL, cK,_,_), Right)::tail)) ->
        rsplay (newNode(newNode(newNode(cL,cK,bL), bK, tL),tK,tR), tail)

    | (Node(tL,tK,tR,_), Item(Node(_, bK, bR,_), Left)::tail) ->
	rsplay (newNode(tL,tK,newNode(tR,bK,bR)), tail)

    | (Node(tL,tK,tR,_), Item(Node(bL, bK, _,_), Right)::tail) ->
	rsplay (newNode(newNode(bL,bK,tL),tK,tR), tail)

    | (_,_) -> failwith "Splay_failed (Should not happen)"
  in

  let rec build_path t path =
    match t with
      | Empty -> failwith "failed build_path"
      | Node(left, (lo,hi), right, _) ->
	  if p < lo && left<>Empty then build_path left (Item(t, Left)::path)
	  else if p > hi && right<>Empty then build_path right (Item(t, Right)::path)
	  else (t,path)
  in

    if t=Empty then Empty else
      rsplay (build_path t [])

let splaydeep t =
  let rec find_deepest = function
    | Node(Empty, (lo,_), Empty, _) -> lo
    | Node(left, _, right, _) ->
	find_deepest (if depth left >= depth right then left else right)
    | Empty -> failwith "find_deepest called with Empty"

  in
    if t=Empty then t else splay t (find_deepest t)

let split_l t l =
  (* split the list of segments in two.  Find the leftmost segment
     whose left endpoint is >= l.  That is the right part of my split. *)
  if t=Empty then (Empty,Empty) else
    let (left, (lo,hi), right) = getroot (splay t l) in
    let put_on_left =
      if lo <= l && l <= hi then lo < l
      else if l < lo then false else true
    in
      if put_on_left
      then (newNode(left, (lo,hi), Empty), right)
      else (left, newNode(Empty,(lo,hi),right))

let split_r t r =
  (* split the list of segments in two.  Find the rightmost segment
     whose right endpoint is <= r.  That is the left part of my split. *)
  if t=Empty then (Empty,Empty) else
    let (left, (lo,hi), right) = getroot (splay t r) in
    let put_on_left =
      if lo <= r && r <= hi then r = hi
      else if r < lo then false else true
    in
      if put_on_left
      then (newNode(left, (lo,hi), Empty), right)
      else (left, newNode(Empty,(lo,hi),right))

let insert t (l,r) =
  (* Insert a new interval that is either contained in,
     is disjoint from, or fully contains some other intervals *)
  if t=Empty then newNode (Empty,(l,r),Empty) else
    let t = splay t l in
    let (left, (lo,hi), right) = getroot t in
      if lo <= l && r <= hi then t else  (* new interval contained *)
	let (s1,s23) = split_l t l in
	let (s2,s3) = split_r s23 r in
	  newNode(s1,(l,r),s3)

(**************************************************************************)

let read_int () = Scanf.bscanf Scanf.Scanning.stdib " %d " (fun x -> x)
let read_pair () = let u = read_int()-1 in (u, read_int()-1)

let () =
  let n = read_int() in
  let m = read_int() in
  let edges = Array.make n [] in
  let () = for i=0 to n-2 do
    let (u,v) = read_pair() in
      edges.(u) <- v::edges.(u);
      edges.(v) <- u::edges.(v)
  done in
  let update = Array.make n [] in
  let () = for i=0 to m-1 do
    let (u,v) = read_pair() in
      update.(u) <- v::update.(u);
      update.(v) <- u::update.(v)
  done in

  let pre = Array.make n (-1) in

  let rec dfspre c u = if pre.(u) >= 0 then c else (
    pre.(u) <- c;
    List.fold_left dfspre (c+1) edges.(u)
  ) in

  let _ = dfspre 0 0 in

  let () = for i=0 to n-1 do
    edges.(i) <- List.filter (fun e -> pre.(e) > pre.(i)) edges.(i)
      (* Edge from parent to child increases pre.()
	 keep edges from parent to child *)
  done in

  let mpre = Array.make n (-1) in  (* max preorder number in the subtree rooted here *)

  let rec dfsmpre c u =
    let c = List.fold_left dfsmpre c edges.(u) in
      mpre.(u) <- max c pre.(u);
      mpre.(u)
  in

  let _ = dfsmpre 0 0 in

  let count = Array.make n 0 in  (* our answer *)

  let rec solve u t = (* u is a node, t is a tree of intervals inherited from the parent of u *)
    let nt = if update.(u) = [] then t else insert t (pre.(u), mpre.(u)) in
    let nt = List.fold_left (
      fun t v -> insert t (pre.(v), mpre.(v))
    ) nt update.(u)
    in

    let rec logint i ac = if i=0 then ac else logint (i/2) (1::ac) in
    let nt = List.fold_left (fun t _ -> splaydeep t) nt (logint (List.length edges.(u)) []) in

(*    let nt = List.fold_left (fun t _ -> splaydeep t) nt edges.(u) in *)
      List.iter (fun v -> solve v nt) edges.(u);
      count.(u) <- size nt;
  in

    solve 0 Empty;

    for i=0 to n-1 do
      Printf.printf "%d " (if count.(i)>0 then count.(i)-1 else 0)
    done;
    print_newline()

(* this is customized splay tree code for storing a set of disjoint intervals *)

type tree = Empty
  | Node of tree * (int * int) * tree * (int * int)
(*          left       item      right  (total length * depth *)
type direction = Left | Right
type path = Item of tree * direction

let size tree = match tree with Empty -> 0 | Node(_, _, _, (size,_)) -> size
let depth tree = match tree with Empty -> 0 | Node(_, _, _, (_,depth)) -> depth

let getroot = function
  | Node(left, k, right, _) -> (left, k, right)
  | _ -> failwith "called getroot on Empty"

let newNode (l, (lo,hi), r) = Node(l, (lo,hi), r,
				   ((size l) + (size r) + (hi-lo+1),
				    1 + max (depth l) (depth r)))

let splay t p =
  (* The following splay function takes as input the currently splayed
     tree (so far) t, and a path list.  It takes two steps up, and calls
     itself recursively.  *)
  let rec rsplay = function
    | (t,[]) -> t
    | (Node(tL,tK,tR,_), Item(Node(_, bK, bR,_), Left)::(Item(Node(_, cK, cR, _), Left)::tail)) ->
	rsplay (newNode(tL,tK,newNode(tR,bK,newNode(bR,cK,cR))), tail)

    | (Node(tL,tK,tR,_), Item(Node(bL, bK, _,_), Right)::(Item(Node(cL, cK,_,_), Right)::tail)) ->
        rsplay (newNode(newNode(newNode(cL,cK,bL), bK, tL),tK,tR), tail)

    | (Node(tL,tK,tR,_), Item(Node(_, bK, bR,_), Left)::tail) ->
	rsplay (newNode(tL,tK,newNode(tR,bK,bR)), tail)

    | (Node(tL,tK,tR,_), Item(Node(bL, bK, _,_), Right)::tail) ->
	rsplay (newNode(newNode(bL,bK,tL),tK,tR), tail)

    | (_,_) -> failwith "Splay_failed (Should not happen)"
  in

  let rec build_path t path =
    match t with
      | Empty -> failwith "failed build_path"
      | Node(left, (lo,hi), right, _) ->
	  if p < lo && left<>Empty then build_path left (Item(t, Left)::path)
	  else if p > hi && right<>Empty then build_path right (Item(t, Right)::path)
	  else (t,path)
  in

    if t=Empty then Empty else
      rsplay (build_path t [])

let splaydeep t =
  let rec find_deepest = function
    | Node(Empty, (lo,_), Empty, _) -> lo
    | Node(left, _, right, _) ->
	find_deepest (if depth left >= depth right then left else right)
    | Empty -> failwith "find_deepest called with Empty"

  in
    if t=Empty then t else splay t (find_deepest t)

let split_l t l =
  (* split the list of segments in two.  Find the leftmost segment
     whose left endpoint is >= l.  That is the right part of my split. *)
  if t=Empty then (Empty,Empty) else
    let (left, (lo,hi), right) = getroot (splay t l) in
    let put_on_left =
      if lo <= l && l <= hi then lo < l
      else if l < lo then false else true
    in
      if put_on_left
      then (newNode(left, (lo,hi), Empty), right)
      else (left, newNode(Empty,(lo,hi),right))

let split_r t r =
  (* split the list of segments in two.  Find the rightmost segment
     whose right endpoint is <= r.  That is the left part of my split. *)
  if t=Empty then (Empty,Empty) else
    let (left, (lo,hi), right) = getroot (splay t r) in
    let put_on_left =
      if lo <= r && r <= hi then r = hi
      else if r < lo then false else true
    in
      if put_on_left
      then (newNode(left, (lo,hi), Empty), right)
      else (left, newNode(Empty,(lo,hi),right))

let insert t (l,r) =
  (* Insert a new interval that is either contained in,
     is disjoint from, or fully contains some other intervals *)
  if t=Empty then newNode (Empty,(l,r),Empty) else
    let t = splay t l in
    let (left, (lo,hi), right) = getroot t in
      if lo <= l && r <= hi then t else  (* new interval contained *)
	let (s1,s23) = split_l t l in
	let (s2,s3) = split_r s23 r in
	  newNode(s1,(l,r),s3)

(**************************************************************************)

let read_int () = Scanf.bscanf Scanf.Scanning.stdib " %d " (fun x -> x)
let read_pair () = let u = read_int()-1 in (u, read_int()-1)

let () =
  let n = read_int() in
  let m = read_int() in
  let edges = Array.make n [] in
  let () = for i=0 to n-2 do
    let (u,v) = read_pair() in
      edges.(u) <- v::edges.(u);
      edges.(v) <- u::edges.(v)
  done in
  let update = Array.make n [] in
  let () = for i=0 to m-1 do
    let (u,v) = read_pair() in
      update.(u) <- v::update.(u);
      update.(v) <- u::update.(v)
  done in

  let pre = Array.make n (-1) in

  let rec dfspre c u = if pre.(u) >= 0 then c else (
    pre.(u) <- c;
    List.fold_left dfspre (c+1) edges.(u)
  ) in

  let _ = dfspre 0 0 in

  let () = for i=0 to n-1 do
    edges.(i) <- List.filter (fun e -> pre.(e) > pre.(i)) edges.(i)
      (* Edge from parent to child increases pre.()
	 keep edges from parent to child *)
  done in

  let mpre = Array.make n (-1) in  (* max preorder number in the subtree rooted here *)

  let rec dfsmpre c u =
    let c = List.fold_left dfsmpre c edges.(u) in
      mpre.(u) <- max c pre.(u);
      mpre.(u)
  in

  let _ = dfsmpre 0 0 in

  let count = Array.make n 0 in  (* our answer *)

  let rec solve u t = (* u is a node, t is a tree of intervals inherited from the parent of u *)
    let nt = if update.(u) = [] then t else insert t (pre.(u), mpre.(u)) in
    let nt = List.fold_left (
      fun t v -> insert t (pre.(v), mpre.(v))
    ) nt update.(u)
    in

(*
    let rec logint i ac = if i=0 then ac else logint (i/2) (1::ac) in
    let nt = List.fold_left (fun t _ -> splaydeep t) nt (logint (List.length edges.(u)) []) in
*)

    let nt = List.fold_left (fun t _ -> splaydeep t) nt edges.(u) in
      List.iter (fun v -> solve v nt) edges.(u);
      count.(u) <- size nt;
  in

    solve 0 Empty;

    for i=0 to n-1 do
      Printf.printf "%d " (if count.(i)>0 then count.(i)-1 else 0)
    done;
    print_newline()


let s = read_line ();;
let sx = List.map int_of_string (Str.split (Str.regexp " +") s);;
let n = List.hd sx;;
let m = List.hd (List.tl sx);;

let a = Array.make n "";;

for i = 0 to (n - 1) do
	a.(i) <- read_line ();
done;;

let rec proc (e: bool array) = function
| j when j = m -> 0
| j ->
	let e' = Array.copy e in
	(*print_newline(Array.iter (fun x -> print_string (if x then "true  " else "false ")) e);*)
	let rec aux = function
	| i when i = n -> proc e' (j+1)
	| i ->
		if (e.(i) && a.(i).[j] < a.(i-1).[j]) then
			1 + proc e (j+1)
		else
			(e'.(i) <- e'.(i) && a.(i).[j] = a.(i-1).[j];
			aux (i+1)) in
	aux 1;;

print_newline (print_int (proc (Array.make n true) 0));;
(*print_newline (print_int (Array.fold_left (fun a x -> if x then 0 else 1) 0 e));;*)

exception Invalid_input

type status =
  | Stable
  | Safe

let (|>) x f = f x

let rec make_list = fun len f ->
  if len = 0 then
    []
  else
    f () :: make_list (len - 1) f

let rec prepend_list_to_list_of_list = fun li acc ->
  match li, acc with
  | h1 :: t1, h2 :: t2 -> (h1 :: h2) :: (prepend_list_to_list_of_list t1 t2)
  | _ -> acc

let string_to_list = fun s ->
  let len = String.length s in
  let rec do_string_to_list = fun s i ->
    if i < len then
      s.[i] :: do_string_to_list s (i + 1)
    else
      []
  in
  do_string_to_list s 0

let read_input = fun n m ->
  let rec do_read_input = fun i acc ->
    if i < n then
      let current_line =
        read_line ()
        |> string_to_list
      in
      prepend_list_to_list_of_list current_line acc
      |> do_read_input (i + 1)
    else
      acc
  in
  make_list m (fun () -> [])
  |> do_read_input 0

let process_one_column = fun status chars ->
  let rec need_to_remove = fun s_list c_list ->
    match s_list, c_list with
    | h1 :: (m1 :: t1 as p1), h2 :: (m2 :: t2 as p2) ->
      if h1 = Stable && h2 < m2 then
        true
      else
        need_to_remove p1 p2
    | _ ->
      false
  in
  if need_to_remove status chars then
    status, true
  else
    let rec get_new_status = fun s_list c_list ->
      match s_list, c_list with
      | h1 :: (m1 :: t1 as p1), h2 :: (m2 :: t2 as p2) ->
        let new_s =
          if h1 = Safe || m2 < h2 then
            Safe
          else
            Stable
        in
        new_s :: get_new_status p1 p2
      | hd :: [], _ ->
        [hd]
      | _ ->
        raise Invalid_input
    in
    (get_new_status status chars), false

let process_all_columns = fun n input ->
  let initial = make_list n (fun () -> Stable) in
  let rec do_process = fun status count input ->
    match input with
    | hd :: tl ->
      let new_status, removed = process_one_column status hd in
      let new_count = if removed then count + 1 else count in
      do_process new_status new_count tl
    | _ ->
      count
  in
  do_process initial 0 input

let () =
  let (n, m) =
    read_line ()
    |> Str.split (Str.regexp " +")
    |> List.map int_of_string
    |> fun li ->
        match li with
        | a :: [b] -> (a, b)
        | _ -> raise Invalid_input
  in
  let input = read_input n m in
  process_all_columns n input
  |> print_int
  |> print_newline

let s = read_line ();;
let sx = List.map int_of_string (Str.split (Str.regexp " +") s);;
let n = List.hd sx;;
let m = List.hd (List.tl sx);;

let a = Array.make n "";;

for i = 0 to (n - 1) do
	a.(i) <- read_line ();
done;;

let rec proc (e: bool array) = function
| j when j = m -> 0
| j ->
	let e' = Array.copy e in

	let rec aux = function
	| i when i = n -> proc e' (j+1)
	| i ->
		if (e.(i) && a.(i).[j] < a.(i-1).[j]) then
			1 + proc e (j+1)
		else
			(e'.(i) <- a.(i).[j] = a.(i-1).[j];
			aux (i+1)) in
	aux 1;;

print_newline (print_int (proc (Array.make n true) 0));;
(*print_newline (print_int (Array.fold_left (fun a x -> if x then 0 else 1) 0 e));;*)

exception Invalid_input

type status =
  | Stable
  | Safe

let (|>) x f = f x

let rec make_list = fun len f ->
  if len = 0 then
    []
  else
    f () :: make_list (len - 1) f

let rec prepend_list_to_list_of_list = fun li acc ->
  match li, acc with
  | h1 :: t1, h2 :: t2 -> (h1 :: h2) :: (prepend_list_to_list_of_list t1 t2)
  | _ -> acc

let string_to_list = fun s ->
  let len = String.length s in
  let rec do_string_to_list = fun s i ->
    if i < len then
      s.[i] :: do_string_to_list s (i + 1)
    else
      []
  in
  do_string_to_list s 0

let read_input = fun n m ->
  let rec do_read_input = fun i acc ->
    if i < n then
      let current_line =
        read_line ()
        |> string_to_list
      in
      prepend_list_to_list_of_list current_line acc
      |> do_read_input (i + 1)
    else
      acc
  in
  make_list m (fun () -> [])
  |> do_read_input 0

let process_one_column = fun status chars ->
  let rec need_to_remove = fun s_list c_list ->
    match s_list, c_list with
    | h1 :: (m1 :: t1 as p1), h2 :: (m2 :: t2 as p2) ->
      if h1 = Stable && h2 < m2 then
        true
      else
        need_to_remove p1 p2
    | _ ->
      false
  in
  if need_to_remove status chars then
    status, true
  else
    let rec get_new_status = fun s_list c_list ->
      match s_list, c_list with
      | h1 :: (m1 :: t1 as p1), h2 :: (m2 :: t2 as p2) ->
        let new_s =
          if h1 = Safe || m2 < h2 then
            Safe
          else
            Stable
        in
        new_s :: get_new_status p1 p2
      | _ ->
        []
    in
    (get_new_status status chars), false

let process_all_columns = fun n input ->
  let initial = make_list n (fun () -> Stable) in
  let rec do_process = fun status count input ->
    match input with
    | hd :: tl ->
      let new_status, removed = process_one_column status hd in
      let new_count = if removed then count + 1 else count in
      do_process new_status new_count tl
    | _ ->
      count
  in
  do_process initial 0 input

let () =
  let (n, m) =
    read_line ()
    |> Str.split (Str.regexp " +")
    |> List.map int_of_string
    |> fun li ->
        match li with
        | a :: [b] -> (a, b)
        | _ -> raise Invalid_input
  in
  let input = read_input n m in
  process_all_columns n input
  |> print_int
  |> print_newline

exception Invalid_input

type status =
  | Stable
  | Safe

let (|>) x f = f x

let rec make_list = fun len f ->
  if len = 0 then
    []
  else
    f () :: make_list (len - 1) f

let rec prepend_list_to_list_of_list = fun li acc ->
  match li, acc with
  | h1 :: t1, h2 :: t2 -> (h1 :: h2) :: (prepend_list_to_list_of_list t1 t2)
  | _ -> acc

let string_to_list = fun s ->
  let len = String.length s in
  let rec do_string_to_list = fun s i ->
    if i < len then
      s.[i] :: do_string_to_list s (i + 1)
    else
      []
  in
  do_string_to_list s 0

let read_input = fun n m ->
  let rec do_read_input = fun i acc ->
    if i < n then
      let current_line =
        read_line ()
        |> string_to_list
      in
      prepend_list_to_list_of_list current_line acc
      |> do_read_input (i + 1)
    else
      acc
  in
  make_list m (fun () -> [])
  |> do_read_input 0

let process_one_column = fun status chars ->
  let rec need_to_remove = fun s_list c_list ->
    match s_list, c_list with
    | h1 :: (m1 :: t1 as p1), h2 :: (m2 :: t2 as p2) ->
      if h1 = Stable && h2 < m2 then
        true
      else
        need_to_remove p1 p2
    | _ ->
      false
  in
  if need_to_remove status chars then
    status, true
  else
    let rec get_new_status = fun s_list c_list ->
      match s_list, c_list with
      | h1 :: (m1 :: t1 as p1), h2 :: (m2 :: t2 as p2) ->
        let new_s =
          if h1 = Stable && m2 < h2 then
            Safe
          else
            Stable
        in
        new_s :: get_new_status p1 p2
      | _ ->
        []
    in
    (get_new_status status chars), false

let process_all_columns = fun n input ->
  let initial = make_list n (fun () -> Stable) in
  let rec do_process = fun status count input ->
    match input with
    | hd :: tl ->
      let new_status, removed = process_one_column status hd in
      let new_count = if removed then count + 1 else count in
      do_process new_status new_count tl
    | _ ->
      count
  in
  do_process initial 0 input

let () =
  let (n, m) =
    read_line ()
    |> Str.split (Str.regexp " +")
    |> List.map int_of_string
    |> fun li ->
        match li with
        | a :: [b] -> (a, b)
        | _ -> raise Invalid_input
  in
  let input = read_input n m in
  process_all_columns n input
  |> print_int
  |> print_newline


(* Codeforces 492B VaniaFonari *)

open List;;
open String;;
open Array;;
open Int64;;

let gr () = Scanf.scanf " %d" (fun i -> i);;
let grf () = Scanf.scanf " %f" (fun i -> i);;
let grl () = Scanf.scanf " %Ld" (fun i -> i);;
let rdln() = input_line Pervasives.stdin;;
(* let spli s = Str.split (Str.regexp " ") s;; *)
let printlisti li = List.iter (fun i -> (print_int i; print_string " ")) li;;
let printarri ai = Array.iter (fun i -> (print_int i; print_string " ")) ai;;
let printarri64 ai = Array.iter (fun i -> (print_string (Int64.to_string i); print_string " ")) ai;;

let rec readlist n acc = match n with
	| 0 -> acc
	| _ -> readlist (n - 1) (gr() :: acc);;

let miscomp a b = a - b;;

let rec maxdif dif l = match l with
| a :: b :: tl ->
	let d = b - a in
	let dd = if d>dif then d else dif in
	maxdif dd (b :: tl)
| _ -> dif;;

let main () =
	let n = gr () in
	let l = gr () in
	let aal : int list = readlist n [] in
	let aso : int list = List.sort miscomp (l :: aal) in
	let d0 = maxdif 0 (0 :: aso) in
	let f0 = ((float_of_int d0) /. 2.0) in
	let d1 = float_of_int (List.nth aso 0) in
	let d2 = float_of_int (l - (List.nth aso (n-1))) in
	let d = max f0 (max d1 d2) in
	begin
	  print_float d
	end;;

main();;

let read () = Scanf.scanf "%d " (fun n -> n)

let input () =
    let n = read () in
    let length = float (read ()) in
    let rec loop list i =
        if i < n
        then
            let var = float (read ()) in
            loop (var :: list) (i + 1)
        else
            (length, list)
    in loop [] 0

let get_max head prev max =
    if prev = float (-1)
    then
        Pervasives.max head max
    else
        Pervasives.max ((head -. prev) /. (float 2)) max

let solve (length, list) =
    let lampposts = List.sort (Pervasives.compare) list in
    let d_start = 0.0 -. List.hd lampposts in
    let d_end = length -. List.hd (List.rev lampposts) in
    let d_min = Pervasives.max d_start d_end in

    let rec loop rest prev max =
        match rest with
        | (head :: tail) -> loop tail head (get_max head prev max)
        | [] -> Pervasives.max d_min max
    in loop lampposts (float (-1)) (float 0)

let print result = Printf.printf "%.10f\n" result
let () = print (solve (input ()))

(* Codeforces 349 A Cinema Line done *)

(* you can use either gr or rdln but not both *)
let gr () = Scanf.scanf " %d" (fun i -> i);;
let grf () = Scanf.scanf " %f" (fun i -> i);;
let grl () = Scanf.scanf " %Ld" (fun i -> i);;
let grc () = Scanf.scanf " %c" (fun i -> i);;
let rdln() = input_line stdin;;
(* let spli s = Str.split (Str.regexp " ") s;; *)
let printlisti li = List.iter (fun i -> (print_int i; print_string " ")) li;;
let printarri ai = Array.iter (fun i -> (print_int i; print_string " ")) ai;;
let debug = false;;

let rec readlist n acc = match n with
	| 0 -> acc
	| _ -> readlist (n -1) (gr() :: acc);;
let printlisti li = List.iter (fun i -> (print_int i; print_string " ")) li;;

let rec minrad l d len = match l with
| [] -> d
| h :: [] -> max d (float_of_int (len - h))
| h :: t ->
	let dd = (float_of_int ((List.hd t) - h)) /. 2.0 in
	let dd = max dd d in
	minrad t dd len;;

let main() =
	let n = gr() in
	let len = gr() in
	let ll = readlist n [] in
	let li = List.rev ll in
	let sol = List.sort_uniq compare li in
	let dinit = float_of_int (List.hd sol) in
	let rad = minrad sol dinit len in
	begin
		Printf.printf "%.2f\n" rad
	end;;

main();;

open Str

let print_tuple = fun tuple ->
  let (x, y) = tuple in
  Printf.printf "%d %d\n" x y

let rec print_list = fun l ->
  match l with
  | hd :: tl ->
    print_int hd;
    print_char ' ';
    print_list tl;
  | _ -> ()

let rec find_max_gap = fun l cur_max ->
  match l with
  | hd :: mid :: tl ->
    let diff = mid - hd in
    if diff < cur_max then
      find_max_gap (mid :: tl) cur_max
    else
      find_max_gap (mid :: tl) diff
  | _ -> cur_max

let rec get_last = fun l ->
  match l with
  | [x] ->
    Some x
  | _ :: tl ->
    get_last tl
  | _ -> None

exception Invalid_input

let find_max_gap_including_head_and_tail = fun l e ->
  match get_last l with
  | Some last ->
    List.hd (List.fast_sort (fun i j ->
      if i < j then
        1
      else
        -1
    ) ([(float_of_int (List.hd l)); (float_of_int (e - last)); (float_of_int (find_max_gap l 0)) /. 2.0])
    )
  | None -> raise Invalid_input

let () =
  let (num_of_lanterns, len_of_street) = (fun line ->
    match line with
    | hd :: tl -> (int_of_string hd, int_of_string (List.hd tl))
    | _ -> raise Invalid_input
  ) (Str.split (Str.regexp " +") (read_line ()))
  in
  let lanterns = List.fast_sort (fun i j ->
    i - j
  ) (List.map int_of_string (Str.split (Str.regexp " +") (read_line ())))
  in
  print_float (find_max_gap_including_head_and_tail lanterns len_of_street);
  print_newline ()

(* Codeforces 492B VaniaFonari *)

open List;;
open String;;
open Array;;
open Int64;;

let gr () = Scanf.scanf " %d" (fun i -> i);;
let grf () = Scanf.scanf " %f" (fun i -> i);;
let grl () = Scanf.scanf " %Ld" (fun i -> i);;
let rdln() = input_line Pervasives.stdin;;
(* let spli s = Str.split (Str.regexp " ") s;; *)
let printlisti li = List.iter (fun i -> (print_int i; print_string " ")) li;;
let printarri ai = Array.iter (fun i -> (print_int i; print_string " ")) ai;;
let printarri64 ai = Array.iter (fun i -> (print_string (Int64.to_string i); print_string " ")) ai;;

let rec readlist n acc = match n with
	| 0 -> acc
	| _ -> readlist (n - 1) (gr() :: acc);;

let miscomp a b = a - b;;

let rec maxdif dif l = match l with
| a :: b :: tl ->
	let d = b - a in
	let dd = if d>dif then d else dif in
	maxdif dd (b :: tl)
| _ -> dif;;

let main () =
	let n = gr () in
	let l = gr () in
	let aal : int list = readlist n [] in
	let aso : int list = List.sort miscomp (l :: aal) in
	let df = maxdif 0 (0 :: aso) in
	begin
	  print_float ((float_of_int df) /. 2.0)
	end;;

main();;


open Printf open Scanf
module Lib = struct
  let i32,i64,ist = Int64.(to_int,of_int,to_string)
  let (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (%$) = (mod)
  let labs = Int64.abs
  let (+),(-),( * ),(/),(mod),(%) = Int64.(add,sub,mul,div,rem,rem)
  let (+=) r v = r := !r + v
  let (-=) r v = r := !r - v
  let ( *= ) r v = r := !r * v
  let (/=) r v = r := !r / v
  let (%=) r v = r := !r % v
  let max_i64,min_i64 = Int64.(max_int,min_int)
  (* math *)
  let ceildiv p q = (p+q-1L) / q
  let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n)
  let lcm m n = m / gcd m n * n
  module Int64_infix = struct
    let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) =
      let open Int64 in
      (logand),(logor),(logxor),lognot,
      (fun u v -> shift_left u (i32 v)),
      (fun u v -> shift_right u (i32 v)),
      (fun u v -> shift_right_logical u (i32 v))
  end
  let pow n k =
    let rec f a n = function
    | 0L -> a | 1L -> n*a | k when k mod 2L = 0L -> f a (n*n) (k/2L) | k -> f (a*n) (n*n) (k/2L)
    in f 1L n k
  (* input *)
  let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf " %Ld" (fun v -> v)) let iia = input_i64_array
  let get_i64 _ = Scanf.scanf " %Ld" (fun v -> v) let gi = get_i64
  let get_2_i64 _ = Scanf.scanf " %Ld %Ld" (fun u v -> u,v) let g2 = get_2_i64
  let get_3_i64 _ = Scanf.scanf " %Ld %Ld %Ld" (fun u v w -> u,v,w) let g3 = get_3_i64
  let get_4_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld" (fun u v w x -> u,v,w,x) let g4 = get_4_i64
  let get_5_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld %Ld" (fun u v w x y -> u,v,w,x,y) let g5 = get_5_i64
  let i32_get_int _ = Scanf.scanf " %d" (fun v -> v) let i32_get_2_ints _ = Scanf.scanf " %d %d" (fun u v -> u,v) let i32_get_3_ints _ = Scanf.scanf " %d %d %d" (fun u v w -> u,v,w) let i32_get_4_ints _ = Scanf.scanf " %d %d %d %d" (fun u v w x -> u,v,w,x) let i32_get_5_ints _ = Scanf.scanf " %d %d %d %d %d" (fun u v w x y -> u,v,w,x,y)
  (* utils *)
  external id : 'a -> 'a = "%identity"
  let ( *< ) f g x = f (g x)
  let ( *> ) f g x = g (f x)
  let rv f p q = f q p (* ex. 24 |> rv (/) 6 *)
  let alen a = i64 @@ Array.length a
  let llen l = i64 @@  List.length l
  let slen s = String.length s
  let string_of_list ?(separator=" ") f ls = ls |> List.map f |> String.concat separator
  let string_of_array ?(separator=" ") f a = a |> Array.to_list |> string_of_list ~separator f
  let char_list_of_string str = let rec f0 i a = if i<0 then a else f0 (i-$1) (str.[i]::a) in f0 (String.length str -$ 1) []
  let string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) "" ls
  let fail _ = failwith "fail"
  let dx,dy = [|1;0;-1;0|],[|0;1;0;-1|]
  let range l r = let ls = ref [] in for i=i32 l to i32 r do ls := i :: !ls done;!ls |> List.rev
  let cartesian_product u v = u |> List.map (fun p -> List.map (fun q -> p,q) v) |> List.flatten
  let shuffle a = Array.sort (fun _ _ -> (Random.int 3) -$ 1) a
  let binary_search ng ok f = let d = if ng < ok then 1L else -1L in
    let rec f0 ng ok =
      if labs (ok - ng) <= 1L then ok
      else let mid = ng + (ok - ng) / 2L in if f mid then f0 ng mid else f0 mid ok
    in f0 (ng-1L*d) (ok+1L*d)
  let lower_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >= v)
  let upper_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >  v)
  let equal_range a v = lower_bound a v, upper_bound a v (* #=snd-fst *)
  let rec fix f x = f (fix f) x
  let fix_memo ?(size=10000) f x =
    let tb = Hashtbl.create ~random:true size in
    let rec f0 x =
      try Hashtbl.find tb x with
      | Not_found -> (let v = f f0 x in Hashtbl.add tb x v; v)
    in f0 x
  (* imperative *)
  let rep f t ?(stride=1L) fbod = let i = ref f in while !i <= t do fbod !i; i := !i + stride done
  let repb f t ?(stride=1L) fbod = let i,c = ref f,ref true in while !i <= t && !c do
    match fbod !i with | `Break -> c := false | `Ok -> i := !i + stride done
  let repm f t ?(stride=1L) m0 fbod =
    let i,c,m = ref f,ref true,ref m0 in
    while !i<=t && !c do match fbod !m !i with
    | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i + stride done; !m
  let repi f t ?(stride=1) fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ stride done
  let repib f t ?(stride=1) fbod = let i,c = ref f,ref true in while !i <= t && !c do
    match fbod !i with | `Break -> c := false | `Ok -> i := !i +$ stride done
  let repim f t ?(stride=1) m0 fbod =
    let i,c,m = ref f,ref true,ref m0 in
    while !i<=t && !c do match fbod !m !i with
    | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i +$ stride done; !m
  let rep_rev f t ?(stride=1L) fbod = rep t f ~stride @@ fun v -> fbod @@ f + t - v
  let repb_rev f t ?(stride=1L) fbod = repb t f ~stride @@ fun v -> fbod @@ f + t - v
  let repm_rev f t ?(stride=1L) m0 fbod = repm f t ~stride m0 @@ fun u v -> fbod u @@ f + t - v
  let repi_rev f t ?(stride=1) fbod = repi t f ~stride @@ fun v -> fbod @@ f +$ t -$ v
  let repib_rev f t ?(stride=1) fbod = repib t f ~stride @@ fun v -> fbod @@ f +$ t -$ v
  let repim_rev f t ?(stride=1) m0 fbod = repim f t ~stride m0 @@ fun u v -> fbod u @@ f +$ t -$ v
  (* output *)
  let print_list_mle f ls = string_of_list f ls |> print_endline
  let print_array_mle f a = string_of_array f a |> print_endline
  let print_list f ls = ls |> List.iter (fun v -> printf "%s " @@ f v); print_newline ()
  let print_array f a = a |> Array.iter (fun v -> printf "%s " @@ f v); print_newline ()
  (* debug *)
  let dump_2darr f a = a |> Array.iter (fun b -> print_array f b)
  let dump_i64_list ls = print_list ist ls
  let dump_i64_array a = print_array ist a
end open Lib open Array

let md = 998244353L
let () =
  let n = gi 0 in let n = i32 n in
  let s = scanf " %s" @@ id in
  if s.[0] = s.[n-$1] then (
    let f,c = ref true,ref 0 in
    repi 0 (n-$1) (fun i ->
      if !f && s.[i] = s.[0] then (
        c := i+$1
      ) else f := false;
    );
    (* printf "%d" !c; *)
    let p = i64 !c mod md in
    let f,c = ref true,ref 0 in
    repi_rev (n-$1) 0 (fun i ->
      if !f && s.[i] = s.[n-$1] then (
        c := n-$i
      ) else f := false;
    );
    (* printf "%d" !c; *)
    let q = i64 !c mod md in
    printf "%Ld\n" @@ (((p+1L)*(q+1L)) mod md);
  ) else (
    let f,c = ref true,ref 0 in
    repi 0 (n-$1) (fun i ->
      if !f && s.[i] = s.[0] then (
        c := i+$1
      ) else f := false;
    );
    (* printf "%d\n" !c; *)
    let p = i64 !c in
    let f,c = ref true,ref 0 in
    repi_rev (n-$1) 0 (fun i ->
      if !f && s.[i] = s.[n-$1] then (
        c := n-$i
      ) else f := false;
    );
    (* printf "%d\n" !c; *)
    let q = i64 !c in
    printf "%Ld\n" @@ ((p+1L)+(q+1L)-1L) mod md;
  )

let rec fix f x = f (fix f) x
let i64,i32 = Int64.(of_int,to_int)
let md = 998244353L
let ( **% ) p q = Int64.(rem (mul p q) md);;
Scanf.(Array.(
  let n = scanf " %d" @@ fun v -> v in
  let s = scanf " %s" @@ fun v -> v in
  let p = fix (fun f i a ->
    if s.[i] = s.[0] then f (i+1) (i::a)
    else a
  ) 0 [] |> List.length in
  let q = fix (fun f i a ->
    if s.[i] = s.[n-1] then f (i-1) (i::a)
    else a
  ) (n-1) [] |> List.length in
  if s.[0] = s.[n-1] then (
    print_int @@ i32 @@ (i64 @@ p+1) **% (i64 @@ q+1)
  ) else (
    print_int @@ i32 @@ (i64 ((p+1) + (q+1) - 1) **% 1L)
  )
))

open Printf open Scanf
module Lib = struct
  let i32,i64,ist = Int64.(to_int,of_int,to_string)
  let (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (%$) = (mod)
  let labs = Int64.abs
  let (+),(-),( * ),(/),(mod),(%) = Int64.(add,sub,mul,div,rem,rem)
  let (+=) r v = r := !r + v
  let (-=) r v = r := !r - v
  let ( *= ) r v = r := !r * v
  let (/=) r v = r := !r / v
  let (%=) r v = r := !r % v
  let max_i64,min_i64 = Int64.(max_int,min_int)
  (* math *)
  let ceildiv p q = (p+q-1L) / q
  let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n)
  let lcm m n = m / gcd m n * n
  module Int64_infix = struct
    let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) =
      let open Int64 in
      (logand),(logor),(logxor),lognot,
      (fun u v -> shift_left u (i32 v)),
      (fun u v -> shift_right u (i32 v)),
      (fun u v -> shift_right_logical u (i32 v))
  end
  let pow n k =
    let rec f a n = function
    | 0L -> a | 1L -> n*a | k when k mod 2L = 0L -> f a (n*n) (k/2L) | k -> f (a*n) (n*n) (k/2L)
    in f 1L n k
  (* input *)
  let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf " %Ld" (fun v -> v)) let iia = input_i64_array
  let get_i64 _ = Scanf.scanf " %Ld" (fun v -> v) let gi = get_i64
  let get_2_i64 _ = Scanf.scanf " %Ld %Ld" (fun u v -> u,v) let g2 = get_2_i64
  let get_3_i64 _ = Scanf.scanf " %Ld %Ld %Ld" (fun u v w -> u,v,w) let g3 = get_3_i64
  let get_4_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld" (fun u v w x -> u,v,w,x) let g4 = get_4_i64
  let get_5_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld %Ld" (fun u v w x y -> u,v,w,x,y) let g5 = get_5_i64
  let i32_get_int _ = Scanf.scanf " %d" (fun v -> v) let i32_get_2_ints _ = Scanf.scanf " %d %d" (fun u v -> u,v) let i32_get_3_ints _ = Scanf.scanf " %d %d %d" (fun u v w -> u,v,w) let i32_get_4_ints _ = Scanf.scanf " %d %d %d %d" (fun u v w x -> u,v,w,x) let i32_get_5_ints _ = Scanf.scanf " %d %d %d %d %d" (fun u v w x y -> u,v,w,x,y)
  (* utils *)
  external id : 'a -> 'a = "%identity"
  let ( *< ) f g x = f (g x)
  let ( *> ) f g x = g (f x)
  let rv f p q = f q p (* ex. 24 |> rv (/) 6 *)
  let alen a = i64 @@ Array.length a
  let llen l = i64 @@  List.length l
  let slen s = String.length s
  let string_of_list ?(separator=" ") f ls = ls |> List.map f |> String.concat separator
  let string_of_array ?(separator=" ") f a = a |> Array.to_list |> string_of_list ~separator f
  let char_list_of_string str = let rec f0 i a = if i<0 then a else f0 (i-$1) (str.[i]::a) in f0 (String.length str -$ 1) []
  let string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) "" ls
  let fail _ = failwith "fail"
  let dx,dy = [|1;0;-1;0|],[|0;1;0;-1|]
  let range l r = let ls = ref [] in for i=i32 l to i32 r do ls := i :: !ls done;!ls |> List.rev
  let cartesian_product u v = u |> List.map (fun p -> List.map (fun q -> p,q) v) |> List.flatten
  let shuffle a = Array.sort (fun _ _ -> (Random.int 3) -$ 1) a
  let binary_search ng ok f = let d = if ng < ok then 1L else -1L in
    let rec f0 ng ok =
      if labs (ok - ng) <= 1L then ok
      else let mid = ng + (ok - ng) / 2L in if f mid then f0 ng mid else f0 mid ok
    in f0 (ng-1L*d) (ok+1L*d)
  let lower_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >= v)
  let upper_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >  v)
  let equal_range a v = lower_bound a v, upper_bound a v (* #=snd-fst *)
  let rec fix f x = f (fix f) x
  let fix_memo ?(size=10000) f x =
    let tb = Hashtbl.create ~random:true size in
    let rec f0 x =
      try Hashtbl.find tb x with
      | Not_found -> (let v = f f0 x in Hashtbl.add tb x v; v)
    in f0 x
  (* imperative *)
  let rep f t ?(stride=1L) fbod = let i = ref f in while !i <= t do fbod !i; i := !i + stride done
  let repb f t ?(stride=1L) fbod = let i,c = ref f,ref true in while !i <= t && !c do
    match fbod !i with | `Break -> c := false | `Ok -> i := !i + stride done
  let repm f t ?(stride=1L) m0 fbod =
    let i,c,m = ref f,ref true,ref m0 in
    while !i<=t && !c do match fbod !m !i with
    | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i + stride done; !m
  let repi f t ?(stride=1) fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ stride done
  let repib f t ?(stride=1) fbod = let i,c = ref f,ref true in while !i <= t && !c do
    match fbod !i with | `Break -> c := false | `Ok -> i := !i +$ stride done
  let repim f t ?(stride=1) m0 fbod =
    let i,c,m = ref f,ref true,ref m0 in
    while !i<=t && !c do match fbod !m !i with
    | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i +$ stride done; !m
  let rep_rev f t ?(stride=1L) fbod = rep t f ~stride @@ fun v -> fbod @@ f + t - v
  let repb_rev f t ?(stride=1L) fbod = repb t f ~stride @@ fun v -> fbod @@ f + t - v
  let repm_rev f t ?(stride=1L) m0 fbod = repm f t ~stride m0 @@ fun u v -> fbod u @@ f + t - v
  let repi_rev f t ?(stride=1) fbod = repi t f ~stride @@ fun v -> fbod @@ f +$ t -$ v
  let repib_rev f t ?(stride=1) fbod = repib t f ~stride @@ fun v -> fbod @@ f +$ t -$ v
  let repim_rev f t ?(stride=1) m0 fbod = repim f t ~stride m0 @@ fun u v -> fbod u @@ f +$ t -$ v
  (* output *)
  let print_list_mle f ls = string_of_list f ls |> print_endline
  let print_array_mle f a = string_of_array f a |> print_endline
  let print_list f ls = ls |> List.iter (fun v -> printf "%s " @@ f v); print_newline ()
  let print_array f a = a |> Array.iter (fun v -> printf "%s " @@ f v); print_newline ()
  (* debug *)
  let dump_2darr f a = a |> Array.iter (fun b -> print_array f b)
  let dump_i64_list ls = print_list ist ls
  let dump_i64_array a = print_array ist a
end open Lib open Array

let md = 998244353
let () =
  let n = gi 0 in let n = i32 n in
  let s = scanf " %s" @@ id in
  if s.[0] = s.[n-$1] then (
    let f,c = ref true,ref 0 in
    repi 0 (n-$1) (fun i ->
      if !f && s.[i] = s.[0] then (
        c := i+$1
      ) else f := false;
    );
    (* printf "%d" !c; *)
    let p = !c %$ md in
    let f,c = ref true,ref 0 in
    repi_rev (n-$1) 0 (fun i ->
      if !f && s.[i] = s.[n-$1] then (
        c := n-$i
      ) else f := false;
    );
    (* printf "%d" !c; *)
    let q = !c %$ md in
    printf "%d\n" @@ (((p+$1)*$(q+$1)) %$ md);
  ) else (
    let f,c = ref true,ref 0 in
    repi 0 (n-$1) (fun i ->
      if !f && s.[i] = s.[0] then (
        c := i+$1
      ) else f := false;
    );
    (* printf "%d" !c; *)
    let p = !c in
    let f,c = ref true,ref 0 in
    repi_rev (n-$1) 0 (fun i ->
      if !f && s.[i] = s.[n-$1] then (
        c := n-$i
      ) else f := false;
    );
    (* printf "%d" !c; *)
    let q = !c in
    printf "%d\n" @@ ((p+$1)+$(q+$1)-$1) %$ md;
  )

open Printf open Scanf
module Lib = struct
  let i32,i64,ist = Int64.(to_int,of_int,to_string)
  let (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (%$) = (mod)
  let labs = Int64.abs
  let (+),(-),( * ),(/),(mod),(%) = Int64.(add,sub,mul,div,rem,rem)
  let (+=) r v = r := !r + v
  let (-=) r v = r := !r - v
  let ( *= ) r v = r := !r * v
  let (/=) r v = r := !r / v
  let (%=) r v = r := !r % v
  let max_i64,min_i64 = Int64.(max_int,min_int)
  (* math *)
  let ceildiv p q = (p+q-1L) / q
  let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n)
  let lcm m n = m / gcd m n * n
  module Int64_infix = struct
    let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) =
      let open Int64 in
      (logand),(logor),(logxor),lognot,
      (fun u v -> shift_left u (i32 v)),
      (fun u v -> shift_right u (i32 v)),
      (fun u v -> shift_right_logical u (i32 v))
  end
  let pow n k =
    let rec f a n = function
    | 0L -> a | 1L -> n*a | k when k mod 2L = 0L -> f a (n*n) (k/2L) | k -> f (a*n) (n*n) (k/2L)
    in f 1L n k
  (* input *)
  let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf " %Ld" (fun v -> v)) let iia = input_i64_array
  let get_i64 _ = Scanf.scanf " %Ld" (fun v -> v) let gi = get_i64
  let get_2_i64 _ = Scanf.scanf " %Ld %Ld" (fun u v -> u,v) let g2 = get_2_i64
  let get_3_i64 _ = Scanf.scanf " %Ld %Ld %Ld" (fun u v w -> u,v,w) let g3 = get_3_i64
  let get_4_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld" (fun u v w x -> u,v,w,x) let g4 = get_4_i64
  let get_5_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld %Ld" (fun u v w x y -> u,v,w,x,y) let g5 = get_5_i64
  let i32_get_int _ = Scanf.scanf " %d" (fun v -> v) let i32_get_2_ints _ = Scanf.scanf " %d %d" (fun u v -> u,v) let i32_get_3_ints _ = Scanf.scanf " %d %d %d" (fun u v w -> u,v,w) let i32_get_4_ints _ = Scanf.scanf " %d %d %d %d" (fun u v w x -> u,v,w,x) let i32_get_5_ints _ = Scanf.scanf " %d %d %d %d %d" (fun u v w x y -> u,v,w,x,y)
  (* utils *)
  external id : 'a -> 'a = "%identity"
  let ( *< ) f g x = f (g x)
  let ( *> ) f g x = g (f x)
  let rv f p q = f q p (* ex. 24 |> rv (/) 6 *)
  let alen a = i64 @@ Array.length a
  let llen l = i64 @@  List.length l
  let slen s = String.length s
  let string_of_list ?(separator=" ") f ls = ls |> List.map f |> String.concat separator
  let string_of_array ?(separator=" ") f a = a |> Array.to_list |> string_of_list ~separator f
  let char_list_of_string str = let rec f0 i a = if i<0 then a else f0 (i-$1) (str.[i]::a) in f0 (String.length str -$ 1) []
  let string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) "" ls
  let fail _ = failwith "fail"
  let dx,dy = [|1;0;-1;0|],[|0;1;0;-1|]
  let range l r = let ls = ref [] in for i=i32 l to i32 r do ls := i :: !ls done;!ls |> List.rev
  let cartesian_product u v = u |> List.map (fun p -> List.map (fun q -> p,q) v) |> List.flatten
  let shuffle a = Array.sort (fun _ _ -> (Random.int 3) -$ 1) a
  let binary_search ng ok f = let d = if ng < ok then 1L else -1L in
    let rec f0 ng ok =
      if labs (ok - ng) <= 1L then ok
      else let mid = ng + (ok - ng) / 2L in if f mid then f0 ng mid else f0 mid ok
    in f0 (ng-1L*d) (ok+1L*d)
  let lower_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >= v)
  let upper_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >  v)
  let equal_range a v = lower_bound a v, upper_bound a v (* #=snd-fst *)
  let rec fix f x = f (fix f) x
  let fix_memo ?(size=10000) f x =
    let tb = Hashtbl.create ~random:true size in
    let rec f0 x =
      try Hashtbl.find tb x with
      | Not_found -> (let v = f f0 x in Hashtbl.add tb x v; v)
    in f0 x
  (* imperative *)
  let rep f t ?(stride=1L) fbod = let i = ref f in while !i <= t do fbod !i; i := !i + stride done
  let repb f t ?(stride=1L) fbod = let i,c = ref f,ref true in while !i <= t && !c do
    match fbod !i with | `Break -> c := false | `Ok -> i := !i + stride done
  let repm f t ?(stride=1L) m0 fbod =
    let i,c,m = ref f,ref true,ref m0 in
    while !i<=t && !c do match fbod !m !i with
    | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i + stride done; !m
  let repi f t ?(stride=1) fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ stride done
  let repib f t ?(stride=1) fbod = let i,c = ref f,ref true in while !i <= t && !c do
    match fbod !i with | `Break -> c := false | `Ok -> i := !i +$ stride done
  let repim f t ?(stride=1) m0 fbod =
    let i,c,m = ref f,ref true,ref m0 in
    while !i<=t && !c do match fbod !m !i with
    | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i +$ stride done; !m
  let rep_rev f t ?(stride=1L) fbod = rep t f ~stride @@ fun v -> fbod @@ f + t - v
  let repb_rev f t ?(stride=1L) fbod = repb t f ~stride @@ fun v -> fbod @@ f + t - v
  let repm_rev f t ?(stride=1L) m0 fbod = repm f t ~stride m0 @@ fun u v -> fbod u @@ f + t - v
  let repi_rev f t ?(stride=1) fbod = repi t f ~stride @@ fun v -> fbod @@ f +$ t -$ v
  let repib_rev f t ?(stride=1) fbod = repib t f ~stride @@ fun v -> fbod @@ f +$ t -$ v
  let repim_rev f t ?(stride=1) m0 fbod = repim f t ~stride m0 @@ fun u v -> fbod u @@ f +$ t -$ v
  (* output *)
  let print_list_mle f ls = string_of_list f ls |> print_endline
  let print_array_mle f a = string_of_array f a |> print_endline
  let print_list f ls = ls |> List.iter (fun v -> printf "%s " @@ f v); print_newline ()
  let print_array f a = a |> Array.iter (fun v -> printf "%s " @@ f v); print_newline ()
  (* debug *)
  let dump_2darr f a = a |> Array.iter (fun b -> print_array f b)
  let dump_i64_list ls = print_list ist ls
  let dump_i64_array a = print_array ist a
end open Lib open Array

let md = 998244353
let () =
  let n = gi 0 in let n = i32 n in
  let s = scanf " %s" @@ id in
  if s.[0] = s.[n-$1] then (
    (* let f,c = ref true,ref s.[0] in
    repi 0 (n-$1) (fun i -> f := !f && !c = s.[i]);
    if !f then (
      fail 0
    ) else (

    ) *)
    let f,c = ref true,ref 0 in
    repi 0 (n-$1) (fun i ->
      if !f && s.[i] = s.[0] then (
        c := i+$1
      ) else f := false;
    );
    (* printf "%d" !c; *)
    let p = !c in
    let f,c = ref true,ref 0 in
    repi_rev (n-$1) 0 (fun i ->
      if !f && s.[i] = s.[n-$1] then (
        c := n-$i
      ) else f := false;
    );
    (* printf "%d" !c; *)
    let q = !c in
    printf "%d" @@ (((p+$1) %$ md)*$((q+$1) %$ md) %$ md);
  ) else (
    let f,c = ref true,ref 0 in
    repi 0 (n-$1) (fun i ->
      if !f && s.[i] = s.[0] then (
        c := i+$1
      ) else f := false;
    );
    (* printf "%d" !c; *)
    let p = !c in
    let f,c = ref true,ref 0 in
    repi_rev (n-$1) 0 (fun i ->
      if !f && s.[i] = s.[n-$1] then (
        c := n-$i
      ) else f := false;
    );
    (* printf "%d" !c; *)
    let q = !c in
    printf "%d\n" @@ (p+$q+$1) %$ md;
  )

open Printf open Scanf
module Lib = struct
  let i32,i64,ist = Int64.(to_int,of_int,to_string)
  let (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (%$) = (mod)
  let labs = Int64.abs
  let (+),(-),( * ),(/),(mod),(%) = Int64.(add,sub,mul,div,rem,rem)
  let (+=) r v = r := !r + v
  let (-=) r v = r := !r - v
  let ( *= ) r v = r := !r * v
  let (/=) r v = r := !r / v
  let (%=) r v = r := !r % v
  let max_i64,min_i64 = Int64.(max_int,min_int)
  (* math *)
  let ceildiv p q = (p+q-1L) / q
  let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n)
  let lcm m n = m / gcd m n * n
  module Int64_infix = struct
    let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) =
      let open Int64 in
      (logand),(logor),(logxor),lognot,
      (fun u v -> shift_left u (i32 v)),
      (fun u v -> shift_right u (i32 v)),
      (fun u v -> shift_right_logical u (i32 v))
  end
  let pow n k =
    let rec f a n = function
    | 0L -> a | 1L -> n*a | k when k mod 2L = 0L -> f a (n*n) (k/2L) | k -> f (a*n) (n*n) (k/2L)
    in f 1L n k
  (* input *)
  let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf " %Ld" (fun v -> v)) let iia = input_i64_array
  let get_i64 _ = Scanf.scanf " %Ld" (fun v -> v) let gi = get_i64
  let get_2_i64 _ = Scanf.scanf " %Ld %Ld" (fun u v -> u,v) let g2 = get_2_i64
  let get_3_i64 _ = Scanf.scanf " %Ld %Ld %Ld" (fun u v w -> u,v,w) let g3 = get_3_i64
  let get_4_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld" (fun u v w x -> u,v,w,x) let g4 = get_4_i64
  let get_5_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld %Ld" (fun u v w x y -> u,v,w,x,y) let g5 = get_5_i64
  let i32_get_int _ = Scanf.scanf " %d" (fun v -> v) let i32_get_2_ints _ = Scanf.scanf " %d %d" (fun u v -> u,v) let i32_get_3_ints _ = Scanf.scanf " %d %d %d" (fun u v w -> u,v,w) let i32_get_4_ints _ = Scanf.scanf " %d %d %d %d" (fun u v w x -> u,v,w,x) let i32_get_5_ints _ = Scanf.scanf " %d %d %d %d %d" (fun u v w x y -> u,v,w,x,y)
  (* utils *)
  external id : 'a -> 'a = "%identity"
  let ( *< ) f g x = f (g x)
  let ( *> ) f g x = g (f x)
  let rv f p q = f q p (* ex. 24 |> rv (/) 6 *)
  let alen a = i64 @@ Array.length a
  let llen l = i64 @@  List.length l
  let slen s = String.length s
  let string_of_list ?(separator=" ") f ls = ls |> List.map f |> String.concat separator
  let string_of_array ?(separator=" ") f a = a |> Array.to_list |> string_of_list ~separator f
  let char_list_of_string str = let rec f0 i a = if i<0 then a else f0 (i-$1) (str.[i]::a) in f0 (String.length str -$ 1) []
  let string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) "" ls
  let fail _ = failwith "fail"
  let dx,dy = [|1;0;-1;0|],[|0;1;0;-1|]
  let range l r = let ls = ref [] in for i=i32 l to i32 r do ls := i :: !ls done;!ls |> List.rev
  let cartesian_product u v = u |> List.map (fun p -> List.map (fun q -> p,q) v) |> List.flatten
  let shuffle a = Array.sort (fun _ _ -> (Random.int 3) -$ 1) a
  let binary_search ng ok f = let d = if ng < ok then 1L else -1L in
    let rec f0 ng ok =
      if labs (ok - ng) <= 1L then ok
      else let mid = ng + (ok - ng) / 2L in if f mid then f0 ng mid else f0 mid ok
    in f0 (ng-1L*d) (ok+1L*d)
  let lower_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >= v)
  let upper_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >  v)
  let equal_range a v = lower_bound a v, upper_bound a v (* #=snd-fst *)
  let rec fix f x = f (fix f) x
  let fix_memo ?(size=10000) f x =
    let tb = Hashtbl.create ~random:true size in
    let rec f0 x =
      try Hashtbl.find tb x with
      | Not_found -> (let v = f f0 x in Hashtbl.add tb x v; v)
    in f0 x
  (* imperative *)
  let rep f t ?(stride=1L) fbod = let i = ref f in while !i <= t do fbod !i; i := !i + stride done
  let repb f t ?(stride=1L) fbod = let i,c = ref f,ref true in while !i <= t && !c do
    match fbod !i with | `Break -> c := false | `Ok -> i := !i + stride done
  let repm f t ?(stride=1L) m0 fbod =
    let i,c,m = ref f,ref true,ref m0 in
    while !i<=t && !c do match fbod !m !i with
    | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i + stride done; !m
  let repi f t ?(stride=1) fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ stride done
  let repib f t ?(stride=1) fbod = let i,c = ref f,ref true in while !i <= t && !c do
    match fbod !i with | `Break -> c := false | `Ok -> i := !i +$ stride done
  let repim f t ?(stride=1) m0 fbod =
    let i,c,m = ref f,ref true,ref m0 in
    while !i<=t && !c do match fbod !m !i with
    | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i +$ stride done; !m
  let rep_rev f t ?(stride=1L) fbod = rep t f ~stride @@ fun v -> fbod @@ f + t - v
  let repb_rev f t ?(stride=1L) fbod = repb t f ~stride @@ fun v -> fbod @@ f + t - v
  let repm_rev f t ?(stride=1L) m0 fbod = repm f t ~stride m0 @@ fun u v -> fbod u @@ f + t - v
  let repi_rev f t ?(stride=1) fbod = repi t f ~stride @@ fun v -> fbod @@ f +$ t -$ v
  let repib_rev f t ?(stride=1) fbod = repib t f ~stride @@ fun v -> fbod @@ f +$ t -$ v
  let repim_rev f t ?(stride=1) m0 fbod = repim f t ~stride m0 @@ fun u v -> fbod u @@ f +$ t -$ v
  (* output *)
  let print_list_mle f ls = string_of_list f ls |> print_endline
  let print_array_mle f a = string_of_array f a |> print_endline
  let print_list f ls = ls |> List.iter (fun v -> printf "%s " @@ f v); print_newline ()
  let print_array f a = a |> Array.iter (fun v -> printf "%s " @@ f v); print_newline ()
  (* debug *)
  let dump_2darr f a = a |> Array.iter (fun b -> print_array f b)
  let dump_i64_list ls = print_list ist ls
  let dump_i64_array a = print_array ist a
end open Lib open Array
let allsame s =
  let f = ref true in
  String.iter (fun v -> if v <> s.[0] then f := false) s; !f
let () =
  let n = gi 0 in let n = i32 n in
  let s = scanf " %s" @@ id in
  let c = ref 0L in
  repi 0 (n) (fun i ->
    repi i (n) (fun j ->
      let p = String.sub s 0 i in
      let q = String.sub s j (n-$j) in
      let f = allsame @@ p ^ q  in
      if f then
      printf "%s ^ %s = %s :: %b\n"
        p q (p^q) f
      ;
      if f then c+=1L
    )
  ); printf "%Ld\n" !c

open Printf open Scanf
module Lib = struct
  let i32,i64,ist = Int64.(to_int,of_int,to_string)
  let (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (%$) = (mod)
  let labs = Int64.abs
  let (+),(-),( * ),(/),(mod),(%) = Int64.(add,sub,mul,div,rem,rem)
  let (+=) r v = r := !r + v
  let (-=) r v = r := !r - v
  let ( *= ) r v = r := !r * v
  let (/=) r v = r := !r / v
  let (%=) r v = r := !r % v
  let max_i64,min_i64 = Int64.(max_int,min_int)
  (* math *)
  let ceildiv p q = (p+q-1L) / q
  let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n)
  let lcm m n = m / gcd m n * n
  module Int64_infix = struct
    let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) =
      let open Int64 in
      (logand),(logor),(logxor),lognot,
      (fun u v -> shift_left u (i32 v)),
      (fun u v -> shift_right u (i32 v)),
      (fun u v -> shift_right_logical u (i32 v))
  end
  let pow n k =
    let rec f a n = function
    | 0L -> a | 1L -> n*a | k when k mod 2L = 0L -> f a (n*n) (k/2L) | k -> f (a*n) (n*n) (k/2L)
    in f 1L n k
  (* input *)
  let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf " %Ld" (fun v -> v)) let iia = input_i64_array
  let get_i64 _ = Scanf.scanf " %Ld" (fun v -> v) let gi = get_i64
  let get_2_i64 _ = Scanf.scanf " %Ld %Ld" (fun u v -> u,v) let g2 = get_2_i64
  let get_3_i64 _ = Scanf.scanf " %Ld %Ld %Ld" (fun u v w -> u,v,w) let g3 = get_3_i64
  let get_4_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld" (fun u v w x -> u,v,w,x) let g4 = get_4_i64
  let get_5_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld %Ld" (fun u v w x y -> u,v,w,x,y) let g5 = get_5_i64
  let i32_get_int _ = Scanf.scanf " %d" (fun v -> v) let i32_get_2_ints _ = Scanf.scanf " %d %d" (fun u v -> u,v) let i32_get_3_ints _ = Scanf.scanf " %d %d %d" (fun u v w -> u,v,w) let i32_get_4_ints _ = Scanf.scanf " %d %d %d %d" (fun u v w x -> u,v,w,x) let i32_get_5_ints _ = Scanf.scanf " %d %d %d %d %d" (fun u v w x y -> u,v,w,x,y)
  (* utils *)
  external id : 'a -> 'a = "%identity"
  let ( *< ) f g x = f (g x)
  let ( *> ) f g x = g (f x)
  let rv f p q = f q p (* ex. 24 |> rv (/) 6 *)
  let alen a = i64 @@ Array.length a
  let llen l = i64 @@  List.length l
  let slen s = String.length s
  let string_of_list ?(separator=" ") f ls = ls |> List.map f |> String.concat separator
  let string_of_array ?(separator=" ") f a = a |> Array.to_list |> string_of_list ~separator f
  let char_list_of_string str = let rec f0 i a = if i<0 then a else f0 (i-$1) (str.[i]::a) in f0 (String.length str -$ 1) []
  let string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) "" ls
  let fail _ = failwith "fail"
  let dx,dy = [|1;0;-1;0|],[|0;1;0;-1|]
  let range l r = let ls = ref [] in for i=i32 l to i32 r do ls := i :: !ls done;!ls |> List.rev
  let cartesian_product u v = u |> List.map (fun p -> List.map (fun q -> p,q) v) |> List.flatten
  let shuffle a = Array.sort (fun _ _ -> (Random.int 3) -$ 1) a
  let binary_search ng ok f = let d = if ng < ok then 1L else -1L in
    let rec f0 ng ok =
      if labs (ok - ng) <= 1L then ok
      else let mid = ng + (ok - ng) / 2L in if f mid then f0 ng mid else f0 mid ok
    in f0 (ng-1L*d) (ok+1L*d)
  let lower_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >= v)
  let upper_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >  v)
  let equal_range a v = lower_bound a v, upper_bound a v (* #=snd-fst *)
  let rec fix f x = f (fix f) x
  let fix_memo ?(size=10000) f x =
    let tb = Hashtbl.create ~random:true size in
    let rec f0 x =
      try Hashtbl.find tb x with
      | Not_found -> (let v = f f0 x in Hashtbl.add tb x v; v)
    in f0 x
  (* imperative *)
  let rep f t ?(stride=1L) fbod = let i = ref f in while !i <= t do fbod !i; i := !i + stride done
  let repb f t ?(stride=1L) fbod = let i,c = ref f,ref true in while !i <= t && !c do
    match fbod !i with | `Break -> c := false | `Ok -> i := !i + stride done
  let repm f t ?(stride=1L) m0 fbod =
    let i,c,m = ref f,ref true,ref m0 in
    while !i<=t && !c do match fbod !m !i with
    | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i + stride done; !m
  let repi f t ?(stride=1) fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ stride done
  let repib f t ?(stride=1) fbod = let i,c = ref f,ref true in while !i <= t && !c do
    match fbod !i with | `Break -> c := false | `Ok -> i := !i +$ stride done
  let repim f t ?(stride=1) m0 fbod =
    let i,c,m = ref f,ref true,ref m0 in
    while !i<=t && !c do match fbod !m !i with
    | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i +$ stride done; !m
  let rep_rev f t ?(stride=1L) fbod = rep t f ~stride @@ fun v -> fbod @@ f + t - v
  let repb_rev f t ?(stride=1L) fbod = repb t f ~stride @@ fun v -> fbod @@ f + t - v
  let repm_rev f t ?(stride=1L) m0 fbod = repm f t ~stride m0 @@ fun u v -> fbod u @@ f + t - v
  let repi_rev f t ?(stride=1) fbod = repi t f ~stride @@ fun v -> fbod @@ f +$ t -$ v
  let repib_rev f t ?(stride=1) fbod = repib t f ~stride @@ fun v -> fbod @@ f +$ t -$ v
  let repim_rev f t ?(stride=1) m0 fbod = repim f t ~stride m0 @@ fun u v -> fbod u @@ f +$ t -$ v
  (* output *)
  let print_list_mle f ls = string_of_list f ls |> print_endline
  let print_array_mle f a = string_of_array f a |> print_endline
  let print_list f ls = ls |> List.iter (fun v -> printf "%s " @@ f v); print_newline ()
  let print_array f a = a |> Array.iter (fun v -> printf "%s " @@ f v); print_newline ()
  (* debug *)
  let dump_2darr f a = a |> Array.iter (fun b -> print_array f b)
  let dump_i64_list ls = print_list ist ls
  let dump_i64_array a = print_array ist a
end open Lib open Array

let () =
  let n = gi 0 in let n = i32 n in
  let s = scanf " %s" @@ id in
  if s.[0] = s.[n-$1] then (
    (* let f,c = ref true,ref s.[0] in
    repi 0 (n-$1) (fun i -> f := !f && !c = s.[i]);
    if !f then (
      fail 0
    ) else (

    ) *)
    let f,c = ref true,ref 0 in
    repi 0 (n-$1) (fun i ->
      if !f && s.[i] = s.[0] then (
        c := i+$1
      ) else f := false;
    );
    (* printf "%d" !c; *)
    let p = !c in
    let f,c = ref true,ref 0 in
    repi_rev (n-$1) 0 (fun i ->
      if !f && s.[i] = s.[n-$1] then (
        c := n-$i
      ) else f := false;
    );
    (* printf "%d" !c; *)
    let q = !c in
    printf "%d" @@ p*$q;
  ) else (
    let f,c = ref true,ref 0 in
    repi 0 (n-$1) (fun i ->
      if !f && s.[i] = s.[0] then (
        c := i+$1
      ) else f := false;
    );
    (* printf "%d" !c; *)
    let p = !c in
    let f,c = ref true,ref 0 in
    repi_rev (n-$1) 0 (fun i ->
      if !f && s.[i] = s.[n-$1] then (
        c := n-$i
      ) else f := false;
    );
    (* printf "%d" !c; *)
    let q = !c in
    printf "%d\n" @@ p+$q+$1;
  )

open Printf open Scanf
module Lib = struct
  let i32,i64,ist = Int64.(to_int,of_int,to_string)
  let (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (%$) = (mod)
  let labs = Int64.abs
  let (+),(-),( * ),(/),(mod),(%) = Int64.(add,sub,mul,div,rem,rem)
  let (+=) r v = r := !r + v
  let (-=) r v = r := !r - v
  let ( *= ) r v = r := !r * v
  let (/=) r v = r := !r / v
  let (%=) r v = r := !r % v
  let max_i64,min_i64 = Int64.(max_int,min_int)
  (* math *)
  let ceildiv p q = (p+q-1L) / q
  let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n)
  let lcm m n = m / gcd m n * n
  module Int64_infix = struct
    let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) =
      let open Int64 in
      (logand),(logor),(logxor),lognot,
      (fun u v -> shift_left u (i32 v)),
      (fun u v -> shift_right u (i32 v)),
      (fun u v -> shift_right_logical u (i32 v))
  end
  let pow n k =
    let rec f a n = function
    | 0L -> a | 1L -> n*a | k when k mod 2L = 0L -> f a (n*n) (k/2L) | k -> f (a*n) (n*n) (k/2L)
    in f 1L n k
  (* input *)
  let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf " %Ld" (fun v -> v)) let iia = input_i64_array
  let get_i64 _ = Scanf.scanf " %Ld" (fun v -> v) let gi = get_i64
  let get_2_i64 _ = Scanf.scanf " %Ld %Ld" (fun u v -> u,v) let g2 = get_2_i64
  let get_3_i64 _ = Scanf.scanf " %Ld %Ld %Ld" (fun u v w -> u,v,w) let g3 = get_3_i64
  let get_4_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld" (fun u v w x -> u,v,w,x) let g4 = get_4_i64
  let get_5_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld %Ld" (fun u v w x y -> u,v,w,x,y) let g5 = get_5_i64
  let i32_get_int _ = Scanf.scanf " %d" (fun v -> v) let i32_get_2_ints _ = Scanf.scanf " %d %d" (fun u v -> u,v) let i32_get_3_ints _ = Scanf.scanf " %d %d %d" (fun u v w -> u,v,w) let i32_get_4_ints _ = Scanf.scanf " %d %d %d %d" (fun u v w x -> u,v,w,x) let i32_get_5_ints _ = Scanf.scanf " %d %d %d %d %d" (fun u v w x y -> u,v,w,x,y)
  (* utils *)
  external id : 'a -> 'a = "%identity"
  let ( *< ) f g x = f (g x)
  let ( *> ) f g x = g (f x)
  let rv f p q = f q p (* ex. 24 |> rv (/) 6 *)
  let alen a = i64 @@ Array.length a
  let llen l = i64 @@  List.length l
  let slen s = String.length s
  let string_of_list ?(separator=" ") f ls = ls |> List.map f |> String.concat separator
  let string_of_array ?(separator=" ") f a = a |> Array.to_list |> string_of_list ~separator f
  let char_list_of_string str = let rec f0 i a = if i<0 then a else f0 (i-$1) (str.[i]::a) in f0 (String.length str -$ 1) []
  let string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) "" ls
  let fail _ = failwith "fail"
  let dx,dy = [|1;0;-1;0|],[|0;1;0;-1|]
  let range l r = let ls = ref [] in for i=i32 l to i32 r do ls := i :: !ls done;!ls |> List.rev
  let cartesian_product u v = u |> List.map (fun p -> List.map (fun q -> p,q) v) |> List.flatten
  let shuffle a = Array.sort (fun _ _ -> (Random.int 3) -$ 1) a
  let binary_search ng ok f = let d = if ng < ok then 1L else -1L in
    let rec f0 ng ok =
      if labs (ok - ng) <= 1L then ok
      else let mid = ng + (ok - ng) / 2L in if f mid then f0 ng mid else f0 mid ok
    in f0 (ng-1L*d) (ok+1L*d)
  let lower_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >= v)
  let upper_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >  v)
  let equal_range a v = lower_bound a v, upper_bound a v (* #=snd-fst *)
  let rec fix f x = f (fix f) x
  let fix_memo ?(size=10000) f x =
    let tb = Hashtbl.create ~random:true size in
    let rec f0 x =
      try Hashtbl.find tb x with
      | Not_found -> (let v = f f0 x in Hashtbl.add tb x v; v)
    in f0 x
  (* imperative *)
  let rep f t ?(stride=1L) fbod = let i = ref f in while !i <= t do fbod !i; i := !i + stride done
  let repb f t ?(stride=1L) fbod = let i,c = ref f,ref true in while !i <= t && !c do
    match fbod !i with | `Break -> c := false | `Ok -> i := !i + stride done
  let repm f t ?(stride=1L) m0 fbod =
    let i,c,m = ref f,ref true,ref m0 in
    while !i<=t && !c do match fbod !m !i with
    | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i + stride done; !m
  let repi f t ?(stride=1) fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ stride done
  let repib f t ?(stride=1) fbod = let i,c = ref f,ref true in while !i <= t && !c do
    match fbod !i with | `Break -> c := false | `Ok -> i := !i +$ stride done
  let repim f t ?(stride=1) m0 fbod =
    let i,c,m = ref f,ref true,ref m0 in
    while !i<=t && !c do match fbod !m !i with
    | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i +$ stride done; !m
  let rep_rev f t ?(stride=1L) fbod = rep t f ~stride @@ fun v -> fbod @@ f + t - v
  let repb_rev f t ?(stride=1L) fbod = repb t f ~stride @@ fun v -> fbod @@ f + t - v
  let repm_rev f t ?(stride=1L) m0 fbod = repm f t ~stride m0 @@ fun u v -> fbod u @@ f + t - v
  let repi_rev f t ?(stride=1) fbod = repi t f ~stride @@ fun v -> fbod @@ f +$ t -$ v
  let repib_rev f t ?(stride=1) fbod = repib t f ~stride @@ fun v -> fbod @@ f +$ t -$ v
  let repim_rev f t ?(stride=1) m0 fbod = repim f t ~stride m0 @@ fun u v -> fbod u @@ f +$ t -$ v
  (* output *)
  let print_list_mle f ls = string_of_list f ls |> print_endline
  let print_array_mle f a = string_of_array f a |> print_endline
  let print_list f ls = ls |> List.iter (fun v -> printf "%s " @@ f v); print_newline ()
  let print_array f a = a |> Array.iter (fun v -> printf "%s " @@ f v); print_newline ()
  (* debug *)
  let dump_2darr f a = a |> Array.iter (fun b -> print_array f b)
  let dump_i64_list ls = print_list ist ls
  let dump_i64_array a = print_array ist a
end open Lib open Array

let () =
  let n = gi 0 in let n = i32 n in
  let s = scanf " %s" @@ id in
  if s.[0] = s.[n-$1] then (
    (* let f,c = ref true,ref s.[0] in
    repi 0 (n-$1) (fun i -> f := !f && !c = s.[i]);
    if !f then (
      fail 0
    ) else (

    ) *)
    let f,c = ref true,ref 0 in
    repi 0 (n-$1) (fun i ->
      if !f && s.[i] = s.[0] then (
        c := i+$1
      ) else f := false;
    );
    (* printf "%d" !c; *)
    let p = !c in
    let f,c = ref true,ref 0 in
    repi_rev (n-$1) 0 (fun i ->
      if !f && s.[i] = s.[n-$1] then (
        c := n-$i
      ) else f := false;
    );
    (* printf "%d" !c; *)
    let q = !c in
    printf "%d" @@ (p+$1)*$(q+$1);
  ) else (
    let f,c = ref true,ref 0 in
    repi 0 (n-$1) (fun i ->
      if !f && s.[i] = s.[0] then (
        c := i+$1
      ) else f := false;
    );
    (* printf "%d" !c; *)
    let p = !c in
    let f,c = ref true,ref 0 in
    repi_rev (n-$1) 0 (fun i ->
      if !f && s.[i] = s.[n-$1] then (
        c := n-$i
      ) else f := false;
    );
    (* printf "%d" !c; *)
    let q = !c in
    printf "%d\n" @@ p+$q+$1;
  )


open Big_int

let rec yolo now = function
	|t::q	-> Big_int.add_big_int (Big_int.abs_big_int (Big_int.sub_big_int now t)) (yolo t q)
	| []	-> Big_int.big_int_of_int 0

let main () =
	let n = Scanf.scanf "%d" (fun i -> i) and l = ref [] in
		for j=1 to n do
			Scanf.scanf " %d" (fun i -> l := (Big_int.big_int_of_int i):: !l);
		done;
	Printf.printf "%s" (Big_int.string_of_big_int (yolo (Big_int.big_int_of_int 0) (List.rev !l)));;

main ();;

open Printf
open Scanf

let ( ** ) a b = Int64.mul a b
let ( ++ ) a b = Int64.add a b
let ( -- ) a b = Int64.sub a b

let rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)
let sum i j f = fold i j (fun i a -> (f i) ++ a) 0L

let long x = Int64.of_int x
let short x = Int64.to_int x

let read_int () = bscanf Scanning.stdib " %d " (fun x -> x)
let () =
  let n = read_int () in

  let b = Array.init n (fun _ -> long (read_int())) in

  let rec loop i running_total total_ops =
    if i=n then total_ops else (
      let x = running_total -- b.(i) in
      let total_ops = total_ops ++ (Int64.abs x) in
      let running_total = running_total -- x in
      loop (i+1) running_total total_ops
    )
  in

  let answer = loop 0 0L 0L in

  printf "%Ld\n" answer

let n = read_int ();;
let a = Array.of_list (List.map (Int64.of_string) (Str.split (Str.regexp " ") (read_line ())));;
let x = ref 0L and ans = ref 0L;;
for i = 0 to n - 1 do
	ans :=
		Int64.add !ans (Int64.abs (Int64.sub !x  a.(i)));
		x := a.(i);
done;;
print_string (Int64.to_string !ans);;


open Printf
open Scanf

(* Implementation of Dinic's algorithm for max flow. See ../spoj/PROFIT/
   for additional algorithms. *)

let infinite_c = 10000 (* "infinite" capacity *)

let maxflow s t adj cap =
  (* s and t are nodes (numbers). g is a graph (represented via an
     array of adjacency lists). c is a 1-d array of capacities.  The
     adjacency list on node v stores pairs like (w,i) where w is the
     other node, and i is the index into the capacity array for where
     this capacity is stored.  It's set up so that i lxor 1 is where the
     capacity of edge (w,v) is stored.  We compute the maximum flow in
     the same representation as the capacities.  *)

  let c = Array.copy cap in
  let n = Array.length adj in
  let alive = Array.make n [] in
  let level = Array.make n 0 in
  let queue = Array.make n 0 in
  let front = ref 0 in
  let back = ref 0 in

  let push w = queue.(!back) <- w; back := !back+1 in
  let eject() = let x = queue.(!front) in front := !front + 1; x; in

  let rec bfs () =
    let rec loop () =
      if !front = !back then false else
	let v = eject() in
	  if level.(v) = level.(t) then true else (
	    List.iter (
	      fun (w,i) -> if level.(w) < 0 && c.(i) > 0 then (
		level.(w) <- level.(v) + 1;
		push w
	      )
	    ) adj.(v);
	    loop ()
	  )
    in
      level.(s) <- 0;
      back := 0; front := 0;
      push s;
      loop ();
  in

  let rec dfs v cap =
    (* Does a DFS from v looking for a path to t.  It tries to push cap units
       of flow to t.  It returns the amount of flow actually pushed *)
    if v=t then cap else
      let rec loop total remaining li =
	  match li with
	    | [] ->
		alive.(v) <- [];
		total
	    | (w,i)::tail ->
		if level.(w) = level.(v)+1 && c.(i) > 0 then (
		  let p = dfs w (min c.(i) remaining) in
		    c.(i) <- c.(i) - p;
		    c.(i lxor 1) <- c.(i lxor 1) + p;
		    if remaining-p = 0 then (
		      alive.(v) <- li;
		      total+p
		    ) else loop (total+p) (remaining-p) tail
		) else loop total remaining tail
      in loop 0 cap alive.(v)
  in

  let rec main_loop flow_so_far =
    for i=0 to n-1 do level.(i) <- -1; done;
    Array.blit adj 0 alive 0 n;
    if bfs () then main_loop (flow_so_far + (dfs s infinite_c)) else flow_so_far
  in
    main_loop 0

let factor n =
  let rec loop n p ac =
    if n=1 then ac
    else if p*p > n then (n::ac)
    else if n mod p = 0 then loop (n/p) p (p::ac)
    else loop n (p+1) ac
  in
    List.rev (loop n 2 [])

let read_int () = bscanf Scanning.stdib " %d " (fun x -> x)
let read_pair () = let u = read_int() in (u,read_int())

let () =
  let n = read_int () in
  let m = read_int () in
  let a = Array.init n (fun _ -> read_int()) in
  let pair = Array.init m (fun _ ->
    let i = read_int() -1 in
    let j = read_int() -1 in
    if i land 1 = 0 then (i,j) else (j,i)
  ) in

  let fact = Array.init n (fun i -> factor a.(i)) in

  let primeset = Hashtbl.create 10 in  (* the set of primes that occur *)
  for i=0 to n-1 do
    List.iter (fun p -> Hashtbl.replace primeset p true) fact.(i)
  done;

  let build_graph p =
    (* build the graph for a specific prime p *)
    let s = n in
    let t = n+1 in
    let adj = Array.make (n+2) [] in
    let cap = Array.make (2*m + 2*n) 0 in

    let add_edge u v c cr ind indr =
      adj.(u) <- (v,ind)::adj.(u);
      adj.(v) <- (u,indr)::adj.(v);
      cap.(ind) <- c;
      cap.(indr) <- cr
    in

    for k = 0 to m-1 do
      let (i,j) = pair.(k) in
      add_edge i j infinite_c 0 (2*k) (2*k+1)
    done;

    for v = 0 to n-1 do
      let capacity = List.length (List.filter (fun e -> e = p) fact.(v)) in
      let edgeno = 2*m + 2*v in
      if v land 1 = 0 then (
	add_edge s v capacity 0 edgeno (edgeno+1);
      ) else (
	add_edge v t capacity 0 edgeno (edgeno+1);
      )
    done;
    (s,t,adj,cap)
  in

  let flowsum = ref 0 in

  Hashtbl.iter (fun p _ ->
    let (s,t,adj,cap) = build_graph p in
    let f = maxflow s t adj cap in
    flowsum := !flowsum + f
  ) primeset;

  printf "%d\n" !flowsum


(* 7:22 *)

open Printf
open Scanf

let rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)
let minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i)

let read_int _ = bscanf Scanning.stdib " %d " (fun x -> x)
let () =
  let n = read_int () in
  let a = Array.init n read_int in

  let m = 200_001 in
  let vtime = Array.make (m+1) (2*m) in

  for i=0 to n-1 do
    vtime.(a.(i)) <- i
  done;

  let cafe = minf 0 m (fun cafe -> vtime.(cafe)) in

  printf "%d\n" a.(cafe)

let n = read_int () in
let h = Hashtbl.create n in
for i = 0 to n-1 do Hashtbl.replace h (Scanf.scanf " %d" (fun x -> x)) i done;
print_int @@ fst @@ Hashtbl.fold (fun a b c -> if b < snd c then (a,b) else c) h (min_int, max_int);

module IntSet = Set.Make(struct
    let compare = Pervasives.compare
    type t = int
end);;
let n = read_int () in
let a = Array.make n 0 and
s = ref IntSet.empty in
for i = 0 to n-1 do begin
    a.(i) <- Scanf.scanf " %d" (fun x -> x);
    s := IntSet.add a.(i) !s
end done;
let p = ref 0 in
for i = n-1 downto 0 do begin
    if IntSet.mem a.(i) !s then begin
        p := a.(i) ;
        s := IntSet.remove a.(i) !s
    end
end done;
print_int !p;