UTS Open '18 P2 - ABCs

View as PDF

Submit solution


Points: 3 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

You have 3 sequences A, B, and C, each containing 3 integers. A subsequence of C is valid if for each C_i in the subsequence, B_i = A_{i-1} (indices are taken mod 3, so A_0 = A_3).

What is the maximum sum of a valid subsequence of C?

Input Specification

The first row contains A_1, A_2, A_3, the second row contains B_1, B_2, B_3, and the third row contains C_1, C_2, C_3.

-10^5 \le A_i,B_i,C_i \le 10^5 for all i.

Output Specification

Output the maximum sum of a valid subsequence of C (The subsequence can be empty, in which case the sum would be 0).

Sample Input

5 6 5
6 5 6
6 1 4

Sample Output

5

Explanation for Sample Output

Since B_2 = A_1 and B_3 = A_2, C_2 and C_3 are valid and can be included in the subsequence. However, B_1 \ne A_0, so C_1 cannot be included in the subsequence. This subsequence has sum 5.


Comments

There are no comments at the moment.