Trianglane


Submit solution

Points: 1
Time limit: 1.0s
Memory limit: 256M

Problem type
Allowed languages
Python

Problem Description

The builder Boqi just completed her latest work: an exquisite alleyway.

This alleyway consists of two rows of tiles, each containing exactly C white equilateral triangular tiles with a side length of 1.

Among them, the first tile in the top row (counting from the left) points upward, and each pair of adjacent triangular tiles (i.e., tiles that share a common edge) point in opposite directions (refer to the illustration for details).

Unfortunately, she accidentally knocked over a bucket of black paint, causing some of the triangular tiles to be stained black.

Since the paint on the stained tiles is still wet, she plans to use tape to enclose the edges of all the stained areas to prevent anyone from accidentally stepping on them.

Please calculate how many meters of tape she needs to use.

Input Format

  • The first line contains the integer C.
  • The second line contains C integers, either 0 or 1, representing the colors of the tiles in the first row. If the i-th integer is 1, it means the i-th tile (from the left) is black; if it is 0, it means the i-th tile is white.
  • The third line contains C integers, either 0 or 1, representing the colors of the tiles in the second row. If the i-th integer is 1, it means the i-th tile (from the left) is black; if it is 0, it means the i-th tile is white.

Output Format

An integer representing the required length of tape in meters.

Data Range

1 ≤ C ≤ 2 × 10^5

Examples

Sample Input 1
5
1 0 1 0 1
0 0 0 0 0
Sample Output 1
9

Explanation: The distribution of tile colors and the tape placement are shown in the figure below. A total of 9 meters of tape is required.

Sample 1

Sample Input 2
7
0 0 1 1 0 1 0
0 0 1 0 1 0 0
Sample Output 2
11

Explanation: The distribution of tile colors and the tape placement are shown in the figure below. A total of 11 meters of tape is required.

Sample 2 ```


Comments

There are no comments at the moment.