#include #include #include using namespace std; int main() { // Get input int N; scanf("%d\n", &N); std::vector< int > values (N); std::vector< char > suits (N); scanf("%c%d", &suits[0], &values[0]); for(int i = 1; i < N; i++) { scanf(" %c%d", &suits[i], &values[i]); } // Go over all valid suit permutations int best_lis = 0; vector< char > suit_order {'E', 'R', 'S', 'W', 'C'}; do { // Translate the hand to integers with the same relative order vector< int > hand (N); for (int i=0; i hand[j] && lis_aux[i] < lis_aux[j] + 1) lis_aux[i] = lis_aux[j] + 1; } int lis = *max_element(lis_aux, lis_aux + N); // Take the best LIS over all suit orders best_lis = max(best_lis, lis); } while (next_permutation(suit_order.begin(), suit_order.end() - 1)); // All cards not in the LIS should be moved printf("%d\n", N - best_lis); return 0; }