A - Three Integers Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300

問題文

黒板に 3 つの非負整数 A, B, C が書かれています. あなたは,以下の 2 つの操作を好きな順序で好きな回数繰り返すことができます.

  • 2 つの整数を選んで,それらから 1 を引く.
  • すべての整数から 1 を引く.

あなたの目標は,黒板に書かれている数をすべて 0 にすることです. 目標が達成可能であるかどうか判定し,また可能であるなら必要な最小の操作回数を求めてください.

制約

  • 0 \leq A, B, C \leq 10^{18}

入力

入力は以下の形式で標準入力から与えられる.

A B C

出力

目標が達成可能でない場合,-1 を出力せよ.可能である場合,必要な最小の操作回数を出力せよ.


入力例 1

2 2 3

出力例 1

3

例えば次のように操作を行うことで,すべての数を 0 にすることができます.

  • AC から 1 を引く.黒板に書かれた数は 1, 2, 2 となる.
  • BC から 1 を引く.黒板に書かれた数は 1, 1, 1 となる.
  • すべての数から 1 を引く.黒板に書かれた数は 0, 0, 0 となる.

入力例 2

0 0 1

出力例 2

-1

入力例 3

0 0 0

出力例 3

0

Score : 300 points

Problem Statement

Three non-negative integers A, B, and C are written on a blackboard. You can perform the following two operations any number of times in any order.

  • Subtract 1 from two of the written integers of your choice.
  • Subtract 1 from all of the written integers.

Your objective is to make all the numbers on the blackboard 0. Determine whether it is achievable. If it is, find the minimum number of times you need to perform an operation to achieve it.

Constraints

  • 0 \leq A, B, C \leq 10^{18}

Input

Input is given from Standard Input in the following format:

A B C

Output

If the objective is unachievable, print -1. If it is achievable, print the minimum number of times you need to perform an operation to achieve it.


Sample Input 1

2 2 3

Sample Output 1

3

Here is one way to make all the numbers 0.

  • Subtract 1 from A and C. Now the numbers are 1, 2, 2.
  • Subtract 1 from B and C. Now the numbers are 1, 1, 1.
  • Subtract 1 from all the numbers. Now the numbers are 0, 0, 0.

Sample Input 2

0 0 1

Sample Output 2

-1

Sample Input 3

0 0 0

Sample Output 3

0