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:
nblues = int(input())
profits = dict()
for _ in range(nblues):
    word = input().rstrip("\n")
    profits[word] = profits.get(word, 0) + 1

nreds = int(input())
for _ in range(nreds):
    word = input().rstrip("\n")
    profits[word] = profits.get(word, 0) - 1

print(max(0, max(profits.items(), key=lambda t: t[1])[1]))

Submission status: Accepted

Solution code:
n = int(input())
blue = {}
for _ in range(n):
  s = input()
  if(s in blue):
    blue[s] += 1
  else:
    blue[s] = 1
m = int(input())
red = {}
for _ in range(m):
  t = input()
  if(t in red):
    red[t] += 1
  else:
    red[t] = 1
res = -100
for key, value in blue.items():
  tmp = 0
  if(key in red):
    tmp = blue[key] - red[key]
  else:
    tmp = blue[key]
  if(tmp > res):
    res = tmp
if(res >= 0):
  print(res)
else:
  print(0)

Submission status: Accepted

Solution code:
n = int(input())
can = []
for i in range(n):
  now = input()
  for j in range(len(can)):
    if now == can[j][0]:
      can[j][1] += 1
      break
  else:
    can.append([now,1])
m = int(input())
for i in range(m):
  now = input()
  for j in range(len(can)):
    if now == can[j][0]:
      can[j][1] -= 1
      break
maxi = 0
for j in range(len(can)):
  if can[j][1] > maxi:
    maxi = can[j][1]
print(maxi)

Submission status: Accepted

Solution code:
n = int(input())
s = [input()for _ in range(n)]
m = int(input())
t = [input()for _ in range(m)]
d = {}
for i in s:
    if i not in d:
        d[i] = 1
    else:
        d[i] += 1
for i in t:
    if i not in d:
        d[i] = -1
    else:
        d[i] -= 1
d = sorted(d.items(), key=lambda x: x[1], reverse=True)
print(max(d[0][1], 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)]
total = 0
for x in S:
    s = S.count(x)
    t = T.count(x)
    total = max(total,s-t)
print(total)

Submission status: Accepted

Solution code:
BlueN = int(input())
BlueList = []
for i in range(0,BlueN):
  BlueList.append(input())

RedN = int(input())
RedList = []
for i in range(0,RedN):
  RedList.append(input())

stocker = 0

for i in set(BlueList):
  if BlueList.count(i) * 1 + RedList.count(i) * -1 >= stocker:
    stocker = BlueList.count(i) * 1 + RedList.count(i) * -1

print(stocker)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict

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

d = defaultdict(int)
for x in s:
    d[x] += 1
for x in t:
    d[x] -= 1
print(max(0, max(d.values())))

Submission status: Accepted

Solution code:
from collections import Counter

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()
cnt_s = Counter(s)
cnt_t = Counter(t)
ans = [0]
cnt = 0
for i in range(len(cnt_s)):
    s_value = cnt_s.most_common()[i][0]
    s_count = cnt_s.most_common()[i][1]
    for j in range(len(cnt_t)):
        t_value = cnt_t.most_common()[j][0]
        t_count = cnt_t.most_common()[j][1]
        if s_value == t_value:
            ans.append(s_count-t_count)
            cnt = 1
            break
    if cnt == 0:
        ans.append(s_count)
    cnt = 0
print(max(ans))

Submission status: Accepted

Solution code:
n1 = int(input())
li1 = list(input() for i in range(n1))
n2 = int(input())
li2 = list(input() for i in range(n2))

prof = []
for i in range(n1):
    if li1[i] in li2:
        prof.append(li1.count(li1[i]) - li2.count(li1[i]))
    elif li1[i] not in li2:
        prof.append(li1.count(li1[i]))
#print(prof)
if max(prof)>0:
    print(max(prof))
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(N, M)
#print(s, t)

from collections import Counter
S = Counter(s)
#print(S)
T = Counter(t)
x = S-T
#print(x)
count = (x.most_common(1))
try:
  if (count[0][1]):
    print(count[0][1])
except IndexError:
  print('0')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
Ni=[]
Mi=[]
Payoff=0
for i in range(N):
    Ni.append(input())
for i in range(int(input())):
    Mi.append(input())
for i in set(Ni+Mi):
    Payoff=max(Payoff, Ni.count(i)-Mi.count(i))
print(Payoff)

Submission status: Accepted

Solution code:
from collections import defaultdict
d = defaultdict(int)
d['0'] = 0
n = int(input())
for i in range(n):
  d[input()] += 1 
m = int(input())
for i in range(m):
  d[input()] -= 1
print(max(d.values()))

Submission status: Accepted

Solution code:
n = int(input())
s = [str(input()) for i in range(n)]
m = int(input())
t = [str(input()) for j in range(m)]
words = list(set(s + t))
print(max([max(s.count(words[i]) - t.count(words[i]) for i in range(len(words))), 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)]

yen = {}

for i in range(len(s)):
    if s[i] in yen:
        yen[s[i]] += 1
    else:
        yen[s[i]] = 1

for name in yen.keys():
    for i in t:
        if i == name:
            yen[name] -= 1

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

Submission status: Accepted

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

import collections

s_count_dict = collections.Counter(s_list)
t_count_dict = collections.Counter(t_list)

max_count = 0
for s_word, s_count in s_count_dict.items():
    # 要素として存在しない値を指定すると0を返す。（エラーにはならない）
    diff_count = s_count - t_count_dict[s_word] 
    if diff_count > max_count:
        max_count = diff_count

print(max_count)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter


if __name__ == '__main__':
    n = int(input())
    s = [input() for _ in range(n)]
    m = int(input())
    t = [input() for _ in range(m)]
    s_set = set(s)
    print(max(0, max([s.count(i) - t.count(i) for i in s_set])))

Submission status: Accepted

Solution code:
n=int(input())
s=[input() for _ in range(n)]
m=int(input())
t=[input() for _ in range(m)]
cs=set(s)
a=0
for c in cs:
    if a<s.count(c)-t.count(c):
        a=s.count(c)-t.count(c)
print(a)

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())
#内包表記で辞書を作成
#list(set(s))で重複を取り除いたlistを取得
num_s = {key: 0 for key in list(set(s))}
for i in num_s.keys():
    num_s[i] = s.count(i)
for i in num_s.keys():
    num_s[i] -= t.count(i)
#valueの値が最大となるkeyを取得
ans = max(num_s.values())
if ans < 0:
    print(0)
else:
    print(ans)

Submission status: Accepted

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

ans = 0

for i in lis:
    ans = max(ans,lis.count(i)-lit.count(i))

print(ans)

Submission status: Accepted

Solution code:
a = int(input())
b = [input() for i in range(a)]
c = int(input())
d = [input() for j in range(c)]
g = [0]*a
t = 0
for k in b:
    e = b.count(k)
    f = d.count(k)
    g[t] = e - f
    t +=1
if max(g) < 0:
    print(0)
else:
    print(max(g))

Submission status: Accepted

Solution code:
n = int(input())
b=[input() for _ in [0]*n]
m = int(input())
r=[input() for _ in [0]*m]
ans = 0
for s in set(b):
  ans = max([ans,b.count(s)-r.count(s)])
print(ans)

Submission status: Accepted

Solution code:
nN = int(input())
 
sListA = []
nListA = [ 0 for i in range(202)]
 
for i in range(nN):
  sTmp = input()
  if sTmp in sListA:
    nTmp = sListA.index(sTmp)
    nListA[nTmp] += 1
  else:
    sListA.append(sTmp)
    nTmp = sListA.index(sTmp)
    nListA[nTmp] += 1
 
    
nN = int(input())
sListB = []
nListB = [ 0 for i in range(nN)]
 
for i in range(nN):
  sTmp = input()
  if sTmp in sListA:
    nTmp = sListA.index(sTmp)
    nListA[nTmp] -= 1
  else:
    sListA.append(sTmp)
    nTmp = sListA.index(sTmp)
    nListA[nTmp] -= 1
 
nMax = max(nListA)
# print(sListA)
print(nMax)

Submission status: Accepted

Solution code:
 #ABC 83, B - two anagrams

from collections import Counter
n = int(input())
S = Counter([input() for i in range(n)])

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

diff = S - T
if diff:
    print(diff.most_common()[0][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)]
st = s + t
d = {}
for i in range(n+m):
	d.setdefault(st[i],0)
for i in s:
	d[i] += 1
for i in t:
	d[i] -= 1

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

Submission status: Accepted

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

M = int(input())
for _ in range(M):
    t = input()
    if t in cards.keys():
        cards[t] -= 1
    else:
        continue
ans = max(max(cards.values()),0)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

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

res = 0
for u in ss:
    tmp = ss.count(u) - tt.count(u)
    res = max(res, tmp)
print(res)

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=[]

strset =set(s)
strlist = list(strset)

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

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

Submission status: Accepted

Solution code:
N = int(input())
s =[input() for i in range(N)]
M = int(input())
t =[input() for i in range(M)]
ansmx= -100
ans=0

strset =set(s)
strlist = list(strset)

for i in range(len(strlist)):
    str1=strlist[i]
    ans = s.count(str1)-t.count(str1)
    if ans>ansmx:
        ansmx = ans
if ansmx <0:
    print(0)
else:
    print(ansmx)

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)]
ansmx= -100
ans=0

strset =set(s+t)
strlist = list(strset)

for i in range(len(strlist)):
    str1=strlist[i]
    ans = s.count(str1)-t.count(str1)
    if ans>ansmx:
        ansmx = ans
if ansmx <0:
    print(0)
else:
    print(ansmx)

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

for s in S:
  z.append(S.count(s)-T.count(s))

print(max(z))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter


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_cnt = Counter(s)
t_cnt = Counter(t)
ans_dict = {}
for key in s_cnt.keys():
    ans_dict[key] = s_cnt[key] - t_cnt[key]
print(max(max(ans_dict.values()), 0))

Submission status: Accepted

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

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

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)]
s_set = list(set(s))
t_set = list(set(t))
check_list = []
for i in s_set:
    check_list.append(s.count(i) - t.count(i))
print(max(max(check_list), 0))

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

ans_list = []

for i in range(N):
    tmp = s.count(s[i]) - t.count(s[i])
    ans_list.append(tmp)

ans = max(0, max(ans_list))

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

for i in range(N):
    if s[i] in t:
        if s.count(s[i]) > t.count(s[i]):
            count = s.count(s[i]) - t.count(s[i])
            if count > ans:
                ans = count
    elif s[i] not in t:
        count = s.count(s[i])
        if count > ans:
            ans = count

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

c = Counter()
N = int(input())
for _ in range(N):
    s = input()
    c[s] += 1
M = int(input())
for _ in range(M):
    t = input()
    c[t] -= 1
print(max(0, c.most_common(1)[0][1]))

Submission status: Accepted

Solution code:
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
  return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
  read_all = [tuple(map(int, input().split())) for _ in range(N)]
  return map(list,zip(*read_all))

#################

N = I()
s = ['0']*N
for i in range(N):
  s[i] = str(input())
M = I()
t = ['0']*M
for i in range(M):
  t[i] = str(input())

from collections import Counter
sc = Counter(s)
tc = Counter(t)
ans = 0
for i in range(N):
  tmp = sc[s[i]] - tc[s[i]]
  if tmp > ans:
    ans = tmp
print(ans)

Submission status: Accepted

Solution code:
import math

n = int(input())
#a = int(input())
#d,x = list(map(int,input().split(" ")))
#ls = list(input().split(" "))
#ls = list(map(int,input().split(" ")))
#a,b,c = list(input().split())
#string = input()
#ls = [int(input()) for i in range(n)]
ls1 = [input() for i in range(n)]
m = int(input())
ls2 = [input() for i in range(m)]

ans = [0]

for i in ls1:
  ans.append(ls1.count(i) - ls2.count(i))
print(max(ans))

Submission status: Accepted

Solution code:
n=int(input())
a=[input() for _ in range(n)]
m=int(input())
b=[input() for _ in range(m)]
A=list(set(a))
ans=[0]
for i in range(len(A)):
    cnt=0
    cnt=a.count(A[i])-b.count(A[i])
    ans.append(cnt)
print(max(ans))

Submission status: Accepted

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

ans = 0
for i in a1:
    ans = max(ans, a1.count(i) - a2.count(i))
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())

str2count1 = {}
for s in S:
    if s not in str2count1:
        str2count1[s] = 0
    str2count1[s] += 1

str2count2 = {}
for t in T:
    if t not in str2count2:
        str2count2[t] = 0
    str2count2[t] += 1

max_diff = 0
for key, value in str2count1.items():
    diff = value - str2count2[key] if key in str2count2 else value
    if max_diff < diff:
        max_diff = diff
print(max_diff)

Submission status: Accepted

Solution code:
N = int(input())
sList = [['' for i in range(1)] for j in range(N)]

for i in range(N):
    sList[i] = input()

M = int(input())
tList = [['' for i in range(1)] for j in range(M)]
for i in range(M):
    tList[i] = input()

ansMax = 0
for i in sList:
    tmp = sList.count(i) - tList.count(i)
    ansMax = max(ansMax, tmp)

print(ansMax)

Submission status: Accepted

Solution code:
dic = {}

N = int(input())
for k in range(N):
  i = input()
  if i in dic:
    dic[i] += 1
  else:
    dic[i] = 1

M = int(input())
for j in range(M):
  i = input()
  if i in dic:
    dic[i] -= 1

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

Submission status: Accepted

Solution code:
dic = {}

N = int(input())
s = [input() for i in range(N)]
for i in range(N):
  dic.setdefault(s[i],0)
  dic[s[i]] += 1
  
M = int(input())
t = [input() for j in range(M)]
for j in range(M):
  dic.setdefault(t[j],0)
  dic[t[j]] -= 1

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

Submission status: Accepted

Solution code:
N = int(input())
words = []
for _ in range(N):
  words.append(('plus', input()))
M = int(input())
for _ in range(M):
  words.append(('minus', input()))
ans = 0
for i in range(N):
  point = 1
  for j in range(N+M):
    if words[i][1] == words[j][1] and i != j:
      if words[j][0] == 'plus':
        point += 1
      else:
        point -= 1
  ans = max(ans, point)
print(ans)

Submission status: Accepted

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

for _ in range(int(input())):
    i = input()
    if i in d:
        d[i] -= 1

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

Submission status: Accepted

Solution code:
n = int(input())
st = {}
for i in range(0,n):
    si = input()
    if si in st:
        st[si] += 1
    else:
        st[si] = 1
m = int(input())
for i in range(0,m):
    ti = input()
    if ti in st:
        st[ti] -= 1
    else:
        st[ti] = -1
stlist = list(st.items())
stlist.sort(key=lambda x:x[1])
stlist.reverse()
print(max(stlist[0][1],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
dic = {'0':0}
us = list(set(s))
for i in us:
    tmp = s.count(i) - t.count(i)
    dic['{}'.format(i)] = tmp
print(max(dic.values()))

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)]
cs = collections.Counter(s)
ct = collections.Counter(t)
ans = 0
for k in cs.keys():
#  print(k, cs[k], ct[k])
  c = cs[k] - ct[k]
  if c > ans:
    ans = c
print(max(ans, 0))

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    a, b, c = LI()
    if a + b >= c:
        print("Yes")
    else:
        print("No")
    return

#B
def B():
    n = II()
    s = SR(n)
    m = II()
    t = SR(m)
    ans = 0
    for si in s:
        ans = max(ans, s.count(si) - t.count(si))
    print(ans)
    return

#C
def C():
    n = II()
    ab = LIR(n)
    cd = LIR(n)
    ab.sort()
    cd.sort()
    check = [0 for i in range(n)]
    ans = 0
    for _, c in enumerate(cd):
        d = c[1]
        c = c[0]
        maxy = -1
        x = -1
        for k, a in enumerate(ab):
            b = a[1]
            a = a[0]
            if maxy < b and c > a and check[k] == 0 and d > b:
                maxy = b
                x = k
        if x != -1:
            ans += 1
            check[x] += 1
    print(ans)


    return

#D
def D():
    N = II()
    a = LI()
    b = LI()
    ans = 0
    for i in range(29):
        t = 2 ** i
        a2 = [A % (2 * t) for A in a]
        b2 = [B % (2 * t) for B in b]
        a2.sort()
        b2.sort()
        ansb = 0
        r1 = r2 = r3 = 0
        for A in reversed(a2):
            while r1 < N and A + b2[r1] < t:
                r1 += 1
            while r2 < N and A + b2[r2] < 2*t:
                r2 += 1
            while r3 < N and A + b2[r3] < 3*t:
                r3 += 1
            ansb += (r2 - r1) + (N - r3)
        ans += ((ansb %2 ) << i)
    print(ans)
    return

#Solve
if __name__ == '__main__':
    B()

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)]
d={}
for w in l1:
    if w in list(d.keys()):
        d[w]+=1
    else:
        d[w]=1
for w in l2:
    if w in list(d.keys()):
        d[w]-=1
print(max(0,max(list(d.values()))))

Submission status: Accepted

Solution code:
a = int(input())
b = {}
for i in range(a):
    c = input()
    if c in b:
        b[c] += 1
    else:
        b.setdefault(c, 1)
a = int(input())
for i in range(a):
    c = input()
    if c in b:
        b[c] -= 1
    else:
        b.setdefault(c, 1)
b = sorted(b.values(), reverse=True)
print(max(b[0], 0))

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
ds = defaultdict(int)
for i in range(n):
    s = input()
    ds[s] += 1


m = int(input())
for i in range(m):
    t = input()
    ds[t] -= 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def main():
    N = int(input())
    S = {}
    
    for i in range(N):
        tmp = input()
        if tmp in S:
            S[tmp] += 1
        else:
            S[tmp] = 1
            
    M = int(input())
    for i in range(M):
        tmp = input()
        if tmp in S:
            S[tmp] -= 1
        else:
            S[tmp] = -1
            
    ans = 0
    for v in S.values():
        if ans < v:
            ans = v
    
    print(ans)
    
	
if __name__ == "__main__":
	main()

Submission status: Accepted

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

for i in range(n):
    tmp = input()
    dic[tmp] += 1

m = int(input())
ans = 0
for i in range(m):
    tmp = input()
    dic[tmp] -= 1
print(max(max(dic.values()),0))

Submission status: Accepted

Solution code:
from collections import defaultdict
d = defaultdict(lambda : 0)
for i in range(int(input())): d[input()]+=1
for j in range(int(input())): d[input()]-=1
ans = max(d.values())
print(ans if ans>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)]
li=[]
for word in S:
  s=S.count(word)
  t=T.count(word)
  li.append(s-t)
if max(li) < 0:print(0)
else:print(max(li))

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):
  tmp = s.count(i)-t.count(i)
  if ans < tmp:
    ans = tmp 
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)]
ss = set(s)
sl = Counter(s)
tl = Counter(t)
goukei=[]
for i in ss:
  goukei.append(sl[i]-tl[i])
  
if max(goukei) > 0:
  print(max(goukei))
else:
  print(0)

Submission status: Accepted

Solution code:
a=int(input())
b=[str(input()) for i in range(a)]
c=int(input())
d=[str(input()) for i in range(c)]

bset=list(set(b))
e=[]
for i in bset:
  e.append(b.count(i)-d.count(i))

f=max(e)
print(max(0,f))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys

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

N = int(input())
s = [input() for _ in range(N)]
M = int(input())
t = [input() for _ in range(M)]
a = set(s)
s_num = 0
t_num = 0
max_num = 0

for i in a:
    s_num = s.count(i)
    t_num = t.count(i)
    if max_num < s_num - t_num:
        max_num = s_num - t_num
print(max_num)

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:
# coding: utf-8
# Your code here!

from collections import defaultdict

n = int(input())
x = [str(input()) for _ in range(n)]
m = int(input())
y = [str(input()) for _ in range(m)]

dx = defaultdict(int)
dy = defaultdict(int)

for temp_x in x:
    dx[temp_x] += 1
for temp_y in y:
    dy[temp_y] += 1
    
max_count = 0
for k in dx.keys():
    max_count = max(max_count, dx[k] - dy[k])
    
print(max_count)

Submission status: Accepted

Solution code:
a = int(input())
b = {}
for i in range(a):
    c = input()
    if c not in b:
        b.setdefault(c, 1)
    else:
        b[c] = b.get(c) + 1
d = int(input())
for i in range(d):
    c = input()
    if c not in b:
        b.setdefault(c, 1)
    else:
        b[c] = b.get(c) - 1
b = sorted(b.values(), reverse=True)
print(max(b[0], 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 w in s:
    ans = max(ans, s.count(w) -  t.count(w))

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
s1 = list(set(s))
for i in s1:
    x = s.count(i) - t.count(i)
    if ans < x:
        ans = x
print(ans)

Submission status: Accepted

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

count_max = 0
for s in set(s_list):
    count = s_list.count(s) - t_list.count(s)
    if count > count_max:
        count_max = count
for t in set(t_list):
    count = s_list.count(t) - t_list.count(t)
    if count > count_max:
        count_max = count

print(count_max)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
ns = [input() for i in range(n)]
m = int(input())
ms = [input() for i in range(m)]
cn = dict(Counter(ns).most_common())
cm = dict(Counter(ms).most_common())
for i in cn.keys():
    cn[i] -= cm[i] if i in cm else 0
print(max(sorted(cn.values(), reverse=True)[0], 0))

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

mny_l=[]

for i in range(n):
    mny=0
    for j in range(n):
        if s[i]==s[j]:
            mny+=1
    for j in range(m):
        if s[i]==t[j]:
            mny-=1
    mny_l.append(mny)
ans=max(0,max(mny_l))
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

dic = {}

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

print(max(max(dic.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)]
count = 0
for s in S:
    count = max(count, S.count(s) - T.count(s))
print(count)

Submission status: Accepted

Solution code:
cardcost = {}
N = int(input())
for i in range(N):
    s = input()
    scost = cardcost.get(s, 0)
    cardcost[s] = scost+1

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


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

Submission status: Accepted

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

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:
#!/usr/bin/env python3


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [tuple(map(typ, input().split())) if m > 1 else typ(input()) for _ in range(n)]


def main():
    N, = read_h()
    s = read_v(N, typ=str)
    M, = read_h()
    t = read_v(M, typ=str)

    cnt = {}
    for si in s:
        cnt[si] = cnt.get(si, 0) + 1
    for ti in t:
        cnt[ti] = cnt.get(ti, 0) - 1

    ans = max(0, *cnt.values())
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
dict = {'A':0}
for i in range(n):
    str = input()
    dict[str] = dict.get(str,0) + 1
m = int(input())
for i in range(m):
    str = input()
    dict[str] = dict.get(str,0) - 1
print(max(dict.values()))

Submission status: Accepted

Solution code:
n = int(input())
dict = {'a':0}
for i in range(n):
    str = input()
    dict[str] = dict.get(str,0) + 1
m = int(input())
for i in range(m):
    str = input()
    dict[str] = dict.get(str,0) - 1
print(max(dict.values()))