Problem:


Score : 200 points

Problem Statement

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

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

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

At most how much can he earn on balance?

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

Constraints

N and M are integers.

1 \leq N, M \leq 100

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

Input

Input is given from Standard Input in the following format:

N
s_1
s_2
:
s_N
M
t_1
t_2
:
t_M

Output

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

Sample Input 1

3
apple
orange
apple
1
grape

Sample Output 1

2

He can earn 2 yen by announcing apple.

Sample Input 2

3
apple
orange
apple
5
apple
apple
apple
apple
apple

Sample Output 2

1

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

Sample Input 3

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

Sample Output 3

0

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

Sample Input 4

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

Sample Output 4

1



Sample input:
3
apple
orange
apple
1
grape


Sample output:
2

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(input())
    d = defaultdict(int)
    for _ in range(N):
        d[input()] += 1
    M = int(input())
    for _ in range(M):
        d[input()] -= 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)]

ss = set(s)
mx = 0
for ssi in ss:
    mx = max(mx, s.count(ssi) - t.count(ssi))
print(mx)

Submission status: Accepted

Solution code:
import collections

n= int(input())
A =[input() for _ in range(n)]
Ac = collections.Counter(A)
m= int(input())
B =[input() for _ in range(m)]
Bc = collections.Counter(B)
ans =[]
for i in Ac.keys():
    ans.append(Ac[i]-Bc[i])
print(max(max(ans),0))

Submission status: Accepted

Solution code:
import collections

n = int(input())
s = [input() for i in range(n)]
m = int(input())
t = [input() for i in range(m)]
d = collections.Counter(s)

for k in t:
    if k in d:
        d[k]-=1
print(d.most_common()[0][1] if d.most_common()[0][1]>=0 else 0)

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)]
d = Counter(S)
for t in T:
    if t in d:
        d[t]+=-1
    else:
        d[t]=-1
print(d.most_common()[0][1] if d.most_common()[0][1]>0 else 0)

Submission status: Accepted

Solution code:
# coding:utf-8

n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]
word = list(set(s))
ans = 0

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

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

li = []
nums = []
for s in S:
    if s not in li:
        li.append(s)
        nums.append(1)
    else:
        nums[li.index(s)] += 1
for t in T:
    if t in li:
        nums[li.index(t)] -= 1
mx = max(nums)
ans = max(0, mx)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections as ct
n = int(input())
s_c = ct.Counter([input() for i in range(n)])
m = int(input())
t_c = ct.defaultdict(int, ct.Counter([input() for i in range(m)]))
ans = max([s_c[k] - t_c[k] for k in s_c])
print(max(ans, 0))

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

X_list = []
for str in s_list:
    x = s_list.count(str) - t_list.count(str)
    X_list.append(x)

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

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

c = collections.Counter(s).most_common()
C = []
for i in range(len(c)):
    C.append([c[i][0], c[i][1]])

ans = []
for j in range(len(C)):
    if C[j][0] in t:
        C[j][1] -= t.count(C[j][0])
    ans.append(C[j][1])

print(max(ans) if max(ans) > 0 else 0)

Submission status: Accepted

Solution code:
result = 0
blue_num = int(input())
blue_list = []

for i in range(blue_num):
  blue_list.append(input())
  
red_num = int(input())
red_list = []

for i in range(red_num):
  red_list.append(input())
  
for key in set(blue_list + red_list):
  point = blue_list.count(key) - red_list.count(key)
  if result < point:
    result = point

print(result)

Submission status: Accepted

Solution code:
from collections import Counter

s=Counter(input() for i in range(int(input())))
t=Counter(input() for i in range(int(input())))
print(max([0]+[s[i]-t[i] for i in s.keys()]))

Submission status: Accepted

Solution code:
import collections

N=int(input())
s=collections.Counter([input() for i in range(N)])
M=int(input())
t=collections.Counter([input() for i in range(M)])

print(max([0]+[s[i]-t[i] for i in s.keys()]))

Submission status: Accepted

Solution code:
N = int(input())
S = []
for i in range(N):
  Si = str(input())
  S.append(Si) 
  
M = int(input())
T = []
for i in range(M):
  Ti = str(input())
  T.append(Ti)

max_point = 0
for i in range(N):
  point = len([1 for s in S if s==S[i]]) - len([1 for t in T if t==S[i]])
  max_point = max([max_point,point])
  
print(max_point)

Submission status: Accepted

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

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

max=0

for i in range(s_num):
    if max < int(s.count(s[i]) - t.count(s[i])):
        max = int(s.count(s[i]) - t.count(s[i]))
        #print('int(s.count(s[i]) - t.count(s[i]))=',int(s.count(s[i]) - t.count(s[i])))
print(max)

Submission status: Accepted

Solution code:
n = int(input())
b = []
b_i = [0 for i in range(110)]
for i in range(n):
    s = input()
    if not s in b:
        b.append(s)
        b_i[b.index(s)] += 1
    else:
        b_i[b.index(s)] += 1 
m = int(input())
for i in range(m):
    t = input()
    if not t in b:
        b.append(t)
        b_i[b.index(t)] += 1
    else:
        b_i[b.index(t)] -= 1 
print(max(b_i))

Submission status: Accepted

Solution code:
N=input()
N=int(N)
s = [0 for i in range(N)]
#sの入力
for i in range(N):
    s[i]=input()

M=input()
M=int(M)
t = [0 for i in range(M)]
#sの入力
for i in range(M):
    t[i]=input()

#処理
ans=0
for i in range(N):
    count=0
    #ターゲット
    target=s[i]
    #判定
    #プラス分
    for j in range(N):
        if target==s[j]:
            count+=1
    #マイナス分
    for j in range(M):
        if target==t[j]:
            count-=1
    #結果の更新
    if ans<count:
        ans=count

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

sset=list(set(s))
tset=list(set(t))

Nset=len(sset)
ans=0
for i in range(Nset):
  if s.count(sset[i])-t.count(sset[i])>ans:
    ans=s.count(sset[i])-t.count(sset[i])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N = int(sys.stdin.readline())
s = [sys.stdin.readline().rstrip() for i in range(N)]
M = int(sys.stdin.readline())
t = [sys.stdin.readline().rstrip() for i in range(M)]
ans = 0
p = 0
m = 0
for i in s:
    p = s.count(i)
    m = t.count(i)
    ans = max(ans, p - m)
print(ans)

Submission status: Accepted

Solution code:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    n = ni()
    s = [ns() for _ in range(n)]
    m = ni()
    t = [ns() for _ in range(m)]

    c1 = Counter(s)
    c2 = Counter(t)
    ans = []
    for key1, value1 in c1.items():
        if key1 in c2.keys():
            ans.append(value1 - c2[key1])
        else:
            ans.append(value1)

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

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 _ in range(M)]
S1 = set(S)
result = []

for a in S1:
    if a not in T:
        result.append(S.count(a))
    else:
        if S.count(a) >= T.count(a):
            result.append(S.count(a) - T.count(a))

if not result:
    print(0)
else:
    print(max(result))

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(0, *[S.count(s) - T.count(s) for s in set(S)]))

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)]
s_set=collections.Counter(s)
t_set=collections.Counter(t)
score=[]
for w in s_set:
    score+=[s_set[w]-t_set[w]]
print(max(score) if max(score)>0 else 0)

Submission status: Accepted

Solution code:
n=int(input())
s={}
for _ in range(n):
  si=input()
  if si in s:
    s[si]+=1
  else:
    s[si]=1
m=int(input())
t={}
for _ in range(m):
  ti=input()
  if ti in t:
    t[ti]+=1
  else:
    t[ti]=1

ans=0
for i in s:
  p=s[i]-t.get(i, 0)
  if p>ans:
    ans=p
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)]
maxp = 0
for i in s:
    pre = s.count(i)-t.count(i)
    maxp = max(maxp,pre)
print(maxp)

Submission status: Accepted

Solution code:
from collections import defaultdict
dic = defaultdict(int)
n = int(input())
for i in range(n):
    dic[input()] += 1
n = int(input())
for i in range(n):
    dic[input()] -= 1
m = sorted([i for i in dic.values()])[-1]
if m >= 0:
    print(m)
else:
    print(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()
    
p = "" 
counter = 0
ans = 0

for i in range(N):
    p = s[i]
    for ii in range(N):
        if p == s[ii]:
            counter += 1
    for iii in range(M):
        if p == t[iii]:
            counter -= 1
    if ans < counter:
        ans = counter
    counter = 0    

print(ans)

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)]
count_red = Counter(s)
count_blue = Counter(t)
ans = [0]
for i in count_red:
    a = count_red[i]
    if i in count_blue:
        a -= count_blue[i]
    ans.append(a)
print(max(ans))

Submission status: Accepted

Solution code:
from sys import stdin
import sys

N = int(input())
S = [input() for i in range(N)]

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

words_count = {}
for i in range(N):
    words_count[S[i]] = words_count.get(S[i], 0) + 1

for i in range(M):
    words_count[T[i]] = words_count.get(T[i], 0) - 1

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

print(max([s.count(S) - t.count(S) for S in s] + [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())
max = 0
for a in s:
  cnt = s.count(a) - t.count(a)
  if cnt > max:
    max = cnt
print(max * (max > 0))

Submission status: Accepted

Solution code:
B = [input() for i in range(int(input()))]
R = [input() for i in range(int(input()))]
B_dict = {}

for i in B:
    if i in B_dict:
        B_dict[i] += 1
    else:
        B_dict[i] = 1

max = 0
for item in B_dict:
    b_value = B_dict[item]
    r_value = R.count(item)
    if b_value - r_value > max:
        max = b_value - r_value

print(max)

Submission status: Accepted

Solution code:
import collections

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

    cs = collections.Counter(S)
    ct = collections.Counter(T)
    ans = 0
    for s in cs:
        ans = max(ans,cs[s]-ct[s])
    print(ans)


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)]
a = list(set(s+t))
ans = {'min': 0}
for i in a:
    ans[i] = 0
for i in s:
    ans[i] += 1
for i in t:
    ans[i] -= 1

print(max(ans.values()))

Submission status: Accepted

Solution code:
from collections import defaultdict

dic = defaultdict(int)

N = int(input())
s = [input() for _ in range(N)]
M = int(input())
t = [input() for _ in range(M)]
for i in s:
    dic[i] += 1

for i in t:
    dic[i] -= 1

ans = 0
for k, v in dic.items():
    ans = max(ans, v)
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 s in set(S):
    ans = max(ans, S.count(s) - T.count(s))

print(ans)

Submission status: Accepted

Solution code:
red_str_list=[]
blue_str_list=[]

blue_cnt=int(input())

for _  in range(blue_cnt):
  red_str_list.append(input())
  
red_cnt=int(input())
for _  in range(red_cnt):
  blue_str_list.append(input())
  
ans=0
dic = dict()

for i in red_str_list:
  if (i in dic.keys()):
    dic[i]+=1
  else:
    dic[i]=1
    
for i in blue_str_list:
  if (i in dic.keys()):
    if dic[i]>0:
      dic[i]-=1

print(max(dic.values()))

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
a = [input() for i in range(n)]
m = int(input())
b = [input() for i in range(m)]

a_cnt = Counter(a)
b_cnt = Counter(b)

maxs = 0
for k, v in a_cnt.items():
    maxs = max(maxs, v - b_cnt[k])
print(maxs)

Submission status: Accepted

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

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

# calc
d = {}
for i in s:
    if i in d.keys():
        d[i] += 1
    else:
        d[i] = 1 

for i in t:
    if i in d.keys():
        d[i] -= 1
    else:
        d[i] = -1

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

Submission status: Accepted

Solution code:
def myAnswer(N:int,s:list,M:int,t:list) -> int:
   dic = dict()
   for blueCard in s:
      if(blueCard in dic.keys()):
         dic[blueCard]+=1
      else:
         dic[blueCard]=1
   for redCard in t:
      if(redCard in dic.keys()):
         if(dic[redCard] > 0):
            dic[redCard] -= 1
   return max(dic.values())


def modelAnswer():
   tmp=1
def main():
   N = int(input())
   s = [input() for _ in range(N)]
   M = int(input())
   t = [input() for _ in range(M)]
   print(myAnswer(N,s[:],M,t[:]))
if __name__ == '__main__':
   main()

Submission status: Accepted

Solution code:
a=int(input())
b,d,e=[],[],[0]
for i in range(a):
    b.append(str(input()))
c=int(input())
up,down=0,0
for j in range(c):
    d.append(str(input()))
for k in set(b):
    up+=b.count(k)
    down+=d.count(k)
    e.append(up-down)
    up,down=0,0
print(max(e))

Submission status: Accepted

Solution code:
b_list = [input() for i in range(int(input()))]
r_list = [input() for i in range(int(input()))]

ans = 0 
for i in list(set(b_list)):
  if ans <= b_list.count(i) - r_list.count(i):
    ans = b_list.count(i) - r_list.count(i)
    
print(int(ans))

Submission status: Accepted

Solution code:
import collections
n = int(input())
Lista = [str(input()) for i in range(n)]
m = int(input())
Listb = [str(input()) for j in range(m)]
lst = []
for k in range(m):
  if Listb[k] in Lista:
    Lista.remove(Listb[k])
if len(Lista) > 0:
  lst = collections.Counter(Lista)
  print(lst.most_common()[0][1])
elif len(Lista) == 0:
  print(0)

Submission status: Accepted

Solution code:
N = int(input())
li1 = [input() for _ in range(N)]
M = int(input())
li2 = [input() for _ in range(M)]
ans = 0
for i in set(li1):
    tmp = li1.count(i) - li2.count(i)
    ans = max(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
dic = dict()
for a in range(int(input())):
    i = input()
    if not i in dic:
        dic[i] = 1
    else:
        dic[i] = dic[i]+1
for b in range(int(input())):
    i = input()
    if not i in dic:
        dic[i] = -1
    else:
        dic[i] = dic[i]-1
print(max(max([a for a in dic.values()]), 0))

Submission status: Accepted

Solution code:
n = int(input())
S = []
T = []

for i in range(n):
    S += [input()]

m = int(input())

for i in range(m):
    T += [input()]

ans = 0

for tango in set(S):
    tmp = S.count(tango) - T.count(tango)
    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 word in set(s):
    if word not in t:
        ans = max(ans, s.count(word))
    else:
        ans = max(ans, s.count(word) - t.count(word))
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())
count1 = Counter(s)
count2 = Counter(t)
ans = -1 * M
for key in count1.keys():
    ans = max(ans, count1[key] - count2[key])
ans = max(ans, 0)
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
cards = defaultdict(int)
n = int(input())
for _ in range(n):
    s = input()
    cards[s] += 1
m = int(input())
for _ in range(m):
    t = input()
    cards[t] -= 1
ans = 0
for k, v in cards.items():
    ans = max(ans, v)
print(ans)

Submission status: Accepted

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

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

A=[]
for i in S:
    A.append(S.count(i)-T.count(i))

print(max(0,max(A)))

Submission status: Accepted

Solution code:
N = int(input())

dic = {}
word = ""

for i in range(N):
    word = input()
    if word in dic:
        dic[word] += 1
    else:
        dic[word] = 1

M = int(input())

for i in range(M):
    word = input()
    if word in dic:
        dic[word] -= 1
    else:
        dic[word] = -1

li = list(dic.values())

s = max(li)

if s > 0:
    print(s)
else:
    print(0)

Submission status: Accepted

Solution code:
n = int(input())
r = [input() for i in range(n)]
m = int(input())
b = [input() for i in range(m)]
rb = set(r+b)
ans = 0

for w in rb:
    x = r.count(w)
    y = b.count(w)
    if x-y > ans:
        ans = x-y

print(ans)

Submission status: Accepted

Solution code:
icase=0
if icase==0:
    s=dict()
    n=int(input())
    for i in range(n):
        si=input()
        if si in s:
            s[si]=s[si]+1
        else:
            s[si]=1
    t=dict()
    m=int(input())
    for i in range(m):
        ti=input()
        if ti in t:
            t[ti]=t[ti]+1
        else:
            t[ti]=1
    smax=0
    for ss in s.items():
        if ss[0] in t:
            st=ss[1]-t[ss[0]]
        else:
            st=ss[1]
        smax=max(smax,st)
    print(smax)

Submission status: Accepted

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

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=[]

tmp=s.copy()
tmp=set(tmp)
tmp=list(tmp)

for i in tmp:
    S=s.count(i)
    T=t.count(i)
    l.append(S-T)
print(max(0,max(l)))

Submission status: Accepted

Solution code:

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

tmp = s.copy()
tmp = set(tmp)
tmp = list(tmp)

for i in range(len(tmp)):
    S = s.count(tmp[i])
    T = t.count(tmp[i])
    l.append(S-T)

print(max(0,max(l)))

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# solution
import io

n=[input() for i in range(int(input()))]
m=[input() for i in range(int(input()))]
array=list(set(n))
print(max(0,max(n.count(array[i])-m.count(array[i]) for i in range(len(array)))))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
dict = {}
s = [input() for i in range(N)]
for x in range(N):
    dict[s[x]] = 0
for y in range(N):
    dict[s[y]] += 1
# print(dict)

M = int(input())
t = [input() for i in range(M)]
for z in range(M):
    if t[z] in dict:
        dict[t[z]] -= 1
if max(dict.values()) > 0:
    print(max(dict.values()))
else:
    print(0)

Submission status: Accepted

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

ans = 0
for ss in s:
    score = s.count(ss) - t.count(ss)
    if ans < score:
        ans = score
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
st = set() # 空のセットを生成
s = [] # 空のリストを生成

for i in range(N):
    char = input()
    st.add(char) # セットに要素を追加するにはadd()を使う
    s.append(char) # リストに要素を追加するにはappend()を使う

M = int(input())
t = [] # 空のリストを生成

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

ans = -100 # ありうる最小値を初期値に設定
char = 0

for x in st:
    char = s.count(x)
    char -= t.count(x)
    ans = max(ans, char)

print(ans if 0 <= ans else 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)]

dicts = {}
small = 0
for i in s:
    if i not in dicts.keys():
        dicts[i] = 1
    else:
        dicts[i] += 1
    
for i in t:
    if i not in dicts.keys():
        dicts[i] = -1
    else:
        dicts[i] -= 1

tmp = max(dicts.values())
print(max(tmp, small))

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    blue = [input() for _ in range(N)]
    M = int(input())
    red = [input() for _ in range(M)]
    words = set(blue+red)
    x = -1000
    for w in words:
        pos = blue.count(w)
        neg = red.count(w)
        x = max(x, pos - neg)

    if x > 0:
        print(x)
    else:
        print(0)
main()

Submission status: Accepted

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

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 key in S.keys():
    ans = max(S.get(key)-T.get(key,0),ans)
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)]
money=0
for word in s:
    money = max(money,s.count(word)-t.count(word))
print(money)

Submission status: Accepted

Solution code:
import sys
N = int(sys.stdin.readline())
S = [sys.stdin.readline() for i in range(N)]
M = int(sys.stdin.readline())
T = [sys.stdin.readline() for j in range(M)]
ans = 0
for s in S:
  money = S.count(s) + T.count(s) * -1
  ans = max(ans, money)
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import Counter
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, s: "List[str]", M: int, t: "List[str]"):
    ctr = Counter(s)
    ctr.subtract(t)
    ((_key, cnt),) = ctr.most_common(1)
    print(max(0, cnt))


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:
import sys
N = int(sys.stdin.readline())
S = [sys.stdin.readline() for i in range(N)]
M = int(sys.stdin.readline())
T = [sys.stdin.readline() for j in range(M)]
ans = 0
for s in S:
  money = S.count(s) + T.count(s) * -1
  ans = max(ans, money)
print(ans)

Submission status: Accepted

Solution code:
# ABC 091: B – Two Colors Card Game
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]

money = 0

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

print(money)

Submission status: Accepted

Solution code:
def resolve():
    table={}
    n=int(input())
    for i in range(n):
        tmp=input()
        if tmp in table.keys():
            table[tmp]+=1
        else:
            table[tmp]=1
    m=int(input())
    for i in range(m):
        tmp=input()
        if tmp in table.keys():
            table[tmp]-=1
        else:
            table[tmp]=-1
    ans=max(table.values())
    if ans<0:
        print(0)
    else:
        print(ans)
resolve()

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

import collections
c_s = collections.Counter(s)
c_t = collections.Counter(t)

ans = 0
for k,v in c_s.items():
  ans = max((c_s[k]-c_t[k]),ans)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = dict()
word = []
ans = 0
for i in range(N):
    s = input()
    if s not in word:
        word.append(s)
    if s in S:
        S[s] += 1
    else:
        S[s] = 1

M = int(input())
T = dict()
for i in range(M):
    t = input()
    if t not in word:
        word.append(t)
    if t in T:
        T[t] += 1
    else:
        T[t] = 1

for w in word:
    if w in S and w in T:
        money = S[w] - T[w]
    elif w in S:
        money = S[w]
    else:
        money = -1 * T[w]
    if money > ans:
        ans = money
print(ans)

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)])
ans = 0
for key in S.keys():
    ans = max(S.get(key) - T.get(key, 0), 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)]
ans = 0
for s in s_list:
    score = s_list.count(s) - t_list.count(s)
    if ans < score:
        ans = score
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
dict = {}
for _ in range(n):
    s = input()
    if s not in dict:
        dict[s] = 0
    dict[s] += 1

m = int(input())
for _ in range(m):
    t = input()
    if t not in dict:
        dict[t] = 0
    dict[t] -= 1
print(max(dict.values()) if max(dict.values()) > 0 else 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 = list(set(s))
print(max(0,max(s.count(l[i])-t.count(l[i]) for i in range(len(l)))))

Submission status: Accepted

Solution code:
N = int(input())
S = dict()
for _ in range(N):
    s = input()
    if s not in S:
        S[s] = 1
    else:
        S[s] += 1
M = int(input())
T = dict()
for _ in range(M):
    t = input()
    if t not in T:
        T[t] = 1
    else:
        T[t] += 1

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

print(ans)