#include<iostream>
#include<stdio.h>
using namespace std;
#define max 100001
inline void S(int &x) {
register int c = getchar_unlocked();
x = 0;
int neg = 0;
for(; ((c<48 || c>57) && c != '-'); c = getchar_unlocked());
if(c=='-') {
neg = 1;
c = getchar_unlocked();
}
for(; c>47 && c<58 ; c = getchar_unlocked())
{
x = (x<<1) + (x<<3) + c - 48;
}
if(neg)
x = -x;
}
struct rem{
int r0,r1,r2;
};
rem tree[3*max];
int lazy[3*max]={0};
void prepare(int node)
{
lazy[node] = (lazy[node])%3;
int ans=lazy[node],t;
if(ans==1)
{
t= tree[2*node].r2;
tree[2*node].r2= tree[2*node].r1;
tree[2*node].r1= tree[2*node].r0;
tree[2*node].r0= t;
t= tree[2*node+1].r2;
tree[2*node+1].r2= tree[2*node+1].r1;
tree[2*node+1].r1= tree[2*node+1].r0;
tree[2*node+1].r0= t;
}
else if(ans==2)
{
t= tree[2*node].r2;
tree[2*node].r2= tree[2*node].r0;
tree[2*node].r0= tree[2*node].r1;
tree[2*node].r1= t;
int t= tree[2*node+1].r2;
tree[2*node+1].r2= tree[2*node+1].r0;
tree[2*node+1].r0= tree[2*node+1].r1;
tree[2*node+1].r1= t;
}
else return;
lazy[2*node] = (lazy[2*node] + lazy[node])%3;
lazy[2*node+1] = (lazy[2*node+1] + lazy[node])%3;
lazy[node]=0;
}
void make_tree(int node, int start, int end)
{
if(start==end)
{
tree[node].r0= 1;
tree[node].r1= 0;
tree[node].r2= 0;
return;
}
int mid = (start+end)/2;
make_tree(2*node, start, mid);
make_tree(2*node+1, mid+1, end);
tree[node].r0= (end-start+1);
tree[node].r1= 0;
tree[node].r2= 0;
}
void update(int node, int start, int end, int ra1, int ra2)
{
if(ra1>end || ra2<start) return;
if(start>=ra1 && end<=ra2)
{
int temp=tree[node].r2;
tree[node].r2= tree[node].r1;
tree[node].r1= tree[node].r0;
tree[node].r0= temp;
lazy[node]= (lazy[node]+1)%3;
return;
}
int mid= (start+end)/2;
if(lazy[node]) prepare(node);
update(2*node, start, mid,ra1,ra2);
update(2*node+1, mid+1, end, ra1, ra2);
tree[node].r0= tree[2*node].r0 + tree[2*node+1].r0;
tree[node].r1= tree[2*node].r1 + tree[2*node+1].r1;
tree[node].r2= tree[2*node].r2 + tree[2*node+1].r2;
}
int query(int node, int start, int end, int ra1, int ra2)
{
if(ra1>end || ra2<start)
return 0;
if(start>=ra1 && end<=ra2)
return tree[node].r0;
if(lazy[node]) prepare(node);
int mid = (start+end)/2;
return query(2*node, start, mid, ra1, ra2) + query(2*node+1, mid+1,end,ra1,ra2);
}
int main()
{
std::ios_base::sync_with_stdio(false);
int q,n,a,f,x,y;
//cin>>n>>q;
S(n); S(q);
make_tree(1,0,n-1);
while(q--)
{
//cin>>f>>x>>y;
S(f); S(x); S(y);
if(f==0)
update(1,0,n-1,x,y);
else
cout<<query(1,0,n-1,x,y)<<endl;
}
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPHN0ZGlvLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojZGVmaW5lIG1heCAxMDAwMDEKCmlubGluZSB2b2lkIFMoaW50ICZ4KSB7CnJlZ2lzdGVyIGludCBjID0gZ2V0Y2hhcl91bmxvY2tlZCgpOwp4ID0gMDsKaW50IG5lZyA9IDA7CmZvcig7ICgoYzw0OCB8fCBjPjU3KSAmJiBjICE9ICctJyk7IGMgPSBnZXRjaGFyX3VubG9ja2VkKCkpOwppZihjPT0nLScpIHsKICAgICAgIG5lZyA9IDE7CiAgICAgICAgYyA9IGdldGNoYXJfdW5sb2NrZWQoKTsKICAgIH0KICAgIGZvcig7IGM+NDcgJiYgYzw1OCA7IGMgPSBnZXRjaGFyX3VubG9ja2VkKCkpCiAgICB7CiAgICAgICAgeCA9ICh4PDwxKSArICh4PDwzKSArIGMgLSA0ODsKICAgIH0KICAgIGlmKG5lZykKICAgICAgICB4ID0gLXg7Cn0KCnN0cnVjdCByZW17CmludCByMCxyMSxyMjsKfTsKCnJlbSB0cmVlWzM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