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:
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]

n = int(input())
s = [input() for _ in range(n)]

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

ss = list(set(s))
ans = [0] * len(ss)

for i in range(len(ss)):
    for j in range(n):
        if ss[i] == s[j]:
            ans[i] += 1
    for j in range(m):
        if ss[i] == t[j]:
            ans[i] -= 1

print(max(max(ans), 0))

Submission status: Accepted

Solution code:
import collections
N = int(input())
lsN = []
for i in range(N):
    lsN.append(input())
M = int(input())
lsM = []
for i in range(M):
    lsM.append(input())

counterN = collections.Counter(lsN)
counterM = collections.Counter(lsM)
ans = 0
for key in counterN.keys():
    money = counterN[key]
    if key in counterM.keys():
        money -= counterM[key]
    ans = max(ans,money)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for T in range(0,N)]
M = int(input())
T = [input() for T in range(0,M)]
MAX = 0
for IS in set(S):
    Point = S.count(IS)-T.count(IS)
    if MAX<Point:
        MAX = Point
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)]

import collections

cS = collections.Counter(S)
cT = collections.Counter(T)
ans = 0

for x in list(cS.keys()):
  ans = max(cS[x] - cT[x],ans)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
blue = []
for i in range(N):
  blue.append(input())
M = int(input())
red = []
for i in range(M):
  red.append(input())
ans = 0
for i in range(N):
  count = 0
  for j in range(N):
    if blue[j] == blue[i]:
      count += 1
  for j in range(M):
    if red[j] == blue[i]:
      count -= 1
  if count > ans:
    ans = count
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 set(s):
    ans = max(ans, s.count(i)-t.count(i))
print(ans)

Submission status: Accepted

Solution code:
N = input()
s = []
for i in range(int(N)):
  s.append(input())
M = input()
t = []
for i in range(int(M)):
  t.append(input())
  
strdict = dict()
strset = set()
strset.add('')
strdict['']=0

for str in s:
  if str in strset:
    strdict[str]+=1
  else:
    strset.add(str)
    strdict[str]=1
for str in t:
  if str in strset:
    strdict[str]-=1
  else:
    strset.add(str)
    strdict[str]=-1

maxval=0
for str in strset:
  if maxval < strdict[str]:
    maxval=strdict[str]
print(maxval)

Submission status: Accepted

Solution code:
n = int(input())
d = {}
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
  else: d[t] = -1
    
print(max(0, max(d.values())))

Submission status: Accepted

Solution code:
import statistics
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:
    tmp = s.count(i) - t.count(i)
    if ans <= tmp:
        ans = tmp
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 s:
    tmp = s.count(i) - t.count(i)
    if ans <= tmp:
        ans = tmp
print(ans)

Submission status: Accepted

Solution code:
blue=int(input())
b=[]
r=[]
count=[]
for i in range(blue):
  b.append(input())
red=int(input())
for i in range(red):
  r.append(input())
for i in b:
  count.append(b.count(i)-r.count(i))
if max(count)<0:
  print(0)
else:
  print(max(count))

Submission status: Accepted

Solution code:
blue=int(input())
b=[]
r=[]
for i in range(blue):
  b.append(input())
red=int(input())
for i in range(red):
  r.append(input())
count=[]
for i in range(len(b)):
  counter=0
  for j in range(len(b)):
    if b[i]==b[j]:
      counter+=1
  for j in range(len(r)):
    if b[i]==r[j]:
      counter-=1
  count.append(counter)
if max(count)<0:
  print(0)
else:
  print(max(count))

Submission status: Accepted

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

Pt = max([S.count(s)-T.count(s) for s in S])

print(max(0, Pt))

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
s = Counter([input().strip() for i in range(N)])
M = int(input())
t = Counter([input().strip() for i in range(M)])
r = 0
for k, v in s.items():
    r = max(r, v-t.get(k, 0))
print(r)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    S = [0] * N
    for i in range(N):
        S[i] = readline().strip()
    M = int(readline())
    T = [0] * M
    for i in range(M):
        T[i] = readline().strip()

    c1 = Counter(S)
    c2 = Counter(T)

    ans = 0
    for k, v in c1.items():
        if ans < v - c2[k]:
            ans = v - c2[k]

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())


dic_blue = {}
for i in range(n):
    a = str(input())
    if a in dic_blue:
        dic_blue[a] += 1
    else:
        dic_blue[a] = 1

m = int(input())
dic_red = {}
for i in range(m):
    b = str(input())
    if b in dic_red:
        dic_red[b] += 1
    else:
        dic_red[b] = 1

total_list = []
total_list.append(0)
for j in dic_blue.keys():
    total = 0
    if j in dic_red:
        total = dic_blue[j] - dic_red[j]
        total_list.append(total)
    else:
        total = dic_blue[j]
        total_list.append(total)

print(max(total_list))

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)]
a=[0]*101
for i in range(N):
    a[i]=s.count(s[i])
    for j in range(M):
        if s[i]==t[j]:
            a[i]-=1

print(max(a))

Submission status: Accepted

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

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

res = 0

for s in S:
    if s in T:
        if S[s] - T[s] > 0:
            res = max(res, S[s] - T[s])

    else:
        res = max(res, S[s])

print(res)

Submission status: Accepted

Solution code:
L=list()
R=list()
N=int(input())
for i in range(N):
  S=input()
  L.append(S)
M=int(input())
for i in range(M):
  S=input()
  R.append(S)
maxa=0
for i in range(N):
  s=L.count(L[i])-R.count(L[i])
  maxa=max(maxa,s)
print(maxa)

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    S = []
    for _ in range(N):
        s = input()
        S.append(s)
    M = int(input())
    T = []
    for __ in range(M):
        t = input()
        T.append(t)
    SS = set(S)
    ans = []
    for i in SS:
        ans.append(S.count(i)-T.count(i))
    print(max(max(ans), 0))
resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict


def main():

    blue = defaultdict(int)
    red = defaultdict(int)

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

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

    ans = 0

    for word, cnt in blue.items():
        if word in red.keys():
            ans = max(ans, cnt - red[word])
        else:
            ans = max(ans, cnt)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict
def main():
    d = defaultdict(int)
    n = int(input())
    for _ in range(n):
        d[input()] += 1
    n = int(input())
    for _ in range(n):
        d[input()] -= 1
    print(max(0, *d.values()))

if __name__ == '__main__':
    main()

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

c1 = Counter(s)
c2 = Counter(t)

MAX=0
for k1 in c1.keys():
  count = c1[k1]
  for k2 in c2.keys():
    if k1==k2:
      count -= c2[k2]
  MAX = max(MAX,count)

print(MAX)

Submission status: Accepted

Solution code:
N=int(input())
CARD={}
for i in range(N):
  s = str(input())
  if s not in CARD:
    CARD[s] = 1
  else:
    CARD[s]+=1
M=int(input())
for i in range(M):
  t = str(input())
  if t in CARD:
    CARD[t]-=1
print(max(max(CARD.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)]
ans = 0
for i in s:
    tmp = s.count(i) - t.count(i)
    ans = max(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict as ddf
n=int(input())
s=[input() for _ in range(n)]
m=int(input())
t=[input() for _ in range(m)]

dd=ddf(lambda:0)
for e in s: dd[e]+=1
for e in t: dd[e]-=1
print(max(0,max(dd.values())))

Submission status: Accepted

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

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

ans=0
for i in s:
    ans=max(ans,s.count(i)-t.count(i))
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)]
money = []
for plus in collections.Counter(s).most_common():
    if plus[0] in t:
        money.append(plus[1] - collections.Counter(t).get(plus[0]))
    else:
        money.append(plus[1])
if max(money) < 0:
    print(0)
else:
    print(max(money))

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 st in s:
    if st not in d:
        d[st] = 0
    d[st] += 1
for st in t:
    if st not in d:
        d[st] = 0
    d[st] -= 1

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

Submission status: Accepted

Solution code:
n=int(input())
plus=[input() for _ in range(n)]
m=int(input())
minus=[input() for _ in range(m)]
res=[]
for i in plus:
    a=plus.count(i)
    b=minus.count(i)
    res+=[(a-b,i)]
res.sort(reverse=1)
print(max(0,res[0][0]))

Submission status: Accepted

Solution code:

import collections
n = int(raw_input())
cca = collections.Counter([raw_input() for _ in range(n)])
m = int(raw_input())
ccb = collections.Counter([raw_input() for _ in range(m)])

r = 0
for w in cca.keys() + ccb.keys():
	r = max(r,cca[w] - ccb[w])
print r

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())
m=0
for blue in blues:
    x=blues.count(blue)-reds.count(blue)
    m=max(m,x)
print(m)

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)]
s2=list(set(s))
counter=0
for i in range(len(s2)):
    if s.count(s2[i])-t.count(s2[i])>counter:
        counter=s.count(s2[i])-t.count(s2[i])

print(counter)

Submission status: Accepted

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

ans = 0
for s in S:
    rwd = 0
    for i in range(n):
        if s == S[i]:
            rwd += 1
    for i in range(m):
        if s == T[i]:
            rwd -= 1
    ans = max(rwd, ans)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s_list = []
for _ in range(n):
    s_list.append(input())
m = int(input())
t_list = []
for _ in range(m):
    t_list.append(input())
    
# print(s_list)
# print(t_list)

st_set = set(s_list + t_list)
# print(st_set)

ans = 0
for st in st_set:
    # print(s_list.count(st))
    # print(t_list.count(st))
    # print(f"{s_list.count(st)} {t_list.count(st)}")
    ans = max(ans, s_list.count(st) - t_list.count(st))

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

s.sort()
S = []
S.append(s[0])
for i in range(len(s)-1):
    if s[i] != s[i+1]:
        S.append(s[i+1])

MAX = 0
for i in S:
    d = s.count(i) - t.count(i)
    MAX = max(MAX, d)

print(MAX)

Submission status: Accepted

Solution code:
blue = [input() for _ in range(int(input()))]
red = [input() for _ in range(int(input()))]
ans = 0
for i in set(blue):
    c= blue.count(i) - red.count(i)
    ans = max(c, ans, 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)]

cnt = 0

for s in set(S):
    score = S.count(s) - T.count(s)
    if score > cnt:
        cnt = score
        
print(cnt)

Submission status: Accepted

Solution code:
# AtCoder Beginner Contest 091
# B - Two Colors Card Game

import collections

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

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

C_S=collections.Counter(S)
C_T=collections.Counter(T)

score=0

for word in C_S:
    temp_score=C_S[word] - C_T[word]
    if temp_score>score :
        score=temp_score
    else:
        pass

print(score)

Submission status: Accepted

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

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

answer = 0
for skey in sn.keys():
  if not skey in tn:
    check = sn[skey]
  else :
    check = sn[skey] - tn[skey]
  if answer < check:
    answer = check

print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
cards = {}

n = int(input())
for _ in range(n):
    s = input()
    cards[s] = cards.get(s,0)+1

m = int(input())
for _ in range(m):
    t = input()
    cards[t] = cards.get(t,0)-1

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

Submission status: Accepted

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

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

maxi = 0
words = ""
for i in list(set(plus)):
  temp = plus.count(i) - minus.count(i)
  if maxi < temp:
    maxi = temp
    words = i
print(maxi)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

for i in card.values():
    if i > ans:
        ans = 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)]
o=0
for k in s:
    ans=max(s.count(k)-t.count(k),o)
    o=ans

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

d = defaultdict(int)
N = int(input())
for _ in range(N):
    s = str(input())
    d[s] += 1
M = int(input())
for _ in range(M):
    t = str(input())
    d[t] -= 1

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

Submission status: Accepted

Solution code:
l={}
N=int(input())
for i in range(N):
    a=input()
    if a in l:
        l[a]+=1
    else:
        l[a]=1
M=int(input())
for j in range(M):
    b=input()
    if b in l:
        l[b]-=1

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

Submission status: Accepted

Solution code:
points = {}
n = int(input())
for _ in range(n):
    s = input()
    points.setdefault(s, 0)
    points[s] += 1
m = int(input())
for _ in range(m):
    s = input()
    points.setdefault(s, 0)
    points[s] -= 1
print(max(0, max(points.values())))

Submission status: Accepted

Solution code:
N = int(input())
ListP = []
for i in range (N):
  ListP.append(input())
M = int(input())
ListN = []
for i in range (M):
  ListN.append(input())
res = 0
mid = 0
for i in range(N):
  mid += ListP.count(ListP[i])
  mid += -ListN.count(ListP[i])
  res = max(res,mid)
  mid = 0
print(res)

Submission status: Accepted

Solution code:
d = {}

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

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

print(max(0, max(i for i in d.values())))

Submission status: Accepted

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

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

for i in range(M):
    if t[i] in dic:
        dic[t[i]]-=1
    else:
        dic[t[i]]=-1

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

Submission status: Accepted

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

ans = 0
for w in set(blue_words):
  tmp = blue_words.count(w) - red_words.count(w)
  if tmp > ans:
    ans = tmp

print(ans)

Submission status: Accepted

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

for k, j in t.items():
    if k in s:
        s[k] -= j

values, counts = zip(*s.most_common())
print(max(0,counts[0]))

Submission status: Accepted

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

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


if __name__ == "__main__":
    solve()

Submission status: Accepted

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

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

keys = s.keys() & t.keys()
for key in keys:
    s[key] -= t[key]

print(max(max(s.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)]

ans = 0

for s in set(S):
    ans = max (ans, S.count(s) - T.count(s))
    
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
ex_list = []
for i in range(N):
    if s[i] not in ex_list:
        if s.count(s[i]) > t.count(s[i]):
            ans = max(s.count(s[i])-t.count(s[i]),ans)
            ex_list.append(s[i])
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
bluedict = {}
for i in range(n):
    word = input()
    if bluedict.get(word) == None:
        bluedict[word] = 1
    else:
        bluedict[word] += 1

m = int(input())
reddict = {}
for i in range(m):
    word = input()
    if reddict.get(word) == None:
        reddict[word] = 1
    else:
        reddict[word] += 1

m = 0
for blueword in bluedict.keys():
    c = 0
    c += bluedict[blueword]
    if reddict.get(blueword) != None:
        c -= reddict[blueword]
    m = max(m,c)

print(m)

Submission status: Accepted

Solution code:
N = int(input())
jisyo = {}
for i in range(N):
  a = input()
  if a not in jisyo:
    jisyo[a] = 1
  else:
    jisyo[a] +=1
M = int(input())
for i in range(M):
  b = input()
  if b not in jisyo:
    jisyo[b] = -1
  else:
    jisyo[b] -=1
maxi = 0
for i,k in jisyo.items():
  if maxi < k:
    maxi = k
print(maxi)

Submission status: Accepted

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def S(): return sys.stdin.readline().rstrip()

N = I()
s = [S() for i in range(N)]
M = I()
t = [S() for i in range(M)]

from collections import Counter

c1 = Counter(s)
c2 = Counter(t)
ans = 0
for a in c1.keys():
    ans = max(ans,c1[a]-c2[a])

print(ans)

Submission status: Accepted

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

l = list(set(s))


mx  = max(s.count(l[i])-t.count(l[i]) for i in range(len(l)))
print(max(0,mx))

Submission status: Accepted

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

#print(Counter(s))
cs = Counter(s)
ct = Counter(t)
for i in cs:
    #print(i,cs[i])
    for j in ct:
        #print(j,ct[j])
        if i == j:
            cs[i]=cs[i]-ct[j]
            
#print(cs)
print(max(0,cs.most_common(1)[0][1]))

Submission status: Accepted

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

blues = []
reds = []

count = []
for i in range(n):
    count.append(0)
max_count = 0

for i in range(n):
    p = input()
    blues.append(p)

v = input()
m = int(v)

for i in range(m):
    q = input()
    reds.append(q)

for i in range(len(blues)):
    for j in range(len(blues)):
        if blues[i] == blues[j]:
            count[i] += 1

for i in range(len(blues)):
    for j in range(len(reds)):
        if blues[i] == reds[j]:
            count[i] -= 1

for i in range(len(count)):
    max_count = max(max_count, count[i])

print(max_count)

Submission status: Accepted

Solution code:
N_1 = int(input())
A = [str(input()) for i in range(N_1)]
N_2 = int(input())
B = [str(input()) for i in range(N_2)]

C = A+B
D = list(set(C))
E=[]
for i in range(len(D)):
    NN = A.count(D[i]) - B.count(D[i])
    E.append(NN)
if max(E)>=0:
    print(max(E))
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)]
count = []
mx = 0
words_list = list(set(s+t))
for word in words_list :
    count.append([word, 0])
for word in words_list :
    idx = words_list.index(word)
    count[idx][1] += s.count(word)
    count[idx][1] -= t.count(word)
for i in range(len(words_list)) :
      mx = max(mx,count[i][1])
print(mx)

Submission status: Accepted

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

count = 0
for i in range(n):
  count = s.count(s[i]) - t.count(s[i]) if count < s.count(s[i]) - t.count(s[i]) else count
print(count)

Submission status: Accepted

Solution code:
s ={}
n = int(input())
for _ in range(n):
    word = input()
    s[word] = s.get(word, 0)+1
m = int(input())
for _ in range(m):
    word = input()
    s[word] = s.get(word, 0)-1

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

Submission status: Accepted

Solution code:
import sys

def I(): 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 main():
    n = I()
    s = [input() for _ in range(n)]
    m = I()
    t = [input() for _ in range(m)]
    word = set(s) | set(t)
    ans = 0
    for w in word:
        cnt = s.count(w)
        cnt -= t.count(w)
        ans = max(ans, cnt)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(m):
    t = input()
    if t in count:
        count[t] -= 1
    else:
        count[t] = -1
max_v = max(count.values())
if max_v < 0:
    max_v = 0
print(max_v)

Submission status: Accepted

Solution code:
import collections

N = int(input())

a = []
b = []
for i in range(N):
    s = input()
    a.append(s)

M = int(input())
for i in range(M):
    t = input()
    b.append(t)

a1 = collections.Counter(a)
a2 = a1.most_common()

ans = 0
for i in range(len(a1)):
    total = a2[i][1] - b.count(a2[i][0])
    if total > ans:
        ans = total
    else:
        continue
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)]

s1=set(s)
a=b=0
for ss in s1:
  a=s.count(ss)-t.count(ss)
  if a>b:
    b=a
print(b)

Submission status: Accepted

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

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)]
S = list(set(s))
T = list(set(t))
b = []

for x in range(len(S)):
  a = s.count(S[x]) - t.count(S[x])
  b.append(a)
ans = max(0, max(b))
print(ans)

Submission status: Accepted

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

sd=C(s)
td=C(t)

max=0
for k in sd:
  if sd[k]-td[k]>max:
    max=sd[k]-td[k]
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)]

max = 0
for c in S:
    money = S.count(c) - T.count(c)
    if money > max:
        max = money
print(max)

Submission status: Accepted

Solution code:
import collections
n = int(input())
lb = [input() for _ in range(n)]
m = int(input())
la = [input() for _ in range(m)]


cntb = collections.Counter(lb)
cnta = collections.Counter(la)
t_max = 0
cntb.subtract(cnta)

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

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)]
dic_s = {}
for i in set(s):
    dic_s[i] = s.count(i) 
dic_t = {}
for i in set(t):
    dic_t[i] = t.count(i)
ss=set(s)
ts=set(t)
if(ss & ts == set()):
    print(max(dic_s.values()))
else:
    dic_c = {}
    for i in ss&ts:
        dic_c[i] = dic_s[i] - dic_t[i]
    if(not (ss & (ss^ts) == set())):
        for i in ss & (ss^ts):
            dic_c[i] = dic_s[i]
    if(max(dic_c.values()) < 0):
        print(0)
    else:
        print(max(dic_c.values()))

Submission status: Accepted

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

reds = dict()
blues = dict()

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

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


ans=0
for k in blues.keys():
  if k in reds:
    num = blues[k]-reds[k]
    if num>0:
      ans = max(ans,num)
      continue
  else:
    ans = max(ans,blues[k])
  # ans+=blues[k]

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

# input
N = int(input())
s = []

for i in range(N):
    s.append(str(input()))

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

for j in range(M):
    t.append(str(input()))

set_s = set(s)
set_t = set(t)
ans = 0
tmp_ans = 0

for tmp_s in set_s:
    # 演算
    tmp_ans = s.count(tmp_s) - t.count(tmp_s)
    # 最大値判定
    ans = max(ans, tmp_ans)

print(ans)

Submission status: Accepted

Solution code:
#from heapq import heapify,heappush,heappop
N = int(input())

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Created: Jul, 12, 2020 07:48:40 by Nobody
# $Author$
# $Date$
# $URL$
__giturl__ = "$URL$"


from collections import defaultdict
from sys import stdin
input = stdin.readline


def main():
  N = int(input())
  S = [input()[:-1] for _ in range(N)]

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

  smap = defaultdict(int)
  tmap = defaultdict(int)
  for i in range(N):
    smap[S[i]] += 1
  for i in range(M):
    tmap[T[i]] += 1

  max_ = 0
  for key in smap.keys():
    max_ = max(max_, smap[key]-tmap[key])

  print(max_)


if(__name__ == '__main__'):
  main()