Problem:


Score : 200 points

Problem Statement

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

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

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

At most how much can he earn on balance?

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

Constraints

N and M are integers.

1 \leq N, M \leq 100

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

Input

Input is given from Standard Input in the following format:

N
s_1
s_2
:
s_N
M
t_1
t_2
:
t_M

Output

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

Sample Input 1

3
apple
orange
apple
1
grape

Sample Output 1

2

He can earn 2 yen by announcing apple.

Sample Input 2

3
apple
orange
apple
5
apple
apple
apple
apple
apple

Sample Output 2

1

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

Sample Input 3

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

Sample Output 3

0

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

Sample Input 4

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

Sample Output 4

1



Sample input:
3
apple
orange
apple
1
grape


Sample output:
2

Submission status: Accepted

Solution code:
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = int(sys.stdin.readline().rstrip())
    S = [str(sys.stdin.readline().rstrip()) for _ in range(N)]
    M = int(sys.stdin.readline().rstrip())
    T = [str(sys.stdin.readline().rstrip()) for _ in range(M)]
    target = set(S)

    ret = 0
    for s in target:
        tmp = S.count(s) - T.count(s)
        if ret < tmp:
            ret = tmp

    print(ret)


if __name__ == '__main__':
    main()

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 query in set(s+t):
    gain = s.count(query) - t.count(query)
    res=max(res,gain)
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)]
l = [0]*n
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())

get_dict={}
for i in range(N):
  s=input()
  if s in get_dict.keys():
    get_dict[s]+=1
  else:
    get_dict[s]=1
    
M=int(input())
lose_dict={}
for i in range(M):
  s=input()
  if s in lose_dict.keys():
    lose_dict[s]+=1
  else:
    lose_dict[s]=1

ind=list(set(list(get_dict.keys())+list(lose_dict.keys())))
ans=0
for s in ind:
  try:
    a=get_dict[s]
  except:
    a=0
  try:
    b=lose_dict[s]
  except:
    b=0
  ans=max(ans, a-b)
  
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

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

a=Counter(A)
b=Counter(B)

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

Submission status: Accepted

Solution code:
n=int(input())
blue=[input() for _ in range(n)]
m=int(input())
red=[input() for _ in range(m)]
l=list(set(blue))
print(max(0,max(blue.count(l[i])-red.count(l[i]) for i in range(len(l)))))

Submission status: Accepted

Solution code:
from collections import defaultdict
def solve():
    N = int(input())
    blue = defaultdict(int)
    for i in range(N):
        s = input()
        blue[s] += 1
    
    M = int(input())
    red = defaultdict(int)
    for i in range(M):
        t = input()
        red[t] += 1

    mx = 0
    for item in blue.items():
        mx = max(mx, item[1] - red[item[0]])

    print(mx)
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys
import math
#a,b= map(int,input().split())
a=int(input())
li0=[]
li1=[]
for d in range(a):
  li0.append(input())
b=int(input())
for f in range(b):
  li1.append(input())
jug=0

for i in li0:
  count=0
  for j in li0:
    if i==j:
      count+=1
  for k in li1:
    if i==k:
      count-=1
  jug=max(jug,count)
#a, b, c = [list(map(int, input().split())) for _ in range(3)]
#li0= [int(x) for x in input().split()]
print(jug)

Submission status: Accepted

Solution code:

import collections

def uzai():
            n = int(input())
            s = []
            for i in range(n):
                        s_i = input()
                        s.append(s_i)
            count_dict_s = collections.Counter(s)
            return n, s, count_dict_s

n,s,count_dict_s = uzai()
m,t,count_dict_t = uzai()

#print("count_dict_s",count_dict_s)
#print("count_dict_t",count_dict_t)

s_count_l=[]
for s_name, s_count in count_dict_s.items():
            for t_name, t_count in count_dict_t.items():
                    if s_name==t_name:
                                 s_count_l.append(s_count-t_count)
                    elif s_name not in count_dict_t:
                                 s_count_l.append(s_count)
                                # print(s_name,s_count_l)
if max(s_count_l)<=0:
            print('0')
else:
             print(max(s_count_l))

Submission status: Accepted

Solution code:
n=int(input())
b=[input() for _ in range(n)]
m=int(input())
r=[input() for _ in range(m)]
l=list(set(b))
a=[]
for s in l:
    a.append(b.count(s) - r.count(s))

print(max(max(a),0))

Submission status: Accepted

Solution code:
N = int(input())
dic = {}
for i in range(N):
    s = input()
    if s in dic:
        dic[s] += 1
    else:
        dic[s] = 1
M = int(input())
dic2 = {}
for i in range(M):
    s = input()
    if s in dic2:
        dic2[s] += 1
    else:
        dic2[s] = 1
ans = 0
for k,v in dic.items():
    tmp = v
    for k2,v2 in dic2.items():
        if k == k2:
            tmp -= v2
    ans = max(tmp,ans)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
lsn=[(input()) for i in range(n)]
m = int(input())
lsm=[(input()) for i in range(m)]
ls = []
for i in range(n):
  ls.append(lsn.count(lsn[i])-lsm.count(lsn[i]))
if max(ls) <= 0:
  print(0)
else:
  print(max(ls))

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)]
ans, sav = 0, 0
smc = Counter(s).most_common()
for v, i in smc:
    if v in t:
        sav = i - t.count(v)
    else:
        sav = i

    if ans < sav:
        ans = sav
if ans < 0:
    ans = 0
print(ans)

Submission status: Accepted

Solution code:
import collections
d = collections.defaultdict(int)
N = int(input())
for _ in range(N):
  s = input()
  d[s] += 1
M = int(input())
for _ in range(M):
  s = input()
  d[s] -= 1
ret = 0
for k,v in d.items():
  ret = max(ret,v)
print(ret)

Submission status: Accepted

Solution code:
n=int(input())
a=[] ; b=[]
for _ in range(n):
    a.append(input())
m=int(input())
for _ in range(m):
    b.append(input())
from collections import Counter
a=Counter(a)
b=Counter(b)
for i in b:
    if i in a:
        a[i]=max(0,a[i]-b[i])
print(max(a.values()))

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
n=int(input())
a=[] ; b=[]
for _ in range(n):
    a.append(input())
m=int(input())
for _ in range(m):
    b.append(input())
from collections import Counter
a=Counter(a)
b=Counter(b)
for i in b:
    if i in a:
        a[i]=max(0,a[i]-b[i])
print(max(a.values()))

Submission status: Accepted

Solution code:
import collections
s = [input() for i in range(int(input()))]
t = [input() for i in range(int(input()))]
s = list(collections.Counter(s).items())
ans = [0]
for i in range(len(s)):
  ans.append(s[i][1]-t.count(s[i][0]))
ans.sort(reverse = True)
print(ans[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 = [0] * n
for i in range(n):   
    count[i] = s.count(s[i])
    for j in range(m):
        if s[i] == t[j]:
            count[i] -= 1
if all(i < 0 for i in count):
    print(0)
else:
    print(max(count))

Submission status: Accepted

Solution code:
#ABC091

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

for i in set(s):
    l.append([s.count(i)-t.count(i),i])
l = sorted(l,reverse=True)


print(max(l[0][0],0))

Submission status: Accepted

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

#print(S, T)
S_set = set(S)
#print(S_set)

max_cnt = -100
for checker in S_set:
  cnt = 0
  for s in S:
    if s == checker:
      cnt += 1
  for t in T:
    if t == checker:
      cnt -= 1
  if cnt > max_cnt:
    max_cnt = cnt
if max_cnt < 0:
  print(0)
else:
  print(max_cnt)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
s = [input() for i in range(n)]
m = int(input())
t = [input() for i in range(m)]
s_cnt = Counter(s)
t_cnt = Counter(t)
ans = []

for i in s_cnt:
    if i in t_cnt:
        cal = s_cnt[i] - t_cnt[i]
        if cal <= 0:
            cal = 0
        ans.append(cal)
    else:
        ans.append(s_cnt[i])
print(max(ans))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

s_map = {}
N = int(input())
for _ in range(N):
    s = input().rstrip('\r\n')
    num = s_map.get(s)
    if num == None:
        num = 1
    else:
        num += 1
    s_map[s] = num
M = int(input())
for _ in range(M):
    s = input().rstrip('\r\n')
    num = s_map.get(s)
    if num == None:
        num = -1
    else:
        num -= 1
    s_map[s] = num
s_map_sorted = sorted(s_map.items(), key=lambda x:x[1], reverse=True)
ans = max(0, s_map_sorted[0][1])
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = []
L = []
for i in range(N):
  s = str(input())
  S.append(s)
M = int(input())
for i in range(M):
  l = str(input())
  L.append(l)
Ans = 0
for i in range(N):
  a = S[i]
  A = S.count(a)-L.count(a)  
  if A > Ans:
    Ans = A
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)]

ctr = Counter(s)

for val in t:
    if not val in ctr:
        continue
    ctr[val] -= 1

ans = ctr.most_common()[0][1]
if ans >= 0:
    print(ans)
else:
    ans = 0
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())
blu_list = [str(input()) for _ in range(n)]
m = int(input())
red_list = [str(input()) for _ in range(m)]

blu_set_list = list(set(blu_list))
red_set_list = list(set(red_list))
set_list = blu_set_list + red_set_list

blu_cnt = []
red_cnt = []
ans = []

for i in set_list:
    blu_cnt.append(blu_list.count(i))
    red_cnt.append(red_list.count(i))

for i in range(len(set_list)):
    ans.append(blu_cnt[i] - red_cnt[i])

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

Submission status: Accepted

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

sc=Counter(s).most_common()
li=[]
for k,j in sc:
    cnt=0
    for x in range(len(t)):
        if(k==t[x]):
            cnt+=1
    li.append(j-cnt)
if(len(li)!=0):
    print(max(0,max(li)))

Submission status: Accepted

Solution code:
n = [input() for i in range(int(input()))]
m = [input() for i in range(int(input()))]
words = list(set(n))
print(max(0,max(n.count(words[i])-m.count(words[i]) for i in range(len(words)))))

Submission status: Accepted

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

import collections

posi = collections.Counter(s_L)

ans = {}
for k,v in posi.items():
    for t in t_L:
        if t == k:
            v -= 1
    ans[k] = v


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

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

Submission status: Accepted

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

counts = {}

for r in RED:
    counts[r] = (counts.get(r) or 0) + 1
    
for b in BLUE:
    counts[b] = (counts.get(b) or 0) - 1
    
print(max(max(counts.values()),0))

Submission status: Accepted

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

Submission status: Accepted

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

for _ in range(M):
    try:
        S.remove(input())
    except:
        pass

if S==[]:
    print(0)
else:
    S_=Counter(S)
    print(S_.most_common()[0][1])

Submission status: Accepted

Solution code:
from collections import defaultdict

cards = defaultdict(int)

N = int(input())

for _ in range(N):
  cards[input()] += 1
  
M = int(input())  

for _ in range(M):
  cards[input()] -= 1
  
print(max(
  max(cards.values()),
  0
))

Submission status: Accepted

Solution code:
#091_B
n=int(input())
s=[input() for _ in range(n)]
m=int(input())
t=[input() for _ in range(m)]

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

Submission status: Accepted

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

m = int(input())
red_card = {}
for _ in range(m):
    s = input()
    if s not in red_card:
        red_card[s] = 1
    else:
        red_card[s] += 1
max_diff = 0
for s in blue_card:
    if s not in red_card:
        red_card[s] = 0
    diff = blue_card[s] - red_card[s]
    max_diff = max(max_diff, diff)
print(max_diff)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

result = 0
for i in range(len(s)):
    result = max(s[i][1]-t[s[i][0]], result)
print(result)

Submission status: Accepted

Solution code:
import collections
n = int(input())
s = list()
for i in range(n):
    s.append(input())
m = int(input())
t = list()
for i in range(m):
    t.append(input())
st = set(s)
tt = set(t)
sc = collections.Counter(s)
tc = collections.Counter(t)
highest = -float("inf")
for i in st:
    x = sc[i] - tc[i]
    if x > highest:
        highest = x
if highest < 0:
    print(0)
else:

    print(highest)

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
temp = set(S)
for i in temp:
    if S.count(i) - T.count(i) > ans:
        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)]

set_S=set(S)
dict_S=collections.Counter(S)
set_T=set(T)
dict_T=collections.Counter(T)

for i in set_S:
    if i in set_T:
        dict_S[i]-=dict_T[i]
print(max(max(dict_S.values()),0))

Submission status: Accepted

Solution code:
n = int(input())
S = [input() for _ in range(n)]
D = {}
for s in S:
    if s in D:
        D[s] += 1
    else:
        D[s] = 1
m = int(input())
T = [input() for _ in range(m)]
for t in T:
    if t in D:
        D[t] -= 1
D_sorted = sorted(D.items(), key=lambda x: x[1], reverse=True)
for k, v in D_sorted:
    print(max(0, v))
    exit()

Submission status: Accepted

Solution code:
ls_blue = [input() for _ in range(int(input()))]
ls_red = [input() for _ in range(int(input()))]
set_all = set(ls_blue + ls_red)
dic_point = {}
for word in set_all:
    dic_point[word] = ls_blue.count(word) - ls_red.count(word)

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

Submission status: Accepted

Solution code:
def main(n, s: list, m, t: list):
    choices = set(s + t)

    ans = [0]

    for choice in choices:
        ans_t = 0
        for _s in s:
            if choice == _s:
                ans_t += 1
        for _t in t:
            if choice == _t:
                ans_t -= 1

        ans.append(ans_t)

    print(max(ans))


if __name__ == "__main__":
    n = int(input())
    s = [input() for _ in range(n)]
    m = int(input())
    t = [input() for _ in range(m)]

    main(n, s, m, t)

Submission status: Accepted

Solution code:
from itertools import groupby

def solve():
    N = int(input())
    a = [input() for _ in range(N)]
    a.sort()
    M = int(input())
    b = [input() for _ in range(M)]
    b.sort()
    
    d = {}
    gr = groupby(a)
    for key, group in gr:
        d.setdefault(key, []).append(len(list(group)))
    
    gr = groupby(b)
    for key, group in gr:
        d.setdefault(key, []).append(-len(list(group)))
    
    m = 0
    for k, v in d.items():
        su = sum(v)
        if su > m:
            m = su
    return m

print(solve())

Submission status: Accepted

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

def main():
    N = int(input())
    cards = defaultdict(int)
    for _ in range(N):
        cards[input()] += 1

    M = int(input())
    for _ in range(M):
        cards[input()] -= 1
    print(max(max(cards.values()),0))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
s_li = [input() for i in range(N)]
M = int(input())
t_li = [input() for i in range(M)]
cost_dic = {}
for i in range(N) :
    cost_dic[s_li[i]] = s_li.count(s_li[i]) - t_li.count(s_li[i])
cost_sorted = sorted(cost_dic.items(), key=lambda x:x[1],reverse=True)
print(max(0, cost_sorted[0][1]))

Submission status: Accepted

Solution code:
import collections

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

ans = 0
word = []
wordCnt = []

for i in range(n):
    if not blue[i] in word:
        word.append(blue[i])
        wordCnt.append(1)
    else:
        for j in enumerate(word):
            if blue[i] == j[1]:
                wordCnt[j[0]] += 1

for i in range(m):
    if not red[i] in word:
        word.append(red[i])
        wordCnt.append(-1)
    else:
        for j in enumerate(word):
            if red[i] == j[1]:
                wordCnt[j[0]] -= 1

ans = max(wordCnt)
if ans < 0:
    ans = 0
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict
blue = defaultdict(int)
red = defaultdict(int)

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

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

ans = 0
for k, v in blue.items():
    w = v - red[k]

    ans = max(w, ans)
print(ans)

Submission status: Accepted

Solution code:
from operator import itemgetter
n=int(input())
s=[input() for i in range(n)]
m=int(input())
t=[input() for i in range(m)]
d=dict()
for i in range(n):
  if s[i] not in d:
    d[s[i]]=1
  else:
    d[s[i]]+=1
for i in range(m):
  if t[i] in d:
    d[t[i]]-=1
d=sorted(list(d.items()),reverse=True,key=itemgetter(1))
if d[0][1]>0:
  print(d[0][1])
else:
  print(0)

Submission status: Accepted

Solution code:

n=int(input())
blue=[input() for _ in range(n)]
bset = set(blue)

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

print(max([max(0, blue.count(b) - red.count(b)) for b in bset]))

Submission status: Accepted

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

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

counter = dict()

for s in ss:
    counter.setdefault(s, 0)
    c = counter.get(s)
    counter[s] = c + 1
    
for t in ts:
    counter.setdefault(t, 0)
    c = counter.get(t)
    counter[t] =  c - 1
    
ans = max(counter.values())
if ans < 0:
    ans = 0
print(ans)

Submission status: Accepted

Solution code:
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

from collections import defaultdict

N = ni()
s = nsn(N)
M = ni()
t = nsn(M)

d = defaultdict(int)
b = defaultdict(int)
for i in range(N):
    d[s[i]] += 1

for i in range(M):
    b[t[i]] += 1

ans = -inf
for k, v in d.items():
    ans = max(ans, v - b[k])

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

for i in set(s):
  num = s.count(i) - t.count(i)
  if num > ans :
    ans = num
    
    
print(ans)

Submission status: Accepted

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

M=int(input())
for i in range(M):
    score[input()]-=1
    
print(max(0,max(score.values())))

Submission status: Accepted

Solution code:
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:
N=int(input())
A=[]
for i in range(N):
  A.append(input())

K=int(input())
for i in range(K):
  s=input()
  if (str(s) in A)==1:
    A.remove(s)
B=set(A)
ans=0
for i in B:
  if A.count(i)>ans:
    ans=A.count(i)
print(ans)

Submission status: Accepted

Solution code:
def BlueCardsCnt(cards, n):
    for i in range(n):
        s = input()
        cards.setdefault(s, 0)
        cards[s] += 1
    return cards

def RedCardsCnt(cards, m):
    for i in range(m):
        s = input()
        cards.setdefault(s, 0)
        cards[s] -= 1
    return cards

N = int(input())
cards = {}
cards = BlueCardsCnt(cards, N)
M = int(input())
cards = RedCardsCnt(cards, M)

max_v = max(cards.values())

if max_v <=0:
    print(0)
else :
    print(max_v)

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

list_all = list( set(blue) | set(red) )
dict_all = dict.fromkeys(list_all, 0)

for i in range(len(blue)) :
    dict_all[blue[i]] += 1

for i in range(len(red)) :
    dict_all[red[i]] -= 1

if max(dict_all.values()) >= 0 :
    print(max(dict_all.values()))
else :
    print(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 range(n):
  ans = max(ans, max(0, s.count(s[i]) - t.count(s[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)))))
#nの中の要素数からmの中の要素数を引いたものと0のうち大きい方を出力

Submission status: Accepted

Solution code:
n = int(input())
nl = [input() for _ in [0]*n]
m = int(input())
ml = [input() for _ in [0]*m]
xl = list(set(nl + ml))
x,y,z = 0,0,0
for i in range(len(xl)):
    x = nl.count(xl[i])
    y = ml.count(xl[i])
    z = max(z, (x-y))
print(z)

Submission status: Accepted

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


#----------
N = int(input().strip())
S_list = [input().strip() for _ in range(N)]

M = int(input().strip())
T_list = [input().strip() for _ in range(M)]
#----------
text_dic = {}

for word in S_list:
    if word not in text_dic:
        text_dic[word] = 1
    else:
        text_dic[word] += 1

for word in T_list:
    if word not in text_dic:
        text_dic[word] = -1
    else:
        text_dic[word] -= 1

result = max(text_dic.values())
if result < 0:
    result = 0

print(result)

Submission status: Accepted

Solution code:
import collections

n = int(input())
s = list(input() for i in range(n))
m = int(input())
t = list(input() for j in range(m))

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

s -= t
s = dict(s)

print(max(s.values()) if len(s) != 0 else 0)

Submission status: Accepted

Solution code:
from collections import defaultdict
blue, red = defaultdict(int), defaultdict(int)
n = int(input())
for _ in range(n):
    blue[input()] += 1
m = int(input())
for _ in range(m):
    red[input()] += 1
    
ans = []
for k in blue.keys():
    ans.append(max(0, blue[k]-red[k]))
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)]
L = list(set(S))
print(max(0,max(S.count(L[i])-T.count(L[i]) for i in range(len(L)))))

Submission status: Accepted

Solution code:
from collections import defaultdict

def main():
    N = int(input())
    blue_str_freq = defaultdict(int)
    for blue_str in [input() for _ in range(N)]:
        blue_str_freq[blue_str] += 1

    M = int(input())
    red_str_freq = defaultdict(int)
    for red_str in [input() for _ in range(M)]:
        red_str_freq[red_str] += 1

    max_val = 0
    for blue_str, blue_freq in blue_str_freq.items():
        if blue_freq - red_str_freq[blue_str] > max_val:
            max_val = blue_freq - red_str_freq[blue_str]
    print(max_val)

if __name__ == '__main__':
    main()

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

answer = max(d.values())
if answer < 0:
    answer = 0

print(answer)

Submission status: Accepted

Solution code:
n = int(input())
d = {}
for _ in range(n):
    s = input()
    if s not in d.keys():
        d[s] = 0
    d[s] += 1
m = int(input())
for _ in range(m):
    s = input()
    if s in d.keys():
        d[s] -= 1
d = sorted(d.items(), key=lambda x:x[1])
if d[-1][1] == - (m - 1) or (d[-1][1] < 0): print(0)
else: print(d[-1][1])

Submission status: Accepted

Solution code:
lst_blue = []
lst_red = []
dic = {}

N = int(input())
for i in range(0,N):
  lst_blue.append(input())
M = int(input())
for i in range(0,M):
  lst_red.append(input())

for i in list(set(lst_blue)):
  dic[i] = int(lst_blue.count(i))

for i in lst_red:
  if i in dic:
    dic[i] -= 1
    
print(max(0,max(dic.values())))

Submission status: Accepted

Solution code:
from collections import defaultdict

N = int(input())
S = defaultdict(int)
for n in range(N):
  key = input()
  S[key] += 1

  
M = int(input())
T = defaultdict(int)
for n in range(M):
  key = input()
  T[key] += 1

ans = 0
## 青いカードにカウントされているカードごとに計算する
for key in S:
  if key in T:
    _ = S[key] - T[key]
  else:
    _ = S[key]
  
  ans = max(ans,_)

print(ans)

Submission status: Accepted

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

lis = set(s)
ans = 0

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

Submission status: Accepted

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

N=int(input())
for i in range(N):
    s=input()
    dd[s]+=1
    
M=int(input())
for _ in range(M):
    t=input()
    dd[t]-=1
    
ans=0
for k,v in dd.items():
    ans=max(ans,v)
    
print(ans)

Submission status: Accepted

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

l=[]
for i in p:
  l.append(p.count(i)-m.count(i))
print(max(0,max(l)))

Submission status: Accepted

Solution code:
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(max(d.values()), 0))

Submission status: Accepted

Solution code:
n=int(input())
s=[input() for _ in range(n)]
m=int(input())
t=[input() for _ in range(m)]
ans=0
buf=0
s.sort()
t.sort()
for i in range(n):
    buf=0
    for j in range(i,n):
        if s[i]==s[j]:
            buf+=1
        elif s[i]<s[j]:
            break
    for j in range(m):
        if s[i]==t[j]:
            buf-=1
        elif s[i]<t[j]:
            break
    if buf>ans:
        ans=buf
print(ans)

Submission status: Accepted

Solution code:
S=[input() for _ in range(int(input()))]
T=[input() for _ in range(int(input()))]
ans=0
for i in S:
    tmp=S.count(i)-T.count(i)
    if tmp>ans:
        ans=tmp
print(ans)

Submission status: Accepted

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

for j in range(m):
  s = input()
  if s not in d2:
    d2[s] = 1
  else:
    d2[s] += 1
k1 = d1.keys()
k2 = d2.keys()
a = 0
temp = 0
for x in k1:
  if x not in k2:
    if a < d1[x]:
      a = d1[x]
  else:
    temp = d1[x] - d2[x]
    if a < temp:
      a = temp
print(a)

Submission status: Accepted

Solution code:
n = int(input())
A = []
for i in range(n):
    A.append(input())
m = int(input())
B =[]
for j in range(m):
    B.append(input())

C = []

for i in list(set(A)):
    C.append(A.count(i) - B.count(i))
print(max(max(C), 0))

Submission status: Accepted

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

count = 0
ans = 0

for k in set(A):
    count = A.count(k)-B.count(k)
    if count >= 0 and ans <= count:
        ans = count

print(ans)