let n = read_int () in
let tr = Array.make n false in

let g () =
let l = Scanf.Scanning.from_string (read_line ()) in
try
let tc = Scanf.bscanf l "%d " (fun x -> x) in
(for i = 1 to tc do
 let k = Scanf.bscanf l "%d " (fun x -> x) in
 tr.(k-1) <-  true
done)
with _ -> ()
in
g() ; g() ;

let f () =
 let result = ref true in
 for i = 0 to n-1 do
  if tr.(i) = false then result := false
 done;
 !result
in

if f () then
print_endline "I become the guy."
else
print_endline "Oh, my keyboard!";;

module IntSet = Set.Make(
  struct
    let compare = Pervasives.compare
    type t = int
  end ) ;;

let rec split s i acc =
begin
  if i > String.length s
  then List.rev acc
  else
      let first =
      if String.contains_from s i ' '
         then  String.index_from s i ' '
         else String.length s
    in split s (first+1) (int_of_string (String.init (first-i) (fun x -> String.get s (i+x))) :: acc)
end in

let from_list xs = List.fold_right IntSet.add xs IntSet.empty in
let alln =
    let len = int_of_string (read_line()) in
    Array.init len (fun a -> a+1)
        |> (fun xs -> Array.fold_right IntSet.add xs IntSet.empty)  in
let x = split (read_line ()) 0 [] |> List.tl |> from_list in
let y = split (read_line ()) 0 [] |> List.tl |> from_list in
print_string (if IntSet.equal alln (IntSet.union x y) then "I become the guy." else "Oh, my keyboard!")

let rec get_uniques = function
    | head :: (middle :: _ as tail) ->
        if head = middle
        then
            get_uniques tail
        else
            (head :: get_uniques tail)
    | smaller -> smaller

let read () = List.map (fun n -> Pervasives.int_of_string n) (Str.split (Str.regexp " ") (Pervasives.read_line ()))

let n = Pervasives.read_int ()
let x_levels = read ()
let y_levels = read ()

let result =
    let len = List.length (get_uniques (List.sort (compare) (List.append (List.tl x_levels) (List.tl y_levels))))
    in
    if  len = n
    then
        "I become the guy."
    else
        "Oh, my keyboard!"

let () = Printf.printf "%s\n" result

let read () = let total = Scanf.scanf "%d " (fun n -> n) in
    let rec loop list n =
        if n > 0
        then
            let var = Scanf.scanf "%d " (fun k -> k) in
            loop (var :: list) (n - 1)
        else
            list
    in loop [] total

let rec get_uniques = function
    | head :: (middle :: _ as tail) ->
        if head = middle
        then
            get_uniques tail
        else
            (head :: get_uniques tail)
    | smaller -> smaller

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

let result =
    let len = List.length (get_uniques (List.sort (compare) (List.append x_levels y_levels)))
    in
    if  len = n
    then
        "I become the guy."
    else
        "Oh, my keyboard!"

let () = Printf.printf "%s\n" result

let rec get_uniques = function
    | head :: (middle :: _ as tail) ->
        if head = middle
        then
            get_uniques tail
        else
            (head :: get_uniques tail)
    | smaller -> smaller

let read () = List.map (fun n -> Pervasives.int_of_string n) (Str.split (Str.regexp " ") (Pervasives.read_line ()))

let n = Pervasives.read_int ()
let x_levels = read ()
let y_levels = read ()

let result =
    let len = List.length (get_uniques (List.sort (compare) (List.append x_levels y_levels)))
    in
    if  len = n
    then
        "I become the guy."
    else
        "Oh, my keyboard!"

let () = Printf.printf "%s\n" result

let n = read_int () in
let tr = Array.make n false in

let g () =
let l = Scanf.Scanning.from_string (read_line ()) in
try
(for i = 1 to n do
 let k = Scanf.bscanf l "%d " (fun x -> x) in
 tr.(k-1) <-  true
done)
with _ -> ()
in
g() ; g() ;

let f () =
 let result = ref true in
 for i = 0 to n-1 do
  if tr.(i) = false then result := false
 done;
 !result
in

if f () then
print_endline "I become the guy."
else
print_endline "Oh, my keyboard!";;

let n = read_int () in
let tr = Array.make n false in

let g () =
let l = Scanf.Scanning.from_string (read_line ()) in
try
(for i = 1 to n do
 let k = Scanf.bscanf l "%d " (fun x -> x) in
 tr.(k-1) <-  true
done)
with _ -> ()
in
g() ; g() ;

let f () =
 let result = ref true in
 for i = 0 to n-1 do
  if tr.(i) = false then result := false
 done;
 !result
in

if f () then
print_endline "I become the guy"
else
print_endline "Oh, my keyboard!";;

module IntSet = Set.Make(
  struct
    let compare = Pervasives.compare
    type t = int
  end ) ;;

let rec split s i acc =
begin
  if i == 1 + String.length s
  then acc
  else
      let first =
      if String.contains_from s i ' '
         then  String.index_from s i ' '
         else String.length s
    in split s (first+1) (int_of_string (String.init (first-i) (fun x -> String.get s (i+x))) :: acc)
end in

let from_list xs = List.fold_right IntSet.add xs IntSet.empty in
let alln =
    let len = int_of_string (read_line()) in
    Array.init len (fun a -> a+1)
        |> (fun xs -> Array.fold_right IntSet.add xs IntSet.empty)  in
let x = split (read_line ()) 0 [] |> List.tl |> from_list in
let y = split (read_line ()) 0 [] |> List.tl |> from_list in
print_string (if IntSet.equal alln (IntSet.union x y) then "I become the guy." else "Oh, my keyboard!")


module MultiSet_test = struct
  module Make (X:Map.OrderedType) = struct
    include Map.Make(X)
    let count v set =
      try find v set with Not_found -> 0
    let remove_each v set =
      let k = count v set in
      if k<=0 then raise Not_found
      else if k=1 then remove v set
      else add v (k-1) set
    let add_each v set =
      let k = count v set in
      if k=0 then add v 1 set
      else add v (k+1) set
    let iter_each f set =
      let rec f0 k = function
      | 0 -> ()
      | i -> let () = f k in f0 k (i-1)
      in iter f0 set
    let fold_each f set ac =
      let rec f0 k i ac = match i with
      | 0 -> ac
      | i -> f0 k (i-1) (f k ac)
      in fold f0 set ac
    let bindings_each set =
      fold_each (fun v ls -> v::ls) set []
      |> List.rev
    let min_binding_each set = fst @@ min_binding set
    let max_binding_each set = fst @@ max_binding set
    let exists_each f = exists (fun k _ -> f k)
    let cardinal_each set =
      (* O(#node). an aux variable might lead you to O(1) perf *)
      fold (fun _ v sum -> sum + v) set 0
  end
end
module S = MultiSet_test.Make (struct
  type t = int let compare = compare
end);;
Array.(Scanf.(
  scanf " %d %d" @@ fun n m ->
    let a = init m (fun _ -> scanf " %d" @@ fun v -> v) in
    let c = make n 0 in
    fold_left (fun (s,round) v ->
      let v = v-1 in
      let s = S.remove_each c.(v) s in
      let s = S.add_each (c.(v)+1) s in
      c.(v) <- c.(v) + 1;
      let p = S.min_binding_each s in
      print_char (
        if p > round then '1' else '0'
      ); (s,p)
    ) (S.singleton 0 n, 0) a |> ignore))

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_lim,min_i64_lim = Int64.(max_int,min_int)
  let max_i64,min_i64 = 2000000000000000000L,-2000000000000000000L
  (* 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
module SegTree = struct
  module type S = sig
    type t
    val  op: t -> t -> t
    val ide: t
    val upd: t -> t -> t
  end
  module RMQ = struct type t = int64 let op = min let ide = max_i64 let upd u v = v end
  module RSQ = struct type t = int64 let op = (+) let ide = 0L let upd u v = u+v end
  let par i = (i-$1)/$2
  let chl i = 2*$i+$1
  let chr i = 2*$i+$2
  module Make (X:S) = struct
    type t = SegTree of (X.t array * int)
    let raw (SegTree (a,_)) = a
    let make raw = (* O(n) *)
      let ln = Array.length raw in
      let n =
        let n = ref 1 in
        while !n<ln do n := !n*$2 done; !n in
      let a = Array.make (2*$n-$1) X.ide in
      for i=0 to ln-$1 do
        a.(i+$n-$1) <- raw.(i) done;
      for i=n-$2 downto 0 do
        a.(i) <- X.op a.(chl i) a.(chr i) done;
      SegTree (a,n)
    let update_destructive (SegTree(a,n)) i v =
      let i = ref @@ i+$(n-$1) in
      a.(!i) <- X.upd a.(!i) v;
      while !i>0 do
        i := par !i;
        a.(!i) <- X.op a.(chl !i) a.(chr !i) done
    let get_half_open (SegTree(a,n)) l r = (* O(logn), [l,r) *)
      let rec f0 i p q =
        if q<=l || r<=p then X.ide
        else if l<=p && q<=r then a.(i)
        else
          let vl = f0 (2*$i+$1) p ((p+$q)/$2) in
          let vr = f0 (2*$i+$2) ((p+$q)/$2) q in
          X.op vl vr
      in f0 0 0 n
    let get_closed seg l r = get_half_open seg l (r+$1) (* [l,r] *)
  end
end
module SI = SegTree.Make(struct
  type t = int64
  let op = min let ide = max_i64 let upd u v = v
end)
let () =
  let n,m = g2 0 in
  let a = iia m in
  let s = SI.make @@ make (i32 n) 0L in
  let k = ref 1L in
  iter (fun v ->
    let i = i32 v -$ 1 in
    SI.update_destructive s i (SI.get_closed s i i + 1L);
    let mn = SI.get_closed s 0 (i32 n-$1) in
    if mn = !k then (
      printf "1"; k += 1L
    ) else printf "0";
    (* printf ": %Ld : %Ld : %s\n" mn !k (
      string_of_array ist @@ init (i32 n) (fun i -> SI.get_closed s i i)
    ) *)
  ) a

  (* let b = make (i32 n) 0L in
  let k = ref 1L in
  iter (fun v ->
    let i = i32 v -$ 1 in
    b.(i) <- b.(i) + 1L;
    if fold_left min max_i64 b = !k then (
      printf "1"; k += 1L
    ) else printf "0"
  ) a *)

(* module BIT = struct
  let lsb i = i land -i
  let sum i b = (* 0-indexed; Σa[0,i-1] *)
    fix (fun f i s -> if i>0 then f (i -$ lsb i) (s + b.(i)) else s) i 0L
  let sum_closed i = sum (i+$1) (* 0-indexed; Σa[0,i] *)
  let sum_interval l r b = (* 0-indexed; Σa[l,r] = Σa[0,r+1-1] - Σ[0,l-1] *)
    if l>r then 0L else sum (r+$1) b - sum l b
  let add i x b = (* 0-indexed; a[i]+=x. not b *)
    if i<0 then raise @@ Invalid_argument "index should be >= 1 (0-indexed a[i-1]+=x)";
    fix (fun f i -> if i<Array.length b then (
      b.(i) <- b.(i) + x; f (i +$ lsb i))) (i+$1)
  let of_array a = let b = Array.make (Array.length a +$ 1) 0L in
    Array.iteri (fun i v -> add (i+$1) v b) a; b
  let make n = Array.make (n+$1) 0L
  let reconst b = Array.init (Array.length b-$1) (fun i -> sum_interval i i b)
  (* initialization: http://hos.ac/slides/20140319_bit.pdf *)
end
let () =
  let n,m = g2 0 in
  let a = iia m in
  let b = BIT.make (i32 n+$1) in
  let k = ref 1L in
  iter (fun v ->
    BIT.add (i32 v) 1L b;
    if BIT.sum_closed (i32 n) b = !k then (
      printf "1";
      k += 1L
    ) else (
      printf "0"
    )
  ) a; *)

open Printf
open Scanf

module Pset = Set.Make (struct type t = int*int let compare = compare end)

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

let read_int _ = bscanf Scanning.stdib " %d " (fun x -> x)
let read_pair _ = bscanf Scanning.stdib " %d %d " (fun x y -> (x,y))
let () =
  let (n,m) = read_pair () in
  let a = Array.init m (fun _ -> read_int() -1) in (*difficulty reduced by 1 *)

  let hist = Array.make n 0 in

  let rec insert i s = if i=n then s else insert (i+1) (Pset.add (0,i) s) in

  let set = insert 0 Pset.empty in

  let rec loop j s prev_low_freq = if j=m then () else (
    let old = (hist.(a.(j)), a.(j)) in
    hist.(a.(j)) <- hist.(a.(j)) + 1;
    let new_elt = (hist.(a.(j)), a.(j)) in
    let s = Pset.remove old s in
    let s = Pset.add new_elt s in
    let (freq,_) = Pset.min_elt s in
    if freq > prev_low_freq then printf "1" else printf "0";
    loop (j+1) s freq
  ) in

  let () = loop 0 set 0 in
  print_newline()

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

let () =
    let n = read_int () and m = read_int () in
    let a = Array.init m read_int
    and cnt = Array.make (n + 1) 0
    and ans = Array.make m 0
    and index = ref 1 in
    for i = 0 to m - 1 do
        cnt.(a.(i)) <- cnt.(a.(i)) + 1;
        while cnt.(!index) <> 0 do
            cnt.(!index) <- cnt.(!index) - 1;
            if !index = n then ans.(i) <- 1;
            index := !index mod n + 1
        done
    done;
    for i = 0 to m - 1 do
        printf "%d" ans.(i)
    done

Array.(Scanf.(
  scanf " %d %d" @@ fun n m ->
    let cnt,exist = make n 0, make m 0 in
    init m @@ fun _ -> scanf " %d" @@ fun v -> (
      let v = v - 1 in
      exist.(cnt.(v)) <- exist.(cnt.(v)) + 1;
      print_string (
        if exist.(cnt.(v)) = n then "1" else "0");
      cnt.(v) <- cnt.(v) + 1)))

module SegTree = struct
  module type S = sig
    type t
    val  op: t -> t -> t
    val ide: t
    val upd: t -> t -> t
  end
  module RMQ : S with type t = int64 =
    struct
      type t = int64 let op = min
      let ide = Int64.max_int let upd _ v = v
    end
  module RSQ : S with type t = int64 =
    struct
      type t = int64 let op = Int64.add
      let ide = 0L let upd prev v = op prev v
    end
  let par i = (i-1)/2
  let chl i = 2*i+1
  let chr i = 2*i+2
  module Make (X:S) = struct
    type t = SegTree of (X.t array * int)
    let raw (SegTree (a,_)) = a
    let make raw = (* O(n) *)
      let ln = Array.length raw in
      let n =
        let n = ref 1 in
        while !n<ln do n := !n*2 done; !n in
      let a = Array.make (2*n-1) X.ide in
      for i=0 to ln-1 do
        a.(i+n-1) <- raw.(i) done;
      for i=n-2 downto 0 do
        a.(i) <- X.op a.(chl i) a.(chr i) done;
      SegTree (a,n)
    let update_destructive (SegTree(a,n)) i v =
      let i = ref @@ i+(n-1) in
      a.(!i) <- X.upd a.(!i) v;
      while !i>0 do
        i := par !i;
        a.(!i) <- X.op a.(chl !i) a.(chr !i) done
    let get_half_open (SegTree(a,n)) l r = (* O(logn), [l,r) *)
      let rec f0 i p q =
        if q<=l || r<=p then X.ide
        else if l<=p && q<=r then a.(i)
        else
          let vl = f0 (2*i+1) p ((p+q)/2) in
          let vr = f0 (2*i+2) ((p+q)/2) q in
          X.op vl vr
      in f0 0 0 n
    let get_closed seg l r = get_half_open seg l (r+1) (* [l,r] *)
  end
end
let (++) = Int64.add
module S = SegTree.Make(SegTree.RMQ);;
Scanf.(Array.(scanf " %d %d" @@ fun n m ->
  let a = init m (fun _ -> scanf " %d" @@ fun v -> v) in
  let s = S.make @@ make (n+1) 0L in
  fold_left (fun k v ->
    S.update_destructive s v (S.get_closed s v v ++ 1L);
    if S.get_closed s 1 n = k then (
      print_int 1; k++1L
    ) else (
      print_int 0; k
    )
  ) 1L a |> ignore
))


let rec fix f x = f (fix f) x
let gcd = fix (fun f m n ->
  if n=0 then m else f n (m mod n));;
Scanf.(Array.(
  let t = scanf " %d" @@ fun v -> v in
  init t (fun _ ->
    let d = scanf " %d" @@ fun v -> v in
    let g = gcd 180 (180-d) in
    let p,q = 180/g,(180-d)/g in
    Printf.printf "%d\n" @@
      if q=1 then p*2 else p)))

open Printf
open Scanf

let rec gcd a b = if a=0 then b else gcd (b mod a) a

let read_int _ = bscanf Scanning.stdin " %d " (fun x -> x)
let read_pair _ = bscanf Scanning.stdin " %d %d " (fun x y -> (x,y))
let () =
  let cases = read_int () in
  for case = 1 to cases do
    let ang = read_int () in
    let num = 2*ang in
    let den = 360 in
    let g = gcd num den in
    let (num,den) = (num/g, den/g) in
    let (num,den) = if num+1 = den then (2*num,2*den) else (num,den) in
    printf "%d\n" den
  done

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 t = gi 0 in
  rep 1L t (fun _ ->
    let d = gi 0 in
    let g = gcd 180L (180L-d) in
    let p,q = 180L/g, (180L-d)/g in
    (* n=pi,k=qi *)
    let f = ref false in
    rep 1L 180L (fun i ->
      let n1,k1 = p*i,q*i in
      if not !f && k1 < n1 && k1 >= 2L then (
        f := true;
        (* printf "  %Ld; %Ld\n" n1 k1; *)
        printf "%Ld\n" n1;
      )
    )
  )

let rec fix f x = f (fix f) x
let gcd = fix (fun f m n ->
  if n=0 then m else f n (m mod n));;
Scanf.(Array.(
  let t = scanf " %d" @@ fun v -> v in
  init t (fun _ ->
    let d = scanf " %d" @@ fun v -> v in
    let g = gcd 180 (180-d) in
    let p,q = 180/g,(180-d)/g in
    Printf.printf "%d\n" @@ p*2)))

let rec fix f x = f (fix f) x
let gcd = fix (fun f m n ->
  if n=0 then m else f n (m mod n));;
Scanf.(Array.(
  let t = scanf " %d" @@ fun v -> v in
  init t (fun _ ->
    let d = scanf " %d" @@ fun v -> v in
    let g = gcd 180 (180-d) in
    let p,q = 180/g,(180-d)/g in
    Printf.printf "%d\n" @@
      if q=1 then p else p*2
  )
))


open Printf open Scanf
module MyInt = struct let (+) = (+) let (-) = (-) let (/) = (/) let ( * ) = ( * ) let (mod) = (mod) let (%) = (mod) let (+=) r v = r := !r + v let (-=) r v = r := !r - v let ( *=) r v= r := !r * v let (/=) r v = r := !r / v end
module MyInt64 = struct
	let (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (+) p q = Int64.add p q let (-) p q = Int64.sub p q let ( * ) p q = Int64.mul p q let (/) p q = Int64.div p q 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 labs p = if p < 0L then -1L*p else p let (~|) p = Int64.to_int p let (~~|) p = Int64.of_int p let input_i64_array n = Array.init (~| n) (fun _ -> Scanf.scanf " %Ld" (fun v -> v)) let get_i64 _ = Scanf.scanf " %Ld" (fun v -> v) let get_2_i64 _ = Scanf.scanf " %Ld %Ld" (fun u v -> u,v) let get_3_i64 _ = Scanf.scanf " %Ld %Ld %Ld" (fun u v w -> u,v,w) let get_4_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld" (fun u v w x -> u,v,w,x) let get_5_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld %Ld" (fun u v w x y -> u,v,w,x,y) let print_i64_endline n = n |> Int64.to_string |> print_endline let (mod) m n = m - (m/n) * n let (%) = (mod) let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n) let lcm m n = (m*n) / gcd m n let rep from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod ~~| !i with | `Break -> f := false | _ -> i := !i +$ 1; done
	let string_of_list ?(separator=" ") f ls = let rec f0 a s = match a with | [] -> s | [h] -> s ^ (f h) ^ separator | h::t -> f0 t (s ^ (f h) ^ separator) in f0 ls "" 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 (@@@) = (@) let (@) a i = a.(~|i) let (<@) a (i,v) = a.(~|i) <- v
	let ceildiv m n = (m+n-1L) / n
end open MyInt64

let () =
	let n,k = get_2_i64 0
	in
	let a0 = ceildiv k n
	in printf "%Ld\n" a0

let split_on_space (str: string): string list =
	let length = String.length str in
	let is_space: int -> bool =
		fun index ->
			if (index < 0) || (index >= length) then true
			else str.[index] = ' '
	in
	let is_start: int -> bool =
		fun index -> not (is_space index) && is_space (index - 1)
	in
	let is_end: int -> bool =
		fun index -> not (is_space index) && is_space (index + 1)
	in
	let indices = Array.init length (fun i -> i) in
	let indices = Array.to_list indices in
	let start_pos = List.filter is_start indices in
	let end_pos = List.filter is_end indices in
	let make_substring: string list -> int -> int -> string list =
		fun tokens left right ->
			let new_token = String.sub str left (right - left + 1) in
			new_token :: tokens
	in
	let tokens = List.fold_left2 make_substring [] start_pos end_pos in
	List.rev tokens

class reader channel =
	object (this)

	val mutable tokens = []

  method private get_tokens () =
    let new_line = read_line () in
    let tokens = split_on_space new_line in
    match tokens with
    | [] -> this#get_tokens ()
    | _ -> tokens

	method next_string () =
    if (List.length tokens = 0) then tokens <- this#get_tokens();
    let result = List.hd tokens in
    tokens <- List.tl tokens; result

  method next_int () =
    let str = this#next_string() in (Int64.of_string) str

  method next_float () =
    let str = this#next_string() in (float_of_string) str

end

let reader = new reader stdin

let ( + ) = Int64.add
let ( - ) = Int64.sub
let ( * ) = Int64.mul
let ( / ) = Int64.div
let ( % ) = Int64.rem

let compare = Int64.compare
let ( = ) a b = compare a b = 0
let ( < ) a b = compare a b < 0
let ( > ) a b = compare a b > 0
let ( <= ) a b = compare a b <= 0
let ( >= ) a b = compare a b >= 0

let () =
  let n = reader#next_int () in
  let k = reader#next_int () in
  let res = k / n in
  let res = if k % n = Int64.zero then res else res + Int64.one in
  print_endline (Int64.to_string res);

let split_on_space (str: string): string list =
	let length = String.length str in
	let is_space: int -> bool =
		fun index ->
			if (index < 0) || (index >= length) then true
			else str.[index] = ' '
	in
	let is_start: int -> bool =
		fun index -> not (is_space index) && is_space (index - 1)
	in
	let is_end: int -> bool =
		fun index -> not (is_space index) && is_space (index + 1)
	in
	let indices = Array.init length (fun i -> i) in
	let indices = Array.to_list indices in
	let start_pos = List.filter is_start indices in
	let end_pos = List.filter is_end indices in
	let make_substring: string list -> int -> int -> string list =
		fun tokens left right ->
			let new_token = String.sub str left (right - left + 1) in
			new_token :: tokens
	in
	let tokens = List.fold_left2 make_substring [] start_pos end_pos in
	List.rev tokens

class reader channel =
	object (this)

	val mutable tokens = []

  method private get_tokens () =
    let new_line = read_line () in
    let tokens = split_on_space new_line in
    match tokens with
    | [] -> this#get_tokens ()
    | _ -> tokens

	method next_string () =
    if (List.length tokens = 0) then tokens <- this#get_tokens();
    let result = List.hd tokens in
    tokens <- List.tl tokens; result

  method next_int () =
    let str = this#next_string() in (Int64.of_string) str

  method next_float () =
    let str = this#next_string() in (float_of_string) str

end

let reader = new reader stdin

let () =
  let n = reader#next_int () in
  let k = reader#next_int () in
  let res = if n > k then Int64.one else Int64.div k n in
  print_endline (Int64.to_string res);
  flush stdout


open Scanf
open Printf

let print_list_x l = List.iter (fun (a,b) -> printf "%d %s\n" a (if b = -1 then "starts" else "ends")) l
let print_list l = List.iter (fun (a,b) -> printf "%d %d\n" a b) l

let read_int () = scanf " %d" (fun x -> x)
let read_pair () = scanf " %d %d" (fun x y -> (x,y))
let read_list num =
    let rec pom num acc =
        if num = 0 then acc
        else
            let a,b = read_pair () in
            let x,y = (a, -1), (b, 1) in
            pom (num - 1) (x :: y :: acc)
    in pom num []

let n = read_int ()
let k = read_int ()
let intervals = read_list n

(*let get_result ar =
    let cur = ref (fst( ar.(0)))
    and ind, curind = ref 0, ref 0
    and cnt = ref 0 in
    while !ind < n do
        cnt := 0;
        curind := !ind;
        printf "Having %d \n" (fst(ar.(!curind)));
        while !curind < n && fst(ar.(!curind)) = !cur do
            incr cnt;
            let (a,b) = ar.(!curind) in
            ar.(!curind) <- (a+1, b);
            incr curind
        done;
        let (a,b) = ar.(!ind) in
        if (a > b) then incr ind;
        if !cnt >= k then printf "%d \n" !cur; (* fixme *)
        cur := fst (ar.(!ind))
    done*)

let update_result (level, last, li) (num, state) =
    let nlevel = level - state in
    if nlevel = k && state = -1 then (nlevel, num, li)
    else if level = k && state = 1 then (nlevel, num, (last, num)::li)
    else (nlevel, last, li)

let get_result l =
    let _, _, a = List.fold_left update_result (0, 0, []) l
    in List.rev a
    (*let loop l cnt acc =
        match l with
        | []
        | (a,b)::t ->
    in loop l 0 []*)

let print_result res =
    print_int (List.length res); print_newline ();
    print_list res

let intervals = List.sort compare intervals
let res = get_result intervals
let () = print_result res

let getnum =
  let l = 512000 in
  let buf = String.make l ' ' in
  let s = ref 0 in
  let pos = ref 0 in
  let getc () =
    if !pos >= !s then (
      let new_s = input stdin buf 0 l in
	(*if new_s = 0 then raise End_of_file;*)
	s := new_s;
	if new_s = 0 then (
	  buf.[0] <- '\000';
	  s := 1;
	);
	pos := 0;
    );
    let c = buf.[!pos] in
      incr pos;
      c
  in
  let aux () =
    let n = ref 0 in
    let k = ref 1 in
      if !s - !pos < 50 then (
	let c = ref (getc ()) in
	  while !c <= ' ' do
	    c := getc ()
	  done;
	  if !c = '-' then (
	    k := -1;
	    c := getc ();
	  );
	  while !c > ' ' do
	    n := !n * 10 + (Char.code !c - Char.code '0');
	    c := getc ()
	  done;
	  !n * !k
      ) else (
	let c = ref (buf.[!pos]) in
	  incr pos;
	  while !c <= ' ' do
	    c := buf.[!pos];
	    incr pos;
	  done;
	  if !c = '-' then (
	    k := -1;
	    c := buf.[!pos];
	    incr pos;
	  );
	  while !c > ' ' do
	    n := !n * 10 + (Char.code !c - Char.code '0');
	    c := buf.[!pos];
	    incr pos;
	  done;
	  !n * !k
      )
  in
    aux

let _ =
  let n = getnum () in
  let k = getnum () in
  let a = Array.make (2 * n) (0, 0) in
    for i = 0 to n - 1 do
      let l = getnum () in
      let r = getnum () in
	a.(2 * i) <- (l, 0);
	a.(2 * i + 1) <- (r, 1);
    done;
    Array.sort compare a;
    let res = ref [] in
    let cnt = ref 0 in
    let start = ref 0 in
      for i = 0 to 2 * n - 1 do
	let (x, t) = a.(i) in
	  if !cnt >= k
	  then res := (!start, x) :: !res;
	  if t = 0
	  then incr cnt
	  else decr cnt;
	  if !cnt >= k
	  then start := x;
      done;
      let res = List.rev !res in
      let rec combine =
	function
	  | [] -> []
	  | (x1, y1) :: (x2, y2) :: xs when y1 = x2 ->
	      combine ((x1, y2) :: xs)
	  | x :: xs ->
	      x :: combine xs
      in
      let res = combine res in
	Printf.printf "%d\n" (List.length res);
	List.iter (fun (x, y) -> Printf.printf "%d %d\n" x y) res;

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let k = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = Array.make (2 * n) (0, 0) in
    for i = 0 to n - 1 do
      let l = Scanf.bscanf sb "%d " (fun s -> s) in
      let r = Scanf.bscanf sb "%d " (fun s -> s) in
	a.(2 * i) <- (l, 0);
	a.(2 * i + 1) <- (r, 1);
    done;
    Array.sort compare a;
    let res = ref [] in
    let cnt = ref 0 in
    let start = ref 0 in
      for i = 0 to 2 * n - 1 do
	let (x, t) = a.(i) in
	  if !cnt = k
	  then res := (!start, x) :: !res;
	  if t = 0
	  then incr cnt
	  else decr cnt;
	  if !cnt = k
	  then start := x;
      done;
      let res = List.rev !res in
      let rec combine =
	function
	  | [] -> []
	  | (x1, y1) :: (x2, y2) :: xs when y1 = x2 ->
	      combine ((x1, y2) :: xs)
	  | x :: xs ->
	      x :: combine xs
      in
      let res = combine res in
	Printf.printf "%d\n" (List.length res);
	List.iter (fun (x, y) -> Printf.printf "%d %d\n" x y) res;

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let k = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = Array.make (2 * n) (0, 0) in
    for i = 0 to n - 1 do
      let l = Scanf.bscanf sb "%d " (fun s -> s) in
      let r = Scanf.bscanf sb "%d " (fun s -> s) in
	a.(2 * i) <- (l, 0);
	a.(2 * i + 1) <- (r, -1);
    done;
    Array.sort compare a;
    let res = ref [] in
    let cnt = ref 0 in
    let start = ref 0 in
      for i = 0 to 2 * n - 1 do
	let (x, t) = a.(i) in
	  if !cnt = k
	  then res := (!start, x) :: !res;
	  if t = 0
	  then incr cnt
	  else decr cnt;
	  if !cnt = k
	  then start := x;
      done;
      let res = List.rev !res in
      let rec combine =
	function
	  | [] -> []
	  | (x1, y1) :: (x2, y2) :: xs when y1 = x2 ->
	      combine ((x1, y2) :: xs)
	  | x :: xs ->
	      x :: combine xs
      in
      let res = combine res in
	Printf.printf "%d\n" (List.length res);
	List.iter (fun (x, y) -> Printf.printf "%d %d\n" x y) res;


open Printf
open Scanf

let read_int () = bscanf Scanning.stdib " %d " (fun x -> x)
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 () =
  let n = read_int() in
  let k = read_int() in
  let s = Array.init n (fun _ -> read_int()) in

  let fit size =  (* return true if they fit in k boxes of size s.  Assume s >= s.(n-1) *)
    let rec loop i j count =
      if i = j then count+1 else if i>j then count else (
	if s.(i) + s.(j) > size
	then loop i (j-1) (count+1)
	else loop (i+1) (j-1) (count+1)
      )
    in
    let c = loop 0 (n-1) 0 in
    c <= k
  in

  let rec bsearch lo hi = (* lo fails and hi succeeds *)
    if lo = hi-1 then hi else
      let m = (lo+hi)/2 in
      if fit m then bsearch lo m else bsearch m hi
  in

  let answer = if fit s.(n-1)
    then s.(n-1)
    else bsearch s.(n-1) (2*(s.(n-1)))
  in

  printf "%d\n" answer

let main () =
   let (n,k) = Scanf.scanf "%d %d" (fun i j -> (i,j)) in
   let tab = Array.make (2 * k) 0 in
       for i=1 to n do
           Scanf.scanf " %d" (fun j -> tab.(n - i) <- j);
       done;
   let res = ref 0 in
       for i=0 to 2*k - 1 do
           res := max !res (tab.(i) + tab.(2 * k - i - 1));
       done;
   Printf.printf "%d" !res;;

main ();;


let (+|) = Int64.add
let (-|) = Int64.sub
let ( *| ) = Int64.mul
let ( /| ) = Int64.div

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let m = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = Array.make m 0 in
    for i = 0 to n - 1 do
      let k = Scanf.bscanf sb "%d " (fun s -> s) in
      let k = k - 1 in
	a.(k) <- a.(k) + 1
    done;
    let res = ref 0L in
      for i = 0 to m - 1 do
	for j = i + 1 to m - 1 do
	  res := !res +| Int64.of_int a.(i) *| Int64.of_int a.(j)
	done
      done;
      Printf.printf "%Ld\n" !res

open Printf
open Scanf

let read_int () = bscanf Scanning.stdib " %d " (fun x -> x)
let ( ++ ) a b = Int64.add a b
let ( ** ) a b = Int64.mul a b
let long x = Int64.of_int x
let rec sum i j f ac = if i>j then ac else sum (i+1) j f (ac ++ (f i))

let () =

  let n = read_int() in
  let m = read_int() in
  let a = Array.init n (fun _ -> read_int()) in

  let count = Array.make (m+1) 0L in

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

  let answer =
    sum 1 (m-1) (fun i -> sum (i+1) m (fun j -> count.(i)**count.(j)) 0L) 0L
  in

  printf "%Ld\n" answer


let (+|) = Int64.add
let (-|) = Int64.sub
let ( *| ) = Int64.mul
let ( /| ) = Int64.div

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = Array.make n 0L in
  let es = Array.make n [] in
  let () =
    for i = 0 to n - 1 do
      a.(i) <- Scanf.bscanf sb "%Ld " (fun s -> s)
    done;
    for i = 1 to n - 1 do
      let p = Scanf.bscanf sb "%d " (fun s -> s) in
      let c = Scanf.bscanf sb "%Ld " (fun s -> s) in
	es.(p - 1) <- (i, c) :: es.(p - 1)
    done;
  in
  let es = Array.map Array.of_list es in
  let res = ref 0 in
  let rec dfs u s =
    if s < 0L || s > a.(u)
    then incr res;
    for i = 0 to Array.length es.(u) - 1 do
	let (v, c) = es.(u).(i) in
	  if s < 0L || s > a.(u)
	  then dfs v (-1L)
	  else (
	    let s = max 0L (s +| c) in
	      dfs v s
	  )
    done
  in
    dfs 0 0L;
    Printf.printf "%d\n" !res

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 ( // ) a b = Int64.div a b
let ( %% ) a b = Int64.rem a b

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 a = Array.init n (fun _ -> long (read_int())) in

  let tree = Array.make n [] in
  let c = Array.make n 0L in
  let add_edge i j =
    tree.(i) <- j::tree.(i);
    tree.(j) <- i::tree.(j)
  in

  for i = 1 to n-1 do
    let p = -1 + read_int() in
    c.(i) <- long (read_int());
    add_edge i p
  done;

  let mark = Array.make n false in

  let rec dfs v p dist =
    List.iter (fun w ->
      if w <> p then (
	let dist = max 0L (dist ++ c.(w)) in
	dfs w v dist;
	if dist > a.(w) then mark.(w) <- true
      )
    ) tree.(v)
  in

  dfs 0 (-1) 0L;

  let rec dfs2 v p =
    if mark.(v) then 0 else (
      List.fold_left (fun ac w ->
	if w = p then ac else ac + (dfs2 w v)
      ) 1 tree.(v)
    )
  in

  let good_count = dfs2 0 (-1) in

  printf "%d\n" (n - good_count)

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 ( // ) a b = Int64.div a b
let ( %% ) a b = Int64.rem a b

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 a = Array.init n (fun _ -> long (read_int())) in

  let tree = Array.make n [] in
  let c = Array.make n 0L in
  let add_edge i j =
    tree.(i) <- j::tree.(i);
    tree.(j) <- i::tree.(j)
  in

  for i = 1 to n-1 do
    let p = -1 + read_int() in
    c.(i) <- long (read_int());
    add_edge i p
  done;

  let mark = Array.make n false in

  let rec dfs v p dist =
    List.iter (fun w ->
      if w <> p then (
	let dist = dist ++ c.(w) in
	dfs w v dist;
	if dist > a.(w) then mark.(w) <- true
      )
    ) tree.(v)
  in

  dfs 0 (-1) 0L;

  let rec dfs2 v p =
    if mark.(v) then 0 else (
      List.fold_left (fun ac w ->
	if w = p then ac else ac + (dfs2 w v)
      ) 1 tree.(v)
    )
  in

  let good_count = dfs2 0 (-1) in

  printf "%d\n" (n - good_count)


open Scanf

let () = Printexc.record_backtrace true

let read_array n =
  let f i = scanf " %u" (fun i -> i) in
  Array.init n f

let count_array f a =
  Array.fold_left (fun i v -> if f v then i + 1 else i) 0 a

let () =
  let n = scanf " %u " (fun i -> i) in
  let a = read_array n in
  let ret = ref 0 in
  let n1 = count_array (fun x -> x = 1) a in
  let n2 = count_array (fun x -> x = 2) a in
  let n1_0a = ref 0 in
  let n2_0a = ref 0 in
  for ia = 0 to n do begin
    if ia > 0 then begin
      match a.(ia - 1) with
      | 1 -> n1_0a := !n1_0a + 1
      | 2 -> n2_0a := !n2_0a + 1
      | _ -> ()
    end;
    let max_diff = ref min_int in
    let n1_0b = ref !n1_0a in
    let n2_0b = ref !n2_0a in
    for ib = ia to n do
      if ib > ia then begin
        match a.(ib - 1) with
        | 1 -> n1_0b := !n1_0b + 1
        | 2 -> n2_0b := !n2_0b + 1
        | _ -> ()
      end;
      max_diff := max !max_diff (!n2_0b - !n1_0b);
      let n2_bn = n2 - !n2_0b in
      ret := max !ret
        (!n1_0a + n2_bn + !n1_0b - !n2_0a + !max_diff)
    done
  end
  done;
  !ret |> string_of_int |> print_endline

open Scanf

let read_array n =
  let f i = scanf " %u" (fun i -> i) in
  Array.init n f

let count_array f a =
  Array.fold_left (fun i v -> if f v then i + 1 else i) 0 a

let update_ref (ref1, ref2) = function
  | 1 -> ref1 := !ref1 + 1
  | 2 -> ref2 := !ref2 + 1
  | _ -> ()

(*
  ret = max(n1_0a + n2_bn + n2_ak + n1_kb)
      => n1_0a + (n2 - n2_0b) + n2_0k - n2_0a + n1_0b - n1_0k
      => n1_0a + n2_bn - n2_0a + n1_0b + **(n2_0k - n1_0k)**
*)
let () =
  let n = scanf " %u " (fun i -> i) in
  let a = read_array n in

  let ret = ref 0 in
  let n2 = count_array (fun x -> x = 2) a in
  let n1_0a = ref 0 in
  let n2_0a = ref 0 in
  for ia = 0 to n do begin
    if ia > 0 then begin update_ref (n1_0a, n2_0a) a.(ia - 1) end;
    let max_diff = ref min_int in
    let n1_0b = ref !n1_0a in
    let n2_0b = ref !n2_0a in
    for ib = ia to n do
      if ib > ia then begin update_ref (n1_0b, n2_0b) a.(ib - 1) end;
      (* the diff. we are maximizing is effectively (n2_0k - n1_0k) *)
      max_diff := max !max_diff (!n2_0b - !n1_0b);
      let n2_bn = n2 - !n2_0b in
      ret := max !ret
        (!n1_0a + n2_bn + !n1_0b - !n2_0a + !max_diff)
    done
  end
  done;
  !ret |> string_of_int |> print_endline


let ( ** ) a b = Int64.mul a b
let ( ++ ) a b = Int64.add a b
let ( -- ) a b = Int64.sub a b
let ( // ) a b = Int64.div a b
let ( %% ) a b = Int64.rem a b
let long x = Int64.of_int x
let short x = Int64.to_int x

open Printf
open Scanf

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

let () =
        let n = read_int() in
        let a = Array.make n 0 in
        for i = 0 to n - 1 do
                a.(i) <- read_int()
        done;
        let res = ref 1 in
        let cur = ref 1 in
        for i = 1 to n - 1 do
                if a.(i) > a.(i - 1) then
                        cur := !cur + 1
                else
                        cur := 1;
                if res < cur then
                        res := !cur
        done;
        printf "%d\n" !res

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

;;

let rec solve lst cnt ans prev =
    match lst with
    | [] -> max cnt ans
    | hd :: tl -> if hd > prev then
                    solve tl (cnt+1) (max cnt ans) hd
                  else
                    solve tl 1  (max cnt ans) hd
;;

let  main () =
    let _ = read_int () in
    let l = read_nums () in
    let n = solve l 1 1 1000000007 in
    let () = print_int n in
    print_string "\n"

;;

main ()

open Scanf
open Printf

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

let a = Array.make (n+1) 0

let b = Array.make (n+1) 0

for i = 1 to n do
  let j = Scanf.scanf "%d " ( fun x -> x ) in
  a.(i)<-j
done

let cnt = ref 0

for i = 1 to n do
  begin
  if a.(i) > a.(i-1) then
    cnt := !cnt + 1
  else
    cnt := 1
  end; b.(i) <- !cnt
done

(*test
let () = Array.iter (fun x -> printf "%d " x) b
*)

let ff = Array.make (n+1) (-10)
let rec f m =
  if m = 1 then
    1
  else
    if ff.(m-1) < 0 then
      begin
      ff.(m-1) <- f (m-1);
      max ff.(m-1) b.(m)
      end
  else
    max ff.(m-1) b.(m)

let rslt = f n in
printf "%d\n" rslt

open Printf
let input_int_array n =
	Array.init n (fun _ -> Scanf.scanf " %d" (fun v -> v))

let get_int () = Scanf.scanf " %d" (fun v -> v)
let get_2_ints () = Scanf.scanf " %d %d" (fun u v -> u,v)
let get_3_ints () = Scanf.scanf " %d %d %d" (fun u v w -> u,v,w)
let get_4_ints () = Scanf.scanf " %d %d %d %d" (fun u v w x -> u,v,w,x)
let get_5_ints () = Scanf.scanf " %d %d %d %d %d" (fun u v w x y -> u,v,w,x,y)

let print_int_endline n = n |> string_of_int |> print_endline

let () =
  let n = get_int ()
  in let a = input_int_array n
  in let v,len,lenmax = ref a.(0),ref 1,ref 1
  in
  for i=1 to (n-1) do
    if !v < a.(i) then (
      len := !len+1;
      if !len > !lenmax then lenmax := !len;
    ) else (
      len := 1;
    );
    v := a.(i)
  done;
  !lenmax |> print_int_endline

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = Array.make n 0 in
  let _ =
    for i = 0 to n - 1 do
      a.(i) <- Scanf.bscanf sb "%d " (fun s -> s)
    done;
  in
  let res = ref 1 in
  let p = ref a.(0) in
  let len = ref 1 in
    for i = 1 to n - 1 do
      if a.(i) > !p then (
	p := a.(i);
	incr len;
	res := max !res !len;
      ) else (
	p := a.(i);
	len := 1;
      )
    done;
    Printf.printf "%d\n" !res

let n = int_of_string (input_line stdin) ;;

let rec solve last acc best count =
    if count == 0 then max best acc
    else let num = Scanf.scanf "%d " (fun a -> a) in
        if num > last then solve num (acc + 1) best (count - 1)
        else solve num 1 (max best acc) (count - 1) ;;

let ans = solve 0 0 0 n in
    Printf.printf "%d\n" ans ;;

let n = int_of_string (input_line stdin) ;;

let rec solve last acc best count =
    Printf.printf "solve %d %d %d %d\n" last acc best count ;
    if count == 0 then max best acc
    else let num = Scanf.scanf "%d " (fun a -> a) in
        if num > last then solve num (acc + 1) best (count - 1)
        else solve num 1 (max best acc) (count - 1) ;;

let ans = solve 0 0 0 n in
    Printf.printf "%d\n" ans ;;


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 rec exists i j f = (i<=j) && ((f i) || exists (i+1) j f)

let read_int _ = bscanf Scanning.stdin " %d " (fun x -> x)
let () =
  let cases = read_int() in
  for case = 1 to cases do
    let n = read_int() in
    let a = Array.init n read_int in
    let s = sum 0 (n-1) (fun i -> a.(i)) in
    if exists 0 (n-1) (fun i -> a.(i) * n = s)
    then printf "Yes\n" else printf "No\n"
  done


let color_tree n g =
  let colors = Array.make (n+1) 0 in
  let k_max = ref 1 in
  let rec dfs v p =
    let parent_c = colors.(p) in
    let self_c = colors.(v) in
    let children = List.filter (fun x -> x != p) g.(v) in
    let k = ref 0 in
    List.iter (fun child ->
        incr k;
        while !k = parent_c || !k = self_c do incr k done;
        colors.(child) <- !k;
        dfs child v
    ) children;
    k_max := max !k_max !k
  in
  colors.(1) <- 1;
  dfs 1 0;
  (!k_max, colors)

let () =
  let n = Scanf.scanf "%d" (fun x -> x) in
  let out = Array.make (n + 1) [] in
  for i = 2 to n do
    let (a, b) = Scanf.scanf " %d %d" (fun x y -> (x, y)) in
    out.(a) <- b :: out.(a);
    out.(b) <- a :: out.(b)
  done;
  let (k, colors) = color_tree n out in
  Printf.printf "%d\n%d" k colors.(1);
  for i = 2 to n do
    Printf.printf " %d" colors.(i)
  done;
  Printf.printf "\n"

open Printf
open Scanf

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

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

let () =
  let n = read_int () in

  let tree = Array.make n [] in

  let add_edge (i,j) =
    tree.(i) <- j::tree.(i);
    tree.(j) <- i::tree.(j)
  in

  for i=1 to n-1 do add_edge (read_pair ()) done;

  let color = Array.make n 0 in

  let nextcolor trycolor p v =
    let pcolor = if p < 0 then 0 else color.(p) in
    let vcolor = if v < 0 then 0 else color.(v) in
    if trycolor <> pcolor && trycolor <> vcolor then trycolor
    else
      let trycolor = trycolor + 1 in
      if trycolor <> pcolor && trycolor <> vcolor then trycolor
      else trycolor + 1
  in

  let rec dfs p v =
    let _ = List.fold_left (fun trycolor w -> if w = p then trycolor else (
      color.(w) <- nextcolor trycolor p v;
      dfs v w;
      color.(w) + 1
    )
    ) 1 tree.(v)
    in ()
  in

  color.(0) <- 1;
  dfs (-1) 0;

  let mcolor = maxf 0 (n-1) (fun i -> color.(i)) in

  printf "%d\n" mcolor;

  for i=0 to n-1 do
    printf "%d " color.(i)
  done;

  print_newline()

let color_tree n g =
  let colors = Array.make (n+1) 0 in
  let k_max = ref 1 in
  let rec dfs v p =
    let parent_c = colors.(p) in
    let self_c = colors.(v) in
    let children = List.filter (fun x -> x != p) g.(v) in
    let k = ref 0 in
    List.iter (fun child ->
        incr k;
        if !k = parent_c then incr k;
        if !k = self_c then incr k;
        colors.(child) <- !k;
        dfs child v
    ) children;
    k_max := max !k_max !k
  in
  colors.(1) <- 1;
  dfs 1 0;
  (!k_max, colors)

let () =
  let n = Scanf.scanf "%d" (fun x -> x) in
  let out = Array.make (n + 1) [] in
  for i = 2 to n do
    let (a, b) = Scanf.scanf " %d %d" (fun x y -> (x, y)) in
    out.(a) <- b :: out.(a);
    out.(b) <- a :: out.(b)
  done;
  let (k, colors) = color_tree n out in
  Printf.printf "%d\n%d" k colors.(1);
  for i = 2 to n do
    Printf.printf " %d" colors.(i)
  done;
  Printf.printf "\n"


let read_int () = Scanf.scanf "%d " (fun x -> x);;
let read_int3 () = Scanf.scanf " %d %d %d " (fun x y z -> (x,y,z) );;

let inc_or_dec = function
  | "X++" -> 1
  | "++X" -> 1
  | "--X" -> -1
  | "X--" -> -1
;;

let read_s () = Scanf.scanf "%s " (fun x -> inc_or_dec x );;

let n = read_int ();;

let a = Array.init n (fun i -> (read_s () ));;

let b = Array.fold_left (+) 0 a in print_int b; print_endline ""

open Printf;;
open Scanf;;
let n=read_int();;

let rec solve n x =
  if n=0 then x
  else
    let s=read_line() in
     if ((s="X++") || (s="++X")) then (solve (n-1) (x+1)) else (solve (n-1) (x-1))
;;

printf "%d\n" (solve n 0);;

open Printf;;
open Scanf;;
open List;;
let rec initlist n = if (n=0) then [] else 0::(initlist (n-1)) ;;

			let n=read_int();;
			let r=map (fun x -> read_line()) (initlist n);;
			let ans=fold_left (fun x y -> if ((y="X++") || (y="++X")) then x+1 else x-1) 0 r;;
			  printf "%d\n" ans;;

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

let execute s x = match s with
    |"X++" | "++X" -> x + 1
    |_ -> x - 1

let rec solve n x =
    if n > 0
    then
        let bit_function = Scanf.scanf "%s " (fun s -> s) in
        solve (n - 1) (execute bit_function x)
    else
        Printf.printf "%d\n" x

let () = solve number_of_operations 0

let () =
  let n = Scanf.scanf "%d " (fun a -> a) in
  let a_lst = Array.to_list @@ Array.init n (fun _ -> Scanf.scanf "%s " (fun a -> a)) in
  let l = List.map (fun x -> String.sub x 1 1) a_lst in

  let p = List.filter (fun x -> x = "+") l |>
          List.length in
  let m = n-p in
  Printf.printf "%d\n" @@ p-m

let rec solve (n : int) (ak : int) =
  if n = 0 then
    ak
  else
    let op = read_line () in
    match op with
    | "X++" -> solve (n - 1) (ak + 1)
    | "++X" -> solve (n - 1) (ak + 1)
    | "X--" -> solve (n - 1) (ak - 1)
    | "--X" -> solve (n - 1) (ak - 1)
    | _ -> raise (Failure "Unsupported Operation")

let () =
  let n = read_int () in
  Printf.printf "%d" (solve n 0)

let n=Scanf.scanf "%d" (fun a->a);;
let x=ref 0;;
for i=1 to n do
   x:=!x+(Scanf.scanf " %s" (fun a-> if (String.contains a '+')==true then 1 else -1))
done;;
print_int(!x);;

let rec read_lines n =
  match n with
  | 0 -> []
  | _ -> let res = read_line () in
    res :: read_lines (n - 1)

let () =
  let num = read_int() in
  let res = read_lines num in
  List.fold_left (fun num str ->
    if String.contains str '-'
    then
      num - 1
    else
      num + 1
    ) 0 res
  |> Printf.printf "%d"
;;

let read_int () = Scanf.scanf "%d " (fun x -> x);;
let read_int3 () = Scanf.scanf " %d %d %d " (fun x y z -> (x,y,z) );;

let inc_or_dec = function
  | "X++" -> 1
  | "++X" -> 1
  | _ -> -1
;;

let read_s () = Scanf.scanf "%s " (fun x -> inc_or_dec x );;

let n = read_int ();;

let a = Array.init n (fun i -> (read_s () ));;

let b = Array.fold_left (+) 0 a in print_int b; print_endline ""

let read_int () = Scanf.scanf "%d" (fun x -> x)
let read_string () = Scanf.scanf " %s" (fun x -> x)

let get_bit n =
  let rec calculate_bit r = function
    | 0 -> r
    | n ->  match read_string () with
              | "X++" | "++X" -> calculate_bit (r + 1) (n - 1)
              | "X--" | "--X" -> calculate_bit (r - 1) (n - 1)
              | q -> Printf.printf "%s\n" q; assert  false
  in calculate_bit 0 n

let () = Printf.printf "%d\n" (get_bit (read_int ()))

let pf = Printf.printf;;
let sf = Scanf.scanf;;

let (|>) x f = f x;;
let (@@) f x = f x;;
let read0() = sf "%d " (fun x -> x)
let read1() = sf "%d\n" (fun x -> x)
let read2() = sf "%d %d\n" (fun x y -> x, y)
let read3() = sf "%d %d %d\n" (fun x y z -> x, y, z)

exception Error of string

let inf = 1000000000;;
let eps = 1e-11;;

let _ =
  let n = int_of_string @@ read_line() in
  let res = ref 0 in
  for i = 1 to n do
    let s = read_line() in
    res := !res + if s.[1] == '+' then 1 else -1
  done;
  pf "%d\n" !res
;;

open Printf

let read_ints() =
	Array.map (int_of_string) (Array.of_list (Str.split (Str.regexp " +") (read_line())))

let main =
    let n = read_int() in
    let ans = ref 0 in
    for i = 1 to n do
        let ins = read_line() in
        if ins.[1] = '+' then
            ans := !ans + 1
        else
            ans := !ans - 1
    done;
    printf "%d\n" !ans

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

let () =
  let n = read_int() in
  let x = ref 0 in
    for i=1 to n do
      let s = read_string() in
	if s="++X" || s="X++" then x := !x+1
	else if s="--X" || s="X--" then x := !x-1
	else failwith "bad statement"
    done;
    Printf.printf "%d\n" !x


(* An implementation of link-cut trees in ocaml *)

type node = {
  mutable id:(int*int);
  mutable l:node;
  mutable r:node;
  mutable p:node
}

let rec null = {id=(0,0); l=null; r=null; p=null}

let isroot n =
  n.p == null || (n.p.l != n && n.p.r != n)

let update p = ()

let discharge p = ()

let rot_right p =
  let q = p.p in
  let r = q.p in
  q.l <- p.r;
  if q.l != null then q.l.p <- q;
  p.r <- q;
  q.p <- p;
  p.p <- r;
  if r != null then (
    if r.l == q then r.l <- p
    else if r.r == q then r.r <- p
  );
  update q

let rot_left p =
  let q = p.p in
  let r = q.p in
  q.r <- p.l;
  if q.r != null then q.r.p <- q;
  p.l <- q;
  q.p <- p;
  p.p <- r;
  if r != null then (
    if r.r == q then r.r <- p
    else if r.l == q then r.l <- p
  );
  update q

let splay p =
  let rec loop p = if not (isroot p) then
      let q = p.p in
      if isroot q then (
	discharge q;
	discharge p;
	if q.l == p then rot_right p else rot_left p
      ) else (
	let r = q.p in
	discharge r;
	discharge q;
	discharge p;
	if r.l == q then (
	  if q.l == p then (rot_right q; rot_right p)
	  else (rot_left p; rot_right p)
	) else (
	  if q.r == p then (rot_left q; rot_left p)
	  else (rot_right p; rot_left p)
	)
      );
      loop p
  in
  loop p;
  discharge p;  (* useful only if p was already the root *)
  update p      (* only useful if p was not already a root *)

let expose q =
  let rec loop r p = if p==null then r else (
    splay p;
    p.l <- r;
    update p;
    loop p p.p
  ) in

  let r = loop null q in
  splay(q);
  r  (* we only use this return value in the LCA operation *)

let link p q =
  ignore(expose p);
  if p.r != null then failwith "p's right child should be null";
  p.p <- q

let lca a b =
  ignore(expose a);
  expose(b)

let cut a =
  ignore(expose a);
  if a.r != null then (
    a.r.p <- null;
    a.r <- null;
    update a
  )

let findroot p =
  ignore(expose p);
  let rec loop p = if p.r == null then p else loop p.r in
  let p = loop p in
  splay p;
  p

(*--------------------------------------------------------------------------*)

open Printf
open Scanf

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

let () =
  let n = read_int() in
  let m = read_int() in
  let q = read_int() in

  let board = Array.make n "" in
  let treenode = Array.make_matrix n m null in
  let nodetype = Array.make_matrix n m (0,0) in

  let on_board (i,j) = i>=0 && i<n && j>=0 && j<m in
  let getnodetype (i,j) = nodetype.(i).(j) in

  let linkcell (i,j) dir =
    (* cell(i,j) is a root.  we want to link it to the cell in direction dir *)
    let (ii,jj) =
      match dir with
        | '<' -> (i,j-1)
        | '>' -> (i,j+1)
        | '^' -> (i-1,j)
        | 'v' -> (i+1,j)
	| _ -> failwith "bad direction"
    in

    nodetype.(i).(j) <- (ii,jj);
    if on_board (ii,jj) then (
      let a = treenode.(i).(j) in (* a is already a root *)
      let b = treenode.(ii).(jj) in
      let broot = findroot b in

      if broot != a then (  (* not a cycle root *)
	nodetype.(i).(j) <- (-1,-1);   (* a is no longer a root *)
	link a b;
      )
    )
  in

  let update_board (i,j) dir =
    let a = treenode.(i).(j) in
    let b = findroot a in
    let (ii,jj) = getnodetype b.id in
    cut a;
    if on_board (ii,jj) then ( (* b is the root of a cycle tree *)
      let c = treenode.(ii).(jj) in
      if a != b && lca a c == a then link b c;
    );
    linkcell (i,j) dir
  in

  for i=0 to n-1 do
    board.(i) <- read_string()
  done;

  for i=0 to n-1 do
    for j=0 to m-1 do
      treenode.(i).(j) <- {null with id=(i,j)}
    done
  done;

  for i=0 to n-1 do
    for j=0 to m-1 do
      linkcell (i,j) board.(i).[j]
    done
  done;

  for query=0 to q-1 do
    let command = read_string() in
    let i = read_int()-1 in
    let j = read_int()-1 in

    match command with
      | "A" ->
	let r = findroot treenode.(i).(j) in
	let (ii,jj) = getnodetype r.id in
	if on_board (ii,jj)
	then printf "-1 -1\n"
	else printf "%d %d\n" (ii+1) (jj+1)
      | "C" ->
	update_board (i,j) (read_string()).[0]
      | _ -> failwith "unsupported command"
  done

type node = {
  mutable id:(int*int);
  mutable l:node;
  mutable r:node;
  mutable p:node
}

let rec null = {id=(0,0); l=null; r=null; p=null}

let isroot n =
  n.p == null || (n.p.l != n && n.p.r != n)

let update p = ()

let discharge p = ()

let rot_right p =
  let q = p.p in
  let r = q.p in
  q.l <- p.r;
  if q.l != null then q.l.p <- q;
  p.r <- q;
  q.p <- p;
  p.p <- r;
  if r != null then (
    if r.l == q then r.l <- p
    else if r.r == q then r.r <- p
  );
  update q

let rot_left p =
  let q = p.p in
  let r = q.p in
  q.r <- p.l;
  if q.r != null then q.r.p <- q;
  p.l <- q;
  q.p <- p;
  p.p <- r;
  if r != null then (
    if r.r == q then r.r <- p
    else if r.l == q then r.l <- p
  );
  update q

let splay p =
  let rec loop p = if not (isroot p) then
      let q = p.p in
      if isroot q then (
	discharge q;
	discharge p;
	if q.l == p then rot_right p else rot_left p
      ) else (
	let r = q.p in
	discharge r;
	discharge q;
	discharge p;
	if r.l == q then (
	  if q.l == p then (rot_right q; rot_right p)
	  else (rot_left p; rot_right p)
	) else (
	  if q.r == p then (rot_left q; rot_left p)
	  else (rot_right p; rot_left p)
	)
      );
      loop p
  in
  loop p;
  discharge p;  (* useful only if p was already the root *)
  update p      (* only useful if p was not already a root *)

let expose q =
  let rec loop r p = if p==null then r else (
    splay p;
    p.l <- r;
    update p;
    loop p p.p
  ) in

  let r = loop null q in
  splay(q);
  r  (* we only use this return value in the LCA operation *)

let link p q =
  ignore(expose p);
  if p.l != null then failwith "p's left child should be null";
  p.p <- q

let lca a b =
  ignore(expose a);
  expose(b)

let cut a =
  ignore(expose a);
  if a.r != null then (
    a.r.p <- null;
    a.r <- null;
    update a
  )

let findroot p =
  ignore(expose p);
  let rec loop p = if p.r == null then p else loop p.r in
  let p = loop p in
  splay p;
  p

(*--------------------------------------------------------------------------*)

open Printf
open Scanf

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

let () =
  let n = read_int() in
  let m = read_int() in
  let q = read_int() in

  let board = Array.make n "" in
  let treenode = Array.make_matrix n m null in
  let nodetype = Array.make_matrix n m (0,0) in

  let on_board (i,j) = i>=0 && i<n && j>=0 && j<m in
  let getnodetype (i,j) = nodetype.(i).(j) in

  let linkcell (i,j) dir =
    (* cell(i,j) is a root.  we want to link it to the cell in direction dir *)
    let (ii,jj) =
      match dir with
        | '<' -> (i,j-1)
        | '>' -> (i,j+1)
        | '^' -> (i-1,j)
        | 'v' -> (i+1,j)
	| _ -> failwith "bad direction"
    in

    nodetype.(i).(j) <- (ii,jj);
    if on_board (ii,jj) then (
      let a = treenode.(i).(j) in (* a is already a root *)
      let b = treenode.(ii).(jj) in
      let broot = findroot b in

      if broot != a then (  (* not a cycle root *)
	nodetype.(i).(j) <- (-1,-1);   (* a is no longer a root *)
	link a b;
      )
    )
  in

  let update_board (i,j) dir =
    let a = treenode.(i).(j) in
    let b = findroot a in
    let (ii,jj) = getnodetype b.id in
    cut a;
    if on_board (ii,jj) then ( (* b is the root of a cycle tree *)
      let c = treenode.(ii).(jj) in
      if a != b && lca a c == a then link b c;
    );
    linkcell (i,j) dir
  in

  for i=0 to n-1 do
    board.(i) <- read_string()
  done;

  for i=0 to n-1 do
    for j=0 to m-1 do
      treenode.(i).(j) <- {null with id=(i,j)}
    done
  done;

  for i=0 to n-1 do
    for j=0 to m-1 do
      linkcell (i,j) board.(i).[j]
    done
  done;

  for query=0 to q-1 do
    let command = read_string() in
    let i = read_int()-1 in
    let j = read_int()-1 in

    match command with
      | "A" ->
	let r = findroot treenode.(i).(j) in
	let (ii,jj) = getnodetype r.id in
	if on_board (ii,jj)
	then printf "-1 -1\n"
	else printf "%d %d\n" (ii+1) (jj+1)
      | "C" ->
	update_board (i,j) (read_string()).[0]
      | _ -> failwith "unsupported command"
  done


type tree = Node of int*tree*tree | Leaf
type operator = Or | Xor

let (|>) x f = f x

let flip = function
    Or -> Xor
  | Xor -> Or

let denote_op = function
  |  Or -> (lor)
  | Xor -> (lxor)
;;

let compose_tree seq =
  let rec build_row op seq acc =
    match seq with
      | [] -> List.rev acc
      | (Node (a,tl,tr)) :: (Node (b,tl2,tr2)) :: xs ->
          build_row op xs
            ((Node (denote_op op a b, Node (a, tl, tr), Node (b, tl2, tr2))) :: acc)
  in
  let rec iter_rows op seq =
    match seq with
        [t] -> t
      | xs ->
          iter_rows (flip op) (build_row op seq [])
  in
    iter_rows Or seq

let rec update_leaf leafs p v t =
  match t with
    | Leaf -> Leaf
    | Node (a, Leaf, Leaf) -> Node (v, Leaf, Leaf)
    | Node (a,tl,tr) ->
        if (p > leafs/2) then
          Node (a,tl, update_leaf (leafs/2) (p - (leafs/2)) v tr)
        else
          Node (a, update_leaf (leafs/2) p v tl,tr)

let rec recalculate_path leafs p t =
  match t with
    | Leaf -> failwith "invariant broken"
    | Node (a, Leaf, Leaf) -> (Node (a, Leaf, Leaf), Or)
    | Node (a,tl,tr) ->
        if (p > leafs/2) then
          let (Node (v,tl2,tr2), op) =
            recalculate_path (leafs/2) (p - (leafs/2)) tr in
            match tl with
                Leaf -> failwith "invariant broken"
              | Node (b,_,_) ->
                  (Node (denote_op op b v, tl, Node (v,tl2,tr2)), flip op)
        else
          let (Node (v,tl2,tr2),op) = recalculate_path (leafs/2) p tl in
            match tr with
                Leaf -> failwith "invariant broken"
              | Node (b,_,_) ->
                  (Node (denote_op op b v, Node (v,tl2,tr2), tr), flip op)

let rec print_tree = function
    Leaf -> Printf.printf " - "
  | Node (a, tl, tr) ->
      print_tree tl;
      Printf.printf "%d " a;
      print_tree tr

let rec print_root = function
    Leaf -> failwith "error"
  | Node (a, _, _) ->
      Printf.printf "%d\n" a

let main =
  let (n,m) = Scanf.scanf "%d %d\n" (fun a b -> (a,b)) in
  let leafs = 2 lsl (n-1) in
  let rec aux f n acc =
    match n with
        0 -> List.rev acc
      | n ->
          aux f (n-1) ((f ()) :: acc)
  in
  let tree =
    aux (fun _ -> Scanf.scanf "%d " (fun n -> Node (n, Leaf, Leaf))) leafs [] |>
      compose_tree
  in
  let queries = aux (fun _ -> Scanf.scanf "%d %d " (fun p v -> (p,v))) m [] in
    List.fold_left (fun t (p,v) ->
                      let t_new =
                        update_leaf leafs p v t |>
                        recalculate_path leafs p |>
                        fst
                      in print_root t_new; t_new) tree queries

let n,m = Scanf.scanf "%d %d\n" (fun x y->x,y);;
let arr = Array.make (1 lsl n) 0;;
let rec read_ints x =
  if x = (1 lsl n) then ()
  else begin
    arr.(x) <- Scanf.scanf "%d " (fun x -> x);
    read_ints (x+1);
  end in
read_ints 0;;

type t = Leaf | Node of t * int * t;;

let oper n l r =
  if (n mod 2) = 0 then (l lxor r)
  else (l lor r);;

let tree =
  let rec make_tree n x =
    if n = 0 then
      Node (Leaf,arr.(x),Leaf)
    else
      match (make_tree (n-1) (2*x)) ,(make_tree (n-1) (2*x+1)) with
      | (Node(_,l,_) as a),(Node(_,r,_) as b) -> Node(a,(oper n l r),b)
  in make_tree n 0;;

let rec modify tree n x p =
  match tree with
  | Node (Leaf,key,Leaf) as org ->
    if (x = p) then Node(Leaf,arr.(p),Leaf) else org
  | Node (left,key,right) as org ->
    let len = (1 lsl n) in
    let a,b = x*len,x*len+len-1 in
    if (p>=a && p<=b) then
      match (modify left (n-1) (x+x) p),(modify right (n-1) (x+x+1) p) with
      | (Node(_,l,_) as a),(Node(_,r,_) as b) -> Node (a,(oper n l r),b)
    else org;;

let rec query tree x =
  if x = m then
    ()
  else begin
    let p,b = Scanf.scanf "%d %d\n" (fun x y -> (x-1),y) in
    arr.(p) <- b;
    let tree = modify tree n 0 p in
    let Node(_,key,_) = tree in
    Printf.printf "%d\n" key;
    query tree (x+1);
  end in query tree 0;;

type tree = Node of int*tree*tree | Leaf
type operator = Or | Xor

let (|>) x f = f x

let flip = function
    Or -> Xor
  | Xor -> Or

let denote_op = function
  |  Or -> (lor)
  | Xor -> (lxor)
;;

let compose_tree seq =
  let rec build_row op seq acc =
    match seq with
      | [] -> List.rev acc
      | (Node (a,tl,tr)) :: (Node (b,tl2,tr2)) :: xs ->
          build_row op xs
            ((Node (denote_op op a b, Node (a, tl, tr), Node (b, tl2, tr2))) :: acc)
  in
  let rec iter_rows op seq =
    match seq with
        [t] -> t
      | xs ->
          iter_rows (flip op) (build_row op seq [])
  in
    iter_rows Or seq

let rec update_leaf leafs p v t =
  match t with
    | Leaf -> Leaf
    | Node (a, Leaf, Leaf) -> Node (v, Leaf, Leaf)
    | Node (a,tl,tr) ->
        if (p > leafs/2) then
          Node (a,tl, update_leaf (leafs/2) (p/2) v tr)
        else
          Node (a, update_leaf (leafs/2) p v tl,tr)

let rec recalculate_path leafs p t =
  match t with
    | Leaf -> failwith "invariant broken"
    | Node (a, Leaf, Leaf) -> (Node (a, Leaf, Leaf), Or)
    | Node (a,tl,tr) ->
        if (p > leafs/2) then
          let (Node (v,tl2,tr2), op) =
            recalculate_path (leafs/2) (p/2) tr in
            match tl with
                Leaf -> failwith "invariant broken"
              | Node (b,_,_) ->
                  (Node (denote_op op b v, tl, Node (v,tl2,tr2)), flip op)
        else
          let (Node (v,tl2,tr2),op) = recalculate_path (leafs/2) p tl in
            match tr with
                Leaf -> failwith "invariant broken"
              | Node (b,_,_) ->
                  (Node (denote_op op b v, Node (v,tl2,tr2), tr), flip op)

let rec print_tree = function
    Leaf -> Printf.printf " - "
  | Node (a, tl, tr) ->
      print_tree tl;
      Printf.printf "%d " a;
      print_tree tr

let rec print_root = function
    Leaf -> failwith "error"
  | Node (a, _, _) ->
      Printf.printf "%d\n" a

let main =
  let (n,m) = Scanf.scanf "%d %d\n" (fun a b -> (a,b)) in
  let leafs = 2 lsl (n-1) in
  let rec aux f n acc =
    match n with
        0 -> List.rev acc
      | n ->
          aux f (n-1) ((f ()) :: acc)
  in
  let tree =
    aux (fun _ -> Scanf.scanf "%d " (fun n -> Node (n, Leaf, Leaf))) leafs [] |>
      compose_tree
  in
  let queries = aux (fun _ -> Scanf.scanf "%d %d " (fun p v -> (p,v))) m [] in
    List.fold_left (fun t (p,v) ->
                      let t_new =
                        update_leaf leafs p v t |>
                        recalculate_path leafs p |>
                        fst
                      in print_root t_new; t_new) tree queries

type tree = Node of int*tree*tree | Leaf
type operator = Or | Xor

let (|>) x f = f x

let flip = function
    Or -> Xor
  | Xor -> Or

let denote_op = function
  |  Or -> (lor)
  | Xor -> (lxor)
;;

let compose_tree seq =
  let rec build_row op seq acc =
    match seq with
      | [] -> List.rev acc
      | (Node (a,tl,tr)) :: (Node (b,tl2,tr2)) :: xs ->
          build_row op xs
            ((Node (denote_op op a b, Node (a, tl, tr), Node (b, tl2, tr2))) :: acc)
  in
  let rec iter_rows op seq =
    match seq with
        [t] -> t
      | xs ->
          iter_rows (flip op) (build_row op seq [])
  in
    iter_rows Or seq

let rec update_leaf leafs p v t =
  match t with
    | Leaf -> Leaf
    | Node (a, Leaf, Leaf) -> Node (v, Leaf, Leaf)
    | Node (a,tl,tr) ->
        if (p > leafs/2) then
          Node (a,tl, update_leaf (leafs/2) (p mod (leafs/2)) v tr)
        else
          Node (a, update_leaf (leafs/2) p v tl,tr)

let rec recalculate_path leafs p t =
  match t with
    | Leaf -> failwith "invariant broken"
    | Node (a, Leaf, Leaf) -> (Node (a, Leaf, Leaf), Or)
    | Node (a,tl,tr) ->
        if (p > leafs/2) then
          let (Node (v,tl2,tr2), op) =
            recalculate_path (leafs/2) (p mod (leafs/2)) tr in
            match tl with
                Leaf -> failwith "invariant broken"
              | Node (b,_,_) ->
                  (Node (denote_op op b v, tl, Node (v,tl2,tr2)), flip op)
        else
          let (Node (v,tl2,tr2),op) = recalculate_path (leafs/2) p tl in
            match tr with
                Leaf -> failwith "invariant broken"
              | Node (b,_,_) ->
                  (Node (denote_op op b v, Node (v,tl2,tr2), tr), flip op)

let rec print_root = function
    Leaf -> failwith "error"
  | Node (a, _, _) ->
      Printf.printf "%d\n" a

let main =
  let (n,m) = Scanf.scanf "%d %d\n" (fun a b -> (a,b)) in
  let leafs = 2 lsl (n-1) in
  let rec aux f n acc =
    match n with
        0 -> List.rev acc
      | n ->
          aux f (n-1) ((f ()) :: acc)
  in
  let tree =
    aux (fun _ -> Scanf.scanf "%d " (fun n -> Node (n, Leaf, Leaf))) leafs [] |>
      compose_tree
  in
  let queries = aux (fun _ -> Scanf.scanf "%d %d " (fun p v -> (p,v))) m [] in
    List.fold_left (fun t (p,v) ->
                      let t_new =
                        update_leaf leafs p v t |>
                        recalculate_path leafs p |>
                        fst
                      in print_root t_new; t_new) tree queries

type tree = Node of int*tree*tree | Leaf
type operator = Or | Xor

let (|>) x f = f x

let flip = function
    Or -> Xor
  | Xor -> Or

let denote_op = function
  |  Or -> (lor)
  | Xor -> (lxor)
;;

let compose_tree seq =
  let rec build_row op seq acc =
    match seq with
      | [] -> List.rev acc
      | (Node (a,tl,tr)) :: (Node (b,tl2,tr2)) :: xs ->
          build_row op xs
            ((Node (denote_op op a b, Node (a, tl, tr), Node (b, tl2, tr2))) :: acc)
  in
  let rec iter_rows op seq =
    match seq with
        [t] -> t
      | xs ->
          iter_rows (flip op) (build_row op seq [])
  in
    iter_rows Or seq

let rec update_leaf leafs p v t =
  match t with
    | Leaf -> Leaf
    | Node (a, Leaf, Leaf) -> Node (v, Leaf, Leaf)
    | Node (a,tl,tr) ->
        if (p > leafs/2) then
          Node (a,tl, update_leaf (leafs/2) (p/2) v tr)
        else
          Node (a, update_leaf (leafs/2) p v tl,tr)

let rec recalculate_path leafs p t =
  match t with
    | Leaf -> failwith "invariant broken"
    | Node (a, Leaf, Leaf) -> (Node (a, Leaf, Leaf), Or)
    | Node (a,tl,tr) ->
        if (p > leafs/2) then
          let (Node (v,tl2,tr2), op) =
            recalculate_path (leafs/2) (p/2) tr in
            match tl with
                Leaf -> failwith "invariant broken"
              | Node (b,_,_) ->
                  (Node (denote_op op b v, tl, Node (v,tl2,tr2)), flip op)
        else
          let (Node (v,tl2,tr2),op) = recalculate_path (leafs/2) p tl in
            match tr with
                Leaf -> failwith "invariant broken"
              | Node (b,_,_) ->
                  (Node (denote_op op b v, Node (v,tl2,tr2), tr), flip op)

let rec print_tree = function
    Leaf -> Printf.printf " - "
  | Node (a, tl, tr) ->
      print_tree tl;
      Printf.printf "%d " a;
      print_tree tr

let rec print_root = function
    Leaf -> failwith "error"
  | Node (a, _, _) ->
      Printf.printf "%d\n" a

let main =
  let (n,m) = Scanf.scanf "%d %d\n" (fun a b -> (a,b)) in
  let leafs = 2 lsl (n-1) in
  let rec aux f n acc =
    match n with
        0 -> List.rev acc
      | n ->
          aux f (n-1) ((f ()) :: acc)
  in
  let tree =
    aux (fun _ -> Scanf.scanf "%d " (fun n -> Node (n, Leaf, Leaf))) leafs [] |>
      compose_tree
  in
  let queries = aux (fun _ -> Scanf.scanf "%d %d " (fun p v -> (p,v))) m [] in
    List.fold_left (fun t (p,v) ->
                      let t_new =
                        update_leaf leafs p v t |>
                        recalculate_path leafs p |>
                        fst
                      in print_tree t_new; Printf.printf "\n\n"; t_new) tree queries


open Printf

let main =
  let t = read_int() in
  for i = 1 to t do
    let _ = read_int() in
    let brackets = read_line() in

    let answer = ref 0 in
    let m = ref 0 in

    String.iter (fun c ->
      if c = '(' then
        m := !m + 1
      else if c = ')' then
        m := !m - 1;
        if !m < 0 then
          answer := max (!answer) (-(!m))
    ) brackets;
    printf "%d\n" (!answer)
  done

module A = Array
module C = Char
module I = Int64
module L = List
module Q = Queue
module S = String

let pf = Printf.printf
let sf = Scanf.scanf
let ssf = Scanf.sscanf

let read_int () = sf "%d " (fun x -> x)
let read_float () = sf "%f " (fun x -> x)
let read_char () = sf "%c" (fun x -> x)
let read_array read n = A.init n (fun _ -> read ())
let read_list read n = for i = 1 to n do read () done
let read_line () = sf "%s\n" (fun x -> x)
let err s = raise (Failure s)

let inf = int_of_float 1e18
let eps = 1e-11

let count_dangling n xs =
  let rec loop dangling openb i =
    if i = n then dangling
    else if xs.[i] = '(' then loop dangling (openb + 1) (i + 1)
    else if openb == 0 then loop (dangling + 1) openb (i + 1)
    else loop dangling (openb - 1) (i + 1)
  in loop 0 0 0

let () =
  for i = 1 to (read_int ()) do
    let n = (read_int ()) in
    let s =  (read_line ()) in
    pf "%d\n" (count_dangling n s)
  done


open Printf
open Scanf
let read_string _ = bscanf Scanning.stdib " %s " (fun x -> x)

let () =
    let s = read_string () in
    let n = String.length s in
    let pref = Array.make n 0
    and cntA = ref 0
    and ans = ref 0 in
    for i = 0 to n - 1 do
        pref.(i) <- pref.(max 0 (i - 1)) + (if s.[i] = 'a' then 1 else 0);
        cntA := !cntA + (if s.[i] = 'a' then 1 else 0)
    done;
    let left = ref 0 in
    for i = 0 to n - 1 do
        let curA = ref 0
        and curB = ref 0 in
        for j = i to n - 1 do
            curA := !curA + (if s.[j] = 'a' then 1 else 0);
            curB := !curB + (if s.[j] = 'b' then 1 else 0);
            let right = !cntA - !left - !curA in
            ans := max !ans (!left + !curB + right)
        done;
        left := !left + (if s.[i] = 'a' then 1 else 0)
    done;
    printf "%d\n" (max !left !ans)

open Printf
open Scanf
let read_int _ = bscanf Scanning.stdib " %d " (fun x -> x)
let read_string () = bscanf Scanning.stdib " %s " (fun x -> x)

let () =
	let s = read_string ()
	and wyn = ref 0 in
	let n = String.length s in

	let a = Array.make (n + 1) 0
	and b = Array.make (n + 1) 0 in

	for i = 1 to n do
		a.(i) <- a.(i - 1);
		b.(i) <- b.(i - 1);

		if s.[i - 1] = 'a' then
			a.(i) <- a.(i) + 1
		else
			b.(i) <- b.(i) + 1
	done;

	for i = 0 to n do
		for j = i + 1 to n do
			let bb = b.(i) + b.(n) - b.(j)
			and aa = a.(j) - a.(i) in

			wyn := max !wyn (n - bb - aa);
		done;
	done;

	for i = 1 to n do
		let aa = a.(n) - a.(i)
		and bb = b.(i) in
		wyn := max !wyn (n - aa - bb);
	done;

	printf "%d\n" !wyn;;

open Printf
open Scanf
let read_int _ = bscanf Scanning.stdib " %d " (fun x -> x)
let read_string () = bscanf Scanning.stdib " %s " (fun x -> x)

let () =
	let s = read_string ()
	and wyn = ref 0 in
	let n = String.length s in

	let a = Array.make (n + 1) 0
	and b = Array.make (n + 1) 0 in

	for i = 1 to n do
		a.(i) <- a.(i - 1);
		b.(i) <- b.(i - 1);

		if s.[i - 1] = 'a' then
			a.(i) <- a.(i) + 1
		else
			b.(i) <- b.(i) + 1
	done;

	for i = 0 to n do
		for j = i + 1 to n do
			let bb = b.(i) + b.(n) - b.(j)
			and aa = a.(j) - a.(i) in

			wyn := max !wyn (n - bb - aa);
		done;
	done;

	printf "%d\n" !wyn;;

open Printf
open Scanf
let read_int _ = bscanf Scanning.stdib " %d " (fun x -> x)
let read_string () = bscanf Scanning.stdib " %s " (fun x -> x)

let () =
	let s = read_string ()
	and wyn = ref 0 in
	let n = String.length s in

	let a = Array.make (n + 1) 0
	and b = Array.make (n + 1) 0 in

	for i = 1 to n do
		a.(i) <- a.(i - 1);
		b.(i) <- b.(i - 1);

		if s.[i - 1] = 'a' then
			a.(i) <- a.(i) + 1
		else
			b.(i) <- b.(i) + 1
	done;

	for i = 1 to n do
		for j = i + 1 to n do
			let bb = b.(i) + b.(n) - b.(j)
			and aa = a.(j) - a.(i) in

			wyn := max !wyn (n - bb - aa);
		done;
	done;

	printf "%d\n" !wyn;;

open Printf
open Scanf
let read_string _ = bscanf Scanning.stdib " %s " (fun x -> x)

let () =
    let s = read_string () in
    let n = String.length s in
    let pref = Array.make n 0
    and cntA = ref 0
    and ans = ref 0 in
    for i = 0 to n - 1 do
        pref.(i) <- pref.(max 0 (i - 1)) + (if s.[i] = 'a' then 1 else 0);
        cntA := !cntA + (if s.[i] = 'a' then 1 else 0)
    done;
    let left = ref 0 in
    for i = 0 to n - 1 do
        let curA = ref 0
        and curB = ref 0 in
        for j = i to n - 1 do
            curA := !curA + (if s.[j] = 'a' then 1 else 0);
            curB := !curB + (if s.[j] = 'b' then 1 else 0);
            let right = !cntA - !left - !curA in
            ans := max !ans (!left + !curB + right)
        done;
        left := !left + (if s.[i] = 'a' then 1 else 0)
    done;
    printf "%d\n" !ans


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 ( // ) a b = Int64.div a b
let ( %% ) a b = Int64.rem a b

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

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

let read_int () = bscanf Scanning.stdib " %d " (fun x -> x)
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 (i,j) =
    g.(i) <- j::g.(i);
    g.(j) <- i::g.(j)
  in
  let d = Array.make n 0 in

  for i = 0 to m-1 do
    let u = -1+read_int() in
    let v = -1+read_int() in
    d.(u) <- d.(u) + 1;
    d.(v) <- d.(v) + 1;
    add_edge (u,v)
  done;

  let l = Array.make n 1 in

  for u = 0 to n-1 do
    l.(u) <- List.fold_left (fun ac v -> if u > v then max ac (1+l.(v)) else ac) 1 g.(u)
  done;

  let answer = maxf 0 (n-1) (fun v -> (long (l.(v))) ** (long d.(v))) in

  printf "%Ld\n" answer

let read1 () = Scanf.scanf "%d\n" ( fun x -> x );;
let read2 () = Scanf.scanf "%d %d\n" ( fun x y -> x, y );;
let read3 () = Scanf.scanf "%d %d %d\n" ( fun x y z -> x, y, z);;
let read x = (if x = 0 then Scanf.scanf "%d\n" else Scanf.scanf "%d ") ( fun x -> x );;

let (+$) x y =
  if x > max_int - y then max_int
  else x + y;;

let rec ( *$ ) x y =
  if y = 0 then 0 else
  if y mod 2 = 1 then x *$ (y-1) +$ x
  else let a = x *$ (y/2) in a +$ a;;

let rec loop n tab =
  if n >= 0 then
  let x = read n in
  tab.(x) <- true;
  loop (n-1) tab
  else ();;

let ( *| ) = Int64.mul;;

let _ =
  let (n, m) = read2 () in
  let g = Array.make (n+1) []
  and tab = Array.make (n+1) 1
  and wynik = ref Int64.zero in
  for i=1 to m do
    let (a,b) = read2 () in
    g.(a) <- b::g.(a);
    g.(b) <- a::g.(b)
  done;
  for i=1 to n do
    List.iter (fun x -> if x < i then tab.(i) <- max tab.(i) (tab.(x)+1) ) g.(i);
    if compare !wynik ( ( Int64.of_int tab.(i) ) *| ( Int64.of_int ( List.length g.(i) ) ) ) < 0 then
      wynik :=  ( ( Int64.of_int tab.(i) ) *| ( Int64.of_int ( List.length g.(i) ) ) ) ;
  done;
  Printf.printf "%Ld\n" !wynik;;

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

let () =
	let n = read_int ()
	and m = read_int ()
	and wyn = ref 0L in

	let g = Array.make (n + 1) []
	and dlugosc = Array.make (n + 1) 1L in

	for i = 1 to m do
		let a = read_int ()
		and b = read_int () in

		g.(a) <- b::g.(a);
		g.(b) <- a::g.(b);
	done;

	for i = 1 to n do
		let s = Int64.of_int (List.length g.(i)) in

		List.iter (fun x -> if x < i then dlugosc.(i) <- max dlugosc.(i) (Int64.add dlugosc.(x) 1L);) g.(i);

		wyn := max !wyn (Int64.mul dlugosc.(i) s)
	done;

	printf "%Ld\n" !wyn;;

open Printf
open Scanf
let read_int _ = bscanf Scanning.stdib " %d " (fun x -> x)
let long x = Int64.of_int x
let ( ++ ) a b = Int64.add a b
let ( ** ) a b = Int64.mul a b

let () =
    let n = read_int () and m = read_int () in
    let g = Array.make (n + 1) []
    and dp = Array.make (n + 1) 0L
    and ans = ref 0L in
    for i = 1 to m do
        let a = read_int () and b = read_int () in
        g.(a) <- b::g.(a);
        g.(b) <- a::g.(b)
    done;
    for i = 1 to n do
        dp.(i) <- max 1L (List.fold_left (fun acc x -> if x < i then max acc (dp.(x) ++ 1L) else acc) 0L g.(i));
        ans := max !ans (dp.(i) ** long ((List.length g.(i))))
    done;
    printf "%Ld\n" !ans

let read1 () = Scanf.scanf "%d\n" ( fun x -> x );;
let read2 () = Scanf.scanf "%d %d\n" ( fun x y -> x, y );;
let read3 () = Scanf.scanf "%d %d %d\n" ( fun x y z -> x, y, z);;
let read x = (if x = 0 then Scanf.scanf "%d\n" else Scanf.scanf "%d ") ( fun x -> x );;

let (+$) x y =
  if x > max_int - y then max_int
  else x + y;;

let rec ( *$ ) x y =
  if y = 0 then 0 else
  if y mod 2 = 1 then x *$ (y-1) +$ x
  else let a = x *$ (y/2) in a +$ a;;

let rec loop n tab =
  if n >= 0 then
  let x = read n in
  tab.(x) <- true;
  loop (n-1) tab
  else ();;

let _ =
  let (n, m) = read2 () in
  let g = Array.make (n+1) []
  and tab = Array.make (n+1) 1
  and wynik = ref 0 in
  for i=1 to m do
    let (a,b) = read2 () in
    g.(a) <- b::g.(a);
    g.(b) <- a::g.(b)
  done;
  for i=1 to n do
    List.iter (fun x -> if x < i then tab.(i) <- max tab.(i) (tab.(x)+1) ) g.(i);
    wynik := max !wynik ( tab.(i) * ( List.length g.(i) ) )
  done;
  Printf.printf "%d\n" !wynik;;

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

let () =
	let n = read_int ()
	and m = read_int ()
	and wyn = ref 0 in

	let g = Array.make (n + 1) []
	and dlugosc = Array.make (n + 1) 1 in

	for i = 1 to m do
		let a = read_int ()
		and b = read_int () in

		g.(a) <- b::g.(a);
		g.(b) <- a::g.(b);
	done;

	for i = 1 to n do
		let s = List.length g.(i) in

		List.iter (fun x -> if x < i then dlugosc.(i) <- max dlugosc.(i) (dlugosc.(x) + 1);) g.(i);

		wyn := max !wyn (dlugosc.(i) * s)
	done;

	printf "%d\n" !wyn;;


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

let n = read_int () ;;
let x = read_int () ;;

let a =
    let rec loop i f =
        if i = n then f []
        else
            let ai = read_int ()
            in loop (i + 1) (fun l -> f ((Int64.of_int ai) :: l))
    in loop 0 (fun x -> x) ;;

let split_list l n =
    let rec loop i f = function
        | [] -> (f [], [])
        | h :: t ->
            if i = n then (f [h], t)
            else loop (i + 1) (fun tl -> f (h :: tl)) t
    in loop 1 (fun x -> x) l ;;

let left, right = split_list a x ;;

(* Get the index and value of the smallest element from the right of a list *)
let get_right_min l =
    let f = fun (i, (index, value)) a ->
        if a <= value then (i + 1, (i, a)) else (i + 1, (index, value))
    in let i, (index, value) = List.fold_left f (0, (0, Int64.max_int)) l
    in index, value ;;

(* Determine which box was selected in the beginning with 0-based index *)
let start, value =
    let (ind1, val1), (ind2, val2) = (get_right_min left), (get_right_min right)
    in if val1 <= val2 then (ind1, val1) else (ind2 + x, val2) ;;

let original =
    (*
        Make sure to remove the leftover balls between (start, x - 1]. If
        start >= x then remove a ball between [0, x - 1] U (start, n). y
        represents the leftover balls.
    *)
    let y = if start >= x then x + n - start - 1 else x - start - 1
    in List.mapi
        (fun i ai ->
            if i = start then
                Int64.add (Int64.mul (Int64.of_int n) value) (Int64.of_int y)
            else
                if start < x && i > start && i < x ||
                   start >= x && (i >= 0 && i < x || i > start && i < n) then
                    Int64.sub ai (Int64.add value Int64.one)
                else Int64.sub ai value)
        a ;;

let rec print_list = function
    | [] -> ()
    | h :: t -> Printf.printf "%Ld " h; print_list t
in print_list original; Printf.printf "\n" ;;

(* Codeforces 260C KorobkiBalls *)

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 -> List.rev acc
	| _ -> readlist (n -1) (gr() :: acc);;

let rec readarray i n ar =
	if i < n then begin
		ar.(i) <- (Int64.of_int (gr()));
		readarray (i +1) n ar
	end;;

let debug = false;;

let n = gr();;
let last = gr();;
let an = Array.make n Int64.zero;;

let rec step i cnt =
	if an.(i) = Int64.zero then an.(i) <- cnt
	else begin
		an.(i) <- Int64.pred an.(i);
		let ii = if i =0 then n -1 else i -1 in
		step ii (Int64.succ cnt)
	end;;

let rec find_min i mn =
	if i = n then mn
	else let mini = if an.(i) < mn then an.(i) else mn in
	find_min (i+1) mini;;

let rec substract_min i mn =
	if i = n then ()
	else begin
		an.(i) <- Int64.sub an.(i) mn;
		substract_min (i+1) mn
  end;;

let main () = begin
		readarray 0 n an;
(*		print_int n; print_string " ";
		print_int last; print_string " ";*)
		let mini = Int64.pred (find_min 0 an.(0)) in
		begin
		  substract_min 0 mini;
			let cnt = Int64.mul (Int64.of_int n) mini in
			step (last -1) cnt
		end;
		printarri64 an;
		print_newline()
	end;;

main();;

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

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 ( ** ) a b = Int64.mul a b
let ( ++ ) a b = Int64.add a b

let () =
  let n = read_int() in
  let x = read_int() in
  let x = x-1 in

  let a = Array.make n 0 in

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

    let b = Array.copy a in

    let rec scan i count besti = if count = n then besti else
      scan ((i-1+n) mod n) (count+1) (if a.(i) < a.(besti) then i else besti)
    in

    let besti = scan x 0 x in

    let rec sublast i = if i = besti then () else (
      a.(i) <- a.(i) - 1;
      sublast ((i-1+n) mod n)
    )
    in

    let () = sublast x in

    let diff = sum 0 (n-1) (fun i -> b.(i) - a.(i)) in

    let repeat = a.(besti) in

    let pile = (Int64.of_int diff) ++ (Int64.of_int repeat) ** (Int64.of_int n) in

      for i=0 to n-1 do
	if i = besti then Printf.printf "%Ld " pile
	else Printf.printf "%d " (a.(i) - repeat)
      done;

      print_newline()

(* Codeforces 260C KorobkiBalls *)

open String;;
open Array;;

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 rec readlist n acc = match n with
	| 0 -> List.rev acc
	| _ -> readlist (n -1) (gr() :: acc);;
let rec readarray i n ar =
	if i < n then begin
		ar.(i) <- gr(); readarray (i +1) n ar
	end;;

let debug = false;;

let n = gr();;
let last = gr();;
let an = Array.make n 0;;

let rec step i cnt =
	if an.(i) = 0 then an.(i) <- cnt
	else begin
		an.(i) <- an.(i) - 1;
		let ii = if i =0 then n -1 else i -1 in
		step ii (cnt +1)
	end;;

let rec find_min i mn =
	if i = n then mn
	else let mini = if an.(i) < mn then an.(i) else mn in
	find_min (i+1) mini;;

let rec substract_min i mn =
	if i = n then ()
	else begin
		an.(i) <- an.(i) - mn;
		substract_min (i+1) mn
  end;;

let main () = begin
		readarray 0 n an;
(*		print_int n; print_string " ";
		print_int last; print_string " ";*)
		let mini = (find_min 0 an.(0) - 1) in
		begin
		  substract_min 0 mini;
			let cnt = n *mini in
			step (last -1) cnt
		end;
		printarri an;
		print_newline()
	end;;

main();;

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

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 () =
  let n = read_int() in
  let x = read_int() in
  let x = x-1 in

  let a = Array.make n 0 in

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

    let b = Array.copy a in

    let rec scan i count besti = if count = n then besti else
      scan ((i-1+n) mod n) (count+1) (if a.(i) < a.(besti) then i else besti)
    in

    let besti = scan x 0 x in

    let rec sublast i = if i = besti then () else (
      a.(i) <- a.(i) - 1;
      sublast ((i-1+n) mod n)
    )
    in

    let () = sublast x in

    let diff = sum 0 (n-1) (fun i -> b.(i) - a.(i)) in

    let repeat = a.(besti) in

    let pile = diff + repeat * n in

      for i=0 to n-1 do
	let ans = if i = besti then pile else a.(i) - repeat in
	  Printf.printf "%d " ans
      done;

      print_newline()

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

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 () =
  let n = read_int() in
  let x = read_int() in
  let x = x-1 in

  let a = Array.make n 0 in

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

    let b = Array.copy a in

    let rec scan i count besti = if count = n then besti else
      scan ((i-1+n) mod n) (count+1) (if a.(i) < a.(besti) then i else besti)
    in

    let besti = scan x 0 x in

(*      Printf.printf "besti= %d\n" besti; *)

    let rec sublast i =
      a.(i) <- a.(i) - 1;
      if i = besti then () else sublast ((i-1+n) mod n)
    in

    let () = sublast x in
(*
      for i=0 to n-1 do
	Printf.printf "a.(%d) = %d\n" i a.(i)
      done;
*)
    let diff = sum 0 (n-1) (fun i -> b.(i) - a.(i)) in

(*      Printf.printf "diff = %d\n" diff; *)

    let repeat = a.(besti)+1 in

(*      Printf.printf "repeat = %d\n" repeat; *)

    let pile = diff + repeat * n -1 in

      for i=0 to n-1 do
	let ans = if i = besti then pile else a.(i) - repeat in
	  Printf.printf "%d " ans
      done;

      print_newline()