UTS Open '18 P2 - ABCs

View as PDF

Submit solution

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

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

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 Format

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 Format

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


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.


There are no comments at the moment.