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:
dic = {}
for i in range(int(input())):
    stri = input()
    if stri in dic:
        dic[stri] += 1
    else:
        dic[stri] = 1

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

maximum = 0

for key in dic:
    if dic[key] > maximum:
        maximum = dic[key]
        
print(maximum)

Submission status: Accepted

Solution code:
n = int(raw_input())
blue = {}
red = {}

for a in range(n):
  q = raw_input()
  if q not in blue:
    blue[q] = 1
    red[q] = 0
  else:
    blue[q] += 1

m = int(raw_input())
for a in range(m):
  q = raw_input()
  if q not in red:
    red[q] = 1
    if q not in blue:
      blue[q] = 0
  else:
    red[q] += 1

ans = 0

for a in blue:
  if ans < (blue[a] - red[a]):
    ans = blue[a] - red[a]
print ans

Submission status: Accepted

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


N = int(input())
p = {}

for _ in range(N):
    s = input()
    if s not in p.keys():
        p[s] = 1
    else:
        p[s] += 1

M = int(input())

for _ in range(M):
    t = input()
    if t not in p.keys():
        p[t] = -1
    else:
        p[t] -= 1

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

Submission status: Accepted

Solution code:
N = int(input())
S_list = []
for _ in range(N):
    S_list.append(input())
M = int(input())
T_list = []
for _ in range(M):
    T_list.append(input())

dict_ = {0: 0}
for s in S_list:
    if s not in dict_.keys():
        dict_[s] = 1
    else:
        dict_[s] += 1
for t in T_list:
    if t not in dict_.keys():
        dict_[t] = -1
    else:
        dict_[t] -= 1

print(max(dict_.values()))

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
p = 0
for i in range(n):
    cnt = 0
    tmp = s[i]
    for j in range(n):
        if s[j] == tmp:
            cnt += 1
    for k in range(m):
        if tmp == t[k]:
            cnt -= 1
    p = max(p,cnt)
print(p)

Submission status: Accepted

Solution code:
n = int(input())
d = {}
for i in range(n):
    a=input()
    if a in d:
        d[a]+=1
    else:
        d[a]=1
m = int(input())
for i in range(m):
    a=input()
    if a in d:
        d[a]-=1
    else:
        d[a]=-1
m=max(d.values())
if m<0:
    m=0
print(m)

Submission status: Accepted

Solution code:
N=int(input())
s=['a']*N
for i in range(N):
	s[i] = input()

M=int(input())
t=['b']*M
for k in range(M):
	t[k] = input()

ans = 0
tmp = 0

for i in range(N):
	tmp = int(s.count(s[i]) - t.count(s[i]))
	if ans < tmp:
		ans = tmp

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
cs = {}
for i in range(n):
    si = input()
    if si in cs:
        cs[si] += 1
    else:
        cs[si] = 1
m = int(input())
ct = {}
for i in range(m):
    ti = input()
    if ti in ct:
        ct[ti] += 1
    else:
        ct[ti] = 1

res = 0
su = 0
for si in cs:
    su = cs[si]
    if si in ct:
        su -= ct[si]
    res = max(su, res)

print(res)

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
targets = list(set(s))
for target in targets:
    ans = max(ans, s.count(target) - t.count(target))

print(ans)

Submission status: Accepted

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

R = int(input())
for i in range(R):
    a = input()
    if a in b:
        b[a] -= 1
    else:
        b[a] = -1
ans = max(b.values())
if max(b.values()) < 0:
    ans = 0

print(ans)

Submission status: Accepted

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

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

sums = {}
for s in array_s:
    if not s in sums:
        sums[s] = 1
    else:
        sums[s] += 1

for t in array_t:
    if t in sums:
        sums[t] -= 1

max_x = 0
for key in sums.keys():
    if max_x < sums[key]:
        max_x = sums[key]

print(max_x)

Submission status: Accepted

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

ans = 0
for key in S:
    if key in T.keys():
        ans_ = S[key] - T[key]
    else:
        ans_ = S[key]
    ans = max(ans, ans_)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
bdict = {}
rdict = {}
for i in range(0, n):
    line = input()
    if not (line in bdict):
        bdict[line] = 0
    bdict[line] += 1
m = int(input())
for i in range(0, m):
    line = input()
    if not (line in rdict):
        rdict[line] = 0
    rdict[line] += 1
ans = 0
temp = 0
for i in bdict.items():
    temp = i[1]
    if i[0] in rdict:
        temp -= rdict[i[0]]
    if temp > ans:
        ans = temp
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())
s_set = list(set(s))
max_s = 0
for i in range(len(s_set)):
    sum_s = 0
    for j in range(N):
        if s_set[i] == s[j]:
            sum_s += 1
    for j in range(M):
        if s_set[i] == t[j]:
            sum_s -= 1
    max_s = max(max_s, sum_s)

print(max_s)

Submission status: Accepted

Solution code:

num = int(input())

score = {}
for i in range(num):
    val = input()
    if val in score.keys():
        score[val] += 1
    else:
        score[val] = 1

num = int(input())
for i in range(num):
    val = input()
    if val in score.keys():
        score[val] -= 1

max_val = 0
for result in score.values():
    if max_val < result:
        max_val = result

print(max_val)

Submission status: Accepted

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

count = [0,]
for s_i in s:
   k = 0
   for i in range(N):
      if s_i == s[i]:
         k += 1
   for i in range(M):
      if s_i == t[i]:
         k -= 1
   count.append(k)


print(max(count))

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

for i in blue:
  bc  = blue.count(i)
  rc = red.count(i)
  if bc-rc>maxyen:
    maxyen = bc-rc
 
print(maxyen)

Submission status: Accepted

Solution code:
data = {}

n = int(input())
for i in range(n):
    string = input()
    if string in data.keys():
        data[string] += 1
    else:
        data[string] = 1

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

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

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

Submission status: Accepted

Solution code:
import sys
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    dic = {}
    for i in range(N):
        input_raw = read_func().strip().split()
        if input_raw[0] in dic:
            dic[input_raw[0]] += 1
        else:
            dic[input_raw[0]] = 1
    input_raw = read_func().strip().split()
    [M] = [int(input_raw[0])]
    for i in range(M):
        input_raw = read_func().strip().split()
        if input_raw[0] in dic:
            dic[input_raw[0]] -= 1

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
lis = []
li = []
ans = 0
for i in range(n):lis.append(str(input()))
m = int(input())
for i in range(m):li.append(str(input()))
for i in range(n):
    cou = lis.count(lis[i])-li.count(lis[i])
    ans = max(ans,cou)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
word_dic = {}
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
        if word_dic[word] < 1:
            word_dic.pop(word)

if len(list(word_dic.keys())) == 0:
    print(0)
else:
    word_dic = sorted(word_dic.items(), key=lambda x: x[1])
    print(word_dic[-1][1])

Submission status: Accepted

Solution code:
from collections import Counter
N=input()
s=[ raw_input() for i in range(N) ]
M=input()
t=[ raw_input() for i in range(M) ]

cs=Counter(s)
ct=Counter(t)

ans=0
for i in cs.keys():
	ans=max(ans, cs[i]-ct[i])

print ans

Submission status: Accepted

Solution code:
rcards = dict()
bcards = dict()
N = int(input())
for i in range(0, N):
    s = input()
    if s not in bcards.keys():
        bcards[s] = 0
    bcards[s] += 1
M = int(input())
for i in range(0, M):
    s = input()
    if s not in rcards.keys():
        rcards[s] = 0
    rcards[s] += 1
ans = int()
for s in bcards.keys():
    tmp = bcards[s]
    if s in rcards.keys():
        tmp -= rcards[s]
    if ans < tmp:
        ans = tmp
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter


def main():
    """
    blue: a, a, d
    red:  a, b, c

    a: 2-1= 1
    b,c: 0-1=-1
    d: 1-0=1
    """
    N = int(input())
    S = [input() for _ in range(N)]
    M = int(input())
    T = [input() for _ in range(M)]

    b = Counter(S)
    r = Counter(T)
    b_r = b - r

    ans = 0
    for word, count in b_r.most_common():
        ans = max(ans, count)
        break

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
words = {}

N = int(input())
for i in range(N):
    s = input()
    point = words.get(s, 0)
    words[s] = point+1

M = int(input())
for i in range(M):
    s = input()
    point = words.get(s, 0)
    words[s] = point-1

result = max(words.items(), key=lambda x:x[1])[1]
if result < 0:
    print(0)
else:
    print(result)

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

Set=set(S)

a=0
A=[0]
for i in Set:
    a=0
    if i in S:
        a+=S.count(i)
    if i in T:
        a-=T.count(i)
    A.append(a)

print(max(A))

Submission status: Accepted

Solution code:
# -- coding: utf-8 --
N = int(input())
dict_res = {}
for i in range(N):
    char = input()
    if not char in dict_res:
        dict_res[char] = 1
    else:
        dict_res[char] += 1
M = int(input())
for i in range(M):
    char = input()
    if not char in dict_res:
        dict_res[char] = -1
    else:
        dict_res[char] -= 1
res = max(dict_res.values())
if res < 0:
    print(0)
else:
    print(res)

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())
max_game = 0
for i in range(n):
    if max_game < s.count(s[i]) - t.count(s[i]):
        max_game = s.count(s[i]) - t.count(s[i])
print(max_game)

Submission status: Accepted

Solution code:
n=int(input())
sslis=[]
snumlis=[]
for i in range(n):
    s=input()
    if s in sslis:
        snumlis[sslis.index(s)]+=1
    else:
        sslis.append(s)
        snumlis.append(1)
m=int(input())
tslis=[]
tnumlis=[]
for i in range(m):
    s=input()
    if s in tslis:
        tnumlis[tslis.index(s)]+=1
    else:
        tslis.append(s)
        tnumlis.append(1)
b=0
for i in range(len(sslis)):
    a=0
    if sslis[i] in tslis:
        a=snumlis[i]-tnumlis[tslis.index(sslis[i])]
    else:
        a=snumlis[i]
    b=max(a,b)
print(b)

Submission status: Accepted

Solution code:
N = int(input())
s_list = []
for i in range(N):
    p = input()
    s_list.append(p)
M = int(input())
t_list = []
for i in range(M):
    p2 = input()
    t_list.append(p2)
s_count_list = [0 for i in range(N)]
#s_listの中身を１つずつ計算しますよ…
for i in range(N):
    name = s_list[i]
    count = 0
    #このnameと同じものを探しカウントする
    for k in range(N):
        if s_list[k] == name:
            count += 1
    for t in range(M):
        if t_list[t] == name:
            count -= 1
    s_count_list[i] = count
max_c = max(s_count_list)
if max_c < 0:
    max_c = 0
print(max_c)

Submission status: Accepted

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

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

count_Max = 0
for l in S_list:
    count = 0
    for m in S_list:
        if m == l:
            count += 1
    for n in T_list:
        if n == l:
            count -= 1

    if count > count_Max:
        count_Max = count
print(count_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())

A = list(set(s))
B = []

for k in range(len(A)):
    B.append(s.count(A[k])-t.count(A[k]))

C = max(B)

if C>0:
    print(C)
else:
    print("0")

Submission status: Accepted

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

count=0
for i in an:
    c=an[i]-bn.get(i,0)
    if c>count:
        count=c
print(count)

Submission status: Accepted

Solution code:
words = {}

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

M = int(input())
for _ in range(M):
    t = input()
    if t in words.keys():
        words[t] -= 1
    else:
        words[t] = -1

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

Submission status: Accepted

Solution code:
from collections import defaultdict

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

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

d = defaultdict(int)
for _s in s:
    d[_s] += 1
for _t in t:
    d[_t] -= 1

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    ss = {}
    tt = {}
    for i in range(n):
        key = input()
        if not key in ss:
            ss[key] = 1
        else:
            ss[key] += 1
    m = int(input())
    for i in range(m):
        key = input()
        if not key in tt:
            tt[key] = 1
        else:
            tt[key] += 1
    ans = 0
    for k, v in ss.items():
        if k in tt:
            ans = max(ans, v - tt[k])
        else:
            ans = max(ans, v)
    print(ans)
main()

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())

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

list_t = []
M = int(input())
for i in range(M):
    list_t += [input()]

counter_s = Counter(list_s)
counter_t = Counter(list_t)

for key, count in counter_t.items():
    if key in counter_s:
        counter_s[key] -= count
    else:
        counter_s[key] = -1 * count

m = max(counter_s.values())

print(m if m > 0 else 0)

Submission status: Accepted

Solution code:
n = int(input())
s = {}
for i in range(n):
    word = input()
    if(word in s):
        s[word] += 1
    else:
        s[word] = 1
m = int(input())
t = {}
for i in range(m):
    word = input()
    if(word in s):
        s[word] -= 1
a = []
for x in s:
    a.append(s[x])
ans = max(a)
if(ans < 0):
    print(0)
else:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict as dd
from pprint import pprint as pp

rs = lambda: input()
ri = lambda: int(input())
ria = lambda: list(map(int, input().split()))
rian = lambda n: [ria() for _ in range(n)]

N = ri()
s = dd(int)
for _ in range(N):
    s[rs()] += 1
M = ri()
t = dd(int)
for _ in range(M):
    t[rs()] += 1

names = set(s.keys()) | set(t.keys()) | set([None])
result = max(s[name] - t[name] for name in names)
print(result)

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())
N_count = Counter(s)
M_count = Counter(t)
ans = 0
for i in N_count.keys():
    temp = N_count[i] -M_count[i]
    if ans <= temp:
        ans = temp
print(ans)

Submission status: Accepted

Solution code:
GI = lambda: int(input()); GIS = lambda: map(int, input().split()); LGIS = lambda: list(GIS())

from collections import Counter
def main():
  ss = Counter(input() for _ in range(GI()))
  ts = Counter(input() for _ in range(GI()))

  for k in ss:
    if k in ts:
      ss[k] -= ts[k]

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

main()

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)]
reward = [0]
for st in s:
    r = s.count(st) - t.count(st)
    reward.append(r)
print(max(reward))

Submission status: Accepted

Solution code:




def main():
    co=0
    n=input()
    n=int(n)
    l1=[]
    l2=[]
    for i in range(n):
        l1.append(input())
    m=input()
    m=int(m)
    for j in range(m):
        l2.append(input())

    for l in l1:
        co=max(co,l1.count(l)-l2.count(l))


    print(co)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import collections

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

n_dict = collections.Counter(n_array)

m = int(input())
m_array = []
for i in range(m):
    m_array.append(input())
m_dict = collections.Counter(m_array)

res = 0
for i, j in n_dict.items():
    if j - m_array.count(i) > res:
        res = j - m_array.count(i)

print(res)

Submission status: Accepted

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

if max(red.values()) <= 0:
    print(0)
else:
    print(max(red.values()))

Submission status: Accepted

Solution code:
count = dict([])
n = int(input().strip())
for _ in range(n):
    key = input()
    if key in count:
        count[key] += 1
    else:
        count[key] = 1
m = int(input().strip())
for _ in range(m):
    key = input()
    if key in count:
        count[key] -= 1
    else:
        count[key] = -1
num = 0
for k, v in count.items():
    if num < v:
        num = v
print(num)

Submission status: Accepted

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

score = 0
for word in s:
	n = s.count(word)
	m = t.count(word)
	if n > m:
		score = max(score, n-m)

print(score)

Submission status: Accepted

Solution code:
n = int(input())
x = [input() for i in range(n)]
m = int(input())
y = [input() for i in range(m)]
z,answer = set(x+y),0
for j in z:
	num = x.count(j)-y.count(j)
	if num > answer:
		answer = num
print(answer)

Submission status: Accepted

Solution code:

from collections import Counter

n = int(input())
N = [input() for i in range(n)]
m = int(input())
M = [input() for i in range(m)]

nc = Counter(N)
mc = Counter(M)

a = set(list(nc.keys())+list(mc.keys()))
ans = 0

for i in a:
    b = nc[i]-mc[i]
    if ans < b:
        ans = b
        
print(ans)

Submission status: Accepted

Solution code:
import collections
c=collections.Counter()
n=int(input())
for _ in range(n):
    c[input()] +=1
m=int(input())
for _ in range(m):
    c[input()] -=1
print(max(0,c.most_common(1)[0][1]))

Submission status: Accepted

Solution code:
N = int(input())
ss = []
for i in range(N):
    ss.append(input())
M = int(input())
ts = []
for i in range(M):
    ts.append(input())
ans = 0
for s in ss:
    tmp = ss.count(s) - ts.count(s)
    if tmp > ans:
        ans = tmp
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

n=int(input())
s=[]
for _ in range(n):
    s.append(input())
m=int(input())
t=[]
for _ in range(m):
    t.append(input())
sc=Counter(s)-Counter(t)
ans=0

for ss in sc.values():
    ans=max(ans,ss)
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
B - Two Colors Card Game
https://beta.atcoder.jp/contests/abc091/tasks/abc091_b

"""
import sys
from sys import stdin
from collections import defaultdict
input = stdin.readline


def main(args):
    words = defaultdict(int)

    N = int(input())
    for _ in range(N):
        w = input().strip()
        words[w] += 1
    M = int(input())
    for _ in range(M):
        w = input().strip()
        words[w] -= 1

    ans = 0
    for k, v in words.items():
        ans = max(ans, v)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

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

U = list(set([''] + S + T))

R = []

for u in U:
    R.append(sum([s == u for s in S]) - sum([t == u for t in T]))

print(max(R))

Submission status: Accepted

Solution code:
d = {}
n = int(raw_input())
for i in range(n):
	s = raw_input()
	if d.get(s) == None:
		d[s] = 1;
	else:
		d[s] += 1;
m = int(raw_input())
for i in range(m):
	s = raw_input()
	if d.get(s) == None:
		d[s] = -1;
	else:
		d[s] -= 1;
ans = -10000000000
for i in d:
	if d[i] > ans:
		ans = d[i];

print max(ans,0);

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
rec = defaultdict(int)
for i in range(n):
    a = input()
    rec[a] += 1
m = int(input())
for i in range(m):
    a = input()
    rec[a] -= 1

q = -100000
for k, v in rec.items():
    if q <= v:
        q = v

print(max(q, 0))

Submission status: Accepted

Solution code:
N = int(input())
A = {}
for i in range(N):
    tmp = input()
    if tmp not in A:
        A[tmp] = 1
    else:
        A[tmp] +=1
M = int(input())
B = {}
for j in range(M):
    tmp = input()
    if tmp not in B:
        B[tmp] = 1
    else:
        B[tmp] +=1
maxV = 0
for k,v in A.items():
    if k in B:
        maxV = max(maxV,v-B[k])
    else:
        maxV = max(maxV,v)
print(maxV)

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

cards = defaultdict(int)
for i in s:
    cards[i] += 1
for j in t:
    cards[j] -= 1

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

Submission status: Accepted

Solution code:
N = int(input())
s = [input() for n in range(N)]
M = int(input())
t = [input() for m in range(M)]
max_coin = 0
for word in s:
    coin = s.count(word) - t.count(word) 
    max_coin = coin if coin > max_coin else max_coin
print(max_coin)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    A = []
    for _ in range(n):
        A.append(input())
    m = int(input())
    B = []
    for _ in range(m):
        B.append(input())
    
    ans = 0
    A_set = list(set(A))
    for i in range(len(A_set)):
        tmp = 0
        for j in range(len(A)):
            if(A_set[i] == A[j]):
                tmp += 1
        for j in range(len(B)): 
            if(A_set[i] == B[j]):
                tmp -= 1
        ans = max(ans, tmp)
    print(ans)

    
if __name__ == "__main__":
    main()

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

c = {}
for s in S:
    c[s] = c.get(s, 0) + 1
for s in T:
    c[s] = c.get(s, 0) - 1

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a=int(input())
x=[]
for i in range(a):
	s=str(input())
	x.append(s)
b=int(input())
y=[]
for i in range(b):
	s=str(input())
	y.append(s)
m=0
for i in range(a):
	a=x.count(x[i])-y.count(x[i])
	if(a>m):
		m=a
print(m)

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())
sset = set(s)
money = 0
for i in sset:
    money = max(money,s.count(i)-t.count(i))
print(money)

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

print(ans)

Submission status: Accepted

Solution code:
import math

n = int(input(""))
blue = []
red = []
for i in range(0,n):
    blue.append(input(""))
m = int(input(""))
for i in range(0,m):
    red.append(input(""))
ans = 0
for i in range(0,n):
    temp = 0
    for str in blue:
        temp += 1 if blue[i] == str else 0
    for str in red:
        temp -= 1 if blue[i] == str else 0
    ans = max(ans,temp)
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)]

result = 0
for s in S:
    score = S.count(s) - T.count(s)
    if result < score:
        result = score
print(result)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

def main():
    blue = [int(input()) for i in range(int(input()))]
    red = [int(input()) for i in range(int(input()))]
    l = list(set(blue))
    print(max(0, max(blue.count(l[i]) - red.count(l[i]) for i in range(len(l)))))


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

T1 = [x+'*' for x in T]
arr = S + T1
list1 = []
for i in range(len(arr)):
  if arr[i] not

list2 = [] in list2:
    s = arr.count(arr[i])
    t = arr.count(arr[i]+'*')
    a = s-t
    list1.append((arr[i], a))
    list2.append(arr[i])

for i in list1:
  
  if i[0].endswith('*'):
    list1.remove(i)
  print(list1)

ans1 = max(list1, key= lambda x:x[1])

if int(ans1[1]) <= 0:
  print(0)
else:
  print(ans1[1])

Submission status: Runtime Error

Solution code:
x = int(input())
a = [input() for i in range(x)]
y = int(input())
b = [input() for h in range(y)]

count_max = 0
for j in a:
  if (a.count(j) - b.count(j)) > count_max:
    a.count(j) - b.count(j) = count_max
print(count_max)

Submission status: Runtime Error

Solution code:
x = int(input())
a = [input() for i in range(x)]
y = int(input())
b = [input() for h in range(y)]

count_max = 0
for j in a:
  if a.count(j) - b.count(j) > count_max:
    a.count(j) - b.count(j) = count_max
print(count_max)

Submission status: Runtime Error

Solution code:
x = int(input())
a = [input() for i in range(x)]
y = int(input())
b = [input() for i in range(y)]

count_max = 0
for i in a:
  if x.count(i) - y.count(i) > count_max:
    x.count(i) - y.count(i) = count_max
print(count_max)