func_code_string: #include <bits/stdc++.h>   using namespace std;   int n;   int a[510];   vector<pair<int, int> > edges;   vector<int> leaf, nonleaf;   int d = 0;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) {       if (a[i] == 1)         leaf.push_back(i);       else         nonleaf.push_back(i);     }     d = nonleaf.size() - 1 + min((int)leaf.size(), 2);     int reserved = -1;     if (!leaf.empty()) reserved = leaf.back(), leaf.pop_back();     for (int i = 0; i < (int)nonleaf.size() - 1; i++) {       int k = nonleaf[i];       while (!leaf.empty() && a[k] > 1) {         edges.push_back({leaf.back(), k});         leaf.pop_back();         a[k]--;       }       a[k]--;       a[nonleaf[i + 1]]--;       edges.push_back({k, nonleaf[i + 1]});     }     int tp = 501;     if (!nonleaf.empty()) tp = nonleaf.back();     if (reserved != -1) leaf.push_back(reserved);     while (!leaf.empty() && a[tp] > 0) {       edges.push_back({leaf.back(), tp});       leaf.pop_back();       a[tp]--;     }     if (leaf.empty()) {       printf( YES %d n , d);       printf( %d n , (int)edges.size());       for (auto k : edges) {         printf( %d %d n , k.first, k.second);       }     } else {       printf( NO n );     }     return 0;   }   