#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,j,k,l=0,m,n,p,q;
    string a,b,c;
    int x[100005]={0};
    vector <int> v1,v2;
    cin>>a;
    cin>>k;
    m=a.size();
    q=m+k;
    for(i=0;i<26;i++){
        cin>>p;
        v1.push_back(p);
    }
    v2=v1;
    for(i=0;i<a.size();i++){
        k=a[i]-'a';
        x[i]=v1[k];
    }
    for(i=0;i<a.size();i++){
        l+=(i+1)*x[i];
        //cout<<i+1<<endl;
    }
    sort(v2.begin(),v2.end());
    for(j=m;j<q;j++){
        l+=(j+1)*v2[25];
    }
    cout<<l<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,j,k,l=0,m,n,p,q;
    string a,b,c;
    int x[27]={0};
    vector <int> v1,v2;
    cin>>a;
    cin>>k;
    m=a.size();
    q=m+k;
    for(i=0;i<26;i++){
        cin>>p;
        v1.push_back(p);
    }
    v2=v1;
    for(i=0;i<a.size();i++){
        k=a[i]-'a';
        x[i]=v1[k];
    }
    for(i=0;i<a.size();i++){
        l+=(i+1)*x[i];
        //cout<<i+1<<endl;
    }
    sort(v2.begin(),v2.end());
    for(j=m;j<q;j++){
        l+=(j+1)*v2[25];
    }
    cout<<l<<endl;
    return 0;
}


//Lets create a history !
#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007
#define maxx ((ll)1e6+5)
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
#define int long long
#define INF 1000000000000000005
#define N 200005
ll fpow(ll x,ll y,ll p=MOD){x=x%p;ll sum=1;while(y){if(y&1)sum=sum*x;sum%=p;y=y>>1;x=x*x;x%=p;}return sum;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%MOD;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(fpow(fact[r],MOD-2)))%MOD; res=(res*(fpow(fact[n-r],MOD-2)))%MOD; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(fpow(fact[n-r],MOD-2)))%MOD; return res;}
ll modmul(ll x, ll y){return (x*y)%MOD;}
ll modadd(ll x, ll y){return (x+y)%MOD;}
ll modsub(ll x, ll y){return (x-y+MOD)%MOD;}
using namespace std;

signed main(){
    string s;
    cin>>s;
    int k;
    cin>>k;
    int a[26];
    int j=0;
    int maxi=0;
    for(int i=0;i<26;i++){
        cin>>a[i];
        if(a[i]>maxi){
            maxi=a[i];
            j=i;
        }
    }
    cout<<s;
    for(int i=0;i<k;i++){
        cout<<char(j+'a');
    }

}


//Lets create a history !
#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007
#define maxx ((ll)1e6+5)
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
#define int long long
#define INF 1000000000000000005
#define N 200005
ll fpow(ll x,ll y,ll p=MOD){x=x%p;ll sum=1;while(y){if(y&1)sum=sum*x;sum%=p;y=y>>1;x=x*x;x%=p;}return sum;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%MOD;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(fpow(fact[r],MOD-2)))%MOD; res=(res*(fpow(fact[n-r],MOD-2)))%MOD; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(fpow(fact[n-r],MOD-2)))%MOD; return res;}
ll modmul(ll x, ll y){return (x*y)%MOD;}
ll modadd(ll x, ll y){return (x+y)%MOD;}
ll modsub(ll x, ll y){return (x-y+MOD)%MOD;}
using namespace std;

signed main(){
    string s;
    cin>>s;
    int k;
    cin>>k;
    int a[26];
    int j=0;
    int maxi=0;
    for(int i=0;i<26;i++){
        cin>>a[i];

        maxi=max(maxi,a[i]);
    }
    int ans=0;
    for(int i=0;i<s.length();i++){
        ans+=(i+1)*a[s[i]-'a'];
    }
    for(int j=s.length()+1;j<=s.length()+k;j++){
        ans+=maxi*j;
    }

    cout<<ans;

}


#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int k;
	cin>>k;
	int n=26;
	int w[n+1];
	for(int i=1;i<=n;i++){
		cin>>w[i];
	}
	int max= *max_element(w+1, w+n+1);
	int l=s.length();

    int score=0;
    for(int i=0;i<l;i++){
    	 for (int j=0;j<26;j++){
    	 	if(s[i]==char(j+'a')){
    	 	score=score+(i+1)*w[j];
    	 	}

		 }
	}
	for(int o=l+1;o<=l+k;o++){
		score=score+o*max;
	}
	cout<<score;
	return 0;
	}


#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int k;
	cin>>k;
	int n=26;
	int w[n+1];
	for(int i=1;i<=n;i++){
		cin>>w[i];
	}
	int max= *max_element(w+1, w+n+1);
	int l=s.length();

    int score=0;
    for(int i=0;i<l;i++){
    	 for (int j=0;j<26;j++){
    	 	if(s[i]==char(j+'a')){
    	 	score=score+(i+1)*w[j+1];
    	 	}

		 }
	}
	for(int o=l+1;o<=l+k;o++){
		score=score+o*max;
	}
	cout<<score;
	return 0;
	}


#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int k;
	cin>>k;
	int n=26;
	int w[n];
	for(int i=0;i<n;i++){
		cin>>w[i];
	}
	int max= *max_element(w, w+n);
	int l=s.length();

    int score=0;
    for(int i=0;i<l;i++){
    	 for (int j=0;j<26;j++){
    	 	if(s[i]==char(j+'a')){
    	 	score=score+(i+1)*w[j];
    	 	}

		 }
	}
	for(int o=l+1;o<=l+k;o++){
		score=score+o*max;
	}
	cout<<score;
	return 0;
	}


#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int k;
	cin>>k;
	int n=26;
	int w[n+1];
	for(int i=1;i<=n;i++){
		cin>>w[i];
	}
	int max= *max_element(w+1, w+n+1);
	int l=s.length();
	map< char, int > mp;
	map<char, int>::iterator it ;
	for(int i=0;i<26;i++){
        mp[char(i+'a')]=w[i+1];
	}

    int score=0;
    for(int i=0;i<l;i++){
    	 for (auto j : mp){
    	 	if(s[i]==j.first){
    	 	score=score+(i+1)*j.second;
    	 	}

		 }
	}
	for(int o=l+1;o<=l+k;o++){
		score=score+o*max;
	}
	cout<<score;
	return 0;
	}


#include <bits/stdc++.h>
using namespace std;
string s;
int k, mx = -4, in, cur;
int check(string s, int c)
{
	int cnt = 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] != s[i - 1])
			cnt = i - 1;
	}
	s = substring(cnt, s.size() - 1);
	return c * cnt;
}
int main()
{
	cin >> s >> k;
	sort(s.begin(), s.end());
	for (char i = 'a'; i <= 'z'; i++)
	{
		cin >> in;
		cur += check(s, in);
		mx = max(mx, max);
	}
	cout << cur + (k * mx);
}


#include <bits/stdc++.h>
using namespace std;
string s;
int k, mx = -4, in, cur;
int check(string &s, int c)
{
	int cnt = 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] != s[i - 1])
			cnt = i - 1;
	}
	s = s.substr(cnt, s.size() - 1);
	return c * cnt;
}
int main()
{
	cin >> s >> k;
	sort(s.begin(), s.end());
	for (char i = 'a'; i <= 'z'; i++)
	{
		cin >> in;
		cur += check(s, in);
		mx = max(mx, in);
	}
	cout << cur + (k * mx);
}


#include <bits/stdc++.h>
using namespace std;
string s;
int k, mx = -4, in, cur;
int check(string &s, int c)
{
	int cnt = 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] != s[i - 1])
			cnt = i - 1;
	}
	s = substring(cnt, s.size() - 1);
	return c * cnt;
}
int main()
{
	cin >> s >> k;
	sort(s.begin(), s.end());
	for (char i = 'a'; i <= 'z'; i++)
	{
		cin >> in;
		cur += check(s, in);
		mx = max(mx, max);
	}
	cout << cur + (k * mx);
}


#include <bits/stdc++.h>
using namespace std;
string s;
int k, mx = -4, in, cur;
int check(string s, int c, char l)
{
	int cnt = 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] != s[i - 1] && s[i - 1] == l)
			cnt = i - 1;
	}
	s = s.substr(cnt, s.size() - 1);
	return c * cnt;
}
int main()
{
	cin >> s >> k;
	sort(s.begin(), s.end());
	for (char i = 'a'; i <= 'z'; i++)
	{
		cin >> in;
		cur += check(s, in, i);
		mx = max(mx, in);
	}
	cout << cur + (k * mx);
}


#include <bits/stdc++.h>
using namespace std;
string s;
int k, mx = -4, in, cur;
int check(string s, int c)
{
	int cnt = 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] != s[i - 1])
			cnt = i - 1;
	}
	s = s.substr(cnt, s.size() - 1);
	return c * cnt;
}
int main()
{
	cin >> s >> k;
	sort(s.begin(), s.end());
	for (char i = 'a'; i <= 'z'; i++)
	{
		cin >> in;
		cur += check(s, in);
		mx = max(mx, in);
	}
	cout << cur + (k * mx);
}


#include <bits/stdc++.h>
using namespace std;
string s;
int k, mx = -4, in, cur;
int check(string &s, int c)
{
	int cnt = 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] != s[i - 1])
			cnt = i - 1;
	}
	s = substr(cnt, s.size() - 1);
	return c * cnt;
}
int main()
{
	cin >> s >> k;
	sort(s.begin(), s.end());
	for (char i = 'a'; i <= 'z'; i++)
	{
		cin >> in;
		cur += check(s, in);
		mx = max(mx, in);
	}
	cout << cur + (k * mx);
}


#include <bits/stdc++.h>
using namespace std;
string s;
int k, mx = -4, in, cur;
int check(string &s, int c)
{
	int cnt = 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] != s[i - 1])
			cnt = i - 1;
	}
	s = substring(cnt, s.size() - 1);
	return c * cnt;
}
int main()
{
	cin >> s >> k;
	sort(s.begin(), s.end());
	for (char i = 'a'; i <= 'z'; i++)
	{
		cin >> in;
		cur += check(s, in);
		mx = max(mx, in);
	}
	cout << cur + (k * mx);
}


#include <bits/stdc++.h>
using namespace std;
int k, a[26], m, n, i, l;
string s;
int main()
{
	cin >> s >> k;
	for (i = 0; i < 26; i++)
	{
		cin >> a[i];
		m = max(m, a[i]);
	}
	for (i = 0; i < s.size() + k; i++)
	{
		if (i < s.size())
		{
			l = s[i] - 'a';
			n = n + (i + 1) * a[l];
		}
		else
			n = n + (i + 1) * m;
	}
	cout << n;
}


#include <bits/stdc++.h>

using namespace std;

long long int ans = 0, k;
string s;

int main() {
	cin >> s;
	cin >> k;
	int maximum = -1;
	vector<int> v;
	for (int i = 0; i < 26; ++i) {
		int x;
		cin >> x;
		v.push_back(x);
		maximum = max(x, maximum);
	}
	for (int i = 1; i <= s.size() + k; ++i) {
		if (i < k) {
			ans += (s[i] - 'a') * (i);
		} else {
			ans += i * maximum;
		}
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long int ans = 0, k;
string s;

int main() {
	cin >> s;
	cin >> k;
	int maximum = -1;
	vector<int> v;
	for (int i = 0; i < 26; ++i) {
		int x;
		cin >> x;
		v.push_back(x);
		maximum = max(x, maximum);
	}
	for (int i = 0; i < s.size() + k; ++i) {
		if (i < k) {
			ans += v[s[i] - 'a'] * (i + 1);
		} else {
			ans += (i + 1) * maximum;
		}
		// cout << ans << endl;
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long int ans = 0, k;
string s;

int main() {
	cin >> s;
	cin >> k;
	int maximum = -1;
	vector<int> v;
	for (int i = 0; i < 26; ++i) {
		int x;
		cin >> x;
		v.push_back(x);
		maximum = max(x, maximum);
	}
	for (int i = 0; i < s.size() + k; ++i) {
		if (i < s.size()) {
			ans += v[s[i] - 97] * (i + 1);
		} else {
			ans += (i + 1) * maximum;
		}
		// cout << ans << endl;
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long int ans = 0, k;
string s;

int main() {
	cin >> s;
	cin >> k;
	int maximum = -1;
	vector<int> v;
	for (int i = 0; i < 26; ++i) {
		int x;
		cin >> x;
		v.push_back(x);
		maximum = max(x, maximum);
	}
	for (int i = 1; i <= s.size() + k; ++i) {
		if (i < k) {
			ans += (s[i] - 'a') * (i);
			cout << ans << endl;
		} else {
			ans += i * maximum;
		}
	}
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;

int main()
{
    char s[1000];
    cin>>s;
    int l=strlen(s);
    int k;
    cin>>k;
    int a[26];
    int max=0;
   for(int i=1;i<=26;i++)
   {
       cin>>a[i];
       if(a[i]>max)
            max=a[i];
   }

    int sum=0;
    for(int i=0;i<l+k;i++)
    {
        if(i<l)
            sum=sum+a[s[i]%96]*(i+1);

        else
            sum=sum+(i+1)*max;
    }
    cout<<sum;
}


#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;

int main()
{
    char s[1001];
    cin>>s;
    int l=strlen(s);
    int k;
    cin>>k;
    int a[27];
    int max=0;
   for(int i=1;i<=26;i++)
   {
       cin>>a[i];
     //  cout<<a[i];
      //  if(a[i]>max)
       //     max=a[i];
   }

  for(int i=1;i<=26;i++)
   {
    //   cin>>a[i];
        if(a[i]>max)
            max=a[i];
   }
//cout<<max;
    long long int  sum=0;
    for(int i=0;i<l;i++)
    {
        if(i<l)
            sum=sum+a[s[i]%96]*(i+1);

    }
    sum=sum + (long long int)(k + l * 2 + 1)*k *max / 2;
    cout<<sum;
}


#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<functional>
#include<deque>
// C
#include<cstdio>
#include<cstring>
#include<ctime>
#include<cctype>
#include<cmath>
// namespace
using namespace std;
// typedef
typedef long long lli;
typedef unsigned long long ull;
// const variable
#define MAX_N 1000
#define MAX_M 1000
#define INF 2e9
#define NONE -1
const double PI = 2.0 * acos(0.0);
int main(){
	char str[1001];
	while (scanf("%s", str) == 1){
		int k, V[26], m = 0;
		lli ans = 0;
		scanf("%d", &k);
		for (int i = 0; i < 26; i++)
			scanf("%d", V + i);
		for (int i = 0; i < 26; i++)
			m = max(V[i], m);
		for (int i = 0; str[i] != '\0'; i++)
			ans += V[(str[i] - 'a')] * (i + 1);
		ans += (long long int)(k + strlen(str) * 2 + 1)*k *m / 2;
		printf("%lld\n", ans);
	}
	return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;

int main()
{
    char s[1000];
    cin>>s;
    int l=strlen(s);
    int k;
    cin>>k;
    int a[26];
    int max=0;
   for(int i=1;i<=26;i++)
   {
       cin>>a[i];
       if(a[i]>max)
            max=a[i];
   }

    long long int  sum=0;
    for(int i=0;i<l;i++)
    {
        if(i<l)
            sum=sum+a[s[i]%96]*(i+1);

    }
        sum=sum + (long long int)(k + l * 2 + 1)*k *max / 2;
    cout<<sum;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz 100000
int main()
{
    string s;
    cin>>s;
    int n,m,counter=0,sum=0;
    cin>>n;
    int a[26],i;
    for(i=0;i<26;i++)
        cin>>a[i];
    for(i=1;i<=s.length();i++)
        sum+=i*a[s[i-1]-'a'];
    sort(a,a+26);
    for(i=s.length()+1;;i++)
    {
        sum+=i*a[25];
        counter++;
        if(counter==n) break;
    }
    cout<<sum<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz 100000
int main()
{
    string s;
    cin>>s;
    int n,m,counter=0,sum=0;
    cin>>n;
    int a[26],i;
    for(i=0;i<26;i++)
        cin>>a[i];
    for(i=1;i<=s.length();i++)
        sum+=i*a[s[i-1]-'a'];
    sort(a,a+26);
    int maxi=a[25];
    for(i=s.length()+1;i<=s.length()+n;i++)
    {
        sum+=i*maxi;
        counter++;

    }
    cout<<sum<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz 100000
int main()
{
    string s;
    cin>>s;
    int n,m,counter=0,sum=0;
    cin>>n;
    int a[26],i;
    for(i=0;i<26;i++)
        cin>>a[i];
    for(i=1;i<=s.length();i++)
        sum+=i*a[s[i-1]-'a'];
    sort(a,a+n);
    for(i=s.length()+1;;i++)
    {
        sum+=i*a[n-1];
        counter++;
        if(counter==n) break;
    }
    cout<<sum<<endl;
}


#include <iostream>
#include <bits/stdc++.h>
//typedef long long  ll;
#define ll long long
#define ld long double
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;

ll gcd(ll a, ll b)
{
    if (!a)
        return b;
    return gcd(b%a,a);
}

ll lcm(ll a, ll b)
{
    return (a*b)/gcd(a, b);
}

bool isPrime(ll n)
{
    if (n <= 1)
        return false;
    for (ll i = 2; i < n; i++)
        if (n % i == 0)
            return false;
    return true;
}

ll fast_power(ll x, unsigned ll y)
{
    if (y == 0)
        return 1;
    else if (y%2 == 0)
        return fast_power(x, y/2)*fast_power(x, y/2);
    else
        return x*fast_power(x, y/2)*fast_power(x, y/2);
}

// stoi convert string to int
// stol convert string to long int

/*
vector<ll>Divisors;
void printDivisors(ll n)
{
    for (ll i=1; i<=sqrt(n); i++)
    {
        if (n%i == 0)
        {
            if (n/i == i)
                Divisors.push_back(i);

            else
            {
                Divisors.push_back(n/i);
                Divisors.push_back(i);
            }
        }
    }
}
*/
/*
bool prime[1000005];
void SieveOfEratosthenes(ll n)
{

    memset(prime, true, sizeof(prime));

    for (ll p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (ll i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
}
*/

int main()
{

    SPEED
    ll n,x;
    //cin >> n;
    string s;
    cin >> s;
    ll k ;
    cin >> k;
    vector< pair<ll,char> >v;
    map<char,ll>mp;
    for(char a='a';a<='z';a++)
    {
        cin >> x;
        v.push_back(make_pair(x,a));
        mp[a]=x;
    }
    sort(v.rbegin(),v.rend());
    ll i=0;
    while(true)
    {
        if(v[i].first>0)
        {
            s+=v[i].second;
            v[i].first-=1;
            k-=1;
        }
        if(v[i].first==0)
        {
            i++;
        }
        if(k==0)
            break;

    }
    ll ans=0;
    //cout<<s;
    for(ll j=1;j<=s.size();j++)
    {
        ans+=(mp[s[j-1]]*j);
    }
    cout<< ans;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
//typedef long long  ll;
#define ll long long
#define ld long double
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;

ll gcd(ll a, ll b)
{
    if (!a)
        return b;
    return gcd(b%a,a);
}

ll lcm(ll a, ll b)
{
    return (a*b)/gcd(a, b);
}

bool isPrime(ll n)
{
    if (n <= 1)
        return false;
    for (ll i = 2; i < n; i++)
        if (n % i == 0)
            return false;
    return true;
}

ll fast_power(ll x, unsigned ll y)
{
    if (y == 0)
        return 1;
    else if (y%2 == 0)
        return fast_power(x, y/2)*fast_power(x, y/2);
    else
        return x*fast_power(x, y/2)*fast_power(x, y/2);
}

// stoi convert string to int
// stol convert string to long int

/*
vector<ll>Divisors;
void printDivisors(ll n)
{
    for (ll i=1; i<=sqrt(n); i++)
    {
        if (n%i == 0)
        {
            if (n/i == i)
                Divisors.push_back(i);

            else
            {
                Divisors.push_back(n/i);
                Divisors.push_back(i);
            }
        }
    }
}
*/
/*
bool prime[1000005];
void SieveOfEratosthenes(ll n)
{

    memset(prime, true, sizeof(prime));

    for (ll p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (ll i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
}
*/

int main()
{

    SPEED
    ll n=0,x;
    //cin >> n;
    string s;
    cin >> s;
    ll k ;
    cin >> k;
    //vector< pair<ll,char> >v;
    map<char,ll>mp;
    for(char a='a';a<='z';a++)
    {
        cin >> x;
        //v.push_back(make_pair(x,a));
        mp[a]=x;
        if(n<x)
            n=x;
    }
    //sort(v.rbegin(),v.rend());
    ll i=0;

    ll ans=0;
    //cout<<s;
    for(ll j=1;j<=s.size();j++)
    {
        ans+=(mp[s[j-1]]*j);
    }
    for(ll j=s.size()+1;j<=s.size()+k;j++)
        ans+=(n*j);
    cout<< ans;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
//typedef long long  ll;
#define ll long long
#define ld long double
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;

ll gcd(ll a, ll b)
{
    if (!a)
        return b;
    return gcd(b%a,a);
}

ll lcm(ll a, ll b)
{
    return (a*b)/gcd(a, b);
}

bool isPrime(ll n)
{
    if (n <= 1)
        return false;
    for (ll i = 2; i < n; i++)
        if (n % i == 0)
            return false;
    return true;
}

ll fast_power(ll x, unsigned ll y)
{
    if (y == 0)
        return 1;
    else if (y%2 == 0)
        return fast_power(x, y/2)*fast_power(x, y/2);
    else
        return x*fast_power(x, y/2)*fast_power(x, y/2);
}

// stoi convert string to int
// stol convert string to long int

/*
vector<ll>Divisors;
void printDivisors(ll n)
{
    for (ll i=1; i<=sqrt(n); i++)
    {
        if (n%i == 0)
        {
            if (n/i == i)
                Divisors.push_back(i);

            else
            {
                Divisors.push_back(n/i);
                Divisors.push_back(i);
            }
        }
    }
}
*/
/*
bool prime[1000005];
void SieveOfEratosthenes(ll n)
{

    memset(prime, true, sizeof(prime));

    for (ll p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (ll i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
}
*/

int main()
{

    SPEED
    ll n,x;
    //cin >> n;
    string s;
    cin >> s;
    ll k ;
    cin >> k;
    vector< pair<ll,char> >v;
    map<char,ll>mp;
    for(char a='a';a<='z';a++)
    {
        cin >> x;
        v.push_back(make_pair(x,a));
        mp[a]=x;
    }
    sort(v.rbegin(),v.rend());
    ll i=0;
    while(true)
    {
        if(v[i].first>0)
        {
            s+=v[i].second;
            //v[i].first-=1;
            k-=1;
        }

        if(k==0)
            break;

    }
    ll ans=0;
    //cout<<s;
    for(ll j=1;j<=s.size();j++)
    {
        ans+=(mp[s[j-1]]*j);
    }
    cout<< ans;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
//typedef long long  ll;
#define ll long long
#define ld long double
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;

ll gcd(ll a, ll b)
{
    if (!a)
        return b;
    return gcd(b%a,a);
}

ll lcm(ll a, ll b)
{
    return (a*b)/gcd(a, b);
}

bool isPrime(ll n)
{
    if (n <= 1)
        return false;
    for (ll i = 2; i < n; i++)
        if (n % i == 0)
            return false;
    return true;
}

ll fast_power(ll x, unsigned ll y)
{
    if (y == 0)
        return 1;
    else if (y%2 == 0)
        return fast_power(x, y/2)*fast_power(x, y/2);
    else
        return x*fast_power(x, y/2)*fast_power(x, y/2);
}

// stoi convert string to int
// stol convert string to long int

/*
vector<ll>Divisors;
void printDivisors(ll n)
{
    for (ll i=1; i<=sqrt(n); i++)
    {
        if (n%i == 0)
        {
            if (n/i == i)
                Divisors.push_back(i);

            else
            {
                Divisors.push_back(n/i);
                Divisors.push_back(i);
            }
        }
    }
}
*/
/*
bool prime[1000005];
void SieveOfEratosthenes(ll n)
{

    memset(prime, true, sizeof(prime));

    for (ll p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (ll i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
}
*/

int main()
{

    SPEED
    ll n,x;
    //cin >> n;
    string s;
    cin >> s;
    ll k ;
    cin >> k;
    vector< pair<ll,char> >v;
    map<char,ll>mp;
    for(char a='a';a<='z';a++)
    {
        cin >> x;
        v.push_back(make_pair(x,a));
        mp[a]=x;
    }
    sort(v.rbegin(),v.rend());
    ll i=0;
    while(true)
    {
        if(v[i].first>0)
        {
            s+=v[i].second;
            v[i].first-=1;
            k-=1;
        }

        if(k==0)
            break;

    }
    ll ans=0;
    //cout<<s;
    for(ll j=1;j<=s.size();j++)
    {
        ans+=(mp[s[j-1]]*j);
    }
    cout<< ans;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include<vector>
#include <string>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <set>
#include <iterator>
#include <cmath>

using namespace std;

int main()
{
      string s;
      int arr[26];
      int k;
      cin>>s>>k;
      int max=0;
      int pos=0;
      for(int i=0;i<8;i++)
      {
            cin>>arr[i];
            if(arr[i]>max)
            {
                  max=arr[i];
                  pos=i;
            }
      }
      char ch=(char)(pos+97);
      int i=1;
      int ans=0;
      for(;i<=s.length();i++)
      {
            ans=ans+(arr[(((int)s[i-1])-97)]*i);
      }
      for(int j=0;j<k;j++)
      {
            ans=ans+(arr[pos]*i);
            i=i+1;
      }
      cout<<ans;
}


#include <iostream>
#include <bits/stdc++.h>
#include<vector>
#include <string>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <set>
#include <iterator>
#include <cmath>

using namespace std;

int main()
{
      string s;
      int arr[26];
      int k;
      cin>>s>>k;
      int max=0;
      int pos=0;
      for(int i=0;i<26;i++)
      {
            cin>>arr[i];
            if(arr[i]>max)
            {
                  max=arr[i];
                  pos=i;
            }
      }
      char ch=(char)(pos+97);
      int i=1;
      int ans=0;
      for(;i<=s.length();i++)
      {
            ans=ans+(arr[(((int)s[i-1])-97)]*i);
      }
      for(int j=0;j<k;j++)
      {
            ans=ans+(arr[pos]*i);
            i=i+1;
      }
      cout<<ans;
}


#include <iostream>
#include <bits/stdc++.h>
#include<vector>
#include <string>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <set>
#include <iterator>
#include <cmath>

using namespace std;

int main()
{
      string s;
      int arr[26];
      int k;
      cin>>s>>k;
      int max=0;
      int pos=0;
      for(int i=0;i<26;i++)
      {
            cin>>arr[i];
            if(arr[i]>max)
            {
                  max=arr[i];
                  pos=i;
            }
      }
      char ch=(char)(pos+97);
      int i=1;
      cout<<ch<<" "<<pos<<" "<<max<<"\n";
      int ans=0;
      for(;i<=s.length();i++)
      {
            ans=ans+(arr[(((int)s[i-1])-97)]*i);
      }
      cout<<ans<<" "<<i<<"\n";
      for(int j=0;j<k;j++)
      {
            ans=ans+(arr[pos]*i);
            i=i+1;
      }
      cout<<ans<<" "<<i;
}


#include<bits/stdc++.h>
using namespace std;
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long

void solve(){
	string s; cin >> s;
	int k; cin >> k; bool f = true;
	int val[26], mx = 0;
	for(int i = 0; i < 26; i++) {cin >> val[i]; if(val[i] > mx) mx = val[i];}
	for(int j = s.length()-1; j >= 0; j--)
	{
		if(val[s[j]-'a'] < mx) {
			s.insert(j+1,k, mx+'a');
			cout<<s<<endl;
			f = false;
			break;		}
	}
	if(f) s.insert(0,k, mx+'a');
	int ret = 0;
	for(int i = 0; i < s.length(); i++) ret += val[s[i]-'a']*(i+1);
	cout<<ret<<endl;
}

int main(){
	solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long

void solve(){
	string s; cin >> s;
	int k; cin >> k; bool f = true;
	int val[26], mx = 0;
	for(int i = 0; i < 26; i++) {cin >> val[i]; if(val[i] > val[mx]) mx = i;}
	for(int j = s.length()-1; j >= 0; j--)
	{
		if(val[s[j]-'a'] < val[mx]) {
			s.insert(j+1, k, mx+'a');
			f = false;
			break;
		}
	}
	if(f) s.insert(0, k, mx+'a');
	int ret = 0;
	for(int i = 0; i < s.length(); i++) ret += val[s[i]-'a']*(i+1);
	cout<<ret<<endl;
}

int main(){
	solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long

void solve(){
	string s; cin >> s;
	int k; cin >> k; bool f = true;
	int val[26], mx = 0;
	for(int i = 0; i < 26; i++) {cin >> val[i]; if(val[i] > mx) mx = val[i];}
	for(int j = s.length()-1; j >= 0; j--)
	{
		if(val[s[j]-'a'] < mx) {
			s.insert(j+1,k, mx+'a');
			f = false;
			break;
		}
	}
	if(f) s.insert(0,k, mx+'a');
	int ret = 0;
	for(int i = 0; i < s.length(); i++) ret += val[s[i]-'a']*(i+1);
	cout<<ret<<endl;
}

int main(){
	solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct word{
    char ch[26];
    int val[26];
};

int main(){
    int i=0,cnt=0,d=1;
    struct word s;
    for(char ch='a';ch<='z';ch++){
        s.ch[i++]=ch;
        s.val[i]=0;
    }
    char str[1000];
    int k;
    cin>>str;
    cin>>k;
    for(i=0;i<26;i++){
        cin>>s.val[i];
    }
    int len=strlen(str);
    int ar[len],c=0;
    for(i=0;i<26;i++){
        if(s.ch[i]==str[c]){
            ar[c++]=s.val[i];
        }
    }
    c=*max_element(ar,ar+len);
    for(i=0;i<len;i++){
        cnt=cnt+(ar[i]*d++);
    }
    for(i=0;i<k;i++){
        cnt=cnt+(c*d++);
    }
    cout<<cnt;
}


#include<bits/stdc++.h>
using namespace std;
struct word{
    char ch[26];
    int val[26];
};

int main(){
    int i=0,cnt=0,d=1;
    struct word s;
    for(char ch='a';ch<='z';ch++){
        s.ch[i++]=ch;
        s.val[i]=0;
    }
    char str[1000];
    int k;
    cin>>str;
    cin>>k;
    for(i=0;i<26;i++){
        cin>>s.val[i];
    }
    int len=strlen(str);
    int ar[len],c=0;
    for(i=0;i<26;i++){
        if(s.ch[i]==str[c]){
            ar[c++]=s.val[i];
        }
    }
    c=*max_element(s.val,s.val+26);
    for(i=0;i<len;i++){
        cnt=cnt+(ar[i]*d++);
    }
    for(i=0;i<k;i++){
        cnt=cnt+(c*d++);
    }
    cout<<cnt;
}


#include<bits/stdc++.h>
using namespace std;
struct word{
    char ch[26];
    int val[26];
};

int main(){
    int i=0,cnt=0,d=1;
    struct word s;
    for(char ch='a';ch<='z';ch++){
        s.ch[i++]=ch;
    }
    char str[1000];
    int k;
    cin>>str;
    cin>>k;
    for(i=0;i<26;i++){
        cin>>s.val[i];
    }
    int len=strlen(str);
    int ar[len],c=0;
    for(i=0;i<len;i++){
        for(int j=0;j<26;j++){
            if(str[i]==s.ch[j])
                ar[i]=s.val[j];
        }
    }
    c=*max_element(s.val,s.val+26);
    for(i=0;i<len;i++){
        cnt=cnt+(ar[i]*d++);
    }
    for(i=0;i<k;i++){
        cnt=cnt+(c*d++);
    }
    cout<<cnt;
}


#include<bits/stdc++.h>
#define f(i,a,b) for(i=a;i<b;i++)
#define f_(i,a,b) for(i=a;i>=b;i--)
#define T_ ll t; cin>>t; while(t--)
#define NeedForSpeed ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define mod 1000000007
#define mp make_pair
#define read(a,n) for(i=0;i<n;i++) cin>>a[i]
#define pr(a,n)  for(i=0;i<n;i++) cout<<a[i] << " "; cout<<"\n"
#define ff first
#define ss second
#define iof freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define sp << " " <<
#define nl << "\n";
#define all(s) s.begin(),s.end()
#define minv(a) *min_element(all(a))
#define maxv(a) *max_element(all(a))
#define sumv(a) accumulate(all(a),0)
#define lb lower_bound
#define ub upper_bound
#define vi vector<ll>

typedef long long ll ; typedef long double ld;
using namespace std;
const int INF=0x3f3f3f3f;
bool isPrime(ll N){for (ll i = 2; i * i <=N; ++i){if (N % i == 0)return false;}return true;}
bool sortinrev(const pair<int,int> &a,const pair<int,int> &b){return (a.first > b.first);}
int gcd(int a, int b){if(b==0) return a;return gcd(b, a%b);}
// bool comp(const pair<int,int> &a,const pair<int,int> &b){
//     if(a.first==b.first)
//         return a.second<b.second;
//     else
//         return a.first>b.first;
// }
//vector<bool>prime(1000000001, true);
//void SieveOfEratosthenes(ll n)
//{
//    for (ll p=2; p*p<=n; p++){
//        if (prime[p] == true){
//            for (ll i=p*p; i<=n; i += p)
//                prime[i] = false;
//        }
//    }
//}
//bool comp(string i,string j){
 //   ll l1=i.length();
   // ll l2=j.length();
     //  if(l1==l2){
       //    return i<j;
       //}
        //return l1<l2;
//}
  bool eight(long long int a)
  {
  	int c=0;
  	while(a!=0)
  	{
  		long long int k=a%10;
  		if(k==8)
  		{
  			c++;
  			break;
		  }
		  a=a/10;
	  }
	  if(c!=0)
	  {
	  	return true;
	  }
	  else{
	  	return false;
	  }
  }

int main() {
NeedForSpeed;
string s;
cin>>s;
int h;
cin>>h;
//int a[27];
char ch='a';
int chark=0;
map<char,int> m;
for(int i=0;i<26;i++)
{
	int x;
	cin>>x;
	chark=int(ch);
	m.insert(pair<char,int>(ch,x));
	chark++;
	ch=char(chark);
}
map<char,int>:: iterator it;
string d=s;
sort(d.begin(),d.end());
int y=d.size()-1;
char k=s[y];
int l;
for(it=m.begin();it!=m.end();it++)
{
	if(it->first==k)
	{
		l=it->second;
		break;
	}
}
int i=1;
int sum=0;
for(it=m.begin();;it++)
{
   if(it->first==s[i])
   {
   	sum=sum+(it->second*(i));
   	i++;

   }
   if(i>=s.size())
   {
   	sum=sum+i*l;
   	i++;

   }
   if(it==m.end())
   {
   	it=m.begin();
   }
   if(i>s.size()+h)
   {
   	break;
   }

}
cout<<sum-1;

}


#include<bits/stdc++.h>
#define f(i,a,b) for(i=a;i<b;i++)
#define f_(i,a,b) for(i=a;i>=b;i--)
#define T_ ll t; cin>>t; while(t--)
#define NeedForSpeed ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define mod 1000000007
#define mp make_pair
#define read(a,n) for(i=0;i<n;i++) cin>>a[i]
#define pr(a,n)  for(i=0;i<n;i++) cout<<a[i] << " "; cout<<"\n"
#define ff first
#define ss second
#define iof freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define sp << " " <<
#define nl << "\n";
#define all(s) s.begin(),s.end()
#define minv(a) *min_element(all(a))
#define maxv(a) *max_element(all(a))
#define sumv(a) accumulate(all(a),0)
#define lb lower_bound
#define ub upper_bound
#define vi vector<ll>

typedef long long ll ; typedef long double ld;
using namespace std;
const int INF=0x3f3f3f3f;
bool isPrime(ll N){for (ll i = 2; i * i <=N; ++i){if (N % i == 0)return false;}return true;}
bool sortinrev(const pair<int,int> &a,const pair<int,int> &b){return (a.first > b.first);}
int gcd(int a, int b){if(b==0) return a;return gcd(b, a%b);}
// bool comp(const pair<int,int> &a,const pair<int,int> &b){
//     if(a.first==b.first)
//         return a.second<b.second;
//     else
//         return a.first>b.first;
// }
//vector<bool>prime(1000000001, true);
//void SieveOfEratosthenes(ll n)
//{
//    for (ll p=2; p*p<=n; p++){
//        if (prime[p] == true){
//            for (ll i=p*p; i<=n; i += p)
//                prime[i] = false;
//        }
//    }
//}
//bool comp(string i,string j){
 //   ll l1=i.length();
   // ll l2=j.length();
     //  if(l1==l2){
       //    return i<j;
       //}
        //return l1<l2;
//}
  bool eight(long long int a)
  {
  	int c=0;
  	while(a!=0)
  	{
  		long long int k=a%10;
  		if(k==8)
  		{
  			c++;
  			break;
		  }
		  a=a/10;
	  }
	  if(c!=0)
	  {
	  	return true;
	  }
	  else{
	  	return false;
	  }
  }

int main() {
NeedForSpeed;
string s;
cin>>s;
int h;
cin>>h;
//int a[27];
char ch='a';
int chark=0;
map<char,int> m;
for(int i=0;i<26;i++)
{
	int x;
	cin>>x;
	chark=int(ch);
	m.insert(pair<char,int>(ch,x));
	chark++;
	ch=char(chark);
}
map<char,int>:: iterator it;
string d=s;
sort(d.begin(),d.end());
int y=d.size()-1;
char k=s[y];
int l;
for(it=m.begin();it!=m.end();it++)
{
	if(it->first==k)
	{
		l=it->second;
		break;
	}
}
int i=1;
int sum=0;
for(it=m.begin();;it++)
{
   if(it->first==s[i])
   {
   	sum=sum+(it->second*(i));
   	i++;

   }
   if(i>=s.size())
   {
   	sum=sum+i*l;
   	i++;

   }
   if(i>s.size()+h)
   {
   	break;
   }

}
cout<<sum-1;

}


#include<bits/stdc++.h>
    #define f(i,a,b) for(i=a;i<b;i++)
    #define f_(i,a,b) for(i=a;i>=b;i--)
    #define T_ ll t; cin>>t; while(t--)
    #define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
    #define pb push_back
    #define mp make_pair
    #define read(a,n) for(ll  i=0;i<n;i++) cin>>a[i]
    #define pr(a,n)  for(ll  i=0;i<n;i++) cout<<a[i]<<" "; cout<<"\n"
    #define ff first
    #define ss second
    #define all(s) s.begin(),s.end()

    typedef long long ll ; typedef long double ld;
    using namespace std;
    bool isPrime(int N){for (int i = 2; i * i <=N; ++i){if (N % i == 0)return false;}return true;}
    bool sortinrev(const pair<int,int> &a,const pair<int,int> &b){return (a.first > b.first);}
    int gcd(int a, int b){if(b==0) return a;return gcd(b, a%b);}

    int main() {
        fast;
//        T_ {
            long long int k,i,ans=0;
            string s;
            int a[26]={0};
            cin >> s;
            cin >> k;
            int maxm=0;
            for(i=0;i<26;i++){
                cin >> a[i];
                if(a[i]>maxm){
                    maxm=a[i];
                }
            }
            for(i=0;i<s.length();i++){
                ans=ans+(i+1)*(a[s[i]-'a']);
            }
//            cout << ans << " " << maxm << "\n";
            for(i=s.length();i<s.length()+k;i++){
                ans=ans+(i+1)*maxm;
            }
            cout << ans << "\n";
        return 0;
    }


#include<bits/stdc++.h>
#define f(i,a,b) for(i=a;i<b;i++)
#define f_(i,a,b) for(i=a;i>=b;i--)
#define T_ ll t; cin>>t; while(t--)
#define NeedForSpeed ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define mod 1000000007
#define mp make_pair
#define read(a,n) for(i=0;i<n;i++) cin>>a[i]
#define pr(a,n)  for(i=0;i<n;i++) cout<<a[i] << " "; cout<<"\n"
#define ff first
#define ss second
#define iof freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define sp << " " <<
#define nl << "\n";
#define all(s) s.begin(),s.end()
#define minv(a) *min_element(all(a))
#define maxv(a) *max_element(all(a))
#define sumv(a) accumulate(all(a),0)
#define lb lower_bound
#define ub upper_bound
#define vi vector<ll>

typedef long long ll ; typedef long double ld;
using namespace std;
const int INF=0x3f3f3f3f;
bool isPrime(ll N){for (ll i = 2; i * i <=N; ++i){if (N % i == 0)return false;}return true;}
bool sortinrev(const pair<int,int> &a,const pair<int,int> &b){return (a.first > b.first);}
int gcd(int a, int b){if(b==0) return a;return gcd(b, a%b);}
// bool comp(const pair<int,int> &a,const pair<int,int> &b){
//     if(a.first==b.first)
//         return a.second<b.second;
//     else
//         return a.first>b.first;
// }
//vector<bool>prime(1000000001, true);
//void SieveOfEratosthenes(ll n)
//{
//    for (ll p=2; p*p<=n; p++){
//        if (prime[p] == true){
//            for (ll i=p*p; i<=n; i += p)
//                prime[i] = false;
//        }
//    }
//}
//bool comp(string i,string j){
 //   ll l1=i.length();
   // ll l2=j.length();
     //  if(l1==l2){
       //    return i<j;
       //}
        //return l1<l2;
//}
  bool eight(long long int a)
  {
  	int c=0;
  	while(a!=0)
  	{
  		long long int k=a%10;
  		if(k==8)
  		{
  			c++;
  			break;
		  }
		  a=a/10;
	  }
	  if(c!=0)
	  {
	  	return true;
	  }
	  else{
	  	return false;
	  }
  }

int main() {
NeedForSpeed;
string s;
cin>>s;
int h;
cin>>h;
//int a[27];
char ch='a';
int chark=0;
map<char,int> m;
int mx=INT_MIN;
for(int i=0;i<26;i++)
{
	int x;
	cin>>x;
	mx=max(x,mx);
	chark=int(ch);
	m.insert(pair<char,int>(ch,x));
	chark++;
	ch=char(chark);
}
map<char,int>:: iterator it;
int i=1;
int sum=0;
for(it=m.begin();;it++)
{
   if(it->first==s[i])
   {
   	sum=sum+(it->second*(i));
   	i++;

   }
   if(i>=s.size())
   {
   	sum=sum+i*mx;
   	i++;

   }
   if(i>s.size()+h)
   {
   	break;
   }

}
cout<<sum;

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    string str;
    cin >> str;
    int k;
    cin >> k;
    long long a[200] = {0}, mx = 0;
    for(int i = 97; i < 97+26; i++)
    {
        cin >> a[i];
        mx = max(a[i], mx);
    }

    int s = str.size();
    /*for(int i = 0; i < s; i++)
    {
        mx = max(mx, a[str[i]]);
    }*/
    long long cnt = 0, f = 1;
    for(int i = 0; i < s+k; i++)
    {
        if(i < s)
            cnt += f*a[str[i]];
        else
            cnt += f*mx;

        f++;
    }
    cout << cnt << endl;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    string str;
    cin >> str;
    int k;
    cin >> k;
    int a[200] = {0};
    for(int i = 97; i < 97+26; i++)
        cin >> a[i];
    long long mx = 0, s = str.size();
    for(int i = 0; i < s; i++)
    {
        mx = max(mx, a[str[i]]);
    }
    long long cnt = 0, f = 1;
    for(int i = 0; i < s+k; i++)
    {
        if(i < s)
            cnt += f*a[str[i]];
        else
            cnt += f*mx;

        f++;
    }
    cout << cnt << endl;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    string str;
    cin >> str;
    int k;
    cin >> k;
    long long a[200] = {0};
    for(int i = 97; i < 97+26; i++)
        cin >> a[i];
    long long mx = 0, s = str.size();
    for(int i = 0; i < s; i++)
    {
        mx = max(mx, a[str[i]]);
    }
    long long cnt = 0, f = 1;
    for(int i = 0; i < s+k; i++)
    {
        if(i < s)
            cnt += f*a[str[i]];
        else
            cnt += f*mx;

        f++;
    }
    cout << cnt << endl;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    char s[100000];
    cin>>s;
    long long l = strlen(s);
    long long k,largest = 0;
    cin>>k;
    long long a[26] = {};
    for(int i = 97; i <= 122; i++)
    {
        cin>>a[i];
        if(a[i] > largest)
            largest  = a[i];
    }
    long long sum = 0;
    for(int i = 0; i < l; i++)
    {
        sum = sum + (a[s[i]] * (i+1));
    }
    long long m = l;
    for(int i = 0; i < k; i++)
    {
        m++;
        sum = sum + (largest*m);
    }
    printf("%d\n",sum);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    char s[100000];
    cin>>s;
    int l = strlen(s);
    int k,largest = 0;
    cin>>k;
    int a[26] = {};
    for(int i = 97; i <= 122; i++)
    {
        cin>>a[i];
        if(a[i] > largest)
            largest  = a[i];
    }
    long long sum = 0;
    for(int i = 0; i < l; i++)
    {
        sum = sum + (a[s[i]] * (i+1));
    }
    long long m = l;
    for(int i = 0; i < k; i++)
    {
        m++;
        sum = sum + (largest*m);
    }
    printf("%d\n",sum);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    char s[100000];
    cin>>s;
    int l = strlen(s);
    int k,largest = 0;
    scanf("%d",&k);
    int a[26] = {};
    for(int i = 97; i <= 122; i++)
    {
        scanf("%d",&a[i]);
        if(a[i] > largest)
            largest  = a[i];
    }
    long long sum = 0;
    for(long long i = 0; i < l; i++)
    {
        sum = sum + (a[s[i]] * (i+1));
    }
    long long m = l;
    for(long long i = 0; i < k; i++)
    {
        m++;
        sum = sum + (largest*m);
    }
    printf("%d\n",sum);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    char s[100000];
    cin>>s;
    int l = strlen(s);
    int k,largest = 0;
    cin>>k;
    int a[26] = {};
    for(int i = 97; i <= 122; i++)
    {
        cin>>a[i];
        if(a[i] > largest)
            largest  = a[i];
    }
    long long sum = 0, j=0;
    for(; j < l; j++)
        sum = sum + (a[s[j]] * (j+1));

    for(j=j+1; j <= l+k; j++)
        sum = sum + (largest*j);

    cout<<sum<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    char s[100000];
    cin>>s;
    int l = strlen(s);
    int k,largest = 0;
    scanf("%d",&k);
    int a[150] = {};
    for(int i = 97; i <= 122; i++)
    {
        scanf("%d",&a[i]);
        if(a[i] > largest)
            largest  = a[i];
    }
    long long sum = 0;
    for(long long i = 0; i < l; i++)
    {
        sum = sum + (a[s[i]] * (i+1));
    }
    long long m = l;
    for(long long i = 0; i < k; i++)
    {
        m++;
        sum = sum + (largest*m);
    }
    printf("%d\n",sum);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cstdint>
#include<cmath>
using namespace std;

int n,m,f=0,k=0;
char c=0;
int main()
{
    char s[1000];
    long long k,max,sum=0;
    int a[26];
    cin>>s>>k;

    max=0;
    for(int i=0;i<26;i++)
    {
        cin>>a[i];
        if(max<a[i])
        max=a[i];
    }
    for(int i=0;i<k+strlen(s);i++)
    {
        if(i<strlen(s))
        {
            sum+=(i+1)*a[s[i]-'a'];

        }
        else
        {
            m=3;
            sum+=(i+1)*max;

        }
    }
    cout<<sum;

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cstdint>
#include<cmath>
using namespace std;

int n,m,f=0,k=0;
char c=0;
int main()
{
    char s[1000];
    long long k,max,sum=0;
    int a[26];
    cin>>s>>k;

    max=0;
    for(int i=0;i<26;i++)
    {
        cin>>a[i];
        if(max<a[i])
        max=a[i];
    }
    for(int i=0;i<k+strlen(s);i++)
    {
        if(s[i]!='\0' && m!=3)
        {
            sum+=(i+1)*a[s[i]-'a'];

        }
        else if(s[i]=='\0')
        {
            m=3;
            sum+=(i+1)*max;

        }
    }
    cout<<sum;

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cstdint>
#include<cmath>
using namespace std;

int n,m,f=0,k=0;
char c=0;
int main()
{
    char s[1000];
    int k,max,sum=0;
    int a[26];
    cin>>s>>k;

    max=0;
    for(int i=0;i<26;i++)
    {
        cin>>a[i];
        if(max<a[i])
        max=a[i];
    }
    for(int i=0;i<k+strlen(s);i++)
    {
        if(s[i]!='\0' && m!=3)
        {
            sum+=(i+1)*a[s[i]-'a'];
            m=3;
        }
        else
        {
            sum+=(i+1)*max;
        }
    }
    cout<<sum;

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cstdint>
#include<cmath>
using namespace std;

int n,m,f=0,k=0;
char c=0;
int main()
{
    char s[1000];
    long long k,max,sum=0;
    int a[26];
    cin>>s>>k;

    max=0;
    for(int i=0;i<26;i++)
    {
        cin>>a[i];
        if(max<a[i])
        max=a[i];
    }
    for(int i=0;i<k+strlen(s);i++)
    {
        if(s[i]!='\0' && m!=3)
        {
            sum+=(i+1)*a[s[i]-'a'];
            m=3;
        }
        else
        {
            sum+=(i+1)*max;
        }
    }
    cout<<sum;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	string s; cin >> s;
	int k; cin >> k;
	char answer = 'a', number = 0;
	for(int i = 0; i < 26; ++i)
	{
		int w; cin >> w;
		if(w > number) {answer = 'a' + i; number = w;}
	}
	cout << s << string(k, answer);
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	string s; cin >> s;
	int k; cin >> k;
	map<char, int> values;
	char answer = 'a', number = 0;
	for(int i = 0; i < 26; ++i)
	{
		int w; cin >> w;
		values['a' + i] = w;
		if(w > number) {answer = 'a' + i; number = w;}
	}
	s += string(k, answer);
	int result = 0;
	for(int i = 0; i < s.size(); ++i) result += (i + 1) * values[s[i]];
	cout << result;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	string s; cin >> s;
	for(auto& c : s) c -= 'a';
	int k; cin >> k;
	map<int, int> values;
	int answer = 0;
	for(int i = 0; i < 26; ++i)
	{
		int w; cin >> w;
		values[i] = w;
		answer = max(answer, w);
	}
	values[-1] = answer;
	s += string(k, -1);
	int result = 0;
	for(int i = 0; i < s.size(); ++i) result += (i + 1) * values[s[i]];
	cout << result;
}


#include <bits/stdc++.h>
using namespace std;

int arr[26];

int main()
{
    string s;
    cin >> s;
    int n;
    cin >> n;

    int mx = arr[0];
    int j = 0;
    for (int i = 0; i < 26; i++)
    {
        cin >> arr[i];
        if (arr[i] > mx)
        {
            mx = arr[i];
            j = i;
        }
    }

    int ans = 0;
    int i;
    for (i = 0; i < s.length(); i++)
    {
        ans += ((i + 1) * (arr[s[i] - 'a']));
    }

        for (; i < (s.length() + n); i++)
    {
        ans += ((i + 1) * (arr[s[j] - 'a']));
    }

    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    long long int k, a[26], sum = 0, n = s.size();
    cin >> k;
    for (int i = 0; i < 26; i++)
        cin >> a[i];
    for (int i = 0; i < s.size(); i++)
        sum += a[s[i] - 97] * (i + 1);
    sort(a, a + 26);
    cout << sum + a[25] * ((n + k) * (n + k + 1) - n * (n + 1)) / 2;
}


#include <bits/stdc++.h>
using namespace std;

int arr[26];

int main()
{
    string s;
    cin >> s;
    int n;
    cin >> n;

    int mx = arr[0];
    int j = 0;
    for (int i = 0; i < 26; i++)
    {
        cin >> arr[i];
        if (arr[i] > mx)
        {
            mx = arr[i];
            j = i;
        }
    }

    int ans = 0;
    int i;
    for (i = 0; i < s.length(); i++)
    {
        ans += ((i + 1) * (arr[s[i] - 'a']));
    }
    if (n != 0)
    {
        for (; i < (s.length() + n); i++)
            ans += ((i + 1) * (arr[s[j] - 'a']));
        cout << ans << endl;
    }
    else
    {
        cout << ans << endl;
    }

    return 0;
}


// In the name of God
// Code by: mrMaster

#include <bits/stdc++.h>

using namespace std;

#define int long long

string s;
int res = 1;
vector<int>v;

main()
{
	cin >> s;
	v.push_back(0);
	for(int i=0;i<s.size()-1;++i)
		if((s[i]-'0')+(s[i+1]-'0') != 9)
			v.push_back(i+1);
	v.push_back(s.size());
	for(int i=0;i<v.size()-1;++i){
		int t = v[i+1]-v[i];
		if(t%2)
			res *= (t+1)/2;
	}
	cout << res << endl;
	return 0;
}


// In the name of God
// Code by: mrMaster

#include <bits/stdc++.h>

using namespace std;

string s;
vector<int>v;
long long res = 1;

int main()
{
	cin >> s;
	for(int i=0;i<s.size()-1;++i)
		if((int(s[i]-'0')+int(s[i+1]-'0')) == 9)
			v.push_back(i);
	int counter = 0;
	v.push_back(1e5);
	for(int i=0;i<v.size()-1;++i){
		if(v[i] == v[i+1]-1)
			++counter;
		else{
			if(counter%2)
				res *= 2;
			counter = 0;
		}
	}
	cout << res << endl;
	return 0;
}


// In the name of God
// Code by: mrMaster

#include <bits/stdc++.h>

using namespace std;

#define int long long

string s;
vector<int>v;
int res = 1;

main()
{
	cin >> s;
	for(int i=0;i<s.size()-1;++i)
		if((s[i]-'0')+(s[i+1]-'0') == 9)
			v.push_back(i);
	int counter = 0;
	v.push_back(1e5+1000);
	for(int i=0;i<v.size()-1;++i){
		if(v[i] == v[i+1]-1)
			++counter;
		else{
			if(counter%2)
				res *= 2;
			counter = 0;
		}
	}
	cout << res << endl;
	return 0;
}


// In the name of God
// Code by: mrMaster

#include <bits/stdc++.h>

using namespace std;

string s;
int res = 1;
vector<int>v;

int main()
{
	cin >> s;
	v.push_back(0);
	for(int i=0;i<s.size()-1;++i)
		if((s[i]-'0')+(s[i+1]-'0') != 9)
			v.push_back(i+1);
	v.push_back(s.size());
	for(int i=0;i<v.size()-1;++i){
		int t = v[i+1]-v[i];
		if(t != 1 && t%2)
			res *= 2;
	}
	cout << res << endl;
	return 0;
}


// In the name of God
// Code by: mrMaster

#include <bits/stdc++.h>

using namespace std;

string s;
int res = 1;
vector<int>v;

int main()
{
	cin >> s;
	v.push_back(0);
	for(int i=0;i<s.size()-1;++i)
		if((s[i]-'0')+(s[i+1]-'0') != 9)
			v.push_back(i+1);
	v.push_back(s.size());
	for(int i=0;i<v.size()-1;++i){
		int t = v[i+1]-v[i];
		if(t%2)
			res *= (t+1)/2;
	}
	cout << res << endl;
	return 0;
}


// In the name of God
// Code by: mrMaster

#include <bits/stdc++.h>

using namespace std;

#define int long long

string s;
vector<int>v;
int res = 1;

main()
{
	cin >> s;
	for(int i=0;i<s.size()-1;++i)
		if((s[i]-'0')+(s[i+1]-'0') == 9)
			v.push_back(i);
	int counter = 0;
	v.push_back(1e5);
	for(int i=0;i<v.size()-1;++i){
		if(v[i] == v[i+1]-1)
			++counter;
		else{
			if(counter%2)
				res *= 2;
			counter = 0;
		}
	}
	cout << res << endl;
	return 0;
}


#include <stdio.h>
#include <string.h>
char a[100005];
int cnt[100005];

int main() {
	scanf("%s", a);
	int len=strlen(a);
	__int64 ans=1;
	int i;

	memset(cnt,0,sizeof(cnt));
	for(i=0; i<len-1; i++) {
		if(a[i]+a[i+1]-96 == 9 && a[i]!='0' && a[i]!='9') {
			cnt[i]++;
			cnt[i+1]++;
		}
	}
	int cnt1;
	for(i=0; i<len; i++) {
		if(a[i]==2) {
			cnt1=0;
			while(a[i]==2) {
				cnt1++;
				i++;
			}
			if(cnt1%2)
				ans+=cnt1;
		}
	}
	printf("%I64d\n",ans);

	return 0;
}


#include <stdio.h>
#include <string.h>
char a[100005];
int cnt[100005];

int main() {
	scanf("%s", a);
	int len=strlen(a);
	__int64 ans=1;

	memset(cnt,0,sizeof(cnt));
	for(int i=0; i<len-1; i++) {
		if(a[i]+a[i+1]-96 == 9 && a[i]!='0' && a[i]!='9') {
			cnt[i]++;
			cnt[i+1]++;
		}
	}
	int cnt1;
	for(i=0; i<len; i++) {
		if(a[i]==2) {
			cnt1=0;
			while(a[i]==2) {
				cnt1++;
				i++;
			}
			if(cnt1%2)
				ans+=cnt1;
		}
	}
	printf("%I64d\n",ans);

	return 0;
}


#include <stdio.h>
#include <string.h>
char a[100005];
int cnt[100005];

int main() {
	scanf("%s", a);
	int len=strlen(a);
	__int64 ans=1;
	int i;

	memset(cnt,0,sizeof(cnt));
	for(i=0; i<len; i++) {
		if(a[i]+a[i+1]-96 == 9 && a[i]!='0' && a[i]!='9') {
			cnt[i]++;
			cnt[i+1]++;
		}
	}
	int cnt1;
	for(i=0; i<len; i++) {
		if(cnt[i]==2) {
			cnt1=0;
			while(cnt[i]==2) {
				cnt1++;
				i++;
			}
			if(cnt1%2)
				ans += cnt1;
		}
	}
	printf("%I64d\n",ans);

	return 0;
}


#include <stdio.h>
#include <string.h>
char a[100005];
int cnt[100005];

int main() {
	scanf("%s", a);
	int len=strlen(a);
	__int64 ans=1;
	int i;

	memset(cnt,0,sizeof(cnt));
	for(i=0; i<len; i++) {
		if(a[i]+a[i+1]-96 == 9 && a[i]!='0' && a[i]!='9') {
			cnt[i]++;
			cnt[i+1]++;
		}
	}
	int cnt1;
	for(i=0; i<len; i++) {
		if(cnt[i]==2) {
			cnt1=0;
			while(cnt[i]==2) {
				cnt1++;
				i++;
			}
			if(cnt1%2) {
				if(cnt1==1)
					ans *= 2;
				else
					ans *= cnt1;
			}
		}
	}
	printf("%I64d\n",ans);

	return 0;
}


#include <stdio.h>
#include <string.h>
char a[1000005];
int cnt[1000005];

int main() {
    scanf("%s", a);
    int len=strlen(a);
    __int64 ans=1;
    int i;

    memset(cnt,0,sizeof(cnt));
    for(i=0; i<len; i++) {
        if(a[i]+a[i+1]-96 == 9 && a[i]!='0' && a[i]!='9') {
            cnt[i]++;
            cnt[i+1]++;
        }
    }
    int cnt1;
    for(i=0; i<len; i++) {
        if(cnt[i]==2) {
            cnt1=0;
            while(cnt[i]==2) {
                cnt1++;
                i++;
            }
            if(cnt1%2) {
                if(cnt1==1)
                    ans *= 2;
                else
                    ans *= cnt1;
            }
            printf("%d\n", cnt1);
        }
    }
    printf("%I64d\n",ans);

    return 0;
}


#include <stdio.h>
#include <string.h>
char a[1000005];
int cnt[1000005];

int main() {
	scanf("%s", a);
	int len=strlen(a);
	__int64 ans=1;
	int i;

	memset(cnt,0,sizeof(cnt));
	for(i=0; i<len; i++) {
		if(a[i]+a[i+1]-96 == 9 && a[i]!='0' && a[i]!='9') {
			cnt[i]++;
			cnt[i+1]++;
		}
	}
	int cnt1;
	for(i=0; i<len; i++) {
		if(cnt[i]==2) {
			cnt1=0;
			while(cnt[i]==2) {
				cnt1++;
				i++;
			}
			if(cnt1%2) {
				if(cnt1==1)
					ans *= 2;
				else
					ans *= cnt1;
			}
		}
	}
	printf("%I64d\n",ans);

	return 0;
}


#include <stdio.h>
#include <string.h>
char a[1000005];
int cnt[1000005];

int main() {
    scanf("%s", a);
    int len=strlen(a);
    __int64 ans=1;
    int i;

    memset(cnt,0,sizeof(cnt));
    for(i=0; i<len; i++) {
        if(a[i]+a[i+1]-96 == 9 && a[i]!='0' && a[i]!='9') {
            cnt[i]++;
            cnt[i+1]++;
        }
    }
    int cnt1;
    for(i=0; i<len; i++) {
        if(cnt[i]==2) {
            cnt1=0;
            while(cnt[i]==2) {
                cnt1++;
                i++;
            }
            if(cnt1%2) {
                if(cnt1==1)
                    ans *= 2;
                else
                    ans *= cnt1;
            }
        }
    }
    printf("%I64d\n",ans);

    return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char s[10000010];
int main()
{
    scanf("%s",s);
    int l=strlen(s);
    long long ans=1,top=0;
    for(int i=0;i<l-1;i++)
    {
        if(s[i]-'0'+s[i+1]-'0'==9)
            top++;
        else
        {
            if(top>0)
                ans*=top;
            top=0;
        }
    }
    if(top!=0)
        ans*=top;
    printf("%I64d\n",ans);
    return 0;
}
/*2018-07-31 20:05:12.118*/


#include<cstdio>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstdlib>
#include<cstring>
using namespace std;
char s[100008];
int a[100009];
int main()
{
    while(~scanf("%s",s)){
        int l=strlen(s);
        int ans=1;
        for(int i=1;i<=l;++i){
            if(s[i]-'0'+s[i-1]-'0'==9){
                a[i]=a[i-1]+1;
            }
            else if(a[i-1]>0&&a[i-1]%2==0){
                ans*=(a[i-1]/2+1);
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}
/*2018-07-31 22:30:53.842*/


#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=100005;
int num[N];
char str[N];
int main()
{
	while(cin>>str)
	{
		memset(num,0,sizeof(num));
		int sum=1;
		int len=strlen(str);
		for(int i=1;i<=len;i++)
		{
			if(str[i]-'0'+str[i-1]-'0'==9)
			{
				num[i]=num[i-1]+1;
			}
			else if(num[i-1]>0&&num[i-1]%2==0)
				sum*=(num[i-1]/2+1);
		}
		cout<<sum<<endl;
	}
	return 0;
}/*2018-07-31 20:13:00.133*/


#include<stdio.h>
#include<string>
#include<string.h>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stdlib.h>
#include<algorithm>
using namespace std;
#define ll long long
char c[100005];
int main()
{
    int num,ans;
    while(~scanf("%s",c))
    {
        num=ans=1;
        int n=strlen(c);
        c[n]=0;
        for(int i=0;i<n;i++)
        {
            if((c[i]+c[i+1]-'0'-'0')==9)
            {
                num++;
            }
            else if((c[i-1]+c[i]-'0'-'0')==9&&(c[i]+c[i+1]-'0'-'0')!=9)
            {
                //printf("%d",num);
                if(num&1)
                {
                    ans*=num-1;
                }
                num=1;
            }
        }
        printf("%d\n",ans);
    }
}
/*2018-07-31 20:12:03.188*/


#include<iostream>
#include<string>
using namespace std;
typedef long long ll;
string s;
int main(){
    ll ans = 1, flag = 0;
    cin >> s;
    for(int i = 1; i < s.size() - 1; i ++){
        if(s[i] + s[i-1] - '0' - '0' == 9 && s[i] + s[i+1] - '0' - '0' == 9)
            flag ++;
        else{
            if(flag & 1){
                ans *= ((flag + 3) / 2);
            }
            flag = 0;
        }
    }
    if(flag & 1){
        ans *= (flag + 3) / 2;
    }
    cout << ans << endl;
    return 0;
}/*2018-08-01 15:12:48.812*/


#include<stdio.h>
#include<stdlib.h>
#include<queue>
#include<string.h>
#include<algorithm>
#include<map>
using namespace std;
char str[100];
int num[100];
int main()
{
    scanf("%s",str);
    int len=strlen(str);
    memset(num,0,sizeof(num));
    int sum=1;
    for(int i=1;i<=len;i++)
    {
        if(str[i]-'0'+str[i-1]-'0'==9)
        {
            num[i]=num[i-1]+1;
        }
        else
        {
            if(num[i-1]%2==0&&num[i-1]>0)
            {
                sum*=(num[i-1]/2+1);

            }
        }
    }
    printf("%d\n",sum);
    return 0;

}
/*2018-07-31 21:41:13.226*/


#include<queue>
#include<stack>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
typedef long long ll;
int dp[1000005];
char s[1000005];
int main()
{
    int i,j,n,t;
    long long ans;
    scanf("%s",s+1);
    s[1]-='0';
    ans=1;
    for(i=2;s[i];i++)
    {
        s[i]-='0';
        dp[i]=dp[i-1];
        if(s[i]+s[i-1]==9)
        {
            if(dp[i]==dp[i-2]+1)
            {
                ans*=2;
            }
            dp[i]=max(dp[i],dp[i-2]+1);

        }
    }
    printf("%I64d\n",ans);
    return 0;
}
/*2018-07-31 19:42:50.341*/


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1e5+7, INF=0x3f3f3f3f;
char str[N];
int main(){
    register ll cnt, ans=1;
    register int i, len;
    scanf("%s", str);
    len=strlen(str);
    str[len++]='a';
    for(i=0; str[i+1]; ++i){
        if(str[i]+str[i+1]-2*'0'==9){
            cnt++;
        }else{
            ans*=cnt&1?(cnt/2+1):1;
        }
    }
    printf("%I64d\n", ans);
}
/*2018-07-31 21:16:59.033*/


#include<stdio.h>
#include<string>
#include<string.h>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stdlib.h>
#include<algorithm>
using namespace std;
#define ll long long
char c[100005];
int main()
{
    ll num,ans;
    while(~scanf("%s",c))
    {
        num=ans=1;
        int n=strlen(c);
        c[n]=0;
        for(int i=0;i<n;i++)
        {
            if((c[i]+c[i+1]-'0'-'0')==9)
            {
                num++;
            }
            else if((c[i-1]+c[i]-'0'-'0')==9&&(c[i]+c[i+1]-'0'-'0')!=9)
            {
                if(num&1)
                {
                    ans*=num-1;
                }
                num=1;
            }
        }
        printf("%I64d\n",ans);
    }
}
/*2018-07-31 20:15:23.195*/


#include<stdio.h>
#include<string>
#include<string.h>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stdlib.h>
#include<algorithm>
using namespace std;
#define ll long long
char c[1000005];
int main()
{
    ll num,ans;
    while(~scanf("%s",c))
    {
        ans=1;
        num=0;
        int n=strlen(c);
        for(int i=0; i<n; i++)
        {
            if((c[i]+c[i+1]-'0'-'0')==9)
                num++;
            else
            {
                if(num&&num%2==0)
                    ans=ans*(num/2+1);
                num=0;
            }
        }
        printf("%I64d\n",ans);
    }
}
/*2018-07-31 20:39:47.561*/


#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
    char a, b;
    b = '9';
    int sum = 0, ans = 1;
    while(scanf("%c", &a) && a!='\n')
    {
        if(a - '0' + b - '0' == 9)
        {
            sum++;
//            printf("%c %c %d\n", a, b, sum);
        }
        else
        {
            if(sum % 2 == 0 && sum > 0)
            {
                ans *= 2;
            }
            sum = 0;
        }
        b = a;
    }
    if(sum % 2 == 0 && sum > 0)
        printf("%d", ans*2);
    else
        printf("%d", ans);

}
/*2018-07-31 19:51:32.55*/


#include<cstdio>
#include<cstring>
typedef long long ll;
char word[100005];
int main()
{
    while(~scanf("%s",word))
    {
        int len=strlen(word);
        ll sum=1;
        ll num=1;
        for(int i=1;i<len;i++)
        {
            if((word[i]-'0')+(word[i-1]-'0')==9)
            {
                num++;
            }
            else
            {
                if(num>1)
                {
                    if(num%2==1)
                    {
                        sum*=((num/2)+1);
                        num=1;
                    }
                    else
                    {
                        num=1;
                    }
                }
            }
        }
        if(num>1&&num%2==1)
        printf("%I64d\n",sum*(num/2+1));
        else
            printf("%I64d\n",sum);
    }
    return 0;
}
/*2018-08-01 00:15:00.845*/


#include<stdio.h>
#include<string>
#include<string.h>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stdlib.h>
#include<algorithm>
using namespace std;
#define ll long long
char c[100005];
int main()
{
    ll num,ans;
    while(~scanf("%s",c))
    {
        num=ans=1;
        int n=strlen(c);
        c[n]=0;
        for(int i=0;i<n;i++)
        {
            if((c[i]+c[i+1]-'0'-'0')==9)
            {
                num++;
            }
            else if((c[i-1]+c[i]-'0'-'0')==9&&(c[i]+c[i+1]-'0'-'0')!=9)
            {
                if(num&1)
                    ans*=num-1;
                num=1;
            }
            else
                num=1;
        }
        printf("%I64d\n",ans);
    }
}
/*2018-07-31 20:18:07.388*/


#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;

typedef long long ll;

string s;

ll powf(ll a,ll b)
{
    ll r=1,k=a;
    while(b!=0)
    {
        if(b&1) r= r*k;
        k = k * k;
        b>>=1;
    }
    return r;
}

vector<ll> www;

int main()
{
    ios::sync_with_stdio(false);
    cin >> s;
    long long flag = 0;
    for(int i = 1; i < s.size() - 1; i ++)
    {
        if(s[i] - '0' + s[i-1] - '0' == 9 && s[i] - '0' + s[i+1] - '0' == 9)
            flag ++;
        else
        {
//            cout << flag <<endl ;
            if(flag & 1)
            {
                www.push_back(flag + 1);
            }
            flag = 0;
        }
    }
    ll ans = 1;
    for(int i = 0; i < www.size(); i ++){
        ans *= www[i];
    }
    cout << ans << endl;
    return 0;
}
/*2018-07-31 20:29:48.398*/


#include <stdio.h>
#include <string.h>
#define TT 100000+2
char a[TT];
__int64 solve ( ) {
	int len=strlen (a);
	__int64 save=1,s=1;
	for (int i=00;i<len;i++) {
		if (a[i]+a[i+1]-2*'0'==9)
			save++;
		else {
			if (save%2==1)
			s=s*(save+1)/2;
			save=1;
		}
	}
	return s;
}
int main ( ) {
	while (gets(a)) {
		__int64 sum=solve ( );
		printf("%I64d\n",sum);
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
const int N = 100000 + 5;
using namespace std;
char a[N],len,i;
__int64 solve(){
	__int64 flag = 1,ans = 1;
		for(i = 0; i < len;i++){
			if(a[i] + a[i + 1] - 2 * '0' == 9)
			flag++;
			else{
				if(flag % 2 == 1)
				ans *= ((flag + 1) / 2);
				flag = 1;
			}
		}
		return ans;
}
int main(){
	gets(a);
		len = strlen(a);
		__int64 flag = 1,ans = 1;
		printf("%I64d\n",solve());
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
const int N = 100000 + 5;
using namespace std;
char a[N],len,i;
int main(){
	while(gets(a)){
		len = strlen(a);
		__int64 flag = 1,ans = 1;
		for(i = 0; i < len;i++){
			if(a[i] + a[i + 1] - 2 * '0' == 9)
			flag++;
			else{
				if(flag % 2 == 1)
				ans *= ((flag + 1) / 2);
				flag = 1;
			}
		}
		printf("%I64d\n",ans);
		}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
const int N = 100000 + 5;
using namespace std;
char a[N],len,i;
int main(){
	gets(a);
		len = strlen(a);
		__int64 flag = 1,ans = 1;
		for(i = 0; i < len;i++){
			if(a[i] + a[i + 1] - 2 * '0' == 9)
			flag++;
			else{
				if(flag % 2 == 1)
				ans *= ((flag + 1) / 2);
				flag = 1;
			}
		}
		printf("%I64d\n",ans);
	return 0;
}


char a[TT];
__int64 solve ( ) {
	int len=strlen (a);
	__int64 save=1,s=1;
	for (int i=00;i<len;i++) {
		if (a[i]+a[i+1]-2*'0'==9)
			save++;
		else {
			if (save%2==1)
			s=s*(save+1)/2;
			save=1;
		}
	}
	return s;
}
int main ( ) {
	while (gets(a)) {
		__int64 sum=solve ( );
		printf("%I64d\n",sum);
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
const int N = 100000 + 5;
using namespace std;
char a[N],len,i;
int main(){
	while(gets(a)){
		len = strlen(a);
		__int64 flag = 1,ans = 1;
		for(i = 00; i < len;i++){
			if(a[i] + a[i + 1] - 2 * '0' == 9)
			flag++;
			else{
				if(flag % 2 == 1)
				ans *= ((flag + 1) / 2);
				flag = 1;
			}
		}
		printf("%I64d\n",ans);
		}
	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <queue>

#define REP(I, N) for (int I = 0; I < (N); ++I)
#define PER(I, N) for (int I = (N); I >= 0; --I)
#define PERR(I, A, B) for (int I = (A); I >= (B); --I)
#define REPP(I, A, B) for (int I = (A); I <  (B); ++I)
#define REPN(I, A, B) for (int I = (A); I <= (B); ++I)
#define REPPP(I, A, B, C) for (int I = (A); I <  (B); I += C)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define RIIII(X, Y, Z, W) scanf("%d%d%d%d", &(X), &(Y), &(Z), &(W))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define DRIIII(X, Y, Z, W) int X, Y, Z, W; scanf("%d%d%d%d", &X, &Y, &Z, &W)
#define RS(X) scanf("%s", (X))
#define LEN(X) int(strlen(X))
#define MS0(X) memset((X), 0, sizeof(X))
#define MSI(X) memset((X), 0xFF, sizeof(X))
#define F first
#define S second
#define MP make_pair
#define PB push_back

using namespace std;

#ifdef DK
const int size = 100;
#else
const int size = 1e6 + 10;
#endif

char a[size];

char s1[] = "12345678";
char s2[] = "87654321";

int main()
{
#ifdef DK
  freopen("in.txt", "r", stdin);
#endif

  RS(a);

  int len = LEN(a);

  if (len == 1) {
    printf("1");
    return 0;
  }

  bool has = false;

  REP(i, len) {
    if (a[i] == '9') {
      has = true;
      break;
    }
  }

  int res = 0;

  REP(i, len - 1) {
    int cnt = 0;

    REPP(k, i, len - 1) {
      bool f = false;

      REP(j, 8) {
        if (a[k] == s1[j] && a[k + 1] == s2[j]) {
          cnt++;
          f = true;
          break;
        }
      }

      if (!f) {
        i = k;
        break;
      }
    }

    if (cnt > 0) {
      cnt++;

      if (cnt % 2 == 0) {
//        res++;
      } else {
        res+=(cnt + 1) / 2;
      }
    }

    cnt = 0;
  }

  if (has && res == 0) {
    printf("1");
    return 0;
  }

  printf("%d", res);

  return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <queue>

#define REP(I, N) for (int I = 0; I < (N); ++I)
#define PER(I, N) for (int I = (N); I >= 0; --I)
#define PERR(I, A, B) for (int I = (A); I >= (B); --I)
#define REPP(I, A, B) for (int I = (A); I <  (B); ++I)
#define REPN(I, A, B) for (int I = (A); I <= (B); ++I)
#define REPPP(I, A, B, C) for (int I = (A); I <  (B); I += C)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define RIIII(X, Y, Z, W) scanf("%d%d%d%d", &(X), &(Y), &(Z), &(W))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define DRIIII(X, Y, Z, W) int X, Y, Z, W; scanf("%d%d%d%d", &X, &Y, &Z, &W)
#define RS(X) scanf("%s", (X))
#define LEN(X) int(strlen(X))
#define MS0(X) memset((X), 0, sizeof(X))
#define MSI(X) memset((X), 0xFF, sizeof(X))
#define F first
#define S second
#define MP make_pair
#define PB push_back

using namespace std;

#ifdef DK
const int size = 100;
#else
const int size = 1e5 + 10;
#endif

char a[size];

char s1[] = "12345678";
char s2[] = "87654321";

typedef unsigned long long int ll;

int main()
{
#ifdef DK
  freopen("in.txt", "r", stdin);
#endif

  RS(a);

  int len = LEN(a);

  if (len == 1) {
    printf("1");
    return 0;
  }

  bool has = false;

  REP(i, len) {
    if (a[i] == '9') {
      has = true;
      break;
    }
  }

  ll res = has ? 1 : 0;

  REP(i, len - 1) {
    ll cnt = 0;

    REPP(k, i, len - 1) {
      bool f = false;

      REP(j, 8) {
        if (a[k] == s1[j] && a[k + 1] == s2[j]) {
          cnt++;
          f = true;
          break;
        }
      }

      if (!f || k == len - 2) {
        i = k;
        break;
      }
    }

    if (cnt > 0) {
      cnt++;

      if (res == 0) {
        res = 1;
      }

      if (cnt % 2 != 0) {
        res *= (cnt / 2 + 1);
      }
    }

    cnt = 0;
  }

  if (has && res == 0) {
    printf("1");
    return 0;
  }

  cout << res;

  return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <queue>

#define REP(I, N) for (int I = 0; I < (N); ++I)
#define PER(I, N) for (int I = (N); I >= 0; --I)
#define PERR(I, A, B) for (int I = (A); I >= (B); --I)
#define REPP(I, A, B) for (int I = (A); I <  (B); ++I)
#define REPN(I, A, B) for (int I = (A); I <= (B); ++I)
#define REPPP(I, A, B, C) for (int I = (A); I <  (B); I += C)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define RIIII(X, Y, Z, W) scanf("%d%d%d%d", &(X), &(Y), &(Z), &(W))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define DRIIII(X, Y, Z, W) int X, Y, Z, W; scanf("%d%d%d%d", &X, &Y, &Z, &W)
#define RS(X) scanf("%s", (X))
#define LEN(X) int(strlen(X))
#define MS0(X) memset((X), 0, sizeof(X))
#define MSI(X) memset((X), 0xFF, sizeof(X))
#define F first
#define S second
#define MP make_pair
#define PB push_back

using namespace std;

#ifdef DK
const int size = 100;
#else
const int size = 1e5 + 10;
#endif

char a[size];

char s1[] = "12345678";
char s2[] = "87654321";

int main()
{
#ifdef DK
  freopen("in.txt", "r", stdin);
#endif

  RS(a);

  int len = LEN(a);

  if (len == 1) {
    printf("1");
    return 0;
  }

  bool has = false;

  REP(i, len) {
    if (a[i] == '9') {
      has = true;
      break;
    }
  }

  int res = 0;

  REP(i, len - 1) {
    int cnt = 0;

    REPP(k, i, len - 1) {
      bool f = false;

      REP(j, 8) {
        if (a[k] == s1[j] && a[k + 1] == s2[j]) {
          cnt++;
          f = true;
          break;
        }
      }

      if (!f) {
        i = k;
        break;
      }
    }

    if (cnt > 0) {
      cnt++;

      if (cnt % 2 != 0) {
        res+=(cnt + 1) / 2;
      }
    }

    cnt = 0;
  }

  if (has && res == 0) {
    printf("1");
    return 0;
  }

  printf("%d", res);

  return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <queue>

#define REP(I, N) for (int I = 0; I < (N); ++I)
#define PER(I, N) for (int I = (N); I >= 0; --I)
#define PERR(I, A, B) for (int I = (A); I >= (B); --I)
#define REPP(I, A, B) for (int I = (A); I <  (B); ++I)
#define REPN(I, A, B) for (int I = (A); I <= (B); ++I)
#define REPPP(I, A, B, C) for (int I = (A); I <  (B); I += C)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define RIIII(X, Y, Z, W) scanf("%d%d%d%d", &(X), &(Y), &(Z), &(W))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define DRIIII(X, Y, Z, W) int X, Y, Z, W; scanf("%d%d%d%d", &X, &Y, &Z, &W)
#define RS(X) scanf("%s", (X))
#define LEN(X) int(strlen(X))
#define MS0(X) memset((X), 0, sizeof(X))
#define MSI(X) memset((X), 0xFF, sizeof(X))
#define F first
#define S second
#define MP make_pair
#define PB push_back

using namespace std;

#ifdef DK
const int size = 100;
#else
const int size = 1e5 + 10;
#endif

char a[size];

char s1[] = "12345678";
char s2[] = "87654321";

typedef unsigned long long int ll;

int main()
{
#ifdef DK
  freopen("in.txt", "r", stdin);
#endif

  RS(a);

  int len = LEN(a);

  if (len == 1) {
    printf("1");
    return 0;
  }

  bool has = false;

  REP(i, len) {
    if (a[i] == '9') {
      has = true;
      break;
    }
  }

  ll res = has ? 1 : 0;

  REP(i, len - 1) {
    ll cnt = 0;

    REPP(k, i, len - 1) {
      bool f = false;

      REP(j, 8) {
        if (a[k] == s1[j] && a[k + 1] == s2[j]) {
          cnt++;
          f = true;
          break;
        }
      }

      if (!f || k == len - 2) {
        i = k;
        break;
      }
    }

    if (cnt > 0) {
      cnt++;

      if (res == 0) {
        res = 1;
      }

      if (cnt % 2 != 0) {
        res *= (1 << cnt / 2);
      }
    }
  }

  if (has && res == 0) {
    printf("1");
    return 0;
  }

  cout << res;

  return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <queue>

#define REP(I, N) for (int I = 0; I < (N); ++I)
#define PER(I, N) for (int I = (N); I >= 0; --I)
#define PERR(I, A, B) for (int I = (A); I >= (B); --I)
#define REPP(I, A, B) for (int I = (A); I <  (B); ++I)
#define REPN(I, A, B) for (int I = (A); I <= (B); ++I)
#define REPPP(I, A, B, C) for (int I = (A); I <  (B); I += C)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define RIIII(X, Y, Z, W) scanf("%d%d%d%d", &(X), &(Y), &(Z), &(W))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define DRIIII(X, Y, Z, W) int X, Y, Z, W; scanf("%d%d%d%d", &X, &Y, &Z, &W)
#define RS(X) scanf("%s", (X))
#define LEN(X) int(strlen(X))
#define MS0(X) memset((X), 0, sizeof(X))
#define MSI(X) memset((X), 0xFF, sizeof(X))
#define F first
#define S second
#define MP make_pair
#define PB push_back

using namespace std;

#ifdef DK
const int size = 100;
#else
const int size = 1e5 + 10;
#endif

char a[size];

char s1[] = "12345678";
char s2[] = "87654321";

typedef unsigned long long int ll;

int main()
{
#ifdef DK
  freopen("in.txt", "r", stdin);
#endif

  RS(a);

  int len = LEN(a);

  if (len == 1) {
    printf("1");
    return 0;
  }

  bool has = false;

  REP(i, len) {
    if (a[i] == '9') {
      has = true;
      break;
    }
  }

  ll res = has ? 1 : 0;
  ll s = 0;

  REP(i, len - 1) {
    ll cnt = 0;

    REPP(k, i, len - 1) {
      bool f = false;

      REP(j, 8) {
        if (a[k] == s1[j] && a[k + 1] == s2[j]) {
          cnt++;
          f = true;
          break;
        }
      }

      if (!f || k == len - 2) {
        i = k;
        break;
      }
    }

    if (cnt > 0) {
      cnt++;

      if (res == 0) {
        res = 1;
      }

      if (cnt % 2 != 0) {
        s += (cnt / 2);
      }
    }
  }

  if (res) {
    res = 1 << s;
  }

  if (has && res == 0) {
    printf("1");
    return 0;
  }

  cout << res;

  return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <queue>

#define REP(I, N) for (int I = 0; I < (N); ++I)
#define PER(I, N) for (int I = (N); I >= 0; --I)
#define PERR(I, A, B) for (int I = (A); I >= (B); --I)
#define REPP(I, A, B) for (int I = (A); I <  (B); ++I)
#define REPN(I, A, B) for (int I = (A); I <= (B); ++I)
#define REPPP(I, A, B, C) for (int I = (A); I <  (B); I += C)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define RIIII(X, Y, Z, W) scanf("%d%d%d%d", &(X), &(Y), &(Z), &(W))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define DRIIII(X, Y, Z, W) int X, Y, Z, W; scanf("%d%d%d%d", &X, &Y, &Z, &W)
#define RS(X) scanf("%s", (X))
#define LEN(X) int(strlen(X))
#define MS0(X) memset((X), 0, sizeof(X))
#define MSI(X) memset((X), 0xFF, sizeof(X))
#define F first
#define S second
#define MP make_pair
#define PB push_back

using namespace std;

#ifdef DK
const int size = 100;
#else
const int size = 1e5 + 10;
#endif

char a[size];

char s1[] = "12345678";
char s2[] = "87654321";

int main()
{
#ifdef DK
  freopen("in.txt", "r", stdin);
#endif

  RS(a);

  int len = LEN(a);

  if (len == 1) {
    printf("1");
    return 0;
  }

  bool has = false;

  REP(i, len) {
    if (a[i] == '9') {
      has = true;
      break;
    }
  }

  int res = 0;

  REP(i, len - 1) {
    int cnt = 0;

    REPP(k, i, len - 1) {
      bool f = false;

      REP(j, 8) {
        if (a[k] == s1[j] && a[k + 1] == s2[j]) {
          cnt++;
          f = true;
          break;
        }
      }

      if (!f || k == len - 2) {
        i = k;
        break;
      }
    }

    if (cnt > 0) {
      cnt++;

      if (cnt % 2 != 0) {
        res+=(cnt + 1) / 2;
      }
    }

    cnt = 0;
  }

  if (has && res == 0) {
    printf("1");
    return 0;
  }

  printf("%d", res);

  return 0;
}


#include <bits/stdc++.h>

#define ill unsigned long long

using namespace std;

const int INF = 1e9 + 7;
const int MXN = 1e5 + 7;

char s[MXN];
ill n, ans = 1;

int main()
{
    gets(s);
    n = strlen(s);

    ill cur = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i] + s[i + 1] - 96 == 9)
        {
            cur++;
        }
        else
        {
            cur++;
            ans *= (cur + 1) / 2;

            cur = 0;
        }
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

#define ill unsigned long long

using namespace std;

const int INF = 1e9 + 7;
const int MXN = 1e5 + 7;

char s[MXN];
ill n, ans = 1;

int main()
{
    gets(s);
    n = strlen(s);

    ill cur = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i] + s[i + 1] - 96 == 9)
        {
            cur++;
        }
        else
        {
            cur++;
            if (cur > 2)
                ans *= (cur + 1) / 2;
            cur = 0;
        }
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

#define ill long long

using namespace std;

const int INF = 1e9 + 7;
const int MXN = 1e5 + 7;

string s;
ill ans = 1;

int main()
{
    cin >> s;

    int cur = 0;
    while (cur < s.length() - 1)
    {
        if (s[cur] + s[cur + 1] - 96 == 9)
        {
            int tmp = 1;
            int id = cur + 1;
            while (s[cur + 2] == s[cur] && s[cur + 1] == s[id] && cur + 2 < s.length())
            {
                cur += 2;
                tmp += 2;
            }
            if (tmp & 1)
                ans *= (tmp / 2) + 1;
        }
        cur++;
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

#define ill long long

using namespace std;

const int INF = 1e9 + 7;
const int MXN = 1e5 + 7;

string s;
ill ans = 1;

int main()
{
    cin >> s;

    ill cur = 0;
    while (cur < s.length() - 1)
    {
        if (s[cur] + s[cur + 1] - 96 == 9)
        {
            ill tmp = 1;
            ill id = cur + 1;

            cur++;
            while (s[cur] + s[cur + 1] - 96 == 9 && cur + 1 < s.length())
                tmp++, cur++;

            if (tmp & 1)
                ans *= (tmp >> 1) + 1;
        }
        cur++;
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

#define ill unsigned long long

using namespace std;

const int INF = 1e9 + 7;
const int MXN = 1e5 + 7;

char s[MXN];
ill n, ans = 1;

int main()
{
    gets(s);
    n = strlen(s);

    ill cur = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i] + s[i + 1] - 96 == 9)
        {
            cur++;
        }
        else
        {
            cur++;
            if (cur & 1)
                ans *= (cur + 1) / 2;

            cur = 0;
        }
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

#define ill unsigned long long

using namespace std;

const int INF = 1e9 + 7;
const int MXN = 1e5 + 7;

char s[MXN];
ill n, ans = 1;

int main()
{
    gets(s);
    n = strlen(s);

    ill cur = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i] + s[i + 1] - 96 == 9)
        {
            cur++;
        }
        else
        {
            cur++;
            if (cur & 1)
                ans *= cur / 2;
            cur = 0;
        }
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

#define ill long long

using namespace std;

const int INF = 1e9 + 7;
const int MXN = 1e5 + 7;

string s;
ill ans = 1;

int main()
{
    cin >> s;

    ill cur = 0;
    while (cur < s.length() - 1)
    {
        if (s[cur] + s[cur + 1] - 96 == 9)
        {
            ill tmp = 1;
            ill id = cur + 1;
            while (s[cur + 2] == s[cur] && s[cur + 1] == s[id] && cur + 2 < s.length())
            {
                cur += 2;
                tmp += 2;
            }
            if (tmp & 1)
                ans *= (tmp >> 1) + 1;
        }
        cur++;
    }
    cout << ans;
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int arr[1000000],i,n=1,flag=0,count=0,c;
    cin>>n;
    do
    {
        arr[count]=(n%10);
        n/=10;
        count++;
    }while(n>0);
    n=1;
    for(i=0;i<(count-1);i++)
    {
        c=0;
        if((arr[i] + arr[(i+1)])==9)
        {
            flag=1;
            while((arr[i]+arr[(i+1)])==9 && i<(count-1))
            {
                i++;
                c++;
            }
            i--;
            if(c%2==0)
            {
                c=(c/2)+1;
                n*=c;
            }
        }
    }
if(flag==0)
cout<<0;

else
cout<<n;

}


#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    char ch;
    int arr[100000000],i,flag=0,count=0;
    long c,n=1;
    do
    {
        cin.get(ch);
        if(ch>='0' && ch<='9')
        {
        arr[count]= int(ch)-'0';
        count++;
        }
    }while(ch>='0' && ch<='9');
    n=1;
    for(i=0;i<(count-1);i++)
    {
        c=0;
        if((arr[i] + arr[(i+1)])==9)
        {
            flag=1;
            while((arr[i]+arr[(i+1)])==9 && i<(count-1))
            {
                i++;
                c++;
            }
            i--;
            if(c%2==0)
            {
                c=(c/2)+1;
                n*=c;
            }
        }
    }
if(flag==0)
cout<<1;

else
cout<<n;

}


#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    char ch;
    int arr[1000000],i,n=1,flag=0,count=0,c;
    do
    {
        cin.get(ch);
        if(ch>='0' && ch<='9')
        {
        arr[count]= int(ch)-'0';
        count++;
        }
    }while(ch>='0' && ch<='9');
    n=1;
    for(i=0;i<(count-1);i++)
    {
        c=0;
        if((arr[i] + arr[(i+1)])==9)
        {
            flag=1;
            while((arr[i]+arr[(i+1)])==9 && i<(count-1))
            {
                i++;
                c++;
            }
            i--;
            if(c%2==0)
            {
                c=(c/2)+1;
                n*=c;
            }
        }
    }
if(flag==0)
cout<<1;

else
cout<<n;

}


#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    char ch;
    int arr[10000000],i,flag=0,count=0;
    long long c,n=1;
    do
    {
        cin.get(ch);
        if(ch>='0' && ch<='9')
        {
        arr[count]= int(ch)-'0';
        count++;
        }
    }while(ch>='0' && ch<='9');
    n=1;
    for(i=0;i<(count-1);i++)
    {
        c=0;
        if((arr[i] + arr[(i+1)])==9)
        {
            flag=1;
            while((arr[i]+arr[(i+1)])==9 && i<(count-1))
            {
                i++;
                c++;
            }
            i--;
            if(c%2==0)
            {
                c=(c/2)+1;
                n*=c;
            }
        }
    }
if(flag==0)
cout<<1;

else
cout<<n;

}


#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    char ch;
    int arr[1000000],i,flag=0,count=0;
    long c,n=1;
    do
    {
        cin.get(ch);
        if(ch>='0' && ch<='9')
        {
        arr[count]= int(ch)-'0';
        count++;
        }
    }while(ch>='0' && ch<='9');
    n=1;
    for(i=0;i<(count-1);i++)
    {
        c=0;
        if((arr[i] + arr[(i+1)])==9)
        {
            flag=1;
            while((arr[i]+arr[(i+1)])==9 && i<(count-1))
            {
                i++;
                c++;
            }
            i--;
            if(c%2==0)
            {
                c=(c/2)+1;
                n*=c;
            }
        }
    }
if(flag==0)
cout<<1;

else
cout<<n;

}


#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    char ch;
    int arr[10000000],i,flag=0,count=0;
    long c,n=1;
    do
    {
        cin.get(ch);
        if(ch>='0' && ch<='9')
        {
        arr[count]= int(ch)-'0';
        count++;
        }
    }while(ch>='0' && ch<='9');
    n=1;
    for(i=0;i<(count-1);i++)
    {
        c=0;
        if((arr[i] + arr[(i+1)])==9)
        {
            flag=1;
            while((arr[i]+arr[(i+1)])==9 && i<(count-1))
            {
                i++;
                c++;
            }
            i--;
            if(c%2==0)
            {
                c=(c/2)+1;
                n*=c;
            }
        }
    }
if(flag==0)
cout<<1;

else
cout<<n;

}


#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int arr[1000000],i,n=1,flag=0,count=0,c;
    cin>>n;
    do
    {
        arr[count]=(n%10);
        n/=10;
        count++;
    }while(n>0);
    n=1;
    for(i=0;i<(count-1);i++)
    {
        c=0;
        if((arr[i] + arr[(i+1)])==9)
        {
            flag=1;
            while((arr[i]+arr[(i+1)])==9 && i<(count-1))
            {
                i++;
                c++;
            }
            i--;
            if(c%2==0)
            {
                c=(c/2)+1;
                n*=c;
            }
        }
    }
if(flag==0)
cout<<1;

else
cout<<n;

}


/*Archit Mittal*/

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<utility>
#include<set>

#define ull unsigned long long
#define ll long long
#define pii pair<int,int>
#define pb(x) push_back(x)
#define S(x) scanf("%d",&x)
#define Sl(x) scanf("%lld",&x)
#define M(x,i) memset(x,i,sizeof(x))
#define F(i,a,n) for(i=(a);i<(n);++i)
#define FD(i,a,n) for(i=(a);i>=(n);--i)

using namespace std;

int main()
{
    string s;
	int i;
	ll ans=0,p,cnt;
	cin>>s;

	int len=s.length();

	cnt=0;
	while(i<s.length()-1){
		if((s[i]-'0'+s[i+1]-'0')==9){
			cnt++;
		} else {
			if(cnt>1){
				cnt++;
				if(cnt&1){
					ans+=(cnt+1)/2;
				} else {
					p=cnt/2;
					if(p>1)ans+=(p-1)*(p-2)+p;
				}
			}
				cnt=0;
		}
		//cout<<i<<" "<<ans<<endl;
		i++;
	}
	//cout<<cnt<<endl;
	if(cnt>1){
				cnt++;
				if(cnt&1){
					ans+=(cnt+1)/2;
				} else {
					p=cnt/2;
					if(p>1)ans+=(ll)(p-1)*(p-2)+p;
				}
	}
	if(ans==0)cout<<1<<endl;
	else cout<<ans<<endl;
}


/*Archit Mittal*/

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<utility>
#include<set>

#define ull unsigned long long
#define ll long long
#define pii pair<int,int>
#define pb(x) push_back(x)
#define S(x) scanf("%d",&x)
#define Sl(x) scanf("%lld",&x)
#define M(x,i) memset(x,i,sizeof(x))
#define F(i,a,n) for(i=(a);i<(n);++i)
#define FD(i,a,n) for(i=(a);i>=(n);--i)

using namespace std;

map<int,int> mpc;
map<string,int> mp;
int ans,len;
void dfs(string s)
{
	int i;
	if(mp[s]==0){
		//cout<<s<<endl;
		mp[s]=1;
		int cnt=0;
		F(i,0,len){
			if(s[i]=='9')cnt++;
		}
		ans=max(ans,cnt);
		mpc[cnt]++;
    	F(i,0,len-1){
    		if((s[i]-'0'+s[i+1]-'0')==9){
    			dfs(s.substr(0,i)+"9"+s.substr(i+2));
    		}
    	}
	}
}
int main()
{
    string s;
	cin>>s;
	len=s.length();
	dfs(s);
	cout<<mpc[ans]<<endl;
}


/*Archit Mittal*/

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<utility>
#include<set>

#define ull unsigned long long
#define ll long long
#define pii pair<int,int>
#define pb(x) push_back(x)
#define S(x) scanf("%d",&x)
#define Sl(x) scanf("%lld",&x)
#define M(x,i) memset(x,i,sizeof(x))
#define F(i,a,n) for(i=(a);i<(n);++i)
#define FD(i,a,n) for(i=(a);i>=(n);--i)

using namespace std;

int main()
{
    string s;
	int i,cnt,p;
	ll ans=1;
	cin>>s;

	int len=s.length();

	cnt=0;
	while(i<s.length()-1){
		if((s[i]-'0'+s[i+1]-'0')==9){
			cnt++;
		} else {
			if(cnt>1){
				cnt++;
				if(cnt&1){
					ans+=(cnt+1)/2;
				} else {
					p=cnt/2;
					if(p>1)ans+=(ll)(p-1)*(p-2)+p;
				}
			}
				cnt=0;
		}
		//cout<<i<<" "<<ans<<endl;
		i++;
	}
	//cout<<cnt<<endl;
	if(cnt>1){
				cnt++;
				if(cnt&1){
					ans+=(cnt+1)/2;
				} else {
					p=cnt/2;
					if(p>1)ans+=(ll)(p-1)*(p-2)+p;
				}
			}
	cout<<ans<<endl;
}


/*Archit Mittal*/

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<utility>
#include<set>

#define ull unsigned long long
#define ll long long
#define pii pair<int,int>
#define pb(x) push_back(x)
#define S(x) scanf("%d",&x)
#define Sl(x) scanf("%lld",&x)
#define M(x,i) memset(x,i,sizeof(x))
#define F(i,a,n) for(i=(a);i<(n);++i)
#define FD(i,a,n) for(i=(a);i>=(n);--i)

using namespace std;

int main()
{
    string s;
	int i;
	ll ans=0,p,cnt;
	cin>>s;

	int len=s.length();

	cnt=0;
	while(i<s.length()-1){
		if((s[i]-'0'+s[i+1]-'0')==9){
			cnt++;
		} else {
			if(cnt>1){
				cnt++;
				if(cnt&1){
					ans+=(cnt+1)/2;
				} else {
					p=cnt/2;
					if(p>1)ans+=((p-1)*p)/2+1;
				}
			}
				cnt=0;
		}
		//cout<<i<<" "<<ans<<endl;
		i++;
	}
	//cout<<cnt<<endl;
	if(cnt>1){
				cnt++;
				if(cnt&1){
					ans+=(cnt+1)/2;
				} else {
					p=cnt/2;
					if(p>1)ans+=((p-1)*p)/2+1;
				}
	}
	if(ans==0)cout<<1<<endl;
	else cout<<ans<<endl;
}


/*Archit Mittal*/

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<utility>
#include<set>

#define ull unsigned long long
#define ll long long
#define pii pair<int,int>
#define pb(x) push_back(x)
#define S(x) scanf("%d",&x)
#define Sl(x) scanf("%lld",&x)
#define M(x,i) memset(x,i,sizeof(x))
#define F(i,a,n) for(i=(a);i<(n);++i)
#define FD(i,a,n) for(i=(a);i>=(n);--i)

using namespace std;

int main()
{
    string s;
	int i;
	ll ans=1,p,cnt;
	cin>>s;

	int len=s.length();

	cnt=0;
	while(i<s.length()-1){
		if((s[i]-'0'+s[i+1]-'0')==9){
			cnt++;
		} else {
			if(cnt>1){
				cnt++;
				if(cnt&1){
					ans*=(cnt+1)/2;
				}
			}
				cnt=0;
		}
		i++;
	}
	//cout<<cnt<<endl;
	if(cnt>1){
				cnt++;
				if(cnt&1){
					ans*=(cnt+1)/2;
				}
	}
	if(ans==0)cout<<1<<endl;
	else cout<<ans<<endl;
}


/*Archit Mittal*/

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<utility>
#include<set>

#define ull unsigned long long
#define ll long long
#define pii pair<int,int>
#define pb(x) push_back(x)
#define S(x) scanf("%d",&x)
#define Sl(x) scanf("%lld",&x)
#define M(x,i) memset(x,i,sizeof(x))
#define F(i,a,n) for(i=(a);i<(n);++i)
#define FD(i,a,n) for(i=(a);i>=(n);--i)

using namespace std;

int main()
{
    string s;
	int i;
	ll ans=0,p,cnt;
	cin>>s;

	int len=s.length();

	cnt=0;
	while(i<s.length()-1){
		if((s[i]-'0'+s[i+1]-'0')==9){
			cnt++;
		} else {
			if(cnt>1){
				cnt++;
				if(cnt&1){
					ans+=(cnt+1)/2;
				} /*else {
					p=cnt/2;
					if(p>1)ans+=((p-1)*p)/2+1;
				}*/
			}
				cnt=0;
		}
		//cout<<i<<" "<<ans<<endl;
		i++;
	}
	//cout<<cnt<<endl;
	if(cnt>1){
				cnt++;
				if(cnt&1){
					ans+=(cnt+1)/2;
				} /*else {
					p=cnt/2;
					if(p>1)ans+=((p-1)*p)/2+1;
				}*/
	}
	if(ans==0)cout<<1<<endl;
	else cout<<ans<<endl;
}


/*Archit Mittal*/

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<utility>
#include<set>

#define ull unsigned long long
#define ll long long
#define pii pair<int,int>
#define pb(x) push_back(x)
#define S(x) scanf("%d",&x)
#define Sl(x) scanf("%lld",&x)
#define M(x,i) memset(x,i,sizeof(x))
#define F(i,a,n) for(i=(a);i<(n);++i)
#define FD(i,a,n) for(i=(a);i>=(n);--i)

using namespace std;

int main()
{
    string s;
	int i,cnt,p;
	ll ans=0;
	cin>>s;

	int len=s.length();

	cnt=0;
	while(i<s.length()-1){
		if((s[i]-'0'+s[i+1]-'0')==9){
			cnt++;
		} else {
			if(cnt>1){
				cnt++;
				if(cnt&1){
					ans+=(cnt+1)/2;
				} else {
					p=cnt/2;
					if(p>1)ans+=(ll)(p-1)*(p-2)+p;
				}
			}
				cnt=0;
		}
		//cout<<i<<" "<<ans<<endl;
		i++;
	}
	//cout<<cnt<<endl;
	if(cnt>1){
				cnt++;
				if(cnt&1){
					ans+=(cnt+1)/2;
				} else {
					p=cnt/2;
					if(p>1)ans+=(ll)(p-1)*(p-2)+p;
				}
			}
	if(ans==0)cout<<1<<endl;
	else cout<<ans<<endl;
}


#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <utility>
#include <iostream>
#include <algorithm>
#include <stdexcept>
#include <functional>

using namespace std;

#define PB push_back
#define MP make_pair
#define AA first
#define BB second
#define OP begin()
#define ED end()

typedef long long LL;
typedef pair<int, int> PII;
char s[111111];
int a[111111];
LL dp[111111];
void solve(){
    while(~scanf("%s",s)){
        int len=strlen(s),i;
        for(i=0;i<=len;i++)dp[i]=0LL;
        for(i=0;i<len;i++)a[i]=s[i]-'0';
        dp[0]=1LL;
        for(i=0;i<len;i++){
            if(i+1<len&&a[i]+a[i+1]==9){
                if(i+2<len&&a[i]==a[i+2])dp[i+3]+=dp[i];
                dp[i+2]+=dp[i];
            }else dp[i+1]+=dp[i];
        }
//      for(i=0;i<=len;i++)cout<<dp[i]<<" ";cout<<endl;
        cout<<dp[len]<<endl;
    }
}
/*
2727
*/
int main(){
//  while(1)
        solve();
    return 0;
}


#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <utility>
#include <iostream>
#include <algorithm>
#include <stdexcept>
#include <functional>

using namespace std;

#define PB push_back
#define MP make_pair
#define AA first
#define BB second
#define OP begin()
#define ED end()

typedef long long LL;
typedef pair<int, int> PII;
char s[111111];
int a[111111];
LL dp[111111];
void solve(){
	while(~scanf("%s",s)){
		int len=strlen(s),i;
		for(i=0;i<=len;i++)dp[i]=0LL;
		for(i=0;i<len;i++)a[i]=s[i]-'0';
		LL res=1LL;
		for(i=0;i<len;i++){
			int j=i+1;
			while(j<len&&a[j-1]+a[j]==9)j++;
			if((j-i)%2!=0)res*=(j-i+1)/2;
		}
//		for(i=0;i<=len;i++)cout<<dp[i]<<" ";cout<<endl;
//		cout<<dp[len]<<endl;
		cout<<res<<endl;
	}
}
/*
2727
*/
int main(){
//	while(1)
		solve();
	return 0;
}


#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <utility>
#include <iostream>
#include <algorithm>
#include <stdexcept>
#include <functional>

using namespace std;

#define PB push_back
#define MP make_pair
#define AA first
#define BB second
#define OP begin()
#define ED end()

typedef long long LL;
typedef pair<int, int> PII;
char s[111111];
int a[111111];
void solve(){
    while(~scanf("%s",s)){
        int len=strlen(s),i;
        for(i=0;i<len;i++)a[i]=s[i]-'0';
        LL res=1LL;
        for(i=0;i<len;){
            int j=i+1;
            while(j<len&&a[j-1]+a[j]==9)j++;
            if((j-i)%2!=0)res*=1LL*(j-i+1)/2;
            i=j;
        }
        cout<<res<<endl;
    }
}
int main(){
        solve();
    return 0;
}


#include <iostream>
#include <stdio.h>
using namespace std;
long long t = 1;
int main()
{
    int i,j,k = 0;
    char ch;
    j = 10;
    while (scanf("%c",&ch))
    {
        if (ch > '9' || ch < '0') break;
        i = ch - '0';
        if (i + j ==9)
        {
            k++;
        }else
        {
            if (k % 2 ==0)
            t = t*(1+k/2);
            k = 0;
        }
        j = i;
    }
    cout << t<<endl;
    return 0;
}


#include <iostream>
#include <stdio.h>
using namespace std;
unsigned long long t = 1;
int main()
{
    int i,j,k = 0;
    char ch;
    j = 10;
    while (scanf("%c",&ch))
    {
        if (ch > '9' || ch <= '0') break;
        i = ch - '0';
        if (i + j ==9)
        {
            k++;
        }else
        {
            if (k % 2 ==0)
                t = t*(1+k/2);
            k = 0;
        }
        j = i;
    }
    if (k % 2 ==0)
        t =t *(1+k/2);
    cout <<t<<endl;
    return 0;
}


#include <iostream>
#include <stdio.h>
using namespace std;
int a[100011] = {};
int main()
{
    int i,j,k = 0;
    char ch;
    j = 10;
    while (scanf("%c",&ch))
    {
        if (ch > '9' || ch < '0') break;
        i = ch - '0';
        if (i + j ==9)
        {
            k++;
        }else
        {
            a[k]++;
            k = 0;
        }
        j = i;
    }
    a[k] ++;
    unsigned long long t = 1;
    for ( i = 1; i < 100011;i++)
    {
        if ((i %2 == 0) && a[i] != 0)
        {
            t = t*a[i]*(1+i/2);
        }
    }
    cout << t<<endl;
    return 0;
}