import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class magic_as implements Runnable {
    BufferedReader in;
    StringTokenizer st;

    int nextInt() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(in.readLine());
            } catch (IOException e) {
                throw new AssertionError();
            }
        }
        return Integer.parseInt(st.nextToken());
    }

    class Potion implements Comparable<Potion> {
        int x;
        int y;
        long c;

        Potion(int x, int y, long c) {
            this.x = min(x, y);
            this.y = max(x, y);
            this.c = c;
        }

        @Override
        public String toString() {
            return x + " " + y + " " + c;
        }

        public String toAns() {
            return (x + 1) + " " + (y + 1) + " " + c;
        }

        public int compareTo(Potion o) {
            return x != o.x ? x - o.x : y - o.y;
        }
    }

    class Substance implements Comparable<Substance> {
        int i;
        long c;

        Substance(int i, long c) {
            this.i = i;
            this.c = c;
        }

        public int compareTo(Substance o) {
            if (c < o.c) {
                return -1;
            } else if (c > o.c) {
                return 1;
            } else {
                return i - o.i;
            }
        }
    }

    public void solve() throws IOException {
        in = new BufferedReader(new FileReader("magic.in"));
        PrintWriter out = new PrintWriter(new File("magic.out"));

        int n = nextInt();
        assert 2 <= n && n <= 100000;
        long[] a = new long[n];
        long s = 0;
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
            s += a[i];
            assert 1 <= a[i] && a[i] <= (int)1e9;
        }

        ArrayList<Potion> ans = new ArrayList<Potion>();

        boolean single = false;
        for (int i = 0; i < n; i++) {
            if (a[i] >= s - a[i]) {
                single = true;
                break;
            }
        }
        if (!single) {
            TreeSet<Substance> st = new TreeSet<Substance>();
            Substance[] ss = new Substance[n];
            for (int i = 0; i < n; i++) {
                ss[i] = new Substance(i, a[i]);
                st.add(ss[i]);
            }

            int i = 0;
            int j = 1;
            binary:
            while (j < n) {
                while (i < n && a[i] == 0) {
                    i++;
                }
                if (i >= n) {
                    break;
                }
                if (j < i + 1) {
                    j = i + 1;
                }
                while (j < n && a[j] == 0) {
                    j++;
                }
                if (j >= n) {
                    break;
                }

                long v = min(a[i], a[j]);
                st.remove(ss[i]);
                st.remove(ss[j]);
                ss[i].c -= v;
                ss[j].c -= v;
                st.add(ss[i]);
                st.add(ss[j]);
                long thens = s - 2 * v;
                long maxc = st.last().c;
                if (maxc <= thens - maxc + 1) {
                    a[i] -= v;
                    a[j] -= v;
                    s -= 2 * v;
                    ans.add(new Potion(i, j, v));
                    continue;
                }

                long l = 0;
                long r = min(a[i], a[j]) + 1;
                st.remove(ss[i]);
                st.remove(ss[j]);
                ss[i].c += v;
                ss[j].c += v;
                while (l < r - 1) {
                    long m = (l + r) / 2;
                    ss[i].c -= m;
                    ss[j].c -= m;
                    st.add(ss[i]);
                    st.add(ss[j]);
                    thens = s - 2 * m;
                    maxc = st.last().c;
                    boolean can = maxc <= thens - maxc + 1;
                    st.remove(ss[i]);
                    st.remove(ss[j]);
                    ss[i].c += m;
                    ss[j].c += m;
                    if (can) {
                        l = m;
                    } else {
                        r = m;
                    }
                }
                ss[i].c -= l;
                ss[j].c -= l;
                s -= 2 * l;
                st.add(ss[i]);
                st.add(ss[j]);
                a[i] -= l;
                a[j] -= l;
                if (l > 0) {
                    ans.add(new Potion(i, j, l));
                }

                assert st.last().c >= s - st.last().c;
                break binary;
            }
        }
        for (int i = 0; i < n; i++) {
            if (a[i] >= s - a[i]) {
                for (int j = 0; j < n; j++) {
                    if (i != j && a[j] > 0) {
                        ans.add(new Potion(i, j, a[j]));
                    }
                }
                break;
            }
        }


        Collections.sort(ans);
        out.println(ans.size());
        for (Potion p : ans) {
            out.println(p.toAns());
        }

        in.close();
        out.close();
    }

    public void run() {
        try {
            solve();
        } catch (IOException e) {
            System.exit(1);
        }
    }

    public static void main(String[] s) {
        new Thread(new magic_as()).start();
    }
}