#include <bits/stdc++.h>
using namespace std;
int t[45][45];
long long dp[45][45][45][45];
long long rec(int n, int from, int via, int to) {
  if (n == 1) return min(t[from][to], t[from][via] + t[via][to]);
  long long &ret = dp[n][from][via][to];
  if (ret != -1) return ret;
  ret = rec(n - 1, from, to, via) + rec(n - 1, via, from, to) + t[from][to];
  ret = min(ret, rec(n - 1, from, via, to) + t[from][via] +
                     rec(n - 1, to, via, from) + t[via][to] +
                     rec(n - 1, from, via, to));
  return ret;
}
int main() {
  int n, m, cas = 3;
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < cas; i++)
    for (int j = 0; j < cas; j++) scanf("%d", &t[i][j]);
  scanf("%d", &n);
  printf("%lld\n", rec(n, 0, 1, 2));
  return 0;
}
