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:
#coding:utf-8
n = int(input())
blue = []
plus = []
for i in range(n):
    s = input()
    if s in blue:
        plus[blue.index(s)] += 1
    else:
        blue.append(s)
        plus.append(1)
m = int(input())
for i in range(m):
    s = input()
    if s in blue:
        plus[blue.index(s)] -= 1
    else:
        blue.append(s)
        plus.append(-1)
print(max(0, max(plus)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

c=Counter(s).most_common()
p=[]
for i in range(len(c)):
	p.append(c[i][1]-t.count(c[i][0]))
point=max(p)
if point<0:
	point=0
print(point)

Submission status: Accepted

Solution code:
blue_dict = {}
red_dict = {}

N = int(input())
for i in range(N):
    s = input()
    if s in blue_dict:
        blue_dict[s] = blue_dict[s] + 1
    else:
        blue_dict[s] = 1

M = int(input())
for i in range(M):
    s = input()
    if s in red_dict:
        red_dict[s] = red_dict[s] + 1
    else:
        red_dict[s] = 1

point_max = 0
for s in blue_dict:
    point = blue_dict[s] - red_dict.get(s, 0)
    point_max = max(point_max, point)
print(point_max)

Submission status: Accepted

Solution code:
memo = {}

n = int(input())
for i in range(n):
    s = input().strip()
    if s not in memo:
        memo[s] = 1
    else:
        memo[s] += 1

n = int(input())
for i in range(n):
    s = input().strip()
    if s not in memo:
        memo[s] = -1
    else:
        memo[s] -= 1

res =  max(memo.values())
if res<0:
    res = 0

print(res)

Submission status: Accepted

Solution code:
from collections import defaultdict

blue = defaultdict(int)
red = defaultdict(int)

for i in range(int(input())):
    blue[input()] += 1

for i in range(int(input())):
    red[input()] +=1

max_key = max(blue.items(), key=lambda x:x[1]-red[x[0]])[0]

print(max(0, blue[max_key]-red[max_key]))

Submission status: Accepted

Solution code:
from collections import Counter, defaultdict
n = int(input())
s= []
t = defaultdict(int)
for _ in range(n):
    s.append(input())
u = Counter(s)
m = int(input())
for _ in range(m):
    word = input()
    t[word] -= 1
    if word in u.keys():
        u[word] -= 1

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

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
ao = []
for i in range(N):
    ao.append(input())

ao_cnt = Counter(ao)

M = int(input())
aka = []
for i in range(M):
    aka.append(input())

aka_cnt = Counter(aka)

ao_cnt.subtract(aka_cnt)
if ao_cnt.most_common(1)[0][1] <= 0:
    print(0)
else:
    print(ao_cnt.most_common(1)[0][1])

Submission status: Accepted

Solution code:
N = int(input())
L = {}
for i in range (N):
	a = input()
	if a in L :
		L[a] += 1
	else :
		L[a] = 1
M = int(input())
for i in range (M):
	a = input()
	if a in L and L[a] > 0:
		L[a] -= 1
	else :
		pass
maximum = 0
for i in L :
	if L[i] > maximum :
		maximum = L[i]
	else :
		pass
print (maximum)

Submission status: Accepted

Solution code:
from collections import Counter

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

s_count = Counter(s)
t_count = Counter(t)

s_count.subtract(t_count)

res = max(s_count.values())

if res > 0:
    print(res)
else:
    print(0)

Submission status: Accepted

Solution code:
from collections import Counter
import numpy as np

a = int(input())
a_list = []
b_list = []

for i in range(a):
  a_list.append(input())

b = int(input())

for i in range(b):
  b_list.append(input())
a_count = Counter(a_list)
b_count = Counter(b_list)
a_list_no_overlap = set(a_list)

point = []
for i in a_list_no_overlap:
    point.append(a_count[i]-b_count[i])

point_max = max(point)
if point_max<0:
  print(0)
else:
  print(point_max)

Submission status: Accepted

Solution code:
from collections import defaultdict

red_num = int(input())

str_dict = {}
for i in range(red_num):
    str = input()
    str_dict[str] = str_dict.get(str, 0) + 1

blue_num = int(input())

for i in range(blue_num):
    str = input()
    str_dict[str] = str_dict.get(str, 0) - 1

result = max(str_dict.values())

if result >= 1:
    print(result)
else:
    print(0)

Submission status: Accepted

Solution code:
N=int(input())
wordList={}
tmpWord=""
for i in range(N):
    tmpWord=input()
    if tmpWord in wordList:
        wordList[tmpWord]+=1
    else:
        wordList[tmpWord]=1
M=int(input())
for i in range(M):
    tmpWord=input()
    if tmpWord in wordList:
        wordList[tmpWord]-=1
if max(wordList.values())<=0:
    print("0")
else:
    print(max(wordList.values()))

Submission status: Accepted

Solution code:
n = int(input())
s = ["0"]*n
dict = {}
for i in range(n):
    s[i] = input()
    if s[i] in dict:
        dict[s[i]] += 1
    else:
        dict[s[i]] = 1

m = int(input())
t = ["0"]*m
for i in range(m):
    t[i] = input()
    if t[i] in dict:
         dict[t[i]] -= 1
    else:
         dict[t[i]] = -1
    if dict[t[i]] < 0 :
         dict[t[i]] = 0
print(max(dict.values()))

Submission status: Accepted

Solution code:
import collections

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

count = collections.Counter()

for s in S:
    count[s] += 1
for t in T:
    count[t] -= 1
    
print(max(count.most_common(1)[0][1], 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=[]
import collections
data=collections.Counter(s)
deta=collections.Counter(t)
for i,j in data.items():
    for k,l in deta.items():
        if i==k:
            ans.append(j-l)
        if i not in t:
            ans.append(j)
if max(ans)<0:
    print(0)
else:
    print(max(ans))

Submission status: Accepted

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

n = int(input())						# 5
for i in range(n):
	k = input()
	d[k] += 1

n = int(input())						# 5
for i in range(n):
	k = input()
	d[k] -= 1

#print(*d)

d = sorted(d.items(), key=lambda x: -x[1])
i = max(0, d[0][1])
print(i)

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

print(max)

Submission status: Accepted

Solution code:
from collections import Counter
N1 = int(input())
a = [input() for i in range(N1)]

N2 = int(input())
b = [input() for i in range(N2)]

counterA = Counter(a)
counterB = Counter(b)

counterA.subtract(counterB)
for c, d in counterA.most_common(1):
    print(max(0,d))

Submission status: Accepted

Solution code:
a = int(input())
blue = []
count = []
for i in range(a):
    x = input()
    if x in blue:
        count[blue.index(x)] += 1
    else:
        blue.append(x)
        count.append(1)
b = int(input())
for i in range(b):
    x = input()
    if x in blue:
        count[blue.index(x)] -= 1
    else:
        blue.append(x)
        count.append(-1)

count.sort()
count.reverse()
if count[0] < 0:
    print("0")
else:
    print (count[0])

Submission status: Accepted

Solution code:
N = int(input())
words = [0 for i in range(0,N)]
for i in range(0,N):
    words[i] = input()
M = int(input())

for i in range(0,M):
    t = input()
    words.append(t)
SUM = []
#print(words)
for i in range(0,N+M):
    count = 0
    for j in range(0,N):
        if words[i] == words[j]:
            count += 1

    for j in range(N,N+M):
        if words[i] == words[j]:
            count -= 1
    SUM.append(count)

#print(SUM)
ans = max(SUM)
if ans >= 0:
    print(ans)
else:
    print(0)

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
s = []
for _ in range(n):
    s.append(ns())

m = ni()
t = []
for _ in range(m):
    t.append(ns())

ns = set(s)
ns = list(ns)
ts = [0]*len(ns)
for i in range(len(ns)):
    for j in s:
        if ns[i] == j:
            ts[i] += 1
    for j in t:
        if ns[i] == j:
            ts[i] -= 1
ts.sort(reverse=True)
if ts[0] > 0:
    print(ts[0])
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

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

M = int(input())
for i in range(M):
    T = input().rstrip()
    if T in S:
        S[T] -= 1
        if S[T]==0:
            del S[T]

#print(S)
if len(S)==0:
    print('0')
else:
    print(max(list(S.values())))

Submission status: Accepted

Solution code:
# coding : utf-8 

N = int(input())
n = {}
for i in range(N):
    st = input()
    if st in n:
        n[st] += 1
    else:
        n[st] = 1
M = int(input())
m = {}
for i in range(M):
    st = input()
    if st in m:
        m[st] += 1
    else:
        m[st] = 1
maxl = 0
for st,i in n.items():
    if st not in m:
        maxl = max(i,maxl)
    else:
        maxl = max(i-m[st],maxl)

print(maxl)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
listBlue = [input() for i in range(N)]
M = int(input())
listRed = [input() for i in range(M)]

counterBlue = Counter(listBlue)
counterRed = Counter(listRed)
counterSum = counterBlue - counterRed
if len(counterSum) == 0:
    print(0)
else:
    ans = max(counterSum.values())
    print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
nl = [input() for i in range(n)]
m = int(input())
ml = [input() for j in range(m)]

ndict = dict(Counter(nl))
mdict = dict(Counter(ml))

difflist = []

for k1, v1 in ndict.items():
    if k1 in mdict:
        diff = v1 - mdict[k1]
        difflist.append(diff)
    else:
        difflist.append(v1)

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

Submission status: Accepted

Solution code:
#coding=utf-8

def solve(ss, ts):
    u_ss = list(set(ss))
    u_ts = list(set(ts))
    ss_dict = {}
    ts_dict = {}
    for u in u_ss:
        ss_dict[u] = ss.count(u)
    for u in u_ts:
        ts_dict[u] = ts.count(u)
    ans_dict = {}
    for u in list(ss_dict.keys()) + list(ts_dict.keys()):
        ss_dict[u] = ss_dict[u] if u in list(ss_dict.keys()) else 0
        ts_dict[u] = ts_dict[u] if u in list(ts_dict.keys()) else 0

        ans_dict[u] = ss_dict[u] - ts_dict[u]
    ans = max(list(ans_dict.values()))
    if ans < 0:
        ans = 0
    return ans

if __name__ == '__main__':
    N = int(input())
    ss = []
    ts = []
    for _ in range(N):
       ss = ss + [input()] 
    M = int(input())
    for _ in range(M):
       ts = ts + [input()] 

    print(solve(ss, ts))

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

count_s = collections.Counter(s)
count_t = collections.Counter(t)
ans = 0
for key in count_s:
    point = count_s[key]
    if key in count_t.keys():
         point -= count_t[key]
    
    if ans < point:
        ans = point
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
Blue_Cards = []
for i in range(N):
    Blue_Cards. append(input())
M = int(input())
Red_Cards = []
for n in range(M):
    Red_Cards. append(input())
Q = 0
for l in range(N):
    P = int(Blue_Cards. count(Blue_Cards[l]))-int(Red_Cards. count(Blue_Cards[l]))
    if P > Q:
        Q = P
print(Q)

Submission status: Accepted

Solution code:
a=[]
b=[]
x=0
y=0
z=x-y
ans=[]

N=int(input())
for i in range(N):
  c=input()
  a.append(c)
M=int(input())
for i in range(M):
  c=input()
  b.append(c)
  
for i in a:
  for j in a:
    if(i==j):
      x+=1
  for k in b:
    if(i==k):
      y+=1
  z=x-y
  if(z<=0):
    z=0
  ans.append(z)
  x=0
  y=0
  z=0

d=max(ans)
print(d)

Submission status: Accepted

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

def main():
	N = int(input())
	s = []
	for i in range(N):
		s.append(input())
	M = int(input())
	t = []
	for i in range(M):
		t.append(input())

	s_uniq = list(set(s))
	s_dict = {}
	for i in range(len(s_uniq)):
		s_dict[s_uniq[i]] = s.count(s_uniq[i])
	t_uniq = list(set(t))
	t_dict = {}
	for i in range(len(t_uniq)):
		t_dict[t_uniq[i]] = t.count(t_uniq[i])

	u_list = []
	for i in range(len(s_uniq)):
		if s_uniq[i] in t_dict.keys():
			u_list.append(s_dict[s_uniq[i]] - t_dict[s_uniq[i]])
		else:
			u_list.append(s_dict[s_uniq[i]])
	if max(u_list) < 1:
		print(0)
	else:
		print(max(u_list))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

from collections import Counter

def main():
    bCardNum = int(input())
    bCard = [input() for s in range(bCardNum)]
    
    rCardNum = int(input())
    rCard = [input() for s in range(rCardNum)]
    
#    print(bCard)
#    print(rCard)
    
    uniq_bCard = list(set(bCard))
#    print(uniq_bCard)
    
    result = 0
    
    count_bCard = Counter(bCard)
    count_rCard = Counter(rCard)
    
    for string in uniq_bCard:
        tmp = count_bCard[string] - count_rCard[string]
        if(tmp > result):
            result = tmp
    
    print(result)
    
if __name__=="__main__":
    main()

Submission status: Accepted

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

# AtCoder Beginner Contest
# Problem B

if __name__ == '__main__':
    blue_card_count = int(input())
    blue_cards = list()

    for i in range(blue_card_count):
        blue_cards.append(input())

    red_card_count = int(input())
    red_cards = list()

    for i in range(red_card_count):
        red_cards.append(input())

    count_max = 0

    set_blue_card = set(blue_cards)

    for blue_card in set_blue_card:
        candidate = blue_cards.count(blue_card) - red_cards.count(blue_card)
        if candidate > count_max:
            count_max = candidate

    print(count_max)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(raw_input())
li = list()
for i in range(0,n):
    li.append(raw_input())
count = Counter(li)
m = int(raw_input())
for i in range(0,m):
    s = raw_input()
    if count[s] != 0:
        count[s] -= 1
print count.most_common(1)[0][1]

Submission status: Accepted

Solution code:
def main():
    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 = []
    
    for i in s:
        ans.append( s.count(i) - t.count(i))
    
    ans = max(ans)
    if ans < 0:
        ans = 0
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8

N = int(input())
ao = {}
ao2 = []
memo = {}
for i in range(N):
    ao_t = input()
    ao2.append(ao_t)

M = int(input())
aka = {}
aka2 = []
for i in range(M):
    aka_t  = input()
    aka2.append(aka_t)


for i in ao2:
    try:
        ao[i] += 1
    except:
        ao[i] = 1

for i in aka2:
    try:
        aka[i] += 1
    except:
        aka[i] = 1




ans = 0
meno = 0

memo2 = {}

for k, v in ao.items():
    try:
        memo = aka[k]
        memo2[k] = v - memo
    except:
        memo2[k] = v

flag = 0
for k, v in sorted(memo2.items(), key=lambda x: -x[1]):
    if flag == 0:
        if v < 0:
            print(0)
        else:
            print(v)
    flag = 1

Submission status: Accepted

Solution code:
# coding: utf-8

b = []
r = []

# input
N = int(input())
for i in range(N):
    arg = input()
    b.append(arg)

M = int(input())
for i in range(M):
    arg = input()
    r.append(arg)

# solve
br = b + r
for i in range(len(br)):
    # initialize
    count_b = 0
    count_r = 0
    # target string
    s = br[i]
    # check blue cards
    for j in range(len(b)):
        if (b[j] == s):
            count_b += 1
    # check red cards
    for j in range(len(r)):
        if (r[j] == s):
            count_r += 1
    # check difference
    diff = count_b - count_r
    if (i == 0):
        X = diff
    elif (diff > X):
        X = diff
if (X < 0):
    X = 0

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

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

values = list(count.values())
keys = list(count.keys())
maxCount = max(values)
if maxCount > 0:
    print ( maxCount)
else:
    print (0)

Submission status: Accepted

Solution code:
def abc091_b():
    from collections import Counter
    _strs = []
    _strt = []
    _max = 0
    _n = int(input())
    for i in range(_n):
        _strs.append(str(input()))
    _m = int(input())
    for i in range(_m):
        _strt.append(str(input()))
    _strs2 = list(set(_strs))
    for element in _strs2:
        _score = Counter(_strs)[element] - Counter(_strt)[element]
        if _score > _max:
            _max = _score
    print(_max)


abc091_b()

Submission status: Accepted

Solution code:
import sys


def main():
    N = int(sys.stdin.readline())
    s = [x[:-1] if x[-1] == '\n' else x for x in [sys.stdin.readline()
                                                  for _ in range(N)]]
    M = int(sys.stdin.readline())
    t = [x[:-1] if x[-1] == '\n' else x for x in [sys.stdin.readline()
                                                  for _ in range(M)]]
    spam = [len([y for y in s if x == y]) -
            len([y for y in t if x == y]) for x in s]
    print(max(spam + [0]))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
Flag = 0
TmpNum = 0
Count = 0
Data = [[0 for i in range(2)]  for j in range(N)]

for i in range(N):
    TmpS = input()
    Num = i
    if Num == 0:
        Data[i][0] = TmpS
        Data[i][1] = 1
        Count += 1
    else:
        Flag = 0
        for i2 in range(Num):
            if TmpS == Data[i2][0]:
                Flag = 1
                TmpNum = i2
                break
        
        if Flag == 1:
            Data[TmpNum][1] += 1
        else:
            Data[Count][0] = TmpS
            Data[Count][1] = 1
            Count += 1

M = int(input())
for i in range(M):
    TmpS = input()
    for i2 in range(Count):
        if TmpS == Data[i2][0]:
            Data[i2][1] -= 1
            break

Data = sorted(Data, key=lambda x: x[1],  reverse=True) 

Ans = Data[0][1]
if Ans < 0:
    Ans = 0

print(Ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

s = Counter(s)
t = Counter(t)

pointmax = 0

for a in s:
    ans = s[a] - t[a]
    if(ans > pointmax):
        pointmax = ans

print(pointmax)

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()))
    
from collections import Counter
import numpy as np
counter = Counter(s)
sw = []
sc = []
for word, cnt in counter.most_common():
    sw.append(word)
    sc.append(cnt)
counter2 = Counter(t)
tw = []
tc = []
for word, cnt in counter2.most_common():
    tw.append(word)
    tc.append(cnt)
    
sw = np.array(sw)
sc = np.array(sc)
tw = np.array(tw)
tc = np.array(tc)

anslist = []
for i in range(len(sw)):
    anslist.append(sc[i] - sum((sw[i] == tw)*tc))
ans = max(anslist)
if(ans < 0):
    print("0")
else:
    print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

b = defaultdict(lambda :0)
r = defaultdict(lambda :0)

b[""] = 0

n = int(input())
for i in range(n):
    a = input()
    a.replace("\r","")
    b[a] += 1
m = int(input())
for i in range(m):
    a = input()
    a.replace("\r","")
    r[a] += 1
      
b_keys = list(b.keys())
r_keys = list(r.keys())
all_keys = list(set(b_keys).union(set(r_keys)))
pays = defaultdict(lambda :0)

for i in all_keys: 
    pays[i] = b[i] - r[i]

print(max(pays.values()))

Submission status: Accepted

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

M = int(input())
for i in range(M):
    t_i = input()
    if t_i not in point:
        continue
    else:
        point[t_i]-=1

ans = 0
for i in point.keys():
    ans = max(ans, point[i])

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

Submission status: Accepted

Solution code:
N = int(input())
b = []
for i in range(N):
    string = input()
    b.append(string)
r = []
M = int(input())
for i in range(M):
    r.append(input())

bd = {}
for a in b:
    if a not in bd:
        bd[a] = 0
    bd[a] += 1
rd = {}
for a in r:
    if a not in rd:
        rd[a] = 0
    rd[a] += 1

counter = []
keys = set(bd) | set(rd)
for key in keys:
    tmp = 0
    if key in bd:
        tmp += bd[key]
    if key in rd:
        tmp -= rd[key]
    counter.append(tmp)
foo = max(counter)
if foo > 0:
    print(foo)
else:
    print(0)

Submission status: Accepted

Solution code:
blue=[]
red=[]
point=0
point_blue=0
point_red=0

N=int(input())
for i in range(N):
    blue+=[input()]
M=int(input())
for i in range(M):
    red+=[input()]

for i in blue:
    point_blue=blue.count(i)
    point_red=red.count(i)
    if point_blue-point_red>point:
        point=point_blue-point_red

print(point)

Submission status: Accepted

Solution code:
blue = []
red = []
N = int(input())
for card in range(N):
    blue.append(input())
M = int(input())
for card in range(M):
    red.append(input())

max = 0
for b in blue:
    if max < blue.count(b) - red.count(b):
        max = blue.count(b) - red.count(b)
        
print(max)

Submission status: Accepted

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

s = Counter(S)
t = Counter(T)
for k1,v1 in s.items():
  for k2,v2 in t.items():
    if k1==k2:
      s[k1] -= v2
print(max(max(s.values()),0))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

def main():
    N = int(input())
    s = [input() for i in range(N)]
    M = int(input())
    t = [input() for i in range(M)]
    max_point = 0

    for a in s:
        add_point = s.count(a)
        sub_point = t.count(a)
        max_point = max(add_point - sub_point,max_point)

    print(max_point)
if __name__=='__main__':
    main()

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

d={}
for s in S:
    if s in d:
        d[s]+=1
    else:
        d[s]=1
for t in T:
    if t in d:
        d[t]-=1
ans=0
for i in d.values():
    if i>=0 and i>ans:
        ans=i
print(ans)

Submission status: Accepted

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

N = int(input())
s = []
for i in range(0,N):
    data = input()
    s.append(data)

M = int(input())
t = []
for i in range(0,M):
    data = input()
    t.append(data)

st = s + t

plus  = []
minus = []
for i in st:
    p = 0
    m = 0
    for j in s:
        if i == j:
            p = p + 1
        else:
            pass
    for j in t:
        if i == j:
            m = m - 1
        else:
            pass
            
    plus.append(p)
    minus.append(m)

pmax=0
for i,j in zip(plus,minus):
    if 0 < (i + j) and pmax <(i + j):
        pmax = i + j
    else:
        pass

print(pmax)

Submission status: Accepted

Solution code:
n=int(input())
blue=[input() for i in range(n)]
m=int(input())
red=[input() for j in range(m)]
point=0
for word in blue:
    if blue.count(word)-red.count(word)>point:
        point=blue.count(word)-red.count(word)

print(point)

Submission status: Accepted

Solution code:
from collections import defaultdict

if __name__ == '__main__':
    N = int(input().strip())
    s = [input().strip() for _ in range(N)]
    M = int(input().strip())
    t = [input().strip() for _ in range(M)]

    d = defaultdict(int)
    d[""] = 0

    for word in s:
        d[word] += 1

    for word in t:
        d[word] -= 1

    max_key = None
    max_value = -1
    for (key, value) in d.items():
        if max_key is None:
            max_key = key
            max_value = value
            continue

        if max_value < value:
            max_key = key
            max_value = value

    print(max_value)

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

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    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()))
    s_dict = {}
    for ele in s:
        if ele in s_dict.keys():
            s_dict[ele] += 1
        else:
            s_dict[ele] = 1
    t_dict = {}
    for ele in t:
        if ele in t_dict.keys():
            t_dict[ele] += 1
        else:
            t_dict[ele] = 1
    buf = list(set(s + t))
    max = 0
    for ele in buf:
        s_num = 0
        t_num = 0
        if ele in s_dict.keys():
            s_num = s_dict[ele]
        if ele in t_dict.keys():
            t_num = t_dict[ele]
        if (s_num - t_num) > max:
            max = s_num - t_num
    print(max)

Submission status: Accepted

Solution code:
N = int(input())
i = 0
jj = []
s = []
while i < N:
	s.append(input())
	i += 1
M = int(input())
j = 0
t = []
while j < M:
	t.append(input())
	j += 1
for ss in s:
	if ss in t:
		jj.append(s.count(ss)-t.count(ss))
	else:
		jj.append(s.count(ss))
balance = max(jj)
if balance < 0:
	balance = 0
print(balance)

Submission status: Accepted

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

m = int(input())
t = {}
for i in range(m):
    r = input()
    if r in t:
        t[r] += 1
    else:
        t[r] = 1

temp = 0
for b in s.keys():
    val = 0
    if b in t.keys():
        val = s[b] - t[b]
    else:
        val = s[b]
    if val > temp:
        temp = val

print(temp)

Submission status: Accepted

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

dct={}
for strings in s:
    dct.setdefault(strings,0)
    dct[strings]+=1
    
for strings in t:
    if strings in dct:
        dct[strings]-=1

if max(dct.values())>=1:
    print(max(dct.values()))
else:
    print("0")

Submission status: Accepted

Solution code:
from collections import defaultdict

d = defaultdict(lambda: 0)

def get_card(num, mode):
    for _ in range(num):
        w = input()
        if mode == 'blue':
            d[w] += 1
        elif mode == 'red':
            d[w] -= 1

            
if __name__ == '__main__':
    n = int(input())
    get_card(n, mode='blue')
    m = int(input())
    get_card(m, mode='red')
    ans = sorted(d.items(), key=lambda x: x[1], reverse=True)
    if ans[0][1] >= 0:
        print(ans[0][1])
    else:
        print(0)

Submission status: Accepted

Solution code:
n=int(input())
s=[]
for i in range(n):
    s.append(input())
s.sort()
s.append("unkounkounkounko")

m=int(input())
ss=[]
for i in range(m):
    ss.append(input())
ss.sort()
ss.append("unkounkounkounko")


s_number=[]
k=1
for i in range(n):
    if s[i]!=s[i+1]:
        s_number.append([s[i],k])
        k=1
    else:
        k+=1

ss_number=[]
k=1
for i in range(m):
    if ss[i]!=ss[i+1]:
        ss_number.append([ss[i],k])
        k=1
    else:
        k+=1

point=0
point_m=[]
for i in range(len(s_number)):
    point=s_number[i][1]
    for j in range(len(ss_number)):

        if s_number[i][0]==ss_number[j][0]:
            point=max(0, s_number[i][1]-ss_number[j][1])
    point_m.append(point)


#print(s,ss)

#print(s_number)
#print(ss_number)
print(max(point_m))

Submission status: Accepted

Solution code:
from collections import Counter

def max_earn(blue_cards, red_cards):
    blue_dict = Counter(blue_cards)
    red_dict = Counter(red_cards)
    maximum = 0
    for (k, v) in blue_dict.items():
        if k in red_dict:
            maximum = max(maximum, v - red_dict[k])
        else:
            maximum = max(maximum, v)
    return maximum


if __name__ == '__main__':
    blue_cards = [raw_input() for _ in xrange(int(raw_input()))]
    red_cards = [raw_input() for _ in xrange(int(raw_input()))]
    print max_earn(blue_cards, red_cards)