## COCI '14 Contest 7 #3 ACM

View as PDF

Points: 12 (partial)
Time limit: 0.6s
Memory limit: 64M

Problem types

The team of the University of Zagreb - Stjepan, Ivan and Gustav — are taking part in the World Finals of the ACM International Collegiate Programming Contest in Morocco. Their technical guide Goran has come up with an invincible strategy to use for solving tasks in the finals.

In the very beginning, each team member quickly estimates the difficulty of each of the tasks. The difficulties are described by numbers from to , and their meaning is the following:

• - hehehe
• - bring it on!
• - well OK.
• - hmmmm…
• - are you insane?

After this, they will distribute the tasks between them. For simplicity's sake, this array of tasks will be split into three parts so that each team member gets a nonempty array of consecutive tasks to contemplate about. The distribution is made so that the sum of estimated difficulties is minimal, whereas only the estimates of the team members whom that task is assigned to is calculated. Your task is to calculate that minimal possible sum.

#### Input

The first line of input contains the integer , the number of tasks.

Each of the following three lines contains integers (from to ): the estimated task difficulties, give respectively. First of those lines corresponds to Stjepan's estimates, the second to Ivan's and the third to Gustav's.

#### Output

The first and only line of output must contain the minimum sum of difficulties.

#### Sample Input 1

3
1 3 3
1 1 1
1 2 3

#### Sample Output 1

4

#### Explanation for Sample Output 1

Stjepan gets the first, Gustav the second and Ivan the third task.

#### Sample Input 2

7
3 3 4 1 3 4 4
4 2 5 1 5 5 4
5 5 1 3 4 4 4

#### Sample Output 2

19