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
The first line contains single integer $ n $ ( $ 1
Output Format
Print single integer — the length of the longest subsequence of Vladik's sequence that satisfies both conditions.
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.