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

# a, b =map(int,input().split())
a = list()
d = {}
for i in range(n):
    val = input()
    d[val] = d.get(val, 0)+1
k = int(input())
b = list()
for i in range(k):
    val = input()
    d[val] = d.get(val, 0)-1

val_sorted = sorted(d.items(), key=lambda x: x[1], reverse=True)
for i in val_sorted:
    if int(i[1]) < 0:
        print(0)
        break
    print(i[1])
    break

Submission status: Accepted

Solution code:
def l(): return [input() for _ in range(int(input()))]
p, m = l(), l()
c = 0
for s in set(p):
    c = max(p.count(s) - m.count(s), c)
print(c)

Submission status: Accepted

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

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

w=list(set(s))
a=[0]
for i in range(len(w)):
    a.append(s.count(w[i])-t.count(w[i]))

print(max(a))

Submission status: Accepted

Solution code:
def L(P,K,x):
  for i in range(K):
    t = input()
    try:
      P[t]+=1*x
    except:
      P[t]=1*x
  return P

P = {"":0}

N = int(input())
P = L(P,N,1)
M = int(input())
P = L(P,M,-1)
print(max(P.values()))

Submission status: Accepted

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import Counter
from pprint import pprint

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

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col):
    data.sort(key=lambda x:x[col],reverse=False)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

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

sc = Counter(s)
sck = list(sc.keys())
scv = list(sc.values())
# print(sc,sck,scv)
tc = Counter(t)
tck = list(tc.keys())
tcv = list(tc.values())
# print(tc,tck,tcv)

ans = 0
for i in range(len(sc)):
    w = sck[i]
    p = scv[i]
    # print(w,p)
    p2 = tc[w]
    # print(p2)
    M = p - p2
    ans = max(ans,M)
print(ans)

Submission status: Accepted

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
sc = []
for i in range(n):
    sc.append(input())
ob = set(sc)
m = ii()
disc = []
for i in range(m):
    disc.append(input())

score = 0
for i in ob:
    score = max(score,sc.count(i)-disc.count(i))
print(score)

Submission status: Accepted

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

s_count, t_count = [0]*len(l), [0]*len(l)
for i in range(N):
    s_count[l.index(s[i])] += 1
for i in range(M):
    t_count[l.index(t[i])] += 1

ans_l = [0]
for i in range(len(l)):
    ans_l.append(s_count[i] - t_count[i])

print(max(ans_l))

Submission status: Accepted

Solution code:
import sys

def resolve():
    N = int(input())
    words = {"___": 0}
    for i in range(N):
        s = input()
        if s not in words:
            words[s] = 1
        else:
            words[s] += 1
    M = int(input())
    for i in range(M):
        t = input()
        if t not in words:
            words[t] = -1
        else:
            words[t] += -1
    print(max(words.values()))
    

if '__main__' == __name__:
    resolve()

Submission status: Accepted

Solution code:
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


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

    N = ii()
    B = [iss() for _ in range(N)]
    M = ii()
    R = [iss() for _ in range(M)]
    ret = 0
    for b in B:
        ret = max(ret, B.count(b) - R.count(b))

    print(ret)


if __name__ == '__main__':
    main()

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

say = set(s)

#print(say)

M = 0
for saying in say:
    M = max(M, s.count(saying) - t.count(saying))
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)]
ans = 0
for word in set(s):
    cnt = s.count(word) - t.count(word)
    ans = max(ans, cnt)
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 s in S:
  ans = max(ans, S.count(s) - T.count(s))
print(ans)

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)]
a = set(blue)
ans = []
for i in a:
  b = 0
  for j in range(n):
    if blue[j] == i:
      b += 1
  for j in range(m):
    if red[j] == i:
      b -= 1
  ans.append(b)
print(max(0, max(ans)))

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

Solution code:
N = int(input())
ls1 = []
ls2 = []
ls3 = []
ans = []
for i in range(N):
    s = input()
    ls1.append(s)
    ls3.append(s)
M = int(input())
for j in range(M):
    t = input()
    ls2.append(t)
    ls3.append(t)
k = set(ls3)
p = list(k)
for i in range(len(p)):
    ans.append(ls1.count(p[i])-ls2.count(p[i]))
print(max(0,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) ]
print( max( 0, max([ s.count(i)-t.count(i) for i in set(s) ]) ) )

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(300000)
from collections import defaultdict

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')

N = I()
S = [input() for _ in range(N)]
M = I()
T = [input() for _ in range(M)]

d = defaultdict(int)
for s in S:
    d[s] += 1
for t in T:
    d[t] = max(0, d[t] - 1)

print(max(d.values()))

Submission status: Accepted

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

Submission status: Accepted

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

m = int(input())
blue =[]
for i in range(m):
  l = str(input())
  blue.append(l)
  
import collections

cr = collections.Counter(red)
crs = list(cr.most_common())
cb = collections.Counter(blue)
cbs = list(cb.most_common())

result =[]

for i in range(len(cbs)):
  for j in range(len(crs)):
    if cbs[i][0]==crs[j][0]:
      result.append(crs[j][1]-cbs[i][1])
    else:
      flag = False
      count = 0
      for k in range(len(cbs)):
        if cbs[k].count(crs[j][0]) == 0:
          count+=1
      if count == len(cbs):
        result.append(crs[j][1])
        flag = False
        count = 0

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

Submission status: Accepted

Solution code:
n=int(input())
syugo=set()
S,T=[],[]
ans=0
for i in range(n):
    s=input()
    S.append(s)
    syugo.add(s)
m=int(input())
for i in range(m):
    t=input()
    T.append(t)
    syugo.add(t)
syugo=list(syugo) #リスト型に直す
syugo.append("0")
for i in range(len(syugo)):
    sin=S.count(syugo[i])
    tin=T.count(syugo[i])
    if ans<sin-tin:
        ans=sin-tin
print(ans)

Submission status: Accepted

Solution code:
a=int(input())
b=[input() for i in range(a)]
c=int(input())
d=[input() for i in range(c)]
 
yen=0
for i in set(b):
    num=b.count(i)
    num2=d.count(i)
    yen=max(yen,num-num2)
print(yen)

Submission status: Accepted

Solution code:

import math
#import itertools
#import statistics
#import numpy as np
import collections
n = int(input())
#a = list(map(int, input().split()))
#a = list(map(int, input().split()))
s = []
for i in range(n):
    s.append(input())
m = int(input())
t = []
for j in range(m):
    t.append(input())

s2 = collections.Counter(s)
t2 = collections.Counter(t)
point = 0
ans  = 0
#print(s2)
#print(t2)
for i in s2.keys():
    for j in t2.keys():
        if i==j:
            point = s2.get(i)-t2.get(j)
            #print(i+j+""+str(point))
            break
        else:
            point = s2.get(i)
    #print(point)
    if ans < point:
        ans = point

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)]
st=s+t
u=set(s+t)
ans=0
for i in u:
  count=0
  for j in range(n+m):
    if i==st[j]:
      count+=1 if j<=n-1 else (-1)
  ans=max(ans,count)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
N_lis = []
for n in range(N):
  N_lis.append(input())
  
M = int(input())
M_lis = []
for m in range(M):
  M_lis.append(input())
  
ans = 0
for n in N_lis:
  x = N_lis.count(n) - M_lis.count(n)
  if x > ans:
    ans = x
print(ans)

Submission status: Accepted

Solution code:
import collections

n = int(input())
tmp = []
for _ in range(n):
    tmp.append(str(input()))
p = collections.Counter(tmp)
m = int(input())
for _ in range(m):
    p[str(input())]-=1

print(max(0, p.most_common()[0][1]))

Submission status: Accepted

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

for w in s:
  diff = s.count(w) - t.count(w)
  if diff > ans:
    ans = diff

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=[""]*n
for i in range(n):
  s[i]=input()
m=int(input())  
t=[""]*m
for j in range(m):
  t[j]=input()
C=[0]
 
for i in range(n):
  p=s[i]
  c=s.count(str(s[i]))-t.count(str(s[i]))
  C.append(c)
  
print(max(C))

Submission status: Accepted

Solution code:
ans = -101

N = int(input())
N_list = []
for _ in range(N):
    N_list.append(input())

M = int(input())
M_list = []
for _ in range(M):
    M_list.append(input())

MN_list = N_list[:]
MN_list.extend(M_list)
MN_list = set(MN_list)

for word in MN_list:
    word_point = 0
    for item in N_list:
        if word == item:
            word_point += 1
    for item in M_list:
        if word == item:
            word_point -= 1
    ans = max(ans, word_point)

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

Submission status: Accepted

Solution code:
n = int(input())
list_S = [input() for _ in range(n)]
m = int(input())
list_T = [input() for _ in range(m)]
ans = 0
set_S = list(set(list_S))
for c in set_S:
    if list_S.count(c)-list_T.count(c)>0:
       ans =  max(ans, list_S.count(c)-list_T.count(c))

print(ans)

Submission status: Accepted

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

ss = collections.Counter(s)
tt = collections.Counter(t)
ans = 0
for i in ss:
    sub = ss[i]
    if i in tt:
        sub -= tt[i]
    ans = max(ans, sub)
    
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

cnt = defaultdict(int)

for m in range(2):
    n = int(input())
    for i in range(n):
        s = input()
        if m == 0:
            cnt[s] += 1
        else:
            cnt[s] -= 1

print(max(max(cnt.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
s_count = 0
t_count = 0

for i in set(s):
    s_count = 0
    t_count = 0
    for j in s:
        if j == i:
            s_count += 1
    for k in t:
        if k == i:
            t_count +=1
    
    ans = max(ans, s_count - t_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)]
A = [0]
for j in s:
  A.append(s.count(j) - t.count(j))
print(max(A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = int(input())
al = []
for i in range(a):
  al.append(input())
b = int(input())
bl = []
for i in range(b):
  bl.append(input())
aa = list(set(al))
c =[]
for i in range(len(aa)):
  c.append(al.count(aa[i])-bl.count(aa[i]))
print(max(max(c),0))

Submission status: Accepted

Solution code:
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
 
def main():
  n = int(input())
  s = [input() for _ in range(n)]
  m = int(input())
  t = [input() for _ in range(m)]
  
  Nya = list(set(s))
  #print(Nya)
  Ma = 0
  for i in range(len(Nya)):
    Fi = s.count(Nya[i])
    Se = t.count(Nya[i])
    Ma = max(Ma,Fi-Se)
  print(Ma)
    
    
    
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
n = int(input())
slis = []
for i in range(n):
    slis.append(input())
m = int(input())
tlis = []
for i in range(m):
    tlis.append(input())
x = 0
for i in set(slis):
    ok = slis.count(i)
    ng = tlis.count(i)
    x = max(x, ok-ng)
print(x)

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())
  
s = set(blue)

maxnum = 0
for item in s:
  cnt = blue.count(item) - red.count(item)
  if cnt > maxnum:
    maxnum = cnt

print(maxnum)

Submission status: Accepted

Solution code:
import copy
import collections

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

l = copy.copy(s)
for i in range(n):
  if l[i] in t:
    s.remove(l[i])
    t.remove(l[i])

if not s:
  print(0)
else:
  num = collections.Counter(s)
  print(max(num.values()))

Submission status: Accepted

Solution code:
from  collections import  Counter
list1 = []
list2 = []

n1 = int(input())
for i in range(n1):
  list1.append(input())
n2= int(input())
for i in range(n2):
  list2.append(input())

set_list1 = set(list1)
Counter_list1  = Counter(list1)
set_list2 = set(list2)
Counter_list2 = Counter(list2)

ans = 0
for i in set_list1:
  dummy = Counter_list1[i] - Counter_list2[i]
  ans = max(ans,dummy)
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
m = {}
for i in range(N):
  s = input()
  if s in m:
    m[s] += 1
  else:
    m[s] = 1
M=int(input())
for i in range(M):
  t = input()
  if t in m:
    m[t] -= 1
  else:
    m[t] = -1
ans = 0
for k,v in m.items():
  ans = max( ans, 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 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)]
m=int(input())
t = [input() for _ in range(m)]

def list_difference(s,t):
    l = s.copy()
    for value in t:
        if value in l:
            l.remove(value)
    return l
l=list_difference(s,t)
l1=Counter(l)
if len(l)>0:print(l1.most_common()[0][1])
else:print(0)

Submission status: Accepted

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

for i in range(m):
    t = input()
    if t in s:
        s.remove(t)

c = collections.Counter(s)
c = list(c.most_common())
if c:
    print(c[0][1])
else:
    print(0)

Submission status: Accepted

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

M = int(input())
for _ in range(M):
    t = input()
    if t not in D: D[t]=0
    D[t] -= 1

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

Submission status: Accepted

Solution code:
import collections
n = int(input())
arr = []
for i in range(n):
  arr.append(input())
m = int(input())
for i in range(m):
  s = input()
  if s in arr:
    arr.remove(s)
if len(arr) == 0:
  print(0)
else:
  arr = collections.Counter(arr)
  print(arr.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)]
s2=dict()
t2=dict()
for i in range(n):
    if s[i] in s2:
        s2[s[i]]+=1
    else:
        s2[s[i]]=1
        t2[s[i]]=0
for i in range(m):
    if t[i] in t2:
        t2[t[i]]+=1
    else:
        t2[t[i]]=1
ans=0
for i in s2:
    ans=max(s2[i]-t2[i],ans)
print(ans)

Submission status: Accepted

Solution code:

def main():
    n, nn, nnn = map(int, input().split(' '))
    print('Yes' if n + nn >= nnn else 'No')


def main_b():
    t = int(input())
    ad = [input() for i in range(t)]
    t = int(input())
    mo = [input() for i in range(t)]

    from collections import Counter
    ad = dict(Counter(ad))
    mo = dict(Counter(mo))
    ans = 0
    for a in ad:
        tmp = ad.get(a, 0) - mo.get(a, 0)
        if ans < tmp:
            ans = tmp
    print(ans)
if __name__ == '__main__':
    main_b()

Submission status: Accepted

Solution code:

def main():
    n, nn, nnn = map(int, input().split(' '))
    print('Yes' if n + nn >= nnn else 'No')


def main_b():
    ad = {}
    mo = {}
    t = int(input())
    for i in range(t):
        c = input()
        ad.setdefault(c, 0)
        ad[c] += 1
    t = int(input())
    for i in range(t):
        c = input()
        mo.setdefault(c, 0)
        mo[c] += 1
    ans = 0
    for a in ad:
        tmp = ad.get(a, 0) - mo.get(a, 0)
        if ans < tmp:
            ans = tmp
    print(ans)
if __name__ == '__main__':
    main_b()

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()
ans = 0
w = s[0]
c = 0
for i in s:
    if i == w:
        c += 1
    else:
        for j in t:
            if j == w:
                c -= 1
        if ans < c:
            ans = c
        c = 1
        w = i
for i in t:
    if i == w:
        c -= 1
if ans < c:
    ans = c
print(ans)

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

from collections import Counter
sd=dict(Counter(s))
td=dict(Counter(t))
ans=0
for x in sd:
    y=sd.get(x,0)-td.get(x,0)
    ans=max(y,ans)
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)]

ls = []
ls.extend(s)
ls.extend(t)

ls = set(ls)
d = {l:0 for l in ls}

for sn in s:
    d[sn] += 1
for tn in t:
    d[tn] -= 1
# print(d)
d = sorted(d.items(),key = lambda x:x[1],reverse = True)
if d[0][1] > 0:
    print(d[0][1])
else:
    print(0)

Submission status: Accepted

Solution code:
from collections import defaultdict


def main():

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

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

    words['len(word)>10'] = 0
    print(max(words.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)]

cs = Counter(s)
ct = Counter(t)
ans = 0
for k, v in cs.items():
    if k in ct.keys():
        ans = max(ans, v-ct[k])
    else:
        ans = max(ans, v)

print(ans)

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)]
T = [""] * n
ans = 0

for i in range(n):
    if A[i] not in T:
        T[i] = A[i]
        ans = max(ans, A.count(A[i]) - B.count(A[i]), 0)

print(ans)

Submission status: Accepted

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

m = int(input())
dict_t = {}
for i in range(m):
    t = input()
    dict_t[t] = dict_t.get(t, 0) + 1

ans = 0
for k, v in dict_s.items():
    add = v
    add -= dict_t.get(k, 0)
    ans = max(ans, add)

print(ans)

Submission status: Accepted

Solution code:
#どっちで出すか注意, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    N = int(input())
    a = []
    for _ in range(N):
        a.append(input().rstrip())
    M = int(input())
    b = []
    for _ in range(M):
        b.append(input().rstrip())
    s = set(a)
    res = 0
    for i in s:
        res = max(res, a.count(i)-b.count(i))
    print(res)

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

cnt = 0
for x in s:
    cnt = max(s.count(x) - t.count(x), cnt)
print(cnt)

Submission status: Accepted

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

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

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

for i in x:
    t = x[i] - y[i]
    ans = max(t, ans)

print(ans)

Submission status: Accepted

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

cnt = 0
for s in si:
  cnt = max(si.count(s)-ti.count(s), cnt)
print(cnt)

Submission status: Accepted

Solution code:
#abc091_b
import collections
N = int(input())
S = [input() for i in range(N)]
M = int(input())
T = [input() for i in range(M)]
S_c = collections.Counter(S)
T_c = collections.Counter(T)
ans = 0

for s_word,s_count in S_c.items():
    if ans < s_count-T_c[s_word]:
        ans = s_count-T_c[s_word]

print(max(ans,0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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()))
all_card = []
card_point = []
for i in range(n):
    if s[i] in all_card:
        card_point[all_card.index(s[i])] += 1
    else:
        all_card.append(s[i])
        card_point.append(1)

for i in range(m):
    if t[i] in all_card:
        card_point[all_card.index(t[i])] -= 1
    else:
        all_card.append(t[i])
        card_point.append(-1)

print(max(0,max(card_point)))

Submission status: Accepted

Solution code:
key = dict()

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

m = int(input())

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

sub = []
for i in key.values():
  sub.append(i)
print(max([max(sub), 0]))

Submission status: Accepted

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

from collections import Counter
sc = Counter(s)
tc = Counter(t)
s_keys, s_values = zip(*sc.most_common())
t_keys, t_values = zip(*tc.most_common())
ans = 0
for i in range(len(s_values)):
  for j in range(len(t_values)):
    minus = 0
    if s_keys[i] == t_keys[j]:
      minus = t_values[j]
      ans = max(ans, s_values[i] - minus)
    if s_keys[i] not in t_keys:
      ans = max(ans, s_values[i])
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())

ans=0
for w in s:
    now=0
    for blue in s:
        if w==blue:
            now+=1

    for red in t:
        if w==red:
            now-=1
    ans=max(ans,now)
print(ans)

Submission status: Accepted

Solution code:
s = []
t = []
N = int(input())
for _ in range(N):
    s.append(input())
M = int(input())
for _ in range(M):
    t.append(input())
s_set = set(s)
s_list = list(s_set)
c = []
count = 0
for i in range(len(s_list)):
    for j in range(len(s)):
        if s_list[i] == s[j]:
            count += 1
    for k in range(len(t)):
        if s_list[i] == t[k]:
            count -= 1
    c.append(count)
    count = 0
ans = max(c)
if ans > 0:
    print(ans)
else:
    print(0)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
list_s = list(input() for i in range(n))
m = int(input())
list_t = list(input() for i in range(m))
count =0
set_s =list(set(list_s))
for i in set_s:
  count = max(count,list_s.count(i)-list_t.count(i))
print(count)

Submission status: Accepted

Solution code:
n=int(input())
from collections import Counter
cc=Counter()
for _ in range(n):
    cc[input()]+=1
m=int(input())
ans=0
for _ in range(m):
    x=input()
    if cc[x]==0:
        continue
    else:
        cc[x]-=1
for i in cc:
    ans=max(ans,cc[i])
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())
s=[0]*N

for i in range(N):
    s[i]=input()
M=int(input())
t=[0]*M
for j in range(M):
    t[j]=input()

c=dict(Counter(s))
d=dict(Counter(t))
maxi=0
#print(c)
#print(d)

for item in c:
    if item in d:
        tmp = c[item]-d[item]
    else:
        tmp = c[item]
    maxi=max(maxi, tmp)
   
print(maxi)

Submission status: Accepted

Solution code:
def card_count(n):
    card_dict={}
    for i in range(n):
        s = input()
        card_dict.setdefault(s,0)
        card_dict[s]+=1
    return card_dict        

N=int(input())
blue=card_count(N)
M=int(input())
red=card_count(M)
for k,v in blue.items():
    v-=red.get(k,0)
    if v<0:
        v=0
    blue[k]=v
print(max(blue.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)]

import collections 
CS = collections.Counter(S)
CT = collections.Counter(T)

ans = 0

sS = set(S)

for i in sS:
    x = CS[i]
    if i in T:
        x -= CT[i]
    ans = max(ans,x)
    
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
from collections import Counter
a=[input()for i in range(n)]
ca=Counter(a)
m=int(input())
b=[input()for i in range(m)]
cb=Counter(b)

ans=0
for i in a:
    tmp=ca[i]-cb[i]
    ans=max(ans,tmp)
print(max(ans,0))

Submission status: Accepted

Solution code:
# デバッグ用
GBN_DEBUG = False
GBN_DEBUG = True
def dprn(s, i):
    if GBN_DEBUG: print(", " + s + " = " + str(i), end = "")
def dprns(s):
    if GBN_DEBUG: print(", " + s, end = "")
def dprni(i):
    if GBN_DEBUG: print(i, end=" ")
def endl(): 
    if GBN_DEBUG: print('')
def puts(s): print(s)

#本体ここから

#S = input()
N = int(input())
#S, T = input().split()
#N, M = map(int, input().split())
s = [input() for _ in range(N)]
#A = list(map(int, input().split()))

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

blueSet = set(s) # 青いカードに書かれてる文字の種類
numBlueWord = len(blueSet) # 青いカードに書かれてる文字の種類の数
ans = 0
for i in range(numBlueWord):
    blueWord = blueSet.pop() # setは[]が使えないのね。。。pop()で取り出し
                             # N, M < 100 だし、こんな事をするより
                             # 重複承知で読み込んだリストをそのまま使うほうが
                             # 提出までの時間は早かったりして。
    #print(popBlueWord)
    earn = s.count(blueWord) # blueWord が書かれてる青いカードの枚数
    loss = t.count(blueWord) # blueWord が書かれてる赤いカードの枚数
    ans = max(ans, earn - loss)

print(ans)