#include <bits/stdc++.h> using namespace std; typedef long long ll; #ifdef DEBUG #define var(x) cerr << #x << ": " << x << '\n'; #define range(a, b) cerr << #a <<", " << #b << ": "; for (auto _it = a; _it != b; ++_it) cerr << *_it << ' '; cerr <<'\n'; #else #define cerr if (false) cerr #define var(x) #define range(a, b) #endif #define pii pair<int, int> #define F first #define S second #define T(x, i) get<i>(x) #define all(v) v.begin(), v.end() #define forn(i, n) for (int i = 0; i < n; i++) #define int long long const int MAXN = 1e6 + 10; int n; mt19937_64 rng(1033); vector<pii> nb(pii a) { vector<pii> res; for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { if (j != 0 && i != 0) res.push_back({a.F + i, a.S + j}); } } return res; } bool ins(int l, int r, int x) { if (x < l || r < x) return false; return true; } int to_seg(int l, int r, int x) { if (ins(l, r, x)) return 0; return min(abs(l - x), abs(r - x)); } int get_d(pii a) { return abs(a.F) + abs(a.S); } int get_d(pii a, pii b) { a.F -= b.F; a.S -= b.S; return get_d(a); } pii step(pii a, pii b, int k) { auto d = b; d.F -= a.F; d.S -= a.S; d.F *= k; d.S *= k; a.F += d.F; a.S += d.S; return a; } pii get(int a, int b, int M, int l, int r) { cerr << "get " << a << ' ' << b << ' ' << M << ' ' << l << ' ' << r << endl; vector<pii> can; can.push_back({a, M - a}); can.push_back({a, a - M}); can.push_back({M - b, b}); can.push_back({b - M, b}); can.push_back({M, 0}); can.push_back({0, M}); can.push_back({-M, 0}); can.push_back({0, -M}); // int l = M - s; // int r = M + s; for (auto p : can) { if (get_d(p) != M) continue; auto pp2 = nb(p); int was = get_d(p, {a, b}); if (ins(l, r, was)) { cerr << "\t\t good 1 " << p.F << ' ' << p.S << endl; return p; } int need_steps = to_seg(l, r, was); assert(need_steps % 2 == 0); need_steps /= 2; for (auto p2 : pp2) { if (get_d(p2) != M) continue; auto p3 = step(p, p2, need_steps); int now = get_d(p3, {a, b}); if (ins(l, r, now)) { cerr << "\t\t good3 " << p3.F << ' ' << p3.S << endl; return p3; } cerr << "\t\t bad3 " << p3.F << ' ' << p3.S << endl; } } assert(false); } pii get_lr(vector<int> d) { if (d.empty()) return {0, 0}; int M = d[0]; int s = 0; for (auto i : d) s += i; s -= M; int l = M - s; int r = M + s; return {l, r}; } vector<pii> solver(int a, int b, vector<int> d) { cerr << "\n\n\n\n\n\n\n\n Solver(" << a << ' ' << b << ": \n\t"; range(d.begin(), d.end()); if (d.empty()) { assert(a == 0 && b == 0); return {}; } int M = d[0]; int s = 0; for (auto i : d) s += i; s -= M; int l = M - s; int r = M + s; bool revx = false; bool revy = false; if (a < 0) { revx = true; a *= -1; } if (b < 0) { revy = true; b *= -1; } d.erase(d.begin()); auto [ln, rn] = get_lr(d); auto [sa, sb] = get(a, b, M, ln, rn); int na = a - sa; int nb = b - sb; auto res = solver(na, nb, d); res.insert(res.begin(), {sa, sb}); if (revx) { for (auto p : res) p.F *= -1; } if (revy) { for (auto p : res) p.S *= -1; } return res; } bool check(int a, int b, vector<int> d) { int M = d[0]; int s = 0; for (auto i : d) s += i; s -= M; int l = M - s; int r = M + s; int need = a + b; if (l % 2 != need % 2) return false; if (need < l || r < need) return false; return true; } void solve() { int a, b, s = 0; // cin >> a >> b; a = abs((ll)rng()) % (10); b = abs((ll)rng()) % (10); n--; vector<int> dd(n); forn(i, n) { // cin >> dd[i]; dd[i] = abs((ll)rng()) % (10); } sort(all(dd)); reverse(all(dd)); cerr << "test " << n << ' ' << a << ' ' << b << endl; range(dd.begin(), dd.end()); auto can = check(a, b, dd); if (!can) { cout << "NO\n"; } else { auto ans = solver(a, b, dd); cout << "YES\n"; pii cur = {0, 0}; cout << cur.F << ' ' << cur.S << '\n'; for (auto d : ans) { cur.F += d.F; cur.S += d.S; cout << cur.F << ' ' << cur.S << '\n'; } } } signed main() { #ifdef DEBUG freopen("H.in", "r", stdin); // freopen("output.out", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); // while (cin >> n) solve(); for (int i = 0; i < 1000; i++) { n = (abs((ll)rng()) % (3)) + 2; cerr << "n = " << n << endl; solve(); } }