#include <iostream>
using namespace std;
int main() {
int t1,t2,t3,x,y,z,n; bool wd=false;
cin>>n;
cin>>t1>>t2>>t3;
x = t1; y = x + t2; z = y + t3;
for (int i = 0; i<n-1; i++){
cin>>t1>>t2>>t3;
if ((t1<0)||(t2<0)||(t3<0)) {cout<<"Ошибка"; wd=true; break;}
else { x += t1; y = max(x, y) + t2; z = max(y, z) + t3;}
}
if (wd == false) {
cout<<"Общее время обработки всех деталей = "<<z;}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CglpbnQgdDEsdDIsdDMseCx5LHosbjsgYm9vbCB3ZD1mYWxzZTsKCWNpbj4+bjsKCWNpbj4+dDE+PnQyPj50MzsKCXggPSB0MTsgeSA9IHggKyB0MjsgeiA9IHkgKyB0MzsKCWZvciAoaW50IGkgPSAwOyBpPG4tMTsgaSsrKXsKCQljaW4+PnQxPj50Mj4+dDM7CgkJaWYgKCh0MTwwKXx8KHQyPDApfHwodDM8MCkpIHtjb3V0PDwi0J7RiNC40LHQutCwIjsgd2Q9dHJ1ZTsgYnJlYWs7fQoJCWVsc2UgeyB4ICs9IHQxOyB5ID0gbWF4KHgsIHkpICsgdDI7IHogPSBtYXgoeSwgeikgKyB0Mzt9Cgl9CglpZiAod2QgPT0gZmFsc2UpIHsKCQljb3V0PDwi0J7QsdGJ0LXQtSDQstGA0LXQvNGPINC+0LHRgNCw0LHQvtGC0LrQuCDQstGB0LXRhSDQtNC10YLQsNC70LXQuSA9ICI8PHo7fQp9