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:
NL = []
ML = []
sL = []
SL = []
N = int(input())
for i in range(N):
	s = input()
	NL.append(s)
	sL.append(s)

M = int(input())
for i in range(M):
	t = input()
	ML.append(t)
	sL.append(t)

sL = sorted(sL)
SL.append(sL[0])
for i in range(1, len(sL)):
	if sL[i] != sL[i - 1]:
		SL.append(sL[i])


c = 0
for i in range(len(SL)):
	if NL.count(SL[i]) - ML.count(SL[i]) > c:
		c = NL.count(SL[i]) - ML.count(SL[i])

print(c)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import Counter

n = ni()
blue = []
for _ in range(n):
    blue.append(ns())
    
m = ni()
red = []
for _ in range(m):
    red.append(ns())
    
blc = Counter(blue)
rdc = Counter(red)

ans = 0
for bk, bv in blc.items():
    if bk in rdc.keys():
        ans = max(ans, bv - rdc[bk])
    else:
        ans = max(ans, bv)
        
        
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

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

ans = -10000
for key, value in cs.items():
    if ct[key] > 0:
        ans = max(ans, value - ct[key])
    else:
        ans = max(ans, value)
for key, value in ct.items():
    if cs[key] > 0:
        ans = max(ans, -value + ct[key])
    else:
        ans = max(ans, -value)

print(ans)

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())
ans = -10**8
L3 = list(set(L1))
for i in range(len(L3)) :
    p = L1.count(L3[i])
    q = L2.count(L3[i])
    if ans < p-q :
        ans = p-q
if ans < 0 :
    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)]

from collections import Counter
CS=Counter(S)
CT=Counter(T)

ANS=0
for i in CS:
    if CS[i]-CT[i]>ANS:
        ANS=CS[i]-CT[i]

print(ANS)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
S = [input() for i in range(N)]
M = int(input())
T = [input() for i in range(M)]
c1 = Counter(S)
c2 = Counter(T)

ans = 0
for k,v in c1.items():
    tmp = v - c2[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)]

d = {}

for i in range(N):
    if s[i] in d:
        d[s[i]] += 1
    else:
        d[s[i]] = 1
    
for i in range(M):
    if t[i] in d:
        d[t[i]] -= 1
    else:
        d[t[i]] = -1

v = list(d.values())
v.append(0)
print(max(v))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

dic = dict()


def main() -> None:
    n = next_int()
    register(n, 1)
    m = next_int()
    register(m, -1)

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

    print(ans)


def register(n: int, t: int) -> None:
    global dic
    for i in range(n):
        s = input()
        if s in dic:
            dic[s] += t
        else:
            dic[s] = t


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


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

S=set(s[i] for i in range(n))
L=len(S)
x = list(S)
a=[0]*(L+1)
for i in range(L):
    a[i]=s.count(x[i])-t.count(x[i])
print(max(a))

Submission status: Accepted

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

x = 0
for s in S:
    a = S.count(s)
    b = T.count(s)
    x = max(x, a-b)
print(x)

Submission status: Accepted

Solution code:
n=int(input())
s=[]
t=[]
ans=0
for i in range(n):
    s.append(input())
m=int(input())
for i in range(m):
    t.append(input())
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 = [input() for i in range(n)]
m = int(input())
t = [input() for i in range(m)]

mc_s = Counter(s).most_common()
mc_t = Counter(t).most_common()

ans = []
for i in mc_s:
    for j in mc_t:
        if i[0] == j[0]:
            ans.append(i[1] - j[1])

ans = [0] * len(mc_s)
for i in range(len(mc_s)):
    ans[i] = mc_s[i][1]
    for j in range(len(mc_t)):
        if mc_s[i][0] == mc_t[j][0]:
            ans[i] = min(ans[i], mc_s[i][1] - mc_t[j][1])

ans.sort(reverse=True)
print(max(0,ans[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)]
word = set(s+t)
cou = 0
clist = []
for i in word:
  cou = s.count(i) - t.count(i)
  clist.append(cou)
ans = max(clist)
if ans < 0:
  ans = 0
print(ans)

Submission status: Accepted

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

m = int(input())
td = {input():1}
for i in range(m-1):
    t = input()
    if t in td:
        td[t] += 1
    else:
        td[t] = 1

for x in td:
    if x in sd:
        sd[x] -= td[x]

print(max(0,max(map(int, sd.values()))))

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())
dict_index = set(s_list + t_list)
s_count = [s_list.count(i) for i in dict_index]
t_count = [t_list.count(i) for i in dict_index]
dict_count = [i - n for i, n in zip(s_count, t_count)]
if max(dict_count) < 0:
  print(0)
else:
  print(max(dict_count))

Submission status: Accepted

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

Submission status: Accepted

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

p = set([] + s)

ans = 0
for x in p:
    ans = max(ans, s.count(x) - t.count(x))

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

Submission status: Accepted

Solution code:
dict = {}

n = int(input())

for i in range(n):
	s = input()
	try:
		dict[s] += 1
	except:
		dict[s] = 1

m = int(input())

for i in range(m):
	s = input()
	try:
		dict[s] -= 1
	except:
		dict[s] = -1

ans = sorted(dict.items(), key=lambda x: -x[1])

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

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

S = sorted(set(s))
for _ in S:
  a = s.count(_) - t.count(_)
  if ans < a:
    ans = a

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

print(max(0, max([s.count(text)-t.count(text) for text in set(s) | set(t)])))

Submission status: Accepted

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

words = {}
for i in range(n):
    if not s[i] in words.keys():
        words[s[i]] = 1
    else:
        words[s[i]] += 1
for i in range(m):
    if not t[i] in words.keys():
        words[t[i]] = -1
    else:
        words[t[i]] -= 1

ans = 0
for k, v in words.items():
    ans = max(ans, v)
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)]

Z = []
for si in S:
    Z.append(S.count(si) - T.count(si))
    
if max(Z) < 0:
    print("0")
else:
    print(max(Z))

Submission status: Accepted

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

maxs = 0

for si in s:
    tmp = s.count(si) - t.count(si)
    if tmp > maxs:
        maxs = tmp

print(maxs)

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

x = 0

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

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

Submission status: Accepted

Solution code:
a=[]
b=[]
m=0

for _ in [0]*int(input()):
  a += [input()]
for _ in [0]*int(input()):
  b += [input()]

for s in a:
  m = max(m, a.count(s)-b.count(s))
print(m)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
s = [input() for _ in range(N)]
M = int(input())
t = [input() for _ in range(M)]
gain = 0

s_count = Counter(s)
t_count = Counter(t)
for s_str, s_num in s_count.items():
    if s_str not in t_count:
        gain = max(s_num, gain)
    elif s_num > t_count[s_str]:
        gain = max(s_num - t_count[s_str], gain)

print(gain)

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

l = list(set(s + t))

ans = 0

for word in l:
    ans = max(ans, s.count(word) - t.count(word))

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
Ns = []
for i in range(N):
    word = input()
    Ns.append(word)
M = int(input())
Ms = []
for i in range(M):
    word = input()
    Ms.append(word)
unique_words = list(set(Ns+Ms))
ans = 0
for word in unique_words:
    ans = max(ans,Ns.count(word)-Ms.count(word))
print(ans)

Submission status: Accepted

Solution code:
s = {}
t = {}
ans = 0
for i in range(int(input())):
    key = input()
    try:
        s[key] += 1
    except:
        s[key] = 1
for i in range(int(input())):
    key = input()
    try:
        t[key] += 1
    except:
        t[key] = 1
for key in s.keys():
    snum = s[key]
    tnum = 0
    try:
        tnum = t[key]
    except:
        pass
    ans = max(ans, snum - tnum)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
list_s = []
list_t = []
for i in range(0,n):
    list_s.append(str(input()))
m = int(input())
for i in range(0,m):
    list_t.append(str(input()))
ans = 0
for card in list_s:
    if ans < list_s.count(card) - list_t.count(card):
        ans = list_s.count(card) - list_t.count(card)
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)]
ans=0
for l in s:
    if s.count(l)-t.count(l)>ans:
        ans=s.count(l)-t.count(l)
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
s=[]

for i in range(N):
  s1=input()
  s.append(s1)
M=int(input())
t=[]
for i in range(M):
  t1=input()
  t.append(t1)
s.sort()
t.sort()
u=[0]
for i in range(N):
  x=s.count(s[i])-t.count(s[i])
  u.append(x)
print(max(u))

Submission status: Accepted

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

max_profit = -100  # M <= 100 -> min_profit is larger than -100
canditates = set(s_list)
for canditate in canditates:
    tmp_profit = s_list.count(canditate) - t_list.count(canditate)
    if tmp_profit > max_profit:
        max_profit = tmp_profit   
print(max(max_profit, 0))

Submission status: Accepted

Solution code:
n = int(input())
blue = []
for i in range(n):
    blue.append(input())
m = int(input())
red = []
for i in range(m):
    red.append(input())
ans = ""
mon = 0
for i in range(n):
    if blue.count(blue[i]) - red.count(blue[i]) > mon:
        mon = blue.count(blue[i]) - red.count(blue[i])
print(mon)

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)])
union = list(set(s) | set(t))
l = [s.count(union[i])-t.count(union[i]) for i in range(len(union))]
if max(l) > 0:
  print(max(l))
else:
  print(0)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

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

maxv = sorted(d.values(), reverse=True)[0]
if maxv > 0:
    print(maxv)
else:
    print(0)

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)]
c=0
for k in s:
  a=s.count(k)-t.count(k)
  if a>c:c=a
print(c)

Submission status: Accepted

Solution code:
N = int(input())
J = [input() for i in range(N)]
M = int(input())
K = [input() for i in range(M)]
L = []
Z = []
for i in range(len(J)):
  if (J[i] not in L):
    L.append(J[i])
for j in range(len(L)):
  p = J.count(L[j])
  q = K.count(L[j])
  Z.append(p-q)
Z.sort()
Z.reverse()
if (Z[0] <= 0):
  print('0')
else:
  print(Z[0])

Submission status: Accepted

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

pointList = dict();

for temp in s:
  pointList[temp] = 0
for temp in t:
  pointList[temp] = 0
  
for temp in s:
  pointList[temp] += 1
for temp in t:
  pointList[temp] -= 1
  
ans = max(0, max(pointList.values()))

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
indexB =0
blueL =[]
while indexB<n:
    blueL.append(input())
    indexB+=1

m = int(input())
indexR =0
redL =[]
while indexR<m:
    redL.append(input())
    indexR+=1

blueL.sort()
length = len(blueL)
index1 =0
ansM=0
while index1<length:
    money =0
    for blueC in blueL:
        if blueL[index1] ==blueC:
            money+=1
    for redC in redL:
        if blueL[index1] ==redC:
            money-=1
    if ansM<money:
        ansM=money
    index1+=1

print(ansM)

Submission status: Accepted

Solution code:
N = int(input())
b_list = [input() for _ in range(N)]
b_set = set(b_list)
M = int(input())
r_list = [input() for _ in range(M)]
ans = 0

for i in b_set:
	ans = max(ans, b_list.count(i)-r_list.count(i))

print(ans)

Submission status: Accepted

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

score = [0]

for s_test in s:
    scr = 0
    for ss in s:
        if ss == s_test:
            scr += 1
    for tt in t:
        if tt == s_test:
            scr -= 1
    score.append(scr)

ans = max(score)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
plus = {}

for i in range(n):
    a = input()
    if a in plus.keys():
        plus[a] += 1
    else:
        plus[a] = 1

m = int(input())
minus = {}
for i in range(m):
    a = input()
    if a in minus.keys():
        minus[a] += 1
    else:
        minus[a] = 1

mv = 0
for i in plus.keys():
    if i in minus.keys():
        t = plus[i] - minus[i]
    else:
        t = plus[i]
    mv = max(t, mv)

print(mv)

Submission status: Accepted

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


Max=-int(M)
for i in range(int(N)):
    point=int(0)
    str=Blue[i]
    for s in Blue:
        if s==str:
            point+=int(1)

    for s in Red:
        if s==str:
            point-=int(1)

    Max=max(Max,point)
print(max(Max,0))

Submission status: Accepted

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

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

s_unique = list(set(s))
# t_unique = list(set(t))

rieki = 0
son = 0
cnt = 0
res = 0
for i in s_unique:
    rieki = s.count(i)
    son = t.count(i)
    res = max(res, rieki - son)

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
S=[input() for i in range(N)]
M=int(input())
T=[input() for i in range(M)]
max=0
for i in range(N):
    cnt=0
    for j in range(N):
        if S[i]==S[j]:
            cnt+=1
    for k in range(M):
        if S[i]==T[k]:
            cnt-=1
    if max<cnt:
        max=cnt
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())
ans = []
for _ in s:
    ans.append(s.count(_)-t.count(_))
if max(ans) >= 0:
    print(max(ans))
else:
    print(0)

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

sets = set(s)

ans = [0]
for word in sets:
    tmp = 0
    tmp += s.count(word)
    tmp -= t.count(word)
    ans.append(tmp)

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

print(ans)

Submission status: Accepted

Solution code:
#91b
n=int(input())
s=[input() for _ in range(n)]

m=int(input())
t=[input() for _ in range(m)]
ans=0

st=set(s+t)
for i in st:
    ans = max(s.count(i) - t.count(i) , ans)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
s_list = [input() for _ in range(N)]
M = int(input())
t_list = [input() for _ in range(M)]
tmp = s_list.copy()
tmp.append("fdsfsdfsfs")
s_set = list(set(tmp))
result = []
for s in s_set:
    r = 0
    for i in s_list:
        if i == s:
            r += 1
    for j in t_list:
        if j == s:
            r -= 1
    result.append(r)
print(max(result))

Submission status: Accepted

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

for i in range(M):
    if t[i] in s:
        s.remove(t[i])

for i in range(len(s)):
    if sum < s.count(s[i]):
        sum = s.count(s[i])
print(sum)

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())
mmax = -200
for i in s:
    m = 0
    for j in s:
        if i == j:
            m += 1
    for j in t:
        if i == j:
            m -= 1
    if mmax < m:
        mmax = m
    if mmax < 0:
        mmax = 0

print(mmax)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
card = {}
for i in range(N):
  S = input()
  card[S] = card.get(S, 0) + 1
 
M = int(input())
for i in range(M):
  S = input()
  card[S] = card.get(S, 0) - 1

tmp = list(card.values())
tmp.append(0)
print(max(tmp))

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

X = {}
for s in S:
  if s in X:
    X[s] += 1
  else:
    X[s] = 1

for t in T:
  if t in X:
    X[t] -= 1

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

Submission status: Accepted

Solution code:
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def main():
    N = int(input())
    S = []
    for _ in range(N):
        S.append(input())
    M = int(input())
    T = []
    for _ in range(M):
        T.append(input())

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
d={}
n=int(input())
for i in range(n):
    s=input()
    if s in d: d[s]+=1
    else:      d[s] =1
n=int(input())
for i in range(n):
    s=input()
    if s in d: d[s]-=1
ans=chk=0
for i in d:
    ans=max(ans,d[i])
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
blue = []
for i in range(N):
    blue.append(input())
M = int(input())
red = []
for j in range(M):
    red.append(input())
blue_Counter = Counter(blue)
red_Counter = Counter(red)
ans = blue_Counter - red_Counter
if not ans.most_common():
    print(0)
else:
    print(ans.most_common()[0][1])

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


# --------------------------------------------

dp = None


def main():
    N = int(input())
    B = [input() for _ in range(N)]
    M = int(input())
    R = [input() for _ in range(M)]

    ans = -9999999999999

    for b in B:
        cnt = 0

        for bb in B:
            if b == bb:
                cnt += 1

        for r in R:
            if r == b:
                cnt -= 1

        ans = max(cnt, ans)

    print(max(ans, 0))


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N = int(input())

names = []
num = []

for i in range(N):
	s = input()
	if not s in names:
		names.append(s)
		num.append(1)
	else:
		ind = names.index(s)
		num[ind] += 1

M = int(input())

for i in range(M):
	s = input()
	if not s in names:
		names.append(s)
		num.append(-1)
	else:
		ind = names.index(s)
		num[ind] -= 1

print(max(max(num),0))

Submission status: Accepted

Solution code:
n=int(input())
s=[]
for i in range(n):
    s.append(input())
m=int(input())
for i in range(m):
    a=input()
    if(a in s):s.remove(a)
d=set(s)
ans=0
for i in d:
    ans=max(ans,s.count(i))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = []
for i in range(N) :
    s = input()
    S.append(s)
M = int(input())
T = []
for j in range(M) :
    t = input()
    T.append(t)
candidate = []
for k in range(len(S)) :
    counter1 = S.count(S[k])
    counter2 = T.count(S[k])
    counter = counter1 - counter2
    candidate.append(counter)
print(max(max(candidate),0))

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = Counter(input() for _ in range(N))
M = int(input())
for _ in range(M):
    A[input()] -= 1

print(max(max(A.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)]
list = [s.count(s[j])-t.count(s[j]) for j in range(len(s))]
list.append(0)
print(max(list))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
s=[input() for _ in range(n)]
s.append('1')
m=int(input())
t=[input() for _ in range(m)]
t.append('1')
res = -float('inf')
for l in s:
    tmp = s.count(l)-t.count(l)
    res = max(res,tmp)
print(res)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
s1 = [input() for i in range(N)]
M = int(input())
s2 = [input() for i in range(M)]
c1 = Counter(s1)
c2 = Counter(s2)
ans = 0
for k in c1.keys():
    ans = max(ans, c1[k] - c2[k])
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())

ans_cand = [0]
for say in S:
    ans = 0
    for s in S:
        if say == s:
            ans += 1
    for t in T:
        if say == t:
            ans -= 1
        
    ans_cand.append(ans)
print(max(ans_cand))

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
s1 = [input() for i in range(N)]
c1 = Counter(s1)
M = int(input())
s2 = [input() for i in range(M)]
c2 = Counter(s2)

ans = 0
for k,v in c1.items():
    ans = max(ans, v-c2[k])
print(ans)

Submission status: Accepted

Solution code:
N= int(input())
s = list()
for i in range(N):
    s.append(input())

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

    
max_count = 0
for i in range(N):
    for j in range(M):
        B = s.count(s[i]) - t.count(s[i])
        C = s.count(t[j]) - t.count(t[j])
        
        if B > C:
            E = B
        else:
            E = C
               
        if E > max_count:
            max_count = E
    
print(max_count)

Submission status: Accepted

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

d = {}
for k in s:
    if k in d.keys():
        d[k] += 1
    else:
        d[k] = 1
for k in t:
    if k in d.keys():
        d[k] -= 1
    else:
        d[k] = -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)]
l = [0] + [s.count(i) - t.count(i) for i in set(s + t)]
print(max(l))

Submission status: Accepted

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(max(d.values()),0))

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
s = [input() for _ in range(n)]

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

sc = Counter(s)
tc = Counter(t)
res = 0 
for s_key, s_value in zip(sc.keys(), sc.values()):
    t_value = tc[s_key]
    if s_value - t_value > res:
        res = s_value - t_value
print(res)

Submission status: Accepted

Solution code:
import collections
N = int(input())
blue = [list(input().split()) for i in range(N)]
M = int(input())
red = [list(input().split()) for i in range(M)]
sum =0
for i in blue:
    score = blue.count(i) - red.count(i)
    if score>sum:
        sum = score
print(sum)