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 = [input() for i in range(N)]

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

n_num = 0
m_num = 0
x = []
y = []

for i in range(N):
    n_num = s.count(s[i])
    m_num = t.count(s[i]) * -1
    x.append(n_num + m_num)


for j in range(M):
    n_num = s.count(t[j])
    m_num = t.count(t[j]) * -1
    y.append(n_num + m_num)

ans = x + y
if max(ans) < 0:
    print(0)
else:
    print(max(ans))

Submission status: Accepted

Solution code:
n =int(input())
a = [input() for i in range(n)]
m =int(input())
b = [input() for i in range(m)]
l = set(a)
e = -100000
for i in l:
    e = max(e,a.count(i)-b.count(i))
print(max(e,0))

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)]
c = Counter(a)
d = Counter(b)
e = -100000
for i,j in c.most_common():
    e = max(j-d[i],e)
print(max(e,0))

Submission status: Accepted

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

ans = 0

for i in list_blue:
    point = list_blue.count(i) - list_red.count(i)
    if ans < point:
        ans = point

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)]
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())
max_score = 0
word_list1 = []
for i in range(n):
    s = input()
    word_list1.append(s)

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


what_to_say = set(word_list1)


for i in what_to_say:
    score = 0
    for j in word_list1:
        if i == j:
            score += 1
    for k in word_list2:
        if i == k:
            score -= 1
    if score > max_score:
        max_score = score

print(max_score)

Submission status: Accepted

Solution code:
dict_ = dict()
[exec("dict_['{0}'] = dict_.get('{0}', 0) + 1".format(input())) for _ in range(int(input()))]
[exec("dict_['{0}'] = dict_.get('{0}', 0) - 1".format(input())) for _ in range(int(input()))]
print(max(max(dict_.values()), 0))

Submission status: Accepted

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

m=int(input())
for i in range(m):
    t=input()
    re.append(t)
count=[0]
for i in range(n):
    brcou=0
    for j in range(n):
        if br[i]==br[j]:
            brcou+=1
    for k in range(m):
        if br[i]==re[k]:
            brcou-=1
    count.append(brcou)
print(max(count))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, string
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**7)
inf = float('inf')
mod = 10**9+7
ans = inf ;count = 0 ;pro = 1
D=collections.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(0,max(D.values())))

Submission status: Accepted

Solution code:
N=int(input())
sn=[input() for i in range(N)]
M=int(input())
tn=[input() for i in range(M)]
ans = 0
value =[]
for l in set(sn):
    value.append(sn.count(l) - tn.count(l))
print(max(0, max(value)))

Submission status: Accepted

Solution code:
N = int(input())
s = [input() for s in range(N)]
M = int(input())
t = [input() for t in range(M)]
ans = [s.count(s[i]) - t.count(s[i]) for i in range(N)]
ans.append(0)
print(max(ans))

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)]
blue = collections.Counter(s)
red = collections.Counter(t)
ans = ""
for k_b,v_b in blue.items():
  for k_r,v_r in red.items():
    if k_b == k_r:
      blue[k_b] = v_b - v_r
if max(blue.values()) < 0:
  print(0)
else:
  print(max(blue.values()))

Submission status: Accepted

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

lst = []
lst.extend(nlst)
lst.extend(mlst)
lst = set(lst)

c = [nlst.count(i) - mlst.count(i) for i in lst]
c.append(0)
print(max(c))

Submission status: Accepted

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

ls_u =ls_s + ls_t
p = m + n 

ans = 0


for i in range(n):
    cnt = 0
    for j in range(p):
        if ls_u[i] == ls_u[j] and j <= n - 1:
            cnt += 1
        elif ls_u[i] == ls_u[j] and n - 1 < j:
            cnt += -1
    if cnt >= ans:
        ans = cnt

print(ans)

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

m = 0
for s1 in S:
    x = 0
    for s2 in S:
        if s1 == s2:
            x += 1
    for t in T:
        if t == s1:
            x -= 1

    if x > m:
        m = x
print(m)

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

for i in range(len(t)):
    for j in range(len(s)):
        if t[i] == s[j]:
            del s[j]
            break

d = collections.defaultdict(int)

for c in s:
    d[c] += 1

if len(d) == 0:
    print(0)
else:
    print(max(d.values()))

Submission status: Accepted

Solution code:
N = int(input())

s_dict = {}

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

M = int(input())

t_dict = {}

for i in range(M):
    t = input()
    if t in t_dict:
        t_dict[t] += 1
    else:
        t_dict[t] = 1

maximum = 0

for s_key, s_value in s_dict.items():
    if s_key in t_dict:
        maximum = max(0, s_value - t_dict[s_key], maximum)
    else:
        maximum = max(s_value, maximum)
        
print(maximum)

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

xs = []
for i in set(s+t):
    x = 0
    for j in s:
        if i == j:
            x += 1
    for k in t:
        if i == k:
            x -= 1
    xs.append(x)
print(max(xs + [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 S:
    ans = max(ans, S.count(i) - T.count(i))

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s, t = [],[]
for _ in range(n):
    s.append(input())
s_dict = {s_:0 for s_ in s}
s_dict['aaaaaaaaaaa'] = 0
m = int(input())
for _ in range(m):
    t.append(input())
t_dict = {t_:0 for t_ in t}
for i in range(n):
    s_dict[s[i]] += 1
for i in range(m):
    t_dict[t[i]] += 1
    
for i in s_dict:
    if i in t_dict:
        s_dict[i] -= t_dict[i]
        
print(max(s_dict.values()))

Submission status: Accepted

Solution code:
dicN={}
for i in range(int(input())):
  x=input()
  if x in dicN:
    dicN[x]+=1
  else:
    dicN[x]=1
dicM={}
for i in range(int(input())):
  x=input()
  if x in dicM:
    dicM[x]+=1
  else:
    dicM[x]=1
ls=[0]
for k,v in dicN.items():
  if k in dicM:
    ls.append(v-dicM[k])
  else:
    ls.append(v)
print(max(ls))

Submission status: Accepted

Solution code:
n = int(input())
S = []
for _ in range(n):
    S.append(str(input()))

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

W = S + T

ans = 0

for w in W:
    can = S.count(w) - T.count(w)
    if can >= ans:
        ans = can

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 blue in s:
  reward = s.count(blue) - t.count(blue)
  if reward > 0 and reward > ans:
    ans = reward
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
s = [input() for i in range(N)]
M=int(input())
t = [input() for j in range(M)]
st=s+t
st=(list(set(st)))
cost=[]

for k in st:
    cost.append(s.count(k)-t.count(k))

if max(cost)<=0:
    print(0)
else:
    print(max(cost))

Submission status: Accepted

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

M = int(input())
t = []
for i in range(M):
    t.append(str(input()))
ans = 0
for i in s:
    x = s.count(i)
    y = t.count(i)
    if x - y > ans:
        ans = x - y

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
n_l = list(str(input()) for i in range(n))
m = int(input())
m_l = list(str(input()) for _ in range(m))

index = list(list(set(n_l)) + list(set(m_l)))
l = []

for k in range(len(index)):
    key = index[k]
    a = n_l.count(key)
    b = m_l.count(key)
    l.append(a-b)

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

Submission status: Accepted

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

ans = max(c.most_common()[0][1], 0)
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
BlueCard = list(input() for _ in range(N))
M = int(input())
RedCard = list(input() for _ in range(M))
BlueCard_Counter = Counter(BlueCard)
RedCard_Counter = Counter(RedCard)
ans = 0
for key , blue_cnt in BlueCard_Counter.items():
    if key in RedCard:
        red_cnt = RedCard_Counter[key]
    else:
        red_cnt = 0
    now = blue_cnt - red_cnt
    if ans < now:
        ans = now
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S=[str(input()) for i in range(N)]
M=int(input())
T=[str(input()) for i in range(M)]
S.sort()
result=0

for i in range(N):
	if i<N-1 and S[i]!=S[i+1]:
		if S.count(S[i])-T.count(S[i])>result:
			result=S.count(S[i])-T.count(S[i])
	elif i==N-1 and S.count(S[i])-T.count(S[i])>result:
		result=S.count(S[i])-T.count(S[i])
print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#091b
import collections

N = int(input())
blue_cards = []
for i in range(N):
    s = str(input())
    blue_cards.append(s)
    
M = int(input())
red_cards = []
for i in range(M):
    t = str(input())
    red_cards.append(t)

blue_cards_counted = collections.Counter(blue_cards)
red_cards_counted = collections.Counter(red_cards)

for word in red_cards_counted:
    blue_cards_counted[word] -= red_cards_counted[word]       
    
#print(blue_cards_counted)
print(max(0,max(blue_cards_counted.values())))

Submission status: Accepted

Solution code:
##### 解けた #####

import numpy as np

N=int(input())
S=np.full((N,),".",dtype=object)

# プラスの方
for n in range(N):
    S[n]=input()

M=int(input())
T=np.full((M,),".",dtype=object)

# マイナスの方
for m in range(M):
    T[m]=input()

ust=np.unique(np.append(S,T)) # プラスマイナスについてのユニーク
maxy=0 # これから更新する最大値

# 各ユニークについて
for u in ust:
    y=(len(np.where(S==u)[0])-len(np.where(T==u)[0]))
    maxy=max(maxy,y)

print(maxy)

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

a = Counter(s)
b = Counter(t)

a.subtract(b)
print (max(0,a.most_common(1)[0][1]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
l = [input() for _ in range(n)]

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

c = Counter(l)
c2 = Counter(l2)


ans = [0]

for k,v in c.items():
    ans.append(v-c2[k])
    
print(max(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [input() for i in range(n)]
m = int(input())
b = [input() for i in range(m)]
min = 0
for i in range(n):
    max = a.count(a[i])-b.count(a[i])
    if max >= min:
        min = max
    else:
        pass
print(min)

Submission status: Accepted

Solution code:
N = int(input())

card = {}
for i in range(N):
    tmp = input()
    if tmp in card:
        card[tmp] += 1
    else:
        card[tmp] = 1
        
M = int(input())
for i in range(M):
    tmp = input()
    if tmp in card:
        card[tmp] -= 1
 
print(max(0, max(card.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)]

ans = 0
s_set = set(s)

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

Submission status: Accepted

Solution code:
#テストファイルで実行する時
import sys
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')

n = int(input())
s = [list(map(str,input().split())) for i in range(n)]

m = int(input())
t = [list(map(str,input().split())) for i in range(m)]

ans = -1000

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

print( ans if ans >=0 else 0)

Submission status: Accepted

Solution code:
n = int(input())

al = []
for _ in range(n):
    al.append(input())

m = int(input())
bl = []
for _ in range(m):
    bl.append(input())

ans = 0
for i in list(set(al)):
    tmp = al.count(i) - bl.count(i)
    ans = max(ans,tmp)

print(ans)

Submission status: Accepted

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

answer = 0
for word in cards:
  if answer < cards[word]:
    answer = cards[word]
# print(cards)
print(0 if answer < 0 else answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict 

dic_b = defaultdict(int)
dic_r = defaultdict(int)

N = int(input())
for _ in range(N):
    dic_b[input()] +=1 

M = int(input())
for _ in range(M):
    dic_r[input()] +=1 
#print(dic_b); print(dic_r)

dif = []
for key in dic_b:
    dif.append(dic_b[key] - dic_r[key])
#print(dif)

print( max(0, max(dif)) )

Submission status: Accepted

Solution code:
def examB():
    N = I(); s = [S() for _ in range(N)]
    M = I(); t = [S() for _ in range(M)]
    d = defaultdict(int)
    for l in s:
        d[l] +=1
    for l in t:
        d[l] -=1
    ans = max(0,max(d.values()))
    print(ans)


import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examB()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 青のカードを記録
N = int(input())
colors = {}
for _ in range(N):
    color = input()
    if colors.get(color):
        colors[color] += 1
    else:
        colors[color] = 1

# 赤のカードを記録        
M = int(input())
for _ in range(M):
    color = input()
    if colors.get(color):
        colors[color] -= 1
    else:
        colors[color] = -1

max_point = 0
for value in colors.values():
    if value > max_point:
        max_point = value
print(max_point)

Submission status: Accepted

Solution code:
n = int(input())
s = []
for _ in range(n) :
    s += [input()]
m = int(input())
t = []
for _ in range(m) :
    t += [input()]
wordlist = list(set(s))
s_countdict = {word : s.count(word) for word in wordlist}
t_countdict = {word : t.count(word) for word in wordlist}
pointlist = [s_countdict[word] - t_countdict[word] for word in wordlist]
print(max(max(pointlist), 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)]

d={}
for i in s:
  d[i]=d.get(i,0)+1
for i in t:
  d[i]=d.get(i,0)-1
ans=max(0,max(d.values()))
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
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect_left
import heapq

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()))
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 s:
	ans = max(ans, dic_s[st]-dic_t[st])
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np
import math

n = int(stdin.readline().rstrip())
lin = [stdin.readline().rstrip() for _ in range(n)]
m = int(stdin.readline().rstrip())
lim = [stdin.readline().rstrip() for _ in range(m)]

lis = list(set(lin))
ma = 0
for i in lis:
    ma = max(lin.count(i)-lim.count(i),ma)

print(ma)

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

sCount = {}
for s in S:
    sCount[s] = S.count(s)

tCount = {}
for t in T:
    tCount[t] = T.count(t)

union = sCount.keys() & tCount.keys()
ans = sCount;
for i in union:
    ans[i] = sCount[i] - tCount[i]
    
if max(ans.values()) >= 0:
    print(max(ans.values()))
else:
    print(0)

Submission status: Accepted

Solution code:
N = int(input())
S = {}
for i in range(N):
    j = input()
    if((j in S) == False):
        S[j] = 1
    else:
        S[j] += 1
M = int(input())
T = {}
for i in range(M):
    j = input()
    if((j in T) == False):
        T[j] = 1
    else:
        T[j] += 1
ans = 0
for key,value in S.items():
    if(key in T):
        ans = max(ans,value - T[key])
    else:
        ans = max(ans,value)
print(ans)

Submission status: Accepted

Solution code:
import collections


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

    Mcnt = 0
    for s, ns in S.items():
        cnt = 0
        if s in list(T.elements()):
            if T[s] < ns:
                cnt = ns - T[s]
        else:
            cnt = ns

        if cnt > Mcnt:
            Mcnt = cnt

    print(Mcnt)


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

s1=set(s)
t1=set(t)
ans=0
for i in s1:
    ans=max(ans,s.count(i)-t.count(i))
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 range(len(s)):
    point = 0
    kw = s[i]
    for j in range(len(s)):
        if s[j] == kw:
            point += 1
    for j in range(len(t)):
        if t[j] == kw:
            point -= 1
    ans = max(ans, point)
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)]

announced = set(s + t)
earned = 0

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

print(earned if earned > 0 else 0)

Submission status: Accepted

Solution code:
N = int(input())
p = {}

for _ in range(N):
    s = input()
    p.setdefault(s, 0)
    p[s] += 1

M = int(input())

for _ in range(M):
    s = input()
    p.setdefault(s, 0)
    p[s] -= 1

ans = max(p.values())

print(ans if ans >= 0 else 0)

Submission status: Accepted

Solution code:
from collections import defaultdict

d = defaultdict(int)
n = int(input())
for _ in range(n):
  key = input()
  d[key] += 1
m = int(input())
for _ in range(m):
  key = input()
  d[key] -= 1
print(max(max(d.values()), 0))

Submission status: Accepted

Solution code:
N = int(input())
blues = [input() for _ in range(N)]
M = int(input())
reds = [input() for _ in range(M)]
points = [blues.count(blue)-reds.count(blue) for blue in blues]
print(max(points) if max(points)>0 else 0)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
n=int(input())
s=[]
ans=-10000
for i in range(n):
    s.append(input())
m=int(input())
t=[]
for j in range(m):
    t.append(input())
for k in range(n):
    if s.count(s[k])-t.count(s[k])>ans:
        ans=s.count(s[k])-t.count(s[k])
if ans>0:
    print(ans)
else:
    print(0)

Submission status: Accepted

Solution code:
n = int(input())
list_str = []
list_p = []
for _ in range(n):
  s = input()
  if s in list_str:
    list_p[list_str.index(s)] += 1
  else:
    list_str.append(s)
    list_p.append(1)
m = int(input())
for _ in range(m):
  t = input()
  if t in list_str:
    list_p[list_str.index(t)] -= 1
  else:
    list_str.append(s)
    list_p.append(-1)
if max(list_p) >= 0:
  print(max(list_p))
else:
  print(0)

Submission status: Accepted

Solution code:
from itertools import chain
import sys
def input(): return sys.stdin.readline().strip()

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

main()

Submission status: Accepted

Solution code:
b = [input() for i in range(int(input()))]
r = [input() for i in range(int(input()))]
k = 0
for w in list(set(b)):
  k = max(k, b.count(w) - r.count(w))
print(k)

Submission status: Accepted

Solution code:
b = [input() for i in range(int(input()))]
r = [input() for i in range(int(input()))]
o = 0
for w in list(set(b)):
  o = max(o, b.count(w) - r.count(w))
  
print(o)

Submission status: Accepted

Solution code:
import collections

def insert_card(card_number, card_list):
    i = 0
    while i < card_number:
        card_list.append(input())
        i += 1


blue_card_number = int(input())
blue_card_list = []
insert_card(blue_card_number, blue_card_list)

red_card_number = int(input())
red_card_list = []
insert_card(red_card_number, red_card_list)

blue_card_collection = collections.Counter(blue_card_list)
red_card_collection = collections.Counter(red_card_list)

result_card_collection = blue_card_collection - red_card_collection

answer_collection = sorted(result_card_collection.items(), key=lambda x:x[1], reverse=True)
if answer_collection == []:
    print(0)
else:
    print(answer_collection[0][1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict
d = defaultdict(int)

n = int(input())
for _ in range(n):
    d[input()] += 1

m = int(input())
for _ in range(m):
    d[input()] -= 1


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

Submission status: Accepted

Solution code:
n = int(input())
ss = [input() for _ in range(n)]
m = int(input())
tt = [input() for _ in range(m)]
ans = 0

for s in ss:
    ans = max(ans, (ss.count(s)-tt.count(s)))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

s_set=set(s)
ans=0
for i in s:
    score = s.count(i)-t.count(i)
    if score>ans:
        ans=score
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
l = {}
ans = 0
for _ in range(N):
  s = input()
  if s in l:
    l[s] = l[s] + 1
  else:
    l[s] = 1
M = int(input())
for _ in range(M):
  s = input()
  if s in l:
    l[s] = l[s] - 1
for v in l.values():
  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)]

Max = 0
for i in set(s):
    C = 0
    C = s.count(i) - t.count(i)
    if Max < C:
        Max = C
print(Max)

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

d = {}
for i in s:
    d[i] = d.get(i, 0)+1
for i in t:
    d[i] = d.get(i, 0)-1
ans = max(0, max(d.values()))
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
s = [input() for i in range(n)]
m = inp()
t = [input() for i in range(m)]
ds = defaultdict(int)
dt = defaultdict(int)
for i in s:
    ds[i] += 1
for i in t:
    dt[i] += 1
res = 0
for key in ds.keys():
    res = max(res, ds[key] - dt[key])
print(res)

Submission status: Accepted

Solution code:
#                         author:  kagemeka 
#                         created: 2019-11-06 22:04:18(JST)
import sys
import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator

def main():
    l = sys.stdin.read().split()
    n = int(l[0])
    m = int(l[n+1])
    a = collections.Counter(l[1:n+1])
    b = collections.Counter(l[n+2:n+m+2])
    for s, c in b.items():
        if s in a:
            a[s] -= c

    ma = max(max(a.values()), 0)
    print(ma)
        

if __name__ == "__main__":
    # execute only if run as a script
    main()

Submission status: Accepted

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

nums = []
for s in scounter.keys():
    nums.append(scounter[s] - tcounter[s])

max_num = max(nums)
print(max_num if max_num > 0 else 0)

Submission status: Accepted

Solution code:
n = int(input())
s = []
for i in range(n):
    j = input()
    s.append(j)
m = int(input())
t = []
for k in range(m):
    h = input()
    t.append(h)
couS=[]
for i in range(n):
    count=0
    count+=s.count(s[i])
    count-=t.count(s[i])
    couS.append(count)
    
if max(couS)<0:
    print(0)
else:
    print(max(couS))

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


def list_diff(list1, list2):
    result = list1.copy()
    for val in list2:
        if val in result:
            result.remove(val)
    return result


def count_max(diff_list):
    cnt_list = [diff_list.count(ele) for ele in set(diff_list)]
    if len(cnt_list) != 0:
        return max(cnt_list)
    else:
        return 0


lst = list_diff(s_list, t_list)
print(count_max(lst))

Submission status: Accepted

Solution code:
D = {}
N = int(input())
for _ in range(N):
    a = input()
    if a in D:
        D[a] += 1
    else:
        D[a] = 1
M = int(input())
for _ in range(M):
    a = input()
    if a in D:
        D[a] -= 1
    else:
        D[a] = -1
ma = 0
for a in D:
    ma = max(ma, D[a])
print(ma)