#include <bits/stdc++.h>
using namespace std;
int cost[5][5], n, rem;
long long dp[105][10][10];
int main() {
  int n;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> cost[i][j];
    }
  }
  cin >> n;
  int zo;
  for (int k = 1; k <= n; k++)
    for (int i = 0; i < 3; i++)
      for (int j = 0; j < 3; j++)
        if (i - j) {
          rem = (3 ^ i ^ j);
          dp[k][i][j] = min(dp[k - 1][i][rem] + cost[i][j] + dp[k - 1][rem][j],
                            dp[k - 1][i][j] + cost[i][rem] + dp[k - 1][j][i] +
                                cost[rem][j] + dp[k - 1][i][j]);
        }
  cout << dp[n][0][2] << endl;
  ;
}
