There are n cities and m two-way roads in Berland, each road connects two cities. It is known that there is no more than one road connecting each pair of cities, and there is no road which connects the city with itself. It is possible that there is no way to get from one city to some other city using only these roads.The road minister decided to make a reform in Berland and to orient all roads in the country, i.e. to make each road one-way. The minister wants to maximize the number of cities, for which the number of roads that begins in the city equals to the number of roads that ends in it.

The first line contains a positive integer t (1 ≤ t ≤ 200) — the number of testsets in the input. Each of the testsets is given in the following way. The first line contains two integers n and m (1 ≤ n ≤ 200, 0 ≤ m ≤ n·(n - 1) / 2) — the number of cities and the number of roads in Berland.  The next m lines contain the description of roads in Berland. Each line contains two integers u and v (1 ≤ u, v ≤ n) — the cities the corresponding road connects. It's guaranteed that there are no self-loops and multiple roads. It is possible that there is no way along roads between a pair of cities. It is guaranteed that the total number of cities in all testset of input data doesn't exceed 200. Pay attention that for hacks, you can only use tests consisting of one testset, so t should be equal to one.

For each testset print the maximum number of such cities that the number of roads that begins in the city, is equal to the number of roads that ends in it. In the next m lines print oriented roads. First print the number of the city where the road begins and then the number of the city where the road ends. If there are several answers, print any of them. It is allowed to print roads in each test in arbitrary order. Each road should be printed exactly once.

let zip xs ys =
  let rec h accu xs' ys' =
    match (xs', ys') with
    | [], _ | _, [] -> accu
    | x :: xr, y :: yr -> h ((x, y) :: accu) xr yr
  in
  h [] xs ys

(* --- *)
exception UnwrapNone

let unwrap v = match v with Some x -> x | _ -> raise UnwrapNone

(* -- *)
module RandomizedSet = struct
  type ('a, 'b) t =
    { hash: ('b, int) Hashtbl.t
    ; arr: 'a option array
    ; mutable size: int
    ; cap: int }

  let create cap =
    {hash= Hashtbl.create cap; arr= Array.make cap None; size= 0; cap}

  let is_empty set = set.size = 0

  let is_full set = set.size = set.cap

  let insert set v =
    let {hash; arr; cap} = set in
    match (Hashtbl.mem hash v, is_full set) with
    | true, _ -> false
    | _, true -> false
    | _ ->
      arr.(set.size) <- Some v ;
      Hashtbl.replace hash v set.size ;
      set.size <- set.size + 1 ;
      true

  let remove set v =
    let {hash; arr; cap} = set in
    if Hashtbl.mem hash v then (
      let i = Hashtbl.find hash v in
      let another = arr.(set.size - 1) in
      if i <> set.size - 1 then (
        arr.(i) <- another ;
        Hashtbl.replace hash (unwrap another) i ) ;
      set.size <- set.size - 1 ;
      Hashtbl.remove hash v ;
      true )
    else false

  let get_next set = if is_empty set then None else set.arr.(0)
end

(* --- *)
let concat_chars cs = String.concat "" (List.map (String.make 1) cs)

let explode str =
  let exploded = ref [] in
  for i = String.length str - 1 downto 0 do
    exploded := str.[i] :: !exploded
  done ;
  !exploded

let split_on_char c str =
  let exploded = explode str in
  let cs', pending' =
    List.fold_right
      (fun x (ls, pending) ->
         match (x = c, pending) with
         | false, _ -> (ls, x :: pending)
         | true, [] -> (ls, pending)
         | true, _ -> (pending :: ls, []) )
      exploded ([], [])
  in
  List.map concat_chars (if pending' = [] then cs' else pending' :: cs')

(* --- *)
exception InputError of string

let read_into_int_list () =
  read_line () |> String.trim |> split_on_char ' ' |> List.map int_of_string

(* --- *)
type 'a edge = {from: 'a; to': 'a}

(* --- *)
let do_case () =
  match read_into_int_list () with
  | [vertices_count; edges_count] ->
    let degs = Array.make (vertices_count + 1) 0 in
    let adj =
      Array.init (vertices_count + 1) (fun _ ->
          RandomizedSet.create vertices_count )
    in
    (* read in edges *)
    for i = 1 to edges_count do
      match read_into_int_list () with
      | [from; to'] ->
        degs.(from) <- degs.(from) + 1 ;
        degs.(to') <- degs.(to') + 1 ;
        RandomizedSet.insert adj.(from) {from; to'} ;
        RandomizedSet.insert adj.(to') {from; to'}
      | _ -> raise @@ InputError "unexpected edge input"
    done ;
    (* connect all odd vertices with an additional one *)
    let addv_i = 0 in
    let even_count = ref 0 in
    for i = 1 to vertices_count do
      if degs.(i) mod 2 <> 0 then (
        let e = {from= i; to'= addv_i} in
        RandomizedSet.insert adj.(i) e ;
        RandomizedSet.insert adj.(addv_i) e ;
        () )
      else even_count := !even_count + 1
    done ;
    Printf.printf "%d\n" !even_count ;
    (* dfs *)
    let rec dfs v =
      while not @@ RandomizedSet.is_empty adj.(v) do
        match RandomizedSet.get_next adj.(v) with
        | Some e ->
          let next = if e.from = v then e.to' else e.from in
          RandomizedSet.remove adj.(v) e ;
          RandomizedSet.remove adj.(next) e ;
          if next <> addv_i && v <> addv_i then
            Printf.printf "%d %d\n" v next ;
          dfs next
        | None -> ()
      done
    in
    for i = 0 to vertices_count do
      dfs i
    done
  | _ -> raise @@ InputError "unexpected vertice_count and edges_count input"

(* --- *)
let test_case_count = read_line () |> int_of_string

;;
for i = 1 to test_case_count do
  do_case ()
done

(* --- *)
exception UnwrapNone

let unwrap v = match v with Some x -> x | _ -> raise UnwrapNone

(* -- *)
module RandomizedSet = struct
  type ('a, 'b) t =
    { hash: ('b, int) Hashtbl.t
    ; arr: 'a option array
    ; mutable size: int
    ; cap: int }

  let create cap =
    {hash= Hashtbl.create cap; arr= Array.make cap None; size= 0; cap}

  let is_empty set = set.size = 0

  let is_full set = set.size = set.cap

  let insert set v =
    let {hash; arr; cap} = set in
    match (Hashtbl.mem hash v, is_full set) with
    | true, _ | _, true -> false
    | _ ->
        arr.(set.size) <- Some v ;
        Hashtbl.replace hash v set.size ;
        set.size <- set.size + 1 ;
        true

  let remove set v =
    let {hash; arr; cap} = set in
    if Hashtbl.mem hash v then (
      let i = Hashtbl.find hash v in
      let another = arr.(set.size - 1) in
      if i <> set.size - 1 then (
        arr.(i) <- another ;
        Hashtbl.replace hash (unwrap another) i ) ;
      set.size <- set.size - 1 ;
      Hashtbl.remove hash v ;
      true )
    else false

  let get_next set = if is_empty set then None else set.arr.(0)
end

(* --- *)
let concat_chars cs = String.concat "" (List.map (String.make 1) cs)

let explode str =
  let exploded = ref [] in
  for i = String.length str - 1 downto 0 do
    exploded := str.[i] :: !exploded
  done ;
  !exploded

let split_on_char c str =
  let exploded = explode str in
  let cs', pending' =
    List.fold_right
      (fun x (ls, pending) ->
        match (x = c, pending) with
        | false, _ -> (ls, x :: pending)
        | true, [] -> (ls, pending)
        | true, _ -> (pending :: ls, []) )
      exploded ([], [])
  in
  List.map concat_chars (if pending' = [] then cs' else pending' :: cs')

(* --- *)
exception InputError of string

let read_into_int_list () =
  read_line () |> String.trim |> split_on_char ' ' |> List.map int_of_string

(* --- *)
let do_case () =
  match read_into_int_list () with
  | [vertices_count; edges_count] ->
      let degs = Array.make (vertices_count + 1) 0 in
      let adj =
        Array.init (vertices_count + 1) (fun _ ->
            RandomizedSet.create vertices_count )
      in
      (* read in edges *)
      for i = 1 to edges_count do
        match read_into_int_list () with
        | [one; another] ->
            degs.(one) <- degs.(one) + 1 ;
            degs.(another) <- degs.(another) + 1 ;
            RandomizedSet.insert adj.(one) (one, another) ;
            RandomizedSet.insert adj.(another) (one, another)
        | _ -> raise @@ InputError "unexpected edge input"
      done ;
      (* connect all odd vertices with an additional one *)
      let addv_i = 0 in
      let even_count = ref 0 in
      for i = 1 to vertices_count do
        if degs.(i) mod 2 <> 0 then (
          let e = (i, addv_i) in
          RandomizedSet.insert adj.(i) e ;
          RandomizedSet.insert adj.(addv_i) e ;
          () )
        else even_count := !even_count + 1
      done ;
      Printf.printf "%d\n" !even_count ;
      (* dfs *)
      let rec dfs v =
        while not @@ RandomizedSet.is_empty adj.(v) do
          match RandomizedSet.get_next adj.(v) with
          | Some ((one, another) as e) ->
              let next = if one = v then another else one in
              RandomizedSet.remove adj.(v) e ;
              RandomizedSet.remove adj.(next) e ;
              if next <> addv_i && v <> addv_i then
                Printf.printf "%d %d\n" v next ;
              dfs next
          | None -> ()
        done
      in
      for i = 0 to vertices_count do
        dfs i
      done
  | _ -> raise @@ InputError "unexpected vertice_count and edges_count input"

(* --- *)
let test_case_count = read_line () |> int_of_string

;;
for i = 1 to test_case_count do
  do_case ()
done

(* --- *)
exception UnwrapNone

let unwrap v = match v with Some x -> x | _ -> raise UnwrapNone

(* -- *)
module RandomizedSet = struct
  type ('a, 'b) t =
    { hash: ('b, int) Hashtbl.t
    ; arr: 'a option array
    ; mutable size: int
    ; cap: int }

  let create cap =
    {hash= Hashtbl.create cap; arr= Array.make cap None; size= 0; cap}

  let is_empty set = set.size = 0

  let is_full set = set.size = set.cap

  let insert set v =
    let {hash; arr; cap} = set in
    match (Hashtbl.mem hash v, is_full set) with
    | true, _ | _, true -> false
    | _ ->
      arr.(set.size) <- Some v ;
      Hashtbl.replace hash v set.size ;
      set.size <- set.size + 1 ;
      true

  let remove set v =
    let {hash; arr; cap} = set in
    if Hashtbl.mem hash v then (
      let i = Hashtbl.find hash v in
      let another = arr.(set.size - 1) in
      if i <> set.size - 1 then (
        arr.(i) <- another ;
        Hashtbl.replace hash (unwrap another) i ) ;
      set.size <- set.size - 1 ;
      Hashtbl.remove hash v ;
      true )
    else false

  let get_random set =
    if is_empty set then None else set.arr.(Random.int set.size)
end

(* --- *)
let concat_chars cs = String.concat "" (List.map (String.make 1) cs)

let explode str =
  let exploded = ref [] in
  for i = String.length str - 1 downto 0 do
    exploded := str.[i] :: !exploded
  done ;
  !exploded

let split_on_char c str =
  let exploded = explode str in
  let cs', pending' =
    List.fold_right
      (fun x (ls, pending) ->
         match (x = c, pending) with
         | false, _ -> (ls, x :: pending)
         | true, [] -> (ls, pending)
         | true, _ -> (pending :: ls, []) )
      exploded ([], [])
  in
  List.map concat_chars (if pending' = [] then cs' else pending' :: cs')

(* --- *)
exception InputError of string

let read_into_int_list () =
  read_line () |> String.trim |> split_on_char ' ' |> List.map int_of_string

(* --- *)
let do_case () =
  match read_into_int_list () with
  | [vertices_count; edges_count] ->
    let degs = Array.make (vertices_count + 1) 0 in
    let adj =
      Array.init (vertices_count + 1) (fun _ ->
          RandomizedSet.create vertices_count )
    in
    (* read in edges *)
    for i = 1 to edges_count do
      match read_into_int_list () with
      | [one; another] ->
        degs.(one) <- degs.(one) + 1 ;
        degs.(another) <- degs.(another) + 1 ;
        RandomizedSet.insert adj.(one) (one, another) ;
        RandomizedSet.insert adj.(another) (one, another)
      | _ -> raise @@ InputError "unexpected edge input"
    done ;
    (* connect all odd vertices with an additional one *)
    let addv_i = 0 in
    let even_count = ref 0 in
    for i = 1 to vertices_count do
      if degs.(i) mod 2 <> 0 then (
        let e = (i, addv_i) in
        RandomizedSet.insert adj.(i) e ;
        RandomizedSet.insert adj.(addv_i) e ;
        () )
      else even_count := !even_count + 1
    done ;
    Printf.printf "%d\n" !even_count ;
    (* dfs *)
    let rec dfs v =
      while not @@ RandomizedSet.is_empty adj.(v) do
        match RandomizedSet.get_random adj.(v) with
        | Some ((one, another) as e) ->
          let next = if one = v then another else one in
          RandomizedSet.remove adj.(v) e ;
          RandomizedSet.remove adj.(next) e ;
          if next <> addv_i && v <> addv_i then
            Printf.printf "%d %d\n" v next ;
          dfs next
        | None -> ()
      done
    in
    for i = 0 to vertices_count do
      dfs i
    done
  | _ -> raise @@ InputError "unexpected vertice_count and edges_count input"

(* --- *)
let test_case_count = read_line () |> int_of_string

;;
for i = 1 to test_case_count do
  do_case ()
done

let zip xs ys =
  let rec h accu xs' ys' =
    match (xs', ys') with
    | [], _ | _, [] -> accu
    | x :: xr, y :: yr -> h ((x, y) :: accu) xr yr
  in
  h [] xs ys

(* --- *)
exception UnwrapNone

let unwrap v = match v with Some x -> x | _ -> raise UnwrapNone

(* -- *)
module RandomizedSet = struct
  type ('a, 'b) t =
    { hash: ('b, int) Hashtbl.t
    ; arr: 'a option array
    ; mutable size: int
    ; cap: int }

  let create cap =
    {hash= Hashtbl.create cap; arr= Array.make cap None; size= 0; cap}

  let is_empty set = set.size = 0

  let is_full set = set.size = set.cap

  let insert set v =
    let {hash; arr; cap} = set in
    match (Hashtbl.mem hash v, is_full set) with
    | true, _ -> false
    | _, true -> false
    | _ ->
      arr.(set.size) <- Some v ;
      Hashtbl.replace hash v set.size ;
      set.size <- set.size + 1 ;
      true

  let remove set v =
    let {hash; arr; cap} = set in
    if Hashtbl.mem hash v then (
      let i = Hashtbl.find hash v in
      let another = arr.(set.size - 1) in
      if i <> set.size - 1 then (
        arr.(i) <- another ;
        Hashtbl.replace hash (unwrap another) i ) ;
      set.size <- set.size - 1 ;
      Hashtbl.remove hash v ;
      true )
    else false

  let get_next set = if is_empty set then None else set.arr.(0)
end

(* --- *)
let concat_chars cs = String.concat "" (List.map (String.make 1) cs)

let explode str =
  let exploded = ref [] in
  for i = String.length str - 1 downto 0 do
    exploded := str.[i] :: !exploded
  done ;
  !exploded

let split_on_char c str =
  let exploded = explode str in
  let cs', pending' =
    List.fold_right
      (fun x (ls, pending) ->
         match (x = c, pending) with
         | false, _ -> (ls, x :: pending)
         | true, [] -> (ls, pending)
         | true, _ -> (pending :: ls, []) )
      exploded ([], [])
  in
  List.map concat_chars (if pending' = [] then cs' else pending' :: cs')

(* --- *)
exception InputError of string

let read_into_int_list () =
  read_line () |> String.trim |> split_on_char ' ' |> List.map int_of_string

(* --- *)
type 'a edge = {from: 'a; to': 'a}

let identify {from; to'} =
  let f' = string_of_int from and t' = string_of_int to' in
  if from < to' then f' ^ "-" ^ t' else t' ^ "-" ^ f'

(* --- *)

let do_case () =
  match read_into_int_list () with
  | [vertices_count; edges_count] ->
    let degs = Array.make (vertices_count + 1) 0 in
    let adj =
      Array.init (vertices_count + 1) (fun _ ->
          RandomizedSet.create vertices_count )
    in
    (* read in edges *)
    for i = 1 to edges_count do
      match read_into_int_list () with
      | [from; to'] ->
        degs.(from) <- degs.(from) + 1 ;
        degs.(to') <- degs.(to') + 1 ;
        RandomizedSet.insert adj.(from) {from; to'} ;
        RandomizedSet.insert adj.(to') {from; to'}
      | _ -> raise @@ InputError "unexpected edge input"
    done ;
    (* connect all odd vertices with an additional one *)
    let addv_i = 0 in
    let even_count = ref 0 in
    for i = 1 to vertices_count do
      if degs.(i) mod 2 <> 0 then (
        let e = {from= i; to'= addv_i} in
        RandomizedSet.insert adj.(i) e ;
        RandomizedSet.insert adj.(addv_i) e ;
        () )
      else even_count := !even_count + 1
    done ;
    Printf.printf "%d\n" !even_count ;
    (* dfs *)
    let passed_vertices = ref [] in
    (* used to indicate that one vertex has been found in one component *)
    let is_vertex_visited = Array.make (vertices_count + 1) false in
    let rec dfs v =
      while not @@ RandomizedSet.is_empty adj.(v) do
        match RandomizedSet.get_next adj.(v) with
        | Some e ->
          let next = if e.from = v then e.to' else e.from in
          RandomizedSet.remove adj.(v) e ;
          RandomizedSet.remove adj.(next) e ;
          dfs next
        | None -> ()
      done ;
      is_vertex_visited.(v) <- true ;
      passed_vertices := v :: !passed_vertices
    in
    for i = 0 to vertices_count do
      if not is_vertex_visited.(i) then (
        (* reset passed_vertices when entering a new component *)
        passed_vertices := [] ;
        dfs i ;
        (* get path from passed_vertices within current component *)
        List.fold_left
          (fun es ((a, b) as e) ->
             if a = addv_i || b = addv_i then es else e :: es )
          []
        @@ zip !passed_vertices @@ List.tl !passed_vertices
        |> List.iter (fun (a, b) -> Printf.printf "%d %d\n" a b) )
    done
  | _ -> raise @@ InputError "unexpected vertice_count and edges_count input"

(* --- *)
let test_case_count = read_line () |> int_of_string

;;
for i = 1 to test_case_count do
  do_case () ;
done


You are given two strings $$$s$$$ and $$$t$$$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $$$1$$$. You can't choose a string if it is empty.For example:  by applying a move to the string "where", the result is the string "here",  by applying a move to the string "a", the result is an empty string "". You are required to make two given strings equal using the fewest number of moves. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the initial strings.Write a program that finds the minimum number of moves to make two given strings $$$s$$$ and $$$t$$$ equal.

The first line of the input contains $$$s$$$. In the second line of the input contains $$$t$$$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $$$2\cdot10^5$$$, inclusive.

Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings.

NoteIn the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est".In the second example, the move should be applied to the string "codeforces" $$$8$$$ times. As a result, the string becomes "codeforces" $$$\to$$$ "es". The move should be applied to the string "yes" once. The result is the same string "yes" $$$\to$$$ "es".In the third example, you can make the strings equal only by completely deleting them. That is, in the end, both strings will be empty.In the fourth example, the first character of the second string should be deleted.

open Scanf
open Printf

let s = scanf "%s" (fun n -> n)

let s' = scanf " %s" (fun n -> n)

let compare s s' =
  let rec loop i i' =
    if i = -1 || i' = -1 then
      i, i'
    else if s.[i] = s'.[i'] then
      loop (i-1) (i'-1)
    else
      i, i'
  in loop (String.length s - 1) (String.length s' - 1)

let process s s' =
  let i, i' = compare s s' in
  i + i' + 2

let () =
  let out = process s s' in
  printf "%d\n" out;
  ()

open Printf

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 print_int_endline n = n |> string_of_int |> print_endline

let () =
  let rec f0 (lu,lv) = match lu,lv with
  | [],[] -> 0
  | [],rest | rest,[] -> List.length rest
  | p::tlu,q::tlv ->
    if p=q then f0 (tlu,tlv)
    else (List.length tlu + List.length tlv + 2)
  in
  Scanf.scanf " %s %s" (fun u v ->
    List.rev @@ char_list_of_string u,
    List.rev @@ char_list_of_string v)
  |> f0 |> printf "%d\n"


You are given a simple undirected graph with $$$n$$$ vertices, $$$n$$$ is even. You are going to write a letter on each vertex. Each letter should be one of the first $$$k$$$ letters of the Latin alphabet.A path in the graph is called Hamiltonian if it visits each vertex exactly once. A string is called palindromic if it reads the same from left to right and from right to left. A path in the graph is called palindromic if the letters on the vertices in it spell a palindromic string without changing the order.A string of length $$$n$$$ is good if:   each letter is one of the first $$$k$$$ lowercase Latin letters;  if you write the $$$i$$$-th letter of the string on the $$$i$$$-th vertex of the graph, there will exist a palindromic Hamiltonian path in the graph. Note that the path doesn't necesserily go through the vertices in order $$$1, 2, \dots, n$$$.Count the number of good strings.

The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$2 \le n \le 12$$$; $$$n$$$ is even; $$$0 \le m \le \frac{n \cdot (n-1)}{2}$$$; $$$1 \le k \le 12$$$) — the number of vertices in the graph, the number of edges in the graph and the number of first letters of the Latin alphabet that can be used. Each of the next $$$m$$$ lines contains two integers $$$v$$$ and $$$u$$$ ($$$1 \le v, u \le n$$$; $$$v \neq u$$$) — the edges of the graph. The graph doesn't contain multiple edges and self-loops.

Print a single integer — number of good strings.

(* https://codeforces.com/problemset/problem/1569/F *)

(* let _ = Gc.(set { (get()) with minor_heap_size = 5_000_000 }) *)

(* let fnv_P = 0x01000193 *)
(* let fnv_0 = 0x811c9dc5 *)

module S = struct
  type 'a t = ('a -> unit) -> unit
  module Infix = struct
    let (>>=) s f i = s (fun x -> f x i)
    let (>>|) s f i = s (fun x -> i (f x))
    let (--) a b f = for i = a to b do f i done
    let (++) s1 s2 i = s1 i; s2 i
  end
  let return x i = i x
  let filter p s i = s (fun x -> if p x then i x)
  let map f s i = s (fun x -> i (f x))
  let of_list xs i = List.iter i xs
  let of_array xs i = Array.iter i xs
  let fold f a s =
    let acc = ref a in
    s (fun x -> acc := f !acc x);
    !acc
  let to_list s = fold (fun xs x -> x::xs) [] s |> List.rev
  let length s = fold (fun n _ -> n + 1) 0 s
  let null _ = ()
  (* let sum = fold (+) 0 *)
  let sum64 = fold Int64.add 0L
end

module Vset : sig
  type t
  val compare : t -> t -> int
  val equal : t -> t -> bool
  val empty : t
  val to_int : t -> int
  val of_int : int -> t
  (* val hash : int -> t -> int *)
  val sg : int -> t
  val add : int -> t -> t
  val mem : int -> t -> bool
  val union : t -> t -> t
  val iter : (int -> unit) -> t -> unit
  (* val pp : Format.formatter -> t -> unit *)
end = struct (* vertex sets *)
  type t = int
  let compare (a: t) b = compare a b
  let equal (a: t) b = a == b
  let union t1 t2 = t1 lor t2
  let sg x =
    (* assert (0 <= x && x <= 30); *)
    1 lsl x
  let add x t =
    (* assert (0 <= x && x <= 30); *)
    (1 lsl x) lor t
  let mem x t =
    (* assert (0 <= x && x <= 30); *)
    (1 lsl x) land t <> 0
  let empty = 0
  let to_int x = x
  let of_int x = x
  (* let hash h t = *)
  (*   let b1 = t land 0xff *)
  (*   and b2 = (t lsr 8) land 0xff in *)
  (*   (((h * fnv_P) lxor b1) * fnv_P) lxor b2 *)
  let iter f t =
    let rec go f x = function
    | 0 -> ()
    | t -> if t land 1 = 1 then f x; go f (x + 1) (t lsr 1) in
    go f 0 t
  (* let pp ppf = Fmt.pf ppf "@[<1>{%a}@]" (Fmt.iter ~sep:Fmt.comma iter Fmt.int) *)
end

(* #install_printer Vset.pp *)

let init n f =
  let rec go i n f = if i < n then f i :: go (i + 1) n f else [] in
  go 0 n f

let rec lequal (l1: Vset.t list) l2 = match l1, l2 with
| a1::l1, a2::l2 -> a1 == a2 && lequal l1 l2
| [], [] -> true
| _, _ -> false

let rec lequal (l1: Vset.t list) l2 =
  match l1, l2 with
  | a::l1, b::l2 ->
      let r1 = a == b in
    ( match l1, l2 with
      | a::l1, b::l2 ->
          let r2 = a == b in
        ( match l1, l2 with
          | a::l1, b::l2 ->
              let r3 = a == b in
            ( match l1, l2 with
              | a::l1, b::l2 ->
                  let r4 = a == b in
                ( match l1, l2 with
                  | a::l1, b::l2 ->
                      let r5 = a == b in
                    ( match l1, l2 with
                      | a::l1, b::l2 ->
                          let r6 = a == b in
                        ( match l1, l2 with
                          | _::_, _::_ -> assert false
                          | [], [] -> r1 && r2 && r3 && r4 && r5 && r6
                          | _ -> false )
                      | [], [] -> r1 && r2 && r3 && r4 && r5
                      | _ -> false )
                  | [], [] -> r1 && r2 && r3 && r4
                  | _ -> false )
                | [], [] -> r1 && r2 && r3
                | _ -> false )
          | [], [] -> r1 && r2
          | _ -> false )
      | [], [] -> r1
      | _ -> false )
  | [], [] -> true
  | _ -> false

(* let rec lequal (l1: Vset.t list) l2 = *)
(*   match l1, l2 with a::l1, b::l2 -> *)
(*     a == b && (match l1, l2 with a::l1, b::l2 -> *)
(*       a == b && (match l1, l2 with a::l1, b::l2 -> *)
(*         a == b && (match l1, l2 with a::l1, b::l2 -> *)
(*           a == b && (match l1, l2 with a::l1, b::l2 -> *)
(*             a == b && (match l1, l2 with a::l1, b::l2 -> *)
(*               a == b && (match l1, l2 with a::l1, b::l2 -> lequal l1 l2 | [], [] -> true | _ -> false) *)
(*             | [], [] -> true | _ -> false) *)
(*           | [], [] -> true | _ -> false) *)
(*         | [], [] -> true | _ -> false) *)
(*       | [], [] -> true | _ -> false) *)
(*     | [], [] -> true | _ -> false) *)
(*   | [], [] -> true | _ -> false *)

(* let lhash xs = *)
(*   let rec go h = function x::xs -> go (Vset.hash h x) xs | _ -> h in *)
(*   go fnv_0 xs land 0x3fffffff *)

let lhash xs =
  let rec go h = function [] -> h
  | x::xs ->
      let h = Hashtbl.seeded_hash h x in match xs with [] -> h
      | x::xs ->
          let h = Hashtbl.seeded_hash h x in match xs with [] -> h
          | x::xs ->
              let h = Hashtbl.seeded_hash h x in match xs with [] -> h
              | x::xs ->
                  let h = Hashtbl.seeded_hash h x in match xs with [] -> h
                  | x::xs ->
                      let h = Hashtbl.seeded_hash h x in match xs with [] -> h
                      | x::xs ->
                          let h = Hashtbl.seeded_hash h x in match xs with [] -> h
                          | _ -> go h xs in
  (* let rec go h = function x::xs -> go (Hashtbl.seeded_hash h x) xs | _ -> h in *)
  go 0 xs

let aequal (l1: Vset.t array) l2 =
  let rec go i l1 l2 = i < 0 || l1.(i) == l2.(i) && go (i - 1) l1 l2 in
  let m = Array.length l1 and n = Array.length l2 in
  m = n && go (m - 1) l1 l2

let ahash a =
  let s = ref 0 in
  for i = 0 to Array.length a - 1 do s := Hashtbl.seeded_hash !s a.(i) done;
  !s

module HSet = struct
  type t = { mutable tab : Vset.t list array; mutable n : int }
  let create b = { tab = Array.make (1 lsl b) []; n = 0 }
  let index0 v tab = (lhash v) land (Array.length tab - 1)
  let istep i tab = (i + 1) land (Array.length tab - 1)

  let rec repack ({ tab; _ } as t) =
    t.n <- 0;
    t.tab <- Array.make (Array.length t.tab lsl 1) [];
    for i = 0 to Array.length tab - 1 do
      let v = tab.(i) in if v != [] then scan v t |> ignore
    done

  and scan v t =
    let rec go v ({ tab; n } as t) i =
      let v0 = tab.(i) in
      if v0 == [] then begin
        tab.(i) <- v;
        let n = n + 1 in
        t.n <- n;
        if n lsl 2 > Array.length tab then repack t;
        false
      end else lequal v0 v || go v t (istep i tab) in
    go v t (index0 v t.tab)

  (* let find v t = *)
  (*   let rec go v ({ tab; _ } as t) i c = *)
  (*     if lequal v tab.(i) then c else go v t (istep i tab) (c + 1) in *)
  (*   go v t (index0 v t.tab) 0 *)

  (* let stat t = *)
  (*   let r = Array.make_matrix 10 6 0 in *)
  (*   for i = 0 to Array.length t.tab - 1 do *)
  (*     let v = t.tab.(i) in *)
  (*     if v != [] then *)
  (*       let d = find v t and l = List.length v in *)
  (*       r.(min d 9).(l - 1) <- r.(min d 9).(l - 1) + 1 *)
  (*   done; *)
  (*   r *)

(*   let pp_stat ppf t = *)
(*     let cap = Array.length t.tab in *)
(*     Fmt.pf ppf "@[<v>cap: %d n: %d (load: %f)@ pos: @[<v>" *)
(*        cap t.n (float t.n /. float cap); *)
(*     let s = stat t in *)
(*     for d = 0 to Array.length s - 1 do *)
(*       let row = s.(d) in *)
(*       if Array.fold_left (+) 0 row > 0 then *)
(*         Fmt.pf ppf "hop %d:  @[%a@]@ " d Fmt.(array ~sep:sp int) s.(d) *)
(*     done; *)
(*     Fmt.pf ppf "@]@]" *)
end

(* module Partition = struct *)
(*   type t = bytes *)
(*   let gets t i = Bytes.get_int16_ne t i |> Vset.of_int *)
(*   let sets t i s = Vset.to_int s |> Bytes.set_int16_ne t i *)
(*   let ins t s = *)
(*     let open Bytes in *)
(*     let rec go i = *)
(*       assert (i < length t - 1); *)
(*       let s1 = gets t i in *)
(*       if s1 == Vset.empty then sets t i s *)
(*       else match Vset.compare s s1 with *)
(*       | 0 -> () *)
(*       | 1 -> go (i + 2) *)
(*       | _ -> *)
(*           blit t i t (i + 2) (length t - i - 2); *)
(*           set_int16_ne t i (Vset.to_int s) in *)
(*     go 0 *)
(*   let create n k = *)
(*     let b = Bytes.make (n * 2) '\x00' in *)
(*     k (ins b); *)
(*     b *)
(*   let join t i j = *)
(*     let open Bytes in *)
(*     let n = length t in *)
(*     let i = min i j * 2 and j = max i j * 2 in *)
(*     let s = Vset.union (gets t i) (gets t j) in *)
(*     let t1 = make (n - 2) '\x00' in *)
(*     blit t 0 t1 0 i; *)
(*     blit t (i + 2) t1 i (j - i - 2); *)
(*     blit t (j + 2) t1 (j - 2) (n - j - 2); *)
(*     ins t1 s; *)
(*     t1 *)
(*   let card t = Bytes.length t / 2 *)
(* end *)

(* #install_printer Vset.pp *)

module Pmem = struct
  module Vsmap = Map.Make(Vset)
  type t = { mutable m : t Vsmap.t }  (* no partition is a prefix of another *)
  let create () = { m = Vsmap.empty }
  let mem t ss =
    let rec go t = function s::ss -> go (Vsmap.find s t.m) ss | [] -> true in
    try go t ss with Not_found -> false
  let rec add t = function
  | [] -> ()
  | s::ss -> match Vsmap.find s t.m with
      | t -> add t ss
      | exception Not_found ->
          let t1 = create () in
          t.m <- Vsmap.add s t1 t.m; add t1 ss
end

module I64 = struct
  include Int64
  let ( + ) = add and ( - ) = sub and ( * ) = mul and ( / ) = div and v = of_int
end

let fac n =
  let rec go a = function 0 -> a | n -> go I64.(a * v n) (n - 1) in
  go 1L n

let prod n k =
  let rec go a n = function 0 -> a | k -> go I64.(a * v n) (n - 1) (k - 1) in
  go 1L n k

let rec choose k n =
  assert (k <= n);
  if k > n / 2 then choose (n - k) n else I64.(prod n k / fac k)

let stop (type a) f =
  let module M = struct exception Stop of a end in
  try f (fun x -> raise (M.Stop x)) with M.Stop x -> x

let seen (type a) ~eq ~hash () =
  let module H = Hashtbl.Make(struct type t = a let hash, equal = hash, eq end) in
  let ht = H.create 100_003 in
  (* let cnt = ref 0 in *)
  (* at_exit (fun () -> *)
  (*   let open Hashtbl in *)
  (*   let stat = H.stats ht in *)
  (*   Fmt.pr "@[<v 2>stats:@ queries: %d@ len: %d@ bkts: %d@ histo: %a@]@." *)
  (*     !cnt stat.num_bindings stat.num_buckets *)
  (*     Fmt.(Dump.array int) stat.bucket_histogram); *)
  (* fun x -> if H.mem ht x then (incr cnt; true) else (H.add ht x (); false) *)
  fun x -> H.mem ht x || (H.add ht x (); false)

let seen2 (type a) ~cmp () =
  let module S = Set.Make(struct type t = a let compare = cmp end) in
  let r = ref S.empty in
  fun x -> let s = !r in S.mem x s || (r := S.add x s; false)

let seen3 () =
  let m = Pmem.create () in
  fun x -> Pmem.mem m x || (Pmem.add m x; false)

let seen4 () =
  let h = HSet.create 10 in
  (* at_exit (fun () -> Fmt.pr "stat: @[%a@]@." HSet.pp_stat h); *)
  fun x -> HSet.scan x h

let rec lines ic i = match input_line ic with
| exception End_of_file -> ()
| line -> i line; lines ic i

open S.Infix

let partitions_of n =
  assert (n land 1 = 0);
  let rec go acc = function
  | x::y::xs -> go (x::acc) (y::xs) ++ go acc (x + y::xs)
  | r -> S.return (r @ acc) in
  go [] (init (n / 2) (fun _ -> 2))

let assignments n k = (* upper bound for a complete graph *)
  let rec go acc n = function
  | [] -> acc
  | x::xs -> go I64.(acc * choose x n) (n - x) xs in
  partitions_of n
    |> S.map (fun p -> List.length p, p)
    |> S.filter (fun (x, _) -> x <= k)
    |> S.map I64.(fun (x, p) -> go 1L n p * choose x k)
    |> S.sum64

(* module Vmap = Map.Make(struct type t = int let compare (a: int) b = compare a b end) *)

let graph vs = (* from edges *)
  let a = Array.make 12 [] in
  vs (fun (v1, v2) ->
    let v1 = v1 - 1 and v2 = v2 - 1 in
    a.(v1) <- v2 :: a.(v1); a.(v2) <- v1 :: a.(v2));
  let a = Array.map (fun vs -> List.sort compare vs |> Array.of_list) a in
  fun v -> a.(v)

let hams (n, succ) it =
  let ham = Array.make n (-42) in
  let rec go seen v i =
    ham.(i) <- v;
    if i < n - 1 then
      let vxn = succ v in
      for vi = 0 to Array.length vxn - 1 do
        let v1 = vxn.(vi) in
        if not (Vset.mem v1 seen) then go Vset.(add v1 seen) v1 (i + 1)
      done
    else if ham.(0) <= v then it ham in
  for v0 = 0 to n - 1 do go Vset.(sg v0) v0 0 done

(* let join p it = *)
(*   let n = Array.length p in *)
(*   for i = 0 to n - 2 do *)
(*     for j = i + 1 to n - 1 do *)
(*       let p1 = Array.init (n - 1) @@ fun k -> *)
(*         if k = i then Vset.union p.(i) p.(j) else *)
(*         if k >= j then p.(k + 1) else p.(k) in *)
(*       Array.sort Vset.compare p1; *)
(*       it p1 *)
(*     done *)
(*   done *)

(* let coarser k seen ham = *)
(*   let rec go p0 = *)
(*     if not (seen p0) then *)
(*       match Array.length p0 with *)
(*       | c when c <= 1 -> S.return p0 *)
(*       | c when c <= k -> S.return p0 ++ (join p0 >>= go) *)
(*       | c -> join p0 >>= go *)
(*     else S.null in *)
(*   let n = Array.length ham in *)
(*   let p0 = Array.init (n / 2) @@ fun i -> Vset.(sg ham.(i) |> add ham.(n - i - 1)) in *)
(*   Array.sort Vset.compare p0; *)
(*   go p0 *)

(* let partitions k hams = *)
(*   let memo = seen ~eq:aequal ~hash:ahash () in *)
(*   hams >>= coarser k memo *)

let rec ins v0 = function
| [] -> [v0]
| v::vs as ss ->
    match Vset.compare v0 v with -1 -> v0 :: ss | 1 -> v :: ins v0 vs | _ -> ss

let rec sel acc xs it = match xs with
| [] -> ()
| x::xs -> it (acc, x, xs); sel (x::acc) xs it

let join p it =
  sel [] p @@ fun (xs, s1, ys) ->
  sel xs ys @@ fun (xs, s2, ys) ->
    ins (Vset.union s1 s2) List.(rev_append xs ys) |> it

let partition ham =
  let n = Array.length ham in
  let rec go acc = function
  | 0 -> acc
  | i -> go (ins Vset.(sg ham.(i - 1) |> add ham.(n - i)) acc) (i - 1) in
  go [] (n / 2)

let coarser k seen1 seen2 p it = (* coarser partitions *)
  let rec go c p =
    if not (seen2 p) then begin
      if c <= 1 then it p else
      if c <= k then (it p; join p (go (c - 1))) else
        join p (go (c - 1))
    end in
  if not (seen1 p) then go (List.length p) p

let partitions k hams =
  (* let eq = lequal and hash = lhash in *)
  (* let memo1 = seen ~eq ~hash () and memo2 = seen ~eq ~hash () in *)
  (* let memo = seen2 ~cmp:(List.compare Vset.compare) () in *)
  (* let memo = seen3 () in *)
  (* let memo1 = seen4 () and memo2 = seen4 () in *)
  (* let memo1 = seen4 () and memo2 = seen ~eq ~hash () in *)
  let memo1 = seen4 () and memo2 = seen3 () in
  hams >>= fun ham -> coarser k memo1 memo2 (partition ham)

(* let join p it = *)
(*   let n = Partition.card p in *)
(*   for i = 0 to n - 2 do *)
(*     for j = i + 1 to n - 1 do *)
(*       it (Partition.join p i j) *)
(*     done *)
(*   done *)

(* let partition ham = *)
(*   let n = Array.length ham in *)
(*   Partition.create (n / 2) @@ fun add -> *)
(*     for i = 0 to n / 2 - 1 do *)
(*       add Vset.(sg ham.(i) |> add ham.(n - i - 1)) *)
(*     done *)

(* let coarser k seen p = *)
(*   let rec go p = *)
(*     if not (seen p) then *)
(*       match Partition.card p with *)
(*       | c when c <= 1 -> S.return p *)
(*       | c when c <= k -> S.return p ++ (join p >>= go) *)
(*       | c -> join p >>= go *)
(*     else S.null in *)
(*   go p *)

(* let partitions k hams = *)
(*   let memo = seen ~eq:Bytes.equal ~hash:Hashtbl.hash () in *)
(*   hams >>= fun ham -> coarser k memo (partition ham) *)

let count g k = (* legal letter assignments *)
  (* let ns = hams g |> partitions k |> S.map (fun s -> prod k (Array.length s)) in *)
  let ns = hams g |> partitions k |> S.map (fun s -> prod k (List.length s)) in
  (* let ns = hams g |> partitions k |> S.map (fun s -> prod k (Partition.card s)) in *)
  let max = assignments (fst g) k in
  stop @@ fun exit ->
    let f a b =
      let a = I64.(a + b) in
      if a = max then exit max else a in
    S.fold f 0L ns

let input ic =
  Scanf.sscanf (input_line ic) "%d %d %d" @@ fun vx lx k ->
    let vxn = lines ic |> S.map @@ fun s -> Scanf.sscanf s "%d %d" (fun a b -> a, b) in
    (vx, graph vxn), k

let _ =
  let g, k = input stdin in
  Format.printf "%Ld@." (count g k)

let g1 = 4, graph (S.of_list [(1,2); (2,3); (3,4)])
let g2 = 4, graph (S.of_list [(1,2); (1,3); (1,4); (2,3); (2,4); (3,4)])
let g3 = 12, graph (S.of_list [
  (1,3); (2,6); (3,6); (3,7); (4,8); (8,5); (8,7); (9,4); (5,9); (10,1);
  (10,4); (10,6); (9,10); (11,1); (5,11); (7,11); (12,2); (12,5); (12,11) ])
let g20 = 12, graph (S.of_list [
  (3,4); (4,9); (12,8); (12,11); (12,1); (8,11); (1,7); (1,3); (2,6); (10,12);
  (3,12); (3,8); (3,5); (8,5); (11,4); (2,5); (1,6); (4,12); (9,8); (12,7);
  (5,9); (9,12); (10,9); (7,5); (2,8); (7,2); (2,11); (7,3); (4,6); (1,5);
  (5,10); (2,10); (9,6); (8,10); (12,5); (4,5); (1,2); (5,11); (4,7); (7,10);
  (6,5); (11,6); (9,2); (11,10); (2,12); (2,4); (10,4); (3,2); (6,3); (9,3);
  (8,4); (3,11); (9,11); (1,10); (1,8); (12,6); (11,1); (6,8); (9,1); (11,7);
  (9,7); (4,1); (8,7); (10,3); (10,6); (6,7) ])

let complete n =
  let a =
    Array.init n @@ fun i ->
      Array.init (n - 1) @@ fun j ->
        if j < i then j else j + 1 in
  n, fun v -> a.(v)

let check name g k res =
  let x = count g k in
  Format.printf "%s -> %Ld  (of %Ld)@." name x (assignments (fst g) k);
  assert (x = res)

(* let _ = *)
(*   check "g1" g1 3 9L; *)
(*   check "g2" g2 3 21L; *)
(*   check "g3" g3 12 456165084L; *)
(*   check "g20" g20 2 2048L; *)
(*   () *)

(* (1* let check_complete n k = *1) *)
(* (1*   let c = count (complete n) k *1) *)
(* (1*   and l = assignments n k in *1) *)
(* (1*   Format.printf "count: %d, limit: %d@." c l; *1) *)
(* (1*   assert (c = l) *1) *)

(* (1* let _ = *1) *)
(* (1*   for n = 1 to 5 do *1) *)
(* (1*     let n = n * 2 in *1) *)
(* (1*     Format.printf "@[<v 2>n = %d@ " n; *1) *)
(* (1*     for k = 1 to 12 do *1) *)
(* (1*       let c = count (complete n) k *1) *)
(* (1*       and l = assignments n k in *1) *)
(* (1*       Format.printf "k = %d ->  %d  (limit %d)@ " k c l; *1) *)
(* (1*       assert (c = l) *1) *)
(* (1*     done; *1) *)
(* (1*     Format.printf "@]@." *1) *)
(* (1*   done *1) *)

(* (1* let _ = Format.printf "%d@." (hams g20 |> S.length) *1) *)

(* (1* let _ = Format.printf "%d@." (count g20 2) *1) *)

(* (1* (2* let _ = Format.printf "%d@." (count (g4 10) 12) *2) *1) *)
(* (1* (2* let _ = Format.printf "%d@." (g4 10 |> hams |> S.length) *2) *1) *)

(* (1* (2* let s = Vset.[|empty |> add 1 |> add 2; empty |> add 3 |> add 4; empty |> add 5 |> add 6|] *2) *1) *)
(* (1* (2* let _ = reducex s |> S.to_list *2) *1) *)

(* (1* (2* let ham_g1 = hams g1 |> S.to_list |> List.hd *2) *1) *)
(* (1* (2* let ham_g2 = hams g2 |> S.to_list |> List.hd *2) *1) *)
(* (1* (2* let ham_g3 = hams g3 |> S.to_list |> List.hd *2) *1) *)
(* (1* (2* let hamm = [|1; 2; 3; 4; 5; 6|] *2) *1) *)

(* (1* (2* let h0 = hams g3 |> S.to_list |> List.hd *2) *1) *)
(* (1* (2* let pp0 = p0x h0 *2) *1) *)
(* (1* (2* let xxx i = *2) *1) *)
(* (1* (2*   let a = h0.(i) and b = h0.(12 - i - 1) in *2) *1) *)
(* (1* (2*   Vset.(empty |> add a |> add b), (a, b) *2) *1) *)
(* (1* (2* let l2 = reducex pp0 |> S.to_list *2) *1) *)

(* (1* (2* let xs = (hams g2 >>= partitions1x 3) |> S.to_list |> List.sort_uniq compare *2) *1) *)
(* (1* (2* List.iter (Array.sort compare) xs *2) *1) *)
(* (1* (2* xs *2) *1) *)

(* https://codeforces.com/problemset/problem/1569/F *)

module S = struct
  type 'a t = ('a -> unit) -> unit
  module Infix = struct
    let (>>=) s f i = s (fun x -> f x i)
    let (>>|) s f i = s (fun x -> i (f x))
    let (--) a b f = for i = a to b do f i done
    let (++) s1 s2 i = s1 i; s2 i
  end
  let return x i = i x
  let filter p s i = s (fun x -> if p x then i x)
  let map f s i = s (fun x -> i (f x))
  let of_list xs i = List.iter i xs
  let of_array xs i = Array.iter i xs
  let fold f a s =
    let acc = ref a in
    s (fun x -> acc := f !acc x);
    !acc
  let to_list s = fold (fun xs x -> x::xs) [] s |> List.rev
  let length s = fold (fun n _ -> n + 1) 0 s
  let null _ = ()
  let sum = fold (+) 0
end

module Vset : sig
  type t
  val compare : t -> t -> int
  val equal : t -> t -> bool
  val empty : t
  val sg : int -> t
  val add : int -> t -> t
  val mem : int -> t -> bool
  val union : t -> t -> t
  val iter : (int -> unit) -> t -> unit
  (* val pp : Format.formatter -> t -> unit *)
end = struct (* vertex sets *)
  type t = int
  let compare (a: t) b = compare a b
  let equal (a: t) b = a == b
  let union t1 t2 = t1 lor t2
  let sg x =
    (* assert (0 <= x && x <= 62); *)
    1 lsl x
  let add x t =
    (* assert (0 <= x && x <= 62); *)
    (1 lsl x) lor t
  let mem x t =
    (* assert (0 <= x && x <= 62); *)
    (1 lsl x) land t <> 0
  let empty = 0
  let iter f t =
    let rec go f x = function
    | 0 -> ()
    | t -> if t land 1 = 1 then f x; go f (x + 1) (t lsr 1) in
    go f 0 t
  (* let pp ppf = Fmt.pf ppf "@[<1>{%a}@]" (Fmt.iter ~sep:Fmt.comma iter Fmt.int) *)
end

(* #install_printer Vset.pp *)

let fac n =
  let rec go acc = function 0 -> acc | n -> go (acc * n) (n - 1) in
  go 1 n

let prod n k =
  let rec go acc n = function 0 -> acc | k -> go (acc * n) (n - 1) (k - 1) in
  go 1 n k

let rec choose k n =
  assert (k <= n);
  if k > n / 2 then choose (n - k) n else prod n k / fac k

let stop (type a) f =
  let module M = struct exception Stop of a end in
  try f (fun x -> raise (M.Stop x)) with M.Stop x -> x

let seen (type a) ~eq ~hash () =
  let module H = Hashtbl.Make(struct type t = a let hash, equal = hash, eq end) in
  let ht = H.create 4096 in
  (* at_exit (fun () -> Format.printf "ht pop: %d@." (H.length ht)); *)
  fun x -> if H.mem ht x then true else ( H.add ht x (); false )

let init n f =
  let rec go i n f = if i < n then f i :: go (i + 1) n f else [] in
  go 0 n f

let rec lequal eq l1 l2 = match l1, l2 with
| a1::l1, a2::l2 -> eq a1 a2 && lequal eq l1 l2
| [], [] -> true
| _, _ -> false

let rec lhash seed = function
| a::xs -> lhash Hashtbl.(seeded_hash seed a) xs
| [] -> seed

let rec lines ic i = match input_line ic with
| exception End_of_file -> ()
| line -> i line; lines ic i

open S.Infix

let partitions_of n =
  assert (n land 1 = 0);
  let rec go acc = function
  | x::y::xs -> go (x::acc) (y::xs) ++ go acc (x + y::xs)
  | r -> S.return (r @ acc) in
  go [] (init (n / 2) (fun _ -> 2))

let assignments n k = (* upper bound for a complete graph *)
  let rec go acc n = function
  | [] -> acc
  | x::xs -> go (acc * choose x n) (n - x) xs in
  partitions_of n
    |> S.map (fun p -> List.length p, p)
    |> S.filter (fun (x, _) -> x <= k)
    |> S.map (fun (x, p) -> go 1 n p * choose x k)
    |> S.sum

module Vmap = Map.Make(struct type t = int let compare (a: int) b = compare a b end)

let graph vs = (* graph from edges *)
  let ext v1 v2 m =
    let xs = match Vmap.find v1 m with xs -> xs | exception Not_found -> [] in
    Vmap.add v1 (v2::xs) m in
  let m = S.fold (fun m (v1, v2) -> ext v1 v2 m |> ext v2 v1) Vmap.empty vs in
  let a = Array.init 12 @@ fun i ->
    try Vmap.find (i + 1) m |> List.sort compare |> Array.of_list
    with Not_found -> [||] in
  fun v -> a.(v - 1)

let hams (n, succ) it =
  let ham = Array.make n 0 in
  let rec go seen v i =
    ham.(i) <- v;
    if i < n - 1 then
      succ v |> Array.iter (fun v1 ->
        if not (Vset.mem v1 seen) then go Vset.(add v1 seen) v1 (i + 1))
    else if ham.(0) <= v then it ham in
  for v0 = 1 to n do go Vset.(sg v0) v0 0 done

let select xs =
  let rec go acc = function
  | [] -> S.null
  | x::xs -> S.return (acc, x, xs) ++ go (x::acc) xs in
  go [] xs

let coarser p =
  select p >>= fun (xs, s1, ys) ->
  select ys >>| fun (ys, s2, zs) ->
    Vset.union s1 s2 :: xs @ ys @ zs

let partitions1 k seen ham = (* partitions induced by a hamiltonian *)
  let rec go s0 =
    let s0 = List.sort Vset.compare s0 in
    if seen s0 then S.null else
    match List.length s0 with
    | c when c <= 1 -> S.return s0
    | c when c <= k -> S.return s0 ++ (coarser s0 >>= go)
    | c -> coarser s0 >>= go in
  let n = Array.length ham in
  let p0 = init (n/2) @@ fun i ->
    Vset.(empty |> add ham.(i) |> add ham.(n - i - 1)) in
  go p0

let p_memo () = seen ~eq:(lequal Vset.equal) ~hash:(lhash 0) ()

let partitions k hams = S.(hams >>= partitions1 k (p_memo ()))

let count g k = (* legal letter assignments *)
  let ns = hams g |> partitions k |> S.map (fun s -> prod k (List.length s)) in
  let max = assignments (fst g) k in
  stop @@ fun exit ->
    S.fold (fun a x -> let ax = a + x in if ax = max then exit max else ax) 0 ns

let input ic =
  Scanf.sscanf (input_line ic) "%d %d %d" @@ fun vx lx k ->
    let vxn = lines ic |> S.map @@ fun s -> Scanf.sscanf s "%d %d" (fun a b -> a, b) in
    (vx, graph vxn), k

let _ =
  let g, k = input stdin in
  Format.printf "%d@." (count g k)

(* let g1 = 4, graph (S.of_list [(1,2); (2,3); (3,4)]) *)
(* let g2 = 4, graph (S.of_list [(1,2); (1,3); (1,4); (2,3); (2,4); (3,4)]) *)
(* let g3 = 12, graph (S.of_list [ *)
(*   (1,3); (2,6); (3,6); (3,7); (4,8); (8,5); (8,7); (9,4); (5,9); (10,1); *)
(*   (10,4); (10,6); (9,10); (11,1); (5,11); (7,11); (12,2); (12,5); (12,11) ]) *)
(* let g20 = 12, graph (S.of_list [ *)
(*   (3,4); (4,9); (12,8); (12,11); (12,1); (8,11); (1,7); (1,3); (2,6); (10,12); *)
(*   (3,12); (3,8); (3,5); (8,5); (11,4); (2,5); (1,6); (4,12); (9,8); (12,7); *)
(*   (5,9); (9,12); (10,9); (7,5); (2,8); (7,2); (2,11); (7,3); (4,6); (1,5); *)
(*   (5,10); (2,10); (9,6); (8,10); (12,5); (4,5); (1,2); (5,11); (4,7); (7,10); *)
(*   (6,5); (11,6); (9,2); (11,10); (2,12); (2,4); (10,4); (3,2); (6,3); (9,3); *)
(*   (8,4); (3,11); (9,11); (1,10); (1,8); (12,6); (11,1); (6,8); (9,1); (11,7); *)
(*   (9,7); (4,1); (8,7); (10,3); (10,6); (6,7) ]) *)

(* let complete n = *)
(*   let a = *)
(*     Array.init n @@ fun i -> *)
(*       Array.init (n - 1) @@ fun j -> *)
(*         if j < i then j + 1 else j + 2 in *)
(*   n, fun v -> a.(v - 1) *)

(* let check name g k res = *)
(*   let x = count g k in *)
(*   Format.printf "%s -> %d  (of %d)@." name x (assignments (fst g) k); *)
(*   assert (x = res) *)

(* let _ = *)
(*   check "g1" g1 3 9; *)
(*   check "g2" g2 3 21; *)
(*   check "g3" g3 12 456165084 *)

(* (1* let check_complete n k = *1) *)
(* (1*   let c = count (complete n) k *1) *)
(* (1*   and l = assignments n k in *1) *)
(* (1*   Format.printf "count: %d, limit: %d@." c l; *1) *)
(* (1*   assert (c = l) *1) *)

(* (1* let _ = *1) *)
(* (1*   for n = 1 to 5 do *1) *)
(* (1*     let n = n * 2 in *1) *)
(* (1*     Format.printf "@[<v 2>n = %d@ " n; *1) *)
(* (1*     for k = 1 to 12 do *1) *)
(* (1*       let c = count (complete n) k *1) *)
(* (1*       and l = assignments n k in *1) *)
(* (1*       Format.printf "k = %d ->  %d  (limit %d)@ " k c l; *1) *)
(* (1*       assert (c = l) *1) *)
(* (1*     done; *1) *)
(* (1*     Format.printf "@]@." *1) *)
(* (1*   done *1) *)

(* (1* let _ = Format.printf "%d@." (hams g20 |> S.length) *1) *)

(* (1* let _ = Format.printf "%d@." (count g20 2) *1) *)

(* (1* (2* let _ = Format.printf "%d@." (count (g4 10) 12) *2) *1) *)
(* (1* (2* let _ = Format.printf "%d@." (g4 10 |> hams |> S.length) *2) *1) *)

(* (1* (2* let s = Vset.[|empty |> add 1 |> add 2; empty |> add 3 |> add 4; empty |> add 5 |> add 6|] *2) *1) *)
(* (1* (2* let _ = reducex s |> S.to_list *2) *1) *)

(* (1* (2* let ham_g1 = hams g1 |> S.to_list |> List.hd *2) *1) *)
(* (1* (2* let ham_g2 = hams g2 |> S.to_list |> List.hd *2) *1) *)
(* (1* (2* let ham_g3 = hams g3 |> S.to_list |> List.hd *2) *1) *)
(* (1* (2* let hamm = [|1; 2; 3; 4; 5; 6|] *2) *1) *)

(* (1* (2* let h0 = hams g3 |> S.to_list |> List.hd *2) *1) *)
(* (1* (2* let pp0 = p0x h0 *2) *1) *)
(* (1* (2* let xxx i = *2) *1) *)
(* (1* (2*   let a = h0.(i) and b = h0.(12 - i - 1) in *2) *1) *)
(* (1* (2*   Vset.(empty |> add a |> add b), (a, b) *2) *1) *)
(* (1* (2* let l2 = reducex pp0 |> S.to_list *2) *1) *)

(* (1* (2* let xs = (hams g2 >>= partitions1x 3) |> S.to_list |> List.sort_uniq compare *2) *1) *)
(* (1* (2* List.iter (Array.sort compare) xs *2) *1) *)
(* (1* (2* xs *2) *1) *)

let _ = Format.printf "compiler test.@."


Frodo was caught by Saruman. He tore a pouch from Frodo's neck, shook out its contents —there was a pile of different rings: gold and silver..."How am I to tell which is the One?!" the mage howled."Throw them one by one into the Cracks of Doom and watch when Mordor falls!" Somewhere in a parallel Middle-earth, when Saruman caught Frodo, he only found $$$n$$$ rings. And the $$$i$$$-th ring was either gold or silver. For convenience Saruman wrote down a binary string $$$s$$$ of $$$n$$$ characters, where the $$$i$$$-th character was 0 if the $$$i$$$-th ring was gold, and 1 if it was silver.Saruman has a magic function $$$f$$$, which takes a binary string and returns a number obtained by converting the string into a binary number and then converting the binary number into a decimal number. For example, $$$f(001010) = 10, f(111) = 7, f(11011101) = 221$$$.Saruman, however, thinks that the order of the rings plays some important role. He wants to find $$$2$$$ pairs of integers $$$(l_1, r_1), (l_2, r_2)$$$, such that: $$$1 \le l_1 \le n$$$, $$$1 \le r_1 \le n$$$, $$$r_1-l_1+1\ge \lfloor \frac{n}{2} \rfloor$$$  $$$1 \le l_2 \le n$$$, $$$1 \le r_2 \le n$$$, $$$r_2-l_2+1\ge \lfloor \frac{n}{2} \rfloor$$$  Pairs $$$(l_1, r_1)$$$ and $$$(l_2, r_2)$$$ are distinct. That is, at least one of $$$l_1 \neq l_2$$$ and $$$r_1 \neq r_2$$$ must hold. Let $$$t$$$ be the substring $$$s[l_1:r_1]$$$ of $$$s$$$, and $$$w$$$ be the substring $$$s[l_2:r_2]$$$ of $$$s$$$. Then there exists non-negative integer $$$k$$$, such that $$$f(t) = f(w) \cdot k$$$.Here substring $$$s[l:r]$$$ denotes $$$s_ls_{l+1}\ldots s_{r-1}s_r$$$, and $$$\lfloor x \rfloor$$$ denotes rounding the number down to the nearest integer.Help Saruman solve this problem! It is guaranteed that under the constraints of the problem at least one solution exists.

Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 10^3$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^4$$$) — length of the string. The second line of each test case contains a non-empty binary string of length $$$n$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For every test case print four integers $$$l_1$$$, $$$r_1$$$, $$$l_2$$$, $$$r_2$$$, which denote the beginning of the first substring, the end of the first substring, the beginning of the second substring, and the end of the second substring, respectively. If there are multiple solutions, print any.

open Printf
open Scanf

let read_int _ = bscanf Scanning.stdin " %d " (fun x -> x)
let read_int_char _ = bscanf Scanning.stdin " %c " (fun x -> int_of_char x - 48)

let rec find lst x =
    match lst with
    | [] -> -100000000
    | h :: t -> if x = h then 0 else 1 + find t x

let find_last lst x =
  if find lst x < 0 then -1
  else List.length lst - 1 - find (List.rev lst) x

let () =
  let cases = read_int () in
  for case = 1 to cases do
    let n = read_int () in
    let n2 = (n+1)/2 in
    let a = Array.init n (fun _ -> read_int_char ()) in
    let l = Array.to_list a in
    let last = find_last l 0 in
    if last >= n2 then printf "%d %d %d %d\n" 1 (last+1) 1 last
    else if List.nth l (n2-1) = 0 then
      printf "%d %d %d %d\n" n2 n (n2+1) n
    else
      printf "%d %d %d %d\n" n2 (n-1) (n2+1) n
  done

open Printf
open Scanf

let read_int _ = bscanf Scanning.stdin " %d " (fun x -> x)
let read_int_char _ = bscanf Scanning.stdin " %c " (fun x -> int_of_char x - 48)

let rec find lst x =
    match lst with
    | [] -> -100000000
    | h :: t -> if x = h then 0 else 1 + find t x

let find_last lst x =
  if find lst x < 0 then -1
  else List.length lst - 1 - find (List.rev lst) x

let () =
  let cases = read_int () in
  for case = 1 to cases do
    let n = read_int () in
    let n2 = (n+1)/2 in
    let a = Array.init n (fun _ -> read_int_char ()) in
    let l = Array.to_list a in
    let last = find_last l 0 in
    if last > n2 then printf "%d %d %d %d\n" 1 last 1 (last-1)
    else if List.nth l (n2-1) = 0 then
      printf "%d %d %d %d\n" n2 n (n2+1) n
    else
      printf "%d %d %d %d\n" n2 (n-1) (n2+1) n
  done


You have two strings $$$s_1$$$ and $$$s_2$$$ of length $$$n$$$, consisting of lowercase English letters. You can perform the following operation any (possibly zero) number of times:   Choose a positive integer $$$1 \leq k \leq n$$$.  Swap the prefix of the string $$$s_1$$$ and the suffix of the string $$$s_2$$$ of length $$$k$$$. Is it possible to make these two strings equal by doing described operations?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then the test cases follow. Each test case consists of three lines. The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the strings $$$s_1$$$ and $$$s_2$$$.  The second line contains the string $$$s_1$$$ of length $$$n$$$, consisting of lowercase English letters. The third line contains the string $$$s_2$$$ of length $$$n$$$, consisting of lowercase English letters. It is guaranteed that the sum of $$$n$$$ for all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print "YES" if it is possible to make the strings equal, and "NO" otherwise.

7

3

cbc

aba

5

abcaa

cbabb

5

abcaa

cbabz

1

a

a

1

a

b

6

abadaa

adaaba

8

abcabdaa

adabcaba

NoteIn the first test case:  Initially $$$s_1 = \mathtt{cbc}$$$, $$$s_2 = \mathtt{aba}$$$.  Operation with $$$k = 1$$$, after the operation $$$s_1 = \mathtt{abc}$$$, $$$s_2 = \mathtt{abc}$$$. In the second test case:  Initially $$$s_1 = \mathtt{abcaa}$$$, $$$s_2 = \mathtt{cbabb}$$$.  Operation with $$$k = 2$$$, after the operation $$$s_1 = \mathtt{bbcaa}$$$, $$$s_2 = \mathtt{cbaab}$$$.  Operation with $$$k = 3$$$, after the operation $$$s_1 = \mathtt{aabaa}$$$, $$$s_2 = \mathtt{cbbbc}$$$.  Operation with $$$k = 1$$$, after the operation $$$s_1 = \mathtt{cabaa}$$$, $$$s_2 = \mathtt{cbbba}$$$.  Operation with $$$k = 2$$$, after the operation $$$s_1 = \mathtt{babaa}$$$, $$$s_2 = \mathtt{cbbca}$$$.  Operation with $$$k = 1$$$, after the operation $$$s_1 = \mathtt{aabaa}$$$, $$$s_2 = \mathtt{cbbcb}$$$.  Operation with $$$k = 2$$$, after the operation $$$s_1 = \mathtt{cbbaa}$$$, $$$s_2 = \mathtt{cbbaa}$$$. In the third test case, it's impossible to make strings equal.

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

let read_int _ = bscanf Scanning.stdin " %d " (fun x -> x)
let read_string _ = bscanf Scanning.stdin " %s " (fun x -> x)
let l2n c = (int_of_char c) - (int_of_char 'a')

let () =
  let cases = read_int() in
  for case = 1 to cases do
    let n = read_int() in
    let st_to_array s = Array.init n (fun i -> l2n s.[i]) in
    let s = st_to_array (read_string ()) in
    let t = st_to_array (read_string ()) in
    let pairs = Array.make_matrix 26 26 0 in
    let inc (x,y) =
      let (x,y) = min (x,y) (y,x) in
      pairs.(x).(y) <- 1 + pairs.(x).(y)
    in

    for i=0 to n-1 do
      let j = n-1-i in
      inc (s.(i),t.(j))
    done;

    let distinct_pairs_ok =
      forall 0 24 (fun i -> forall (i+1) 25 (fun j ->
	pairs.(i).(j) land 1 = 0
      ))
    in

    let n_odd_identital_pairs =
      sum 0 25 (fun i -> pairs.(i).(i) land 1)
    in

    if distinct_pairs_ok && (n_odd_identital_pairs = n land 1)
    then printf "YES\n" else printf "NO\n"
  done


There are $$$n$$$ points on the plane, $$$(x_1,y_1), (x_2,y_2), \ldots, (x_n,y_n)$$$.You need to place an isosceles triangle with two sides on the coordinate axis to cover all points (a point is covered if it lies inside the triangle or on the side of the triangle). Calculate the minimum length of the shorter side of the triangle.

First line contains one integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$). Each of the next $$$n$$$ lines contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \leq x_i,y_i \leq 10^9$$$).

Print the minimum length of the shorter side of the triangle. It can be proved that it's always an integer.

NoteIllustration for the first example: Illustration for the second example:

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 let abs v = abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) let min_int,max_int = min_int,max_int 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 repb 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; !f let repm from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod !m (~~| !i) with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; !m let repmb from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod (~~| !i) !m with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; (!m,!f) 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
	let abs v = Int64.abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = let open Int64 in (logand),(logor),(logxor),lognot,(fun u v -> shift_left u (~|v)),(fun u v -> shift_right u (~|v)),(fun u v -> shift_right_logical u (~|v)) let min_int,max_int = Int64.min_int,Int64.max_int let get_string _ = scanf " %s" (fun v -> v)
	let i32,i64 = Int64.to_int,Int64.of_int let alen a = i64 @@ Array.length a
end open MyInt64

let () =
	let n = get_i64 0 in
	repm 1L n 0L (fun m _ ->
		let x,y = get_2_i64 9 in `Ok (max m (x+y))
	)
	|> printf "%Ld\n"


There are n lights aligned in a row. These lights are numbered 1 to n from left to right. Initially some of the lights are switched on. Shaass wants to switch all the lights on. At each step he can switch a light on (this light should be switched off at that moment) if there's at least one adjacent light which is already switched on. He knows the initial state of lights and he's wondering how many different ways there exist to switch all the lights on. Please find the required number of ways modulo 1000000007 (109 + 7).

The first line of the input contains two integers n and m where n is the number of lights in the sequence and m is the number of lights which are initially switched on, (1 ≤ n ≤ 1000, 1 ≤ m ≤ n). The second line contains m distinct integers, each between 1 to n inclusive, denoting the indices of lights which are initially switched on.

In the only line of the output print the number of different possible ways to switch on all the lights modulo 1000000007 (109 + 7).

open Int64

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

let sum a b =
	Int64.to_int(Int64.rem (Int64.add (Int64.of_int a) (Int64.of_int b)) (Int64.of_int mmod))
;;

let pdt a b =
	Int64.to_int(Int64.rem (Int64.mul (Int64.of_int a) (Int64.of_int b)) (Int64.of_int mmod))
;;

let rec pow a n =
	if n=0 then 1 else
	let b = pow a (n/2) in
	if (n mod 2) = 0 then pdt b b else pdt a (pdt b b)
 ;;

 let rec comb n m =
	if m = 0 or n = m then 1
	else sum (comb(n-1) (m-1)) (comb(n-1) m)
;;

let init_binomial n m =
  let b = Array.make_matrix (n+1) (m+1) 0 in
    for i=0 to n do for j=0 to min i m do
      b.(i).(j) <- if j=0 then 1 else sum b.(i-1).(j-1) b.(i-1).(j)
    done done;
    b
;;

let n = read_int 0 in
let k = read_int 0 in
let a = Array.init k read_int in
let b = Array.make (n+2) 0 in
let s = Array.make 5 0 in
let bb = init_binomial n n in

for i = 0 to k-1 do
	b.(a.(i)) <- 1
done;

b.(n+1) <- 1;
s.(1) <- n - k;
s.(2) <- 1;

for i = 1 to n+1 do
	if b.(i) = 0 then s.(0) <- s.(0) + 1
	else begin
		if s.(3) = 1 then begin
			if s.(4) > 0 then s.(2) <- pdt (s.(2)) (pow 2 (s.(4) - 1));
			s.(4) <- s.(0);
		end;

		s.(3) <- 1;

		s.(2) <- pdt (s.(2)) (bb.(s.(1)).(s.(0)));
		s.(1) <- s.(1) - s.(0);
		s.(0) <- 0;
	end;
done;

Printf.printf "%d\n" s.(2)

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

let mval = 1_000_000_007L

let ( ** ) a b = (Int64.rem (Int64.mul a b) mval)
let ( ++ ) a b = (Int64.rem (Int64.add a b) mval)
(* let ( -- ) a b = Int64.sub a b
   let ( // ) a b = Int64.div a b *)

(*------------create binomial--------------*)
let init_binomial n m =
  (* compute an array b so that b.(p).(q) = (p choose q),
     where 0 <= p <= n and 0 <= q <= m. *)
  let b = Array.make_matrix (n+1) (m+1) 0L in
    for i=0 to n do for j=0 to min i m do
      b.(i).(j) <- if j=0 then 1L else b.(i-1).(j-1) ++ b.(i-1).(j)
    done done;
    b

let init_powers n =
  let p = Array.make (n+1) 1L in
    for i=1 to n do
      p.(i) <- p.(i-1) ++ p.(i-1)
    done;
    p

let () =
  let n = read_int() in
  let m = read_int() in
  let on = Array.make (m+2) 0 in
  let () = for i=1 to m do
      on.(i) <- read_int();
  done in

  let () = on.(m+1) <- n+1 in

  let () = Array.sort compare on in

  let bi = init_binomial n n in
  let po = init_powers n in

  let rec find_gaps i stop ac = if i=stop then ac else
    (* consider gap from on.(i-1) to on.(i) *)
    if on.(i-1) + 1 = on.(i) then find_gaps (i+1) stop ac else
      find_gaps (i+1) stop ((on.(i) - on.(i-1) - 1) :: ac)
  in

  let gaps = find_gaps 1 (m+2) [] in
  let gaps = Array.of_list gaps in
  let g = Array.length gaps in

  let rec bloop i s ac = if i=g then ac else
    let s = s+gaps.(i) in
    let ac = ac ** bi.(s).(gaps.(i)) in
      bloop (i+1) s ac
  in

  let mix_count = bloop 0 0 1L in

  let pgaps = find_gaps 2 (m+1) [] in

  let rec ploop gl ac = match gl with [] -> ac
    | g::gl -> ploop gl (po.(g-1) ** ac)
  in
  let pow_count = ploop pgaps 1L in

    Printf.printf "%Ld\n" (pow_count ** mix_count);

open Int64

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

let sum a b =
	(a + b) mod mmod
;;

let pdt a b =
	Int64.to_int(Int64.rem (Int64.mul (Int64.of_int a) (Int64.of_int b)) (Int64.of_int mmod))
;;

let rec pow a n =
	if n=0 then 1 else
	let b = pow a (n/2) in
	if (n mod 2) = 0 then pdt b b else pdt a (pdt b b)
 ;;

 let rec comb n m =
	if m = 0 or n = m then 1
	else sum (comb(n-1) (m-1)) (comb(n-1) m)
;;

let n = read_int 0 in
let k = read_int 0 in
let a = Array.init k read_int in
let b = Array.make (n+2) 0 in
let s = Array.make 5 0 in

for i = 0 to k-1 do
	b.(a.(i)) <- 1
done;

b.(n+1) <- 1;

s.(1) <- n - k;
s.(2) <- 1;

for i = 1 to n+1 do
	if b.(i) = 0 then s.(0) <- s.(0) + 1
	else begin
		if s.(3) = 1 then s.(2) <- pdt (s.(2)) ((pow 2 s.(4)) - 1);
		if (s.(0) > 0) then begin s.(3) <- 1; s.(4) <- s.(0); end;
		s.(2) <- pdt (s.(2)) (comb s.(1) s.(0));
		s.(1) <- s.(1) - s.(0);
		s.(0) <- 0;
	end;
done;

Printf.printf "%d\n" s.(2)

(*
(pdt (pow k (k-1)) (pow (n-k) (n-k)))
*)

open Int64

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

let sum a b =
	(a + b) mod mmod
;;

let pdt a b =
	Int64.to_int(Int64.rem (Int64.mul (Int64.of_int a) (Int64.of_int b)) (Int64.of_int mmod))
;;

let rec pow a n =
	if n=0 then 1 else
	let b = pow a (n/2) in
	if (n mod 2) = 0 then pdt b b else pdt a (pdt b b)
 ;;

 let rec comb n m =
	if m = 0 or n = m then 1
	else sum (comb(n-1) (m-1)) (comb(n-1) m)
;;

let n = read_int 0 in
let k = read_int 0 in
let a = Array.init k read_int in
let b = Array.make (n+2) 0 in
let s = Array.make 5 0 in

for i = 0 to k-1 do
	b.(a.(i)) <- 1
done;

b.(n+1) <- 1;
s.(1) <- n - k;
s.(2) <- 1;

for i = 1 to n+1 do
	if b.(i) = 0 then s.(0) <- s.(0) + 1
	else begin
		if s.(3) = 1 && s.(4) > 0 then s.(2) <- pdt (s.(2)) ((pow 2 s.(4)) - 1);
		s.(3) <- 1; s.(4) <- s.(0);
		s.(2) <- pdt (s.(2)) (comb s.(1) s.(0));
		s.(1) <- s.(1) - s.(0);
		s.(0) <- 0;
	end;
done;

Printf.printf "%d\n" s.(2)

(*
(pdt (pow k (k-1)) (pow (n-k) (n-k)))
*)

open Int64

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

let sum a b =
	(a + b) mod mmod
;;

let pdt a b =
	Int64.to_int(Int64.rem (Int64.mul (Int64.of_int a) (Int64.of_int b)) (Int64.of_int mmod))
;;

let rec pow a n =
	if n=0 then 1 else
	let b = pow a (n/2) in
	if (n mod 2) = 0 then pdt b b else pdt a (pdt b b)
 ;;

 let rec comb n m =
	if m = 0 or n = m then 1
	else sum (comb(n-1) (m-1)) (comb(n-1) m)
;;

let n = read_int 0 in
let k = read_int 0 in
let a = Array.init k read_int in
let b = Array.make (n+2) 0 in
let s = Array.make 5 0 in

for i = 0 to k-1 do
	b.(a.(i)) <- 1
done;

b.(n) <- 1;

s.(1) <- n - k;
s.(2) <- 1;

for i = 1 to n+1 do
	if b.(i) = 0 then s.(0) <- s.(0) + 1
	else begin
		if s.(3) = 1 then s.(2) <- pdt (s.(2)) ((pow 2 s.(4)) - 1);
		s.(3) <- 1;
		s.(4) <- s.(0);
		s.(2) <- pdt (s.(2)) (comb s.(1) s.(0));
		s.(1) <- s.(1) - s.(0);
		s.(0) <- 0;
	end;
done;

Printf.printf "%d\n" s.(2)

(*
(pdt (pow k (k-1)) (pow (n-k) (n-k)))
*)

open Int64

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

let sum a b =
	(a + b) mod mmod
;;

let pdt a b =
	Int64.to_int(Int64.rem (Int64.mul (Int64.of_int a) (Int64.of_int b)) (Int64.of_int mmod))
;;

let rec pow a n =
	if n=0 then 1 else
	let b = pow a (n/2) in
	if (n mod 2) = 0 then pdt b b else pdt a (pdt b b)
 ;;

 let rec comb n m =
	if m = 0 or n = m then 1
	else sum (comb(n-1) (m-1)) (comb(n-1) m)
;;

let n = read_int 0 in
let k = read_int 0 in
let a = Array.init k read_int in
let b = Array.make (n+2) 0 in
let s = Array.make 5 0 in

for i = 0 to k-1 do
	b.(a.(i)) <- 1
done;

b.(n+1) <- 1;
s.(1) <- n - k;
s.(2) <- 1;

for i = 1 to n+1 do
	if b.(i) = 0 then s.(0) <- s.(0) + 1
	else begin
		if (s.(3) = 1) && (s.(4) > 0) then begin
			s.(2) <- pdt (s.(2)) (pow 2 (s.(4) - 1));
			s.(4) <- s.(0);
		end;

		s.(3) <- 1;

		s.(2) <- pdt (s.(2)) (comb s.(1) s.(0));
		s.(1) <- s.(1) - s.(0);
		s.(0) <- 0;
	end;
done;

Printf.printf "%d\n" s.(2)

(*
(pdt (pow k (k-1)) (pow (n-k) (n-k)))
*)

open Int64

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

let sum a b =
	(a + b) mod mmod
;;

let pdt a b =
	Int64.to_int(Int64.rem (Int64.mul (Int64.of_int a) (Int64.of_int b)) (Int64.of_int mmod))
;;

let rec pow a n =
	if n=0 then 1 else
	let b = pow a (n/2) in
	if (n mod 2) = 0 then pdt b b else pdt a (pdt b b)
 ;;

 let rec comb n m =
	if m = 0 or n = m then 1
	else sum (comb(n-1) (m-1)) (comb(n-1) m)
;;

let init_binomial n m =
  let b = Array.make_matrix (n+1) (m+1) 0 in
    for i=0 to n do for j=0 to min i m do
      b.(i).(j) <- if j=0 then 1 else sum b.(i-1).(j-1) b.(i-1).(j)
    done done;
    b
;;

let n = read_int 0 in
let k = read_int 0 in
let a = Array.init k read_int in
let b = Array.make (n+2) 0 in
let s = Array.make 5 0 in
let bb = init_binomial n n in

for i = 0 to k-1 do
	b.(a.(i)) <- 1
done;

b.(n+1) <- 1;
s.(1) <- n - k;
s.(2) <- 1;

for i = 1 to n+1 do
	if b.(i) = 0 then s.(0) <- s.(0) + 1
	else begin
		if s.(3) = 1 then begin
			if s.(4) > 0 then s.(2) <- pdt (s.(2)) (pow 2 (s.(4) - 1));
			s.(4) <- s.(0);
		end;

		s.(3) <- 1;

		s.(2) <- pdt (s.(2)) (bb.(s.(1)).(s.(0)));
		s.(1) <- s.(1) - s.(0);
		s.(0) <- 0;
	end;
done;

Printf.printf "%d\n" s.(2)

open Int64

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

let sum a b =
	(a + b) mod mmod
;;

let pdt a b =
	Int64.to_int(Int64.rem (Int64.mul (Int64.of_int a) (Int64.of_int b)) (Int64.of_int mmod))
;;

let rec pow a n =
	if n=0 then 1 else
	let b = pow a (n/2) in
	if (n mod 2) = 0 then pdt b b else pdt a (pdt b b)
 ;;

 let rec comb n m =
	if m = 0 or n = m then 1
	else sum (comb(n-1) (m-1)) (comb(n-1) m)
;;

let n = read_int 0 in
let k = read_int 0 in
let a = Array.init k read_int in
let b = Array.make (n+2) 0 in
let s = Array.make 5 0 in

for i = 0 to k-1 do
	b.(a.(i)) <- 1
done;

b.(n+1) <- 1;
s.(1) <- n - k;
s.(2) <- 1;

for i = 1 to n+1 do
	if b.(i) = 0 then s.(0) <- s.(0) + 1
	else begin
		if s.(3) = 1 && s.(4) > 0 then s.(2) <- pdt (s.(2)) (pow 2 (s.(4) - 1));
		s.(3) <- 1; s.(4) <- s.(0);
		s.(2) <- pdt (s.(2)) (comb s.(1) s.(0));
		s.(1) <- s.(1) - s.(0);
		s.(0) <- 0;
	end;
done;

Printf.printf "%d\n" s.(2)

(*
(pdt (pow k (k-1)) (pow (n-k) (n-k)))
*)


You are given $$$n$$$ numbers $$$a_1, a_2, \ldots, a_n$$$. Is it possible to arrange them in a circle in such a way that every number is strictly less than the sum of its neighbors?For example, for the array $$$[1, 4, 5, 6, 7, 8]$$$, the arrangement on the left is valid, while arrangement on the right is not, as $$$5\ge 4 + 1$$$ and $$$8> 1 + 6$$$.

The first line contains a single integer $$$n$$$ ($$$3\le n \le 10^5$$$) — the number of numbers. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \le 10^9$$$) — the numbers. The given numbers are not necessarily distinct (i.e. duplicates are allowed).

If there is no solution, output "NO" in the first line.  If there is a solution, output "YES" in the first line. In the second line output $$$n$$$ numbers — elements of the array in the order they will stay in the circle. The first and the last element you output are considered neighbors in the circle. If there are multiple solutions, output any of them. You can print the circle starting with any element.

NoteOne of the possible arrangements is shown in the first example: $$$4< 2 + 3$$$;$$$2 < 4 + 3$$$;$$$3< 4 + 2$$$.One of the possible arrangements is shown in the second example.No matter how we arrange $$$13, 8, 5$$$ in a circle in the third example, $$$13$$$ will have $$$8$$$ and $$$5$$$ as neighbors, but $$$13\ge 8 + 5$$$. There is no solution in the fourth example.

let () =
    let split s =
        let rec loop i cur flag acc =
            if i = String.length s then (
                if flag then cur :: acc else acc
            ) else (
                match flag, s.[i] with
                | true,  ' ' -> loop (i + 1) 0 false (cur :: acc)
                | false, ' ' -> loop (i + 1) 0 false acc
                | true,  v   -> loop (i + 1) (cur * 10 + int_of_char v - 48) true acc
                | false, v   -> loop (i + 1) (cur * 10 + int_of_char v - 48) true acc
            )
        in
        List.rev (loop 0 0 false [])
    in
    let main () =
        let n = int_of_string (read_line ()) in
        let a = Array.of_list (split (read_line ())) in
        Array.sort (fun a b -> compare b a) a;
        if a.(0) >= a.(1) + a.(2) then print_endline "NO" else (
            print_endline "YES";
            for i = 0 to n - 1 do
                let k = i * 2 in
                let k = if k < n then k else 2 * n - 1 - k in
                Printf.printf "%d " a.(k)
            done;
            print_newline ()
        )

    in
    main ()


Nadeko's birthday is approaching! As she decorated the room for the party, a long garland of Dianthus-shaped paper pieces was placed on a prominent part of the wall. Brother Koyomi will like it!Still unsatisfied with the garland, Nadeko decided to polish it again. The garland has n pieces numbered from 1 to n from left to right, and the i-th piece has a colour si, denoted by a lowercase English letter. Nadeko will repaint at most m of the pieces to give each of them an arbitrary new colour (still denoted by a lowercase English letter). After this work, she finds out all subsegments of the garland containing pieces of only colour c — Brother Koyomi's favourite one, and takes the length of the longest among them to be the Koyomity of the garland.For instance, let's say the garland is represented by "kooomo", and Brother Koyomi's favourite colour is "o". Among all subsegments containing pieces of "o" only, "ooo" is the longest, with a length of 3. Thus the Koyomity of this garland equals 3.But problem arises as Nadeko is unsure about Brother Koyomi's favourite colour, and has swaying ideas on the amount of work to do. She has q plans on this, each of which can be expressed as a pair of an integer mi and a lowercase letter ci, meanings of which are explained above. You are to find out the maximum Koyomity achievable after repainting the garland according to each plan.

The first line of input contains a positive integer n (1 ≤ n ≤ 1 500) — the length of the garland. The second line contains n lowercase English letters s1s2... sn as a string — the initial colours of paper pieces on the garland. The third line contains a positive integer q (1 ≤ q ≤ 200 000) — the number of plans Nadeko has. The next q lines describe one plan each: the i-th among them contains an integer mi (1 ≤ mi ≤ n) — the maximum amount of pieces to repaint, followed by a space, then by a lowercase English letter ci — Koyomi's possible favourite colour.

Output q lines: for each work plan, output one line containing an integer — the largest Koyomity achievable after repainting the garland according to it.

15
yamatonadeshiko
10
1 a
2 a
3 a
4 a
5 a
1 b
2 b
3 b
4 b
5 b

NoteIn the first sample, there are three plans:   In the first plan, at most 1 piece can be repainted. Repainting the "y" piece to become "o" results in "kooomi", whose Koyomity of 3 is the best achievable;  In the second plan, at most 4 pieces can be repainted, and "oooooo" results in a Koyomity of 6;  In the third plan, at most 4 pieces can be repainted, and "mmmmmi" and "kmmmmm" both result in a Koyomity of 5.

(* started codeing 11:39  *)
(* done coding 11:54 *)
(* submit: 12:06 (wrong answer) *)

open Printf
open Scanf

let l2n c = (int_of_char c) - (int_of_char 'a')

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 s = read_string () in
  let s = Array.init n (fun i -> l2n s.[i]) in
  let q = read_int () in
  let query = Array.init q (fun _ ->
    let m = read_int() in
    let c = l2n ((read_string()).[0]) in
    (m,c)
  ) in

  let pre = Array.make_matrix (n+1) 26 0 in
  (* pre.(i).(c) = the number of c's in s.(0)...s.(i-1) *)

  for c = 0 to 25 do
    for i=1 to n do
      pre.(i).(c) <- pre.(i-1).(c) + (if s.(i-1) = c then 1 else 0)
    done
  done;

  let range_count i j c = pre.(j+1).(c) - pre.(i).(c) in
  (* the number of c's in the range s.(i) ... s.(j)  *)

  let ans = Array.make_matrix (n+1) 26 0 in

  for i=0 to n-1 do
    for j=i to n-1 do
      for c=0 to 25 do
	let len = j-i+1 in
	let count = len - (range_count i j c) in
	ans.(count).(c) <- max ans.(count).(c) len
      done
    done
  done;

  for c=0 to 25 do
    for count = 1 to n do
      ans.(count).(c) <- max ans.(count-1).(c) ans.(count).(c)
    done
  done;

  for qx = 0 to q-1 do
    let (m,c) = query.(qx) in
    printf "%d\n" ans.(m).(c)
  done;

(* started codeing 11:39  *)
(* done coding 11:54 *)
(* submit: *)

open Printf
open Scanf

let l2n c = (int_of_char c) - (int_of_char 'a')

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

let read_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 s = read_string () in
  let s = Array.init n (fun i -> l2n s.[i]) in
  let q = read_int () in
  let query = Array.init q (fun _ ->
    let m = read_int() in
    let c = l2n ((read_string()).[0]) in
    (m,c)
  ) in

  let pre = Array.make_matrix (n+1) 26 0 in
  (* pre.(i).(c) = the number of c's in s.(0)...s.(i-1) *)

  for c = 0 to 25 do
    for i=1 to n do
      pre.(i).(c) <- pre.(i-1).(c) + (if s.(i-1) = c then 1 else 0)
    done
  done;

  let range_count i j c = pre.(j+1).(c) - pre.(i).(c) in
  (* the number of c's in the range s.(i) ... s.(j)  *)

  let ans = Array.make_matrix (n+1) 26 0 in

  for i=0 to n-1 do
    for j=i to n-1 do
      for c=0 to 25 do
	let len = j-i+1 in
	let count = len - (range_count i j c) in
	ans.(count).(c) <- max ans.(count).(c) len
      done
    done
  done;

  for qx = 0 to q-1 do
    let (m,c) = query.(qx) in
    printf "%d\n" ans.(m).(c)
  done;


You are given a permutation $$$p_1, p_2, \dots, p_n$$$. Then, an undirected graph is constructed in the following way: add an edge between vertices $$$i$$$, $$$j$$$ such that $$$i < j$$$ if and only if $$$p_i > p_j$$$. Your task is to count the number of connected components in this graph.Two vertices $$$u$$$ and $$$v$$$ belong to the same connected component if and only if there is at least one path along edges connecting $$$u$$$ and $$$v$$$.A permutation is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the permutation. The second line of each test case contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$) — the elements of the permutation. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print one integer $$$k$$$ — the number of connected components.

NoteEach separate test case is depicted in the image below. The colored squares represent the elements of the permutation. For one permutation, each color represents some connected component. The number of distinct colors is the answer.

(* Codeforces 1638 C Inversion Graph train *)

(* 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 list *)
let rec readlist n acc = match n with
	| 0 -> List.rev 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 count_comps i cnt max lp comps = match lp with
    | [] -> comps
    | hp :: t ->
        let ncnt = if hp <= i+1 then cnt+1 else cnt in
        let nmax = if hp > max then hp else max in
        let ni = i+1 in
        let ncomps = if nmax == (i+1) then comps+1 else comps in
        (* let _ = Printf.printf "ncnt nmax ni ncomps = %d %d %d %d\n" ncnt nmax ni ncomps in *)
        count_comps ni ncnt nmax t ncomps;;

let do_one () =
    let n = gr () in
    let p = readlist n [] in
    let cnt = count_comps 0 0 0 p 0 in
	(print_int cnt; print_string "\n");;

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

let main() =
	do_all ();;

main();;


You are given a set of all integers from $$$l$$$ to $$$r$$$ inclusive, $$$l < r$$$, $$$(r - l + 1) \le 3 \cdot 10^5$$$ and $$$(r - l)$$$ is always odd.You want to split these numbers into exactly $$$\frac{r - l + 1}{2}$$$ pairs in such a way that for each pair $$$(i, j)$$$ the greatest common divisor of $$$i$$$ and $$$j$$$ is equal to $$$1$$$. Each number should appear in exactly one of the pairs.Print the resulting pairs or output that no solution exists. If there are multiple solutions, print any of them.

If any solution exists, print "YES" in the first line. Each of the next $$$\frac{r - l + 1}{2}$$$ lines should contain some pair of integers. GCD of numbers in each pair should be equal to $$$1$$$. All $$$(r - l + 1)$$$ numbers should be pairwise distinct and should have values from $$$l$$$ to $$$r$$$ inclusive. If there are multiple solutions, print any of them. If there exists no solution, print "NO".

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 let abs v = abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) let min_int,max_int = min_int,max_int 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 repb 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; !f let repm from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod !m (~~| !i) with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; !m let repmb from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod (~~| !i) !m with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; (!m,!f) 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
	let abs v = Int64.abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = let open Int64 in (logand),(logor),(logxor),lognot,(fun u v -> shift_left u (~|v)),(fun u v -> shift_right u (~|v)),(fun u v -> shift_right_logical u (~|v)) let min_int,max_int = Int64.min_int,Int64.max_int let get_string _ = scanf " %s" (fun v -> v)
	let i32,i64 = Int64.to_int,Int64.of_int let alen a = i64 @@ Array.length a
end open MyInt64

let () =
	let l,r = get_2_i64 0 in
	let p = ref l in
	printf "YES\n";
	while !p <= r do
		printf "%Ld %Ld\n" !p (!p+1L);
		p += 2L;
	done;


Vasya has decided to build a zip-line on trees of a nearby forest. He wants the line to be as long as possible but he doesn't remember exactly the heights of all trees in the forest. He is sure that he remembers correct heights of all trees except, possibly, one of them.It is known that the forest consists of n trees staying in a row numbered from left to right with integers from 1 to n. According to Vasya, the height of the i-th tree is equal to hi. The zip-line of length k should hang over k (1 ≤ k ≤ n) trees i1, i2, ..., ik (i1 < i2 < ... < ik) such that their heights form an increasing sequence, that is hi1 < hi2 < ... < hik.Petya had been in this forest together with Vasya, and he now has q assumptions about the mistake in Vasya's sequence h. His i-th assumption consists of two integers ai and bi indicating that, according to Petya, the height of the tree numbered ai is actually equal to bi. Note that Petya's assumptions are independent from each other.Your task is to find the maximum length of a zip-line that can be built over the trees under each of the q assumptions.In this problem the length of a zip line is considered equal to the number of trees that form this zip-line.

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 400 000) — the number of the trees in the forest and the number of Petya's assumptions, respectively. The following line contains n integers hi (1 ≤ hi ≤ 109) — the heights of trees according to Vasya. Each of the following m lines contains two integers ai and bi (1 ≤ ai ≤ n, 1 ≤ bi ≤ 109).

For each of the Petya's assumptions output one integer, indicating the maximum length of a zip-line that can be built under this assumption.

NoteConsider the first sample. The first assumption actually coincides with the height remembered by Vasya. In the second assumption the heights of the trees are (4, 2, 3, 4), in the third one they are (1, 2, 3, 3) and in the fourth one they are (1, 2, 3, 5).

let hmax = 1_000_000_001;;
let rec readlist n f = match n with
    | 0 -> []
    | _ ->  f() :: readlist (n-1) f ;;
let (n, m) = Scanf.scanf "%d %d" (fun x y -> (x,y)) ;;
let ans = Array.make m 0 ;;
let q = Array.make n [] ;;
let h = Array.make n 0 ;;
for i = 0 to n-1 do
    h.(i) <- Scanf.scanf " %d" (fun x -> x)
done ;;
for i = 0 to m-1 do
    let (a,b) = Scanf.scanf " %d %d" (fun x y -> (x-1, y)) in
    q.(a) <- (i, b) :: q.(a)
done ;;

module M = Map.Make(struct type t = int let compare = compare end)

let calcpre () =
    let zpre = Array.make n 0 and
        minWithSize = Array.make (n+1) (hmax+1) in
    let rec calcpre_ i m  =
        if i < n then
        let score h = 1 + ( snd @@ M.max_binding @@ (fun (x1,_,_) -> x1) @@ M.split h m ) in (
            List.iter (fun (id, hnew) -> ans.(id) <- score hnew ) q.(i);
            let zhere = score h.(i) in
                zpre.(i) <- zhere;
                calcpre_ (i+1) (if h.(i) < minWithSize.(zhere)
                               then let oldh = minWithSize.(zhere) in
                               (minWithSize.(zhere) <- h.(i) ;
                                m |> M.remove oldh |> M.add h.(i) zhere)
                               else m)
        )
   in calcpre_ 0 (M.singleton 0 0) ; zpre
;;
let zpre = calcpre () ;;

let calcpost () =
    let maxWithSize = Array.make (n+1) (-1) in
    let rec calcpost i m = if i >= 0
        then let score h = snd @@ M.min_binding @@ (fun (_,_,x3) -> x3) @@ M.split h m in (
            List.iter (fun (id, hnew) -> ans.(id) <- ans.(id) + score hnew) q.(i) ;
            let zhere = 1 + score h.(i) in
                calcpost (i-1) (if h.(i) > maxWithSize.(zhere)
                                    then let oldh = maxWithSize.(zhere) in
                                    (maxWithSize.(zhere) <- h.(i) ;
                                        m |> M.remove oldh |> M.add h.(i) zhere )
                                    else m)
        ) else snd @@ M.min_binding m
    in calcpost (n-1) (M.singleton hmax 0)
;;
let zmax = calcpost () ;;

let critical = Array.make zmax true ;;
let iused = Array.make n false;;
let maxWithSize = Array.make (zmax+1) 0 in (
    maxWithSize.(zmax) <- hmax;
    for i = n-1 downto 0 do
        let zhere = zpre.(i) in
        if h.(i) < maxWithSize.(zhere) then (
            iused.(i) <- true ;
            if maxWithSize.(zhere - 1) != 0 then critical.(zhere - 1) <- false ;
            maxWithSize.(zhere - 1) <- max maxWithSize.(zhere - 1) h.(i)
        )
    done
) ;;

Array.iteri (fun i qq -> List.iter (fun (id, hnew) -> ans.(id) <- max ans.(id) (if iused.(i) && critical.(zpre.(i) - 1) then zmax-1 else zmax) ) qq) q ;;
Array.iter (Printf.printf "%d\n") ans ;;

(*

9 9
3 4 3 4 3 4 3 4 3
1 3
2 3
3 3
4 3
5 3
6 3
7 3
8 3
9 3

*)


Vasya often uses public transport. The transport in the city is of two types: trolleys and buses. The city has n buses and m trolleys, the buses are numbered by integers from 1 to n, the trolleys are numbered by integers from 1 to m.Public transport is not free. There are 4 types of tickets:   A ticket for one ride on some bus or trolley. It costs c1 burles;  A ticket for an unlimited number of rides on some bus or on some trolley. It costs c2 burles;  A ticket for an unlimited number of rides on all buses or all trolleys. It costs c3 burles;  A ticket for an unlimited number of rides on all buses and trolleys. It costs c4 burles. Vasya knows for sure the number of rides he is going to make and the transport he is going to use. He asked you for help to find the minimum sum of burles he will have to spend on the tickets.

The first line contains four integers c1, c2, c3, c4 (1 ≤ c1, c2, c3, c4 ≤ 1000) — the costs of the tickets. The second line contains two integers n and m (1 ≤ n, m ≤ 1000) — the number of buses and trolleys Vasya is going to use. The third line contains n integers ai (0 ≤ ai ≤ 1000) — the number of times Vasya is going to use the bus number i. The fourth line contains m integers bi (0 ≤ bi ≤ 1000) — the number of times Vasya is going to use the trolley number i.

Print a single number — the minimum sum of burles Vasya will have to spend on the tickets.

NoteIn the first sample the profitable strategy is to buy two tickets of the first type (for the first bus), one ticket of the second type (for the second bus) and one ticket of the third type (for all trolleys). It totals to (2·1) + 3 + 7 = 12 burles.In the second sample the profitable strategy is to buy one ticket of the fourth type.In the third sample the profitable strategy is to buy two tickets of the third type: for all buses and for all trolleys.

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

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 solve k d =
  if d <> 0 then begin
    let s = String.create k in
    s.[0] <- char_of_int (d + int_of_char '0');
    String.fill s 1 (k - 1) '0';
    print_endline s
  end else if k = 1 then begin
    print_endline "0"
  end else begin
    print_endline "No solution";
  end
;;

let input () =
  let cs = Scanf.scanf "%d %d %d %d " (fun c1 c2 c3 c4 -> c1, c2, c3, c4) in
  let m, n = Scanf.scanf "%d %d " (fun m n -> m, n) in
  let rec iter i =
    if i = 0 then []
    else (Scanf.scanf "%d " ident) :: iter (i - 1) in
  let buses = iter m in
  let trolleys = iter n in
  (cs, m, n, buses, trolleys)
;;

let solve c1 c2 c3 c4 buses trolleys =
  let min_buses = List.map buses ~f:(fun i -> min (c1 * i) c2) in
  let min_trolleys = List.map trolleys ~f:(fun i -> min (c1 * i) c2) in
  let sum_buses = min (List.fold_left ~init:0 min_buses ~f:(+)) c3 in
  let sum_trolleys = min (List.fold_left ~init:0 min_trolleys ~f:(+)) c3 in
  min (sum_buses + sum_trolleys) c4
;;

let () =
  let ((c1, c2, c3, c4), _, _, buses, trolleys) = input () in
  let res = solve c1 c2 c3 c4 buses trolleys in
  Printf.printf "%d\n" res
;;


Flatland has recently introduced a new type of an eye check for the driver's licence. The check goes like that: there is a plane with mannequins standing on it. You should tell the value of the minimum angle with the vertex at the origin of coordinates and with all mannequins standing inside or on the boarder of this angle. As you spend lots of time "glued to the screen", your vision is impaired. So you have to write a program that will pass the check for you.

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of mannequins. Next n lines contain two space-separated integers each: xi, yi (|xi|, |yi| ≤ 1000) — the coordinates of the i-th mannequin. It is guaranteed that the origin of the coordinates has no mannequin. It is guaranteed that no two mannequins are located in the same point on the plane.

Print a single real number — the value of the sought angle in degrees. The answer will be considered valid if the relative or absolute error doesn't exceed 10 - 6.

NoteSolution for the first sample test is shown below:   Solution for the second sample test is shown below:   Solution for the third sample test is shown below:   Solution for the fourth sample test is shown below:

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

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 pi = 4.0 *. (atan2 1.0 1.0)

let () =
  let n = read_int() in
  let p = Array.init n (fun _ ->
			  let (x,y) = read_pair() in
			  let (x,y) = (float(x), float(y)) in
			    atan2 x y
		       ) in

    if n=1 then Printf.printf "0.0\n" else
      let () = Array.sort compare p in
      let a1 = maxf 0 (n-2) (fun i -> p.(i+1) -. p.(i)) in
      let a2 = (pi -. p.(n-1)) +. (p.(0) -. (-. pi)) in
      let answer = max a1 a2 in
	Printf.printf "%5.10f\n" (180.0 *. ((2.0*.pi -. answer) /. pi))

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

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 pi = 4.0 *. (atan2 1.0 1.0)

let () =
  let n = read_int() in
  let p = Array.init n (fun _ ->
			  let (x,y) = read_pair() in
			  let (x,y) = (float(x), float(y)) in
			    atan2 x y
		       ) in

    if n=1 then Printf.printf "360.0\n" else
      let () = Array.sort compare p in
      let a1 = maxf 0 (n-2) (fun i -> p.(i+1) -. p.(i)) in
      let a2 = (pi -. p.(n-1)) +. (p.(0) -. (-. pi)) in
      let answer = max a1 a2 in
	Printf.printf "%5.10f\n" (180.0 *. ((2.0*.pi -. answer) /. pi))