#include<bits/stdc++.h>
using namespace std;
int n,x,sum;
int main(){
    scanf("%d",&n);
    if(n==1){
        scanf("%d",&x);
        if(x==0)printf("NO");
        else printf("YES");
        return 0;
    }
    for(int i=0;i<n;i++){
        scanf("%d",&x);
        if(x==0)
            sum++;
    }
    if(sum==1)printf("YES");
    else printf("NO");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define SC scanf
#define PR printf
#define pb push_back
#define mp make_pair
#define SZ(v) ((int)(v).size())
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef pair<pii,pii> ppp;
typedef vector<int> vi;
typedef vector<pii> vii;
const int INF=0x3f3f3f3f;
const ll LL_INF=0x3f3f3f3f3f3f3f3f;
const int xx[4]={1,-1,0,0};
const int yy[4]={0,0,1,-1};
int inline in(){
	int x=0,c;
	for(;(unsigned int)((c=getchar())-'0')>=10;){
		if(c=='-')return -in();
		if(!~c)throw ~0;
	}
	do{
		x=(x<<3)+(x<<1)+(c-'0');
	}while((unsigned int)((c=getchar())-'0')<10);
	return x;
}
int n;
int a[1005];
int main(){
    ios::sync_with_stdio(false);
	n=in();
	int cnt=0;
	for(int i=1;i<=n;i++){
		a[i]=in();
		if(a[i]==0)cnt++;
	}
	if(n==1&&cnt==1)return puts("NO");
	if(n==1&&cnt==0)return puts("YES");
	return puts(cnt==1?"YES":"NO");
}


#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC once
%:pragma GCC optimize("Ofast")
%:pragma GCC optimize("inline")
%:pragma GCC optimize("-fgcse")
%:pragma GCC optimize("-fgcse-lm")
%:pragma GCC optimize("-fipa-sra")
%:pragma GCC optimize("-ftree-pre")
%:pragma GCC optimize("-ftree-vrp")
%:pragma GCC optimize("-fpeephole2")
%:pragma GCC optimize("-ffast-math")
%:pragma GCC optimize("-fsched-spec")
%:pragma GCC optimize("unroll-loops")
%:pragma GCC optimize("-falign-jumps")
%:pragma GCC optimize("-falign-loops")
%:pragma GCC optimize("-falign-labels")
%:pragma GCC optimize("-fdevirtualize")
%:pragma GCC optimize("-fcaller-saves")
%:pragma GCC optimize("-fcrossjumping")
%:pragma GCC optimize("-fthread-jumps")
%:pragma GCC optimize("-funroll-loops")
%:pragma GCC optimize("-fwhole-program")
%:pragma GCC optimize("-freorder-blocks")
%:pragma GCC optimize("-fschedule-insns")
%:pragma GCC optimize("inline-functions")
%:pragma GCC optimize("-ftree-tail-merge")
%:pragma GCC optimize("-fschedule-insns2")
%:pragma GCC optimize("-fstrict-aliasing")
%:pragma GCC optimize("-fstrict-overflow")
%:pragma GCC optimize("-falign-functions")
%:pragma GCC optimize("-fcse-skip-blocks")
%:pragma GCC optimize("-fcse-follow-jumps")
%:pragma GCC optimize("-fsched-interblock")
%:pragma GCC optimize("-fpartial-inlining")
%:pragma GCC optimize("no-stack-protector")
%:pragma GCC optimize("-freorder-functions")
%:pragma GCC optimize("-findirect-inlining")
%:pragma GCC optimize("-fhoist-adjacent-loads")
%:pragma GCC optimize("-frerun-cse-after-loop")
%:pragma GCC optimize("inline-small-functions")
%:pragma GCC optimize("-finline-small-functions")
%:pragma GCC optimize("-ftree-switch-conversion")
%:pragma GCC optimize("-foptimize-sibling-calls")
%:pragma GCC optimize("-fexpensive-optimizations")
%:pragma GCC optimize("-funsafe-loop-optimizations")
%:pragma GCC optimize("inline-functions-called-once")
%:pragma GCC optimize("-fdelete-null-pointer-checks")
#include <bits/stdc++.h>
using namespace std;
inline char gc() {
    static char buf[1 << 17], *p1 = buf, *p2 = buf;
    return p1 == p2 && (p2 = (p1 = buf) +
        fread(buf, 1, 1 << 17, stdin), p1 == p2) ?
        EOF : *p1++;
}
template<class T>
inline bool read(T &n) {
    char ch = gc();
    for(n = 0; (ch < '0' || ch > '9') && ch != EOF; ch = gc());
    if(ch != EOF) {
        for(;ch >='0' && ch <= '9'; ch = gc())
            n = (n << 1) + (n << 3) + ch - '0';
        return true;
    }
    return false;
}
int main()
{
    int n,m,sum = 0;
    read(n);
    for(register int i = 0 ; i < n ; i ++)
    {
        read(m);
        sum += m;
    }
    if(n-sum == min(1,n-1))puts("YES");
    else puts("NO");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,sum=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>m;
        sum+=m;
    }
    if(n-sum==min(1,n-1))cout<<"YES";
    else cout<<"NO";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a,n,ko[1001];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>ko[i];
		if(ko[i]==0)
		a++;
	}
	if(n==1)
	{
		if(ko[1]==1)
		{
			cout<<"YES";
		}
		else cout<<"NO";
	}
	if(n>1)
	{
		if(a==1)
		{
			cout<<"YES";
		}
		else cout<<"NO";
	}

}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<cstdlib>
using namespace std;
int n,now;
bool a;
int main(){
    cin>>n>>a;
	if(a==0) now=1;
    if(n==1){
    	if(a==1) cout<<"YES";
    	else cout<<"NO";
    	return 0;
	}
	for(int i=2;i<=n;i++){
		cin>>a;
		if(a==0)
			if(now){
				cout<<"NO";
				return 0;
			}
			else now=1;
	}
	if(now==1) cout<<"YES";
	else cout<<"NO";
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n;bool x,flag=0;cin>>n;
	if(n==1)
	{
		cin>>x;
		if(x==1)cout<<"YES";
		else cout<<"NO";
		return 0;
	}
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		if(x==0)
		{
			if(flag==0)flag=1;
			else if(flag==1)
			{
				cout<<"NO";
				return 0;
			}
		}
	}
	cout<<"YES";
	return 0;
}


#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
	int i,j,n,flag=0;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>j;
		if(!j)
			flag++;
	}
	if(flag==1||n==1)
		cout<<"YES";
	else
		cout<<"NO";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long int n;
int main()
{
    int m=0,s=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
    	cin>>m;
    	if(m==1)
    	{
    		s++;
    	}
	}
	if(s%2==0)
	{
		cout<<"YES";
	}
	else
	{
		cout<<"NO";
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,ans=0;
	cin>>n;
	short j[n+5];
	for(int i=1;i<=n;i++)
		cin>>j[i],ans+=j[i];
	if(n==1&&ans==1)
	{
		cout<<"YES";
		return 0;
	}
	if(n==1&&ans==0)
	{
		cout<<"NO";
		return 0;
	}
	if(ans==(n-1))
	{
		cout<<"YES";
		return 0;
	}
	cout<<"NO";
 	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[10010];
int main()
{
	int n,sum=0;
	cin>>n;
	if(n==1)
	{
		cin>>a[1];
		if(a[1]==1) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
		return 0;
	}
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]==0) sum++;
	}
	if(sum>1||a[n]==0)
		cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int t[2],a[1001],n,x;
int main() {
    cin>>n;
    if(n==1){
    	cin>>x;
    	if(x==0) cout<<"NO"<<endl;
    	else cout<<"YES"<<endl;
    	return 0;
    }
    for(int i=0;i<n;i++){
        cin>>a[i];
        t[a[i]]++;
    }
    if (t[0]==1) cout<<"YES";
    else cout<<"NO";
    return 0;
}


#include<cstdio>
int n,s;
inline int r(){
	int o=0;char c=getchar();
	while(c<48||c>57)	c=getchar();
	while(c<58&&c>47)	o=(o<<1)+(o<<3)+(c^48),c=getchar();
	return o;
}
int main(){
	n=r();
	for(int i=0;i<n;++i)	s+=r();
	if(n^1)	puts(n-s^1?"NO":"YES");
	else puts(s?"YES":"NO");
    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int n,m[3580],Max;
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>m[i];
		if(m[i]==0){
			Max++;
		}
	}
	if(Max==1||n==1) cout<<"YES";
	else cout<<"NO";
	return 0;
}


#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
	int i,j,n,flag=0;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>j;
		if(!j)
			flag++;
	}
	if((flag==1&&n>1)||(n==1&&flag==0))
		cout<<"YES";
	else
		cout<<"NO";
	return 0;
}


#include<cstdio>
using namespace std;
int main(){
    int n,tot=0,a;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a);
        tot+=a^1;
    }
    if(n==1){
        puts(tot?"YES":"NO");
    }
    else {
        puts(tot<=1?"YES":"NO");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,ans,m;
int main(){
    cin>>n;
    if(n==1){
    	cin>>m;
    	if(m)cout<<"YES";
    	else cout<<"NO";
	}
	else{
		int flag=0;
		for(int i=1;i<=n;i++)
		{
			cin>>m;
			if(flag==0&&!m)flag=1;
			if(flag==1&&!m){
				cout<<"NO";
				return 0;
			}
			if(flag)cout<<"YES";
			else cout<<"NO";
		}
	}
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,sum = 0;
    cin >> n;
    for(int i = 0 ; i < n ; i ++)
    {
        cin >> m;
        sum += m;
    }
    if(n-sum == min(1,n-1))
    {
      cout<<"YES";
    }
    else
    {
      cout<<"NO";
    }
    return 0;
}


#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <string>
#include <sstream>
#include <vector>
#include <stack>
#include <queue>
//fixed<<setprecision(2)
using namespace std;
int WorkTime[10000]={};
int main(){
	int n,k;
	int c=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>k;
		if(k==0){
			c++;
			if(c>1){
				cout<<"NO";
				return 0;
			}
		}
	}
	if(c==1){
		cout<<"YES";
	}
	else{
		cout<<"NO";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n;
int s=0;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		int a;
		cin>>a;
		if(a==1)s++;
	}
	if(n==1&&s==1)cout<<"YES";
	else{
		if(n>1&&s==n-1)cout<<"TES";
		else cout<<"NO";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int sth[2]={0};
int main()
{
	int n;
	cin>>n;
	while(n--)
	{
		int x;
		cin>>x;
		sth[x]++;
	}
	if(sth[0]==1)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int n;
    int a;
    int cnt=0;
    if(n==1)
    {
        cin>>a;
        if(a==0)
        {
            cout<<"No"<<endl;
            return 0;
        }
        else
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    else
    {
        for(int i=1;i<=n;i++)
        {
            cin>>a;
            if(a==1) cnt++;
        }
        if(cnt==n-1)
        {
            cout<<"Yes"<<endl;
        }
        else
        {
            cout<<"No"<<endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    bool fl;
    bool vis=0;
    cin>>n;
    while(n--){
        cin>>fl;
        if(vis==1){
            cout<<"NO";
            return 0;
        }
        if(fl==0){
            vis=1;
        }
    }
    cout<<"YES";
    return 0;
}


#include <iostream>
using namespace std;
int n, x;
bool op = false;
int main()
{
    cin >> n;
    if(n == 1)
    {
        cin >> x;
        if(x == 1)
        {
            cout << "YES";
        }
        else
        {
            cout << "NO";
        }
        return 0;
    }
    while(n --)
    {
        cin >> x;
        if(!x)
        {
            if(op)
            {
                cout << "NO";
                return 0;
            }
            op = true;
        }
    }
    if(!op) cout <<"NO";
    else cout << "YES";
}


#include <iostream>
using namespace std;
int n, a[1001]; bool tmp;
int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    if (n == 1) cout << (a[1] == 0 ? "NO\n" : "YES\n");
    else for (int i = 1; i <= n; i++) if (a[i] == 0) {
        if (tmp) goto here;
        else tmp = 1;
    }
    if (tmp) { cout << "YES\n"; return 0;}
    here:;
    cout << "NO\n";
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#define INF 0x3f3f3f3f
using namespace std;

int n,a,t;
int main(){
	cin>>n;
	if(n==1){
		cout<<"YES";
		return 0;
	}
	for(int i=1;i<=n;i++){
		if(t==2){
			cout<<"NO";
			return 0;
		}
		cin>>a;
		if(a==0)t++;
		if(t==2){
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
	return 0;
}


#include<cstdio>
#include<algorithm>
#define fi first
#define se second
#define mp std::make_pair
typedef long long ll;
typedef std::pair<ll,ll> pll;
const int N=300005;
int n,m,top;pll a[N];ll k,b;
double slope(pll a,pll b){return 1.0*(a.se-b.se)/(a.fi-b.fi);}
ll calc(pll x){return k*x.fi+b+x.se;}
int main(){
	scanf("%d%d",&n,&m);a[top=1]=mp(0,0);
	for(int i=1,tp,k1,k2;i<=m;++i){
		scanf("%d%d",&tp,&k1);
		if(tp==1)a[top=1]=mp(0,0),k=b=0,n+=k1;else
		if(tp==2){
			pll now=mp(n,-(n*k+b));
			while(top>1&&slope(now,a[top])<=slope(a[top],a[top-1]))--top;
			a[++top]=now,n+=k1;
		}else{
			scanf("%d",&k2);
			b+=k1,k+=k2;
		}
		while(top>1&&calc(a[top])>=calc(a[top-1]))--top;
		printf("%lld %lld\n",a[top].fi+1,calc(a[top]));
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#define INF 0x3f3f3f3f3f3f3f3f
#define MAXN 200010
using namespace std;

#define int long long

int readin()
{
	char c=getchar();
	int read_ans=0;
	while(c<'0'||c>'9')
		c=getchar();
	while(c>='0'&&c<='9')
	{
		read_ans=read_ans*10+c-'0';
		c=getchar();
	}
	return read_ans;
}

int n,m;

// priority_queue
int hd=0;
int tl=0;
int nxt[MAXN];
int num[MAXN];
int len[MAXN];
int pos[MAXN];
int tail=0;

void addf(int k)
{
	nxt[++tail]=hd;
	num[tail]=0;
	pos[tail]=1;
	len[tail]=k;
	hd=tail;
}
void adde(int k)
{
	nxt[tl]=++tail;
	num[tail]=0;
	pos[tail]=pos[tl]+len[tl];
	len[tail]=k;
	tl=tail;
}

signed main()
{
	// freopen("dance.in","r",stdin);
	//freopen("dance.out","w",stdout);
	n=readin();
	m=readin();
	addf(n);
	tl=1;
	int op,now_u,now_v;
	int minnum=0;
	int minpos=1;
	//int d1=0,d2=0;
	int tot=n;
	for (register int i=1;i<=m;++i)
	{
		op=readin();
		if (op==1)
		{
			now_u=readin();
			puts("1 0");
			tot+=now_u;
			minnum=0;
			minpos=1;
			addf(now_u);
		}
		if (op==2)
		{
			now_u=readin();
			if (minnum==0)
				printf("%lld 0\n",minpos);
			else
			{
				printf("%lld 0\n",tot+1);
				minnum=0;
				minpos=tot+1;
			}
			tot+=now_u;
			adde(now_u);
		}
		if (op==3)
		{
			now_u=readin();
			now_v=readin();
			// d1+=now_u;
			// d2+=
			minnum=INF;
			minpos=0;
			for (register int i=hd;i;i=nxt[i])
			{
				num[i]+=now_u;
				num[i]+=now_v*(pos[i]-1);
				//cout<<"QAQ"<<num[i]<<" "<<pos[i]<<"QAQ";
				if (num[i]<minnum)
				{
					minnum=num[i];
					minpos=pos[i];
				}
			}
			//puts("");
			printf("%lld %lld\n",minpos,minnum);
		}
	}
	return 0;
}


    #include<bits/stdc++.h>

    using namespace std;
    const double eps = 1e-9;
    const int maxn = 1023000;
    struct Point
    {
        long long x, y;
        Point(){}
        Point(long long _x, long long _y)
        {
            x = _x, y = _y;
        }
        Point operator -(const Point &b)const
        {
            return Point(x - b.x,y - b.y);
        }
        double operator *(const Point &b)const
        {
            return (double)x*b.y - (double)y*b.x;
        }
    };
   // long long calc(Point A) {return A.y+k*A.x+b;}
    Point st[maxn];
    long long k, b;
    int top, op;
    int main()
    {
        int n, m, tmp;
        cin >> n >> m;
        st[++top] = Point(0,0);
        while(m--)
        {
            scanf("%d", &op);
            if(op == 1)
            {
                st[top=1] = Point(1,0);
                scanf("%d", &tmp);
                n += tmp, k = b = 0;
            }
            else if(op == 2)
            {
                Point tail = Point(n+1, -(n*k+b));
                scanf("%d", &tmp);
                n += tmp;
                while(top>1 && (tail-st[top-1])*(st[top]-st[top-1])>=0) top--;
                st[++top] = tail;
            }
            else
            {
                scanf("%d", &tmp);
                b += tmp;
                scanf("%d", &tmp);
                k += tmp;
            }
            while(top>1 && st[top].y+st[top].x*k - st[top-1].y-st[top-1].x*k >= 0) top--;
            printf("%lld %lld\n",st[top].x, st[top].y+(st[top].x-1)*k+b);
             //  cout << st[top].x << ' ' << st[top].y+(st[top].x-1)*k+b << "!!!"<<endl;
        }
        return 0;
    }


#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N=3e5+2;
typedef long long ll;
typedef long double db;
ll st[N],zb[N],k,b,cd,y;
int tp,m,c,x;
inline void read(int &x)
{
	c=getchar();
	while ((c<48)||(c>57)) c=getchar();
	x=c^48;c=getchar();
	while ((c>=48)&&(c<=57))
	{
		x=x*10+(c^48);
		c=getchar();
	}
}
int main()
{
	read(x);cd=x;tp=1;read(m);zb[1]=1;
	for (;m--;printf("%lld %lld\n",zb[tp],st[tp]+zb[tp]*k+b))
	{
		read(x);
		if(x==1)
		{
			read(x);cd+=x;
			tp=1;k=b=0;
			continue;
		}
		if (x==2)
		{
			read(x);y=-k*(cd+1)-b;
			//if (st[tp]==-k*zb[tp]-b) {cd+=x;continue;}
			while ((tp>1)&&((db)(st[tp]-y)*(zb[tp]-zb[tp-1])>=(db)(st[tp-1]-st[tp])*(cd+1-zb[tp]))) --tp;
			zb[++tp]=cd+1;
			st[tp]=y;
			cd+=x;
			continue;
		}
		read(x);b+=x;read(x);k+=x;b-=x;
		while ((tp>1)&&((st[tp-1]-st[tp])<=(db)(zb[tp]-zb[tp-1])*k)) --tp;
	}
}


    #include<bits/stdc++.h>

    using namespace std;
    const double eps = 1e-9;
    const int maxn = 1023000;
    struct Point
    {
        long long x, y;
        Point(){}
        Point(long long _x, long long _y)
        {
            x = _x, y = _y;
        }
        Point operator -(const Point &b)const
        {
            return Point(x - b.x,y - b.y);
        }
        double operator *(const Point &b)const
        {
            return (double)x*b.y - (double)y*b.x;
        }
    };
   // long long calc(Point A) {return A.y+k*A.x+b;}
    Point st[maxn];
    long long k, b;
    int top, op;
    int main()
    {
        int n, m, tmp;
        cin >> n >> m;
        st[++top] = Point(1,0);
        while(m--)
        {
            scanf("%d", &op);
            if(op == 1)
            {
                st[top=1] = Point(1,0);
                scanf("%d", &tmp);
                n += tmp, k = b = 0;
            }
            else if(op == 2)
            {
                Point tail = Point(n+1, -((n)*k+b));
                scanf("%d", &tmp);
                n += tmp;
                while(top>1 && (tail-st[top-1])*(st[top]-st[top-1])>=0) top--;
                st[++top] = tail;
            }
            else
            {
                scanf("%d", &tmp);
                b += tmp;
                scanf("%d", &tmp);
                k += tmp;
            }
            while(top>1 && st[top].y+st[top].x*k - st[top-1].y-st[top-1].x*k >= 0) top--;
            printf("%lld %lld\n",st[top].x, st[top].y+(st[top].x-1)*k+b);
             //  cout << st[top].x << ' ' << st[top].y+(st[top].x-1)*k+b << "!!!"<<endl;
        }
        return 0;
    }


#include<bits/stdc++.h>
using namespace std;
#define reg register
typedef long long ll;
#define eps 1e-6
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++)
static char buf[100000],*p1=buf,*p2=buf;
inline int read(void){
	reg char ch=getchar();
	reg int res=0;
	while(ch<'0'||'9'<ch)ch=getchar();
	while('0'<=ch&&ch<='9')res=10*res+ch-'0',ch=getchar();
	return res;
}

const int MAXM=3e5+5;

struct Node{
	ll x,y;
	inline Node(reg ll x=0,reg ll y=0):x(x),y(y){
		return;
	}
	inline Node operator-(const Node& a)const{
		return Node(x-a.x,y-a.y);
	}
	inline double operator*(const Node& a){
		return 1.0*x*a.y-1.0*y*a.x;
	}
};

ll K,B;

inline ll Calc(const Node& a){
	return a.y+K*a.x+B;
}

ll n;
int m;
Node S[MAXM];

int main(void){
	n=read(),m=read();
	reg int top=0;
	S[top=1]=Node(0,0);
	while(m--){
		static int type;
		static ll k,b,s;
		type=read();
		switch(type){
			case 1:{
				k=read();
				n+=k;
				S[top=1]=Node(0,0);
				K=B=0;
				break;
			}
			case 2:{
				k=read();
				Node t(n,-(n*K+B));
				n+=k;
				while(top>1&&(t-S[top-1])*(S[top]-S[top-1])>-eps)
					--top;
				S[++top]=t;
				break;
			}
			case 3:{
				b=read(),s=read();
				B+=b,K+=s;
				break;
			}
		}
		while(top>1&&Calc(S[top])>=Calc(S[top-1]))
			--top;
		printf("%lld %lld\n",S[top].x+1,Calc(S[top]));
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N=3e5+2;
typedef long long ll;
ll st[N],zb[N],k,b,cd,qd;
int tp,m,c,x;
inline void read(int &x)
{
	c=getchar();
	while ((c<48)||(c>57)) c=getchar();
	x=c^48;c=getchar();
	while ((c>=48)&&(c<=57))
	{
		x=x*10+(c^48);
		c=getchar();
	}
}
int main()
{
	read(x);cd=x;tp=1;read(m);zb[1]=1;
	for (;m--;printf("%lld %lld\n",zb[tp],st[tp]+zb[tp]*k+b))
	{
		read(x);
		if(x==1)
		{
			read(x);cd+=x;
			tp=1;k=b=0;
			continue;
		}
		if (x==2)
		{
			read(x);
			//if (st[tp]==-k*zb[tp]-b) {cd+=x;continue;}
			zb[++tp]=cd+1;
			st[tp]=-k*zb[tp]-b;
			cd+=x;
		while ((tp>1)&&((st[tp-1]-st[tp])/(zb[tp]-zb[tp-1])<=k)) --tp;
			continue;
		}
		read(x);b+=x;read(x);k+=x;b-=x;
		while ((tp>1)&&((st[tp-1]-st[tp])/(zb[tp]-zb[tp-1])<=k)) --tp;
	}
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define N 100005
#define mk make_pair
int n,m,len,top;
pair<int,int> ans,seq[N];
inline void ri(int &x)
{
	x=0;
	bool sg=0;
	char c=getchar();
	while (!isdigit(c)) sg=(c=='-'),c=getchar();
	while (isdigit(c)) x=x*10+c-'0',c=getchar();
	if (sg) x=-x;
}
pair<int,int> tmp[N];
signed main()
{
// 	freopen("dance.in","r",stdin);
// 	freopen("dance.out","w",stdout);
	ri(n),ri(m);
	ans=mk(0,0);
	len=n-1;
	seq[++top]=ans;
	for (register int i=1; i<=m; i++) {
		int op,x,y;
		ri(op);
		if (op==1) {
			ri(x),top=1;
			seq[top]=ans=mk(0,0);
			len+=x;
		} else if (op==2) {
			ri(x);
			seq[++top]=mk(len+1,0);
			int ll=0;
			ans.second=666666666;
			for (register int i=1; i<=top; i++)
				if (ans.second>seq[i].second) {
					ans=seq[i];
					tmp[++ll]=ans;
				}
			for (register int i=1; i<=ll; i++)
				seq[i]=tmp[i];
			top=ll;
			len+=x;
		} else {
			ri(x),ri(y);
			for (register int i=1; i<=top; i++)
				seq[i].second+=x+y*seq[i].first;
			int ll=0;
			ans.second=666666666;
			for (register int i=1; i<=top; i++)
				if (ans.second>seq[i].second) {
					ans=seq[i];
					tmp[++ll]=ans;
				}
			for (register int i=1; i<=ll; i++)
				seq[i]=tmp[i];
			top=ll;
		}
		printf("%lld %lld\n",ans.first+1,ans.second);
	}
	return 0;
}


    #include<bits/stdc++.h>

    using namespace std;
    const double eps = 1e-9;
    const int maxn = 1023000;
    struct Point
    {
        long long x, y;
        Point(){}
        Point(long long _x, long long _y)
        {
            x = _x, y = _y;
        }
        Point operator -(const Point &b)const
        {
            return Point(x - b.x,y - b.y);
        }
        double operator *(const Point &b)const
        {
            return (double)x*b.y - (double)y*b.x;
        }
    };
   // long long calc(Point A) {return A.y+k*A.x+b;}
    Point st[maxn];
    long long k, b;
    int top, op;
    int main()
    {
        int n, m, tmp;
        cin >> n >> m;
        st[++top] = Point(0,0);
        while(m--)
        {
            scanf("%d", &op);
            if(op == 1)
            {
                st[top=1] = Point(0,0);
                scanf("%d", &tmp);
                n += tmp, k = b = 0;
            }
            else if(op == 2)
            {
                Point tail = Point(n, -(n*k+b));
                scanf("%d", &tmp);
                n += tmp;
                while(top>1 && (tail-st[top-1])*(st[top]-st[top-1])>=0) top--;
                st[++top] = tail;
            }
            else
            {
                scanf("%d", &tmp);
                b += tmp;
                scanf("%d", &tmp);
                k += tmp;
            }
            while(top>1 && st[top].y+st[top].x*k - st[top-1].y-st[top-1].x*k >= 0) top--;
            printf("%lld %lld\n",st[top].x+1, st[top].y+(st[top].x)*k+b);
             //  cout << st[top].x << ' ' << st[top].y+(st[top].x-1)*k+b << "!!!"<<endl;
        }
        return 0;
    }


#include<bits/stdc++.h>
using namespace std;

#define int long long

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf long double

#define pii pair<int,int >
#define vec vector<int >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;

int n,q,top,sum[maxn],suma,sumb;
struct P {
    int x,y;
    P operator - (const P &a) const {return (P){x-a.x,y-a.y};}
    lf operator * (const P &a) const {return (lf)x*a.y-(lf)y*a.x;}
}sta[maxn];

signed main() {
    read(n),read(q);n--;
    sta[++top]=(P){0,0};
    for(int i=1;i<=q;i++) {
        int op,a;read(op),read(a);
        if(op==1) {
            suma=sumb=0;top=0;n+=a;
            sta[++top]=(P){0,0};
        } else if(op==2) {
            int x=n+1,y=-suma*(n+1)-sumb;n+=a;
            while(top>1&&(sta[top-1]-sta[top])*((P){x,y}-sta[top])>1.00) top--;
            sta[++top]=(P){x,y};
        } else {
            int b;read(b);suma+=b,sumb+=a;
        }
        while(top>1&&(lf)sta[top].x*suma+sta[top].y>=(lf)sta[top-1].x*suma+sta[top-1].y) top--;
        printf("%lld %lld\n",sta[top].x+1,sta[top].y+sta[top].x*suma+sumb);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll maxn = 300010;
const double eps = 1e-10;

ll n,m,cnt;
ll sumk,sumb,a[maxn],num,s1[maxn],s2[maxn];

ll getval(ll x)
{
    return (sumk - s1[x]) * (a[x] - 1) + sumb - s2[x];
}

void tiaozheng()
{
    while (cnt > 1)
    {
        ll temp1 = getval(cnt),temp2 = getval(cnt - 1);
        if (temp2 <= temp1)
            --cnt;
        else
            break;
    }
}

void tiaozheng2()
{
    while (cnt > 1)
    {
        ll temp1 = getval(cnt),temp2 = getval(cnt - 1);
        if ((long double)temp1 * (long double)(a[cnt] - a[cnt - 1]) + eps >= (long double)temp2 * (long double)(num + 1 - a[cnt]))
            --cnt;
        else
            break;
    }
}

int main()
{
    scanf("%lld%lld",&n,&m);
    num = n;
    a[cnt = 1] = 1;
    while (m--)
    {
        ll opt,x,y;
        scanf("%lld",&opt);
        if (opt == 1)
        {
            scanf("%lld",&x);
            num += x;
            sumk = sumb = 0;
            cnt = 0;
            ++cnt;
            a[cnt] = 1;
            s1[cnt] = s2[cnt] = 0;
        }
        if (opt == 2)
        {
            scanf("%lld",&x);
            tiaozheng2();
            ++cnt;
            a[cnt] = num + 1;
            s1[cnt] = sumk;
            s2[cnt] = sumb;
            num += x;
            tiaozheng();
        }
        if (opt == 3)
        {
            scanf("%lld%lld",&x,&y);
            sumk += y;
            sumb += x;
            tiaozheng();
        }
        printf("%lld %lld\n",a[cnt],(a[cnt] - 1) * (sumk - s1[cnt]) + sumb - s2[cnt]);
    }

    return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N=3e5+2;
typedef long long ll;
ll st[N],zb[N],k,b,cd,qd;
int tp,m,c,x;
inline void read(int &x)
{
	c=getchar();
	while ((c<48)||(c>57)) c=getchar();
	x=c^48;c=getchar();
	while ((c>=48)&&(c<=57))
	{
		x=x*10+(c^48);
		c=getchar();
	}
}
int main()
{
	read(x);cd=x;tp=1;read(m);zb[1]=1;
	for (;m--;printf("%lld %lld\n",zb[tp],st[tp]+zb[tp]*k+b))
	{
		read(x);
		if(x==1)
		{
			read(x);cd+=x;
			tp=1;k=b=0;
			continue;
		}
		if (x==2)
		{
			read(x);
			//if (st[tp]==-k*zb[tp]-b) {cd+=x;continue;}
			zb[++tp]=cd+1;
			st[tp]=-k*zb[tp]-b;
			cd+=x;
		while ((tp>1)&&((st[tp-1]-st[tp])<=(zb[tp]-zb[tp-1])*k)) --tp;
			continue;
		}
		read(x);b+=x;read(x);k+=x;b-=x;
		while ((tp>1)&&((st[tp-1]-st[tp])<=(zb[tp]-zb[tp-1])*k)) --tp;
	}
}


#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 4e5 + 500, inf = 1e9;
int n, m, top, tail;
struct Node { int pos; long long x; } a[N], mn;
signed main() {
	scanf("%lld%lld", &n, &m);
	a[top = 1] = (Node) {1, 0}; tail = n;
	for (int i = 1, opt, x, y; i <= m; i++) {
		scanf("%lld", &opt);
		if (opt == 1) {
			scanf("%lld", &x);
			a[top = 1] = (Node) {1, 0};
			puts("1 0"); tail += x;
		}
		else if (opt == 2) {
			scanf("%lld", &x);
			a[++top] = (Node) {tail + 1, 0}; tail += x;
			mn = (Node){0, inf}; for (int i = 1; i <= top; i++) if (mn.x > a[i].x) mn = a[i];
			printf("%lld %lld\n", mn.pos, mn.x);
		} else {
			scanf("%lld%lld", &x, &y); mn = (Node){0, inf};
			for (int i = 1; i <= top; i++) {
				a[i].x += x + y * (a[i].pos - 1);
				if (mn.x > a[i].x) mn = a[i];
			}
			printf("%lld %lld\n", mn.pos, mn.x);
		}
	}
	return 0;
}


#include <iostream>

const int N = 200000 + 7;

int q;
long long L, R;
long long B, D;
long long p[N], d[N];
int k;

long long f(int x)
{
	return d[x] + (p[x] - L) * D + B;
};

int main() {
	scanf("%lld%d", &R, &q);
	L = 1;
	p[k = 1] = 1;
	d[1] = 0;
	for (long long t, x; q; --q) {
		scanf("%lld%lld", &t, &x);
		if (t == 1)
		{
			L -= x;
			B = D = 0;
			p[k = 1] = L;
			d[1] = 0;
		}
		if (t == 2)
		{
			R += x;
			p[++k] = R - x + 1;
			d[k] = -(p[k] - L) * D - B;
		}
		if (t == 3)
		{
			B += x;
			scanf("%lld", &x);
			D += x;
			while (k > 1 && f(k - 1) <= f(k)) --k;
		}
		printf("%lld %lld\n", p[k] - L + 1, f(k));
	}
	return 0;
}


//https://codeforces.com/contest/1137/problem/E
#include<iostream>
#include<cstdio>
#include<cstring>
#define maxn 300000
#include<algorithm>
using namespace std;
typedef long long ll;
typedef long double db;
inline void qread(int& x) {
	x=0;
	int sign=1;
	char c=getchar();
	while(c<'0'||c>'9') {
		if(c=='-') sign=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9') {
		x=x*10+c-'0';
		c=getchar();
	}
	x=x*sign;
}
inline void qprint(ll x) {
	if(x<0) {
		putchar('-');
		qprint(-x);
	} else if(x==0) {
		putchar('0');
		return;
	} else {
		if(x>=10) qprint(x/10);
		putchar('0'+x%10);
	}
}

struct point {
	ll x;
	ll y;
	point() {

	}
	point(ll _x,ll _y) {
		x=_x;
		y=_y;
	}
};
db slope(point p,point q) {
	return (db)(p.y-q.y)/(p.x-q.x);
}
int top;
point st[maxn+5];

int n,m;
ll sums[maxn+5],sumb[maxn+5];
inline ll calc(point p,int i) {
	return (p.x-1)*sums[i]+p.y+sumb[i];
}

int main() {
	int cmd,k,b,s;
	qread(n);
	qread(m);
	top=0;
	st[++top]=point(1,0);
	for(int i=1; i<=m; i++) {
		qread(cmd);
		sums[i]=sums[i-1];
		sumb[i]=sumb[i-1];
		if(cmd==1) {
			qread(k);
			top=0;
			st[++top]=point(1,0);
			sums[i]=0;
			sumb[i]=0;
			n+=k;
		} else if(cmd==2) {
			qread(k);
			point x=point(n+1,-calc(point(n+1,0),i));
			while(top>1&&slope(st[top],st[top-1])>=slope(x,st[top-1])) top--;
			st[++top]=x;
			n+=k;
		} else {
			qread(b);
			qread(s);
			sums[i]+=s;
			sumb[i]+=b;
		}
		while(top>1&&calc(st[top],i)>=calc(st[top-1],i)) top--;
		printf("%I64d %I64d\n",st[top].x,calc(st[top],i));
	}
}


#include<iostream>
#include<cstdio>
#include<cstring>
#define maxn 100000
#include<algorithm>
using namespace std;
typedef long long ll;
typedef long double db;
inline void qread(int& x) {
	x=0;
	int sign=1;
	char c=getchar();
	while(c<'0'||c>'9') {
		if(c=='-') sign=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9') {
		x=x*10+c-'0';
		c=getchar();
	}
	x=x*sign;
}
inline void qprint(ll x) {
	if(x<0) {
		putchar('-');
		qprint(-x);
	} else if(x==0) {
		putchar('0');
		return;
	} else {
		if(x>=10) qprint(x/10);
		putchar('0'+x%10);
	}
}

struct point {
	ll x;
	ll y;
	point() {

	}
	point(ll _x,ll _y) {
		x=_x;
		y=_y;
	}
};
db slope(point p,point q) {
	return (db)(p.y-q.y)/(p.x-q.x);
}
int top;
point st[maxn+5];

int n,m;
ll sums[maxn+5],sumb[maxn+5];
inline ll calc(point p,int i) {
	return (p.x-1)*sums[i]+p.y+sumb[i];
}

int main() {
	int cmd,k,b,s;
	qread(n);
	qread(m);
	top=0;
	st[++top]=point(1,0);
	for(int i=1; i<=m; i++) {
		qread(cmd);
		sums[i]=sums[i-1];
		sumb[i]=sumb[i-1];
		if(cmd==1) {
			qread(k);
			top=0;
			st[++top]=point(1,0);
			sums[i]=0;
			sumb[i]=0;
			n+=k;
		} else if(cmd==2) {
			qread(k);
			point x=point(n+1,-calc(point(n+1,0),i));
			while(top>1&&slope(st[top],st[top-1])>=slope(x,st[top-1])) top--;
			st[++top]=x;
			n+=k;
		} else {
			qread(b);
			qread(s);
			sums[i]+=s;
			sumb[i]+=b;
		}
		while(top>1&&calc(st[top],i)>=calc(st[top-1],i)) top--;
		printf("%I64d %I64d\n",st[top].x,calc(st[top],i));
	}
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=100005;
pair <ll,ll> s[N];
int top=0;ll add=0,mul=0;
void pop(){
	while (top>1)
		if (s[top].second*mul+s[top].first>=s[top-1].second*mul+s[top-1].first) --top;
		else break;
}
double cross(pair<ll,ll> a,pair<ll,ll> b,pair<ll,ll> c){
	double vala=add+a.second*mul+a.first,valb=add+b.second*mul+b.first,valc=add+c.second*mul+c.first;
	return (double)(valc-valb)*(b.second-a.second)-(double)(valb-vala)*(c.second-b.second);
}
void insert(pair<ll,ll> val){
	while (top>1&&cross(s[top-1],s[top],val)<1e-9) --top;
	s[++top]=val;
}
int main (){
	ll n;int m;scanf ("%lld%d",&n,&m);
	s[top=1]=make_pair(0,0);
	while (m--){
		int opt;scanf ("%d",&opt);
		if (opt==1){
			int k;scanf ("%d",&k);
			add=0,mul=0;n+=k;
			s[top=1]=make_pair(0,0);
		}else if (opt==2){
			int k;scanf ("%d",&k);
			insert(make_pair(-add-mul*n,n));
			n+=k;
		}else{
			int b,s;scanf ("%d%d",&b,&s);
			add+=b,mul+=s;pop();
		}
		printf ("%lld %lld\n",s[top].second+1,add+mul*s[top].second+s[top].first);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=300005;
pair <ll,ll> s[N];
int top=0;ll add=0,mul=0;
void pop(){
	while (top>1)
		if (s[top].second*mul+s[top].first>=s[top-1].second*mul+s[top-1].first) --top;
		else break;
}
double cross(pair<ll,ll> a,pair<ll,ll> b,pair<ll,ll> c){
	double vala=add+a.second*mul+a.first,valb=add+b.second*mul+b.first,valc=add+c.second*mul+c.first;
	return (double)(valc-valb)*(b.second-a.second)-(double)(valb-vala)*(c.second-b.second);
}
void insert(pair<ll,ll> val){
	if (s[top].second*mul+s[top].first+add==0) return;
	while (top>1&&cross(s[top-1],s[top],val)<1e-9) --top;
	s[++top]=val;
}
int main (){
	ll n;int m;scanf ("%lld%d",&n,&m);
	s[top=1]=make_pair(0,0);
	while (m--){
		int opt;scanf ("%d",&opt);
		if (opt==1){
			int k;scanf ("%d",&k);
			add=0,mul=0;n+=k;
			s[top=1]=make_pair(0,0);
		}else if (opt==2){
			int k;scanf ("%d",&k);
			insert(make_pair(-add-mul*n,n));
			n+=k;
		}else{
			int b,s;scanf ("%d%d",&b,&s);
			add+=b,mul+=s;pop();
		}
		printf ("%lld %lld\n",s[top].second+1,add+mul*s[top].second+s[top].first);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=300005;
pair <ll,ll> s[N];
int top=0;ll add=0,mul=0;
void pop(){
	while (top>1)
		if (s[top].second*mul+s[top].first>=s[top-1].second*mul+s[top-1].first) --top;
		else break;
}
double cross(pair<ll,ll> a,pair<ll,ll> b,pair<ll,ll> c){
	double vala=add+a.second*mul+a.first,valb=add+b.second*mul+b.first,valc=add+c.second*mul+c.first;
	return (double)(valc-valb)*(b.second-a.second)-(double)(valb-vala)*(c.second-b.second);
}
void insert(pair<ll,ll> val){
	while (top>1&&cross(s[top-1],s[top],val)<1e-9) --top;
	s[++top]=val;
}
int main (){
	ll n;int m;scanf ("%lld%d",&n,&m);
	s[top=1]=make_pair(0,0);
	while (m--){
		int opt;scanf ("%d",&opt);
		if (opt==1){
			int k;scanf ("%d",&k);
			add=0,mul=0;n+=k;
			s[top=1]=make_pair(0,0);
		}else if (opt==2){
			int k;scanf ("%d",&k);
			insert(make_pair(-add-mul*n,n));
			n+=k;
		}else{
			int b,s;scanf ("%d%d",&b,&s);
			add+=b,mul+=s;pop();
		}
		printf ("%lld %lld\n",s[top].second+1,add+mul*s[top].second+s[top].first);
	}
	return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>

template<typename T>
void read(T& a) {
	static char c;
	static bool b;
	a = 0, b = false;
	for(c = getchar(); !isdigit(c) && c != '-'; c = getchar());
	if(c == '-') c = getchar(), b = true;
	for(; isdigit(c); c = getchar()) a = a * 10 + (c - '0');
	if(b) a = -a;
}

using namespace std;

typedef long long lint;

const int MAXN = 1e5 + 10;
const int MOD = 998244353;
const int INF = 0x3f3f3f3f;

struct Segment {
	int start, val;
};

int n, len, cnt;
Segment ans[MAXN], tmp[MAXN], curans;

void query()
{
	curans.val = INF;
	int tcnt = 0;
	for(int i=1; i<=cnt; ++i)
		if(curans.val > ans[i].val)
			curans = ans[i], tmp[++tcnt] = ans[i];
	for(int i=1; i<=tcnt; ++i)
		ans[i] = tmp[i];
	cnt = tcnt;
}

//#define Judge
int main()
{
#ifdef Judge
	freopen("dance.in", "r", stdin);
	freopen("dance.out", "w", stdout);
#endif
	int m;
	read(n), read(m);
	len = n - 1;
	cnt = 0;
	curans = (Segment) { 0, 0 };
	ans[++cnt] = curans;
	for(int opt, x, y; m; --m) {
		read(opt), read(x);
		if(opt == 3) {
			read(y);
			for(int i=1; i<=cnt; ++i)
				ans[i].val += x + y * ans[i].start;
		} else if(opt == 2) {
			ans[++cnt] = (Segment) { len+1, 0 };
			len += x;
		} else {
			curans = ans[cnt = 1] = (Segment) { 0, 0 };
			len += x;
		}
		query();
		printf("%d %d\n", curans.start+1, curans.val);
	}
	return 0;
}

/*
1 8
1 1
3 1 1
3 1 1
2 1
2 1
3 1 1
2 1
3 1 5
*/


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#define INF 0x3f3f3f3f3f3f3f3f
#define MAXN 200010
using namespace std;

#define int long long

int readin()
{
	char c=getchar();
	int read_ans=0;
	while(c<'0'||c>'9')
		c=getchar();
	while(c>='0'&&c<='9')
	{
		read_ans=read_ans*10+c-'0';
		c=getchar();
	}
	return read_ans;
}

int n,m;

// priority_queue
int hd=0;
int tl=0;
int nxt[MAXN];
int num[MAXN];
int len[MAXN];
int pos[MAXN];
int tail=0;

void addf(int k)
{
	nxt[++tail]=hd;
	num[tail]=0;
	pos[tail]=1;
	len[tail]=k;
	hd=tail;
}
void adde(int k)
{
	nxt[tl]=++tail;
	num[tail]=0;
	pos[tail]=pos[tl]+1;
	len[tail]=k;
	tl=tail;
}

signed main()
{
	// freopen("dance.in","r",stdin);
	// freopen("dance.out","w",stdout);
	n=readin();
	m=readin();
	addf(n);
	int op,now_u,now_v;
	int minnum=0;
	int minpos=1;
	//int d1=0,d2=0;
	int tot=n;
	for (register int i=1;i<=m;++i)
	{
		op=readin();
		if (op==1)
		{
			now_u=readin();
			puts("1 0");
			tot+=now_u;
			minnum=0;
			minpos=1;
			addf(now_u);
		}
		if (op==2)
		{
			now_u=readin();
			if (minnum==0)
				printf("%lld 0\n",minpos);
			else
			{
				printf("%lld 0\n",tot+1);
				minnum=0;
				minpos=tot+1;
			}
			tot+=now_u;
			adde(now_u);
		}
		if (op==3)
		{
			now_u=readin();
			now_v=readin();
			// d1+=now_u;
			// d2+=
			minnum=INF;
			minpos=0;
			for (register int i=hd;i;i=nxt[i])
			{
				num[i]+=now_u;
				num[i]+=now_v*(pos[i]-1);
				if (num[i]<minnum)
				{
					minnum=num[i];
					minpos=pos[i];
				}
			}
			printf("%lld %lld\n",minpos,minnum);
		}
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N=3e5+2;
typedef long long ll;
ll st[N],zb[N],k,b,cd,qd;
int tp,m,c,x;
inline void read(int &x)
{
	c=getchar();
	while ((c<48)||(c>57)) c=getchar();
	x=c^48;c=getchar();
	while ((c>=48)&&(c<=57))
	{
		x=x*10+(c^48);
		c=getchar();
	}
}
int main()
{
	read(x);cd=x;tp=1;read(m);zb[1]=1;
	for (;m--;printf("%lld %lld\n",zb[tp],st[tp]+zb[tp]*k+b))
	{
		read(x);
		if(x==1)
		{
			read(x);cd+=x;
			tp=1;k=b=0;
			continue;
		}
		if (x==2)
		{
			read(x);
			if (st[tp]==-k*zb[tp]-b) {cd+=x;continue;}
			zb[++tp]=cd+1;
			st[tp]=-k*zb[tp]-b;
			cd+=x;
			continue;
		}
		read(x);b+=x;read(x);k+=x;b-=x;
		while ((tp>1)&&((st[tp-1]-st[tp])/(zb[tp]-zb[tp-1])<=k)) --tp;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define reg register
typedef long long ll;
#define eps 1e-6
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++)
static char buf[100000],*p1=buf,*p2=buf;
inline int read(void){
	reg char ch=getchar();
	reg int res=0;
	while(ch<'0'||'9'<ch)ch=getchar();
	while('0'<=ch&&ch<='9')res=10*res+ch-'0',ch=getchar();
	return res;
}

const int MAXM=3e5+5;

struct Node{
	ll x,y;
	inline Node(reg ll x=0,reg ll y=0):x(x),y(y){
		return;
	}
	inline Node operator-(const Node& a)const{
		return Node(x-a.x,y-a.y);
	}
	inline double operator*(const Node& a){
		return 1.0*x*a.y-1.0*y*a.x;
	}
};

ll K,B;

inline ll Calc(const Node& a){
	return a.y+K*a.x+B;
}

ll n;
int m;
Node S[MAXM];

int main(void){
	n=read(),m=read();
	reg int top=0;
	S[top=1]=Node(0,0);
	while(m--){
		static int type;
		static ll k,b,s;
		type=read();
		switch(type){
			case 1:{
				k=read();
				n+=k;
				S[top=1]=Node(0,0);
				K=B=0;
				break;
			}
			case 2:{
				k=read();
				Node t(n,-(n*K+B));
				n+=k;
				while(top>1&&(t-S[top-1])*(S[top]-S[top-1])>-eps)
					--top;
				S[++top]=t;
				break;
			}
			case 3:{
				b=read(),s=read();
				B+=b,K+=s;
				break;
			}
		}
		while(top>1&&Calc(S[top])>=Calc(S[top-1]))
			--top;
		printf("%lld %lld\n",S[top].x+1,Calc(S[top]));
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N=3e5+2;
typedef long long ll;
ll st[N],zb[N],k,b,cd,qd;
int tp,m,c,x;
inline void read(int &x)
{
	c=getchar();
	while ((c<48)||(c>57)) c=getchar();
	x=c^48;c=getchar();
	while ((c>=48)&&(c<=57))
	{
		x=x*10+(c^48);
		c=getchar();
	}
}
int main()
{
	read(x);if (x!=1) while (1);cd=x;tp=1;read(m);zb[1]=1;if (m!=8)while (1);
	for (;m--;printf("%lld %lld\n",zb[tp],st[tp]+zb[tp]*k+b))
	{
		read(x);
		if(x==1)
		{
			read(x);cd+=x;
			tp=1;k=b=0;
			continue;
		}
		if (x==2)
		{
			read(x);
			zb[++tp]=cd+1;
			st[tp]=-k*zb[tp]-b;
			cd+=x;
			continue;
		}
		read(x);b+=x;read(x);k+=x;b-=x;
		while ((tp>1)&&((st[tp-1]-st[tp])/(zb[tp]-zb[tp-1])<=k)) --tp;
	}
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll maxn = 300010;

ll n,m,cnt;
ll sumk,sumb,a[maxn],num,s1[maxn],s2[maxn];

ll getval(ll x)
{
    return (sumk - s1[x]) * (a[x] - 1) + sumb - s2[x];
}

void tiaozheng()
{
    while (cnt > 1)
    {
        ll temp1 = getval(cnt),temp2 = getval(cnt - 1);
        if (temp2 <= temp1)
            --cnt;
        else
            break;
    }
}

void tiaozheng2()
{
    while (cnt > 1)
    {
        ll temp1 = getval(cnt),temp2 = getval(cnt - 1);
        if (temp1 * (a[cnt] - a[cnt - 1]) >= temp2 * (num + 1 - a[cnt]))
            --cnt;
        else
            break;
    }
}

int main()
{
    scanf("%lld%lld",&n,&m);
    num = n;
    a[cnt = 1] = 1;
    while (m--)
    {
        ll opt,x,y;
        scanf("%lld",&opt);
        if (opt == 1)
        {
            scanf("%lld",&x);
            num += x;
            sumk = sumb = 0;
            cnt = 0;
            ++cnt;
            a[cnt] = 1;
            s1[cnt] = s2[cnt] = 0;
        }
        if (opt == 2)
        {
            scanf("%lld",&x);
            tiaozheng2();
            ++cnt;
            a[cnt] = num + 1;
            s1[cnt] = sumk;
            s2[cnt] = sumb;
            num += x;
            tiaozheng();
        }
        if (opt == 3)
        {
            scanf("%lld%lld",&x,&y);
            sumk += y;
            sumb += x;
            tiaozheng();
        }
        printf("%lld %lld\n",a[cnt],(a[cnt] - 1) * (sumk - s1[cnt]) + sumb - s2[cnt]);
    }

    return 0;
}


#include <iostream>

const int N = 200000 + 7;

int q;
long long L, R;
long long B, D;
long long p[N], d[N];
int k;

long long f(int x)
{
	return d[x] + (p[x] - L) * D + B;
};

int main() {
	scanf("%lld%d", &R, &q);
	L = 1;
	p[k = 1] = 1;
	d[1] = 0;
	for (long long t, x; q; --q) {
		scanf("%lld%lld", &t, &x);
		if (t == 1)
		{
			L -= x;
			B = D = 0;
			p[k = 1] = L;
			d[1] = 0;
		}
		if (t == 2)
		{
			R += x;
			p[++k] = R - x + 1;
			d[k] = -(p[k] - L) * D - B;
		}
		if (t == 3)
		{
			B += x;
			scanf("%lld", &x);
			D += x;
		}
		while (k > 1 && f(k - 1) <= f(k)) --k;
		printf("%lld %lld\n", p[k] - L + 1, f(k));
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N=3e5+2;
typedef long long ll;
ll st[N],zb[N],k,b,cd,qd;
int tp,m,c,x;
inline void read(int &x)
{
	c=getchar();
	while ((c<48)||(c>57)) c=getchar();
	x=c^48;c=getchar();
	while ((c>=48)&&(c<=57))
	{
		x=x*10+(c^48);
		c=getchar();
	}
}
int main()
{
	read(x);cd=x;tp=1;read(m);zb[1]=1;
	for (;m--;printf("%lld %lld\n",zb[tp],st[tp]+zb[tp]*k+b))
	{
		read(x);
		if(x==1)
		{
			read(x);cd+=x;
			tp=1;k=b=0;
			continue;
		}
		if (x==2)
		{
			read(x);
			if (st[tp]==-k*zb[tp]-b) continue;
			zb[++tp]=cd+1;
			st[tp]=-k*zb[tp]-b;
			cd+=x;
			continue;
		}
		read(x);b+=x;read(x);k+=x;b-=x;
		while ((tp>1)&&((st[tp-1]-st[tp])/(zb[tp]-zb[tp-1])<=k)) --tp;
	}
}


#include <bits/stdc++.h>
using namespace std;
#define ri register int
typedef long long ll;
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// input a letter
	template <class I>
	inline void get (I &x) {
		for (c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		x = c;
	}
	// input a string
	inline void read (char *s){
		for(c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		for(; c >= 'A' && c <= 'Z'; c = gc()) *++s = c;
		*++s = '\0';
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: gi;
using io :: get;
using io :: read;
using io :: putc;
using io :: print;
const int N=1e5+5;
struct node{
	ll x,y;
	node(ll _x=0,ll _y=0){
		x=_x;y=_y;
	}
	inline node operator -(const node &rhs)const{
		return node(x-rhs.x,y-rhs.y);
	}
}st[N];
inline bool cmp(node a,node b){
	return a.y*b.x<=a.x*b.y;
}
ll add_k,add_b;
inline ll calc(node a){
	return add_k*a.x+add_b+a.y;
}
int main(){
	ri n,m,opt,k,b,s,top;
	st[top=1]=node();
	gi(n);gi(m);
	while(m--){
		gi(opt);
		if(opt==1){
			gi(k);n+=k;
			st[top=1]=node();
			add_k=add_b=0;
		}
		else if(opt==2){
			gi(k);
			node now=node(n,-(add_k*n+add_b));
			n+=k;
			while(top>1&&cmp(now-st[top],st[top]-st[top-1]))
				--top;
			st[++top]=now;
		}
		else
			gi(b),gi(s),
			add_b+=b,
			add_k+=s;
		while(top>1&&calc(st[top])>=calc(st[top-1])) --top;
		print(st[top].x+1);putc(' ');print(calc(st[top]));putc('\n');
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N=3e5+2;
typedef long long ll;
typedef long double db;
ll st[N],zb[N],k,b,cd,y;
int tp,m,c,x;
inline void read(int &x)
{
	c=getchar();
	while ((c<48)||(c>57)) c=getchar();
	x=c^48;c=getchar();
	while ((c>=48)&&(c<=57))
	{
		x=x*10+(c^48);
		c=getchar();
	}
}
int main()
{
	read(x);cd=x;tp=1;read(m);zb[1]=1;
	for (;m--;printf("%lld %lld\n",zb[tp],st[tp]+zb[tp]*k+b))
	{
		read(x);
		if(x==1)
		{
			read(x);cd+=x;
			tp=1;k=b=0;
			continue;
		}
		if (x==2)
		{
			read(x);y=-k*(cd+1)-b;
			if (st[tp]==-k*zb[tp]-b) {cd+=x;continue;}
			while ((tp>1)&&((db)(st[tp]-y)*(zb[tp]-zb[tp-1])>=(db)(st[tp-1]-st[tp])*(cd+1-zb[tp]))) --tp;
			zb[++tp]=cd+1;
			st[tp]=y;
			cd+=x;
			continue;
		}
		read(x);b+=x;read(x);k+=x;b-=x;
		while ((tp>1)&&((st[tp-1]-st[tp])<=(db)(zb[tp]-zb[tp-1])*k)) --tp;
	}
}


    #include<bits/stdc++.h>

    using namespace std;
    const double eps = 1e-9;
    const int maxn = 1023000;
    struct Point
    {
        long long x, y;
        Point(){}
        Point(long long _x, long long _y)
        {
            x = _x, y = _y;
        }
        Point operator -(const Point &b)const
        {
            return Point(x - b.x,y - b.y);
        }
        double operator *(const Point &b)const
        {
            return (double)x*b.y - (double)y*b.x;
        }
    };
   // long long calc(Point A) {return A.y+k*A.x+b;}
    Point st[maxn];
    long long k, b;
    int top, op;
    int main()
    {
        int n, m, tmp;
        scanf("%d%d",&n, &m);
        st[++top] = Point(0,0);
        while(m--)
        {
            scanf("%d", &op);
            if(op == 1)
            {
                st[top=1] = Point(1,0);
                scanf("%d", &tmp);
                n += tmp, k = b = 0;
            }
            else if(op == 2)
            {
                Point tail = Point(n, -(n*k+b));
                scanf("%d", &tmp);
                n += tmp;
                while(top>1 && (tail-st[top-1])*(st[top]-st[top-1])>=0) top--;
                st[++top] = tail;
            }
            else
            {
                scanf("%d", &tmp);
                b += tmp;
                scanf("%d", &tmp);
                k += tmp;
            }
            while(top>1 && st[top].y+st[top].x*k - st[top-1].y-st[top-1].x*k >= 0) top--;
            printf("%lld %lld\n",st[top].x+1, st[top].y+(st[top].x)*k+b);
             //  cout << st[top].x << ' ' << st[top].y+(st[top].x-1)*k+b << "!!!"<<endl;
        }
        return 0;
    }


#include <iostream>
#include <cstdio>

#include <array>
#include <deque>

using namespace std;

using ll = long long;
#define tl(X) static_cast<ll>(X)

const ll INF = 1e18;
ll divf(ll n, ll d)
{
  if(d < 0) n*=-1, d*=-1;
  if(n < 0) return -((-n+d)/d);
  return (n-1)/d;
}
using i2 = array<ll, 2>;
struct L
{
public:
  ll i;
  ll m, b;
  mutable ll r;
  L(ll i, ll m, ll b, ll r = -1LL) : i(i), m(m), b(b), r(r) {}
  ll operator * (const L& o) const
  {
    if(o.m == m) return o.b < b ? -INF : INF;
    return divf(o.b - b, m - o.m);
  }
  i2 operator [] (const ll& x) {return {i, m * x + b};}
};
#define IT iterator
struct H : public deque<L>
{
public:
  bool upd(const L& l, IT n)
  {
    if(n == end()) return l.r = INF, 0;
    if((l.r = l**n) >= n->r) return 1;
    return 0;
  }
  void ins(const L& l)
  {
    for(;upd(l, begin());) pop_front();
    push_front(l);
  }
  i2 operator [] (const ll& x)
  {
    for(;x > front().r;pop_front());
    return front()[x];
  }
} T;

ll l;
ll b, s;
int B, S;
int M;
int k;

void q1(void)
{
  T.clear();
  scanf("%d", &k);
  l += k;
  b = s = 0LL;
  T.ins({0LL, 0LL, 0LL});
}
void q2(void)
{
  scanf("%d", &k);
  T.ins({l, l, -s*l-b});
  l += k;
}
void q3(void)
{
  scanf("%d%d", &B, &S);
  b += B, s += S;
}
void ans(const i2& x) {printf("%lld %lld\n", 1+x[0], x[1] + b);}
int main(void)
{
  scanf("%lld%d", &l, &M);
  for(int i = 0, q;i < M;i++)
  {
    scanf("%d", &q);
    if(q==1) q1();
    if(q==2) q2();
    if(q==3) q3();
    ans(T[s]);
  }
  return 0;
}


#include <iostream>
#include <cstdio>

#include <array>
#include <deque>

using namespace std;

using ll = long long;
#define tl(X) static_cast<ll>(X)

const ll INF = 1e18;
ll divf(ll n, ll d)
{
  if(d < 0) n*=-1, d*=-1;
  if(n < 0) return -((-n+d)/d);
  return (n-1)/d;
}
using i2 = array<ll, 2>;
struct L
{
public:
  ll i;
  ll m, b;
  mutable ll r;
  L(ll i, ll m, ll b, ll r = -1LL) : i(i), m(m), b(b), r(r) {}
  ll operator * (const L& o) const
  {
    if(o.m == m) return o.b < b ? -INF : INF;
    return divf(o.b - b, m - o.m);
  }
  i2 operator [] (const ll& x) {return {i, m * x + b};}
};
#define IT iterator
struct H : public deque<L>
{
public:
  bool upd(const L& l, IT n)
  {
    if(n == end()) return l.r = INF, 0;
    if((l.r = l**n) >= n->r) return 1;
    return 0;
  }
  void ins(const L& l)
  {
    for(;upd(l, begin());) pop_front();
    push_front(l);
  }
  i2 operator [] (const ll& x)
  {
    for(;x > front().r;pop_front());
    return front()[x];
  }
} T;

ll l;
ll b, s;
int B, S;
int M;
int k;

void q1(void)
{
  T.clear();
  scanf("%d", &k);
  l += k;
  b = s = 0LL;
  T.ins({0LL, 0LL, 0LL});
}
void q2(void)
{
  scanf("%d", &k);
  T.ins({l, l, -s*l-b});
  l += k;
}
void q3(void)
{
  scanf("%d%d", &B, &S);
  b += B, s += S;
}
void ans(const i2& x) {printf("%lld %lld\n", 1+x[0], x[1] + b);}
int main(void)
{
  scanf("%lld%d", &l, &M);
  T.ins({0LL, 0LL, 0LL});
  for(int i = 0, q;i < M;i++)
  {
    scanf("%d", &q);
    if(q==1) q1();
    if(q==2) q2();
    if(q==3) q3();
    ans(T[s]);
  }
  return 0;
}


#include <iostream>
#include <cstdio>

#include <array>
#include <deque>

using namespace std;

using ll = long long;
#define tl(X) static_cast<ll>(X)

const ll INF = 1e18;
ll divf(ll n, ll d)
{
  if(d < 0) n*=-1, d*=-1;
  if(n < 0) return -((-n+d-1)/d);
  return n/d;
}
using i2 = array<ll, 2>;
struct L
{
public:
  ll i;
  ll m, b;
  mutable ll r;
  L(ll i, ll m, ll b, ll r = -1LL) : i(i), m(m), b(b), r(r) {}
  ll operator * (const L& o) const
  {
    if(o.m == m) return o.b < b ? -INF : INF;
    return divf(o.b - b - 1, m - o.m);
  }
  i2 operator [] (const ll& x) {return {i, m * x + b};}
};
#define IT iterator
struct H : public deque<L>
{
public:
  bool upd(const L& l, IT n)
  {
    if(n == end()) return l.r = INF, 0;
    if((l.r = l**n) >= n->r) return 1;
    return 0;
  }
  void ins(const L& l)
  {
    for(;upd(l, begin());) pop_front();
    push_front(l);
  }
  i2 operator [] (const ll& x)
  {
    for(;x > front().r;pop_front());
    return front()[x];
  }
} T;

ll l;
ll b, s;
int B, S;
int M;
int k;

void q1(void)
{
  T.clear();
  scanf("%d", &k);
  l += k;
  b = s = 0LL;
  T.ins({0LL, 0LL, 0LL});
}
void q2(void)
{
  scanf("%d", &k);
  T.ins({l, l, -s*l-b});
  l += k;
}
void q3(void)
{
  scanf("%d%d", &B, &S);
  b += B, s += S;
}
void ans(const i2& x) {printf("%lld %lld\n", 1+x[0], x[1] + b);}
int main(void)
{
  scanf("%lld%d", &l, &M);
  T.ins({0LL, 0LL, 0LL});
  for(int i = 0, q;i < M;i++)
  {
    scanf("%d", &q);
    if(q==1) q1();
    if(q==2) q2();
    if(q==3) q3();
    ans(T[s]);
  }
  return 0;
}


#include<bits/stdc++.h>

#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3fLL
#define mod 1000000007
#define pb push_back
#define sq(x) ((x)*(x))
#define sz(a) ((int)a.size())
#define eps 1e-8
#define x first
#define y second
#define bpt(x) (__builtin_popcount(x))
#define bptl(x) (__builtin_popcountll(x))
#define bit(x, y) (((x)>>(y))&1)
#define bclz(x) (__builtin_clz(x))
#define bclzl(x) ((x) ? (__builtin_clzll(x)) : 0)
#define bctz(x) (__builtin_ctz(x))
#define bctzl(x) (__builtin_ctzll(x))
#define shit(a) (1 << (a))
#define rev(a) (power(a, mod-2, mod))
#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;
typedef long long INT;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
typedef vector<int> VI;

template<typename T, typename U> inline void smin(T &a, U b) {if(a>b) a=b;}
template<typename T, typename U> inline void smax(T &a, U b) {if(a<b) a=b;}

template<class T>inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}
template<class T>inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}
template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}
template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}
template <class T> inline void println(T x) {print(x); putchar('\n');}
template <class T> inline void printsp(T x) {print(x); putchar(' ');}
template <class T1, class T2> inline void print(T1 x1, T2 x2) {printsp(x1), println(x2);}
template <class T1, class T2, class T3> inline void print(T1 x1, T2 x2, T3 x3) {printsp(x1), printsp(x2), println(x3);}
template <class T1, class T2, class T3, class T4> inline void print(T1 x1, T2 x2, T3 x3, T4 x4) {printsp(x1), printsp(x2), printsp(x3), println(x4);}
template <class T> inline void eprint(T x) {cerr << "--------> " <<x << endl;}
template <class T1, class T2> inline void eprint(T1 x, T2 y) { cerr << "--------> " << x << ' ' << y << endl; }
template <class T1, class T2, class T3> inline void eprint(T1 x, T2 y, T3 z) { cerr << " -------> " << x << ' ' << y << ' ' << z << endl;}
template <class T1, class T2, class T3, class T4> inline void eprint(T1 x, T2 y, T3 z, T4 w) { cerr << " -------> " << x << ' ' << y << ' ' << z << ' ' << w << endl;}
int power(int a, int b, int m, int ans=1) {
	for(; b; b>>=1, a=1LL*a*a%m) if(b&1) ans=1LL*ans*a%m;
	return ans;
}

struct point{
	INT x, y;
	point(INT x=0, INT y=0) : x(x), y(y) {}
	point operator - (const point &u) const{
		return point(x-u.x, y-u.y);
	}
};

INT add, co;
vector<point> vec;
point z, r;

bool ok(point &u, point &v, point &w) {
	z = u - w;
	r = v - w;
	return (long double)z.x * r.y >= (long double)z.y * r.x;
}

INT calc(point &p) {
	return add+co*p.x+p.y;
}

int main() {
#ifndef	ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	int n, m;
	cin >> n >> m;
	int now=n;
	vec.pb(point(0, 0));
	point tmp;
	while(m--) {
		int t, k, s;
		gn(t, k);
		if(t==1) {
			vec.clear();
			vec.pb(point(0, 0));
			now+=k;
			add=co=0;
		}
		if(t==2) {
			point tmp(now, -co*now-add);
			while(sz(vec) > 1 and ok(tmp, vec.back(), vec[sz(vec)-2])) vec.pop_back();
			vec.pb(tmp);
			now+=k;
		}
		if(t==3) {
			gn(s);
			add+=k;
			co +=s;
		}
		while(sz(vec) > 1 and calc(vec.back()) >= calc(vec[sz(vec)-2])) vec.pop_back();
		print(vec.back().x+1, calc(vec.back()));
	}
	return 0;
}


#include<bits/stdc++.h>

#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3fLL
#define mod 1000000007
#define pb push_back
#define sq(x) ((x)*(x))
#define sz(a) ((int)a.size())
#define eps 1e-8
#define x first
#define y second
#define bpt(x) (__builtin_popcount(x))
#define bptl(x) (__builtin_popcountll(x))
#define bit(x, y) (((x)>>(y))&1)
#define bclz(x) (__builtin_clz(x))
#define bclzl(x) ((x) ? (__builtin_clzll(x)) : 0)
#define bctz(x) (__builtin_ctz(x))
#define bctzl(x) (__builtin_ctzll(x))
#define shit(a) (1 << (a))
#define rev(a) (power(a, mod-2, mod))
#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;
typedef long long INT;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
typedef vector<int> VI;

template<typename T, typename U> inline void smin(T &a, U b) {if(a>b) a=b;}
template<typename T, typename U> inline void smax(T &a, U b) {if(a<b) a=b;}

template<class T>inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}
template<class T>inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}
template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}
template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}
template <class T> inline void println(T x) {print(x); putchar('\n');}
template <class T> inline void printsp(T x) {print(x); putchar(' ');}
template <class T1, class T2> inline void print(T1 x1, T2 x2) {printsp(x1), println(x2);}
template <class T1, class T2, class T3> inline void print(T1 x1, T2 x2, T3 x3) {printsp(x1), printsp(x2), println(x3);}
template <class T1, class T2, class T3, class T4> inline void print(T1 x1, T2 x2, T3 x3, T4 x4) {printsp(x1), printsp(x2), printsp(x3), println(x4);}
template <class T> inline void eprint(T x) {cerr << "--------> " <<x << endl;}
template <class T1, class T2> inline void eprint(T1 x, T2 y) { cerr << "--------> " << x << ' ' << y << endl; }
template <class T1, class T2, class T3> inline void eprint(T1 x, T2 y, T3 z) { cerr << " -------> " << x << ' ' << y << ' ' << z << endl;}
template <class T1, class T2, class T3, class T4> inline void eprint(T1 x, T2 y, T3 z, T4 w) { cerr << " -------> " << x << ' ' << y << ' ' << z << ' ' << w << endl;}
int power(int a, int b, int m, int ans=1) {
	for(; b; b>>=1, a=1LL*a*a%m) if(b&1) ans=1LL*ans*a%m;
	return ans;
}

struct point{
	INT x, y;
	point(INT x=0, INT y=0) : x(x), y(y) {}
	point operator - (const point &u) const{
		return point(x-u.x, y-u.y);
	}
};

INT add, co;
vector<point> vec;
point z, r;

bool ok(point &u, point &v, point &w) {
	z = u - w;
	r = v - w;
	return (long double)z.x * r.y >= (long double)z.y * r.x;
}

INT calc(point &p) {
	return add+co*p.x+p.y;
}

int main() {
#ifndef	ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	int n, m;
	cin >> n >> m;
	int now=1;
	vec.pb(point(0, 0));
	point tmp;
	while(m--) {
		int t, k, s;
		gn(t, k);
		if(t==1) {
			vec.clear();
			vec.pb(point(0, 0));
			now+=k;
			add=co=0;
		}
		if(t==2) {
			point tmp(now, -co*now-add);
			while(sz(vec) > 1 and ok(tmp, vec.back(), vec[sz(vec)-2])) vec.pop_back();
			vec.pb(tmp);
			now+=k;
		}
		if(t==3) {
			gn(s);
			add+=k;
			co +=s;
		}
		while(sz(vec) > 1 and calc(vec.back()) >= calc(vec[sz(vec)-2])) vec.pop_back();
		print(vec.back().x+1, calc(vec.back()));
	}
	return 0;
}


#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
#define fi first
#define se second
using namespace std;
typedef long long LL;
const int MAXN = 300005;

template <typename T> inline void read(T &AKNOI) {
	T x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	AKNOI = flag * x;
}

int n, m, t, nw;
LL k, b;
pair<LL, LL> q[MAXN];

inline double slope(int x, int y) {
	return 1.0 * (q[y].se - q[x].se) / (q[y].fi - q[x].fi);
}

inline LL F(int x) {
	return k * q[x].fi + b + q[x].se;
}

void solve() {
	read(n); read(m); nw = m + 2;
	q[t = 1] = make_pair(0, 0);
	int op, x, y;
	while (m--) {
		read(op); read(x);
		if (op == 1) {
			n += x;
			q[t = 1] = make_pair(0, 0);
			k = b = 0;
		} else if (op == 2) {
			q[nw] = make_pair(n, -k * n - b);
			n += x;
			while (t > 1 && slope(t, nw) <= slope(t - 1, t)) --t;
			q[++t] = q[nw];
		} else {
			read(y);
			b += x;
			k += y;
		}
		while (t > 1 && F(t) >= F(t - 1)) --t;
		printf("%lld %lld\n", q[t].fi + 1, F(t));
	}
}

int main() {
	solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

ll n, m;
ll B = 0, S = 0;

bool cmp(pll x, pll y) {
	return x.first * S + x.second <= y.first * S + y.second;
}

int main() {
	scanf("%I64d%I64d", &n, &m);

	vector<pll> v;
	while (m --) {
		int type, k;
		scanf("%d", &type);
		if (type == 1) {
			scanf("%d", &k);
			n += k;
			B = S = 0;
			v.clear();
			v.push_back(pll(0, 0));
		}
		else if (type == 2) {
			scanf("%d", &k);
			int j = v.size() - 1;
			while (j >= 1 && 1.0l*(v[j-1].second-v[j].second)/(v[j].first-v[j-1].first)<=1.0l*(v[j].second+B+n*S)/(n-v[j].first)) {
				v.pop_back();
				j --;
			}
			v.push_back(pll(n, -B-n*S));
			n += k;
		}
		else {
			int b, s;
			scanf("%d%d", &b, &s);
			B += b;
			S += s;
		}
		int j = v.size() - 1;
		while (j >= 1 && cmp(v[j-1], v[j])) v.pop_back(), j --;
		printf("%I64d %I64d\n", v.back().first + 1, v.back().first * S + v.back().second + B);
	}
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int n, m;

struct arith {
	ll index;
	ll val;
	arith(ll index = 0, ll val = 0):index(index), val(val){}
};

struct moment {
	ll add;
	list<arith>::iterator it;
	moment(ll add, list<arith>::iterator it):add(add), it(it) {}
	bool operator < (const moment &x) const {return add < x.add;}
};

ll _ceil(ll x, ll y) {
	if (x <= 0) return 0;
	return (x - 1) / y + 1;
}

map<ll, bool> del;

int main() {
	scanf("%d%d", &n, &m);
	ll st = 0, en = n;
	ll B = 0, S = 0;
	list<arith> L;
	set<moment> M;
	list<arith>::iterator it, tm;
	L.push_back(arith(0, 0));
	int type;
	while (m --) {
		scanf("%d", &type);
		if (type == 1) {
			int k;
			scanf("%d", &k);
			st -= k;
			it = L.begin();
			L.insert(it, arith(st, -B - st * S));
			if (L.size() > 1) {
				tm = L.begin();
				M.insert(moment(_ceil(tm->val-it->val,it->index-tm->index), tm));
			}
		}
		else if (type == 2) {
			int k;
			scanf("%d", &k);
			it = L.end();
			L.insert(it, arith(en, -B - en * S));
			en += k;
			if (L.size() > 1) {
				it --;
				tm = it;
				tm --;
				M.insert(moment(_ceil(tm->val-it->val,it->index-tm->index), tm));
			}
		}
		else {
			int b, s;
			scanf("%d%d", &b, &s);
			S += s;
			B += b - st * s;
		}
		while (1) {
			if (M.empty()) break;
			it = M.begin()->it;

			ll tar = M.begin()->add;
			if (S < tar) break;
			M.erase(M.begin());
			if (del[it->index]) continue;
			tm = it;
			tm ++;
			if (tm != L.end()) {
				L.erase(tm);
				del[tm->index] = 1;
				tm = it;
				tm ++;
				if (tm != L.end()) M.insert(moment(_ceil(it->val-tm->val, tm->index-it->index), it));
			}
		}
		printf("%I64d %I64d\n", L.back().index - st + 1, L.back().val + B + L.back().index * S);
	}
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

ll n, m;
ll B = 0, S = 0;

bool cmp(pll x, pll y) {
	return x.first * S + x.second <= y.first * S + y.second;
}

int main() {
	scanf("%I64d%I64d", &n, &m);

	vector<pll> v;
	v.push_back(pll(0, 0));
	while (m --) {
		int type, k;
		scanf("%d", &type);
		if (type == 1) {
			scanf("%d", &k);
			n += k;
			B = S = 0;
			v.clear();
			v.push_back(pll(0, 0));
		}
		else if (type == 2) {
			scanf("%d", &k);
			int j = v.size() - 1;
			while (j >= 1 && 1.0l*(v[j-1].second-v[j].second)/(v[j].first-v[j-1].first)<=1.0l*(v[j].second+B+n*S)/(n-v[j].first)) {
				v.pop_back();
				j --;
			}
			v.push_back(pll(n, -B-n*S));
			n += k;
		}
		else {
			int b, s;
			scanf("%d%d", &b, &s);
			B += b;
			S += s;
		}
		int j = v.size() - 1;
		while (j >= 1 && cmp(v[j-1], v[j])) v.pop_back(), j --;
		printf("%I64d %I64d\n", v.back().first + 1, v.back().first * S + v.back().second + B);
	}
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int n, m;

struct arith {
	ll index;
	ll val;
	arith(ll index = 0, ll val = 0):index(index), val(val){}
};

struct moment {
	ll add;
	list<arith>::iterator it;
	moment(ll add, list<arith>::iterator it):add(add), it(it) {}
	bool operator < (const moment &x) const {return add < x.add;}
};

ll _ceil(ll x, ll y) {
	if (x <= 0) return 0;
	return (x - 1) / y + 1;
}

int main() {
	scanf("%d%d", &n, &m);
	ll st = 0, en = n;
	ll B = 0, S = 0;
	list<arith> L;
	set<moment> M;
	list<arith>::iterator it, tm;
	L.push_back(arith(0, 0));
	int type;
	while (m --) {
		scanf("%d", &type);
		if (type == 1) {
			int k;
			scanf("%d", &k);
			st -= k;
			it = L.begin();
			L.insert(it, arith(st, -B - st * S));
			if (L.size() > 1) {
				tm = L.begin();
				M.insert(moment(_ceil(tm->val-it->val,it->index-tm->index), tm));
			}
		}
		else if (type == 2) {
			int k;
			scanf("%d", &k);
			it = L.end();
			L.insert(it, arith(en, -B - en * S));
			en += k;
			if (L.size() > 1) {
				it --;
				tm = it;
				tm --;
				M.insert(moment(_ceil(tm->val-it->val,it->index-tm->index), tm));
			}
		}
		else {
			int b, s;
			scanf("%d%d", &b, &s);
			S += s;
			B += b - st * s;
		}
		while (1) {
			if (M.empty()) break;
			it = M.begin()->it;
			ll tar = M.begin()->add;
			if (S < tar) break;
			M.erase(M.begin());
			tm = it;
			tm ++;
			if (tm != L.end()) {
				L.erase(tm);
				tm = it;
				tm ++;
				M.insert(moment(_ceil(it->val-tm->val, tm->index-it->index), it));
			}
		}
		printf("%I64d %I64d\n", L.back().index - st + 1, L.back().val + B + L.back().index * S);
	}
}


# include<iostream>
# include<cstring>
# include<cstdio>
# include<algorithm>
# define LL long long
using namespace std;
const int MAX=3e5+5;
struct Point{
	LL x,y;
	Point(LL X=0,LL Y=0) {x=X,y=Y;}
}_P[MAX];
int m,Top;
LL n,k,d;
double K(Point a,Point b) {return double(a.y-b.y)/double(a.x-b.x);}
int main()
{
	scanf("%I64d%d",&n,&m),Top=1;
	for(int i=1,op,x,y;i<=m;++i)
	  {
	  	scanf("%d",&op);
	  	if(op==1) scanf("%d",&x),Top=1,k=d=0,_P[1]=Point(0,0),n+=x;
	  	else if(op==2)
	  	{
	  		scanf("%d",&x);
			Point A=Point(n,-n*k-d);
	  		while(Top>1&&K(_P[Top],A)<=K(_P[Top-1],_P[Top])) --Top;
	  		_P[++Top]=A,n+=x;
		}
		else if(op==3) scanf("%d%d",&x,&y),d+=x,k+=y;
		while(Top>1&&_P[Top].y+_P[Top].x*k>=_P[Top-1].y+_P[Top-1].x*k) --Top;
		printf("%I64d %I64d\n",_P[Top].x+1,_P[Top].y+_P[Top].x*k+d);
	  }
	return 0;
}


# include<iostream>
# include<cstring>
# include<cstdio>
# include<algorithm>
# define LL long long
using namespace std;
const int MAX=3e5+3;
struct Point{
	LL x,y;
	Point(LL X=0,LL Y=0) {x=X,y=Y;}
}_P[MAX];
int m,Top;
LL n,k,d;
double K(Point a,Point b) {return double(a.y-b.y)/double(a.x-b.x);}
int main()
{
	scanf("%I64d%d",&n,&m),Top=1;
	for(int i=1,op,x,y;i<=m;++i)
	  {
	  	scanf("%d",&op);
	  	if(op==1) scanf("%d",&x),Top=1,k=d=0,_P[1]=Point(0,0),n+=x;
	  	else if(op==2)
	  	{
	  		scanf("%d",&x);
			Point A=Point(n,-n*k-d);
	  		while(Top>1&&K(_P[Top],A)<=K(_P[Top-1],_P[Top])) --Top;
	  		_P[++Top]=A,n+=x;
		}
		else if(op==3) scanf("%d%d",&x,&y),d+=x,k+=y;
		while(Top>1&&_P[Top].y+_P[Top].x*k>=_P[Top-1].y+_P[Top-1].x*k) --Top;
		printf("%I64d %I64d\n",_P[Top].x+1,_P[Top].y+_P[Top].x*k+d);
	  }
	return 0;
}


# include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int maxn(3e5 + 5);

int n, m;
ll Q[maxn], val[maxn], mov, hd, tl, ed, tagb, tags;

inline ll Calc(int x) {  return val[x] + tagb + tags * (Q[x] + mov - 1);  }

int main() {
	ll op, k, b, s;
	scanf("%d%d", &n, &m);
	Q[hd = tl = 0] = val[0] = 0, ed = n;
	while (m--) {
		scanf("%lld", &op);
		if (op <= 2) scanf("%lld", &k);
		else scanf("%lld%lld", &b, &s);
		if (op == 1) mov += k, ed += k, Q[hd = tl = 0] = 1 - mov, val[hd] = tagb = tags = 0;
		else if (op == 2) {
			if (hd >= tl || 1.0 * (Calc(tl) - Calc(tl - 1)) / (Q[tl] - Q[tl - 1]) > 1.0 * Calc(tl) / (ed + 1 - Q[tl] - mov))
				Q[++tl] = ed + 1 - mov, val[tl] = -tagb - tags * ed;
			ed += k;
		}
		else {
			tagb += b, tags += s;
			while (hd < tl && val[tl] + tags * (Q[tl] - Q[tl - 1]) - val[tl - 1] >= 0) --tl;
		}
		printf("%lld %lld\n", Q[tl] + mov, Calc(tl));
	}
    return 0;
}


# include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int maxn(3e5 + 5);

int n, m;
ll Q[maxn], val[maxn], mov, hd, tl, ed, tagb, tags;

inline ll Calc(int x) {  return val[x] + tagb + tags * (Q[x] + mov - 1);  }
//orz yyb
int main() {
	ll op, k, b, s;
	scanf("%d%d", &n, &m);
	Q[hd = tl = val[0] = 0] = 1, ed = n;
	while (m--) {
		scanf("%lld", &op);
		if (op <= 2) scanf("%lld", &k);
		else scanf("%lld%lld", &b, &s);
		if (op == 1) mov += k, ed += k, Q[hd = tl = 0] = 1 - mov, val[hd] = tagb = tags = 0;
		else if (op == 2) {
			while (hd < tl && 1.0 * (Calc(tl) - Calc(tl - 1)) / (Q[tl] - Q[tl - 1]) >= -1.0 * Calc(tl) / (ed + 1 - Q[tl] - mov)) --tl;
			Q[++tl] = ed + 1 - mov, val[tl] = -tagb - tags * ed, ed += k;
		}
		else tagb += b, tags += s;
		while (hd < tl && val[tl] + tags * (Q[tl] - Q[tl - 1]) - val[tl - 1] >= 0) --tl;
		printf("%lld %lld\n", Q[tl] + mov, Calc(tl));
	}
    return 0;
}


# include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int maxn(3e5 + 5);

int n, m;
ll Q[maxn], val[maxn], mov, hd, tl, ed, tagb, tags;

inline ll Calc(int x) {  return val[x] + tagb + tags * (Q[x] + mov - 1);  }

int main() {
	ll op, k, b, s;
	scanf("%d%d", &n, &m);
	Q[hd = tl = val[0] = 0] = 1, ed = n;
	while (m--) {
		scanf("%lld", &op);
		if (op <= 2) scanf("%lld", &k);
		else scanf("%lld%lld", &b, &s);
		if (op == 1) mov += k, ed += k, Q[hd = tl = 0] = 1 - mov, val[hd] = tagb = tags = 0;
		else if (op == 2) {
			while (hd < tl && 1.0 * (Calc(tl) - Calc(tl - 1)) / (Q[tl] - Q[tl - 1]) >= -1.0 * Calc(tl) / (ed + 1 - Q[tl] - mov)) --tl;
			Q[++tl] = ed + 1 - mov, val[tl] = -tagb - tags * ed, ed += k;
		}
		else tagb += b, tags += s;
		while (hd < tl && val[tl] + tags * (Q[tl] - Q[tl - 1]) - val[tl - 1] >= 0) --tl;
		printf("%lld %lld\n", Q[tl] + mov, Calc(tl));
	}
    return 0;
}


#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(register int i=(a);i>=(b);--i)
#define int long long
using namespace std;
inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}
#define maxn 1000005
struct node{
	int x,y;
	node operator -(const node&b)const{return (node){x-b.x,y-b.y};}
};
inline double getk(node a,node b){
	return 1.0*(a.y-b.y)/(a.x-b.x);
}
int n,m,top,k,b;
node s[maxn];
inline void clear(){top=1;s[1]=(node){0,0};}
inline int calc(node u){
	return u.y+u.x*k+b;
}
signed main()
{
	n=read(),m=read();top=1;
	while(m--)
	{
		int op=read();
		if(op==1){
			clear();
			n+=read(),k=b=0;
		}else if(op==2){
			node u=(node){n,-n*k-b};
			n+=read();
			while(top>1 && getk(u,s[top])<=getk(s[top],s[top-1]))
				top--;
			s[++top]=u;
		}else b+=read(),k+=read();
		while(top>1&&calc(s[top])>=calc(s[top-1]))
			top--;
		printf("%lld %lld\n",s[top].x+1,calc(s[top]));
	}
    return 0;
}


#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(register int i=(a);i>=(b);--i)
#define int long long
using namespace std;
inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}
#define maxn 1000005
struct node{
	int x,y;
	node operator -(const node&b)const{return (node){x-b.x,y-b.y};}
};
inline double getk(node a,node b){
	return 1.0*(a.y-b.y)/(a.x-b.x);
}
int n,m,top,k,b;
node s[maxn];
inline void clear(){top=1;s[1]=(node){0,0};}
inline int calc(node u){
	return u.y+u.x*k+b;
}
signed main()
{
	n=read(),m=read();top=1;
	while(m--)
	{
		int op=read();
		if(op==1){
			clear();
			n+=read(),k=b=0;
		}else if(op==2){
			node u=(node){n,-n*k-b};
			n+=read();
			while(top>1 && getk(u,s[top])>getk(u,s[top-1]))
				top--;
			s[++top]=u;
		}else b+=read(),k+=read();
		while(top>1&&calc(s[top])>=calc(s[top-1]))
			top--;
		printf("%lld %lld\n",s[top].x+1,calc(s[top]));
	}
    return 0;
}


#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(register int i=(a);i>=(b);--i)
#define int long long
using namespace std;
inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}
#define maxn 1000005
struct node{
	int x,y;
	node operator -(const node&b)const{return (node){x-b.x,y-b.y};}
};
inline double getk(node a,node b){
	return 1.0*(a.y-b.y)/(a.x-b.x);
}
int n,m,top,k,b;
node s[maxn];
inline void clear(){top=1;s[1]=(node){0,0};}
inline int calc(node u){
	return u.y+u.x*k+b;
}
signed main()
{
	n=read(),m=read();
	while(m--)
	{
		int op=read();
		if(op==1){
			clear();
			n+=read(),k=b=0;
		}else if(op==2){
			node u=(node){n,-n*k-b};
			n+=read();
			while(top>1 && getk(u,s[top])>getk(u,s[top-1]))
				top--;
			s[++top]=u;
		}else b+=read(),k+=read();
		while(top>1&&calc(s[top])>=calc(s[top-1]))
			top--;
		printf("%lld %lld\n",s[top].x+1,calc(s[top]));
	}
    return 0;
}


#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(register int i=(a);i>=(b);--i)
#define int long long
using namespace std;
inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}
#define maxn 1000005
struct node{
	int x,y;
	node operator -(const node&b)const{return (node){x-b.x,y-b.y};}
};
inline double getk(node a,node b){
	return 1.0*(a.y-b.y)/(a.x-b.x);
}
int n,m,top,k,b;
node s[maxn];
inline void clear(){top=1;s[1]=(node){0,0};}
inline int calc(node u){
	return u.y+u.x*k+b;
}
signed main()
{
	n=read(),m=read();
	while(m--)
	{
		int op=read();
		if(op==1){
			clear();
			n+=read(),k=b=0;
		}else if(op==2){
			node u=(node){n,-n*k-b};
			n+=read();
			while(top>1 && getk(u,s[top])<=getk(s[top],s[top-1]))
				top--;
			s[++top]=u;
		}else b+=read(),k+=read();
		while(top>1&&calc(s[top])>=calc(s[top-1]))
			top--;
		printf("%lld %lld\n",s[top].x+1,calc(s[top]));
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=3e5+7;
#define int long long
typedef pair<int,int>pii;
int n,k,b,Q,top;
pii st[N];
long double getk(pii a,pii b){return 1.0*(b.second-a.second)/(a.first-b.first);}
int calc(pii a){return(a.first-1)*k+a.second+b;}
signed main()
{
	scanf("%lld%lld",&n,&Q);
	st[top=1]=pii(1,0);
	while(Q--)
	{
		int op,x,y;scanf("%lld%lld",&op,&x);
		if(op==1)st[top=1]=pii(1,0),k=b=0,n+=x;
		else if(op==2)
		{
			pii u=pii(n+1,-calc(pii(n+1,0)));
			while(top>1&&getk(u,st[top])>=getk(st[top],st[top-1]))--top;
			st[++top]=u,n+=x;
		}
		else scanf("%lld",&y),b+=x,k+=y;
		while(top>1&&calc(st[top])>=calc(st[top-1]))--top;
		printf("%lld %lld\n",st[top].first,calc(st[top]));
	}
}


#include <bits/stdc++.h>

#define rin(i,a,b) for(int i=(a);i<=(b);++i)
#define irin(i,a,b) for(int i=(a);i>=(b);--i)
#define trav(i,a) for(int i=head[a];i;i=e[i].nxt)
#define Size(a) (int)a.size()
#define mkpr std::make_pair
#define fi first
#define se second
#define lowbit(a) ((a)&(-(a)))
typedef long long LL;
typedef std::pair<int,int> pii;

using std::cerr;
using std::endl;

inline int read(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int MAXM=300005;
const double eps=1e-8;

int m,cnt,top,sta[MAXM];
LL n,nowk,nowb;

inline long double lfabs(long double x){
	return x>=0?x:-x;
}

inline long double dcmp(long double x,long double y){
	if(lfabs(x-y)<eps)return 0;
	if(x<y)return -1;
	else return 1;
}

struct point{
	LL x,y;
	inline friend point operator + (point a,point b){
		return (point){a.x+b.x,a.y+b.y};
	}
	inline friend point operator - (point a,point b){
		return (point){a.x-b.x,a.y-b.y};
	}
}a[MAXM];

typedef point vector;

inline long double cross(vector a,vector b){
	return (long double)a.x*b.y-(long double)a.y*b.x;
}

inline bool toleft(point a,point b,point c){
	return dcmp(cross(b-a,c-b),0)>0;
}

int main(){
	n=read(),m=read();
	rin(i,1,n)a[++cnt]=(point){i,0};
	sta[++top]=1;
	rin(i,1,m){
		int opt=read();
		if(opt==1){
			int k=read();n+=k;
			cnt=top=nowk=nowb=0;
			a[++cnt]=(point){1,0};
			sta[++top]=1;
		}
		else if(opt==2){
			int k=read();++n;
			a[++cnt]=(point){n,-nowk*(n-1)-nowb};
			while(top>=2&&!toleft(a[sta[top-1]],a[sta[top]],a[cnt]))--top;
			sta[++top]=cnt;n+=k-1;
		}
		else nowb+=read(),nowk+=read();
		while(top>=2&&a[sta[top]].y-a[sta[top-1]].y+nowk*(a[sta[top]].x-a[sta[top-1]].x)>=0)--top;
		printf("%I64d %I64d\n",a[sta[top]].x,a[sta[top]].y+nowk*(a[sta[top]].x-1)+nowb);
	}
	return 0;
}


#include <bits/stdc++.h>

#define rin(i,a,b) for(register int i=(a);i<=(b);++i)
#define irin(i,a,b) for(register int i=(a);i>=(b);--i)
#define trav(i,a) for(register int i=head[a];i;i=e[i].nxt)
typedef long long LL;

using std::cin;
using std::cout;
using std::endl;

inline int read(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int MAXN=300005;

int n,m;
LL fst,lst,fid,lid;

inline void print(){
	if(fst<=lst){
		printf("%lld %lld\n",fid,fst);
	}
	else{
		printf("%lld %lld\n",lid,lst);
	}
}

int main(){
	n=read(),m=read();
	fst=lst=0;fid=lid=1;
	while(m--){
		int opt=read();
		if(opt==1){
			int k=read();
			fst=0,fid=1;
			lid+=k;
			n+=k;
			print();
		}
		else if(opt==2){
			int k=read();
			if(lst) lst=0,lid=n+1;
			n+=k;
			print();
		}
		else{
			LL b=read(),s=read();
			fst+=b+(fid-1)*s;
			lst+=b+(lid-1)*s;
			print();
		}
	}
	return 0;
}


#include <bits/stdc++.h>

#define rin(i,a,b) for(int i=(a);i<=(b);++i)
#define irin(i,a,b) for(int i=(a);i>=(b);--i)
#define trav(i,a) for(int i=head[a];i;i=e[i].nxt)
#define Size(a) (int)a.size()
#define mkpr std::make_pair
#define fi first
#define se second
#define lowbit(a) ((a)&(-(a)))
typedef long long LL;
typedef std::pair<int,int> pii;

using std::cerr;
using std::endl;

inline int read(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int MAXM=300005;
const double eps=1e-8;

int m,cnt,top,sta[MAXM];
LL n,nowk,nowb;

inline long double lfabs(long double x){
	return x>=0?x:-x;
}

inline long double dcmp(long double x,long double y){
	if(lfabs(x-y)<eps)return 0;
	if(x<y)return -1;
	else return 1;
}

struct point{
	LL x,y;
	inline friend point operator + (point a,point b){
		return (point){a.x+b.x,a.y+b.y};
	}
	inline friend point operator - (point a,point b){
		return (point){a.x-b.x,a.y-b.y};
	}
}a[MAXM];

typedef point vector;

inline long double cross(vector a,vector b){
	return (long double)a.x*b.y-(long double)a.y*b.x;
}

inline bool toleft(point a,point b,point c){
	return dcmp(cross(b-a,c-b),0)>0;
}

int main(){
	n=read(),m=read();
	a[++cnt]=(point){1,0};
	sta[++top]=1;
	rin(i,1,m){
		int opt=read();
		if(opt==1){
			int k=read();n+=k;
			cnt=top=nowk=nowb=0;
			a[++cnt]=(point){1,0};
			sta[++top]=1;
		}
		else if(opt==2){
			int k=read();++n;
			a[++cnt]=(point){n,-nowk*(n-1)-nowb};
			while(top>=2&&!toleft(a[sta[top-1]],a[sta[top]],a[cnt]))--top;
			sta[++top]=cnt;n+=k-1;
		}
		else nowb+=read(),nowk+=read();
		while(top>=2&&a[sta[top]].y-a[sta[top-1]].y+nowk*(a[sta[top]].x-a[sta[top-1]].x)>=0)--top;
		printf("%I64d %I64d\n",a[sta[top]].x,a[sta[top]].y+nowk*(a[sta[top]].x-1)+nowb);
	}
	return 0;
}


//minamoto
#include<bits/stdc++.h>
#define R register
#define ll long long
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
    R int res,f=1;R char ch;
    while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
    for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
    return res*f;
}
char sr[1<<21],z[20];int C=-1,Z=0;
inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(R ll x){
    if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x;
    while(z[++Z]=x%10+48,x/=10);
    while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
const int N=5e5+5;
struct node{
	node *lc,*rc;int s,id;ll v,c;
	inline void init(R int ss,R int Id,R ll vv){s=ss,id=Id,v=vv,lc=rc=NULL;}
}pool[N],*p[N],*T,*g;
struct point{
	node *c;ll v;
	point(){c=NULL,v=0;}
	point(node *cc,ll vv):c(cc),v(vv){}
	inline bool operator <(const point &b)const{return v>b.v;}
	inline bool operator ==(const point &b)const{return c==b.c&&v==b.v;}
};
struct Queue{
	priority_queue<point>A,B;
	inline void push(R point x){A.push(x);}
	inline void pop(R point x){B.push(x);}
	inline void pop(){A.pop();}
	inline bool empty(){
		while(!B.empty()&&A.top()==B.top())A.pop(),B.pop();
		return A.empty();
	}
	inline point top(){
		while(!B.empty()&&A.top()==B.top())A.pop(),B.pop();
		return A.top();
	}
}q;
int n,m,tot,op,b,s,k,sum;ll sumb,sums,tmpb,tmps;
inline void insh(){p[++tot]->init(sum+k,1,0),T=p[tot],tmpb=tmps=0;while(!q.empty())q.pop();}
inline ll val(node *it){return tmpb+tmps*(it->id-1)+it->v;}
void inst(){
	if(val(T)==0)return T->s+=k,void();
	p[++tot]->init(k,sum+1,-tmpb-tmps*sum);
	p[tot]->c=(val(T)-val(p[tot])+T->s-1)/T->s+tmps;
	p[tot]->lc=T,T->rc=p[tot],q.push(point(p[tot],p[tot]->c));
	T=p[tot];
}
void update(){
	tmpb+=b,tmps+=s;
	while(!q.empty()&&q.top().v<=tmps){
		g=q.top().c,q.pop();
		if(g==T)T=g->lc,T->s+=g->s,T->rc=NULL;
		else{
			g->lc->rc=g->rc,g->rc->lc=g->lc,g->lc->s+=g->s;
			q.pop(point(g->rc,g->rc->c));
			g->rc->c=(val(g->lc)-val(g->rc)+g->lc->s-1)/g->lc->s+tmps;
			q.push(point(g->rc,g->rc->c));
		}
	}
}
int main(){
//	freopen("testdata.in","r",stdin);
	n=read(),m=read();
	fp(i,1,N-5)p[i]=&pool[i];
	k=n,insh(),sum=k;
	while(m--){
		op=read();
		switch(op){
			case 1:k=read(),insh(),sum+=k;break;
			case 2:k=read(),inst(),sum+=k;break;
			case 3:b=read(),s=read(),update(),sumb+=b,sums+=s;break;
		}
		print(T->id),sr[C]=' ',print(val(T));
	}
	return Ot(),0;
}


//minamoto
#include<bits/stdc++.h>
#define R register
#define ll long long
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
    R int res,f=1;R char ch;
    while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
    for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
    return res*f;
}
char sr[1<<21],z[20];int C=-1,Z=0;
inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(R ll x){
    if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x;
    while(z[++Z]=x%10+48,x/=10);
    while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
const int N=5e5+5;
struct node{
	node *lc,*rc;int s,id;ll v,c;
	inline void init(R int ss,R int Id,R ll vv){s=ss,id=Id,v=vv,lc=rc=NULL;}
}pool[N],*p[N],*T,*g;
struct point{
	node *c;ll v;
	point(){c=NULL,v=0;}
	point(node *cc,ll vv):c(cc),v(vv){}
	inline bool operator <(const point &b)const{return v>b.v;}
	inline bool operator ==(const point &b)const{return c==b.c&&v==b.v;}
};
struct Queue{
	priority_queue<point>A,B;
	inline void push(R point x){A.push(x);}
	inline void pop(R point x){B.push(x);}
	inline void pop(){A.pop();}
	inline bool empty(){
		while(!B.empty()&&A.top()==B.top())A.pop(),B.pop();
		return A.empty();
	}
	inline point top(){
		while(!B.empty()&&A.top()==B.top())A.pop(),B.pop();
		return A.top();
	}
}q;
int n,m,tot,op,b,s,k,sum;ll sumb,sums,tmpb,tmps;
inline void insh(){p[++tot]->init(sum+k,1,0),T=p[tot],tmpb=tmps=0;while(!q.empty())q.pop();}
inline ll val(node *it){return tmpb+tmps*(it->id-1)+it->v;}
void inst(){
	if(val(T)==0)return T->s+=k,void();
	p[++tot]->init(k,sum+1,-tmpb-tmps*sum);
	p[tot]->c=(val(T)-val(p[tot])+T->s-1)/T->s+tmps;
	p[tot]->lc=T,T->rc=p[tot],q.push(point(p[tot],p[tot]->c));
	T=p[tot];
}
void update(){
	tmpb+=b,tmps+=s;
	while(!q.empty()&&q.top().v<=tmps){
		g=q.top().c,q.pop();
		if(g==T)T=g->lc,T->s+=g->s,T->rc=NULL;
		else{
			g->lc->rc=g->rc,g->rc->lc=g->lc,g->lc->s+=g->s;
			q.pop(point(g->rc,g->rc->c));
			g->rc->c=(val(g->lc)-val(g->rc)+g->lc->s-1)/g->lc->s+tmps;
			q.push(point(g->rc,g->rc->c));
		}
	}
}
int main(){
//	freopen("testdata.in","r",stdin);
	n=read(),m=read();
	fp(i,1,N-5)p[i]=&pool[i];
	k=n,insh(),sum=k;
	while(m--){
		op=read();
		switch(op){
			case 1:k=read(),insh(),sum+=k;break;
			case 2:k=read(),inst(),sum+=k;break;
			case 3:b=read(),s=read(),update();break;
		}
		print(T->id),sr[C]=' ',print(val(T));
	}
	return Ot(),0;
}


//minamoto
#include<bits/stdc++.h>
#define R register
#define ll long long
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
    R int res,f=1;R char ch;
    while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
    for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
    return res*f;
}
char sr[1<<21],z[20];int C=-1,Z=0;
inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(R ll x){
    if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x;
    while(z[++Z]=x%10+48,x/=10);
    while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
const int N=3e5+5;
struct node{
	node *lc,*rc;int s,id;ll v;
	inline void init(R int ss,R int Id,R ll vv){s=ss,id=Id,v=vv,lc=rc=NULL;}
}pool[N],*p[N],*T,*g;
struct point{
	node *c;ll v;
	point(){c=NULL,v=0;}
	point(node *cc,ll vv):c(cc),v(vv){}
	inline bool operator <(const point &b)const{return v>b.v;}
	inline bool operator ==(const point &b)const{return c==b.c;}
};priority_queue<point>q;
int n,m,tot,op,b,s,k,sum;ll sumb,sums,tmpb,tmps;
inline void insh(){p[++tot]->init(sum+k,1,0),T=p[tot],tmpb=tmps=0;while(!q.empty())q.pop();}
inline ll val(node *it){return tmpb+tmps*(it->id-1)+it->v;}
void inst(){
	if(val(T)==0)return T->s+=k,void();
	p[++tot]->init(k,sum+1,-tmpb-tmps*sum);
	p[tot]->lc=T,T->rc=p[tot],q.push(point(p[tot],(val(T)-val(p[tot])+T->s-1)/T->s+tmps));
	T=p[tot];
}
void update(){
	tmpb+=b,tmps+=s;
	while(!q.empty()&&q.top().v<=tmps){
		g=q.top().c,q.pop();
		if(g==T)T=g->lc,T->s+=g->s,T->rc=NULL;
		else{
			g->lc->rc=g->rc,g->rc->lc=g->lc,g->lc->s+=g->s;
			q.push(point(g->rc,(val(g->lc)-val(g->rc)+g->lc->s-1)/g->lc->s+tmps));
		}
	}
}
int main(){
//	freopen("testdata.in","r",stdin);
	n=read(),m=read();
	fp(i,1,m)p[i]=&pool[i];
	sum=k=n,insh();
	while(m--){
		op=read();
		switch(op){
			case 1:k=read(),insh(),sum+=k;break;
			case 2:k=read(),inst(),sum+=k;break;
			case 3:b=read(),s=read(),update(),sumb+=b,sums+=s;break;
		}
//		puts("qwq");
		print(T->id),sr[C]=' ',print(val(T));
	}
	return Ot(),0;
}


//minamoto
#include<bits/stdc++.h>
#define R register
#define ll long long
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
    R int res,f=1;R char ch;
    while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
    for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
    return res*f;
}
char sr[1<<21],z[20];int C=-1,Z=0;
inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(R ll x){
    if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x;
    while(z[++Z]=x%10+48,x/=10);
    while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
const int N=3e5+5;
struct node{
	node *lc,*rc;int s,id;ll v,c;
	inline void init(R int ss,R int Id,R ll vv){s=ss,id=Id,v=vv,lc=rc=NULL;}
}pool[N],*p[N],*T,*g;
struct point{
	node *c;ll v;
	point(){c=NULL,v=0;}
	point(node *cc,ll vv):c(cc),v(vv){}
	inline bool operator <(const point &b)const{return v>b.v;}
	inline bool operator ==(const point &b)const{return c==b.c&&v==b.v;}
};
struct Queue{
	priority_queue<point>A,B;
	inline void push(R point x){A.push(x);}
	inline void pop(R point x){B.push(x);}
	inline void pop(){A.pop();}
	inline bool empty(){
		while(!B.empty()&&A.top()==B.top())A.pop(),B.pop();
		return A.empty();
	}
	inline point top(){
		while(!B.empty()&&A.top()==B.top())A.pop(),B.pop();
		return A.top();
	}
}q;
int n,m,tot,op,b,s,k,sum;ll sumb,sums,tmpb,tmps;
inline void insh(){p[++tot]->init(sum+k,1,0),T=p[tot],tmpb=tmps=0;while(!q.empty())q.pop();}
inline ll val(node *it){return tmpb+tmps*(it->id-1)+it->v;}
void inst(){
	if(val(T)==0)return T->s+=k,void();
	p[++tot]->init(k,sum+1,-tmpb-tmps*sum);
	p[tot]->c=(val(T)-val(p[tot])+T->s-1)/T->s+tmps;
	p[tot]->lc=T,T->rc=p[tot],q.push(point(p[tot],p[tot]->c));
	T=p[tot];
}
void update(){
	tmpb+=b,tmps+=s;
	while(!q.empty()&&q.top().v<=tmps){
		g=q.top().c,q.pop();
		if(g==T)T=g->lc,T->s+=g->s,T->rc=NULL;
		else{
			g->lc->rc=g->rc,g->rc->lc=g->lc,g->lc->s+=g->s;
			q.pop(point(g->rc,g->rc->c));
			g->rc->c=(val(g->lc)-val(g->rc)+g->lc->s-1)/g->lc->s+tmps;
			q.push(point(g->rc,g->rc->c));
		}
	}
}
int main(){
//	freopen("testdata.in","r",stdin);
	n=read(),m=read();
	fp(i,1,m)p[i]=&pool[i];
	k=n,insh(),sum=k;
	while(m--){
		op=read();
		switch(op){
			case 1:k=read(),insh(),sum+=k;break;
			case 2:k=read(),inst(),sum+=k;break;
			case 3:b=read(),s=read(),update(),sumb+=b,sums+=s;break;
		}
		print(T->id),sr[C]=' ',print(val(T));
	}
	return Ot(),0;
}


//minamoto
#include<bits/stdc++.h>
#define R register
#define ll long long
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
    R int res,f=1;R char ch;
    while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
    for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
    return res*f;
}
char sr[1<<21],z[20];int C=-1,Z=0;
inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(R ll x){
    if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x;
    while(z[++Z]=x%10+48,x/=10);
    while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
const int N=3e5+5;
struct node{
	node *lc,*rc;int s,id;ll v;
	inline void init(R int ss,R int Id,R ll vv){s=ss,id=Id,v=vv,lc=rc=NULL;}
}pool[N],*p[N],*T,*g;
struct point{
	node *c;ll v;
	point(){c=NULL,v=0;}
	point(node *cc,ll vv):c(cc),v(vv){}
	inline bool operator <(const point &b)const{return v>b.v;}
	inline bool operator ==(const point &b)const{return c==b.c;}
};priority_queue<point>q;
int n,m,tot,op,b,s,k,sum;ll sumb,sums,tmpb,tmps;
inline void insh(){p[++tot]->init(sum+k,1,0),T=p[tot],tmpb=tmps=0;while(!q.empty())q.pop();}
inline ll val(node *it){return tmpb+tmps*(it->id-1)+it->v;}
void inst(){
	if(val(T)==0)return T->s+=k,void();
	p[++tot]->init(k,sum+1,-tmpb-tmps*sum);
	p[tot]->lc=T,T->rc=p[tot],q.push(point(p[tot],(val(T)-val(p[tot])+T->s-1)/T->s+tmps));
	T=p[tot];
}
void update(){
	tmpb+=b,tmps+=s;
	while(!q.empty()&&q.top().v<=tmps){
		g=q.top().c,q.pop();
		if(g==T)T=g->lc,T->s+=g->s,T->rc=NULL;
		else{
			g->lc->rc=g->rc,g->rc->lc=g->lc,g->lc->s+=g->s;
			q.push(point(g->rc,(val(g->lc)-val(g->rc)+g->lc->s-1)/g->lc->s+tmps));
		}
	}
}
int main(){
//	freopen("testdata.in","r",stdin);
	n=read(),m=read();
	fp(i,1,m)p[i]=&pool[i];
	sum=k=n,insh();
	while(m--){
		op=read();
		switch(op){
			case 1:k=read(),insh(),sum+=k;break;
			case 2:k=read(),inst(),sum+=k;break;
			case 3:b=read(),s=read(),update(),sumb+=b,sums+=s;break;
		}
		print(T->id),sr[C]=' ',print(val(T));
	}
	return Ot(),0;
}


/*
Author: QAQ-Automaton
LANG: C++
PROG: E.cpp
Mail: cnyalilk@vip.qq.com
*/
#include<bits/stdc++.h>
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define DEBUG printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define all(x) x.begin(),x.end()
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define inf 0x3f3f3f3f3f3f3f3f3f3f3f3f3f3f3f3f
const double eps=1e-8;
const double pi=acos(-1.0);
template<class T>int chkmin(T &a,T b){return a>b?a=b,1:0;}
template<class T>int chkmax(T &a,T b){return a<b?a=b,1:0;}
template<class T>T sqr(T a){return a*a;}
template<class T>T mmin(T a,T b){return a<b?a:b;}
template<class T>T mmax(T a,T b){return a>b?a:b;}
template<class T>T aabs(T a){return a<0?-a:a;}
template<class T>int dcmp(T a,T b){return a>b;}
template<int *a>int cmp_a(int x,int y){return a[x]<a[y];}
#define min mmin
#define max mmax
#define abs aabs
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	inline bool read (signed &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;else if(c==EOF)return 0;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;
		return 1;
	}

	inline bool read (long long &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;else if(c==EOF)return 0;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;
		return 1;
	}
	inline bool read (char &x) {
		x=gc();
		return x!=EOF;
	}
	inline bool read(char *x){
		while((*x=gc())=='\n' || *x==' '||*x=='\r')if(*x==EOF)return 0;
		while(!(*x=='\n'||*x==' '||*x=='\r'))*(++x)=gc();
		*x=0;
		return 1;
	}
	template<typename A,typename ...B>
	inline bool read(A &x,B &...y){
		return read(x)&&read(y...);
	}
	// print a signed integer
	inline bool write (signed x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
		return 0;
	}

	inline bool write (long long x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
		return 0;
	}
	inline bool write (char x) {
		putc(x);
		return 0;
	}
	inline bool write(const char *x){
		while(*x){putc(*x);++x;}
		return 0;
	}
	inline bool write(char *x){
		while(*x){putc(*x);++x;}
		return 0;
	}
	template<typename A,typename ...B>
	inline bool write(A x,B ...y){
		return write(x)||write(y...);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: read;
using io :: putc;
using io :: write;
int cnt,m,tp,x,y,s,d;
pii stk[300005];
int top;
void init(){
	s=d=0;
	top=1;
	stk[top]=make_pair(0,0);
}
void add1(){
	pii nw=make_pair(cnt,-s-d*cnt);
	cnt+=x;
	if(stk[top].y+d*stk[top].x+s==0)return;
	while(top>1 && (nw.y-stk[top].y)*1./(nw.x-stk[top].x)<=(nw.y-stk[top-1].y)*1./(nw.x-stk[top-1].x))--top;
	stk[++top]=nw;
}
void add2(){
	s+=x;d+=y;
	while(top>1 && (stk[top].y-stk[top-1].y)*1./(stk[top].x-stk[top-1].x)>=-d)--top;
}
int main(){
#ifdef QAQAutoMaton
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
#endif
	read(cnt,m);
	init();
	for(;m;--m){
		read(tp,x);
		if(tp==1){
			cnt+=x;
			init();
		}
		else if(tp==2){
			add1();
		}
		else{
			read(y);
			add2();
		}
		write(stk[top].x+1,' ',stk[top].y+s+stk[top].x*d,'\n');
	}
	return 0;
}