1289. Lunch

 

Vlad wants to take a couple of fruits for lunch. He has a different bananas, b different apples and c different pears. In how many ways can he choose 2 different fruits from the available ones?

 

Input. Three non-negative integers a, b and c are given. All integers do not exceed 106.

 

Output. Print the number of ways to choose 2 different fruits for lunch.

 

Sample input

Sample output

3 4 2

26

 

 

SOLUTION

mathematics

 

Algorithm analysis

You can choose two different fruits in one of the following ways:

·        a banana and an apple in a * b ways;

·        a banana and a pear in a * c ways;

·        an apple and a pear in b * c ways;

Thus, you can select two different fruits in a * b + a * c + b * c ways. Considering that a, b, c ≤ 106, the answer will be no more than 3 * 1012. You should use the long long type.

 

Algorithm realization

Read the input data.

 

scanf("%lld %lld %lld",&a,&b,&c);

 

Compute and print the answer.

 

res = a * b + a * c + b * c;

printf("%lld\n",res);

 

Java realization

 

import java.util.*;

 

class Main

{

  public static void main(String[] args)

  {

    Scanner con = new Scanner(System.in);

    long a = con.nextLong();

    long b = con.nextLong();

    long c = con.nextLong();

    long res = a * b + a * c + b * c;

    System.out.println(res);

    con.close();

  }

}

 

Python realization

Read the input data.

 

a, b, c = map(int,input().split())

 

Compute and print the answer.

 

res = a * b + a * c + b * c

print(res)