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:

import collections


def main():


    N = int(input())
    sList = [input() for _ in range(N)]
    M = int(input())
    tLIst = [ input() for _ in range(M)]
    sDict = collections.Counter(sList)
    tDict = collections.Counter(tLIst)
    sDict.subtract(tDict)
    ansList = []
    for i in sDict:
        ansList.append(sDict[i])
    print(max(ansList)if max(ansList) > 0 else 0)






if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
sn = list(input() for i in range(n))
m = int(input())
mn = list(input() for i in range(m))
ss = []
for i in range(len(sn)):
  ss.append(sn.count(sn[i])-mn.count(sn[i]))
print (max(max(ss),0))

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_num = collections.Counter(s)
t_num = collections.Counter(t)

ans = 0
for key in s_num:
    if key in t_num:
        ans = max(ans, s_num[key] - t_num[key])
    else:
        ans = max(ans, s_num[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)]
l =[0]*n
for j in range(n):
  a = s.count(s[j])
  b = t.count(s[j])
  l[j] = a-b
print(max(max(l),0))

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = list(input() for hoge in range(n))
m = int(input())
t  = list(input() for hoge in range(m))
scount = Counter(s)
tcount = Counter(t)
maxyen = 0
for i in range(n):
         if (scount[s[i]] - tcount[s[i]]) > maxyen:
                  maxyen = (scount[s[i]] - tcount[s[i]])
print(maxyen)

Submission status: Accepted

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

ans_dic = sorted(dic.items(),key=lambda x:x[1],reverse = True)
print( max(ans_dic[0][1], 0))

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)
d2 = defaultdict(int)
for k in S:
    d[k] += 1
    d2[k] = 0

for k in d2:
    d2[k] = S.count(k) - T.count(k)

d2 = sorted(d2.items(), key=lambda x: x[1], reverse=True)

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

Submission status: Accepted

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

for i in s:
    cnt = s.count(i) - t.count(i)
    if yMax < cnt:
        yMax = cnt
print(yMax)

Submission status: Accepted

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

for i in s:
    cnt = s.count(i) - t.count(i)
    if yenMax < cnt:
        yenMax = cnt
print(yenMax)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s = [input() for n in range(int(input()))]
t = [input() for m in range(int(input()))]
l=list(set(s))
ans = max( s.count(l[i]) - t.count(l[i]) for i in range(len(l)) )
print(max(0, 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] + [v - t.count(k) for k, v in Counter(s).items()]))

Submission status: Accepted

Solution code:
from collections import Counter

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

s.subtract(t)

print(max(0, max(s.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)]

counter1 = collections.Counter(s)
counter2 = collections.Counter(t)
ans = max(counter1[k] - counter2[k] for k in counter1)
print(max(ans, 0))

Submission status: Accepted

Solution code:
import collections

n = int(input())
ss = collections.Counter([input().strip() for _ in range(n)])
m = int(input())
ts = collections.Counter([input().strip() for _ in range(m)])

res = 0
for key, val in ss.items():
    res = max(res, val - ts[key])
print(res)

Submission status: Accepted

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

from collections import Counter

blue = Counter(S)
red = Counter(T)

pnt = []

for b in blue:
    if b in red:
        pnt.append(blue[b] - red[b])
    else:
        pnt.append(blue[b])
        
print(max(pnt) if max(pnt) > 0 else 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)]
from collections import defaultdict
a = defaultdict(int)

for i in S:
    a[i] += 1
for i in T:
    a[i] -= 1
    
ans = 0
for i in a:
    if a[i] > ans:
        ans = a[i]
        
print(ans)

Submission status: Accepted

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

for i in range(len(s)):
    cnt.append(s.count(s[i]) - t.count(s[i]))
print(max(max(cnt),0))

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

cand_str_set = set(s_list)

calced_list = [(s_list.count(str_i) - t_list.count(str_i)) for str_i in cand_str_set]
calced_list.append(0)

print(max(calced_list))

Submission status: Accepted

Solution code:
import numpy as np

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 = np.array(s)
t = np.array(t)
s_uni = np.unique(s)

ans = 0
for i,ch_s in enumerate(s_uni):
  ans_tmp = (s==ch_s).sum()
  ans_tmp -= (t==ch_s).sum()
  if ans_tmp > ans:
    ans = ans_tmp
print(int(ans))

Submission status: Accepted

Solution code:
import collections
N = int(input())
s = [input() for i in range(N)]
s = collections.Counter(s)
s = list(s.items())
M = int(input())
t = [input() for i in range(M)]
ans = 0
for i in s:
  count = 0
  for j in t:
    if i[0] == j:
      count += 1
  if ans <= i[1] - count:
    ans = i[1] - count
print(ans)

Submission status: Accepted

Solution code:

import sys
from collections import deque, defaultdict
import copy
import bisect
#sys.setrecursionlimit(10 ** 9)
import math
import heapq
from itertools import combinations, permutations

import sys
def input():
	return sys.stdin.readline().strip()

N = int(input())
ans = 0
mozi = defaultdict(int)
for i in range(N):
	s = input()
	mozi[s] += 1
M = int(input())
for i in range(M):
	t = input()
	mozi[t] -= 1

for i in mozi:
	ans = max(ans, mozi[i])
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
dict = {}
for i in range(n):
  temp = input()
  if temp in dict:
    dict[temp] += 1
  else:
    dict.setdefault(temp, 1)
    
m = int(input())
for i in range(m):
  temp = input()
  if temp in dict:
    dict[temp] += -1
  else:
    dict.setdefault(temp, -1)
    
max_value = max(dict.values())
print(max(max_value, 0))

Submission status: Accepted

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

ans=0
for a in range(0,N):
  A=NList.count(NList[a])-MList.count(NList[a])
  if A >ans:
    ans = A
    
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)]
print(max(0, max(s.count(w)-t.count(w) for w in set(s))))

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
s = [input() for i in range(N)]
M = int(input())
t = [input() for i in range(M)]
sl = Counter(s)
tl = Counter(t)
ans = [0]

for i in range(len(sl)):
    if list(sl)[i] in tl:
        ans.append(sl[list(sl)[i]] - tl[list(sl)[i]])
    else:
        ans.append(sl[list(sl)[i]])

print(max(ans))

Submission status: Accepted

Solution code:
# ABC091b
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n = int(input())
s = dict()
for _ in range(n):
    i = input()[:-1]
    if (s.get(i) == None):
        s[i] = 1
    else:
        s[i] += 1
m = int(input())
for _ in range(m):
    i = input()[:-1]
    if (s.get(i) == None):
        s[i] = -1
    else:
        s[i] -= 1
print(max(max(s.values()), 0))

Submission status: Accepted

Solution code:
from collections import defaultdict

s = defaultdict(int)

N = int(input())
for _ in range(N):
	s[input()] += 1
M = int(input())
for _ in range(M):
	s[input()] -= 1

answer = max(s.values())
if answer < 0:
	answer = 0
print(answer)

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))
ans=0
for i in range(len(l)):
    ans=max(ans,s.count(l[i])-t.count(l[i]))
print(ans)

Submission status: Accepted

Solution code:
s = [input() for i in range(int(input()))]
t = [input() for i 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)))))

Submission status: Accepted

Solution code:
"""
N = int(input())
A, B = map(int,input().split())
lst = [list(map(int,input().split())) for i in range(M)]
A = list(map(int,input().split()))
"""

from collections import Counter

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

S_cnt = list(Counter(S).items())
#print(S_cnt)

lst = []
for i in range(len(S_cnt)):
  point = S_cnt[i][1]
  for j in range(len(T)):
    if T[j] == S_cnt[i][0]:
      point -= 1
  lst.append(point)
ans = max(0, max(lst))
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
t = [input() for i in range(n)] 
m=int(input())
q= [input() for i in range(m)] 
z=set(t)
base=[0]
for i in z:
  base.append(t.count(i)-q.count(i))
print(max(base))

Submission status: Accepted

Solution code:
n = int(input())
s = [list(map(str,input().split())) for i in range(n)]
m = int(input())
t = [list(map(str,input().split())) for i in range(m)]


c=0
for i in range(n):
    c=max(c,s.count(s[i])-t.count(s[i]))

print(c)

Submission status: Accepted

Solution code:
N = int(input())
Blue = []
for i in range(N):
  Blue.append(input())
M = int(input())
Red = []
for i in range(M):
  Red.append(input())
import collections
bc = collections.Counter(Blue)
rc = collections.Counter(Red)

BL = list(bc.keys())

m = 0

for bl in BL:
  m = max(bc.get(bl)-rc.get(bl,0),m)
  
print(m)

Submission status: Accepted

Solution code:
def main():
  n = int(input())
  plus = {}
  for i in range(n):
    p_key = input()
    if plus.get(p_key) is None:
      plus[p_key] = 1
    else:
      plus[p_key] += 1
  m = int(input())
  minus = {}
  for i in range(m):
    m_key = input()
    if plus.get(m_key) is None:
      plus[m_key] = -1
    else:
      plus[m_key] -= 1
  
  for k in plus.keys():
    if minus.get(k) is None:
      pass
    else:
      plus[k] += minus[k]
  
  res = 0
  for v in plus.values():
    res = max(res, v)    
  print(res)
  return 0

if __name__ == "__main__":
  main()

Submission status: Accepted

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

from collections import Counter

blue = Counter(S)
red = Counter(T)

point = []

for bkey in blue:
    if bkey in red:
        point.append(blue[bkey] - red[bkey])
    else:
        point.append(blue[bkey])
        
print(max(point) if max(point) > 0 else 0)

Submission status: Accepted

Solution code:
n = int(input())
blues = [input() for _ in range(n)]
m = int(input())
reds = [input() for _ in range(m)]
words = set(blues)
_max = 0
for w in words:
    score = 0
    score += blues.count(w)
    score -= reds.count(w)
    if _max < score:
        _max = score
print(_max)

Submission status: Accepted

Solution code:
from collections import defaultdict

count = defaultdict(lambda: 0)

n = int(input())
for _ in range(n):
    count[input()] += 1
    
m = int(input())
for _ in range(m):
    count[input()] -= 1

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    d = {}
    
    N = int(input())
    for si in range(N):
        si = input()
        if si in d.keys():
            d[si] += 1
        else:
            d[si] = 1
            
    M = int(input())
    for ti in range(M):
        ti = input()
        if ti in d.keys():
            d[ti] -= 1
        else:
            d[ti] = -1
    
    X = max(d.values())
    if X > 0:
        print(X)
    else:
        print(0)

Submission status: Accepted

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

m = int(input())
for i in range(m):
    s = input()
    if s in count:
        count[s] -= 1

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

Submission status: Accepted

Solution code:
s = [input() for i in range(int(input()))]
t = [input() for i in range(int(input()))]
import collections as cl
dic_s = cl.Counter(s)
dic_t = cl.Counter(t)
max_value = 0
for key in dic_s.keys():
  if key in dic_t:
    if dic_s[key] > dic_t[key]:
      max_value = max(dic_s[key] - dic_t[key], max_value)
  else:
    max_value = max(dic_s[key], max_value)
print(max_value)

Submission status: Accepted

Solution code:
N=int(input())
s=[]
t=[]
for i in range(N):
    a=str(input())
    s.append(a)
M=int(input())
for i in range(M):
    b=str(input())
    t.append(b)
u=0
for i in list(set(s)):
    u=max(u,s.count(i)-t.count(i))
print(u)

Submission status: Accepted

Solution code:
n = int(input())
d = {}
for i in range(n):
    s = input()
    try:
        d[s] += 1
    except:
        d[s] = 1
m = int(input())
for i in range(m):
    s = input()
    try:
        d[s] -= 1
    except:
        d[s] = -1
ans = 0
for v in d.values():
    ans = max(ans, v)
print(ans)

Submission status: Accepted

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

a = 0
for x in list(set(s)):
    a = max(a, s.count(x) - t.count(x))

print(a)

Submission status: Accepted

Solution code:
def count(list, item):
    c = 0
    for i in list:
        if i == item:
            c += 1
    return c

def remove_item(list, item):
    list = [i for i in list if i != item]
    return list

#入力
N = int(input())
s = []
for i in range(N):
    s.append(input())
M = int(input())
t = []
for j in range(M):
    t.append(input())
best = 0

while(len(s) != 0):
    #sの最初の要素の青、赤のカードに書かれている数の差を求める
    w = s[0]
    n_s = count(s,w)
    n_t = count(t,w)
    #もらえる金額の更新
    if n_s - n_t > best:
        best = n_s - n_t
    #s,tから今調べた要素を削除する
    s = remove_item(s,w)
    t = remove_item(t,w)

print(best)

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) - Counter(t)
if c:
    print(max(c.values()))
else:
    print(0)

Submission status: Accepted

Solution code:
# sys.stdin.readline
import collections
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N = int(input())
        s = [input() for _ in range(N)]
        M = int(input())
        t = [input() for _ in range(M)]
        s_c = collections.Counter(s)
        t_c = collections.Counter(t)

        ans = 0
        for k, s_v in s_c.items():
            t_v = t_c.get(k)
            if not t_v:
                ans = max(ans, s_v)
            else:
                ans = max(ans, max(0, s_v - t_v))
        print(ans)


# Run main
if __name__ == '__main__':
    AtCoder().main()

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())
ans=float('-inf')
for i in range (n):
    sa=s.count(s[i])-t.count(s[i])
    ans=max(ans,sa)
if ans<0:
    print(0)
else:
    print(ans)

Submission status: Accepted

Solution code:
n=int(input())
nl=[input() for i in range(n)]
m=int(input())
ml=[input() for i in range(m)]
nsl=list(set(nl))
mx=0
for x in range(len(nsl)):
	d=nl.count(nsl[x])-ml.count(nsl[x])
	if d>mx:mx=d
print(max(0,mx))

Submission status: Accepted

Solution code:
N_1=int(input())
a={}
for i in range(N_1):
    fruit=input()
    count=0
    if fruit in a:
        a[fruit] +=1
    else:
        a[fruit]=1
        
N_2=int(input())
b={}
for i in range(N_2):
    fruit=input()
    count=0
    if fruit in b:
        b[fruit] +=1
    else:
        b[fruit]=1
c=[]
d=[]
max_num=0
for j,fruit_1 in a.items():
    for k,fruit_2 in b.items():
        if j == k:
            total=fruit_1-fruit_2
            c.append(total)
    if not j in b:            
        d.append(fruit_1)

if len(c) == 0 :
    max_num=max(d)
    

if len(d) == 0:
    max_num=max(c)

if len(c) !=0 and len(d) !=0:
    if max(c) > max(d) :
        max_num=max(c)
    else:
        max_num=max(d)
    
if max_num <0:
    max_num=0

print(max_num)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
c = []
for i in range(n):
    c.append(input())
d = []
m = int(input())
for i in range(m):
    d.append(input())

scores = []
for i in c:
    score = 0
    for j in range(n):
        if i == c[j]:
            score += 1
    for j in range(m):
        if i == d[j]:
            score -= 1
    scores.append(score)
if max(scores) >= 0:
    print(max(scores))
else:
    print(0)

Submission status: Accepted

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

print(max(0,max(N.count(L[j])-M.count(L[j]) for j in range(len(L)))))

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)]
c1 = collections.Counter(S)
answer = 0
for word in c1:
    count = c1[word] - T.count(word)
    answer = max(answer, count)
print(answer)

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)]
c1 = collections.Counter(S)
c2 = collections.Counter(T)
answer = 0
for word in c1:
    if word in c2:
        count = c1[word] - c2[word]
    else:
        count = c1[word]
    answer = max(answer, count)
print(answer)

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 range(n):
    diff = s.count(s[i]) - t.count(s[i])
    ans = max(ans, diff)

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

    dic_s = {}
    for i in range(N):
        if s[i] in dic_s:
            dic_s[s[i]] += 1
        else:
            dic_s[s[i]] = 1
            
    dic_t = {}
    for i in range(M):
        if t[i] in dic_t:
            dic_t[t[i]] += 1
        else:
            dic_t[t[i]] = 1
    
    ans = 0
    for c in list(dic_s):
        if c not in dic_t:
            ans = max(ans, dic_s[c])
            # print(c)
        else:
            if dic_s[c] > dic_t[c]:
                ans  = max(ans, dic_s[c] - dic_t[c])
                # print(c)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = [input() for i in range(int(input()))]
m = [input() for i 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:
n = int(input())
blue = [input() for i in range(n)]
m =int(input())
red = [input() for i in range(m)]
blue_x = list(set(blue))
ans = 0
for b in blue_x:
  ans = max(ans,blue.count(b)-red.count(b))
print(ans)

Submission status: Accepted

Solution code:
a=int(input())
b=list(input() for _ in range(a))
c=int(input())
d=list(input() for _ in range(c))
x=[]
for i in set(b):
  x+=[b.count(i)-d.count(i)]
print(max(max(x),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 p in s:
    cnt1=s.count(p)
    cnt2=t.count(p)
    ans=max(ans,cnt1-cnt2)
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:
    cnt1=s.count(i)
    cnt2=t.count(i)
    ans=max(ans,cnt1-cnt2)
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter as c;n,*s=open(0);n=int(n);print(max([0]+[v for v in(c(s[:n])-c(s[n+1:])).values()]))

Submission status: Accepted

Solution code:
from collections import*;a,b=eval('Counter([input()for _ in[0]*int(input())]),'*2);print(max([0]+[v for v in(a-b).values()]))

Submission status: Accepted

Solution code:
from collections import Counter
a=[input() for _ in range(int(input()))]
b=[input() for _ in range(int(input()))]
c=Counter(a)-Counter(b)
print(max([0]+[v for v in c.values()]))

Submission status: Accepted

Solution code:
def read_dict():
  n = int(input())
  c = {}
  
  for _ in range(n):
    s = input()
    if s in c:
      c[s] += 1
    else:
      c[s] = 1
  return c

blue = read_dict()
red = read_dict()

res = 0
for text in blue:
  to_add = blue[text]
  to_subtract = 0 if text not in red else red[text]
  res = max(res, to_add - to_subtract)
  
print(res)

Submission status: Accepted

Solution code:
import sys
from statistics import *
from collections import *
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
ct = 0
dic = {}
for i in range(n):
    s = input()
    if s not in dic.keys():
        dic[s] = 1
    else:
        dic[s] += 1
m = ni()
for i in range(m):
    t = input()
    if t in dic.keys():
        dic[t] -= 1
print(max(0, *dic.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)]
point = 0
lst = list(set(s))

for i in range(len(lst)):
  tmp = s.count(lst[i]) - t.count(lst[i])
  if tmp > point:
    point = tmp

print(point)

Submission status: Accepted

Solution code:
D = {}
N = int(input())
for i in range(N):
  s = input()
  if not(s in D):
    D[s] = 0
  D[s] += 1
M = int(input())
for i in range(M):
  t = input()
  if not(t in D):
    D[t] = 0
  D[t] -= 1
r = max(0, max(D.values()))
print(r)

Submission status: Accepted

Solution code:
from collections import*;C=Counter
n=int(input());c=C(input()for _ in range(n))
m=int(input());c.subtract(C(input()for _ in range(m)))
print(max(max(c.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)]

point = 0
set = list(set(s))
for i in range(len(set)):
    tmp = s.count(set[i]) - t.count(set[i])
    if tmp > point:
        point = tmp
print(point)

Submission status: Accepted

Solution code:
n = int(input())
s_li = [input() for i in range(n)]
m = int(input())
t_li = [input() for i in range(m)]
tmp_map = {}
for s in s_li:
    if s not in tmp_map:
        tmp_map[s] = 1
    else:
        tmp_map[s] +=1
for m in t_li:
    if m not in tmp_map:
        tmp_map[m] = -1
    else:
        tmp_map[m] -=1
print(max(tmp_map.values()) if max(tmp_map.values())>0 else 0)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

n = int(input())
blues = []
for i in range(n):
    blues.append(input())

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

variation = list(set(blues + reds))

patterns = [0]

for v in variation:
    patterns.append(blues.count(v) - reds.count(v))

print(max(patterns))

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)]
score = 0

for i in range(n):
    score = max(score, a.count(a[i])-b.count(a[i]))

print(score)

Submission status: Accepted

Solution code:
"""#################################################################
【ABC091】
B - Two Colors Card Game
#################################################################"""

#インポート
import sys

#入力用
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))  #リスト(int型)
def MI(): return map(int, sys.stdin.readline().rstrip().split())        #多変数(int型)
def II(): return int(sys.stdin.readline().rstrip())                     # 1変数(int型)
def S(): return sys.stdin.readline().rstrip()                           #文字列(str型)

N = II()
s = [S() for _ in range(N)]
M = II()
t = [S() for _ in range(M)]
max = 0
for x in set(s):
    a = s.count(x)
    b = t.count(x)
    if max < a - b:
        max = a - b
print(max)

Submission status: Accepted

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

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

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


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

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

ans = 0
for i in set(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 Counter
n = int(input())
s = [input().rstrip() for _ in range(n)]
m = int(input())
t = [input().rstrip() for _ in range(m)]
sc = Counter(s)
tc = Counter(t)
for k in tc:
    sc[k] -= tc[k]

mc = sc.most_common(1)
if len(mc) and mc[0][1] > 0:
    print(mc[0][1])
else:
    print(0)

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))
ss = set(s)
ans = []

for i in ss:
    ans.append(s.count(i)-t.count(i))

print(max(0, max(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))
ss = set(s)
ans = []

for i in ss:
    ans.append(s.count(i)-t.count(i))

if max(ans) < 0:
    print(0)
else:
    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)]

sset = list(set(s)) # set型のままではインデックスを選べないので注意,この文はなくても良いがforループの短縮に繋がる
count = [s.count(sset[i]) - t.count(sset[i]) for i in range(len(sset))] # sにある要素で得点をリストに入れる(tのみにある文字列は答えになり得ない)
ans = max(0, max(count)) # countの最大値が負だったら0を返す

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

count = [s.count(s[i]) - t.count(s[i]) for i in range(N)] # sにある要素で得点をリストに入れる(tのみにある文字列は答えになり得ない)
ans = max(0, max(count)) # countが全て負だったら0を返す

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

S_set = list(set(S))
score = 0

for s in S_set:
  x = S.count(s)
  y = T.count(s)
  if x - y > score:
    score = x - y
print(score)

Submission status: Accepted

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

set_s = list(set(s))
print( max(0,max(s.count(set_s[i])-t.count(set_s[i]) for i in range(len(set_s)))) )

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 ws0 in s:
    point = 0
    for ws1 in s:
        if ws0 == ws1:
            point += 1
    for wt in t:
        if ws0 == wt:
            point -= 1
    ans = max(ans, point)
print(ans)