#include <algorithm>
#include "validate.h"

using namespace std;

int n;
int stacks[100];
int sum, big;
bool possible;

void read_input(istream &in) {
    in >> n;
    for (int i = 1; i <= n; i++) {
        in >> stacks[i];
        sum += stacks[i];
        big = max(big,stacks[i]);
    }
    possible = sum%2 == 0 && big <= sum-big;
}


void check_solution(istream &sol) {
    string answer;
    sol >> answer;
    transform(answer.begin(), answer.end(), answer.begin(), ::tolower);
    if (possible && answer != "yes") {
        wrong_answer("Solution exists but first line is not 'yes'");
    }
    if (!possible && answer != "no") {
        wrong_answer("No solution exists but first line is not 'no'");
    }
    if (possible) {
        for (int i = 1; i <= sum/2; i++) {
            int a = 0, b = 0;
            if (!(sol >> a >> b)) {
                wrong_answer("Failed to read %d'th move", i);
            }
            if (a < 1 || a > n || b < 1 || b > n || a == b) {
                wrong_answer("%d'th move (%d, %d) is invalid", i, a, b);
            }
            if (stacks[a] == 0 || stacks[b] == 0) {
                wrong_answer("%d'th move (%d, %d) is invalid; taking coin from empty stack", i, a, b);
            }
            stacks[a]--;
            stacks[b]--;
        }
    }
}

int main(int argc, char **argv) {
    init_io(argc, argv);

    read_input(judge_in);
    check_solution(author_out);

    string trash;
    if (author_out >> trash) {
        wrong_answer("Trailing output");
    }

    accept();
}
