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:
s=[]
t=[]

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

word=set(s)

max_point = -101


for w in word:
    tmp=s.count(w)-t.count(w)
    if tmp >= max_point:
        max_point = tmp

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

Submission status: Accepted

Solution code:
N = int(input())
cards = {"a" * 10: 0}
for _ in range(N):
    s = input()
    cards[s] = cards.get(s, 0) + 1
M = int(input())
for _ in range(M):
    s = input()
    cards[s] = cards.get(s, 0) - 1
print(max(cards.values()))

Submission status: Accepted

Solution code:
from collections import Counter
#cotest_temp
n = int(input())
lst1 = [input() for i in range(n)]
m = int(input())
lst2 = [input() for i in range(m)]
#n,m = map(int,input().split())
#lst1 = list(map(int,input().split()))

l = Counter(lst1)
k = Counter(lst2)

ans = 0

for i in l:
    if i in lst2:
        ans = max(ans,l[i]-k[i])
    else:
        ans = max(ans,l[i])

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

card = {}

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

M = int(input())
for i in range(M):
    t = input()
    if t in card:
        card[t] -= 1
    else:
        card[t] = -1

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

Submission status: Accepted

Solution code:
from collections import defaultdict


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

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

ans = [num for num in count.values()] + [0]
print(max(ans))

Submission status: Accepted

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

set_r = list(set(r))

ans = 0
for i in set_r:
	ans = max(ans, r.count(i) - b.count(i))
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
S = Counter([input() for _ in range(int(input()))])
T = Counter([input() for _ in range(int(input()))])
print(max(0, max(v-(T[k] if k in T else 0) for k, v in S.items())))

Submission status: Accepted

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

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

uniq = set(plus+minus)

result = []
for i in uniq:
  result.append(plus.count(i)-minus.count(i))

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

Submission status: Accepted

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

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

ans = [s.count(si) - t.count(si) for si in set(s)]

print(max(0, max(ans)))

Submission status: Accepted

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

cards = set(blue) | set(red)
blue_map = {}
red_map = {}
for x in blue:
    if blue_map.get(x) is None:
        blue_map[x] = 1
    else:
        blue_map[x] += 1

for x in red:
    if red_map.get(x) is None:
        red_map[x] = 1
    else:
        red_map[x] += 1

result = max([blue_map.get(key, 0) - red_map.get(key, 0) for key in cards])
if result < 0:
    result = 0
print(result)

Submission status: Accepted

Solution code:
# blue card: N
N = int(input())
s = [''] * N
for i in range(N):
    s[i] = str(input())

# red card: M
M = int(input())
t = [''] * M
for i in range(M):
    t[i] = str(input())

# max(blueの要素xの重複数　- redの要素xの重複数), xがないときは0
scoreList1 = []
for i in range(N):
    win1 = 0
    lose1 = 0
    if s[i] in s:
        win1 += s.count(s[i])
    if s[i] in t:
        lose1 += t.count(s[i])
    if s.count(s[i]) < t.count(s[i]):
        win1 = 0
        lose1 = 0
    scoreList1.append(win1 - lose1)

scoreList2 = []
for j in range(M):
    win2 = 0
    lose2 = 0
    if t[j] in s:
        win2 += s.count(t[j])
    if t[j] in t:
        lose2 += t.count(t[j])
    if s.count(t[j]) < t.count(t[j]):
        win2 = 0
        lose2 = 0
    scoreList2.append(win2 - lose2)

scoreList = scoreList1 + scoreList2
print(max(scoreList))

Submission status: Accepted

Solution code:
N = int(input())

blue_dict = {}
red_dict = {}

for i in range(N):
  tmp = input()
  if tmp in blue_dict:
    blue_dict[tmp] += 1
  else:
    blue_dict[tmp] = 1
    
M = int(input())
for i in range(M):
  tmp = input()
  if tmp in red_dict:
    red_dict[tmp] += 1
  else:
    red_dict[tmp] = 1


blue_dict = sorted(blue_dict.items(), key = lambda x: x[1])
red_dict = sorted(red_dict.items(), key = lambda x: x[1])


def search_red(red_dict, word):
  for i in red_dict:
    if i[0] == word:
      return i[1]
  return 0

ans = 0
for i in blue_dict:
    ans = max(ans, i[1] - search_red(red_dict, i[0]))

print(ans)

Submission status: Accepted

Solution code:
x=[]

n=int(input())
d1={}
for i in range(n):
  s=input()
  x.append(s)
  if s in d1:
    d1[s]+=1
  else:
    d1[s]=1
    
m=int(input())
d2={}
for i in range(m):
  t=input()
  x.append(t)
  if t in d2:
    d2[t]+=1
  else:
    d2[t]=1

ans=0
for s in x:
  cnt=0
  if s in d1:
    cnt+=d1[s]
  if s in d2:
    cnt-=d2[s]
  if ans<cnt:
    ans=cnt

print(ans)

Submission status: Accepted

Solution code:
import sys
N = int(input())
A=[input() for i in range(N)]
M = int(input())
B=[input() for i in range(M)]
s = list(set(A) | set(B))
cnt = 0
for i in s:
  cnt = max(cnt,A.count(i)-B.count(i))
#  print(i,A.count(i),B.count(i),cnt)
print(max(0,cnt))

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
s_cards = [input() for _ in range(N)]
M = int(input())
t_cards = [input() for _ in range(M)]

d = defaultdict(int)
for s in s_cards:
    d[s] += 1

m = 0
for s in d:
    m = max(m, d[s] - t_cards.count(s))
print(m)

Submission status: Accepted

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

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

score = [s.count(x) - t.count(x) for x in s]
smax = max(score)
if (smax < 0):
   print(0)
else:
   print(smax)

Submission status: Accepted

Solution code:
N = int(input())

d = {}
 
for _ in range(N):
    s = input()
    if s in d:
        d[s] = d[s] + 1
    else:
        d[s] = 1

M = int(input())

for _ in range(M):
    t = input()
    if t in d:
        d[t] = d[t] - 1
    else:
        d[t] = 0

max = 0

for key in d:
    if d[key]>max:
        max = d[key]

print(max)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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, cur = 0, 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 = ["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)

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

# 青いカード(1円加算)
N = int(input())
s = list()
for i in range(N):
	s.append(str(input()))
# 赤いカード(1円損失)
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)

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

s.subtract(t)

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

Submission status: Accepted

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

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)

Submission status: Accepted

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

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

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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -coding: utf-8 -

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
#    print(n_s - n_t)
    dp = max(dp, n_s - n_t)
    
print(dp)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ベン図的にみると赤と青の両方にかかれているやつは考えなくていい（+1円-1円なので）
# と思ったけど複数枚に同じのが書かれている場合があるなこれ
# なので辞書でカウントしつつリストとってxnor
# と思ったけど問題文よく読んだら最悪でも0とれるので青を基準に考えればいいだけだった
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)

Submission status: Accepted

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

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

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

print(cnt)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

# print(points)

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

if ans < 0:
    ans = 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)]

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)

Submission status: Accepted

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

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)) 
L=set(S)
print(max(0,max(S.count(l)-T.count(l) for l in L)))

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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 Counter

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

ans = 0

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

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)

ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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)

ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:



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

Submission status: Accepted

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