#include <bits/stdc++.h>
using namespace std;
long long Map[10][10];
long long dp[44][9][9];
long long gao(long long n, long long from, long long to) {
  if (n == 0) return 0;
  if (~dp[n][from][to]) return dp[n][from][to];
  long long mid = 6 - from - to;
  long long ret;
  long long tt = gao(n - 1, from, mid) + Map[from][to] + gao(n - 1, mid, to);
  long long tt1 = gao(n - 1, from, to) + Map[from][mid] + gao(n - 1, to, from) +
                  Map[mid][to] + gao(n - 1, from, to);
  ret = min(tt, tt1);
  return dp[n][from][to] = ret;
}
int main() {
  long long n;
  memset(dp, -1, sizeof(dp));
  for (long long i = 1; i <= 3; i++)
    for (long long j = 1; j <= 3; j++) scanf("%I64d", &Map[i][j]);
  scanf("%I64d", &n);
  cout << gao(n, 1, 3) << endl;
  return 0;
}
