Problem:


Score : 200 points

Problem Statement

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

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

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

At most how much can he earn on balance?

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

Constraints

N and M are integers.

1 \leq N, M \leq 100

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

Input

Input is given from Standard Input in the following format:

N
s_1
s_2
:
s_N
M
t_1
t_2
:
t_M

Output

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

Sample Input 1

3
apple
orange
apple
1
grape

Sample Output 1

2

He can earn 2 yen by announcing apple.

Sample Input 2

3
apple
orange
apple
5
apple
apple
apple
apple
apple

Sample Output 2

1

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

Sample Input 3

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

Sample Output 3

0

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

Sample Input 4

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

Sample Output 4

1



Sample input:
3
apple
orange
apple
1
grape


Sample output:
2

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for n in range(N)]
M = int(input())
T = [input() for m in range(M)]
ans = 0

for s in S:
  ans = max(ans,S.count(s)-T.count(s))
  
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict

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

Submission status: Accepted

Solution code:
import collections
i = int(input())
blue = [input() for b in range(i)]
l = int(input())
red = [input() for r in range(l)]
bluecount = collections.Counter(blue)
redcount = collections.Counter(red)

c = 0
for i, j in bluecount.items():
    c = max(j-redcount[i], c)
print(c)

Submission status: Accepted

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

lst = [0]*(N+1)

for i in range(N):
    ref = S[i]
    lst[i] = S.count(ref) - T.count(ref)

ans = max(lst)
print(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)
c = 0
for i, j in S.items():
    c = max(j-T[i], c)
print(c)

Submission status: Accepted

Solution code:
s = []
t = []
ans = 0

n = int(input())
for i in range(n):
    si = input()
    s.append(si)

m = int(input())
for i in range(m):
    ti = input()
    t.append(ti)

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


m = int(input())
r = [input() for i in range(m)]

from collections import Counter
bc = Counter(b)
rc = Counter(r)

bs = list(set(b))

res = 0
for i in bs:
    res = max(res,bc[i]-rc[i])
    
print(res)

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

cs = collections.Counter(s)
ct = collections.Counter(t)

ans = 0

for i, j in cs.items():
    ans = max(j-ct[i], ans)

print(ans)

Submission status: Accepted

Solution code:
import sys
import collections

input = sys.stdin.readline

def main():
    ans = 0
    n = int(input())
    s = [input().rstrip('\n') for _ in range(n)]
    m = int(input())
    t = [input().rstrip('\n') for _ in range(m)]
    cs = collections.Counter(s)
    ct = collections.Counter(t)
    for k,v in cs.items():
        ans = max(v-ct[k], ans)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
dic = {}
N = int(input())
for _ in range(N):
    s = input()
    dic.setdefault(s, 0)
    dic[s] += 1
M = int(input())
for _ in range(M):
    s = input()
    try:
        dic[s] -= 1
    except:
        continue
m = 0
for k in dic:
    m = max(m, dic[k])
print(m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
Pl = []
Mi = []

N = int(input())
for i in range(N):
    Pl.append(input().rstrip('\n'))
M = int(input())
for i in range(M):
    Mi.append(input().rstrip('\n'))

ans = 0
for s in Pl:
    ans = max(ans, Pl.count(s)-Mi.count(s))
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
E={"*":0}
for _ in range(N):
    S=input()
    if S in E:
        E[S]+=1
    else:
        E[S]=1

M=int(input())
for _ in range(M):
    S=input()
    if S in E:
        E[S]-=1
    else:
        E[S]=-1

print(max(E.values()))

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    dict = defaultdict(int)
    for _ in range(N):
        string = input()
        dict[string] += 1
    M = int(input())
    for _ in range(M):
        string = input()
        dict[string] -= 1

    ans = 0
    for key in dict: ans = max(ans, dict[key])
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
s = [input() for i in range(n)]
m = int(input())
t = [input() for i in range(m)]

ans = 0
for i in s:
    sc = s.count(i)
    tc = t.count(i)
    cnt = sc - tc
    if cnt > ans:
        ans = cnt

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
s = ""
S = []
for i in range(N):
    s = input()
    S.append(s)
M = int(input())
t = ""
T = []
for i in range(M):
    t = input()
    T.append(t)
#青いカードSi * N 赤いカードTi * M
S = sorted(S)
T = sorted(T)
W = []
c = -1
num = []
for i in range(N):
    if not(S[i] in W):
        W.append(S[i])
        num.append(0)
        c += 1
        for j in range(i,N):
            if W[c] == S[j]:
                num[c] += 1
        for j in range(M):
            if W[c] == T[j]:
                num[c] -= 1
num.append(0)
print(max(num))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
a, b = [], []
N = int(input())
for i in range(N): a.append(input())
M = int(input())
for i in range(M): b.append(input())

c = Counter(a)
max0 = 0
for i in c.most_common(): max0 = max(max0, i[1]-b.count(i[0]))
print(max0)

Submission status: Accepted

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

m = int(input())

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

if max(n_s.values()) < 0 :
  print(0)
else:
  print(max(n_s.values()))

Submission status: Accepted

Solution code:
n = int(input())
S = list(input() for _ in range(n))
m = int(input())
T = list(input() for _ in range(m))
ans = 0
for i in list(set(S)):
    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)]

x = list(set(s))
res = 0
for str_ in x:
    res = max(res, s.count(str_) - t.count(str_))
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)]
card=list(set(s))
print(max(0,max(s.count(card[i])-t.count(card[i]) for i in range(len(card)))))

Submission status: Accepted

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

import sys
from collections import defaultdict
# import pprint
# 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(blue_count, blue_list, red_count, red_list):
    result = 0
    allDict = defaultdict(int)
    for j in range(0, blue_count, +1):
        allDict[blue_list[j]] += 1
    for j in range(0, red_count, +1):
        allDict[red_list[j]] -= 1
    # algorithm
    # print("{}".format(allDict))
    dictList = list(allDict.values()) + [0]
    dictList.sort(reverse=True)
    # pprint.pprint("{}".format(dictList))
    result = dictList[0]
    return result


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

Submission status: Accepted

Solution code:
N = int(input())

p_names = []
p_count = []
for n in range(N):
    p_count.append(0)

for n in range(N):
    tmp = input()
    if tmp in p_names:
        index = p_names.index(tmp)
        p_count[index] += 1
    else:
        p_names.append(tmp)
        index = p_names.index(tmp)
        p_count[index] += 1
        
M = int(input())
for m in range(M):
    tmp = input()
    if tmp in p_names:
        index = p_names.index(tmp)
        p_count[index] -= 1
    else:
        continue

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

Submission status: Accepted

Solution code:
import math
def main():
  n=int(input())
  s = [input() for i in range(n)]
  m=int(input())
  t = [input() for i in range(m)]
  ans=0
  while len(s)>0:
    num=s.count(s[0])-t.count(s[0])
    if ans<num:
      ans=num
    s=[x for x in s if x != s[0]]
  print(ans)
  
main()

Submission status: Accepted

Solution code:
import sys
N = int(input())
array_plus = []
for I in range(N):
    array_plus.append(input())
M = int(input())
array_minus = []
for J in range(M):
    array_minus.append(input())

if not (1 <= N <= 100 and 1 <= M <= 100):
    sys.exit()
for K in range(len(array_plus)):
    if len(array_plus[K]) > 10:
        sys.exit()
    if not array_plus[K].islower():
        sys.exit()
for L in range(len(array_minus)):
    if len(array_minus[L]) > 10:
        sys.exit()
    if not array_minus[L].islower():
        sys.exit()

all = []
all = array_plus+array_minus
all_unique = set(all)
all_unique = list(all_unique)
result = 0
for I in range(len(all_unique)):
    tmp = array_plus.count(all_unique[I]) - array_minus.count(all_unique[I])
    if tmp > result:
        result = tmp
print(result)

Submission status: Accepted

Solution code:
n=int(input())
dic={}

for i in range(n):
    s=input()
    if s not in dic:
        dic[s]=1
    else:
        dic[s]+=1
#print(dic)

m=int(input())
for i in range(m):
    t=input()
    if t in dic:
        dic[t]-=1
    
ans_list=sorted(dic.items(),key=lambda x:x[1],reverse=True)
#print(ans_list)

if ans_list[0][1]<0:
    print(0)
else:
    print(ans_list[0][1])

Submission status: Accepted

Solution code:
from collections import defaultdict

n = int(input())
S = [input() for i in range(n)]
m = int(input())
T = [input() for i in range(m)]

dictS = defaultdict(int)
dictT = defaultdict(int)

for s in S:
    dictS[s] += 1
for t in T:
    dictT[t] += 1

res = 0
for key in dictS:
    res = max(res, dictS[key] - dictT[key])
print(res)

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

L = set(S + T)
ans = 0
for l in L:
    blue = S.count(l)
    red = T.count(l)
    ans = max(ans, blue-red)

print(ans)

Submission status: Accepted

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

s.sort()
t.sort()
for i in range(N-1):
    if s[i]!=s[i+1]:
        sf=s.count(s[i+1])
        tf=t.count(s[i+1])
        if sf>tf:
            temp=sf-tf
            if temp>ans:
                ans=temp
sf=s.count(s[0])
tf=t.count(s[0])
if sf>tf:
    temp=sf-tf
    if ans<temp:
        ans=temp
print(ans)

Submission status: Accepted

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

m = int(input())
for _ in range(m):
  t = input()
  if t in d: d[t] -= 1
    
maxNum = max(d.values())
if maxNum > 0: print(maxNum)
else: print(0)

Submission status: Accepted

Solution code:
def actual(N, S, M, T):
    points = [S.count(word) - T.count(word) for word in set(S)]

    return max(0, max(points))

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

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

print(actual(N, S, M, T))

Submission status: Accepted

Solution code:
blue={}
red={}
n=int(input())
for i in range(n):
    s=input()
    blue[s]=blue.get(s,0)+1
m=int(input())
for i in range(m):
    t=input()
    red[t]=red.get(t,0)+1

mx=0
for k,v in blue.items():
    mx=max(mx,blue[k]-red.get(k,0))
print(mx)

Submission status: Accepted

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

ma = 0

blueset = set(blues)

for S in blueset:
  ma = max(ma,blues.count(S)-reds.count(S))
print(ma)

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    s = [input() for _ in range(N)]
    M = int(input())
    t = [input() for _ in range(M)]
    sdict = {k: 0 for k in set(s)}
    tdict = {k: 0 for k in set(t)}
    for w in s:
        sdict[w] += 1
    for w in t:
        tdict[w] += 1
    ks = set(s) | set(t)
    ans = 0
    for key in ks:
        ans = max(ans, sdict.get(key, 0) - tdict.get(key, 0))

    print(ans)

    return
resolve()

Submission status: Accepted

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

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

M = int(input())

for _ in range(M):
    t = input()
    if t in words:
        words[t] -= 1

val = sorted(words.values())

if val:
    if val[-1] < 0:
        print(0)
    else:
        print(val[-1])
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)]
dict={}

for i in s:
  if i not in dict.keys():
    dict[i]=1
  else:
    dict[i]+=1
for j in t:
  if j in s:
    dict[j]-=1
m=max(dict.values())
print(m if m>0 else "0")

Submission status: Accepted

Solution code:
import collections

n = int(input())
blue = []
for i in range(n):
    blue.append(input())

red = []   
m = int(input())
for i in range(m):
    red.append(input())
    
b1 = collections.Counter(blue)
r1 = collections.Counter(red)

ans = 0

for key, value in b1.items():
    if key in r1:
        tmp = b1[key] - r1[key]
        ans = max(ans, tmp)
    else:
        ans = max(ans, b1[key])
        
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
B = Counter([input() for _ in range(N)])
M = int(input())
R = Counter([input() for _ in range(M)])
res = 0
for k, v in B.items():
    res = max(res, v - R[k])
print(res)

Submission status: Accepted

Solution code:
A = int(input())
X = [input() for _ in range(A)]
B = int(input())
Y = [input() for _ in range(B)]
t = 0
for x in X:
  if X.count(x)-Y.count(x)>t:
    t = X.count(x)-Y.count(x)
  else:
    pass
print(t)

Submission status: Accepted

Solution code:
n=int(input())
nlst=[input() for i in range(n)]
m=int(input())
mlst=[input() for i in range(m)]
ans=0
for i in nlst:
    plus=nlst.count(i)
    minus=mlst.count(i)
    ans=max(ans,plus-minus)
    
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)]
maxA = 0
for s in set(S):
    maxA = max(maxA, S.count(s) - T.count(s))
print(maxA)

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 S.count(S[i]) > T.count(S[i]):
        ans = max(ans, S.count(S[i]) - T.count(S[i]))
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())#blue card +
s = list(input() for i in range(N))
M = int(input())#red card -
t = list(input() for i in range(M))
count_p = Counter(s)
count_m = Counter(t)
counter = count_p - count_m
if (len(counter.values()) == 0):
    print (0)
else:
    print(max(counter.values()))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for n in range(N)]
M = int(input())
T = [input() for m in range(M)]
A = [0]

for s in S:
  A.append(S.count(s)-T.count(s))

print(max(A))

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

x=defaultdict(int)
for i in s:
  x[i]+=1
  
for i in t:
  x[i]-=1
  
ans=0
for y in x.keys():
  ans=max(ans, x[y])
  
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
cnt=0
for i in range(n):
  for j in range(n):
    if s[i]==s[j]:
      cnt+=1
  for k in range(m):
    if s[i]==t[k]:
      cnt-=1
  ans=max(ans,cnt)
  cnt=0
print(ans)

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())

A = {}
for _ in range(N):
    a = input()
    A[a] = A.get(a, 0) + 1

M = int(input())
B = {}
for _ in range(M):
    b = input()
    B[b] = B.get(b, 0) + 1

ans = 0
for k, v in A.items():
    ans = max(ans, v - B.get(k, 0))

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(len(s)):
    if s.count(s[i])-t.count(s[i])>ans:
        ans=s.count(s[i])-t.count(s[i])
print(ans)

Submission status: Accepted

Solution code:
# Problem: https://atcoder.jp/contests/abc091/tasks/abc091_b
# Python 2nd 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(blueCard, redCard):
    result = 0
    cardDict = defaultdict(int)
    for j in range(0, len(blueCard), +1):
        cardDict[blueCard[j]] += 1
    for j in range(0, len(redCard), +1):
        cardDict[redCard[j]] -= 1
    # print("{}".format(list(cardDict.keys())))
    cardList = list(cardDict.keys())
    for j in range(0, len(cardList), +1):
        if result < cardDict[cardList[j]]:
            result = cardDict[cardList[j]]

    # algorithm
    return result


if __name__ == "__main__":
    N = II()
    blueCard = list()
    for _ in range(0, N, +1):
        strings = sys.stdin.readline().strip('\n')
        blueCard.append(strings)
    M = II()
    redCard = list()
    for _ in range(0, M, +1):
        strings = sys.stdin.readline().strip('\n')
        redCard.append(strings)
#    print("Blue:{}".format(blueCard))
#    print("Red {}".format(redCard))
    print("{}".format(solver(blueCard, redCard)))

Submission status: Accepted

Solution code:
from collections import defaultdict
def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

n = readInt()
s = defaultdict(int)
for i in range(n):
  s[input()]+=1
m = readInt()
t = defaultdict(int)
for i in range(m):
  t[input()]+=1

ans = 0
for i in s:
  ans = max(ans,s[i]-t[i])
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

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

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

Submission status: Accepted

Solution code:
n=[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:
def dict_update(val):
    s = input()
    if s not in v:
        v[s] = val
    else:
        v[s] += val


v = {}
n = int(input())
for i in range(n):
    dict_update(1)
m = int(input())
for j in range(m):
    dict_update(-1)
print(max(max(v.values()), 0))

Submission status: Accepted

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

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

Max = 0
for item in Blue.items():
    s = item[0]
    v = item[1]
    if s in Red:
        v -= Red[s]
    Max = max(Max, v)
print(Max)

Submission status: Accepted

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

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

M = int(input())

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

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

Submission status: Accepted

Solution code:
n = int(input())
dic1 = {}
for i in range(n):
  temp = input()
  dic1.setdefault(temp, 0)
  dic1[temp] += 1
m = int(input())
for i in range(m):
  temp = input()
  dic1.setdefault(temp, 0)
  dic1[temp] -= 1
print(max(0, max(list(dic1.values()))))

Submission status: Accepted

Solution code:
N=int(input())
s=[input() for _ in range(N)]
M=int(input())
t=[input() for _ in range(M)]
ans=-10**9
for i in range(N):
  a=0
  for j in range(N):
    if s[i]==s[j]:
      a+=1
  for k in range(M):
    if s[i]==t[k]:
      a-=1
  ans=max(ans,a)
if ans<0:
  print(0)
else:
  print(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)]
x = collections.Counter(s)
for i in t:
    x[i] -= 1
print(max(max(x.values()),0))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[7]:


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


# In[8]:


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


# In[ ]:

Submission status: Accepted

Solution code:
# Begin Header {{{
from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement
# }}} End Header
# _________コーディングはここから！！___________
# ... 最小側の制約も確認した？
# ... オーバーフローしない？
n = int(input())
blue = [input() for i in range(n)]
k = int(input())
red = [input() for i in range(k)]
T={}
for x in blue:
    if x not in T: T[x] = 1
    else: T[x]+=1
for x in red:
    if x not in T: T[x] = -1
    else: T[x]-=1
print(max(max(T.values()), 0))

Submission status: Accepted

Solution code:
from collections import Counter

# input
N = int(input())
S = Counter([input() for i in range(N)])
M = int(input())
T = Counter([input() for j in range(M)])

# check
max_cnt = 0
for s in S.keys():
    cnt = S[s]
    if s in T.keys():
        cnt -= T[s]

    if max_cnt < cnt:
        max_cnt = cnt

print(max_cnt)

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 S:
    p = S.count(i)
    m = T.count(i)
    ans = max(ans, p - m)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
s = [input() for s in range(N)]
M = int(input())
t = [input() for t in range(M)]
ans = 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 = int(input())
s = [input() for _ in range(N)]
M = int(input())
t = [input() for _ in range(M)]
ans = 0
for i in s:
        ans = max(s.count(i) - t.count(i),ans)
print(ans)

Submission status: Accepted

Solution code:
def INT():
    return int(input())

def MI():
    return map(int, input().split())

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

from collections import Counter

N = INT()
s = [input() for _ in range(N)]
M = INT()
t = [input() for _ in range(M)]

s = Counter(s)
t = Counter(t)
ans = 0

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

Submission status: Accepted

Solution code:
n = int(input())
s = []

for a in range(n):
    s.append(input())

t = []
m = int(input())

for a in range(m):
    t.append(input())

kind = list(set(s))
kind_length = len(kind)

counter = dict()
for a in range(kind_length):
    counter[kind[a]] = 0

for a in range(n):
    counter[s[a]] += 1

for a in range(m):
    if t[a] not in counter:
        continue
    counter[t[a]] -= 1

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

Submission status: Accepted

Solution code:
N=int(input())
b=[]
for _ in range(N):
  b.append(input())
M=int(input())
r=[]
for _ in range(M):
  r.append(input())

from collections import Counter
red=Counter(r)
blue=Counter(b)
ans=0
for k, v in blue.items():
  ans=max(ans, v-red[k])
print(ans)

Submission status: Accepted

Solution code:
d = {"DUMMY": 0}
n = int(input())
for i in range(n):
  s = input()
  d[s] = d.get(s, 0) + 1

n = int(input())
for i in range(n):
  s = input()
  d[s] = d.get(s, 0) - 1

print(max(d.values()))

Submission status: Accepted

Solution code:
n = int(input())
s = [str(input()) for i in range(n)]
m = int(input())
t = [str(input()) for i in range(m)]
used = []
for i in range(n):
    if s[i] not in used:
        used.append(str(s[i]))
for j in range(m):
    if t[j] not in used:
        used.append(str(t[j]))

ans = [0]*len(used)
for i in range(len(used)):
    for j in range(n):
        if s[j] == used[i]:
            ans[used.index(used[i])] += 1

for i in range(len(used)):
    for j in range(m):
        if t[j] == used[i]:
            ans[used.index(used[i])] -= 1
if max(ans) >= 0:
    print(max(ans))
else:
    print(0)

Submission status: Accepted

Solution code:
import heapq

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

l = list(set(s))
total = 0
for i in l:
    total = max(total, s.count(i) - t.count(i))

print(total)

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)]
maxi = 0
for i in s:
    cnt = s.count(i) - t.count(i)
    maxi = max(maxi,cnt)
print(maxi)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)
import collections

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

    s = collections.Counter(s)
    t = collections.Counter(t)

    ans = 0
    for key, value in s.items():
        if key in t:
            ans = max(ans, value-t[key])
        else:
            ans = max(ans, value)

    print(ans)
    return


if __name__ == "__main__":
    main()
    sys.exit(0)

Submission status: Accepted

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

for si in S_set:
    counter = 0
    for t in T:
        if t == si:
            counter += -1
    for s in S:
        if s == si:
            counter += 1
    counters.append(counter)
print(max(max(counters),0))

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
from collections import Counter

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
S = [sr() for _ in range(N)]
count_S = Counter(S)
M = ir()
T = [sr() for _ in range(M)]
count_T = Counter(T)
answer = 0
for k, v in count_S.items():
    temp = v - count_T[k]
    if temp > answer:
        answer = temp

print(answer)

Submission status: Accepted

Solution code:
def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    N = ii()
    s = [input() for _ in range(N)]
    M = ii()
    t = [input() for _ in range(M)]
    dic = {}
    for v in s:
        if not v in dic:
            dic[v] = 0
        dic[v] += 1
    for v in t:
        if not v in dic:
            dic[v] = 0
        dic[v] -= 1

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import collections

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

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

S = collections.Counter(s)
T = collections.Counter(t)

S.most_common()
T.most_common()

ans = S - T

try:
    print(ans.most_common()[0][1])
except:
    print('0')