#include <bits/stdc++.h>
using namespace std;
long long pd[41][3][3];
long long t[3][3];
int notin(int a, int b) {
  int m = min(a, b), M = max(a, b);
  if (m > 0) return 0;
  if (M < 2) return 2;
  return 1;
}
long long solve(int n, int from, int to) {
  if (!n) return 0;
  int other = notin(from, to);
  if (pd[n][from][to] == -1) {
    pd[n][from][to] =
        min(solve(n - 1, from, other) + t[from][to] + solve(n - 1, other, to),
            solve(n - 1, from, to) + t[from][other] + solve(n - 1, to, from) +
                t[other][to] + solve(n - 1, from, to));
  }
  return pd[n][from][to];
}
int main(void) {
  int n;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> t[i][j];
    }
  }
  cin >> n;
  memset(pd, -1, sizeof pd);
  cout << solve(n, 0, 2) << endl;
  return 0;
}
