Problem:
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Min, Max and Sum

Write a program which reads a sequence of $n$ integers $a_i (i = 1, 2, ... n)$, and prints the minimum value, maximum value and sum of the sequence.

Input

In the first line, an integer $n$ is given. In the next line, $n$ integers $a_i$ are given in a line.

Output

Print the minimum value, maximum value and sum in a line. Put a single space between the values.

Constraints

$0 < n \leq 10000$

$-1000000 \leq a_i \leq 1000000$

Sample Input

5
10 1 5 4 17

Sample Output

1 17 37

Solution in JAVA (judge verdict: Wrong Answer)

import java.io.*;
public class Main {
	public static void main(String[] args){
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		try{
			String line1 = reader.readLine();
			int n = Integer.parseInt(line1);//1stLine
			String line2 = reader.readLine();//2ndLine
			String[] sarray = line2.split(" ", -1);
			int[] num = new int[n];
			for(int i = 0 ; i < n ; i++){
				num[i] = Integer.parseInt(sarray[i]);
			}
			
			int min = 0;//min number
			int p = 0;
			while(min < n - 1 && p < n - 1){
				p++;
				if(num[min] > num[p]){
					min = p;
				}
			}
			
			int max = 0;//max number
			int q = 0;
			while(max < n - 1 && q < n - 1){
				q++;
				if(num[max] < num[q]){
					max = q;
				}
			}
			
			int sum[] = new int[n + 1]; //sum
			sum[0] = 0;
			for(int j = 1; j <= n; j++){
				sum[j] = num[j - 1] + sum[j - 1];
			}
			
			System.out.println(num[min] + " " + num[max] + " " + sum[n]);
			} catch (IOException e) {
          System.out.println(e);
        } catch (NumberFormatException e) {
          System.out.println("error");
        }
    }
}