#include #include #include #include template struct Vector { using V = std::array; V vec; // constructor Vector(T val = 0) { vec.fill(val); } // getter T& operator[](int i) { return vec[i]; } T operator[](int i) const { return vec[i]; } typename V::iterator begin() { return vec.begin(); } typename V::iterator end() { return vec.end(); } // arithmetic Vector operator+(const Vector& v) const { return Vector(*this) += v; } Vector operator-(const Vector& v) const { return Vector(*this) -= v; } T operator*(const Vector& v) const { T ret(0); for (int i = 0; i < D; ++i) ret += vec[i] * v[i]; return ret; } // compound assignment Vector& operator+=(const Vector& v) { for (int i = 0; i < D; ++i) vec[i] += v[i]; return *this; } Vector& operator-=(const Vector& v) { for (int i = 0; i < D; ++i) vec[i] -= v[i]; return *this; } }; template struct Matrix { using M = std::array, D>; M mat; // constructor Matrix(T val = 0) { for (auto& v : mat) v.fill(val); } static Matrix id() { Matrix m; for (int i = 0; i < D; ++i) m[i][i] = 1; return m; } // getter std::array& operator[](int i) { return mat[i]; } std::array operator[](int i) const { return mat[i]; } typename M::iterator begin() { return mat.begin(); } typename M::iterator end() { return mat.end(); } // arithmetic Matrix operator+(const Matrix& m) const { return Matrix(*this) += m; } Matrix operator-(const Matrix& m) const { return Matrix(*this) -= m; } Matrix operator*(const Matrix& m) const { return Matrix(*this) *= m; } template Matrix pow(U k) { Matrix ret = id(); Matrix a = *this; while (k > 0) { if (k & 1) ret *= a; a *= a; k >>= 1; } return ret; } // compound assignment Matrix& operator+=(const Matrix& m) { for (int i = 0; i < D; ++i) { for (int j = 0; j < D; ++j) { mat[i][j] += m[i][j]; } } return *this; } Matrix& operator-=(const Matrix& m) { for (int i = 0; i < D; ++i) { for (int j = 0; j < D; ++j) { mat[i][j] -= m[i][j]; } } return *this; } Matrix& operator*=(const Matrix& m) { M nmat; for (auto& v : nmat) v.fill(0); for (int i = 0; i < D; ++i) { for (int j = 0; j < D; ++j) { for (int k = 0; k < D; ++k) { nmat[i][j] += mat[i][k] * m[k][j]; } } } mat = nmat; return *this; } // arithmetic with vector using Vec = Vector; Vec operator*(const Vec& v) { Vec ret; for (int i = 0; i < D; ++i) { for (int j = 0; j < D; ++j) { ret[i] += mat[i][j] * v[j]; } } return ret; } }; using lint = long long; using Vec = Vector; using Mat = Matrix; void solve() { int n; Vec v; std::cin >> n >> v[0] >> v[1]; v[2] = 1; std::vector> ps(n); for (auto& [k, d] : ps) { std::cin >> k; --k; if (k == 2) { d = -1; } else { std::cin >> d; } } std::reverse(ps.begin(), ps.end()); std::vector> ans; auto a = Mat::id(); for (auto [k, d] : ps) { Mat b; if (k == 2) { b[1][0] = -1; b[0][1] = b[2][2] = 1; } else { b = Mat::id(); b[k][2] = d; } a = a * b; auto nv = a * v; ans.emplace_back(nv[0], nv[1]); } std::reverse(ans.begin(), ans.end()); for (auto [x, y] : ans) std::cout << x << " " << y << "\n"; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }