// @rakibul-islam
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const ll oo = 1e17;
// 1 + 3 + 5 + 7 + 9
int main() {
cin.tie(0)->sync_with_stdio(0);
string s; cin >> s;
int n; cin >> n;
ll fst = 0, snd = 0;
int i = 0;
while (s[i] != '+') {
fst *= 10;
fst += int(s[i] - '0');
i++;
}
i++;
while (s[i] != '+') {
snd *= 10;
snd += int(s[i] - '0');
i++;
}
ll dif = (snd - fst);
ll add = dif * (n - 1);
ll N = fst + add;
ll sum = n * (fst + N);
sum /= 2;
cout << sum << "\n";
return 0;
}