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())
blue=[input() for i in range(N)]
M=int(input())
red=[input() for i in range(M)]
line=[]
for i in range(N):
    if blue[i]==0:
        continue
    else:
        c=0
        for j in range(1,N-i):
            if blue[i]==blue[i+j]:
                blue[i+j]=0
                c+=1
        for k in range(M):
                if red[k]==blue[i]:
                    c-=1
        else:
            line.append(c+1)
print(max(line) if max(line)>0 else 0)

Submission status: Accepted

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

def main():
    n = int(input())
    s_list = []
    for i in range(n):
        s_list.append(input())
    m = int(input())
    m_list = []
    for i in range(m):
        m_list.append(input())

    sen_set = set(s_list + m_list)
    max_money = 0
    for sen in sen_set:
        money = 0
        for i in s_list:
            if sen == i:
                money += 1
        for j in m_list:
            if sen == j:
                money -= 1
        if max_money < money:
            max_money = money
    
    print(max_money)



if __name__ == '__main__':
    main()

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())
ans = 0
#SS = set(S)|set(T)
CS = Counter(S)
CT = Counter(T)
A = [0]
for x in CS:
    if CS[x] > CT[x]:
        A.append(CS[x]-CT[x])
print(max(A))

Submission status: Accepted

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

def countDic(str_list):
    ret = {}
    for s in str_list:
        if s in ret.keys():
            ret[s] += 1
        else:
            ret[s] = 1
    return ret

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

s_c = countDic(s)
t_c = countDic(t)
a = []
for k in s_c.keys():
    if k in t_c.keys():
        a.append(s_c[k] - t_c[k])
    else:
        a.append(s_c[k])
if max(a) > 0:
    print(max(a))
else:
    print(0)

Submission status: Accepted

Solution code:
N = int(input())
dirB = {}
for _ in range(N):
    w = input()
    dirB[w] = dirB.setdefault(w, 0) + 1

M = int(input())
dirR = {}
for _ in range(M):
    w = input()
    dirR[w] = dirR.setdefault(w, 0) + 1
    
res = 0
for w in dirB:
    count = dirB[w] - dirR.setdefault(w, 0)
    if count > res:
        res = count
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)]

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

Submission status: Accepted

Solution code:
N = int(input())
s = []
t = []
p = []
ans = 0
for i in range(0,N):
	s.append(input())
M = int(input())
for i in range(0,M):
	t.append(input())
for i in range(0,N):
	p.append(0)
	for j in range(0,N):
		if s[i] == s[j]:
			p[i] += 1
	for k in range(0,M):
		if s[i] == t[k]:
			p[i] -= 1
	if ans < p[i]:
		ans = p[i]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s,t = list(),list()

for i in range(n):
    s.append(input())

m = int(input())

for i in range(m):
    t.append(input())

s.sort()
t.sort()

s_ = set(s)
t_ = set(t)

s_,t_ = list(s_),list(t_)
st_ = s_ + t_
st = set(st_)

res_list = list(st)
lo = len(res_list)
res_co = [0]*lo

for i in range(lo):
    res_co[i] += s.count(res_list[i])
    res_co[i] -= t.count(res_list[i])

#point = res_co.index(max(res_co))
#print(res_list)
#print(res_co)
if max(res_co) >= 0:
    print(max(res_co))
else:
    print(0)

Submission status: Accepted

Solution code:
N = int(input())
s_list = [input() for i in range(N)]
M = int(input())
t_list = [input() for i in range(M)]
X = 0
for i in range(N):
	X = max(X, s_list.count(s_list[i]) - t_list.count(s_list[i]))
print(X)

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

# 別のインスタンスを作成する
s2 = s[:]
# 和集合をとる
set(s2)
ans = 0

for i in s2:
    if ans < s.count(i) - t.count(i):
        ans = s.count(i) - t.count(i)

print(ans)

Submission status: Accepted

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

s2=s[:]
set(s2)
ans=0
for i in s2:
    if ans<s.count(i)-t.count(i):
        ans=s.count(i)-t.count(i)
print(ans)

Submission status: Accepted

Solution code:
n = int(raw_input())
blue={}
for x in range(0, n):
  tmp=raw_input()
  if(tmp in blue):
	blue[tmp]+=1
  else:
    blue[tmp]=1

m = int(raw_input())
for x in range(m):
  tmp=raw_input()
  if(tmp in blue):
	blue[tmp]-=1
  else:
    blue[tmp]=-1

max=0
for key, val in blue.items():
  if(max<val):
    max=val

print max

Submission status: Accepted

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

x = 0
a = 0

for str in s:
    x = s.count(str) - t.count(str)
    if x > a:
        a = x

print(a)

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

a=[]
for i in range(n):
    a.append(s.count(s[i])-t.count(s[i]))

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

Submission status: Accepted

Solution code:
N=int(input())

S=input()

ans=[]
tmp=[1,S]
ans.append(tmp)
count=1

for i in range(1,N):
    S=input()
    for j in range(count):
        if ans[j][1]==S:
            ans[j][0]+=1
            break
    else:
        tmp=[1,S]
        ans.append(tmp)
        count+=1

M=int(input())

for i in range(M):
    S=input()
    for j in range(count):
        if ans[j][1]==S:
            ans[j][0]-=1
            break

ans.sort()
ans.reverse()

if ans[0][0]<0:
    print(0)
else:
    print(ans[0][0])

Submission status: Accepted

Solution code:
from collections import Counter
 
n = int(input())
ss = Counter(input() for _ in range(n))
m = int(input())
ts = Counter(input() for _ in range(m))
answer = max(cs - ts[s] for s, cs in ss.items())
print(answer if answer > 0 else 0)

Submission status: Accepted

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

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

Submission status: Accepted

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


    cand = list(set(s))
    g = [s.count(c) - t.count(c) for c in cand]
    ans = max(g)
    if ans < 0:
        print(0)
    else:
        print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
v = {}
for _ in range(n):
    s = input()
    if s in v:
        v[s] += 1
    else:
        v[s] = 1
m = int(input())
for _ in range(m):
    t = input()
    if t in v:
        v[t] -= 1
    else:
        v[t] = -1
print(max(list(v.values()) + [0]))

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

cnt = collections.Counter()
for d in s:
    cnt[d] += 1
for d in t:
    cnt[d] += -1

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

Submission status: Accepted

Solution code:
N = int(input())
s_n = []
for i in range(N):
    s_n.append(input())
M = int(input())
for j in range(M):
    youso = input()
    if youso in s_n:
        s_n.remove(youso)
max_point = 0
for k in range(len(s_n)):
    max_point = [s_n.count(s_n[k]),max_point][s_n.count(s_n[k])<max_point]
print(max_point)

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)]
X = 0
for i in range(N):
	if s_list.count(s_list[i]) - t_list.count(s_list[i]) >= X:
		X = s_list.count(s_list[i]) - t_list.count(s_list[i])
print(X)

Submission status: Accepted

Solution code:
n = int(input())
blues = dict([])
for i in range(n):
    s = input()
    if s in blues.keys():
        blues[s] += 1
    else: 
        blues[s] = 1

m = int(input())
for i in range(m):
    t = input()
    if t in blues.keys():
        blues[t] -= 1
    else: 
        blues[t] = -1

ans = max(blues.values())
if ans < 0:
    print(0) # 辞書にないstrを受け取ったほうが良い
else:
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = list()
for _ in range(N):
    S.append(input())
M = int(input())
T = list()
for _ in range(M):
    T.append(input())

all_words = set(S+T) # unique strings only
scores = [S.count(w) - T.count(w) for w in all_words]
print(max(0,max(scores)))

Submission status: Accepted

Solution code:
from collections import Counter

N=int(raw_input())
s=[raw_input() for j in xrange(N)]
st1 = Counter(s)

M=int(raw_input())
t=[raw_input() for j in xrange(M)]
st2 = Counter(t)

best = 0
for k,v in st1.items():
  score = v - st2[k]
  best = max(best, score)
print best

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
s = []
ans_dict = {}
for i in range(N):
    s.append(input())
M = int(input())
t = []
for i in range(M):
    t.append(input())
for s_i in s:
    if s_i in ans_dict.keys():
        ans_dict[s_i] += 1
    else:
        ans_dict[s_i] = 1
for t_i in t:
    if t_i in ans_dict.keys():
        ans_dict[t_i] -= 1
    else:
        ans_dict[t_i] = 1

ans = 0
for v in ans_dict.values():
    ans = max(ans, v)
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
ss = Counter(input() for _ in range(n))
m = int(input())
ts = Counter(input() for _ in range(m))
print(max(max(0, cs - ts[s]) for s, cs in ss.items()))

Submission status: Accepted

Solution code:
import collections
n = int(input())
s = collections.Counter([input() for i in range(n)])
m = int(input())
t = collections.Counter([input() for i in range(m)])

mv = 0
for k,v in s.items():
    if k in t:
        mv = max(mv, v-t[k])
    else:
        mv = max(mv, v)
print(mv)

Submission status: Accepted

Solution code:
dictionary = {}
N = int(input())
for i in range(N):
    word = input()
    if word not in dictionary:
        dictionary[word] = 1
    else:
        dictionary[word] += 1
M = int(input())
for i in range(M):
    word = input()
    if word not in dictionary:
        dictionary[word] = -1
    else:
        dictionary[word] -= 1

anslist = sorted(dictionary.items(), key = lambda x: -x[1])
ans = anslist[0][1]
if ans < 0: ans = 0
print(ans)

Submission status: Accepted

Solution code:
N=int(input())

S=[None]*N
for i in range(N):
  S[i]=input()


M=int(input())
T=[None]*M
for i in range(M):
  T[i]=input()
  
score=0

for i in range(N):
  count=0
  for j in range(N):
    if S[i]==S[j]:
      count+=1
  for k in range(M):
    if S[i]==T[k]:
      count-=1
  if count>score:
    score=count
    
print(score)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

S = []
for i in range(N):
  S.append(str(input()))

M = int(input())

T = []
for i in range(M):
  T.append(str(input()))

money = [0]

for i in S:
  cc = S.count(i)-T.count(i)
  money.append(cc)

print(max(money))

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

ans = 0
u = set(s + t)
for k in u:
    cnt1 = 0
    for l in s:
        if l == k:
            cnt1 += 1
    cnt2 = 0
    for m in t:
        if m == k:
            cnt2 -= 1
    if cnt1 + cnt2 >= ans:
        ans = cnt1 + cnt2

print(ans)

Submission status: Accepted

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

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

redwords = set(red)

maxyen = 0
for word in redwords:
    red_count = red.count(word)
    blue_count = blue.count(word)
    if red_count - blue_count > maxyen:
        maxyen = red_count - blue_count

print(maxyen)

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 = [s.count(i) - t.count(i) for i in s]
b = max(a)
if b < 0:
    print(0)
else:
    print(b)

Submission status: Accepted

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

T=[]
M = int(input())
for j in range(0,M):
	t = str(input())
	T.append(t)

S_uniq = list(set(S))

num = []
for p in S_uniq:
	s_count = S.count(p)
	t_count = T.count(p)
	counts = s_count - t_count
	num.append(counts)

num.sort()
num.reverse()
if(num[0] < 0):
	print("0")
else:
	print(num[0])

Submission status: Accepted

Solution code:
N=int(input())
blue=[]
red=[]
ans=0

target=""

for i in range(N):
    blue.append(input())
M=int(input())
for j in range(M):
    red.append(input())

for k in range(N):
    target=""
    target=blue[k]
    count=0
    for i in range(N):
        
        if target==blue[i]:
            count+=1
    for j in range(M):
        if target==red[j]:
            count-=1
    if count>ans:
        ans=count
        
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for x in range(n)]
m = int(input())
t = [input() for x in range(m)]
ans = 0
for i in range(n):
	counter = 0
	for u in range(n):
		if s[i] == s[u]:
			counter += 1
	for x in range(m):
		if s[i] == t[x]:
			counter -= 1
	if ans <= counter:
		ans = counter
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_max = 0
for i in range(N):
    count = s.count(s[i]) - t.count(s[i])
    if count > count_max:
         count_max = count
            
print(count_max)

Submission status: Accepted

Solution code:
d={'':0}
for _ in[0]*int(input()):e=input();d[e]=d.get(e,0)+1
for _ in[0]*int(input()):e=input();d[e]=d.get(e,0)-1
print(max(d.values()))

Submission status: Accepted

Solution code:
d={'':0}
for _ in[0]*int(input()):e=input();d[e]=d.get(e,0)+1
for _ in[0]*int(input()):e=input();d[e]=d.get(e,0)-1
#print(max(d[max(d,key=lambda x:d[x])],0))
print(max(d.values()))

Submission status: Accepted

Solution code:
d={}
for _ in[0]*int(input()):e=input();d[e]=d.get(e,0)+1
for _ in[0]*int(input()):e=input();d[e]=d.get(e,0)-1
print(max(d[max(d,key=lambda x:d[x])],0))

Submission status: Accepted

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

for i in range(n):
    x.append(s.count(s[i]) - t.count(s[i]))
    
x

if max(x)>=0:
    print('{}'.format(max(x)))
else:
    print('0')

Submission status: Accepted

Solution code:
n = int(input())
words = ['']
nums = [0]
while n > 0:
    w = input()
    if w not in words:
        words.append(w)
        nums.append(1)
    else:
        index = words.index(w)
        nums[index] += 1
    n -= 1
m = int(input())
while m > 0:
    wb = input()
    if wb in words:
        index = words.index(wb)
        nums[index] -= 1
    m -= 1
print(max(nums))

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())
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]
s_t = s + t
s_t_unique = get_unique_list(s_t)
results = []
for i in range(len(s_t_unique)):
    s_count = s.count(s_t_unique[i])
    t_count = t.count(s_t_unique[i])
    result = s_count - t_count
    results.append(result)
if max(results) >= 0:
    print(max(results))
else: 
    print(0)

Submission status: Accepted

Solution code:
N = int(input())
S_count = dict()

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

M = int(input())
T_count = dict()

for _ in range(M):
    tmp = input()
    if tmp not in T_count:
        T_count[tmp] = 1
    else:
        T_count[tmp] += 1

max_v = 0

for e in S_count:
    t = 0 if e not in T_count else T_count[e]

    if S_count[e] - t > max_v:
        max_v = S_count[e] - t

print(max_v)

Submission status: Accepted

Solution code:
N = int(input())

red = []
blue = []

for i in range(N):
    red.append(input())

M = int(input())

for j in range(M):
    blue.append(input())
    

words = []
for i in range(N):
    if(red[i] not in words):
        words.append(red[i])

for j in range(M):
    if(blue[j] not in words):
        words.append(blue[j])

maximum = 0
for i in range(len(words)):
    money = red.count(words[i])-blue.count(words[i])
    maximum = max(money,maximum)

if maximum<=0:
    print(0)
else:
    print(maximum)

Submission status: Accepted

Solution code:
from collections import defaultdict

dict=defaultdict(int)

N=int(input())
for i in range(N):
  s=input()
  dict[s]+=1

M=int(input())
for i in range(M):
  s=input()
  dict[s]-=1

ans=0
for a,b in dict.items():
  ans=max(ans,b)
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)] 

Sw = list(set(S))
Tw = list(set(T))

mm = 0
for i in Sw:
    tmp = S.count(i) - T.count(i)
    if mm < tmp:
        mm = tmp

for i in Tw:
    tmp = S.count(i) - T.count(i)
    if mm < tmp:
        mm = tmp

print(mm)

Submission status: Accepted

Solution code:
N = int(input())
list_blue = [input() for i in range(N)]

M = int(input())
list_red = [input() for i in range(M)]

set_blue = set(list_blue)
set_red = set(list_red)
set_union = set_blue | set_red

list_count = [0 for i in range(len(set_union))]
k = 0

for str in set_union:
    for i in range(N):
        if list_blue[i] == str:
            list_count[k] += 1
    for j in range(M):
        if list_red[j] == str:
            list_count[k] -= 1
    k += 1

n_max = max(list_count)

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

Submission status: Accepted

Solution code:
from itertools import groupby

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

def main():
    for t in T:
        if t in S:
            S.remove(t)
    S.sort() # have to sort before using groupby()
    ans = [len(list(g)) for key, g in groupby(S)]
    print(max([0] + ans))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

max_gain = 0
for i in range(N):
    blue = len([s[j] for j in range(N) if s[j] == s[i]])
    red = len([t[j] for j in range(M) if t[j] == s[i]])
    max_gain = max(max_gain, blue - red)

print(max_gain)

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

Submission status: Accepted

Solution code:
from sys import stdin

num_blue = stdin.readline().rstrip()
word_blue = []

for i in range(int(num_blue)) :
    word_blue.append(stdin.readline().rstrip())


num_red = stdin.readline().rstrip()
word_red = []

for i in range(int(num_red)) :
    word_red.append(stdin.readline().rstrip())

counter_max = 0

for i in range(int(num_blue)):
   counter = word_blue.count(word_blue[i]) - word_red.count(word_blue[i])
   if counter > counter_max:
       counter_max = counter
   
print(counter_max)

Submission status: Accepted

Solution code:
n = int(input())
blue = {}
i = 0
while i < n:
    temp = input()
    if temp in blue:
        blue[temp] += 1
    else:
        blue[temp] = 1
    i += 1
#print(blue)

m = int(input())
red = {}
i = 0
while i < m:
    temp = input()
    if temp in red:
        red[temp] += 1
    else:
        red[temp] = 1
    i += 1
#print(red)

max_score = 0
score = 0
for key in blue.keys():
    if key not in red:
        score = blue[key]
    else:
        score = blue[key] - red[key]
    max_score = max(max_score, score)
    
if max_score < 0:
    print(0)
else:
    print(max_score)

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 u in set(S):
    tmp = S.count(u) - T.count(u)
    if ans < tmp:
        ans = tmp
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
dd = defaultdict(int)
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):
    dd[S[i]] += 1
for i in range(M):
    dd[T[i]] += -1
ans = max(dd.values())
print(max(0,ans))

Submission status: Accepted

Solution code:
# -*- Coding: utf-8 -*-
n = int(input())
dict = {}
for i in range(n) :
    s = input()
    if(s in dict.keys()) :
        dict[s]+=1
    else :
        dict[s] = 1
m = int(input())
for i in range(m):
    t = input()
    if(t in dict.keys()) :
        dict[t]-=1
    else :
        dict[t] = -1
print(max(0,max(dict.values())))

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
l = []
for i in range(n):
    l.append(input())
n = int(input())
l2 = []
for i in range(n):
    l2.append(input())
l = Counter(l)
l2 = Counter(l2)
m = [0]
for i in l.keys():
    try:
        m.append(l[i] - l2[i])
    except:
        pass
print(max(m))

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())
    
word = set(S+T)

value = [0]
for w in word:
    value.append(S.count(w)-T.count(w))
    
print(max(value))

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    
    d = {'xxxxxxxx': 0}
    for i in range(0, n):
        s = input().strip()
        if s in d.keys():
            d[s] += 1
        else:
            d[s] = 1
    
    m = int(input())
    
    for i in range(0, m):
        s = input().strip()
        if s in d.keys():
            d[s] -= 1
        else:
            d[s] = -1

    print(max(d.values()) )

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter 
n=int(input())
ap=[input() for i in range(n)]
cp=Counter(ap)
m=int(input())
am=[input() for i in range(m)]
cm=Counter(am)
ans=0
for i in cp:
  ans=max(ans,cp[i]-cm[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())
cnt,ans=0,0
for i in range(n):
    temp=s[i]
    for j in range(n):
        if temp==s[j]:
            cnt+=1
    for j in range(m):
        if temp == t[j]:
            cnt-=1
    ans = max(ans,cnt)
    cnt=0
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
li = [input() for i in range(N)]

M = int(input())
a = 0
li2 = [input() for i in range(M)]

ans = []
for i in li:
    ans.append(max(0,li.count(i) - li2.count(i)))

print(max(ans))

Submission status: Accepted

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

ans=0
for i in range(N):
    kans=0
    for j in range(i,N):
        if s[i]==s[j]:
            kans+=1
    for j in range(M):
        if s[i]==t[j]:
            kans-=1
    if ans<kans:
        ans=kans
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
d = {}
for i in range(N):
  s = input()
  if s in d:
    d[s] += 1
  else:
    d[s] = 1
M = int(input())
for i in range(M):
  s = input()
  if s in d:
    d[s] -= 1
  else:
    d[s] = -1
l = []
for thisKey in d:
  l.append(d[thisKey])
if max(l) >= 0:
  print(max(l))
else:
  print(0)

Submission status: Accepted

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

max = 0
for i in range(n):
    count = 0
    if blue_card[i] in red_card:
        count = blue_card.count(blue_card[i]) - red_card.count(blue_card[i]) 
    else:
        count = blue_card.count(blue_card[i])
    if count >= max:
        max = count
    
print(max)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(raw_input())
a = [raw_input() for _ in range(n)]
c = Counter(a)
m = int(raw_input())
b = [raw_input() for _ in range(m)]
d = Counter(b)
i = 0
for k,ct in c.items():
    j = ct - d[k]
    i = max(i,j)
print i

Submission status: Accepted

Solution code:
score, s, t = 0, [], []
n = int(input())
for i in range(n):
    s.append(input())
m = int(input())
for i in range(m):
    t.append(input())
for c in list(set(s)):
    if(s.count(c) - t.count(c) > score):
        score = s.count(c) - t.count(c)
print(score)

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


max_s = 0
max_t = 0
get = 0

for word in s:
    max_s = s.count(word)
    max_t = t.count(word)
    if(get < max_s - max_t):
        get = max_s - max_t

print(get)

Submission status: Accepted

Solution code:
n = int(input())
s = list()
counter = 0

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

for i in range(m):
    t.append(input())

for word in s:
    counter = max(counter,s.count(word) -t.count(word))
print(counter)

Submission status: Accepted

Solution code:
n = int(input())
s = list()
counter = 0

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

for i in range(m):
    t.append(input())
    
for word in s:
    counter = max(counter,s.count(word) - t.count(word))
    
print(counter)

Submission status: Accepted

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

# 青カードのリスト
blue_count = int(input())
blue_list = []
for i in range(blue_count):
	blue_list.append(input())
# 赤カードのリスト
red_count = int(input())
red_list = []
for i in range(red_count):
	red_list.append(input())

# 全単語リスト作成
all_words = []
# 赤青を連結
all_words.extend(blue_list)
all_words.extend(red_list)
# 重複を削除
all_words = list(set(all_words))

# 全単語でdictを作る
word_dict = {}
for word in all_words:
	word_dict[word] = 0
# 青カード分足す
for word in blue_list:
	word_dict[word] += 1
# 赤カード分引く
for word in red_list:
	word_dict[word] -= 1
# 結果値をリストに
result_list = []
for key, value in word_dict.items():
	result_list.append(value)
# 最大値を算出
result = max(result_list)
# 最大値が0以下なら0
if result <= 0:
	ans = 0
else:
	ans = result

print(ans)

Submission status: Accepted

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

sum_max = 0
for i in range(n):
    sum_tmp = 0
    for j in range(n):
        if s[i] == s[j]:
            sum_tmp += 1
    for j in range(m):
        if s[i] == t[j]:
            sum_tmp -= 1
    if sum_tmp > sum_max:
        sum_max = 0
        sum_max += sum_tmp
print(sum_max)

Submission status: Accepted

Solution code:
D={"":0}
for i in range(input()):
  k=raw_input()
  D[k]=D.setdefault(k,0)+1
for i in range(input()):
  k=raw_input()
  D[k]=D.setdefault(k,0)-1
print max(D.values())

Submission status: Accepted

Solution code:
D = {}
for i in range(input()):
    k = raw_input()
    if not k in D:
        D[k] = 0
    D[k] += 1
for i in range(input()):
    k = raw_input()
    if not k in D:
        D[k] = 0
    D[k] -= 1
print max(0, max(D.values()))

Submission status: Accepted

Solution code:
ps = dict()
ss = []
n = int(input())
for _ in range(n):
    s = input()
    ss.append(s)
    if s in ps:
        ps[s] += 1
    else:
        ps[s] = 1
ts = []
m = int(input())
for _ in range(m):
    s = input()
    ts.append(s)
    if s in ps:
        ps[s] -= 1
    else:
        ps[s] = 1
ans = max(0, max(ps.values()))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

import collections
sc_tc = []
for i in s:
    if s.count(i) - t.count(i)> 0:
        sctc = s.count(i) - t.count(i)
    else:
        sctc = 0
    sc_tc.append(sctc)

print(max(sc_tc))