PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#QHD0000003. Kỳ nghỉ (Vacation)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Kỳ nghỉ (Vacation)

Vacation

Source: AtCoder

Problem Statement

A student has NN days of vacation. On each day, the student must choose exactly one of three activities:

  • Activity A earns aia_i happiness points on day ii.
  • Activity B earns bib_i happiness points on day ii.
  • Activity C earns cic_i happiness points on day ii.

The same activity cannot be chosen on two consecutive days. Total happiness is the sum of the points earned over all NN days.

Find the maximum possible total happiness.

Input

The first line contains NN, the number of vacation days.

Each of the next NN lines contains three integers ai,bi,cia_i,b_i,c_i, the happiness points for the three activities on day ii.

Output

Print one integer: the maximum achievable total happiness.

Subtasks

  • Subtask 1 (20 points): 1≤N≤51\le N\le 5; 1≤ai≤1041\le a_i\le 10^4 (1≤i≤N1\le i\le N); 1≤bi≤1041\le b_i\le 10^4 (1≤i≤N1\le i\le N); 1≤ci≤1041\le c_i\le 10^4 (1≤i≤N1\le i\le N).
  • Subtask 2 (30 points): 1≤N≤5001\le N\le 500; 1≤ai≤1041\le a_i\le 10^4 (1≤i≤N1\le i\le N); 1≤bi≤1041\le b_i\le 10^4 (1≤i≤N1\le i\le N); 1≤ci≤1041\le c_i\le 10^4 (1≤i≤N1\le i\le N).
  • Subtask 3 (50 points): 1≤N≤1051\le N\le 10^5; 1≤ai≤1041\le a_i\le 10^4 (1≤i≤N1\le i\le N); 1≤bi≤1041\le b_i\le 10^4 (1≤i≤N1\le i\le N); 1≤ci≤1041\le c_i\le 10^4 (1≤i≤N1\le i\le N).

Examples

Input

3
10 40 70
20 50 80
30 60 90

Output

210

Explanation

An optimal choice is C on day 1 (7070), B on day 2 (5050), and C on day 3 (9090). Consecutive activities differ and the total is 70+50+90=21070+50+90=210.