Problem:


Score : 200 points

Problem Statement

Takahashi has N blue cards and M red cards.
A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i.

Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen.

Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces atcoder, he will not earn money even if there are blue cards with atcoderr, atcode, btcoder, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.)

At most how much can he earn on balance?

Note that the same string may be written on multiple cards.

Constraints

N and M are integers.

1 \leq N, M \leq 100

s_1, s_2, ..., s_N, t_1, t_2, ..., t_M are all strings of lengths between 1 and 10 (inclusive) consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
s_1
s_2
:
s_N
M
t_1
t_2
:
t_M

Output

If Takahashi can earn at most X yen on balance, print X.

Sample Input 1

3
apple
orange
apple
1
grape

Sample Output 1

2

He can earn 2 yen by announcing apple.

Sample Input 2

3
apple
orange
apple
5
apple
apple
apple
apple
apple

Sample Output 2

1

If he announces apple, he will lose 3 yen. If he announces orange, he can earn 1 yen.

Sample Input 3

1
voldemort
10
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort

Sample Output 3

0

If he announces voldemort, he will lose 9 yen. If he announces orange, for example, he can avoid losing a yen.

Sample Input 4

6
red
red
blue
yellow
yellow
red
5
red
red
yellow
green
blue

Sample Output 4

1



Sample input:
3
apple
orange
apple
1
grape


Sample output:
2

Submission status: Accepted

Solution code:
N = int(input())
s = []
mozi = set()
for i in range(N):
  S =input()
  s.append(S)
  mozi.add(S)
M = int(input())
t = []
for i in range(M):
  t.append(input())
ans = 0
for elem in mozi:
    cur = 0
    for i in range(N):
        if elem == s[i]:
            cur += 1
    for j in range(M):
        if elem == t[j]:
            cur -=1
    ans = max(ans,cur)

print(ans)

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())
s_ = collections.Counter(s)
t_ = collections.Counter(t)
a = []
for key in s_.keys():
    num = s_[key] - t_[key]
    a.append(num)
print(max(max(a),0))

Submission status: Accepted

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

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

SD = {}
for s in S:
    SD[s] = SD.get(s, 0) + 1

TD = {}
for t in T:
    TD[t] = TD.get(t, 0) + 1

# print(SD)
# print(TD)

ans = 0
for k, v in SD.items():
    # print(k,v)
    ans = max(ans, v - TD.get(k, 0))

print(ans)

Submission status: Accepted

Solution code:
s, t = [], []

N = int(input())
for i in range(N):
  s.append(input())
M= int(input())
for i in range(M):
  t.append(input())
  
dic = list(set(s + t))
result = 0
for i in range(len(dic)):
  result = max(result, s.count(dic[i]) - t.count(dic[i]))
print(result)

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

Submission status: Accepted

Solution code:
N = int(input())
cards = {}
for _ in range(N):
    fraise = input()
    if not fraise in cards:
        cards[fraise] = 1
    else:
        cards[fraise] += 1
M = int(input())
for _ in range(M):
    fraise = input()
    if not fraise in cards:
        cards[fraise] = -1
    else:
        cards[fraise] -= 1
max = 0
for card in cards:
    if cards[card] > max:
        max = cards[card]
print(max)

Submission status: Accepted

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

cs = dict(collections.Counter(s_list))
ct = dict(collections.Counter(t_list))

count_list = []
for k,v in cs.items():
    if k in ct:
        if ct[k] < v:
            count_list.append(v-ct[k])
    else:
        count_list.append(v)

print(max(count_list) if len(count_list)!= 0 else 0)

Submission status: Accepted

Solution code:
N = int(input())
plus = []
for _ in range(N):
    plus.append(input())
M = int(input())
minus = []
for _ in range(M):
    minus.append(input())
def counter(array):
    from collections import Counter
    return list(Counter(array).most_common())
plus = counter(plus)
minus = counter(minus)
ans = 0
for x in plus:
    for y in minus:
        if x[0] == y[0]:
            ans = max(ans,x[1] - y[1])
            break
    else:
        ans = max(ans,x[1])
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
s = {}
for _ in range(n):
    c = input()
    if c not in s:
        s[c] = 0
    s[c] += 1

m = int(input())
t = {}
for _ in range(m):
    c = input()
    if c not in t:
        t[c] = 0
    t[c] += 1

res = 0
for k in s.keys():
    r = s[k]
    if k in t:
        r -= t[k]
    res = max(res, r)

for k in t.keys():
    r = 0
    if k in s:
        r += s[k]
    r -= t[k]
    res = max(res, r)

print(res)

Submission status: Accepted

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

str_count = {}
for s in sn:
    if s in str_count:
        str_count[s] += 1
    else:
        str_count[s] = 1
for t in tn:
    if t in str_count:
        str_count[t] -= 1
    else:
        str_count[t] = -1

m = max(str_count.values())
print(m if m > 0 else 0)

Submission status: Accepted

Solution code:
N = int(input())
s = [input() for i in range(N)]
M = int(input())
t = [input() for j in range(M)]
a = 0
for i in range(len(s)):
    a = max(a, s.count(s[i]) - t.count(s[i]))
print(a)

Submission status: Accepted

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
sl = [stdin.readline().rstrip() for _ in range(n)]
m = int(stdin.readline().rstrip())
tl = [stdin.readline().rstrip() for _ in range(m)]
ans=[sl.count(s) - tl.count(s) for s in set(sl)]
if max(ans) < 0:
    print(0)
else:
    print(max(ans))

Submission status: Accepted

Solution code:
N = int(input())
s = [input() for i in range(N)]
M = int(input())
t = [input() for i in range(M)]
 
result = 0
for ch in s:
    score = s.count(ch) - t.count(ch)
    if result < score:
        result = score
print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
blue = []
red = []
score_list = []
for i in range(n):
    blue.append(input())
m = int(input())
for j in range(m):
    red.append(input())
for value in blue:
    score = 0
    for s in blue:
        if value == s:
            score += 1
    for t in red:
        if value == t:
            score -= 1
    if score not in score_list:
        score_list.append(score)
if max(score_list) < 0:
    print(0)
else:
    print(max(score_list))

Submission status: Accepted

Solution code:
from random import randint
# from typing import TypeVar, Tuple, List, Optional, Iterable


# K = TypeVar("K")
# V = TypeVar("V")

class ListNode:
    def __init__(self, key, value, next_=None):
        self.key, self.value, self.next = key, value, next_


class HashMapLinkedList:
    def __init__(self):
        self.__head = ListNode(None, None)
        self.__tail = self.__head
        self.__num_items = 0

    def __repr__(self):
        return "->" +  " -> ".join(str(kv_pair) for kv_pair in self)

    def __len__(self):
        return self.__num_items

    def find(self, key):
        cur_node = self.__head.next
        while cur_node:
            if cur_node.key == key:
                return cur_node
            cur_node = cur_node.next
        raise ValueError(key if type(key) != str else "'" + key + "'")

    def insert(self, key, value):
        # when there already exists the key-value pair, update the value.
        try:
            node = self.find(key)
            node.value = value
            return 0
        # Otherwise, add a new key-value pair.
        except ValueError:
            self.__tail.next = ListNode(key, value)
            self.__tail = self.__tail.next
            self.__num_items += 1
            return 1

    def delete(self, key):
        cur_node = self.__head
        while cur_node.next:
            if cur_node.next.key == key:
                cur_node.next = cur_node.next.next
                self.__num_items -= 1
                return
            cur_node = cur_node.next

    def __iter__(self):
        self._cur_node = self.__head.next
        return self

    def __next__(self):
        if not self._cur_node:
            raise StopIteration()
        key, value = self._cur_node.key, self._cur_node.value
        self._cur_node = self._cur_node.next
        return (key, value)


class HashMap:
    SCALE_FACTOR = 2
    SHRINKAGE_THRESHOLD = 4
    PRIME_NUMBER = (1 << 31) - 1
    def __init__(self, capacity=16):
        self.__arr = [HashMapLinkedList() for _ in range(capacity)]
        self.__capacity = capacity
        self.__num_items = 0
        self.__param1 = randint(0, self.PRIME_NUMBER - 1)
        self.__param2 = randint(0, self.PRIME_NUMBER - 1)

    def __repr__(self) -> str:
        kv_pairs = [kv_pair for linked_list in self.__arr for kv_pair in linked_list]
        return "{" + ", ".join((str(key) if type(key) != str else "'" + key + "'") \
            + ": " + str(value) for key, value in kv_pairs) + "}"

    def __len__(self) -> int:
        return self.__num_items

    def _range_hash(self, prehash):
        """
        Converts an arbitrary integer to an integer within [0, self.__capacity).
        """
        return (self.__param1 * prehash + self.__param2) % self.__capacity
    
    def _resize(self, enlarge=True):
        if enlarge:
            self.__capacity *= self.SCALE_FACTOR
        else:
            self.__capacity //= self.SCALE_FACTOR
        new_arr = [HashMapLinkedList() for _ in range(self.__capacity)]
        for linked_list in self.__arr:
            for key, value in linked_list:
                new_idx = self._range_hash(hash(key))
                new_arr[new_idx].insert(key, value)
        self.__arr = new_arr

    def insert(self, key, value):
        """
        Inserts an item whose key and value are key and value.
        """
        idx = self._range_hash(hash(key))
        self.__num_items += self.__arr[idx].insert(key, value)
        # When #items becomes the capacity, double the capacity.
        if self.__num_items == self.__capacity:
            self._resize(enlarge=True)

    def __setitem__(self, key, value):
        self.insert(key, value)

    def find(self, key):
        """
        Find the corresponding value given a key.
        """
        idx = self._range_hash(hash(key))
        node = self.__arr[idx].find(key)
        return node.value

    def __getitem__(self, key):
        return self.find(key)
    
    def __contains__(self, key):
        try:
            self.find(key)
            return True
        except ValueError:
            return False

    def delete(self, key):
        """
        Delete the item whose key is key.
        """
        idx = self._range_hash(hash(key))
        self.__arr[idx].delete(key)
        self.__num_items -= 1
        # When #items is less than or equal to the capacity, halve the capacity.
        if self.__num_items * self.SHRINKAGE_THRESHOLD <= self.__capacity:
            self._resize(enlarge=False)

    def __delitem__(self, key):
        self.delete(key)
    
    def keys(self):
        for linked_list in self.__arr:
            for k, _ in linked_list:
                yield k
    
    def values(self):
        for linked_list in self.__arr:
            for _, v in linked_list:
                yield v
    
    def items(self):
        for linked_list in self.__arr:
            for k, v in linked_list:
                yield (k, v)


N = int(input())
counter = HashMap()

for _ in range(N):
    s = input()
    if s not in counter:
        counter[s] = 1
    else:
        counter[s] += 1

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

max_profit = 0
for profit in counter.values():
    max_profit = max(max_profit, profit)
print(max_profit)

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:
    yen = s.count(i) - t.count(i)
    if ans <= yen:
        ans = yen

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

c = Counter()
N = int(input())
for _ in range(N):
    s = input()
    c[s] += 1
M = int(input())
for _ in range(M):
    s = input()
    c[s] -= 1
print(max(list(c.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)]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter


def solve(string):
    n, *rest = string.split()
    n = int(n)
    count = Counter(rest[:n])
    m = rest[n]
    count -= Counter(rest[n + 1:])
    return str(max(max(count.values()), 0)) if len(count) > 0 else "0"


if __name__ == '__main__':
    n = int(input())
    ins = '{}\n'.format(n) + '\n'.join([input() for _ in range(n)])
    m = int(input())
    print(solve(ins + '\n{}\n'.format(m) + '\n'.join([input() for _ in range(m)])))

Submission status: Accepted

Solution code:
def solve(string):
    count = dict([])
    n, *rest = string.split()
    n = int(n)
    blues = rest[:n]
    m = rest[n]
    reds = rest[n + 1:]
    for key in blues:
        if key in count:
            count[key] += 1
        else:
            count[key] = 1
    for key in reds:
        if key in count:
            count[key] -= 1
        else:
            count[key] = -1
    num = 0
    for k, v in count.items():
        if num < v:
            num = v
    return str(num)


if __name__ == '__main__':
    n = int(input())
    ins = '{}\n'.format(n) + '\n'.join([input() for _ in range(n)])
    m = int(input())
    print(solve(ins + '\n{}\n'.format(m) + '\n'.join([input() for _ in range(m)])))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

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

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

s_counter = collections.Counter(s)
t_counter = collections.Counter(t)

x_max = 0
for n in s_counter.keys():
    x_max = max(x_max, s_counter[n] - t_counter[n])

print(x_max)

Submission status: Accepted

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

result = {}
for s in ss:
    if not s in result:
        result[s] = 0
    result[s] += 1
for t in ts:
    if not t in result:
        result[t] = 0
    result[t] -= 1
ans = max(0, max(result.values()))

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
blue={}
for _ in range(N):
    s=input()
    if s in blue.keys():
        blue[s]+=1
    else:
        blue[s]=1
M=int(input())
red={}
for _ in range(M):
    t=input()
    if t in red.keys():
        red[t]+=1
    else:
        red[t]=1
ans=0
for k in blue.keys():
    tmp=blue[k]
    if k in red.keys():
        tmp-=red[k]
    ans=max(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

N = int(input())
d1 = defaultdict(int)
d2 = defaultdict(int)
for i in range(N):
    d1[input()] += 1
M = int(input())
for i in range(M):
    d2[input()] += 1
ans = []
for x in d1:
    ans.append(d1[x]-d2[x])
print(max(max(ans), 0))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N = int(lines.pop(0))
    NLIST = {}
    for i in range(N):
        s = lines.pop(0)
        if s in NLIST:
            NLIST[s] += 1
        else:
            NLIST[s] = 1

    M = int(lines.pop(0))
    for i in range(M):
        s = lines.pop(0)
        if s in NLIST:
            NLIST[s] -= 1
        else:
            NLIST[s] = -1
    print(max(max(NLIST.values()), 0))

lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

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

Submission status: Accepted

Solution code:
import numpy as np
from collections import Counter
ans=[]
N=int(input())
a=Counter([input() for _ in range(N)])
M=int(input())
b=Counter([input() for _ in range(M)])
for k, v in a.items():
  if k in b.keys():
    ans.append(v-b[k])
  else:
    ans.append(v)
print(max(0, *ans))

Submission status: Accepted

Solution code:
# /usr/bin/python
# -*- coding: utf-8 -*-
#
import sys

s = {}
t = {}
for _ in range(int(input())):
  st = str(input())
  if st not in s:
    s[st] = 1
  else:
    s[st] += 1
for _ in range(int(input())):
  st = str(input())
  if st not in t:
    t[st] = 1
  else:
    t[st] += 1


ans = 0
for st in s:
  if st not in t:
    ans = max(ans,s[st])
  else:
    ans = max(ans,s[st]-t[st])

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
dic={}
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):
    s=input()
    if s in dic:
        dic[s]-=1
print(max(max(dic.values()),0))

Submission status: Accepted

Solution code:
N=int(input())
words={}
for i in range(N):
  c = input()
  if c not in words:
    words[c]=1
  else:
    words[c]+=1
M=int(input())
for i in range(M):
  c = input()
  if c not in words:
    words[c]=-1
  else:
    words[c]-=1
print(max(0,max(list(words.values()))))

Submission status: Accepted

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

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


max_count = 0
for (k, v) in gain_set.items():
    c = lose_set[k]
    d = v - c
    if max_count < d:
        max_count = d

print(max_count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

N = np.int(input())
slist = [input() for _ in range(N)]
M = np.int(input())
tlist = [input() for _ in range(M)]
sslist = np.array(list(set(slist)))
number = np.zeros(len(sslist))
for i in range(len(sslist)):
    number[i] = np.sum(slist.count(sslist[i])) - np.sum(tlist.count(sslist[i]))
answer = np.int(np.max(number))  
print(np.max((answer, 0)))

Submission status: Accepted

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

ans = 0

card = set(s + t)

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

print(ans)

Submission status: Accepted

Solution code:
import collections
l = collections.Counter()
n = int(input())
for i in range(n):
    k = input()
    l[k] += 1
n = int(input())
for i in range(n):
    k = input()
    l[k] -= 1
l = l.most_common()
print(l[0][1] if l[0][1] >= 0 else 0)

Submission status: Accepted

Solution code:
import collections

n = int(input())
blueCards = [input() for i in range(n)]
blueCards = collections.Counter(blueCards)
m = int(input())
redCards = [input() for i in range(m)]
redCards = collections.Counter(redCards)

diff = blueCards - redCards
print(diff.most_common()[0][1]) if diff else print(0)

Submission status: Accepted

Solution code:
N = int(input())
s = sum([input().split() for _ in range(N)],[])
M = int(input())
t = sum([input().split() for _ in range(M)],[])
getmax = 0

for i in range(N):
    tmp = s.count(s[i])-t.count(s[i])
    if tmp > getmax:
        getmax = tmp

print(max(getmax,0))

Submission status: Accepted

Solution code:
#91B
n = int(input())
s = list(map(str,[input() for i in range(n)]))
m = int(input())
t = list(map(str,[input() for i in range(m)]))
answer = 0

for i in range(n):
	aka = s.count(s[i])
	ao = t.count(s[i])
	answer = max(answer, (aka-ao))
print(answer)

Submission status: Accepted

Solution code:
n=int(input())
a=[]
b=[]
c=[0]
for i in range(n):
    a.append(input())
m=int(input())
for i in range(m):
    b.append(input())
for d in a:
    ans=a.count(d)-b.count(d)
    c.append(ans)
print(max(c))

Submission status: Accepted

Solution code:
n = int(input()) 
s = []
t = []

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

for i in range(m):
	t.append(input())
    
max = 0

for i in range(n):
	k = s.count(s[i]) - t.count(s[i])
	if max < k:
		max = k
        
print(max)

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

# 処理
D = {}
for i in range(N):
  if s[i] in D.keys():  # 辞書Dに文字列s[i]が含まれる
    D[s[i]] += 1
  else:                 # 辞書Dに文字列s[i]が含まれない
    D[s[i]] = 1
    
for i in range(M):
  if t[i] in D.keys():  # 辞書Dに文字列t[i]が含まれる
    D[t[i]] -= 1
  
ans = 0  # 答え
for v in D.values():  # 辞書Dの値の集合を全て調べる
  ans = max(ans, v)

# 出力
print(ans)

Submission status: Accepted

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

max_score = 0
for s_ in s:
    score = s.count(s_) - t.count(s_)
    if score > max_score:
        max_score = score

print(max_score)

Submission status: Accepted

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

S = set(s)
T = set(t)
cands = []

for i in S:
    cands.append(s.count(i)-t.count(i))

print(max(max(cands), 0))

Submission status: Accepted

Solution code:
from collections import Counter

lst1 = [input() for _ in range(int(input()))]
lst2 = [input() for _ in range(int(input()))]

c = Counter(lst1)
c.subtract(Counter(lst2))
n = max(c.values())
print(max(0, n))

Submission status: Accepted

Solution code:
import collections
import itertools
import numpy as np
import sys
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


N = I()
s = [S() for i in range(N)]
M = I()
t = [S() for i in range(M)]
dic = {}

for i in s:
    if i not in dic:
        dic[i] = 1
    else:
        dic[i] += 1

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


cnt = list(dic.values())
cnt.sort()
if cnt == "" or cnt[-1] < 0:
    print(0)
else:
    print(cnt[-1])

Submission status: Accepted

Solution code:
n=int(input())
hoge=[]
for i in range(n):
  hoge.append(input())
m=int(input())
huga=[]
for i in range(m):
  huga.append(input())
ans=[]
ans.append(0)
for i in range(len(hoge)):
  ans.append(hoge.count(hoge[i])-huga.count(hoge[i]))

print(max(ans))

Submission status: Accepted

Solution code:
def two_color_card_games(N: int, S: list, M: int, T: list) -> int:
    # default おこずかいを失う言葉しかない場合は、何も言わない。
    d = {'': 0}
    for s in S:
        d.setdefault(s, 0)
        d[s] += 1

    for t in T:
        d.setdefault(t, 0)
        d[t] -= 1

    return max(d.values())


if __name__ == "__main__":
    N = int(input())
    S = [input() for _ in range(N)]
    M = int(input())
    T = [input() for _ in range(M)]
    ans = two_color_card_games(N, S, M, T)
    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 set(s):
  count = max(count, s.count(i)-t.count(i))
print(count)

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)])
a=[]
for i in range(len(s)):
    a.append(s.count(s[i])-t.count(s[i]))
a.sort()
print(max(0,a[-1]))

Submission status: Accepted

Solution code:
N = int(input())
card = {}
for i in range(N):
    temp = input()
    if temp in card:
        card[temp] += 1
    else:
        card[temp] = 1
M = int(input())
for i in range(M):
    temp = input()
    if temp in card:
        card[temp] -= 1

vals = card.values()
print(str(max(0, max(vals))))

Submission status: Accepted

Solution code:
import collections
N = int(input())
Ss= [input() for i in range(N)]
M = int(input())
Mm = [input() for i in range(M)]
Scounter = collections.Counter(Ss)
Mcounter = collections.Counter(Mm)
Ansdic = {}
for s,value in Scounter.items():
    if s not in Ansdic:
        Ansdic[s]=value
    else:
        Ansdic[s]+=value
for m,value in Mcounter.items():
    if m not in Ansdic:
        Ansdic[m]=-value
    else:
        Ansdic[m]-=value
print(max(0,max(Ansdic.values())))

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

Submission status: Accepted

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

M = int(input())
for i in range(M):
  t = input()
  if(t in dic_t):
    dic_t[t] += 1
  else:
    dic_t[t] = 1
  if(t in dic_s):
    dummy = 0
  else:
    dic_s[t] = 0
    all_str.append(t)
 
point = []
for i in range(len(all_str)):
  point.append(dic_s[all_str[i]] - dic_t[all_str[i]])
if(max(point)<=0):
  print(0)
else:
  print(max(point))

Submission status: Accepted

Solution code:
N = int(input())
blue = [input() for i in range(N)]
M = int(input())
red = [input() for i in range(M)]
blue_dict = {}
red_dict = {}
for s in blue:
    if s not in blue_dict:
        blue_dict[s] = 1
    else:
        blue_dict[s] += 1

for t in red:
    if t not in red_dict:
        red_dict[t] = 1
    else:
        red_dict[t] += 1

ans = 0
for key in blue_dict:
    if key in red_dict:
        ans = max(ans, blue_dict[key] - red_dict[key])
    else:
        ans = max(ans, blue_dict[key])
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)]

v = 0
for s in set(S):
    v = max(v, S.count(s)-T.count(s))
print(v)

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

Submission status: Accepted

Solution code:
s = []
t = []

N = int(input())
for i in range(N):
    s.append(input())

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

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

print(count)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc091/tasks/abc091_b

import itertools
import collections
import bisect

def main():
    N = int(input())
    S = [input() for _ in range(N)]
    sc = collections.Counter(S)
    M = int(input())
    T = [input() for _ in range(M)]
    tc = collections.Counter(T)

    ans = 0
    for item in sc.items():
        ans = max(ans, item[1] - tc[item[0]])
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict


def main():
    N = int(input())
    d = defaultdict(lambda: 0)
    for _ in range(N):
        s = input()
        d[s] += 1
    M = int(input())
    for _ in range(M):
        s = input()
        d[s] -= 1
    print(max(list(d.values()) + [0]))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())
S = {}
for _ in range(N):
    s = input()
    if s not in S:
        S[s] = 0
    S[s] += 1
M = int(input())
for _ in range(M):
    s = input()
    if s not in S:
        S[s] = 0
    S[s] -= 1
T = list(S.values())
T.append(0)
print(max(T))

Submission status: Accepted

Solution code:
import collections
n = int(input())
s = []
for i in range(n):
	s.append(input())
m = int(input())
t = []
for i in range(m):
	t.append(input())
cs = collections.Counter(s)
ct = collections.Counter(t)
ans = []
for i in range(len(cs)):
	for j in range(len(ct)):
		if cs.most_common()[i][0] == ct.most_common()[j][0]:
			ans.append([cs.most_common()[i][1] - ct.most_common()[j][1], cs.most_common()[i][0]])
			break
	if cs.most_common()[i][0] not in ct.keys():
		ans.append([cs.most_common()[i][1], cs.most_common()[i][0]])
ans.sort(reverse=True)
if ans[0][0] <= 0:
	print(0)
else:
	print(ans[0][0])

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:
    Dic[s] = Dic.get(s,0) + 1
for t in T:
    Dic[t] = Dic.get(t,0) - 1
             
print(max(max(Dic.values()),0))

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    S = [str(input().strip()) for _ in range(N)]
    M = int(input())
    T = [str(input().strip()) for _ in range(M)]

    ans = 0
    for s in S:
        cur = sum([s == a for a in S]) - sum([s == b for b in T])
        ans = max(ans, cur)
    print(ans)

if __name__ == '__main__':
    main()

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())
maximam=0
for i in blue:
    b=blue.count(i)
    r=red.count(i)
    maximam=max(maximam,b-r)
print(maximam)