CF743E Vladik and cards
Description
Vladik was bored on his way home and decided to play the following game. He took $ n $ cards and put them in a row in front of himself. Every card has a positive integer number not exceeding $ 8 $ written on it. He decided to find the longest subsequence of cards which satisfies the following conditions:
- the number of occurrences of each number from $ 1 $ to $ 8 $ in the subsequence doesn't differ by more then $ 1 $ from the number of occurrences of any other number. Formally, if there are $ c_{k} $ cards with number $ k $ on them in the subsequence, than for all pairs of integers  the condition $ |c_{i}-c_{j}|
Input Format
N/A
Output Format
N/A
Explanation/Hint
In the first sample all the numbers written on the cards are equal, so you can't take more than one card, otherwise you'll violate the first condition.