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 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def Yes(): print("Yes"); return
def No(): print("No"); return

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def Base_10_to_n(X, n):
  if (int(X/n)):
    return Base_10_to_n(int(X/n), n)+[X%n]
  return [X%n]


#############
# Main Code #
#############

N = inputI()
P_dic = defaultdict(int)
for _ in range(N):
  k = inputS()
  P_dic[k] += 1
M = inputI()
M_dic = defaultdict(int)
for _ in range(M):
  k = inputS()
  M_dic[k] += 1

  
ans = 0
for k in P_dic:
  ans = max(ans,P_dic[k]-M_dic[k])
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
sl = []
for i in range(n):
  s = str(input())
  sl.append(s)
m = int(input())
tl = []
for i in range(m):
  t = str(input())
  tl.append(t)
al = sl + tl
setal = set(al)
lsetal = list(setal)
cl = []
for i in range(len(lsetal)):
  cp = sl.count(lsetal[i])
  cm = tl.count(lsetal[i])
  cl.append(cp - cm)
mcl = max(cl)
if mcl > 0:
  print(mcl)
else:
  print('0')

Submission status: Accepted

Solution code:
import collections
n=[]
for i in range(int(input())):
    n.append(input())
    N = collections.Counter(n)
m=[]
for j in range(int(input())):
    m.append(input())
    M= collections.Counter(m)
intersection=list(N.keys()&M.keys())
for k in range(len(intersection)):
    N[intersection[k]]=N[intersection[k]]-M[intersection[k]]
print(max(max(list(N.values())),0))

Submission status: Accepted

Solution code:
N = int(input())
dn = {}
dm = {}

for _ in range(N):
    s = input()
    if s in dn:
        dn[s] += 1
    else:
        dn[s] = 1
        
M = int(input())
for _ in range(M):
    t = input()
    if t in dm:
        dm[t] += 1
    else:
        dm[t] = 1

ans = 0
for k, v in dn.items():
    res = v
    if k in dm:
        res -= dm[k]
    ans = max(ans, res)

print(ans)

Submission status: Accepted

Solution code:
dic = {}

n = int(input())
for _ in range(n):
    s = input()
    if dic.get(s):
        dic[s] += 1
    else: 
        dic[s] = 1
        
m = int(input())
for _ in range(m):
    s = input()
    if dic.get(s):
        dic[s] -= 1
    else: 
        dic[s] = -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)]
ans = 0
for x in set(S):
    score = 0
    score += sum([s == x for s in S])
    score -= sum([t == x for t in T])
    ans = max(ans, score)
print(ans)

Submission status: Accepted

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

orange = [0]
for i in s:
    a = s.count(i)
    b = t.count(i)
    orange.append(a - b)

print(max(orange))

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)]
S=list(set(s))
S2=[s.count(S[i]) for i in range(len(S))]
#print(S,S2)
for i in range(len(S)):
    x=t.count(S[i])
    S2[i]-=x
if max(S2)>=0:
    print(max(S2))
else:
    print(0)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = [input() for i in range(n)]
m = int(input())
t = [input() for i in range(m)]
sc = Counter(s)
tc = Counter(t)
a = 0
for sck in sc.keys():
    a = max(a,sc.get(sck,0)-tc.get(sck,0))
if a>=1:
    print(a)
else:
    print(0)

Submission status: Accepted

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

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())
b=[input() for i in range(n)]
m=int(input())
r=[input() for i in range(m)]

ans=[0]

for i in set(b):
    ans.append(b.count(i)-r.count(i))

print(max(ans))

Submission status: Accepted

Solution code:
import collections

n=int(input())
lb=[input() for i in range(n)]
m=int(input())
lr=[input() for i in range(m)]

for i in range(len(lr)):
    if lr[i] in lb:
        lb.remove(lr[i])
    else:
        pass
if lb==[]:
    ans=0
else:
    s=collections.Counter(lb)
    ans=s.most_common()[0][1]      

print(ans)

Submission status: Accepted

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

d = {}
for each in s:
  d[each] = d.get(each, 0) + 1
for each in t:
  d[each] = d.get(each, 0) - 1

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

Submission status: Accepted

Solution code:
N = int(input())
NList1 = []
NList2 = []
ans = 0
for i in range(N):
  tmp = input()
  NList1.append(tmp)
  NList2.append(tmp)
M = int(input())
MList = []
for k in range(M):
  tmp = input()
  MList.append(tmp)
NList2 = list(set(NList2))
for t in NList2:
  tmp2 = NList1.count(t) - MList.count(t)
  ans = max(ans,tmp2)
print(str(ans))

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    S = {}

    for _ in range(n):
        s = input()

        if s in S:
            S[s] +=1
        else:
            S[s] = 1
    
    m = int(input())
    
    for _ in range(m):
        t = input()

        if t in S:
            S[t] -= 1
        else:
            S[t] = -1
    
    print(max(0, max(list(S.values()))))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict

memo = defaultdict(int)

N = int(input())

for i in range(N):
    tmp = input()
    memo[tmp] += 1

M = int(input())

for i in range(M):
    tmp = input()
    memo[tmp] -= 1

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

Submission status: Accepted

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

Submission status: Accepted

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

S = {}
T = {}
p = 0

for i in s:
    if i not in S:
        S[i] = 1
    else:
        S[i] += 1
for i in t:
    if i not in T:
        T[i] = 1
    else:
        T[i] += 1

for i in S:
    if i not in T:
        p = max(p, S[i])
    else:
        if S[i] > T[i]:
            p = max(p, S[i] - T[i])
print(p)

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]
L1 = list(set(s) - set(t))
L2 = list(set(s) & set(t))
ans = 0
for i in L1:
    ans = max(ans, s.count(i))
for j in L2:
    ans = max(ans, s.count(j) - t.count(j))
print(ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    ls=[input() for i in range(n)]
    m=int(input())
    lt=[input() for i in range(m)]
    lbutu=list(set(ls)|set(lt))
    kosu=len(lbutu)
    lnum=[0]*kosu
    for j in ls:
        for k in range(kosu):
            if j==lbutu[k]:
                lnum[k]+=1
    for j in lt:
        for k in range(kosu):
            if j==lbutu[k]:
                lnum[k]-=1
    if max(lnum)<0:
        print(0)
    else:
        print(max(lnum))

resolve()

Submission status: Accepted

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

r = 0
for l in L:
    n = N.count(l) - M.count(l)
    if r < n:
        r = n
print(r)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = list()

for a in range(n):
    s.append(input())

t = list()
m = int(input())

count_s = dict(Counter(s))

for a in range(m):
    t = input()
    if t not in count_s.keys():
        continue
    count_s[t] -= 1

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

Submission status: Accepted

Solution code:
n = int(input())
s = list()

for a in range(n):
    s.append(input())

t = list()
m = int(input())

for a in range(m):
    t.append(input())

kind = list(set(s))
kind_length = len(kind)

counter = dict()
for a in range(kind_length):
    counter[kind[a]] = 0

for a in range(n):
    counter[s[a]] += 1

for a in range(m):
    if t[a] not in counter:
        continue
    counter[t[a]] -= 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = int(input())
b = [input() for _ in range(a) ]
c = int(input())
d = [input() for _ in range(c) ]

bb = set(b)
dd = set(d)
s = max(b.count(i) -d.count(i)  for i in bb)
print(s if s > 0 else 0)

Submission status: Accepted

Solution code:
# x1, y1, x2, y2 = map(int, input().split())

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

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

price = []
tmp = 0 
for i in range(n):
    price.append(s.count(s[i]) - t.count(s[i]))

print(max(0, max(price)))

Submission status: Accepted

Solution code:
N = int(input())
S =[]
for n in range(N):
    S.append(input())
T = []
M = int(input())
for m in range(M):
    T.append(input())
from collections import Counter
C_S = Counter(S)
C_T = Counter(T)
m = 0
for k,v in C_S.items():
    if v - C_T[k]>m:
        m =v - C_T[k]
print(m)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
s_input=Counter([input() for i in range(n)])
m = int(input())
t_input=Counter([input() for i in range(m)])

ans=0
for k,v in s_input.items():
    if k in t_input:
        tmp=v-t_input[k]
    else:
        tmp=v
    ans=max(tmp,ans)

print(max(ans,0))

Submission status: Accepted

Solution code:
def resolve():
	n = int(input())
	d = dict()
	for _ in range(n):
		v = input()
		if d.get(v):
			d[v] += 1
		else:
			d[v] = 1
	m = int(input())
	for _ in range(m):
		v = input()
		if d.get(v):
			d[v] -= 1
		else:
			d[v] = -1
	ans = float('-inf')
	for k in d.keys():
		ans = max(ans, d[k])
	print(max(ans, 0))
resolve()

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc091/tasks/abc091_b
from collections import defaultdict
n = int(input())
s = defaultdict(int)
for _ in range(n):
    s[input()] += 1

m = int(input())
t = defaultdict(int)
for _ in range(m):
    t[input()] += 1


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

d = {}
for each in s:
  d[each] = d.get(each, 0) + 1
for each in t:
  d[each] = d.get(each, 0) - 1

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

Submission status: Accepted

Solution code:
import collections
S=int(input())
D=[]
for i in range(S):
   D.append(input())
D=collections.Counter(D)
N=int(input())
for i in range(N):
   J=input()
   D[J]-=1
N = D.most_common()[0][1]
if 0 < N:
   print(N)
else:
   print(0)

Submission status: Accepted

Solution code:
n = int(input())
n_word = [input() for nesya in range(n)]
m = int(input())
m_word = [input() for motsu in range(m)]
ans = 0
for nn in n_word:
  point = n_word.count(nn) - m_word.count(nn)
  if point > ans:
    ans = point
print(ans)

Submission status: Accepted

Solution code:
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from collections import defaultdict
def resolve():
    N,=pin()
    a=defaultdict(lambda :0)
    for i in range(N):
        t=input()
        a[t]+=1
    M,=pin()
    for j in range(M):
        s=input()
        a[s]-=1
    t=(max(a.values()))          
    print(max(0,t))  
#%%submit!
resolve()

Submission status: Accepted

Solution code:
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from fractions import gcd
def resolve():
    N,=pin()
    a=dict()
    for i in range(N):
        t=input()
        a.setdefault(t,0)
        a[t]+=1
    M,=pin()
    for j in range(M):
        s=input()
        a.setdefault(s,0)
        a[s]-=1
    t=(max(a.values()))          
    print(max(0,t))  
#%%submit!
resolve()

Submission status: Accepted

Solution code:
lwrd = list()
lcnt = list()

N = int(input())
for i in range(N):
    w = input()
    if w in lwrd:
        lcnt[lwrd.index(w)] += 1
    else:
        lwrd.append(w)
        lcnt.append(1)

M = int(input())
for i in range(M):
    w = input()
    if w in lwrd:
        lcnt[lwrd.index(w)] -= 1
    else:
        lwrd.append(w)
        lcnt.append(-1)

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

Submission status: Accepted

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

print(max(0,max(s.count(s[i]) - t.count(s[i]) for i in range(len(s)))))

Submission status: Accepted

Solution code:
N = int(input())
s = []
syuugou = set()
for _ in range(N):
    i = input()
    s.append(i)
    syuugou.add(i)
M = int(input())
t = []
for _ in range(M):
    i = input()
    t.append(i)
    syuugou.add(i)
    
def counter(array):
    from collections import Counter
    return Counter(array)
t = counter(t)
s = counter(s)
ans = [0]
for x in syuugou:
    ans.append(s[x] - t[x])
print(max(ans))

Submission status: Accepted

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

Submission status: Accepted

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

    sc = Counter(s)
    tc = Counter(t)
    r = 0
    for sce in sc:
        r = max(r, sc[sce] - tc[sce])

    print(r)


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

dict = {}

for s in S:
    if s not in dict:
        dict[s] = 1
    else:
        dict[s] += 1

for t in T:
    if t not in dict:
        dict[t] = -1
    else:
        dict[t] -= 1

if max(dict.values()) <= 0:
    print(int(0))
else:
    print(max(dict.values()))

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)])
G = S-T
G["@"]=0
print(max([a for a in G.values()]))

Submission status: Accepted

Solution code:
import collections

N = int(input())
blue = [input() for i in range(N)]

M = int(input())
red = [input() for j in range(M)]

CTR_blue = collections.Counter(blue)
CTR_red = collections.Counter(red)

maxx = 0

for v in CTR_blue.keys():
    cnt = CTR_blue[v] - CTR_red[v]
    
    maxx = max(cnt, maxx)

print(maxx)

Submission status: Accepted

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

Sdict = {}
Tdict = {}
N = int(input().rstrip())
for i in range(N):
  item = input().rstrip()
  if item not in Sdict.keys():
    Sdict[item] = 1
  else:
    Sdict[item] += 1
M = int(input().rstrip())
for i in range(M):
  item = input().rstrip()
  if item not in Tdict.keys():
    Tdict[item] = 1
  else:
    Tdict[item] += 1

ans_dict = {'0': 0}
for i in Sdict.keys():
  S = Sdict[i]
  if i not in Tdict:
    T = 0
  else:
    T = Tdict[i]
  ans_dict[i] = S-T

print(max(ans_dict.values()))

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())
res = 0
for i in range(N):
    temp = S.count(S[i])-T.count(S[i])
    if res < temp:
        res = temp
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)]

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

Submission status: Accepted

Solution code:
from collections import defaultdict
def solve():
    N = int(input())
    d = defaultdict(lambda: 0)
    for i in range(N):
        S = input()
        d[S] += 1
    M = int(input())
    for i in range(M):
        T = input()
        d[T] -= 1
    ans = 0
    for v in d.values():
        ans = max(ans,v)
    return ans
print(solve())

Submission status: Accepted

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

ans = 0

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

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

ans = 0
key = ''
for i in s.keys():
    ans = max((s[i]-t[i]), ans)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    from collections import defaultdict

    d = defaultdict(int)

    N = int(input())
    for _ in range(N):
        s = input()
        d[s] += 1

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans={}

for i in s:
    if i not in ans.keys():
        ans[i]=1
    else:
        ans[i]+=1
for j in t:
    if j not in ans.keys():
        ans[j]=-1
    else:
        ans[j]-=1
print(max(max(ans.values()),0))

Submission status: Accepted

Solution code:
N = int(input())

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

M = int(input())

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

Firstlist_set = list(set(Firstlist))

Point = []
for i in range (0, len(Firstlist_set)):
	Point.append(Firstlist.count(Firstlist_set[i]))

for i in range (0, len(Firstlist_set)):
	Point[i] = Point[i] - Secondlist.count(Firstlist_set[i])

print(max(max(Point),0))

Submission status: Accepted

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

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

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

words = set(red) | set(blue)

for key in red:
    total[key] += 1

for key in blue:
    total[key] -= 1

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

Submission status: Accepted

Solution code:
N = int(input())

s = [input() for i in range(N)]

from collections import Counter

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

Submission status: Accepted

Solution code:
dict = {}

N = int(input())

for i in range(N):
    s = str(input())
    if  (s in dict.keys())== False:
        dict.setdefault(s,1)
    else:
        dict[s] += 1

M = int(input())

for j in range(M):
    t = str(input())
    if (t in dict.keys())== False:
        dict.setdefault(s,-1)
    else:
        dict[t] -= 1

        
m = 0
for k in dict:
    m = max(dict[k],m)

print(m)

Submission status: Accepted

Solution code:
import collections
import sys

input = sys.stdin.readline

def myindex(l, x, default=-1):
    if x in l:
        return l.index(x)
    else:
        return default

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

    countS = list(zip(*collections.Counter(S).items()))
    countT = list(zip(*collections.Counter(T).items()))

    ans = 0
    for i, tmp in enumerate(countS[0]):
        cntS = countS[1][i]
        myidxT = myindex(countT[0], tmp)
        cntT = countT[1][myidxT]*(myidxT != -1)
        ans = max(ans, cntS-cntT)
    
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

dic = dict()

for i in range(N):
    if s[i] not in dic:
        dic[s[i]] = 1
    else:
        dic[s[i]] += 1


for i in range(M):
    if t[i] in dic:
        dic[t[i]] -= 1

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

Submission status: Accepted

Solution code:
def resolve():
    n = int(input())
    s = list(input() for _ in range(n))
    m = int(input())
    t = list(input() for _ in range(m))

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

    print(ans if ans > 0 else 0)

resolve()

Submission status: Accepted

Solution code:
def main():
    from collections import Counter
    n = int(input())
    s = [input() for _ in range(n)]
    ss = set(s)
    m = int(input())
    t = [input() for _ in range(m)]
    res = 0
    for i in ss:
        tmp = s.count(i) - t.count(i)
        res = max(tmp,res)
    print(res)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
from collections import Counter
c = Counter()
for i in range(n):
  a = input()
  c.update({a:1})
  
m = int(input())
for i in range(m):
  s = input()
  if c[s] >= 1:
    c.update({s:-1})
    
print(c.most_common()[0][1])

Submission status: Accepted

Solution code:
n=int(input())
s=[ input() for i in range(n)]
m=int(input())
t=[ input() for i in range(m)]
ans=dict()
for i in s:
  if not(i in ans):
    ans[i]=1
  else:
    ans[i]+=1
for i in t:
  if not(i in ans):
    ans[i]=-1
  else:
    ans[i]-=1
hantei=0
for i in ans:
  if ans[i]>hantei:
    hantei=ans[i]
print(hantei)

Submission status: Accepted

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

R={}
M=int(input())
for i in range(M):
    s=input()
    if s in R:
        R[s]+=1
    else:
        R[s]=1
    T.append(s)

T=set(T)
ans=0
for t in T:
    if t in B:
        b=B[t]
    else:
        b=0
    if t in R:
        r=R[t]
    else:
        r=0
    now=b-r
    ans=max(ans, now)
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import Counter
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    S = [input() for _ in range(n)]
    m = int(input())
    T = [input() for _ in range(m)]

    D_S = Counter(S)
    D_T = Counter(T)
    res = 0
    for k, v in D_S.items():
        cnt = v - D_T.get(k, 0)
        res = max(res, cnt)

    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    s_dic = {}
    for _ in range(n):
        s = input()
        if s in s_dic:
            s_dic[s] += 1
        else:
            s_dic[s] = 1
    m = int(input())
    t_dic = {}
    for _ in range(m):
        t = input()
        if t in t_dic:
            t_dic[t] += 1
        else:
            t_dic[t] = 1
    ans = 0
    for s in s_dic.keys():
        tmp = s_dic[s]
        if s in t_dic:
            tmp -= t_dic[s]
        ans = max(ans, tmp)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()
n=I()
lisa=[input().rstrip() for i in range(n)]
m=I()
lisb=[input().rstrip() for i in range(m)]
u=Counter(lisa)
v=Counter(lisb)
mx=0
for j in u.keys():
    ans=u[j]-v[j]
    if ans>mx:
        mx=ans
print(mx)

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

ans = 0
for x,y in s.items():
  a = y
  if x in t:
    a -= t[x]
  if ans < a: ans = a
print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    S = [input() for i in range(N)]
    M = int(input())
    T = [input() for i in range(M)]
    ans = 0
    from collections import Counter
    c = Counter(S)
    cT = Counter(T)
    for k, v in c.items():
        ans = max(ans, v - cT[k])
    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)]
from collections import Counter
cnt_s = Counter(s)
cnt_t = Counter(t)
money = 0
for i in set(s):
    temp = cnt_s[i] - cnt_t[i]
    if money < temp:money = temp
print(money)

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

d = collections.defaultdict(int)
for x in s:
    d[x] += 1
for x in t:
    d[x] -= 1

ans = 0
for x in d:
    ans = max(ans, d[x])
print(ans)