let pick_up_max l =
	match l with
		| [] -> failwith "Empty list"
		| e :: es ->
			let rec loop max acc = function
				| [] -> (max, acc)
				| x :: xs ->
					if x > max then loop x (max :: acc) xs
					else            loop max (x :: acc) xs
			in loop e [] es

let rec play cards alice bob =
	if cards = [] then
		alice - bob
	else
		let (max, rest) = pick_up_max cards in
		let alice' = alice + max in
		if rest = [] then
			alice' - bob
		else
			let (max, rest) = pick_up_max rest in
			let bob' = bob + max in
			play rest alice' bob'

let () =
	let _ = read_int () in
	let cards =
		read_line ()
		|> Str.split (Str.regexp " ")
		|> List.map int_of_string
	in print_endline (string_of_int (play cards 0 0))
