#include <iostream>
using namespace std;
int N =0;
int res[1001][1001]={9999,};
int MIN = 10000;
int func(int n, int c, int B, int *tri[501]){
if (n==0){
if (tri[n][c] < MIN){
MIN = tri[n][c];
B=c;
}
}
else{
if (c != B){
if ((res[n-1][B] + tri[n][c]) < MIN){
MIN= res[n-1][B] + tri[n][c];
res[n][c] = MIN;
B=c;
}
}
}
cout<< "B: " <<B<< "값: " << tri[n][B] << " n" << n << " c" << c << " MIN "<< MIN << " " << endl;
return MIN;
}
int main(){
cin >> N;
int** tri = new int*[N+1];
for (int i = 0; i < N; i++) {
tri[i] = new int[N+1];
fill_n(tri[i], N, 0);
for (int j = 0; j < 3; j++) {
cin >> tri[i][j];
}
}
int B=-1;
int a=-1;
for (int i = 0; i < N ; i++) {
MIN = 10000;
for (int j = 0; j < 3; j++) {
if (j==B){
continue;
}
else{
B = func(i,j,B, tri);
}
}
res[i][0] = MIN;
res[i][1] = MIN;
res[i][2] = MIN;
cout << "min: "<< MIN<< " " << B << endl;
}
int r_min = 10000;
for (int j = 0; j < 3; j++) {
if (r_min > res[N-1][j]) {
r_min=res[N-1][j];
}
cout << res[N-1][j] << endl;
}
return 0;
}