Problems
Solitaire (small limits)
Solitaire (small limits)
\includegraphics{https://static.e-olymp.com/content/05/05a59779996b63c439954988fc1337c93cd4dbbd.jpg}
\includegraphics{https://static.e-olymp.com/content/56/56d51528350efc7833e9e9a9facf2e2e28d40e1a.jpg}
\includegraphics{https://static.e-olymp.com/content/28/283fb2df106142ed023b860c0faf64537977a348.jpg}
\includegraphics{https://static.e-olymp.com/content/3c/3cfba9ca77263cdb04bd327371fc5923b856015f.jpg}
"N-T solitaire" - is a card game for one player. There are \textbf{4N} (\textbf{3} ≤ \textbf{N} ≤ \textbf{15}) cards in the game and each card corresponds to a unique pair of it's value (an integer in the range \textbf{1}\textit{\textbf{..}}\textbf{N}) and suit (, , or ). In the initial position all cards are laid out in \textbf{T} (\textbf{4} ≤ \textbf{T} ≤ \textbf{8}) piles; moreover, each of \textbf{(4N)\%T} first piles has \textbf{(4N/T)+1} cards, others have \textbf{4N/T} cards each (here "\textbf{/}" and "\textbf{\%}" - integer division and remainder of division, respectively). If the sum of the values of upper cards of two piles is \textbf{N+1}, then these two cards can be moved to discard pile (irrespective of their suits). This is the only way to move the cards.
Write a program that will determine the maximum number of cards that one can move to the discard pile.
\InputFile
\includegraphics{https://static.e-olymp.com/content/28/283fb2df106142ed023b860c0faf64537977a348.jpg}
\includegraphics{https://static.e-olymp.com/content/3c/3cfba9ca77263cdb04bd327371fc5923b856015f.jpg}
\includegraphics{https://static.e-olymp.com/content/05/05a59779996b63c439954988fc1337c93cd4dbbd.jpg}
\includegraphics{https://static.e-olymp.com/content/56/56d51528350efc7833e9e9a9facf2e2e28d40e1a.jpg}
The firs line contains two integers \textbf{N} and \textbf{T}, then there are \textbf{T} lines with descriptions of the corresponding piles. Each card is described as its value (an integer) and a suit (the char with ASCII-code \textbf{03}(), \textbf{04}(), \textbf{05}() or \textbf{06}()) without space between. Descriptions of the cards inside the same pile are single-space separated. Description's direction from left to right corresponds to the order of cards from bottom to up.
\textbf{Sample Input}
\includegraphics{https://static.e-olymp.com/content/0a/0a02930e6fb07541b2168c4f7faebe88381ca2c3.jpg}
\OutputFile
Your program should print a single integer - the maximum number of cards that can be moved to the discard pile.
Input example #1
3 5 2 2 2 2 3 1 3 1 1 3 1 3
Output example #1
10