You are given array $a$ of length $n$. You can choose one segment $[l, r]$ ($1 \le l \le r \le n$) and integer value $k$ (positive, negative or even zero) and change $a_l, a_{l + 1}, \dots, a_r$ by $k$ each (i.e. $a_i := a_i + k$ for each $l \le i \le r$).

What is the maximum possible number of elements with value $c$ that can be obtained after one such operation?


-----Input-----

The first line contains two integers $n$ and $c$ ($1 \le n \le 5 \cdot 10^5$, $1 \le c \le 5 \cdot 10^5$) — the length of array and the value $c$ to obtain.

The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 5 \cdot 10^5$) — array $a$.


-----Output-----

Print one integer — the maximum possible number of elements with value $c$ which can be obtained after performing operation described above.


-----Examples-----
Input
6 9
9 9 9 9 9 9

Output
6

Input
3 2
6 2 6

Output
2



-----Note-----

In the first example we can choose any segment and $k = 0$. The array will stay same.

In the second example we can choose segment $[1, 3]$ and $k = -4$. The array will become $[2, -2, 2]$.

Difficulty: HARD

Solutions:
import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] > k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

class TrieNode:

	def __init__(self):
		self.children = [None] * 26
		self.isEndOfWord = False

class Trie:

	def __init__(self):
		self.root = self.getNode()

	def getNode(self):
		return TrieNode()

	def _charToIndex(self, ch):
		return ord(ch) - ord('a')

	def insert(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				pCrawl.children[index] = self.getNode()
			pCrawl = pCrawl.children[index]
		pCrawl.isEndOfWord = True

	def search(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				return False
			pCrawl = pCrawl.children[index]
		return pCrawl != None and pCrawl.isEndOfWord

class Node:

	def __init__(self, data):
		self.data = data
		self.count = 0
		self.left = None
		self.right = None

class BinaryTrie:

	def __init__(self):
		self.root = Node(0)

	def insert(self, pre_xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = pre_xor & 1 << i
			if val:
				if not self.temp.right:
					self.temp.right = Node(0)
				self.temp = self.temp.right
				self.temp.count += 1
			if not val:
				if not self.temp.left:
					self.temp.left = Node(0)
				self.temp = self.temp.left
				self.temp.count += 1
		self.temp.data = pre_xor

	def query(self, xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = xor & 1 << i
			if not val:
				if self.temp.left and self.temp.left.count > 0:
					self.temp = self.temp.left
				elif self.temp.right:
					self.temp = self.temp.right
			elif self.temp.right and self.temp.right.count > 0:
				self.temp = self.temp.right
			elif self.temp.left:
				self.temp = self.temp.left
			self.temp.count -= 1
		return xor ^ self.temp.data
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
a = defaultdict(list)
c = [0] * (n + 1)
for i in range(n):
	a[l[i] - 1].append(i + 1)
	if l[i] == k:
		c[i + 1] = 1
for i in range(1, n + 1):
	c[i] += c[i - 1]

def find():
	ans = c[n]
	for i in a:
		if i == k - 1:
			continue
		st = a[i][0]
		cou = 1
		if i != k - 1 and len(a[i]) >= 1:
			ans = max(ans, c[n] + 1)
		ans = max(ans, len(a[i]))
		for j in range(1, len(a[i])):
			cou += 1
			ans = max(ans, cou - c[a[i][j]] + c[st - 1] + c[n])
			if cou - c[a[i][j]] + c[st - 1] <= 0:
				st = a[i][j]
				cou = 1
	print(ans)
find()


import os, sys
from io import BytesIO, IOBase
from collections import defaultdict, Counter
from copy import deepcopy

def main():
	(n, c) = map(int, input().split())
	a = list(map(int, input().split()))
	nums = defaultdict(lambda : [0])
	(freq, minus) = (Counter(), 0)
	for i in a:
		if i == c:
			minus += 1
		else:
			freq[i] += 1
			nums[i].append(freq[i] - minus)
	tot = minus
	suff = deepcopy(nums)
	for i in nums:
		for j in range(len(nums[i]) - 2, 0, -1):
			suff[i][j] = max(suff[i][j], suff[i][j + 1])
	(freq, ans) = (Counter(), tot)
	for i in a:
		if i == c:
			continue
		freq[i] += 1
		ans = max(ans, suff[i][freq[i]] - nums[i][freq[i]] + 1 + tot)
	print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from collections import Counter
(n, c) = map(int, input().split())
a = list(map(int, input().split()))
counter = Counter()
minus = 0
count = a.count(c)
maxi = 0
for i in range(n):
	if a[i] != c:
		if counter[a[i]] < minus:
			counter[a[i]] = minus
		counter[a[i]] += 1
		maxi = max(maxi, counter[a[i]] + count - minus)
	else:
		minus += 1
print(max(maxi, minus))


(n, c) = map(int, input().split(' '))
nums = list(map(int, input().split(' ')))
cPast = 0
countC = 0
for value in nums:
	if value == c:
		countC += 1

def sawC(groupsList):
	for (key, groups) in groupsList.items():
		if groups[-1] < 0:
			groups[-1] -= 1
		else:
			groups += [-1]
	return groupsList
solution = countC
groupsList = {}
for num in nums:
	if num == c:
		groupsList = sawC(groupsList)
	elif num in groupsList.keys():
		if groupsList[num][-1] > 0:
			groupsList[num][-1] += 1
		else:
			groupsList[num] += [1]
	else:
		groupsList[num] = [1]
for (key, groups) in groupsList.items():
	maxDiff = 1
	currDiff = 0
	newDiff = 0
	for group in groups:
		currDiff += group
		if group > currDiff:
			currDiff = group
		if currDiff > maxDiff:
			maxDiff = currDiff
	if maxDiff + countC > solution:
		solution = countC + maxDiff
print(solution)


(n, tar) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
from collections import defaultdict
d = defaultdict(lambda : [])
count = 0
for i in range(n):
	d[a[i]].append(i)
	if a[i] == tar:
		count += 1
presum = [1 if a[0] == tar else 0]
for e in a[1:]:
	if e == tar:
		presum.append(presum[-1] + 1)
	else:
		presum.append(presum[-1])
final = 0
for (k, v) in d.items():
	if k == tar:
		continue
	t = 1
	tt = 1
	for i in range(1, len(v)):
		ind = v[i]
		preind = v[i - 1]
		t -= presum[ind] - presum[preind]
		t = max(t, 0)
		t += 1
		tt = max(tt, t)
	final = max(final, tt)
print(final + count)


t = list(map(int, input().split()))
n = t[0]
c = t[1]
a = list(map(int, input().split()))
f = []
for i in range(0, 500001):
	f.append(0)
l = []
for i in range(0, 500001):
	l.append([0])
m = 0
for i in range(n):
	l[a[i]].append(f[a[i]] - m)
	if a[i] == c:
		m += 1
	f[a[i]] += 1
	l[a[i]].append(f[a[i]] - m)
ma = 0
for i in l:
	mi = 0
	for j in i:
		if j < mi:
			mi = j
		if ma < j - mi:
			ma = j - mi
print(m + ma)


import os
import sys
from io import BytesIO, IOBase

def solve(x):
	(mas, ma) = (0, 0)
	for i in range(len(x)):
		mas += x[i]
		if mas <= 0:
			mas = 0
		ma = max(ma, mas)
	return ma

def main():
	(n, c) = map(int, input().split())
	a = list(map(int, input().split()))
	(ma, dp) = (max(a) + 1, [0] * (n + 1))
	b = [[] for _ in range(ma + 1)]
	for (i, v) in enumerate(a):
		b[v].append(i)
		dp[i + 1] += dp[i]
		if v == c:
			dp[i + 1] += 1
	maa = 0
	for i in range(1, ma + 1):
		if b[i] and i != c:
			z = b[i]
			(mas, mi) = (1, 1)
			for j in range(1, len(z)):
				mas += -(dp[z[j] + 1] - dp[z[j - 1]])
				if mas <= 0:
					mas = 0
				mi = max(mi, mas)
				mas += 1
				if mas <= 0:
					mas = 0
				mi = max(mi, mas)
			maa = max(maa, mi)
	print(dp[n] + maa)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, c) = list(map(int, input().split()))
res1 = [0] * 500001
res = 0
for ai in map(int, input().split()):
	res1[ai] = max(res1[ai], res1[c])
	res1[ai] += 1
	res = max(res, res1[ai] - res1[c])
print(res + res1[c])


(length, target) = [int(i) for i in input().strip().split()]
array = [1000000000000] + [int(i) for i in input().strip().split()]
num_dict = dict()
(up, down, pre, dp) = ([], [], dict(), [0 for i in range(length + 1)])
index = 0
ans = 0
for i in range(length + 1):
	if array[i] == target:
		index += 1
		up.append(index)
	else:
		up.append(index)
index = 0
for i in range(length, -1, -1):
	if array[i] == target:
		index += 1
		down.append(index)
	else:
		down.append(index)
down.reverse()
down.append(0)
for i in range(1, length + 1):
	if array[i] not in pre:
		pre[array[i]] = 0
	dp[i] = max(up[i - 1] + 1, dp[pre[array[i]]] + 1)
	pre[array[i]] = i
	ans = max(ans, dp[i] + down[i + 1])
print(ans)


(n, c) = list(map(int, input().split()))
cnt = [0] * 500005
ans = 0
for v in map(int, input().split()):
	if v == c:
		cnt[c] = cnt[c] + 1
	else:
		if cnt[v] < cnt[c]:
			cnt[v] = cnt[c]
		cnt[v] += 1
	ans = max(ans, cnt[v] - cnt[c])
print(ans + cnt[c])


def maxseg(a):
	cur_max = 0
	global_max = 0
	pre_ = 0
	for (i, x) in enumerate(a):
		if x > 0:
			cur_max = max(x, cur_max + pre_ + x)
			global_max = max(global_max, cur_max)
		else:
			pre_ = x
	return global_max

def push(d, u, i):
	if u not in d:
		d[u] = []
	d[u].append(i)

def get_sum(a, l, r):
	if l == 0:
		return a[r]
	return a[r] - a[l - 1]

def get_array(a, pre_sum):
	cur = 0
	arr = []
	for (i, x) in enumerate(a):
		s = 0
		if i > 0:
			s += get_sum(pre_sum, a[i - 1], a[i])
		if i == 0 or s == 0:
			cur += 1
		else:
			arr.append(cur)
			arr.append(-s)
			cur = 1
	arr.append(cur)
	return arr
(n, c) = map(int, input().split())
a = list(map(int, input().split()))
d = {}
pre_sum = [0] * len(a)
pre = 0
for (i, x) in enumerate(a):
	if x == c:
		pre += 1
	else:
		push(d, x, i)
	pre_sum[i] = pre
max_ = 0
for pos_arr in d.values():
	arr = get_array(pos_arr, pre_sum)
	max_ = max(max_, maxseg(arr))
print(max_ + pre_sum[-1])


(n, val) = map(int, input().split())
a = [0] + list(map(int, input().split()))
suma = [0 for i in range(n + 1)]
mx = 0
target = 0
for i in range(1, n + 1):
	suma[i] = suma[i - 1]
	mx = max(mx, a[i])
	if a[i] == val:
		target += 1
		suma[i] += 1
ans = 0
pre = [0 for i in range(mx + 1)]
dp = [0]
for i in range(1, n + 1):
	dp.append(max(1, 1 + dp[pre[a[i]]] - suma[i] + suma[pre[a[i]]]))
	if a[i] != val:
		ans = max(ans, dp[i])
	pre[a[i]] = i
print(ans + target)


k = [*map(int, input().split())]
list1 = [*map(int, input().split())]
z = [0] * 500001
o = 0
for i in list1:
	z[i] = max(z[i], z[k[1]])
	z[i] += 1
	o = max(o, z[i] - z[k[1]])
print(o + z[k[1]])


(n, c) = list(map(int, input().split()))
a = list(map(int, input().split()))
nc = 0
last = {}
preconfs = []
preconfc = []
for i in range(n):
	if a[i] == c:
		nc += 1
		last[c] = i
		preconfs.append(i)
	else:
		if not a[i] in last:
			preconfs.append(1)
		else:
			preconfs.append(preconfs[last[a[i]]] + 1)
		last[a[i]] = i
	preconfc.append(nc)
content = {}
for i in range(n):
	if a[i] in content:
		content[a[i]][0] += 1
		content[a[i]].append(i)
	else:
		content[a[i]] = [1, i]

def val(i, j):
	if a[i] == a[j]:
		return nc + (preconfs[j] - preconfs[i] + 1) - (preconfc[j] - preconfc[i]) + (a[i] == c and -1 or 0)
	print('erreur')

def rec_sol(i, j, tab):
	if i == j:
		return (i, i, j, j)
	k = (i + j) // 2
	r1 = rec_sol(i, k, tab)
	r2 = rec_sol(k + 1, j, tab)
	i1 = max([r1[0], r2[0]], key=lambda x: val(tab[x], tab[j]))
	(i2, i3) = max([(r1[0], r2[3]), (r1[1], r1[2]), (r2[1], r2[2]), (r1[0], j)], key=lambda x: val(tab[x[0]], tab[x[1]]))
	i4 = max([r1[3], r2[3]], key=lambda x: val(tab[i], tab[x]))
	return (i1, i2, i3, i4)

def get_sol(k):
	s = rec_sol(1, content[k][0], content[k])
	return val(content[k][s[1]], content[k][s[2]])
res = []
for i in content:
	if i != c:
		res.append(get_sol(i))
if res:
	print(max(res))
else:
	print(n)


(n, c) = map(int, input().split())
ans = [0] * 500001
res = 0
for i in map(int, input().split()):
	ans[i] = max(ans[i], ans[c])
	ans[i] += 1
	res = max(res, ans[i] - ans[c])
print(res + ans[c])


import math
(n, c) = map(int, input().split())
a = list(map(int, input().split()))
mex = 500001
occurences = [[] for _ in range(mex)]
C = []

def noc(ind):
	(start, end, id) = (0, len(C) - 1, -1)
	while start <= end:
		mid = (start + end) // 2
		if C[mid] < ind:
			id = mid
			start = mid + 1
		else:
			end = mid - 1
	return id + 1
total_c = a.count(c)
for (i, e) in enumerate(a):
	if e == c:
		C.append(i)
	else:
		occurences[e].append(i)
ans = total_c
for l in occurences:
	mn = math.inf
	for (i, e) in enumerate(l):
		Oc = noc(e)
		mn = min(mn, i - Oc)
		ans = max(ans, i - Oc - mn + total_c + 1)
print(ans)


import sys
from array import array
import typing as Tp

def input():
	return sys.stdin.buffer.readline().decode('utf-8')

def main():
	from collections import Counter
	(n, c) = map(int, input().split())
	a = list(map(int, input().split()))
	c_cnt = ans = a.count(c)
	counter = Counter()
	minus = 0
	for x in a:
		if x != c:
			if counter[x] < minus:
				counter[x] = minus
			counter[x] += 1
			ans = max(ans, counter[x] + c_cnt - minus)
		else:
			minus += 1
	print(ans)
main()


import os
import sys
import math
from io import BytesIO, IOBase
import io
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree1:

	def __init__(self, data, default=10 ** 6, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)
MOD = 10 ** 9 + 7

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod = 10 ** 9 + 7
omod = 998244353

class LazySegTree:

	def __init__(self, _op, _e, _mapping, _composition, _id, v):

		def set(p, x):
			assert 0 <= p < _n
			p += _size
			for i in range(_log, 0, -1):
				_push(p >> i)
			_d[p] = x
			for i in range(1, _log + 1):
				_update(p >> i)

		def get(p):
			assert 0 <= p < _n
			p += _size
			for i in range(_log, 0, -1):
				_push(p >> i)
			return _d[p]

		def prod(l, r):
			assert 0 <= l <= r <= _n
			if l == r:
				return _e
			l += _size
			r += _size
			for i in range(_log, 0, -1):
				if l >> i << i != l:
					_push(l >> i)
				if r >> i << i != r:
					_push(r >> i)
			sml = _e
			smr = _e
			while l < r:
				if l & 1:
					sml = _op(sml, _d[l])
					l += 1
				if r & 1:
					r -= 1
					smr = _op(_d[r], smr)
				l >>= 1
				r >>= 1
			return _op(sml, smr)

		def apply(l, r, f):
			assert 0 <= l <= r <= _n
			if l == r:
				return
			l += _size
			r += _size
			for i in range(_log, 0, -1):
				if l >> i << i != l:
					_push(l >> i)
				if r >> i << i != r:
					_push(r - 1 >> i)
			l2 = l
			r2 = r
			while l < r:
				if l & 1:
					_all_apply(l, f)
					l += 1
				if r & 1:
					r -= 1
					_all_apply(r, f)
				l >>= 1
				r >>= 1
			l = l2
			r = r2
			for i in range(1, _log + 1):
				if l >> i << i != l:
					_update(l >> i)
				if r >> i << i != r:
					_update(r - 1 >> i)

		def _update(k):
			_d[k] = _op(_d[2 * k], _d[2 * k + 1])

		def _all_apply(k, f):
			_d[k] = _mapping(f, _d[k])
			if k < _size:
				_lz[k] = _composition(f, _lz[k])

		def _push(k):
			_all_apply(2 * k, _lz[k])
			_all_apply(2 * k + 1, _lz[k])
			_lz[k] = _id
		_n = len(v)
		_log = _n.bit_length()
		_size = 1 << _log
		_d = [_e] * (2 * _size)
		_lz = [_id] * _size
		for i in range(_n):
			_d[_size + i] = v[i]
		for i in range(_size - 1, 0, -1):
			_update(i)
		self.set = set
		self.get = get
		self.prod = prod
		self.apply = apply
MIL = 1 << 20

def makeNode(total, count):
	return total * MIL + count

def getTotal(node):
	return math.floor(node / MIL)

def getCount(node):
	return node - getTotal(node) * MIL
nodeIdentity = makeNode(0.0, 0.0)

def nodeOp(node1, node2):
	return node1 + node2
	return makeNode(getTotal(node1) + getTotal(node2), getCount(node1) + getCount(node2))
identityMapping = -1

def mapping(tag, node):
	if tag == identityMapping:
		return node
	count = getCount(node)
	return makeNode(tag * count, count)

def composition(mapping1, mapping2):
	return mapping1 if mapping1 != identityMapping else mapping2
prime = [True for i in range(10)]
pp = [0] * 10

def SieveOfEratosthenes(n=10):
	p = 2
	c = 0
	while p * p <= n:
		if prime[p] == True:
			c += 1
			for i in range(p, n + 1, p):
				pp[i] += 1
				prime[i] = False
		p += 1

def binarySearch(arr, n, key):
	left = 0
	right = n - 1
	mid = 0
	res = arr[n - 1]
	while left <= right:
		mid = (right + left) // 2
		if arr[mid] >= key:
			res = arr[mid]
			right = mid - 1
		else:
			left = mid + 1
	return res

def binarySearch1(arr, n, key):
	left = 0
	right = n - 1
	mid = 0
	res = arr[0]
	while left <= right:
		mid = (right + left) // 2
		if arr[mid] > key:
			right = mid - 1
		else:
			res = arr[mid]
			left = mid + 1
	return res
(n, c) = map(int, input().split())
ans = [0] * 500001
res = 0
for i in map(int, input().split()):
	ans[i] = max(ans[i], ans[c])
	ans[i] += 1
	res = max(res, ans[i] - ans[c])
print(res + ans[c])


import sys
line = sys.stdin.readline().strip().split()
n = int(line[0])
c = int(line[1])
a = list(map(int, sys.stdin.readline().strip().split()))
cright = [0] * (n + 1)
maxfreq = [0] * (5 * 10 ** 5 + 1)
for i in range(0, n):
	if a[n - 1 - i] == c:
		cright[n - 1 - i] = cright[n - i] + 1
	else:
		cright[n - 1 - i] = cright[n - i]
result = cright[0]
cleft = 0
for i in range(0, n):
	if a[i] != c:
		maxfreq[a[i]] = max([maxfreq[a[i]], cleft]) + 1
	else:
		cleft = cleft + 1
	if maxfreq[a[i]] + cright[i + 1] > result:
		result = maxfreq[a[i]] + cright[i + 1]
print(result)


(n, c) = map(int, input().split())
A = list(map(int, input().split()))
freq = [0] * n
for i in range(n):
	if A[i] == c:
		freq[i] += 1
for i in range(1, n):
	freq[i] += freq[i - 1]

def F(i, j):
	return freq[j] - (freq[i - 1] if i >= 1 else 0)

def kadane(B):
	ans = cur = mn = 0
	for x in B:
		cur += x
		ans = max(cur - mn, ans)
		mn = min(mn, cur)
	return ans
prev = dict()
B = dict()
for i in range(n):
	if A[i] not in B:
		B[A[i]] = []
	if A[i] in prev:
		B[A[i]].append(-F(prev[A[i]] + 1, i - 1))
	prev[A[i]] = i
	B[A[i]].append(1)

def solve_case(A, x):
	ans = kadane(B[x])
	return freq[-1] + ans
ans = freq[-1]
for x in set(A):
	if x == c:
		continue
	case = solve_case(A, x)
	ans = max(ans, case)
print(ans)


line = input().split()
n = int(line[0])
c = int(line[1])
line = [int(x) for x in input().split()]
base_ans = 0
for num in line:
	if num == c:
		base_ans += 1
lut = {}
best_delta = 0
for num in line:
	if num == c:
		to_delete = []
		for key in lut:
			lut[key] -= 1
			if lut[key] <= 0:
				to_delete.append(key)
		for key in to_delete:
			del lut[key]
	else:
		if num in lut:
			lut[num] += 1
		else:
			lut[num] = 1
		if lut[num] >= best_delta:
			best_delta = lut[num]
print(base_ans + best_delta)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')
from math import factorial
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def main():
	(n, c) = RL()
	arr = RLL()
	cnum = arr.count(c)
	dic = defaultdict(int)
	cnow = 0
	res = 0
	for i in range(n):
		if arr[i] == c:
			cnow += 1
		else:
			if dic[arr[i]] < cnow:
				dic[arr[i]] = cnow
			dic[arr[i]] += 1
			res = max(res, dic[arr[i]] - cnow)
	print(res + cnum)
main()


(n, c) = map(int, input().split())
a = [0]
a.extend([int(i) for i in input().split()])
cntc = [0]
seg = {}
last = {}
for i in range(1, n + 1):
	cntc.append(cntc[i - 1] + (1 if a[i] == c else 0))

def getcntc(left, right):
	return cntc[right] - cntc[left - 1]
for i in range(1, n + 1):
	seg.setdefault(a[i], []).append(-getcntc(last.setdefault(a[i], 0) + 1, i - 1))
	last[a[i]] = i
	seg[a[i]].append(1)
for key in seg:
	seg[key].append(-getcntc(last[key] + 1, n))
total = 0
m = max(a)
for d in range(1, m + 1):
	peak = 0
	ans = 0
	if d in seg and d != c:
		for s in seg[d]:
			ans = max(0, ans + s)
			peak = max(ans, peak)
		peak += getcntc(1, n)
	total = max(total, peak)
total = max(total, getcntc(1, n))
print(total)


(n, c) = map(int, input().split())
a = list(map(int, input().split()))
cs = 0
x = a.count(c)
best = [x] * 5000001
curr = [x] * 5000001
rec = [0] * 5000001
for i in range(n):
	if a[i] == c:
		cs += 1
	else:
		curr[a[i]] = max(x, curr[a[i]] + rec[a[i]] - cs) + 1
		best[a[i]] = max(best[a[i]], curr[a[i]])
		rec[a[i]] = cs
print(max(best))


import sys
input = sys.stdin.readline
(n, c) = map(int, input().split())
a = list(map(int, input().split()))
N = 5 * 10 ** 5 + 10
ans = [0] * N
res = 0
for aa in a:
	ans[aa] = max(ans[aa], ans[c])
	ans[aa] += 1
	res = max(res, ans[aa] - ans[c])
print(res + ans[c])


from collections import defaultdict

def solve():
	(N, C) = map(int, input().split())
	arr = [int(k) for k in input().split()]
	cnt = 0
	best = 0
	freq = defaultdict(int)
	for i in range(N):
		freq[arr[i]] = max(freq[arr[i]], freq[C])
		freq[arr[i]] += 1
		cur = freq[arr[i]] - freq[C]
		if cur > best:
			best = cur
	print(best + freq[C])
solve()


import sys
input = sys.stdin.readline
(n, c) = map(int, input().split())
ar = list(map(int, input().split()))
br = []
count = 0
for i in range(n):
	if ar[i] == c:
		count += 1
	br.append(count)
dic = {}
for i in range(n):
	if ar[i] != c:
		if ar[i] in dic:
			dic[ar[i]].append(i)
		else:
			dic[ar[i]] = [i]
ans = 0
for i in dic:
	le = len(dic[i])
	if le == 1:
		ans = max(ans, 1)
	else:
		ans = max(ans, 1)
		su = 0
		flag = False
		for j in range(1, le):
			r = dic[i][j]
			l = dic[i][j - 1]
			if flag:
				su += 1 - (br[r] - br[l])
			else:
				flag = True
				su += 2 - (br[r] - br[l])
			ans = max(ans, su)
			if su <= 0:
				flag = False
				su = 0
print(br[-1] + ans)