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

Solution (Python):
N=int(input())
n=[str(input()) for i in range(N)]
M=int(input())
m=[str(input()) for i in range(M)]
print(max(0, max(n.count(n[i])-m.count(n[i]) for i in range(N))))

Solution (Python):

N=int(input())
S=[]
T=[]
for i in range(N):
    S.append(input())
M=int(input())
for i in range(M):
    T.append(input())
S_=list(set(S))
ans=0
for i in range(len(S_)):
    ns=S.count(S_[i])
    nt=T.count(S_[i])
    ans=max(ans,ns-nt)
print(ans)

Solution (Python):
from collections import defaultdict

blue=int(input())
blueList = []

for i in range(blue):
  blueList.append(input())

red=int(input())
redList = []

for i in range(red):
  redList.append(input())

dict = defaultdict(int)

for b in blueList:
  dict[b] += 1

for r in redList:
  dict[r] -= 1

max = -10000

for s in dict:
  if dict[s] > max:
    max = dict[s]

if max <= 0:
  max = 0
print(max)

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

Solution (Python):
N = int(input())
S = ["0"] * N
for i in range(N) :
    S[i] = input()
M = int(input())
T = ["0"] * M
for i in range(M) :
    T[i] = input()
count = -100
for i in range(N) :
    a = 0
    for j in range(N) :
        if S[j] == S[i] :
            a += 1
    for k in T :
        if S[i] == k :
            a -= 1
    count = max(a,count)
if count<= 0 :
    count = 0
print(count)

Solution (Python):
N=int(input())
s=[]
for i in range(N):
  s.append(str(input()))
M=int(input())
t=[]
for i in range(M):
  t.append(str(input()))
li=list(set(s))
ans=[]
for i in range(len(li)):
  ans.append(s.count(li[i])-t.count(li[i]))
print(max(max(ans),0))

Solution (Python):
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 set(s):   
    ans = max(ans,s.count(i) - t.count(i))
        
print(ans)

Solution (Python):
from collections import Counter
N = int(input())
blue = Counter([input() for _ in range(N)])
M = int(input())
red = Counter([input() for _ in range(M)])

diff = blue - red
print(max(diff.values()) if diff else 0)

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

S = collections.Counter(s)
T = collections.Counter(t)


ans = [0]
for key, cont in S.most_common():
  if cont > T[key]:
    ans.append(cont-T[key])
print(max(ans))

Solution (Python):
def counting(tar_word,tar_list):
	count = 0
	for i in range(len(tar_list)):
		if tar_word == tar_list[i]:
			count += 1
	return count


N = int(input())
s = list()
for i in range(N):
	s.append(str(input()))

M = int(input())
t = list()
for i in range(M):
	t.append(str(input()))
target = s+t
target = set(target)
target = list(target)

ans = list()
for tar in target:
	count = 0
	count += counting(tar,s)
	count -= counting(tar,t)
	ans.append(count)

print(max(ans)) if max(ans) >= 0 else print(0)

Solution (Python):
import collections

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

s.subtract(t)

if s.most_common()[0][1] > 0:
  ans = s.most_common()[0][1]
else:
  ans = 0
print(ans)

Solution (Python):
n = int(input())
blue = [input() for _ in range(n)]
m = int(input())
red = [input() for _ in range(m)]

ans = 0

def count_br(moji, s, t):
  count = 0
  for i in s:
    if i == moji:
      count += 1
  for i in t:
    if i == moji:
      count -= 1
  return count

for i in range(len(blue)):
  ans = max(ans, count_br(blue[i], blue, red))
  
print(ans)

Solution (Python):
a = int(input())
A = [input() for _ in range(a)]
b = int(input())
B = [input() for _ in range(b)]
a = list(set(A) | set(B))
c = []
for i in range(len(a)):
  c.append(A.count(a[i]) - B.count(a[i]))
if max(c) < 0:
  print(0)
else:
  print(max(c))

Solution (Python):
n = int(input())
s = list(input() for _ in range(n))
m = int(input())
t = list(input() for _ in range(m))

res = []
for i in range(n):
    res.append(s.count(s[i]) - t.count(s[i]))
if max(res) > 0:
    print(max(res))
else:
    print(0)

Solution (Python):
import sys
input = sys.stdin.readline
N=int(input())
s=[input().strip() for i in range(N)]
M=int(input())
t=[input().strip() for i in range(M)]
from collections import defaultdict
a=defaultdict(int)
for i in range(N):
    a[s[i]]+=1
for i in range(M):
    a[t[i]]-=1
print(max(0,max(a.values())))

Solution (Python):
import sys


def solve(inp):
    N = int(inp.readline())
    S = [inp.readline() for i in range(N)]
    M = int(inp.readline())
    T = [inp.readline() for i in range(M)]

    score = {}
    for s in S:
        if s not in score:
            score[s] = 0
        score[s] += 1
    for t in T:
        if t not in score:
            score[t] = 0
        score[t] -= 1

    m = max(0, max(score.values()))
    return str(m)


def main():
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
s = []
for _ in range(N):
    s.append(input().rstrip())
M = int(input())
t = []
for _ in range(M):
    t.append(input().rstrip())
from collections import Counter
cs = Counter(s)
ct = Counter(t)
ans = {}
for i in cs.keys():
    ans[i] = cs[i] - ct[i]
ans_max = max(ans.values())
print(max(0, ans_max))

Solution (Python):
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 set(s):
  point = s.count(i) - t.count(i)
  if ans < point:
    ans = point
print(ans)

Solution (Python):


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_sp = set(s)
dp = 0

for sp in s_sp:
    
    n_s = s.count(sp)
    
    try:
        n_t = t.count(sp)
    except:
        n_t = 0
        pass

    dp = max(dp, n_s - n_t)
    
print(dp)

Solution (Python):
N = int(input())
from collections import defaultdict
d_blue = defaultdict(int)
strs = set()
for i in range(N):
    s = input()
    d_blue[s] += 1
    strs.add(s)
M = int(input())
d_red = defaultdict(int)
for j in range(M):
    t = input()
    d_red[t] += 1
    strs.add(t)

ans = 0
for s in strs:
    b = d_blue[s]
    t = d_red[s]
    ans = max(ans,b-t)

print(ans)

Solution (Python):
S = [input() for _ in range(int(input()))]
T = [input() for _ in range(int(input()))]
l = list(set(S))
print(max(0, max(S.count(l[i]) - T.count(l[i]) for i in range(len(l)))))

Solution (Python):
N = int(input())
As = [input() for _ in range(N)]
M = int(input())
Bs = [input() for _ in range(M)]
c = max([As.count(a) - Bs.count(a) for a in As])
print(0 if c < 0 else c)

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

ans = 0
for w in set(s):
    m = s.count(w) - t.count(w)
    ans = max(ans, m)

print(ans)

Solution (Python):
n = int(input())
s = [input() for i in range(n)]
m = int(input())
t = [input() for i in range(m)]
candi = [0]
for i in s:
    tmp = 0
    for j in s:
        if i == j:
            tmp += 1
    for j in t:
        if i ==j:
            tmp -= 1
    candi.append(tmp)
print(max(candi))

Solution (Python):
import collections

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

s,t = collections.Counter(s), collections.Counter(t)
ans = 0

for i in s.most_common():
    ans = max(ans, i[1] - t[i[0]])

print(ans)

Solution (Python):
s={}
for i in range(int(input())):
  ss=input()
  if ss in s:
    s[ss]+=1
  else:
    s[ss]=1
t={}
for i in range(int(input())):
  tt=input()
  if tt in t:
    t[tt]+=1
  else:
    t[tt]=1
for k,v in s.items():
  if k in t:
    s[k]-=t[k]
ans=sorted(s.items(),key=lambda x:x[1])
if ans[-1][1]>=0:
  print(ans[-1][1])
else:
  print(0)

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

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

print(ans)

Solution (Python):
n = int(input())
s = [input() for i in range(n)]
m = int(input())
t = [input() for i in range(m)]
d = {}
ans = 0
for c in s:
    if c not in d:
        d[c] = 1
    else:
        d[c] += 1
for c in t:
    if c in d:
        d[c] -= 1
for c in d:
    ans = max(ans,d[c])
print(ans)

Solution (Python):
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):
    y=s.count(s[i])-t.count(s[i])
    if ans<y:
        ans=y
print(ans)

Solution (Python):
n = int(input())
s = []
for i in range(n):
    s.append(str(input()))
m = int(input())
t = []
for i in range(m):
    t.append(str(input()))

lst = list(set(s+t))
sumlst = [0]

for i in range(len(lst)):
    sumlst.append(s.count(lst[i])-t.count(lst[i]))

print(max(sumlst))

Solution (Python):




blues = {}
for _ in range(int(input())):
    r = input()
    if r in blues:
        blues[r] += 1
    else:
        blues[r] = 1
reds = {}
for _ in range(int(input())):
    b = input()
    if b in reds:
        reds[b] += 1
    else:
        reds[b] = 1

ans = 0
for k, v in blues.items():
    if k in reds:
        ans = max(ans, blues[k] - reds[k])
    else:
        ans = max(ans, v)

print(ans)

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

l = []
for i in range(n):
  S = s.count(s[i])
  T = t.count(s[i])
  l.append(S - T)
  
if max(l) < 0:
  print(0)
else:
  print(max(l))

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

l = list(set(s)) 

cnt=0
for k in range(len(l)):
    cnt = max(cnt, s.count(l[k]) - t.count(l[k]))

print(cnt)

Solution (Python):
from collections import Counter
s=[input() for _ in range(int(input()))]
cs=Counter(s)
t=[input() for _ in range(int(input()))]
ct=Counter(t)
ans = 0
for key in cs.keys():
    res = cs[key] - ct[key]
    ans = max(ans, res)
print(ans)

Solution (Python):
from collections import Counter

N = int(input())
S = [input() for i in range(N)]
M = int(input())
T = [input() for i in range(M)]

cou_S = Counter(S)
cou_T = Counter(T)

ans = [0]
for key in cou_S:
    ans.append(cou_S[key] - cou_T.get(key, 0))
print(max(ans))

Solution (Python):
ans={}
n=int(input())
for i in range(n):
    a = input()
    if a in ans:
        ans[a]+=1
    else:
        ans[a] = 1
m=int(input())
for i in range(m):
    a = input()
    if a in ans:
        ans[a]-=1
    else:
        ans[a] = -1
ans = sorted(ans.items(), key=lambda x: x[1], reverse=True)
if ans[0][1] < 0:
    print(0)
else:
    print(ans[0][1])

Solution (Python):
n=int(input())
d=dict()
for i in range(n):
  s = input()
  if s in d.keys():
    d[s] = d[s] + 1
  else:
    d[s] = 1
    
m=int(input())
for i in range(m):
  s = input()
  if s in d.keys():
    d[s] = d[s] - 1
print(max(0,max(d.values())))

Solution (Python):
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)))))

Solution (Python):
d = {}
N = int(input())
for _ in range(N):
    s = input()
    if s in d:
        d[s] += 1
    else:
        d[s] = 1
M = int(input())
for _ in range(M):
    t = input()
    if t in d:
        d[t] -= 1
    else:
        d[t] = -1
print(max(0, *d.values()))

Solution (Python):
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:
    ans = max(ans,s.count(i)-t.count(i))
print(ans)

Solution (Python):
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:
  ans = max(ans, s.count(i) - t.count(i))

print(ans)

Solution (Python):
from collections import Counter

N = int(input())
s = [input() for i in range(N)]
M = int(input())
t = [input() for i in range(M)]
a = Counter(s)
a = a.most_common()


ans = 0
for i in a:
  if i[0] not in t:
    ans = max(i[1],ans)

  elif i[0] in t:
    ans = max(i[1] - t.count(i[0]),ans)


print(ans)

Solution (Python):
import sys
from collections import defaultdict

n = int(sys.stdin.readline().rstrip())
s = sys.stdin.read().split()

def main():

    score = defaultdict(int)
    for w in s[:n]:
        score[w] += 1
    for w in s[n+1:]:
        score[w] -= 1

    ans = max(max(score.values()), 0)
    return ans

if __name__ == '__main__':
    ans = main()
    print(ans)

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

st = list(set(s + t))
d = dict()
for _st in st:
    d[_st] = 0

for i in range(n):
    d[s[i]] += 1
for i in range(m):
    d[t[i]] -= 1

print(max([0] + list(d.values())))

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

n = []
for i in range(N):
  S = s.count(s[i])
  T = t.count(s[i])
  n.append(S - T)

if max(n) < 0:
  print(0)
else:
  print(max(n))

Solution (Python):
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

N = int(input())

points = {}

for _ in range(N):
    c = input()

    if c in points:
        points[c] += 1
    else:
        points[c] = 1

M = int(input())

for _ in range(M):
    c = input()

    if c in points:
        points[c] -= 1
    else:
        points[c] = -1

ans = 0



for v in points.values():
    if ans < v:
        ans = v

if ans < 0:
    ans = 0

print(ans)

Solution (Python):

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

l = list(set(s))
a = max (s.count(l[i]) - t.count(l[i]) for i in range(len(l)))

print(a if a > 0 else 0)

Solution (Python):
from collections import Counter

N = int(input())
S = []
S_append = S.append
for _ in range(N):
    S_append(input())

M = int(input())
T = []
T_append = T.append
for _ in range(M):
    T_append(input())

SC = Counter(S)
TC = Counter(T)

dif = SC - TC
if len(dif):
    print(max(dif.values()))
else:
    print(0)

Solution (Python):
n=int(input())
S=list(input() for _ in range(n)) 
m=int(input())
T=list(input() for _ in range(m)) 
L=set(S)
print(max(0,max(S.count(l)-T.count(l) for l in L)))

Solution (Python):
n=int(input())
s=[str(input()) for i in range(n)]
m=int(input())
t=[str(input()) for i in range(m)]
ans=0
s_new=list(set(s))
for i in range(len(s_new)):
    if (s.count(s_new[i])-t.count(s_new[i]))>ans:
        ans=s.count(s_new[i])-t.count(s_new[i])
print(ans)

Solution (Python):
N = int(input())
str_to_point = {}
for i in range(N):
    val = input()
    if val in set(list(str_to_point.keys())):
        str_to_point[val] += 1
    else:
        str_to_point[val] = 1

M = int(input())
for i in range(M):
    val = input()
    if val in set(list(str_to_point.keys())):
        str_to_point[val] -= 1
    else:
        str_to_point[val] = -1

ans = max(str_to_point.values())
if ans < 0:
    print(0)
else:
    print(ans)

Solution (Python):
from collections import defaultdict

n = int(input())
ss = [input() for _ in range(n)]
m = int(input())
ts = [input() for _ in range(m)]

scores = defaultdict(int)
for s in ss:
    scores[s] += 1
for t in ts:
    scores[t] -= 1

ans = max(max(scores.values()), 0)
print(ans)

Solution (Python):
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)))))

Solution (Python):
n = [input() for _ in range(int(input()))]
m = [input() for _ in range(int(input()))]
l = list(set(n))

y = [0]
for i in range(len(l)):
    x = n.count(l[i]) - m.count(l[i])
    y.append(x)

print(max(y))

Solution (Python):
from collections import Counter
n=int(input())
a=[input() for i in range(n)]
m=int(input())
b=[input() for i in range(m)]
ca = Counter(a)
cb = Counter(b)
ans = [0]
for s,n in ca.items():
  ans.append(n-cb[s])
print(max(ans))

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

from collections import Counter

u = Counter(s)
v = Counter(t)

ans = 0

for key, value in u.items():
    ans = max(ans, value - v[key])
print(ans)

Solution (Python):
n = int(input())
a = [input() for i in range(n)]
m = int(input())
b = [input() for i in range(m)]

from collections import Counter

c = Counter(a)
d = Counter(b)

ans = 0

for key, value in c.items():
    ans = max(ans, value - d[key])
print(ans)

Solution (Python):
a = [input() for _ in range(int(input()))]
b = [input() for _ in range(int(input()))]
l = list(set(a))
c = max(0, max([a.count(i) - b.count(i) for i in l]))
print(c)

Solution (Python):
import math

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

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

Solution (Python):
import sys
from collections import defaultdict
d = defaultdict(int)
n = int(input())
for _ in range(n):
    d[input()] += 1
m = int(input())
for _ in range(m):
    d[input()] -= 1

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

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

Solution (Python):


n = int(input())
a = [input() for i in range(n)]

m = int(input())
b = [input() for i in range(m)]

from collections import Counter

c = Counter(a)
d = Counter(b)

ans = 0

for key, value in c.items():
  ans = max(ans, value - d[key])
 
print(ans)

Solution (Python):
N = int(input())

ss = []
for _ in range(N):
    ss.append(input())

M = int(input())
ts = []
for _ in range(M):
    ts.append(input())

ans = 0
for s in ss:
    ans = max(ans, ss.count(s) - ts.count(s))

print(ans)

Solution (Python):
n = int(input())
lb = []
lr = []

for i in range(n):
    lb.append(input())

say = list(set(lb))

m = int(input())
for i in range(m):
    lr.append(input())

p = []
for i in range(len(say)):
    c = lb.count(say[i]) - lr.count(say[i])
    p.append(c)



if max(p) <= 0:
    print(0)
else:
    print(max(p))

Solution (Python):
n = int(input())
ns = [input() for _ in range(n)]
m = int(input())
ms = [input() for _ in range(m)]

ans = 0
for x in set(ns):
    tmp = ns.count(x) - ms.count(x)
    if ans < tmp:
        ans = tmp
        
print(ans)

Solution (Python):
n = int(input())
blues = []
for i in range(n):
  blues.append(input())
m = int(input())
reds = []
for j in range(m):
  reds.append(input())
pairs = {}
count = 0
count_b = 0
count_r = 0
setted_blues = set(blues)
setted_reds = set(reds)
for k in setted_blues:
  count_b = blues.count(k)
  pairs[k] = count_b
for l in setted_reds:
  count_r = reds.count(l)
  for m,n in pairs.items():
    if m == l:
      count = n - count_r
      pairs[m] = count
sorted_pairs = sorted(pairs.items(),key = lambda x:x[1],reverse = True)
answer = sorted_pairs[0][1]
if answer < 0:
  answer = 0
print(answer)

Solution (Python):
n=int(input())
s=[input() for i in range(n)]
m=int(input())
t=[input() for j in range(m)]
l=list(set(s))

result=max(0,max(s.count(i)-t.count(i) for i in l))
print(result)

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

result=0
for item in s:
    temp=s.count(item)-t.count(item)
    if result<temp:
        result=temp

print(result)

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

Solution (Python):
import collections
N = int(input())
blue = []
red = []
for i in range(N):
    s = input()
    blue.append(s)
bc = sorted(collections.Counter(blue).items(), key = lambda x:x[1],reverse = True)
M = int(input())
for i in range(M):
    t = input()
    red.append(t)
rc = collections.Counter(red)

count = []
for i in range(len(bc)):
    count.append(bc[i][1])
    if bc[i][0] in rc:
        count[i] -= rc[bc[i][0]]

print(max(0,max(count)))

Solution (Python):



def main()->None:
    N = int(input())
    range_N = range(N)
    s = []
    for _ in range_N:
        s.append(input())
    M = int(input())
    range_M = range(M)
    t = []
    for _ in range_M:
        t.append(input())
    
    
    max_total = 0
    for i in s:
        s_count = s.count(i)
        t_count = t.count(i)
        total = s_count - t_count
        if total > max_total:
            max_total = total

    print(max_total)




if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
s = {}
for i in range(N):
    si = input()
    if si in s:
        s[si] += 1
    else:
        s[si] = 1
M = int(input())
for i in range(M):
    ti = input()
    if ti in s:
        s[ti] -= 1
ans = 0
for val in s.values():
    ans = max(ans, val)
print(ans)

Solution (Python):

N = int(input())
s = [input() for i in range(N)]

M = int(input())
t = [input() for j in range(M)]

n_num = 0
m_num = 0
x = []
y = []

for i in range(N):
    n_num = s.count(s[i])
    m_num = t.count(s[i]) * -1
    x.append(n_num + m_num)


for j in range(M):
    n_num = s.count(t[j])
    m_num = t.count(t[j]) * -1
    y.append(n_num + m_num)

ans = x + y
if max(ans) < 0:
    print(0)
else:
    print(max(ans))

Solution (Python):
n =int(input())
a = [input() for i in range(n)]
m =int(input())
b = [input() for i in range(m)]
l = set(a)
e = -100000
for i in l:
    e = max(e,a.count(i)-b.count(i))
print(max(e,0))

Solution (Python):
from collections import Counter
n =int(input())
a = [input() for i in range(n)]
m =int(input())
b = [input() for i in range(m)]
c = Counter(a)
d = Counter(b)
e = -100000
for i,j in c.most_common():
    e = max(j-d[i],e)
print(max(e,0))

Solution (Python):
n = int(input())
list_blue = [input() for i in range(n)]
m = int(input())
list_red = [input() for i in range(m)]

ans = 0

for i in list_blue:
    point = list_blue.count(i) - list_red.count(i)
    if ans < point:
        ans = point

print(ans)

Solution (Python):
N=int(input())
s=[input() for _ in range(N)]
M=int(input())
t=[input() for _ in range(M)]
l=list(set(s))
print(max(0,max(s.count(l[i])-t.count(l[i]) for i in range(len(l)))))

Solution (Python):
n = int(input())
max_score = 0
word_list1 = []
for i in range(n):
    s = input()
    word_list1.append(s)

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


what_to_say = set(word_list1)


for i in what_to_say:
    score = 0
    for j in word_list1:
        if i == j:
            score += 1
    for k in word_list2:
        if i == k:
            score -= 1
    if score > max_score:
        max_score = score

print(max_score)

Solution (Python):
dict_ = dict()
[exec("dict_['{0}'] = dict_.get('{0}', 0) + 1".format(input())) for _ in range(int(input()))]
[exec("dict_['{0}'] = dict_.get('{0}', 0) - 1".format(input())) for _ in range(int(input()))]
print(max(max(dict_.values()), 0))

Solution (Python):
n=int(input())
br=[]
re=[]
for i in range(n):
    s=input()
    br.append(s)

m=int(input())
for i in range(m):
    t=input()
    re.append(t)
count=[0]
for i in range(n):
    brcou=0
    for j in range(n):
        if br[i]==br[j]:
            brcou+=1
    for k in range(m):
        if br[i]==re[k]:
            brcou-=1
    count.append(brcou)
print(max(count))

Solution (Python):

import sys, math, itertools, heapq, collections, bisect, string
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**7)
inf = float('inf')
mod = 10**9+7
ans = inf ;count = 0 ;pro = 1
D=collections.defaultdict(int)
n=int(input())
for i in range(n):
    s=input()
    D[s]+=1
m=int(input())
for i in range(m):
    s=input()
    D[s]-=1
print(max(0,max(D.values())))

Solution (Python):
N=int(input())
sn=[input() for i in range(N)]
M=int(input())
tn=[input() for i in range(M)]
ans = 0
value =[]
for l in set(sn):
    value.append(sn.count(l) - tn.count(l))
print(max(0, max(value)))

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

Solution (Python):
import collections
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]
blue = collections.Counter(s)
red = collections.Counter(t)
ans = ""
for k_b,v_b in blue.items():
  for k_r,v_r in red.items():
    if k_b == k_r:
      blue[k_b] = v_b - v_r
if max(blue.values()) < 0:
  print(0)
else:
  print(max(blue.values()))

Solution (Python):
n = int(input())
nlst = [input() for _ in range(n)]
m = int(input())
mlst = [input() for _ in range(m)]

lst = []
lst.extend(nlst)
lst.extend(mlst)
lst = set(lst)

c = [nlst.count(i) - mlst.count(i) for i in lst]
c.append(0)
print(max(c))

Solution (Python):
n = int(input())
ls_s = [input() for _ in range(n)]
m = int(input())
ls_t = [input() for _ in range(m)]

ls_u =ls_s + ls_t
p = m + n 

ans = 0


for i in range(n):
    cnt = 0
    for j in range(p):
        if ls_u[i] == ls_u[j] and j <= n - 1:
            cnt += 1
        elif ls_u[i] == ls_u[j] and n - 1 < j:
            cnt += -1
    if cnt >= ans:
        ans = cnt

print(ans)

Solution (Python):
N = int(input())
S = [0] * N
for i in range(N):
    S[i] = input()

M = int(input())
T = [0] * M
for i in range(M):
    T[i] = input()

m = 0
for s1 in S:
    x = 0
    for s2 in S:
        if s1 == s2:
            x += 1
    for t in T:
        if t == s1:
            x -= 1

    if x > m:
        m = x
print(m)

Solution (Python):
import collections

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

for i in range(len(t)):
    for j in range(len(s)):
        if t[i] == s[j]:
            del s[j]
            break

d = collections.defaultdict(int)

for c in s:
    d[c] += 1

if len(d) == 0:
    print(0)
else:
    print(max(d.values()))

Solution (Python):
N = int(input())

s_dict = {}

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

M = int(input())

t_dict = {}

for i in range(M):
    t = input()
    if t in t_dict:
        t_dict[t] += 1
    else:
        t_dict[t] = 1

maximum = 0

for s_key, s_value in s_dict.items():
    if s_key in t_dict:
        maximum = max(0, s_value - t_dict[s_key], maximum)
    else:
        maximum = max(s_value, maximum)
        
print(maximum)

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

xs = []
for i in set(s+t):
    x = 0
    for j in s:
        if i == j:
            x += 1
    for k in t:
        if i == k:
            x -= 1
    xs.append(x)
print(max(xs + [0]))

Solution (Python):
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:
    ans = max(ans, S.count(i) - T.count(i))

print(ans)

Solution (Python):
n = int(input())
s, t = [],[]
for _ in range(n):
    s.append(input())
s_dict = {s_:0 for s_ in s}
s_dict['aaaaaaaaaaa'] = 0
m = int(input())
for _ in range(m):
    t.append(input())
t_dict = {t_:0 for t_ in t}
for i in range(n):
    s_dict[s[i]] += 1
for i in range(m):
    t_dict[t[i]] += 1
    
for i in s_dict:
    if i in t_dict:
        s_dict[i] -= t_dict[i]
        
print(max(s_dict.values()))

Solution (Python):
dicN={}
for i in range(int(input())):
  x=input()
  if x in dicN:
    dicN[x]+=1
  else:
    dicN[x]=1
dicM={}
for i in range(int(input())):
  x=input()
  if x in dicM:
    dicM[x]+=1
  else:
    dicM[x]=1
ls=[0]
for k,v in dicN.items():
  if k in dicM:
    ls.append(v-dicM[k])
  else:
    ls.append(v)
print(max(ls))

Solution (Python):
n = int(input())
S = []
for _ in range(n):
    S.append(str(input()))

m = int(input())
T = []
for _ in range(m):
    T.append(str(input()))

W = S + T

ans = 0

for w in W:
    can = S.count(w) - T.count(w)
    if can >= ans:
        ans = can

print(ans)

Solution (Python):
N = int(input())
s = [input() for _ in range(N)]
M = int(input())
t = [input() for _ in range(M)]
ans = 0
for blue in s:
  reward = s.count(blue) - t.count(blue)
  if reward > 0 and reward > ans:
    ans = reward
print(ans)

Solution (Python):
N=int(input())
s = [input() for i in range(N)]
M=int(input())
t = [input() for j in range(M)]
st=s+t
st=(list(set(st)))
cost=[]

for k in st:
    cost.append(s.count(k)-t.count(k))

if max(cost)<=0:
    print(0)
else:
    print(max(cost))

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

M = int(input())
t = []
for i in range(M):
    t.append(str(input()))
ans = 0
for i in s:
    x = s.count(i)
    y = t.count(i)
    if x - y > ans:
        ans = x - y

print(ans)

Solution (Python):
n = int(input())
n_l = list(str(input()) for i in range(n))
m = int(input())
m_l = list(str(input()) for _ in range(m))

index = list(list(set(n_l)) + list(set(m_l)))
l = []

for k in range(len(index)):
    key = index[k]
    a = n_l.count(key)
    b = m_l.count(key)
    l.append(a-b)

if max(l) < 0:
    print(0)
else:
    print(max(l))

Solution (Python):
from collections import Counter
c = Counter()
N = int(input())
for _ in range(N):
    s = input()
    c[s] += 1
M = int(input())
for _ in range(M):
    t = input()
    c[t] -= 1

ans = max(c.most_common()[0][1], 0)
print(ans)