Problem:


Score : 200 points

Problem Statement

Takahashi has N blue cards and M red cards.
A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i.

Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen.

Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces atcoder, he will not earn money even if there are blue cards with atcoderr, atcode, btcoder, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.)

At most how much can he earn on balance?

Note that the same string may be written on multiple cards.

Constraints

N and M are integers.

1 \leq N, M \leq 100

s_1, s_2, ..., s_N, t_1, t_2, ..., t_M are all strings of lengths between 1 and 10 (inclusive) consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
s_1
s_2
:
s_N
M
t_1
t_2
:
t_M

Output

If Takahashi can earn at most X yen on balance, print X.

Sample Input 1

3
apple
orange
apple
1
grape

Sample Output 1

2

He can earn 2 yen by announcing apple.

Sample Input 2

3
apple
orange
apple
5
apple
apple
apple
apple
apple

Sample Output 2

1

If he announces apple, he will lose 3 yen. If he announces orange, he can earn 1 yen.

Sample Input 3

1
voldemort
10
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort

Sample Output 3

0

If he announces voldemort, he will lose 9 yen. If he announces orange, for example, he can avoid losing a yen.

Sample Input 4

6
red
red
blue
yellow
yellow
red
5
red
red
yellow
green
blue

Sample Output 4

1



Sample input:
3
apple
orange
apple
1
grape


Sample output:
2

Submission status: Accepted

Solution code:
N = int(input())

words = []

blue_cards = {}
for i in range(N):
  s = input()
  if s in blue_cards:
    blue_cards[s] = blue_cards[s] + 1
  else:
    blue_cards[s] = 1
  if s not in words:
    words.append(s)

M = int(input())

red_cards= {}
for i in range(M):
  s = input()
  if s in red_cards:
    red_cards[s] = red_cards[s] + 1
  else:
    red_cards[s] = 1
  if s not in words:
    words.append(s)

max_money = 0
for word in words:
  get_money, lose_money = 0, 0
  if word in blue_cards:
    get_money = blue_cards[word]
  if word in red_cards:
    lose_money = red_cards[word]
  max_money = max(max_money, get_money - lose_money)

print(max_money)

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]
num = {i:s.count(i) for i in set(s)}
out = [v-max(0,t.count(k)) for k, v in num.items()]
print(max(max(out),0))

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
ss = [input() for _ in range(n)]
m = int(input())
ts = [input() for _ in range(m)]

c0 = Counter(ss) - Counter(ts)
if c0:
    word, count = c0.most_common(1)[0]
    print(count)
else:
    print(0)

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)]
print(max([0] + [blue.count(s) - red.count(s) for s in set(blue)]))

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

a = list(set(s))

ans = 0
for i in range(len(a)):
    count = 0
    for j in range(n):
        if s[j] == a[i]:
            count += 1
    for j in range(m):
        if t[j] == a[i]:
            count -= 1
    if count > ans:
        ans = count
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

S = defaultdict(int)

N=int(input())
for i in range(N):S[input()] += 1
N=int(input())
for i in range(N):S[input()] -= 1
    
ans = max(S.values())
if ans<0:ans=0
print(ans)

Submission status: Accepted

Solution code:
def makeDictionary(in_item, out_item):
    for item in in_item:
        if item in out_item.keys():
            out_item[item] += 1
        else:
            out_item[item] = 1

sResult = {}
tResult = {}

N = int(input())
s = makeDictionary([input() for i in range(N)], sResult)
M = int(input())
t = makeDictionary([input() for i in range(M)], tResult)

for item in tResult.keys():
    if item in sResult:
        sResult[item] -= tResult[item]

result = max(sResult.values())

if result < 0:
    print(0)
else:
    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)]
pay=0
for si in s:
    aa=list(filter(lambda x: x==si, s))
    dd=list(filter(lambda x: x==si, t))
    tmp=len(aa)-len(dd)
    pay = tmp if pay<tmp else pay
print(pay)

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

s1 = list(set(s))
a = [0 for i in range(101)]
for i in range (len(s1)):
    for j in range (N):
        if s1[i] == s[j]:
            a[i]+=1
for i in range (len(s1)):
    for j in range (M):
        if s1[i] == t[j]:
            a[i]-=1
print(max(a))

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

print(ans)

Submission status: Accepted

Solution code:
dic1 = {}
dic2 = {}
n = int(input())
for i in range(n):
    line = input()
    if line not in dic1:
        dic1[line] = 1
    else:
        dic1[line] += 1
m = int(input())
for i in range(m):
    line = input()
    if line not in dic2:
        dic2[line] = 1
    else:
        dic2[line] += 1
key1 = list(dic1.keys())
ls = [0]*len(dic1)
for i in range(len(dic1)):
    if key1[i] in dic2:
        ls[i] = dic1[key1[i]]-dic2[key1[i]]
    else:
        ls[i] = dic1[key1[i]]
print(max(ls) if max(ls)>0 else 0)

Submission status: Accepted

Solution code:
from collections import Counter
c = Counter([input() for i in range(int(input()))])
c -= Counter([input() for i in range(int(input()))])
print(c.most_common()[0][1] if c else 0)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
blue_list = [input() for _ in range(N)]
blue = Counter(blue_list)

M = int(input())
red_list = [input() for _ in range(M)]
red = Counter(red_list)

blue.subtract(red)
c = blue.most_common(1)[0][1]
if c < 0:
    print(0)
else:
    print(c)

Submission status: Accepted

Solution code:
N = int(input())
s = [input() for _ in range(N)]
M = int(input())
t = [input() for _ in range(M)]
cnt = 0
for i in s:
    if cnt < s.count(i)-t.count(i):
        cnt = s.count(i)-t.count(i)
print(cnt)

Submission status: Accepted

Solution code:
import collections

bluecard = []
redcard = []

n = int(input())
for i in range(n):
    bluecard.append(input())

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

blue_count = collections.Counter(bluecard)
red_count = collections.Counter(redcard)
diff = blue_count - red_count
if len(diff.keys()) > 0:
    print(diff.most_common(1)[0][1])
else:
    print(0)

Submission status: Accepted

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

b = int(input())
t = {}
for i in range(b):
    tmp = input()
    if tmp in t:
        t[tmp] += 1
    else:
        t[tmp] = 1

ans = 0
for key, value in s.items():
    ans = max(value - t.get(key, 0), ans)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
word_list = {}

for i in range(n):
    s = input()
    if s not in word_list :
        word_list[s] = 1
    else:
        word_list[s] += 1

m = int(input())

for j in range(m):
    s = input()
    if s not in word_list:
        word_list[s] = -1
    else:
        word_list[s] -= 1
if max(word_list.values()) < 0:
    print(0)
else:
    print(max(word_list.values()))

Submission status: Accepted

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

M = int(input())
t = []
for i in range(M):
    t.append(input())
    
cnt = {}

for S in s:
    if S not in cnt.keys():
        cnt[S] = 1
    else:
        cnt[S] += 1

for T in t:
    if T not in cnt.keys():
        cnt[T] = -1
    else:
        cnt[T] -= 1
        
if max(cnt.values()) < 0:
    print(0)
else:
    print(max(cnt.values()))

Submission status: Accepted

Solution code:
from collections import Counter

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

for _ in range(int(input())):
    t = input()
    if t in s:
        s.remove(t)

if len(s) == 0:
    print(0)
else:
    c = Counter(s)
    print(c.most_common(1)[0][1])

Submission status: Accepted

Solution code:
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()
cost = [1 for i in range(N)]
for i in range(N):
    for j in s[i+1:]:
        if s[i] == j :
            cost[i] += 1
    for j in t:
        if s[i] == j:
            cost[i] -= 1

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

Submission status: Accepted

Solution code:
N = int(input())
sl = [input() for i in range(N)]
M = int(input())
tl = [input() for i in range(M)]
ans = 0
for s in sl:
    tmp = sl.count(s)
    if s in tl:
        tmp -= tl.count(s)
    ans = max(ans, tmp)
print(ans)

Submission status: Accepted

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

c = 0
for i in a:
    d = a.count(i)-b.count(i)
    c = max(c,d)
print(c)

Submission status: Accepted

Solution code:
N = int(input())

word = {}

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

M = int(input())

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

money = max(word.values())

if money >= 0:
    print(money)
else:
    print(0)

Submission status: Accepted

Solution code:
N = input()
n = []
for i in range(N):
    n.append(raw_input())
M = input()
m = []
for i in range(M):
    m.append(raw_input())

result = [n.count(a) - m.count(a) for a in n]
max_ = max(result)
if max_ < 0:
    print(0)
else:
    print(max_)

Submission status: Accepted

Solution code:
n=int(input())
s=[]
for i in range(n):
    s.append([str(input()),1])
m=int(input())
for i in range(m):
    s.append([str(input()),-1])
s.sort()
x=s[0][0]
max_s=0
a=0
for i in range(n+m):
    if x==s[i][0]:
        a+=s[i][1]
    else:
        x=s[i][0]
        max_s=max(max_s,a)
        a=s[i][1]
print(max(a,max_s))

Submission status: Accepted

Solution code:
N=int(input())
wordcount={}
for i in range(N):
  s=str(input())
  wordcount[s]=wordcount.get(s,0)+1
M=int(input())
for i in range(M):
  s=str(input())
  wordcount[s]=wordcount.get(s,0)-1
counter=wordcount.values()
f=max(counter)
if f>=0:
  print(f)
else:
  print(0)

Submission status: Accepted

Solution code:
N=int(input())
D = {}
for _ in range(N):
  s = input().strip()
  if s not in D:
  	D[s] = 0
  D[s] += 1

M=int(input())
for _ in range(M):
  s = input().strip()
  if s not in D:
  	D[s] = 0
  D[s] -= 1
print(max(list(D.values()) + [0]))

Submission status: Accepted

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

max_count = -9999
for i in range(len(s)):

    #print(s[i],s.count(s[i]),t.count(s[i]))

    if (s.count(s[i]) - t.count(s[i])) > max_count:
        max_count = s.count(s[i]) - t.count(s[i])

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

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
blue_ls = [input() for _ in range(n)]
m = int(input())
red_ls = [input() for _ in range(m)]

blue_counter = Counter(blue_ls)
red_counter = Counter(red_ls)
diff_counter = blue_counter - red_counter

if diff_counter:
    print(diff_counter.most_common(1)[0][1])
else:
    print("0")

Submission status: Accepted

Solution code:
n = int(input())
d = {}
for i in range(n):
      s = input()
      if not s in d.keys():
            d.setdefault(s,0)
      d[s]+=1
m = int(input())
for i in range(m):
      s = input()
      if s in d.keys():
            d[s] -= 1
ans = 0
for i in d.keys():
      ans = max(ans, d[i])
print(ans)

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

dic = defaultdict(int)

for st in s:
    dic[st] = dic[st]+1
for st in t:
    dic[st] = dic[st]-1

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

s.sort()
word = ""
max = 0
for i in range(n):
  if s[i] == word:
    continue
    
  word = s[i]
  points = s.count(word) - t.count(word)
  if points > max:
    max = points

print(max)

Submission status: Accepted

Solution code:
n = int(input())
blue = {}
for i in range(n):
    w = input()
    blue[w] = blue.get(w, 0) + 1

m = int(input())
red = {}
for i in range(m):
    w = input()
    red[w] = red.get(w, 0) + 1

pt_lst = []
for i in blue:
    pt = blue[i] - red.get(i, 0)
    pt_lst.append(pt)

pt = max(pt_lst)
if pt < 0:
    pt = 0

print(pt)

Submission status: Accepted

Solution code:
N = int(input())

blue_list=list()
for i in range (N):
    N_ = str(input())
    blue_list.append(N_)

M = int(input())
red_list=list()
for i in range (M):
    M_ = str(input())
    red_list.append(M_) 

output_final=0
for i in range (0,N):
    objective=blue_list[i]
    plus=blue_list.count(objective)
    minus=red_list.count(objective)
    output=plus-minus
    if output>=output_final:
        output_final=output
print (output_final)

Submission status: Accepted

Solution code:
from collections import Counter
s,t = [],[]

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

M = int(input())
for i in range(M):
    t.append(input())

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

print(max(sd.most_common(1)[0][1],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())

words = list(set(s))
max = 0
for word in words:
    count = s.count(word) - t.count(word)
    if count > max:
        max = count

print(max)

Submission status: Accepted

Solution code:
N = int(input())
S = []
for i in range(N):
    S.append(input())
M = int(input())
T = []
for j in range(M):
    T.append(input())

maxmoney = 0
maxword = "aaaaa"
for i in range(N):
    money = 0
    for j in range(N):
        if S[i]==S[j]:
            money = money + 1
    for j in range(M):
        if S[i] == T[j]:
            money = money - 1
    if money > maxmoney:
        maxmoney = money
        maxword = S[i]
print(maxmoney)

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())
    
#print(s)
#print(t)
    
s_set = set(s)
money = 0
for word in s_set:
    cur = s.count(word)-t.count(word)
    if cur > money:
        money = cur
if money < 0:
    money = 0
print(money)

Submission status: Accepted

Solution code:
n = int(input())
blue = [input() for i in range(n)]
m = int(input())
red = [input() for i in range(m)]
x = 0
for w in set(blue):
    tmp = blue.count(w) - red.count(w)
    if tmp > x:
        x = tmp
print(x)

Submission status: Accepted

Solution code:
N=int(input())
list_s=[str(input()) for s in range(N)]
M=int(input())
list_t=[str(input()) for t in range(M)]
X=0
C=0
for i in range(N):
  A=list_s.count(list_s[i])
  B=list_t.count(list_s[i])
  if (A-B)>X:
    X=A-B
for i in range(M):
  A=list_s.count(list_t[i])
  B=list_t.count(list_t[i])
  if (A-B)>X:
    X=A-B

print(X)

Submission status: Accepted

Solution code:
import math
import sys
from collections import Counter
def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

n = int(arr_data[0][0])
m = int(arr_data[n+1][0])


#print(n,m)

arr_blue=[]
arr_red=[]
for v in range(1,1+n):
    
    arr_blue.append(arr_data[v][0])
    
for v in range(n+1+1,n+1+1+m):
    
    arr_red.append(arr_data[v][0])


list01=Counter(arr_blue)
list02=Counter(arr_red)

#print(arr_blue)    
#print(arr_red)    

maxdata=0
    
for k in list01:
    
#    print(k,list01[k],list02[k])    
    
    if maxdata<list01[k]-list02[k]:
        
        maxdata=list01[k]-list02[k]
        
print(maxdata)

Submission status: Accepted

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

for word in set(blue):
    ans_n = blue.count(word) - red.count(word)
    if ans_n > ans:
        ans = ans_n
print(ans)

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)]
blue_dic = defaultdict(int)
red_dic = defaultdict(int)
res = 0
for i in range(n):
    blue_dic[s[i]] += 1
for i in range(m):
    red_dic[t[i]] += 1
for i in range(n):
    res = max(res, blue_dic[s[i]] - red_dic[s[i]])
print(res)

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

str_list = set(s + t)

X = 0

for i in str_list:
  tmp = 0
  for j in s:
    if i == j:
      tmp += 1
  for j in t:
    if i == j:
      tmp -= 1
  if tmp > X:
    X = tmp

print(X)

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)]
 
k = [0]
 
for x in a:
  temp = a.count(x)-b.count(x)
  k.append(temp)
for y in b:
  temp = a.count(y)-b.count(y)
  k.append(temp)
print(max(k))

Submission status: Accepted

Solution code:
def main():
    m = int(input())
    count = {}
    for i in range(m):
        s = input()
        count.setdefault(s, 0)
        count[s] += 1

    n = int(input())
    for i in range(n):
        s = input()
        count.setdefault(s, 0)
        count[s] -= 1

    mx = max(count.values())
    print(mx if mx > 0 else 0)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#■標準入力ショートカット

from collections import defaultdict


def get_next_int():
    return int(float(input()))


def get_next_ints(delim=" "):
    return tuple([int(float(x)) for x in input().split(delim)])


def get_next_str():
    return input()


def get_next_strs(delim=" "):
    return tuple(input().split(delim))


def get_next_by_types(*value_types, delim=" "):
    return tuple([t(x) for t, x in zip(value_types, input().split(delim))])


def solve():
    N = get_next_int()
    ans = defaultdict(int)
    for i in range(N):
        key = input()
        ans[key] += 1
    M = get_next_int()
    for i in range(M):
        key = input()
        ans[key] -= 1
    max_val = max(ans.values())
    value = 0 if max_val < 0 else max_val
    print(value)


solve()

Submission status: Accepted

Solution code:
ans = 0

n = int(raw_input())
blue = []
for i in range(0, n):
	blue.append(raw_input())

m = int(raw_input())
red = []
for i in range(0, m):
	red.append(raw_input())

while blue != []:
	countblue = 0
	countred = 0
	blueword = blue[0]
	while blueword in blue:
		countblue = countblue + 1
		blue.remove(blueword)
	while blueword in red:
		countred = countred + 1
		red.remove(blueword)
	if countblue - countred > ans:
		ans = countblue - countred

print ans

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n = input()
    s = {}
    for i in range(n):
        a = raw_input()
        if a not in s.keys():
            s[a] = 1
        else:
            s[a] += 1
    m = input()
    t = {}
    for i in range(m):
        a = raw_input()
        if a not in t.keys():
            t[a] = 1
        else:
            t[a] += 1
    m = 0
    for a in s.keys():
        if a in t.keys():
            m = max(m, s[a] - t[a])
        else:
            m = max(m, s[a])
    print m

Submission status: Accepted

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

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

for i in range(n):
    for j in range(m):
        if s[i]==t[j]:
            s[i] = ""
            t[j] = ""
#print(s)
#print(t)
max_score = 0
for i in range(n):
    if s[i]!="" and s.count(s[i])>=max_score:
        max_score = s.count(s[i])
print(max_score)

Submission status: Accepted

Solution code:
import collections

def solve(N, blues, M, reds):
    blue_count = collections.Counter(blues)
    red_count  = collections.Counter(reds)

    if len(blue_count - red_count) == 0:
        return 0

    return (blue_count - red_count).most_common()[0][1]

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

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

print(solve(N, blues, M, reds))

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
plus = Counter([input() for _ in range(N)])
M = int(input())
minus = Counter([input() for _ in range(M)])

ans = 0
for k, v in dict(plus).items():
    if minus[k]:
        ans = max(ans, v - minus[k])
    else:
        ans = max(ans, v)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
s=[]
for i in range(N):
    s+=[input()]
M=int(input())
t=[]
for j in range(M):
    t+=[input()]
u=[]
for k in range(N):
    u.append(s.count(s[k])-t.count(s[k]))
if max(u)<0:
    print("0")
else:
    print(max(u))

Submission status: Accepted

Solution code:
# ABC 092 C
N = int(input())
s = [str(input()) for i in range(N)]
M = int(input())
t = [str(input()) for i in range(M)]
ans = 0

for i in range(N):
    ans = max(s.count(s[i])-t.count(s[i]), ans)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
s = {}
t_get = 0
for i in range(N):
    tmp = input()
    if (tmp in s.keys()) == False:
        s[tmp] = 1
    else:
        s[tmp] += 1

M = int(input())
for i in range(M):
    tmp = input()
    if(tmp in s.keys()) == False:
        s[tmp] = -1
    else:
        s[tmp] -= 1

for value in s.values():
    if value > t_get:
        t_get = value
print(t_get)

Submission status: Accepted

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

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

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

result = 0
trash = []
for w in s:
    if w not in trash:
        tmp = s.count(w) - t.count(w)
        if tmp > result:
            result = tmp
        trash.append(w)

print(result)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
blue = int(input())
bluelist = []
redlist = []
for i in range(blue):
    bluelist.append(input())
red = int(input())
for i in range(red):
    redlist.append(input())
maxyen = 0
for x in bluelist:
    yen = bluelist.count(x) - redlist.count(x)
    if yen > maxyen:
        maxyen = yen
print(maxyen)

Submission status: Accepted

Solution code:
N = int(input())
s = {0:0}
for i in range(N):
    tmp = input()
    if tmp in s.keys():
        s[tmp]+=1
    else:
        s[tmp] = 1
M = int(input())
for i in range(M):
    tmp = input()
    if tmp in s.keys():
        s[tmp]-=1
    else:
        s[tmp] = -1

print(max(s.values()))

Submission status: Accepted

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

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

#print(s)
#print(t)
max_score = 0

for e in s:
    score = s.count(e) - t.count(e)
    if score > max_score:
        max_score = score

print(max_score)

Submission status: Accepted

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

for _ in range(N):
    k = input()
    if k not in d:
        d[k] = 1
    else:
        d[k] += 1

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

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

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

Submission status: Accepted

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

ans = 0
while len(s) > 0:

    i += 1
    s_tmp = s[0]
    ans_tmp = s.count(s_tmp) - t.count(s_tmp)

    while s.count(s_tmp) > 0:
        s.remove(s_tmp)
    while t.count(s_tmp) > 0:
        t.remove(s_tmp)

    if ans_tmp > ans:
        ans = ans_tmp

print (max(ans, 0))

Submission status: Accepted

Solution code:

mc = []
nc = []

M = int(input())
for m in range(0,M):
	mc.append(input())

N = int(input())
for n in range(0,N):
	nc.append(input())

max_num = 0
for i in range(0,M):
	stre = mc[i]
	count_dict = mc.count(stre) + nc.count(stre)*-1
	if (max_num <= count_dict):
		max_num = count_dict
	
print(max_num)

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

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

SC.subtract(TC)
k, v = SC.most_common()[0]

print(max(v, 0))

Submission status: Accepted

Solution code:
from collections import Counter, defaultdict
s = Counter([input() for i in range(int(input()))])
d = Counter([input() for i in range(int(input()))])
s = s - d
try:
    print(sorted([x for x in s.items()], key=lambda x: x[1])[-1][-1])
except:
    print(0)

Submission status: Accepted

Solution code:
#青:N, s_i earn
#赤:M, t_i lose
N = int(input())
bl = [input() for i in range(N)]
M = int(input())
rl = [input() for i in range(M)]

yenResult = 0
for i in set(bl):
    yen = 0
    yen += bl.count(i)
    yen -= rl.count(i)
    if yen > yenResult:
        yenResult = yen
print(yenResult)

Submission status: Accepted

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

result_yen = 0
for i in set(bl):
    yen = 0
    yen += bl.count(i)
    yen -= rl.count(i)
    if yen > result_yen:
        result_yen = yen
print(0 if result_yen == 0 else result_yen)

Submission status: Accepted

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

M= int(input())
b=[]
for i in range(M):
    b.append(input())
    
c=[]
for s in set(a+b):
    c.append(a.count(s)-b.count(s))

print(max(0,max(c)))

Submission status: Accepted

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

num_minus = int(input())
str_minus = []
for i in range(num_minus):
    str_minus.append(input())

cost_list = []
for s in set(str_plus + str_minus):
    cost_list.append(str_plus.count(s) - str_minus.count(s))

print(max(0, max(cost_list)))

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
nlist=[]
for i in range(n):
  nlist.append(input())
m = int(input())
mlist = []
for j in range(m):
  mlist.append(input())
cn = Counter(nlist)
cm = Counter(mlist)
csum = cn-cm
if not csum.most_common():
  print(0)
else:
  print(csum.most_common()[0][1])

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())
set_s = list(set(s))
max_yen = -9999
for x in range(len(set_s)):
    yen = s.count(set_s[x]) - t.count(set_s[x])
    if yen > max_yen:
        max_yen = yen
if max_yen < 0:
    print("0")
else:
    print(max_yen)

Submission status: Accepted

Solution code:
cnt_dict = {}

N = int(input())
for _ in range(N):
    s = input()
    if cnt_dict.get(s) is not None:
        cnt_dict[s] += 1
    else:
        cnt_dict[s] = 1

M = int(input())
for _ in range(M):
    t = input()
    if cnt_dict.get(t) is not None:
        cnt_dict[t] -= 1


ans =  max(cnt_dict.items(), key=lambda x:x[1])[1]
if ans > 0:
    print(ans)
else:
    print(0)

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

maxX = 0
word = set(Blue+Red)
for w in word:
    x = Blue.count(w) - Red.count(w)
    if x > maxX:
        maxX = x

print(maxX)

Submission status: Accepted

Solution code:
n = int(input())
blue =[]
red = []
result = 0

for i in range (n):
  word = input()
  blue.append(word)
  
m = int(input())

for i in range (m):
  word = input()
  red.append(word)

for word in blue:
  temp = blue.count(word) - red.count(word)
  
  if temp > result:
    result = temp
    
print (result)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
s1 = [input() for i in range(N)]
c1 = Counter(s1)
M = int(input())
s2 = [input() for i in range(M)]
c2 = Counter(s2)

ans = 0
for k,v in c1.items():
    ans = max(ans, v - c2[k])
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)]
res = {}
for i in S:
    if i in S:
        if i in T:
            res[i] = S.count(i) - T.count(i)
        else:
            res[i] = S.count(i)
if max(res.values()) <= 0:
    print(0)
else:
    print(max(res.values()))

Submission status: Accepted

Solution code:
import sys

l={}
n = int(sys.stdin.readline())

for i in range(n):
    a = sys.stdin.readline().strip()
    if a in l.keys():
        l[a] += 1
    else:
        l[a] = 1

m = int(sys.stdin.readline())

for i in range(m):
    b = sys.stdin.readline().strip()
    if b in l.keys():
        l[b] -= 1

print(max(l.values()) if max(l.values()) > 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)]
u = list(set(s + t))
ans = 0
for i in u:
    ans = max(ans, s.count(i) - t.count(i))
print(ans)

Submission status: Accepted

Solution code:
word_dic = {}
N = int(input())
for i in range(N):
    word = input()
    if word in word_dic.keys():
        word_dic[word] += 1
    else:
        word_dic[word] = 1
        
M = int(input())
for i in range(M):
    word = input()
    if word in word_dic.keys():
        word_dic[word] -= 1
        
score = max(word_dic.values())
if score < 0:
    score = 0
print(score)

Submission status: Accepted

Solution code:
list1 = []
list2 = []
tmp = 0
max = 0
n2 = input()
n = int(n2)
for i in range(n):
   list1.append(input())
m2 = input()
m = int(m2)
for i in range(m):
   list2.append(input())
for person in list1:
   tmp = 0
   for people in list1:
       if(people == person):
          tmp += 1
   for people in list2:
       if(people == person):
          tmp -= 1
   if(tmp > max):
       max = tmp
print(max)