1. Concise Abridged Statement
––––––––––––––––––––––––
You have N players and you must schedule a sequence of chess games so that:
- In the first game any two players meet.
- In each subsequent game, one of the players is the winner of the previous game.
- No game is drawn.
You are given an array a[1..N], where a[i] is the total number of games player i must play. Construct any valid sequence of games (winner, loser) that uses exactly ∑a[i]/2 games and in which each player i appears exactly a[i] times (either as winner or loser).

2. Detailed Editorial
––––––––––––––––
Let G = (∑a[i]) / 2 be the total number of games; it is guaranteed that ∑a[i] is even and that a solution exists.

Key idea: we maintain a “current champion” who must appear in every match (except the first game where we pick any champion). We will build the match list one by one, always honoring the rule that the previous winner (the champion) plays next.

Greedy strategy:
1. Sort players in descending order of remaining games. We keep the degrees in the array a[] (sorted in place) and a permutation perm[] that records the original index of each sorted position. The champion will always sit at position pos in this sorted order, starting at pos=0.
2. We iterate G times to schedule each game. At each step:
   - If a[pos] > 1, let the champion win. We record a partial match (champion, placeholder) and decrement a[pos] by 1. We will assign the actual opponent later.
   - If a[pos] == 1, then if the champion plays and wins he would have zero games left but we still need to hand off the champion token to someone who has remaining games. So instead we force the champion to lose to the next-strongest player (position pos+1). We record (pos+1 beats pos), decrement a[pos] and a[pos+1], and advance pos++ so the new champion is at the old position pos+1.
3. After this first pass, every game where the champion won has recorded only the winner and a “–1” placeholder for the loser. We now walk through those games in order and assign real opponents greedily from the pool of players with undepleted degrees (we keep advancing pos, skipping any position with a[pos]==0). Each time we assign an opponent to a “champion-win” match, we decrement that opponent’s remaining games.
4. Finally we output the G matches in the order we created them, translating the 0-based sorted indices back to the original player labels via perm.

Why it works:
- At each step, the champion (who must play) has at least one remaining game, so we never “get stuck.”
- For a[pos]>1 we let the champion win, preserving him as champion and consuming one of his matches.
- When exactly one match remains for the champion, we force him to lose to hand off the champion token to someone else who still needs matches.
- Every match consumes exactly two game‐slots, and by the end all remaining degrees are zero.

Time complexity: sorting O(N log N) plus O(G + N), comfortably within limits since G ≤ 10 000.

3. C++ Solution
––––––––––––––––
```cpp
#include <bits/stdc++.h>

using namespace std;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    return out << x.first << ' ' << x.second;
}

template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& x) {
    return in >> x.first >> x.second;
}

template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for(auto& x: a) {
        in >> x;
    }
    return in;
};

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
    for(auto x: a) {
        out << x << ' ';
    }
    return out;
};

int n;
vector<int> a;

void read() {
    cin >> n;
    a.resize(n);
    cin >> a;
}

void solve() {
    /*
     * The games form a chain where the winner of each game plays the next, so
     * game g and game g+1 share exactly one player (the carried-over winner).
     * The total number of games is G = (sum of all game counts) / 2.
     *
     * Sort players by remaining game count descending (perm records original
     * indices). Build the winner column greedily: while the busiest player
     * still owes more than one game, make him the winner of the next game and
     * defer choosing his opponent; when he owes exactly one, he plays the next
     * player and we advance. We then fill each deferred opponent slot with the
     * next player that still has games left. Outputting (winner, loser) per
     * game with the winner first satisfies the "winner plays next" rule.
     */

    int sum_deg = accumulate(a.begin(), a.end(), 0);
    assert(sum_deg % 2 == 0);

    vector<int> perm(n);
    iota(perm.begin(), perm.end(), 0);
    sort(perm.begin(), perm.end(), [&](int i, int j) {
        return a[i] > a[j];
    });
    sort(a.rbegin(), a.rend());

    vector<pair<int, int>> matches;
    int pos = 0;
    for(int i = 0; i < sum_deg / 2; i++) {
        if(a[pos] == 1) {
            matches.emplace_back(pos + 1, pos);
            a[pos]--;
            a[pos + 1]--;
            pos++;
        } else {
            matches.emplace_back(pos, -1);
            a[pos]--;
        }
    }

    for(auto& match: matches) {
        if(match.second != -1) {
            continue;
        }
        while(a[pos] == 0) {
            pos++;
        }

        match.second = pos;
        a[pos]--;
    }

    cout << matches.size() << '\n';
    for(const auto& match: matches) {
        cout << perm[match.first] + 1 << ' ' << perm[match.second] + 1 << '\n';
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1;
    // cin >> T;
    for(int test = 1; test <= T; test++) {
        read();
        // cout << "Case #" << test << ": ";
        solve();
    }

    return 0;
}
```

4. Python Solution with Detailed Comments
––––––––––––––––––––––––––––––––––––
```python
import sys

def main():
    data = sys.stdin.read().split()
    n = int(data[0])
    a = list(map(int, data[1:]))

    total = sum(a)
    assert total % 2 == 0
    G = total // 2

    # Create sorted order of players by descending games
    perm = list(range(n))
    perm.sort(key=lambda i: -a[i])

    # b[i] = remaining games of the player at sorted position i
    b = [a[i] for i in perm]

    matches = []  # will store tuples (winner_idx, loser_idx or -1)
    p = 0         # current champion pointer

    # Phase 1: decide winners & placeholders
    for _ in range(G):
        if b[p] > 1:
            # champion wins, postpone picking loser
            matches.append([p, -1])
            b[p] -= 1
        else:
            # champion must lose to pass on the token
            matches.append([p+1, p])
            b[p]   -= 1
            b[p+1] -= 1
            p += 1  # new champion

    # Phase 2: fill in the losers for placeholder matches
    q = 0
    for mv in matches:
        if mv[1] != -1:
            continue
        # find next player with leftover games
        while b[q] == 0:
            q += 1
        mv[1] = q
        b[q] -= 1

    # Print results, translating back to 1-based original indices
    out = [str(G)]
    for w, l in matches:
        # perm[w] is the original index, add 1 for 1-based
        out.append(f"{perm[w]+1} {perm[l]+1}")
    print("\n".join(out))

if __name__ == "__main__":
    main()
```

5. Compressed Editorial
––––––––––––––––
Sort players by remaining matches descending. Always keep the “current champion” at the front.
- While champion has >1 games, let him win and record (champion, –1).
- When he has exactly one left, force him to lose to the next player, decrement both, and advance the champion pointer.
After scheduling all games, fill each “–1” loser slot by greedily picking any player who still needs matches. This produces a valid chain of G=∑a[i]/2 games in which each player appears exactly a[i] times.
