#include <bits/stdc++.h>
using namespace std;
long long g[5][5], f[45][5][5], n;
int main() {
  for (int i = 1; i <= 3; ++i)
    for (int j = 1; j <= 3; ++j) cin >> g[i][j];
  cin >> n;
  for (int i = 1; i <= 3; ++i)
    for (int j = 1; j <= 3; ++j) f[0][i][j] = 0;
  for (int t = 1; t <= n; ++t) {
    for (int i = 1; i <= 3; ++i)
      for (int j = 1; j <= 3; ++j) {
        if (i == j) continue;
        int k = 6 - i - j;
        f[t][i][j] = f[t - 1][i][k] + f[t - 1][k][j] + g[i][j];
        f[t][i][j] = min(f[t][i][j], f[t - 1][i][j] + g[i][k] + f[t - 1][j][i] +
                                         g[k][j] + f[t - 1][i][j]);
      }
  }
  cout << f[n][1][3] << endl;
  return 0;
}
