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(raw_input())
blue = []
for i in range(0, N):
	blue.append(raw_input())
wordlist = []
for i in range(0, N):
	if blue[i] not in wordlist: wordlist.append(blue[i])
M = int(raw_input())
red = []
for i in range(0, M):
	red.append(raw_input())

max = 0
for i in range(0, len(wordlist)):
	sum = 0
	for j in range(0, N):
		if wordlist[i] == blue[j]: sum += 1
	for j in range(0, M):
		if wordlist[i] == red[j]: sum -= 1
	if max < sum: max = sum
print max

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

Submission status: Accepted

Solution code:
n=int(input())
s=[input() for _ in range(n)]
m=int(input())
t=[input() for _ in range(m)]
ss=set(s)
answer=[s.count(i)-t.count(i) for i in ss]
print(max(answer) if max(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)]

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

Submission status: Accepted

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


def solve(N: int, s: "List[str]", M: int, t: "List[str]"):
    dic = {}
    for a in s:
        if a in dic:
            dic[a] += 1
        else:
            dic[a] = 1
    for a in t:
        if a in dic:
            dic[a] -= 1
        else:
            dic[a] = -1
    ret = 0
    for val in dic.values():
        ret = max(ret, val)
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [ next(tokens) for _ in range(N) ]  # type: "List[str]"
    M = int(next(tokens))  # type: int
    t = [ next(tokens) for _ in range(M) ]  # type: "List[str]"
    solve(N, s, M, t)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
ad = {}
mi = {}

n = int(input())
for i in range(n):
    s = input()
    n = ad.get(s, 0)
    n += 1
    ad[s] = n

n = int(input())
for i in range(n):
    s = input()
    n = mi.get(s, 0)
    n += 1
    mi[s] = n

res = 0
for k in ad.keys():
    val = ad[k]
    val -= mi.get(k, 0)
    res = max(res, val)

print(res)

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

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:
  cnt1 = S.count(i)
  cnt2 = T.count(i)
  ans = max(cnt1-cnt2,ans)
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)]

ans = 0

for a in S:
    p = S.count(a)
    q = T.count(a)
    ans = max(ans, p - q)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
aoaka = set()
s = []
t = []
for i in range(n):
    new = input()
    s.append(new)
    aoaka.add(new)
m = int(input())
for i in range(m):
    new = input()
    t.append(new)
    aoaka.add(new)
saidai = 0
for i in aoaka:
    cnt = 0
    cnt = cnt + s.count(i) - t.count(i)
    saidai = max(saidai,cnt)
print(saidai)

Submission status: Accepted

Solution code:
import collections

blue = int(input())
blue_string = [input() for i in range(blue)]
blue_type = set(blue_string)
red = int(input())
red_string = [input() for i in range(red)]
red_type = set(red_string)
result = [0]

for i in blue_type:
    bulue_sort_count = blue_string.count(i)
    red_sort_count = red_string.count(i)
    result.append(bulue_sort_count - red_sort_count )
print(max(result))

Submission status: Accepted

Solution code:
import collections

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_col = collections.Counter(s)
t_col = collections.Counter(t)

s_com = s_col.most_common()
t_com = t_col.most_common()

ans = []

for item in s:
    try:
        ans.append(s_col[item] - t_col[item])
    except:
        ans.append(s_col[item])

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s_dic = {}
for _ in range(int(input())):
    s = input()
    if not s in s_dic.keys():s_dic[s] = 1
    else:s_dic[s] += 1
for _ in range(int(input())):
    t = input()
    if t in s_dic.keys():s_dic[t] -= 1
print(max(0,max(s_dic.values())))

Submission status: Accepted

Solution code:
import collections

n = int(input())
s = [input() for i in range(n)]
m = int(input())
t = [input() for i in range(m)]
c = collections.Counter(s)
d = collections.Counter(t)
counter = c -d
try:
        print(counter.most_common(1)[0][1])
except IndexError:
        print("0")

Submission status: Accepted

Solution code:
# 入力
N=int(input())

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

M=int(input())

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

# 考えられる最低得点で初期化
mx=-len(l2)

for x in l1:
  # 得点
  a=l1.count(x)

  # 失点
  b=l2.count(x)

  mx=max(mx,a-b)

# 得点が負だった場合は0を出力
print(max(mx,0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


class UnionFind:

    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, i):
        if self.parent[i] == i:
            return i
        self.parent[i] = self.root(self.parent[i])
        return self.parent[i]

    def unite(self, i, j):
        rooti = self.root(i)
        rootj = self.root(j)
        if rooti == rootj:
            return
        if rooti < rootj:
            self.parent[rootj] = rooti
        else:
            self.parent[rooti] = rootj

    def same(self, i, j):
        return self.root(i) == self.root(j)


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


def main():
    n = intin()
    slist = [input() for _ in range(n)]
    m = intin()
    tlist = [input() for _ in range(m)]

    counts = defaultdict(int)
    for s in slist:
        counts[s] += 1

    for t in tlist:
        counts[t] -= 1

    ans = 0
    for s, count in counts.items():
        ans = max(ans, count)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from sys import stdin
N=int(stdin.readline().rstrip())

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

M=int(stdin.readline().rstrip())

red=[]
for j in range(M):
    red.append((input()))

ans = len(set(blue)) * [0]
for ind,k in enumerate(set(blue)):
    ans[ind] = blue.count(k) - red.count(k)

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

Submission status: Accepted

Solution code:
#B

n = int(input())
w = []
sn = []
tn = []
for _ in range(n):
    s = input()
    f = True
    for i in range(len(w)):
        if w[i] == s:
            sn[i] += 1
            f = False
            break
    if f:
        w.append(s)
        sn.append(1)
        tn.append(0)
        
m = int(input())
for _ in range(m):
    t = input()
    f = True
    for i in range(len(w)):
        if w[i] == t:
            tn[i] += 1
            f = False
            break
    if f:
        w.append(t)
        tn.append(1)
        sn.append(0)
        
#print(sn,tn)
        
print(max([sn[i]-tn[i] for i in range(len(w))]+[0]))

Submission status: Accepted

Solution code:
n=int(input())
a=[]
b=[]
c=[]

for i in range(n):
    a.append(str(input()))
m=int(input())
for s in range(m):
    b.append(str(input()))
for k in range(n):
    c.append(a.count(a[k])-b.count(a[k]))
for l in range(m):
    c.append(a.count(b[l]) - b.count(b[l]))
c.append(0)
print(max(c))

Submission status: Accepted

Solution code:
ifhesay={}
def say(word,add):
	if word in ifhesay:
		ifhesay[word]+=add
	else:
		ifhesay[word]=add

n=int(input())

for i in range(n):
	say(input(),1)

m=int(input())

for i in range(m):
	say(input(),-1)

max=0

for k in ifhesay:
	v=ifhesay[k]
	if v>max:
		max=v
print(max)

Submission status: Accepted

Solution code:
import collections

N = int(input())
S = [input() for s in range(N)]
M = int(input())
T = [input() for t in range(M)]
S_counter = collections.Counter(S)
T_counter = collections.Counter(T)

for k, v in S_counter.items():
    if k in T_counter:
        S_counter[k] = S_counter[k] - T_counter[k] if (S_counter[k] - T_counter[k]) > 0 else 0

print(max(S_counter.values()))

Submission status: Accepted

Solution code:
import collections
N = int(input())
s = [input() for _ in range(N)]
M = int(input())
t = [input() for _ in range(M)]
cs = collections.Counter(s)
ct = collections.Counter(t)
points = 0
for key in cs.keys():
    points = max(points, cs[key] - ct[key])
print(points)

Submission status: Accepted

Solution code:
from collections import Counter as cnt

N = int(input())
counter = {}
for i in range(N):
  s = input()
  if s not in counter:
    counter[s] = [1,0]
  else:
    counter[s][0] += 1
N = int(input())
for i in range(N):
  s = input()
  if s not in counter:
    counter[s] = [0,1]
  else:
    counter[s][1] += 1
counter[0] = [0,0]

print(max([b-r for b,r in counter.values()]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [input() for _ in range(n)]
m = int(input())
b = [input() for _ in range(m)]
words = list(set(a) or set(b))
ans = 0

for word in words:
    ans = max(ans, a.count(word) - b.count(word))
print(ans)

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


mine = 0
    
flags = [1] * N

for i in range(N):
    plus = 1
    minus = 0
    
    if flags[i] == 0:
        continue
        
    if flags[i] == 1:
        flags[i] = 0
    
    for j in range(i+1, N):
        if s[i] == s[j]:
            plus += 1
            flags[j] = 0
            
    for k in range(M):
        if s[i] == t[k]:
            minus += 1
            
    mine = max([mine, plus - minus]) 

    
print(mine)

Submission status: Accepted

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

maxlist=[0]
for i in range(n):
    mx=0
    for j in range(n):
        if a[i]==a[j]:
            mx+=1
    for k in range(m):
        if a[i]==t[k]:
            mx-=1
    maxlist.append(mx)

print(max(maxlist))

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

print(max(kari))

Submission status: Accepted

Solution code:
N = int(input())
s = [input() for _ in range(N)]
M = int(input())
t = [input() for _ in range(M)]
ans = 0
for i in range(N):
    tmp = s[i]
    cnt = 0
    for i in range(N):
        if tmp == s[i]:
            cnt += 1
    for j in range(M):
        if tmp == t[j]:
            cnt -= 1
    ans = max(ans,cnt)
      
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)]

res={}

for i in s:
    res[i] = res.get(i, 0) + 1

for i in t:
    res[i] = res.get(i, 0) - 1

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

Submission status: Accepted

Solution code:
import collections

blue = [input() for i in range(int(input()))]
red = [input() for i in range(int(input()))]

blue_c = collections.Counter(blue)
red_c = collections.Counter(red)

ans = 0

blue_s = set(blue)

for i in blue_s:
    if blue_c[i] - red_c[i] > ans:
        ans = blue_c[i] - red_c[i]
        
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

def main():
    data = defaultdict(int)

    num = int(input())
    for i in range(num):
        aaa = input()
        data[aaa] += 1

    num = int(input())
    for i in range(num):
        aaa = input()
        data[aaa] -= 1

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




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
S = Counter([input() for _ in range(N)])
M = int(input())
T = Counter([input() for _ in range(M)])
print(max((S - T).values()) if len(S - T) > 0 else 0)

Submission status: Accepted

Solution code:
# 2019/05/16
# AtCoder Beginner Contest 091 - B

# Input
n = int(input())
bc = list()
for i in range(n):
    bc.append(input())

m = int(input())
rc = list()
for j in range(m):
    rc.append(input())

bc.sort()
rc.sort()

# Count up
strdict = dict()
wk_str = bc[0]
wk_cnt = 1
for i in range(1, n):
    if wk_str != bc[i]:
        strdict[wk_str] = wk_cnt
        wk_cnt = 1
        wk_str = bc[i]
    else:
        wk_cnt += 1

strdict[wk_str] = wk_cnt

wk_str = rc[0]
wk_cnt = 1

for j in range(1, m):
    if wk_str != rc[j]:
        if strdict.get(wk_str) == None:
            strdict[wk_str] = wk_cnt * -1
        else:
            strdict[wk_str] += wk_cnt * -1
        wk_cnt = 1
        wk_str = rc[j]
    else:
        wk_cnt += 1

if strdict.get(wk_str) == None:
    strdict[wk_str] = wk_cnt * -1
else:
    strdict[wk_str] += wk_cnt * -1

# Search max
maxval = -101
for k in strdict.keys():
    if maxval < strdict[k]:
        maxval = strdict[k]

ans = max(maxval, 0)

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=[input() for i in range(n)]
m=int(input())
t=[input() for j in range(m)]
ans=0
for i in range(n):
  count=0
  for ii in range(n):
    if s[i]==s[ii]:
      count+=1
  for jj in range(m):
    if s[i]==t[jj]:
      count-=1
  ans=max(count,ans)
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)]
ans = 0
for i in s:
  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())
b = []
r = []
all_l = []
for i in range(N):
  tmp = input()
  b.append(tmp)
  all_l.append(tmp)
N = int(input())
for i in range(N):
  tmp = input()
  r.append(tmp)
  all_l.append(tmp)
all_l = list(set(all_l))
ans = 0
for i in all_l:
  ans = max(ans, b.count(i)-r.count(i))
print(ans)

Submission status: Accepted

Solution code:
n0 = int(input()) 
t0 = [input() for i in range(n0)] 
n1 = int(input()) 
t1 = [input() for i in range(n1)] 
s = set(t0) | set(t1)
l = max([sum([1 for x0 in t0 if x0 == i]) - sum([1 for x1 in t1 if x1 == i]) for i in s])
print(max(l,0))

Submission status: Accepted

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

    
print(max(K))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
b = [input() for i in range(n)]
m = int(input())
r = [input() for j in range(m)]
ans = 0
for i in b:
    if b.count(i)-r.count(i) > ans:
        ans = b.count(i)-r.count(i)            
print(ans)

Submission status: Accepted

Solution code:
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 = {s: S.count(s) for s in S}
T = {t: T.count(t) for t in T}

ans = 0
for s in S:
    adv = S[s] - T.get(s, 0)
    ans = max(ans, adv)
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)]

print(max([s.count(S) - t.count(S) for S in s]+[0]))

Submission status: Accepted

Solution code:
N = int(input())
S = {'__min__': 0}
for _ in range(N):
    s = input()
    if S.get(s) == None:
        S[s] = 1
    else:
        S[s] += 1

M = int(input())
for _ in range(M):
    t = input()
    if S.get(t) == None:
        continue
    elif S[t] <= 1:
        S.pop(t)
    else:
        S[t] -= 1

print(max(S.values()))

Submission status: Accepted

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

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

cnt = 0

for i in s:
    x = s.count(i) - t.count(i)
    cnt = max(cnt,x)

print(cnt)

Submission status: Accepted

Solution code:
from collections import defaultdict


s_box = defaultdict(int)
t_box = defaultdict(int)

N = int(input())
s = [str(input()) for i in range(N)]
M = int(input())
t = [str(input()) for j in range(M)]

for key in s:
    s_box[key] += 1
for key in t:
    t_box[key] += 1

ans = []

for k, v in t_box.items():
    s_box[k] -= v

for v in s_box.values():
    ans.append(v)

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

Submission status: Accepted

Solution code:
n=int(input())
ans={}
for i in range(n):
    s=input()
    ans[s]=ans.get(s,0)+1
m=int(input())
for i in range(m):
    t=input()
    ans[t]=ans.get(t,0)-1
print(max(ans.values()) if max(ans.values())>0 else 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())
ans = 0
for key in s:
  if s.count(key)-t.count(key) > ans:
    ans = s.count(key)-t.count(key)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

sset = list(set(s))
imax = 0
for i in range(len(sset)):
    if imax < s.count(sset[i]) - t.count(sset[i]):
        imax = s.count(sset[i]) - t.count(sset[i])
print(imax)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict
dicS = defaultdict(lambda: 0)
dicT = defaultdict(lambda: 0)
N = int(input())
S=[input() for i in range(N)]
M = int(input())
T=[input() for i in range(M)]
for s in S:
    dicS[s]+=1
for t in T:
    dicT[t]+=1
ans=0
for word, cnt in dicS.items():
    ans = max(ans, cnt-dicT[word])
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
import random

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

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

# 単語数が辞書で帰ってくる
count_s = Counter(s)

for t in range(len(T)):
    if T[t] in count_s:
        count_s[T[t]] -= 1
    else:
        count_s[T[t]] = -1

count_s[str(random.random())] = 0

print(max(count_s.values()))

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    g = {}
    for i in range(n):
        s = input()
        if s in g:
            g[s] += 1
        else:
            g[s] = 1
    
    m = f()[0]
    for i in range(m):
        s = input()
        if s in g:
            g[s] -= 1
        else:
            g[s] = -1

    mxv = 0
    for k,v in g.items():
        mxv = max(mxv, v)
    
    print(mxv)

solve()

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_s = set(s)
ans = 0

for i in set_s:
    ans = max(ans, s.count(i) - t.count(i))

print(ans)

Submission status: Accepted

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

set_s = set(blue_card)
max_v = 0
for s in set_s:  
  num = blue_card.count(s) - red_card.count(s)
  max_v = max(max_v, num)
print(max(0, max_v))

Submission status: Accepted

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

result = 0

for i in set(blue):
    x = blue.count(i) - red.count(i)
    if x > 0 and x > result:
        result = x

print(result)

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))
l=[]
for i in s:
    l+=[s.count(i)-t.count(i)]
print(max(max(l),0))

Submission status: Accepted

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

st_list=list(set(s_list)|set(t_list))
ans_list=[]
for k in range(len(st_list)):
    ans_list.append(s_list.count(st_list[k])-t_list.count(st_list[k]))

ans_list.sort()
if ans_list[-1]>=0:
    ans=ans_list[-1]
else:
    ans=0
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)]
l = list(set(S))
ans = 0
for i in range(len(l)):
    ans = max(S.count(l[i])-T.count(l[i]),ans)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

s = [input() for _ in range(N)]
u = list(set(s))

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

v = []
for i in range(len(u)):
  v.append(s.count(u[i]) - t.count(u[i]))
  
print(max(v) if max(v) >= 0 else 0)

Submission status: Accepted

Solution code:
from collections import Counter
def main(s, t):
    s_c = sorted(Counter(s).items(), key=lambda x: -x[1])
    t_c = Counter(t)
    tmp = 0
    for k, v in s_c:
        minus = t_c[k] if k in t_c.keys() else 0
        tmp = max(tmp, v - minus)
    print(tmp)

if __name__ == '__main__':
    N = int(input().strip())
    s = [input().strip() for _ in range(N)]
    M = int(input().strip())
    t = [input().strip() for _ in range(M)]
    main(s, t)

Submission status: Accepted

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

M = int(input())
t = []
for j in range(M):
    t += [str(input())]


ans = 0
for k in s:
    ans = max(ans, s.count(k) - t.count(k))
print (ans)

Submission status: Accepted

Solution code:
s=[]
t=[]
check=[]
cnt=0
max=0
B=int(input())
s=[input() for i in range(B)]
R=int(input())
t=[input() for i in range(R)]
s.sort()
check=list(set(s))

for i in range(len(check)):
	for j in range(R):
		if check[i]==t[j]:
			cnt+=1
	if max<s.count(check[i])-cnt:
		max=s.count(check[i])-cnt
	cnt=0

print(max)

Submission status: Accepted

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

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



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

Submission status: Accepted

Solution code:

from collections import defaultdict

def read_input():
    n = int(input())
    blue_cards = []
    for i in range(n):
        blue_cards.append(input())

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

    return n, m, blue_cards, red_cards

def submit():
    n, m, blue_cards, red_cards = read_input()

    blue_file = defaultdict(int)
    for b in blue_cards:
        blue_file[b] += 1

    red_file = defaultdict(int)
    for r in red_cards:
        red_file[r] += 1

    all_words = set(list(blue_file.keys()) + list(red_file.keys()))

    x = 0
    for word in all_words:
        p = blue_file[word] - red_file[word]
        if p > x:
            x = p

    print(x)



if __name__ == '__main__':
    submit()

Submission status: Accepted

Solution code:
from collections import Counter

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

ma = 0
for s in S.keys():
    if s in T:
        ma = max(ma, S[s] - T[s])
    else:
        ma = max(ma, S[s])

print(ma)

Submission status: Accepted

Solution code:
from collections import Counter

st1 = Counter([input() for _ in range(int(input()))])
st2 = Counter([input() for _ in range(int(input()))])

print(max(0, max([st1[key] - st2[key] for key in st1.keys()])))

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
st1 = [input() for _ in range(n)]
m = int(input())
st2 = [input() for _ in range(m)]

st1_cnt = Counter(st1)
st2_cnt = Counter(st2)

gain = []
for key in st1_cnt.keys():
    gain.append(st1_cnt[key] - st2_cnt[key])
gain.append(0)

print(max(gain))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
n=[]
S=set()
for i in range(N):
  A=input()
  n.append(A)
  S.add(A)
M=int(input())
m=[]
for i in range(M):
  A=input()
  m.append(A)
  S.add(A)
P=[0]
for i in S:
  P.append(n.count(i)-m.count(i))
print(max(P))

Submission status: Accepted

Solution code:
# ABC091B - Two Colors Card Game
n = int(input())
lst_1 = [input().rstrip() for _ in range(n)]
set_1 = set(lst_1)
m = int(input())
lst_2 = [input().rstrip() for _ in range(m)]
count = 0

for i in set_1:
    count = max(count, lst_1.count(i) - lst_2.count(i))

print(count)