P27178 [AtCoder] The Tourist Problem
省选
题目描述

Problem Description

Tourist has two lists.

Both lists have a length of $ N $, and the $ j $th element of the $ i $th list is $ A_{i,j} $. $ A_{i,j} $ is a positive or negative integer, but not zero.

Tourist wants to perform the following operations on these lists:

  • First, replace all negative integers in the two lists with positive integers. The same numbers must be replaced with the same numbers, and different numbers must be replaced with different numbers.
  • Next, prepare a piece of paper with a grid of $ 2 $ rows and $ N $ columns, and write the $ j $th number of the $ i $th list in the $ i $th row and $ j $th column.
  • Finally, cut the paper with scissors along the edges where adjacent cells have different numbers and the outer frame. The paper will then be divided into several pieces, and you need to count the number of these pieces.

Tourist wants to minimize the number of pieces the paper is divided into by cleverly replacing the negative integers. How many pieces will the paper be divided into?

Input Format

The input is given from the standard input in the following format:

$ N $ $ A_{1,1} $ $ A_{1,2} $ $ ... $ $ A_{1,N} $ $ A_{2,1} $ $ A_{2,2} $ $ ... $ $ A_{2,N} $

Output Format

Output the number of pieces the paper is divided into.

Sample Input and Output

Sample Input #1

5
1 2 1 2 1
-1 -2 -3 -3 -3

Sample Output #1

5

Sample Input #2

15
1 -1 1 -1 -1 -2 2 -1 3 3 3 -3 -2 -2 1
2 -1 1 1 -1 -2 -1 2 -2 3 3 -2 -2 -2 3

Sample Output #2

9

Notes/Hints

Constraints

  • $ 1≦N≦10^5 $
  • $ 1≦|A_{i,j}|≦300 $

Sample Explanation 1

For example, if you replace $ -1 $ with $ 999 $, $ -2 $ with $ 2 $, and $ -3 $ with $ 1 $, the result will be as shown in the figure below, and the number of pieces will be the minimum of $ 5 $. 92e7ebbff942cc1af02ea1a3e5aa7a75.png

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
5 1 2 1 2 1 -1 -2 -3 -3 -3
样例输出
5