LogiQuest

262. Vacation Plan

MediumDynamic Programming

Each day you choose one of three activities with given happiness points, but you cannot do the same activity on two consecutive days. Print the maximum total happiness.

Input format

Line 1: n Next n lines: a b c

Output format

The maximum happiness.

Example 1

Input

3
10 40 70
20 50 80
30 60 90

Output

210

Example 2

Input

1
100 10 1

Output

100

Constraints

1 ≤ n ≤ 10⁵

Read input from standard input and print the answer to standard output. Your code is judged against 3 test cases, most of them hidden.

Loading the MyLoginn IDE…