void main(){ import std.stdio, std.string, std.conv, std.algorithm; int n; long px, py; rd(n, px, py); int m=3; auto mats=new long[][][](n, m, m); foreach(i; 0..n){ auto args=readln.split.to!(int[]); if(args[0]==1){ mats[i][0][0]=mats[i][1][1]=mats[i][2][2]=1; mats[i][0][2]=args[1]; }else if(args[0]==2){ mats[i][0][0]=mats[i][1][1]=mats[i][2][2]=1; mats[i][1][2]=args[1]; }else if(args[0]==3){ mats[i][0][1]=1; mats[i][1][0]=-1; mats[i][2][2]=1; } } auto T=new long[][](m, m); T[0][0]=T[1][1]=T[2][2]=1; long[] v=[px, py, 1L]; struct Point{ long x, y; string toString(){ return x.to!(string)~" "~y.to!(string); } } auto points=new Point[](n); foreach_reverse(idx, mat; mats){ auto U=new long[][](m, m); foreach(i; 0..m)foreach(j; 0..m){ long tmp=0; foreach(k; 0..m) tmp+=T[i][k]*mat[k][j]; U[i][j]=tmp; } T.swap(U); long qx=0, qy=0; foreach(k; 0..m){ qx+=T[0][k]*v[k]; qy+=T[1][k]*v[k]; } points[idx]=Point(qx, qy); // writeln(qx, " ", qy); } writefln("%(%s\n%)", points); } void rd(T...)(ref T x){ import std.stdio, std.string, std.conv; auto l=readln.split; assert(l.length==x.length); foreach(i, ref e; x) e=l[i].to!(typeof(e)); }