#include #include #include #include #include #include #include #include #include #include #include #define FORE(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define FC(aa, bb) FORE(bb, aa) #define debug(x) cerr << #x << " = " << x << endl; #define debugv(x) cerr << #x << " = " ; FORE(it, (x)) cerr << *it << ", "; cerr << endl; #define fup(i, a, b) for(int i = (a); i <= (b); ++i) #define fdo(i, a, b) for(int i = (a); i >= (b); --i) #define FOR fup #define FORD fdo #define REP(i, n) for(int i = 0; i < (n); ++i) #define ALL(x) (x).begin(), (x).end() #define CLR(x) memset((x), 0, sizeof(x)) #define MP make_pair #define PB push_back #define siz(a) ((int)(a).size()) #define SZ siz #define inf 1000000000 #define FI first #define SE second using namespace std; typedef long long lli; typedef double ld; typedef lli LL; typedef ld LD; typedef vector VI; typedef pair PII; struct poly { int t[12]; void init() { CLR(t); } void wypisz() { cout << "POLY " << endl; fup(i, 0, 4) cout << i << " " << t[i] << endl; } }; const int mod = 23; poly mul(poly a, poly b) { poly c; c.init(); fup(i, 0, 4) fup(j, 0, 4) { c.t[i + j] += a.t[i] * b.t[j]; c.t[i + j] %= mod; } return c; } poly sum(poly a, poly b) { poly c; c.init(); fup(i, 0, 4) { c.t[i] = a.t[i] + b.t[i]; c.t[i] %= mod; } return c; } int n; int y[6]; int x[6]; bool jest[12]; int odw[24]; void do_mod() { cout << "NUM 23" << endl; cout << "ADD" << endl; cout << "NUM 23" << endl; cout << "MOD" << endl; } void generate(poly p) { fup(i, 1, 3) cout << "DUP" << endl; cout << "NUM 0" << endl; fdo(i, 4, 1) { cout << "NUM " << p.t[i] << endl; cout << "ADD" << endl; cout << "MUL" << endl; do_mod(); } cout << "NUM " << p.t[0] << endl; cout << "ADD" << endl; do_mod(); } int main() { fup(i, 1, mod - 1) { fup(j, 1, mod - 1) if ((i * j) % mod == 1) odw[i] = j; } while (cin >> n) { if (n == 0) break; CLR(jest); fup(i, 1, n) { cin >> x[i] >> y[i]; jest[x[i]] = 1; } fup(i, n + 1, 5) { fup(j, 0, 10) if (!jest[j]) { jest[j] = 1; x[i] = j; break; } } poly w; w.init(); //fup(i, 1, 5) cout << x[i] << " " << y[i] << endl; fup(i, 1, 5) { poly ww; ww.init(); ww.t[0] = 1; fup(j, 1, 5) if (i != j) { int dol = (x[i] - x[j] + mod) % mod; poly gora; gora.init(); gora.t[1] = 1; gora.t[0] = (-x[j] + mod) % mod; poly doll; doll.init(); doll.t[0] = odw[dol]; gora = mul(gora, doll); //gora.wypisz(); ww = mul(ww, gora); } poly yy; yy.init(); yy.t[0] = y[i]; ww = mul(ww, yy); w = sum(w, ww); } //w.wypisz(); generate(w); cout << "END" << endl; /* cout << 5 << endl; fup(i, 1, 5) cout << x[i] << endl;*/ cout << endl; } return 0; }