Problem:


Score : 200 points

Problem Statement

Takahashi has N blue cards and M red cards.
A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i.

Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen.

Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces atcoder, he will not earn money even if there are blue cards with atcoderr, atcode, btcoder, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.)

At most how much can he earn on balance?

Note that the same string may be written on multiple cards.

Constraints

N and M are integers.

1 \leq N, M \leq 100

s_1, s_2, ..., s_N, t_1, t_2, ..., t_M are all strings of lengths between 1 and 10 (inclusive) consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
s_1
s_2
:
s_N
M
t_1
t_2
:
t_M

Output

If Takahashi can earn at most X yen on balance, print X.

Sample Input 1

3
apple
orange
apple
1
grape

Sample Output 1

2

He can earn 2 yen by announcing apple.

Sample Input 2

3
apple
orange
apple
5
apple
apple
apple
apple
apple

Sample Output 2

1

If he announces apple, he will lose 3 yen. If he announces orange, he can earn 1 yen.

Sample Input 3

1
voldemort
10
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort

Sample Output 3

0

If he announces voldemort, he will lose 9 yen. If he announces orange, for example, he can avoid losing a yen.

Sample Input 4

6
red
red
blue
yellow
yellow
red
5
red
red
yellow
green
blue

Sample Output 4

1



Sample input:
3
apple
orange
apple
1
grape


Sample output:
2

Submission status: Accepted

Solution code:
N = int(input())
s = ["" for _ in range(N)]
for i in range(N):
    s[i] = input()
M = int(input())
t = ["" for _ in range(M)]
for i in range(M):
    t[i] = input()

s_set = list(set(s))
t_set = list(set(t))

ans = ""
INF = -float("inf")

for i in s_set:
    score = s.count(i) - t.count(i)
    if INF < score:
        INF = score
        ans = i
for i in t_set:
    score = s.count(i) - t.count(i)
    if INF < score:
        INF = score
        ans = i

if INF < 0:
    print(0)
else:
    print(INF)

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
s = defaultdict(int)
t = defaultdict(int)

for i in range(n):
    x = input()
    s[x] += 1

m = int(input())
for i in range(m):
    x = input()
    t[x] += 1

ans = 0
for x, v in s.items():
    now = v - t[x]
    ans = max(ans, now)

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
ans=0
count=0
s={}
t={}
for i in range(n):
  a=input()
  if a not in s:
    s[a]=1
  else:
    s[a]+=1
m=int(input())
for i in range(m):
  a=input()
  if a not in t:
    t[a]=1
  else:
    t[a]+=1
    
S=list(s.keys())
T=list(t.keys())
for i in range(len(S)):
  if S[i] in T:
    count=s[S[i]]-t[S[i]]
  else: count=s[S[i]]
  ans=max(ans,count)
  
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
s = [None] * n
for i in range(n):
    s[i] = input().rstrip()

m = int(input())
t = [None] * m
for i in range(m):
    t[i] = input().rstrip()

ctr = Counter(s) - Counter(t)
if ctr:
    print(ctr.most_common(1)[0][1])
else:
    print(0)

Submission status: Accepted

Solution code:
N = int(input())
n_list = []
for i in range(N):
  n_list.append(input())
M = int(input())
m_list = []
for i in range(M):
  m_list.append(input())
add_dic = {}
for n in n_list:
  add = add_dic.get(n, 0)
  add_dic[n] = add + 1
diff_dic = {}
for m in m_list:
  diff = diff_dic.get(m, 0)
  diff_dic[m] = diff + 1

max_ = 0
for key, add in add_dic.items():
  total = add - diff_dic.get(key, 0)
  if total > max_:
    max_ = total

print(max_)

Submission status: Accepted

Solution code:
n = int(input())
s = []
for _ in range(n):
    s.append(str(input()))
m = int(input())
t = []
for _ in range(m):
    t.append(str(input()))
a = []
for i in s:
    if i not in a:
        a.append(i)
for i in t:
    if i not in a:
        a.append(i)
b = []
for i in a:
    x = s.count(i)
    y = t.count(i)
    b.append(x - y)
print(max(0, max(b)))

Submission status: Accepted

Solution code:
n = int(input())
str_dict = dict()
for i in range(n):
    s = input()
    if s not in str_dict:
        str_dict[s] = 1
    else:
        str_dict[s] += 1

m = int(input())
for i in range(m):
    t = input()
    if t not in str_dict:
        str_dict[t] = -1
    else:
        str_dict[t] -= 1

res = max(0, sorted(list(str_dict.values()))[-1])
print(res)

Submission status: Accepted

Solution code:
n = int(input())
a = [input() for i in range(n)]
m = int(input())
b = [input() for i in range(m)]
s = a + b
t = []
for i in s:
  t.append(a.count(i) - b.count(i))
  
print(0 if max(t) <= 0 else max(t))

Submission status: Accepted

Solution code:
import collections

N = int(input())
nlist = []
for i in range(N):
    nlist.append(input())

M = int(input())
mlist = []
for i in range(M):
    mlist.append(input())

for i in mlist:
    if i in nlist:
        nlist.remove(i)

nlist = collections.Counter(nlist).most_common()

if nlist==[]:
    print(0)
    exit()

print(nlist[0][1])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3


def main():
    N = int(input())
    s = [input() for _ in range(N)]
    M = int(input())
    t = [input() for _ in range(M)]
    y = 0
    for ss in set(s):
        yy = s.count(ss) - t.count(ss)
        if y < yy:
            y = yy
    print(y)


main()

Submission status: Accepted

Solution code:
N = int(input())
S = []
for i in range(N):
    s = input()
    S.append(s)

M = int(input())
T = []
for i in range(M):
    t = input()
    T.append(t)

ans = -1
x = 0
for i in S:
    x = S.count(i) - T.count(i)
    ans = max(ans, x)

if ans < 0:
    ans = 0

print(ans)

Submission status: Accepted

Solution code:
blue = []
red = []
ans = 0
n = int(input())
for i in range(n):
  blue.append(input())
m = int(input())
for j in range(m):
  red.append(input())
word = set(blue)
for k in word:
  c = blue.count(k) - red.count(k)
  ans = max(ans,c)
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

N=int(input())
pts = dict()
for _ in range(N):
    s = input().strip()
    if not pts.get(s):
        pts[s] = 0
    pts[s] += 1

M=int(input())
for _ in range(M):
    t = input().strip()
    if not pts.get(t):
        pts[t] = 0
    pts[t] -= 1

print(max(0, max(pts.values())))

Submission status: Accepted

Solution code:
N = int(input())
L = list(input() for i in range(N))
M = int(input())
T = list(input() for i in range(M))

Li = []
for i in set(L):
    if i not in T:
        K = 0
    else:
        K = T.count(i)
    Li.append(L.count(i) - K)

print(max(Li) if max(Li)>0 else 0)

Submission status: Accepted

Solution code:
N = int(input())
Ns = []
for i in range(N):
  Ns.append(input())
  
M = int(input())
Ms = []
for i in range(M):
  Ms.append(input())
  
Ws = list(set(Ns + Ms))

As = []
for i in Ws:
  ans = 0
  for j in Ns:
    if i == j:
      ans += 1
  for j in Ms:
    if i == j:
      ans -= 1
  As.append(ans)
  
print(max(max(As), 0))

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]

c = Counter(s).most_common()
d = Counter(t)

p = -1000

for k, v in c:
    p = max(p, v - d[k])

print(max(p, 0))

Submission status: Accepted

Solution code:
def resolve():
    n = int(input())
    blue_cards = list()
    for i in range(n):
        card = input()
        blue_cards.append(card)
    blue_cards = sorted(blue_cards)
    m = int(input())
    red_cards = list()
    for i in range(m):
        card = input()
        red_cards.append(card)
    red_cards = sorted(red_cards)
    former = ""
    cards_points = []
    for card in blue_cards:
        point = 0
        if former == card:
            continue
        else:
            p = blue_cards.count(card)
            m = red_cards.count(card)
            point = p - m
            cards_points.append(point)
            former = card
    cards_points = sorted(cards_points)
    if cards_points[-1] < 0:
        print(0)
    else:
        print(cards_points[-1])
resolve()

Submission status: Accepted

Solution code:
from collections import defaultdict


n=int(input())
s=[input() for i in range(n)]
m=int(input())
t=[input() for i in range(m)]


dic=defaultdict(int)
for i in range(n):
    dic[s[i]]+=1

for i in range(m):
    dic[t[i]]-=1

ans=0
for i in dic.values():
    ans=max(ans,i)
print(ans)

Submission status: Accepted

Solution code:
s_dict = dict()
n = int(input())
for _ in range(n):
    s = input()
    if not s in s_dict:
        s_dict[s] = 1
    else:
        s_dict[s] += 1
n = int(input())
for _ in range(n):
    s = input()
    if s in s_dict:
        s_dict[s] -= 1
print(max(max(s_dict.values()), 0))

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]
li = []
for i in range(n):
    li += [s.count(s[i])-t.count(s[i])]
print(max(max(li),0))

Submission status: Accepted

Solution code:
n=int(input())
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########

d=defaultdict(int)
for i in range(n):
    d[input()]+=1
m=int(input())
for i in range(m):
    d[input()]-=1
print(max(0, max(d.values())))

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    s = [SS() for _ in range(N)]
    M = I()
    t = [SS() for _ in range(M)]

    cnt_s = collections.Counter(s)
    cnt_t = collections.Counter(t)
    ans = max([max(cnt_s[i] - cnt_t[i], 0) for i in (cnt_s.keys() | cnt_t.keys())])
    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]

s_l = list(set(s))
cnt = []

for i in s_l:
    cnt.append(s.count(i)-t.count(i))
    
if max(cnt) <= 0:
    print(0)
else:
    print(max(cnt))

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]

ans = 0
for i in s:
    ans = max(ans,s.count(i)-t.count(i))

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = {}
for i in range(n):
    s = str(input())
    if s in a.keys():
        a[s] = a[s] + 1
    else:
        a[s] = 1
        
m = int(input())
for i in range(m):
    t = str(input())
    if t in a.keys():
        a[t] = a[t] - 1
    else:
        a[t] = -1
if max(a.values()) >= 0:
    print(max(a.values()))
elif max(a.values()) < 0:
    print(0)

Submission status: Accepted

Solution code:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353


N = int(input())
s = defaultdict(int)

for i in range(N):
    s[input()] += 1

M = int(input())
t = defaultdict(int)
for i in range(M):
    t[input()] += 1

m = 0
for p in list(s.keys()):
    m = max(m, s[p] - t[p])
print(m)

Submission status: Accepted

Solution code:
n = [input() for _ in range(int(input()))]
m = [input() for _ in range(int(input()))]

l = list(set(n))

print(max(0,max(n.count(l[i]) - m.count(l[i]) for i in range(len(l)))))

Submission status: Accepted

Solution code:
Blue=[]
Red=[]

n=int(input())
for i in range(n):
    s=input()
    Blue.append(s)
    
m=int(input())
for i in range(m):
    t=input()
    Red.append(t)

ans=0
for a in Blue:
    plus = Blue.count(a)
    minus = Red.count(a)
    point = plus - minus
    ans = max(ans, point)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
d={}
for i in range(n):
    x=input()
    if(x not in d):
        d[x]=1
    else:
        d[x]+=1
m=int(input())
for i in range(m):
    x=input()
    if(x not in d):
        d[x]=-1
    else:
        d[x]-=1
l=list(d.values())
print(max(max(l),0))

Submission status: Accepted

Solution code:
#B - Two Colors Card Game
N = int(input())
s = [input() for _ in range(N)]
M = int(input())
t = [input() for _ in range(M)]
s_set = list(set(s))

maxim = 0
for i in s_set:
    count = 0
    for j in s:
        if i == j:
            count += 1
    for k in t:
        if i == k:
            count -= 1
    if maxim<count:
        maxim = count
print(maxim)

Submission status: Accepted

Solution code:
#値を入力
n = int(input())
s = []
for i in range(n):
  s.append(input())

m = int(input())
t = []
for i in range(m):
  t.append(input())

#sに含まれる文字列個数を辞書にカウント
dic = {}

for i in range(n):
  if s[i] not in dic:
    dic[s[i]] = 0
  dic[s[i]] += 1

#tの文字列の中で、sにも含まれている文字列の引き算だけ行う
for i in range(m):
  if t[i] in dic:
    dic[t[i]] -= 1

#辞書の最大値あるいは0のうち大きい方が答え
max_dic = max(max(dic.values()), 0)

print(max_dic)

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for i in range(n)]
m = int(input())
t = [input() for i in range(m)]
l = []
ans = -1000
for i in range(n):
    if s[i] not in l:
        l.append(s[i])
        pnt = s.count(s[i]) - t.count(s[i])
        ans = max(ans, pnt)
if ans < 0:
    print(0)
else:
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for i in range(n)]
m = int(input())
t = [input() for i in range(m)]

maxCount = 0
for i in s:
    if s.count(i) - t.count(i) > maxCount:
        maxCount = s.count(i) - t.count(i)
print(maxCount)

Submission status: Accepted

Solution code:
x = int(input())
a = [input() for i in range(x)]
y = int(input())
b = [input() for h in range(y)]

count_max = 0
for j in a:
  if (a.count(j) - b.count(j)) > count_max:
    count_max = a.count(j) - b.count(j)
print(count_max)

Submission status: Accepted

Solution code:
x = int(input())
a = [input() for _ in range(x)]
y = int(input())
b = [input() for _ in range(y)]

count_max = 0
for j in a:
  if (a.count(j) - b.count(j)) > count_max:
    count_max = a.count(j) - b.count(j)
print(count_max)

Submission status: Accepted

Solution code:
N = int(input())
s = {}
for i in range(N):
    str = input()
    if str in s:
        s[str]+=1
    else:
        s[str] = 1
M = int(input())
for j in range(M):
    str = input()
    if str in s:
        s[str]-= 1
    else:
        s[str] = -1
if max(s.values()) < 0:
    print(0)
else:
    print(max(s.values()))

Submission status: Accepted

Solution code:
N=int(input())
s=[]
for i in range(N):
    s.append(input())
M=int(input())
t=[]
for i in range(M):
    t.append(input())
wordlist=list(set(s))+list(set(t))
wordcount=[]
for i in range(len(wordlist)):
    wordcount.append(s.count(wordlist[i])-t.count(wordlist[i]))
if max(wordcount)>=1:
    print(max(wordcount))
else:
    print(0)

Submission status: Accepted

Solution code:
from collections import Counter as C

n = int(input())
blue = C([input() for _ in range(n)])
m = int(input())
red = C([input() for _ in range(m)])

points = dict(blue)
for rk, rv in red.items():
    points[rk] = points.get(rk, 0) - rv
else:
    print(max(0, max(points.values())))

Submission status: Accepted

Solution code:
import collections

n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]

s_counter = collections.Counter(s)
t_counter = collections.Counter(t)
t_keys = list(t_counter.keys())
ans = []

for key in s_counter.keys():
    if key in t_keys:
        ans.append(int(s_counter[key]) - int(t_counter[key]))
    else:
        ans.append(s_counter[key])
max_ans = max(ans)
if max_ans < 0:
    print(0)
else:
    print(max_ans)

Submission status: Accepted

Solution code:
N = int(input())
s = [(input()) for _ in range(N)] + ['0']
M = int(input())
t = [(input()) for _ in range(M)]
s.sort(reverse=True)
sc = 0
ans = 0
for i in range(N) :
    sc += 1
    if s[i] == s[i+1] :
        continue
    tc = t.count(s[i])
    ans = max(ans,sc-tc)
    sc = 0

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
blue = [input() for _ in range(n)]

m = int(input())
red = [input() for _ in range(m)]

price_max = 0
for a in blue:
    if (blue.count(a) - red.count(a)) > price_max:
        price_max = blue.count(a) - red.count(a)
print(price_max)

Submission status: Accepted

Solution code:
N = int(input())
s = []
for i in range(N):
    s.append(input())

M = int(input())
t = []
for i in range(M):
    t.append(input())

s_set = list(set(s))
t_set = list(set(t))

ans = 0
for i in range(len(s_set)):
    y = 0
    for j in range(N):
        if s_set[i] == s[j]:
            y += 1
    for k in range(M):
        if s_set[i] == t[k]:
            y -= 1
    if y > ans:
      ans = y

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
s_list = [input() for _ in range(N)]
M = int(input())
t_list = [input() for _ in range(M)]

rev_list = []
for i in range(len(s_list)):
    a = s_list.count(s_list[i])
    b = t_list.count(s_list[i])
    if a >= b:
        ans_num = a-b
    else:
        ans_num = 0
    rev_list.append(ans_num)
    
print(max(rev_list))

Submission status: Accepted

Solution code:
from collections import Counter

blue_cards = [input() for _ in range(int(input()))]
red_cards = Counter([input() for _ in range(int(input()))])

sources = set(blue_cards)
blue_cards = Counter(blue_cards)

result = 0
for x in sources:
  tmp = blue_cards[x]
  
  if x in red_cards:
    tmp -= red_cards[x]
  
  result = max(result, tmp)
  
print(result)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
S = [input() for _ in range(n)]
m = int(input())
T = [input() for _ in range(m)]

cnt_S = Counter(S)
cnt_T = Counter(T)
values, counts = zip(*cnt_S.most_common())

ans = 0
for i in range(len(values)):
    ans = max(ans, counts[i] - cnt_T[values[i]])
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for _ in range(N)]
M = int(input())
T = [input() for _ in range(M)]

ans = 0
P = set(S)
for i in P:
    ans = max(ans,S.count(i)-T.count(i))

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

S = defaultdict(int)
T = defaultdict(int)

for _ in range(int(input())):
    S[input()] += 1

for _ in range(int(input())):
    T[input()] += 1

print(max(0, max([S[k] - T[k] for k, v in S.items()])))

Submission status: Accepted

Solution code:
import collections
n = int(input())
s = [input() for _ in range(n)]
# s.append('')
m = int(input())
t = [input() for _ in range(m)]
# t.append('')
sc = collections.Counter(s)
tc = collections.Counter(t)
# print(sc, tc)
ans = 0
for string, times in sc.items():
    if string in tc.keys():
        ans = max(ans, times - tc[string])
    else:
        ans = max(ans, times)
        
        
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
s=[]
for i in range(N):
    s.append(str(input()))
M=int(input())
t=[]
for j in range(M):
    t.append(str(input()))

ans=0
for i in range(N):
    x=s.count(s[i])
    y=t.count(s[i])
    if ans<x-y:
        ans=x-y
print(ans)

Submission status: Accepted

Solution code:
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') 
inf = float('inf') ;mod = 10**9+7 
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
blue = []
red = []
for i in range(n):
    s = input()
    blue.append(s)
m = int(input())
for i in range(m):
    t = input()
    red.append(t)
for i in range(n):
    c = blue[i]
    chk = blue.count(c) - red.count(c)
    if chk > ans:
        ans = chk
print(ans)

Submission status: Accepted

Solution code:
N = int(input()) 
S = [input() for _ in range(N)]
new_S = set(S)
M = int(input()) 
T = [input() for _ in range(M)]
use = 0
for i in new_S:
    use1 = S.count(i) - T.count(i) 
    use = max(use,use1)

print(use)

Submission status: Accepted

Solution code:

import collections

N=input()

N=int(N)

aaa=[]

for i in range(N):
    a1=input()
    aaa.append(a1)


M=input()

M=int(M)


bbb=[]

for i in range(M):
    a1=input()
    bbb.append(a1)
    
#print(aaa)

#print(bbb)


c = collections.Counter(aaa)

d = collections.Counter(bbb)

#print(c)

#print(d)

#print(c-d)

dic2 = sorted((c-d).items(), key=lambda x:x[1], reverse=True)


#print(len(dic2))

if len(dic2)==0:
    print(0)
else:
    print(dic2[0][1])

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for _ in range(N)]
M = int(input())
T = [input() for _ in range(M)]

ans = 0
for s in S:
  ans = max(ans, S.count(s)-T.count(s))

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for _ in range(N)]
M = int(input())
T = [input() for _ in range(M)]

ans = 0

for s in S:
    point_S = S.count(s)
    point_T = T.count(s)
    ans = max(ans, point_S - point_T)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]

print(max(0, *[s.count(sn) - t.count(sn) for sn in set(s)]))

Submission status: Accepted

Solution code:
import collections
n=int(input())
s = [input() for _ in range(n)]
m=int(input())
m = [input() for _ in range(m)]
dd = collections.defaultdict(int)
for i in s:
    dd[i]+=1
for i in m:
    dd[i]-=1
print(max(0,max(dd.values())))

Submission status: Accepted

Solution code:
n = int(input())
s = [list(input()) for i in range(n)]
m = int(input())
t = [list(input()) for i in range(m)]

ans = 0
for i in s:
  ans = max(s.count(i) - t.count(i), ans)
  
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
s = [input() for i in range(N)]
M = int(input())
t = [input() for i in range(M)]
ans = 0
for i in range(N):
    ans = max(ans, s.count(s[i])-t.count(s[i]))
print(max(ans,0))

Submission status: Accepted

Solution code:
N = int(input())
s = [input() for i in range(N)]
M = int(input())
t = [input() for i in range(M)]
ans = 0
for i in range(N):
    ans = max(ans, s.count(s[i])-t.count(s[i]))
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = list(input() for i in range(n))
m = int(input())
t = list(input() for i in range(m))

count = 0

for i in s:
    v = s.count(i) - t.count(i)
    if v >= count:
        count = v

print(count)

Submission status: Accepted

Solution code:
#
# abc091 b
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3
apple
orange
apple
1
grape"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """3
apple
orange
apple
5
apple
apple
apple
apple
apple"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """1
voldemort
10
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """6
red
red
blue
yellow
yellow
red
5
red
red
yellow
green
blue"""
        output = """1"""
        self.assertIO(input, output)


def resolve():
    N = int(input())
    s = []
    for _ in range(N):
        s.append(input())
    M = int(input())
    t = []
    for _ in range(M):
        t.append(input())
    ans = 0
    for i in range(N):
        ans = max(s.count(s[i]) - t.count(s[i]), ans)
    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Accepted

Solution code:
#
# abc091 b
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3
apple
orange
apple
1
grape"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """3
apple
orange
apple
5
apple
apple
apple
apple
apple"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """1
voldemort
10
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """6
red
red
blue
yellow
yellow
red
5
red
red
yellow
green
blue"""
        output = """1"""
        self.assertIO(input, output)


def resolve():
    N = int(input())
    l = {}
    for _ in range(N):
        w = input()
        if w in l:
            l[w] += 1
        else:
            l[w] = 1
    M = int(input())
    for _ in range(M):
        w = input()
        if w in l:
            l[w] -= 1
        else:
            l[w] = -1
    print(max(max(l.values()), 0))


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Accepted

Solution code:
dic = {}
n = int(input())
for i in range(n):
    s = str(input())
    dic.setdefault(s,0)
    dic[s] += 1
m = int(input())
for j in range(m):
    t = str(input())
    dic.setdefault(t,0)
    dic[t] -= 1
ans = max(dic.values())
if ans<0:
    ans = 0
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
s = [input() for i in range(N)]
M = int(input())
t = [input() for i in range(M)]

ans = 0
for i in s:
    if s.count(i) - t.count(i) > ans:
        ans = s.count(i) - t.count(i)
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

n=int(input())
s=[input() for _ in range(n)]
m=int(input())
t=[input() for _ in range(m)]

d=defaultdict(int)
for x in s:
  d[x]+=1
for y in t:
  d[y]-=1

print(max(0,max(d.values())))

Submission status: Accepted

Solution code:
def calc(blue, red):
	lst = []
	
	for ch in blue:
		if ch in red:
			lst.append(blue[ch] - red[ch])
		else:
			lst.append(blue[ch])

	return max(lst)


def main():
	N = int(input())
	blue = {}

	for _ in range(N):
		ch = input()
		if ch in blue:
			blue[ch] += 1
		else:
			blue[ch] = 1

	M = int(input())
	red = {}

	for _ in range(M):
		ch = input()
		if ch in red:
			red[ch] += 1
		else:
			red[ch] = 1

	value = calc(blue, red)

	if value >= 0:
		print(value)
	else:
		print(0)	

  
if __name__ == "__main__":
  	main()

Submission status: Accepted

Solution code:
n=int(input())
s=[input() for i in range(n)]
m=int(input())
t=[input() for i in range(m)]
ans=0
for i in range(n):
  a=s.count(s[i])-t.count(s[i])
  ans=max(ans,a)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
s = {}
for i in range(N):
    text = input()
    if not (text in s.keys()):
        s[text] = 1
    else:
        s[text] += 1

M = int(input())
t = dict()
for i in range(M):
    text = input()
    if not (text in t.keys()):
        t[text] = 1
    else:
        t[text] += 1

for key in s.keys():
    if key not in t.keys():
        t[key] = 0


maxVal = 0
for key in s.keys():
    maxVal = max(maxVal, s[key] - t[key])

print(maxVal)

Submission status: Accepted

Solution code:
d={}
a=[]
N=int(input())
for i in range(N):
  s=input()
  if s not in a:
    a.append(s)
    d[s]=1
  else:
    d[s]+=1
  a=list(set(a))
M=int(input())
for j in range(M):
  t=input()
  if t not in a:
    a.append(t)
    d[t]=-1
  else:
    d[t]-=1
  a=list(set(a))
ans=0
for k in a:
  ans=max(ans,d[k])
print(ans)

Submission status: Accepted

Solution code:
r1,r2=[input() for _ in range(int(input()))],[input() for _ in range(int(input()))]
print(max(0,max([r1.count(i)-r2.count(i) for i in set(r1)])))

Submission status: Accepted

Solution code:
r1,r2=[input() for _ in range(int(input()))],[input() for _ in range(int(input()))];ans=0
ans=[r1.count(i)-r2.count(i) for i in set(r1)];print(max(0,max(ans)))

Submission status: Accepted

Solution code:
r1=[input() for _ in range(int(input()))];r2=[input() for _ in range(int(input()))];ans=0
for i in set(r1): ans=max(ans,r1.count(i)-r2.count(i))
print(ans)

Submission status: Accepted

Solution code:
d={}
r=[input() for _ in range(int(input()))]
for _ in range(int(input())):
  a=input()
  if a in r:
    r.pop(r.index(a))
for i in r:
  if i not in d:
    d[i] = 1
  else:
    d[i] += 1
d=sorted(d.items(),key=lambda x:-x[1])
print([0,d[0][1]][d[0][1]>0] if d else 0)

Submission status: Accepted

Solution code:
N = int(input())
s = [input() for _ in range(N)]
M = int(input())
t = [input() for _ in range(M)]
print(max(max([s.count(e)-t.count(e) for e in s+t]),0))

Submission status: Accepted

Solution code:
n = int(input())
s = [str(input()) for i in range(n)]
m = int(input())
t = [str(input()) for h in range(m)]

from collections import Counter
s = Counter(s).most_common()
t = Counter(t).most_common()
l = []
for x in range(len(s)):
    z = 'Y'
    for y in range(len(t)):
        if s[x][0] == t[y][0]:
            l.append((s[x][1]-t[y][1],s[x][0]))
            z = 'N'
            break
    if z == 'Y':
        l.append((s[x][1],s[x][0]))
l.sort()
if l[-1][0] < 0:
    print(0)
else:
    print(l[-1][0])

Submission status: Accepted

Solution code:
n = int(input())
slist = [input() for _ in range(n)]
sset = set(slist)
m = int(input())
tlist = [input() for _ in range(m)]

ans = 0
for s in sset:
	if slist.count(s)>tlist.count(s):
		ans =max(ans,slist.count(s)-tlist.count(s))
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S=list()
for i in range(N):
  S.append(input())
M=int(input())
T=list()
for i in range(M):
  T.append(input())
ans=0
for i in S:
  v=S.count(i)-T.count(i)
  if v>ans:
    ans=v
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a={}
for _ in range(n):
  s=input()
  if a.get(s):a[s]+=1
  else:a[s]=1
m=int(input())
b={}
for _ in range(m):
  s=input()
  if b.get(s):b[s]+=1
  else:b[s]=1
ans=0
for i in a:
  ans=max(a[i]-b.get(i,0),ans)
print(ans)