/// Md Abdur Rahman Salman ///
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define bug(x) cout << #x << ": " << x << endl
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
string s, t; cin >> t;
s = "";
for(auto c : t)
{
if(c != '+' and c != '.')
{
s += c;
}
}
ll n; cin >> n;
if(n == 1 or s.size() == 1)
{
cout << s[0] << endl;
return 0;
}
ll a = s[0] - '0';
ll y = s[1] - '0';
ll d = y - a;
ll sum = (1LL * n * (2 * a + (n - 1) * d)) / 2;
cout << sum << endl;
return 0;
}