#include <bits/stdc++.h>
using namespace std;
long long cost[3][3];
const int MX = 60;
long long dp[MX][3][3];
bool used[MX][3][3];
long long minCost(long long n, long long from, long long to) {
  if (n == 0) return 0;
  if (used[n][from][to]) {
    return dp[n][from][to];
  }
  used[n][from][to] = true;
  long long aux;
  for (int i = 0; i < 3; i++) {
    if (i != from && i != to) {
      aux = i;
      break;
    }
  }
  return dp[n][from][to] = min(minCost(n - 1, from, aux) + cost[from][to] +
                                   minCost(n - 1, aux, to),
                               minCost(n - 1, from, to) + cost[from][aux] +
                                   minCost(n - 1, to, from) + cost[aux][to] +
                                   minCost(n - 1, from, to));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  for (long long i = 0; i < (long long)3; i++) {
    for (long long j = 0; j < (long long)3; j++) {
      cin >> cost[i][j];
    }
  }
  long long n;
  cin >> n;
  cout << minCost(n, 0, 2) << "\n";
  return 0;
}
