This page is still under construction.

Parts of this page are still being built. What you see may change.

Split

Interview

Time limit2sMemory limit1024 MB

Summary
Given a distinct integer sequence, find its maximum, then output the sum of elements before it and the sum of elements after it.
Level

Easy1 of 10

Topics
Array, Implementation
Solved
No attempts yet

Problem

You are given an integer sequence A = (A1, A2, ..., AN) of length N. All values in A are distinct.

When the sequence is split at its maximum value, output the sum of the values before the maximum and the sum of the values after the maximum.

That is, if the maximum value of the sequence A is Ax, output A1 + A2 + … + Ax-1 and Ax+1 + Ax+2 + … + AN.

If there is no value before the maximum, the sum of the values before the maximum is 0.

Likewise, if there is no value after the maximum, the sum of the values after the maximum is 0.

Input

Input is given from standard input in the following format.

N
A1 A2 … AN

Output

The output consists of 2 lines.

On line 1, output the sum of the values before the maximum value of the integer sequence A.

On line 2, output the sum of the values after the maximum value of the integer sequence A.

Constraints

  • 1 ≦ N ≦ 100.
  • 1 ≦ Ai ≦ 2000 (1 ≦ i ≦ N).
  • Ai ≠ Aj (1 ≦ i < j ≦ N).

Examples4

  1. Example 1

    Input
    5
    9 3 16 8 1
    
    Expected output
    12
    9
    
  2. Example 2

    Input
    6
    121 8 5 4 1 3
    
    Expected output
    0
    21
    
  3. Example 3

    Input
    1
    2000
    
    Expected output
    0
    0
    
  4. Example 4

    Input
    10
    9 12 30 63 55 8 10 1 27 13
    
    Expected output
    51
    114