# HDU-3555:Bomb

### Description

The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the time bomb. The number sequence of the time bomb counts from 1 to N. If the current number sequence includes the sub-sequence "49", the power of the blast would add one point.
Now the counter-terrorist knows the number N. They want to know the final points of the power. Can you help them?

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
using namespace std;
int t;LL a;
LL n,f,ans;
int work(LL x)
{
int re=0;
while(x) a[++re]=x%10,x/=10;
return re;
}
int main()
{
scanf("%d",&t);
f=1;
for(int i=1;i<=22;i++)
{
f[i]=f[i-1]*10-f[i-1];
f[i]=f[i-1];
f[i]=f[i-1]+f[i-1]*10;
}
while(t--)
{
ans=0;
scanf("%lld",&n);n++;
int len=work(n);
a[len+1]=0;
bool flag=0;
for(int i=len;i>0;i--)
{
ans+=f[i-1]*a[i];
if(flag) ans+=f[i-1]*a[i];
if(!flag&&a[i]>4)ans+=f[i-1];
if(a[i+1]==4&&a[i]==9) flag=1;
}
printf("%lld\n",ans);
}
return 0;
}