Under construction

Still being built. Things may change

Φ²

Time limit1sMemory limit1024 MB

Summary
Each day, microorganisms in a line absorb adjacent neighbors no bigger than themselves, front to back. Output the survivor's final size and starting index.
Level

Medium6 of 10

Topics
Simulation, Linked list, Implementation
Solved
No attempts yet

Problem

Sunah is studying a certain microorganism. While researching it, Sunah found that when several of these microorganisms are arranged in a line, they absorb each other according to the following rules until only one remains.

  1. Once per day, starting from the microorganism at the front of the line, each microorganism in turn absorbs all adjacent microorganisms that are smaller than or equal to its own size. When it absorbs another microorganism, its size increases by the size of the absorbed one.
  2. An absorbed microorganism disappears and cannot act. For example, if there are three microorganisms with sizes 33, 22, and 11, then 22 is absorbed by 33 before its turn comes, so after one day the remaining sizes are 55 and 11.
  3. A microorganism absorbs everything it will absorb that day in a single action. For example, if there are three microorganisms with sizes 33, 44, and 55, and it is 44's turn, then 44 absorbs only 33. It is impossible for 44 to absorb 55 the same day after becoming 77. So after one day the remaining sizes are 77 and 55.

Input

The first line contains the number of microorganisms NN. (1≤N≤500 0001\le N\le 500\,000)

The second line contains NN integers a1,a2,…,aNa_1,a_2,\ldots,a_N separated by spaces, where aia_i is the initial size of the ii-th microorganism. Each initial size is an integer from 11 to NN, inclusive. No two microorganisms have the same initial size.

Output

Print the final size of the microorganism that remains at the end on the first line.

Print the initial position of that microorganism on the second line.

Examples1

  1. Example 1

    Input
    5
    4 1 3 2 5
    
    Expected output
    15
    5