/*
ID: untamed
PROG: COOLPROBLEM
LANG: C++
*/
#include<iostream>
#include<string>
using namespace std;
string s;
int tree[1<<19];
int lazy[1<<19];
int n,q;
int sum_of_digits(int p)//Returns the sum of digits of a number
{
int h=0;
while(p)
{
h+=p%10;
p/=10;
}
return h;
}
void input()//Reading the string and the number of queries
{
cin>>s;
n=s.size();
s="A"+s;//Let's make it 1-based
cin>>q;
}
void Build_tree(int a, int b, int node)
{
if(a>b)//Bad
return;
if(a==b)//Leaf node
{
int d=((s[a]-'0')<<1);//Multiplying the digit by 2
tree[node]=sum_of_digits(d);
return;
}
Build_tree(a,(a+b)>>1,node<<1);
Build_tree(((a+b)>>1)+1,b,(node<<1)|1);
tree[node]=tree[node<<1]+tree[(node<<1)|1];
}
void Update_tree(int a, int b, int i, int j, int node, int value)
{
if(lazy[node])//We have to change all digits to lazy[node]
{
tree[node]=(b-a+1)*(lazy[node]<<1);
if(a!=b)//It has got children
{
lazy[node<<1]=lazy[node];
lazy[(node<<1)|1]=lazy[node];
}
lazy[node]=0;
}
if(a>b || a>j || b<i)//Out of range
return;
if(a>=i && b<=j)//Totally fits in the range
{
tree[node]=(b-a+1)*sum_of_digits(value<<1);
if(a!=b)//It has got children
{
lazy[node<<1]=value;
lazy[(node<<1)|1]=value;
}
return;
}
Update_tree(a,(a+b)>>1,i,j,node<<1,value);
Update_tree(((a+b)>>1)+1,b,i,j,(node<<1)|1,value);
tree[node]=tree[node<<1]+tree[(node<<1)|1];
}
int Query_tree(int a, int b, int i, int j, int node)
{
if(a>b || a>j || b<i)//Out of range
return 0;
if(lazy[node])//We have to change all digits to lazy[node]
{
tree[node]=(b-a+1)*(lazy[node]<<1);
if(a!=b)//It has got children
{
lazy[node<<1]=lazy[node];
lazy[(node<<1)|1]=lazy[node];
}
lazy[node]=0;
}
if(a>=i && b<=j)//Totally fits in the range
return tree[node];
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;
}
void solve()
{
Build_tree(1,n,1);
int type,i,a,b,v;
//type=0 means update
//type=1 means query
for(i=1;i<=q;i++)
{
cin>>type;
if(type==0)
{
cin>>a>>b>>v;
a++;b++;//It's 1-based
Update_tree(1,n,a,b,1,v);
}
else
{
cout<<Query_tree(1,n,1,n,1)<<'\n';
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
input();
solve();
return 0;
}
LyoKSUQ6IHVudGFtZWQKUFJPRzogQ09PTFBST0JMRU0KTEFORzogQysrCiovCgojaW5jbHVkZTxpb3N0cmVhbT4KI2luY2x1ZGU8c3RyaW5nPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnN0cmluZyBzOwoKaW50IHRyZWVbMTw8MTldOwppbnQgbGF6eVsxPDwxOV07CgppbnQgbixxOwoKaW50IHN1bV9vZl9kaWdpdHMoaW50IHApLy9SZXR1cm5zIHRoZSBzdW0gb2YgZGlnaXRzIG9mIGEgbnVtYmVyCnsKICAgIGludCBoPTA7CiAgICB3aGlsZShwKQogICAgewogICAgICAgIGgrPXAlMTA7CiAgICAgICAgcC89MTA7CiAgICB9CiAgICByZXR1cm4gaDsKfQoKdm9pZCBpbnB1dCgpLy9SZWFkaW5nIHRoZSBzdHJpbmcgYW5kIHRoZSBudW1iZXIgb2YgcXVlcmllcwp7CiAgICBjaW4+PnM7CiAgICBuPXMuc2l6ZSgpOwogICAgcz0iQSIrczsvL0xldCdzIG1ha2UgaXQgMS1iYXNlZAogICAgY2luPj5xOwp9Cgp2b2lkIEJ1aWxkX3RyZWUoaW50IGEsIGludCBiLCBpbnQgbm9kZSkKewogICAgaWYoYT5iKS8vQmFkCiAgICAgICAgcmV0dXJuOwogICAgaWYoYT09YikvL0xlYWYgbm9kZQogICAgewogICAgICAgIGludCBkPSgoc1thXS0nMCcpPDwxKTsvL011bHRpcGx5aW5nIHRoZSBkaWdpdCBieSAyCiAgICAgICAgdHJlZVtub2RlXT1zdW1fb2Z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XJ5CiAgICBmb3IoaT0xO2k8PXE7aSsrKQogICAgewogICAgICAgIGNpbj4+dHlwZTsKICAgICAgICBpZih0eXBlPT0wKQogICAgICAgIHsKICAgICAgICAgICAgY2luPj5hPj5iPj52OwogICAgICAgICAgICBhKys7YisrOy8vSXQncyAxLWJhc2VkCiAgICAgICAgICAgIFVwZGF0ZV90cmVlKDEsbixhLGIsMSx2KTsKICAgICAgICB9CiAgICAgICAgZWxzZQogICAgICAgIHsKICAgICAgICAgICAgY291dDw8UXVlcnlfdHJlZSgxLG4sMSxuLDEpPDwnXG4nOwogICAgICAgIH0KICAgIH0KfQoKaW50IG1haW4oKQp7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKICAgIGNpbi50aWUoTlVMTCk7CiAgICBpbnB1dCgpOwogICAgc29sdmUoKTsKICAgIHJldHVybiAwOwp9Cg==