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 Ci in the subsequence, Bi=Ai1 (indices are taken mod 3, so A0=A3).

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

Input Specification

The first row contains A1,A2,A3, the second row contains B1,B2,B3, and the third row contains C1,C2,C3.

105Ai,Bi,Ci105 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

Copy
5 6 5
6 5 6
6 1 4

Sample Output

Copy
5

Explanation for Sample Output

Since B2=A1 and B3=A2, C2 and C3 are valid and can be included in the subsequence. However, B1A0, so C1 cannot be included in the subsequence. This subsequence has sum 5.


Comments

There are no comments at the moment.