### 2015 Canadian Computing Competition, Stage 1

## Problem S2: Jerseys

A school team is trying to assign jerseys numbered 1, 2, 3, …, `J` to student athletes. The size of each jersey is either small (S), medium (M) or large (L).

Each athlete has requested a specific jersey number and a preferred size. The athletes will not be satisfied with a jersey that is the wrong number or that is smaller than their preferred size. They will be satisfied with a jersey that is their preferred size or larger as long as it is the right number. Two students cannot be given the same jersey.

Your task is to determine the maximum number of requests that can be satisfied.

### Input

The first line of input is the integer `J` which is the number of jerseys.

The second line of input is the integer `A` which is the number of athletes.

The next `J` lines are each the characters S, M or L. Line `j` gives the size of jersey `j` (1 ≤ `j` ≤ `J`).

The last `A` lines are each the character S, M or L followed by a space followed by an integer. Line `a` (1 ≤ `a` ≤ `A`) gives the requested size and jersey number for athlete `a` where the athletes are numbered 1, 2, 3, …, `A`.

For 50% of the test cases, 1 ≤ `J` ≤ 10^{3} and 1 ≤ `A` ≤ 10^{3}.

For the remaining 50% of the test cases, 1 ≤ `J` ≤ 10^{6} and 1 ≤ `A` ≤ 10^{6}.

### Output

The output will consist of a single integer which is the maximum number of requests that can be satisfied.

### Sample Input

4 3 M S S L L 3 S 3 L 1

### Sample Output

1

### Explanation

Jersey 1 cannot be assigned because it is medium and athlete 3 requested large. No athlete requested jersey 2 or 4. Jersey 3 (small) can be assigned to athlete 2 (small), but not athlete 1 (large).

All Submissions

Best Solutions

**Point Value:** 5 (partial)

**Time Limit:** 2.00s

**Memory Limit:** 256M

**Added:** Feb 21, 2015

**Languages Allowed:**

C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

## Comments (Search)

gpfaulton Feb 19, 2017 - 6:07:18 pm UTC [user] hardcodingjargonon Feb 19, 2017 - 8:55:32 pm UTC Re: [user] hardcodinggpfaulton Jan 25, 2017 - 1:50:57 am UTC "Two students cannot be given the same jersey."magmascorpion919on Jan 30, 2017 - 10:19:57 pm UTC Re: "Two students cannot be given the same jersey."P234reron Nov 08, 2016 - 3:30:37 pm UTC ErrorI could have sworn my code worked before for this question

jargonon Nov 14, 2016 - 1:10:53 am UTC Re: Error