#include <bits/stdc++.h>
using namespace std;
const double PI = 2.0 * acos(0.0);
const double EPS = 1e-9;
int cases = 1;
double getdist(pair<int, int> a, pair<int, int> b) {
  return sqrt(pow(a.first - b.first, 2) + pow(a.second - b.second, 2));
}
void read(void) { return; }
long long dp[45][3][3][3];
int cost[3][3];
long long rec(int n, int from, int media, int to) {
  if (n == 0) return 0;
  long long& ret = dp[n][from][media][to];
  if (ret != -1) return ret;
  long long first, second;
  first = rec(n - 1, from, to, media) + cost[from][to] +
          rec(n - 1, media, from, to);
  second = rec(n - 1, from, media, to) + cost[from][media] +
           rec(n - 1, to, media, from) + cost[media][to] +
           rec(n - 1, from, media, to);
  return ret = min(first, second);
}
int main() {
  int test, n;
  for (int i = 0; i < 3; ++i)
    for (int j = 0; j < 3; ++j) scanf("%d", &cost[i][j]);
  memset(dp, -1, sizeof(dp));
  cin >> n;
  long long ans = rec(n, 0, 1, 2);
  cout << ans << endl;
  return 0;
}
