let main() =
  let s = Scanf.scanf " %s" (fun i -> i) in
  let n = String.length s in
  let k = Scanf.scanf " %d" (fun i -> i) in
  let a = Array.make_matrix n n 0 in
  for l = 2 to n do
    for i = 0 to n-l do
      let j = i + l - 1 in
      a.(i).(j) <- (if l == 2 then 0 else a.(i+1).(j-1)) + (if s.[i] == s.[j] then 0 else 1);
    done;
  done;
  let b = Array.make_matrix (k+1) (n+1) (2*n) in let p = Array.make_matrix (k+1) (n+1) (-1) in
  b.(0).(0) <- 0;
  for l = 1 to k do
    let br = b.(l-1) in let bn = b.(l) in
    for i = 0 to (n-1) do
      let x = br.(i) in let y = a.(i) in
      for j = (i+1) to n do
        let v = x + y.(j-1) in
        if bn.(j) > v then (bn.(j) <- v; p.(l).(j) <- i) else ();
      done;
    done;
  done;
  let d = Array.init k (fun i -> b.(i+1).(n), i+1) in
  let best_v, best_k = Array.fold_left (fun b x -> if (fst b) < (fst x) then b else x) (2*n, -1) d in
  let rec h i j =
    if i < j then (s.[j] <- s.[i]; h (i+1) (j-1)) else ()
  in
  let g i j =
    h i j;
    String.sub s i (j - i + 1)
  in
  let rec ans k j l =
    if k = 0 then l else (let i = p.(k).(j) in ans (k-1) i ((g i (j-1))::l))
  in
  Printf.printf "%d\n%s\n" best_v (String.concat "+" (ans best_k n []))
  ;;
main()

let getint () = Scanf.bscanf Scanf.Scanning.stdin " %d" (fun i->i)
let getstr () = Scanf.bscanf Scanf.Scanning.stdin " %s" (fun s-> s)
let getchar () = Scanf.bscanf Scanf.Scanning.stdin " %c" (fun i->i)
let inf = 1000000007

let s = getstr ()
let n = String.length s
let k = getint ()
let cost = Array.make_matrix n n 0
let dp = Array.make_matrix (n+1) (k+1) inf
let tb = Array.make_matrix (n+1) (k+1) 0

let calc_cost () =
  for i = 0 to n-1 do
    for j = i to n-1 do
      let i' = ref i and j' = ref j in
        while !i' <= !j' do
          if s.[!i'] <> s.[!j'] then cost.(i).(j) <- cost.(i).(j) + 1;
          incr i'; decr j'
        done
    done
  done

let minimize () =
  for j = 0 to k do
    dp.(0).(j) <- 0
  done;
  for i = 1 to n do
    for j = 1 to k do
      for m = 0 to i-1 do
        if dp.(i).(j) > dp.(m).(j-1) + cost.(m).(i-1)
        then
          begin
            dp.(i).(j) <- dp.(m).(j-1) + cost.(m).(i-1);
            tb.(i).(j) <- m
          end
      done
    done
  done

let trace_back () =
  let len = ref n and k' = ref k and l = ref [] in
  while !len <> 0 do
    l := (!len - tb.(!len).(!k')) :: !l;
    len := tb.(!len).(!k');
    decr k'
  done;
  let last = ref 0 in
  List.iter
  (
      fun len ->
        let i = ref !last and j = ref (!last + len - 1) in
        while !i <= !j do
          if s.[!i] <> s.[!j] then s.[!i] <- s.[!j];
          incr i; decr j
        done;
        for i = !last to !last+ len - 1 do
          print_char s.[i];
        done;
        last := !last + len;
        if !last <> n then print_char '+'
        else print_char '\n';
    )
    !l

let _ =
  calc_cost ();
  minimize ();
  print_int dp.(n).(k); print_newline ();
  trace_back ()

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

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

let str = read_string ();;
let k = read_int ();;
let n = String.length str;;

let dp = Array.create_matrix 505 505 10000000;;
let cnt = Array.create_matrix 505 505 0;;
let mark = Array.create_matrix 505 505 0;;

let _ = for i = 0 to (n-1) do
           for j = (i+1) to (n-1) do
              for t1 = i to ((j+i)/2) do
                 if str.[t1]!=str.[j-t1+i] then cnt.(i).(j) <- cnt.(i).(j) + 1
              done
            done
         done;;

let _ = for i = 0 to (n-1) do
              dp.(i).(1) <- cnt.(0).(i);
              mark.(i).(1) <- -1
        done;;

let _ = for i = 0 to (n-1) do
            for j = 2 to (min (i+1) k) do
                for t = 0 to (i-1) do
                    if dp.(t).(j-1) + cnt.(t+1).(i) < dp.(i).(j) then
                     begin
                        dp.(i).(j) <- dp.(t).(j-1) + cnt.(t+1).(i);
                        mark.(i).(j) <- t
                     end
                done
            done
         done;;

let ans = ref 10000000;;
let len = ref (-1);;
let p = ref 0;;

let _ = for i = 1 to k do
            if dp.(n-1).(i) < !ans then
             begin
               ans := dp.(n-1).(i);
               len := i;
               p := mark.(n-1).(i)
             end
        done;;

let rec solve2 str i j =
   if i>=j then str
   else if str.[i]!=str.[j] then begin str.[i] <- str.[j]; solve2 str (i+1) (j-1) end
   else solve2 str (i+1) (j-1);;

let rec solve str len s t =
     if len = 1 then solve2 (String.sub str s (t-s+1)) 0 (t-s)
     else solve (String.sub str 0 s) (len-1) (mark.(s-1).(len-1)+1) (s-1) ^ "+" ^ solve2 (String.sub str s (t-s+1)) 0 (t-s);;

if n = 1 then Printf.printf "0\n%s\n" str
else Printf.printf "%d\n%s\n" (!ans) (solve str (!len) (!p+1) (n-1));;

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

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

let str = read_string ();;
let k = read_int ();;
let n = String.length str;;

let dp = Array.create_matrix 505 505 10000000;;
let cnt = Array.create_matrix 505 505 0;;
let mark = Array.create_matrix 505 505 0;;

let _ = for i = 0 to (n-1) do
           for j = (i+1) to (n-1) do
              for t1 = i to ((j+i)/2) do
                 if str.[t1]!=str.[j-t1+i] then cnt.(i).(j) <- cnt.(i).(j) + 1
              done
            done
         done;;

let _ = for i = 0 to (n-1) do
              dp.(i).(1) <- cnt.(0).(i);
              mark.(i).(1) <- -1
        done;;

let _ = for i = 0 to (n-1) do
            for j = 2 to (min (i+1) k) do
                for t = 0 to (i-1) do
                    if dp.(t).(j-1) + cnt.(t+1).(i) < dp.(i).(j) then
                     begin
                        dp.(i).(j) <- dp.(t).(j-1) + cnt.(t+1).(i);
                        mark.(i).(j) <- t
                     end
                done
            done
         done;;

let ans = ref 10000000;;
let len = ref (-1);;
let p = ref 0;;

let _ = for i = 1 to k do
            if dp.(n-1).(i) < !ans then
             begin
               ans := dp.(n-1).(i);
               len := i;
               p := mark.(n-1).(i)
             end
        done;;

let rec solve2 str i j =
   if i>=j then str
   else if str.[i]!=str.[j] then begin str.[i] <- str.[j]; solve2 str (i+1) (j-1) end
   else solve2 str (i+1) (j-1);;

let rec solve str len s t str_ans =
     if len = 0 then str_ans
     else if len = 1 then solve "" 0 0 0 (solve2 (String.sub str s (t-s+1)) 0 (t-s) ^ str_ans )
     else solve (String.sub str 0 s) (len-1) (mark.(s-1).(len-1)+1) (s-1)  ("+" ^ solve2 (String.sub str s (t-s+1)) 0 (t-s) ^  str_ans) ;;

if n = 1 then Printf.printf "0\n%s\n" str
else let str_ans = (solve str (!len) (!p+1) (n-1) "") in Printf.printf "%d\n%s\n" (!ans) str_ans;;

let s = input_line stdin;;
let n = String.length s;;
let k = read_int ();;
let f = Array.make_matrix n n 0;;
for i = n - 1 downto 0 do
 for j = i to n - 1 do
  if i == j then begin
   f.(i).(j) <- 0
  end else if i + 1 == j then begin
   f.(i).(j) <- if s.[i] != s.[j] then 1 else 0;
  end else begin
   f.(i).(j) <- f.(i + 1).(j - 1) + if s.[i] != s.[j] then 1 else 0;
  end;
 done
done;;
let g = Array.make_matrix (n + 1) (n + 1) 12345;;
let p = Array.make_matrix (n + 1) (n + 1) 12345;;
g.(0).(0) <- 0;;
for i = 0 to n - 1 do
 for j = 0 to i do
  for l = i + 1 to n do
   let cur = g.(i).(j) + f.(i).(l - 1) in
   if g.(l).(j + 1) > cur then begin
    g.(l).(j + 1) <- cur;
    p.(l).(j + 1) <- i;
   end
  done;
 done
done;;
let h = Array.make n "";;
let u = ref 0;;
let v = ref n;;
for j = 0 to k do
 if g.(n).(!u) > g.(n).(j) then begin u := j end
done;;
Printf.printf "%d\n" g.(n).(!u);;
let w = ref 0;;
for j = 0 to !u - 1 do
 let c = String.sub s p.(!v).(!u - j) (!v - p.(!v).(!u - j)) in
 let t = String.length c in
 let x = ref 0 in
 let y = ref (t - 1) in begin
  while !x < !y do
   c.[!y] <- c.[!x];
   x := !x + 1;
   y := !y - 1;
  done;
  h.(j) <- c;
  v := p.(!v).(!u - j);
 end;
done;;
for j = !u - 1 downto 0 do
 Printf.printf "%s%s" h.(j) (if j == 0 then "\n" else "+");
done;;

let main() =
  let s = Scanf.scanf " %s" (fun i -> i) in
  let n = String.length s in
  let k = Scanf.scanf " %d" (fun i -> i) in
  let a = Array.make_matrix n n 0 in
  let rec d1 l =
    let rec d2 i =
      let j = i + l - 1 in
      if j < n then (a.(i).(j) <- (if l == 2 then 0 else a.(i+1).(j-1)) + (if s.[i] == s.[j] then 0 else 1); d2 (i+1)) else ()
    in
    d2 0;
    if l < n then d1 (l+1) else ()
  in
  d1 2;
  let b = Array.make_matrix (k+1) (n+1) (2*n) in
  let p = Array.make_matrix (k+1) (n+1) (-1) in
  b.(0).(0) <- 0;
  let rec f1 l =
    let br = b.(l-1) in let bn = b.(l) in
    let rec f2 i =
      let x = br.(i) in let y = a.(i) in
      let rec f3 j =
        let v = x + y.(j-1) in
        if bn.(j) > v then (bn.(j) <- v; p.(l).(j) <- i) else ();
        if j < n then f3 (j+1) else ()
      in
      f3 (i+1);
      if i < (n-1) then f2 (i+1) else ()
    in
    f2 0;
    if l < k then f1 (l+1) else ();
  in
  f1 1;
  let d = Array.init k (fun i -> b.(i+1).(n), i+1) in
  let best_v, best_k = Array.fold_left (fun b x -> if (fst b) < (fst x) then b else x) (2*n, -1) d in
  let rec h i j =
    if i < j then (s.[j] <- s.[i]; h (i+1) (j-1)) else ()
  in
  let g i j =
    h i j;
    String.sub s i (j - i + 1)
  in
  let rec ans k j l =
    if k = 0 then l else (let i = p.(k).(j) in ans (k-1) i ((g i (j-1))::l))
  in
  Printf.printf "%d\n%s\n" best_v (String.concat "+" (ans best_k n []))
  ;;
main()

let _ =
  let sb = Scanf.Scanning.stdib in
  let s = Scanf.bscanf sb "%s " (fun s -> s) in
  let k = Scanf.bscanf sb "%d " (fun s -> s) in
  let n = String.length s in
  let c = Array.make_matrix n n 0 in
  let _ =
    for i = 0 to n - 1 do
      for j = i to n - 1 do
	let d = ref 0 in
	  for k = 0 to (j - i + 1) / 2 - 1 do
	    if s.[i + k] <> s.[j - k]
	    then incr d;
	  done;
	  c.(i).(j) <- !d
      done
    done
  in
  (*let _ =
    for i = 0 to n - 1 do
      for j = i to n - 1 do
	Printf.printf "%d " c.(i).(j)
      done;
      Printf.printf "\n"
    done
  in*)
  (*let min (x : int) y = if x < y then x else y in*)
  let a = Array.make_matrix (k + 1) (n + 1) 10000 in
  let d = Array.make_matrix (k + 1) (n + 1) 10000 in
    a.(0).(0) <- 0;
    for i = 1 to k do
      a.(i).(0) <- 0;
      for j = 1 to n do
	for r = 0 to j - 1 do
	  if a.(i).(j) > a.(i - 1).(r) + c.(r).(j - 1) then (
	    a.(i).(j) <- a.(i - 1).(r) + c.(r).(j - 1);
	    d.(i).(j) <- r;
	  )
	done
      done
    done;
    (*let _ =
      for i = 0 to k do
	for j = 0 to n do
	  Printf.printf "%d(%d) " a.(i).(j) d.(i).(j)
	done;
	Printf.printf "\n"
      done
    in*)
    let palindromize s =
      let n = String.length s in
	for i = 0 to n / 2 - 1 do
	  if s.[i] <> s.[n - i - 1]
	  then s.[i] <- s.[n - i - 1]
	done
    in
    let res = a.(k).(n) in
    let ss = ref [] in
    let _ =
      let i = ref n in
	for j = k downto 1 do
	  if !i > 0 then (
	    let r = d.(j).(!i) in
	      ss := String.sub s r (!i - r) :: !ss;
	      i := r;
	  )
	done
    in
      assert (!ss <> []);
      Printf.printf "%d\n" res;
      let f = ref true in
	List.iter
	  (fun s ->
	     if not !f
	     then Printf.printf "+";
	     f := false;
	     assert (s <> "");
	     palindromize s;
	     Printf.printf "%s" s
	  ) !ss;
	Printf.printf "\n"

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

let inf = 1_000_000
let rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)

let argmin i j f =
  fold i j (
    fun k (index,v) -> let m = (f k) in if m<v then (k,m) else (index,v)
  ) (i-1, inf)

let s = read_string()
let k = read_int()
let n = String.length s

let dist = Array.make_matrix n n 0

let delta i j = if s.[i] = s.[j] then 0 else 1

let () =
  for l = 1 to n do
    for i=0 to n-l do
      let j = i+l-1 in
	dist.(i).(j) <-
	  if i+1 <= j-1 then dist.(i+1).(j-1) + (delta i j)
	  else delta i j
    done
  done

let c = Array.make_matrix n (k+1) (-1)
let bj = Array.make_matrix n (k+1) 0

let rec cost i p =
  if i<0 then 0 else
    if c.(i).(p) >= 0 then c.(i).(p) else
      let cc =
	if p=1 then dist.(0).(i) else
	  let (j,opt) = argmin 0 i (fun j -> (cost (j-1) (p-1)) + dist.(j).(i)) in
	    bj.(i).(p) <- j;
	    opt
      in
	c.(i).(p) <- cc;
	cc

let make_palindrome i j = (* return a palindrome of s.[i...j] *)
  let l = j-i+1 in
  let r = String.sub s i l in
    for k=0 to l/2-1 do
      r.[k] <- r.[l-1-k]
    done;
    r

let rec build_soln i p ac =
  if i<0 || p<1 then ac else
    let j = bj.(i).(p) in
      build_soln (j-1) (p-1) ((make_palindrome j i)::ac)

let () =
  Printf.printf "%d\n" (cost (n-1) k);
  Printf.printf "%s\n" (String.concat "+" (build_soln (n-1) k []));

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

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

let str = read_string ();;
let k = read_int ();;
let n = String.length str;;

let dp = Array.create_matrix 505 505 10000000;;
let cnt = Array.create_matrix 505 505 0;;
let mark = Array.create_matrix 505 505 0;;

let _ = for i = 0 to (n-1) do
           for j = (i+1) to (n-1) do
              for t1 = i to ((j+i)/2) do
                 if str.[t1]!=str.[j-t1+i] then cnt.(i).(j) <- cnt.(i).(j) + 1
                 else ()
              done
            done
         done;;

let _ = for i = 0 to (n-1) do
            begin
              dp.(i).(1) <- cnt.(0).(i);
              mark.(i).(1) <- -1
            end
        done;;

let _ = for i = 0 to (n-1) do
            for j = 2 to (min (i+1) k) do
                for t = 0 to (i-1) do
                    if dp.(t).(j-1) + cnt.(t+1).(i) < dp.(i).(j) then
                        dp.(i).(j) <- dp.(t).(j-1) + cnt.(t+1).(i);
                        mark.(i).(j) <- t
                done
            done
         done;;

let ans = ref 10000000;;
let len = ref (-1);;
let p = ref 0;;

let _ = for i = 1 to k do
            if dp.(n-1).(i) < !ans then
               ans := dp.(n-1).(i);
               len := i;
               p := mark.(n-1).(i)
        done;;

let rec solve2 str i j =
   if i>=j then str
   else if str.[i]!=str.[j] then begin str.[i] <- str.[j]; solve2 str (i+1) (j-1) end
   else solve2 str (i+1) (j-1);;

let rec solve str len s t =
     if len = 1 then solve2 (String.sub str s (t-s+1)) s t
     else solve (String.sub str 0 s) (len-1) (mark.(s-1).(len-1)+1) (s-1) ^ "+" ^ solve2 (String.sub str s (t-s+1)) s t;;

if n = 1 then Printf.printf "0\n%s\n" str
else Printf.printf "%d\n%s\n" (!ans) (solve str (!len) (!p+1) (n-1));;

(*************** Ocaml stdio functions **********************)
let stdin_stream = Stream.of_channel stdin;;
let stdout_buffer = Buffer.create 65536;;
let rec gi() =
  match Stream.next stdin_stream with
    '-' ->  - (ri 0)
  | '+' ->  ri 0
  | '0'..'9' as c -> ri ((int_of_char c) - 48)
  | _ -> gi ()
and ri x =
  match Stream.next stdin_stream with
    '0'..'9' as c -> ri (((int_of_char c) - 48) + (x * 10))
  | _ -> x
;;
let flushout () = Buffer.output_buffer stdout stdout_buffer; Buffer.reset stdout_buffer;;
let putchar c =
  if (Buffer.length stdout_buffer) >= 65536 then flushout() else ();
  Buffer.add_char stdout_buffer c;;
let rec ppi i = if i < 10 then putchar (char_of_int (48 + i)) else (ppi (i / 10); putchar (char_of_int (48 + (i mod 10)))) ;;
let pi i = if i >= 0 then ppi i else (putchar ('-'); ppi (-i));;
let pa a = let n = Array.length a in Array.iteri (fun i j -> pi j; putchar (if i == (n-1) then '\n' else ' ')) a;;
(*************** Ocaml solution ******************************)
open Array
let main() =
  let s = Scanf.scanf "%s" (fun i -> i) in
  let mk = Scanf.scanf " %d" (fun i -> i) in
  let l = String.length s in
  let a = make_matrix l l (-1, 0) in
  let b = make_matrix (mk+1) (l+1) 10000 in
  let c = make_matrix (mk+1) (l+1) (-1) in
  let rec f i j =
    if (j-i) <= 1 then (0,0)
    else (if (fst a.(i).(j)) >= 0 then a.(i).(j)
          else
            (
            let (u,_) = f (i+1) (j-1) in
            let r = if s.[i] == s.[j] then (u, 0) else (u + 1, 1) in
            a.(i).(j) <- r;
            r
            )
         )
    in
  let rec g i j =
    if (j-i) <= 1 then ()
    else ((match snd (f i j) with
            1 -> s.[i] <- s.[j]
          | _ -> ()
           ); g (i+1) (j-1))
    in
  b.(mk).(0) <- 0;
  for k = (mk - 1) downto 0 do
    for i = 0 to (l - 1) do
      let w = b.(k+1).(i) in
      for j = (i+1) to l do
        let v = w + (fst (f i (j-1))) in
        if v < b.(k).(j) then ( b.(k).(j) <- v; c.(k).(j) <- i )
        else ()
        done
      done
    done;
  let rec h j k a =
    if k == mk then a
    else (
      let i = c.(k).(j) in
      g i (j-1);
      let ss = String.sub s i (j - i) in
      h i (k+1) (ss::a)
      )
    in
  let y = h l 0 [] in
  Printf.printf "%d\n%s\n" (b.(0).(l)) (String.concat "+" y)
  ;;
main();;
flushout ()

let _ =
  let sb = Scanf.Scanning.stdib in
  let s = Scanf.bscanf sb "%s " (fun s -> s) in
  let k = Scanf.bscanf sb "%d " (fun s -> s) in
  let n = String.length s in
  let c = Array.make_matrix n n 0 in
  let _ =
    for i = 0 to n - 1 do
      for j = i to n - 1 do
	let d = ref 0 in
	  for k = 0 to (j - i + 1) / 2 - 1 do
	    if s.[i + k] <> s.[j - k]
	    then incr d;
	  done;
	  c.(i).(j) <- !d
      done
    done
  in
  (*let _ =
    for i = 0 to n - 1 do
      for j = i to n - 1 do
	Printf.printf "%d " c.(i).(j)
      done;
      Printf.printf "\n"
    done
  in*)
  (*let min (x : int) y = if x < y then x else y in*)
  let a = Array.make_matrix (k + 1) (n + 1) 10000 in
  let d = Array.make_matrix (k + 1) (n + 1) 10000 in
    a.(0).(0) <- 0;
    for i = 1 to k do
      a.(i).(0) <- 0;
      for j = 0 to n do
	for r = 0 to j - 1 do
	  if a.(i).(j) > a.(i - 1).(r) + c.(r).(j - 1) then (
	    a.(i).(j) <- a.(i - 1).(r) + c.(r).(j - 1);
	    d.(i).(j) <- r;
	  )
	done
      done
    done;
    (*let _ =
      for i = 0 to k do
	for j = 0 to n do
	  Printf.printf "%d " a.(i).(j)
	done;
	Printf.printf "\n"
      done
    in*)
    let palindromize s =
      let n = String.length s in
	for i = 0 to n / 2 do
	  if s.[i] <> s.[n - i - 1]
	  then s.[i] <- s.[n - i - 1]
	done
    in
    let res = a.(k).(n) in
    let ss = ref [] in
    let _ =
      let i = ref n in
	for j = k downto 1 do
	  if !i > 0 then (
	    let r = d.(k).(!i) in
	      ss := String.sub s r (!i - r) :: !ss;
	      i := r;
	  )
	done
    in
      Printf.printf "%d\n" res;
      let f = ref true in
	List.iter
	  (fun s ->
	     if not !f
	     then Printf.printf "+";
	     f := false;
	     palindromize s;
	     Printf.printf "%s" s
	  ) !ss;
	Printf.printf "\n"

let _ =
  let sb = Scanf.Scanning.stdib in
  let s = Scanf.bscanf sb "%s " (fun s -> s) in
  let k = Scanf.bscanf sb "%d " (fun s -> s) in
  let n = String.length s in
  let c = Array.make_matrix n n 0 in
  let _ =
    for i = 0 to n - 1 do
      for j = i to n - 1 do
	let d = ref 0 in
	  for k = 0 to (j - i + 1) / 2 - 1 do
	    if s.[i + k] <> s.[j - k]
	    then incr d;
	  done;
	  c.(i).(j) <- !d
      done
    done
  in
  (*let _ =
    for i = 0 to n - 1 do
      for j = i to n - 1 do
	Printf.printf "%d " c.(i).(j)
      done;
      Printf.printf "\n"
    done
  in*)
  (*let min (x : int) y = if x < y then x else y in*)
  let a = Array.make_matrix (k + 1) (n + 1) 10000 in
  let d = Array.make_matrix (k + 1) (n + 1) 10000 in
    a.(0).(0) <- 0;
    for i = 1 to k do
      a.(i).(0) <- 0;
      for j = 1 to n do
	for r = 0 to j - 1 do
	  if a.(i).(j) > a.(i - 1).(r) + c.(r).(j - 1) then (
	    a.(i).(j) <- a.(i - 1).(r) + c.(r).(j - 1);
	    d.(i).(j) <- r;
	  )
	done
      done
    done;
    (*let _ =
      for i = 0 to k do
	for j = 0 to n do
	  Printf.printf "%d " a.(i).(j)
	done;
	Printf.printf "\n"
      done
    in*)
    let palindromize s =
      let n = String.length s in
	for i = 0 to n / 2 - 1 do
	  if s.[i] <> s.[n - i - 1]
	  then s.[i] <- s.[n - i - 1]
	done
    in
    let res = a.(k).(n) in
    let ss = ref [] in
    let _ =
      let i = ref n in
	for j = k downto 1 do
	  if !i > 0 then (
	    let r = d.(k).(!i) in
	      ss := String.sub s r (!i - r) :: !ss;
	      i := r;
	  )
	done
    in
      assert (!ss <> []);
      Printf.printf "%d\n" res;
      let f = ref true in
	List.iter
	  (fun s ->
	     if not !f
	     then Printf.printf "+";
	     f := false;
	     assert (s <> "");
	     palindromize s;
	     Printf.printf "%s" s
	  ) !ss;
	Printf.printf "\n"

let _ =
  let sb = Scanf.Scanning.stdib in
  let s = Scanf.bscanf sb "%s " (fun s -> s) in
  let k = Scanf.bscanf sb "%d " (fun s -> s) in
  let n = String.length s in
  let c = Array.make_matrix n n 0 in
  let _ =
    for i = 0 to n - 1 do
      for j = i to n - 1 do
	let d = ref 0 in
	  for k = 0 to (j - i + 1) / 2 - 1 do
	    if s.[i + k] <> s.[j - k]
	    then incr d;
	  done;
	  c.(i).(j) <- !d
      done
    done
  in
  (*let _ =
    for i = 0 to n - 1 do
      for j = i to n - 1 do
	Printf.printf "%d " c.(i).(j)
      done;
      Printf.printf "\n"
    done
  in*)
  (*let min (x : int) y = if x < y then x else y in*)
  let a = Array.make_matrix (k + 1) (n + 1) 10000 in
  let d = Array.make_matrix (k + 1) (n + 1) 10000 in
    a.(0).(0) <- 0;
    for i = 1 to k do
      a.(i).(0) <- 0;
      for j = 1 to n do
	for r = 0 to j - 1 do
	  if a.(i).(j) > a.(i - 1).(r) + c.(r).(j - 1) then (
	    a.(i).(j) <- a.(i - 1).(r) + c.(r).(j - 1);
	    d.(i).(j) <- r;
	  )
	done
      done
    done;
    (*let _ =
      for i = 0 to k do
	for j = 0 to n do
	  Printf.printf "%d " a.(i).(j)
	done;
	Printf.printf "\n"
      done
    in*)
    let palindromize s =
      let n = String.length s in
	for i = 0 to n / 2 do
	  if s.[i] <> s.[n - i - 1]
	  then s.[i] <- s.[n - i - 1]
	done
    in
    let res = a.(k).(n) in
    let ss = ref [] in
    let _ =
      let i = ref n in
	for j = k downto 1 do
	  if !i > 0 then (
	    let r = d.(k).(!i) in
	      ss := String.sub s r (!i - r) :: !ss;
	      i := r;
	  )
	done
    in
      assert (!ss <> []);
      Printf.printf "%d\n" res;
      let f = ref true in
	List.iter
	  (fun s ->
	     if not !f
	     then Printf.printf "+";
	     f := false;
	     assert (s <> "");
	     palindromize s;
	     Printf.printf "%s" s
	  ) !ss;
	Printf.printf "\n"


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

let () =
  let t = gi 0 in
  rep 1L t (fun _ ->
    let l,r = g2 0 in
    (* let f,u,v = ref true,ref l,ref r in
    while !f do
      while !f do
        if !v mod !u = 0L then (
          f := false;
          printf "%Ld %Ld\n" !u !v
        );
        v -= 1L
      done;
      u += 1L;
    done; *)
    (* let f,u = ref true,ref l in
    while !f do
    done *)
    (* if l*2L > r then (

    ) *)
    printf "%Ld %Ld\n" l (l*2L);
  )

Scanf.(Array.(
  let t = scanf " %d" @@ fun v -> v in
  init t (fun _ ->
    let l = scanf " %d %d" @@ fun p _ -> p in
    Printf.printf "%d %d\n" l (l*2))))


let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let k = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = Array.make_matrix n n 0 in
  let c = Array.make n 0 in
  let tot = ref true in
  let m = ref 0 in
    for i = 0 to n - 1 do
      for j = 0 to n - 1 do
	if i <> j && c.(i) < k && a.(i).(j) = 0 then (
	  c.(i) <- c.(i) + 1;
	  incr m;
	  a.(i).(j) <- 1;
	  a.(j).(i) <- -1;
	)
      done
    done;
    for i = 0 to n - 1 do
      if c.(i) < k
      then tot := false;
    done;
    if not !tot
    then Printf.printf "-1\n"
    else (
      Printf.printf "%d\n" (n * k);
      for i = 0 to n - 1 do
	for j = 0 to n - 1 do
	  if a.(i).(j) = 1
	  then Printf.printf "%d %d\n" (i + 1) (j + 1);
	done
      done;
    )

let read_int()=Scanf.scanf " %d" (fun x->x);;
let n=read_int() and k=read_int();;
let m=n*(n-1)/2;;
let nb=k*n;;
let mat=Array.make_matrix (n+1) (n+1) 0;;
let b=ref true

let rec win r i j=
if r=0 then ()
else if i=j then win r i (j+1)
else if j>n then b:=false
else
   begin
   if mat.(i).(j)=0 then (mat.(i).(j)<-1;mat.(j).(i)<-(-1);win (r-1) i (j+1))
   else win r i (j+1)
   end;;

if nb>m then b:=false;;

for i=1 to n do
   win k i 1
done;;

if !b=false then print_int(-1) else
begin
print_int nb;
print_newline();
for i=1 to n do
   for j=1 to n do
      if mat.(i).(j)=1 then Printf.printf "%d %d\n" i j
   done
done
end;;


open Printf
open Scanf

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

let read_int () = bscanf Scanning.stdib " %d " (fun x -> x)
let () =
  let n = read_int() in
  let x = Array.init n (fun _ -> read_int()) in
  Array.sort compare x;
  let l = (n-2)/2 in
  let v = n-2-l in

  printf "%d\n" (minf 0 v (fun i -> x.(i+n-v-1) - x.(i)))

open Str

let n = int_of_string @@ read_line () ;;
let xs = List.sort compare
    ( List.map int_of_string ( (split @@ regexp " ") (read_line()) ) );;

let maxInIntv len =
    let rec miii l r c = match r with
        | [] -> 0
        | rx::rt -> if rx - List.hd l <= len
                        then max c ( miii l rt (c+1) )
                        else miii (List.tl l) r (c-1)
    in miii xs xs 1
in
let rec optlen lmin lmax =
    if lmin = lmax then lmin
    else
    let mid = lmin/2 + lmax/2 in
    if (maxInIntv mid) > n/2
        then optlen lmin mid
        else optlen (mid+1) lmax
in
print_int @@ optlen 1 1_000_000_000

open Str

let n = int_of_string @@ read_line () ;;
let xs = List.map int_of_string ( (split @@ regexp " ") (read_line()) ) ;;

print_int (List.nth xs (n-1) );;

(* let maxInIntv len =
    let rec miii (l as lx::lt) r c = match r with
        | [] -> 0
        | rx::rt -> if rx - lx <= len
                        then max c ( miii l rt (c+1) )
                        else miii lt r (c-1)
    in miii xs xs 1
in
let rec minlen lmin lmax =
    if lmin = lmax then lmin
    else
    let mid = lmin/2 + lmax/2 *)


let t = read_int() in

for i = 1 to t do
    let n=read_int() in
    let s=read_line() in
    let co = ref 0 in
    for j = 0 to (n-1) do
        if s.[j] = 'Q' then
            co := !co + 1
        else
            co := max (!co - 1) 0
    done;
    if !co > 0 then
        print_string("No\n")
    else
        print_string("Yes\n");
done

let t = read_int() in

for i = 1 to t do
    let n=read_int() in
    let s=read_line() in
    let co = ref 0 in
    for j = 0 to (n-1) do
        if s.[j] = 'Q' then
            co := !co + 1
        else
            co := !co - 1
    done;
    if !co > 0 then
        print_string("No\n")
    else
        print_string("Yes\n");
done


let rec str_to_list (str : string) (index : int) =
  if index = String.length str then
    []
  else
    (String.get str index) :: str_to_list str (index + 1)
;;

let rec main (t : int) =
  if t = 0 then
    ()
  else
    (let str = read_line () in
     let str_list = str_to_list str 0 in
     let num_ones = List.fold_left (fun acc x -> if x = '1' then acc + 1 else acc) 0 str_list in
     let num_zeros = (String.length str) - num_ones in
     if (min num_ones num_zeros) mod 2 = 0 then
       print_endline "NET"
     else
       print_endline "DA"
     ;
     main (t-1)
    );;

let t = read_int () in
main t

(* Codeforces 1373 B. 01 Game 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 reversed list *)
let rec readlist n acc = match n with
	| 0 -> acc
	| _ -> readlist (n -1) (gr() :: acc);;
let printlisti li = List.iter (fun i -> (print_int i; print_string " ")) li;;
let printlists ls = List.iter (fun s -> (print_string s; print_string " ")) ls;;

let rec countz cnt idx s =
	if idx == (String.length s) then cnt
	else
		let ncnt = if s.[idx]=='0' then (cnt + 1) else cnt in
		countz ncnt (idx + 1) s;;

let game s  =
    let nz = countz 0 0 s in
		let no = (String.length s) - nz in
		let minzo = if nz < no then nz else no in
		(* let _ = Printf.printf "minzo = %d\n" minzo in *)
		let alice_win = (minzo mod 2) == 1 in
		alice_win;;

let do_one () =
    let s = rdln() in
    let ans = game s in
		let sans = if ans then "DA" else "NET" in
    Printf.printf "%s\n" sans;;

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

let main() =
	let st = rdln () in
	let t = int_of_string st in
	do_all t;;

main();;


let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let cnt = ref 0 in
    for i = 1 to n do
      let k = Scanf.bscanf sb "%d " (fun s -> s) in
	if k = 0
	then incr cnt
    done;
    if (n > 1 && !cnt = 1) || (n = 1 && !cnt = 0)
    then Printf.printf "YES\n"
    else Printf.printf "NO\n"

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

;;

let rec sum nums acc = match nums with
    | [] ->  acc
    | hd :: tl -> sum tl (acc + hd)

;;

let get_ans () =

    let (n, nums) = read_nums () in
    let x = sum nums 0 in
    if (n = 1 && x = 1) then
        true
    else if (n > 1 && (n-1) = x) then
        true
    else
        false
;;

let r = get_ans () in
if r then
    print_string "YES\n"
else
    print_string "NO\n"

let () = Scanf.scanf "%d\n" (fun n ->
    let a = Array.init n (fun _ -> Scanf.scanf "%d%_c" (fun x -> x)) in
    let s = Array.fold_left (+) 0 a in
    print_endline (if (n = 1 && s = 1) || (n > 1 && s = n - 1) then "YES" else "NO"))

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

;;

let rec sum nums acc = match nums with
    | [] ->  acc
    | hd :: tl -> sum tl (acc + hd)

let get_ans () =

    let (n, nums) = read_nums () in
    let x = sum nums 0 in
    (n = 1 && x = 1) || ((n-1) = x)

;;

let r = get_ans () in
if r then
    print_string "YES\n"
else
    print_string "NO\n"


let _ =
  let mm = 1000000000 in
  let mmm = 1000000000l in
  let mmmm = 1000000000L in
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let m = Scanf.bscanf sb "%d " (fun s -> s) in
  let add x y =
    let r =
      Int32.to_int
	(Int32.rem
	   (Int32.add
	      (Int32.of_int x)
	      (Int32.of_int y))
	   mmm)
    in
      if r < 0
      then r + mm
      else r
  in
  let mul x y =
    let r =
      Int64.to_int
	(Int64.rem
	   (Int64.mul
	      (Int64.of_int x)
	      (Int64.of_int y))
	   mmmm)
    in
      if r < 0
      then r + mm
      else r
  in
  let o = 131072 * 2 in
  (*let o = 16 in*)
  let fib = Array.make (o + 1) 0 in
  let _ =
    fib.(1) <- 1;
    for i = 2 to o do
      fib.(i) <- add fib.(i - 1) fib.(i - 2)
    done
  in
  let d = Array.make (o + 1) 0 in
  let shift ofs v v' =
    let res = add (mul fib.(ofs + 1) v) (mul fib.(ofs) v') in
      (*Printf.printf "shift %d %d %d  %d -> %d\n" ofs v v' fib.(ofs + 1) res;*)
      res
  in
  let a = Array.make (2 * o) 0 in
  let a' = Array.make (2 * o) 0 in
  let rec update i x l r k =
    if l = r then (
      a.(k) <- x;
      a'.(k) <- 0;
    ) else (
      let m = (l + r) / 2 in
	if i <= m
	then update i x l m (2 * k + 1)
	else update i x (m + 1) r (2 * k + 2);
	let a1 = a.(2 * k + 1) in
	let a2 = a.(2 * k + 2) in
	let a1' = a'.(2 * k + 1) in
	let a2' = a'.(2 * k + 2) in
	  a.(k) <- add a1 (shift (m - l + 1) a2 a2');
	  a'.(k) <- add a1' (shift (m - l + 0) a2 a2');
    )
  in
  let rec rmq x y l r k =
    if x <= l && r <= y
    then (
      shift (l - x) a.(k) a'.(k)
    ) else (
      let m = (l + r) / 2 in
	if m < x
	then rmq x y (m + 1) r (2 * k + 2)
	else if m >= y
	then rmq x y l m (2 * k + 1)
	else
	  let a1 = rmq x y l m (2 * k + 1)
	  and a2 = rmq x y (m + 1) r (2 * k + 2) in
	    add a1 a2
    )
  in
  let () =
    for i = 1 to n do
      d.(i) <- Scanf.bscanf sb "%d " (fun s -> s);
      update i d.(i) 1 o 0
    done;
  in
    for k = 1 to m do
(*for j = 0 to Array.length a - 1 do
  Printf.printf "%d " a.(j);
done;
Printf.printf "\n";*)
      let op = Scanf.bscanf sb "%d " (fun s -> s) in
	match op with
	  | 1 ->
	      let i = Scanf.bscanf sb "%d " (fun s -> s) in
	      let v = Scanf.bscanf sb "%d " (fun s -> s) in
		d.(i) <- v;
		update i v 1 o 0;
	  | 2 ->
	      let l = Scanf.bscanf sb "%d " (fun s -> s) in
	      let r = Scanf.bscanf sb "%d " (fun s -> s) in
	      let res = rmq l r 1 o 0 in
		Printf.printf "%d\n" res;
	  | _ -> assert false
    done

let _ =
  let mm = 1000000000 in
  let mmm = 1000000000l in
  let mmmm = 1000000000L in
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let m = Scanf.bscanf sb "%d " (fun s -> s) in
  let add x y =
    let r =
      Int32.to_int
	(Int32.rem
	   (Int32.add
	      (Int32.of_int x)
	      (Int32.of_int y))
	   mmm)
    in
      if r < 0
      then r + mm
      else r
  in
  let mul x y =
    let r =
      Int64.to_int
	(Int64.rem
	   (Int64.mul
	      (Int64.of_int x)
	      (Int64.of_int y))
	   mmmm)
    in
      if r < 0
      then r + mm
      else r
  in
  let o = 131072 * 2 in
  (*let o = 16 in*)
  let fib = Array.make (o + 1) 0 in
  let _ =
    fib.(1) <- 1;
    for i = 2 to o do
      fib.(i) <- add fib.(i - 1) fib.(i - 2)
    done
  in
  let d = Array.make (o + 1) 0 in
  let shift pos ofs v =
    let res = add (mul fib.(ofs + 1) v) (mul fib.(ofs) (add v (-d.(pos)))) in
      (*Printf.printf "shift %d %d %d  %d %d -> %d\n" pos ofs v d.(pos) fib.(ofs + 1) res;*)
      res
  in
  let a = Array.make (2 * o) 0 in
  let rec update i x l r k =
    if l = r then (
      a.(k) <- x;
    ) else (
      let m = (l + r) / 2 in
	if i <= m
	then update i x l m (2 * k + 1)
	else update i x (m + 1) r (2 * k + 2);
	let a1 = a.(2 * k + 1) in
	let a2 = a.(2 * k + 2) in
	  a.(k) <- add a1 (shift (m + 1) (m - l + 1) a2);
    )
  in
  let rec rmq x y l r k =
    if x <= l && r <= y
    then (
      a.(k)
    ) else (
      let m = (l + r) / 2 in
	if m < x
	then rmq x y (m + 1) r (2 * k + 2)
	else if m >= y
	then rmq x y l m (2 * k + 1)
	else
	  let a1 = rmq x y l m (2 * k + 1)
	  and a2 = rmq x y (m + 1) r (2 * k + 2) in
	    add a1 (shift (m + 1) (m - x + 1) a2)
    )
  in
  let () =
    for i = 1 to n do
      d.(i) <- Scanf.bscanf sb "%d " (fun s -> s);
      update i d.(i) 1 o 0
    done;
  in
    for k = 1 to m do
(*for j = 0 to Array.length a - 1 do
  Printf.printf "%d " a.(j);
done;
Printf.printf "\n";*)
      let op = Scanf.bscanf sb "%d " (fun s -> s) in
	match op with
	  | 1 ->
	      let i = Scanf.bscanf sb "%d " (fun s -> s) in
	      let v = Scanf.bscanf sb "%d " (fun s -> s) in
		d.(i) <- v;
	  | 2 ->
	      let l = Scanf.bscanf sb "%d " (fun s -> s) in
	      let r = Scanf.bscanf sb "%d " (fun s -> s) in
	      let res = ref 0 in
		for i = l to r do
		  res := add !res (mul fib.(i - l + 1) d.(i))
		done;
		Printf.printf "%d\n" !res;
	  | _ -> assert false
    done

let _ =
  let mm = 1000000000 in
  let mmm = 1000000000l in
  let mmmm = 1000000000L in
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let m = Scanf.bscanf sb "%d " (fun s -> s) in
  let add x y =
    let r =
      Int32.to_int
	(Int32.rem
	   (Int32.add
	      (Int32.of_int x)
	      (Int32.of_int y))
	   mmm)
    in
      if r < 0
      then r + mm
      else r
  in
  let mul x y =
    let r =
      Int64.to_int
	(Int64.rem
	   (Int64.mul
	      (Int64.of_int x)
	      (Int64.of_int y))
	   mmmm)
    in
      if r < 0
      then r + mm
      else r
  in
  let o = 131072 * 2 in
  (*let o = 8 in*)
  let fib = Array.make (o + 1) 0 in
  let _ =
    fib.(1) <- 1;
    for i = 2 to o do
      fib.(i) <- add fib.(i - 1) fib.(i - 2)
    done
  in
  let d = Array.make (o + 1) 0 in
  let shift pos ofs v =
    let res = add (mul fib.(ofs + 1) v) (mul fib.(ofs) (add v (-d.(pos)))) in
      (*Printf.printf "shift %d %d %d  %d %d -> %d\n" pos ofs v d.(pos) fib.(ofs + 1) res;*)
      res
  in
  let a = Array.make (2 * o) 0 in
  let rec update i x l r k =
    if l = r then (
      a.(k) <- x;
    ) else (
      let m = (l + r) / 2 in
	if i <= m
	then update i x l m (2 * k + 1)
	else update i x (m + 1) r (2 * k + 2);
	let a1 = a.(2 * k + 1) in
	let a2 = a.(2 * k + 2) in
	  a.(k) <- add a1 (shift (m + 1) (m - l + 1) a2);
    )
  in
  let rec rmq x y l r k =
    if x <= l && r <= y
    then (
      a.(k)
    ) else (
      let m = (l + r) / 2 in
	if m < x
	then rmq x y (m + 1) r (2 * k + 2)
	else if m >= y
	then rmq x y l m (2 * k + 1)
	else
	  let a1 = rmq x y l m (2 * k + 1)
	  and a2 = rmq x y (m + 1) r (2 * k + 2) in
	    add a1 (shift (m + 1) (m - x + 1) a2)
    )
  in
  let () =
    for i = 1 to n do
      d.(i) <- Scanf.bscanf sb "%d " (fun s -> s);
      update i d.(i) 1 o 0
    done;
  in
    for k = 1 to m do
(*for j = 0 to Array.length a - 1 do
  Printf.printf "%d " a.(j);
done;
Printf.printf "\n";*)
      let op = Scanf.bscanf sb "%d " (fun s -> s) in
	match op with
	  | 1 ->
	      let i = Scanf.bscanf sb "%d " (fun s -> s) in
	      let v = Scanf.bscanf sb "%d " (fun s -> s) in
		d.(i) <- v;
		update i v 1 o 0;
	  | 2 ->
	      let l = Scanf.bscanf sb "%d " (fun s -> s) in
	      let r = Scanf.bscanf sb "%d " (fun s -> s) in
	      let res = rmq l r 1 o 0 in
		Printf.printf "%d\n" res;
	  | _ -> assert false
    done

let _ =
  let mm = 1000000000 in
  let mmm = 1000000000l in
  let mmmm = 1000000000L in
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let m = Scanf.bscanf sb "%d " (fun s -> s) in
  let add x y =
    let r =
      Int32.to_int
	(Int32.rem
	   (Int32.add
	      (Int32.of_int x)
	      (Int32.of_int y))
	   mmm)
    in
      if r < 0
      then r + mm
      else r
  in
  let mul x y =
    let r =
      Int64.to_int
	(Int64.rem
	   (Int64.mul
	      (Int64.of_int x)
	      (Int64.of_int y))
	   mmmm)
    in
      if r < 0
      then r + mm
      else r
  in
  let o = 131072 * 2 in
  (*let o = 8 in*)
  let fib = Array.make (o + 1) 0 in
  let _ =
    fib.(1) <- 1;
    for i = 2 to o do
      fib.(i) <- add fib.(i - 1) fib.(i - 2)
    done
  in
  let d = Array.make (o + 1) 0 in
  let shift pos ofs v =
    let res = add (mul fib.(ofs + 1) v) (mul fib.(ofs) (v - d.(pos))) in
      (*Printf.printf "shift %d %d %d  %d %d -> %d\n" pos ofs v d.(pos) fib.(ofs + 1) res;*)
      res
  in
  let a = Array.make (2 * o) 0 in
  let rec update i x l r k =
    if l = r then (
      a.(k) <- x;
    ) else (
      let m = (l + r) / 2 in
	if i <= m
	then update i x l m (2 * k + 1)
	else update i x (m + 1) r (2 * k + 2);
	let a1 = a.(2 * k + 1) in
	let a2 = a.(2 * k + 2) in
	  a.(k) <- add a1 (shift (m + 1) (m - l + 1) a2);
    )
  in
  let rec rmq x y l r k =
    if x <= l && r <= y
    then (
      a.(k)
    ) else (
      let m = (l + r) / 2 in
	if m < x
	then rmq x y (m + 1) r (2 * k + 2)
	else if m >= y
	then rmq x y l m (2 * k + 1)
	else
	  let a1 = rmq x y l m (2 * k + 1)
	  and a2 = rmq x y (m + 1) r (2 * k + 2) in
	    add a1 (shift (m + 1) (m - x + 1) a2)
    )
  in
  let () =
    for i = 1 to n do
      d.(i) <- Scanf.bscanf sb "%d " (fun s -> s);
      update i d.(i) 1 o 0
    done;
  in
    for k = 1 to m do
(*for j = 0 to Array.length a - 1 do
  Printf.printf "%d " a.(j);
done;
Printf.printf "\n";*)
      let op = Scanf.bscanf sb "%d " (fun s -> s) in
	match op with
	  | 1 ->
	      let i = Scanf.bscanf sb "%d " (fun s -> s) in
	      let v = Scanf.bscanf sb "%d " (fun s -> s) in
		d.(i) <- v;
		update i v 1 o 0;
	  | 2 ->
	      let l = Scanf.bscanf sb "%d " (fun s -> s) in
	      let r = Scanf.bscanf sb "%d " (fun s -> s) in
	      let res = rmq l r 1 o 0 in
		Printf.printf "%d\n" res;
	  | _ -> assert false
    done

let _ =
  let mm = 1000000000 in
  let mmm = 1000000000l in
  let mmmm = 1000000000L in
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let m = Scanf.bscanf sb "%d " (fun s -> s) in
  let add x y =
    Int32.to_int
      (Int32.rem
	 (Int32.add
	    (Int32.of_int x)
	    (Int32.of_int y))
	 mmm)
  in
  let mul x y =
    Int64.to_int
      (Int64.rem
	 (Int64.mul
	    (Int64.of_int x)
	    (Int64.of_int y))
	 mmmm)
  in
  let o = 131072 * 2 in
  (*let o = 8 in*)
  let fib = Array.make (o + 1) 0 in
  let _ =
    fib.(1) <- 1;
    for i = 2 to o do
      fib.(i) <- add fib.(i - 1) fib.(i - 2)
    done
  in
  let d = Array.make (o + 1) 0 in
  let shift pos ofs v =
    let res = add (mul fib.(ofs + 1) v) (mul fib.(ofs) (v - d.(pos))) in
      (*Printf.printf "shift %d %d %d  %d %d -> %d\n" pos ofs v d.(pos) fib.(ofs + 1) res;*)
      res
  in
  let a = Array.make (2 * o) 0 in
  let rec update i x l r k =
    if l = r then (
      a.(k) <- x;
    ) else (
      let m = (l + r) / 2 in
	if i <= m
	then update i x l m (2 * k + 1)
	else update i x (m + 1) r (2 * k + 2);
	let a1 = a.(2 * k + 1) in
	let a2 = a.(2 * k + 2) in
	  a.(k) <- a1 + shift (m + 1) (m - l + 1) a2;
    )
  in
  let rec rmq x y l r k =
    if x <= l && r <= y
    then (
      a.(k)
    ) else (
      let m = (l + r) / 2 in
	if m < x
	then rmq x y (m + 1) r (2 * k + 2)
	else if m >= y
	then rmq x y l m (2 * k + 1)
	else
	  let a1 = rmq x y l m (2 * k + 1)
	  and a2 = rmq x y (m + 1) r (2 * k + 2) in
	    a1 + shift (m + 1) (m - x + 1) a2
    )
  in
  let () =
    for i = 1 to n do
      d.(i) <- Scanf.bscanf sb "%d " (fun s -> s);
      update i d.(i) 1 o 0
    done;
  in
    for k = 1 to m do
(*for j = 0 to Array.length a - 1 do
  Printf.printf "%d " a.(j);
done;
Printf.printf "\n";*)
      let op = Scanf.bscanf sb "%d " (fun s -> s) in
	match op with
	  | 1 ->
	      let i = Scanf.bscanf sb "%d " (fun s -> s) in
	      let v = Scanf.bscanf sb "%d " (fun s -> s) in
		d.(i) <- v;
		update i v 1 o 0;
	  | 2 ->
	      let l = Scanf.bscanf sb "%d " (fun s -> s) in
	      let r = Scanf.bscanf sb "%d " (fun s -> s) in
	      let res = rmq l r 1 o 0 in
		Printf.printf "%d\n" res;
	  | _ -> assert false
    done


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

let rec read_log_lengths = function
    | 0 -> []
    | n -> (read_int ())::(read_log_lengths (n-1))
;;

let rec get_num_moves = function
    | 0 -> 0
    | n ->
        let log_length=read_int () in
        log_length-1 + get_num_moves (n-1)
;;

(* Moves | Length 0 | 1, 1 | 2, 2 | 3, 3 | 4 *)
let calculate_test_case = function
    | num_moves ->
        if (num_moves mod 2 == 0) then "maomao90"
        else "errorgorn"

;;

let rec iterate_through_cases = function
    | 0 -> 0
    | n ->
        let num_logs = read_int () in
        let num_moves = get_num_moves num_logs in
        print_string (calculate_test_case num_moves);
        print_newline ();
        iterate_through_cases (n-1)
;;

let num_cases = read_int () in
iterate_through_cases num_cases;;

let parse len str = let rep = Array.make len (-1) in
  let temp = ref "" in
  let j = ref 0 in
  for i = 0 to String.length str -1 do
    if str.[i] = ' ' then
      (rep.(!j) <- (int_of_string !temp) ; incr j ; temp:=""  )
    else
      (temp:= !temp ^ (String.make 1 str.[i]))
  done; rep.(!j) <- (int_of_string !temp) ;rep
;;

let n = int_of_string (input_line stdin) in
for i = 0 to n-1 do
  let len = int_of_string (input_line stdin) in
  let str = (input_line stdin) in
  let tab = parse len str in
  let rep = ref 0 in
  for j = 0 to len -1 do
    rep := !rep + tab.(j) -1
  done;
  if !rep mod 2 = 1 then
    print_endline "errorgorn"
  else
    print_endline "maomao90"
done;;


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

let rec max_int_from_input max = function
    | 0 -> max
    | n ->
        let new_in = read_int () in
        if (max < new_in) then max_int_from_input new_in (n-1)
        else max_int_from_input max (n-1)
;;

let rec run_test_case = function
    | 0 -> 0
    | n ->
        let num_alice = read_int () in
        let max_alice = max_int_from_input 0 num_alice in
        let num_bob = read_int () in
        let max_bob = max_int_from_input 0 num_bob in
        if (max_alice > max_bob) then begin
            print_string "Alice\n";
            print_string "Alice\n";
            run_test_case (n-1)
        end
        else if (max_alice == max_bob) then begin
            print_string "Alice\n";
            print_string "Bob\n";
            run_test_case (n-1)
        end
        else begin
            print_string "Bob\n";
            print_string "Bob\n";
            run_test_case (n-1)
        end
;;

let num_cases = read_int () in
run_test_case num_cases;;

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

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

  let cases = read_int()in
  for case = 1 to cases do
    let n = read_int() in
    let a = Array.init n read_int in
    let m = read_int() in
    let b = Array.init m read_int in
    let maxa = maxf 0 (n-1) (fun i -> a.(i)) in
    let maxb = maxf 0 (m-1) (fun i -> b.(i)) in
    printf "%s\n" (if maxa >= maxb then "Alice" else "Bob");
    printf "%s\n" (if maxb >= maxa then "Bob" else "Alice");
  done


open Scanf;;
open Printf;;

let rec head n ls =
  match (n, ls) with
    (0, _) -> []
  | (n, []) -> failwith ""
  | (n, x::xs) -> x :: (head (n - 1) xs)

let n, k = scanf "%d %d " (fun x y -> x, y);;
let arr = Array.make (2 * n + 1) 0;;

for i = 0 to 2 * n do
  arr.(i) <- (scanf "%d " (fun x -> x))
done;;

let main () =
  let rec loop i res =
    if i >= 2 * n then res
    else if arr.(i - 1) + 1 < arr.(i) && arr.(i) > arr.(i + 1) + 1 then
      loop (i + 2) (i :: res)
    else loop (i + 2) res in
  let res = head k (loop 1 []) in
  List.iter (fun i -> arr.(i) <- (arr.(i) - 1)) res;;

main ();;

for i = 0 to 2 * n do
  printf "%d " arr.(i)
done;;
printf "\n"

let _ =
  let n = Scanf.scanf " %d" (fun x -> x) in
  let k = ref (Scanf.scanf " %d" (fun x -> x)) in
  let a = Array.create (2*n+1) 0 in
  for i = 0 to 2 * n do
    a.(i) <- Scanf.scanf " %d" (fun x -> x)
  done;
  for i = 0 to n - 1 do
    let j = 2*i+1 in
    if !k > 0 && a.(j) > a.(j-1) + 1 && a.(j) > a.(j+1) + 1 then begin
      k := !k - 1;
      a.(j) <- a.(j) - 1
    end
  done;
  print_string (String.concat " " (List.map string_of_int (Array.to_list a)))
;;

open Scanf;;
open Printf;;

let rec head n ls =
  match (n, ls) with
    (0, _) -> []
  | (n, []) -> failwith ""
  | (n, x::xs) -> x :: (head (n - 1) xs)

let n, k = scanf "%d %d " (fun x y -> x, y);;
let arr = Array.make (2 * n + 1) 0;;

for i = 0 to 2 * n do
  arr.(i) <- (scanf "%d " (fun x -> x))
done;;

let main () =
  let rec loop i res =
    if i >= 2 * n then res
    else if arr.(i - 1) + 1 < arr.(i) && arr.(i) > arr.(i - 1) + 1 then
      loop (i + 2) (i :: res)
    else loop (i + 2) res in
  let res = head k (loop 1 []) in
  List.iter (fun i -> arr.(i) <- (arr.(i) - 1)) res;;

main ();;

for i = 0 to 2 * n do
  printf "%d " arr.(i)
done;;
printf "\n"


module A = Array
module L = List
module I = Int64

let pf = Printf.printf
let sf = Scanf.scanf
let read_int () = sf " %d" (fun x -> x)
let read_array read n = A.init n (fun _ -> read ())

let () =
  let t = read_int () in

  for _ = 1 to t do
    let n = read_int () in
    let k = read_int () in
    let a = read_array read_int n in
    let ans = ref 0 in
    for i = 0 to k - 1 do
      if (a.(i) > k) then ans := !ans + 1;
    done;
    pf "%d\n" !ans;
  done

let get_num () =
  let rec f acc =
    try
      let c = input_byte stdin in
      if int_of_char '0' <= c && c <= int_of_char '9' then
        f ((acc * 10) + c - int_of_char '0')
      else if acc > 0 then Some acc
      else None
    with End_of_file -> if acc > 0 then Some acc else None
  in
  f 0

let solve_case () =
  match (get_num (), get_num ()) with
  | Some n, Some k ->
      let rec f i ans =
        let i = i + 1 in
        if i > n then print_int ans
        else
          match get_num () with
          | Some p ->
              let ans = if i <= k && p > k then ans + 1 else ans in
              f i ans
          | _ -> exit 1
      in
      f 0 0
  | _ -> ()

let () =
  match get_num () with
  | Some t ->
      let rec f i =
        if i = 0 then ()
        else
          let () = solve_case () in
          let () = print_newline () in
          f (i - 1)
      in
      f t
  | _ -> exit 1


(* Codeforces 248C Football Robot Electronic *)

open Big_int;;
open List;;

(* 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 rec readlist n acc = match n with
	| 0 -> List.rev acc
	| _ -> readlist (n -1) (gr() :: acc);;

let rec sumab a b l =
	if a>1 then (sumab (a-1) (b-1) (List.tl l))
	else if b>1 then ((List.hd l) + (sumab 0 (b-1) (List.tl l)))
	else 0;;

let debug = false;;

let main () =
	let n = gr() in
	let d = readlist (n-1) [] in
	let a = gr() in
	let b = gr() in
	let sab = sumab a b d in
	begin
		(* printlisti d;                   *)
		(* print_string "\n now result\n"; *)
	  print_int sab
	end;;

main();;

open Scanf;;

let n = Scanf.bscanf Scanf.Scanning.stdin "%d " (fun x -> x);;
let aa = Array.make (n-1) 0;;

for i = 0 to n - 2 do
  let x = Scanf.bscanf Scanf.Scanning.stdin "%d " (fun y->y) in
  aa.(i) <- x
done
;;

let (a,b) = Scanf.bscanf Scanf.Scanning.stdin "%d %d " (fun x y->(x,y) );;
if b <= a then
  begin
    print_int 0; print_endline "";
    end
else
  let rslt=ref 0 in
  let () =
    for j = (a-1) to (b-2) do
      rslt := !rslt + aa.(j)
    done in print_int !rslt; print_endline ""
;;


Array.(Scanf.scanf " %s %s" @@ fun s t ->
  let f s =
    init (String.length s) (fun i -> s.[i])
    |> map (function
    | 'a' | 'i' | 'u' | 'e' | 'o' -> 1
    | _ -> 0) in
  print_endline @@ if f s = f t then "Yes" else "No")

open Printf
open Scanf

let read_str _ = bscanf Scanning.stdib " %s " (fun x -> x)
let () =
  let s = read_str() in
  let t = read_str() in

  let isvowel c =
    c='a' || c='e' || c='i' || c='o' || c='u'
  in

  let f s =
    let n = String.length s in
    Array.init n (fun i -> isvowel s.[i])
  in

  if (f s) = (f t) then printf "Yes\n" else printf "No\n"

let is_vowel c = c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';;

let rec is_transformable a b i j na nb = na == nb && (if i < na && j < nb then (is_vowel (String.get a i)) == (is_vowel (String.get b j)) && (is_transformable a b (i + 1) (j + 1) na nb) else true);;

let a = read_line() in
let b = read_line() in
print_string (if is_transformable a b 0 0 (String.length a) (String.length b) then "Yes" else "No");;

let is_vowel c = c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';;

let is_transformable a b i j na nb = na == nb && i < na && j < nb && (is_vowel (String.get a i)) == (is_vowel (String.get b j));;

let a = read_line() in
let b = read_line() in
print_string (if is_transformable a b 0 0 (String.length a) (String.length b) then "Yes" else "No");;

open Printf
open Scanf

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

let read_str _ = bscanf Scanning.stdib " %s " (fun x -> x)
let () =
  let s = read_str() in
  let t = read_str() in

  let isvowel c =
    c='a' || c='e' || c='i' || c='o' || c='u'
  in

  let f s =
    let n = String.length s in
    Array.init n (fun i -> isvowel s.[i])
  in

  let alldiff s t =
    let n = String.length s in
    let m = String.length t in
    m = n && (forall 0 (n-1) (fun i -> s.[i] <> t.[i]))
  in

  if (f s) = (f t) && (alldiff s t) then printf "Yes\n" else printf "No\n"


(* --- *)
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

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


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"


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)))
*)


open Printf
open Scanf

let read_int _ = bscanf Scanning.stdin " %d " (fun x -> x)
let read_pair _ = bscanf Scanning.stdin " %d %d " (fun x y -> (x,y))
let () =
  let cases = read_int() in
  for case = 1 to cases do
    let n = read_int() in
    printf "%d\n" n
  done

let scan_int () = Scanf.scanf " %d" (fun x -> x);;
let show_int n = Printf.printf "%d\n" n;;

let t = scan_int ();;
for x = 1 to t do
	let n = scan_int () in
	show_int n
done;;


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

let s = String.lowercase (read_string ())
let n = String.length s

let start = n

let leftmost = Array.init (3*n+1) (fun i -> if i>=start then 0 else max_int/2)

let is_vowel c = match c with 'a' | 'e' | 'i' | 'o' | 'u' -> true | _ -> false

(* we've processed chars 0,1,2...i-1, and have the height and best for that *)
let rec fill_leftmost i height best = if i=n then (height,best) else
  if is_vowel s.[i] then (
    leftmost.(height-1) <- min leftmost.(height-1) (i+1);
    fill_leftmost (i+1) (height-1) (max best (i+1-leftmost.(height-1)))
  ) else (
    leftmost.(height+1) <- min leftmost.(height+1) i;
    leftmost.(height+2) <- min leftmost.(height+2) (i+1);
    fill_leftmost (i+1) (height+2) (max best (i+1-leftmost.(height+2)))
  )

let (height,best) = fill_leftmost 0 start 0

let rec complete h b = if h<0 then b else
  complete (h-1) (max b (n - leftmost.(h)))

let best = complete height best

let cvowel i = if is_vowel s.[i] then 1 else 0

(* vow for the range i....i+best-1, count for the previous one *)
let rec count_strings i count vow =
  let count = count + (if vow<=2*(best-vow) then 1 else 0) in
  if i+best-1 = n-1 then count else
    let vow = vow - (cvowel i) + (cvowel (i+best)) in
      count_strings (i+1) count vow

let rec count_vow i count =
  if i=best then count else count_vow (i+1) (count + (cvowel i))

let () =
  if best = 0
  then Printf.printf "No solution\n"
  else Printf.printf "%d %d\n" best (count_strings 0 0 (count_vow 0 0))

let getint () = Scanf.scanf " %d" (fun i->i)
let getstr () = Scanf.bscanf Scanf.Scanning.stdin "%s" (fun s -> s)
let getval c=
  match c with
    | 'a' | 'e' | 'i' | 'o' | 'u' -> -1
    | _ -> 2

let _ =
  let s = String.lowercase (getstr ()) in
  let n = String.length s in
  let mn = ref 0 in
  let res = ref ~-1 in
  let mxSub  = Array.make 200200 0 in
  let prefix = Array.make 200200 0 in
  let getsum i j = prefix.(j) - (if i=0 then 0 else prefix.(i-1)) in
    for i = 0 to n-1 do
      prefix.(i) <- getval s.[i] + (if i=0 then 0 else prefix.(i-1));
    done;
    for i = 0 to n-1 do
      mxSub.(i) <- prefix.(i) - !mn;
      mn := min !mn prefix.(i);
      let lo = ref 0 and hi = ref i and ans = ref ~-1 in
        while !lo <= !hi do
          let mid = (!lo + !hi) / 2 in
            let right = getsum mid i
            and left = max 0 (if mid=0 then 0 else mxSub.(mid-1)) in
              if left+right>=0 then (ans:= mid; hi := mid-1)
              else lo := mid+1
        done;
        if !ans <> -1 then res := max !res (i - !ans + 1)
    done;
    if !res= -1 then Printf.printf "No solution\n"
    else
      begin
        let cnt = ref 0 in
          for i = 0 to n - !res do
            if getsum i (i + !res - 1)  >=0
            then cnt := !cnt + 1
          done;
          Printf.printf "%d %d\n" !res !cnt
      end

let main() =
  let f = function
    'a' | 'e' | 'i' | 'o' | 'u' -> -1
  | _ -> 2
    in
  let s = Scanf.scanf "%s" String.lowercase in
  let n = String.length s in
  let a = Array.init n (fun i -> (f s.[i])) in
  let b = Array.create (n+1) 0 in
  Array.iteri (fun i x -> b.(i+1) <- b.(i) + x) a;
  let c = Array.mapi (fun i x -> x, i) b in
  Array.stable_sort (fun x y -> compare (fst x) (fst y)) c;
  let rec g k j maxl tot =
    if k < 0 then maxl, tot
    else
      let i = snd c.(k) in
      if i > j then g (k-1) i maxl tot
      else (
        let l = j - i in
        if l < maxl then g (k-1) j maxl tot
        else g (k-1) j l (if l == maxl then (tot+1) else 1)
      )
    in
  let r,v = g n 0 0 0 in
  if r > 0 then Printf.printf "%d %d\n" r v else Printf.printf "No solution\n"
  ;;
main()

let min (x : int) y = if x < y then x else y

let fr n = n + (n land (-n))
let fl n = n land (n - 1)

let fenwick_new n =
  Array.make (n + 1) 1000000000

let fenwick_modify ft n x =
  let i = ref n in
    while !i < Array.length ft do
      ft.(!i) <- min ft.(!i) x;
      i := fr !i;
    done

let fenwick_min ft n =
  let i = ref n in
  let res = ref 1000000000 in
    while !i > 0 do
      res := min !res ft.(!i);
      i := fl !i;
    done;
    !res

let _ =
  let sb = Scanf.Scanning.stdib in
  let s = Scanf.bscanf sb "%s " (fun s -> s) in
  let n = String.length s in
  let ft = fenwick_new 800000 in
  let sum = ref 300000 in
  let res = ref (-1) in
  let a = Array.make (n + 1) !sum in
    fenwick_modify ft !sum 0;
    for i = 0 to n - 1 do
      let c = s.[i] in
	(match c with
	   | 'a' | 'e' | 'i' | 'o' | 'u'
	   | 'A' | 'E' | 'I' | 'O' | 'U' ->
	       decr sum;
	   | _ ->
	       sum := !sum + 2
	);
	let l = fenwick_min ft !sum in
	  (*Printf.printf "asd %d %d %d\n" i !sum l;*)
	  if l < 1000000000 && i + 1 - l > !res then (
	    res := i + 1 - l
	  );
	  fenwick_modify ft !sum (i + 1);
	  a.(i + 1) <- !sum
    done;
    if !res < 0
    then Printf.printf "No solution\n"
    else (
      let c = ref 0 in
	for i = !res to n do
	  if a.(i) - a.(i - !res) >= 0
	  then incr c
	done;
	Printf.printf "%d %d\n" !res !c;
    )

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

let s = String.lowercase (read_string ())
let n = String.length s

let start = n

let leftmost = Array.init (3*n+1) (fun i -> if i>=start then 0 else max_int/2)

let is_vowel c = match c with 'a' | 'e' | 'i' | 'o' | 'u' -> true | _ -> false

(* we've processed chars 0,1,2...i-1, and have the height and best for that *)
let rec fill_leftmost i height bc = if i=n then bc else
  let best_count (b,c) nb = if nb < b then (b,c) else if nb = b then (b,c+1) else (nb, 1) in
  if is_vowel s.[i] then (
    leftmost.(height-1) <- min leftmost.(height-1) (i+1);
    fill_leftmost (i+1) (height-1) (best_count bc (i+1-leftmost.(height-1)))
  ) else (
    leftmost.(height+1) <- min leftmost.(height+1) i;
    leftmost.(height+2) <- min leftmost.(height+2) (i+1);
    fill_leftmost (i+1) (height+2) (best_count bc (i+1-leftmost.(height+2)))
  )

let (best,count) = fill_leftmost 0 start (0,1)

let () =
  if best = 0
  then Printf.printf "No solution\n"
  else Printf.printf "%d %d\n" best count

let main() =
  let f = function
    'a' | 'e' | 'i' | 'o' | 'u' | 'y' -> -1
  | _ -> 2
    in
  let s = Scanf.scanf "%s" String.lowercase in
  let n = String.length s in
  let a = Array.init n (fun i -> (f s.[i])) in
  let b = Array.create (n+1) 0 in
  Array.iteri (fun i x -> b.(i+1) <- b.(i) + x) a;
  let c = Array.mapi (fun i x -> x, i) b in
  Array.stable_sort (fun x y -> compare (fst x) (fst y)) c;
  let rec g k j maxl tot =
    if k < 0 then maxl, tot
    else
      let i = snd c.(k) in
      if i > j then g (k-1) i maxl tot
      else (
        let l = j - i in
        if l < maxl then g (k-1) j maxl tot
        else g (k-1) j l (if l == maxl then (tot+1) else 1)
      )
    in
  let r,v = g n 0 0 0 in
  if r > 0 then Printf.printf "%d %d\n" r v else Printf.printf "No solution\n"
  ;;
main()

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

let s = String.lowercase (read_string ())
let n = String.length s

let start = n

let leftmost = Array.init (3*n+1) (fun i -> if i>=start then 0 else max_int/2)

let is_vowel c = match c with 'a' | 'e' | 'i' | 'o' | 'u' -> true | _ -> false

(* we've processed chars 0,1,2...i-1, and have the height and best for that *)
let rec fill_leftmost i height best = if i=n then (height,best) else
  if is_vowel s.[i] then (
    leftmost.(height-1) <- min leftmost.(height-1) (i+1);
    fill_leftmost (i+1) (height-1) (max best (i+1-leftmost.(height-1)))
  ) else (
    leftmost.(height+1) <- min leftmost.(height+1) i;
    leftmost.(height+2) <- min leftmost.(height+2) (i+1);
    fill_leftmost (i+1) (height+2) (max best (i+1-leftmost.(height+2)))
  )

let (height,best) = fill_leftmost 0 start 0

let rec complete h b = if h<0 then b else
  complete (h-1) (max b (n - leftmost.(h)))

let best = complete height best

let cvowel i = if is_vowel s.[i] then 1 else 0

(* vow for the range i....i+best-1, count for the previous one *)
let rec count_strings i count vow =
  let count = count + (if vow<=2*(best-vow) then 1 else 0) in
  if i+best-1 = n-1 then count else
    let vow = vow - (cvowel i) + (cvowel (i+best)) in
      count_strings (i+1) count vow

let rec count_vow i count =
  if i=best then count else count_vow (i+1) (count + (cvowel i))

;;

Printf.printf "%d %d\n" best (count_strings 0 0 (count_vow 0 0))