#include <bits/stdc++.h>
long long DP[42][7][7], N, T[7][7], o;
using namespace std;
int main() {
  for (int i = 1; i <= 3; i++)
    for (int j = 1; j <= 3; j++) cin >> T[i][j];
  cin >> N;
  for (int n = 1; n <= N; n++)
    for (int a = 1; a <= 3; a++)
      for (int b = 1; b <= 3; b++) {
        o = 6 - a - b;
        DP[n][a][b] =
            min(DP[n - 1][a][o] + T[a][b] + DP[n - 1][o][b],
                2 * DP[n - 1][a][b] + DP[n - 1][b][a] + T[a][o] + T[o][b]);
      }
  cout << DP[N][1][3];
}
