Under construction

Still being built. Things may change

Field Trip

Interview

Time limit3sMemory limit1024 MB

Summary
Split class sections 1 to N into three contiguous groups so that no teacher rides a bus, printing the split points i and j or -1 if impossible.
Level

Medium5 of 10

Topics
Prefix sum, Binary search
Solved
No attempts yet

Problem

You and your classmates are going on an exciting field trip to a downtown museum. Because the museum is an hour away, three buses of identical capacity and a van are dispatched to take everyone to the museum and back. The buses first load only students. Once all students are loaded, teachers fill the remaining spots on the buses. Any teachers left over ride on the van. All the students hope for a "teacher free bus ride," meaning none of the teachers are on a bus.

Students are grouped in nn class sections of different sizes. Each class section is assigned a number from 11 to nn. All students in one class section must ride on the same bus. The buses board class sections in increasing order by number. The first bus loads sections 11 to ii, the second bus loads sections i+1i+1 to jj, and the third bus loads sections j+1j+1 to nn. Every bus must have at least one class section assigned to it.

Given the sizes of the class sections, determine whether it is possible to load students onto the three identical buses and end up with a "teacher free bus ride."

Input

The first line of input contains one integer NN, the number of class sections (3≤N≤1,000,0003 \le N \le 1,000,000). The second line contains NN integers, where the iith integer is the size of the class section with number ii. Class section sizes range from 11 to 10 00010\,000.

Output

If it is possible to load the students onto the three buses in the described way with a teacher free bus ride, output two integers ii and jj (1≤i<j<n1 \le i < j < n). Here ii is the number of the class section loaded last onto the first bus, and jj is the number of the class section loaded last onto the second bus. The third bus loads sections j+1j+1 to nn.

If it is not possible, print "-1".

Examples4

  1. Example 1

    Input
    3
    3 3 3
    
    Expected output
    1 2
    
  2. Example 2

    Input
    3
    9 10 11
    
    Expected output
    -1
    
  3. Example 3

    Input
    9
    1 2 3 1 2 3 1 2 3
    
    Expected output
    3 6
    
  4. Example 4

    Input
    9
    1 2 3 1 2 3 1 2 10
    
    Expected output
    -1