Language: C++

// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)			 	 cerr<<#x<<": "<<x<<endl
#define trace2(x, y)		 	 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)		 	 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)	 	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	vector<int> dp(3,0);
	rep(i,0,n){
		vector<int> c(3);
		vector<int> new_dp(3,0);
		rep(i,0,3) cin >> c[i];
		rep(i,0,3){
			rep(j,0,3){
				if(i!=j){
					new_dp[i]=max(new_dp[i],dp[j]+c[j]);
				}
			}
		}
		dp=new_dp;
	}
	cout << max3(dp[0],dp[1],dp[2]);
	return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)			 	 cerr<<#x<<": "<<x<<endl
#define trace2(x, y)		 	 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)		 	 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)	 	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	vector<int> dp(3,0);
	rep(i,0,n){
		vector<int> c(3);
		vector<int> new_dp(3,0);
		rep(i,0,3) cin >> c[i];
		rep(i,0,3){
			rep(j,0,3){
				if(i!=j){
					new_dp[i]=max(new_dp[i],dp[j]+c[j]);
				}
			}
		}
		dp=new_dp;
	}
	cout << max3(dp[0],dp[1],dp[2]);
	return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


Compiler output:
a.cc:105:4: error: redefinition of 'long long int max3(long long int, long long int, long long int)'
  105 | ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
      |    ^~~~
a.cc:28:4: note: 'long long int max3(long long int, long long int, long long int)' previously defined here
   28 | ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
      |    ^~~~
a.cc:106:4: error: redefinition of 'long long int min3(long long int, long long int, long long int)'
  106 | ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
      |    ^~~~
a.cc:29:4: note: 'long long int min3(long long int, long long int, long long int)' previously defined here
   29 | ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
      |    ^~~~
a.cc:107:10: error: redefinition of 'const long long int M'
  107 | const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
      |          ^
a.cc:30:10: note: 'const long long int M' previously defined here
   30 | const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
      |          ^
a.cc:107:19: error: redefinition of 'const long long int M2'
  107 | const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
      |                   ^~
a.cc:30:19: note: 'const long long int M2' previously defined here
   30 | const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
      |                   ^~
a.cc:107:29: error: redefinition of 'const long long int mod'
  107 | const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
      |                             ^~~
a.cc:30:29: note: 'const long long int mod' previously defined here
   30 | const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
      |                             ^~~
a.cc:107:39: error: redefinition of 'const long long int inf'
  107 | const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
      |                                       ^~~
a.cc:30:39: note: 'const long long int inf' previously defined here
   30 | const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
      |                                       ^~~
a.cc:108:6: error: redefinition of 'void add(int&, int)'
  108 | void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
      |      ^~~
a.cc:31:6: note: 'void add(int&, int)' previously defined here
   31 | void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
      |      ^~~
a.cc:115:5: error: redefinition of 'int X []'
  115 | int X[] = {0, 1, 0, -1};
      |     ^
a.cc:38:5: note: 'int X [4]' previously defined here
   38 | int X[] = {0, 1, 0, -1};
      |     ^
a.cc:116:5: error: redefinition of 'int Y []'
  116 | int Y[] = {-1, 0, 1, 0};
      |     ^
a.cc:39:5: note: 'int Y [4]' previously defined here
   39 | int Y[] = {-1, 0, 1, 0};
      |     ^
a.cc:117:4: error: redefinition of 'long long int power(long long int, long long int)'
  117 | ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}
      |    ^~~~~
a.cc:40:4: note: 'long long int power(long long int, long long int)' previously defined here
   40 | ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}
      |    ^~~~~
a.cc:120:5: error: redefinition of 'int main()'
  120 | int main()
      |     ^~~~
a.cc:43:5: note: 'int main()' previously defined here
   43 | int main()
      |     ^~~~