Problem:
Score : 600 points

Problem Statement

Snuke has an integer sequence, a, of length N. The i-th element of a (1-indexed) is a_{i}.

He can perform the following operation any number of times:

Operation: Choose integers x and y between 1 and N (inclusive), and add a_x to a_y.

He would like to perform this operation between 0 and 2N times (inclusive) so that a satisfies the condition below. Show one such sequence of operations.
It can be proved that such a sequence of operations always exists under the constraints in this problem.

Condition: a_1 \leq a_2 \leq ... \leq a_{N}

Constraints

2 \leq N \leq 50

-10^{6} \leq a_i \leq 10^{6}

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_{N}

Output

Let m be the number of operations in your solution. In the first line, print m.
In the i-th of the subsequent m lines, print the numbers x and y chosen in the i-th operation, with a space in between.
The output will be considered correct if m is between 0 and 2N (inclusive) and a satisfies the condition after the m operations.

Sample Input 1

3
-2 5 -1

Sample Output 1

2
2 3
3 3

After the first operation, a = (-2,5,4).

After the second operation, a = (-2,5,8), and the condition is now satisfied.

Sample Input 2

2
-1 -3

Sample Output 2

1
2 1

After the first operation, a = (-4,-3) and the condition is now satisfied.

Sample Input 3

5
0 0 0 0 0

Sample Output 3

0

The condition is satisfied already in the beginning.

Solution in Java8 (OpenJDK 1.8.0) (judge verdict: Accepted)

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collection;
import java.io.IOException;
import java.util.stream.Collectors;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.LinkedList;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Nondecreasing solver = new Nondecreasing();
        solver.solve(1, in, out);
        out.close();
    }

    static class Nondecreasing {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            long[] A = new long[N];
            Nondecreasing.Entry[] B = new Nondecreasing.Entry[N];
            for (int i = 0; i < N; i++) {
                A[i] = in.nextInt();
                B[i] = new Nondecreasing.Entry(i, A[i]);
            }

            Arrays.sort(B, (e1, e2) -> Long.compare(e1.val, e2.val));

            Nondecreasing.Entry min = B[0];
            Nondecreasing.Entry max = B[N - 1];

            List<int[]> a1 = computeMin(A.clone(), min);
            List<int[]> a2 = computeMax(A.clone(), max);

            if (a1.size() == 1000 && a2.size() == 1000) {
                out.println(0);
                return;
            }

            List<int[]> ans = a1.size() < a2.size() ? a1 : a2;

            out.println(ans.size());
            out.println(ans.stream().map(a -> a[0] + " " + a[1]).collect(Collectors.joining("\n")));
//        out.println(Arrays.stream(A).mapToObj(Objects::toString).collect(joining(" ")));
        }

        private List<int[]> computeMin(long[] A, Nondecreasing.Entry min) {
            if (min.val >= 0) return new ArrayList<>(Collections.nCopies(1000, new int[0]));
            long minSoFar = min.val;
            int min_idx = min.idx;
            int N = A.length;
            List<int[]> ans = new LinkedList<>();
            int cnt = 0;
            for (int i = N - 2; i >= 0; i--) {
                while (A[i] > A[i + 1]) {
                    ans.add(new int[]{min_idx + 1, i + 1});
                    A[i] += A[min_idx];
                    cnt++;
                    if (minSoFar > A[i]) {
                        minSoFar = A[i];
                        min_idx = i;
                    }

                    if (cnt > 1000) return new ArrayList<>(Collections.nCopies(1000, new int[0]));
                }
            }
            return ans;
        }

        private List<int[]> computeMax(long[] A, Nondecreasing.Entry max) {
            if (max.val <= 0) return new ArrayList<>(Collections.nCopies(1000, new int[0]));
            long maxSoFar = max.val;
            int max_idx = max.idx;
            int N = A.length;
            List<int[]> ans = new LinkedList<>();
            int cnt = 0;
            for (int i = 1; i < N; i++) {
                while (A[i - 1] > A[i]) {
                    ans.add(new int[]{max_idx + 1, i + 1});
                    A[i] += A[max_idx];
                    cnt++;
                    if (maxSoFar < A[i]) {
                        maxSoFar = A[i];
                        max_idx = i;
                    }
                    if (cnt > 1000) return new ArrayList<>(Collections.nCopies(1000, new int[0]));
                }
            }
            return ans;
        }

        static class Entry {
            int idx;
            long val;

            public Entry(int idx, long val) {
                this.idx = idx;
                this.val = val;
            }

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}