open Printf
open String

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

let rec msplit t i ll=
  if t="" || i>=String.length t then
    List.rev ll
  else
    begin
      try
        let j = String.index_from t i '/' in
        let s1= String.sub t i (j-i) in
        match s1 with
        |"" -> msplit t (j+1) ll
        |_ -> msplit t (j+1) (s1::ll)
      with
        Not_found ->
        let s1 = String.sub t i ((String.length t) - i) in
        List.rev (s1::ll)
    end

let msplit2 s = msplit s 0 []

              (*
let a = msplit2 "home/xyzt" in
    let () =List.iter (printf "%s ") a in
    print_endline "\n====\n"
               *)

let rec process_cd t cwd =
  if t="" then
    cwd
  else
    begin
      match (String.get t 0) with
      | '/' -> (process_cd (String.sub t 1 ((String.length t)-1)) [])
      | _ ->
         begin
           let ll = msplit t 0 [] in
           process_dirs ll cwd
         end
    end
and process_dirs l c =
  match l with
  | [] -> c
  | hd::lr ->
     begin
       match hd with
       |"." -> process_dirs lr c
       |".."-> process_dirs lr (List.tl c)
       | _ -> process_dirs lr (hd::c)
     end

let rec process_command ls cwd =
  match ls with
  |[] -> ()
  |s::lr ->
    begin
      match s with
      | "pwd" ->
         List.iter (fun x -> printf "/%s" x) (List.rev cwd); print_endline "/";
         process_command lr cwd
      | "cd" ->
         let cwd1 = process_cd (List.hd lr) cwd in
         process_command (List.tl lr) cwd1
    end

let rec readl l =
    let s = Scanf.scanf "%s " (fun x -> x) in
    match s with
    | "" -> List.rev l
    | _ -> readl (s::l)

let commands = readl [];;

  (*
let _ = List.iter (fun x -> printf "%s " x) commands
in print_endline "\n---"
   *)

let _ = process_command commands []

open Printf;;
open Scanf;;

let output_directory dir =
  let rec process_dir dir =
  match dir with
    | []   -> printf "\n"
    | h::t -> printf "%s/" h;
	      process_dir t
  in
  printf "/";
  process_dir (List.rev dir)
;;

let rec change_directory act_dir s idx act_str =
  if idx < (String.length s) then
    match s.[idx] with
    | '/' -> if(act_str = "..") then
		change_directory (List.tl act_dir) s (idx+1) ""
	     else
		change_directory (act_str::act_dir) s (idx+1) ""
    | c   -> change_directory act_dir s (idx+1) (act_str ^ (Char.escaped c))
  else
    act_dir
;;

let process_line dir =
  let s = scanf "%s" (fun x->x) in
(*   printf "mam komende %s\n" s; *)
  if s = "pwd" then begin
(*     printf "%s\n" s; *)
    let _ = scanf "%s\n" (fun x->x) in
    output_directory dir;
    dir
  end else begin
(*     printf "%s\n" s; *)
    let s2 = scanf " %s\n" (fun x->x) in
(*     printf "robie cd do %s\n" s2; *)
    if s2.[0] = '/' then
      change_directory [] (s2^"/") 1 ""
    else
      change_directory dir (s2^"/") 0 ""
  end

;;

let rec solve n directory =
  if n <> 0 then
    solve (n-1) (process_line directory)
;;

let n = scanf "%d\n" (fun x->x) in
solve n []


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

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

let () =
	let q = read_int () in
	for tests = 1 to q do
		let n = read_int () in
		solve n;
	done;


let n = int_of_string (input_line stdin) in
for i = 0 to n-1 do
  let l , r = Scanf.sscanf (input_line stdin) "%d  %d" (fun l r -> (l,r)) in
  if l = 0 then print_endline "1"
  else begin
    let b = Int64.add (Int64.of_int r) (Int64.of_int r) in
    let a = Int64.add b (Int64.of_int (l+1)) in
    print_endline (Int64.to_string a)
  end
done;;

open Printf
open Scanf
module LL = Int64
let rd_ll () = bscanf Scanning.stdin " %Ld " (fun x -> x)

let (&) x = LL.of_int x
let ( + ) x y = LL.add x y
let ( - ) x y = LL.sub x y
let ( * ) x y = LL.mul x y
let ( / ) x y = LL.div x y
let ( % ) x y = x - ( y * (x / y) )

let solve x y =
  if x = 0L then 1L
  else x+2L*y+1L

let () =
  let t = read_int () in
  for i=1 to t do
    let n = rd_ll () in
    let x = rd_ll () in
    printf "%Ld\n" (solve n x)
  done;


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

open Printf
open Scanf

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

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

  Array.sort compare a;

  let rec scan i mval = if i=n then mval else
      if a.(i) >= mval
      then scan (i+1) (mval+1)
      else scan (i+1) mval
  in

  printf "%d\n" (scan 0 1)


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

module Opt = struct
  let get = function
    | None -> assert false
    | Some v -> v
end

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 i_bit x i = (x lsr i) land 1

let () =
  let n = read_int () in
  let q = read_int () in
  let ans = Array.make n 0 in
  let gr = Array.make n [] in
  let qrs = Array.init q (fun _ ->
    let x = read_int () - 1 in
    let y = read_int () - 1 in
    let v = read_int () in
    (x, y, v)
  ) in

  Array.iter (fun (x, y, v) ->
    if (x <> y) then begin
      gr.(x) <- (y, v) :: gr.(x);
      gr.(y) <- (x, v) :: gr.(y);
    end
  ) qrs;

  let bit_val = Array.make n (-1) in
  for b = 29 downto 0 do
    Array.fill bit_val 0 n (-1);
    for i = 0 to q - 1 do
      let (x, y, v) = qrs.(i) in
      (* pf "q = %d %d %d %d\n" i x y v;
      pf "q = %d %d %d %b\n" i  (i_bit v x ) (i_bit v y ) (i_bit v x = 0 && i_bit v y = 0); *)
      if (x = y) then bit_val.(x) <- i_bit v x
      else if (i_bit v b = 0 && i_bit v b = 0) then begin
        bit_val.(x) <- 0;
        bit_val.(y) <- 0;
      end
    done;

    for i = 0 to n - 1 do
      if (bit_val.(i) = -1) then begin
        let is_one = List.exists (fun (y, v) -> bit_val.(y) = 0 && i_bit v b = 1) gr.(i) in
        (* pf "%d %d %b\n" b i is_one; *)
        if (is_one) then bit_val.(i) <- 1
        else bit_val.(i) <- 0;
      end;
      ans.(i) <- ans.(i) lor (bit_val.(i) lsl b);
    done;
  done;

  Array.iter (fun x -> pf "%d " x) ans;

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 (n,q) = read_pair () in
  let constr = Array.init q (fun _ ->
    let i = -1 + read_int() in
    let j = -1 + read_int() in
    let x = read_int() in
    (i,j,x)
  ) in

  let req0 = Array.make n 0 in
  let req1 = Array.make n 0 in

  let adj = Array.make n [] in

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

  for k = 0 to q-1 do
    let (i,j,x) = constr.(k) in
    if i=j then (
      req0.(i) <- req0.(i) lor (lnot x);
      req1.(i) <- req1.(i) lor x
    ) else (
      req0.(i) <- req0.(i) lor (lnot x);
      req0.(j) <- req0.(j) lor (lnot x);
      add_edge i j x
    )
  done;

  for i = 0 to n-1 do
    req1.(i) <- List.fold_left (fun ac (j,x) ->
      (req0.(j) land x) lor ac
    ) req1.(i) adj.(i);
    req0.(i) <- lnot req1.(i)
  done;

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


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 I64_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
  (* input *)
  let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf " %Ld" (fun v -> v))
  let get_i64 _ = Scanf.scanf " %Ld" (fun v -> v)
  let get_2_i64 _ = Scanf.scanf " %Ld %Ld" (fun u v -> u,v)
  let get_3_i64 _ = Scanf.scanf " %Ld %Ld %Ld" (fun u v w -> u,v,w)
  let get_4_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld" (fun u v w x -> u,v,w,x)
  let get_5_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld %Ld" (fun u v w x y -> u,v,w,x,y)
  let 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 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 hoge = init 100 (fun i -> let i = i+$1 in i*$(if i %$ 2=0 then 1 else -1))
  in
  print_array (sprintf "%3d") hoge;
  let cumul = make 100 0 in
  iteri (fun i v ->
    if i<>0 then cumul.(i) <- cumul.(i-$1)+$hoge.(i-$1)
  ) cumul;
  print_array (sprintf "%3d") cumul *)
let f l = l*(if l mod 2L=0L then 1L else -1L)
let g l = ceildiv (l) 2L*(if l mod 2L=0L then 1L else -1L)
let () =
  let q = get_i64 0 in
  rep 1L q (fun _ ->
    let l,r = get_2_i64 0 in
    printf "%Ld\n" @@
    if l=r then f l
    (* else if r=l+1L then f l + f (l+1L)
    else if r=l+2L then f l + f (l+1L) + f (l+2L)
    (*let vl = ceildiv (l) 2L*(if l mod 2L=0L then 1L else -1L) in
    let vr = ceildiv (r) 2L*(if r mod 2L=0L then 1L else -1L) in
    (* printf "%Ld\n" @@ vl + vr *)
    printf "%Ld\n" @@ vl + vr; *)
    else if l = 1L then g r
    else
    (* if l mod 2L=0L && (r-l) mod 2L=0L then g l + g r
    else if l mod 2L=1L && (r-l) mod 2L=0L then 0L
    else if l mod 2L=0L && (r-l) mod 2L=1L then g l + g r
    else 0L *)
    g l + g r *)
    else
    (* if l=1L then g r
    else g (l-1L) + g r *)
    g r - g (l-1L)
  )

open Printf
open Scanf

let (--) = Int64.sub
let (//) = Int64.div
let (%%) = Int64.rem

let sum = function
    r when r %% 2L = 0L -> r // 2L
  | r -> r // 2L -- r

let () =
  let q = scanf " %d" (fun x -> x) in
  for i = 0 to q-1 do
    let l, r = scanf " %Ld %Ld" (fun x y -> x,y) in
    printf "%Ld\n" @@ sum r -- sum (l -- 1L)
  done

open Printf open Scanf
module Lib = struct
  let i32,i64,ist = Int64.(to_int,of_int,to_string)
  let (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (%$) = (mod)
  let labs = Int64.abs
  let (+),(-),( * ),(/),(mod),(%) = Int64.(add,sub,mul,div,rem,rem)
  let (+=) r v = r := !r + v
  let (-=) r v = r := !r - v
  let ( *= ) r v = r := !r * v
  let (/=) r v = r := !r / v
  let (%=) r v = r := !r % v
  let max_i64,min_i64 = Int64.(max_int,min_int)
  (* math *)
  let ceildiv p q = (p+q-1L) / q
  let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n)
  let lcm m n = m / gcd m n * n
  module I64_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
  (* input *)
  let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf " %Ld" (fun v -> v))
  let get_i64 _ = Scanf.scanf " %Ld" (fun v -> v)
  let get_2_i64 _ = Scanf.scanf " %Ld %Ld" (fun u v -> u,v)
  let get_3_i64 _ = Scanf.scanf " %Ld %Ld %Ld" (fun u v w -> u,v,w)
  let get_4_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld" (fun u v w x -> u,v,w,x)
  let get_5_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld %Ld" (fun u v w x y -> u,v,w,x,y)
  let 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 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 hoge = init 100 (fun i -> let i = i+$1 in i*$(if i %$ 2=0 then 1 else -1))
  in
  print_array (sprintf "%3d") hoge;
  let cumul = make 100 0 in
  iteri (fun i v ->
    if i<>0 then cumul.(i) <- cumul.(i-$1)+$hoge.(i-$1)
  ) cumul;
  print_array (sprintf "%3d") cumul *)
let f l = l*(if l mod 2L=0L then 1L else -1L)
let g l = ceildiv (l) 2L*(if l mod 2L=0L then 1L else -1L)
let () =
  let q = get_i64 0 in
  rep 1L q (fun _ ->
    let l,r = get_2_i64 0 in
    printf "%Ld\n" @@
    if l=r then f l
    else if r=l+1L then f l + f (l+1L)
    else if r=l+2L then f l + f (l+1L) + f (l+2L)
    (*let vl = ceildiv (l) 2L*(if l mod 2L=0L then 1L else -1L) in
    let vr = ceildiv (r) 2L*(if r mod 2L=0L then 1L else -1L) in
    (* printf "%Ld\n" @@ vl + vr *)
    printf "%Ld\n" @@ vl + vr; *)
    else
    (* if l mod 2L=0L && (r-l) mod 2L=0L then g l + g r
    else if l mod 2L=1L && (r-l) mod 2L=0L then 0L
    else if l mod 2L=0L && (r-l) mod 2L=1L then g l + g r
    else 0L *)
    g l + g r
  )

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 I64_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
  (* input *)
  let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf " %Ld" (fun v -> v))
  let get_i64 _ = Scanf.scanf " %Ld" (fun v -> v)
  let get_2_i64 _ = Scanf.scanf " %Ld %Ld" (fun u v -> u,v)
  let get_3_i64 _ = Scanf.scanf " %Ld %Ld %Ld" (fun u v w -> u,v,w)
  let get_4_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld" (fun u v w x -> u,v,w,x)
  let get_5_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld %Ld" (fun u v w x y -> u,v,w,x,y)
  let 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 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 hoge = init 100 (fun i -> let i = i+$1 in i*$(if i %$ 2=0 then 1 else -1))
  in
  print_array (sprintf "%3d") hoge;
  let cumul = make 100 0 in
  iteri (fun i v ->
    if i<>0 then cumul.(i) <- cumul.(i-$1)+$hoge.(i-$1)
  ) cumul;
  print_array (sprintf "%3d") cumul; *)
let f l = l*(if l mod 2L=0L then 1L else -1L)
let g l = ceildiv (l) 2L*(if l mod 2L=0L then 1L else -1L)
let () =
  let q = get_i64 0 in
  rep 1L q (fun _ ->
    let l,r = get_2_i64 0 in
    printf "%Ld\n" @@
    if l=r then f l
    else if r=l+1L then f l + f (l+1L)
    else if r=l+2L then f l + f (l+1L) + f (l+2L)
    (*let vl = ceildiv (l) 2L*(if l mod 2L=0L then 1L else -1L) in
    let vr = ceildiv (r) 2L*(if r mod 2L=0L then 1L else -1L) in
    (* printf "%Ld\n" @@ vl + vr *)
    printf "%Ld\n" @@ vl + vr; *)
    else if l mod 2L=0L && (r-l) mod 2L=0L then g l + g r
    else if l mod 2L=1L && (r-l) mod 2L=0L then 0L
    else if l mod 2L=0L && (r-l) mod 2L=1L then g r
    else 0L
  )

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 I64_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
  (* input *)
  let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf " %Ld" (fun v -> v))
  let get_i64 _ = Scanf.scanf " %Ld" (fun v -> v)
  let get_2_i64 _ = Scanf.scanf " %Ld %Ld" (fun u v -> u,v)
  let get_3_i64 _ = Scanf.scanf " %Ld %Ld %Ld" (fun u v w -> u,v,w)
  let get_4_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld" (fun u v w x -> u,v,w,x)
  let get_5_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld %Ld" (fun u v w x y -> u,v,w,x,y)
  let 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 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 hoge = init 100 (fun i -> let i = i+$1 in i*$(if i %$ 2=0 then 1 else -1))
  in
  print_array (sprintf "%3d") hoge;
  let cumul = make 100 0 in
  iteri (fun i v ->
    if i<>0 then cumul.(i) <- cumul.(i-$1)+$hoge.(i-$1)
  ) cumul;
  print_array (sprintf "%3d") cumul *)
let f l = l*(if l mod 2L=0L then 1L else -1L)
let g l = ceildiv (l) 2L*(if l mod 2L=0L then 1L else -1L)
let () =
  let q = get_i64 0 in
  rep 1L q (fun _ ->
    let l,r = get_2_i64 0 in
    printf "%Ld\n" @@
    if l=r then f l
    else if r=l+1L then f l + f (l+1L)
    else if r=l+2L then f l + f (l+1L) + f (l+2L)
    (*let vl = ceildiv (l) 2L*(if l mod 2L=0L then 1L else -1L) in
    let vr = ceildiv (r) 2L*(if r mod 2L=0L then 1L else -1L) in
    (* printf "%Ld\n" @@ vl + vr *)
    printf "%Ld\n" @@ vl + vr; *)
    else if l mod 2L=0L && (r-l) mod 2L=0L then g l + g r
    else if l mod 2L=1L && (r-l) mod 2L=0L then 0L
    else if l mod 2L=0L && (r-l) mod 2L=1L then g l + g r
    else 0L
  )

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 I64_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
  (* input *)
  let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf " %Ld" (fun v -> v))
  let get_i64 _ = Scanf.scanf " %Ld" (fun v -> v)
  let get_2_i64 _ = Scanf.scanf " %Ld %Ld" (fun u v -> u,v)
  let get_3_i64 _ = Scanf.scanf " %Ld %Ld %Ld" (fun u v w -> u,v,w)
  let get_4_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld" (fun u v w x -> u,v,w,x)
  let get_5_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld %Ld" (fun u v w x y -> u,v,w,x,y)
  let 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 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 hoge = init 100 (fun i -> let i = i+$1 in i*$(if i %$ 2=0 then 1 else -1))
  in
  print_array (sprintf "%3d") hoge;
  let cumul = make 100 0 in
  iteri (fun i v ->
    if i<>0 then cumul.(i) <- cumul.(i-$1)+$hoge.(i-$1)
  ) cumul;
  print_array (sprintf "%3d") cumul *)
let f l = l*(if l mod 2L=0L then 1L else -1L)
let g l = ceildiv (l) 2L*(if l mod 2L=0L then 1L else -1L)
let () =
  let q = get_i64 0 in
  rep 1L q (fun _ ->
    let l,r = get_2_i64 0 in
    printf "%Ld\n" @@
    if l=r then f l
    else if r=l+1L then f l + f (l+1L)
    else if r=l+2L then f l + f (l+1L) + f (l+2L)
    (*let vl = ceildiv (l) 2L*(if l mod 2L=0L then 1L else -1L) in
    let vr = ceildiv (r) 2L*(if r mod 2L=0L then 1L else -1L) in
    (* printf "%Ld\n" @@ vl + vr *)
    printf "%Ld\n" @@ vl + vr; *)
    else if l = 1L then g r
    else
    (* if l mod 2L=0L && (r-l) mod 2L=0L then g l + g r
    else if l mod 2L=1L && (r-l) mod 2L=0L then 0L
    else if l mod 2L=0L && (r-l) mod 2L=1L then g l + g r
    else 0L *)
    g l + g r
  )


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

open Printf

let init (x : int) (f : int -> 'a) : 'a list =
  let rec build k =
    if k = x then []
    else (f k) :: build (k + 1) in
  build 0
;;

let run () =
  let n = scan_int () in
  let a = Array.init n (fun _x -> scan_int ()) in
  let posA = ref 0 and posB = ref (n-1) in
  let totA = ref 0 and totB = ref 0 in
  let prv = ref 0 and now = ref 0 in
  let turn = ref 0 and totturn = ref 0 in
  while !posA <= !posB do
    if !turn = 0 then begin
      now  := !now  + a.(!posA);
      totA := !totA + a.(!posA);
      posA := !posA + 1
    end
    else begin
      now  := !now  + a.(!posB);
      totB := !totB + a.(!posB);
      posB := !posB - 1
    end;
    if !now > !prv then begin
      prv := !now;
      now := 0;
      turn := 1 - !turn;
      totturn := !totturn + 1
    end
  done;
  if !now > 0 then incr totturn;
  let lst = [!totturn; !totA; !totB] in
  List.iter (printf "%d ") lst;
  print_endline ""
;;

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

(* Codeforces 1352 D Alice, Bob and Candies comp   *)

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

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

(* ============= above library below custom ========== *)

let rec alice ia sma ib smb lastbob nmov v =
	let rec eat i eaten =
		(* let _ = Printf.printf "al eat i eaten = %d %d\n" i eaten in *)
		if eaten > lastbob then (i, eaten)
		else if i > ib then (i, eaten)
		else
			let eaten = eaten + v.(i) in
			let i = i + 1 in
			eat i eaten in
	let idx,aeat = eat ia 0 in
	let sma = sma + aeat in
  let nmov = nmov + 1 in
	if idx > ib then (nmov, sma, smb)
	else
	bob idx sma ib smb aeat nmov v

and

bob ia sma ib smb lastalice nmov v =
    let rec eat i eaten =
        (* let _ = Printf.printf "bo eat i eaten = %d %d\n" i eaten in *)
        if eaten > lastalice then (i, eaten)
        else if i < ia then (i, eaten)
        else
            let eaten = eaten + v.(i) in
            let i = i - 1 in
            eat i eaten in
    let idx,beat = eat ib 0 in
    let smb = smb + beat in
    let nmov = nmov + 1 in
    if idx < ia then (nmov, sma, smb)
    else
    alice ia sma idx smb beat nmov v;;

let do_one () =
    let n = gr () in
    let a = readlist n [] in
		let a = (List.rev a) in
		let va = Array.of_list a in
		let nm,ca,cb = alice 0 0 (n-1) 0 0 0 va in
  	Printf.printf "%d %d %d\n" nm ca cb;;

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

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

main();;


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

let rec ind i t=if t.[i]=' ' then i else ind (i+1) t;;
let i=ind 0 s;;

let s1=String.sub s 0 i;;
let s2=String.sub s (i+1) (String.length(s)-i-1);;

let a=float_of_string(s1);;
let d=float_of_string(s2);;

let n=read_int();;

let frac b=b-.float_of_int(int_of_float(b));;

let bop b c=
print_float b;
print_string " ";
print_float c;
print_newline();;

let m=ref 0.;;

for i=1 to n do
   m:= !m+.d;
   let p=frac( !m/.(4.0*.a)) in
      if p<0.25 then bop (p*.4.0*.a) 0.0
      else if p<0.5 then bop a ((p-.0.25)*.4.0*.a)
      else if p<0.75 then bop (a-.(p-.0.5)*.4.0*.a) a
      else bop 0.0 (a-.(p-.0.75)*.4.0*.a);
      m:=(p*.4.0*.a)
done;;

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

let a = Scanf.scanf "%f " (fun x -> x);;
let d = Scanf.scanf "%f\n" (fun x -> x);;
let n = Scanf.scanf "%d" (fun x -> x);;

let distance = ref 0.;;

let modulo a b = a -. b *. floor (a /. b);;

for i=1 to n do
  distance := modulo (!distance +. d) (4.*.a);
  match int_of_float (!distance /. a) with
  | 0 -> print_float !distance;
         print_string " ";
         print_float 0.;
         print_string "\n"
  | 1 -> print_float a;
         print_string " ";
         print_float (!distance -. a);
         print_string "\n"
  | 2 -> print_float (3.*.a -. !distance);
         print_string " ";
         print_float a;
         print_string "\n"
  | 3 -> print_float 0.;
         print_string " ";
         print_float (4.*.a -. !distance);
         print_string "\n"
  | _ -> failwith "Erreur !!"
done;

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

let rec ind i t=if t.[i]=' ' then i else ind (i+1) t;;
let i=ind 0 s;;

let s1=String.sub s 0 i;;
let s2=String.sub s (i+1) (String.length(s)-i-1);;

let a=float_of_string(s1);;
let d=float_of_string(s2);;

let n=read_int();;

let frac b=b-.float_of_int(int_of_float(b));;

let bop b c=
print_float b;
print_string " ";
print_float c;
print_newline();;

for i=1 to n do
   let m=float_of_int(i)*.d in
      let p=frac(m/.(4.0*.a)) in
         if p<0.25 then bop (p*.4.0*.a) 0.0
         else if p<0.5 then bop a ((p-.0.25)*.4.0*.a)
         else if p<0.75 then bop (a-.(p-.0.5)*.4.0*.a) a
         else bop 0.0 (a-.(p-.0.75)*.4.0*.a)
done;;


open Printf open Scanf
module Lib = struct
	let i32,i64 = Int64.to_int,Int64.of_int
	let (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (%$) = (mod)
	let labs = Int64.abs
	let (+),(-),( * ),(/),(mod),(%) = Int64.add,Int64.sub,Int64.mul,Int64.div,Int64.rem,Int64.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
	(* 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 I64_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
	(* io *)
	let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf " %Ld" (fun v -> v))
	let get_i64 _ = Scanf.scanf " %Ld" (fun v -> v)
	let get_2_i64 _ = Scanf.scanf " %Ld %Ld" (fun u v -> u,v)
	let get_3_i64 _ = Scanf.scanf " %Ld %Ld %Ld" (fun u v w -> u,v,w)
	let get_4_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld" (fun u v w x -> u,v,w,x)
	let get_5_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld %Ld" (fun u v w x y -> u,v,w,x,y)
	let 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 *)
	let alen a = i64 @@ Array.length a
	let llen l = i64 @@ List.length l
	let string_of_list ?(separator=" ") f ls =
		let rec f0 a s = match a with
		| [] -> s | [h] -> s ^ (f h) ^ separator | h::t -> f0 t (s ^ (f h) ^ separator)
		in f0 ls ""
	let 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
	(* imperative *)
	let rep f t fbod = let i = ref f in while !i <= t do fbod !i; i := !i + 1L done
	let repf f t fbod = let i,c = ref f,ref true in while !i <= t && !c do
		match fbod !i with | `Break -> c := false | `Ok -> i := !i + 1L done
	let repm f t 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 + 1L done; !m
	let repi f t fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ 1 done
	let repif f t fbod = let i,c = ref f,ref true in while !i <= t && !c do
		match fbod !i with | `Break -> c := false | `Ok -> i := !i +$ 1 done
	let repim f t 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 +$ 1 done; !m
	(* debug *)
	let dump_list f ls = string_of_list f ls |> print_endline
	let dump_array f a = string_of_array f a |> print_endline
end open Lib

let binary_search ng ok f =
	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 let d = if ng < ok then 1L else -1L
	in f0 (ng-1L*d) (ok+1L*d)

(* let a,b = get_2_i64 0
let sum = binary_search (2000000018L) 0L (fun v -> v*(v+1L)/2L <= a+b)
let rec f0 ra rb la lb = function
	| 0L -> (la,lb)
	| v ->
		if ra > rb then f0 (ra-v) rb (v::la) lb (v-1L)
		else f0 ra (rb-v) la (v::lb) (v-1L)
let (la,lb) = f0 a b [] [] sum
let () =
	printf "%d\n" @@ List.length la;
	dump_list Int64.to_string la;
	printf "%d\n" @@ List.length lb;
	dump_list Int64.to_string lb; *)

let ist = Int64.to_string
let dump_list ls = ls
	|> List.map ist
	|> String.concat " "
	|> print_endline
let () =
	let a,b = get_2_i64 0 in
	let sum = binary_search (2000000018L) 0L (fun v -> v*(v+1L)/2L <= a+b)
	in
	(* printf "%Ld\n" sum; *)
	let d1,d2 = ref [],ref [] in
	let r1,r2 = ref a,ref b in
	(* rep 1L sum (fun i ->
		let i = sum - i + 1L in
		if !ra > !rb then (
			la := i::!la; ra -= i;
		) else (
			lb := i::!lb; rb -= i;
		)
	); *)
	let i = ref sum in
	while !i >= 1L do
		if !r2 <= !r1 then (
			r1 := !r1 - !i;
			d1 := !i :: !d1
		) else (
			r2 := !r2 - !i;
			d2 := !i :: !d2
		);
		i := !i - 1L
	done;
	printf "%d\n" @@ List.length !d1;
	dump_list !d1;
	printf "%d\n" @@ List.length !d2;
	dump_list !d2;

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
	(* 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 I64_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
	(* io *)
	let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf " %Ld" (fun v -> v))
	let get_i64 _ = Scanf.scanf " %Ld" (fun v -> v)
	let get_2_i64 _ = Scanf.scanf " %Ld %Ld" (fun u v -> u,v)
	let get_3_i64 _ = Scanf.scanf " %Ld %Ld %Ld" (fun u v w -> u,v,w)
	let get_4_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld" (fun u v w x -> u,v,w,x)
	let get_5_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld %Ld" (fun u v w x y -> u,v,w,x,y)
	let 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 *)
	let alen a = i64 @@ Array.length a
	let llen l = i64 @@ List.length l
	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
	(* imperative *)
	let rep f t fbod = let i = ref f in while !i <= t do fbod !i; i := !i + 1L done
	let repf f t fbod = let i,c = ref f,ref true in while !i <= t && !c do
		match fbod !i with | `Break -> c := false | `Ok -> i := !i + 1L done
	let repm f t 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 + 1L done; !m
	let repi f t fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ 1 done
	let repif f t fbod = let i,c = ref f,ref true in while !i <= t && !c do
		match fbod !i with | `Break -> c := false | `Ok -> i := !i +$ 1 done
	let repim f t 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 +$ 1 done; !m
	(* debug *)
	(* let dump_list f ls = ls |> List.map f |> String.concat " " |> print_endline
	let dump_array f a = a |> Array.to_list |> dump_list f *)
	let dump_list f ls = string_of_list f ls |> print_endline
end open Lib

let binary_search ng ok f =
	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 let d = if ng < ok then 1L else -1L
	in f0 (ng-1L*d) (ok+1L*d)

(* let a,b = get_2_i64 0
let sum = binary_search (2000000018L) 0L (fun v -> v*(v+1L)/2L <= a+b)
let rec f0 ra rb la lb = function
	| 0L -> (la,lb)
	| v ->
		if ra > rb then f0 (ra-v) rb (v::la) lb (v-1L)
		else f0 ra (rb-v) la (v::lb) (v-1L)
let (la,lb) = f0 a b [] [] sum
let () =
	printf "%d\n" @@ List.length la;
	dump_list Int64.to_string la;
	printf "%d\n" @@ List.length lb;
	dump_list Int64.to_string lb; *)

let ist = Int64.to_string
let () =
	let a,b = get_2_i64 0 in
	let sum = binary_search (2000000018L) 0L (fun v -> v*(v+1L)/2L <= a+b)
	in
	(* printf "%Ld\n" sum; *)
	let d1,d2 = ref [],ref [] in
	let r1,r2 = ref a,ref b in
	(* rep 1L sum (fun i ->
		let i = sum - i + 1L in
		if !ra > !rb then (
			la := i::!la; ra -= i;
		) else (
			lb := i::!lb; rb -= i;
		)
	); *)
	let i = ref sum in
	while !i >= 1L do
		if !r2 <= !r1 then (
			r1 := !r1 - !i;
			d1 := !i :: !d1
		) else (
			r2 := !r2 - !i;
			d2 := !i :: !d2
		);
		i := !i - 1L
	done;
	printf "%d\n" @@ List.length !d1;
	dump_list ist !d1;
	printf "%d\n" @@ List.length !d2;
	dump_list ist !d2;

let (++),(--),labs,(//),( ** ),i64,ist = Int64.(add,sub,abs,div,mul,of_int,to_string)
let binary_search ng ok f =
	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 let d = if ng < ok then 1L else -1L
	in f0 (ng--d) (ok++d)
let dump_list ls = ls
	|> List.map ist
	|> String.concat " "
	|> print_endline
let () = Scanf.scanf " %Ld %Ld" @@ fun a b ->
	let sum = binary_search 2000000018L 0L (fun v -> v**(v++1L)//2L <= a++b)
	in
	let d1,d2 = ref [], ref [] in
	let a = ref a in
	let i = ref sum in
	while !i >= 1L do
		if !i <= !a then (
			a := !a -- !i;
			d1 := !i :: !d1
		) else d2 := !i :: !d2;
		i := !i -- 1L
	done;
	Printf.printf "%d\n" @@ List.length !d1;
	dump_list !d1;
	Printf.printf "%d\n" @@ List.length !d2;
	dump_list !d2;

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
	(* 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 I64_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
	(* io *)
	let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf " %Ld" (fun v -> v))
	let get_i64 _ = Scanf.scanf " %Ld" (fun v -> v)
	let get_2_i64 _ = Scanf.scanf " %Ld %Ld" (fun u v -> u,v)
	let get_3_i64 _ = Scanf.scanf " %Ld %Ld %Ld" (fun u v w -> u,v,w)
	let get_4_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld" (fun u v w x -> u,v,w,x)
	let get_5_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld %Ld" (fun u v w x y -> u,v,w,x,y)
	let 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 *)
	let alen a = i64 @@ Array.length a
	let llen l = i64 @@ List.length l
	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
	(* imperative *)
	let rep f t fbod = let i = ref f in while !i <= t do fbod !i; i := !i + 1L done
	let repf f t fbod = let i,c = ref f,ref true in while !i <= t && !c do
		match fbod !i with | `Break -> c := false | `Ok -> i := !i + 1L done
	let repm f t 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 + 1L done; !m
	let repi f t fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ 1 done
	let repif f t fbod = let i,c = ref f,ref true in while !i <= t && !c do
		match fbod !i with | `Break -> c := false | `Ok -> i := !i +$ 1 done
	let repim f t 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 +$ 1 done; !m
	(* debug *)
	let dump_list f ls = string_of_list f ls |> print_endline
	let dump_array f a = string_of_array f a |> print_endline
	let dump_list_test f ls = List.iter (fun v -> printf "%s " @@ f v) ls; print_newline ()
end open Lib

let binary_search ng ok f =
	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 let d = if ng < ok then 1L else -1L
	in f0 (ng-1L*d) (ok+1L*d)

(* let a,b = get_2_i64 0
let sum = binary_search (2000000018L) 0L (fun v -> v*(v+1L)/2L <= a+b)
let rec f0 ra rb la lb = function
	| 0L -> (la,lb)
	| v ->
		if ra > rb then f0 (ra-v) rb (v::la) lb (v-1L)
		else f0 ra (rb-v) la (v::lb) (v-1L)
let (la,lb) = f0 a b [] [] sum
let () =
	printf "%d\n" @@ List.length la;
	dump_list Int64.to_string la;
	printf "%d\n" @@ List.length lb;
	dump_list Int64.to_string lb; *)

let ist = Int64.to_string
let () =
	let a,b = get_2_i64 0 in
	let sum = binary_search (2000000018L) 0L (fun v -> v*(v+1L)/2L <= a+b)
	in
	(* printf "%Ld\n" sum; *)
	let d1,d2 = ref [],ref [] in
	let r1,r2 = ref a,ref b in
	(* rep 1L sum (fun i ->
		let i = sum - i + 1L in
		if !ra > !rb then (
			la := i::!la; ra -= i;
		) else (
			lb := i::!lb; rb -= i;
		)
	); *)
	let i = ref sum in
	while !i >= 1L do
		if !r2 <= !r1 then (
			r1 := !r1 - !i;
			d1 := !i :: !d1
		) else (
			r2 := !r2 - !i;
			d2 := !i :: !d2
		);
		i := !i - 1L
	done;
	printf "%d\n" @@ List.length !d1;
	dump_list_test ist !d1;
	printf "%d\n" @@ List.length !d2;
	dump_list_test ist !d2;

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
	(* 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 I64_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
	(* io *)
	let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf " %Ld" (fun v -> v))
	let get_i64 _ = Scanf.scanf " %Ld" (fun v -> v)
	let get_2_i64 _ = Scanf.scanf " %Ld %Ld" (fun u v -> u,v)
	let get_3_i64 _ = Scanf.scanf " %Ld %Ld %Ld" (fun u v w -> u,v,w)
	let get_4_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld" (fun u v w x -> u,v,w,x)
	let get_5_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld %Ld" (fun u v w x y -> u,v,w,x,y)
	let 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 *)
	let alen a = i64 @@ Array.length a
	let llen l = i64 @@ List.length l
	let string_of_list ?(separator=" ") f ls =
		let rec f0 a s = match a with
		| [] -> s | [h] -> s ^ (f h) ^ separator | h::t -> f0 t (s ^ (f h) ^ separator)
		in f0 ls ""
	let 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
	(* imperative *)
	let rep f t fbod = let i = ref f in while !i <= t do fbod !i; i := !i + 1L done
	let repf f t fbod = let i,c = ref f,ref true in while !i <= t && !c do
		match fbod !i with | `Break -> c := false | `Ok -> i := !i + 1L done
	let repm f t 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 + 1L done; !m
	let repi f t fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ 1 done
	let repif f t fbod = let i,c = ref f,ref true in while !i <= t && !c do
		match fbod !i with | `Break -> c := false | `Ok -> i := !i +$ 1 done
	let repim f t 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 +$ 1 done; !m
	(* debug *)
	let dump_list_slow f ls = string_of_list f ls |> print_endline
	let dump_array_slow f a = string_of_array f a |> print_endline
	let dump_i64_list ls = ls
		|> List.map ist
end open Lib

let binary_search ng ok f =
	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 let d = if ng < ok then 1L else -1L
	in f0 (ng-1L*d) (ok+1L*d)

(* let a,b = get_2_i64 0
let sum = binary_search (2000000018L) 0L (fun v -> v*(v+1L)/2L <= a+b)
let rec f0 ra rb la lb = function
	| 0L -> (la,lb)
	| v ->
		if ra > rb then f0 (ra-v) rb (v::la) lb (v-1L)
		else f0 ra (rb-v) la (v::lb) (v-1L)
let (la,lb) = f0 a b [] [] sum
let () =
	printf "%d\n" @@ List.length la;
	dump_list Int64.to_string la;
	printf "%d\n" @@ List.length lb;
	dump_list Int64.to_string lb; *)

let ist = Int64.to_string
let dump_list f ls = ls
	|> List.map f
	|> String.concat " "
	|> print_endline
let () =
	let a,b = get_2_i64 0 in
	let sum = binary_search (2000000018L) 0L (fun v -> v*(v+1L)/2L <= a+b)
	in
	(* printf "%Ld\n" sum; *)
	let d1,d2 = ref [],ref [] in
	let r1,r2 = ref a,ref b in
	(* rep 1L sum (fun i ->
		let i = sum - i + 1L in
		if !ra > !rb then (
			la := i::!la; ra -= i;
		) else (
			lb := i::!lb; rb -= i;
		)
	); *)
	let i = ref sum in
	while !i >= 1L do
		if !r2 <= !r1 then (
			r1 := !r1 - !i;
			d1 := !i :: !d1
		) else (
			r2 := !r2 - !i;
			d2 := !i :: !d2
		);
		i := !i - 1L
	done;
	printf "%d\n" @@ List.length !d1;
	dump_list ist !d1;
	printf "%d\n" @@ List.length !d2;
	dump_list ist !d2;

let (++),(--),labs,(//),( ** ),i64,ist = Int64.(add,sub,abs,div,mul,of_int,to_string)
let binary_search ng ok f =
	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 let d = if ng < ok then 1L else -1L
	in f0 (ng--d) (ok++d)
let dump_list ls = ls
	|> List.map ist
	|> String.concat " "
	|> print_endline
let () = Scanf.scanf " %Ld %Ld" @@ fun a b ->
	let sum = binary_search 2000000018L 0L (fun v -> v**(v++1L)//2L <= a++b)
	in
	let d1,d2 = ref [], ref [] in
	let r1,r2 = ref a, ref b in
	let i = ref sum in
	while !i >= 1L do
		if !r2 <= !r1 then (
			r1 := !r1 -- !i;
			d1 := !i :: !d1
		) else (
			r2 := !r2 -- !i;
			d2 := !i :: !d2
		);
		i := !i -- 1L
	done;
	Printf.printf "%d\n" @@ List.length !d1;
	dump_list !d1;
	Printf.printf "%d\n" @@ List.length !d2;
	dump_list !d2;


type spruce = Leaf of int
            | Node of spruce list

let rec split num str =
  match str with
  | "" -> []
  | s ->
    let (beg, rest) = (String.sub str 0 num, String.sub str num(String.length str - num)) in
    beg :: (split num rest)

let rec returnIntList strList one =
  match strList with
  | h :: t -> if (compare h " " == 0 || compare h "\n" == 0) then
    (int_of_string one) ::(returnIntList t "")
    else returnIntList t (one^h)
  | _ -> (int_of_string one) :: []

let splitToList line =
  let lineList = split 1 line in
  returnIntList lineList ""

let rec makePairList numList num =
  match numList with
  | h :: t -> (h, num) :: (makePairList t (num+1))
  | _ -> []

let rec makeNode pairList num =
  match pairList with
  | (a,b) :: t ->
    if (num == a) then
      Node (Leaf(b) :: (makeNode t b)) :: (makeNode t num)
    else makeNode t num
  | _ -> []

let rec countLeaf node =
  match node with
  | Node(Leaf(a) :: []) ::t -> 1 + countLeaf t
  | Node(Leaf(a) :: t) :: tail -> countLeaf tail
  | _ -> 0

let rec checkNotAllNode node =
  match node with
  | Node (Leaf(b) :: []) :: tail -> true
  | Node (Leaf(a) :: t) :: [] -> false
  | Node (Leaf(a) :: t) :: tail -> checkNotAllNode tail
  | _ -> true

let rec countSpruce spruce =
  match spruce with
  | Node (Leaf(a) :: t) :: tail ->
    let num = countLeaf t in
    if (num >= 3 || num == 0) && (checkNotAllNode t) == true then
      countSpruce t && countSpruce tail
    else false
  | _ -> true

let printLeaf leaf =
  match leaf with
  | Leaf(a) -> print_string "[Leaf : ";print_int a; print_string "]"
  | _ -> print_string " "

let rec printNode node =
  match node with
  | Node (h :: t) :: tail ->
    print_string "[Node : ";printLeaf h; printNode t;print_string"]";
    printNode tail
  | _ -> print_string " "

let n = read_int()
let rec numList k =
  if (k < n) then
    let m = read_int() in
    m :: (numList (k+1))
  else []

let pairList = makePairList (numList 1) 2

let newSpruce =
  Node (Leaf(1) :: (makeNode pairList 1)) :: []

let _ =
  if (countSpruce newSpruce) then print_string "Yes"
  else print_string "No"

(* Codeforces 913 B Christmas Spruce *)

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

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

let rec revert l acc = match l with
	| [] -> acc
	| h :: t ->
			let aa = h :: acc in
			revert t aa;;

let rec setna na li idx =
	if idx = 0 then
		begin
			na.(0) <- [];
			setna na li (idx + 1)
		end
	else
		match li with
		| [] -> ()
		| h :: t ->
				begin
					na.(h - 1) <- idx :: na.(h - 1);
					setna na t (idx + 1)
				end;;

(* count elements of numa array with idndexes in li *)
let rec arr_count numa li = match li with
	| [] -> 0
	| h :: t -> numa.(h) + arr_count numa t;;

let is_leaf li = match li with
	| [] -> 1
	| _ -> 0;;

(* count lefes for current root, returns (isLeaf, good) *)
let check_node na is_leafa idx =
	(* let _ = begin
		print_string "\n check_node ";
		print_int idx;
	    print_string " na_idx ";
			printlisti na.(idx)
	 end in *)
	let lcnt = arr_count is_leafa na.(idx) in
	if is_leafa.(idx) = 0 then lcnt >= 3
	else true;;

let rec all_true idx f nmax =
	if idx < nmax then (f idx) && all_true (idx + 1) f nmax
	else true;;

let main() =
	let n = gr() in
	let a = readlist (n - 1) [] in
	let ar = revert a [] in
  (* let _ = printlisti ar in *)
	let na = Array.make n [] in
	let _ = setna na ar 0 in
	let is_leafa = Array.map is_leaf na in
	begin
		(*print_string "\n is_leafa: ";
		printarri is_leafa;*)
		let simp_check i = check_node na is_leafa i in
		let ok = all_true 0 simp_check n in
		if ok then print_string "Yes"
		else print_string "No"
	end;;

main();;

type spruce = Leaf of int
            | Node of spruce list

let rec split num str =
  match str with
  | "" -> []
  | s ->
    let (beg, rest) = (String.sub str 0 num, String.sub str num(String.length str - num)) in
    beg :: (split num rest)

let rec returnIntList strList one =
  match strList with
  | h :: t -> if (compare h " " == 0 || compare h "\n" == 0) then
    (int_of_string one) ::(returnIntList t "")
    else returnIntList t (one^h)
  | _ -> (int_of_string one) :: []

let splitToList line =
  let lineList = split 1 line in
  returnIntList lineList ""

let rec makePairList numList num =
  match numList with
  | h :: t -> (h, num) :: (makePairList t (num+1))
  | _ -> []

let rec makeNode pairList num =
  match pairList with
  | (a,b) :: t ->
    if (num == a) then
      Node (Leaf(b) :: (makeNode t b)) :: (makeNode t num)
    else makeNode t num
  | _ -> []

let rec countLeaf node =
  match node with
  | Node(Leaf(a) :: []) ::t -> 1 + countLeaf t
  | Node(Leaf(a) :: t) :: tail -> countLeaf tail
  | _ -> 0

let rec checkNotAllNode node =
  match node with
  | Node (Leaf(b) :: []) :: tail -> true
  | Node (Leaf(a) :: t) :: [] -> false
  | Node (Leaf(a) :: t) :: tail -> checkNotAllNode tail
  | _ -> true

let rec countSpruce spruce =
  match spruce with
  | Node (Leaf(a) :: t) :: tail ->
    let num = countLeaf t in
    if (num == 3 || num == 0) && (checkNotAllNode t == true) then
      countSpruce t && countSpruce tail
    else false
  | _ -> true

let printLeaf leaf =
  match leaf with
  | Leaf(a) -> print_string "[Leaf : ";print_int a; print_string "]"
  | _ -> print_string " "

let rec printNode node =
  match node with
  | Node (h :: t) :: tail ->
    print_string "[Node : ";printLeaf h; printNode t;print_string"]";
    printNode tail
  | _ -> print_string " "

let n = read_int()
let rec numList k =
  if (k < n) then
    let m = read_int() in
    m :: (numList (k+1))
  else []

let pairList = makePairList (numList 1) 2

let newSpruce =
  Node (Leaf(1) :: (makeNode pairList 1)) :: []

let _ =
  if (countSpruce newSpruce) then print_string "Yes"
  else print_string "No"

type spruce = Leaf of int
            | Node of spruce list

let rec split num str =
  match str with
  | "" -> []
  | s ->
    let (beg, rest) = (String.sub str 0 num, String.sub str num(String.length str - num)) in
    beg :: (split num rest)

let rec returnIntList strList one =
  match strList with
  | h :: t -> if (compare h " " == 0 || compare h "\n" == 0) then
    (int_of_string one) ::(returnIntList t "")
    else returnIntList t (one^h)
  | _ -> (int_of_string one) :: []

let splitToList line =
  let lineList = split 1 line in
  returnIntList lineList ""

let rec makePairList numList num =
  match numList with
  | h :: t -> (h, num) :: (makePairList t (num+1))
  | _ -> []

let rec makeNode pairList num =
  match pairList with
  | (a,b) :: t ->
    if (num == a) then
      Node (Leaf(b) :: (makeNode t b)) :: (makeNode t num)
    else makeNode t num
  | _ -> []

let rec countLeaf node =
  match node with
  | Node(Leaf(a) :: []) ::t -> 1 + countLeaf t
  | Node(Leaf(a) :: t) :: tail -> countLeaf tail
  | _ -> 0

let rec countSpruce spruce =
  match spruce with
  | Node (Leaf(a) :: t) :: tail ->
    let num = countLeaf t in
    if (num == 3 || num == 0) then
      countSpruce t && countSpruce tail
    else false
  | _ -> true

let printLeaf leaf =
  match leaf with
  | Leaf(a) -> print_string "[Leaf : ";print_int a; print_string "]"
  | _ -> print_string " "

let rec printNode node =
  match node with
  | Node (h :: t) :: tail ->
    print_string "[Node : ";printLeaf h; printNode t;print_string"]";
    printNode tail
  | _ -> print_string " "

let n = read_int()
let rec numList k =
  if (k < n) then
    let m = read_int() in
    m :: (numList (k+1))
  else []

let pairList = makePairList (numList 1) 2

let newSpruce =
  Node (Leaf(1) :: (makeNode pairList 1)) :: []

let _ =
  if (countSpruce newSpruce) then print_string "Yes"
  else print_string "No"


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

let check int n =
    if int >= n
    then
        true
    else
        false

let () =
    let n = read () in
    let rec loop i quart half =
        if i < n
        then
            let cash = read () in
            match cash with
            | 25 -> loop (i + 1) (quart + 1) half
            | 50 ->
                if check quart 1
                then
                    loop (i + 1) (quart - 1) (half + 1)
                else
                    print "NO"
            | 100 ->
                if check half 1 && check quart 1
                then
                    loop (i + 1) (quart - 1) (half - 1)
                else
                    if check quart 3
                    then
                        loop (i + 1) (quart - 3) half
                    else
                        print "NO"
        else
            print "YES"
    in loop 0 0 0

(* Codeforces 349 A Cinema Line *)

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

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

let rec can_change l n50 n25 = match l with
	| [] -> "YES"
	| h :: t -> match h with
			| 25 -> can_change t n50 (n25 + 1)
			| 50 -> if n25 ==0 then "NO" else can_change t (n50 +1) (n25 -1)
			| 100 -> if (2 * n50 + n25 < 3) || (n25 == 0)then "NO"
					else if n50 >0 then can_change t (n50 -1) (n25 -1)
					else can_change t n50 (n25 -3)
			| _ -> "Error, wrong n";;

let main() =
	let n = gr() in
	let l = readlist (n) [] in
	let li = List.rev l in
	let ans = can_change li 0 0 in
	begin
		print_string (ans ^ "\n")
	end;;

main();;

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

let check int n =
    if int >= n
    then
        true
    else
        false

let () =
    let n = read () in
    let rec loop i quart half =
        if i < n
        then
            let cash = read () in
            match cash with
            | 25 -> loop (i + 1) (quart + 1) half
            | 50 ->
                if check quart 1
                then
                    loop (i + 1) (quart - 1) (half + 1)
                else
                    print "NO"
            | 100 ->
                if check half 1 && check quart 1 || check quart 3
                then
                    loop (i + 1) (quart - 1) (half - 1)
                else
                    if check quart 3
                    then
                        loop (i + 1) (quart - 3) half
                    else
                        print "NO"
        else
            print "YES"
    in loop 0 0 0

(* Codeforces 349 A Cinema Line *)

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

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

let rec can_change l n50 n25 = match l with
	| [] -> "YES"
	| h :: t -> match h with
			| 25 -> can_change t n50 (n25 + 1)
			| 50 -> if n25 ==0 then "NO" else can_change t (n50 +1) (n25 -1)
			| 100 -> if (2 * n50 + n25 < 3) || (n50 == 0)then "NO"
					else if n50 >0 then can_change t (n50 -1) (n25 -1)
					else can_change t n50 (n25 -3)
			| _ -> "Error, wrong n";;

let main() =
	let n = gr() in
	let l = readlist (n) [] in
	let li = List.rev l in
	let ans = can_change li 0 0 in
	begin
		print_string (ans ^ "\n")
	end;;

main();;


let list_init n f =
  let rec read_input n new_list =
    if n > 0
    then
      let new_element = f() in
      read_input (n - 1) (new_element :: new_list)
    else
      List.rev new_list
  in read_input n []

let room_data n = list_init n (fun i -> Scanf.scanf "%d %d " (fun s0 s1 -> (s0, s1)))

let input () =
  let number_of_rooms = Scanf.scanf "%d " (fun n -> n) in
  room_data number_of_rooms

let solve list = List.length(List.filter(fun (a, b) -> b - a >= 2) list)

let print result = Printf.printf "%d\n" result

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

let list_init n f =
    let rec read_input n new_list =
        if n > 0
        then
            let new_element = f() in
            read_input (n - 1) (new_element :: new_list)
        else
            List.rev new_list
    in read_input n []

let room_data n = list_init n (fun i -> Scanf.scanf "%d %d " (fun s0 s1 -> (s0, s1)))

let input () =
    let number_of_rooms = Scanf.scanf "%d " (fun n -> n) in
    room_data number_of_rooms

let solve list = List.length(List.filter(fun (a, b) -> b - a >= 2) list)

let print result = Printf.printf "%d\n" result

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

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

let rec solve n ak =
  if n = 0 then
    ak
  else
    let p = read_int () in
    let q = read_int () in
    if q - p < 2 then
      solve (n - 1) ak
    else
      solve (n - 1) (ak + 1)

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

open Printf
type room = R of int*int

let n =  Scanf.scanf "%d " ( fun x -> x) in
let read_int () =  Scanf.scanf "%d %d " ( fun x y -> R(x,y)) in
let a = Array.init n (fun i -> read_int ()) in
let f = function
  | R (p,q) -> if q-p >=2 then true else false
in Array.to_list a |>List.filter (fun x -> f x) |> List.length |> printf "%d\n"

open Scanf
open Printf

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

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

  print_int (Array.fold_left (fun acc pair -> if (fst(pair) + 2 <= snd(pair)) then acc + 1 else acc) 0 a);
  print_newline ();


let [x; a; b] = List.map (Int64.of_string) (Str.split (Str.regexp " ") (read_line ()));;
let k = ref (Int64.div a x);;
if ((Int64.mul !k x) < a) then k := Int64.add !k 1L;;
let t = Int64.sub b (Int64.mul x !k) and ans = ref 0L;;
if t >= 0L then	ans := Int64.add (Int64.div t x) 1L;;
print_string (Int64.to_string !ans);;

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

let _ =
  let sb = Scanf.Scanning.stdib in
  let c = Scanf.bscanf sb "%Ld " (fun s -> s) in
  let a = Scanf.bscanf sb "%Ld " (fun s -> s) in
  let b = Scanf.bscanf sb "%Ld " (fun s -> s) in
  let quot x y =
    let d = x /| y in
    let x' = d *| y in
      if x' <= x
      then d
      else d -| 1L
  in
  let res = quot b c -| quot (a -| 1L) c in
    Printf.printf "%Ld\n" res


open Printf
open Scanf

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

  let cells = Array.make (n*m) (0,0) in

  let next (x,y) =
    if x land 1 = 1 (* left to right *) then
      if y<m then (x,y+1) else (x+1,m)
    else
      if y>1 then (x,y-1) else (x+1,1)
  in

  let rec loop i p = if fst p = n+1 then () else (
    cells.(i) <- p;
    loop (i+1) (next p)
  )
  in

  loop 0 (1,1);

  let small_size = (n*m)/k in
  let big_size = small_size+1 in

(*
  let rec find_mult remain sc = if remain=0 then sc else
      if remain mod big_size = 0 then sc else
	find_mult (remain-small_size) (sc+1)
  in
*)

  let rec find_count c =
    if c*small_size + (k-c)*big_size = n*m then c else find_count (c+1)
  in

  let scount = find_count 1 in

  let bcount = (n*m - scount * small_size)/big_size in

  if scount+bcount <> k then failwith "count wrong";

  let rec loop i p = if i=k then () else
      if i<scount then (
	printf "%d" small_size;
	for j=0 to small_size-1 do
	  let (x,y) = cells.(j+p) in
	  printf " %d %d" x y;
	done;
	print_newline();
	loop (i+1) (p+small_size)
      ) else (
	printf "%d" big_size;
	for j=0 to big_size-1 do
	  let (x,y) = cells.(j+p) in
	  printf " %d %d" x y;
	done;
	print_newline();
	loop (i+1) (p+big_size)
      )
  in

  loop 0 0;

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

let tab=Array.make (k+1) [];;
let a=(n*m)/k;;

let suivant i j s=
   if (s="droite")&&(j<m) then (i,j+1,s)
   else if (s="droite") then (i+1,j,"gauche")
   else if (s="gauche")&&(j>1) then (i,j-1,s)
   else (i+1,j,"droite");;

let i=ref 1;;
let j=ref 0;;
let s=ref "droite";;

for l=1 to k-1 do
   for o=1 to a do
      let (x,y,z)=suivant (!i) (!j) (!s) in
      i:=x;
      j:=y;
      s:=z;
      tab.(l)<-(!i,!j)::tab.(l)
   done
done;;
for o=1 to a+((n*m) mod k) do
   let (x,y,z)=suivant (!i) (!j) (!s) in
   i:=x;
   j:=y;
   s:=z;
   tab.(k)<-(!i, !j)::tab.(k)
done;;
let rec taille=function
|[]->0
|(_,_)::t->1+taille t;;
let rec print_list=function
|[]->print_newline()
|(h,g)::t->Printf.printf "%d %d " h g;print_list t;;
for i=1 to k do
   Printf.printf "%d " (taille tab.(i));
   print_list tab.(i)
done;;


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

let () =
  let n,k = g2 0 in
  let a = iia n in
  let s = scanf " %s" @@ id in
  let r =
    let r = ref [] in
    let now = ref s.[0] in
    let cnt = ref 1L in
    let dmgs = ref [a.(0)] in
    String.iteri (fun i c ->
      if i=0 then ()
      else (
        if !now = c then (
          cnt += 1L;
          dmgs := a.(i) :: !dmgs;
        ) else (
          r := (List.sort (rv compare) !dmgs) :: !r;
          dmgs := a.(i) :: [];
          cnt := 1L;
        );
        now := c
      )
    ) s;
    if !cnt <> 0L then r := (List.sort (rv compare) !dmgs) :: !r;
    List.rev @@ !r
  in
  (* print_list (fun s -> string_of_list ist s ^ "\n") r; *)
  List.fold_left (fun sum ls ->
    if llen ls <= k then (
      sum + List.fold_left (+) 0L ls
    ) else (
      let s = ref 0L in
      List.iteri (fun i v -> if i64 i < k then s += v) ls;
      sum + !s
    )
  ) 0L r |> printf "%Ld"

let rv f p q = f q p
let rec fix f x = f (fix f) x
let (++),( ** ),(--) = Int64.(add,mul,sub)
;;
Scanf.(Array.(scanf " %d %d" @@ fun n k ->
  let a = init n (fun _ -> scanf " %Ld" @@ fun v -> v) in
  let s = scanf " %s" @@ fun v -> v in
  let sects = fix (fun f i ls all ->
    if i=0 then
      f (i+1) (a.(i)::ls) all
    else if i=n then
      if List.length ls <> 0 then (List.sort (rv compare) ls)::all
      else all
    else
      if s.[i] = s.[i-1] then
        f (i+1) (a.(i)::ls) all
      else
        f (i+1) [a.(i)] ((List.sort (rv compare) ls)::all)
  ) 0 [] []
  in
  Printf.printf "%Ld" @@
    List.fold_left (fun sum ls ->
      if List.length ls <= k then
        sum ++ List.fold_left (++) 0L ls
      else
        sum ++ snd (List.fold_left (fun (i,sum) v ->
          if i<k then (i+1,sum++v) else (i+1,sum)
        ) (0,0L) ls)
    ) 0L sects
))

let rv f p q = f q p
let (++),( ** ),(--) = Int64.(add,mul,sub);;
Scanf.(Array.(scanf " %d %d" @@ fun n k ->
  let a = init n (fun _ -> scanf " %Ld" @@ fun v -> v) in
  let b =
    let s = scanf " %s" @@ fun v -> v in
    init n (fun i -> s.[i])
  in
  let sects =
    let _,_,ls,all = fold_left (fun (i,prev,ls,all) c ->
      if i=0 then
        (i+1,c,a.(i)::ls,all)
      else
        if prev=c then
          (i+1,c,a.(i)::ls,all)
        else
          (i+1,c,[a.(i)],(List.sort (rv compare) ls)::all)
    ) (0,'_',[],[]) b
    in
    if List.length ls <> 0 then (List.sort (rv compare) ls)::all
    else all
  in
  Printf.printf "%Ld" @@
    List.fold_left (fun sum ls ->
      if List.length ls <= k then
        sum ++ List.fold_left (++) 0L ls
      else
        sum ++ snd (List.fold_left (fun (i,sum) v ->
          if i<k then (i+1,sum++v) else (i+1,sum)
        ) (0,0L) ls)
    ) 0L sects))

let rv f p q = f q p
let rec fix f x = f (fix f) x
;;
Scanf.(Array.(scanf " %d %d" @@ fun n k ->
  let a = init n (fun _ -> scanf " %d" @@ fun v -> v) in
  let s = scanf " %s" @@ fun v -> v in
  let sects = fix (fun f i ls all ->
    if i=0 then
      f (i+1) (a.(i)::ls) all
    else if i=n then
      if List.length ls <> 0 then (List.sort (rv compare) ls)::all
      else all
    else
      if s.[i] = s.[i-1] then
        f (i+1) (a.(i)::ls) all
      else
        f (i+1) [a.(i)] ((List.sort (rv compare) ls)::all)
  ) 0 [] []
  in
  print_int @@
    List.fold_left (fun sum ls ->
      if List.length ls <= k then
        sum + List.fold_left (+) 0 ls
      else
        sum + snd (List.fold_left (fun (i,sum) v ->
          if i<k then (i+1,sum+v) else (i+1,sum)
        ) (0,0) ls)
    ) 0 sects
))

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

let () =
  let n,k = g2 0 in
  let a = iia n in
  let s = scanf " %s" @@ id in
  let r =
    let r = ref [] in
    let now = ref s.[0] in
    let cnt = ref 1L in
    let dmgs = ref [a.(0)] in
    String.iteri (fun i c ->
      if i=0 then ()
      else (
        if !now = c then (
          cnt += 1L;
          dmgs := a.(i) :: !dmgs;
        ) else (
          r := (List.sort (rv compare) !dmgs) :: !r;
          dmgs := a.(i) :: [];
          cnt := 1L;
        );
        now := c
      )
    ) s;
    if !cnt <> 0L then r := (List.sort (rv compare) !dmgs) :: !r;
    List.rev @@ !r
  in
  print_list (fun s -> string_of_list ist s ^ "\n") r;
  List.fold_left (fun sum ls ->
    if llen ls <= k then (
      sum + List.fold_left (+) 0L ls
    ) else (
      let s = ref 0L in
      List.iteri (fun i v -> if i64 i < k then s += v) ls;
      sum + !s
    )
  ) 0L r |> printf "%Ld"