Little Elephant loves magic squares very much.A magic square is a 3 × 3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15.  The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105. Help the Little Elephant, restore the original magic square, given the Elephant's notes.

The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes. It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105.

Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105. It is guaranteed that there exists at least one magic square that meets the conditions.

(* Codeforces 257B SlonMagSquare *)

open Filename;;
open String;;

(* 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 printarri ai = Array.iter (fun i -> (print_int i; print_string " ")) ai;;
let debug = false;;

let mg = Array.make_matrix 3 3 0;;

let readmat () =
	begin
		for i = 0 to 2 do
			for j = 0 to 2 do
				mg.(i).(j) <- gr()
			done
		done
	end;;

let solve() =
	let cma = (mg.(0).(1) + mg.(0).(2) - mg.(2).(0) - mg.(2).(1)) in
	let bma = mg.(0).(1) + mg.(0).(2) - mg.(1).(0) - mg.(1).(2) in
	let cpa = mg.(2).(0) + mg.(0).(2) in
	let c = (cpa + cma) / 2 in
	let a = (cpa - cma) / 2 in
	let b = a + bma in
	begin
		mg.(0).(0) <- a;
		mg.(1).(1) <- b;
		mg.(2).(2) <- c;
	end;;

let printmat () =
	for i = 0 to 2 do
		begin
			for j = 0 to 2 do
				begin
					print_int mg.(i).(j);
					print_string " "
				end
			done;
			print_newline ()
		end
	done;;

let main () =
	begin
		readmat ();
		solve();
		printmat()
	end;;

main();;

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

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

let () =
  let a = Array.make_matrix 3 3 0 in
    for i=0 to 2 do
      for j=0 to 2 do
	a.(i).(j) <- read_int()
      done
    done;

    let ismagic () =
      let s = sum 0 2 (fun i -> a.(i).(i)) in
	sum 0 2 (fun i -> a.(i).(2-i)) = s &&
(*	sum 0 2 (fun i -> a.(0).(i)) = s &&
	sum 0 2 (fun i -> a.(1).(i)) = s &&
	sum 0 2 (fun i -> a.(2).(i)) = s && *)
	sum 0 2 (fun i -> a.(i).(0)) = s &&
	sum 0 2 (fun i -> a.(i).(1)) = s &&
	sum 0 2 (fun i -> a.(i).(2)) = s
    in

    let rec loop t = if t>100_000 then false else (
      a.(0).(0) <- t;
      let s = t + a.(0).(1) + a.(0).(2) in
	a.(1).(1) <- s - a.(1).(0) - a.(1).(2);
	a.(2).(2) <- s - a.(2).(0) - a.(2).(1);
	if ismagic () then true else loop (t+1)
    )
    in

      if loop 0 then (
	for i=0 to 2 do
	  for j=0 to 2 do
	    Printf.printf "%d " a.(i).(j)
	  done;
	  print_newline()
	done
      ) else (
	Printf.printf "impossible\n"
      )


Mad scientist Mike is busy carrying out experiments in chemistry. Today he will attempt to join three atoms into one molecule.A molecule consists of atoms, with some pairs of atoms connected by atomic bonds. Each atom has a valence number — the number of bonds the atom must form with other atoms. An atom can form one or multiple bonds with any other atom, but it cannot form a bond with itself. The number of bonds of an atom in the molecule must be equal to its valence number.  Mike knows valence numbers of the three atoms. Find a molecule that can be built from these atoms according to the stated rules, or determine that it is impossible.

The single line of the input contains three space-separated integers a, b and c (1 ≤ a, b, c ≤ 106) — the valence numbers of the given atoms.

If such a molecule can be built, print three space-separated integers — the number of bonds between the 1-st and the 2-nd, the 2-nd and the 3-rd, the 3-rd and the 1-st atoms, correspondingly. If there are multiple solutions, output any of them. If there is no solution, print "Impossible" (without the quotes).

NoteThe first sample corresponds to the first figure. There are no bonds between atoms 1 and 2 in this case.The second sample corresponds to the second figure. There is one or more bonds between each pair of atoms.The third sample corresponds to the third figure. There is no solution, because an atom cannot form bonds with itself.The configuration in the fourth figure is impossible as each atom must have at least one atomic bond.

let (a, b, c) = Scanf.scanf "%d %d %d" (fun a b c -> (a, b, c)) in
    (* iterate over number of bonds between a and b *)
    try
        for i = 0 to (min a b) do
            let (ba, bb, bc) = (i, b - i, a - i) in
            if bb < 0 || bc < 0 ||
               not (a = ba + bc && b = ba + bb && c = bb + bc) then ()
            else begin
                Printf.printf "%d %d %d\n" ba bb bc ;
                raise Exit
            end
        done ;
        Printf.printf "Impossible\n"
    with Exit -> () ;;


Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):  After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.

There are two characters in the first string – the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space. In the second strings, a single number n is given (0 ≤ n ≤ 109) – the duration of the rotation. It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.

Output cw, if the direction is clockwise, ccw – if counter-clockwise, and undefined otherwise.

let id x = x and
    f = function
          '>' -> 0
        | '^' -> 90
        | '<' -> 180
        | 'v' -> 270 and
    g = function
          x when x < 0 -> 360 + x
        | x when x > 360 -> x - 360
        | x -> x in

let a = f @@ Scanf.scanf " %c" id and
b = f @@ Scanf.scanf " %c" id and
n = (Scanf.scanf " %d" id) mod 4 in

let c = g (a-b) in
print_string (if c==180 || c == 0 then "undefined" else if c / 90 == n then "cw" else "ccw")

let id x = x and
    f = function
          '>' -> 0
        | '^' -> 90
        | '<' -> 180
        | 'v' -> 270 and
    g = function
          x when x < 0 -> 360 + x
        | x when x > 360 -> x - 360
        | x -> x in

let a = f @@ Scanf.scanf " %c" id and
b = f @@ Scanf.scanf " %c" id and
n = (Scanf.scanf " %d" id) mod 4 in

let c = g (a-b) in
print_string (if c==180 then "undefined" else if c / 90 == n then "cw" else "ccw")


Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word s. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word s.

The first and only line contains the word s, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.

If Vasya managed to say hello, print "YES", otherwise print "NO".

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

let h = "hello";;
let j = ref 0;;
let c = ref (String.get h !j);;
let flag = ref "NO";;

exception Success;;
  try
for i = 0 to String.length s - 1 do
  let si = String.get s i in
  if(si == !c) then
    begin
      incr j;
      if (!j > 4) then raise Success;
      c := String.get h !j;
    end
done
  with Success -> flag := "YES";;

    print_endline !flag;;

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

let rec traverse input target i n =
    if i < String.length target
    then
        if n < String.length input
        then
            let char = String.get input n in
            if char = String.get target i
            then
                traverse input target (i + 1) (n + 1)
            else
                traverse input target i (n + 1)
        else
            "NO"
    else
        "YES"

let solve input = traverse input "hello" 0 0

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

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

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

let rec traverse input target i n =
    if n < String.length input
    then
        if i < String.length target
        then
            let char = String.get input n in
            if char = String.get target i
            then
                if i + 1 = String.length target
                then
                    "YES"
                else
                    traverse input target (i + 1) (n + 1)
            else
                traverse input target i (n + 1)
        else
            "NO"
    else
        "NO"

let solve input = traverse input "hello" 0 0

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

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

let s = read_line () in
let a = try
	let i = ref 0 in
	let _ = String.iter (fun c ->
		i := String.index_from s (!i) c + 1
	) "hello" in
	"YES"
with _ -> "NO" in
print_string a;;

open List;;

let chat = fun s ->
        let hello = ['h';'e';'l';'l';'o'] in

        let rec pom l i len =
                if i > len || (i = len && l != [] ) then
                     print_string "NO"
                else
                        match l with
                        |[] ->  print_string "YES"
                        | hl::tl -> if s.[i] = hl then pom tl (i + 1) len
               else pom l (i + 1) len
        in pom hello 0 (String.length s)
;;

Scanf.scanf "%s" chat;;

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

let rec traverse input target i n =
    if n < String.length input
    then
        if i + 1 < String.length target
        then
            let char = String.get input n in
            if char = String.get target i
            then
                traverse input target (i + 1) (n + 1)
            else
                traverse input target i (n + 1)
        else
            "YES"
    else
        "NO"

let solve input = traverse input "hello" 0 0

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

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

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

let rec traverse input target i n =
    if n < String.length input
    then
        if i < String.length target
        then
            let char = String.get input n in
            if char = String.get target i
            then
                traverse input target (i + 1) (n + 1)
            else
                traverse input target i (n + 1)
        else
            "YES"
    else
        "NO"

let solve input = traverse input "hello" 0 0

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

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

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

let rec traverse input target i n =
    if n < String.length input
    then
        if i < String.length target
        then
            let char = String.get input n in
            if char = String.get target i
            then
                if i = String.length target
                then
                    "YES"
                else
                    traverse input target (i + 1) (n + 1)
            else
                traverse input target i (n + 1)
        else
            "NO"
    else
        "NO"

let solve input = traverse input "hello" 0 0

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

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

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

let rec traverse input target i n =
    if n < String.length input
    then
        if i = String.length target
        then
            "YES"
        else
            let char = String.get input n in
            if char = String.get target i
            then
                traverse input target (i + 1) (n + 1)
            else
                traverse input target i (n + 1)
    else
        "NO"

let solve input = traverse input "hello" 0 0

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

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

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

let h = "hello";;
let j = ref 0;;
let c = ref (String.get h !j);;
let flag = ref "NO";;

exception Success;;
  try
for i = 0 to String.length s - 1 do
  let si = String.get s i in
  if(si == !c) then
    begin
      incr j;
      c := String.get h !j;
      if (!j>=4) then raise Success
    end
done
  with Success -> flag := "YES";;

    print_endline !flag;;


Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there. The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string s with the following structure:  if si = "?", then the digit that goes i-th in the safe code can be anything (between 0 to 9, inclusively);  if si is a digit (between 0 to 9, inclusively), then it means that there is digit si on position i in code;  if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits.  The length of the safe code coincides with the length of the hint. For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666".After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night...

The first line contains string s — the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0. The input limits for scoring 30 points are (subproblem A1):    1 ≤ |s| ≤ 5.  The input limits for scoring 100 points are (subproblems A1+A2):    1 ≤ |s| ≤ 105.  Here |s| means the length of string s.

Print the number of codes that match the given hint.

open Big_int

let (+|) = add_big_int
let (-|) = sub_big_int
let ( *| ) = mult_big_int
let (/|) = div_big_int
let bmod = mod_big_int
let (=|) = eq_big_int
let (/=|) a b = not (a =| b)
let (>|) = gt_big_int
let (<|) = lt_big_int
let (>=|) = ge_big_int
let (<=|) = le_big_int

let n0 = zero_big_int
let n1 = unit_big_int
let n2 = big_int_of_int 2
let n9 = big_int_of_int 9
let n10 = big_int_of_int 10

let _ =
  let sb = Scanf.Scanning.stdib in
  let s = Scanf.bscanf sb "%s " (fun s -> s) in
  let n = String.length s in
  let a = Array.make 10 false in
  let cnt = ref 10 in
  let res = ref n1 in
    for i = 0 to n - 1 do
      let c = s.[i] in
	match c with
	  | '0'..'9' -> ()
	  | '?' ->
	      if i = 0
	      then res := !res *| n9
	      else res := !res *| n10
	  | 'A'..'J' ->
	      let k = Char.code c - Char.code 'A' in
		if not a.(k) then (
		  a.(k) <- true;
		  if i = 0
		  then res := !res *| n9
		  else res := !res *| (big_int_of_int !cnt);
		  decr cnt
		)
	  | _ -> assert false
    done;
    Printf.printf "%s\n" (string_of_big_int !res)

open Big_int

let (+|) = add_big_int
let (-|) = sub_big_int
let ( *| ) = mult_big_int
let (/|) = div_big_int
let bmod = mod_big_int
let (=|) = eq_big_int
let (/=|) a b = not (a =| b)
let (>|) = gt_big_int
let (<|) = lt_big_int
let (>=|) = ge_big_int
let (<=|) = le_big_int

let n0 = zero_big_int
let n1 = unit_big_int
let n2 = big_int_of_int 2
let n9 = big_int_of_int 9
let n10 = big_int_of_int 10

let _ =
  let sb = Scanf.Scanning.stdib in
  let s = Scanf.bscanf sb "%s " (fun s -> s) in
  let n = String.length s in
  let a = Array.make 10 false in
  let b = Array.make 11 0 in
  let cnt = ref 10 in
  let res = ref n1 in
    for i = 0 to n - 1 do
      let c = s.[i] in
	match c with
	  | '0'..'9' -> ()
	  | '?' ->
	      if i = 0
	      then b.(9) <- b.(9) + 1
	      else b.(10) <- b.(10) + 1
	  | 'A'..'J' ->
	      let k = Char.code c - Char.code 'A' in
		if not a.(k) then (
		  a.(k) <- true;
		  if i = 0
		  then b.(9) <- b.(9) + 1
		  else b.(!cnt) <- b.(!cnt) + 1;
		  decr cnt
		)
	  | _ -> assert false
    done;
    for i = 1 to 10 do
      res := !res *| power_int_positive_int i b.(i)
    done;
    Printf.printf "%s\n" (string_of_big_int !res)


Modern text editors usually show some information regarding the document being edited. For example, the number of words, the number of pages, or the number of characters.In this problem you should implement the similar functionality.You are given a string which only consists of:  uppercase and lowercase English letters,  underscore symbols (they are used as separators),  parentheses (both opening and closing). It is guaranteed that each opening parenthesis has a succeeding closing parenthesis. Similarly, each closing parentheses has a preceding opening parentheses matching it. For each pair of matching parentheses there are no other parenthesis between them. In other words, each parenthesis in the string belongs to a matching "opening-closing" pair, and such pairs can't be nested.For example, the following string is valid: "_Hello_Vasya(and_Petya)__bye_(and_OK)".Word is a maximal sequence of consecutive letters, i.e. such sequence that the first character to the left and the first character to the right of it is an underscore, a parenthesis, or it just does not exist. For example, the string above consists of seven words: "Hello", "Vasya", "and", "Petya", "bye", "and" and "OK". Write a program that finds:  the length of the longest word outside the parentheses (print 0, if there is no word outside the parentheses),  the number of words inside the parentheses (print 0, if there is no word inside the parentheses).

The first line of the input contains a single integer n (1 ≤ n ≤ 255) — the length of the given string. The second line contains the string consisting of only lowercase and uppercase English letters, parentheses and underscore symbols.

Print two space-separated integers:   the length of the longest word outside the parentheses (print 0, if there is no word outside the parentheses),  the number of words inside the parentheses (print 0, if there is no word inside the parentheses).

NoteIn the first sample, the words "Hello", "Vasya" and "bye" are outside any of the parentheses, and the words "and", "Petya", "and" and "OK" are inside. Note, that the word "and" is given twice and you should count it twice in the answer.

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

let parse_sentence sentence length =
  let w_outside = ref [] in
  let w_inside = ref [] in
  let buffer = Buffer.create length in
  let in_flag = ref false in
  for i = 0 to length - 1 do
    let c = sentence.[i] in
    if c = '(' then
      begin
        in_flag := true;
        if Buffer.length buffer != 0 then
          begin
            w_outside := (Buffer.contents buffer)::!w_outside;
            Buffer.clear buffer;
          end
      end

    else if c = ')' then
      begin
        in_flag := false;
        if Buffer.length buffer != 0 then
          begin
            w_inside := (Buffer.contents buffer)::!w_inside;
            Buffer.clear buffer;
          end
      end

    else if c = '_' && Buffer.length buffer != 0 then
      begin
        if !in_flag = false then
          begin
            w_outside := (Buffer.contents buffer)::!w_outside;
            Buffer.clear buffer;
          end
        else
          begin
            w_inside := (Buffer.contents buffer)::!w_inside;
            Buffer.clear buffer;
          end
      end
    else if c = '_' then ()
    else if i = length - 1 then
      begin
        Buffer.add_char buffer c;
        w_outside := (Buffer.contents buffer)::!w_outside
      end
    else Buffer.add_char buffer c
  done;
  (!w_outside, !w_inside)

let () =
  let length = read_int () in
  let sentence = read_string () in
  let (w_outside, w_inside) = parse_sentence sentence length in
  let out_max_length = List.fold_left (fun acc ele ->
      max acc (String.length ele)) 0 w_outside in
  Printf.printf "%d %d" out_max_length (List.length w_inside)

open Scanf
open Printf
open Char

let max a b = if a > b then a else b;;

let foo d = let a = lowercase d in if(a >= 'a' && a <= 'z') then 0 else 1;;

let () =
let n = scanf " %d " (fun x-> x) in
let s = scanf " %s " (fun x-> x) in
let rec calc i l typ len cnt =
if i < n then match(s.[i]) with
'(' ->  calc (i + 1) 0 true (max len l) cnt
| ')' -> calc (i + 1) 0 false len cnt
| '_' -> calc (i + 1) 0 typ (if typ then len else (max len l)) cnt
| _ -> calc (i + 1) (l + 1) typ len (if typ then cnt + foo s.[i - 1] else cnt)
else printf "%d %d\n" (max len l) cnt in calc 0 0 false 0 0;;

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

let parse_sentence sentence length =
  let w_outside = ref [] in
  let w_inside = ref [] in
  let buffer = Buffer.create length in
  let in_flag = ref false in
  let has_parentheses = ref false in
  for i = 0 to length - 1 do
    let c = sentence.[i] in
    if c = '(' then
      begin
        in_flag := true;
        has_parentheses := true;
        if Buffer.length buffer != 0 then
          begin
            w_outside := (Buffer.contents buffer)::!w_outside;
            Buffer.clear buffer;
          end
      end

    else if c = ')' then
      begin
        in_flag := false;
        if Buffer.length buffer != 0 then
          begin
            w_inside := (Buffer.contents buffer)::!w_inside;
            Buffer.clear buffer;
          end
      end

    else if c = '_' && Buffer.length buffer != 0 then
      begin
        if !in_flag = false then
          begin
            w_outside := (Buffer.contents buffer)::!w_outside;
            Buffer.clear buffer;
          end
        else
          begin
            w_inside := (Buffer.contents buffer)::!w_inside;
            Buffer.clear buffer;
          end
      end
    else if c = '_' then ()
    else if i = length - 1 && Buffer.length buffer != 0 then
      begin
        Buffer.add_char buffer c;
        w_outside := (Buffer.contents buffer)::!w_outside
      end
    else Buffer.add_char buffer c
  done;
  if !has_parentheses then (!w_outside, !w_inside) else ([], [])

let () =
  let length = read_int () in
  let sentence = read_string () in
  let (w_outside, w_inside) = parse_sentence sentence length in
  let out_max_length = List.fold_left (fun acc ele ->
      max acc (String.length ele)) 0 w_outside in
  Printf.printf "%d %d" out_max_length (List.length w_inside)

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

let parse_sentence sentence length =
  let w_outside = ref [] in
  let w_inside = ref [] in
  let buffer = Buffer.create length in
  let in_flag = ref false in
  for i = 0 to length - 1 do
    let c = sentence.[i] in
    if c = '(' then
      begin
        in_flag := true;
        if Buffer.length buffer != 0 then begin
          w_outside := (Buffer.contents buffer)::!w_outside;Buffer.clear buffer;
        end
      end
    else if c = ')' then
      begin
        in_flag := false;
        if Buffer.length buffer != 0 then begin
          w_inside := (Buffer.contents buffer)::!w_inside; Buffer.clear buffer;
        end
      end
    else if c = '_' && Buffer.length buffer != 0 then
      begin
        if !in_flag = false then begin
          w_outside := (Buffer.contents buffer)::!w_outside;Buffer.clear buffer;
        end
        else begin
          w_inside := (Buffer.contents buffer)::!w_inside;
          Buffer.clear buffer;
        end
      end
    else if c = '_' then ()
    else Buffer.add_char buffer c
  done;
  (!w_outside, !w_inside)

let () =
  let length = read_int () in
  let sentence = read_string () in
  let (w_outside, w_inside) = parse_sentence sentence length in
  let out_max_length = List.fold_left (fun acc ele ->
      max acc (String.length ele)) 0 w_outside in
  Printf.printf "%d %d" out_max_length (List.length w_inside)

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

let parse_sentence sentence length =
  let w_outside = ref [] in
  let w_inside = ref [] in
  let buffer = Buffer.create length in
  let in_flag = ref false in
  for i = 0 to length - 1 do
    let c = sentence.[i] in
    if c = '(' then
      begin
        in_flag := true;
        if Buffer.length buffer != 0 then
          begin
            w_outside := (Buffer.contents buffer)::!w_outside;
            Buffer.clear buffer;
          end
      end

    else if c = ')' then
      begin
        in_flag := false;
        if Buffer.length buffer != 0 then
          begin
            w_inside := (Buffer.contents buffer)::!w_inside;
            Buffer.clear buffer;
          end
      end

    else if c = '_' && Buffer.length buffer != 0 then
      begin
        if !in_flag = false then
          begin
            w_outside := (Buffer.contents buffer)::!w_outside;
            Buffer.clear buffer;
          end
        else
          begin
            w_inside := (Buffer.contents buffer)::!w_inside;
            Buffer.clear buffer;
          end
      end
    else if c = '_' then ()
    else if i = length - 1 && Buffer.length buffer != 0 then
      begin
        Buffer.add_char buffer c;
        w_outside := (Buffer.contents buffer)::!w_outside
      end
    else Buffer.add_char buffer c
  done;
  (!w_outside, !w_inside)

let () =
  let length = read_int () in
  let sentence = read_string () in
  let (w_outside, w_inside) = parse_sentence sentence length in
  let out_max_length = List.fold_left (fun acc ele ->
      max acc (String.length ele)) 0 w_outside in
  Printf.printf "%d %d" out_max_length (List.length w_inside)

open Scanf
open Printf
open Char

let max a b = if a > b then a else b;;

let foo d = let a = lowercase d in if(a >= 'a' && a <= 'z') then 0 else 1;;

let () =
let n = scanf " %d " (fun x-> x) in
let s = scanf " %s " (fun x-> x) in
let rec calc i l typ len cnt =
if i < n then match(s.[i]) with
'(' ->  calc (i + 1) 0 true (max len l) cnt
| ')' -> calc (i + 1) 0 false len cnt
| '_' -> calc (i + 1) 0 typ (if typ then len else (max len l)) cnt
| _ -> calc (i + 1) (l + 1) typ len (if typ then cnt + foo s.[i - 1] else cnt)
else printf "%d %d\n" len cnt in calc 0 0 false 0 0;;


Imp likes his plush toy a lot.  Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies.Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies.

The only line contains two integers x and y (0 ≤ x, y ≤ 109) — the number of copies and the number of original toys Imp wants to get (including the initial one).

Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower).

NoteIn the first example, Imp has to apply the machine twice to original toys and then twice to copies.

let judge x y =
  let times_for_original = y - 1 in
  let copy_produced_by_copy = x - times_for_original in
  (times_for_original >= 0) &&
  (copy_produced_by_copy >= 0) &&
  (copy_produced_by_copy mod 2 == 0) &&
  (copy_produced_by_copy == 0 || times_for_original > 0)

let output_yn v =
  (match v with
  | true -> print_string "Yes"
  | false -> print_string "No");
  print_char '\n'

let () =
  Scanf.scanf "%u %u" judge |> output_yn

(* TODO: do test *)
(* 1 0 *)
(* 2 1 *)

let main () =
  let getNumber () = Scanf.bscanf Scanf.Scanning.stdin " %d" (fun x -> x)
  in let c = getNumber ()
  in let o = getNumber ()
  in if o = 0 then
    Printf.printf "No"
  else if o = 1
    then if c = 0 then
      Printf.printf "Yes"
    else
      Printf.printf "No"
  else if c - o >= -1 && (c - o + 1) mod 2 = 0 then
    Printf.printf "Yes"
  else
    Printf.printf "No"
;;

main ();;

(* Codeforces 914 B Conan and Agasa play a Card Game - not done*)

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

let rec readlist n acc = match n with
	| 0 -> acc
	| _ -> readlist (n -1) (gr() :: acc);;

let printlisti li = List.iter (fun i -> (print_int i; print_string " ")) li;;

let possible x y =
	if y <= 0 then false
	else if x > 0 && y==1 then false
	else if x < (y - 1) then false
	else if (x mod 2) == (y mod 2) then false
	else true;;

let main() =
	let x = gr() in
	let y = gr() in
	let pos = possible x y in
	begin
		print_string (if pos then "Yes" else "No");
		print_string "\n"
	end;;

main();;

let judge x y =
  let times_for_original = y - 1 in
  let copy_produced_by_copy = x - times_for_original in
  (times_for_original >= 0) &&
  (copy_produced_by_copy >= 0) &&
  (copy_produced_by_copy mod 2 == 0)

let output_yn v =
  (match v with
  | true -> print_string "Yes"
  | false -> print_string "No");
  print_char '\n'

let () =
  Scanf.scanf "%u %u" judge |> output_yn

(* TODO: do test *)
(* 1 0 *)

let judge x y =
  let times_for_original = y - 1 in
  let copy_produced_by_copy = x - times_for_original in
  (copy_produced_by_copy >= 0) && (copy_produced_by_copy mod 2 == 0)

let output_yn v =
  (match v with
  | true -> print_string "Yes"
  | false -> print_string "No");
  print_char '\n'

let () =
  Scanf.scanf "%u %u" judge |> output_yn

let main () =
  let getNumber () = Scanf.bscanf Scanf.Scanning.stdin " %d" (fun x -> x)
  in let c = getNumber ()
  in let o = getNumber ()
  in let c1 = o - 1
  in let c2 = c - c1
  in let c2m = c2 mod 2
  in if c < 0 || o <= 0 || c - o < -1 || c2m = 1 then
    Printf.printf "No"
  else
    Printf.printf "Yes"
;;

main ();;

let main () =
  let getNumber () = Scanf.bscanf Scanf.Scanning.stdin " %d" (fun x -> x)
  in let c = getNumber ()
  in let o = getNumber ()
  in if o = 0 then
    Printf.printf "No"
  else if o = 1
    then if c = 0 then
      Printf.printf "Yes"
    else
      Printf.printf "No"
  else if c - o >= -1 && c - o + 1 mod 2 = 0 then
    Printf.printf "Yes"
  else
    Printf.printf "No"
;;

main ();;

let main () =
  let getNumber () = Scanf.bscanf Scanf.Scanning.stdin " %d" (fun x -> x)
  in let c = getNumber ()
  in let o = getNumber ()
  in let c1 = o - 1
  in let c2 = c - c1
  in let c2m = c2 mod 2
  in if c2m = 1 then
    Printf.printf "No"
  else
    Printf.printf "Yes"
;;

main ();;

let main () =
  let getNumber () = Scanf.bscanf Scanf.Scanning.stdin " %d" (fun x -> x)
  in let c = getNumber ()
  in let o = getNumber ()
  in let c1 = o - 1
  in let c2 = c - c1
  in let c2m = c2 mod 2
  in if c2 < 0 || o <= 0 || c - o < -1 || (c - o + 1) mod 2 = 1 then
    Printf.printf "No"
  else
    Printf.printf "Yes"
;;

main ();;

(* Codeforces 914 B Conan and Agasa play a Card Game - not done*)

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

let rec readlist n acc = match n with
	| 0 -> acc
	| _ -> readlist (n -1) (gr() :: acc);;

let printlisti li = List.iter (fun i -> (print_int i; print_string " ")) li;;

let possible x y =
	if x < (y - 1) then false
	else if (x mod 2) == (y mod 2) then false
	else true;;

let main() =
	let x = gr() in
	let y = gr() in
	let pos = possible x y in
	begin
		print_string (if pos then "Yes" else "No");
		print_string "\n"
	end;;

main();;

(* Codeforces 914 B Conan and Agasa play a Card Game - not done*)

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

let rec readlist n acc = match n with
	| 0 -> acc
	| _ -> readlist (n -1) (gr() :: acc);;

let printlisti li = List.iter (fun i -> (print_int i; print_string " ")) li;;

let possible x y =
	if y <= 0 then false
	else if x==2 && y==1 then false
	else if x < (y - 1) then false
	else if (x mod 2) == (y mod 2) then false
	else true;;

let main() =
	let x = gr() in
	let y = gr() in
	let pos = possible x y in
	begin
		print_string (if pos then "Yes" else "No");
		print_string "\n"
	end;;

main();;

(* Codeforces 914 B Conan and Agasa play a Card Game - not done*)

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

let rec readlist n acc = match n with
	| 0 -> acc
	| _ -> readlist (n -1) (gr() :: acc);;

let printlisti li = List.iter (fun i -> (print_int i; print_string " ")) li;;

let possible x y =
	if y <= 0 then false
	else if x < (y - 1) then false
	else if (x mod 2) == (y mod 2) then false
	else true;;

let main() =
	let x = gr() in
	let y = gr() in
	let pos = possible x y in
	begin
		print_string (if pos then "Yes" else "No");
		print_string "\n"
	end;;

main();;


While playing with geometric figures Alex has accidentally invented a concept of a $$$n$$$-th order rhombus in a cell grid.A $$$1$$$-st order rhombus is just a square $$$1 \times 1$$$ (i.e just a cell).A $$$n$$$-th order rhombus for all $$$n \geq 2$$$ one obtains from a $$$n-1$$$-th order rhombus adding all cells which have a common side with it to it (look at the picture to understand it better).    Alex asks you to compute the number of cells in a $$$n$$$-th order rhombus.

The first and only input line contains integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — order of a rhombus whose numbers of cells should be computed.

Print exactly one integer — the number of cells in a $$$n$$$-th order rhombus.

NoteImages of rhombus corresponding to the examples are given in the statement.

let () =
  let n = Scanf.scanf "%d\n" (fun x -> x) in
  let n2 = n/2 in
  let res = ref 0 in
  for i = 0 to n-2 do
    res := !res + 2 * i + 1;
  done;
  Printf.printf "%d\n" (!res * 2 + 2 * (n-1) + 1)
;;


Manao is trying to open a rather challenging lock. The lock has n buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the sequence), or all pressed buttons return to the initial position. When all buttons are pressed into the lock at once, the lock opens.Consider an example with three buttons. Let's say that the opening sequence is: {2, 3, 1}. If you first press buttons 1 or 3, the buttons unpress immediately. If you first press button 2, it stays pressed. If you press 1 after 2, all buttons unpress. If you press 3 after 2, buttons 3 and 2 stay pressed. As soon as you've got two pressed buttons, you only need to press button 1 to open the lock.Manao doesn't know the opening sequence. But he is really smart and he is going to act in the optimal way. Calculate the number of times he's got to push a button in order to open the lock in the worst-case scenario.

A single line contains integer n (1 ≤ n ≤ 2000) — the number of buttons the lock has.

In a single line print the number of times Manao has to push a button in the worst-case scenario.

NoteConsider the first test sample. Manao can fail his first push and push the wrong button. In this case he will already be able to guess the right one with his second push. And his third push will push the second right button. Thus, in the worst-case scenario he will only need 3 pushes.

let ( * ) = Int64.mul
let ( + ) = Int64.add
let ( - ) = Int64.sub
let zero = Int64.zero
let one = Int64.one
let two = Int64.of_int 2

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

let solve number =
    let rec loop i count correct =
        if i > one
        then
            let repress = (i - two) * correct in
            let temp_count = i + repress in
            loop (i - one) (count + temp_count) (correct + one)
        else
            count + one
    in loop number zero one

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

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

let solve number =
    let rec loop i count correct =
        if i > Int64.one
        then
            let repress = Int64.mul (Int64.sub i (Int64.of_int 2)) correct in
            let temp_count = Int64.add i repress in
            loop (Int64.pred i) (Int64.add count temp_count) (Int64.succ correct)
        else
            Int64.succ count
    in loop number Int64.zero Int64.one

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

let ( +: ) = Int64.add in
let ( -: ) = Int64.sub in
let ( *: ) = Int64.mul in
let n = read_line () |> int_of_string |> Int64.of_int in
let rec count n i a =
  match n with
  | 1L -> 1L
  | 2L -> 3L
  | e -> if n-:i =2L then  a+:n+:1L  else count n (i+:1L) (a+:(i+:1L)*:(n-:i)-:i)  in
count n 1L n |> Int64.to_string |> print_string

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

let solve number =
    let rec loop i count correct =
        if i > 1
        then
            let repress = (i - 2) * correct in
            loop (i - 1) (count + i + repress) (correct + 1)
        else
            count + 1
    in loop number 0 1

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

let n = read_line () |> int_of_string in
let rec count n a = if n <= 1 then a else count (n-2) (a+n*(n-1)) in
count n (if n==2 || n mod 2 ==1 then 1 else 0) |> print_int

let n = read_line () |> int_of_string in
let rec count n a = if n <= 1 then a else count (n-2) (a+n*(n-1)) in
print_int (if n==2 then 3 else count n 0)

let n = read_line () |> int_of_string in
let rec count n i a =
  match n with
  | 1 -> 1
  | 2 -> 3
  | e -> if n-i=2 then  a+n+1  else count n (i+1) (a+(i+1)*(n-i)-i) in
count n 1 n |> print_int

let n = read_line () |> int_of_string in
let count = ref 0 in
begin
for i = 1 to n do
  count := !count + (i+1)*(n-i)
done;
print_int (if n == 2 then 3 else !count)
end


Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.One day Petya was delivered a string s, containing only digits. He needs to find a string that represents a lucky number without leading zeroes, is not empty, is contained in s as a substring the maximum number of times.Among all the strings for which the three conditions given above are fulfilled, Petya only needs the lexicographically minimum one. Find this string for Petya.

The single line contains a non-empty string s whose length can range from 1 to 50, inclusive. The string only contains digits. The string can contain leading zeroes.

In the only line print the answer to Petya's problem. If the sought string does not exist, print "-1" (without quotes).

NoteThe lexicographical comparison of strings is performed by the < operator in the modern programming languages. String x is lexicographically less than string y either if x is a prefix of y, or exists such i (1 ≤ i ≤ min(|x|, |y|)), that xi < yi and for any j (1 ≤ j < i) xj = yj. Here |a| denotes the length of string a.In the first sample three conditions are fulfilled for strings "4", "7" and "47". The lexicographically minimum one is "4".In the second sample s has no substrings which are lucky numbers.In the third sample the three conditions are only fulfilled for string "7".

let m4, m7 = ref 0, ref 0 in
try while true do
	let c = input_char stdin in
	if c = '4' then incr m4 else if c = '7' then incr m7
done with _ -> print_string (if !m4 = 0 && !m7 = 0 then "-1"
else if !m4 >= !m7 then "4" else "7");;

let m4, m7 = ref 0, ref 0 in
try while true do
	let c = input_char stdin in
	if c = '4' then incr m4 else if c = '7' then incr m7
done with _ -> print_string (if !m4 = 0 && !m7 = 0 then "-1"
else if !m4 > !m7 then "4" else "7");;


Bizon the Champion is called the Champion for a reason. Bizon the Champion has recently got a present — a new glass cupboard with n shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has a1 first prize cups, a2 second prize cups and a3 third prize cups. Besides, he has b1 first prize medals, b2 second prize medals and b3 third prize medals. Naturally, the rewards in the cupboard must look good, that's why Bizon the Champion decided to follow the rules:  any shelf cannot contain both cups and medals at the same time;  no shelf can contain more than five cups;  no shelf can have more than ten medals. Help Bizon the Champion find out if we can put all the rewards so that all the conditions are fulfilled.

The first line contains integers a1, a2 and a3 (0 ≤ a1, a2, a3 ≤ 100). The second line contains integers b1, b2 and b3 (0 ≤ b1, b2, b3 ≤ 100). The third line contains integer n (1 ≤ n ≤ 100). The numbers in the lines are separated by single spaces.

Print "YES" (without the quotes) if all the rewards can be put on the shelves in the described manner. Otherwise, print "NO" (without the quotes).

let read () = Scanf.scanf "%d " (fun n -> n)
let sum () = Scanf.scanf "%d %d %d " (fun n m l -> n + m + l)
let print result = Printf.printf "%s\n" result

let div_rounding_up = (fun x y ->
    x / y + (match x mod y with
        | 0 -> 0
        | _ -> 1))

let input () =
    let goblets = sum () in
    let medals = sum () in
    let shelves = read () in
    (goblets, medals, shelves)

let solve (goblets, medals, shelves) =
    let goblet_shelves = div_rounding_up goblets 5 in
    let medal_shelves = div_rounding_up medals 10 in
    let shelves_needed = goblet_shelves + medal_shelves in
        if shelves_needed <= shelves
        then
            "YES"
        else
            "NO"

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

let ( |> ) v f = f v
let ( @@ ) f x = f x
let input_to_list ic =
  let buf = Buffer.create 0 in
  let rec aux acc =
    match input_char ic with
    | ' ' -> let v = int_of_string (Buffer.contents buf) in
      Buffer.clear buf; aux (v::acc)
    | '\n' -> let v = int_of_string (Buffer.contents buf) in
      Buffer.clear buf; List.rev (v::acc)
    | c -> Buffer.add_char buf c; aux acc
  in aux []

let read_input () =
  let cups = input_to_list stdin |> List.fold_left (fun sum x -> sum + x) 0 in
  let medals = input_to_list stdin |> List.fold_left (fun sum x -> sum + x) 0 in
  let shelves = int_of_string (input_line stdin) in
  (cups, medals, shelves)

let check_ok (cups, medals, shelves) =
    let shelves_for_cups = cups / 5 + (if cups mod 5 > 0 then 1 else 0)
    in let shelves_for_medals = medals / 10 + (if medals mod 10 > 0 then 1 else 0)
    in shelves_for_cups + shelves_for_medals <= shelves

let () =
    print_endline (if (check_ok (read_input ())) then "YES" else "NO")

let input_to_list ic =
  let buf = Buffer.create 0 in
  let rec aux acc =
    match input_char ic with
    | ' ' -> let v = int_of_string (Buffer.contents buf) in
      Buffer.clear buf; aux (v::acc)
    | '\n' -> let v = int_of_string (Buffer.contents buf) in
      Buffer.clear buf; List.rev (v::acc)
    | c -> Buffer.add_char buf c; aux acc
  in aux []

let read_input () =
  let cups = input_to_list stdin in
  let medals = input_to_list stdin in
  let shelves = int_of_string (input_line stdin) in
  (cups, medals, shelves)

let check_ok (cups, medals, shelves) =
    let shelves_for_cups =
        (List.length cups) / 5 + (if List.length cups mod 5 > 0 then 1 else 0)
    in let shelves_for_medals =
        (List.length medals) / 10 + (if List.length medals mod 10 > 0 then 1 else 0)
    in shelves_for_cups + shelves_for_medals <= shelves

let () =
    print_endline (if (check_ok (read_input ())) then "YES" else "NO")


You are given two set of points. The first set is determined by the equation A1x + B1y + C1 = 0, and the second one is determined by the equation A2x + B2y + C2 = 0.Write the program which finds the number of points in the intersection of two given sets.

The first line of the input contains three integer numbers A1, B1, C1 separated by space. The second line contains three integer numbers A2, B2, C2 separated by space. All the numbers are between -100 and 100, inclusive.

Print the number of points in the intersection or -1 if there are infinite number of points.

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

let () =
  let a = read_int 0 in let b = read_int 0 in let c = read_int 0 in
  let u = read_int 0 in let v = read_int 0 in let w = read_int 0 in
  Printf.printf "%d\n" (if a*v <> b*u then
      1
    else if b*w <> c*v || a*w <> c*u || (a = 0 && b = 0 && c <> 0) || (u = 0 && v = 0 && w <> 0) then
      0
    else
      -1)

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

let () =
  let a = read_int 0 in let b = read_int 0 in let c = read_int 0 in
  let u = read_int 0 in let v = read_int 0 in let w = read_int 0 in
  Printf.printf "%d\n" (if a*v <> b*u then
      1
    else if b*w <> c*v || a*w <> c*u then
      0
    else
      -1)


Polycarpus is an amateur businessman. Recently he was surprised to find out that the market for paper scissors is completely free! Without further ado, Polycarpus decided to start producing and selling such scissors.Polycaprus calculated that the optimal celling price for such scissors would be p bourles. However, he read somewhere that customers are attracted by prices that say something like "Special Offer! Super price 999 bourles!". So Polycarpus decided to lower the price a little if it leads to the desired effect.Polycarpus agrees to lower the price by no more than d bourles so that the number of nines at the end of the resulting price is maximum. If there are several ways to do it, he chooses the maximum possible price.Note, Polycarpus counts only the trailing nines in a price.

The first line contains two integers p and d (1 ≤ p ≤ 1018; 0 ≤ d < p) — the initial price of scissors and the maximum possible price reduction. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.

Print the required price — the maximum price that ends with the largest number of nines and that is less than p by no more than d. The required number shouldn't have leading zeroes.

open Scanf;;
open Printf;;
open Str;;

let split_by_space = split (regexp " +")

let rec head n ls =
  if n < 0 then invalid_arg "head : passed negative integer"
  else
    match (n, ls) with
      (0, _) -> []
    | (n, []) -> failwith "head : list is too short"
    | (n, x::xs) -> x :: (head (n - 1) xs)

let rec tail n ls =
  if n < 0 then invalid_arg "tail : passed negative integer"
  else
    match (n, ls) with
      (0, ls) -> ls
    | (n, []) -> failwith "tail : list is too short"
    | (n, x::xs) -> tail (n - 1) xs

module UF = struct
  type t = int array

  let make n = Array.make n (-1)

  let rec root x uf =
    if uf.(x) < 0 then x
    else (uf.(x) <- root uf.(x) uf; uf.(x))

  let union_set x y uf =
    let x = root x uf and
        y = root y uf in
    begin
      if x != y then
        let x, y = if uf.(y) < uf.(x) then y, x else x, y in
        begin
          uf.(x) <- uf.(x) + uf.(y);
          uf.(y) <- x
        end
    end;
    x != y

  let find_set x y uf = root x uf = root y uf

  let size x uf = - uf.(x)
end

let (+%) = Int64.add
let (-%) = Int64.sub
let ( *% ) = Int64.mul
let (/%) = Int64.div
let (mod) = Int64.rem
let (>%) x y = Int64.compare x y > 0
let (<%) x y = Int64.compare x y < 0
let input () = scanf "%Ld %Ld " (fun x y -> (x, y))

let max_with_9 n d =
  let r = n mod d in
  if r = (d -% 1L) then n
  else n -% r -% 1L

let solve (p, d) =
  let rec loop n mx =
    let res = max_with_9 p n in
    if p -% res >% d then mx
    else loop (n *% 10L) res in
  let mx = loop 10L (-1L) in
  if mx <% 0L then p else mx

let () =
  let inp = input () in
  let res = solve inp in
  printf "%Ld\n" res