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:
from collections import Counter

arr_b = []
N = int(input())
for i in range(N):
    arr_b.append(str(input()))
arr_r = []
N = int(input())
for i in range(N):
    arr_r.append(str(input()))

c_b = Counter(arr_b)
c_r = Counter(arr_r)

res = 0
for k_b in c_b.keys():
    if k_b in c_r :
        if res < c_b[k_b] - c_r[k_b]:
            res = c_b[k_b] - c_r[k_b]
    else:
        if res < c_b[k_b]:
            res = c_b[k_b]

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

count = {s[i]: s.count(s[i]) - t.count(s[i]) for i in range(N) }

result = sorted(count.items(), key=lambda x: x[1], reverse=True)[0][1]
if result > 0:
    print(result)
else:
    print(0)

Submission status: Accepted

Solution code:
N = int(input())
dict_s = {}
for var in range(N):
    s = input()
    if s in dict_s:
        dict_s[s] += 1
    else:
        dict_s[s] = 1
M = int(input())
for var in range(M):
    t = input()
    if t in dict_s:
        dict_s[t] -= 1
dict_s[''] = 0
print (max(dict_s.values()))

Submission status: Accepted

Solution code:
N = int(input())
dict_s = {}
for var in range(N):
    s = input()
    if s in dict_s:
        dict_s[s] += 1
    else:
        dict_s[s] = 1

M = int(input())
for var in range(M):
    t = input()
    if t in dict_s:
        dict_s[t] -= 1

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

Submission status: Accepted

Solution code:
N = int(input())
dict_s = {}
for var in range(N):
    s = input()
    if s in dict_s:
        dict_s[s] = dict_s[s] + 1
    else:
        dict_s[s] = 1

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

tensu = []
for key in dict_s.keys():
    if key in dict_t:
        tensu.append(dict_s[key] - dict_t[key])
    else:
        tensu.append(dict_s[key])

tensu_max=max(tensu)
if tensu_max < 0:
    print(0)
else:
    print(tensu_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 x in s:
    ans = max(ans, s.count(x) - t.count(x))
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
a=[]
for i in range(n):
    a.append(input())
m=int(input())
b=[]
for i in range(m):
    b.append(input())
ans=0
a_counter=Counter(a)
b_counter=Counter(b)

for i in a_counter:
    d=a_counter[i]
    if i in b_counter:
        d-=b_counter[i]
    else:
        d=d
    ans=max(ans,d)
    d=0
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ret = {}
for i in range(n):
    s = input()
    ret[s] = ret.get(s, 0) + 1
m = int(input())
for i in range(m):
    s = input()
    ret[s] = ret.get(s, 0) - 1

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

Submission status: Accepted

Solution code:
#入力
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-tが最大のものを探す
s_set = set(s)
sub = []
for i in s_set:
    a = s.count(i)
    b = t.count(i)
    sub.append(a-b)
if max(sub) >0:
    print(max(sub))
else:
    print('0')

Submission status: Accepted

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

if __name__ == "__main__":
	N = int(input())
	blue_cards = [input() for i in range(N)]
	M = int(input())
	red_cards = [input() for i in range(M)]
	# STőˇé(O(N*N*M), X10^6)
	max_money = 0
	for word in blue_cards:
		money = 0
		for blue in blue_cards:
			if word == blue:
				money += 1
		for red in red_cards:
			if word == red:
				money -= 1
		if money > max_money:
			max_money = money
	print(max_money)

Submission status: Accepted

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

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

word_list = []
for i in s:
    if (i in word_list):
        continue
    else:
        word_list.append(i)

max_value = 0
for i in word_list:
    value = s.count(i) - t.count(i)
    if (max_value < value):
        max_value = value
print(max_value)

Submission status: Accepted

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

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

print(max(max(d.items(), key=lambda x: x[1])[1], 0))

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
blue = list(input() for _ in range(N))
M = int(input())
red = list(input() for _ in range(M))

blue2 = Counter(blue)
red2 = Counter(red)

blue2.subtract(red2)
for word, cnt in blue2.most_common(1):
    if cnt < 0:
        print(0)
    else:
        print(cnt)

Submission status: Accepted

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

total = []
i = 0
while i < n:
	counter = 0
	for k in range(n):
		if s[k] == s[i]:
			counter += 1
	for k in range(m):
		if t[k] == s[i]:
			counter += -1
	total.append(counter)
	i += 1

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

max_point = 0
for string in s:
    point = 0
    for i in s:
        if i == string:
            point += 1
    for j in t:
        if j == string:
            point -= 1
    if point > max_point:
        max_point = point
print(max_point)

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

ans = 0
for str in s: #strは単語を表している。ループの回数としてはn回（sの配列数）
    cou = s.count(str) - t.count(str) #sの中にstr（たとえばapple)が何個あるか、tの中に同じく　str（spple)が何個あるか調べて引いてる。
    ans = max(cou, ans)

print(ans)

Submission status: Accepted

Solution code:
d = {}
N = int(input())
for _ in range(N):
  c = input()
  d[c] = d.get(c, 0)+1
M = int(input())
for _ in range(M):
  c = input()
  d[c] = d.get(c, 0)-1
print(max(max(d.items(), key=lambda x: x[1])[1], 0))

Submission status: Accepted

Solution code:
N=int(input())
res={}
for dummy in range(N):
  s=input()
  if s not in res.keys():
    res[s]=1
  else:
    res[s]+=1
M=int(input())
for dummy in range(M):
  s=input()
  if s not in res.keys():
    res[s]=-1
  else:
    res[s]-=1
tmp=max(res.values())
if tmp<0:print('0')
else: print(tmp)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

count=0

for i in set(s):
    value=s.count(i)-t.count(i)

    if value>count:
        count=value

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

S = set()
blueCard = {}
for i in range(N):
	s = input()
	S.add(s)
	if s not in blueCard:
		blueCard[s] = 1
	else:
		blueCard[s] += 1

M = int(input())
redCard = {}
for i in range(M):
	t = input()
	S.add(t)
	if t not in redCard:
		redCard[t] = 1
	else:
		redCard[t] += 1

res = 0
for u in S:
	if u in blueCard and u not in redCard:
		res = max(res, blueCard[u])
	elif u in blueCard and u in redCard:
		res = max(res, blueCard[u] - redCard[u])
print(res)

Submission status: Accepted

Solution code:
def function(values, num):
    count = int(input())

    for i in range(count):
        name = input()
        if name in values:
            values[name] += num
        else:
            values[name] = 1

    
if __name__ == '__main__':
    values = {}

    function(values, 1)
    function(values, -1)

    max_num = max(values.values())

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

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    c = collections.defaultdict(int)
    for _ in range(n):
        c[S()] += 1
    m = I()
    for _ in range(m):
        c[S()] -= 1

    return max(0, max(c.values()))


print(main())

Submission status: Accepted

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

max = 0
for i in set(s + t):
    sum = 0
    for j in s:
        if i == j:
            sum += 1
    for j in t:
        if i == j:
            sum -= 1
    if sum > max:
        max = sum

print(max)

Submission status: Accepted

Solution code:
wl = {}
N = int(input())
for n in range(N):
    w = input()
    if w in wl:
        wl[w] = wl[w]+1
    else:
        wl[w] = 1 
M = int(input())
for m in range(M):
    w = input()
    if w in wl:
        wl[w] = wl[w]-1
    else:
        wl[w] = -1

mc = ""
c = 0
for k, v in wl.items():
    if c < v:
        mc = k
        c = v

print(c)

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

s_set = set(s_list)
t_set = set(t_list)

result = 0

for s in s_set:
  val = s_list.count(s) - t_list.count(s)
  if val > result:
    result = val

print(result)

Submission status: Accepted

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

ans = 0
for s in xs:
  sum = 0
  for t in xs:
    if s == t: sum += 1
  for t in ys:
    if s == t: sum -= 1
  ans = max(ans, sum)
print(ans)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
if __name__ == "__main__":
    n = int(input())
    s = [ input() for _ in range(n) ]
    m = int(input())
    t = [ input() for _ in range(m) ]
    factors = list(set(s+t))
    dic = { key: 0 for key in factors}
    ans = float("-inf")
    for word in s:
        dic[word] += 1
    for word in t:
        dic[word] -= 1
    for word in list(set(s+t)):
        ans = max(ans, dic[word])
    else:
        if ans < 0:
            print(0)
        else:
            print(ans)

Submission status: Accepted

Solution code:
red = []
blue = []
ans = 0
n = int(input())
for _ in range(n):
    red.append(input())
m = int(input())
for _ in range(m):
    blue.append(input())
for word in set(red):
    if word in blue:
        tmp = red.count(word) - blue.count(word)
    else:
        tmp = red.count(word)
    if tmp > ans:
        ans = tmp
print(ans)

Submission status: Accepted

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

for word in set(red):
    r_num = red.count(word)
    if word in blue:
        tmp = r_num - blue.count(word)
    else:
        tmp = r_num
    if tmp > ans:
        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)]

CounterS = Counter(S)
CounterT = Counter(T)

Max = 0
for key in CounterS.keys():
    i = int(CounterS.get(key, 0)) - int(CounterT.get(key, 0))
    if Max < i:
        Max = i
print(Max)

Submission status: Accepted

Solution code:
dic={}
for i in range(int(input())):
    s=input()
    if s in dic:
        dic[s]+=1
    else:
        dic[s]=1
for i in range(int(input())):
    s=input()
    if s in dic:
        dic[s]-=1
    else:
        dic[s]=-1
print(max(sorted(dic.values())[-1],0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter
def inpl(): return tuple(map(int, input().split()))

N = int(input())
C = Counter()
for _ in range(N):
    C[input()] += 1
M = int(input())
for _ in range(M):
    C[input()] -= 1
print(max(max(C.values()), 0))

Submission status: Accepted

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

ret = 0

for s in set(S):
    ret = max(ret, S.count(s) - T.count(s))

print(ret)

Submission status: Accepted

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

dicts = {}
for i in range(N):
    if(s[i] in dicts):
        dicts[s[i]] += 1
    else:
        dicts[s[i]] = 1
dictt = {}
for i in range(M):
    if(t[i] in dictt):
        dictt[t[i]] += 1
    else:
        dictt[t[i]] = 1

ans = 0
for i in range(N):
    if(s[i] in dictt):
        ans = max(dicts[s[i]] - dictt[s[i]], ans)
    else:
        ans = max(dicts[s[i]], ans)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
blue = ['a']*N
#Nのサイズにしたがって青のカードのリストを作成
for i in range(0,N):
        blue[i] = input()
M = int(input())
red = ['a']*M
#Mのサイズにしたがって赤のカードのリストを作成
for i in range(0,M):
        red[i] = input()
#カードの単語の種類を調べる
set_blue = set(blue)#カードの単語の種類を調べる
set_red = set(red)
#インデックスで参照するためにタプルにする
tuple_blue = tuple(set_blue)
tuple_red = tuple(set_red)

max_score = 0
for i in range(0,len(tuple_blue)):
    score = blue.count(tuple_blue[i])-red.count((tuple_blue[i]))
    if max_score < score:
        max_score = score
print(max_score)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest 091
# B - Two Colors Card Game

from sys import stdin

def multiset(xs, vocabulary=[]):
    d = {}
    for x in xs + vocabulary: d[x] = 0
    for x in xs: d[x] += 1
    return d

def solve(s, t):
    ss = multiset(s)
    tt = multiset(t, vocabulary=s)
    value = max([ss[x] - tt[x] for x in ss])
    return max(value, 0)

def readStrList():
    n = int(stdin.readline())
    s = []
    for i in range(n):
        x = stdin.readline().strip()
        s.append(x)
    return s

s = readStrList()
t = readStrList()
print(solve(s, t))

Submission status: Accepted

Solution code:
N=int(input() )
ans=0
S=[]
T=[]
S=[input() for i in range(0,N) ]
S.sort()
M=int(input() )
i=0
while i<M :
    T.append(input() )
    i=i+1
i=0
j=0
k=0
sans=0
while i<N :
    while S[i+k]==S[i] :
        k=k+1
        if(i+k==N):
            break
    j=0
    while j<M :
        if(S[i]==T[j]):
            sans=sans-1
        j=j+1
    sans+=k
    if(ans<sans):
        ans=sans
    sans=0
    i=i+k
    k=0
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

dic = {}

for i in range(n):
    word = input()

    if word in dic:
        dic[word] += 1
    else:
        dic[word] = 1

m = int(input())

for j in range(m):
    word = input()

    if word in dic:
        dic[word] -= 1
    else:
        dic[word] = -1


print(max(0,max(dic[x] for x in dic)))

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

temp = 0

for i in range(N):
    numN = 0
    numM = 0
    for j in range(N):
        if s[i]==s[j]:
            numN = numN + 1
    for k in range(M):
        if s[i]==t[k]:
            numM = numM + 1
    if temp <= numN-numM:
        temp=numN-numM

print(temp)

Submission status: Accepted

Solution code:
from collections import Counter


N = int(input())
S = Counter()
for _ in range(N):
    s = input()
    S.update([s])
M = int(input())
T = Counter()
for _ in range(M):
    t = input()
    T.update([t])

ans = 0
for s, s_cnt in S.items():
    ans = max(ans, max(s_cnt - T.get(s, 0), 0))
print(ans)

Submission status: Accepted

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

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


ans = 0
for n in range(N):
    count = 0
    for j in range(N):
        if s[n] == s[j]:
            count += 1
    for j in range(M):
        if s[n] == t[j]:
            count -= 1
    ans = max(ans, count)

print(ans)

Submission status: Accepted

Solution code:
s = []
t = []
x = []

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

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

for n in range(N):
    S = s.count(s[- n])
    T = t.count(s[- n])
    x.append(S - T)

for n in range(M):
    S = s.count(t[- n])
    T = t.count(t[- n])
    x.append(S - T)

if max(x) > 0:
    print(max(x))
else:
    print(0)

Submission status: Accepted

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

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

out=sorted(d.items(), key=lambda x: x[1])[-1][1]
if out<0:
    print(0)
else:
    print(out)

Submission status: Accepted

Solution code:
#abc091b

n=int(raw_input())
s=[]
t=[]
for i in xrange(n):
 s.append(raw_input())
m=int(raw_input())
for i in xrange(m):
 t.append(raw_input())
res=0
for i in xrange(n):
 res=max(res,s.count(s[i])-t.count(s[i]))
print res

Submission status: Accepted

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

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

red_set=set(red)
ans = 0

for s in red_set:
    ans = max(ans,red.count(s)-blue.count(s))


print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict as dd

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

ans = 0
for s in po.values():
    if ans < s:
        ans = s
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)]

wordlist=list(set(s+t))
cnt=0
ss=Counter(s)
tt=Counter(t)
for i in wordlist:
    buf=ss[i]-tt[i]
    if cnt<buf:
      cnt=buf
      
print(cnt)

Submission status: Accepted

Solution code:
import pprint
from collections import defaultdict

N = int(input())

SD = defaultdict(int)
for _ in range(N):
    SD[input()] += 1

M = int(input())
TD = defaultdict(int)
for _ in range(M):
    TD[input()] += 1

KS = set(list(SD.keys()) + list(TD.keys()))

RL = [0]
for k in KS:
    RL.append(SD[k] - TD[k])

print(max(RL))

Submission status: Accepted

Solution code:
import copy
n = int(input())
s = []
for i in range(n):
    s += [input()]
checker = copy.deepcopy(s)
checker += ['xxxxxxxxxxxxxxxxxxxx']

m = int(input())
t = []
for i in range(m):
    t += [input()]

r = 0
for ss in set(checker):
    buf = s.count(ss) - t.count(ss)
    if r < buf:
        r = buf
print(r)

Submission status: Accepted

Solution code:
d = {}
for _ in range(int(input())):
  s = input()
  d[s] = d.get(s, 0) + 1
for _ in range(int(input())):
  s = input()
  d[s] = d.get(s, 0) - 1
print(max(0, max(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 str in s:
    cur = s.count(str) - t.count(str)
    ans = max(ans, cur)

print(ans)

Submission status: Accepted

Solution code:
blue = []
red = []
count=countb=countr=x=maxi=0
nblue = int(input())
for c in range(1, nblue+1):
  blue+=[input()]
nred = int(input())
for c in range(1, nred + 1):
  red+=[input()]
for c in range (0, len(blue)): 
  countb=blue.count(blue[c])
  countr=red.count(blue[c])
  if countr>=1:
    countr=red.count(blue[c])
    countb-=countr
  if countb>maxi:
    maxi=countb
    x=c
print(maxi)

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=set()
for i in range(N):
    u.add(s[i])
for i in range(M):
    u.add(t[i])
v=list(u)
w=[0 for i in range(len(v))]
for i in range(N):
    for j in range(len(w)):
        if s[i]==v[j]:
            w[j]+=1
for i in range(M):
    for j in range(len(w)):
        if t[i]==v[j]:
            w[j]-=1
print(max([0,max(w)]))

Submission status: Accepted

Solution code:
N=int(input())
a=list()
for i in range(0,N):
	x=input()
	a.append(x)
M=int(input())
b=list()
for i in range(0,M):
	x=input()
	b.append(x)
A=dict()
B=dict()
for i in a:
	x=a.count(i)
	A[i]=x
for i in b:
	x=b.count(i)
	B[i]=x
res=list()
for i in A:
	if i in B:
		A[i]-=B[i]
m=0
#print(A)
#print(B)
for i in A:
	if A[i]>m:
		m=A[i]
#print(A)
print(m)

Submission status: Accepted

Solution code:
blue=[]
red=[]
count=countb=countr=x=maxi=0
nblue=int(input())
for c in range(1,nblue+1):
  blue+=[input()]
nred=int(input())
for c in range(1,nred+1):
  red+=[input()]
for c in range(0,len(blue)):
  countb=blue.count(blue[c])
  countr=red.count(blue[c])
  if countr>=1:
    countr=red.count(blue[c])
    countb-=countr
  if countb>maxi:
    maxi=countb
    x=c
print(maxi)

Submission status: Accepted

Solution code:
n = int(input())
nlist = [input() for i in range(n)]
m = int(input())
mlist = [input() for i in range(m)]
 
for i in mlist:
    if i in nlist:
        nlist.remove(i)
 
def maxCOUNT( lis ):
  '''
  与えられたリストの中に、最も多く存在する要素を返す
  (最大の数の要素が複数ある場合、pythonのsetで先頭により近い要素を返す)
  '''
  L = lis[:]#copy
  S = set(lis)
  S = list(S)
  MaxCount=0
 
  for elem in S:
    c=0
    while elem in L:
      ind = L.index(elem)
      foo = L.pop(ind)
      c+=1
    if c>MaxCount:
      MaxCount=c
  return MaxCount
 
print(maxCOUNT(nlist))

Submission status: Accepted

Solution code:
# import platform
# ver = platform.python_version_tuple()
# if int(ver[1]) < 5:
#     from fractions import gcd
# else:
#     from math import gcd

# from collections import deque
# from collections import defaultdict
# from collections import Counter
# from itertools import permutations

# from functools import lru_cache
# @lru_cache(maxsize=1024)

def main():
    N = int(input())
    S = tuple(input() for _ in [0] * N)
    M = int(input())
    T = tuple(input() for _ in [0] * M)

    blue = dict()
    for s in S:
        blue[s] = blue.get(s, 0) + 1

    red = dict()
    for t in T:
        red[t] = red.get(t, 0) + 1

    ans = 0
    for k, v in blue.items():
        if k in red:
            ans = max(ans, v - red[k])
        else:
            ans = max(ans, v)
    print(ans)

main()

Submission status: Accepted

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

M=int(input())
b=[]
for m in range(M):
    b.append(input())

c=[]
for i in range(N):
    d=a.count(a[i])
    e=b.count(a[i])
    c.append(d-e)

answer = max(c)

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

Submission status: Accepted

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

M = int(input())
t = []
t_ = set([])
for j in range(M):
    tmp = input()
    t.append(tmp)
    t_.add(tmp)

u = s_.union(t_)

counter = []
for factor in u:
    v = s.count(factor) - t.count(factor)
    if v < 0:
        v = 0
    counter.append(v)
    

print(max(counter))

Submission status: Accepted

Solution code:
from collections import Counter

N=int(input())
N_s=[]
for i in range(N):
    N_s.append(input())
M=int(input())
M_t=[]
for j in range(M):
    M_t.append(input())
Monny_N=Counter(N_s)
Monny_M=Counter(M_t)

for key in Monny_N.keys():
    Monny_N[key] = Monny_N[key]-Monny_M[key]

Monny_max=max(Monny_N.values())

if Monny_max < 0:
    print("0")
else:
    print(Monny_max)

Submission status: Accepted

Solution code:
from collections import Counter

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

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

ls = Counter(s)
lt = Counter(t)

c = 0
for k in ls.keys():
    c_temp = ls[k] - lt[k]
    if c < c_temp:
        c = c_temp

print(c)

Submission status: Accepted

Solution code:
dict_list = {}

N = int(input())

for i in range(N):
	tmp = input()
	if tmp in dict_list.keys():
		dict_list[tmp] += 1
	else:
		dict_list[tmp] = 1

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


answer = max(dict_list.values())
if answer < 0:
	print("0")
else:
	print(answer)

Submission status: Accepted

Solution code:
N=int(input())
Blue=[]
for I in range(N):
	Blue.append(input())
M=int(input())
Red=[]
for J in range(M):
	Red.append(input())
W=[]
Max=-101
for K in Blue:
	if K not in W:
		W.append(K)
		R=Blue.count(K)-Red.count(K)
		if R>Max:
			Max=R
if Max<=0:
	print(0)
else:
	print(Max)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    n_array = []
    for i in range(n):
        word = input()
        n_array.append(word)
    m = int(input())
    m_array = []
    for i in range(m):
        word = input()
        m_array.append(word)
    n_dic = {}
    m_dic = {}
    best = 0
    for i in n_array:
        if i in n_dic:
            n_dic[i] += 1
        else:
            n_dic[i] = 1
    for i in m_array:
        if i in m_dic:
            m_dic[i] += 1
        else:
            m_dic[i] = 1
    for i in n_dic:
        if i in m_array:
            if n_dic[i] - m_dic[i] > best:
                best = n_dic[i] - m_dic[i]
        else:
            if n_dic[i] > best:
                best = n_dic[i]
    print(best)

main()

Submission status: Accepted

Solution code:
s={}
t={}
num=0
n=input()
for i in range(int(n)):
  a=input()
  if a in s.keys():
    s[a]+=1
  else:
    s[a]=1
m=input()
for j in range(int(m)):
  b=input()
  if b in t.keys():
    t[b]+=1
  else:
    t[b]=1
for x in s.keys():
  y=s[x]
  if x in t.keys():
    y-=t[x]
  if y>num:
    num=y
print(str(num))

Submission status: Accepted

Solution code:

blue_dict = {}

N = int(input())
for _ in range(N):
    key = input()
    if key in blue_dict.keys():
        blue_dict[key] += 1
    else:
        blue_dict[key] = 1

M = int(input())
for _ in range(M):
    key = input()
    if key in blue_dict.keys():
        blue_dict[key] -= 1

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

Submission status: Accepted

Solution code:
from collections import defaultdict,Counter
N = input()
Ndic = defaultdict(int)
Mdic = defaultdict(int)
for i in range(int(N)):
    s = input()
    Ndic[s] += 1
M = input()
for j in range(int(M)):
    t = input()
    Mdic[t] += 1

ans = []
c = Counter(Ndic)
for k,v in c.most_common(1):
    mans = v
for k,v in c.most_common():
    if k in Mdic:
        ans.append(Ndic[k]-Mdic[k])
    else:
        ans.append(Ndic[k])

if ans:
    print(max(max(ans),0))
else:
    print(mans)

Submission status: Accepted

Solution code:
from collections import Counter

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

# 重複を削除
ss = list(set(s))

# 要素ごとの件数をもとめる
sc = Counter(s)
tc = Counter(t)

# test
# print(sc)

ans = 0
for i in range(len(ss)):
  wk = sc[ss[i]] - tc[ss[i]]
  if (ans < wk):
    ans = wk

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = [0] * N

for i in range(N):
    for k in range(N):
        if INPn[i] == INPn[k]:
            ans[i] += 1
for i in range(N):
    for j in range(M):

        if INPn[i] == INPm[j]:
            ans[i] -= 1

for i in range(N):
    if ans[i] < 0:
        ans[i] = 0
        
mx = max(ans)
print(mx)