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 = [input() for _ in range(N)]
M = int(input())
t = [input() for _ in range(M)]
S = list(set(s))  #計算削減のため
cnts = [0]
for i in range(len(S)):
	cnts.append(s.count(S[i]) - t.count(S[i]))
print(max(cnts))

Submission status: Accepted

Solution code:
N = int(input())

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

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

hs = {}

for s in Ss:
    if s in list(hs.keys()):
        hs[s] += 1
    else:
        hs[s] = 1

for t in Ts:
    if t in list(hs.keys()):
        hs[t] -= 1

print(max(max([i[1] for i in hs.items()]),0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict
def main():
	N = int(input())
	S = [""]*N
	cards = defaultdict(int)
	for i in range(N):
		S[i] = input()
		cards[S[i]] += 1
	M = int(input())
	T = [""]*M
	for i in range(M):
		T[i] = input()
		cards[T[i]] -= 1

	ans = 0
	for v in cards.values():
		ans = max(ans, v)

	print(ans)


if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
d = {}
n = int(input())
for _ in range(n):
    e = input()
    if e not in d:
        d[e] = 1
    else:
        d[e] += 1
m = int(input())
for _ in range(m):
    e = input()
    if e not in d:
        d[e] = -1
    else:
        d[e] -= 1

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

Submission status: Accepted

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

d = dict((s - t).most_common(1))
print(list(d.values())[0] if d else 0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def make_dict(S):
  dic = dict()
  for s in S:
    if s in dic:
      dic[s] += 1
    else:
      dic[s] = 1
  return dic

N = int(input())
S = [input() for i in range(N)]
M = int(input())
T = [input() for i in range(M)]
blue = make_dict(S)
red = make_dict(T)
ans = 0
for s in blue.keys():
  tmp = blue[s]
  if s in red:
    tmp -= red[s]
  ans = max(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
def make_dict(S):
  dic = dict()
  for s in S:
    if s in dic.keys():
      dic[s] += 1
    else:
      dic[s] = 1
  return dic

N = int(input())
S = [input() for i in range(N)]
M = int(input())
T = [input() for i in range(M)]
blue = make_dict(S)
red = make_dict(T)
ans = 0
for s in blue.keys():
  tmp = blue[s]
  if s in red.keys():
    tmp -= red[s]
  ans = max(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
b=[input()for _ in range(n)]
d={l:b.count(l)for l in set(b)}
m=int(input())
for _ in range(m):
  s=input()
  if s in d.keys():
    d[s]-=1
print(max(list(d.values())+[0]))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from collections import Counter
INF = float("inf")


def solve(N: int, s: "List[str]", M: int, t: "List[str]"):
    m = 0
    rec = ""
    sc = Counter(s)
    st = Counter(t)
    for c, v in sc.items():
        if m < v - st[c]:
            rec = c
            m = v - st[c]
    print(m)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(N)]  # type: "List[str]"
    M = int(next(tokens))  # type: int
    t = [next(tokens) for _ in range(M)]  # type: "List[str]"
    solve(N, s, M, t)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
ss = {}
for i in range(n):
    s = input().strip()
    if s in ss:
        ss[s] += 1
    else:
        ss[s] = 1

m = int(input())
ts = {}
for i in range(m):
    s = input().strip()
    if s in ts:
        ts[s] += 1
    else:
        ts[s] = 1

max_score = 0
for s, sc in ss.items():
    tc = ts[s] if s in ts else 0
    max_score = max(max_score, sc - tc)

print(max_score)

Submission status: Accepted

Solution code:
N = int(input())
s = [str(input()) for i in range(N)]
M = int(input())
t = [str(input()) for i 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())
s = [str(input()) for i in range(N)]
M = int(input())
t = [str(input()) for i in range(M)]
x = {}
for i in s:
    if i in x:
        x[i] += 1
    else:
        x[i] = 1
for i in t:
    if i in x:
        x[i] -= 1
    else:
        x[i] = -1
if max(x.values()) < 0:
    print(0)
else:
    print(max(x.values()))

Submission status: Accepted

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

#全てのsについて、S内の個数とT内の個数を出す
#S-Tが最も大きいものをメモしていき、最大値をansにする
ans = 0
scnt = 0
tcnt = 0
for s in S:
  scnt = 0 #再初期化
  tcnt = 0 #再初期化
  for tmps in S:
    if s == tmps: scnt += 1
  for t in T:
    if t == s: tcnt += 1
  ans = max(ans, scnt - tcnt)
  
print(max(0, ans))

Submission status: Accepted

Solution code:
import sys
from collections import Counter

n = int(input())
s_list = [input() for i in range(n)]
s_cntr = Counter(s_list)
m = int(input())
t_list = [input() for i in range(m)]
t_cntr = Counter(t_list)
ans = 0


for k in dict(s_cntr).keys():
    if k in dict(t_cntr).keys():
        tmp = s_cntr[k] - t_cntr[k]
    else:
        tmp = s_cntr[k]
    if ans < tmp:
        ans = tmp

print(ans)

Submission status: Accepted

Solution code:
D = dict()
N = int(input())
for i in range(N):
    s = input()
    if s in D.keys():
        D[s] += 1
    else:
        D[s] = 1
M = int(input())
for i in range(M):
    t = input()
    if t in D.keys():
        D[t] -= 1
ans = 0
for v in D.values():
    ans = max(ans,v)
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)]
li = []

for i in range(n) :
    word = s[i]
    li.append(s.count(word) - t.count(word))
x = max(li)
if x <= 0 :
    print(0)
else :
    print(x)

Submission status: Accepted

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

word_set = set(S)
max_revenue = 0
for w in word_set:
  revenue = 0
  for s in S:
    if w == s:
      revenue += 1
  for t in T:
    if w == t:
      revenue -= 1
  if revenue > max_revenue:
    max_revenue = revenue

print(max_revenue)

Submission status: Accepted

Solution code:
N = int(input())

b = {}
for i in range(N):
  s = str(input())
  if b.get(s) is None:
    b[s] = 1
  else:
    b[s] += 1
    
r = {}
M = int(input())
for i in range(M):
  s = str(input())
  if r.get(s) is None:
    r[s] = 1
  else:
    r[s] += 1

ans = -999999
for st in b:
  if r.get(st) is None:
    ans = max(ans, b[st])
  else:
    ans = max(ans, b[st] - r[st])
if ans >= 0:
  print(ans)
else:
  print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
  N = int(input())
  s = []
  for _ in range(N):
    s.append(input())
  M  = int(input())
  t = []
  for _ in range(M):
    t.append(input())
  
  su = list(set(s))
  ans = 0
  for row in su:
    point = s.count(row) - t.count(row)
    if ans < point:
      ans = point
  print(ans) 

main()

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
s=[]
for i in range(n):s.append(input())
m=int(input())
t=[]
for i in range(m):t.append(input())
cs=Counter(s).most_common()
ans=0
for i,j in cs:ans=max(ans,j-t.count(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)]
l=list( set(s) )
maxbox=[]
for i in range( len(l) ):
    maxbox.append( int( s.count(l[i])-t.count(l[i]) ) ) 
maxbox.append(0)
print(max(maxbox))

Submission status: Accepted

Solution code:
import sys
from collections import Counter
input = sys.stdin.readline

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


s = Counter(s)
t = Counter(t)
s.subtract(t)

print(max(0, s.most_common(1)[0][1]))

Submission status: Accepted

Solution code:
N = int(input())
s = [input() for _ in [0]*N]
M = int(input())
t = [input() for _ in [0]*M]
ans = {}
for c in s:
    ans[c] = ans.get(c,0) + 1
for c in t:
    ans[c] = ans.get(c,0) - 1
print(max(0,max(ans.values())))

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)]
st = set(s+t)
ans = -10000

for i in st:
    count = 0
    for j in s:
        if i == j:
            count += 1
    for j in t:
        if i == j:
            count -= 1
    ans = max(ans, count)

if ans > 0:
    print(ans)
else:
    print(0)

Submission status: Accepted

Solution code:
N = int(input())
s = [input() for _ in range(N)]
M = int(input())
t = [input() for _ in range(M)]
m = 0
for i in list(set(s)):
  tmp = s.count(i) - t.count(i)
  if tmp > m:
    m = tmp
print(m)

Submission status: Accepted

Solution code:
dic_words = {}
for i in range(0, int(input())):
    word = input()
    if word in dic_words.keys():
        dic_words[word] += 1
    else:
        dic_words[word] = 1

for i in range(0, int(input())):
    word = input()
    if word in dic_words.keys():
        dic_words[word] -= 1
    else:
        dic_words[word] = -1

if (max(dic_words.values()) >= 0):
    print(max(dic_words.values()))
else:
    print(0)

Submission status: Accepted

Solution code:
red = []
blue = []

N = int(input())
for i in range(N):
    red.append(input())
    
M = int(input())
for i in range(M):
    blue.append(input())

counts = [red.count(word) - blue.count(word) for word in red]
ans = max(max(counts), 0)
print(ans)

Submission status: Accepted

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

ans = 0

for i in range(n):
    ans_n = 0
    for j in range(m):
        if sn[i]==sm[j]:
            ans_n -= 1
    for k in range(n):
        if sn[i]==sn[k]:
            ans_n += 1
    ans = max(ans, ans_n)

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
N_list=list(map(str, list(input() for i in range (N))))
M=int(input())
M_list=list(map(str, list(input() for i in range (M))))


N_unique=list(set(N_list))

p_max=-101
for i in N_unique:
    p_max=max(p_max, N_list.count(i)-M_list.count(i))

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

Submission status: Accepted

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

X = 0
for i in range(N):
    temp = 0
    temp = s.count(s[i])
    for j in range(M):
        if s[i] == t[j]:
            temp -= 1
    X = max(X, temp)
print(X)

Submission status: Accepted

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

dict_s = {}
for i in range(N):
    if s[i] in dict_s:
        dict_s[s[i]] += 1
    else:
        dict_s[s[i]] = 1

dict_t = {}
for i in range(M):
    if t[i] in dict_t:
        dict_t[t[i]] += 1
    else:
        dict_t[t[i]] = 1

cnt=0
for i in dict_s:
    x = dict_s[i]
    if i in dict_t:
        x -= dict_t[i]
    if x >= cnt:
        cnt = x
print(cnt)

Submission status: Accepted

Solution code:
d = dict()
N = int(input())
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())))

Submission status: Accepted

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

m = 0
c = 0
for i in range(N):
    w = s[i]
    c = s.count(w)
    c -= t.count(w)
    if m < c:
        m = c
print(m)

Submission status: Accepted

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

X = 0
check = []
for i in blue:
    yen = 0
    if i not in check:
        check.append(i)
        for j in blue:
            if j == i:
                yen += 1
        for j in red:
            if j == i:
                yen -= 1
    X = max(X, yen)

print(X)

Submission status: Accepted

Solution code:
from collections import Counter as c
import sys
input = sys.stdin.readline

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

S = c(S)
T = c(T)
ans = 0
for s in S:
    ans = max(ans,S[s]-T[s])
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 set(s):
  ans = max(ans, s.count(i)-t.count(i))
print(ans)

Submission status: Accepted

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

KEY = set(S + T)

max_point = 0
max_key = ""
for key in KEY:
	point = S.count(key) - T.count(key)
	if max_point < point:
		max_point = point
		max_key = key
#print(max_key)
print(max_point)

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
di0 = {}
di1 = {}
for i in s:
  if(not i in di0):
    di0[i]=1
    di1[i]=0
  else:
    di0[i]+=1
for i in t:
  if(not i in di1):
    di1[i]=1
  else:
    di1[i]+=1
for i in di0:
  ans = max(di0[i]-di1[i],ans)
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))
ans=0
for i in s:
    key=0
    for j in s:
        if i==j:
            key+=1
    for j in t:
        if i==j:
            key-=1
    ans=max(ans,key)
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(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 = []
for i in set(s):
  ans.append(s.count(i) - t.count(i))
print(max(0,max(ans)))

Submission status: Accepted

Solution code:
n=int(input())
a=[input() for s in range(n)]
m=int(input())
b=[input() for t in range(m)]
aa=list(set(a))
bb=list(set(b))
aa.extend(bb)
category=list(set(aa))
c=[0]*len(category)
for i in a:
   for j in category:
       if i==j:
           c[category.index(j)]+=1
for i in b:
   for j in category:
       if i==j:
           c[category.index(i)]-=1
          
if max(c)<0:
    c.append(0)
print(max(c))

Submission status: Accepted

Solution code:
n = int(input())
bl = [input() for _ in range(n)]
m = int(input())
rd = [input() for _ in range(m)]
ans = []
for s in set(bl):
    ans.append(bl.count(s) - rd.count(s))
print(max(0, max(ans)))

Submission status: Accepted

Solution code:
ls_t = [input().rstrip() for _ in range(int(input()))]
ls_s = [input().rstrip() for _ in range(int(input()))]
ls_marged = list(set(ls_t+ls_s))

result = 0

for word in ls_marged:
    t = ls_t.count(word)
    s = ls_s.count(word)
    result = max(result, t-s)

print(result)

Submission status: Accepted

Solution code:
N = int(input())
dct_t = {}

for _ in range(N):
    tmp = input().rstrip()
    if tmp in dct_t:
        dct_t[tmp] += 1
    else:
        dct_t[tmp] = 1

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

for _ in range(M):
    tmp = input().rstrip()
    if tmp in dct_s:
        dct_s[tmp] += 1
    else:
        dct_s[tmp] = 1

result = 0

for t in list(dct_t.keys()):
    for s in list(dct_s.keys()):
        if t in dct_s:
            tmp = dct_t[t] - dct_s[t]
            if result < tmp:
                result = tmp
        elif result < dct_t[t]:
            result = dct_t[t]

print(result)

Submission status: Accepted

Solution code:
n = int(input())
li = []
li2 = []
li4 = []
c = 0

for i in range(n):
    s = input()
    li.append(s)
    li3 = set(li)
    
m = int(input())
for i in range(m):
    t = input()
    li2.append(t)

for a in li3:
    c = li.count(a)
    c -= li2.count(a)
    li4.append(c)

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

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
s = [None]*N
for i in range(N):
    s[i] = input()
M = int(input())
t = [None]*M
for j in range(M):
    t[j] = input()

sc = Counter(s)
tc = Counter(t)

ans = 0
for k in sc.keys():
    ans = max(ans, sc[k] - tc[k])
print(ans)

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)]

print(max(0, max(map(lambda z: z[1] - t.count(z[0]), Counter(s).items()))))

Submission status: Accepted

Solution code:
dict = {}
N = int(raw_input())
for i in range(N):
    blue = raw_input()
    if blue in dict: dict[blue] += 1
    else: dict[blue] = 1

M = int(raw_input())
for i in range(M):
    red = raw_input()
    if red in dict: dict[red] -= 1
    else: dict[red] = -1

if 0 < max(dict.values()): print max(dict.values())
else: print(0)

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 word in set(s):
    given = s.count(word) - t.count(word)
    ans = max(ans, given)
    
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
words = []
s = []
for i in range(N):
    si = input()
    s.append(si)
    if si not in words:
        words.append(si)
M = int(input())
t = []
for i in range(M):
    ti = input()
    t.append(ti)
    if ti not in words:
        words.append(si)
ans = 0
for word in words:
    ans = max(ans, (s.count(word) - t.count(word)))
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
SS=list(set(S))
for s in SS:
    score=S.count(s)-T.count(s)
    ans=max(ans,score)
print(ans)

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())
SS=list(set(S))
TS=list(set(T))
ans=0
for i in range(len(SS)):
    a=S.count(SS[i])
    b=T.count(SS[i])
    ans=max(ans,a-b)
print(ans)

Submission status: Accepted

Solution code:
Blue_card = [input() for i in range(int(input()))]
Red_card = [input() for i in range(int(input()))]
ans_list = [0]
for i in set(Blue_card):
    ans_list.append(Blue_card.count(i) - Red_card.count(i))
print(max(ans_list))

Submission status: Accepted

Solution code:
n=int(input())
arr1=[input() for _ in range(n)]
m=int(input())
arr2=[input() for _ in range(m)]
max=0
for i in range(n):
  tmp=arr1.count(arr1[i])-arr2.count(arr1[i])
  if tmp>max:
    max=tmp
print(max)

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    blue = defaultdict(int)
    for _ in range(n):
        blue[SI()] += 1
        
    m = II()
    red = defaultdict(int)
    for _ in range(m):
        red[SI()] += 1

    res = 0
    for key, v in blue.items():
        res = max(res, v - red[key])

    return res


print(main())

Submission status: Accepted

Solution code:
N=int(input())
BLUE=[input() for i in range(N)]
M=int(input())
RED=[input() for i in range(M)]
List=list(set(list(set(BLUE))+list(set(RED))))
ans=0
for s in List:
  p=BLUE.count(s)
  m=RED.count(s)
  ans=max(ans,p-m)
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)]

c = 0

for i in range(n):
    a = 0
    b = 0
    for j in range(n):
        if s[i] == s[j]:
            a += 1

    for j in range(m):
        if s[i] == t[j]:
            b += 1

    if c < a-b:
        c = a-b

print(c)

Submission status: Accepted

Solution code:
from collections import defaultdict
from fractions import gcd
#from math import factorial
from math import sqrt
from math import ceil
from itertools import permutations
from heapq import *

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

M=int(input())
A=defaultdict(int)
for i in range(M):
    s=input()
    A[s]+=1
Max=0
for key in set(A) | set(B):
    Max=max(Max,B[key]-A[key])
print(Max)

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)]
st = list(set(s) | set(t))

ans = []
for i in st:
    tmp = 0
    tmp += s.count(i)
    tmp -= t.count(i)
    ans.append(tmp)
    
print(max(0, max(ans)))

Submission status: Accepted

Solution code:
N = int(input())
l={}
for _ in range(N):
    s = input()
    if s not in l:
        l[s] = 1
    else:
        l[s] += 1
M = int(input())
for _ in range(M):
    s = input()
    if s in l:
        l[s] -= 1
        
print(max(l.values()) if max(l.values()) >= 0 else 0)

Submission status: Accepted

Solution code:
#ABC 091 B - Two Colors Card Game
import collections
n = int(input())
s = [input() for i in range(n)]
m = int(input())
t = [input() for i in range(m)]
c = collections.Counter(s) - collections.Counter(t)
if not c:
    print(0)
else:
    print(c.most_common()[0][1])

Submission status: Accepted

Solution code:
import collections
n=int(input())
s=[input() for i in range(n)]
m=int(input())
t=[input() for i in range(m)]
smax=collections.Counter(s)
tmax=collections.Counter(t)
ans=[0]
for i,j in smax.items():
    if i in tmax.keys():
        ans+=[smax[i]-tmax[i]]
    else:
        ans+=[j]
print(max(ans))

Submission status: Accepted

Solution code:
N =int(input())
l1 =[input() for i in range(N)]
M =int(input())
l2 =[input() for i in range(M)]
dic = {'':0}
for v in (l1 + l2):
    dic[v] = l1.count(v) - l2.count(v)
print(max(dic.values()))

Submission status: Accepted

Solution code:
N = int(input())
blue = {}
for _ in range(N):
    s = input().rstrip()
    if blue.get(s) == None:
        blue[s] = 1
    else:
        blue[s] += 1
M = int(input())
red = {}
for _ in range(M):
    t = input().rstrip()
    if red.get(t) == None:
        red[t] = 1
    else:
        red[t] += 1
answer = 0
for i, blue_elem in blue.items():
    red_elem = red[i] if red.get(i) != None else 0
    answer = blue_elem - red_elem if answer < blue_elem - red_elem else answer
print(answer)

Submission status: Accepted

Solution code:
#input
n = int(input())
blue = []
for i in range(n):
    s = input()
    blue.append(s)
m = int(input())
red = []
for i in range(m):
    t = input()
    red.append(t)
#maniplate
ans = [0]
for word in (blue + red):
    count = sum([s == word for s in blue])
    count -= sum([t == word for t in red])
    ans.append(count)
#output
print(max(ans))

Submission status: Accepted

Solution code:
from collections import defaultdict
N=int(input())
d=defaultdict(int)
for i in range(N):
  d[input()]+=1
M=int(input())
for i in range(M):
  d[input()]-=1
ans=0
for key in d:
  ans=max(ans,d[key])
print(ans)

Submission status: Accepted

Solution code:
N =int(input())
AB=[[str(j) for j in input().split()] for i in range(N)]
M=int(input())
CD=[[str(j) for j in input().split()] for i in range(M)]
ans = 0
for i in AB:
    if ans < AB.count(i) -CD.count(i) :
        ans = AB.count(i) -CD.count(i)
print(ans)

Submission status: Accepted

Solution code:
n,*s=open(0);print(max(0,*[s.count(i)-s[int(n):].count(i)*2for i in s]))

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
cnt = dict()
for i in range(n):
    s = input()
    try:
        cnt[s] += 1
    except:
        cnt[s] = 1
m = int(input())
for i in range(m):
    s = input()
    try:
        cnt[s] -= 1
    except:
        cnt[s] = -1

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

Submission status: Accepted

Solution code:
d = {}

N = int(input())
for i in range(N):
    s = input()
    d[s] = d.get(s, 0) + 1

M = int(input())
for i in range(M):
    t = input()
    d[t] = d.get(t, 0) - 1

print(max(max(d.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)]
a = 0
for i in s:
    b = s.count(i) - t.count(i)
    if a < b:
        a = b
print(a)

Submission status: Accepted

Solution code:
n = int(raw_input())
s = []
t = []
for i in range(n):
	s.append(str(raw_input()))
m = int(raw_input())
for i in range(m):
	t.append(str(raw_input()))
s_uni = list(set(s))
count = 0
for i in range(len(s_uni)):
	tmp = s.count(s_uni[i]) - t.count(s_uni[i])
	count = max(count, tmp)
print count

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)]

from collections import Counter

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

max = 0

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

print(max)

Submission status: Accepted

Solution code:
# coding: utf-8

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

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

dict_Blue = {}
for str_Blue in input_Blue:
  dict_Blue[str_Blue] = dict_Blue.get(str_Blue,0) + 1

dict_Red = {}
for str_Red in input_Red:
  dict_Red[str_Red] = dict_Red.get(str_Red,0) + 1

for Blue_Key in dict_Blue.keys():
    if Blue_Key in dict_Red.keys():
      dict_Blue[Blue_Key] = dict_Blue[Blue_Key] - dict_Red[Blue_Key]

if max(dict_Blue.values()) < 0 :
       print(0)
else:
       print(max(dict_Blue.values()))

Submission status: Accepted

Solution code:
import collections
N = int(input())
Red_list = []
Blue_list = []
max = 0
for i in range(N):
    s = str(input())
    Red_list.append(s)
M = int(input())
for j in range(M):
    t = str(input())
    Blue_list.append(t)
count_red = collections.Counter(Red_list)
count_blue = collections.Counter(Blue_list)
result = count_red - count_blue
lists = list(result.values())
for i in range(len(lists)):
    if max < lists[i]:
        max = lists[i]
print(max)

Submission status: Accepted

Solution code:
ans = {}
N = int(input())
for _ in range(N):
  S = input()
  if S in ans:
    ans[S] += 1
  else:
    ans[S] = 1
    
N = int(input())
for _ in range(N):
  S = input()
  if S in ans:
    ans[S] -= 1
  else:
    ans[S] = -1

maxans = 0
for key in ans.keys():
  maxans = max(maxans, ans[key])
print(maxans)

Submission status: Accepted

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

ln=s+t
ans=[]
for i in range(len(ln)):
    ctr=0
    test=ln[i]
    for k in range(n):
        if s[k]==test:
            ctr+=1
    for j in range(m):
        if t[j]==test:
            ctr-=1
    ans.append(ctr)

if max(ans)>=0:
    print(max(ans))  
else:
    print(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)]
#print(set(s),set(t))

ans=[0]+[s.count(i)-t.count(i) for i in set(s)]
print(max(ans))

Submission status: Accepted

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

counts = []
for si in S:
    count = 0
    for s in S:
        if s == si:
            count+=1
    for t in T:
        if t == si:
            count -=1
    counts.append(count)

max_count = max(counts)
if max_count < 0:
    print(0)
else:
    print(max_count)

Submission status: Accepted

Solution code:
n = int(input())

words = {"":0}
for i in range(n):
  s = input()
  if s not in words:
    words[s] = 1
  else:
    words[s] += 1
  
m = int(input())
for i in range(m):
  s = input()
  if s not in words:
    words[s] = -1
  else:
    words[s] -= 1

print(max(words.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())

st = list(set(s + t))
sl = list(map(lambda x : s.count(x), st))
tl = list(map(lambda x : t.count(x), st))

ans = []
for i in range(len(st)):
    ans.append(sl[i] - tl[i])
print(max(max(ans), 0))

Submission status: Accepted

Solution code:
a=[]
for i in range(int(input())):
  a+=[input()]
b=[]
for i in range(int(input())):
  b+=[input()]
ans=0
for i in range(len(a)):
  ans=max(ans,a.count(a[i])-b.count(a[i]))
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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()

money = [0] * n

for i in range(n):
    money[i] += 1
    for j in range(i+1,n):
        if s[i] == s[j]:
            money[i] += 1
    for j in range(m):
        if s[i] == t[j]:
            money[i] -= 1

money.sort()

print(max(0,money[-1]))