//MULTQ3 - Multiples of 3
# include <bits/stdc++.h>
using namespace std;
# define mod 1000000007
# define ll long long
# define INF 1e18
# define mp make_pair
# define pb push_back
# define fill(a,v) memset(a, v, sizeof a)
ll N,Q;
struct data
{
ll zeros;
ll ones;
ll twos;
};
data tree[4*123456];
ll lazy[4*123456];
ll ch,L,R;
void build(ll node,ll start,ll end)
{
if(start!=end)
{
ll mid=(start+end)/2;
build(2*node,start,mid);
build(2*node+1,mid+1,end);
tree[node].zeros=tree[2*node].zeros+tree[2*node+1].zeros;
tree[node].ones=tree[2*node].ones+tree[2*node+1].ones;
tree[node].twos=tree[2*node].twos+tree[2*node+1].twos;
}
else
{
tree[node].zeros=1;
tree[node].ones=tree[node].twos=0;
}/*
cout<<start<<":"<<end<<"::"<<endl;
cout<<" "<<"zeros:"<<tree[node].zeros<<endl;
cout<<" "<<"ones:"<<tree[node].ones<<endl;
cout<<" "<<"twos:"<<tree[node].twos<<endl;*/
}
void update(ll node,ll start,ll end)
{
if(lazy[node]!=0)
{
lazy[2*node]+=lazy[node];
lazy[2*node+1]+=lazy[node];
lazy[node]%=3;
ll temp0=tree[node].zeros;
ll temp1=tree[node].ones;
ll temp2=tree[node].twos;
if(lazy[node]==1)
{
tree[node].zeros=temp2;
tree[node].ones=temp0;
tree[node].twos=temp1;
}
else if(lazy[node]==2)
{
tree[node].zeros=temp1;
tree[node].ones=temp2;
tree[node].twos=temp0;
}
lazy[node]=0;
}
if(L>end || R<start)
return;
else if(L<=start && R>=end)//inside
{
lazy[2*node]++;
lazy[2*node+1]++;
ll temp0=tree[node].zeros;
ll temp1=tree[node].ones;
ll temp2=tree[node].twos;
tree[node].zeros=temp2;
tree[node].ones=temp0;
tree[node].twos=temp1;
}
else
{
ll mid=(start+end)/2;
update(2*node,start,mid);
update(2*node+1,mid+1,end);
tree[node].zeros=tree[2*node].zeros+tree[2*node+1].zeros;
tree[node].ones=tree[2*node].ones+tree[2*node+1].ones;
tree[node].twos=tree[2*node].twos+tree[2*node+1].twos;
}
/*
cout<<start<<":"<<end<<"::"<<endl;
cout<<" "<<"zeros:"<<tree[node].zeros<<endl;
cout<<" "<<"ones:"<<tree[node].ones<<endl;
cout<<" "<<"twos:"<<tree[node].twos<<endl;*/
}
data query(ll node,ll start,ll end)
{
data temp;
if(lazy[node]!=0)
{
lazy[2*node]+=lazy[node];
lazy[2*node+1]+=lazy[node];
lazy[node]%=3;
ll temp0=tree[node].zeros;
ll temp1=tree[node].ones;
ll temp2=tree[node].twos;
if(lazy[node]==1)
{
tree[node].zeros=temp2;
tree[node].ones=temp0;
tree[node].twos=temp1;
}
else if(lazy[node]==2)
{
tree[node].zeros=temp1;
tree[node].ones=temp2;
tree[node].twos=temp0;
}
lazy[node]=0;
}
if(L>end || R<start)
{
temp.zeros=temp.ones=temp.twos=0;
return temp;
}
else if(L<=start && R>=end)
return tree[node];
else
{
ll mid=(start+end)/2;
data left=query(2*node,start,mid);
data right=query(2*node+1,mid+1,end);
temp.zeros=left.zeros+right.zeros;
temp.ones=left.ones+right.ones;
temp.twos=left.twos+right.twos;
return temp;
}
}
int main()
{
ll i,j;
scanf("%lld%lld",&N,&Q);
build(1,1,N);
fill(lazy,0);
while(Q--)
{
scanf("%lld%lld%lld",&ch,&L,&R);
L++;
R++;
if(ch==1)
printf("%lld\n",query(1,1,N).zeros);
else
update(1,1,N);
}
return 0;
}
Ly9NVUxUUTMgLSBNdWx0aXBsZXMgb2YgMwojIGluY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojIGRlZmluZSAgbW9kIAkgICAgIDEwMDAwMDAwMDcKIyBkZWZpbmUgIGxsCSAgICAgbG9uZyBsb25nCiMgZGVmaW5lICBJTkYJICAgICAxZTE4CiMgZGVmaW5lICBtcCAgICAgICAgIG1ha2VfcGFpcgojIGRlZmluZSAgcGIgICAgICAgICBwdXNoX2JhY2sKIyBkZWZpbmUgIGZpbGwoYSx2KSAgbWVtc2V0KGEsIHYsIHNp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