Algorithm


A. Worms Evolution
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are n forms of worms. Worms of these forms have lengths a1a2, ..., an. To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to sum of lengths of the other two forms. Help him to do this.

Input

The first line contains integer n (3 ≤ n ≤ 100) — amount of worm's forms. The second line contains n space-separated integers ai (1 ≤ ai ≤ 1000) — lengths of worms of each form.

Output

Output 3 distinct integers i j k (1 ≤ i, j, k ≤ n) — such indexes of worm's forms that ai = aj + ak. If there is no such triple, output -1. If there are several solutions, output any of them. It possible that aj = ak.

Examples
input
Copy
5
1 2 3 5 7
output
Copy
3 2 1
input
Copy
5
1 8 1 5 1
output
Copy
-1



 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <cstdio>
#include <algorithm>
#include <vector>

int main(){

    int n(0); scanf("%d", &n);
    int *array = new int[n];
    for(int k = 0; k < n; k++){scanf("%d", array + k);}

    bool done(0);
    std::vector<int> output;


    for(int a = 0; a < n - 2; a++){
        if(done){break;}
        for(int b = a + 1; b < n - 1; b++){
            if(done){break;}
            for(int c = b + 1; c < n; c++){
                if(array[c] == array[a] + array[b]){output.push_back(c); output.push_back(a); output.push_back(b); done = 1; break;}
                else if(array[b] == array[a] + array[c]){output.push_back(b); output.push_back(a); output.push_back(c); done = 1; break;}
                else if(array[a] == array[b] + array[c]){output.push_back(a); output.push_back(b); output.push_back(c); done = 1; break;}
            }
        }
    }

    if(done){printf("%d %d %d", 1 + output[0], 1 + output[1], 1 + output[2]);}
    else{puts("-1");}

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

Input

x
+
cmd
5
1 2 3 5 7

Output

x
+
cmd
3 2 1
Advertisements

Demonstration


Codeforces Solution-A. Worms Evolution-Solution in C, C++, Java, Python

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