Problem9098--CCC '23 J4/S1 - Trianglane

9098: CCC '23 J4/S1 - Trianglane

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 512 MiB

Description

Canadian Computing Competition: 2023 Stage 1, Junior #4, Senior #1

Bocchi the Builder has just finished constructing her latest project: a pathway consisting of two rows of white equilateral triangular tiles. However, at the last moment, disaster struck, and she accidentally spilled black paint on some of the tiles! Now, she must purchase warning tape to block off the wet areas. Can you help her determine how many meters of tape she needs?

The first triangle will always point upwards, and any pair of adjacent tiles (that is, tiles that share a common side) will point in opposite directions. Every triangle has a side length of 1 meter.

Input

The first line will consist of one integer, $C$, representing the number of columns.

The next two lines will each consist of $C$ integers separated by spaces. Each integer represents the colour of a tile in the room, with 1 indicating that the tile is black and 0 indicating that the tile is white.

The following table shows how the available 15 marks are distributed:

Marks Awarded Bounds on $C$ Additional Constraints
3 marks 1≤C≤2000 Black tiles will never be adjacent and the second row is fully white.
3 marks 1≤C≤2000 The second row is fully white.
5 marks 1≤C≤2000 None
4 marks 1≤C≤200000 None

Output

Output a single integer representing the length of the tape Bocchi must purchase in meters.

Sample 1 Input

5
1 0 1 0 1
0 0 0 0 0

Sample 1 Output

9

The tiles are painted as follows, with the warning tape highlighted in yellow.

Sample 2 Input

7
0 0 1 1 0 0 0
0 0 1 0 1 0 0

Sample 2 Output

8

The tiles are painted as follows, with the warning tape highlighted in yellow.

HINT

相同题目:CCC23 S1

Source/Category