Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/dp-tatil-kunlari

Vacation days

Easy 1000 ms 128 MB 30%
Share

A vacation lasts $n$ days. Each day you may choose one of three activities: swimming, hiking in the mountains or reading a book. On day $i$ they bring $a_{i}$, $b_{i}$ and $c_{i}$ points of joy respectively. The same activity cannot be done on two consecutive days. What is the largest amount of joy you can get during the vacation?

A table of days: the points of the three activities for each day, the chosen cells do not repeat on adjacent days

Input

The first line contains a positive integer $n$. Each of the next $n$ lines contains three positive integers: $a_{i}$, $b_{i}$ and $c_{i}$.

Output

One integer — the largest joy.

Note

$1 \le n \le 10^{5}$
$1 \le a_{i}, b_{i}, c_{i} \le 10^{4}$

Examples

Input #1
3
10 40 70
20 50 80
30 60 90
Output #1
210
Input #2
1
5 9 2
Output #2
9

Sign in to submit a solution

Signing up is free and takes a minute.