#include <bits/stdc++.h>
using namespace std;
long long dp[50][4][4];
int t[4][4];
int main() {
  int n, i, j, k;
  for (i = 1; i <= 3; i++)
    for (j = 1; j <= 3; j++) cin >> t[i][j];
  cin >> n;
  for (k = 1; k <= n; k++)
    for (i = 1; i <= 3; i++)
      for (j = 1; j <= 3; j++) {
        if (i == j) continue;
        long long s1 =
            dp[k - 1][i][6 - i - j] + t[i][j] + dp[k - 1][6 - i - j][j];
        long long s2 = dp[k - 1][i][j] + t[i][6 - i - j] + dp[k - 1][j][i] +
                       t[6 - i - j][j] + dp[k - 1][i][j];
        dp[k][i][j] = min(s1, s2);
      }
  cout << dp[n][1][3] << endl;
  return 0;
}
