#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#define ll long long int
#define MAX 100000+10
#define ull unsigned long long int
#define gcd(a,b) __gcd(a,b)
using namespace std;
struct info
{
int zero,one,two,lazy;
} tree[MAX*5];
void update_lazy(int node)
{
int temp = tree[node].zero;
tree[node].zero = tree[node].two;
tree[node].two = tree[node].one;
tree[node].one = temp;
}
void update_node(int node,int left)
{
tree[left].lazy += tree[node].lazy;
tree[left+1].lazy += tree[node].lazy;
tree[node].lazy%=3;
int shift = tree[node].lazy;
while(shift--)
{
update_lazy(left);
update_lazy(left+1);
}
tree[node].lazy=0;
}
void marge(int node, int left, int right)
{
tree[node].zero= tree[left].zero + tree[right].zero;
tree[node].one= tree[left].one + tree[right].one;
tree[node].two= tree[left].two + tree[right].two;
}
void build(int node, int b, int e)
{
if (b == e)
{
tree[node].one = 0;
tree[node].two = 0;
tree[node].lazy = 0;
tree[node].zero = 1;
return;
}
int Left = node * 2;
int Right = node * 2 + 1;
int mid = (b + e) / 2;
build(Left, b, mid);
build(Right, mid + 1, e);
marge(node,Left,Right);
}
void update(int node, int l, int r, int i, int j)
{
//cout<<node<<" "<<l<<" "<<r<<" "<<i<<" "<<j<<endl;
int Left = node*2;
if(tree[node].lazy!=0){
update_node(node,Left);
}
//no overlap
if(l>r || l>j || r<i) return;
//total overlap
if(l>=i && r<=j){
tree[node].lazy++;
update_lazy(node);
return;
}
//partial overlap
int mid = (l+r)/2;
update(Left,l,mid,i,j);
update(Left+1,mid+1,r,i,j);
marge(node,Left,Left+1);
}
int query(int node,int l,int r,int i,int j)
{
if(l>r || l>j || r<i) return 0;
if(tree[node].lazy!=0){
update_node(node,node*2);
}
if(l>=i && r<=j) return tree[node].zero;
int mid = (l+r)/2;
int Left = node*2;
return query(Left,l,mid,i,j) + query(Left+1,mid+1,r,i,j);
}
int main()
{
int t,no=0;
// scanf("%d",&t);
// while(t--)
{
int n,q,a;
scanf("%d %d",&n,&q);
memset(tree,0,sizeof(tree));
build(1,1,n);
printf("Case %d:\n",++no);
while(q--)
{
int type,l,r;
scanf("%d %d %d",&type,&l,&r);
l++;
r++;
if(type == 0)
{
update(1,1,n,l,r);
}
else
{
printf("%d\n",query(1,1,n,l,r));
}
}
}
return 0;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8c3RyaW5nLmg+CiNpbmNsdWRlIDxzdGRib29sLmg+CiNpbmNsdWRlIDxtYXRoLmg+CiNkZWZpbmUgbGwgbG9uZyBsb25nIGludAojZGVmaW5lIE1BWCAxMDAwMDArMTAKI2RlZmluZSB1bGwgdW5zaWduZWQgbG9uZyBsb25nIGludAojZGVmaW5lIGdjZChhLGIpICAgIF9fZ2NkKGEsYikKCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpzdHJ1Y3QgaW5mbwp7CiAgICBpbnQgemVybyxvbmUsdHdvLGxhenk7Cn0gdHJlZVtNQVgqNV07Cgp2b2lkIHVwZGF0ZV9sYXp5KGludCBub2RlKQp7CiAgICBpbnQgdGVtcCA9IHRyZWVbbm9kZV0uemVybzsKICAgIHRyZWVbbm9kZV0uemVybyA9IHRyZWVbbm9kZV0udHdvOwogICAgdHJlZVtub2RlXS50d28gPSB0cmVlW25vZGVdLm9uZTsKICAgIHRyZWVbbm9kZV0ub25lID0gdGVtcDsKfQoKdm9pZCB1cGRhdGVfbm9kZShpbnQgbm9kZSxpbnQgbGVmdCkKewogICAgdHJlZVtsZWZ0XS5sYXp5ICs9ICB0cmVlW25vZGVdLmxhenk7CiAgICB0cmVlW2xlZnQrMV0ubGF6eSArPSAgdHJlZVtub2RlXS5sYXp5OwoKICAgIHRyZWVbbm9kZV0ubGF6eSU9MzsKICAgIGludCBzaGlmdCA9IHRyZWVbbm9kZV0ubGF6eTsKICAgIHdoaWxlKHNoaWZ0LS0pCiAgICB7CiAgICAgICAgdXBkYXRlX2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iwrK25vKTsKICAgICAgICB3aGlsZShxLS0pCiAgICAgICAgewogICAgICAgICAgICBpbnQgdHlwZSxsLHI7CiAgICAgICAgICAgIHNjYW5mKCIlZCAlZCAlZCIsJnR5cGUsJmwsJnIpOwogICAgICAgICAgICBsKys7CiAgICAgICAgICAgIHIrKzsKCiAgICAgICAgICAgIGlmKHR5cGUgPT0gMCkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgdXBkYXRlKDEsMSxuLGwscik7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBwcmludGYoIiVkXG4iLHF1ZXJ5KDEsMSxuLGwscikpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQoKICAgIHJldHVybiAwOwp9Cg==