1 second
256 megabytes
standard input
standard output
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).
#include <iostream>
#include <cstdio> using namespace std; int get13(int a, int b, int c)
{
int i;
for(i = ; i <= a; ++i){
if(c - i <= b && b - c + i == a - i && c - i >= ){
return i;
}
}
for(i = ; i <= a; ++i){
if(b - i <= c && c - b + i == a - i && b - i >= ){
return i + 10e7;
}
}
return -;
} int main()
{
int a, b, c;
while(scanf("%d %d %d", &a, &b, &c) != EOF){
int i = get13(a, b, c);
if(i == -) {
puts("Impossible");
}
else if(i < 10e7){
printf("%d %d %d\n", a - i, b - a + i, i);
}
else{
i -= 10e7;
printf("%d %d %d\n", i, c - a + i, a - i);
}
}
return ;
}