/* --- "Start your journey in the name of God." --- */
/* ----- Amit Bhowmik ----- */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using int128 = __int128;
using ull = unsigned long long;
using u32 = unsigned;
const ll mod = 1e9 + 7;
const ll mx = 1e7 + 123;
typedef vector<ll> vl;
#define nl '\n';
typedef long double ld;
#define PB push_back
#define F first
#define S second
#define sz(x) x.size()
#define mid(l,r) ((r+l)/2)
const double PI = acos(-1);
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sqr(a) ((a) * (a))
#define YES cout << "YES" << nl;
#define NO cout << "NO" << nl;
#define lowerstr(x) transform(all(x),x.begin(), ::tolower)
#define upperstr(x) transform(all(x),x.begin(), ::toupper)
void solve() {
string s;
ll n;
cin >> s >> n;
vector<ll> v;
string str = "";
for (auto c : s) {
if (isdigit(c)) {
str += c;
}
else if (c == '+') {
if (!str.empty()) {
v.PB(stoll(str));
str.clear();
}
}
}
if (!str.empty()) v.PB(stoll(str));
ll a1 = v[0], a2 = v[1];
ll d = a2 - a1;
ll an = a1 + (n - 1) * d;
cout << (a1 + an) * n / 2 << nl;
return;
}
int main() {
fast_io;
// ll t; cin >> t;
// while(t--)
solve();
return 0;
}