open Printf
open String
open Bigarray
open Num

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

let dp = Array.init (n1+2) (fun _ -> Array.make 3 (num_of_int (-10)) )

let modn = num_of_int 1000000007

let rec ways n flag =
  if n=  0 then
    if flag=1 then num_of_int 1
    else num_of_int 0
  else if n< 0 then
    num_of_int 0
  else
    begin
      let x = dp.(n).(flag) in
      if x >=/ num_of_int 0 then
        x
      else
        begin
          let cnt = ref (num_of_int 0) in
          for i = 1 to d-1 do
            cnt := !cnt +/ (ways (n-i) flag)
          done;
          for i = d to k do
            cnt := !cnt +/ (ways (n-i) 1)
          done; cnt:=mod_num !cnt modn; dp.(n).(flag)<- !cnt; !cnt
        end
    end

let rslt = ways n1 0

let _ = printf "%s\n" (string_of_num rslt)

(* compiled on 64-bit system with ocamlopt -pp camlp4o $file *)

open Printf
open Scanf
open Array

module S = String
module Q = Queue
module T = Stack
module H = Hashtbl
module L = List

(* misc *)
let neg_compare x y = - compare x y
let min3 a b c = min a (min b c)
let mid3 a b c = if a < b then max a (min b c) else max b (min a c)
let max3 a b c = max a (max b c)
let min4 a b c d = min (min a b) (min c d)
let max4 a b c d = max (max a b) (max c d)
let itb a = a <> 0
let bti b = if b then 1 else 0
let rec bsearch_min a b test =
  if b - a = 1 then b else
  let mid = (a-b)/2 + b in
  if test mid then bsearch_min a mid test else
  bsearch_min mid b test
let rec bsearch_max a b test =
  if b - a = 1 then a else
  let mid = (a-b)/2 + b in
  if test mid then bsearch_max mid b test else
  bsearch_max a mid test
(* int *)
let sqrt_floor n = bsearch_max 0 (1 lsl 31) (fun i -> i*i <= n)
let sqrt_ceil n = bsearch_min (-1) (1 lsl 31) (fun i -> n <= i*i)
(* float *)
let round f = truncate (f +. 0.5)
let inv_float f = 1. /. f
(* functional *)
let id x = x
let const x _ = x
let (|>) x f = f x
let (^>) x f = f x
let (@@) a b = a b
let on g f a b = g (f a) (f b)
let rec fix f = f (fun x -> fix f x)
let ift cond a = if cond then a
let ifte cond a b = if cond then a else b
let rec for_ i len c f = if i = len then c else for_ (i+1) len (f i c) f
(* predicate *)
let is_odd x = x land 1 = 1
let is_even x = x land 1 = 0
(* option *)
let is_none = function | Some _ -> false | None -> true
let is_some = function | Some _ -> true | None -> false
let default x = function Some y -> y | None -> x
(* ref *)
let (+=) a b = a := !a + b
let (-=) a b = a := !a - b
let ( *= ) a b = a := !a * b
let assign_min x y = x := min !x y
let assign_max x y = x := max !x y
(* array *)
let set_min x i v = x.(i) <- min x.(i) v
let set_max x i v = x.(i) <- max x.(i) v
let swap arr i j = let t = arr.(i) in arr.(i) <- arr.(j); arr.(j) <- t
(* int, int *)
let (++) (a,b) (c,d) = (a+c,b+d)
let (--) (a,b) (c,d) = (a-c,b-d)
(* Arithmetic *)
let negate x = -x
let rec factorial n = if n = 0 then 1 else n * factorial (n-1)
let rec gcd a b = if b = 0 then a else gcd b (a mod b)
let rec extgcd a b =
  if b = 0 then 1,0,a else
  let x,y,g = extgcd b (a mod b) in
  y,x-(a/b)*y,g
let rec pow x n = if n = 0 then 1 else
  let n' = n/2 in
  let p = pow x n' in
  if is_odd n then x*p*p else p*p
let rec modpow m x n =
  if n = 0 then 1 else
  let n' = n/2 in
  let p = modpow m x n' in
  if is_even n then (p*p mod m) else
  (x*(p*p mod m) mod m)
let modinv m i = let _,x,_ = extgcd m i in x
(* IO *)
let is_digit c =
  let i = int_of_char c in
  48 <= i && i < 58
let is_space c = c = ' ' || c = '\n' || c = '\t' || c = '\r'
let read_char () = try input_char stdin with End_of_file -> '\000'
let rec read_letter () =
  let c = read_char() in
  if is_space c then read_letter() else c
let read_int () =
  let digit c = int_of_char c - 48 in
  let rec read n =
    let c = read_char() in
    if is_digit c then read (10*n + (digit c)) else
    n
  in
  let rec run c =
    if is_digit c then read (digit c) else
    if c = '-' then begin
      let c = read_char() in
      if is_digit c then -read (digit c) else run c
    end else
    if c = '\000' then 0 else
    run (read_char())
  in
  run (read_char())
let read_float () =
  let digit c = float (int_of_char c - 48) in
  let rec read_decimial m f =
    let c = read_char () in
    if is_digit c then read_decimial (m /. 10.) (f +. m *. digit c) else f
  in
  let rec read_integral n =
    let c = read_char () in
    if is_digit c then read_integral (10. *. n +. digit c) else
    if c = '.' then n +. read_decimial 0.1 0.0 else
    n
  in
  let rec run c = begin
    if is_digit c then read_integral (digit c) else
    if c = '-' then begin
      let c = read_char() in
      if is_digit c then -. read_integral (digit c) else
      run c
    end else
    if c = '.' then read_decimial 0.1 0.0 else
    if c = '\000' then 0.0 else
    run (read_char())
  end in
  run (read_char())
let read_word () =
  let open Buffer in
  let buf = create 128 in
  let rec read c =
    if is_space c || c = '\000' then contents buf else begin
      add_char buf c;
      read (read_char())
    end
  in
  let rec run c =
    if is_space c then run (read_char()) else
    if c = '\000' then "" else
    read c
  in
  run (read_char())
let read_line () =
  let open Buffer in
  let buf = create (4*1024) in
  let rec run c =
    if c = '\n' || c = '\000' then contents buf else begin
      add_char buf c;
      run (read_char())
    end
  in
  run (read_char())
let newline () = print_newline()
let print_int n = printf "%d\n" n
let print_tuple s (x,y) = printf s x y
let print_array s arr = Array.iter (printf s) arr; print_newline()
let print_matrix s mat = Array.iter (print_array s) mat
let print_list s lis = List.iter (printf s) lis; print_newline()
;;

let read_int64 () =
  let digit c = Int64.of_int( int_of_char c - 48 )in
  let rec read n =
    let c = read_char() in
    if is_digit c then read (Int64.add (Int64.mul 10L n) (digit c)) else
    n
  in
  let rec run c =
    if is_digit c then read (digit c) else
    if c = '-' then begin
      let c = read_char() in
      if is_digit c then Int64.neg (read (digit c)) else run c
    end else
    if c = '\000' then 0L else
    run (read_char())
  in
  run (read_char())

module LL = struct
  include Int64
  let (+) a b = add a b
  let (-) a b = sub a b
  let ( * ) a b = mul a b
  let (/) a b = div a b
  let (mod) a b = rem a b
  let (land) a b = logand a b
  let (lor) a b = logor a b
  let (lxor) a b = logxor a b
  let (lnot) a = lognot a
end

let modulo = 1_000_000_007L

let isum n up =
  let arr = make (LL.to_int n + 1) (-1L) in
  let read n = arr.(LL.to_int n) in
  let save n v = arr.(LL.to_int n) <- v; v in

  let rec run (n: int64) = LL.(
    if read n <> -1L then read n else
    let ans =
      if n <= 1L then 1L else
      let t = 2L * run (n-1L) mod modulo in
      if n <= up then t else
      (t - run (n-1L-up)) mod modulo
    in
    save n ans
  ) in
  if up = 0L then 0L else LL.((run n + modulo) mod modulo)

let _ =
  let n = read_int64() in
  let k = read_int64() in
  let d = read_int64() in
  let ans = LL.( (isum n k - isum n (d-1L) + modulo) mod modulo) in
  printf "%s\n" (LL.to_string ans)

(* let _ =
  for i = 0 to 10 do
    let i = LL.of_int i in
    printf "%s\n" (LL.to_string (isum i i))
  done *)

open Printf
open Scanf

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

let mm = 1000000007L

let ( ++ ) a b =
  let a = Int64.of_int a in
  let b = Int64.of_int b in
  let ans = Int64.rem (Int64.add a b) mm in
  Int64.to_int ans

let () =
  let n = read_int () in
  let k = read_int () in
  let d = read_int () in

  let a = Array.make_matrix (n+1) (n+k+1) 0 in
  let b = Array.make_matrix (n+1) (n+k+1) 0 in

  a.(0).(0) <- 1;

  let count = ref 0 in

  let rec pass i =
    (* job is to fill in the i+1 st position and continue *)
    if i+1 > n then () else (
      for s=0 to n do
	for v = 1 to k do
	  if v < d then a.(i+1).(s+v) <- a.(i+1).(s+v) ++ a.(i).(s);
	  b.(i+1).(s+v) <- b.(i+1).(s+v) ++ b.(i).(s);
	  if v >= d then b.(i+1).(s+v) <- b.(i+1).(s+v) ++ a.(i).(s);
	done
      done;
      count := !count ++ b.(i+1).(n);
      pass (i+1)
    )
  in

  pass 0;

  printf "%d\n" !count

open Printf
open Scanf

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

let mm = 1000000007L

let ( ++ ) a b =
  let a = Int64.of_int a in
  let b = Int64.of_int b in
  let ans = Int64.rem (Int64.add a b) mm in
  Int64.to_int ans

let () =
  let n = read_int () in
  let k = read_int () in
  let d = read_int () in

  let a = Array.make_matrix (n+1) (n+k+1) 0 in
  let b = Array.make_matrix (n+1) (n+k+1) 0 in

  a.(0).(0) <- 1;

  let count = ref 0 in

  let rec pass i =
    (* job is to fill in the i+1 st position and continue *)
    if i+1 > n then () else (
      for s=0 to n do
	for v = 1 to k do
	  if v < d then a.(i+1).(s+v) <- a.(i+1).(s+v) + a.(i).(s);
	  b.(i+1).(s+v) <- b.(i+1).(s+v) + b.(i).(s);
	  if v >= d then b.(i+1).(s+v) <- b.(i+1).(s+v) + a.(i).(s);
	done
      done;
      count := !count ++ b.(i+1).(n);
      pass (i+1)
    )
  in

  pass 0;

  printf "%d\n" !count

open Printf
open String
open Bigarray

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

let dp = Array.init (n1+2) (fun _ -> Array.make 3 (-10) )

let rec ways n flag =
  if n= 0 then
    if flag=1 then 1
    else 0
  else if n<0 then
    0
  else
    begin
      let x = dp.(n).(flag) in
      if x >=0 then
        x
      else
        begin
          let cnt = ref 0 in
          for i = 1 to d-1 do
            cnt := !cnt + (ways (n-i) flag)
          done;
          for i = d to k do
            cnt := !cnt + (ways (n-i) 1)
          done; dp.(n).(flag)<- !cnt; !cnt
        end
    end

let rslt = ways n1 0

let _ = printf "%d\n" rslt

(* compiled on 64-bit system with ocamlopt -pp camlp4o $file *)

open Printf
open Scanf
open Array

module S = String
module Q = Queue
module T = Stack
module H = Hashtbl
module L = List

(* misc *)
let neg_compare x y = - compare x y
let min3 a b c = min a (min b c)
let mid3 a b c = if a < b then max a (min b c) else max b (min a c)
let max3 a b c = max a (max b c)
let min4 a b c d = min (min a b) (min c d)
let max4 a b c d = max (max a b) (max c d)
let itb a = a <> 0
let bti b = if b then 1 else 0
let rec bsearch_min a b test =
  if b - a = 1 then b else
  let mid = (a-b)/2 + b in
  if test mid then bsearch_min a mid test else
  bsearch_min mid b test
let rec bsearch_max a b test =
  if b - a = 1 then a else
  let mid = (a-b)/2 + b in
  if test mid then bsearch_max mid b test else
  bsearch_max a mid test
(* int *)
let sqrt_floor n = bsearch_max 0 (1 lsl 31) (fun i -> i*i <= n)
let sqrt_ceil n = bsearch_min (-1) (1 lsl 31) (fun i -> n <= i*i)
(* float *)
let round f = truncate (f +. 0.5)
let inv_float f = 1. /. f
(* functional *)
let id x = x
let const x _ = x
let (|>) x f = f x
let (^>) x f = f x
let (@@) a b = a b
let on g f a b = g (f a) (f b)
let rec fix f = f (fun x -> fix f x)
let ift cond a = if cond then a
let ifte cond a b = if cond then a else b
let rec for_ i len c f = if i = len then c else for_ (i+1) len (f i c) f
(* predicate *)
let is_odd x = x land 1 = 1
let is_even x = x land 1 = 0
(* option *)
let is_none = function | Some _ -> false | None -> true
let is_some = function | Some _ -> true | None -> false
let default x = function Some y -> y | None -> x
(* ref *)
let (+=) a b = a := !a + b
let (-=) a b = a := !a - b
let ( *= ) a b = a := !a * b
let assign_min x y = x := min !x y
let assign_max x y = x := max !x y
(* array *)
let set_min x i v = x.(i) <- min x.(i) v
let set_max x i v = x.(i) <- max x.(i) v
let swap arr i j = let t = arr.(i) in arr.(i) <- arr.(j); arr.(j) <- t
(* int, int *)
let (++) (a,b) (c,d) = (a+c,b+d)
let (--) (a,b) (c,d) = (a-c,b-d)
(* Arithmetic *)
let negate x = -x
let rec factorial n = if n = 0 then 1 else n * factorial (n-1)
let rec gcd a b = if b = 0 then a else gcd b (a mod b)
let rec extgcd a b =
  if b = 0 then 1,0,a else
  let x,y,g = extgcd b (a mod b) in
  y,x-(a/b)*y,g
let rec pow x n = if n = 0 then 1 else
  let n' = n/2 in
  let p = pow x n' in
  if is_odd n then x*p*p else p*p
let rec modpow m x n =
  if n = 0 then 1 else
  let n' = n/2 in
  let p = modpow m x n' in
  if is_even n then (p*p mod m) else
  (x*(p*p mod m) mod m)
let modinv m i = let _,x,_ = extgcd m i in x
(* IO *)
let is_digit c =
  let i = int_of_char c in
  48 <= i && i < 58
let is_space c = c = ' ' || c = '\n' || c = '\t' || c = '\r'
let read_char () = try input_char stdin with End_of_file -> '\000'
let rec read_letter () =
  let c = read_char() in
  if is_space c then read_letter() else c
let read_int () =
  let digit c = int_of_char c - 48 in
  let rec read n =
    let c = read_char() in
    if is_digit c then read (10*n + (digit c)) else
    n
  in
  let rec run c =
    if is_digit c then read (digit c) else
    if c = '-' then begin
      let c = read_char() in
      if is_digit c then -read (digit c) else run c
    end else
    if c = '\000' then 0 else
    run (read_char())
  in
  run (read_char())
let read_float () =
  let digit c = float (int_of_char c - 48) in
  let rec read_decimial m f =
    let c = read_char () in
    if is_digit c then read_decimial (m /. 10.) (f +. m *. digit c) else f
  in
  let rec read_integral n =
    let c = read_char () in
    if is_digit c then read_integral (10. *. n +. digit c) else
    if c = '.' then n +. read_decimial 0.1 0.0 else
    n
  in
  let rec run c = begin
    if is_digit c then read_integral (digit c) else
    if c = '-' then begin
      let c = read_char() in
      if is_digit c then -. read_integral (digit c) else
      run c
    end else
    if c = '.' then read_decimial 0.1 0.0 else
    if c = '\000' then 0.0 else
    run (read_char())
  end in
  run (read_char())
let read_word () =
  let open Buffer in
  let buf = create 128 in
  let rec read c =
    if is_space c || c = '\000' then contents buf else begin
      add_char buf c;
      read (read_char())
    end
  in
  let rec run c =
    if is_space c then run (read_char()) else
    if c = '\000' then "" else
    read c
  in
  run (read_char())
let read_line () =
  let open Buffer in
  let buf = create (4*1024) in
  let rec run c =
    if c = '\n' || c = '\000' then contents buf else begin
      add_char buf c;
      run (read_char())
    end
  in
  run (read_char())
let newline () = print_newline()
let print_int n = printf "%d\n" n
let print_tuple s (x,y) = printf s x y
let print_array s arr = Array.iter (printf s) arr; print_newline()
let print_matrix s mat = Array.iter (print_array s) mat
let print_list s lis = List.iter (printf s) lis; print_newline()
;;

let read_int64 () =
  let digit c = Int64.of_int( int_of_char c - 48 )in
  let rec read n =
    let c = read_char() in
    if is_digit c then read (Int64.add (Int64.mul 10L n) (digit c)) else
    n
  in
  let rec run c =
    if is_digit c then read (digit c) else
    if c = '-' then begin
      let c = read_char() in
      if is_digit c then Int64.neg (read (digit c)) else run c
    end else
    if c = '\000' then 0L else
    run (read_char())
  in
  run (read_char())

module LL = struct
  include Int64
  let (+) a b = add a b
  let (-) a b = sub a b
  let ( * ) a b = mul a b
  let (/) a b = div a b
  let (mod) a b = rem a b
  let (land) a b = logand a b
  let (lor) a b = logor a b
  let (lxor) a b = logxor a b
  let (lnot) a = lognot a
end

let modulo = 1_000_000_007L

let isum n up =
  let arr = make (LL.to_int n + 1) (-1L) in
  let read n = arr.(LL.to_int n) in
  let save n v = arr.(LL.to_int n) <- v; v in

  let rec run (n: int64) = LL.(
    if read n <> -1L then read n else
    let ans =
      if n <= 1L then 1L else
      let t = 2L * run (n-1L) mod modulo in
      if n <= up then t else
      (t - run (n-1L-up)) mod modulo
    in
    save n ans
  ) in
  if up = 0L then 0L else run n

let _ =
  let n = read_int64() in
  let k = read_int64() in
  let d = read_int64() in
  let ans = LL.( (isum n k - isum n (d-1L) ) mod modulo) in
  printf "%s\n" (LL.to_string ans)

(* let _ =
  for i = 0 to 10 do
    let i = LL.of_int i in
    printf "%s\n" (LL.to_string (isum i i))
  done *)

(* compiled on 64-bit system with ocamlopt -pp camlp4o $file *)

open Printf
open Scanf
open Array

module S = String
module Q = Queue
module T = Stack
module H = Hashtbl
module L = List

(* misc *)
let neg_compare x y = - compare x y
let min3 a b c = min a (min b c)
let mid3 a b c = if a < b then max a (min b c) else max b (min a c)
let max3 a b c = max a (max b c)
let min4 a b c d = min (min a b) (min c d)
let max4 a b c d = max (max a b) (max c d)
let itb a = a <> 0
let bti b = if b then 1 else 0
let rec bsearch_min a b test =
  if b - a = 1 then b else
  let mid = (a-b)/2 + b in
  if test mid then bsearch_min a mid test else
  bsearch_min mid b test
let rec bsearch_max a b test =
  if b - a = 1 then a else
  let mid = (a-b)/2 + b in
  if test mid then bsearch_max mid b test else
  bsearch_max a mid test
(* int *)
let sqrt_floor n = bsearch_max 0 (1 lsl 31) (fun i -> i*i <= n)
let sqrt_ceil n = bsearch_min (-1) (1 lsl 31) (fun i -> n <= i*i)
(* float *)
let round f = truncate (f +. 0.5)
let inv_float f = 1. /. f
(* functional *)
let id x = x
let const x _ = x
let (|>) x f = f x
let (^>) x f = f x
let (@@) a b = a b
let on g f a b = g (f a) (f b)
let rec fix f = f (fun x -> fix f x)
let ift cond a = if cond then a
let ifte cond a b = if cond then a else b
let rec for_ i len c f = if i = len then c else for_ (i+1) len (f i c) f
(* predicate *)
let is_odd x = x land 1 = 1
let is_even x = x land 1 = 0
(* option *)
let is_none = function | Some _ -> false | None -> true
let is_some = function | Some _ -> true | None -> false
let default x = function Some y -> y | None -> x
(* ref *)
let (+=) a b = a := !a + b
let (-=) a b = a := !a - b
let ( *= ) a b = a := !a * b
let assign_min x y = x := min !x y
let assign_max x y = x := max !x y
(* array *)
let set_min x i v = x.(i) <- min x.(i) v
let set_max x i v = x.(i) <- max x.(i) v
let swap arr i j = let t = arr.(i) in arr.(i) <- arr.(j); arr.(j) <- t
(* int, int *)
let (++) (a,b) (c,d) = (a+c,b+d)
let (--) (a,b) (c,d) = (a-c,b-d)
(* Arithmetic *)
let negate x = -x
let rec factorial n = if n = 0 then 1 else n * factorial (n-1)
let rec gcd a b = if b = 0 then a else gcd b (a mod b)
let rec extgcd a b =
  if b = 0 then 1,0,a else
  let x,y,g = extgcd b (a mod b) in
  y,x-(a/b)*y,g
let rec pow x n = if n = 0 then 1 else
  let n' = n/2 in
  let p = pow x n' in
  if is_odd n then x*p*p else p*p
let rec modpow m x n =
  if n = 0 then 1 else
  let n' = n/2 in
  let p = modpow m x n' in
  if is_even n then (p*p mod m) else
  (x*(p*p mod m) mod m)
let modinv m i = let _,x,_ = extgcd m i in x
(* IO *)
let is_digit c =
  let i = int_of_char c in
  48 <= i && i < 58
let is_space c = c = ' ' || c = '\n' || c = '\t' || c = '\r'
let read_char () = try input_char stdin with End_of_file -> '\000'
let rec read_letter () =
  let c = read_char() in
  if is_space c then read_letter() else c
let read_int () =
  let digit c = int_of_char c - 48 in
  let rec read n =
    let c = read_char() in
    if is_digit c then read (10*n + (digit c)) else
    n
  in
  let rec run c =
    if is_digit c then read (digit c) else
    if c = '-' then begin
      let c = read_char() in
      if is_digit c then -read (digit c) else run c
    end else
    if c = '\000' then 0 else
    run (read_char())
  in
  run (read_char())
let read_float () =
  let digit c = float (int_of_char c - 48) in
  let rec read_decimial m f =
    let c = read_char () in
    if is_digit c then read_decimial (m /. 10.) (f +. m *. digit c) else f
  in
  let rec read_integral n =
    let c = read_char () in
    if is_digit c then read_integral (10. *. n +. digit c) else
    if c = '.' then n +. read_decimial 0.1 0.0 else
    n
  in
  let rec run c = begin
    if is_digit c then read_integral (digit c) else
    if c = '-' then begin
      let c = read_char() in
      if is_digit c then -. read_integral (digit c) else
      run c
    end else
    if c = '.' then read_decimial 0.1 0.0 else
    if c = '\000' then 0.0 else
    run (read_char())
  end in
  run (read_char())
let read_word () =
  let open Buffer in
  let buf = create 128 in
  let rec read c =
    if is_space c || c = '\000' then contents buf else begin
      add_char buf c;
      read (read_char())
    end
  in
  let rec run c =
    if is_space c then run (read_char()) else
    if c = '\000' then "" else
    read c
  in
  run (read_char())
let read_line () =
  let open Buffer in
  let buf = create (4*1024) in
  let rec run c =
    if c = '\n' || c = '\000' then contents buf else begin
      add_char buf c;
      run (read_char())
    end
  in
  run (read_char())
let newline () = print_newline()
let print_int n = printf "%d\n" n
let print_tuple s (x,y) = printf s x y
let print_array s arr = Array.iter (printf s) arr; print_newline()
let print_matrix s mat = Array.iter (print_array s) mat
let print_list s lis = List.iter (printf s) lis; print_newline()
;;

let read_int64 () =
  let digit c = Int64.of_int( int_of_char c - 48 )in
  let rec read n =
    let c = read_char() in
    if is_digit c then read (Int64.add (Int64.mul 10L n) (digit c)) else
    n
  in
  let rec run c =
    if is_digit c then read (digit c) else
    if c = '-' then begin
      let c = read_char() in
      if is_digit c then Int64.neg (read (digit c)) else run c
    end else
    if c = '\000' then 0L else
    run (read_char())
  in
  run (read_char())

module LL = struct
  include Int64
  let (+) a b = add a b
  let (-) a b = sub a b
  let ( * ) a b = mul a b
  let (/) a b = div a b
  let (mod) a b = rem a b
  let (land) a b = logand a b
  let (lor) a b = logor a b
  let (lxor) a b = logxor a b
  let (lnot) a = lognot a
end

let modulo = 1_000_000_007L

let isum n up =
  let arr = make (LL.to_int n + 1) (-1L) in
  let read n = arr.(LL.to_int n) in
  let save n v = arr.(LL.to_int n) <- v; v in

  let rec run (n: int64) = LL.(
    if read n <> -1L then read n else
    let ans =
      if n <= 1L then 1L else
      if up < 1L then 0L else
      if n <= up then 2L * run (n-1L) mod modulo else
      (2L * run (n-1L) - run (n-1L-up)) mod modulo
    in
    save n ans
  ) in
  run n

let _ =
  let n = read_int64() in
  let k = read_int64() in
  let d = read_int64() in
  let ans = LL.( (isum n k - isum n (d-1L) ) mod modulo) in
  printf "%s\n" (LL.to_string ans)

(* compiled on 64-bit system with ocamlopt -pp camlp4o $file *)

open Printf
open Scanf
open Array

module S = String
module Q = Queue
module T = Stack
module H = Hashtbl
module L = List

(* misc *)
let neg_compare x y = - compare x y
let min3 a b c = min a (min b c)
let mid3 a b c = if a < b then max a (min b c) else max b (min a c)
let max3 a b c = max a (max b c)
let min4 a b c d = min (min a b) (min c d)
let max4 a b c d = max (max a b) (max c d)
let itb a = a <> 0
let bti b = if b then 1 else 0
let rec bsearch_min a b test =
  if b - a = 1 then b else
  let mid = (a-b)/2 + b in
  if test mid then bsearch_min a mid test else
  bsearch_min mid b test
let rec bsearch_max a b test =
  if b - a = 1 then a else
  let mid = (a-b)/2 + b in
  if test mid then bsearch_max mid b test else
  bsearch_max a mid test
(* int *)
let sqrt_floor n = bsearch_max 0 (1 lsl 31) (fun i -> i*i <= n)
let sqrt_ceil n = bsearch_min (-1) (1 lsl 31) (fun i -> n <= i*i)
(* float *)
let round f = truncate (f +. 0.5)
let inv_float f = 1. /. f
(* functional *)
let id x = x
let const x _ = x
let (|>) x f = f x
let (^>) x f = f x
let (@@) a b = a b
let on g f a b = g (f a) (f b)
let rec fix f = f (fun x -> fix f x)
let ift cond a = if cond then a
let ifte cond a b = if cond then a else b
let rec for_ i len c f = if i = len then c else for_ (i+1) len (f i c) f
(* predicate *)
let is_odd x = x land 1 = 1
let is_even x = x land 1 = 0
(* option *)
let is_none = function | Some _ -> false | None -> true
let is_some = function | Some _ -> true | None -> false
let default x = function Some y -> y | None -> x
(* ref *)
let (+=) a b = a := !a + b
let (-=) a b = a := !a - b
let ( *= ) a b = a := !a * b
let assign_min x y = x := min !x y
let assign_max x y = x := max !x y
(* array *)
let set_min x i v = x.(i) <- min x.(i) v
let set_max x i v = x.(i) <- max x.(i) v
let swap arr i j = let t = arr.(i) in arr.(i) <- arr.(j); arr.(j) <- t
(* int, int *)
let (++) (a,b) (c,d) = (a+c,b+d)
let (--) (a,b) (c,d) = (a-c,b-d)
(* Arithmetic *)
let negate x = -x
let rec factorial n = if n = 0 then 1 else n * factorial (n-1)
let rec gcd a b = if b = 0 then a else gcd b (a mod b)
let rec extgcd a b =
  if b = 0 then 1,0,a else
  let x,y,g = extgcd b (a mod b) in
  y,x-(a/b)*y,g
let rec pow x n = if n = 0 then 1 else
  let n' = n/2 in
  let p = pow x n' in
  if is_odd n then x*p*p else p*p
let rec modpow m x n =
  if n = 0 then 1 else
  let n' = n/2 in
  let p = modpow m x n' in
  if is_even n then (p*p mod m) else
  (x*(p*p mod m) mod m)
let modinv m i = let _,x,_ = extgcd m i in x
(* IO *)
let is_digit c =
  let i = int_of_char c in
  48 <= i && i < 58
let is_space c = c = ' ' || c = '\n' || c = '\t' || c = '\r'
let read_char () = try input_char stdin with End_of_file -> '\000'
let rec read_letter () =
  let c = read_char() in
  if is_space c then read_letter() else c
let read_int () =
  let digit c = int_of_char c - 48 in
  let rec read n =
    let c = read_char() in
    if is_digit c then read (10*n + (digit c)) else
    n
  in
  let rec run c =
    if is_digit c then read (digit c) else
    if c = '-' then begin
      let c = read_char() in
      if is_digit c then -read (digit c) else run c
    end else
    if c = '\000' then 0 else
    run (read_char())
  in
  run (read_char())
let read_float () =
  let digit c = float (int_of_char c - 48) in
  let rec read_decimial m f =
    let c = read_char () in
    if is_digit c then read_decimial (m /. 10.) (f +. m *. digit c) else f
  in
  let rec read_integral n =
    let c = read_char () in
    if is_digit c then read_integral (10. *. n +. digit c) else
    if c = '.' then n +. read_decimial 0.1 0.0 else
    n
  in
  let rec run c = begin
    if is_digit c then read_integral (digit c) else
    if c = '-' then begin
      let c = read_char() in
      if is_digit c then -. read_integral (digit c) else
      run c
    end else
    if c = '.' then read_decimial 0.1 0.0 else
    if c = '\000' then 0.0 else
    run (read_char())
  end in
  run (read_char())
let read_word () =
  let open Buffer in
  let buf = create 128 in
  let rec read c =
    if is_space c || c = '\000' then contents buf else begin
      add_char buf c;
      read (read_char())
    end
  in
  let rec run c =
    if is_space c then run (read_char()) else
    if c = '\000' then "" else
    read c
  in
  run (read_char())
let read_line () =
  let open Buffer in
  let buf = create (4*1024) in
  let rec run c =
    if c = '\n' || c = '\000' then contents buf else begin
      add_char buf c;
      run (read_char())
    end
  in
  run (read_char())
let newline () = print_newline()
let print_int n = printf "%d\n" n
let print_tuple s (x,y) = printf s x y
let print_array s arr = Array.iter (printf s) arr; print_newline()
let print_matrix s mat = Array.iter (print_array s) mat
let print_list s lis = List.iter (printf s) lis; print_newline()
;;

let read_int64 () =
  let digit c = Int64.of_int( int_of_char c - 48 )in
  let rec read n =
    let c = read_char() in
    if is_digit c then read (Int64.add (Int64.mul 10L n) (digit c)) else
    n
  in
  let rec run c =
    if is_digit c then read (digit c) else
    if c = '-' then begin
      let c = read_char() in
      if is_digit c then Int64.neg (read (digit c)) else run c
    end else
    if c = '\000' then 0L else
    run (read_char())
  in
  run (read_char())

module LL = struct
  include Int64
  let (+) a b = add a b
  let (-) a b = sub a b
  let ( * ) a b = mul a b
  let (/) a b = div a b
  let (mod) a b = rem a b
  let (land) a b = logand a b
  let (lor) a b = logor a b
  let (lxor) a b = logxor a b
  let (lnot) a = lognot a
end

let modulo = 1_000_000_007L

let isum n up =
  let arr = make (LL.to_int n + 1) (-1L) in
  let read n = arr.(LL.to_int n) in
  let save n v = arr.(LL.to_int n) <- v; v in

  let rec run (n: int64) = LL.(
    if read n <> -1L then read n else
    let ans =
      if n <= 1L then 1L else
      if n <= up then 2L * run (n-1L) mod modulo else
      (2L * run (n-1L) - run (n-1L-up)) mod modulo
    in
    save n ans
  ) in
  if up = 0L then 0L else run n

let _ =
  let n = read_int64() in
  let k = read_int64() in
  let d = read_int64() in
  let ans = LL.( (isum n k - isum n (d-1L) ) mod modulo) in
  printf "%s\n" (LL.to_string ans)

(* let _ =
  for i = 0 to 10 do
    let i = LL.of_int i in
    printf "%s\n" (LL.to_string (isum i i))
  done *)

(* compiled on 64-bit system with ocamlopt -pp camlp4o $file *)

open Printf
open Scanf
open Array

module S = String
module Q = Queue
module T = Stack
module H = Hashtbl
module L = List

(* misc *)
let neg_compare x y = - compare x y
let min3 a b c = min a (min b c)
let mid3 a b c = if a < b then max a (min b c) else max b (min a c)
let max3 a b c = max a (max b c)
let min4 a b c d = min (min a b) (min c d)
let max4 a b c d = max (max a b) (max c d)
let itb a = a <> 0
let bti b = if b then 1 else 0
let rec bsearch_min a b test =
  if b - a = 1 then b else
  let mid = (a-b)/2 + b in
  if test mid then bsearch_min a mid test else
  bsearch_min mid b test
let rec bsearch_max a b test =
  if b - a = 1 then a else
  let mid = (a-b)/2 + b in
  if test mid then bsearch_max mid b test else
  bsearch_max a mid test
(* int *)
let sqrt_floor n = bsearch_max 0 (1 lsl 31) (fun i -> i*i <= n)
let sqrt_ceil n = bsearch_min (-1) (1 lsl 31) (fun i -> n <= i*i)
(* float *)
let round f = truncate (f +. 0.5)
let inv_float f = 1. /. f
(* functional *)
let id x = x
let const x _ = x
let (|>) x f = f x
let (^>) x f = f x
let (@@) a b = a b
let on g f a b = g (f a) (f b)
let rec fix f = f (fun x -> fix f x)
let ift cond a = if cond then a
let ifte cond a b = if cond then a else b
let rec for_ i len c f = if i = len then c else for_ (i+1) len (f i c) f
(* predicate *)
let is_odd x = x land 1 = 1
let is_even x = x land 1 = 0
(* option *)
let is_none = function | Some _ -> false | None -> true
let is_some = function | Some _ -> true | None -> false
let default x = function Some y -> y | None -> x
(* ref *)
let (+=) a b = a := !a + b
let (-=) a b = a := !a - b
let ( *= ) a b = a := !a * b
let assign_min x y = x := min !x y
let assign_max x y = x := max !x y
(* array *)
let set_min x i v = x.(i) <- min x.(i) v
let set_max x i v = x.(i) <- max x.(i) v
let swap arr i j = let t = arr.(i) in arr.(i) <- arr.(j); arr.(j) <- t
(* int, int *)
let (++) (a,b) (c,d) = (a+c,b+d)
let (--) (a,b) (c,d) = (a-c,b-d)
(* Arithmetic *)
let negate x = -x
let rec factorial n = if n = 0 then 1 else n * factorial (n-1)
let rec gcd a b = if b = 0 then a else gcd b (a mod b)
let rec extgcd a b =
  if b = 0 then 1,0,a else
  let x,y,g = extgcd b (a mod b) in
  y,x-(a/b)*y,g
let rec pow x n = if n = 0 then 1 else
  let n' = n/2 in
  let p = pow x n' in
  if is_odd n then x*p*p else p*p
let rec modpow m x n =
  if n = 0 then 1 else
  let n' = n/2 in
  let p = modpow m x n' in
  if is_even n then (p*p mod m) else
  (x*(p*p mod m) mod m)
let modinv m i = let _,x,_ = extgcd m i in x
(* IO *)
let is_digit c =
  let i = int_of_char c in
  48 <= i && i < 58
let is_space c = c = ' ' || c = '\n' || c = '\t' || c = '\r'
let read_char () = try input_char stdin with End_of_file -> '\000'
let rec read_letter () =
  let c = read_char() in
  if is_space c then read_letter() else c
let read_int () =
  let digit c = int_of_char c - 48 in
  let rec read n =
    let c = read_char() in
    if is_digit c then read (10*n + (digit c)) else
    n
  in
  let rec run c =
    if is_digit c then read (digit c) else
    if c = '-' then begin
      let c = read_char() in
      if is_digit c then -read (digit c) else run c
    end else
    if c = '\000' then 0 else
    run (read_char())
  in
  run (read_char())
let read_float () =
  let digit c = float (int_of_char c - 48) in
  let rec read_decimial m f =
    let c = read_char () in
    if is_digit c then read_decimial (m /. 10.) (f +. m *. digit c) else f
  in
  let rec read_integral n =
    let c = read_char () in
    if is_digit c then read_integral (10. *. n +. digit c) else
    if c = '.' then n +. read_decimial 0.1 0.0 else
    n
  in
  let rec run c = begin
    if is_digit c then read_integral (digit c) else
    if c = '-' then begin
      let c = read_char() in
      if is_digit c then -. read_integral (digit c) else
      run c
    end else
    if c = '.' then read_decimial 0.1 0.0 else
    if c = '\000' then 0.0 else
    run (read_char())
  end in
  run (read_char())
let read_word () =
  let open Buffer in
  let buf = create 128 in
  let rec read c =
    if is_space c || c = '\000' then contents buf else begin
      add_char buf c;
      read (read_char())
    end
  in
  let rec run c =
    if is_space c then run (read_char()) else
    if c = '\000' then "" else
    read c
  in
  run (read_char())
let read_line () =
  let open Buffer in
  let buf = create (4*1024) in
  let rec run c =
    if c = '\n' || c = '\000' then contents buf else begin
      add_char buf c;
      run (read_char())
    end
  in
  run (read_char())
let newline () = print_newline()
let print_int n = printf "%d\n" n
let print_tuple s (x,y) = printf s x y
let print_array s arr = Array.iter (printf s) arr; print_newline()
let print_matrix s mat = Array.iter (print_array s) mat
let print_list s lis = List.iter (printf s) lis; print_newline()
;;

let isum n up =
  let rec run n =
    if n <= 1 then 1 else
    if n <= up then 2 * run (n-1) else
    2 * run (n-1) - run (n-1-up)
  in
  run n

let _ =
  let n = read_int() in
  let k = read_int() in
  let d = read_int() in
  let ans = isum n k - isum n (d-1) in
  printf "%d\n" ans


open Printf
open Scanf

let read_int _ = bscanf Scanning.stdib " %d " (fun x -> x)
let () =
  let n = read_int () in
  let w = Array.init n read_int in

  let rec loop (x,y) i = if i=n then true else (
    let z = 6 - x - y in
    if w.(i) = x then loop (x,z) (i+1)
    else if w.(i) = y then loop (y,z) (i+1)
    else false
  ) in

  if loop (1,2) 0 then printf "YES\n" else printf "NO\n"

let scan_int () = Scanf.scanf " %d" (fun x -> x);;
let n = scan_int() and gra = ref 1 and pom = ref 0 and gra2 = ref 2  and siedzi = ref 3 and czy = ref 1 in
begin
for i = 1 to n do
	let x= scan_int() in
      if x = !siedzi then czy := 0
      else if !gra = x then begin pom:= !siedzi; siedzi := !gra2; gra2 := !pom end
           else begin pom := !siedzi; siedzi := !gra; gra := !pom end
done;
if !czy = 1 then print_string("YES")
else print_string("NO")
end

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

let n = scan_int();;
let stan = ref 3;;
let wyn = ref 1;;

for i = 0 to (n - 1) do
  let x = scan_int() in
  if((1 lsl (x - 1)) land (!stan) == 0) then wyn := 0;
  stan := (!stan - (1 lsl (x - 1))) lxor 7;
done;

if !wyn = 1 then print_string("YES") else print_string("NO");;


open Printf

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

let n = read_int ()

type action = Rest | Test | Sport | None;;
type day = A | B | C | D;; (* 0, 1, 2, 3*)

let itoa = function
  | 0 -> A
  | 1 -> B
  | 2 -> C
  | 3 -> D

let a = Array.init n (fun i -> (read_int () |> itoa))

let act_poss d act =
  match (d, act) with
  | (A, Sport) -> false
  | (A,  Test) -> false
  | (B, Sport) -> false
  | (C,  Test) -> false
  | (_,     _) -> true

type rmin = { mutable rest : int; mutable sport : int; mutable test : int};;

  (*Note: should not use Array.make here*)
let r = Array.init (n+1) (fun i ->
                     {rest = max_int; sport = max_int; test = max_int });;

let () = r.(0) <- {rest = 0; sport = 0; test = 0};;

let () =
  for i = 1 to n
  do
    let x = r.(i-1).sport in
    let y = r.(i-1).test in
    let z = r.(i-1).rest in
    begin
      if (act_poss a.(i-1) Rest) then
        let w = min x (min y z) in
        if(w<max_int) then r.(i).rest <- (w+1);
      if (act_poss a.(i-1) Sport) then r.(i).sport<- (min y z);
      if (act_poss a.(i-1) Test) then  r.(i).test <- (min x z)
    end;
    (* printf "-- %d %d %d\n" r.(i).rest r.(i).sport r.(i).test *)
  done;;

let () =  printf "%d\n" ( min r.(n).test (min r.(n).rest r.(n).sport ));;

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

let n = read_int ()

type action = Rest | Test | Sport | None;;
type day = A | B | C | D;; (* 0, 1, 2, 3*)

let itoa = function
  | 0 -> A
  | 1 -> B
  | 2 -> C
  | 3 -> D

let a = Array.init n (fun i -> (read_int () |> itoa))

let act_poss d act =
  match (d, act) with
  | (A, Sport) -> false
  | (A,  Test) -> false
  | (B, Sport) -> false
  | (C,  Test) -> false
  | (_,     _) -> true

type rmin = { mutable rest : int; mutable sport : int; mutable test : int};;

  (*Note: should not use Array.make here*)
let r = Array.init (n+1) (fun i ->
                     {rest = max_int; sport = max_int; test = max_int });;

let () = r.(0) <- {rest = 0; sport = 0; test = 0};;

let () =
  for i = 1 to n
  do
    let x = r.(i-1).sport in
    let y = r.(i-1).test in
    let z = r.(i-1).rest in
    begin
      if (act_poss a.(i-1) Rest) then
        let w = min x (min y z) in
        if(w<max_int) then r.(i).rest <- (w+1);
      if (act_poss a.(i-1) Sport) then r.(i).sport<- (min y z);
      if (act_poss a.(i-1) Test) then  r.(i).test <- (min x z)
    end;
    (* printf "-- %d %d %d\n" r.(i).rest r.(i).sport r.(i).test *)
  done;;

let () =  Printf.printf "%d\n" ( min r.(n).test (min r.(n).rest r.(n).sport ));;

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 + 1) (fun i -> if i = 0 then 0 else read_int ())
    and dp = Array.make_matrix (n + 1) 4 1000000000 in
    dp.(0).(0) <- 0;
    for i = 1 to n do
        dp.(i).(0) <- 1 + (min dp.(i - 1).(0) (min dp.(i - 1).(1) dp.(i - 1).(2)));
        if a.(i) = 1 || a.(i) = 3 then
            dp.(i).(1) <- min dp.(i - 1).(0) dp.(i - 1).(2);
        if a.(i) = 2 || a.(i) = 3 then
            dp.(i).(2) <- min dp.(i - 1).(0) dp.(i - 1).(1)
    done;
    printf "%d\n" (min dp.(n).(0) (min dp.(n).(1) dp.(n).(2)))

open Printf

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

let n = read_int ()

type action = Rest | Test | Sport | None;;
type day = A | B | C | D;; (* 0, 1, 2, 3*)

let itoa = function
  | 0 -> A
  | 1 -> B
  | 2 -> C
  | 3 -> D

let a = Array.init n (fun i -> (read_int () |> itoa))

let act_poss d act p_act =
  match (d, act, p_act) with
  | (A, Sport,     _) -> false
  | (A,  Test,     _) -> false
  | (B, Sport,     _) -> false
  | (B,  Test,  Test) -> false
  | (C,  Test,     _) -> false
  | (C, Sport, Sport) -> false
  | (D, Sport, Sport) -> false
  | (D,  Test,  Test) -> false
  | (_,     _,     _) -> true

let r = Array.make (n+1) max_int;;

let () = r.(0) <- 0 in
let act = Array.make (n+1) None in
let () = act.(0) <- Rest in
let () =
  for i = 1 to n
  do
    if (act_poss a.(i-1) Rest act.(i-1) ) then
      begin
        if ( r.(i) > r.(i-1)+1 ) then
          begin
            act.(i) <- Rest;
            r.(i) <- r.(i-1) + 1
          end
      end;
    if (act_poss a.(i-1) Test act.(i-1) ) then
      begin
        if ( r.(i) > r.(i-1) ) then
          begin
            act.(i) <- Test;
            r.(i) <- r.(i-1)
          end
      end;
    if (act_poss a.(i-1) Sport act.(i-1) ) then
      begin
        if ( r.(i) > r.(i-1) ) then
          begin
            act.(i) <- Sport;
            r.(i) <- r.(i-1)
          end
      end;
  done in ()
;;

let () = printf "%d\n" r.(n);;


let (no_of_ppl, no_of_puzzles) = Scanf.scanf "%d %d " (fun n m -> n, m)

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

let sort list = List.sort(Pervasives.compare) (List.rev list)

let find_min list n m =
    let rec traverse i min =
    if i + n - 1< m
    then
        let dif = List.nth list (i + n - 1) - List.nth list i in
        if dif < min
        then
            traverse (i + 1) dif
        else
            traverse (i + 1) min
    else
        min
    in traverse 0 1000

let solve (no_of_ppl, no_of_puzzles) = find_min (sort (read no_of_puzzles)) no_of_ppl no_of_puzzles

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

let () = print (solve (no_of_ppl, no_of_puzzles))

let (n, m) = Scanf.scanf "%d %d\n" (fun n m -> n, m) in

let a = Array.make m 0 in
for i = 0 to m - 1 do
    Scanf.scanf "%d%[ ]" (fun x _ -> a.(i) <- x)
done ;

Array.sort compare a ;

let ans = ref max_int in
for i = 0 to m - n do
    ans := min !ans (a.(i + n - 1) - a.(i))
done ;

Printf.printf "%d\n" !ans ;;

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

let parse_list (n : int) : (int list) =
  let rec parse_list_helper acc = function
    | 0 -> acc
    | n -> parse_list_helper (acc @ [read_int ()]) (n - 1)
  in
    parse_list_helper [] n

let () =
  let ans = ref 1001 in
  let n   = read_int () in
  let m   = read_int () in
  let lst = List.sort compare (parse_list m) in
  for k = 0 to m-n do
    let diff = (List.nth lst (k + n - 1)) - (List.nth lst k) in
    ans := min !ans diff
  done;
  print_int !ans

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

let parse_list (n : int) : (int list) =
  let rec parse_list_helper acc = function
    | 0 -> acc
    | n -> parse_list_helper (acc @ [read_int ()]) (n - 1)
  in
    parse_list_helper [] n

let () =
  let b = ref 1001 in
  let n = read_int () in
  let m = read_int () in
  let lst = parse_list m in
  let sorted_lst = List.sort compare lst in
  for k = 0 to m-n do
    let diff = (List.nth sorted_lst (k + n - 1)) - (List.nth sorted_lst k) in
    b := min !b diff
  done;
  print_int !b

let (n, m) = Scanf.scanf "%d %d\n" (fun n m -> n, m) in
let p = Array.make m 0 in
for i = 0 to m - 1 do
    Scanf.scanf "%d%[ ]" (fun x _ -> p.(i) <- x)
done ;
Array.sort compare p ;
let b = ref max_int in
for i = 0 to m - n do
    b := min !b (p.(i + n - 1) - p.(i))
done ;
Printf.printf "%d\n" !b ;;

open Scanf;;
open String;;

let n = bscanf Scanning.stdin "%d " (fun x -> x);;
let m = bscanf Scanning.stdin "%d " (fun x -> x);;

let p = Array.init m (fun x -> 0);;

for i=0 to m-1 do
  let  f = bscanf Scanning.stdin "%d " (fun x -> x)   in
  p.(i) <- f
done;;

(*Sort the array ascendingly*)
Array.sort (fun x y ->  x-y ) p;;

(*Test the sorting result
Array.iter (fun x -> Printf.printf "%d " x)  p;;
*)

let i = ref 0 in
let maxdiff = ref  max_int in
let () =
  while (!i + n-1) <= (m-1) do
    let diff =  p.(!i+n-1) -p.(!i) in
    if ( diff < !maxdiff) then  maxdiff := diff ;
    i := !i + 1
  done in
print_int !maxdiff; print_endline ""
;;

open Scanf;;
open String;;

let n = Scanf.bscanf Scanf.Scanning.stdin "%d " (fun x -> x);;
let m = Scanf.bscanf Scanf.Scanning.stdin "%d " (fun x -> x);;

let p = Array.init m (fun x -> 0);;

for i=0 to m-1 do
  let  f = Scanf.bscanf Scanf.Scanning.stdin "%d " (fun x -> x)   in
  p.(i) <- f
done;;

(*Sort the array ascendingly*)
Array.sort (fun x y ->  x-y ) p;;

(*Test the sorting result
Array.iter (fun x -> Printf.printf "%d " x)  p;;
*)

let i = ref 0 in
let maxdiff = ref  max_int in
let () =
  while (!i + n-1) <= (m-1) do
    let diff =  p.(!i+n-1) -p.(!i) in
    if ( diff < !maxdiff) then  maxdiff := diff ;
    i := !i + 1
  done in
print_int !maxdiff; print_endline ""
;;

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

let parse_list (n : int) : (int list) =
  let rec parse_list_helper acc = function
    | 0 -> acc
    | n -> parse_list_helper (acc @ [read_int ()]) (n - 1)
  in
    parse_list_helper [] n

let () =
  let ans = ref 1001 in
  let n   = read_int () in
  let m   = read_int () in
  let lst = List.sort compare (parse_list m) in
  for k = 1 to m-n do
    let diff = (List.nth lst (k + n - 1)) - (List.nth lst k) in
    ans := min !ans diff
  done;
  print_int !ans

open Scanf;;
open String;;

let n = Scanf.bscanf Scanf.Scanning.stdin "%d " (fun x -> x);;
let m = Scanf.bscanf Scanf.Scanning.stdin "%d " (fun x -> x);;

let p = Array.init m (fun x -> 0);;

for i=0 to m-1 do
  let  f = Scanf.bscanf Scanf.Scanning.stdin "%d " (fun x -> x)   in
  p.(i) <- f
done;;

(*Sort the array ascendingly*)
Array.sort (fun x y ->  x-y ) p;;

(*Test the sorting result
Array.iter (fun x -> Printf.printf "%d " x)  p;;
*)

let i = ref 0 in
let maxdiff = ref  max_int in
let () =
  while (!i + 3) <= (m-1) do
    let diff =  p.(!i+3) -p.(!i) in
    if ( diff < !maxdiff) then  maxdiff := diff ;
    i := !i + 1
  done in
print_int !maxdiff; print_endline ""
;;


let consonants s =
  let regex_vowel = Str.regexp "[aeiouy]" in
  let vowel_deleted = Str.split regex_vowel (String.lowercase s)
  in
  String.concat "" vowel_deleted
;;

let () =
  Scanf.scanf "%s" (fun s -> String.iter (fun c -> Printf.printf ".%c" c)
                                         (consonants s));
  print_newline ()
;;

let str_to_list s =
    let rec loop i l =
        if i < 0
        then l
        else loop (i - 1) (s.[i] :: l) in
    loop (String.length s - 1) []

let word = Scanf.scanf "%s" (fun word -> str_to_list (String.lowercase(word)))

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

let remove_vowels l = List.filter(fun char -> is_consonant char) l

let add_dot = (fun l -> List.concat(List.map(fun char -> ['.'; char]) l))

let () = List.iter(Printf.printf "%c") (add_dot(remove_vowels word))

String.iter (fun c ->
	if not (c = 'a' || c = 'o' || c = 'y' || c = 'e' || c = 'u' || c = 'i') then
		(print_char '.'; print_char c)
) (String.lowercase (read_line()));;

let stringToList str =
  let rec loop idx str =
    let len = String.length(str) in
    if idx >= len then
      []
    else
      str.[idx] :: loop (idx+1) str in
  loop 0 str;;

let isConsonant ch =
  match ch
  with 'a'|'o'|'y'|'e'|'u'|'i' -> false
  | _ -> true;;

let printWithDot ch =
  Printf.printf ".%c" ch;;

let _ =
  let line = read_line() in
  let l = stringToList (String.lowercase line) in
  List.map printWithDot (List.filter isConsonant l) in
  print_newline()

let s=read_line();;
let rec op t=
if t="" then [] else t.[0]::(op (String.sub t 1 (String.length(t)-1)));;
let l=op s;;
let letter char= match char with
| 'a' | 'e' | 'i' | 'o' | 'u' | 'y'
   | 'A' | 'E' | 'I' | 'O' | 'U' | 'Y' ->()
|'a'..'z'->print_string ".";print_char char
|'A'..'Z'->print_string ".";print_char (Char.chr(int_of_char(char)+32))
|_->();;
let rec doo=function
|[]->()
|h::t->letter h;doo t;;
doo l;;

let do_it c =
	match c with
	'a'|'o'|'y'|'e'|'u'|'i'|'A'|'O'|'Y'|'E'|'U'|'I' -> c
	|_ -> print_string ("." ^ String.make 1 c); c
;;

String.map do_it (String.lowercase (read_line()))

let str=String.lowercase(read_line());;
let ans= ref "" ;;
for i=1 to String.length(str) do
    let va= str.[i-1] in
    if (va!='a' && va!='e' && va!='i' && va!='o' && va!='u' && va!='y') then ans:=(!ans)^(String.make 1 '.')^(String.make 1 va)
done;;
print_endline(!ans)

let atr=read_line();;
let str=String.lowercase(atr);;
let ans= ref "" ;;
for i=1 to String.length(str) do
    let va= str.[i-1] in
    if (va!='a' && va!='e' && va!='i' && va!='o' && va!='u' && va!='y') then ans:=(!ans)^(String.make 1 '.')^(String.make 1 va)
done;;
print_endline(!ans)

open Scanf
open Num
open Printf
open String

let s = Scanf.bscanf Scanf.Scanning.stdin "%s " ( fun x -> x) |> String.lowercase

let explode s =
  let r = ref [] in
  for i = 0 to (length s - 1) do
    let c = String.get s i in
    r := !r@[c]
  done; !r
;;

let is_vowel = function
  | 'a' -> true
  | 'o' -> true
  | 'y' -> true
  | 'e' -> true
  | 'u' -> true
  | 'i' -> true
  | _ -> false

let l = ( explode s
  |> List.filter (fun x -> (not (is_vowel x)) )
  );;

List.iter (fun x -> print_string ("."^(String.make 1 x)) ) l; print_endline "";;

let solve =
  let s = read_line () in
    let terminated_s = s ^ "." in
      let rec parse_string i = match terminated_s.[i] with
        | '.' -> print_string "\n"
        | 'a' | 'o' | 'y' | 'e' | 'u' | 'i'
        | 'A' | 'O' | 'Y' | 'E' | 'U' | 'I' -> parse_string (i+1)
        | c when c >= 'A' && c <= 'Z' ->
          print_char '.'; print_char (Char.lowercase c); parse_string (i+1)
        | c -> print_char '.'; print_char c; parse_string (i+1)
      in parse_string 0; ()

let () = solve

let vowels = 'a'::'i'::'u'::'e'::'o'::'y'::[]

let petya c =
    let lower = Char.lowercase c in
    if List.exists (fun x -> x = lower) vowels then ()
    else Printf.printf ".%c" lower

let main () =
    let gr () = Scanf.scanf "%s\n" (fun i -> i) in
    let str = gr () in
    let () = String.iter petya str in
    Printf.printf("\n")
;;

let _ = main();;

open String;;
open Printf;;
open Scanf;;
open Char;;

let convert ch =
  match ch with
  |'a'|'e'|'u'|'i'|'o'|'y'
  |'A'|'E'|'U'|'I'|'O'|'Y' -> None
  |_ -> Some ("." ^ String.make 1 (Char.lowercase ch))

let rec process inp =
  let res = ref "" in
  for i = 0 to length inp - 1 do
    let ch = convert inp.[i] in
    match ch with
    | Some x -> res := (!res ^ x)
    | None -> ()
  done;
  !res

let () =
  let inp = read_line () in
  printf "%s\n" (process inp)
  ;;

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

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

exception Error of string

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

let f s =
  let t = Char.lowercase s in
  if List.memq t ['a'; 'i'; 'u'; 'e'; 'o'; 'y']
  then ""
  else "." ^ Char.escaped t
;;

let _ =
  let str = read_line() in
  let res = ref "" in
  for i = 0 to String.length str - 1 do
    res := !res ^ f str.[i]
  done;
  print_endline !res
;;

let _ =
    let main () =
        let conv k =
            let s = String.lowercase k in

            let rec loop i acc =
                if i < 0 then acc else
                    let k = try String.index "aoyeui" s.[i] with _ -> -1 in
                    loop (i - 1) (if k >= 0 then acc else s.[i] :: acc)
            in
            loop (String.length s - 1) []
        in
        let s = read_line () in
        let result = conv s in
        List.iter (Printf.printf ".%c") result;
        print_newline ()
    in
    main ()

let atr=read_line();;
let str=String.lowercase(atr);;
let ans= ref "" ;;
for i=1 to String.length(str) do
    let va= str.[i-1] in
    if (va!='a' && va!='e' && va!='i' && va!='o' && va!='u') then ans:=(!ans)^(String.make 1 '.')^(String.make 1 va)
done;;
print_endline(!ans)

let vowels = 'a'::'i'::'u'::'e'::'o'::[]

let petya c =
    let lower = Char.lowercase c in
    if List.exists (fun x -> x = lower) vowels then ()
    else Printf.printf ".%c" lower

let main () =
    let gr () = Scanf.scanf "%s\n" (fun i -> i) in
    let str = gr () in
    let () = String.iter petya str in
    Printf.printf("\n")
;;

let _ = main();;


open Printf

let main =
    let s = read_line() in
    let h = s.[0] in
    let t = String.sub s 1 ((String.length s) - 1) in

    printf "%c%s\n" (Char.uppercase h) t;

let input () = Scanf.scanf "%s" (fun s -> s)

let solve input = String.capitalize input

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

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

let () =
  let s = read_line () in
  let len = String.length s in
  let head = String.sub s 0 1 in
  let tail = String.sub s 1 (len - 1)
  in
  print_endline (String.uppercase head ^ tail);;

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

let () = read_int () |> String.capitalize
|> print_endline ;;

(* Codeforces 281A *)

let _ =
  Printf.printf "%s\n" (Scanf.scanf "%s" (fun s -> String.capitalize s))

let () =
  let s = read_line() in
  let isupper c = int_of_char c <= int_of_char 'Z' && int_of_char c >= int_of_char 'A' in
    if not (isupper s.[0]) then
      s.[0] <- char_of_int ((int_of_char s.[0]) + (int_of_char 'A') - (int_of_char 'a'));

    Printf.printf "%s\n" s


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

let ( $ ) f x = f x

let main () =
  let n = ref (read_int ()) in
  let cur = ref 0 in
  let fail = ref false in
  let t = ref 0 in
  let str = ref "" in
  for i = 1 to !n do
    fail := !fail || not(0 <= !cur && !cur <= 20000);
    t := read_int ();
    str := read_string ();
    if !str = "North" then
      cur := !cur - !t
    else if !str = "South" then
      cur := !cur + !t
    else if (!str = "East" || !str = "West") && (!cur = 0 || !cur = 20000) then
      fail := true

  done;
  Printf.printf (if not !fail && !cur = 0 then "YES" else "NO")

let () = main ()

open Printf
open Scanf

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

let () =
  let n = read_int () in

  let rec loop i x = if i=n then x=0 else
      let t = read_int() in
      match (read_string()) with
	| "South" ->
	  let x = x + t in
	  if x > 20_000 then false
	  else loop (i+1) x
	| "North" ->
	  let x = x - t in
	  if x < 0 then false
	  else loop (i+1) x
	| _ ->
	  if x = 0 || x = 20_000 then false
	  else loop (i+1) x
  in

  if loop 0 0 then printf "Yes\n" else printf "No\n"


let n = int_of_string (input_line stdin);;
let s = input_line stdin;;
let a = Array.make 26 false;;

for i = 0 to n - 1 do
  a.(Char.code (Char.lowercase s.[i]) - Char.code 'a') <- true;
done;;

if List.mem false (Array.to_list a) then print_string "NO"
else print_string "YES";;
print_newline ();;

let input () =
    let total = Scanf.scanf "%d " (fun n -> n) in
    let rec read i list =
        if i < total
        then
            let char = Char.lowercase (Scanf.scanf "%c" (fun c -> c)) in
            read (i + 1) (char :: list)
        else
            list
    in read 0 []

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

let solve list =
    let uniques = List.length (get_uniques (List.sort(Pervasives.compare) list)) in
    if uniques = 26
    then
        "YES"
    else
        "NO"

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

let answer s n =
  let a = Array.make 26 false in
  for i = 0 to n-1 do
    let c = Char.code s.[i] in
    if c >= 97 then a.(c-97) <- true
    else a.(c-65) <- true
  done;
  let b = ref true in
  for i = 0 to 25 do
    b := !b && a.(i)
  done;
  if !b then print_endline "YES" else print_endline "NO"

let () =
  let n = int_of_string (read_line ()) in
  let s = read_line () in
  answer s n


open Printf
open Scanf

let read_int () = bscanf Scanning.stdib " %d " (fun x -> x)
let () =
  let n = read_int () in
  let answer = if n=0 then 1 else [|6;8;4;2|].(n mod 4) in
  printf "%d\n" answer

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

let solve n =
    if n = 0
    then
        1
    else
        match (n mod 4) with
        | 1 -> 8
        | 2 -> 4
        | 3 -> 2
        | 4 | 0 -> 6

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

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


let input = Scanf.scanf "%d %d %d" (fun a b c -> (a, b, c))

let get_max (a, b, c)=
    List.fold_left (Pervasives.max) 0
        [a * (b + c);
        (a + b) * c;
        a * b * c;
        a * b + c;
        a + b * c;
        a + b + c]

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

let () = print (get_max (input))

let () =
let a,b,c = Scanf.scanf "%d %d %d " (fun a b c -> a,b,c) in
Printf.printf "%d\n" @@
List.fold_left max 0
[
a+b+c;
a * b * c;
(a+b) * c;
a+(b * c);
(a * b)+c;
a * (b+c);
]


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

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

module Array = struct
  include ArrayLabels
  let fold_lefti ~f ~init arr =
    let acc = ref init in
    for i = 0 to Array.length arr - 1 do
      acc := f i !acc arr.(i)
    done;
    !acc
  ;;
end
module String = StringLabels ;;
module List  = struct
  include ListLabels ;;
  let rec repeat n a = if n = 0 then [] else a :: repeat (n - 1) a ;;
  let rec drop n a =
    if n = 0 then a
    else match a with
    | [] -> failwith "cannot take"
    | x :: xs -> drop (n - 1) xs ;;

  let init ~f n =
    let res = ref [] in
    for i = 0 to n - 1 do
      res := f i :: !res
    done;
    List.rev !res
  ;;
end ;;
module H = Hashtbl ;;

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

let () =
  let n, m = sf "%d %d " (fun n m -> n, m) in
  let sock = ref n in
  let i = ref 1 in
  while !sock > 0 do
    epf "i, sock = %d, %d\n" !i !sock;
    decr sock;
    if !i > 1 && !i mod m = 0 then incr sock;
    if !sock > 0 then incr i;
  done;
  pf "%d\n" !i
;;

let input () = Scanf.scanf "%d %d" (fun n m -> (n, m))

let add socks days m =
    if days mod m = 0
    then
        socks + 1
    else
        socks

let solve (n, m) =
    let rec loop socks days =
        if socks > 0
        then
            loop ((add socks days m) - 1) (days + 1)
        else
            days - 1
    in loop n 1

let print result = Printf.printf "%d\n" result
let () = print (solve (input ()))


(* Codeforces 103A - UnilShtan *)

open Filename;;

(* you can use either gr or rdln but not both *)
let use_input_txt = false;;
let fn = (Filename.dirname Filename.current_dir_name);;
let filename = Filename.concat "." "input.txt";;
let cin = if use_input_txt then Scanf.Scanning.open_in filename
	else Scanf.Scanning.stdin;;

let cout = open_out "output.txt";;
let gr () = Scanf.bscanf cin " %d" (fun i -> i);;
let grf () = Scanf.scanf " %f" (fun i -> i);;
let grl () = Scanf.scanf " %Ld" (fun i -> i);;
let rdln() = input_line Pervasives.stdin;;
(* let spli s = Str.split (Str.regexp " ") s;; *)
let printlisti li = List.iter (fun i -> (print_int i; print_string " ")) li;;
let printlisti64 li = List.iter (fun i -> (print_string (Int64.to_string 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 -> List.rev acc
	| _ -> readlist (n -1) (gr() :: acc);;

let aa = Array.make 4 "";;

let rec readaa i n =
	if i == n then ()
	else (
		aa.(i) <- rdln();
		readaa (i +1) n
	);;

let cntaa ii jj c =
	let cnt = ref 0 in (
		for i = ii to ii +1 do
			for j = jj to jj +1 do
				if aa.(i).[j] == c then
					cnt := !cnt + 1
			done
		done;
		!cnt
	);;

let rec ifiq () =
	let iqok = ref false in
	begin
		for ii = 0 to 2 do
			for jj = 0 to 2 do
				begin
					if (cntaa ii jj '#') >= 3 then iqok := true;
					if (cntaa ii jj '.') >= 3 then iqok := true
				end
			done
		done;
		!iqok
	end;;

let main() =
	begin
		readaa 0 4;
		print_string (if ifiq() then "YES" else "NO")
	end;;

main();;

let data = Array.init 4 (fun i -> read_line () ) ;;

let solve i j = let cnt = ref 0 in
                for ii = 0 to 1 do for jj = 0 to 1 do
                        if (data.(i+ii)).[j+jj] = '#' then cnt := !cnt + 1
                 done
                done;
                !cnt <= 1;;

let solve2 i j = let cnt = ref 0 in
                for ii = 0 to 1 do for jj = 0 to 1 do
                        if (data.(i+ii)).[j+jj] = '.' then cnt := !cnt + 1
                 done
                done;
                !cnt <= 1;;

(*for i = 0 to 3 do print_endline data.(i) done;;*)

let flag = ref false;;

for i = 0 to 2 do
        for j = 0 to 2 do
                flag := !flag || solve i j || solve2 i j
        done
done;;

if !flag = false then print_string "NO\n"
else print_string "YES\n";;


open Printf open Scanf
module Lib = struct
  let i32,i64,ist = Int64.(to_int,of_int,to_string)
  let (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (%$) = (mod)
  let labs = Int64.abs
  let (+),(-),( * ),(/),(mod),(%) = Int64.(add,sub,mul,div,rem,rem)
  let (+=) r v = r := !r + v
  let (-=) r v = r := !r - v
  let ( *= ) r v = r := !r * v
  let (/=) r v = r := !r / v
  let (%=) r v = r := !r % v
  let max_i64_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 s = scanf " %s" @@ id in
  let n = gi 0 in
  let hat,rep = ref [],ref [] in
  let a = fix (fun f i x ->
    if i>=String.length s then x
    else
      let c = s.[i] in
      if c='?' || c='*' then (
        if c='?' then hat := i::!hat;
        if c='*' then rep := i::!rep;
        f (i+$1) (List.tl x)
      ) else f (i+$1) (c::x)
  ) 0 [] |> List.rev in
  let l = List.length a in
  (* printf "%d\n" l;
  print_list string_of_int !hat;
  print_list string_of_int !rep; *)
  (* print_list (String.make 1) a; *)
  rep := List.sort compare !rep;
  hat := List.sort compare !hat;
  if llen a > n then (
    print_endline "Impossible"; exit 0
  ) else if llen a = n then (
    print_endline @@ string_of_list ~separator:"" (String.make 1) a; exit 0
  );
  if List.length !rep = 0 then (
    if llen a + llen !hat < n then (
      print_endline "Impossible"; exit 0
    ) else (
      let cnt = ref @@ n - llen a in
      String.iteri (fun i c ->
        (* printf "%d :: %d <> %d :: %Ld\n" (List.length !hat) (i+$1) (List.hd !hat) !cnt; *)
        if List.length !hat > 0 && i+$1=List.hd !hat && !cnt > 0L then (
          hat := List.tl !hat;
          print_char c;
          cnt -= 1L;
        ) else if c='?' || (i <= String.length s-$2 && (s.[i+$1]='?' || s.[i+$1]='*'))
        then (

        ) else (
          print_char c;
        )
      ) s
    )
  ) else (
    let rest = i32 @@ n - llen a in
    let j = List.hd !rep in
    String.iteri (fun i c ->
      if i+$1=j then (
        repi 1 rest (fun _ -> printf "%c" c)
      )
      else
      if c='?' || c='*' || (i <= String.length s-$2 && (s.[i+$1]='?' || s.[i+$1]='*')) then ()
      else (
        print_char c
      )
    ) s
  )

let rec fix f x = f (fix f) x;;
Array.(Scanf.scanf " %s %d" @@ fun s n ->
  let a = init (String.length s) (fun i -> s.[i]) in
  let undef = -7 in
  let p,q,r,_ = fold_left (fun (p,q,r,i) -> function
  | '*' -> (List.tl p,   q,i,i+1)
  | '?' -> (List.tl p,i::q,r,i+1)
  |  _  -> (     i::p,   q,r,i+1)
  ) ([],[],undef,0) a in
  let p,q = List.(rev p, rev q) in
  if List.length p = n then
    (List.iter (fun i -> print_char a.(i)) p; exit 0)
  else if List.length p > n then
    (print_string "Impossible"; exit 0);
  let need = n - List.length p in
  let u = ref p in
  if r<>undef then (
    iteri (fun i c ->
      if List.length !u > 0 && List.hd !u = i then (
        print_char a.(i); u := List.tl !u
      ) else if i+1=r then
        for k=1 to need do print_char a.(i) done
    ) a
  ) else (
    if need > List.length q then
      (print_string "Impossible"; exit 0);
    let w = ref q in
    let rest = ref need in
    iteri (fun i c ->
      if List.length !u > 0 && List.hd !u = i then (
        print_char a.(i); u := List.tl !u
      ) else if List.length !w > 0 && List.hd !w = i+1 && !rest > 0 then (
        print_char a.(i); w := List.tl !w;
        rest := !rest - 1
      ) else if i+1=r then
        for k=1 to need do print_char a.(i) done
    ) a
  )
)

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 s = scanf " %s" @@ id in
  let n = gi 0 in
  let hat,rep = ref [],ref [] in
  let a = fix (fun f i x ->
    if i>=String.length s then x
    else
      let c = s.[i] in
      if c='?' || c='*' then (
        if c='?' then hat := i::!hat;
        if c='*' then rep := i::!rep;
        f (i+$1) (List.tl x)
      ) else f (i+$1) (c::x)
  ) 0 [] |> List.rev in
  let l = List.length a in
  (* printf "%d\n" l;
  print_list string_of_int !hat;
  print_list string_of_int !rep; *)
  (* print_list (String.make 1) a; *)
  if llen a > n then (
    print_endline "Impossible"; exit 0
  ) else if llen a = n then (
    print_endline @@ string_of_list ~separator:"" (String.make 1) a; exit 0
  );
  if List.length !rep = 0 then (
    if llen a + llen !hat > n then (
      print_endline "Impossible"; exit 0
    ) else (
      let cnt = ref @@ List.length !hat in
      String.iteri (fun i c ->
        if c='?' then ()
        else (
          if List.length !rep > 0 && i+$1=List.hd !rep && !cnt > 0 then (
            rep := List.tl !rep;
            cnt := !cnt -$ 1;
          );
          print_char c;
        )
      ) s
    )
  ) else (
    let rest = i32 @@ n - llen a in
    let j = List.hd !rep in
    String.iteri (fun i c ->
      if i+$1=j then (
        repi 1 rest (fun _ -> printf "%c" c)
      )
      else
      if c='?' || c='*' || (i <= String.length s-$2 && (s.[i+$1]='?' || s.[i+$1]='*')) then ()
      else (
        print_char c
      )
    ) s
  )

let rec fix f x = f (fix f) x;;
Array.(Scanf.scanf " %s %d" @@ fun s n ->
  let p,q,r,_ = init (String.length s) (fun i -> s.[i])
  |> fold_left (fun (p,q,r,i) c ->
    if c = '?' then (List.tl p,i::q,r,i+1)
    else if c='*' then (List.tl p,q,i::r,i+1)
    else ((c,i)::p,q,r,i+1)
  ) ([],[],[],0) in
  let p,q,r = List.(rev p,rev q,rev r) in
  if List.length p = n then
    List.map fst p |> List.iter print_char
  else if List.length p > n then
    print_endline "Impossible"
  else (
    let need = n - List.length p in
    if List.length r <> 0 then (
      let j = List.hd r in
      List.iter (fun (c,i) ->
        print_char c;
        if i=j-2 then for k=0 to need do
          print_char s.[i+1]
        done
      ) p
    ) else (
      if List.length p + List.length q < n then
        print_endline "Impossible"
      else (
        List.fold_left (fun (rest,q) (c,i) ->
          print_char c;
          match q with
          | [] -> (rest,q)
          | h::t as q ->
            if i=h-2 then (
              print_char s.[h-1]; (rest-1,t)
            ) else (rest,q)
        ) (need,q) p |> ignore
      )
    )
  ))

let rec fix f x = f (fix f) x;;
Array.(Scanf.scanf " %s %d" @@ fun s n ->
  let p,q,r,_ = init (String.length s) (fun i -> s.[i])
  |> fold_left (fun (p,q,r,i) c ->
    if c = '?' then (List.tl p,i::q,r,i+1)
    else if c='*' then (List.tl p,q,i::r,i+1)
    else ((c,i)::p,q,r,i+1)
  ) ([],[],[],0) in
  let p,q,r = List.(rev p,rev q,rev r) in
  if List.length p = n then
    List.map fst p |> List.iter print_char
  else if List.length p > n then
    print_endline "Impossible"
  else (
    let need = n - List.length p in
    if List.length r <> 0 then (
      let j = List.hd r in
      List.iter (fun (c,i) ->
        print_char c;
        if i=j-2 then for k=1 to need do
          print_char s.[i+1]
        done
      ) p
    ) else (
      if List.length p + List.length q < n then
        print_endline "Impossible"
      else (
        List.fold_left (fun (rest,q) (c,i) ->
          print_char c;
          match q with
          | [] -> (rest,q)
          | h::t as q ->
            if i=h-2 then (
              print_char s.[h-1]; (rest-1,t)
            ) else (rest,q)
        ) (need,q) p |> ignore
      )
    )
  ))


open Printf
open Scanf

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

let isupper c = c <= 'Z' && c >= 'A'
let toupper = Char.uppercase

let read_string () = bscanf Scanning.stdib " %s " (fun x -> x)
let () =
  let board = Array.init 8 (fun _ -> read_string()) in

  let score p =
    let s = match toupper p with
      | 'K' -> 0
      | 'Q' -> 9
      | 'R' -> 5
      | 'B' -> 3
      | 'N' -> 3
      | 'P' -> 1
      | '.' -> 0
      | _ -> failwith "bad input"
    in

    if isupper p then s else -s
  in

  let answer = sum 0 7 (fun i -> sum 0 7 (fun j -> score board.(i).[j])) in

  if answer = 0 then printf "Draw\n"
  else if answer > 0 then printf "White\n"
  else printf "Black\n"

let evalue = function
	|'Q'	-> (9,0)
	|'R'	-> (5,0)
	|'B'	-> (3,0)
	|'N'	-> (3,0)
	|'P'	-> (1,0)
	|'q'	-> (0,9)
	|'r'	-> (0,5)
	|'b'	-> (0,3)
	|'n'	-> (0,3)
	|'p'	-> (0,1)
	|_	-> (0,0);;

let main () =
	let a = ref 0 and b = ref 0 and l= ref [] in
	for i=0 to 7 do
		l := (Scanf.scanf "%s\n" (fun j -> j))::!l;
	done;
	List.iter (fun x ->
			for i=0 to String.length x - 1 do
				let (c,d) = evalue (x.[i]) in
					a:= !a + c;
					b:= !b + d;
			done) !l;
	if !a < !b
		then Printf.printf "Black"
		else if !a = !b
			then Printf.printf "Draw"
			else Printf.printf "White";;

main ();;

let score x =
    let check_upp = function
        | 'a' .. 'z' -> false
        | 'A' .. 'Z' -> true
        | _ -> false in
    let upper x = (if (check_upp x) then x else Char.uppercase x) in
    ((if (check_upp x) then 0 else 1) , match (upper x) with
        | 'Q' -> 9
        | 'R' -> 5
        | 'B' -> 3
        | 'N' -> 3
        | 'P' -> 1
        | _ -> 0);;

(*Running Code*)
let ans = [|ref 0; ref 0|];;
for i = 1 to 8 do
    let a = ref (read_line ()) in
    for j = 0 to ((String.length !a) - 1) do
        let p = (score !a.[j]) in
        (ans.(fst p)) := !(ans.(fst p)) + (snd p);
    done;
done;;
print_string (if (!(ans.(0)) > !(ans.(1))) then "White" else (if (!(ans.(0)) = !(ans.(1))) then "Draw" else "Black"));;
print_string "\n"

let read () = Scanf.scanf "%c " (fun c -> c)

let colour char =
    if char != '.' && char != '\n'
    then
        if Char.lowercase char = char
        then
            `Black
        else
            `White
    else
        `Pass

let count char score =
    match Char.lowercase char with
    | 'q' -> score + 9
    | 'r' -> score + 5
    | 'b' | 'n' -> score + 3
    | 'p' -> score + 1
    | 'k' -> score

let get_winner black white =
    if black > white
    then
        "Black"
    else
        if white > black
        then
            "White"
        else
            "Draw"

let solve () =
    let rec loop i score_black score_white =
        if i < 64
        then
            let char = read () in
                match (colour char) with
                | `Black -> loop (i + 1) (count char score_black) score_white
                | `White -> loop (i + 1) score_black (count char score_white)
                | `Pass -> loop (i + 1) score_black score_white
        else
            get_winner score_black score_white
    in loop 0 0 0

let print winner = Printf.printf "%s\n" winner
let () = print (solve ())

let evalue = function
	|'Q'	-> (9,0)
	|'R'	-> (5,0)
	|'B'	-> (3,0)
	|'N'	-> (3,0)
	|'P'	-> (1,0)
	|'q'	-> (0,9)
	|'r'	-> (0,5)
	|'b'	-> (0,3)
	|'n'	-> (0,3)
	|'p'	-> (0,1)
	|_	-> (0,0);;

let main () =
	let a = ref 0 and b = ref 0 and l= ref [] in
	for i=0 to 7 do
		l := (Scanf.scanf "%s" (fun j -> j))::!l;
	done;
	List.iter (fun x ->
			for i=0 to String.length x - 1 do
				let (c,d) = evalue (x.[i]) in
					a:= !a + c;
					b:= !b + d;
			done) !l;
	if !a < !b
		then Printf.printf "White"
		else if !a = !b
			then Printf.printf "Draw"
			else Printf.printf "Black";;

main ();;

open Printf
open Scanf

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

let isupper c = c <= 'Z' && c >= 'A'
let toupper = Char.uppercase

let read_string () = bscanf Scanning.stdib " %s " (fun x -> x)
let () =
  let board = Array.init 8 (fun _ -> read_string()) in

  let score p =
    let s = match toupper p with
      | 'K' -> 0
      | 'Q' -> 8
      | 'R' -> 5
      | 'B' -> 3
      | 'N' -> 3
      | 'P' -> 1
      | '.' -> 0
      | _ -> failwith "bad input"
    in

    if isupper p then s else -s
  in

  let answer = sum 0 7 (fun i -> sum 0 7 (fun j -> score board.(i).[j])) in

  if answer = 0 then printf "Draw\n"
  else if answer > 0 then printf "White\n"
  else printf "Black\n"


let read_int () = Scanf.scanf " %d " (fun x -> x)
let solve n = if n > 2 then n - 2 else n + 2

let main () =
        let n = read_int () in
        let answer = if n > 2 then n - 2 else n + 2 in
        print_int answer;;

main ()

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let m =
    if n + 2 <= 1000
    then n + 2
    else n - 2
  in
    Printf.printf "%d\n" m

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let m = n + 2 in
    Printf.printf "%d\n" m


let input () = Scanf.scanf "%s" (fun s -> (s, String.length s))

let traverse (remix, l) =
    let rec loop i original =
        if i + 3 <= l
        then
            if remix.[i] = 'W'
            then
                if remix.[i + 1] = 'U'
                then
                    if remix.[i + 2] = 'B'
                    then
                        loop (i + 3) (' ' :: original)
                    else
                        loop (i + 2) (remix.[i + 1] :: remix.[i] :: original)
                else
                    loop (i + 1) (remix.[i] :: original)
            else
                loop (i + 1) (remix.[i] :: original)
        else
            if i + 2 <= l
            then
                (' ' :: remix.[i + 1] :: remix.[i] :: original)
            else
                if i + 1 <= l
                then
                    (' ' :: remix.[i] :: original)
                else
                    (' ' :: original)
    in loop 0 [' ']

let solve input = List.rev (traverse input)

let build result =
    let rec loop last list temp =
        (match (temp, last) with
            |(' ' :: tail), ' ' -> loop ' ' list tail
            |(x :: tail), _ ->
               loop x (x :: list) tail
            |[], _ -> List.rev list)
    in loop ' ' [] result

let rec print list =
    (match list with
    |[' '] -> ()
    |(x :: tail) ->
        Printf.printf "%c" x;
        print tail
    |[] -> ())

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

let str_to_list s =
    let rec loop i l =
        if i < 0
        then l
        else loop (i - 1) (s.[i] :: l) in
    loop (String.length s - 1) []

let input () = Scanf.scanf "%s" (fun s -> str_to_list s)

let traverse input =
    let rec loop remix original =
        match remix with
        |('W' :: 'U' :: 'B' :: tail) -> loop tail (' ' :: original)
        |[] -> List.rev original
        |(x :: tail) -> loop tail (x :: original)
    in loop input [' ']

let build result =
    let rec loop last list temp =
        (match (temp, last) with
            |(' ' :: tail), ' ' -> loop ' ' list tail
            |(x :: tail), _ ->
               loop x (x :: list) tail
            |[], _ -> List.rev list)
    in loop ' ' [] result

let rec print list =
    (match list with
    |[' '] -> ()
    |(x :: tail) ->
        Printf.printf "%c" x;
        print tail
    |[] -> ())

let () = print (build (traverse (input())))

let split_WUB s =
  Str.split (Str.regexp "WUB") s

let add_space words =
  let f word =
    if word = "" then word
    else " " ^ word
  in
  (List.hd words) ::  (List.map f (List.tl words))

let solve s =
  List.iter (Printf.printf "%s") (add_space (split_WUB s))

let _ =
  Scanf.scanf " %s" solve


let ints = read_line () |> Str.split (Str.regexp " +")  |> List.map int_of_string in
let d1 = List.nth ints 0 and
    d2 = List.nth ints 1 and
    d3 = List.nth ints 2 and
    max_int = Int32.shift_right (Int32.max_int) 1 |> Int32.to_int in
List.fold_right min [d1+d3+d2; d1+d1+d2+d2; d2+d3+d3+d2 ;d1+d3+d3+d1] max_int |> print_int

open Printf
open Scanf

let ( ** ) a b = Int64.mul a b
let ( ++ ) a b = Int64.add a b
let ( -- ) a b = Int64.sub a b
let long x = Int64.of_int x

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

let () =
  let d1 = read_int () in
  let d2 = read_int () in
  let d3 = read_int () in

  let answer = min (min ((d1++d2)**2L) (d1++d2++d3)) (min ((d1++d3)**2L) ((d2++d3)**2L)) in

  printf "%Ld\n" answer

let input () = Scanf.scanf "%d %d %d" (fun d1 d2 d3 -> d1, d2, d3)
let solve (d1, d2, d3) =
    let p1 = d1 + d2 + d3 in
    let p2 = 2 * d1 + 2 * d2 in
    let p3 = 2 * d1 + 2 * d3 in
    let p4 = 2 * d2 + 2 * d3 in
    let paths = (p1 :: p2 :: p3 :: p4 :: []) in
    let min = List.hd (List.sort (Pervasives.compare) paths) in
    min
let print result = Printf.printf "%d\n" result
let () = print (solve (input ()))

let ints = read_line () |> Str.split (Str.regexp " +")  |> List.map int_of_string in
let d1 = List.nth ints 0 and
    d2 = List.nth ints 1 and
    d3 = List.nth ints 2 and
    max_int = Int32.shift_right (Int32.max_int) 1 |> Int32.to_int in
List.fold_right min [d1+d3+d2; d1+d1+d2+d2; d2+d3+d1] max_int |> print_int

let ints = read_line () |> Str.split (Str.regexp " +")  |> List.map int_of_string in
let d1 = List.nth ints 0 and
    d2 = List.nth ints 1 and
    d3 = List.nth ints 2 and
    max_int = Int32.shift_right (Int32.max_int) 1 |> Int32.to_int in
List.fold_right min [d1+d3+d2; d1+d1+d2+d2; d2+d3+d1; d2+d3+d3+d2] max_int |> print_int

open Printf
open Scanf

let ( ** ) a b = Int64.mul a b
let ( ++ ) a b = Int64.add a b
let ( -- ) a b = Int64.sub a b
let long x = Int64.of_int x

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

let () =
  let d1 = read_int () in
  let d2 = read_int () in
  let d3 = read_int () in

  let answer = min ((d1++d2)**2L) (d1++d2++d3) in

  printf "%Ld\n" answer

open Printf
open Scanf

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

let () =
  let d1 = read_int () in
  let d2 = read_int () in
  let d3 = read_int () in

  let answer = min ((d1+d2)*2) (d1+d2+d3) in

  printf "%d\n" answer


open Printf
open Scanf

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

let read_int _ = bscanf Scanning.stdib " %d " (fun x -> x)
let () =
  let n = read_int () in
  let k = read_int () in
  let a = Array.init n read_int in

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

  printf "%d\n" (max 0 (2*n*k - n - 2 * s))

let read ()  = Scanf.scanf " %d" (fun x -> x) and
    foi = float_of_int in
let (k,n) = (read(), read()) in
let s = ref 0 in
for i = 0 to n-1 do s := !s + (read()) done;
let (fn , fs, fk ) = (foi n, foi !s, foi k) in
print_int @@ if fs /. fn  > fk -. 0.5 then 0 else int_of_float @@ ((fn *. (fk -. 0.5)) -. fs) /. 0.5

let read ()  = Scanf.scanf " %d" (fun x -> x) and
    foi = float_of_int in
let (k,n) = (read(), read()) in
let s = ref 0 in
for i = 0 to n-1 do s := !s + (read()) done;
let (fn , fs, fk ) = (foi n, foi !s, foi k) in
print_int @@ int_of_float @@ ((fn *. (fk -. 0.5)) -. fs) /. 0.5


let ps = ["vaporeon"; "jolteon"; "flareon"; "espeon"; "umbreon"; "leafeon"; "glaceon"; "sylveon"]

let () =
  Scanf.scanf "%d %s " (fun n s ->
    let pat = Str.regexp ("^" ^ s ^ "$") in
    print_endline (List.find (fun p -> Str.string_match pat p 0) ps))
;;

let ps = ["vaporeon"; "jolteon"; "flareon"; "espeon"; "umbreon"; "leafeon"; "glaceon"; "sylveon"]

let () =
  Scanf.scanf "%d %s " (fun n s ->
    let pat = Str.regexp s in
    print_endline (List.find (fun p -> String.length s = String.length p && Str.string_match pat p 0) ps))
;;

let ps = ["vaporeon"; "jolteon"; "flareon"; "espeon"; "umbreon"; "leafeon"; "glaceon"; "sylveon"]

let () =
  Scanf.scanf "%d %s " (fun n s ->
    let pat = Str.regexp s in
    print_endline (List.find (fun p -> Str.string_match pat p 0) ps))
;;


let _ =
  let sb = Scanf.Scanning.stdib in
  let a = Scanf.bscanf sb "%d " (fun s -> s) in
  let b = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = a - 1 in
  let d = [| 6; 2; 5; 5; 4; 5; 6; 3; 7; 6 |] in
  let t = 49 in
  let rec calc n =
    if n = 0
    then 0
    else (
      let r = ref 0 in
      let c = n mod 10 in
	if c = 0
	then (
	  let m = ref n in
	    while !m > 0 do
	      r := !r + d.(!m mod 10);
	      m := !m / 10;
	    done;
	    (*Printf.printf "qwe1 %d %d\n" n (!r - d.(0) + t * (n / 10));*)
	    !r - d.(0) + t * (n / 10) + 10 * calc ((n - 1) / 10);
	) else (
	  let m = ref n in
	    while !m > 0 do
	      r := !r + d.(!m mod 10);
	      m := !m / 10;
	    done;
	    r := (!r - d.(c)) * c;
	    for i = 1 to c do
	      r := !r + d.(i);
	    done;
	    (*!r + t * (n / 10) + 10 * calc (n / 10)*)
	    (*Printf.printf "qwe2 %d %d\n" n !r;*)
	    !r + calc (n - c)
	)
    )
  in
  let res = calc b - calc a in
    Printf.printf "%d\n" res

open Printf
open Scanf

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

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

  let tab = [|6;2;5;5;4;5;6;3;7;6|] in
          (*  0 1 2 3 4 5 6 7 8 9 *)

  let score x = if x=0 then tab.(0) else
      let rec loop x = if x=0 then 0 else tab.(x mod 10) + loop (x/10) in
      loop x
  in

  printf "%d\n" (sum a b score)

let num_segs = function
  | 0 -> 6
  | 1 -> 2
  | 2 -> 5
  | 3 -> 5
  | 4 -> 4
  | 5 -> 5
  | 6 -> 6
  | 7 -> 3
  | 8 -> 7
  | 9 -> 6

let rec total_segs = function
  | 0 -> 0
  | n -> num_segs (n mod 10) + total_segs (n / 10)

let () =
  let [lo; hi] = read_line ()
    |> Str.split (Str.regexp " ")
    |> List.map int_of_string in
  let sum = ref 0 in
  for i = lo to hi do
    sum := !sum + total_segs i
  done;
  print_int !sum;
  print_newline ()

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = Array.make n 0 in
  let _ =
    for i = 0 to n - 1 do
      a.(i) <- Scanf.bscanf sb "%d " (fun s -> s)
    done;
  in
  let ks = ref [] in
  let ht = Hashtbl.create 10 in
  let prev = ref (-1) in
    for i = 0 to n - 1 do
      if Hashtbl.mem ht a.(i) then (
	ks := (!prev + 1, i) :: !ks;
	prev := i;
	Hashtbl.clear ht;
      ) else (
	Hashtbl.replace ht a.(i) ()
      )
    done;
    let ks =
      if !prev = n - 1
      then !ks
      else (
	match !ks with
	  | [] ->
	      Printf.printf "-1\n";
	      exit 0
	  | (l, r) :: ks ->
	      (l, n - 1) :: ks
      )
    in
    let ks = List.rev ks in
      Printf.printf "%d\n" (List.length ks);
      List.iter
	(fun (l, r) ->
	   Printf.printf "%d %d\n" (l + 1) (r + 1)
	) ks


(* Codeforces  *)

(* 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 printlists ls = List.iter (fun s -> (print_string s; print_string " ")) ls;;

let rec head_cnt k cnt l = match l with
| [] -> (cnt, [])
| h :: tl ->
	if h > k then (cnt, l)
	else head_cnt k (cnt+1) tl;;

let main() =
	let n = gr () in
	let k = gr () in
	let a = readlist n [] in
	let ha, tl = head_cnt k 0 a in
	let rev_tl = List.rev tl in
	let ta, _ = head_cnt k 0 rev_tl in
	begin
		(* print_string "a = "; printlisti a;
		print_string " ha = ";
		print_int ha; print_string "  ta = ";
		print_int ta; print_string " \n"; *)
		print_int (ha + ta);
		print_string "\n"
   end;;

main();;

let ( */ ) = Big_int.mult_big_int;;
let ( +/ ) = Big_int.add_big_int;;
let ( -/ ) = Big_int.sub_big_int;;
let to_int = Big_int.int_of_big_int;;
let of_int = Big_int.big_int_of_int;;
let min = Big_int.min_big_int;;
let (modi) = Big_int.mod_big_int;;
let to_string = Big_int.string_of_big_int;;
let of_string = Big_int.big_int_of_string;;
let (</) = Big_int.lt_big_int;;

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

exception End;;

let n,k = Scanf.sscanf (read_line ()) "%i %i" (fun n k -> n,k)  in
let problem = read_line () |> split_on_char ' ' |> List.map int_of_string  |> Array.of_list in
let count = ref 0 in
while !count < n && problem.(!count) <= k do
  incr count;
done;
let tmp = !count in
begin try
  for i = n - 1 downto tmp + 1 do
    if problem.(i) > k then raise End;
    incr count;
  done
  with End -> ();
end;
Printf.printf "%i" !count;
print_newline ();


(* http://codeforces.com/contest/104/problem/A *)

let f n =
  if 0 <= n && n <= 10 then 0
  else if 11 <= n && n <= 19 then 4
  else if n = 20 then 15
  else if n = 21 then 4
  else 0;;
Printf.printf "%d\n" (Scanf.scanf "%d" f);;

let n = read_int () - 10 in
print_int (if n = 10 then 15
else if n >= 1 && n <= 11 then 4
else 0)

(* http://codeforces.com/contest/104/problem/A *)

let f n =
  if 0 <= n && n <= 10 then 0
  else if 11 <= n && n <= 19 then 4
  else if n = 20 then 15
  else if n = 21 then 1
  else 0;;
Printf.printf "%d\n" (Scanf.scanf "%d" f);;


open Int64;;
let scan_int () = Scanf.scanf " %d" (fun x -> x)
let scan_ll () = Scanf.scanf " %Ld" (fun x -> x)
let pom = function (4 | 7) -> 1 | _ -> 0;;

let rec fart n =
	let rec lucky x acc = match x with
		|0L -> acc
		|_ -> lucky (div x 10L) (acc + (pom(to_int(rem x 10L))))
	in
lucky n 0;;

let n = scan_ll ()
let kek = fart n;;
(*print_int kek;;*)

let s = match kek with
	|(4 | 7) -> "YES"
	|_ ->"NO"
;;

print_string s;;

let n = read_line() in
let m = ref 0 in
let _ = String.iter (function
	| ('4'|'7') -> incr m
	| _ -> ()
) n in
print_string (if !m = 4 || !m = 7 then "YES" else "NO");

open Int64;;
let scan_int () = Scanf.scanf " %d" (fun x -> x)
let scan_ll () = Scanf.scanf " %Ld" (fun x -> x)
let ten = of_int(10);;
let zero = of_int(0);;
let pom = function (4 | 7) -> 1 | _ -> 0;;

let rec fart n =
	let rec lucky x acc =
		if x = zero then acc
		else lucky (div x ten) (acc + (pom(to_int(rem x ten))))
	in
lucky n 0;;

let n = scan_ll ()
let kek = fart n;;
(*print_int kek;;*)

let s = match kek with
	|(4 | 7) -> "YES"
	|_ ->"NO"
;;

print_string s;;

let str_to_list s =
    let rec loop i l =
        if i < 0
        then l
        else loop (i - 1) (s.[i] :: l) in
    loop (String.length s - 1) []

let input () = Scanf.scanf "%s" (fun s -> (str_to_list s))

let is_lucky_numbers = function
    |'4' | '7'-> true
    |_ -> false

let count input = List.length(List.filter(is_lucky_numbers) input)

let solve input =
    if is_lucky_numbers(String.get (Pervasives.string_of_int(count input)) 0)
    then
        "YES"
    else
        "NO"

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

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

let n = String.length (read_line()) in
print_string (if n = 4 || n = 7 then "YES" else "NO")