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=[]
for i in range(n):
    blue.append(input())
m=int(input())
red=[]
for i in range(m):
    red.append(input())
max=0
for i in blue:
    b=blue.count(i)
    r=red.count(i)
    if b-r>max:max=b-r
print(max)

Submission status: Accepted

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

Submission status: Accepted

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

cnt = [0]
for i in range(len(s)):
    cnt.append(s.count(s[i]))
print(max(cnt))

Submission status: Accepted

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

red = {}
for i in T:
    if i not in red:
        red[i] = 1
    else:
        red[i] += 1

blue = {}
for i in S:
    if i not in blue:
        blue[i] = 1
    else:
        blue[i] += 1

res = 0
for i in set(S):
    if i not in red:
        tmp = blue[i]
    else:
        tmp = blue[i] - red[i]

    if res < tmp:
        res = tmp

print(res)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc091/tasks/abc091_b
import collections
b = []
n = int(input())
for _ in range(n):
    b.append(input())
bc = collections.Counter(b)
r = []
n = int(input())
for _ in range(n):
    r.append(input())
rc = collections.Counter(r)
c = [0]
for bv in bc.keys():
    c.append(bc[bv] - rc[bv])
print(max(c))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Mar  2 22:51:25 2019

@author: yuta
"""
from collections import Counter
#入力
N = int(input())
S = [input() for i in range(N)]
M = int(input())
T = [input() for j in range(M)]

def main(s,t):
    count_blue = Counter(s)
    count_red = Counter(t)
    all_str = list(set(s+t))
    count_max = 0
    for i in all_str:
        count_i = count_blue[i] - count_red[i]
        if count_i >= count_max:
            count_max = count_i
    print(count_max)

main(S,T)

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 si in set(s):
    res = max(res, s.count(si) - t.count(si))
print(res)

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)]
ans=0
for ai in set(a):
  n=a.count(ai)-b.count(ai)
  if n>ans:
    ans=n
print(ans)

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)])
n = 0
for s, s_c in S.items():
    t_c = 0 if s not in T else T[s]
    n = max(n, s_c - t_c)
print(n)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import collections

N = int(input())

blue_card = []
red_card = []
ans = 0
for i in range(N):
    blue_card.append(input())

M = int(input())

for i in range(M):
    red_card.append(input())
    
blue = collections.Counter(blue_card)
red = collections.Counter(red_card)

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

Submission status: Accepted

Solution code:
def main():
	n = int(input())
	lst = {}
	for _ in range(n):
		temp = input()
		if temp in lst:
			lst[temp] = lst[temp]+1
		else:
			lst[temp] = 1
	m = int(input())
	for _ in range(m):
		temp = input()
		if temp in lst:
			lst[temp] = lst[temp] - 1
	ans = 0
	for i in lst:
		ans = max(lst[i], ans)
	print(ans)

main()

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)
count = []
cnt = 0
for i in u:
    count.append(s.count(i))
    count[cnt] -= t.count(i)
    cnt += 1
res = max(count)
if res <= 0:
    print(0)
else:
    print(res)

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]
ds = {}
dt = {}
for word in s:
    if word not in ds:
        ds[word] = 1
    else:
        ds[word] += 1
for word in t:
    if word not in dt:
        dt[word] = 1
    else:
        dt[word] += 1
ret = 0
for word, count in ds.items():
    if word not in dt:
        tcount = 0
    else:
        tcount = dt[word]
    ret = max(ret, count - tcount)
print(ret)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    s = [input() for _ in range(N)]
    M = int(input())
    t = [input() for _ in range(M)]
    ans = 0
    for ss in s:
        ans = max(ans, s.count(ss) - t.count(ss))
    print(ans)


main()

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)]
d1, d2 = {}, {}
for i in s:
    d1.setdefault(i, 0)
    if i in d1:
        d1[i] += 1
for i in t:
    d2.setdefault(i, 0)
    if i in d2:
        d2[i] += 1
bucket = [d1[i]-d2[i] if i in d2 else d1[i] for i in d1]
ans = max(bucket)
if ans > 0:
    print(ans)
else:
    print(0)

Submission status: Accepted

Solution code:
import collections
n=int(input())
s=[str(input()) for i in range(n)]
m=int(input())
t=[str(input()) for i in range(m)]
s_s=set(s)
t_s=set(t)
#import pdb;pdb.set_trace()
s_c=collections.Counter(s)
t_c=collections.Counter(t)
a_l=[]
for i in s_c.keys():
    a_l.append(s_c[i]-t_c[i])
if max(a_l)>0:
    ans=max(a_l)
else:
    ans=0
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    s_dict = {}
    for i in range(N):
        inp = input()
        if inp not in s_dict.keys():
            s_dict[inp] = 1
        else:
            s_dict[inp] += 1
    M = int(input())
    t_dict = {}
    for i in range(M):
        inp = input()
        if inp not in t_dict.keys():
            t_dict[inp] = 1
        else:
            t_dict[inp] += 1
    ans = 0
    for word in s_dict.keys():
        blue = s_dict[word]
        red = t_dict[word] if word in t_dict.keys() else 0
        get = blue - red
        if get > ans:
            ans = get
    print(ans)


if __name__ == "__main__":
    main()

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

print(ans)

Submission status: Accepted

Solution code:
A = {}

N = input()
for i in range(N):
  s = raw_input()
  if s not in A:
    A[s] = 0
  A[s] += 1
M = input()
for i in range(M):
  t = raw_input()
  if t not in A:
    A[t] = 0
  else:
    A[t] -= 1
print max(A.values()+[0])

Submission status: Accepted

Solution code:
n=int(input())
s=[]
for x in range(n):
    s.append(input())
m=int(input())
t=[]
for y in range(m):
    t.append(input())
q=0
for i in range(n):
    v=s[i]
    c=0
    for k in range(i,n):
        if v==s[k]:
            c+=1
    for j in range(m):
        if v==t[j]:
            c-=1
    if c>q:
        q=c
print(q)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n=int(input())
a={}
for i in range(0,n):
  s=input()
  if s in a.keys():
    a[s]=a[s]+1
  else:
    a[s]=1
m=int(input())
for i in range(0,m):
  t=input()
  if t in a.keys():
    a[t]=a[t]-1
r=0
for k in a.keys():
  r=max(r,a[k])
print(r)

Submission status: Accepted

Solution code:
# B
n = int(input()) 
s = [str(input()) for i in range(n)] 
m = int(input()) 
t = [str(input()) for i in range(m)]
ans = []
for string in list(set(s)):
    ans.append(s.count(string) - t.count(string))
if max(ans) < 0:
    print(0)
else:
    print(max(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 s in S:
  score = 0
  for s2 in S:
    if s == s2:
      score += 1
  for t in T:
    if s == t:
      score -= 1
  ans = max(ans, score)

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)]
money = s.count(s[0]) - t.count(s[0])
for i in set(s):
    if money < s.count(i) - t.count(i):
        money = s.count(i) - t.count(i)
print(money) if money >= 1 else print(0)

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

Submission status: Accepted

Solution code:
n,*s=open(0).readlines();print(max(0,*[s.count(i)-s[int(n):].count(i)*2for i in s]))

Submission status: Accepted

Solution code:
n,*s=open(0).readlines();n=int(n);print(max(0,*[s.count(i)-s[n:].count(i)*2for i in s]))

Submission status: Accepted

Solution code:
n,*s=open(0).readlines();n=int(n);print(max(0,*[s[:n].count(i)-s[n:].count(i)for i in s]))

Submission status: Accepted

Solution code:
n,*s=open(0).readlines();n=int(n);print(max(0,*[s[:n].count(i)-s[n:].count(i)for i in s[:n]]))

Submission status: Accepted

Solution code:
n,*s=open(0).read().split();n=int(n);print(max(0,*[s[:n].count(i)-s[n:].count(i)for i in s[:n]]))

Submission status: Accepted

Solution code:
I=lambda:[input()for _ in[0]*int(input())];s=I();t=I();print(max(0,*[s.count(i)-t.count(i)for i in s]))

Submission status: Accepted

Solution code:
I=lambda:[input()for _ in[0]*int(input())];s=I();t=I();print(max(0,*[s.count(i)-t.count(i)for i in set(s)]))

Submission status: Accepted

Solution code:
I=lambda:[input()for _ in[0]*int(input())];s=I();t=I();print(max([0]+[s.count(i)-t.count(i)for i in set(s)]))

Submission status: Accepted

Solution code:
from collections import*;n,*a=open(0).read().split()
print(max(0,max(v-Counter(a[int(n)+1:])[k] for k,v in Counter(a[0:int(n)]).items())))

Submission status: Accepted

Solution code:
from collections import*
n,*a=open(0).read().split()
blue=a[0:int(n)]
red=a[int(n)+1:]
print(max(0,max(v-Counter(red)[k] for k,v in Counter(blue).items())))

Submission status: Accepted

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

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

res=0
for i in range(n):
    x=S.count(S[i])
    y=T.count(S[i])
    if x-y>res:
        res=x-y
for j in range(m):
    x=S.count(T[j])
    y=T.count(T[j])
    if x-y>res:
        res=x-y

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)]
cnt = {}
for word in s:
    if word in cnt: cnt[word] += 1
    else:cnt[word] = 1
for word2 in t:
    if word2 in cnt:cnt[word2] -= 1
    else : cnt[word2]= -1
ls = [v for k,v in cnt.items()]
if max(ls) <0 :print(0)
else:print(max(ls))

Submission status: Accepted

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

cnt = 0
for v in a.values():
    if v < 0:
        cnt += 1
        
if len(a) == cnt:
    print(0)
else:
    print(max(list(a.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)]
l = set(s+t)
ans = 0
for i in l:
  ans = max(s.count(i) - t.count(i), 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)]
l = set(s+t)
d = [s.count(i) - t.count(i) for i in l] + [0]
print(max(d))

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
blue_cards = [input() for i in range(n)]
m = int(input())
red_cards = [input() for i in range(m)]

blue_c = Counter(blue_cards)
red_c = Counter(red_cards)

score = 0
for k,v in blue_c.most_common():
    score = max(score, v - red_c[k])

print(score)

Submission status: Accepted

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

max_score = 0
for term in blue_cards:
    score = 0
    for card in blue_cards:
        if term == card:
            score +=1
    for card in red_cards:
        if term == card:
            score -=1
    if(max_score < score):
        max_score = score
if max_score < 0:
    max_score = 0

print(max_score)

Submission status: Accepted

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

dic = {}

for l in L:
    if l in dic:
        dic[l] += 1
    else:
        dic[l] = 1
        
for k in K:
    if k in dic:
        dic[k] -= 1
    else:
        dic[k] = -1

res = 0
for i in dic:
    res = max(res, dic[i])
    
print(res)

Submission status: Accepted

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

sss=list(set(ss))
nums = [0] * (len(sss)+1)
for i,s in enumerate(sss):
    nums[i]=ss.count(s) - tt.count(s)
print(max(nums))

Submission status: Accepted

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

tmp_S = {}
for s in S:
  if(s in tmp_S):
    tmp_S[s] += 1
  else:
    tmp_S[s] = 1
for t in T:
  if(t in tmp_S):
    tmp_S[t] -= 1
print(max(0, max(tmp_S.values())))

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

ans=0
for i in range(n):
    strtmp=s[i]
    anstmp=s.count(strtmp)-t.count(strtmp)
    if ans<anstmp:
        ans=anstmp

print(ans)

Submission status: Accepted

Solution code:
int_n = int(input())
blue_card_ar = [input() for i in range(int_n)]

int_m = int(input())
red_card_ar = [input() for i in range(int_m)]

result_ar = []
for x in blue_card_ar:
    result_ar.append(blue_card_ar.count(x) - red_card_ar.count(x))

print(max(result_ar) if max(result_ar) > 0 else 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)]
ans = 0
for s_ in set(s):
    ans = max(ans,s.count(s_)-t.count(s_))
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
st = set()
s = []

for i in range(N):
    tmp = input()
    st.add(tmp)
    s.append(tmp)

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

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

ans = -100
tmp = 0

for x in st:
    tmp = s.count(x)
    tmp -= t.count(x)
    ans = max(ans, tmp)

print(ans if 0 <= ans else 0)

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())
result=0
for i in range(N):
    if s[i] in t:
        ans=s.count(s[i])-t.count(s[i])
    else:
        ans=s.count(s[i])
    if ans>result:
        result=ans
print(result)

Submission status: Accepted

Solution code:
n = int(input())
blue = [input() for x in range(n)]
m = int(input())
red = [input() for x in range(m)]

points = []
for i in range(n):
    point = 0
    point += blue.count(blue[i])
    point -= red.count(blue[i])
    points.append(point)
print(max( max(points), 0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = []
number = []
for i in range(N):
    s = input()
    if s in S:
       number[S.index(s)] += 1
    else:
        number.append(1)
        S.append(s)
M = int(input())
for i in range(M):
    s = input()
    if s in S:
        number[S.index(s)] -= 1

print(max(max(number),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)]
a = 0
b = 0
c = []
for i in range(n):
    a = s.count(s[i])
    b = t.count(s[i])
    c.append(a-b)
if max(c) < 0:
    print(0)
else:
    print(max(c))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
s = []
for _ in [0]*N:
    s.append(input().rstrip())
M = int(input())
t = []
for _ in [0]*M:
    t.append(input().rstrip())

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
dc = {}
for i in range(n):
  s = input()
  if s in dc:
    dc[s] += 1
  else :
    dc[s] = 1
m = int(input())
for i in range(m):
  t = input()
  if t in dc:
    dc[t] -= 1
  else :
    dc[t] = -1
ans = 0
for i in dc:
  ans = max(ans, dc[i])
print(ans)

Submission status: Accepted

Solution code:
from statistics import mean, median,variance,stdev
import sys
import math
import fractions

def j(q):
    if q==1: print("YES")
    else:print("NO")
    exit(0)


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())

#n = ip()                              #入力整数1つ
#d,x= (int(i) for i in input().split())      #入力整数横2つ
#k,a,b = (int(i) for i in input().split())    #入力整数横3つ
#n,m,x,y= (int(i) for i in input().split())  #入力整数横4つ
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列

#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
x =ip()
a = []
for i in range(x):
    a.append(input())
y = ip()
b = []
for i in range(y):
    b.append(input())

c = list(set(a))
d = list(set(b))
m = [0]
for i in range(len(c)):
    m.append(a.count(c[i])-b.count(c[i]))
print(max(m))

Submission status: Accepted

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

counter = dict()
for i in s:
  counter[i] = counter.get(i, 0) + 1
for i in t:
  counter[i] = counter.get(i, 0) - 1

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

Submission status: Accepted

Solution code:
""" AtCoder """

import collections

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

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

ans = 0

for i in range(len(ss)):
    ans = max(ss.most_common()[i][1] - tt[ss.most_common()[i][0]], ans)

print(ans)

Submission status: Accepted

Solution code:
card = {}

N = int(input())

for i in range(N):
    s = input()
    card.setdefault(s, 0)
    card[s] += 1

M = int(input())

for i in range(M):
    t = input()
    card.setdefault(t, 0)
    card[t] -= 1

print(max(0, max(x for x in card.values())))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for _ in range(N)]
M = int(input())
T = [input() for _ in range(M)]
scorelists = []
for key in S:
    score = 0
    for tmp in S:
        if key == tmp:
            score += 1
    for tmp in T:
        if key == tmp:
            score -= 1
    scorelists.append(score)

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

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

money = 0
money_list = []
word_list = list(set(s+t))
for i in range(len(word_list)):
    sum = s.count(word_list[i])
    sum -= t.count(word_list[i])
    if sum < 0:
        sum = 0
    money_list.append(sum)

money_list.sort(reverse = True)
print(money_list[0])

Submission status: Accepted

Solution code:
n=int(input())
S=list(map(str,[input() for i in range(n)]))
m=int(input())
T=list(map(str,[input() for i in range(m)]))
A=[]
for i in range(n):
    score=S.count(S[i])-T.count(S[i])
    A.append(score)
ans=max(0,max(A))
print(ans)

Submission status: Accepted

Solution code:
def getNum(li, st):
    cnt = 0
    for l in li:
        if l == st:
            cnt += 1
    return cnt


n = int(input())
bc = []
for x in range(n):
    bc.append(input())

m = int(input())
rc = []
for x in range(m):
    rc.append(input())

bcu = list(set(bc))
rcu = list(set(rc))

brcu = list(set(bcu + rcu))

blist = {}
rlist = {}

for sentence in brcu:
    blist[sentence] = 0
    rlist[sentence] = 0

for srt in bcu:
    blist[srt] = getNum(bc, srt)

for srt in rcu:
    rlist[srt] = getNum(rc, srt)

# print(brcu)
# print(blist)
# print(rlist)

result = []

for sentence in brcu:
    result.append(blist[sentence] - rlist[sentence])

# print(result)
if max(result) < 0:
    print(0)
else:
    print(max(result))

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 s in S:
  if(s not in d):
    d[s] = 1
  else:
    d[s] += 1
for t in T:
  if(t in d):
    d[t] -= 1
print(max(max(d.values()), 0))

Submission status: Accepted

Solution code:
N=int(input())
s=[input() for i in range(N)]
M=int(input())
l=[input() for i in range(M)]
list_str=list(dict.fromkeys(s+l))
s_l=[]
for i in range(len(list_str)):
  s_l.append(s.count(list_str[i])-l.count(list_str[i]))
#print(all([i < 0 for i in s_l]))
if(all([i < 0 for i in s_l])):
  print(0)
else:print(max(s_l))

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)]
res = 0
for s in S:
    res = max(res, 0, S.count(s) - T.count(s))
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)]
tmp=[0]
for i in range(N):
    point=0
    point+=s.count(s[i])
    point-=t.count(s[i])
    tmp.append(point)
print(max(tmp))

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)]
tmp=[0]
point=0
for i in range(N):
    point+=s.count(s[i])
    if s[i] in t:
        point-=t.count(s[i])
    tmp.append(int(point))
    point=0 
print(max(tmp))

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
c = Counter([input() for _ in range(n)])
m = int(input())
d = Counter([input() for _ in range(m)])

ans = 0
for k in c.keys():
    ans = max(ans, c[k]-d.setdefault(k, 0))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = input()

S = [raw_input() for i in range(N)]

M = input()

T = [raw_input() for i in range(M)]

maximam = 0

for i in S:
    maximam = max(S.count(i)-T.count(i),maximam)

print maximam

Submission status: Accepted

Solution code:
N = input()

S = []
for i in range(N):
    S.append(raw_input())

M = input()

T = []
for i in range(M):
    T.append(raw_input())

maximam = 0

for i in S:
    maximam = max(S.count(i)-T.count(i),maximam)

print maximam

Submission status: Accepted

Solution code:
# ABC 091
def getInt(): return int(input())
def db(x): 
    global debug
    if debug: print(x)
debug = False
N = getInt()
S = []
for i in range(N): S.append(input())
M = getInt()
T = []
for i in range(M): T.append(input())
db((N,M))
db((S,T))
dic = {}
for w in S: 
    if w in dic: dic[w] += 1
    else: dic[w] = 1
for w in T: 
    if w in dic: dic[w] -= 1
    else: dic[w] = -1
db(dic)
db(dic.values())
db(list(dic.values()))

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

Submission status: Accepted

Solution code:
def count(counted, cards, is_blue):
    for word in cards:
        if not word in counted:
            counted[word] = 1 if is_blue else -1
        else:
            counted[word] += 1 * (1 if is_blue else -1)
    return counted


counted = {}
n = int(input())
counted = count(counted, [input() for _ in range(n)], True)
m = int(input())
counted = count(counted, [input() for _ in range(m)], False)
high_score = max(sorted(counted.items(), key=lambda x: x[1], reverse=True)[0][1], 0)
print(high_score)

Submission status: Accepted

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

m = int(input())
for word in [input() for _ in range(m)]:
    if not word in count:
        count[word] = -1
    else:
        count[word] -= 1

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

Submission status: Accepted

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

count = {}
for word in s:
    if not word in count:
        count[word] = 1
    else:
        count[word] += 1
for word in t:
    if not word in count:
        count[word] = -1
    else:
        count[word] -= 1

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

Submission status: Accepted

Solution code:
# n blue card
n = int(input())
s = [input() for _ in range(n)]

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

best = -200

for w in set(s + t):
    r = sum([1 for _ in s if _ == w]) - sum([1 for _ in t if _ == w])
    if r > best:
        best = r

if best < 0:
    best = 0
    
print(best)

Submission status: Accepted

Solution code:
a=int(input())
A=[]
for i in range(a):
  A.append(input())
m=int(input())
B=[]
for j in range(m):
  B.append(input())
ans=[]
for i in A:
  ans.append(A.count(i)-B.count(i))
print(max(0,max(ans)))

Submission status: Accepted

Solution code:
# encoding:utf-8

import numpy as np
import random

n = int(input())
s = []
t = []
for i in range(n):
    s_tem = str(input())
    s.append(s_tem)

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

count_dic = {}

for name in s:
    if name in count_dic.keys():
        count_dic[name] += 1
    else:
        count_dic[name] = 1
for name in t:
    if name in count_dic.keys():
        count_dic[name] -= 1
    else:
        count_dic[name] = -1

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

Submission status: Accepted

Solution code:
point = {}
for i in range(int(input())):
    name = input()
    if (name in point.keys()) == True:
        point[name] += 1
    else:
        point[name] = 1
for i in range(int(input())):
    name = input()
    if (name in point.keys()) == True:
        point[name] -= 1
    else:
        point[name] = -1
result = max(list(point.values()))
if result > 0:
    print(result)
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())

v = 0
ss = set(s)
for x in ss:
    tmp = s.count(x) - t.count(x)
    if tmp > v:
        v = tmp

print(v)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(100000)
dic={}
for i in range(int(input())):
    s=input()
    try:
        dic[s]+=1
    except:
        dic[s]=1
for i in range(int(input())):
    s=input()
    try:
        dic[s]-=1
    except:
        dic[s]=-1

print(max(list(dic.values())+[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)]

memo = {}
for i in range(n):
  if s[i] not in memo:
    memo[s[i]] = 1
  else:
    memo[s[i]] +=1

for i in range(m):
  if t[i] in memo:
    memo[t[i]] -=1

ans=0
for i in memo:
  ans = max(memo[i],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)]

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

ans = 0
for cs in CS:
    k,v = cs
    ans = max(ans, v-CT[k])

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
sss = [input() for _ in range(N)]
M = int(input())
tss = [input() for _ in range(M)]

cntS = Counter(sss)
cntT = Counter(tss)

ans = 0
for key in cntS.keys() | cntT.keys():
    num = 0
    if key in cntS:
        num += cntS[key]
    if key in cntT:
        num -= cntT[key]
    ans = max(ans, num)
print(ans)