Algorithm


A. Restoring Three Numbers
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Polycarp has guessed three positive integers a�, b� and c�. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: a+b�+�, a+c�+�, b+c�+� and a+b+c�+�+�.

You have to guess three numbers a�, b� and c� using given numbers. Print three guessed integers in any order.

Pay attention that some given numbers a�, b� and c� can be equal (it is also possible that a=b=c�=�=�).

Input

The only line of the input contains four positive integers x1,x2,x3,x4�1,�2,�3,�4 (2≤xi≤1092≤��≤109) — numbers written on a board in random order. It is guaranteed that the answer exists for the given number x1,x2,x3,x4�1,�2,�3,�4.

Output

Print such positive integers a�, b� and c� that four numbers written on a board are values a+b�+�, a+c�+�, b+c�+� and a+b+c�+�+� written in some order. Print a�, b� and c� in any order. If there are several answers, you can print any. It is guaranteed that the answer exists.

Examples
input
Copy
3 6 5 4
output
Copy
2 1 3
input
Copy
40 40 40 60
output
Copy
20 20 20
input
Copy
201 101 101 200
output
Copy
1 100 100

 



 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <bits/stdc++.h>

using namespace std;

int x[4];

int main() {
  for(int i = 0; i < 4; ++i)
    scanf("%d", x + i);
  
  sort(x, x + 4);

  do {
    int ab = x[0];
    int ac = x[1];
    int bc = x[2];
    int sum = x[3];

    int a = (ab - bc + ac) / 2;
    int b = (bc - ac + ab) / 2;
    int c = (ac - ab + bc) / 2;

    if(a + b + c == sum) {
      // cout << ab << ' ' << ac << ' ' << bc << ' ' << sum << endl;
      printf("%d %d %d", a, b, c);
      return 0;
    }
  } while(next_permutation(x, x + 4));

  return 0;
}
Copy The Code & Try With Live Editor

Input

x
–
+
cmd
3 6 5 4

Output

x
–
+
cmd
2 1 3
Advertisements

Demonstration


Codeforces Solution-Restoring Three Numbers--Solution in C, C++, Java, Python,Codeforces Solution

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+