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:

def main():
    b = int(input())
    d = dict()

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

    r = int(input())

    for i in range(r):
        s = input()
        if s in d:
            d[s] -= 1
        else:
            d[s] = -1

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







if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import collections
n = int(input())
s = [str(input()) for i in range(n)]
m = int(input())
t = [str(input()) for i in range(m)]
set_s = set(s)
set_t = set(t)
blue = set(s) - set(t)
ss = collections.Counter(s)
tt = collections.Counter(t)
set_s_t = set(s) & set(t)
Max = -999999999
for i in set_s_t:
    Max = max(Max,ss[i]-tt[i])
for i in blue:
    Max = max(Max,ss[i])
if Max < 0:
    Max = 0
print(Max)

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

cs=Counter(S)
ct=Counter(T).most_common()

for i in range(len(ct)):
    cs[ct[i][0]]-=ct[i][1]

print(max(0,cs.most_common()[0][1]))

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
blue_cards = Counter(input() for _ in range(N))
M = int(input())
red_cards = Counter(input() for _ in range(M))
ans = 0
for blue_word, blue_count in blue_cards.items():
    tmp_ans = blue_count
    if blue_word in red_cards.keys():
        tmp_ans -= red_cards[blue_word]
    if tmp_ans > ans:
        ans = tmp_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)]

yen=0
for i in set(s):
    num=s.count(i)
    num2=t.count(i)
    yen=max(yen,num-num2)
print(yen)

Submission status: Accepted

Solution code:
from collections import defaultdict as dd
n=int(input())
d=dd(int)
ans=0
for i in range(n):
    s=input()
    d[s]+=1
m=int(input())
for i in range(m):
    s=input()
    d[s]-=1
v=max(d.values())
print(max(v,0))

Submission status: Accepted

Solution code:
# Problem B - Two Colors Card Game

# input
N = int(input())
s_list = {}
for i in range(N):
    s = input()
    if s in s_list:
        s_list[s] += 1
    else:
        s_list[s] = 1
M = int(input())
t_list = {}
for i in range(M):
    t = input()
    if t in t_list:
        t_list[t] += 1
    else:
        t_list[t] = 1

# initialization
max_cost = 0

# count step
for s in s_list:
    s_cost = s_list[s]
    if s in t_list:
        max_cost = max(max_cost, s_cost - t_list[s])
    else:
        max_cost = max(max_cost, s_cost)

# output
print(max_cost)

Submission status: Accepted

Solution code:
import sys
from collections import deque

def solve():
    input = sys.stdin.readline
    N = int(input())
    point = dict()
    for _ in range(N):
        s = input().strip("\n")
        if s in point: point[s] += 1
        else: point[s] = 1
    M = int(input())
    for _ in range(M):
        s = input().strip("\n")
        if s in point: point[s] -= 1
        else: point[s] = -1
    
    Ans = 0
    for key in point:
        Ans = max(Ans, point[key])
    print(Ans)


    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
n = int(input())
S = {}
for i in range(n):
    s = str(input())
    if s not in S:
        S[s] = 1
    else:
        S[s] += 1
m = int(input())
T = {}
for i in range(m):
    t = str(input())
    if t not in T:
        T[t] = 1
    else:
        T[t] += 1

ans = 0
for k, v in S.items():
    if k in T:
        ans = max(ans, v-T[k])
    else:
        ans = max(ans, v)
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)]
sc=Counter(s)
tc=Counter(t)
u=list(set(s)&set(t))
ans=0
for i in u:
    ans=max(ans,max(0,sc[i]-tc[i]))
v=list(set(s)-set(u))
for i in v:
    ans=max(ans,sc[i])
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
s = []
for i in range(n):
    s.append(input())
m = int(input())
t = []
for i in range(m):
    t.append(input())

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

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    n = int(input())
    s = dict()
    for _ in range(n):
        tmp = input()
        if tmp in s:
            s[tmp] += 1
        else:
            s[tmp] = 1

    m = int(input())
    t = dict()
    for _ in range(m):
        tmp = input()
        if tmp in t:
            t[tmp] += 1
        else:
            t[tmp] = 1

    ans = 0
    for ss in s:
        if ss in t:
            tmp = s[ss] - t[ss]
        else:
            tmp = s[ss]
        if tmp > ans:
            ans = tmp

    print(ans)

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

SS = collections.Counter(S)

TT = collections.Counter(T)

ans = 0
for i in S:
    tes = SS[i] - TT[i]
    ans = max(ans,tes)
    
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)]

from collections import Counter
Sc = Counter(S)
Tc = Counter(T)
ans = 0
for s in set(S):
    tmp = Sc[s] - Tc[s]
    ans = max(ans, tmp)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

m = int(input())
T = {}
for _ in range(m):
    t = input()
    if t in T:
        T[t] += 1
    else:
        T[t] = 1

ans = 0
for k in S.keys():
    if k in T:
        ans = max(ans, S[k]-T[k])
    else:
        ans = max(ans, S[k])
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
s = list(input() for _ in range(n))
m = int(input())
t = list(input() for _ in range(m))

res = Counter(s)
for i in range(m):
    if t[i] in res:
        res[t[i]] -= 1

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

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
s = Counter([input() for k in range(N)])
M = int(input())
t = Counter([input() for k in range(M)])
ans = 0
for e in s:
    if e not in t:
        ans = max(ans,s[e])
    else:
        ans = max(ans,s[e]-t[e])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [input() for i in range(N)]
    M = int(input())
    B = [input() for i in range(M)]
    ans = 0
    from collections import Counter
    S = Counter(A)
    T = Counter(B)
    for k, v in S.items():
        ans = max(ans, v - T[k])
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict

cnt = defaultdict(int)

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

M = int(input())
for _ in range(M):
    cnt[input()] -= 1

ans = 0
for c in cnt.values():
    ans = max(ans, c)
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

cnt = defaultdict(int)

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

M = int(input())
for _ in range(M):
    cnt[input()] -= 1

ans = 0
for c in cnt.values():
    ans = max(ans, c)

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
d=defaultdict(int)
for i in range(int(input())):d[input()]+=1
for i in range(int(input())):d[input()]-=1
print(max(max(d[i]for i in d),0))

Submission status: Accepted

Solution code:
bn = int(input())
bd = []; bdd = {}
for i in range(bn):
    bd = input().split()[0]
    try:
        bdd[str(bd)] += 1
    except:
        bdd[str(bd)] = 1

rn = int(input())
rd = []
for i in range(rn):
    rd = input().split()[0]
    try:
        bdd[str(rd)] -= 1
    except:
        continue
    
l = [s for s in bdd.values()]
l.append(0)
print(max(l))

Submission status: Accepted

Solution code:
n = int(input())
d = {}
for i in range(n):
    s = input()
    try:
        d[s] += 1
    except:
        d[s] = 1

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

max_num = 0
for item in d.items():
    if item[1] > max_num:
        max_num = item[1]

print(max_num)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = []
for i in range(n):
    s.append(input())
s = Counter(s)
m = int(input())
t = []
for i in range(m):
    t.append(input())
t = Counter(t)

mx = 0
for k, v in s.items():
    if k in t:
        s[k] = max(s[k]-t[k], 0)
    mx= max(mx, s[k])
print(mx)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline

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

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

for i in t:
	if(i in s):
		s.pop(s.index(i))




max=0
for i in s:
	if(s.count(i)>max):
		max=s.count(i)

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)]
score = []
for i in range(N):
  score.append(s.count(s[i]) - t.count(s[i]))
if max(score) > 0:
  print(max(score))
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)]
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:
# Ref. https://atcoder.jp/contests/abc091/submissions/5903551

from collections import defaultdict
d = defaultdict(int)

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

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

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

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = [input() for i in range(n)]
m = int(input())
b = [input() for i in range(m)]
x = collections.Counter(a)
y = collections.Counter(b)
ans = 0
for i in x.keys():
    cnt = x[i]
    if i in y.keys(): cnt -= y[i]
    ans = max(ans,cnt)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(input() for _ in range(n))
m = int(input())
b = list(input() for _ in range(m))

dict_a = {}
dict_b = {}

for i in a:
    if i in dict_a:
        dict_a[i] += 1
    else:
        dict_a[i] = 1

for i in b:
    if i in dict_b:
        dict_b[i] += 1
    else:
        dict_b[i] = 1

for c in dict_a.keys():
    if c in dict_b.keys():
        dict_a[c] -= dict_b[c]
print(max(0, max(dict_a.values())))

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    ss = [input() for _ in range(n)]
    m = int(input())
    ts = [input() for _ in range(m)]

    fruits = list(set(ss))
    ans = 0
    for fruit in fruits:
        money = 0
        money += ss.count(fruit)
        money -= ts.count(fruit)
        ans = max(ans, money)
    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)]

ans=0

for i in range(n):
    if ans<s.count(s[i])-t.count(s[i]):
        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)]
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

# print(d)
v = max(d.values())
if v >= 0:
    print(max(d.values()))
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)]

mojiretsu = {}

for item in s:
    if not item in mojiretsu:
        mojiretsu.setdefault(item, 1)
    else:
        mojiretsu[item] += 1

for item in t:
    if not item in mojiretsu:
        mojiretsu.setdefault(item, -1)
    else:
        mojiretsu[item] -= 1

# mojiretsu_sorted = sorted(mojiretsu.items(), key=lambda x:x[1], reverse=True)

# print("{}".format(mojiretsu_sorted.values()))

max_coin = 0
for i in mojiretsu.values():
    if max_coin < i:
        max_coin = i

print("{}".format(max_coin))

Submission status: Accepted

Solution code:
n = int(input())
dic = dict()
for i in range(n):
    s = input()
    if s not in dic:
        dic[s] = 0
    dic[s] += 1
m = int(input())
for i in range(m):
    s = input()
    if s not in dic:
        dic[s] = 0
    dic[s] -= 1
ans = list(dic.values())
print(max(max(ans),0))

Submission status: Accepted

Solution code:
from collections import defaultdict
d = defaultdict(int)
d["D"]=0

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

n=int(input())
for _ in range(n):
  d[input()]-=1
  
print(max(d.values()))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import itertools#これは色々使える組み込み関数みたいなやつ
import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
from collections import Counter
#w=input()
i=0
j=0
s=0#価値の計算に使う何もしないときが0
eq=''
diff= 0
N=int(input())
#red_list =  (list(input())for i in range(N))
red_list =[[input() for i in range(1)for j in range(N)]]
red_simple_list=red_list[0]
#print(red_simple_list)
#Nori=N
#D, N=input().split()
#S=input()
M=int(input())
blue_list =[[input() for i in range(1)for j in range(M)]]
blue_simple_list=blue_list[0]
#print(red_list)
#print(blue_list)
for j in range(N-1):#二次元配列注意
 #print(red_list[0][0])
 #print(j)
 #print(red_list.count(red_list[0][j]))
 eq=red_simple_list[j]
 #print(type(eq))
 #print(eq)
 
 diff=red_simple_list.count(eq)-blue_simple_list.count(eq)
 #diff=red_list.count(red_list[j])-blue_list.count(red_list[j])
 if diff > s:
     s= diff
print(s)

# def flatten_2dim(array):
#     return [item for sublist in array for item in sublist]

# counter = Counter(flatten_2dim(red_list[i]))
# print(counter)
# for word, cntr in counter.most_common():
#     print(word, cntr)
#S_list=list(S)

#M=int(input())
#drink_list = [list(map(int, input().split(" ")))for i in range(M)]
#print(T_list[1])
#D=int(D)
#N=int(N)
#不本意だが内包表記で二次元の空のリストを作成する
     
#dp=[['' for i in range(2)] for j in range(N)]
#absTH=[''for i in range(N)]
#K=int(K)
#S_list=[]
#sentence_list=[]
#total=0
#mojiretu=""
#センテンスを暗記するのではなく、まずinput()を書いて、膨らます感じで記述する。すると#思考の流れ通りに書ける。素晴らしい！
#for i in range(K):
# ID_list.append(i+1)
#print(ID_list)
#for i in range(H)
#この下の行が二次元リストの読み込
#intを消して記号を読み込めるようにしたしかしこれでは文字列から読み込んでいるのと同じ
#weight_value_list =  [list(input())for i in range(N)]#一文字づつばらして入れてしまう
#s = [input() for i in range(N)]
#複数行に複数の入力値を取得し、出力する
#sentence_list =  (list(input())for i in range(N))
#for i in range(H):
#  ppixel_list=list(input())
    
#print(pixel_list)
#high_pixel_list =[['' for i in range(W)]for j in range(2*H)]
#print(high_pixel_list)
#print(pixel_list[0][1])#行　列の順番にかっこが並んでいる
#print(a_list)
first_term=0
second_term=0
#整数二次元配列を読み込む時のやり方
#a_b_c_list =  [list(map(int, input().split(" ")))for i in range(N)]
     
#センテンスを暗記するのではなく、まずinput()を書いて、膨らます感じで記述する。すると#思考の流れ通りに書ける。素晴らしい！
  
     
#x, y = [0]*N, [0]*N#N個の空のリストを作成
#l = list(range(N))#範囲がNのリストを作成する
     
#for i in range(N):
#  x[i], y[i] = map(int, input().split())
#分けて入力する形式を設定することで可読性が高く仕上がっている
#素晴らしいことだ
     
     

#comb = list(itertools.permutations(l))
#prmutation:英語の意味としては順列である
'''p[, r]で
長さrのタプル列、重複なしのあらゆる並びを表す
今回はリストlの重複なしの並び替え順序を新たなリストに収納している
並び方を計算しリストに収納しているイメージ
l[0,1,2]
l[0,2,1]これにもリスト番号が0,1,2と割り振られている
これが全通り入っている
これ作った人はすごい
自分も早く理解したい
'''
#for i in range(0, len(comb)):#i番目のパターンの時を考える。
#  for j in range(0, N-1):#lのリスト番号を読み込み
#    distance += math.sqrt((x[comb[i][j]]-x[comb[i][j+1]])**2 + (y[comb[i][j]]-y[comb[i][j+1]])**2)
'''
各経路の距離を足していき全距離分を経路数
で割れば平均距離が出るので各経路ごとの距離は
不必要と判断されている。
'''
#print(distance/len(comb))
# dp[i+1][j]=max(dp[i][j]+a_b_c_list[i],dp[i][j],dp[i][j])
#リストを一周するようにすればいいのか

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

Submission status: Accepted

Solution code:
from collections import defaultdict
def main():
    N = int(input())
    ans = 0
    s = defaultdict(int)
    for _ in range(N):
        a = input()
        s[a] += 1
    M = int(input())
    for _ in range(M):
        b = input()
        s[b] -= 1
    for v in s.items():
        ans = max(ans,v[1])
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math
import string


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

N = int(input())
s = []
for _ in range(N):
    s.append(input())
# print(s)
M = int(input())
t = []
for _ in range(M):
    t.append(input())
# print(t)
x = 0
y = 0
ma = 0
for i in range(len(s)):
    x = s.count(s[i])
    y = t.count(s[i])
    ma = max(ma, (x-y))
print(ma)

Submission status: Accepted

Solution code:
def Two_Colors(n , sl , m , tl):

    ans = 0
    count = {}

    for i in range(n):
        if sl[i] in count:
            count[sl[i]] += 1
        else:
            count[sl[i]] = 1

    for i in range(m):
        if tl[i] in count:
            count[tl[i]] -= 1
        else:
            count[tl[i]] = -1

    for i in count.values():
        ans = max(ans , i)

    return ans

def main():
    n = int(input())
    sl = [str(input()) for i in range(n)]
    m = int(input())
    tl = [str(input()) for i in range(m)]
    print(Two_Colors(n , sl , m , tl))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
nn=[]
for i in range(n):
    nn.append(input())
m=int(input())
mm=[]
for i in range(m):
    mm.append(input())
ans=0
nns=set(nn)
for i in nns:
    tmp = nn.count(i)- mm.count(i) 
    ans=max(ans,tmp)

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

N = Counter([input() for _ in range(int(input()))])
M = Counter([input() for _ in range(int(input()))])
print(max(0, max(N[key]-M[key] for key in N.keys())))

Submission status: Accepted

Solution code:
N = int(input())
max1 = 0
blue_dic = {}
red_dic = {}
for i in range(N):
    b = input()
    if b in blue_dic:
        blue_dic[b] += 1
    else:
        blue_dic[b] = 1
M = int(input())
for i in range(M):
    r = input()
    if r in red_dic:
        red_dic[r] += 1
    else:
        red_dic[r] = 1
for kb, vb in blue_dic.items():
    tmp = 0
    tmp += vb
    if kb in red_dic:
        tmp -= red_dic[kb]
    if tmp > max1:
        max1 = tmp
print(max1)

Submission status: Accepted

Solution code:
N=int(input())
blue=[]
for a in range(N):
    b=input()
    blue.append(b)
M=int(input())
red=[]
for c in range(M):
    d=input()
    red.append(d)
nblue=[]
for a in blue:
    if a in nblue:
        pass
    else:
        nblue.append(a)
numbers=[]
for b in nblue:
    c=blue.count(b)-red.count(b)
    numbers.append(c)
if max(numbers)<=0:
    print(0)
else:
    print(max(numbers))

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

s1=set(s)
m=0
for i in s1:
    cnt=s.count(i)-t.count(i)
    m=max(cnt,m)
print(m)

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

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

Submission status: Accepted

Solution code:
#abc091 b
n=int(input())
card=dict()
for i in range(n):
    s=input()
    if s not in card:
        card[s]=1
    else:
        card[s]+=1
m=int(input())
for i in range(m):
    t=input()
    if t not in card:
        card[t]=-1
    else:
        card[t]-=1
ans=-m

for i in card.values():
    ans=max(ans,i,0)
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from collections import defaultdict
import sys
#input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))

D = defaultdict(int)
for _ in range(int(input())):
    D[input()] += 1
for _ in range(int(input())):
    D[input()] -= 1

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

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
ss = list(input() for _ in range(n))
m = int(input())
tt = list(input() for _ in range(m))
dic = defaultdict(int)

for s in ss:
    dic[s] += 1
for t in tt:
    dic[t] -= 1

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

Submission status: Accepted

Solution code:
N=int(input())
s=[]
for i in range(N):
    s+=[input()]
M=int(input())
t=[]
for i in range(M):
    t+=[input()]
ans1=0
ss=list(set(s))
for i in range(len(set(s))):
    ans=s.count(ss[i])-t.count(ss[i])
    ans1=max(ans1,ans)
if ans1<0:
    print(0)
    exit()
print(ans1)

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

Counter_S = Counter(S)
Counter_T = Counter(T)
Counter_plus = Counter_S - Counter_T
if len(Counter_plus.values()):
    print(max(Counter_plus.values()))
else:
    print(0)

Submission status: Accepted

Solution code:
N = int(input())
blue = {}
for i in range(N):
    a = input()
    if a not in blue:
        blue[a] = 1
    else:
        blue[a] += 1
        
M = int(input())
#red = {}
for i in range(M):
    a = input()
    if a not in blue:
        blue[a] = -1
    else:
        blue[a] -= 1
print(max(0, max(blue.values())))

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 s in S:
  S_count = S.count(s)
  T_count = T.count(s)
  ans = max(ans,S_count - T_count)

print(ans)

Submission status: Accepted

Solution code:
n=int(input())

card={}
card_key=set([])

for _ in range(n):
  temp=input()
  if temp in card_key:
    card[temp]+=1
  else:
    card_key.add(temp)
    card[temp]=1

m=int(input())

for _ in range(m):
  temp=input()
  if temp in card_key:
    card[temp]-=1
  else:
    card_key.add(temp)
    card[temp]=-1
#print(card)
result=0
for item in card_key:
  result=max(result,card[item])
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)]
ans = 0
for s in set(S+T):
  ans = max(ans, S.count(s) - T.count(s))
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())
blue = Counter([input() for i in range(N)])
M=int(input())
red = [input() for i in range(M)]
for i in red:
    if i in blue:
        blue[i] -=1
ans = 0
for i in blue.values():
    if ans < i:
        ans = i
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
red = {}
for i in range(N):
    tmp = input()
    if tmp in red:
        red[tmp] += 1
    else:
        red[tmp] = 1

M = int(input())
for i in range(M):
    tmp = input()
    if tmp in red:
        red[tmp] -= 1

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

Submission status: Accepted

Solution code:
from collections import *
c=Counter({0:0})
for i in (1,-1):
  for _ in range(int(input())): c[input()]+=i
print(max(c.values()))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
s=[None]*n
for i in range(n):
  s[i]=input()
m=int(input())
t=[None]*m
for i in range(m):
  t[i]=input()
ans=0
a=[0]*n
for i in range(n):
  for j in range(n):
    if s[i]==s[j]:
      a[i]+=1
    else:
      pass
for i in range(n):
  for j in range(m):
    if s[i]==t[j]:
      a[i]-=1
    else:
      pass

b=max(a)
print(max(ans,b))

Submission status: Accepted

Solution code:
# import math
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque
from collections import Counter

# import numpy as np
# import scipy as scp

# 入力の受け取り
n = int(input())
arrN = []
for _ in range(n):
    arrN += [input()]  #table.append(input())とも書ける
m = int(input())
arrM = []
for _ in range(m):
    arrM += [input()]  #table.append(input())とも書ける

countaN = Counter(arrN)
countaM = Counter(arrM)
countaAns = countaN - countaM

if len(countaAns) !=0:
    s,ans = countaAns.most_common()[0]
else:
    ans = 0

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

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+T):
  ans = max(ans, S.count(s) - T.count(s))

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

ds = defaultdict(int)
dt = defaultdict(int)

for i in range(N):
  ds[S[i]] += 1
for i in range(M):
  dt[T[i]] -= 1
  
keys = []
i = 0
for key in ds.keys():
  keys.append(key)
for key in dt.keys():
  keys.append(key)

ans = 0
for s in keys:
  ans = max(ans, ds[s] + dt[s])
print(ans)

Submission status: Accepted

Solution code:
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():
    n=int(input())
    l1=[str(input()) for i in range(n)]
    m=int(input())
    l2=[str(input())    for i in range(m)]

    ans=0
    for i in l1:
        ans=max(l1.count(i)-l2.count(i),ans)
    for j in l2:
        ans=max(l1.count(i)-l2.count(i),ans)
    print(ans)



resolve()

Submission status: Accepted

Solution code:
import sys
import os
import re
import datetime

card = {}

N = int(input())
for _ in range(N):
	s = input()
	if s in card:
		card[s] += 1
	else:
		card[s] = 1
		
M = int(input())
for _ in range(M):
	t = input()
	if t in card:
		card[t] -= 1
	else:
		card[t] = -1

maxCount = 0
#print(card)
for count in card:
	maxCount = max(maxCount, max(card.values()))

print(maxCount)

Submission status: Accepted

Solution code:
N = int(input())
point = dict()
for _ in range(N):
  s = str(input())
  if s in point.keys():
    point[s] += 1
  else:
    point[s] = 1

M = int(input())
for _ in range(M):
  t = str(input())
  if t in point.keys():
    point[t] -= 1

ans = max(max(point.values()), 0)
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())

d = {x: 0 for x in s}
for x in s:
    d[x] += 1

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

ans = max(d.values())

print(max(ans,0))

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict

input = lambda: sys.stdin.readline().rstrip()

N = int(input())

d = defaultdict(int)

for i in range(N):
    word = input()
    d[word] += 1

M = int(input())

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

sorted_d = sorted(d.items(), key=lambda x:x[1], reverse=True)

if sorted_d[0][1] <= 0:
    print(0)
else:
    print(sorted_d[0][1])