description: Bob really likes playing with arrays of numbers. That's why for his birthday, his friends bought him a really interesting machine – an array beautifier. 
  
  The array beautifier takes an array A consisting of N integers, and it outputs a new array B of length N that it constructed based on the array given to it. The array beautifier constructs the new array in the following way: it takes two numbers at different indices from the original array and writes their sum to the end of the new array. It does this step N times - resulting in an output array of length N. During this process, the machine can take the same index multiple times in different steps. 
  
  Bob was very excited about the gift that his friends gave him, so he put his favorite array in the machine. However, when the machine finished, Bob was not happy with the resulting array. He misses his favorite array very much, and hopes to get it back. 
  
  Given the array that the machine outputted, help Bob find an array that could be the original array that he put in the machine. Sometimes the machine makes mistakes, so it is possible that no appropriate input array exists for the array it has outputted. In such case, let Bob know that his array is forever lost.
  
  Input
  
  The first line contains one positive integer N (2 ≤ N ≤ 10^3) – the length of Bob's array.
  
  The second line contains N integers B_1, B_2, ..., B_N (1 ≤ B_i ≤ 10^6) – the elements of the array the machine outputted.
  
  Output
  
  If an appropriate input array exists, print "YES", followed by the input array A_1, A_2, ..., A_N (-10^9 ≤ A_i ≤ 10^9) in the next line. Otherwise, print "NO".
  
  Examples
  
  Input
  
  
  2
  5 5
  
  
  Output
  
  
  YES
  2 3
  
  
  Input
  
  
  3
  1 2 3
  
  
  Output
  
  
  YES
  0 1 2
  
  
  Input
  
  
  3
  2 4 5
  
  
  Output
  
  
  NO
  
  
  Input
  
  
  4
  1 3 5 7
  
  
  Output
  
  
  YES
  6 -3 4 1
solution: #include <bits/stdc++.h>
  using namespace std;
  const int N = 1005;
  int n, m, a[N], b[N], ban[N];
  void solve(int x, int y, int z) {
    assert((x + y + z) % 2 == 0);
    b[1] = (y + z - x) / 2;
    b[2] = (x + z - y) / 2;
    b[3] = (x + y - z) / 2;
  }
  void calc(int hav) {
    for (int i = 1; i <= n; i++) {
      if (!ban[i]) {
        b[hav + 1] = a[i] - b[hav];
        ++hav;
      }
    }
    assert(hav == n);
    puts("YES");
    for (int i = 1; i <= n; i++) printf("%d ", b[i]);
    puts("");
    exit(0);
  }
  map<int, int> mp;
  void dfs(int u, int S, int cnt, int sum) {
    if (m - u + 1 < cnt) return;
    if (u == m + 1) {
      assert(!cnt);
      if (mp[sum]) {
        int T = mp[sum];
        int both = S & T;
        S -= both;
        T -= both;
        stack<int> s1, s2;
        for (int i = 1; i <= m; i++) {
          if (S >> (i - 1) & 1) {
            ban[i] = 1;
            s1.push(a[i]);
          }
        }
        for (int i = 1; i <= m; i++) {
          if (T >> (i - 1) & 1) {
            ban[i] = 1;
            s2.push(a[i]);
          }
        }
        int tot = 1;
        while (!s1.empty()) {
          b[tot + 1] = s1.top() - b[tot];
          ++tot, s1.pop();
          b[tot + 1] = s2.top() - b[tot];
          ++tot, s2.pop();
        }
        calc(--tot);
      }
      mp[sum] = S;
    }
    dfs(u + 1, S, cnt, sum);
    if (cnt) dfs(u + 1, S | (1 << (u - 1)), cnt - 1, sum + a[u]);
  }
  int main() {
    scanf("%d", &n);
    stack<int> s[2];
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      s[a[i] & 1].push(i);
    }
    if (n == 1) {
      printf("YES\n%d\n", a[1]);
      return 0;
    }
    if (n == 2) {
      if (a[1] == a[2])
        printf("YES\n0 %d\n", a[1]);
      else
        puts("NO");
      return 0;
    }
    bool gone = false;
    if (s[0].size() >= 3) {
      int x = s[0].top();
      s[0].pop();
      int y = s[0].top();
      s[0].pop();
      int z = s[0].top();
      s[0].pop();
      ban[x] = ban[y] = ban[z] = 1;
      solve(a[x], a[y], a[z]), gone = true;
    } else if (s[0].size() >= 1 && s[1].size() >= 2) {
      int x = s[0].top();
      s[0].pop();
      int y = s[1].top();
      s[1].pop();
      int z = s[1].top();
      s[1].pop();
      ban[x] = ban[y] = ban[z] = 1;
      solve(a[x], a[y], a[z]), gone = true;
    }
    if (gone) calc(3);
    if (n == 3) {
      puts("NO");
      return 0;
    }
    assert(s[0].empty());
    m = min(n, 26);
    if (n <= 26) {
      for (int i = 1; i <= n / 2; i++) {
        mp.clear();
        dfs(1, 0, i, 0);
      }
      puts("NO");
      return 0;
    }
    dfs(1, 0, 13, 0);
    return 0;
  }
  