#include<bits/stdc++.h>
using namespace std;
int tree[400001][3];
int lazy[400001];
int query( int node , int i , int j , int s , int e )
{
if(lazy[node] != 0)
{
if( i!= j )
{
lazy[2*node] = (lazy[node] + lazy[2*node])%3;
lazy[2*node+1] = ( lazy[node] + lazy[2*node+1])%3;
}
int a = tree[node][0];
int b = tree[node][1];
int c = tree[node][2];
tree[node][1] = a;
tree[node][2] = b;
tree[node][0] = c;
if(lazy[node] == 2)
{
int a = tree[node][0];
int b = tree[node][1];
int c = tree[node][2];
tree[node][1] = a;
tree[node][2] = b;
tree[node][0] = c;
}
lazy[node] = 0;
}
if( i > j || s > j || e < i )
return 0;
if(s <= i && e >= j )
return tree[node][0];
return query(2*node , i , (i+j)>>1 , s , e ) + query(2*node + 1 , ((i+j)>>1)+1 , j , s , e );
}
void update( int node , int i , int j , int s , int e )
{
if(lazy[node] != 0)
{
if( i!= j )
{
lazy[2*node] = ( lazy[node] + lazy[2*node])%3;
lazy[2*node+1] = ( lazy[node] + lazy[2*node+1])%3;
}
int a = tree[node][0];
int b = tree[node][1];
int c = tree[node][2];
tree[node][1] = a;
tree[node][2] = b;
tree[node][0] = c;
if(lazy[node] == 2)
{
int a = tree[node][0];
int b = tree[node][1];
int c = tree[node][2];
tree[node][1] = a;
tree[node][2] = b;
tree[node][0] = c;
}
lazy[node] = 0;
}
if( i > j || s > j || e < i )
return;
if(s <= i && e >= j )
{
int a = tree[node][0];
int b = tree[node][1];
int c = tree[node][2];
tree[node][1] = a;
tree[node][2] = b;
tree[node][0] = c;
if( i != j )
{
lazy[2*node] = ( 1 + lazy[2*node])%3;
lazy[2*node+1] = ( 1 + lazy[2*node+1])%3;
}
return;
}
update(2*node , i , (i+j)>>1 , s , e );
update(2*node + 1 , ((i+j)>>1)+1 , j , s , e );
tree[node][0] = tree[2*node][0] + tree[2*node+1][0];
tree[node][1] = tree[2*node][1] + tree[2*node+1][1];
tree[node][2] = tree[2*node][2] + tree[2*node+1][2];
}
void build(int node , int i , int j )
{
if( i > j )
return;
if(i == j)
tree[node][0] = 1;
else
{
build(2*node , i , (i+j) >> 1);
build(2*node+1 , ((i+j) >> 1) + 1 , j);
tree[node][0] = tree[2*node][0] + tree[2*node+1][0];
}
}
int main(){
int n , q;
scanf("%d%d",&n,&q);
build( 1 , 0 , n - 1);
while( q-- )
{
int ch , l , r;
scanf("%d%d%d",&ch,&l,&r);
if(ch == 0)
update( 1 , 0 , n - 1 , l , r );
else
printf("%d\n" , query( 1 , 0 , n - 1 , l , r ));
}
return 0;
}
using namespace std;
int tree[400001][3];
int lazy[400001];
int query( int node , int i , int j , int s , int e )
{
if(lazy[node] != 0)
{
if( i!= j )
{
lazy[2*node] = (lazy[node] + lazy[2*node])%3;
lazy[2*node+1] = ( lazy[node] + lazy[2*node+1])%3;
}
int a = tree[node][0];
int b = tree[node][1];
int c = tree[node][2];
tree[node][1] = a;
tree[node][2] = b;
tree[node][0] = c;
if(lazy[node] == 2)
{
int a = tree[node][0];
int b = tree[node][1];
int c = tree[node][2];
tree[node][1] = a;
tree[node][2] = b;
tree[node][0] = c;
}
lazy[node] = 0;
}
if( i > j || s > j || e < i )
return 0;
if(s <= i && e >= j )
return tree[node][0];
return query(2*node , i , (i+j)>>1 , s , e ) + query(2*node + 1 , ((i+j)>>1)+1 , j , s , e );
}
void update( int node , int i , int j , int s , int e )
{
if(lazy[node] != 0)
{
if( i!= j )
{
lazy[2*node] = ( lazy[node] + lazy[2*node])%3;
lazy[2*node+1] = ( lazy[node] + lazy[2*node+1])%3;
}
int a = tree[node][0];
int b = tree[node][1];
int c = tree[node][2];
tree[node][1] = a;
tree[node][2] = b;
tree[node][0] = c;
if(lazy[node] == 2)
{
int a = tree[node][0];
int b = tree[node][1];
int c = tree[node][2];
tree[node][1] = a;
tree[node][2] = b;
tree[node][0] = c;
}
lazy[node] = 0;
}
if( i > j || s > j || e < i )
return;
if(s <= i && e >= j )
{
int a = tree[node][0];
int b = tree[node][1];
int c = tree[node][2];
tree[node][1] = a;
tree[node][2] = b;
tree[node][0] = c;
if( i != j )
{
lazy[2*node] = ( 1 + lazy[2*node])%3;
lazy[2*node+1] = ( 1 + lazy[2*node+1])%3;
}
return;
}
update(2*node , i , (i+j)>>1 , s , e );
update(2*node + 1 , ((i+j)>>1)+1 , j , s , e );
tree[node][0] = tree[2*node][0] + tree[2*node+1][0];
tree[node][1] = tree[2*node][1] + tree[2*node+1][1];
tree[node][2] = tree[2*node][2] + tree[2*node+1][2];
}
void build(int node , int i , int j )
{
if( i > j )
return;
if(i == j)
tree[node][0] = 1;
else
{
build(2*node , i , (i+j) >> 1);
build(2*node+1 , ((i+j) >> 1) + 1 , j);
tree[node][0] = tree[2*node][0] + tree[2*node+1][0];
}
}
int main(){
int n , q;
scanf("%d%d",&n,&q);
build( 1 , 0 , n - 1);
while( q-- )
{
int ch , l , r;
scanf("%d%d%d",&ch,&l,&r);
if(ch == 0)
update( 1 , 0 , n - 1 , l , r );
else
printf("%d\n" , query( 1 , 0 , n - 1 , l , r ));
}
return 0;
}