C - Vacation

Problem Statement

Taro's summer vacation starts tomorrow, and he has decided to make plans for it now.

The vacation consists of NN days. For each ii (1iN1≤i≤N), Taro will choose one of the following activities and do it on the ii-th day:

  • A: Swim in the sea. Gain aiai points of happiness.
  • B: Catch bugs in the mountains. Gain bibi points of happiness.
  • C: Do homework at home. Gain cici points of happiness.

As Taro gets bored easily, he cannot do the same activities for two or more consecutive days.

Find the maximum possible total points of happiness that Taro gains.

Constraints

  • All values in input are integers.
  • 1N1051≤N≤105
  • 1ai,bi,ci1041≤ai,bi,ci≤104

Input

Input is given from Standard Input in the following format:

NN
a1a1 b1b1 c1c1
a2a2 b2b2 c2c2
::
aNaN bNbN cNcN

Output

Print the maximum possible total points of happiness that Taro gains.


Sample Input 1 Copy

Copy
3
10 40 70
20 50 80
30 60 90

Sample Output 1 Copy

Copy
210

If Taro does activities in the order C, B, C, he will gain 70+50+90=21070+50+90=210 points of happiness.


Sample Input 2 Copy

Copy
1
100 10 1

Sample Output 2 Copy

Copy
100

Sample Input 3 Copy

Copy
7
6 7 8
8 8 3
2 5 2
7 8 6
4 6 8
2 3 4
7 5 1

Sample Output 3 Copy

Copy
46

Taro should do activities in the order C, A, B, A, C, B, A.

posted @ 2020-06-15 12:19  DeaL57  阅读(222)  评论(0编辑  收藏  举报