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:
a = int(input())
b = list(input() for i in range(a))
c = int(input())
d = list(input() for i in range(c))
e = [0]

for s in b:
  e.append(b.count(s)-d.count(s))
else:
  print(max(e))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(blues, reds):
    blue_counts = {}
    red_counts = {}

    for b in blues:
        if b not in blue_counts:
            blue_counts[b] = 1
        else:
            blue_counts[b] += 1

    for r in reds:
        if r not in red_counts:
            red_counts[r] = 1
        else:
            red_counts[r] += 1

    max_count = 0
    for name, c in blue_counts.items():
        if name in red_counts:
            max_count = max(max_count, c - red_counts[name])
        else:
            max_count = max(max_count, c)
    return max_count


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    [N] = string_to_int(input())
    blues = inputs(N)
    [M] = string_to_int(input())
    reds = inputs(M)
    ret = solve(blues, reds)
    print(ret)

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)]
x=[]
s.sort()
t.sort()

for i in range(n):
    x.append(s.count(s[i])-t.count(s[i]))

print(max(max(x),0))

Submission status: Accepted

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

Submission status: Accepted

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

M = int(input())
for _ in range(M):
    s = input()
    if s in d:
        d[s] -= 1
    else:
        d[s] = -1

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
s = [input().split() for i in range(N)]
M = int(input())
t = [input().split() for i in range(M)]
s.sort()
t.sort()
count = 0
s_sub = []
j = 0
for i in range(M):
    for j in range(N):
        if t[i] == s[j]:
            s[j] = ["0"]
            break
for i in range(N):
    if s[i][0] != "0":
        s_sub.append(s[i][0])
ans = 0
for i in range(len(s_sub)):
    count = 0
    for j in range(len(s_sub)):
        if s_sub[i] == s_sub[j]:
            count += 1
    if ans < count:
        ans = count
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)]

dic = {}
for s in S:
    if s in dic.keys():
        dic[s] += 1
    else:
        dic[s] = 1
for t in T:
    if t in dic.keys():
        dic[t] -= 1
    else:
        dic[t] = -1

possible = dic.values()
print(max(possible) if max(possible) > 0 else 0)

Submission status: Accepted

Solution code:
N = int(input())
list_s = [input() for j in range(N)]
M = int(input())
list_t = [input() for i in range(M)]

###blue:N, red:M, blue:+1, red:-1
###差し引きマックス
###全部マイナスなら0

list = []

for s in list_s:
    list.append(list_s.count(s) - list_t.count(s))
if max(list)>=0:
    print(max(list))
else:
    print(0)

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for i in range(N)]
M = int(input())
T = [input() for i in range(M)]
 
Scores = []
for s in S:
  score = len([s2 for s2 in S if s == s2])
  score -= len([s2 for s2 in T if s == s2])
  Scores.append(score)
print(max(Scores) if max(Scores)>0 else 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 set(s + t):
    ans = max(s.count(i) - t.count(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)]

ans = 0
l = list(set(s))
for i in range(len(l)):
    ans = max(ans,  max(0, s.count(l[i]) - t.count(l[i])))
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)]
words = set(s+t)
ans = 0
for word in words:
    ansi = 0
    ansi += s.count(word)
    ansi -= t.count(word)
    ans = max(ans, ansi)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
lst_blue = [input() for i in range(n)]

m = int(input())
lst_red = [input() for i in range(m)]

ans = 0

for w in lst_blue:
    x = lst_blue.count(w)
    y = lst_red.count(w)
    num = x-y
    if num > ans:
        ans = num
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ao = [input() for _ in range(n)]
m = int(input())
aka = [input() for _ in range(m)]
str = set(ao + aka)
ans = 0
for i in str:
    temp = ao.count(i) - aka.count(i)
    ans = max(temp, ans, 0)
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
result={}
s=[]
t=[]
for i in range(N):
  s.append(input())
  if s[i] in result.keys():
    result[s[i]]+=1
  else:
    result[s[i]]=1
M=int(input())
for j in range(M):
  t.append(input())
  if t[j] in result.keys():
    result[t[j]]-=1
if max(result.values()) > 0:
  print(max(result.values()))
else:
  print(0)

Submission status: Accepted

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

ans = 0
for k, v in counters.items():
    if conutert.get(k):
        ans = max(v-conutert[k], ans)
    else:
        ans = max(v, ans)
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)]

c1 = Counter(s)
c2 = Counter(t)
ans = max(v - c2[i] for i, v in c1.most_common())
print(max(0, 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 i in range(M):
  t[i] = input()
  
p = {si: s.count(si) for si in set(s)}
for ti in t:
  if ti in p:
    p[ti] -= 1
print(max(max(p.values()), 0))

Submission status: Accepted

Solution code:
n=int(input())
blue=[]
red=[]

for i in range(n):
    blue.append(input())

m=int(input())

for j in range(m):
    red.append(input())

ans=[]

for b in blue:
    if blue.count(b)<=red.count(b):
        ans.append(0)

    else:
        ans.append((blue.count(b)-red.count(b)))
print(max(ans))

Submission status: Accepted

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


#重複削除
s_set = list(set(s))
t_set = list(set(t))


#sの中身を確認して数える
deff_max = 0
for i in s_set:
    s_cnt = s.count(i)
    t_cnt = t.count(i)
    
    deff = s_cnt - t_cnt
    
    if deff_max < deff:
        deff_max = deff

print(deff_max)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N = int(input())
    s_list = [str(input()) for i in range(N)]
    M = int(input())
    t_list = [str(input()) for i in range(M)]

    D = {}

    for s in s_list:
        if s in D.keys():
            D[s] = D[s] + 1
        else:
            D[s] = 1

    for t in t_list:
        if t in D.keys():
            D[t] = D[t] - 1
        else:
            D[t] = -1

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

Submission status: Accepted

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

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
d=dict()
for i in range(n):
  a=input()
  if a not in d:
    d[a]=1
  else:
    d[a]+=1
m=int(input())
for i in range(m):
  a=input()
  if a not in d:
    d[a]=-1
  else:
    d[a]-=1
dl=sorted(d.items(),key=lambda x:x[1],reverse=True)
print(max(dl[0][1],0))

Submission status: Accepted

Solution code:
import sys

def input():
    return sys.stdin.readline().rstrip()

if __name__ == "__main__":
    n = int(input())
    sl = [input() for i in range(n)]

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

    maxcount = 0
    for s in set(sl):
        count = sl.count(s) - tl.count(s)
        if count > maxcount:
            maxcount = count

    print(maxcount)

Submission status: Accepted

Solution code:
import sys

def input():
    return sys.stdin.readline().rstrip()

if __name__ == "__main__":
    n = int(input())
    sl = [input() for i in range(n)]

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

    maxcount = 0
    for s in set(sl+tl):
        count = sl.count(s) - tl.count(s)
        if count > maxcount:
            maxcount = count

    print(maxcount)

Submission status: Accepted

Solution code:
import collections

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

blue_cnter = collections.Counter(blue)
red_cnter = collections.Counter(red)

maxget = 0
for key, count in blue_cnter.items():
    # 青のkey基準で考える
    bluecount = count
    redcount = red_cnter.get(key, 0)
    maxget = max(maxget, bluecount-redcount)
print(maxget)

Submission status: Accepted

Solution code:
N = int(input())
S = []
for n in range(N):
  S.append(input())
M = int(input())
T = []
for m in range(M):
  T.append(input())

ST_set = list(set(S + T))
ans = 0
for i in ST_set:
  money = S.count(i) - T.count(i)
  if ans < money:
    ans = money
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

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

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

max_coin = 0

for k, v in S.items():
    coin = v - T[k]
    if coin > max_coin:
        max_coin = coin
for k, v in T.items():
    coin = S[k] - v
    if coin > max_coin:
        max_coin = coin

print(max_coin)

Submission status: Accepted

Solution code:
N = int(input())
A = []
ans = -100000000

for i in range(N):
    A.append(input())

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

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

for c in A:
    X = A.count(c) - B.count(c)
    ans = max(ans, X)

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

Submission status: Accepted

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

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

    ans = 0
    for k in blue.keys():
       ans = max(ans, blue.get(k) - red.get(k, 0))
    print(ans)


abc()

Submission status: Accepted

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

s2 = set(s)

ans = 0

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

print(max(ans, 0))

Submission status: Accepted

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


ans=[]
for i in range(len(a)):
  z=a.count(a[i])
  ans.append(z-b.count(a[i]))


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

Submission status: Accepted

Solution code:
dic = {}

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

sort_dic = sorted(dic.items(), key = lambda x:x[1], reverse = True)
print(sort_dic[0][1] if sort_dic[0][1] > 0 else 0)

Submission status: Accepted

Solution code:
from collections  import defaultdict
d = defaultdict(lambda :0)
N = int(input())
blues =[(input()) for _ in range(N)]

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

for blue in blues:
    d[blue] += 1
for red in reds:
    d[red] -= 1

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

Submission status: Accepted

Solution code:
N = int(input())
slist = []
for _ in range(N):
    slist.append(input())

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

slist_set = set(slist)
tlist_set = set(tlist)
all_set = list(slist_set | tlist_set)

anslist = []
for i in range(len(all_set)):
    ans = 0
    for j in range(N):
        if all_set[i] == slist[j]:
            ans += 1
    
    for j in range(M):
        if all_set[i] == tlist[j]:
            ans -= 1
    anslist.append(ans)
    
if max(anslist) < 0:
    print(0)
else:
    print(max(anslist))

Submission status: Accepted

Solution code:
from functools import reduce
import math
import collections
def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input())
    s = collections.defaultdict(int)
    for i in range(N):
        s[input()] += 1
    M = int(input())
    for i in range(M):
        s[input()] -= 1
    print(max(max(s.values()),0))
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 0
for k, v in dic.items():
  ans = max(ans, v)
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)]
word = set(S + T)
ans = 0

for w in word:
    amount = S.count(w) - T.count(w)
    ans = max(ans, amount)

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=[0]*n
for _ in range(n):
  s[_]=input()
sd={}
for _ in s:
  sd[_]=s.count(_)
m=int(input())
t=[0]*m
for _ in range(m):
  t[_]=input()
l=sd.keys()
for _ in t:
  if _ in l:
    sd[_]-=1
if max(sd.values())<0:
  print(0)
else:
  print(max(sd.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)]
scores = []
sCards = list(set(s))
for c in sCards:
    scores.append(s.count(c) - t.count(c))
if max(scores) < 0:
    print(0)
else:
    print(max(scores))

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

name_union = set(s) | set(t)
money = {}
for i, n in enumerate(name_union):
  money.setdefault(n, s.count(n) - t.count(n))

print(0 if max(money.values()) < 0 else max(money.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)]

name_union = set(s) | set(t)
money = {}
for i, n in enumerate(name_union):
  money.setdefault(n, 0)
  money[n] += sum(map(lambda x: 1 if x == n else 0, s))
  money[n] -= sum(map(lambda x: 1 if x == n else 0, t))
#print(money)
#print(money.values())
print(0 if max(money.values()) < 0 else max(money.values()))

Submission status: Accepted

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

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

name_union = set(s) | set(t)
money = {}
for i, n in enumerate(name_union):
  money.setdefault(n, 0)
  money[n] += sum(map(lambda x: 1 if x == n else 0, s))
  money[n] -= sum(map(lambda x: 1 if x == n else 0, t))
#print(money)
#print(money.values())
print(0 if max(money.values()) < 0 else max(money.values()))

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)]
ans = 0
sd = {k:v for k,v in Counter(s).items()}
td = {k:v for k,v in Counter(t).items()}
for key in sd.keys():
    try:
        ans = max(ans,sd[key]-td[key])
    except:
        ans = max(ans,sd[key])
print(ans)

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:
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

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

sys.setrecursionlimit(2147483647)
INF = float("inf")

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

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

print(ans)

Submission status: Accepted

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

cnt = 0
for s in set(lin):
  tmp = lin.count(s) - lim.count(s)
  cnt = max(cnt,tmp)
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
s = {}
t = {}
for i in range(N):
    k = input()
    if k not in s.keys():
        s[k] = 0
        t[k] = 0
    s[k] += 1

M = int(input())

for i in range(M):
    k = input()
    if k not in t.keys():
        t[k] = 0
    t[k] += 1

ans = 0
for k in s.keys():
    ans = max(ans , s[k] - t[k])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

sset = list(set(s))

ans = 0
for i in range(len(sset)):
    a = sset[i]
    ans = max(ans, s.count(a) - t.count(a))

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

R = {}
for i in s:
  if i in R:
    R[i] += 1
  else:
    R[i] = 1

for i in t:
  if i in R:
    R[i] -= 1

ans = max(R.values())
print(max(0, ans))

Submission status: Accepted

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

ans = 0

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

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

set_s = set(s) 

max_result = 0
for elem in set_s:
    r = s.count(elem) - t.count(elem)
    max_result = max(r, max_result)

print(max_result)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in set(ls):
    sum = ls.count(i) - lt.count(i)
    if sum > ans:
        ans = sum
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
lsn = [input() for _ in range(n)]
m = int(input())
lsm = [input() for _ in range(m)]
 
from collections import defaultdict
 
d = defaultdict(int)
 
for i in lsn:
    d[i] += 1
for j in lsm:
    d[j] -= 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 = max(max((S.count(x) - T.count(x) for x in set(S))), 0)

print(ans)

Submission status: Accepted

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

M = int(input())
for _ in range(M):
    i = input()
    if i in S:
        S[i] -= 1

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

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
A=[]
for i in range(n):
  a=input()
  A.append(a)
m=int(input())
B=[]
for i in range(m):
  b=input()
  B.append(b)
count=[]
for i in range(len(set(A))):
  count.append(A.count(list(set(A))[i])-B.count(list(set(A))[i]))
print(max(count) if max(count)>0 else '0')

Submission status: Accepted

Solution code:
maxi = 0

n_blue = int(input())
blue_str = [input() for _ in range(n_blue)]
n_red = int(input())
red_str = [input() for _ in range(n_red)]

kind = list(set(blue_str))

blue_count= [blue_str.count(i) for i in kind]
red_count= [red_str.count(i) for i in kind]

profit = [blue_count[i] - red_count[i] for i in range(len(blue_count))]

print(max(0, max(profit)))

Submission status: Accepted

Solution code:
n_blue = int(input())
blue_str = []
red_str = []
blue_count = []
red_count = []
maxi = 0
for _ in range(n_blue):
    blue_str.append(input())
n_red = int(input())
for _ in range(n_red):
    red_str.append(input())
kind = list(set(blue_str))
for i in kind:
    blue_count.append(blue_str.count(i))
    red_count.append(red_str.count(i))
for i in range(len(blue_count)):
    tmp = blue_count[i] - red_count[i]
    maxi = max(maxi, tmp)
print(max(0, maxi))

Submission status: Accepted

Solution code:
N=int(input())
A=[input() for _ in range(N)]
M=int(input())
b=list(set(A))
z=0
k=0
B=[input() for _ in range(M)]
c=list(set(B))
for j in range(len(b)):
    k=A.count(b[j])-B.count(b[j])
    z=max(0,z,k)
print(z)

Submission status: Accepted

Solution code:
N = int(input())

words = {'na': 0}  # 選択しない

for i in range(N):

    s = input()

    if s in words:
        words[s] += 1
    else:
        words[s] = 1

M = int(input())

for i in range(M):

    t = input()

    if t in words:
        words[t] -= 1

print(max(words.values()))

Submission status: Accepted

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

tmpList = []
getMoneyList = [0]
for i in range(n):
  if s[i] in tmpList:
    continue
  si = s[i]
  tmpList.append(si)
  cnts = s.count(si)
  cntt = t.count(si)
  if cnts - cntt > 0:
    getMoneyList.append(cnts - cntt)

print(max(getMoneyList))

Submission status: Accepted

Solution code:
d = dict()

def getv(a):
  M = int(input())
  for x in range(M):
    n = input()
    if d.get(n) is None:
      d[n] = 0
    d[n] += a

getv(1)
getv(-1)

print(max(0,d[sorted(d, key=lambda x:d[x], reverse=True)[0]]))

Submission status: Accepted

Solution code:
from collections import Counter  

blue = []
red = []
N = int(input())
for i in range(N):
    blue.append(input())
M = int(input())
for j in range(M):
    red.append(input())
b = Counter(blue)
r = Counter(red)
print(max([0] + [b[x] - r[x] for x in b]))

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)]
from collections import Counter
sc = Counter(s)
tc = Counter(t)
expected_gain = []
for key in sc.keys():
    if key in t:
        expected_gain.append(sc[key] - tc[key])
    else:
        expected_gain.append(sc[key])

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

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)]
cs = Counter(s)
ct = Counter(t)
print(max([0]+[cs[k]-ct[k] for k in cs]))

Submission status: Accepted

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

N = int(input())
S = [input() for i in range(N)]
M = int(input())
T = [input() for i in range(M)]

#print("S =",S)
#print("T =",T)

ans=0
for s in S:
    count = S.count(s)-T.count(s)
    if ans<count:
        ans=count
    
print(ans)

Submission status: Accepted

Solution code:
d = {}
n = int(input())
for i in range(n):
    s = input()
    c = d.get(s, 0)
    d[s] = c + 1
m = int(input())
for i in range(m):
    s = input()
    c = d.get(s, 0)
    d[s] = c - 1
co = 0
wo = ""
for k in d:
    if d[k] > co:
        co = d[k]
        wo = k
print(co if co > 0 else "0")

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
s = Counter(s)
t = Counter(t)
ans = 0
for k, v in s.items():
    if k in t:
        ans = max(ans, max(v - t[k], 0))
    else:
        ans = max(ans, v)
print(ans)

Submission status: Accepted

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

s.sort()
t.sort()

ans = 0
sset = set(s)

for si in sset:
    ans = max(ans, s.count(si)-t.count(si))
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)]

c = {"":0}
for s in S:
    c[s] = c.get(s, 0) + 1
for t in T:
    c[t] = c.get(t, 0) - 1

print(max(c.values()))

Submission status: Accepted

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

l=list(set(n))
print(max(0,max(n.count(l[i])-m.count(l[i]) for i in range(len(l)))))

Submission status: Accepted

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

score=[]
for i in range(n):
    score.append(plus.count(plus[i])-minus.count(plus[i]))
    
print(max(score) if max(score)>0 else 0)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import collections


def solve(N: int, s: "List[str]", M: int, t: "List[str]"):
    cs = collections.Counter(s)
    ts = collections.Counter(t)

    res = 0
    for k,v in cs.items():
        t = v - ts[k]
        res = max(res,t)

    print(res)

    
             



# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [ next(tokens) for _ in range(N) ]  # type: "List[str]"
    M = int(next(tokens))  # type: int
    t = [ next(tokens) for _ in range(M) ]  # type: "List[str]"
    solve(N, s, M, t)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

card_list = list(set(blue_list+red_list))

point = 0

for i in card_list:
	point = max(point,blue_list.count(i)-red_list.count(i))

print(point)

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

money = -1

for i in s:
    cnt = s.count(i) - t.count(i)
    if money < cnt:
        money = cnt

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

Submission status: Accepted

Solution code:
ans = 0
n = int(input())
blue = [input() for i in range(n)]
m = int(input())
red = [input() for i in range(m)]
for i in range(m):
    if red[i] in blue:
        blue.remove(red[i])
for j in list(set(blue)):
    if blue.count(j) > ans:
        ans = blue.count(j)
print(ans)

Submission status: Accepted

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