PivotOJ

Double Deck

시간 제한: 2000ms메모리 제한: 1024MB출처: NCPC 2024BOJ 32552

문제

You are playing a new card game. In the game you have two decks of cards each consisting of NKN \cdot K cards labeled with an integer from 11 to NN, inclusive. Also, each type of card appears precisely KK times in each deck.

The rules of the game are simple. You shuffle both decks and place them face up in front of you, so at each point in time you see the top card in each deck. If the top cards are the same you can take them both and get one point. Otherwise you must discard either card. Your goal is to get as many points as possible.

You have just finished playing a round of this game and you want to know what the maximum score was, knowing the layout of both decks.

입력

The first line of the input contains two integers NN and KK (1N104,1K151 \leq N \leq 10^4, 1 \leq K \leq 15). The second and third line of the input each contain NKN \cdot K integers xix_i (1xiN1 \leq x_i \leq N), describing the layout of the decks. The first number x1x_1 is the topmost card in the deck, x2x_2 is the second, and so on.

No integer in the second line and third line is repeated more than KK times per line.

출력

Print a single integer, the maximum possible score.

예제

예제 1

입력
3 2
3 1 2 3 1 2
2 1 3 1 3 2
출력
4

예제 2

입력
5 3
2 3 4 5 3 5 2 2 4 3 5 1 1 1 4
5 2 3 2 3 1 4 5 1 4 5 1 4 3 2
출력
8
코드를 제출하려면 로그인하세요.