implementation

collections.defaultdictは便利。

#!/usr/bin/env python3
import collections
n = int(input())
shoes = collections.defaultdict(lambda: { 'L': 0, 'R': 0 })
for _ in range(n):
    a, b = input().split()
    shoes[a][b] += 1
result = 0
for cnt in shoes.values():
    result += min(cnt['L'], cnt['R'])
print(result)