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())
blue = [input() for i in range(N)]
M = int(input())
red = [input() for i in range(M)]
blue_only = []

max_get = 0
for i in range(N):
    if blue[i] in red:
        get = blue.count(blue[i]) - red.count(blue[i])
    else:
        get = blue.count(blue[i])
    if get > max_get:
        max_get = get

print(max_get)

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 range(n):
  d[s[i]] = d.get(s[i],0) + 1
for j in range(m):
  d[t[j]] = d.get(t[j],0) - 1
print(max(d.values()) if max(d.values())>0 else 0)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
s_count = Counter([input() for _ in range(N)])
M = int(input())
t_count = Counter([input() for _ in range(M)])

s_count.subtract(t_count)
print(max(0,s_count.most_common(1)[0][1]))

Submission status: Accepted

Solution code:
Blue = []
Red = []
N = int(input())
for _ in range(N):
    Blue.append(input())
M = int(input())
for _ in range(M):
    Red.append(input())
    
Red.sort()
Blue.sort()

P = []
n = 1
for i in range(N):
    if i != N-1:
        if Blue[i] == Blue[i+1]:
            n += 1
        else:
            for j in range(M):
                if Blue[i] == Red[j]:
                    n -= 1
            P.append(n)
            n = 1
    else:
        for j in range(M):
            if Blue[i] == Red[j]:
                n -= 1
        P.append(n)
        n = 1

maxi = max(P)
if maxi < 0:
    print(0)
else:
    print(maxi)

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

    cnt = 0
for s in set(S):
    cnt = max(cnt, S.count(s)-T.count(s))
print(cnt)

Submission status: Accepted

Solution code:
def get_info(diff):
    length = int(input())
    strings = {}
    for _ in range(length):
        tmp = input()
        if tmp in strings:
            strings[tmp] += diff
        else:
            strings[tmp] = diff
    return length, strings


def main():
    blue_card, blue_card_str = get_info(1)
    red_card, red_card_str = get_info(-1)
    answer = 0
    available_keys = (blue_card_str.keys() & red_card_str.keys()) | blue_card_str.keys()
    for key in available_keys:
        if key in red_card_str:
            diff = blue_card_str[key] + red_card_str[key]
        else:
            diff = blue_card_str[key]
        answer = max(answer, diff)
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

"""
ans = s[0]
for h in range(n):
    tmp = s[h]
    money = 0
    money_max = 0
    for i in range(n):
        if s[i] == tmp:
            money += 1
    for j in range(m):
        if t[j] == tmp:
            money -= 1
    if money > money_max:
        money_max = money
        ans = tmp
print(money_max, ans)
"""

Submission status: Accepted

Solution code:
N = int(input())
s = {}
for i in range(N):
  a = input()
  if a in s:
    s[a] += 1
  else:
    s[a] = 1
M = int(input())
t = {}
for i in range(M):
  b = input()
  if b in t:
    t[b] += 1
  else:
    t[b] = 1
ans = 0
for p in s:
  if p in t:
    m = s[p] - t[p]
  else:
    m = s[p]
  if m > ans:
    ans = m
print(ans)

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
c1 = Counter()
c2 = Counter()

for si in S:
    c1[si] += 1

for ti in T:
    c2[ti] += 1

# print(c1)
# print(c2)

ans = 0
for si in c1.keys():
    ans = max(ans, c1[si] - c2[si])

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
blueList = [input() for _ in range(n)]
m = int(input())
redList = [input() for _ in range(m)]
max_score = 0
for i in blueList:
    score = blueList.count(i) - redList.count(i)
    if max_score < score:
        max_score = score
print(max_score)

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)]
l=set(a+b)
m=0
for x in l:
    c=0
    for y in a:
        if x==y:c+=1
    for z in b:
        if x == z:c-=1
    m=max(m,c)
print(max(m,0))

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_counter = collections.Counter(s)
t_counter = collections.Counter(t)

ans = 0
for i in s_counter:
    ans = max(ans, s_counter[i] - t_counter[i])
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)

CARDS = defaultdict(int)
N = int(input())

for _ in range(N):
    s = input()
    CARDS[s] += 1

M = int(input())

for _ in range(M):
    s = input()
    CARDS[s] -= 1

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


print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from collections import Counter


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

    s = Counter(S)
    t = Counter(T)
    result = 0

    for key, value in s.items():
        if value - t[key] > result:
            result = value - t[key]

    print(result)


if __name__ == "__main__":
    main()

Submission status: Accepted

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


def main():
    N = int(input())
    S = [input() for _ in range(N)]
    M = int(input())
    T = [input() for _ in range(M)]
    result = {}
    for s in S:
        if s in result.keys():
            result[s] += 1
        else:
            result[s] = 1
    for t in T:
        if t in result.keys():
            result[t] -= 1
        else:
            result[t] = -1

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict
bjisho = defaultdict(int)
rjisho = defaultdict(int)
blue = int(input())
for i in range(blue):
    bjisho[input()] += 1
red = int(input())
for i in range(2+blue, red+2+blue):
    rjisho[input()] += 1
for i in bjisho:
    if i in rjisho:
        bjisho[i] -= rjisho[i]
dst = max(bjisho.values()) if max(bjisho.values()) > 0 else 0
print(dst)

Submission status: Accepted

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

dict = {}
for i in s_lst:
    if not i in dict.keys():
        dict[i] = 1
    else:
        dict[i] += 1
for i in t_lst:
    if not i in dict.keys():
        dict[i] = -1
    else:
        dict[i] -= 1

infinity = float('inf')
max = -infinity
for i in dict.values():
    if max < i:
        max = i
print(max) if max > 0 else print(0)

Submission status: Accepted

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

dict = {}
for i in s_lst:
    dict[i] = 0
for i in t_lst:
    dict[i] = 0
for i in s_lst:
    dict[i] += 1
for i in t_lst:
    dict[i] -= 1
infinity = float('inf')
max = -infinity
for i in dict.values():
    if max < i:
        max = i
print(max) if max > 0 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())


ans = []
for i in s:
    plus = s.count(i)
    minus = t.count(i)

    score = (plus - minus)
    ans.append(score)

if max(ans) < 0:
    print(0)
else:
    print(max(ans))

Submission status: Accepted

Solution code:
n = int(input())
l_n = [input() for i in range(n)]
m = int(input())
l_m = [input() for i in range(m)]
max_c = 0
for i in range(n):
    max_c = max(max_c, l_n.count(l_n[i]) - l_m.count(l_n[i]))
print(max_c)

Submission status: Accepted

Solution code:
import collections
n=int(input())
s=[]
for _ in range(n):
	s.append(input())
c=collections.Counter(s)
m=int(input())
for _ in range(m):
	t=input()
	c[t] -= 1
if max(c.values()) >= 0:
	print(max(c.values()))
else:
	print(0)

Submission status: Accepted

Solution code:
from collections import defaultdict

b = defaultdict(int)
r = defaultdict(int)

n = int(input())
for i in range(n):
    b[input()] += 1
m = int(input())
for i in range(m):
    r[input()] += 1
ans = 0
for k, v in b.items():
    ans = max(ans, v - r[k])
print(ans)

Submission status: Accepted

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

n = int(input())
for i in range(n):
  b[input()]+=1
m = int(input())
for i in range(m):
  r[input()]+=1
  
ans = 0
for k, v in b.items():
  ans = max(ans, v - r[k])
for k, v in r.items():
  ans = max(ans, b[k] - v)
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:
    in_s = s.count(i)
    in_t = t.count(i)
    ans.append(in_s-in_t)
print(max(ans))

Submission status: Accepted

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

dic_S = {x:0 for x in set(S)}
dic_T = {x:0 for x in set(T)}
ans = list(range(len(set(S))))
for s in S:
    dic_S[s] += 1
for t in T:
    dic_T[t] += 1
for i,key in enumerate(dic_S):
    if key in list(dic_T.keys()):
        ans[i] = dic_S[key]-dic_T[key]
    else:
        ans[i] = dic_S[key]
if max(ans) > 0:
    print(max(ans))
else:
    print(0)

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for x in range(n)]

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

ans = 0
for i in s:
  plus = s.count(i)
  minus = t.count(i)
  temp = plus - minus

  ans = max(ans, temp)

if ans < 0:
  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)]

ans = 0
for ss in s:
    tmp = 0
    for tt in t:
        if ss == tt:
            tmp -= 1
    for sss in s:
        if ss == sss:
            tmp += 1
    ans = max(ans, tmp)
print(ans)

Submission status: Accepted

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

M = int(input())
T = {}
for i in range(M):
    t = input()
    if t not in T:
        T[t] = 1
        continue
    T[t] += 1

ans = 0
for key in S.keys():
    if key not in T:
        ans = max(ans, S[key])
        continue
    ans = max(ans, S[key] - T[key])
print(ans)

Submission status: Accepted

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

for i in range(n):
    tmp = s[i]
    cnt = 0
    for j in range(n):
        if s[j] == tmp:
            cnt += 1

    for j in range(m):
        if t[j] == tmp:
            cnt -= 1
    ans = max(ans, cnt)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
sl = ["" for _ in range(n)]
for i in range(n):
    sl[i] = input()

m = int(input())
tl = ["" for _ in range(m)]
for i in range(m):
    tl[i] = input()

ans = 0
for blue_word in sl:
    ans = max(ans, (sl.count(blue_word)-tl.count(blue_word)))

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)]
def ans1(x):
    return s.count(x)-t.count(x)
ans2=0
ans_1=0
for S in s:
    if ans1(S)>0 and ans1(S)>ans2:
            ans2=ans1(S)
if ans2>=0:
    print(ans2)
else:
    print("0")

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n=int(input())
slist=[input() for i in range(n)]
m=int(input())
tlist=[input() for i in range(m)]
words = set(slist) | set(tlist)
ans=0
for i in words:
  l = slist.count(i) - tlist.count(i)
  ans = max(l,ans)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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 and d[s] > 0:
    d[t] -= 1
print(max(d[s] for s in d))

Submission status: Accepted

Solution code:
from collections import defaultdict
d = defaultdict(int)

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

Submission status: Accepted

Solution code:
import collections
n=int(input())
a=collections.Counter([str(input()) for _ in range(n)])
m=int(input())
b=collections.Counter([str(input()) for _ in range(m)])
ans=0
for k,v in a.items():
  if b.get(k) is None:
    ans=max(ans,v)
  else:
    ans=max(ans,v-b.get(k))
print(ans)

Submission status: Accepted

Solution code:
n = input()
red = []
for i in range(n):
    red.append(raw_input())
k = input()
blue = []
for j in range(k):
    blue.append(raw_input())
ans = 0
for r in red:
    counterR = 0
    counterB = 0
    for word in red:
        if word == r:
            counterR += 1
    for word in blue:
        if word == r:
            counterB += 1
    if ans < counterR - counterB:
        ans = counterR - counterB
print ans

Submission status: Accepted

Solution code:
from collections import defaultdict

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

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

for e in s:
    ds[e] += 1

for e in t:
    dt[e] += 1

ans = 0
for k, v in ds.items():
    money = v - dt[k]
    ans = max(ans, money)

print(ans)

Submission status: Accepted

Solution code:
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n=INT()
    get=[]
    ct=0
    for i in range(n):
        get.append(STR())
    m=INT()
    lost=[]
    for i in range(m):
        lost.append(STR())
    get_set=set(get)
    for gs in get_set:
        temp=get.count(gs)-lost.count(gs)
        ct=max(ct,temp)
    print(ct)
        
if __name__ == '__main__':
    do()

Submission status: Accepted

Solution code:
n = int(input())
s = ['.'] * n
for i in range(n):
    s[i] = str(input())

m = int(input())
t = ['.'] * m
for i in range(m):
    t[i] = str(input())

ans = 0
for i1 in range(n):
    score = 0
    for i2 in range(n):
        if s[i1] == s[i2]:
            score += 1
    for j in range(m):
            if s[i1] == t[j]:
                score -= 1
    if ans <= score:
        ans = score

print(ans)

Submission status: Accepted

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

#n, a, b= map(int, input().split())
#w, h, n  = map(int, input().split())
#s = list(str(input()))
n = int(input())
s = [""]*n
for i in range(n):
  s[i] = str(input())
m = int(input())
t = [""]*m
for i in range(m):
  t[i] = str(input())
#a = list(map(int, input().split()))

c1 = collections.Counter(s)
c2 = collections.Counter(t)
score = [0]*len(s)
counter = 0

for i in c1.keys():
  score[counter] = c1[i] - c2[i]
  counter = counter + 1

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

Submission status: Accepted

Solution code:
N = int(input())
s = []
ans = 0
x = dict()
for i in range(N):
    s.append(input())
    if s[i] in x:
        x[s[i]] += 1
    else:
        x[s[i]] = 1
M = int(input())
t = []
for i in range(M):
    t.append(input())
    if t[i] in x:
        x[t[i]] -= 1

for idx in x:
    ans = max(ans,x[idx])
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
s = [input() for _ in range(N)]
M = int(input())
t = [input() for _ in range(M)]
# 全種類
st = set(s) | set(t)

d1 = defaultdict(int)
d2 = defaultdict(int)

for key in s:
    d1[key] += 1
for key in t:
    d2[key] -= 1

answer = 0
for key in st:
    answer = max(answer, d1[key]+d2[key])
print(answer)

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 range(n):
    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:
nn=int(input())
s_list=[]
for i in range(nn):
	s_list.append(str(input()))
mm=int(input())
t_list=[]
for j in range(mm):
	t_list.append(str(input()))

count_list=[]
for k in range(nn):
	name = s_list[k]
	count=0
	for l in range(nn):
		if name==s_list[l]:
			count+=1
	for m in range(mm):
		if name==t_list[m]:
			count-=1
	count_list.append(count)

max_value=max(count_list)
if max_value<=0:
	max_value=0
print(max_value)

Submission status: Accepted

Solution code:
import sys

nn=int(input())
s_list=[]
for i in range(nn):
	s_list.append(str(input()))
mm=int(input())
t_list=[]
for j in range(mm):
	t_list.append(str(input()))

count_list=[]
for k in range(nn):
	name = s_list[k]
	count=0
	for l in range(nn):
		if name==s_list[l]:
			count+=1
	for m in range(mm):
		if name==t_list[m]:
			count-=1
	count_list.append(count)

for n in range(mm):
	name = t_list[n]
	count=0
	for o in range(nn):
		if name==s_list[o]:
			count+=1
	for p in range(mm):
		if name==t_list[p]:
			count-=1
	count_list.append(count)
max_value=max(count_list)
if max_value<=0:
	max_value=0
print(max_value)

Submission status: Accepted

Solution code:
n = int(input())
s = {}
for i in range(n):
    a = input()
    if a in s:
        s[a] += 1
    else:
        s[a] = 1
t = {}
m = int(input())
for i in range(m):
    a = input()
    if a in t:
        t[a] += 1
    else:
        t[a] = 1
ans = 0
for i,j in s.items():
    if i in t:
        if j > t[i]:
            ans = max(ans,j-t[i])
    else:
        ans = max(ans,j)
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)]
dics = {}
for i in s:
	if i in dics:
		dics[i] += 1
	else:
		dics[i] = 1
dict = {}
for j in t:
	if j in dict:
		dict[j] += 1
	else:
		dict[j] = 1
ans = 0
for i in dics.keys():
	if i in dict:
		ans = max(ans, dics[i]-dict[i])
	else:
		ans = max(ans, dics[i])
print (ans)

Submission status: Accepted

Solution code:
n = int(input())
score = {}
for _ in range(n):
    blue = input()
    if blue in score:
        score[blue] += 1
    else:
        score[blue] = 1
m = int(input())
for _ in range(m):
    red = input()
    if red in score:
        score[red] -= 1
    else:
        score[red] = -1
dict_max = max(score.values())
print(max(dict_max,0))

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

point = [get - t[word] for word, get in s.items()]
print(max(max(point), 0))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from collections import defaultdict

n = int(input())
sd = defaultdict(int)
for _ in range(n):
    s = input()
    sd[s] += 1

m = int(input())
td = defaultdict(int)
for _ in range(m):
    t = input()
    td[t] += 1

res = 0
for s in sd:
    res = max(res, sd[s] - td[s])
print(res)

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

s1=Counter(s)
t1=Counter(t)
#print(s1,t1)
s1.subtract(t1)
if (s1.most_common()[0][1]<0):
    print("0")
else:
    print(s1.most_common()[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)]
ans = 0
for i in range(n):
    ans1 = 0
    for j in range(n):
        if s[i] == s[j]:
            ans1 += 1
    for k in range(m):
        if s[i] == t[k]:
            ans1 -= 1
    ans = max(ans, ans1)
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)]
l = [0]*100
for i in range(n):
    ans = 0
    for j in range(n):
        if s[i] == s[j]:
            ans += 1
    for k in range(m):
        if s[i] == t[k]:
            ans -= 1
    l[i] = ans
print(max(max(l), 0))

Submission status: Accepted

Solution code:
n = int(input())
N = ['']*n
for i in range(n):
    N[i] = input()
m = int(input())
M = ['']*m
for i in range(m):
    M[i] = input()
r = 0
for i in N:
    r = max(N.count(i)-M.count(i), r)
print(r)

Submission status: Accepted

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

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 _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]

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

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(input())
a = [input() for _ in range(n)]
m = int(input())
b = [input() for _ in range(m)]
c = list(set(a))
ans = 0
for i in c:
    if a.count(i) > b.count(i): ans = max(ans,a.count(i) - b.count(i))
print(ans)

Submission status: Accepted

Solution code:
#setの利用
#ABC091B - Two Colors Card Game
#https://atcoder.jp/contests/abc091/tasks/abc091_b

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

lst = list(set(s))
ans = 0
for i in range(len(lst)):
    a = lst[i]
    b = s.count(a) - t.count(a)
    if b > ans:
        ans = b
        
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

def solve(n, S, m, T):
    d = defaultdict(int)
    for s in S:
        d[s] += 1
    for t in T:
        d[t] -= 1
    return max(0, max(d.values()))

_n = int(input())
_S = [input() for _ in range(_n)]
_m = int(input())
_T = [input() for _ in range(_m)]
print(solve(_n, _S, _m, _T))

Submission status: Accepted

Solution code:
n = int(input())
ss = [0] * n
for i in range(n):
    ss[i] = input()

m = int(input())
ts = [0]*m
for i in range(m):
    ts[i] = input()

ans = 0
t = 0

for i in range(n):
    t = 0
    for j in range(n):
        if ss[i] == ss[j]:
            t += 1
    for k in range(m):
        if ss[i] == ts[k]:
            t -= 1
    ans = max(ans,t)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

M = int(input())
tc = Counter([input() for _ in range(M)])
ans = 0
for s in sc.most_common():
    k, v = s
    ans = max(ans, v - tc[k])
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)]

C_S = Counter(S)
C_T = Counter(T)
C_S.subtract(C_T)
print(max(0, C_S.most_common(1)[0][1]))

Submission status: Accepted

Solution code:
from collections import Counter, defaultdict


def solve():
    N = int(input())
    
    A = [input() for _ in range(N)]
    count_A = Counter(A)
    
    M = int(input())
    B = [input() for _ in range(M)]
    count_B = Counter(B)
    for k,v in count_B.items():
        if k in count_A:
            count_A[k] -= v
    
    ret = count_A.most_common()[0][1]
    print(max(ret,0))
    
solve()

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_cnt = Counter(S)
S_key = S_cnt.keys()
T_cnt = Counter(T)

for key,v in T_cnt.items():
    if not key in S_key:
        continue
    S_cnt[key] -= v
print(max(max(S_cnt.values()), 0))

Submission status: Accepted

Solution code:
import collections


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

for _ in range(N):
    s.append(input())

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

for _ in range(M):
    t.append(input())
    
c = collections.Counter(s).most_common()
d = collections.Counter(t).most_common()


m = 0
for e in c:
    g = e[1]
    for f in d:
        if e[0] == f[0]:
            g -= f[1]
    if g > m:
        m = g
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)]
S_Set = set(S)
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
List1 = [input() for i in range(int(input()))]
List2 = [input() for i in range(int(input()))]

Set1 = set(List1)

print(max(max([List1.count(item) - List2.count(item) for item in Set1]),0))

Submission status: Accepted

Solution code:
dic = {"": 0}

n = int(input())
for i in range(n):
  inp = input()
  if inp in dic:
    dic[inp] += 1
  else:
    dic[inp] = 1

m = int(input())
for i in range(m):
  inp = input()
  if inp in dic:
    dic[inp] -= 1
  else:
    dic[inp] = -1

print(max(dic.values()))

Submission status: Accepted

Solution code:
n=int(input())
b=[input() for _ in range(n)]
m=int(input())
r=[input() for _ in range(m)]
d={}
for i in range(n):
  if b[i] in d:
    d[b[i]]+=1
  else:
    d[b[i]]=1
for i in range(m):
  if r[i] in d:
    d[r[i]]-=1
  else:
    d[r[i]]=-1
ans=max(d.values())
if ans<0:
  print(0)
else:
  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)] 
a=0
for i in set(s):
    a=max(s.count(i)-t.count(i),a)
print(a)

Submission status: Accepted

Solution code:
import collections
n = int(input())
li1 = list(input() for _ in range(n))
li1 = collections.Counter(li1)
#print(li1)
m = int(input())
li2 = list((input() for _ in range(m)))
li2 = collections.Counter(li2)
#print(li2)
li3 = li1 - li2
#print(li3)

if li3 == collections.Counter():
    print(0)
else:
    print(max(li3.values()))

Submission status: Accepted

Solution code:
from itertools import groupby as gb 
n=int(input())
sl,vl=[list(a) for a in zip(*[(s,len(list(i))) for s,i in gb(sorted([input() for i in range(n)]))])]
m=int(input())
slm,vlm=[list(a) for a in zip(*[(s,-len(list(i))) for s,i in gb(sorted([input() for i in range(m)]))])]
for i in set(sl)&set(slm):
  vl[sl.index(i)]+=vlm[slm.index(i)]
print(max(0,max(vl)))

Submission status: Accepted

Solution code:
def solve():
  from itertools import groupby as gb 
  n=int(input())
  sl,vl=[list(a) for a in zip(*[(s,len(list(i))) for s,i in gb(sorted([input() for i in range(n)]))])]
  m=int(input())
  slm,vlm=[list(a) for a in zip(*[(s,-len(list(i))) for s,i in gb(sorted([input() for i in range(m)]))])]
  for i in set(sl)&set(slm):
    vl[sl.index(i)]+=vlm[slm.index(i)]
  print(max(0,max(vl)))
  
if __name__=="__main__":
  solve()

Submission status: Accepted

Solution code:
def solve():
  from itertools import groupby as gb 
  n=int(input())
  l=[(s,len(list(i))) for s,i in gb(sorted([input() for i in range(n)]))]
  sl,vl=[list(a) for a in zip(*l)]
  m=int(input())
  lm=[(s,-len(list(i))) for s,i in gb(sorted([input() for i in range(m)]))]
  slm,vlm=[list(a) for a in zip(*lm)]
  for i in set(sl)&set(slm):
    vl[sl.index(i)]+=vlm[slm.index(i)]
  print(max(0,max(vl)))
  
if __name__=="__main__":
  solve()

Submission status: Accepted

Solution code:
from itertools import groupby as gb 
n=int(input())
l=[(s,len(list(i))) for s,i in gb(sorted([input() for i in range(n)]))]
sl,vl=[list(a) for a in zip(*l)]
m=int(input())
lm=[(s,-len(list(i))) for s,i in gb(sorted([input() for i in range(m)]))]
slm,vlm=[list(a) for a in zip(*lm)]
for i in set(sl)&set(slm):
  vl[sl.index(i)]+=vlm[slm.index(i)]
print(max(0,max(vl)))