#include <iostream>
#define MAX 9999999
using namespace std;
int rgb[3][1000];
int last[3][1000];
int N;
int low = 9999999;
void solution(int deep, int check, int sum)
{
if (deep == N)
{
if (low > sum)
low = sum;
return;
}
for (int i = 0; i < 3; i++)
{
if (check == i) continue; //이전의 색과 동일하다면 다른 색 선택
else if (last[i][deep] <= sum + rgb[i][deep]) continue; // 같은 위치에 이전에 입력된 것이 더 작을 경우
else last[i][deep] = sum + rgb[i][deep];
solution(deep + 1, i, last[i][deep]);
}
}
int main(void)
{
cin >> N;
for (int i = 0; i < N; i++)
{
for (int j = 0; j < 3; j++)
{
cin >> rgb[j][i];
last[j][i] = MAX;
}
}
solution(0, 3, 0);
cout << low;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojZGVmaW5lIE1BWCA5OTk5OTk5Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IHJnYlszXVsxMDAwXTsKaW50IGxhc3RbM11bMTAwMF07CmludCBOOwppbnQgbG93ID0gOTk5OTk5OTsKCnZvaWQgc29sdXRpb24oaW50IGRlZXAsIGludCBjaGVjaywgaW50IHN1bSkKewoJaWYgKGRlZXAgPT0gTikKCXsKCQlpZiAobG93ID4gc3VtKQoJCQlsb3cgPSBzdW07CgkJcmV0dXJuOwoJfQoKCWZvciAoaW50IGkgPSAwOyBpIDwgMzsgaSsrKQoJewoJCWlmIChjaGVjayA9PSBpKSBjb250aW51ZTsJLy/snbTsoITsnZgg7IOJ6rO8IOuPmeydvO2VmOuLpOuptCDri6Trpbgg7IOJIOyEoO2DnQoJCWVsc2UgaWYgKGxhc3RbaV1bZGVlcF0gPD0gc3VtICsgcmdiW2ldW2RlZXBdKSBjb250aW51ZTsJLy8g6rCZ7J2AIOychOy5mOyXkCDsnbTsoITsl5Ag7J6F66Cl65CcIOqyg+ydtCDrjZQg7J6R7J2EIOqyveyasAoJCWVsc2UgbGFzdFtpXVtkZWVwXSA9IHN1bSArIHJnYltpXVtkZWVwXTsKCQlzb2x1dGlvbihkZWVwICsgMSwgaSwgbGFzdFtpXVtkZWVwXSk7Cgl9Cn0KaW50IG1haW4odm9pZCkKewoJY2luID4+IE47CgoJZm9yIChpbnQgaSA9IDA7IGkgPCBOOyBpKyspCgl7CgkJZm9yIChpbnQgaiA9IDA7IGogPCAzOyBqKyspCgkJewoJCQljaW4gPj4gcmdiW2pdW2ldOwoJCQlsYXN0W2pdW2ldID0gTUFYOwoJCX0KCX0KCXNvbHV0aW9uKDAsIDMsIDApOwoJY291dCA8PCBsb3c7CglyZXR1cm4gMDsKfQ==