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:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

from collections import defaultdict


dic = defaultdict(int)

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

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

ans = 0
for tmp in dic:
    ans = max(ans, dic[tmp])

print (ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    card = {}
    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
    card = sorted(card.items(), key=lambda x: x[1], reverse=True)
    print(max(card[0][1], 0))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

C = []  
for i in range(N):
  count = 0
  for j in range(N):
    if S[i] == S[j]:
      count = count + 1
  for k in range(M):
    if S[i] == T[k]:
      count = count -1
  C.append(count)

print(max(0,(max(C))))

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 list(set(S)):
  tmp = S.count(i) - T.count(i)
  if ans < tmp:
    ans = tmp
print(ans)

Submission status: Accepted

Solution code:
import sys
import math
n = int(input())
lis=[]
for i in range(n):
    tmp = input()
    lis.append(tmp)
m = int(input())
lit=[]
for i in range(m):
    tmp = input()
    lit.append(tmp)
lis.sort()
lit.sort()
ans=0
for i in range(len(lis)):
    tmp=0
    for j in lis:
            if j==lis[i]:
                tmp += 1
    if(lis[i] not in lit):
        ans = max(ans, tmp)
    else:
        for j in lit:
            if lis[i] == j:
                tmp -= 1
    ans = max(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
blue_cards={}
red_cards={}

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

m=int(input())

for j in range(m):
    s=input()
    if s in red_cards:
        red_cards[s]+=1
    else:
        red_cards[s]=1

ans=0
for word in blue_cards:
    if word not in red_cards:
        ans=max(ans, blue_cards[word])
    else:
        ans=max(ans, blue_cards[word]-red_cards[word])

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

sc = Counter(s)
tc = Counter(t)
ns = len(sc)
ans = 0

for i in range(ns):
  key = sc.most_common()[i][0]
  if key in tc:
    ans = max(sc[key] - tc[key],ans)
  else:
    ans = max(sc[key],ans)
print(ans)

Submission status: Accepted

Solution code:
import collections

n = int(input())
blue = collections.defaultdict(lambda:0)
for _ in range(n):
  blue[input()] += 1

m = int(input())
red = collections.defaultdict(lambda:0)
for _ in range(m):
  red[input()] += 1

ans = 0
for i,v in blue.items():
  if i not in red:
    ans = max(ans, v)
  else:
    if v > red[i]:
      ans = max(ans, v - red[i])
      
print(ans)

Submission status: Accepted

Solution code:
score_dic = {}

for i in range(int(input())):
    s = input()
    if s not in score_dic:
        score_dic[s] = 1
    else:
        score_dic[s] += 1

for i in range(int(input())):
    t = input()
    if t not in score_dic:
        score_dic[t] = -1
    else:
        score_dic[t] -= 1

max_value = max(score_dic.values())
if max_value < 0:
    print(0)
else:
    print(max_value)

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

Submission status: Accepted

Solution code:
N = int(input())

s = [None] * N
for i in range(N):
    s[i] = input()

sx = {x: s.count(x) for x in set(s)}

M = int(input())
t = [None] * M
for i in range(M):
    t[i] = input()

tx = {x: t.count(x) for x in set(t)}

mx = 0
for sk in sx.keys():
    td = tx[sk] if sk in tx else 0
    mx = max(mx, (sx[sk] - td))

print(mx)

Submission status: Accepted

Solution code:
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**7)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
PI = math.pi
# endregion
N = ri()
s = Counter([rs() for _ in range(N)])
M = ri()
t = Counter([rs() for _ in range(M)])
ans = 0
for si in s.items():
    ans = max(ans, max(si[1] - t[si[0]], 0))
print(ans)

Submission status: Accepted

Solution code:
import collections
n = int(input())
blue = [input() for i in range(n)]
blue_count = collections.Counter(blue)
m = int(input())
red = [input() for i in range(m)]
red_count = collections.Counter(red)
yen = []
for k, v in blue_count.items():
    if k in red_count:
        x = red_count[k]
        count = v - x
        yen.append(count)
    else:
        yen.append(v)
y = max(yen)
print(max(0, y))

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)]
ans=0
for i in s:
    if s.count(i)-t.count(i)>ans:
        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 j 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 = [input() for _ in range(int(input()))]
m = [input() for _ in range(int(input()))]
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:
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)

ans = 0
for key in cs.keys():
    ans = max(ans, cs[key] - ct[key])

print(ans)

Submission status: Accepted

Solution code:
import copy
n = int(input())
s = list(range(n))
for i in range(n):
    s[i] = input()
m = int(input())
t = list(range(m))
for i in range(m):
    t[i] = input()
tmp = list(range(m+n))
s2 = sorted(list(set(s)))
s3 = copy.copy(s2)
t2 = sorted(list(set(t)))
s3.extend(t2)
s3 = set(s3)
ans = []

for i in s3:
     ans.append(s.count(i)-t.count(i))
#print(s)
#print(t)
#print(s2)
#print(t2)
#print(s3)
#print(ans)
if max(ans) < 0:
    print(0)
else:
    print(max(ans))

Submission status: Accepted

Solution code:
n = int(input())
b_list = []
uni = []
for i in range(n):
  b = input()
  b_list.append(b)
  if not b in uni:
    uni.append(b)

m = int(input())
r_list = []
r_uni = []
for i in range(m):
  r = input()
  r_list.append(r)
  if not r in uni:
    uni.append(r)

uni.append("aaaaaaaaaaa")
uni_l = len(uni)
c = []
for i in range(uni_l):
  c.append(b_list.count(uni[i]) - r_list.count(uni[i]))
print(max(c))

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
s_inputs = [input() for i in range(n)]
m = int(input())
t_inputs = [input() for i in range(m)]

s_count = Counter(s_inputs)
t_count = Counter(t_inputs)

ans=0
for s in set(s_inputs+t_inputs):
    tmp = s_count[s]-t_count[s]
    if tmp>ans:
        ans=tmp
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
import re
import math
from collections import defaultdict
import itertools
from copy import deepcopy
import random
from heapq import heappop,heappush
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
#@lru_cache(maxsize=None)
readline=sys.stdin.readline
sys.setrecursionlimit(2000000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_power(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
def hani(x,min_,max_):
    ret=x
    if x<min_:ret=min_
    if x>max_:ret=max_
    return ret
def seifu(x):
    return x//abs(x)
###################################################

def main():
    n=int(input())
    dic=defaultdict(int)
    for a in range(n):
        dic[input()]+=1
    m=int(input())
    for a in range(m):
        dic[input()]-=1
    mmax=0
    for a in dic.values():
        mmax=max(mmax,a)
    print(mmax)
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):
    ans = max(s.count(s[i]) - t.count(s[i]), ans)
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 x in set(s) | set(t):
    d = s.count(x) - t.count(x)
    ans = max(ans, d)
print(ans)

Submission status: Accepted

Solution code:
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N = int(input())
S = [input().rstrip() for _ in range(N)]
M = int(input())
T = [input().rstrip() for _ in range(M)]

from collections import defaultdict
dic = defaultdict(int)

for s in S:
    dic[s] += 1
for t in T:
    dic[t] -= 1

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    s_arr = []
    for i in range(N):
        _ =     _in[i+1]   # type:str
        s_arr.append(_)
    M = int(_in[N+1])  # type:int
    t_arr = []
    for i in range(M):
        _ =     _in[i+N+2]   # type:str
        t_arr.append(_)    
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = 0
    w_arr = list(set(s_arr))
    for w in w_arr:
        _ = s_arr.count(w)-t_arr.count(w)
        cnt = max(cnt,_)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)

Submission status: Accepted

Solution code:
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    s_arr = []
    for i in range(N):
        _ =     _in[i+1]   # type:str
        s_arr.append(_)
    M = int(_in[N+1])  # type:int
    t_arr = []
    for i in range(M):
        _ =     _in[i+N+2]   # type:str
        t_arr.append(_)    
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    w_arr = s_arr+t_arr
    w_arr = list(set(w_arr))
    cnt = 0
    for w in w_arr:
        _ = s_arr.count(w)-t_arr.count(w)
        cnt = max(cnt,_)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)

Submission status: Accepted

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

m = int(input())
red_cards = {}
for i in range(m):
    s = input()
    if s in red_cards:
        red_cards[s] += 1
    else:
        red_cards[s] = 1
        
ans = 0
for k in blue_cards:
    if k in red_cards:
        score = blue_cards[k] - red_cards[k]
    else:
        score = blue_cards[k]
    ans = max(ans, score)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter as cnt
b = cnt([input() for _ in range(int(input()))])
r = cnt([input() for _ in range(int(input()))])
a = 0
for l in b.keys(): a = max(a,b[l]-r[l])
print(a)

Submission status: Accepted

Solution code:
N=int(input())
S=list()
for i in range(N):
    S.append(input())
M=int(input())
T=list()
for i in range(M):
    T.append(input())
A=set(S)
ans=0
for i in A:
    s=0
    s=S.count(i)-T.count(i)
    if s>ans:
        ans=s
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = list()
for i in range(N):
  S.append(input())
M = int(input())
T = list()
for i in range(M):
  T.append(input())
count = 0
maxcount = 0
for i in range(N):
  count = 0
  for j in range(N):
    if S[i] == S[j]:
      count += 1
  for j in range(M):
    if S[i] == T[j]:
      count -= 1
  if count > maxcount:
    maxcount = count
print(maxcount)

Submission status: Accepted

Solution code:
import sys
from collections import deque, Counter, defaultdict
from itertools import accumulate  # 累積和
from bisect import bisect_left, bisect
from heapq import heappop, heappush  # 優先度付きキュー
from fractions import gcd
from math import ceil, floor, sqrt
from copy import deepcopy

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

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

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

Submission status: Accepted

Solution code:
def resolve():
    # 整数 1 つ
    n = int(input())
    # 整数複数個
    # a, b, c = list(map(int, input().split()))
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    s = [list(input().split()) for i in range(n)]
    m = int(input())
    t = [list(input().split()) for i in range(m)]

    paymax = 0
    for w in s:
        pay = s.count(w) - t.count(w)
        if paymax < pay:
            paymax = pay

    print(paymax)
resolve()

Submission status: Accepted

Solution code:
N=int(input())
S=dict()
for i in range(N):
	tmp=input()
	if tmp in S:
		S[tmp]+=1
	else:
		S[tmp]=1
M=int(input())
T=dict()
for i in range(M):
	tmp = input()
	if tmp in T:
		T[tmp]+=1
	else:
		T[tmp]=1
ans=0
for SS in S:
	tmp = 0
	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:
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]

sd = {}
for i in s:
    if i not in sd:
        sd[i] = 0
    sd[i] += 1
td = {}
for i in t:
    if i not in td:
        td[i] = 0
    td[i] += 1
d = {}
for i in sd.keys():
    try:
        d[i] = (sd[i] - td[i])
    except:
        d[i] = sd[i]

if max([d[i] for i in d.keys()]) <= 0:
    print(0)
else:
    print(max([d[i] for i in d.keys()]))

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

Submission status: Accepted

Solution code:
from collections import defaultdict
def resolve():
    n = int(input())
    dict = defaultdict(lambda: [0, 0])
    for _ in range(n):
        dict[input()][0] += 1

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

    ans = 0
    for blue, red in dict.values():
        ans = max(ans, blue - red)

    print(ans)

resolve()

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
word={}
for i in range(n):
  if s[i] not in word.keys():
    word[s[i]]=0
  word[s[i]]+=1
for i in range(m):
  if t[i] not in word.keys():
    word[t[i]]=0
  word[t[i]]-=1
for i in word.keys():
  if ans < word[i]:
    ans=word[i]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
di = {'NULL': 0}
for _ in range(n):
    s = input()
    if s in di:
        di[s] += 1
    else:
        di[s] = 1
m = int(input())
for _ in range(m):
    t = input()
    if t in di:
        di[t] -= 1
    else:
        di[t] = -1
print(max(list(di.values())))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n=I()
ss=[input().rstrip() for i in range(n)]
m=I()
ts=[input().rstrip() for i in range(m)]
u=Counter(ss)
v=Counter(ts)
#print(u)
#print(v)
ans=[]
for j in u.keys():
    ans.append(u[j]-v[j])
print(max(max(ans),0))

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
MOD = 1000000007

N = int(input())

num = [0]*(200)

S = {}

cnt = 0
for i in range(N):
    x = input()[:-1]
    if x not in S:
        S[x] = cnt
        num[cnt] = 1
        cnt+=1
    else:
        num[S[x]]+=1

M = int(input())
for i in range(M):
    x = input()[:-1]
    if x not in S:
        pass
    else:
        num[S[x]] -=1


res = 0
for i in num:
    if i > 0:
        res+= i

print(max(num))

Submission status: Accepted

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

MAX = 0
for i in range(N):
    MAX = max(Blue.count(Blue[i])- Red.count(Blue[i]), MAX)

print(MAX)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
blue = []
for _ in range(N):
    blue.append(input())
blue = Counter(blue)

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

diff = blue - red
if len(diff)==0:
    print(0)
else:
    print(max(diff.values()))

Submission status: Accepted

Solution code:
n=int(input())
blue=[input() for i in range(n)]
m = int(input())
red = [input() for i in range(m)]
money = [0 for i in range(n)]

for i in range(n):
  for j in range(n):
    if blue[i] == blue[j]:
      money[i] += 1
  for k in range(m):
    if blue[i] == red[k]:
      money[i] -= 1

if max(money) >= 0:
  print(max(money))
else:
  print(0)

Submission status: Accepted

Solution code:
n=int(input())
res=0
blue=[]
for i in range(n):
  blue.append(input())
m=int(input())
red=[]
for j in range(m):
  red.append(input())

res=0
for i in range(0,n):
  bl=blue.count(blue[i])
  re=red.count(blue[i])
  if bl-re>res:
    res=bl-re
print(res)

Submission status: Accepted

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

judge = 0
for i in range(N-1):
  count = 1
  for j in range(i+1,N):
    if s[i] == s[j]:
      count += 1
  for k in range(M):
    if s[i] == t[k]:
      count -= 1
  if count > judge:
    judge = count
print(judge)

Submission status: Accepted

Solution code:
n = int(input())
sl = list(input() for _ in range(n))
m = int(input())
tl = list(input() for _ in range(m))

ans = 0

for s in sl:
    cnt = sl.count(s) - tl.count(s)
    ans = max(ans, cnt)

print(ans)

Submission status: Accepted

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

max_g = 0
for i in s:
    c_s = s.count(i)
    c_t = t.count(i)

    max_g = max(max_g,c_s-c_t)

print(max_g)

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for i in range(n)]
m = int(input())
t = [input() for i in range(m)]
max = 0
for ss in s:
  if s.count(ss) -t.count(ss) > max:
    max = s.count(ss) - t.count(ss)
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)]
#blue n (str s)
# red m (str t)
sc = Counter(s)
tc = Counter(t)
u = list(set(s + t))
maxcnt = 0
for i in range(len(u)):
	cnt = 0
	cnt += sc[u[i]]
	cnt -= tc[u[i]]
	if cnt >= maxcnt:
		maxcnt = cnt
print(maxcnt)

Submission status: Accepted

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop

import collections

n = int(input())
S = []
U = []
for i in range(n):
    s = input()
    S.append(s)
    U.append(s)
m = int(input())
T = []
for i in range(m):
    t = input()
    T.append(t)
    U.append(t)
U = list(set(U))
cnt = [0] *len(U)
for i in range(n):
    for j in range(len(U)):
        if S[i] == U[j]:
            cnt[j] += 1
for i in range(m):
    for j in range(len(U)):
        if T[i] == U[j]:
            cnt[j]-=1
a = max(cnt)
print(max(a,0))

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
s_counter = Counter()
for _ in range(N):
    s = input()
    s_counter[s] += 1
M = int(input())
t_counter = Counter()
for _ in range(M):
    t = input()
    t_counter[t] += 1
max_profit = 0
for key in s_counter.keys():
    max_profit = max([max_profit, s_counter[key] - t_counter[key]])
print(max_profit)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
s = []
for i in range(N):
    s.append(input())
M=int(input())
t=[]
for k in range(M):
    t.append(input())
count=0
for r in s:
    scount=s.count(r)
    tcount=t.count(r)
    ans=scount-tcount
    if ans>=count:
        count=ans
print(count)

Submission status: Accepted

Solution code:
n = int(input())
B = [input() for _ in range(n)]
m = int(input())
R = [input() for _ in range(m)]
L = list(set(B) | set(R))
dict = {key:0 for key in L}
for b in B:
    dict[b] += 1
for r in R:
    dict[r] -=1
dict.update({"AAA":0})
print(max(dict.values()))

Submission status: Accepted

Solution code:
N = int(input())
Blue = [str(input()) for i in range(N)]
M = int(input())
Red = [str(input()) for i in range(M)]
Blue_Set = list(set(Blue))
X = 0
for i in range(len(Blue_Set)):
  if (Blue.count(Blue_Set[i]) - Red.count(Blue_Set[i])) > X:
    X = Blue.count(Blue_Set[i])-Red.count(Blue_Set[i])
print(X)

Submission status: Accepted

Solution code:
# ABC091B

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

blue = {}
for c in s:
    if c in blue.keys():
        blue[c] += 1
    else:
        blue.setdefault(c, 1)
red = {}
for c in t:
    if c in red.keys():
        red[c] += 1
    else:
        red.setdefault(c, 1)

Max = 0
for blue_key, blue_value in blue.items():
    get = blue_value
    if blue_key in red.keys():
        for red_key, red_value in red.items():
            if blue_key == red_key:
                get -= red_value
                break
    Max = max(Max, get)
print(Max)

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))
List=[s.count(l[i])-t.count(l[i]) for i in range(len(l))]
print(max(0,max(List)))

Submission status: Accepted

Solution code:
n = int(input())
Blue = [input() for _ in range(n)]
m = int(input())
Red = [input() for _ in range(m)]
l = list(set(Blue))
print(max(0,max(Blue.count(l[i])-Red.count(l[i]) for i in range(len(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)]
sc = []
sl = []
tc = []
tl = []
anslist = []
i = 0 
j = 0
k = 0
l = 0

s.sort()
t.sort()


while i < N:
  sc.append(s.count(s[i]))
  sl.append(s[i])
  i += s.count(s[i])
  
while j < M:
  tc.append(t.count(t[j]))
  tl.append(t[j])
  j += t.count(t[j])

for k in range(len(sl)):
  for l in range(len(tl)):
    if tl[l] == sl[k]:
      sc[k] -= tc[l]
  
print(max(max(sc), 0))

Submission status: Accepted

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

Submission status: Accepted

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

d = {}
for val,cnt in Counter(s).items():
    d[val] = cnt

for val,cnt in Counter(t).items():
    if val in d:
        d[val] -= cnt
print(max(max(d.values()),0))

Submission status: Accepted

Solution code:
from collections import defaultdict

N = int(input())
dic = defaultdict(int)
for i in range(N):
  temp = str(input())
  dic[temp] += 1

M = int(input())
for i in range(M):
  temp = str(input())
  dic[temp] -= 1

ans = max(dic.values())
if ans < 0:
  print("0")
else:
  print(ans)

Submission status: Accepted

Solution code:
a = []
n = int(input())
for i in range(n):
    a += [input()]

b = []
m = int(input())
for j in range(m):
    b += [input()]

ans = 0
for k in set(a):
    if k in b:
        ans = max(ans, a.count(k) - b.count(k))
    else:
        ans = max(ans, a.count(k))
print(ans)