#include <bits/stdc++.h> // All praise is due to Allah alone, and peace and blessings be
using namespace std; // upon him, after whom there is no other Prophet.
int32_t main() {
cin.tie(0)->sync_with_stdio(false);
int32_t Case = 1; //cin >> Case;
for (int T = 1; T <= Case; T++) {
string s; cin >> s;
int64_t n; cin >> n;
string a, b;
int i = 0;
for( i = 0; i < s.size(); i++) {
if(s[i] == '+') break;
a.push_back(s[i]);
}
for(i++; i < s.size(); i++) {
if(s[i] == '+') break;
b.push_back(s[i]);
}
int64_t A = stoll(a), B = stoll(b);
__int128_t ans = (A * 2 + (n - 1) * (B - A));
ans *= n;
ans /= 2;
string ok;
while(ans) {
ok.push_back(char(ans % 10 + '0')); ans /= 10;
}
reverse(ok.begin(), ok.end());
if(ok.empty()) cout << "0\n";
else cout << ok << '\n';
}
return 0;
}
// 2.5 * (2 + 4 * 2)