#include <bits/stdc++.h>
using namespace std;
long long int dp[45][4][4], n;
long long int w[4][4];
int main(void) {
  for (int i = 1; i <= 3; i++)
    for (int j = 1; j <= 3; j++) cin >> w[i][j];
  cin >> n;
  for (int i = 1; i <= 3; i++)
    for (int j = 1; j <= 3; j++)
      if (i != j) dp[0][i][j] = 0;
  for (int i = 1; i <= n; i++)
    for (int a = 1; a <= 3; a++)
      for (int b = 1; b <= 3; b++) {
        if (a != b) {
          int c;
          c = 6 - a - b;
          long long int cara1 = dp[i - 1][a][c] + w[a][b] + dp[i - 1][c][b];
          long long int cara2 = dp[i - 1][a][b] + w[a][c] + dp[i - 1][b][a] +
                                w[c][b] + dp[i - 1][a][b];
          dp[i][a][b] = min(cara1, cara2);
        }
      }
  cout << dp[n][1][3] << endl;
}
