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 ps = make 3 (0L,0L) in
  repi 0 2 (fun i -> ps.(i) <- g2 0);
  let px = init 3 (fun i -> ps.(i)) in
  sort compare px;
  let py = init 3 (fun i -> ps.(i)) in
  sort (fun (p,q) (r,s) -> compare q s) py;
  let r = ref [] in
  let xx i = fst px.(i) in
  let yx i = snd px.(i) in
  rep (xx 0) (xx 1) (fun x ->
    r := (x, yx 0) :: !r
  );
  rep (xx 1) (xx 2) (fun x ->
    r := (x, yx 2) :: !r
  );
  rep (min (yx 0) (yx 1)) (max (yx 0) (yx 1)) (fun y ->
    r := (xx 1, y) :: !r
  );
  rep (min (yx 2) (yx 1)) (max (yx 2) (yx 1)) (fun y ->
    r := (xx 1, y) :: !r
  );
  r := List.sort_uniq compare !r;
  printf "%Ld\n" @@ llen !r;
  List.iter (fun (p,q) -> printf "%Ld %Ld\n" p q) !r

open Array
let p = init 3 (fun _ ->
  Scanf.scanf " %d %d" @@ fun u v -> u,v)
let () =
  let dmin = ref max_int in
  let dp,dq = ref 0,ref 0 in
  let _ =
    init 1001 (fun y ->
      init 1001 (fun x ->
        let w = fold_left (fun s (p,q) -> s + abs (x-p) + abs (y-q)) 0 p
        in if w < !dmin then (dmin := w; dp := x; dq := y)))
  in
  let res = ref [] in
  let line (p,q) (r,s) =
    let [|p,q;r,s|] = [p,q;r,s] |> List.sort compare |> of_list in
    for x=p to r do
      res := (x,q) :: !res
    done;
    for y=min q s to max q s do
      res := (r,y) :: !res
    done
  in
  let d = !dp,!dq in
  iter (fun t -> line t d) p;
  let res = List.sort_uniq compare !res in
  Printf.(
    printf "%d\n" @@ List.length res;
    List.iter (fun (p,q) ->
      printf "%d %d\n" p q
    ) res
  )


let rec reverse s i j =
    if i < j then
        begin
            let c = s.[i] in
            s.[i] <- s.[j];
            s.[j] <- c;
            reverse s (i+1) (j-1);
        end
;;

let get_ans () =
    let s = read_line () in
    let () = print_string s in
    let () = reverse s 0 ((String.length s) - 1) in
    let () = print_string s in
    let () = print_string "\n" in
    ()
;;

let () = get_ans ()

let s = Scanf.scanf "%s" (fun x->x) in
    print_string s;
    for i = String.length s - 1 downto 0 do print_char s.[i] done

open Printf
open Scanf

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

let () =
  let n = read_string () in

  let l = String.length n in

  printf "%s" n;

  for i=l-1 downto 0 do
    printf "%c" n.[i]
  done;

  print_newline()


let print_tab tab w =
   print_endline w

let main () =
   let n = Scanf.scanf "%d" (fun i -> i) in
   let tab = Array.make (n-1) 0 in
   let tab' = Array.make (n-1) 0 in
      let j = ref 0 in
      for i = 1 to n do
         let a = Scanf.scanf " %d" (fun i -> i) in
            if a <> 0 then (tab.(!j) <- a;incr j);
      done;
      let j = ref 0 in
      for i = 1 to n do
         let a = Scanf.scanf " %d" (fun i -> i) in
            if a <> 0 then (tab'.(!j) <- a;incr j);
      done;
   let i = ref (-1) and y = tab.(0) in
   let flag = ref true in
      Array.iteri (fun j x -> if x = y then i := j) tab';
      for j = 0 to n-2 do
         flag := !flag && (tab'.((!i + j) mod (n-1)) = tab.(j));
      done;
      print_string (if !flag then "YES" else "NO");;

main ()

open Printf
open Scanf

let rec forall i j f = (i>j) || ((f i) && forall (i+1) j f)

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

  let fill_x a =
    let x = Array.make (n-1) 0 in
    let rec loop i j = if i=n then () else
	if a.(i) = 0 then loop (i+1) j
	else (
	  x.(j) <- a.(i);
	  loop (i+1) (j+1)
	)
    in
    loop 0 0;
    let rec find1 i = if x.(i) = 1 then i else find1 (i+1) in
    (x, find1 0)
  in

  let (ax,ai) = fill_x a in
  let (bx,bi) = fill_x b in

  let ans = forall 0 (n-2) (fun i -> ax.((ai+i) mod (n-1)) = bx.((bi+i) mod (n-1))) in

  if ans then printf "YES\n" else printf "NO\n"


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 q = Scanf.bscanf sb "%d " (fun s -> s) in
  let s = Scanf.bscanf sb "%s " (fun s -> s) in
  let t = Scanf.bscanf sb "%s " (fun s -> s) in
  let a = Array.make (n + 1) 0 in
    for i = 0 to n - m do
      let b = ref true in
	for j = 0 to m - 1 do
	  if s.[i + j] <> t.[j]
	  then b := false
	done;
	if !b
	then a.(i + 1) <- a.(i) + 1
	else a.(i + 1) <- a.(i)
    done;
    for i = 1 to q do
      let l = Scanf.bscanf sb "%d " (fun s -> s) in
      let r = Scanf.bscanf sb "%d " (fun s -> s) in
      let res =
	let r = r - m + 1 in
	  if l <= r
	  then a.(r) - a.(l - 1)
	  else 0
      in
	Printf.printf "%d\n" res
    done;

module type StringView = sig
  type t
  val length: t -> int
  val get: t -> int -> char
end

module MakeStringViewUtil(S: StringView) = struct
  let iteri (f: int -> char -> unit) (src: S.t): unit =
    for i = 0 to (S.length src - 1) do f i (S.get src i) done
end

module MakeStringViewEqual(A: StringView)(B: StringView) = struct
  let equal (a: A.t) (b: B.t) =
    if A.length a != B.length b then false
    else
      let rec f i =
        if i = A.length a then true
        else if A.get a i != B.get b i then false
        else f (i + 1)
      in f 0
end

module MakeStringTruncated(S: StringView) = struct
  type t = S.t * int * int
  let create src l r = (src, l, r)
  let length (_, l, r) = r - l
  let get (src, l, _) i = S.get src (l + i)
end

module StringTruncated = MakeStringTruncated(String)

module Match = struct
  type t = int
  let compare = compare
end

module MatchSet = Set.Make(Match)

module MakeStringFindMultiple(S: StringView) = struct

  let do_find (callback: int -> unit) (term: string) (src: S.t): unit =
    let tlen = String.length term in

    let module STruncated = MakeStringTruncated(S) in
    let module EqStrSTrunc = MakeStringViewEqual(String)(STruncated) in
    let module SUtil = MakeStringViewUtil(S) in

    SUtil.iteri (fun i c ->
        if i <= S.length src - tlen &&
           c = String.get term 0 then
          if EqStrSTrunc.equal term (STruncated.create src i (i + tlen))
          then callback i
      ) src

  let count (term: string) (src: S.t): int =
    let ret = ref 0 in
    do_find (fun _ -> ret := !ret + 1) term src;
    !ret

  let all_matches (term: string) (src: S.t): MatchSet.t =
    let ret = ref MatchSet.empty in
    do_find (fun i -> ret := MatchSet.add i !ret) term src;
    !ret
end

module StringFindMultiple = MakeStringFindMultiple(String)
module StringTruncatedFindMultiple = MakeStringFindMultiple(StringTruncated)

let find_opt (tbl: ('k, 'v) Hashtbl.t) (key: 'k): 'v option =
  let ret = Hashtbl.find_all tbl key in
  match ret with
  | [a] -> Some a
  | _ -> None

module MakeSetBipart(S: Set.S) = struct
  let bipart ((l, r): S.elt * S.elt) (src: S.t): S.t =
    let (_, present, ge) = S.split l src in
    let ge = if present then S.add l ge else ge in
    let (le, _, _) = S.split r ge in
    le
end

module MatchSetBipart = MakeSetBipart(MatchSet)

let _ =
  let n, m, q = Scanf.scanf " %d %d %d" (fun x y z -> x, y, z) in
  let s, t = Scanf.scanf " %s %s" (fun x y -> x, y) in
  let matches = StringFindMultiple.all_matches t s in
  (* let cache = Hashtbl.create 102539 in *)
  for i = 1 to q do
    let entry = Scanf.scanf " %d %d" (fun x y -> x, y) in
    let l, r = entry in
    matches |>
    MatchSetBipart.bipart (l - 1, r - String.length t + 1) |>
    MatchSet.cardinal |>
    string_of_int |> print_endline
    (* let strunc = StringTruncated.create s (l - 1) r in
     * StringTruncatedFindMultiple.count t strunc
     * |> string_of_int |> print_endline *)
  done

module type StringView = sig
  type t
  val length: t -> int
  val get: t -> int -> char
end

module MakeStringViewUtil(S: StringView) = struct
  let iteri (f: int -> char -> unit) (src: S.t): unit =
    for i = 0 to (S.length src - 1) do f i (S.get src i) done
end

module MakeStringViewEqual(A: StringView)(B: StringView) = struct
  let equal (a: A.t) (b: B.t) =
    if A.length a != B.length b then false
    else
      let rec f i =
        if i = A.length a then true
        else if A.get a i != B.get b i then false
        else f (i + 1)
      in f 0
end

module MakeStringTruncated(S: StringView) = struct
  type t = S.t * int * int
  let create src l r = (src, l, r)
  let length (_, l, r) = r - l
  let get (src, l, _) i = S.get src (l + i)
end

module StringTruncated = MakeStringTruncated(String)

module Match = struct
  type t = int
  let compare = compare
end

module MatchSet = Set.Make(Match)

module MakeStringFindMultiple(S: StringView) = struct

  let do_find (callback: int -> unit) (term: string) (src: S.t): unit =
    let tlen = String.length term in

    let module STruncated = MakeStringTruncated(S) in
    let module EqStrSTrunc = MakeStringViewEqual(String)(STruncated) in
    let module SUtil = MakeStringViewUtil(S) in

    SUtil.iteri (fun i c ->
        if i <= S.length src - tlen &&
           c = String.get term 0 then
          if EqStrSTrunc.equal term (STruncated.create src i (i + tlen))
          then callback i
      ) src

  let count (term: string) (src: S.t): int =
    let ret = ref 0 in
    do_find (fun _ -> ret := !ret + 1) term src;
    !ret

  let all_matches (term: string) (src: S.t): MatchSet.t =
    let ret = ref MatchSet.empty in
    do_find (fun i -> ret := MatchSet.add i !ret) term src;
    !ret
end

module StringFindMultiple = MakeStringFindMultiple(String)
module StringTruncatedFindMultiple = MakeStringFindMultiple(StringTruncated)

let find_opt (tbl: ('k, 'v) Hashtbl.t) (key: 'k): 'v option =
  let ret = Hashtbl.find_all tbl key in
  match ret with
  | [a] -> Some a
  | _ -> None

module MakeSetBipart(S: Set.S) = struct
  let bipart ((l, r): S.elt * S.elt) (src: S.t): S.t =
    let (_, present, ge) = S.split l src in
    let ge = if present then S.add l ge else ge in
    let (le, _, _) = S.split r ge in
    le
end

module type OrderedContainer = sig
  type t
  type elt
  val length: t -> int
  val get: int -> t -> elt
end

module MakeBisearch(C: OrderedContainer) = struct
  let find_first_index_satisfying (callback: C.elt -> bool) (cont: C.t): int option =
    let rec f l r =
      if l >= r
      then if l = r && C.get l cont |> callback then Some l else None
      else
        let m = (l + r) / 2 in
        if C.get m cont |> callback then f l m else f (m + 1) r
    in f 0 (C.length cont - 1)
end

module MakeSetToOrderedArray(S: Set.S)(E: Set.OrderedType with type t = S.elt) = struct
  let convert (src: S.t): E.t array =
    let l = S.elements src in
    let ret = Array.of_list l in
    Array.sort E.compare ret;
    ret
end

module MatchArray = struct
  type elt = Match.t
  type t = elt array
  let length = Array.length
  let get i a = Array.get a i
end

module MatchSetBipart = MakeSetBipart(MatchSet)
module MatchSetToOrderedArray = MakeSetToOrderedArray(MatchSet)(Match)
module MatchArrayBisearch = MakeBisearch(MatchArray)

let option_get ~(default: 'a) (x: 'a option): 'a =
  match x with | Some x -> x | None -> default

let _ =
  let n, m, q = Scanf.scanf " %d %d %d" (fun x y z -> x, y, z) in
  let s, t = Scanf.scanf " %s %s" (fun x y -> x, y) in
  let matches_set = StringFindMultiple.all_matches t s in
  let matches = MatchSetToOrderedArray.convert matches_set in
  (* let cache = Hashtbl.create 102539 in *)
  for i = 1 to q do
    let entry = Scanf.scanf " %d %d" (fun x y -> x, y) in
    let l, r = entry in
    let lb = matches |>
             MatchArrayBisearch.find_first_index_satisfying (fun x -> x >= l - 1) |>
             option_get ~default:(Array.length matches) in
    let rb = matches |>
             MatchArrayBisearch.find_first_index_satisfying (fun x -> x > r - String.length t) |>
             option_get ~default:(Array.length matches) in
    (* Printf.printf "-:%d ::%d\n" lb rb; *)
    rb - lb |> max 0 |> string_of_int |> print_endline

    (* matches |>
     * MatchSetBipart.bipart (l - 1, r - String.length t + 1) |>
     * MatchSet.cardinal |>
     * string_of_int |> print_endline *)
    (* let strunc = StringTruncated.create s (l - 1) r in
     * StringTruncatedFindMultiple.count t strunc
     * |> string_of_int |> print_endline *)
  done

module type StringView = sig
  type t
  val length: t -> int
  val get: t -> int -> char
end

module MakeStringViewUtil(S: StringView) = struct
  let iteri (f: int -> char -> unit) (src: S.t): unit =
    for i = 0 to (S.length src - 1) do f i (S.get src i) done
end

module MakeStringViewEqual(A: StringView)(B: StringView) = struct
  let equal (a: A.t) (b: B.t) =
    if A.length a != B.length b then false
    else
      let rec f i =
        if i = A.length a then true
        else if A.get a i != B.get b i then false
        else f (i + 1)
      in f 0
end

module MakeStringTruncated(S: StringView) = struct
  type t = S.t * int * int
  let create src l r = (src, l, r)
  let length (_, l, r) = r - l
  let get (src, l, _) i = S.get src (l + i)
end

module StringTruncated = MakeStringTruncated(String)

module Match = struct
  type t = int
  let compare = compare
end

module MatchSet = Set.Make(Match)

module MakeStringFindMultiple(S: StringView) = struct

  let do_find (callback: int -> unit) (term: string) (src: S.t): unit =
    let tlen = String.length term in

    let module STruncated = MakeStringTruncated(S) in
    let module EqStrSTrunc = MakeStringViewEqual(String)(STruncated) in
    let module SUtil = MakeStringViewUtil(S) in

    SUtil.iteri (fun i c ->
        if i <= S.length src - tlen &&
           c = String.get term 0 then
          if EqStrSTrunc.equal term (STruncated.create src i (i + tlen))
          then callback i
      ) src

  let count (term: string) (src: S.t): int =
    let ret = ref 0 in
    do_find (fun _ -> ret := !ret + 1) term src;
    !ret

  let all_matches (term: string) (src: S.t): MatchSet.t =
    let ret = ref MatchSet.empty in
    do_find (fun i -> ret := MatchSet.add i !ret) term src;
    !ret
end

module StringFindMultiple = MakeStringFindMultiple(String)
module StringTruncatedFindMultiple = MakeStringFindMultiple(StringTruncated)

let find_opt (tbl: ('k, 'v) Hashtbl.t) (key: 'k): 'v option =
  let ret = Hashtbl.find_all tbl key in
  match ret with
  | [a] -> Some a
  | _ -> None

module MakeSetBipart(S: Set.S) = struct
  let bipart ((l, r): S.elt * S.elt) (src: S.t): S.t =
    let (_, present, ge) = S.split l src in
    let ge = if present then S.add l ge else ge in
    let (le, _, _) = S.split r ge in
    le
end

module type OrderedContainer = sig
  type t
  type elt
  val length: t -> int
  val get: int -> t -> elt
end

module MakeBisearch(C: OrderedContainer) = struct
  let find_first_index_satisfying (callback: C.elt -> bool) (cont: C.t): int option =
    let rec f l r =
      if l >= r
      then if l = r && C.get l cont |> callback then Some l else None
      else
        let m = (l + r) / 2 in
        if C.get m cont |> callback then f l m else f (m + 1) r
    in f 0 (C.length cont - 1)
end

module MakeSetToOrderedArray(S: Set.S)(E: Set.OrderedType with type t = S.elt) = struct
  let convert (src: S.t): E.t array =
    let l = S.elements src in
    let ret = Array.of_list l in
    Array.sort E.compare ret;
    ret
end

module MatchArray = struct
  type elt = Match.t
  type t = elt array
  let length = Array.length
  let get i a = Array.get a i
end

module MatchSetBipart = MakeSetBipart(MatchSet)
module MatchSetToOrderedArray = MakeSetToOrderedArray(MatchSet)(Match)
module MatchArrayBisearch = MakeBisearch(MatchArray)

let option_get ~(default: 'a) (x: 'a option): 'a =
  match x with | Some x -> x | None -> default

let _ =
  let n, m, q = Scanf.scanf " %d %d %d" (fun x y z -> x, y, z) in
  let s, t = Scanf.scanf " %s %s" (fun x y -> x, y) in
  let matches_set = StringFindMultiple.all_matches t s in
  let matches = MatchSetToOrderedArray.convert matches_set in
  (* let cache = Hashtbl.create 102539 in *)
  for i = 1 to q do
    let entry = Scanf.scanf " %d %d" (fun x y -> x, y) in
    let l, r = entry in
    let lb = matches |>
             MatchArrayBisearch.find_first_index_satisfying (fun x -> x >= l - 1) |>
             option_get ~default:0 in
    let rb = matches |>
             MatchArrayBisearch.find_first_index_satisfying (fun x -> x <= r - String.length t) |>
             option_get ~default:(-1) in
    (rb - lb + 1) |> max 0 |> string_of_int |> print_endline

    (* matches |>
     * MatchSetBipart.bipart (l - 1, r - String.length t + 1) |>
     * MatchSet.cardinal |>
     * string_of_int |> print_endline *)
    (* let strunc = StringTruncated.create s (l - 1) r in
     * StringTruncatedFindMultiple.count t strunc
     * |> string_of_int |> print_endline *)
  done


let xs, ys, x0, y0, s = Scanf.scanf "%d %d %d %d %s" (fun a b c d e -> (a,b,c-1,d-1,e)) ;;
let next (x,y) ch = match ch with
    | 'L' -> (x, max 0 (y-1))
    | 'R' -> (x, min (ys-1) (y+1))
    | 'U' -> (max 0 (x-1), y)
    | 'D' -> (min (xs-1) (x+1), y)
let v = Array.make_matrix xs ys false ;;
let rec f i (x,y) =
    if i < String.length s then (
        let mine =
        if not v.(x).(y) then (
            v.(x).(y) <- true;
            1
        ) else
            0
        in
        Printf.printf "%d " mine ;
        mine + ( f (i+1) (next (x,y) s.[i]) )
    ) else 0
;;
print_int( xs * ys - f 0 (x0, y0) )

let new_place (x,y) (x0,y0) l =
    let new_xy = ref (x0,y0) in
    (match l with
        | 'R' -> if y0 < y then new_xy := (x0, y0+1)
        | 'L' -> if y0 > 1 then new_xy := (x0, y0-1)
        | 'U' -> if x0 > 1 then new_xy := (x0-1,y0)
        | 'D' -> if x0 < x then new_xy := (x0+1,y0));
    !new_xy

let main () =
    let (lim,pos,w) = Scanf.scanf "%d %d %d %d %s" (fun i j k l m -> ((i,j),(ref (k,l)),m)) and mat = Array.make_matrix 555 555 true and compt = ref 0 in
    for i = 0 to String.length w - 1 do
        let (a,b) = !pos in
            Printf.printf (if mat.(a).(b) = true
                then (mat.(a).(b) <- false; incr compt; "1 ")
                else "0 ");
        pos := new_place lim !pos (w.[i]);
    done;
    Printf.printf "%d" ((fst lim) * (snd lim) - !compt);;

main ();;

(* start: 9:58 *)
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 xm = read_int () in
  let ym = read_int () in
  let x0 = read_int () in
  let y0 = read_int () in

  let s = read_string () in

  let ns = String.length s in

  let bomb = Array.make_matrix (xm+1) (ym+1) 1 in

  let rec loop x y i times_died =
    if i = ns then times_died else (
      let times_died = times_died + bomb.(x).(y) in
	printf "%d " bomb.(x).(y);
	bomb.(x).(y) <- 0;
	let (x,y) =
	  match s.[i] with
	    | 'U' -> (max 1 (x-1), y)
	    | 'D' -> (min xm (x+1), y)
	    | 'L' -> (x, max 1 (y-1))
	    | 'R' -> (x, min ym (y+1))
	    | _ -> failwith "bad char"
	in
	loop x y (i+1) times_died
    )
  in

  let times_died = loop x0 y0 0 0 in

  printf "%d\n" (xm*ym - times_died)


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

open Printf
open List

let run () =
  let n = scan_int () in
  let rec f x b =
    if x = 0 then []
    else begin
      let rest = f (x/10) (b * 10) in
      let tmp = (x mod 10) * b in
      if tmp > 0 then tmp :: rest
      else rest
    end in
  let lst = f n 1 in
  printf "%d\n" (List.length lst);
  List.iter (printf "%d ") lst;
  print_endline ""
;;

let () =
  let t = scan_int () in
  for i = 1 to t do
    run ()
  done
;;

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

let rec f x =
  if x = 0 then [], 0
  else if x < 10 then [x], 1
  else let y = int_of_float (10. ** (float_of_int(int_of_float(log10 (float_of_int x))))) in
    let z = f (x - (x / y) * y) in
      (x / y) * y :: fst z, 1 + snd z
;;

open List
open Printf

let solve () =
  let n = re () in
  let m = f n in
  printf "%d \n" (snd m);
  iter (printf "%d ") (fst m);
  printf "\n"
;;

let _ =
  let t = re () in
  for i = 1 to t do
    solve ()
  done
;;

(* Codeforces 1352 0 Sum of Round Numbers comp   *)

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

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

let rec round_list acc p10 n = match n with
    | 0 -> acc
    | _ ->
			let r = n mod 10 in
			let n_acc = if r == 0 then acc else (r*p10) :: acc in
			let p10 = p10 * 10 in
			let n = n / 10 in
			round_list n_acc p10 n;;

let do_one () =
	let n = gr () in
	let lr = round_list [] 1 n in
	let _ = Printf.printf "%d\n" (List.length lr) in
	let _ = printlisti lr in
	print_string "\n";;

let do_all t =
    for i = 1 to t do
        do_one ()
    done;;

let main() =
	let t = gr () in
	do_all t;;

main();;

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

let rec f x =
  if x = 0 then []
  else if x < 10 then [x]
  else let y = int_of_float (10. ** (float_of_int(int_of_float(log10 (float_of_int x))))) in
    (x / y) * y :: f (x - (x / y) * y)
;;

open List
open Printf

let solve () =
  let n = re () in
  let m = int_of_float(log10 (float_of_int n)) + 1 in
  printf "%d \n" m;
  iter (printf "%d ") (f n);
  printf "\n"
;;

let _ =
  let t = re () in
  for i = 1 to t do
    solve ()
  done
;;

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

let rec f x =
  if x = 0 then []
  else if x < 10 then [x]
  else let y = int_of_float (10. ** (float_of_int(int_of_float(log10 (float_of_int x))))) in
    (x / y) * y :: f (x - (x / y) * y)
;;

open List
open Printf

let solve () =
  let n = re () in
  let () = List.iter (printf "%d ") (f n) in
  printf "\n"
;;

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

let rec f x =
  if x = 0 then []
  else if x < 10 then [x]
  else let y = int_of_float (10. ** (float_of_int(int_of_float(log10 (float_of_int x))))) in
    (x / y) * y :: f (x - (x / y) * y)
;;

open List
open Printf

let solve () =
  let n = 4 in
  iter (printf "%d ") (f n);
  printf "\n"
;;

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

let rec f x =
  if x = 0 then []
  else if x < 10 then [x]
  else let y = int_of_float (10. ** (float_of_int(int_of_float(log10 (float_of_int x))))) in
    (x / y) * y :: f (x - (x / y) * y)
;;

let rec print_list = function
[] -> print_string "\n"
| e::l -> print_int e ; print_string " " ; print_list l

let solve () =
  let n = re () in
  print_list (f n)
;;

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

let rec f x =
  if x = 0 then []
  else if x < 10 then [x]
  else let y = int_of_float (10. ** (float_of_int(int_of_float(log10 (float_of_int x))))) in
    (x / y) * y :: f (x - (x / y) * y)
;;

open List
open Printf

let solve () =
  let n = 4 in
  let m = int_of_float(log10 (float_of_int n)) + 1 in
  printf "%d \n" m;
  iter (printf "%d ") (f n);
  printf "\n"
;;


let n = read_int()

let goods = Array.make 2 0 ;;
let totals = Array.make 2 0 ;;

let handle i good bad =
    let total = good + bad in
    let idx = i - 1 in
        Array.set goods idx (Array.get goods idx + good) ;
        Array.set totals idx (Array.get totals idx + total);;

for i = 1 to n do
    Scanf.scanf "%d %d %d\n" handle
done ;;

for i = 0 to 1 do
    Printf.printf "%s\n" (if (Array.get goods i) >= (Array.get totals i) / 2 then "LIVE" else "DEAD" );
done ;;

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

let () =
  let n = read_int() in
  let ret = Array.make 2 0 in
  let tot = Array.make 2 0 in
    for i=0 to n-1 do
      let (t,x,y) = read_three() in
      let t = t-1 in
    ret.(t) <- ret.(t) + x;
    tot.(t) <- tot.(t) + 10;
    done;
    for j=0 to 1 do
      if 2*ret.(j) >= tot.(j) then print_string "LIVE\n" else print_string "DEAD\n"
    done

let n = read_int()

let goods = Array.make 2 0 ;;
let totals = Array.make 2 0 ;;

let handle i good total =
    let idx = i - 1 in
        Array.set goods idx (Array.get goods idx + good) ;
        Array.set totals idx (Array.get totals idx + total);;

for i = 1 to n do
    Scanf.scanf "%d %d %d\n" handle
done ;;

for i = 0 to 1 do
    Printf.printf "%s\n" (if (Array.get goods i) >= (Array.get totals i) / 2 then "LIVE" else "DEAD" );
done ;;


let read_int()=Scanf.scanf " %d" (fun x->x);;
let n=read_int() and m=read_int();;
let mat=Array.make_matrix (n+1) (m+1) 1;;
let is_square a=(int_of_float(sqrt(float_of_int(a)))*int_of_float(sqrt(float_of_int(a)))=a);;
if n=2 then
   begin
   for j=1 to m do
      mat.(1).(j)<-mat.(1).(j)*3;
      mat.(2).(j)<-mat.(2).(j)*4
   done
   end
else
   begin
   if is_square n then () else
      begin
      if n mod 2=1 then
         begin
         for j=1 to m do
            mat.(1).(j)<-mat.(1).(j)*2
         done;
         for j=1 to m do
            mat.(n).(j)<-mat.(n).(j)*(n+1)/2
         done
         end
      else
         begin
         for j=1 to m do
            mat.(n).(j)<-mat.(n).(j)*(n-2)/2
         done
         end
      end
   end;;

if m=2 then
   begin
   for i=1 to n do
      mat.(i).(1)<-mat.(i).(1)*3;
      mat.(i).(2)<-mat.(i).(2)*4
   done
   end
else
   begin
   if is_square m then () else
      begin
      if m mod 2=1 then
         begin
         for i=1 to n do
            mat.(i).(1)<-mat.(i).(1)*2
         done;
         for i=1 to n do
            mat.(i).(m)<-mat.(i).(m)*(m+1)/2
         done
         end
      else
         begin
         for i=1 to n do
            mat.(i).(m)<-mat.(i).(m)*(m-2)/2
         done
         end
      end
   end;;
for i=1 to n do
   for j=1 to m do
      Printf.printf "%d " mat.(i).(j)
   done;
   print_newline()
done;;

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_matrix n m 0 in
  let x = Array.make m 2 in
  let y = Array.make n 2 in
    if m = 1
    then x.(0) <- 1
    else if m = 2
    then (
      x.(0) <- 3;
      x.(1) <- 4;
    ) else x.(m - 1) <- m - 2;
    if n = 1
    then y.(0) <- 1
    else if n = 2
    then (
      y.(0) <- 3;
      y.(1) <- 4;
    ) else y.(n - 1) <- n - 2;
    for i = 0 to n - 1 do
      for j = 0 to m - 1 do
	a.(i).(j) <- y.(i) * x.(j);
      done;
    done;
    for i = 0 to n - 1 do
      for j = 0 to m - 1 do
	Printf.printf "%d " a.(i).(j);
      done;
      Printf.printf "\n"
    done;


let testcases_str = read_line ()
let testcases = int_of_string testcases_str

let rec split str len n acc =
  if n = len then [ int_of_string acc ]
  else if str.[n] = ' ' then int_of_string acc :: split str len (n + 1) ""
  else split str len (n + 1) (acc ^ String.make 1 str.[n])

let solve () =
  let len = read_line () in
  let nums_string = read_line () in
  let counter_arr = Array.make ((int_of_string len) + 1) 0 in
  let splitted = split nums_string (String.length nums_string) 0 "" in
  let rec loop lst counter =
    match lst with
    | [] -> print_string "-1\n"
    | h :: t ->
        counter.(h) <- counter.(h) + 1;
        if counter.(h) >= 3 then print_string (string_of_int h ^ "\n")
        else loop t counter
  in
  loop splitted counter_arr
;;

for i = 0 to testcases - 1 do
  solve ()
done

(* print any value that appears atleast three times or print -1
   1<=ai<=n, so can have a count array size n? Or sort and see if adjacent next to each other?
    comparsion sort is atleast O(nlgn)
    counting is atmost O(n)
*)

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

let rec fill_count_arr = function
| (count_arr, 0) -> count_arr
| (count_arr, i) ->
  let x = read_int () in
  count_arr.(x-1) <- (count_arr.(x-1)+1);
  fill_count_arr (count_arr, (i-1))
;;

let rec consume_count_arr = function
| (n, count_arr, k, i) ->
  if (i=n) then -1
  else begin
    if (count_arr.(i)>=k) then i+1
    else consume_count_arr (n, count_arr, k, (i+1))
  end
;;
let run_case = function
| () ->
  let n = read_int () in
  let count_arr = Array.make n 0 in
  let filled_arr = fill_count_arr (count_arr, n) in
  let x = consume_count_arr (n, filled_arr, 3, 0) in
  Printf.printf "%d\n" x
;;

let rec iter_cases = function
| 0 -> ()
| t ->
  run_case ();
  iter_cases (t-1)
;;
let t = read_int () in iter_cases (t);;

let getInt () = Scanf.scanf " %d" (fun i -> i);;

let getList(n): int list =
  let rec getList2 ((n: int), (acc: int list)) = match n with
	  | 0 -> List.rev acc
	  | _ -> getList2 (n-1, getInt() :: acc)
  in getList2(n, [])

let getLine() = Scanf.scanf " %s" (fun i -> i);;

let cmp((x: int), (y:int)) = x - y;;

let rec solve((arr: int list), (last: int), (ct: int)) =
match arr with
  | [] -> -1
  | x::xs ->
    if x = last then (
      if (ct + 1) = 3 then x else solve(xs, last, ct + 1))
    else solve(xs, x, 1);;

let main() =
  let t = getInt() in
  for i = 1 to t do
    let n = getInt() in let x = getList(n) in let arr = List.sort (compare) x
  in let ans = solve(arr, -1, 0) in
  print_endline(string_of_int(ans))
  done;;

main();;

let id x = x

module S = struct
  open String

  let split_on_char sep s =
    let r = ref [] in
    let j = ref (String.length s) in
    for i = length s - 1 downto 0 do
      if unsafe_get s i = sep then begin
        r := sub s (i + 1) (!j - i - 1) :: !r;
        j := i
      end
    done;
    sub s 0 !j :: !r
end

let read_ints_line () =
  Scanf.scanf "%s@\n" (fun x -> x)
  |> S.split_on_char ' '
  |> List.filter (fun x -> x <> "")
  |> List.map int_of_string

let solve () =
  let n = Scanf.scanf "%d\n" id in
  let xs = read_ints_line () in
  let counts = Array.make (n + 1) 0 in
  let () = List.iter (fun a -> counts.(a) <- counts.(a) + 1) xs in
  let counts = Array.mapi (fun i c -> (i, c)) counts |> Array.to_list in
  let counts = List.filter (fun (i, c) -> c >= 3) counts in
  match counts with
  | [] -> print_endline "-1"
  | (i, _) :: _ -> Printf.printf "%d\n" i

let () =
  let t = Scanf.scanf "%d\n" id in
  for i = 1 to t do
    solve ()
  done


(* square colours *)
type col = White | Black

let (++) (x, y) (z, w) = (x + z, y + w)

let get a (x, y) =
  try a.(x).(y)
  with Invalid_argument _ -> White

let deltas = [
  [(-1, -1); (0, -1); (-1, 0)]; (* north-west *)
  [( 1, -1); (0, -1); ( 1, 0)]; (* north-east *)
  [(-1,  1); (0,  1); (-1, 0)]; (* south-west *)
  [( 1,  1); (0,  1); ( 1, 0)]; (* south-east *)
]

let () =
  Scanf.scanf "%d %d %d\n" (fun n m k ->
    let board = Array.make_matrix n m White in
    let get = get board in

    let check_square p = List.fold_left (fun b d ->
      b || (List.fold_left (fun i d ->
        i + match get (d ++ p) with | White -> 0 | Black -> 1) 0 d) = 3)
      false deltas
    in

    let rec loop i =
      if i > k then 0
      else begin
        let x, y = Scanf.scanf "%d %d\n" (fun x y -> (x-1, y-1)) in
        board.(x).(y) <- Black;
        if check_square (x, y) then i else loop (i + 1)
      end
    in
    Printf.printf "%d\n" (loop 1)
  )

let carre a b mat =
	(mat.(a).(b)) && (mat.(a-1).(b)) && (mat.(a).(b-1)) && (mat.(a-1).(b-1));;

let rec f mat = function
	|[]		-> -100000
	|(a,b)::q 	-> begin
				mat.(a).(b) <- true;
				if (carre a b mat) || (carre (a+1) b mat) || (carre a (b+1) mat) || (carre (a+1) (b+1) mat)
					then 1
					else 1 + f mat q
				end;;

let final () =
	let (n,m,k) = Scanf.scanf "%d %d %d " (fun i j k -> (i,j,k)) and l = ref [] in
		for i=1 to k do
			l := (Scanf.scanf "%d %d " (fun i j -> (i,j)))::!l;
		done;
	let mat = Array.make_matrix (n+2) (m+2) false in
	let a = f mat (List.rev !l) in
		if a < 0
			then Printf.printf "0"
			else Printf.printf "%d" a;;

final ();;


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

let () =
    let n = read_int () and m = read_int () and x = read_int () and y = read_int () in
    let a = Array.make_matrix (n + 1) (m + 1) ' '
    and cnt = Array.make_matrix (m + 1) 2 0
    and best = Array.make_matrix (m + 1) 2 1000000
    and dp = Array.init (m + 1) (fun _ -> Array.init 2 (fun _ -> Array.make (y + 1) 1000000)) in
    best.(0).(0) <- 0;
    best.(0).(1) <- 0;
    let interval a b color =
        cnt.(b).(color) - cnt.(a - 1).(color) in
    for i = 1 to n do
        for j = 1 to m do
            a.(i).(j) <- read_char ()
        done
    done;
    for i = 1 to m do
        let white = ref 0 and black = ref 0 in
        for j = 1 to n do
            if a.(j).(i) = '.' then incr white
            else incr black
        done;
        cnt.(i).(0) <- cnt.(i - 1).(0) + !white;
        cnt.(i).(1) <- cnt.(i - 1).(1) + !black
    done;
    for i = 1 to m do
        for color = 0 to 1 do
            let other_color = (color + 1) mod 2 in
            for length = x to min y i do
                dp.(i).(color).(length) <- best.(i - length).(other_color) + (interval (i - length + 1) i other_color);
                best.(i).(color) <- min best.(i).(color) dp.(i).(color).(length)
            done
        done
    done;
    printf "%d\n" (min best.(m).(0) best.(m).(1))

let scan_int () = Scanf.scanf " %d" (fun x -> x);;
let scan_string () = Scanf.scanf " %s" (fun x -> x);;
let psp () = print_string " ";; let pnl () = print_newline ();;
let b2i x = if x == true then 1 else 0;;
let dbg x = print_int(x); pnl();;

let n = scan_int() and m = scan_int() and x = scan_int() and y = scan_int();;
let cnt = Array.make (m + 1) 0;; (*liczba zer w i-tej kolumnie*)

for i = 0 to n - 1 do
  let s = scan_string () in
  for j = 0 to m - 1 do
    cnt.(j + 1) <- cnt.(j + 1) + b2i(s.[j] = '.');
  done;
done;;

let duzo = 998244353;;

let dp = Array.make_matrix (m + 1) 2 duzo;;
dp.(0).(0) <- 0;; dp.(0).(1) <- 0;; (* warunki poczatkowe *)

let zer = ref 0 and jed = ref 0;;
for i = 1 to x do
  zer := !zer + (n - cnt.(i));
  jed := !jed + cnt.(i);
done;;

for i = x to m do
  let pZer = ref !zer and pJed = ref !jed in
  for j = i - x + 1 downto max 1 (i - y + 1) do
    dp.(i).(0) <- min (dp.(i).(0)) (dp.(j - 1).(1) + !pZer);
    dp.(i).(1) <- min (dp.(i).(1)) (dp.(j - 1).(0) + !pJed);
    pZer := !pZer + (n - cnt.(j - 1));
    pJed := !pJed + cnt.(j - 1);
  done;
  if i <> m then begin
    zer := !zer + (n - cnt.(i + 1)) - (n - cnt.(i - x + 1));
    jed := !jed + cnt.(i + 1) - cnt.(i - x + 1);
  end;
done;;

print_int (min dp.(m).(0) dp.(m).(1));;

let scan_int () = Scanf.scanf " %d" (fun x -> x);;
let scan_string () = Scanf.scanf " %s" (fun x -> x);;
let psp () = print_string " ";; let pnl () = print_newline ();;
let b2i x = if x == true then 1 else 0;;
let dbg x = print_int(x); pnl();;

let n = scan_int() and m = scan_int() and x = scan_int() and y = scan_int();;
let cnt = Array.make (m + 1) 0;; (*liczba zer w i-tej kolumnie*)

for i = 0 to n - 1 do
  let s = scan_string () in
  for j = 0 to m - 1 do
    cnt.(j + 1) <- cnt.(j + 1) + b2i(s.[j] = '.');
  done;
done;;

let duzo = 998244353;;

let dp = Array.make_matrix (m + 1) 2 duzo;;
dp.(0).(0) <- 0;; dp.(0).(1) <- 0;; (* warunki poczatkowe *)

let zer = ref 0 and jed = ref 0;;
for i = 1 to x - 1 do
  zer := !zer + (n - cnt.(i));
  jed := !jed + cnt.(i);
done;;

for i = x to m do
  let pZer = ref !zer and pJed = ref !jed in
  for j = i - x + 1 downto max 1 (i - y + 1) do
    pZer := !pZer + (n - cnt.(j));
    pJed := !pJed + cnt.(j);
    dp.(i).(0) <- min (dp.(i).(0)) (dp.(j - 1).(1) + !pZer);
    dp.(i).(1) <- min (dp.(i).(1)) (dp.(j - 1).(0) + !pJed);
  done;
  if i <> m then begin
    zer := !zer + (n - cnt.(i)) - (n - cnt.(i - x + 1));
    jed := !jed + cnt.(i) - cnt.(i - x + 1);
  end;
done;;

print_int (min dp.(m).(0) dp.(m).(1));;


let () =
  Scanf.scanf "%d %s" @@ fun n s ->
  let b = Bytes.create n in
  for i = 0 to n / 2 - 1 do
    Bytes.set b i s.[n - 2 * i - 2]
  done;
  for i = n - 1 downto n / 2 do
    Bytes.set b i s.[2 * i - n + 1]
  done;
  Printf.printf "%s\n" b

let decode (s : string) : string =
  let n = String.length s in
  let bs = Bytes.create n in
    begin
      if n mod 2 = 0
      then
        for i = 0 to n/2-1 do
          Bytes.set bs (n/2-1 - i) s.[2*i];
          Bytes.set bs (n/2 + i) s.[2*i+1]
        done
      else begin
        for i = 0 to (n-3)/2 do
          Bytes.set bs ((n-1)/2 + i) s.[2*i];
          Bytes.set bs ((n-3)/2 - i) s.[2*i+1]
        done;
        Bytes.set bs (n-1) s.[n-1]
      end
    end;
    Bytes.unsafe_to_string bs

let main () =
  let n = read_int () in
  let encoded_str = really_input_string stdin n in
    print_string (decode encoded_str)

let _ = main ()


open Big_int

let sieve n =
  let nums = Array.make (n + 1) false in
  let delete m =
    if not nums.(m) then
      for k = 2 to n / m do
        nums.(k * m) <- true
      done
  in
  let result = ref [] in
  nums.(0) <- true;
  nums.(1) <- true;
  for i = 2 to int_of_float(sqrt(float_of_int(n))) + 1 do
    delete i
  done;
  Array.iteri (fun i composite ->
    if not composite then result := i :: !result) nums;
  List.rev !result

let rec factorization ?(result=[]) primes n =
  let add x (* lst *)= function
    | [] -> [(x, 1)]
    | (y, ky) :: ys when y = x -> (x, ky + 1) :: ys
    | ys -> (x, 1) :: ys
  in
  let p = try List.hd primes with Failure _ -> n in
  match n with
    | 1 -> List.rev result
    | _ when n mod p = 0 -> factorization ~result:(add p result) primes (n / p)
    | _ (* <> 0 *)       -> factorization ~result (List.tl primes) n

let rec insert_factor ?(acc=[]) (x, kx) = function
  | [] -> List.rev ((x, kx) :: acc)
  | (y, ky) :: ys when y < x -> insert_factor ~acc:((y, ky) :: acc) (x, kx) ys
  | (y, ky) :: ys when y = x -> List.rev ((x, kx + ky) :: acc) @ ys
  | (y, ky) :: ys (* y > x *) -> List.rev ((x, kx) :: acc) @ ((y, ky) :: ys)

let rec lcm_fact ?(result=[]) lesser greater = match (lesser, greater) with
  | (_, []) -> List.rev result
  | ([], y :: ys) -> lcm_fact ~result:(y :: result) [] ys
  | ((x, kx) :: xs, (y, ky) :: ys) when x = y && kx < ky ->
    lcm_fact ~result:((x, ky - kx) :: result) xs ys
  | ((x, _) :: xs, (y, _) :: ys) when x = y (* kx >= ky *) ->
    lcm_fact ~result xs ys
  | ((x, _) :: xs, (y, _) :: _) when x < y ->
    lcm_fact ~result xs greater
  | (_, y :: ys) (* x > y *) ->
    lcm_fact ~result:(y :: result) lesser ys

let ( *.. ) a b = mult_big_int a b
let ( +.. ) a b = add_big_int a b
let ( ~.. ) a = big_int_of_int a

let rec product ?(result=unit_big_int) = function
  | [] -> result
  | (p, 0) :: ps -> product ~result ps
  | (p, n) :: ps -> product ~result:((~.. p) *.. result) ((p, n - 1) :: ps)

let next_token =
  let buffer = ref "" in
  let first = ref 0 in
  let rec omit_spaces s from =
    try
      (match s.[from] with
        | ' ' -> omit_spaces s (from + 1)
        | _ -> from)
    with
      | Invalid_argument _ -> String.length s
  in
  (fun () ->
    first := omit_spaces !buffer !first;
    while !first > String.length !buffer - 1 do
      buffer := read_line ();
      first := omit_spaces !buffer 0
    done;
    let last = try String.index_from !buffer !first ' '
               with Not_found -> String.length !buffer
    in
    let result = String.sub !buffer !first (last - !first) in
    first := last;
    result)

let next_int () = int_of_string (next_token ())

let () =
  let primes = sieve 31623 in
  let t = next_int () in
  for k = 1 to t do
    let n = next_int () in
    let greater_factors = insert_factor (2, 2) (factorization primes n) in
    let lesser_factors = factorization primes (n + 1) in
    let
        result = (product (lcm_fact lesser_factors greater_factors)) +.. (~.. 1)
    in
    print_endline (string_of_big_int result)
  done

open Big_int

let next_token =
  let buffer = ref "" in
  let first = ref 0 in
  let rec omit_spaces s from =
    try
      (match s.[from] with
        | ' ' -> omit_spaces s (from + 1)
        | _ -> from)
    with
      | Invalid_argument _ -> String.length s
  in
  (fun () ->
    first := omit_spaces !buffer !first;
    while !first > String.length !buffer - 1 do
      buffer := read_line ();
      first := omit_spaces !buffer 0
    done;
    let last = try String.index_from !buffer !first ' '
               with Not_found -> String.length !buffer
    in
    let result = String.sub !buffer !first (last - !first) in
    first := last;
    result)

let next_int () = int_of_string (next_token ())

let ( + ) a b = add_big_int a b
let ( - ) a b = sub_big_int a b
let ( * ) a b = mult_big_int a b
let ( / ) a b = div_big_int a b
let ( % ) a b = mod_big_int a b
let ( < ) a b = lt_big_int a b
let ( > ) a b = gt_big_int a b
let ( = ) a b = eq_big_int a b

let zero = big_int_of_int 0
let one = big_int_of_int 1
let two = big_int_of_int 2
let four = big_int_of_int 4

let rec gcd a b =
  if a < b then gcd b a
  else if b = zero then a
  else gcd b (a % b)

let lcm a b = (a * b) / (gcd a b)

let () =
  let t = next_int () in
  for k = 1 to t do
    let n = big_int_of_int (next_int ()) in
    let result = (lcm (four * n) (n + one)) / (n + one) + one in
    print_endline (string_of_big_int result)
  done

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

let _ =
  let ni () = Scanf.scanf " %d" (fun x -> x) in
  let re = ni () in
  for ri = 1 to re do
    let n = ni () in
    let n' = float_of_int n in
    Printf.printf "%.0f\n" (1.0 +. match (n + 1) mod 4 with
      | 0 -> n'
      | 2 -> 2.0 *. n'
      | _ -> 4.0 *. n'
    )
  done
;;

open Big_int

let next_token =
  let buffer = ref "" in
  let first = ref 0 in
  let rec omit_spaces s from =
    try
      (match s.[from] with
        | ' ' -> omit_spaces s (from + 1)
        | _ -> from)
    with
      | Invalid_argument _ -> String.length s
  in
  (fun () ->
    first := omit_spaces !buffer !first;
    while !first > String.length !buffer - 1 do
      buffer := read_line ();
      first := omit_spaces !buffer 0
    done;
    let last = try String.index_from !buffer !first ' '
               with Not_found -> String.length !buffer
    in
    let result = String.sub !buffer !first (last - !first) in
    first := last;
    result)

let next_int () = int_of_string (next_token ())

let ( *$ ) a b = mult_big_int a b
let ( /$ ) a b = div_big_int a b
let ( +$ ) a b = add_big_int a b
let ( ~$ ) a = big_int_of_int a
let ( %$ ) a b = mod_big_int a b
let ( <$ ) a b = lt_big_int a b
let ( >$ ) a b = gt_big_int a b
let ( =$ ) a b = eq_big_int a b

let rec gcd a b =
  if a <$ b then gcd b a
  else if b =$ (~$ 0) then a
  else gcd b (a %$ b)

let lcm a b = (a *$ b) /$ (gcd a b)

let () =
  let t = next_int () in
  for k = 1 to t do
    let n = ~$ (next_int ()) in
    let
        result = (lcm ((~$ 4) *$ n) (n +$ (~$ 1))) /$ ((n +$ (~$ 1))) +$ (~$ 1)
    in
    print_endline (string_of_big_int result)
  done

let rec gao n =
  if n = 1 then 2
  else if n mod 2 = 0 then 4 * n
  else gao (n / 2 + 1)
;;

let _ =
  let ni () = Scanf.scanf " %d" (fun x -> x) in
  let re = ni () in
  for ri = 1 to re do
    let n = ni () in
    Printf.printf "%d\n" (1 + gao n)
  done
;;

let sieve n =
  let nums = Array.make (n + 1) false in
  let delete m =
    if not nums.(m) then
      for k = 2 to n / m do
        nums.(k * m) <- true
      done
  in
  let result = ref [] in
  nums.(0) <- true;
  nums.(1) <- true;
  for i = 2 to int_of_float(sqrt(float_of_int(n))) + 1 do
    delete i
  done;
  Array.iteri (fun i composite ->
    if not composite then result := i :: !result) nums;
  List.rev !result

let rec factorization ?(result=[]) primes n =
  let add x (* lst *)= function
    | [] -> [(x, 1)]
    | (y, ky) :: ys when y = x -> (x, ky + 1) :: ys
    | ys -> (x, 1) :: ys
  in
  let p = try List.hd primes with Failure _ -> n in
  match n with
    | 1 -> List.rev result
    | _ when n mod p = 0 -> factorization ~result:(add p result) primes (n / p)
    | _ (* <> 0 *)       -> factorization ~result (List.tl primes) n

let rec insert_factor ?(acc=[]) (x, kx) = function
  | [] -> List.rev ((x, kx) :: acc)
  | (y, ky) :: ys when y < x -> insert_factor ~acc:((y, ky) :: acc) (x, kx) ys
  | (y, ky) :: ys when y = x -> List.rev ((x, kx + ky) :: acc) @ ys
  | (y, ky) :: ys (* y > x *) -> List.rev ((x, kx) :: acc) @ ((y, ky) :: ys)

let rec lcm_fact ?(result=[]) lesser greater = match (lesser, greater) with
  | (_, []) -> List.rev result
  | ([], y :: ys) -> lcm_fact ~result:(y :: result) [] ys
  | ((x, kx) :: xs, (y, ky) :: ys) when x = y && kx < ky->
    lcm_fact ~result:((x, ky - kx) :: result) xs ys
  | ((x, _) :: xs, (y, _) :: ys) when x = y ->
    lcm_fact ~result xs ys
  | ((x, _) :: xs, (y, _) :: _) when x < y ->
    lcm_fact ~result xs greater
  | ((x, _) :: _, (y, ky) :: ys) (* x > y *) ->
    lcm_fact ~result:((y, ky) :: result) lesser ys

let rec product ?(result=1) = function
  | [] -> result
  | (p, 0) :: ps -> product ~result ps
  | (p, n) :: ps -> product ~result:(p * result) ((p, n - 1) :: ps)

let next_token =
  let buffer = ref "" in
  let first = ref 0 in
  let rec omit_spaces s from =
    try
      (match s.[from] with
        | ' ' -> omit_spaces s (from + 1)
        | _ -> from)
    with
      | Invalid_argument _ -> String.length s
  in
  (fun () ->
    first := omit_spaces !buffer !first;
    while !first > String.length !buffer - 1 do
      buffer := read_line ();
      first := omit_spaces !buffer 0
    done;
    let last = try String.index_from !buffer !first ' '
               with Not_found -> String.length !buffer
    in
    let result = String.sub !buffer !first (last - !first) in
    first := last;
    result)

let next_int () = int_of_string (next_token ())

let () =
  let primes = sieve 31623 in
  let t = next_int () in
  for k = 1 to t do
    let n = next_int () in
    let greater_factors = insert_factor (2, 2) (factorization primes n) in
    let lesser_factors = factorization primes (n + 1) in
    let result = (product (lcm_fact lesser_factors greater_factors)) + 1 in
    print_endline (string_of_int result)
  done

let sieve n =
  let nums = Array.make (n + 1) false in
  let delete m =
    if not nums.(m) then
      for k = 2 to n / m do
        nums.(k * m) <- true
      done
  in
  let result = ref [] in
  nums.(0) <- true;
  nums.(1) <- true;
  for i = 2 to int_of_float(sqrt(float_of_int(n))) do
    delete i
  done;
  Array.iteri (fun i composite ->
    if not composite then result := i :: !result) nums;
  List.rev !result

let rec factorization ?(result=[]) primes n =
  let add x (* lst *)= function
    | [] -> [(x, 1)]
    | (y, ky) :: ys when y = x -> (x, ky + 1) :: ys
    | ys -> (x, 1) :: ys
  in
  let p = try List.hd primes with Failure _ -> n in
  match n with
    | 1 -> List.rev result
    | _ when n mod p = 0 -> factorization ~result:(add p result) primes (n / p)
    | _ (* <> 0 *)       -> factorization ~result (List.tl primes) n

let rec insert_factor ?(acc=[]) (x, kx) = function
  | [] -> List.rev ((x, kx) :: acc)
  | (y, ky) :: ys when y < x -> insert_factor ~acc:((y, ky) :: acc) (x, kx) ys
  | (y, ky) :: ys when y = x -> List.rev ((x, kx + ky) :: acc) @ ys
  | (y, ky) :: ys (* y > x *) -> List.rev ((x, kx) :: acc) @ ((y, ky) :: ys)

let rec lcm_fact ?(result=[]) lesser greater = match (lesser, greater) with
  | (_, []) -> List.rev result
  | ([], y :: ys) -> lcm_fact ~result:(y :: result) [] ys
  | ((x, kx) :: xs, (y, ky) :: ys) when x = y && kx < ky->
    lcm_fact ~result:((x, ky - kx) :: result) xs ys
  | ((x, _) :: xs, (y, _) :: ys) when x = y ->
    lcm_fact ~result xs ys
  | ((x, _) :: xs, (y, _) :: _) when x < y ->
    lcm_fact ~result xs greater
  | ((x, _) :: _, (y, ky) :: ys) (* x > y *) ->
    lcm_fact ~result:((y, ky) :: result) lesser ys

let rec product ?(result=1) = function
  | [] -> result
  | (p, 0) :: ps -> product ~result ps
  | (p, n) :: ps -> product ~result:(p * result) ((p, n - 1) :: ps)

let next_token =
  let buffer = ref "" in
  let first = ref 0 in
  let rec omit_spaces s from =
    try
      (match s.[from] with
        | ' ' -> omit_spaces s (from + 1)
        | _ -> from)
    with
      | Invalid_argument _ -> String.length s
  in
  (fun () ->
    first := omit_spaces !buffer !first;
    while !first > String.length !buffer - 1 do
      buffer := read_line ();
      first := omit_spaces !buffer 0
    done;
    let last = try String.index_from !buffer !first ' '
               with Not_found -> String.length !buffer
    in
    let result = String.sub !buffer !first (last - !first) in
    first := last;
    result)

let next_int () = int_of_string (next_token ())

let () =
  let primes = sieve 10000 in
  let t = next_int () in
  for k = 1 to t do
    let n = next_int () in
    let greater_factors = insert_factor (2, 2) (factorization primes n) in
    let lesser_factors = factorization primes (n + 1) in
    let result = (product (lcm_fact lesser_factors greater_factors)) + 1 in
    print_endline (string_of_int result)
  done


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

let solve (n, m, c, e0) =
  let open Hashtbl in
  let adjC : ((int, (int, unit) t) t) = create 10 in
  Array.iter
    (fun c -> try let _ = find adjC c in () with Not_found -> add adjC c (create 10))
    c;
  Array.iter
    (fun (u, v) ->
      if c.(u) = c.(v) then ()
      else begin
        replace (find adjC c.(u)) c.(v) ();
        replace (find adjC c.(v)) c.(u) ()
      end)
    e0;
  fold
    (fun c' h (c, q) ->
      let q' = length h in
      if q' > q || q' = q && c' < c
      then (c', q')
      else (c, q))
    adjC
    (-1, -1)
  |> fst

let main () =
  let n = readInt () in
  let m = readInt () in
  let c = Array.init n (fun _ -> readInt ()) in
  let e0 = Array.init m (fun _ -> (readInt () - 1, readInt () - 1)) in
  Printf.printf "%d\n" (solve (n, m, c, e0))

let () = 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 maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)
let minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i)

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

  let c = Array.init n (fun _ -> read_int()) in (* colors of the vertices *)

  let mc = maxf 0 (n-1) (fun i -> c.(i)) in (* maximum color *)

  let carray = Array.init (mc+1) (fun _-> Hashtbl.create 5) in

  let add_edge a b =
    if (c.(a) <> c.(b)) then (
      Hashtbl.replace carray.(c.(a)) c.(b) true;
      Hashtbl.replace carray.(c.(b)) c.(a) true;
    )
  in

  let () =
    for i=0 to m-1 do
      let a = read_int() in
      let b = read_int() in
	add_edge (a-1) (b-1);
    done
  in

  let ccount c = Hashtbl.length carray.(c) in
  let div = maxf 0 mc ccount in
  let i = minf 0 (n-1) (fun j -> if ccount c.(j) = div then c.(j) else (mc+1)) in
    Printf.printf "%d\n" i

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

let solve (n, m, c, e0) =
  let open Hashtbl in
  let adjC : ((int, (int, unit) t) t) = create (n/10) in
  Array.iter
    (fun c -> try let _ = find adjC c in () with Not_found -> add adjC c (create 10))
    c;
  Array.iter
    (fun (u, v) ->
      if c.(u) = c.(v) then ()
      else begin
        replace (find adjC c.(u)) c.(v) ();
        replace (find adjC c.(v)) c.(u) ()
      end)
    e0;
  fold
    (fun c' h (c, q) ->
      let q' = length h in
      if q' > q || q' = q && c' < c
      then (c', q')
      else (c, q))
    adjC
    (-1, -1)
  |> fst

let main () =
  let n = readInt () in
  let m = readInt () in
  let c = Array.init n (fun _ -> readInt ()) in
  let e0 = Array.init m (fun _ -> (readInt () - 1, readInt () - 1)) in
  Printf.printf "%d\n" (solve (n, m, c, e0))

let () = main ()

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

let solve (n, m, c, e0) =
  let open Hashtbl in
  let adjC : ((int, (int, unit) t) t) = create 10 in
  Array.iter
    (fun c -> try let _ = find adjC c in () with Not_found -> add adjC c (create 10))
    c;
  Array.iter
    (fun (u, v) ->
      if c.(u) = c.(v) then ()
      else begin
        replace (find adjC c.(u)) c.(v) ();
        replace (find adjC c.(v)) c.(u) ()
      end)
    e0;
  (* -(snd Seq.(to_seq adjC |> map (fun (c, h) -> (length h, -c)) |> fold_left max (-1, -1))) *)
  -(snd (fold (fun c' h cur -> max (length h, -c') cur) adjC (-1, -1)))

let main () =
  let n = readInt () in
  let m = readInt () in
  let c = Array.init n (fun _ -> readInt ()) in
  let e0 = Array.init m (fun _ -> (readInt () - 1, readInt () - 1)) in
  Printf.printf "%d\n" (solve (n, m, c, e0))

let () = main ()

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

let solve (n, m, c, e0) =
  let open Hashtbl in
  let adjC : ((int, (int, unit) t) t) = create (n/10) in
  Array.iter
    (fun c -> try let _ = find adjC c in () with Not_found -> add adjC c (create 10))
    c;
  Array.iter
    (fun (u, v) ->
      replace (find adjC c.(u)) c.(v) ();
      replace (find adjC c.(v)) c.(u) ())
    e0;
  fst (fold (fun c' h (c, q) -> let q' = length h in if q' > q then (c', q') else (c, q)) adjC (-1, -1) )

let main () =
  let n = readInt () in
  let m = readInt () in
  let c = Array.init n (fun _ -> readInt ()) in
  let e0 = Array.init m (fun _ -> (readInt () - 1, readInt () - 1)) in
  Printf.printf "%d\n" (solve (n, m, c, e0))

let () = 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 maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)
let argmax i j f = fold (i+1) j (fun k (y,j) -> let x = f k in if x > y then (x,k) else (y,j)) ((f i),i)

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

  let c = Array.init n (fun _ -> read_int()) in (* colors of the vertices *)

  let mc = maxf 0 (n-1) (fun i -> c.(i)) in (* maximum color *)

  let carray = Array.init (mc+1) (fun _-> Hashtbl.create 5) in

  let add_edge a b =
    if (c.(a) <> c.(b)) then (
      Hashtbl.replace carray.(c.(a)) c.(b) true;
      Hashtbl.replace carray.(c.(b)) c.(a) true;
    )
  in

  let () =
    for i=0 to m-1 do
      let a = read_int() in
      let b = read_int() in
	add_edge (a-1) (b-1);
    done
  in

  let ccount c = Hashtbl.length carray.(c) in
  let (div,i) = argmax 0 mc ccount in
  let i = if div = 0 then c.(0) else i in
    Printf.printf "%d\n" i

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 maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)
let minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i)

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

  let c = Array.init n (fun _ -> read_int()) in (* colors of the vertices *)

  let mc = maxf 0 (n-1) (fun i -> c.(i)) in (* maximum color *)

  let carray = Array.init (mc+1) (fun _-> Hashtbl.create 5) in

  let add_edge a b =
    if (c.(a) <> c.(b)) then (
      Hashtbl.replace carray.(c.(a)) c.(b) true;
      Hashtbl.replace carray.(c.(b)) c.(a) true;
    )
  in

  let () =
    for i=0 to m-1 do
      let a = read_int() in
      let b = read_int() in
	add_edge (a-1) (b-1);
    done
  in

  let ccount c = Hashtbl.length carray.(c) in
  let div = maxf 0 mc ccount in
  let i = minf 0 (n-1) (fun j -> if ccount c.(j) = div then c.(j) else -1) in
    Printf.printf "%d\n" i


let (|>) x f = f x
let (@@) f x = f x
let id x = x

let () =
  let n = Scanf.scanf "%d " id in
  let rec loop n acc =
    if n = 0 then acc else
    let s = Scanf.scanf "%s " id in
    loop (n-1) ("<3" :: s :: acc)
  in
  let orig = loop n ["<3"] |> List.rev |> String.concat "" in
  let msg = Scanf.scanf "%s " id in
  let i = ref 0 in
  String.iter (fun s ->
    if !i < String.length orig && s = orig.[!i] then incr i
  ) msg;
  print_endline @@ if !i = String.length orig then "yes" else "no";

let (|>) x f = f x ;;
let (@@) f x = f x ;;

let ident x = x ;;
let ident2 x y = (x, y) ;;
let ident3 x y z = (x, y, z) ;;
let ident4 x y z w = (x, y, z, w) ;;
let ident5 x y z w v = (x, y, z, w, v) ;;

let char_to_int x = int_of_char x - int_of_char '0' ;;
let int_to_char x = char_of_int (x + int_of_char '0') ;;

module List = struct
  include ListLabels ;;

  let rec iteri i f = function
    | [] -> ()
    | a::l -> f i a; iteri (i + 1) f l

  let iteri ~f l = iteri 0 f l
end
;;

module Array = struct
  include ArrayLabels ;;

  let reduce ~f xs =
    let acc = ref xs.(0) in
    for i = 1 to length xs - 1 do
      acc := f !acc xs.(i)
    done;
    !acc
  ;;
end
;;

module String = struct
  include StringLabels ;;

  let map_to_list ~f ss =
    let res = ref [] in
    iter ss ~f:(fun c -> res := f c :: !res);
    List.rev !res
  ;;

  let of_char_list ss =
    let res = String.create @@ List.length ss in
    List.iteri ss ~f:(fun i c -> res.[i] <- c);
    res
  ;;

  let iteri ~f a =
    for i = 0 to length a - 1 do f i (unsafe_get a i) done
  ;;
end
;;

module Float = struct
  let (+) = (+.)
  let (-) = (-.)
  let ( * ) = ( *. )
  let (/) = (/.)
end
;;

module Int64 = struct
  include Int64
  let (+) = add
  let (-) = sub
  let ( * ) = mul
  let (/) = div
end
;;

let fold_for ?(skip=1) min max ~init ~f =
  let acc = ref init in
  let cur = ref min in
  while !cur < max do
    acc := f !acc !cur;
    cur := !cur + skip;
  done;
  !acc
;;

let iter_for ?(skip=1) min max ~f =
  let cur = ref min in
  while !cur < max do
    f !cur;
    cur := !cur + skip;
  done
;;

let () =
  let n = Scanf.scanf "%d " ident in
  let ss = fold_for 0 n ~init:[] ~f:(fun acc _ ->
    Scanf.scanf "%s " ident  :: acc) |> List.rev in
  let text = Scanf.scanf "%s " ident in
  let len = String.length text in
  try
    let start = List.fold_left ss ~init:0 ~f:(fun start s ->
      let u = "<3" ^ s in
      let cur = ref start in
      iter_for 0 (String.length u) ~f:(fun i ->
        while u.[i] <> text.[!cur] do
          cur := !cur + 1;
          if !cur >= len then raise Not_found;
        done; cur := !cur + 1);
      !cur) in
    Str.search_forward (Str.regexp "[a-z0-9<>]*<[a-z0-9<>]*3[a-z0-9<>]*") text start |> ignore;
    print_endline "yes";
  with
  | _ -> print_endline "no"
;;

let (|>) x f = f x ;;
let (@@) f x = f x ;;

let ident x = x ;;
let ident2 x y = (x, y) ;;
let ident3 x y z = (x, y, z) ;;
let ident4 x y z w = (x, y, z, w) ;;
let ident5 x y z w v = (x, y, z, w, v) ;;

let char_to_int x = int_of_char x - int_of_char '0' ;;
let int_to_char x = char_of_int (x + int_of_char '0') ;;

module List = struct
  include ListLabels ;;

  let rec iteri i f = function
    | [] -> ()
    | a::l -> f i a; iteri (i + 1) f l

  let iteri ~f l = iteri 0 f l
end
;;

module Array = struct
  include ArrayLabels ;;

  let reduce ~f xs =
    let acc = ref xs.(0) in
    for i = 1 to length xs - 1 do
      acc := f !acc xs.(i)
    done;
    !acc
  ;;
end
;;

module String = struct
  include StringLabels ;;

  let map_to_list ~f ss =
    let res = ref [] in
    iter ss ~f:(fun c -> res := f c :: !res);
    List.rev !res
  ;;

  let of_char_list ss =
    let res = String.create @@ List.length ss in
    List.iteri ss ~f:(fun i c -> res.[i] <- c);
    res
  ;;

  let iteri ~f a =
    for i = 0 to length a - 1 do f i (unsafe_get a i) done
  ;;
end
;;

module Float = struct
  let (+) = (+.)
  let (-) = (-.)
  let ( * ) = ( *. )
  let (/) = (/.)
end
;;

module Int64 = struct
  include Int64
  let (+) = add
  let (-) = sub
  let ( * ) = mul
  let (/) = div
end
;;

let fold_for ?(skip=1) min max ~init ~f =
  let acc = ref init in
  let cur = ref min in
  while !cur < max do
    acc := f !acc !cur;
    cur := !cur + skip;
  done;
  !acc
;;

let iter_for ?(skip=1) min max ~f =
  let cur = ref min in
  while !cur < max do
    f !cur;
    cur := !cur + skip;
  done
;;

let () =
  let n = Scanf.scanf "%d " ident in
  let ss = fold_for 0 n ~init:[] ~f:(fun acc _ ->
    Scanf.scanf "%s " ident  :: acc) |> List.rev in
  let text = Scanf.scanf "%s " ident in
  let len = String.length text in
  try
    let start = List.fold_left ss ~init:0 ~f:(fun start s ->
      let u = "<3" ^ s in
      let cur = ref start in
      iter_for 0 (String.length u) ~f:(fun i ->
        while u.[i] <> text.[!cur] do
          cur := !cur + 1;
          if !cur >= len then raise Not_found;
        done);
      !cur) in
    Str.search_forward (Str.regexp "[a-z0-9<>]*<[a-z0-9<>]*3[a-z0-9<>]*") text start |> ignore;
    print_endline "yes";
  with
  | _ -> print_endline "no"
;;