#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
const int SIZE = 1<<17;
const int TREE_SIZE = SIZE<<2;
struct Node {
int a0,a1,a2;
};
int n;
int q;
int type,a,b;
int i;
Node tree[TREE_SIZE];
int lazy[TREE_SIZE];
void build_tree(int a, int b, int node) {
if(a>b) return;
if(a==b) {
tree[node].a0=1;
tree[node].a1=0;
tree[node].a2=0;
return;
}
tree[node].a0=b-a+1;
tree[node].a1=0;
tree[node].a2=0;
build_tree(a,(a+b)>>1,node<<1);
build_tree(((a+b)>>1)+1,b,(node<<1)|1);
}
void update_tree(int a, int b, int i, int j, int node) {
while(lazy[node]>0) {
lazy[node]--;
//printf("%d\n", lazy[node]);
int tmp=tree[node].a0;
tree[node].a0=tree[node].a2;
tree[node].a2=tree[node].a1;
tree[node].a1=tmp;
if(a!=b) {
lazy[node<<1]=(lazy[node<<1]+1)%3;
lazy[(node<<1)|1]=(lazy[(node<<1)|1]+1)%3;
}
}
if(a>b || a>j || b<i) return;
if(a>=i && b<=j) {
int tmp=tree[node].a0;
tree[node].a0=tree[node].a2;
tree[node].a2=tree[node].a1;
tree[node].a1=tmp;
if(a!=b) {
lazy[node<<1]=(lazy[node<<1]+1)%3;
lazy[(node<<1)|1]=(lazy[(node<<1)|1]+1)%3;
}
return;
}
update_tree(a,(a+b)>>1,i,j,node<<1);
update_tree(((a+b)>>1)+1,b,i,j,(node<<1)|1);
tree[node].a0=tree[node<<1].a0+tree[(node<<1)|1].a0;
tree[node].a1=tree[node<<1].a1+tree[(node<<1)|1].a1;
tree[node].a2=tree[node<<1].a2+tree[(node<<1)|1].a2;
}
int query_tree(int a, int b, int i, int j, int node) {
if(a>b || b<i || a>j) return 0;
while(lazy[node]>0) {
lazy[node]--;
int tmp=tree[node].a0;
tree[node].a0=tree[node].a2;
tree[node].a2=tree[node].a1;
tree[node].a1=tmp;
if(a!=b) {
lazy[node<<1]=(lazy[node<<1]+1)%3;
lazy[(node<<1)|1]=(lazy[(node<<1)|1]+1)%3;
}
}
if(a>=i && b<=j) return tree[node].a0;
int q1,q2;
q1=query_tree(a,(a+b)>>1,i,j,node<<1);
q2=query_tree(((a+b)>>1)+1,b,i,j,(node<<1)|1);
return q1+q2;
}
int main() {
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
//freopen("test.txt","r",stdin);
scanf("%d %d", &n, &q);
build_tree(1,n,1);
for(i=1;i<=q;i++) {
scanf("%d %d %d", &type, &a, &b);
a++;
b++;
if(type==0) update_tree(1,n,a,b,1);
else printf("%d\n", query_tree(1,n,a,b,1));
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgZW5kbCAnXG4nCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IFNJWkUgPSAxPDwxNzsKY29uc3QgaW50IFRSRUVfU0laRSA9IFNJWkU8PDI7CgpzdHJ1Y3QgTm9kZSB7CiAgaW50IGEwLGExLGEyOwp9OwoKaW50IG47CmludCBxOwppbnQgdHlwZSxhLGI7CmludCBpOwpOb2RlIHRyZWVbVFJFRV9TSVpFXTsKaW50IGxhenlbVFJFRV9TSVpFXTsKCnZvaWQgYnVpbGRfdHJlZShpbnQgYSwgaW50IGIsIGludCBub2RlKSB7CiAgaWYoYT5iKSByZXR1cm47CiAgaWYoYT09YikgewogICAgdHJlZVtub2RlXS5hMD0xOwogICAgdHJlZVtub2RlXS5hMT0wOwogICAgdHJlZVtub2RlXS5hMj0wOwogICAgcmV0dXJuOwogIH0KICB0cmVlW25vZGVdLmEwPWItYSsxOwogIHRyZWVbbm9kZV0uYTE9MDsKICB0cmVlW25vZGVdLmEyPTA7CiAgYnVpbGRfdHJlZShhLChhK2IpPj4xLG5vZGU8PDEpOwogIGJ1aWxkX3RyZWUoKChhK2IpPj4xKSsxLGIsKG5vZGU8PDEpfDEpOwp9Cgp2b2lkIHVwZGF0ZV90cmVlKGludCBhLCBpbnQgYiwgaW50IGksIGludCBqLCBpbnQgbm9kZSkgewogIHdoaW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