#include <bits/stdc++.h>
using namespace std;
int mp[4][4], n;
long long dp[50][5][5];
int con[5][5], term, start, aim;
void dfs(int a, int b, long long sum) {
  if (a == aim && b == aim) {
    dp[term][start][aim] = min(dp[term][start][aim], sum);
    return;
  }
  for (int i = 1; i <= 2; i++) {
    int to = a + i;
    if (to > 3) to -= 3;
    if (!con[to][b]) {
      con[to][b] = 1;
      dfs(to, b, sum + dp[term - 1][a][to]);
      con[to][b] = 0;
    }
  }
  for (int i = 1; i <= 2; i++) {
    int to = b + i;
    if (to > 3) to -= 3;
    if (!con[a][to] && a != to && a != b) {
      con[a][to] = 1;
      dfs(a, to, sum + mp[b][to]);
      con[a][to] = 0;
    }
  }
}
int main() {
  for (int i = 1; i <= 3; i++)
    for (int j = 1; j <= 3; j++) scanf("%d", &mp[i][j]);
  scanf("%d", &n);
  memset(dp, 0, sizeof dp);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= 3; j++)
      for (int k = 1; k <= 3; k++) {
        memset(con, 0, sizeof con);
        term = i;
        start = j;
        aim = k;
        dp[i][j][k] = 0x3f3f3f3f3f3f3f3f;
        con[j][j] = 1;
        dfs(j, j, 0);
      }
  printf("%I64d\n", dp[n][1][3]);
  return 0;
}
