#define _USE_MATH_DEFINES #include using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() using ll = long long; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr double EPS = 1e-8; constexpr int MOD = 1000000007; // constexpr int MOD = 998244353; constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1}; template inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; } template inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << fixed << setprecision(20); } } iosetup; template struct Matrix { Matrix(int m, int n, T val = 0) : dat(m, std::vector(n, val)) {} int height() const { return dat.size(); } int width() const { return dat.front().size(); } Matrix pow(long long exponent) const { int n = height(); Matrix tmp = *this, res(n, n, 0); for (int i = 0; i < n; ++i) res[i][i] = 1; while (exponent > 0) { if (exponent & 1) res *= tmp; tmp *= tmp; exponent >>= 1; } return res; } inline const std::vector &operator[](const int idx) const { return dat[idx]; } inline std::vector &operator[](const int idx) { return dat[idx]; } Matrix &operator=(const Matrix &x) { int m = x.height(), n = x.width(); dat.resize(m, std::vector(n)); for (int i = 0; i < m; ++i) for (int j = 0; j < n; ++j) dat[i][j] = x[i][j]; return *this; } Matrix &operator+=(const Matrix &x) { int m = height(), n = width(); for (int i = 0; i < m; ++i) for (int j = 0; j < n; ++j) dat[i][j] += x[i][j]; return *this; } Matrix &operator-=(const Matrix &x) { int m = height(), n = width(); for (int i = 0; i < m; ++i) for (int j = 0; j < n; ++j) dat[i][j] -= x[i][j]; return *this; } Matrix &operator*=(const Matrix &x) { int m = height(), n = x.width(), l = width(); std::vector> res(m, std::vector(n, 0)); for (int i = 0; i < m; ++i) for (int j = 0; j < n; ++j) { for (int k = 0; k < l; ++k) res[i][j] += dat[i][k] * x[k][j]; } std::swap(dat, res); return *this; } Matrix operator+(const Matrix &x) const { return Matrix(*this) += x; } Matrix operator-(const Matrix &x) const { return Matrix(*this) -= x; } Matrix operator*(const Matrix &x) const { return Matrix(*this) *= x; } private: std::vector> dat; }; int main() { int n; cin >> n; Matrix p(3, 1, 1); cin >> p[0][0] >> p[1][0]; vector type(n), d(n); REP(i, n) { cin >> type[i]; if (type[i] == 1 || type[i] == 2) cin >> d[i]; } vector> a; Matrix m(3, 3); REP(i, 3) m[i][i] = 1; for (int i = n - 1; i >= 0; --i) { Matrix command(3, 3); command[2][2] = 1; if (type[i] == 1) { command[0][0] = command[1][1] = 1; command[0][2] = d[i]; } else if (type[i] == 2) { command[0][0] = command[1][1] = 1; command[1][2] = d[i]; } else if (type[i] == 3) { command[0][1] = 1; command[1][0] = -1; } m *= command; a.emplace_back(m * p); } reverse(ALL(a)); REP(i, n) cout << a[i][0][0] << ' ' << a[i][1][0] << '\n'; return 0; }