#include #define ll long long using namespace std; map> opt; ll xs[101]; int main() { srand(time(0)); ifstream input("test.in"); ifstream output("out.txt"); int t; input>>t; for (int i = 0; i < t; i++) { ll x; input>>x; xs[i] = x; int len; output>>len; string s; for (int j = 0; j < len; j++) { output>>s; opt[x].push_back(s); } } input.close(); output.close(); while (true) { vector seq; int slen = 10 + (rand() % 30); for (int i = 0; i < slen; i++) { int type = rand() % 9; if (type == 0) seq.push_back("+"); if (type == 1) seq.push_back("+"); if (type == 2) seq.push_back("+"); if (type == 3) seq.push_back("DUP"); if (type == 4) seq.push_back("DUP"); if (type == 5) seq.push_back("DUP"); if (type == 6) seq.push_back("*"); if (type == 7) seq.push_back("OVER"); if (type == 8) seq.push_back("SWAP"); } vector st = {1}; for (int j = 0; j < seq.size(); j++) { string s = seq[j]; if (s == "+") { if (st.size() == 1) { seq.erase(seq.begin() + j); j--; } else { ll y = st.back(); st.pop_back(); st.back() += y; } } else if (s == "*") { if (st.size() == 1) { seq.erase(seq.begin() + j); j--; } else { ll y = st.back(); st.pop_back(); st.back() *= y; } } else if (s == "DUP") { st.push_back(st.back()); } else if (s == "OVER") { if (st.size() == 1) { seq.erase(seq.begin() + j); j--; } else { st.push_back(st[st.size() - 2]); } } else if (s == "SWAP") { if (st.size() == 1) { seq.erase(seq.begin() + j); j--; } else { swap(st[st.size() - 1], st[st.size() - 2]); } } } while (st.size() > 1) { seq.push_back("+"); ll y = st.back(); st.pop_back(); st.back() += y; } ll x = st.back(); if (opt.find(x) == opt.end()) continue; if (opt[x].size() > seq.size()) { cout<<"Improved "<