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, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n = i_input()
    ans_dict = {"aaaaaaaaaaa": 0}
    for _ in range(n):
        tmp_input = s_input()
        if tmp_input in ans_dict:
            ans_dict[tmp_input] += 1
        else:
            ans_dict[tmp_input] = 1

    m = i_input()
    for _ in range(m):
        tmp_input = s_input()
        if tmp_input in ans_dict:
            ans_dict[tmp_input] -= 1

    print(max(ans_dict.values()))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = dict()
for _ in range(n):
  temp = input()
  try:
    s[temp] += 1
  except:
    s[temp] = 1

m = int(input())

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


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

if s[0][1] < 0:
  print(0)
else:
  print(s[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)]
ans = 0
for i in set(s):
        ans = max(s.count(i) - t.count(i),ans)
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)]
cs = Counter(s)
ct = Counter(t)

ans = 0
for k, v in cs.items():
    tmp = v
    if k in ct.keys():
        tmp -= ct[k]

    ans = max(ans, tmp)

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
plus=[input() for i in range(N)]
M=int(input())
minus=[input() for i in range(M)]
S=list(set(plus+minus))
ans=0
for i in S:
    point=0
    point=plus.count(i)-minus.count(i)
    ans=max(ans,point)
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
plus=[input() for i in range(N)]
M=int(input())
minus=[input() for i in range(M)]
S=list(set(plus+minus))
ans=[]
for i in S:
    point=0
    point=plus.count(i)-minus.count(i)
    ans.append(point)
money=max(ans)
if money>0:
    print(money)
else:
    print(0)

Submission status: Accepted

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

arr=[]
cou=[0]*(n+m)
for i in s:
  if not (i in arr):
    arr.append(i)
  cou[arr.index(i)]+=1
for i in t:
  if not (i in arr):
    arr.append(i)
  cou[arr.index(i)]-=1
print(max(cou))

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for i in range(n)]
m = int(input())
t = [input() for i in range(m)]
s.sort()
t.sort()
ans = 0
count = 1
count2 = 0
for i in range(len(s)):
    if i != len(s)-1:
        if s[i] == s[i+1]:
            count+=1
            continue
    for j in range(len(t)):
        if s[i] > t[j]:
            continue
        elif s[i] < t[j]:
            break
        else:
            count2+=1
    ans = max(count-count2,ans)
    count2 = 0
    count = 1
print(ans)

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))
a = s + t
a = list(set(a))
p = 0

for i in range(len(a)):
    plus = s.count(a[i])
    minus = t.count(a[i])
    if plus - minus > p:
        p = plus - minus

print(p)

Submission status: Accepted

Solution code:
n = int(input())
from collections import defaultdict
s = defaultdict(int)
for i in range(n):
    si = input()
    s[si] += 1

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

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

Submission status: Accepted

Solution code:
n = int(input())
from collections import defaultdict
s = defaultdict(int)
for i in range(n):
    si = input()
    s[si] += 1

m = int(input())
for i in range(m):
    ti = input()
    s[ti] -= 1
ans = 0
for k,v in s.items():
    ans = max(ans, v)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
list_s = []
for i in range(N):
  list_s.append(input())
M = int(input())
list_t = []
for k in range(M):
  list_t.append(input())
list_s_new = list(set(list_s))
cnt_list = []
for l in list_s_new:
  cntplus = list_s.count(l)
  cntminus = list_t.count(l)
  cnt_list.append(cntplus-cntminus)
if max(cnt_list) > 0:
  print(max(cnt_list))
else:
  print(0)

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)]
ans=0
for s in set(a):
    score=a.count(s)-b.count(s)
    if ans<score:
        ans=score
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=[input() for _ in range(int(input()))]
m=[input() for _ in range(int(input()))]
l=list(set(n))
print(max(0,max(n.count(l[i])-m.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)]
u=set(s)
ans=0
for i in u:
  temp=s.count(i)-t.count(i)
  ans=max(ans,temp)
print(ans)

Submission status: Accepted

Solution code:
# Problem: https://atcoder.jp/contests/abc091/tasks/abc091_b
# Python 1st Try

import sys
from collections import defaultdict
# import heapq,copy
# from collections import deque
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(plusCardNum, plusCards, minusCardNum, minusCards):
    result = 0
    selectString = defaultdict(int)
    for j in range(plusCardNum):
    #    print("{}".format(plusCards[j]))
        selectString[plusCards[j]] = selectString[plusCards[j]] + 1
    for j in range(minusCardNum):
        selectString[minusCards[j]] = selectString[minusCards[j]] - 1
    keyList = list(selectString.keys())
    for j in range(0, len(keyList)):
        if result < selectString.get(keyList[j]):
            result = selectString.get(keyList[j])
    return result


if __name__ == "__main__":
    N = II()
    NList = []
    for _ in range(0, N, +1):
        NList.append(input())
    M = II()
    MList = []
    for _ in range(0, M, +1):
        MList.append(input())
    print("{}".format(solver(N, NList, M, MList)))

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = Counter([input() for i in range(n)])
m = int(input())
t = Counter([input() for i in range(m)])
ans = 0
for i in s.most_common():
    ans = max(ans, i[1] - t[i[0]])
print(ans)

Submission status: Accepted

Solution code:
n=int(input())

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

m=int(input())
for i in range(m):
    s=input()
    if s in dic:
        dic[s]-=1
    else:
        dic[s]=-1
        
print(max(0,max(dic.values())))

Submission status: Accepted

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

M = int(input())
red = Counter()
for _ in range(M):
    red[input()] += 1


res = 0
for k in blue.keys():
    res = max(blue[k]-red[k], res)

print(res)

Submission status: Accepted

Solution code:
from collections import Counter

# N = 3
# ARR = ["apple", "orange", "apple"]
# BRR = ["grape"]

N = int(input())
ARR = []

for i in range(N):
    ARR.append(input())

M = int(input())
BRR = []

for j in range(M):
    BRR.append(input())


def calculate(a, b):
    result = {}

    for i in a:
        if result.get(i) == None:
            result.__setitem__(i, 1)
        else:
            result.__setitem__(i, result.get(i) + 1)

    for i in b:
        if result.get(i) == None:
            result.__setitem__(i, -1)
        else:
            result.__setitem__(i, result.get(i) - 1)

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


calculate(ARR, BRR)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n = int(input())
    list1=[]
    for i in range(n):
        a =input()
        list1.append(a)

    m = int(input())
    list2=[]
    for i in range(m):
        a =input()
        list2.append(a)

    max= 0
    set1 = set(list1) | set(list2)

    for i in set1:
        count= list1.count(i)-list2.count(i)

        if count > max:
            max=count
    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 ss in s:
    if ss not in d.keys():
        d[ss] = 1
    else:
        d[ss] += 1
for tt in t:
    if tt not in d.keys():
        d[tt] = -1
    else:
        d[tt] -= 1
max = 0
for dd in d.values():
    if max < dd:
        max = dd
print(max)

Submission status: Accepted

Solution code:
n=[input() for i in range(int(input()))]
m=[input() for i in range(int(input()))]
l=list(set(n))
x=0
for i in l:
    y=max(0,n.count(i)-m.count(i))
    if y > x:
        x=y
print(x)

Submission status: Accepted

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

m = int(input())
dt = {}
for _ in range(m):
    s = input()
    if s not in dt.keys():
        dt[s] = 1
    else:
        dt[s] += 1

ans = 0
for k in ds.keys():
    if k in dt.keys():
        tmp = ds[k] - dt[k]
    else:
        tmp = ds[k]

    if ans < tmp:
        ans = tmp

print (ans)

Submission status: Accepted

Solution code:
n=int(input())
plus=[]
for i in range(n):
    plus.append(input())
    
m=int(input())
minus=[]
for j in range(m):
    minus.append(input())
    
x=plus+minus
#max格納
l=[]
x=set(x)
x=list(x)

for i in range(len(x)):
    l.append(plus.count(x[i])-minus.count(x[i]))
    
if max(l)<0:
    print(0)
else:
    print(max(l))

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for i in range(n)]
s_set = set(s)
m = int(input())
t = [input() for i in range(m)]
ans = 0
for i in s_set:
    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)]
d = {}
for i in s:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
for j in t:
    if j in d:
        d[j] -= 1

sd = sorted(d.items(), key=lambda x:x[1], reverse=True)
print(max(0, sd[0][1]))

Submission status: Accepted

Solution code:
import sys
import math
import itertools
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

n = I()
s = [S() for i in range(n)]
m = I()
t = [S() for i in range(m)]
ans,cnt = 0,0
for i in s:
    cnt = 0
    l = [k for k,x in enumerate(s) if x == i]
    cnt += len(l)
    l = [k for k,x in enumerate(t) if x == i]
    cnt -= len(l)
    ans = max(cnt,ans)
print(ans)

Submission status: Accepted

Solution code:
word=[]
blue=[]
red=[]
n=int(input())
for i in range(n):
  s=input()
  blue.append(s)
  if not s in word:
    word.append(s)
    
m=int(input())
for i in range(m):
  s=input()
  red.append(s)
  if not s in word:
    word.append(s)
ans=0
for wd in word:
  x=blue.count(wd)-red.count(wd)
  if ans<x:
    ans=x
print(ans)

Submission status: Accepted

Solution code:
def dic_inc(d,k,v):
    if k in d: d[k] += v
    else: d[k] = v

s = {}
n = int(input())
for _ in range(n): dic_inc(s, input(), 1)
m = int(input())
for _ in range(m): dic_inc(s, input(),-1)
print(max(0, max(s.values())))

Submission status: Accepted

Solution code:
n = int(input())

s = {}
for _ in range(n):
    x = input()
    if x in s: s[x] += 1
    else: s[x] = 1

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

ans = 0
for k,v in s.items():
    ans = max(ans, v - (t[k] if k in t else 0))
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)]

# print(n,m)
# print(S)
# print(T)

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

t = {}
for x in T:
    if x in t:
        t[x] += 1
    else:
        t[x] = 1

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

Submission status: Accepted

Solution code:
blue = [input() for i in range(int(input()))]
red = [input() for i in range(int(input()))]
print(max(0, max([blue.count(i) - red.count(i) for i in set(blue + red)])))

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
S = [input() for _ in range(N)]
SDic = Counter(S)

M = int(input())
T = [input() for _ in range(M)]
TDic = Counter(T)

DiffDic = SDic - TDic
if len(DiffDic)!=0:
    print(max(DiffDic.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)]

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

print(mx)

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

ctr_s = collections.Counter(s)
ctr_t = collections.Counter(t)
ans = 0
for k,v in ctr_s.items():
    if ctr_s[k]:
        ans = max(ans, v - ctr_t[k])
    else:
        ans = max(ans, v)
print(ans)

Submission status: Accepted

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

for _ in range(n):
    s = input()
    S.append(s)
    
m = int(input())
for _ in range(m):
    t = input()
    T.append(t)

from collections import Counter
cnt_s = Counter(S)
cnt_t = Counter(T)
ans = []
'''
for ks,vs in cnt_s.items():
    for kt,vt in cnt_t.items():
        if ks == kt:
            vs = vs - vt
'''

ans = cnt_s - cnt_t

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

Submission status: Accepted

Solution code:
N = int(input())
s = [input() for _ in range(N)]
M = int(input())
t = [input() for _ in range(M)]
result = {}
for i in s:
  if i not in result:
    result[i] = s.count(i) - t.count(i)
result = sorted(result.items(), key=lambda x:-x[1])
print(result[0][1] if result[0][1] > 0 else 0)

Submission status: Accepted

Solution code:
N = int(input())
s = [input() for _ in range(N)]
M = int(input())
t = [input() for _ in range(M)]
s_t_set = set(s + t)
ans = 0
for word in s_t_set:
    counter = 0
    counter += s.count(word)
    counter -= t.count(word)
    ans = max(ans, counter)
print(ans)

Submission status: Accepted

Solution code:
## B - Two Colors Card Game
N = int(input())
S = []
for n in range(N):
    S.append(input())
M = int(input())
T = []
for m in range(M):
    T.append(input())
val = [0]
for s in set(S):
    val.append(S.count(s) - T.count(s))
print(max(val))

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 = []
for i in range(len(S)):
  p = 0
  q = 0
  for j in range(len(S)):
    if S[i]== S[j]:
      p += 1
  for k in range(len(T)):
    if S[i] == T[k]:
      q += -1
  ANS.append(p+q)

print(max(max(ANS),0))

Submission status: Accepted

Solution code:
N = int(input())
Count = {}
for _ in range(N):
    s = input()
    if s not in Count:
        Count[s] = [1, 0]
    else:
        Count[s][0] += 1
M = int(input())
for _ in range(M):
    s = input()
    if s not in Count:
        Count[s] = [0, 1]
    else:
        Count[s][1] += 1
ANS = []
for t in Count.values():
    ANS.append(t[0] - t[1])
print(max(0, 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)]

s = collections.Counter(S)
t = collections.Counter(T)
gain = 0
for text in s.keys():
  if text in t.keys():
    gain_0 = s[text]-t[text]
    if gain < gain_0:
      gain = gain_0
  else:
    gain_0 = s[text]
    if gain < gain_0:
      gain = gain_0
        
print(gain)

Submission status: Accepted

Solution code:
n = int(input())
words = dict()
for _ in range(n):
    s = input()
    words.setdefault(s, 0)
    words[s] += 1

m = int(input())
for _ in range(m):
    s = input()
    words.setdefault(s, 0)
    words[s] -= 1

mc = 0
for k, c in words.items():
    mc = max(mc, c)

if mc < 0:
    print(0)
else:
    print(mc)

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]
d = {}
for i in s:
    if i not in d:
        d[i] = 1
    else:
        d[i] += 1
for j in t:
    if j not in d:
        d[j] = -1
    else:
        d[j] -= 1

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

Submission status: Accepted

Solution code:
def counting_sort(array_b, max_b, array_r, max_r):
    bucket = {}
    for i in array_b:
        if i in bucket:
            bucket[i] += 1
            continue
        bucket[i] = 1

    for j in array_r:
        if j in bucket:
            bucket[j] -= 1
            continue
        else:
            bucket[j] = -1

    return bucket


def main():
    N = int(input())
    blue_list = [input() for _ in range(N)]
    M = int(input())
    red_list = [input() for _ in range(M)]
    ans_bucket = counting_sort(blue_list, N, red_list, M)
    ans_list = []
    for k in blue_list:
        ans_list.append(ans_bucket[k])
    for h in red_list:
        ans_list.append(ans_bucket[h])
    ans_list.sort(reverse = True)
    if ans_list[0] < 0:
        print(0)
    else:
        print(ans_list[0])
    #ans_bucket_sort = sorted(ans_bucket.items(), key = lambda x:x[1], reverse = True)
    #print(ans_bucket_sort[])

main()

Submission status: Accepted

Solution code:
from collections import defaultdict
b = defaultdict(int)
r = defaultdict(int)
ans = defaultdict(int)

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

m = int(input())
for i in range(m):
  s = input()
  r[s] += 1

for e in b.keys(): 
  if e in r.keys():
    ans[e] = b[e] - r[e]
  else:
    ans[e] = b[e]

p = ans.values()
p = list(p)
p.append(0)
print(max(p))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict

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

def make_count_dict(target_list):
    count_dict = defaultdict(int)
    for key in target_list:
        count_dict[key] += 1
    return count_dict

s_dict = make_count_dict(s_list)
t_dict = make_count_dict(t_list)

ans = 0
for s in s_dict.keys():
    temp = s_dict[s] - t_dict[s]
    if temp > ans:
        ans = temp
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)]

counter = collections.Counter()

for i in s:
    counter[i] += 1

for j in t:
    counter[j] -= 1

ans = max(counter.values())

print(ans if ans >=0 else 0)

Submission status: Accepted

Solution code:
import collections
n = int(input())
fir = [str(input()) for _ in range(n)]
m = int(input())
sec = [str(input()) for _ in range(m)]
fc = []
sc = []
fn = []
sn = []
fir.sort()
sec.sort()
k = 1
for i in range(n-1):
    if fir[i] != fir[i+1]:
        fc.append(k)
        fn.append(fir[i])
        k = 1
    else:
        k += 1
fc.append(k)
fn.append(fir[-1])
l = 1
for j in range(m-1):
    if sec[j] != sec[j+1]:
        sc.append(l)
        sn.append(sec[j])
        l = 1
    else:
        l += 1
sc.append(l)
sn.append(sec[-1])
for p in sn:
    if p in fn:
        q = fn.index(p)
        fc[q] -= sc[sn.index(p)]
print(max(max(fc),0))

Submission status: Accepted

Solution code:
ans=0
n=int(input())
lst=[]
for i in range(n):
  lst.append(input())
m=int(input())
x=[]
for j in range(m):
  x.append(input())
for k in set(lst):
  c=lst.count(k)-x.count(k)
  ans=max(ans,c)
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)]
A = []
B = []
for s in S:
    if s not in A:
        B.append(S.count(s)-T.count(s))
        A.append(s)
ans = max(B)
if ans < 0:
  ans = 0
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
nn = []
mm = []
ll = []
ans = 0
for i in range(N):
  k = input()
  nn.append(k)
  ll.append(k)
M = int(input())
l_s = set(ll)
for i in range(M):
  k = input()
  mm.append(k)
for i in l_s:
  count = 0
  for j in nn:
    if i == j:
      count += 1
  for j in mm:
    if i == j:
      count -= 1
  if count > ans:
    ans = count
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
br=[]
for i in range(n):
  br.append(input())
m=int(input())
re=[]
for i in range(m):
  re.append(input())
point=[]
for i in br:
  bri=br.count(i)
  rei=re.count(i)
  point.append(bri-rei)
point.append(0)
print(max(point))

Submission status: Accepted

Solution code:
import bisect

def solve(n,m,s,t):
    res = 0
    for string in s:
        plus = bisect.bisect_right(s,string)
        plus -= bisect.bisect_left(s,string)
        minus = bisect.bisect_right(t,string)
        minus -= bisect.bisect_left(t,string)
        tmp = plus - minus
        res = max(res,tmp)
    return res

if __name__ == '__main__':
    n = int(input())
    s = []
    for i in range(n):
        si = input()
        bisect.insort_left(s,si)
    m = int(input())
    t = []
    for i in range(m):
        ti = input()
        bisect.insort_left(t,ti)
    print(solve(n,m,s,t))

Submission status: Accepted

Solution code:
# Nはプラス、Mはマイナス
n=[input() for _ in range(int(input()))]
m=[input() for _ in range(int(input()))]
# setはindexが使えないためlist化している。
l=list(set(n))
# 右側のmaxをしておかないとintとlistでmaxを使うことによるエラーとなる。
# []は無くても良い。
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())
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
print(max(max(d.values()),0))

Submission status: Accepted

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

ST = S + T
ST_set= set(ST)

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

if max(list) > 0:
    print(max(list))
else:
    print(0)

Submission status: Accepted

Solution code:
N=int(input())
from collections import defaultdict
d = defaultdict(int)
for i in range(N):
  s=input()
  d[s]+=1
M=int(input())
for i in range(M):
  s=input()
  d[s]-=1
a=sorted(list(d.values()))
print(max(a[-1],0))

Submission status: Accepted

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

for i in u:
    cnt = 0
    for j in s:
        if i == j:
            cnt += 1
    for k in t:
        if i == k:
            cnt -= 1
    l.append(cnt)
print(max(0, max(l)))

Submission status: Accepted

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

for i in u:
    cnt = 0
    for j in s:
        if i == j:
            cnt += 1
    for j in t:
        if i == j:
            cnt -= 1
    l.append(cnt)

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

Submission status: Accepted

Solution code:
import collections

N=int(input())
A=[]
for _ in range(N):
	A.append(input())
M=int(input())
B=[]
for _ in range(M):
	B.append(input())
A=sorted(A)
B=sorted(B)
ans=0
X=collections.Counter(A)
Y=collections.Counter(B)
for i,j in X.items():
	tmp=j
	for p,q in Y.items():
		if i==p:
			tmp=j-q
	ans=max(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
# For taking integer inputs.
import math


def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


n = inp()
blue = []
red = []
for _ in range(n):
    blue.append(input())

m = inp()
for _ in range(m):
    red.append(input())
res = 0
for b in blue:
    res1 = blue.count(b)
    res2 = red.count(b)
    res = max(res, res1 - res2)
print(res)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
blue = Counter([input() for _ in range(N)])
M = int(input())
red = Counter([input() for _ in range(M)])
Max = 0
for key in blue:
    if key in red:
        point = blue[key] - red[key]
    else:
        point = blue[key]
    
    if point>Max:
        Max = point
print(Max)

Submission status: Accepted

Solution code:
import sys
from collections import Counter

input = sys.stdin.readline


def main():
    N = int(input())
    s = [""] * N
    for i in range(N):
        s[i] = input().rstrip()
    M = int(input())
    t = [""] * M
    for i in range(M):
        t[i] = input().rstrip()

    c_s = Counter(s)
    c_t = Counter(t)
    t_keys = c_t.keys()
    t_items = dict(c_t.items())
    ans = 0
    for k, v in c_s.items():
        money = v
        if k in t_keys:
            money -= t_items[k]
        if money > ans:
            ans = money

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import collections
import heapq
import numpy as np

rl = sys.stdin.readline

n = int(rl())

blue = [rl() for _ in range(n)]

m = int(rl())
red = [rl() for _ in range(m)]

ans = 0
for i in list(set(blue)):
    b = blue.count(i) - red.count(i)
    if b > ans:
        ans = b
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

bag = Counter()

N  = int(input())

word_s = []
word_t = []

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

M  = int(input())
for i in range(M):
    bag[input()] -= 1

max = sorted(bag.items(), key=lambda item: item[1], reverse=True)[0][1]

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

Submission status: Accepted

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

S = set(s)
ans = []
for i in S:
    cnt = 0
    for j in s:
        if i == j:
            cnt += 1
    for h in t:
        if i == h:
            cnt -= 1
    ans.append(cnt)

value = max(ans)

if value < 0:
    print(0)
else:
    print(value)

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

s_counter = Counter(S)
t_counter = Counter(T)

result = 0

for k, v in s_counter.items():
    result = max(result, v - (t_counter[k] if t_counter[k] else 0))

print(result if result > 0 else 0)

Submission status: Accepted

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

Submission status: Accepted

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

for _ in range(m):
    t.append(input())
    
point=[None]*100

max_point=0

for i in range(len(s)):
    point_s=s.count(s[i])
    point_t=-1*t.count(s[i])
    point_sum=point_s+point_t
    max_point=max(max_point,point_sum)
    
print(max_point)

Submission status: Accepted

Solution code:
from collections import defaultdict


N = int(input())
blue_cards = defaultdict(int)
for _ in range(N):
    blue_cards[input()] += 1
M = int(input())
red_cards = defaultdict(int)
for _ in range(M):
    red_cards[input()] += 1
ans = 0
for string, score in blue_cards.items():
    ans = max(ans, score - red_cards.get(string, 0))
print(ans)