<|instruction|>
Solve the below problem. The solution should start with an abridged problem statement. Then key observations. Then full solution based on the observations. Then C++ and Python implementations with comments.

299. Triangle
Time limit per test: 0.5 second(s)
Memory limit: 65536 kilobytes
input: standard
output: standard



It is well known that three segments can make a triangle if and only if the sum of lengths of any two of them is strictly greater than the length of the third one. Professor Vasechkin has N segments. He asked you, if you could find at least one set of three segments among them which can be used by professor to make a triangle.

Input
The first line of the input contains the only integer number N (3≤ N≤ 1000). The following N lines contain the length of segments professor has. The length of any segment is the integer number from 1 to 10500.

Output
Write to the output the length of segments requested by the professor — three numbers delimited by spaces. Write three zeros if there are no such three segments.

Example(s)
sample input
sample output
7
1
2
6
4
8
100
73
8 4 6

<|response|>
1. Abridged problem statement  
You are given N positive integer segment lengths (each up to 10 500 digits). Determine any three lengths that can form a non-degenerate triangle (i.e. for lengths a, b, c all of a+b>c, a+c>b and b+c>a must hold). If such a triple exists, print the three lengths; otherwise print “0 0 0”.

2. Key observations  
- Triangle inequality for positive a≤b≤c reduces to a + b > c.  
- If you sort all lengths in non-decreasing order L[0] ≤ L[1] ≤ … ≤ L[N−1], then you only need to check consecutive triples (L[i], L[i+1], L[i+2]) for i=0..N−3.  
- As soon as you find i with L[i] + L[i+1] > L[i+2], that triple works; if no such i exists, no triple anywhere works.  
- Python’s built-in int handles arbitrarily large integers. In C++, you can use Boost.Multiprecision’s cpp_int.

3. Full solution approach  
a. Read N.  
b. Read the N segment lengths into an array of big-integer values.  
c. Sort the array in non-decreasing order.  
d. Loop i from 0 to N−3:  
   • Compute S = L[i] + L[i+1].  
   • If S > L[i+2], output L[i], L[i+1], L[i+2] and terminate.  
e. If the loop finishes without finding a valid triple, output “0 0 0”.

Time complexity: O(N log N) big-integer comparisons and additions, which is fine for N≤1000.

4. C++ implementation with detailed comments  
```cpp
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
// Use Boost.Multiprecision for arbitrary-precision integers
using boost::multiprecision::cpp_int;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;  // Number of segments, 3 ≤ N ≤ 1000

    // Read segment lengths as big integers
    vector<cpp_int> seg(N);
    for(int i = 0; i < N; i++) {
        cin >> seg[i];
    }

    // Sort in non-decreasing order
    sort(seg.begin(), seg.end());

    // Check each consecutive triple for the triangle condition
    for(int i = 0; i + 2 < N; i++) {
        // seg[i] ≤ seg[i+1] ≤ seg[i+2]
        cpp_int sum12 = seg[i] + seg[i+1];
        // Only need to check sum of the two smaller > largest
        if(sum12 > seg[i+2]) {
            // Found a valid triangle
            cout << seg[i] << " " << seg[i+1] << " " << seg[i+2] << "\n";
            return 0;
        }
    }

    // No valid triple found
    cout << "0 0 0\n";
    return 0;
}
```

5. Python implementation with detailed comments  
```python
import sys

def main():
    data = sys.stdin.read().strip().split()
    if not data:
        return
    # First token is N
    n = int(data[0])
    # Next N tokens are segment lengths (very large integers)
    segs = list(map(int, data[1:]))

    # Sort segments in non-decreasing order
    segs.sort()

    # Scan through consecutive triples
    # After sorting, for a ≤ b ≤ c the only non-trivial check is a + b > c
    for i in range(n - 2):
        a, b, c = segs[i], segs[i + 1], segs[i + 2]
        if a + b > c:
            print(a, b, c)
            return

    # If none form a triangle, output three zeros
    print(0, 0, 0)

if __name__ == "__main__":
    main()
```