Problem:


Score : 200 points

Problem Statement

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

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

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

At most how much can he earn on balance?

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

Constraints

N and M are integers.

1 \leq N, M \leq 100

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

Input

Input is given from Standard Input in the following format:

N
s_1
s_2
:
s_N
M
t_1
t_2
:
t_M

Output

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

Sample Input 1

3
apple
orange
apple
1
grape

Sample Output 1

2

He can earn 2 yen by announcing apple.

Sample Input 2

3
apple
orange
apple
5
apple
apple
apple
apple
apple

Sample Output 2

1

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

Sample Input 3

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

Sample Output 3

0

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

Sample Input 4

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

Sample Output 4

1



Sample input:
3
apple
orange
apple
1
grape


Sample output:
2

Submission status: Accepted

Solution code:
from collections import Counter
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
s = [readline().decode().rstrip() for _ in range(n)]
m = int(readline())
t = [readline().decode().rstrip() for _ in range(m)]

sc = Counter(s)
tc = Counter(t)
ans = 0
for k, v in sc.items():
    if k in tc.keys():
        ans = max(ans, v-tc[k])
    else:
        ans = max(ans, v)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ds = {"hoge" : 0}
dt = {"hoge" : 0}
a = set()
for i in range(n):
    s = input()
    if s not in a:
        a.add(s)
        ds[s] =1
        dt[s] = 0
    else:
        ds[s] += 1
m = int(input())
for i in range(m):
    t = input()
    if t not in a:
        a.add(t)
        ds[t] = 0
        dt[t] = 1
    else:
        dt[t] += 1
b = 0
for i in a:
    c = ds[i] - dt[i]
    if b <= c:
        b = c
print(b)

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for _ in range(n)]
set_s = list(set(s))
m = int(input())
t = [input() for _ in range(m)]
ans = [s.count(set_s[i]) - t.count(set_s[i]) for i in range(len(set_s))]
print(max(0, max(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)]

from collections import Counter
CS = Counter(S)
CT = Counter(T)
maxv = 0
for k, v in CS.items():
	maxv = max(maxv, v - CT[k])
print(maxv)

Submission status: Accepted

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

Submission status: Accepted

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

reward = [0]
for st in s:
    r = s.count(st) - t.count(st)
    reward.append(r)
print(max(reward))

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
s = [input() for _ in range(N)]
M = INT()
t = [input() for _ in range(M)]
dic_s = defaultdict(int)
dic_t = defaultdict(int)
for st in s:
	dic_s[st] += 1
for st in t:
	dic_t[st] += 1

ans = 0
for st in dic_s:
	ans = max(ans, dic_s[st]-dic_t[st])
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
slist=[]
sset=set()
for i in range(n):
    slist.append(input())
    sset.add(slist[i])
m=int(input())
ans=0
mlist=[]
for i in range(m):
    mlist.append(input())
for i in range(len(sset)):
    sstr=sset.pop()
    snum=slist.count(sstr)
    mnum=mlist.count(sstr)
    num=snum-mnum
    if num>ans:
        ans=num
print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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

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

ans = 0
for x in Plus:
	ans = max(ans, Plus[x]-Minus[x])

print(ans)

Submission status: Accepted

Solution code:
import collections

n = int(input())
s = [input() for x in range(n)]
m = int(input())
t = [input() for y in range(m)]
ans = 0

S = collections.Counter(s)
T = collections.Counter(t)

for k, v in S.items():
    tmp = 0
    tmp = v
    if k in T:
        tmp -= T[k]
    ans = max(ans, tmp)

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

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

print(max(max(d.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)]

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
S = Counter([input() for i in range(n)])
m = int(input())
T = Counter([input() for i in range(m)])

ans = 0
for k, v in S.items():
    tmp = v
    if k in T:
        tmp -= T[k]
    ans = max(ans, tmp)
            
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:
    ans = max(ans, s.count(i) - t.count(i))

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
cards = defaultdict(int)
n = int(input())
for i in range(n):
  s = input()
  cards[s] += 1

m = int(input())
for i in range(m):
  t = input()
  cards[t] -= 1

max_c = -float('inf')
for v in cards.values():
  max_c = max(max_c, v)
print(max(0, max_c))

Submission status: Accepted

Solution code:
a=[input() for _ in range(int(input()))]
for _ in range(int(input())):
    t=input()
    if t in a:
        a.remove(t)
d={}
for i in a:
  d[i]=d.get(i,0)+1
print(max(d.values()) if a else 0)

Submission status: Accepted

Solution code:
ans = 0
N = int(input())
S = list(input() for _ in range(N))
M = int(input())
T = list(input() for _ in range(M))
for i in range(N):
    ans = max(ans,S.count(S[i])-T.count(S[i]))
print(ans)

Submission status: Accepted

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

def main():
    Res = {}
    N = int(input())
    for i in range(N):
        x=input()
        if x in Res:
            Res[x]+=1
        else:
            Res[x]=1
    M = int(input())
    for i in range(M):
        x=input()
        if x in Res:
            Res[x]-=1
        else:
            Res[x]=-1
    dics = sorted(Res.items(), key=lambda x:x[1], reverse = True)[0]
    print(max(0,dics[1]))

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

Submission status: Accepted

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

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

ans=0
for word in b:
    tmp=0
    for j in range(len(b)):
        if b[j]==word:
            tmp+=1
    for j in range(len(r)):
        if r[j]==word:
            tmp-=1
    if tmp>ans:
        ans=tmp
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)]
dict = {}
for ss in s :
    if ss in dict :
        dict[ss] += 1
    else :
        dict[ss] = 1
for tt in t:
    if tt in dict:
        dict[tt] -= 1
print(max(list(dict.values())+[0]))

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for _ in range(N)]
M = int(input())
T = [input() for _ in range(M)]
sm = {}
for s in S:
    if s in sm:
        sm[s] += 1
    else:
        sm[s] = 1
for t in T:
    if t in sm:
        sm[t] -= 1
print(max(list(sm.values())+[0]))

Submission status: Accepted

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

for i in range(n):
    a.append(input())
m=int(input())
for i in range(m):
    b.append(input())
for i in a:
    if i not in b:
        ans=max(ans,a.count(i))
    else:
        ans=max(ans,a.count(i)-b.count(i))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    d = defaultdict(int)
    n = ii()
    for _ in range(n):
        s = input()
        d[s] += 1
    m = ii()
    for _ in range(m):
        t = input()
        d[t] -= 1
    
    print(max(0, max(d.values())))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

from collections import defaultdict
d=defaultdict(int)
for plus_word in s:
    d[plus_word]+=1
for minus_word in t:
    d[minus_word]-=1

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

Submission status: Accepted

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

m = -101
for i in range(n):
    m = max(m,c[s[i]]-d[s[i]])
for i in range(n):
    m = max(m,c[s[i]]-d[s[i]])
print(max(m,0))

Submission status: Accepted

Solution code:
from collections import defaultdict

words = defaultdict(int)
for _ in range(int(input())):
    words[input()] += 1
for _ in range(int(input())):
    words[input()] -= 1
print(max([x for x in words.values()] + [0]))

Submission status: Accepted

Solution code:
from collections import defaultdict

words = set()
blue = defaultdict(int)
red = defaultdict(int)
for _ in range(int(input())):
    w = input()
    words.add(w)
    blue[w] += 1
for _ in range(int(input())):
    w = input()
    words.add(w)
    red[w] += 1
ans = 0
for w in words:
    ans = max(ans, blue[w] - red[w])
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

cards = {

}

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

m = int(input())

for r in range(m):
    word = input()
    if word not in cards:
        cards[word] = -1
    else:
        cards[word] -= 1

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

Submission status: Accepted

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#

def main():
    n = II()
    ss = Counter([IS() for _ in range(n)])
    m = II()
    tt = Counter([IS() for _ in range(m)])
    tt_key = set(tt.keys())
    maxv = 0
    for s, c in ss.items():
        cnt = c
        if s in tt_key:
            cnt -= tt[s]
        maxv = max(maxv, cnt)
    print(maxv)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in ss:
    if i not in t:
        ans = max(ans, s.count(i))
    else:
        ans = max(ans, s.count(i)-t.count(i))
print(ans)

Submission status: Accepted

Solution code:
import collections,sys
def I(): return int(sys.stdin.readline().rstrip())
def S(): return sys.stdin.readline().rstrip()
s = [S() for _ in range(I())]
t = [S() for _ in range(I())]
ans = 0
count_s = collections.defaultdict(int)
count_t = collections.defaultdict(int)
for x in s:
    count_s[x] += 1
for y in t:
    count_t[y] += 1
for k,v in count_s.items():
    ans = max(ans,v-count_t[k])
print(ans)

Submission status: Accepted

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

# input
N = int(input())
blue = {}
for _ in range(N):
    s = input()
    if s not in blue:
        blue[s] = 1
    else:
        blue[s] += 1

M = int(input())
red = {}
for _ in range(M):
    s = input()
    if s not in red:
        red[s] = 1
    else:
        red[s] += 1

# solve
max_point = 0

for s, blue_count in blue.items():
    red_count = red.get(s) or 0
    point = blue_count - red_count

    if point > max_point:
        max_point = point

print(max_point)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    s=[input() for i in range(N)]
    M=int(input())
    t=[input() for i in range(M)]
    ans=0
    for a in set(s):
        ans=max(ans,s.count(a)-t.count(a))
    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)]

A = 0
for i in S:
    A = max(S.count(i)  - T.count(i), A)

print(A)

Submission status: Accepted

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

from collections import Counter

sc=Counter(s)
tc=Counter(t)

ans=0
for i,j in sc.items():
  tmp=j-tc[i]
  if tmp>0:
    ans=max(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())
c_s = Counter(s)
c_t = Counter(t)

candidates = [0]

for k in c_s.keys():
  candidates.append(c_s[k]-c_t[k])
print(max(candidates))

Submission status: Accepted

Solution code:
import sys,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(n,base=2):
    rt=[]
    for tb in range(base**n):s=[tb//(base**bt)%base for bt in range(n)];rt+=[s]
    return rt
def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)
 
YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb))
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

class Tree:
    def __init__(self,inp_size=None,ls=None,init=True,index=0):
        self.LCA_init_stat=False
        self.ETtable=[]
        if init:
            if ls==None:
                self.stdin(inp_size,index=index)
            else:
                self.size=len(ls)+1
                self.edges,_=GI(self.size,self.size-1,ls,index=index)
        return
 
    def stdin(self,inp_size=None,index=1):
        if inp_size==None:
            self.size=int(input())
        else:
            self.size=inp_size
        self.edges,_=GI(self.size,self.size-1,index=index)
        return
    
    def listin(self,ls,index=0):
        self.size=len(ls)+1
        self.edges,_=GI(self.size,self.size-1,ls,index=index)
        return
 
    def __str__(self):
        return  str(self.edges)
 
    def dfs(self,x,func=lambda prv,nx,dist:prv+dist,root_v=0):
        q=deque()
        q.append(x)
        v=[-1]*self.size
        v[x]=root_v
        while q:
            c=q.pop()
            for nb,d in self.edges[c]:
                if v[nb]==-1:
                    q.append(nb)
                    v[nb]=func(v[c],nb,d)
        return v
 
    def EulerTour(self,x):
        q=deque()
        q.append(x)
        self.depth=[None]*self.size
        self.depth[x]=0
        self.ETtable=[]
        self.ETdepth=[]
        self.ETin=[-1]*self.size
        self.ETout=[-1]*self.size
        cnt=0
        while q:
            c=q.pop()
            if c<0:
                ce=~c
            else:
                ce=c
                for nb,d in self.edges[ce]:
                    if self.depth[nb]==None:
                        q.append(~ce)
                        q.append(nb)
                        self.depth[nb]=self.depth[ce]+1
            self.ETtable.append(ce)
            self.ETdepth.append(self.depth[ce])
            if self.ETin[ce]==-1:
                self.ETin[ce]=cnt
            else:
                self.ETout[ce]=cnt
            cnt+=1
        return
    
    def LCA_init(self,root):
        self.EulerTour(root)
        self.st=SparseTable(self.ETdepth,init_func=min,init_idl=inf)
        self.LCA_init_stat=True
        return
    
    def LCA(self,root,x,y):
        if self.LCA_init_stat==False:
            self.LCA_init(root)
        xin,xout=self.ETin[x],self.ETout[x]
        yin,yout=self.ETin[y],self.ETout[y]
        a=min(xin,yin)
        b=max(xout,yout,xin,yin)
        id_of_min_dep_in_et=self.st.query_id(a,b+1)
        return self.ETtable[id_of_min_dep_in_et]
 
class SparseTable: # O(N log N) for init, O(1) for query(l,r)
    def __init__(self,ls,init_func=min,init_idl=float('inf')):
        self.func=init_func
        self.idl=init_idl
        self.size=len(ls)
        self.N0=self.size.bit_length()
        self.table=[ls[:]]
        self.index=[list(range(self.size))]
        self.lg=[0]*(self.size+1)
        
        for i in range(2,self.size+1):
            self.lg[i]=self.lg[i>>1]+1
 
        for i in range(self.N0):
            tmp=[self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) for j in range(self.size)]
            tmp_id=[self.index[i][j] if self.table[i][j]==self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) else self.index[i][min(j+(1<<i),self.size-1)] for j in range(self.size)]
            self.table+=[tmp]
            self.index+=[tmp_id]
    
    # return func of [l,r)
    def query(self,l,r):
        if r>self.size:r=self.size
        #N=(r-l).bit_length()-1
        N=self.lg[r-l]
        return self.func(self.table[N][l],self.table[N][max(0,r-(1<<N))])
    
    # return index of which val[i] = func of v among [l,r)
    def query_id(self,l,r):
        if r>self.size:r=self.size
        #N=(r-l).bit_length()-1
        N=self.lg[r-l]
        a,b=self.index[N][l],self.index[N][max(0,r-(1<<N))]
        if self.table[0][a]==self.func(self.table[N][l],self.table[N][max(0,r-(1<<N))]):
            b=a
        return b
    
    def __str__(self):
        return str(self.table[0])
 
    def print(self):
        for i in self.table:
            print(*i)
 
class Comb:
    def __init__(self,n,mo=10**9+7):
        self.fac=[0]*(n+1)
        self.inv=[1]*(n+1)
        self.fac[0]=1
        self.fact(n)
        for i in range(1,n+1):
            self.fac[i]=i*self.fac[i-1]%mo
            self.inv[n]*=i
            self.inv[n]%=mo
        self.inv[n]=pow(self.inv[n],mo-2,mo)
        for i in range(1,n):
            self.inv[n-i]=self.inv[n-i+1]*(n-i+1)%mo
        return
    
    def fact(self,n):
        return self.fac[n]
        
    def invf(self,n):
        return self.inv[n]
 
    def comb(self,x,y):
        if y<0 or y>x:
            return 0
        return self.fac[x]*self.inv[x-y]*self.inv[y]%mo

def dijkstra(edge,st):
    # edge=[[(v_to,dist_to_v),...],[],...]
    # initialize: def: d=dist(st,i), prev=[previous vertex in minimum path], q[]
    n=len(edge)
    d=[(0 if st==i else inf) for i in range(n)]
    prev=[0]*n
    q=[(j,i) for i,j in enumerate(d)]
    heapify(q)
    v=[False]*n
    # calc
    while q:
        dist,cur=heappop(q)
        if v[cur]:
            continue
        v[cur]=True
        for dst,dist in edge[cur]:
            alt=d[cur]+dist
            if alt<d[dst]:
                d[dst]=alt
                prev[dst]=cur
                heappush(q,(alt,dst))
    return d,prev


show_flg=False
show_flg=True
ans=0

p=defaultdict(int)

n=I()
for i in range(n):
    p[input()]+=1

m=I()
for i in range(m):
    p[input()]-=1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
dic = Counter()
for _ in range(N):
  dic[input()] += 1
M = int(input())
for _ in range(M):
  dic[input()] -= 1
 
if dic.most_common():
  freq = dic.most_common()[0][1]
  print(max(freq, 0))
else:
  print(0)