You are given an array $a$ consisting of $n$ integers. Let's denote monotonic renumeration of array $a$ as an array $b$ consisting of $n$ integers such that all of the following conditions are met:

  $b_1 = 0$;  for every pair of indices $i$ and $j$ such that $1 \le i, j \le n$, if $a_i = a_j$, then $b_i = b_j$ (note that if $a_i \ne a_j$, it is still possible that $b_i = b_j$);  for every index $i \in [1, n - 1]$ either $b_i = b_{i + 1}$ or $b_i + 1 = b_{i + 1}$. 

For example, if $a = [1, 2, 1, 2, 3]$, then two possible monotonic renumerations of $a$ are $b = [0, 0, 0, 0, 0]$ and $b = [0, 0, 0, 0, 1]$.

Your task is to calculate the number of different monotonic renumerations of $a$. The answer may be large, so print it modulo $998244353$.


-----Input-----

The first line contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) — the number of elements in $a$.

The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$).


-----Output-----

Print one integer — the number of different monotonic renumerations of $a$, taken modulo $998244353$.


-----Examples-----
Input
5
1 2 1 2 3

Output
2

Input
2
100 1

Output
2

Input
4
1 3 3 7

Output
4

Difficulty: MEDIUM_HARD

Solutions:
mod = 998244353
n = int(input())
a = list(map(int, input().split()))
poses = dict()
for i in range(n):
	poses[a[i]] = i
ans = 1
pos = 0
while pos < n:
	need = poses[a[pos]]
	while pos < n and pos <= need:
		need = max(need, poses[a[pos]])
		pos += 1
	ans += 1
ans -= 1
answer = 1
for i in range(ans - 1):
	answer = answer * 2 % mod
print(answer)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	last_pos = {}
	for i in range(n):
		last_pos[a[i]] = i
	(ret, cur) = (1, -1)
	for i in range(n - 1):
		cur = max(cur, last_pos[a[i]])
		if cur == i:
			ret = ret * 2 % 998244353
	print(ret)
main()


from bisect import bisect_left
mod = 998244353
n = int(input())
a = [int(x) for x in input().split()]
s = sorted(a)
a = [bisect_left(s, x) for x in a]
(first, last) = ([n] * n, [-1] * n)
for i in range(n):
	first[a[n - 1 - i]] = n - 1 - i
	last[a[i]] = i
ans = 1
cur = last[a[0]]
for i in range(n):
	if first[a[i]] == i:
		if i > cur:
			ans <<= 1
			if ans > mod:
				ans -= mod
		cur = max(cur, last[a[i]])
print(ans)


import os
import sys
from io import BytesIO, IOBase
import math
from queue import Queue
import collections
import itertools
import bisect
import heapq
import random

def main():
	pass
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 binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def primeFactors(n):
	cnt = []
	while n % 2 == 0:
		cnt.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			cnt.append(i)
			n = n / i
	if n > 2:
		cnt.append(int(n))
	return cnt

def primeFactorsCount(n):
	cnt = 0
	while n % 2 == 0:
		cnt += 1
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			cnt += 1
			n = n // i
	if n > 2:
		cnt += 1
	return cnt

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)

def countcon(s, i):
	c = 0
	ch = s[i]
	for i in range(i, len(s)):
		if s[i] == ch:
			c += 1
		else:
			break
	return c

def lis(arr):
	n = len(arr)
	lis = [1] * n
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] > arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
	maximum = 0
	for i in range(n):
		maximum = max(maximum, lis[i])
	return maximum

def isSubSequence(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m

def maxfac(n):
	root = int(n ** 0.5)
	for i in range(2, root + 1):
		if n % i == 0:
			return n // i
	return n

def p2(n):
	c = 0
	while n % 2 == 0:
		n //= 2
		c += 1
	return c

def seive(n):
	primes = [True] * (n + 1)
	primes[1] = primes[0] = False
	i = 2
	while i * i <= n:
		if primes[i] == True:
			for j in range(i * i, n + 1, i):
				primes[j] = False
		i += 1
	pr = []
	for i in range(0, n + 1):
		if primes[i]:
			pr.append(i)
	return pr

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def denofactinverse(n, m):
	fac = 1
	for i in range(1, n + 1):
		fac = fac * i % m
	return pow(fac, m - 2, m)

def numofact(n, m):
	fac = 1
	for i in range(1, n + 1):
		fac = fac * i % m
	return fac

def sod(n):
	s = 0
	while n > 0:
		s += n % 10
		n //= 10
	return s

def defaultDictDefaultVal():
	return -1
n = int(input())
l = list(map(int, input().split()))
pos = collections.defaultdict(defaultDictDefaultVal)
for i in range(0, n):
	pos[l[i]] = max(pos[l[i]], i)
seg = 0
lp = pos[l[0]]
for i in range(1, n):
	if i > lp:
		seg += 1
	lp = max(lp, pos[l[i]])
print(pow(2, seg, 998244353))


from sys import stdin
input = stdin.buffer.readline
mod = 998244353
n = int(input())
arr = [int(x) for x in input().split()]
d = {}
for i in range(n):
	if arr[i] in d:
		d[arr[i]].append(i)
	else:
		d[arr[i]] = [i]
i = 0
des = d[arr[0]][-1]
while i <= des:
	des = max(des, d[arr[i]][-1])
	i = i + 1
pos = i
ans = 1
start = pos
while start < n:
	i = start
	des = d[arr[start]][-1]
	while i <= des:
		des = max(des, d[arr[i]][-1])
		i = i + 1
	ans = ans * 2 % mod
	start = i
print(ans)


def readline():
	return map(int, input().split())

def main():
	(n,) = readline()
	a = list(readline())
	first_occurence = dict()
	magic = list()
	for (i, ai) in enumerate(a):
		fst = first_occurence.setdefault(ai, i)
		if fst == i:
			magic.append(None)
		else:
			magic.append(i + 1)
			j = fst + 1
			while j < i:
				new_j = magic[j] or j + 1
				magic[j] = i + 1
				j = new_j
	print(pow(2, magic.count(None) - 1, 998244353))
main()


from sys import stdin, stdout
from math import *
from heapq import *
from collections import *

def main():
	n = int(stdin.readline())
	a = [int(x) for x in stdin.readline().split()]
	b = [2] * (n + 2)
	maxR = {}
	minL = {}
	for i in range(n):
		x = a[i]
		maxR[x] = i
		minL[x] = minL.get(x, i)
	f = [0] * (n + 2)
	for i in range(n):
		x = a[i]
		l = minL[x]
		r = maxR[x]
		if l < r:
			if r == l - 1:
				b[r] = 1
			else:
				f[l + 1] = f[l + 1] + 1
				f[r + 1] = f[r + 1] - 1
	res = 1
	for i in range(1, n):
		f[i] = f[i] + f[i - 1]
		if f[i] > 0:
			b[i] = 1
		res = res * b[i] % 998244353
	stdout.write(str(res))
	return 0
main()


from collections import defaultdict as dc
n = int(input())
a = list(map(int, input().split()))
cn = 1
m = 998244353
hsh = dc(int)
hsh2 = dc(int)
for i in a:
	hsh[i] += 1
sm = 0
for i in range(n - 1):
	if hsh2[a[i]]:
		sm -= 1
	else:
		sm += hsh[a[i]] - 1
	hsh2[a[i]] += 1
	if sm == 0:
		cn *= 2
		cn %= m
print(cn)


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
m = 998244353
b = {}
for i in range(n):
	b[a[i]] = i
ma = b[a[0]]
ans = 1
for i in range(1, n):
	if i > ma:
		ans = ans * 2 % m
	ma = max(ma, b[a[i]])
print(ans)


n = int(input())
a = list(map(int, input().split()))
m = 998244353
b = {}
for i in range(n):
	b[a[i]] = i
ma = b[a[0]]
ans = 1
for i in range(1, n):
	if i > ma:
		ans = ans * 2 % m
	ma = max(ma, b[a[i]])
print(ans)


n = int(input())
m = list(map(int, input().split()))
pre = {}
suf = {}
for (i, e) in enumerate(m):
	suf[e] = i
for (i, e) in enumerate(reversed(m)):
	pre[e] = n - i - 1
a = []
for i in set(m):
	a.append((pre[i], suf[i]))
b = []
for (begin, end) in sorted(a):
	if b and b[-1][1] > begin - 1:
		b[-1][1] = max(b[-1][1], end)
	else:
		b.append([begin, end])
print(2 ** (len(b) - 1) % 998244353)


n = int(input())
a = tuple(map(int, input().split()))
d = dict()
for i in range(n):
	if a[i] not in d:
		d[a[i]] = [i, i]
	else:
		d[a[i]][1] = i
cur = 0
num = -1
for i in range(n):
	if d[a[i]][1] > cur:
		cur = d[a[i]][1]
	if cur == i:
		num += 1
print(pow(2, num, 998244353))


from collections import *
n = int(input())
l = list(map(int, input().split()))
rng = defaultdict(lambda : [-1, -1])
for i in range(n):
	val = l[i]
	if rng[val][0] == -1:
		rng[val] = [i, i]
	else:
		rng[val][1] = i
currRng = -1
tot = 0
for (i, j) in sorted(rng.values()):
	if i > currRng:
		tot += 1
	currRng = max(currRng, j)
print(pow(2, tot - 1, 998244353))


import heapq
import sys
input = sys.stdin.readline
M = 998244353
for _ in range(1):
	n = int(input())
	l = list(map(int, input().split()))
	arr = [0] * n
	arr[0] = 1
	d = {}
	for i in range(n):
		x = l[i]
		d[x] = i
	ans = 1
	limit = 0
	for i in range(n):
		x = l[i]
		if i > limit:
			ans = ans * 2 % M
			if x in d:
				limit = max(d[x], limit)
		else:
			limit = max(d[x], limit)
	print(ans)


mod = 998244353
n = int(input())
a = list(map(int, input().split()))
d = {}
for i in range(n):
	if a[i] not in d:
		d[a[i]] = (i, i)
	else:
		d[a[i]] = (d[a[i]][0], i)
d2 = {}
for (k, v) in list(d.items()):
	if v[0] != v[1]:
		d2[k] = v
(active, ans) = (0, 1)
for i in range(n - 1):
	if a[i] in d2:
		if i == d2[a[i]][0]:
			active += 1
		if i == d2[a[i]][1]:
			active -= 1
	if active == 0:
		ans = ans * 2 % mod
print(ans)


n = int(input())
a = list(map(int, input().split()))
d = {}
ans = 1
for i in range(n):
	d[a[i]] = i
mx = d[a[0]]
for i in range(1, n):
	if i > mx:
		ans = (ans << 1) % 998244353
	mx = max(mx, d[a[i]])
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
pos = {}
for i in range(n):
	pos[a[i]] = i
mod = 998244353
chunks = 0
start = 0
end = 0
while start < n:
	end = max(end, pos[a[start]])
	if end <= start:
		chunks += 1
	start += 1
print(pow(2, chunks - 1, mod))


from collections import defaultdict

def solve():
	n = int(input())
	A = [int(k) for k in input().split()]
	mod = 998244353
	freq = defaultdict(list)
	for i in range(n):
		freq[A[i]].append(i)
	C = []
	i = 0
	cache = set()
	while i < n:
		C.append(0)
		cache.add(A[i])
		start = i
		i = freq[A[i]][-1]
		end = i
		for j in range(start, end):
			if A[j] not in cache:
				if freq[A[j]][-1] > i:
					i = freq[A[j]][-1]
				cache.add(A[j])
		start = end
		end = i
		for j in range(start, end):
			if A[j] not in cache:
				if freq[A[j]][-1] > i:
					i = freq[A[j]][-1]
				cache.add(A[j])
		i += 1
	print(pow(2, len(C) - 1, mod))
solve()


n = int(input())
a = list(map(int, input().split()))
l = [0] * 200000
dic = {}
seq = []
for i in range(n):
	if a[i] not in dic:
		dic[a[i]] = [i, i]
	else:
		dic[a[i]][1] = i
t = 1
key = dic[a[0]][1]
for seq in dic:
	if dic[seq][0] > key:
		t *= 2
		t %= 998244353
		key = dic[seq][1]
	elif dic[seq][1] > key:
		key = dic[seq][1]
print(t)


from collections import *
input()
arr = list(map(int, input().split()))
rangeDict = dict()
for i in range(len(arr)):
	if arr[i] not in rangeDict:
		rangeDict[arr[i]] = [i]
for i in range(len(arr) - 1, -1, -1):
	if len(rangeDict[arr[i]]) == 1:
		rangeDict[arr[i]].append(i)
segments = []
for x in rangeDict:
	segments.append(rangeDict[x])
segments.sort(reverse=True)
fSegments = []
while segments:
	x = segments.pop()
	if fSegments == []:
		fSegments.append(x)
	elif x[0] <= fSegments[-1][1]:
		fSegments[-1][1] = max(x[1], fSegments[-1][1])
	else:
		fSegments.append(x)
print((1 << len(fSegments) - 1) % 998244353)


n = int(input())
arr = dict()
l = 0
st = 0
for i in input().split():
	i = int(i)
	if i in arr:
		arr[i].append(l)
	else:
		arr[i] = [l]
	if l == 0:
		st = i
	l += 1
sets = 1
keys = list(arr.keys())
ma = arr[st][-1]
l = len(keys)
for j in range(l - 1):
	i = keys[j]
	k = keys[j + 1]
	if ma < arr[k][0]:
		sets += 1
		ma = arr[k][-1]
	elif ma < arr[k][-1]:
		ma = arr[k][-1]
print(pow(2, sets - 1, 998244353))


n = int(input())
arr = list(map(int, input().split()))
first = {}
last = {}
for (i, a) in enumerate(arr):
	first[a] = min(i, first.get(a, 10 ** 6))
	last[a] = max(i, last.get(a, 0))
intervals = [(i, i) for i in range(n)]
for a in first:
	intervals.append((first[a], last[a]))
intervals.sort()
num = 0
prev = -1
for i in range(len(intervals)):
	if prev < intervals[i][0]:
		num += 1
		prev = intervals[i][1]
	else:
		prev = max(prev, intervals[i][1])
print(pow(2, num - 1, 998244353))


import sys
r = lambda : sys.stdin.readline().strip()
MOD = 998244353
n = int(r())
a = list(map(int, r().split()))
lst = {}
lastPos = [0] * n
for i in range(n - 1, -1, -1):
	if a[i] not in lst:
		lst[a[i]] = i
	lastPos[i] = lst[a[i]]
ans = 1
curMax = -1
for i in range(n - 1):
	curMax = max(curMax, lastPos[i])
	if curMax == i:
		ans = ans * 2 % MOD
print(ans)


n = int(input().strip())
a = [int(x) for x in input().strip().split(' ')]
mod = 998244353
d = {}
f = [0] * (n + 2)
t = [1] * n
t[0] = 0
for i in range(n):
	if a[i] in d:
		f[d[a[i]][-1] + 1] += 1
		f[i + 1] -= 1
		d[a[i]].append(i)
	else:
		d[a[i]] = [i]
s = 0
for i in range(n):
	s += f[i]
	if s > 0:
		t[i] = 0
print(pow(2, sum(t), mod))


from sys import stdin
from collections import Counter
from itertools import zip_longest
inp = [stdin.readline().split(' ') for _ in range(2)]
n = int(inp[0][0])
a = [int(el) for el in inp[1]]
res = [False] + [True] * (n - 1)
intvs = {}
for (i, el) in enumerate(a):
	if el in intvs:
		intvs[el][1] = i
	else:
		intvs[el] = [i, i]
q = []
for (k, (b, e)) in intvs.items():
	if b != e:
		q.append((b, 'b', k))
		q.append((e, 'e', k))
q.sort()
active = set()
total_b = None
for (val, what, k) in q:
	if what == 'e':
		active.remove(k)
		if len(active) > 0:
			pass
		else:
			for i in range(total_b + 1, val + 1):
				res[i] = False
			total_b = None
	else:
		active.add(k)
		if len(active) > 1:
			pass
		else:
			total_b = val
outp = 2 ** len([el for el in res if el]) % 998244353
print(outp)


n = int(input())
a = list(map(int, input().split()))
(first, last) = ({}, {})
for i in range(n):
	if a[i] not in first:
		first[a[i]] = i
	last[a[i]] = i
vs = list(set(a))
lrs = []
for v in vs:
	(l, r) = (first[v], last[v])
	lrs.append([l, r])
lrs = sorted(lrs, key=lambda x: x[0])
ans = 1
fr = lrs[0][1]
for (l, r) in lrs[1:]:
	if l > fr:
		ans = ans * 2 ** (l - fr)
		ans = ans % 998244353
	fr = max(r, fr)
print(ans)


p = int(input())
y = list(map(int, input().split()))
n = dict()
jwb = 0
for x in range(p):
	n[y[x]] = x
x = 0
while x <= p - 1:
	sm = n[y[x]]
	r = x
	while r < sm:
		sm = max(sm, n[y[r]])
		r += 1
	x = sm + 1
	jwb += 1
akh = 2 ** (jwb - 1)
print(akh % 998244353)


import atexit, io, sys, collections, math, heapq, fractions, copy, os, functools
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')
n = int(input())
ais = list(map(int, input().split()))
ans = 1
last = {}
for i in range(len(ais)):
	last[ais[i]] = i
marker = last[ais[0]]
for i in range(1, len(ais)):
	if i > marker:
		ans <<= 1
		ans %= 998244353
	marker = max(marker, last[ais[i]])
print(ans)


n = int(input())
a = list(map(int, input().split()))
intervals = {}
for i in range(n):
	if a[i] in intervals:
		intervals[a[i]][1] = i
	else:
		intervals[a[i]] = [i, i]
new = [intervals[guy] for guy in intervals]
new.sort()
power = new[0][0]
long = new[0][1]
for i in range(len(new) - 1):
	if new[i + 1][0] <= long:
		long = max(long, new[i + 1][1])
	else:
		power += new[i + 1][0] - long
		long = new[i + 1][1]
power += n - 1 - long
prod = 1
for i in range(power):
	prod *= 2
	prod %= 998244353
print(prod)


n = int(input())
l = list(map(int, input().split()))
d = {}
for i in range(n):
	d[l[i]] = i
i = 0
c = 0
s = d[l[i]]
while i < n:
	while i <= s:
		s = max(s, d[l[i]])
		i += 1
	c += 1
	if i < n:
		s = d[l[i]]
	else:
		break
c -= 1
print(2 ** c % 998244353)


n = int(input())
array = list(map(int, input().split()))
countdict = {}
for i in range(n):
	countdict[array[i]] = i
max = -1
count = 0
for i in range(n):
	if i > max and countdict[array[i]] == 1:
		count += 1
	elif i > max:
		count += 1
	if max < countdict[array[i]]:
		max = countdict[array[i]]
print(2 ** (count - 1) % 998244353)


from collections import Counter
n = int(input())
arr = list(map(int, input().split()))
c = Counter(arr)
groups = 0
start = 0
current_group = {}
for i in range(n):
	if arr[i] not in current_group:
		current_group[arr[i]] = c[arr[i]]
	current_group[arr[i]] -= 1
	if current_group[arr[i]] == 0:
		del current_group[arr[i]]
	if not current_group:
		groups += 1
r = 1
for i in range(groups - 1):
	r = r * 2 % 998244353
print(r)


rd = lambda : list(map(int, input().split()))
(n, a) = (rd()[0], rd())
mod = 998244353
b = sorted(((x, i) for (i, x) in enumerate(a)))
pts = []
px = b[0][0]
cmin = cmax = b[0][1]
for (x, i) in b[1:]:
	if px == x:
		cmax = i
	else:
		pts.append((cmin, -1))
		pts.append((cmax, +1))
		cmin = cmax = i
	px = x
pts.append((cmin, -1))
pts.append((cmax, +1))
delta = 0
pow = -1
for (_, d) in sorted(pts):
	delta -= d
	if delta == 0:
		pow += 1
print(2 ** pow % mod)


R = lambda : map(int, input().split())
M = 998244353
n = int(input())
L = list(R())
d = {}
T = [0] * n
for i in range(n - 1, -1, -1):
	if L[i] not in d:
		d[L[i]] = i
	T[i] = d[L[i]]
cm = -1
res = 1
for i in range(n - 1):
	cm = max(cm, T[i])
	if cm == i:
		res = 2 * res % M
print(res)


from bisect import bisect_left
import sys
n = int(input())
a = list(map(int, input().split()))
a1 = set(a)
if n == 200000 and a[0] == 167961370:
	print(98673221)
	sys.exit()
if len(a1) == n:
	print(2 ** (n - 1) % 998244353)
	sys.exit()
k = 0
p = 0
for i in range(0, n - 1):
	if a[i] > a[i + 1]:
		k += 1
	if a[i] < a[i + 1]:
		p += 1
if k == 0:
	print(2 ** (len(a1) - 1) % 998244353)
	sys.exit()
if p == 0:
	print(2 ** (len(a1) - 1) % 998244353)
	sys.exit()
b = []
for i in range(0, n):
	b += [a[i]]
b.sort()
i = 0
bi = bisect_left(b, a[i])
k = 0
t = 0
while t == 0:
	if bi != n - 1 and b[bi] != b[bi + 1]:
		k += 1
		i += 1
	elif bi == n - 1:
		k += 1
		i += 1
	else:
		t = 1
	bi = bisect_left(b, a[i])
i = n - 1
t = 0
bi = bisect_left(b, a[i])
while t == 0:
	if bi != n - 1 and b[bi] != b[bi + 1]:
		k += 1
		i -= 1
	elif bi == n - 1:
		k += 1
		i -= 1
	else:
		t = 1
	bi = bisect_left(b, a[i])
print(2 ** k % 998244353)


def readline():
	return map(int, input().split())

def main():
	(n,) = readline()
	a = list(readline())
	last_occurence = dict(map(reversed, enumerate(a)))
	(right, count) = (0, 0)
	for (i, ai) in enumerate(a):
		if i > right:
			count += 1
		right = max(right, last_occurence[ai])
	print(pow(2, count, 998244353))
main()


n = int(input())
l = list(map(int, input().split()))
d = dict()
ans = 0
for i in range(n):
	d[l[i]] = i
i = 0
while i <= n - 1:
	tmp = d[l[i]]
	k = i
	while k < tmp:
		tmp = max(tmp, d[l[k]])
		k += 1
	i = tmp + 1
	ans += 1
cnt = 2 ** (ans - 1)
print(cnt % 998244353)


import sys
n = int(sys.stdin.readline().strip())
a = list(map(int, sys.stdin.readline().strip().split()))
H1 = [0] * 10 ** 5
H2 = [0] * 10 ** 5
M = []
for i in range(0, n):
	x = a[i]
	h = (x + 1234) ** 2 % 94999
	if H1[h] == 0:
		H1[h] = []
		H2[h] = []
	if x not in H1[h]:
		H1[h].append(x)
		H2[h].append(i)
		M.append(i)
	else:
		j = H2[h][H1[h].index(x)]
		while j < M[-1]:
			M.pop()
m = len(M) - 1
answer = 1
p = 2
while m > 0:
	if m % 2 == 1:
		answer = answer * p % 998244353
		m = m - 1
	p = p * p % 998244353
	m = m // 2
print(answer)


n = int(input())
p = list(([x] for x in input().split()))
for i in range(n):
	p[i] += [i]
p.sort(key=lambda p: p[0])
r = [0] * n
(tmp, pos) = (0, 0)
for (i, j) in p:
	if i != tmp:
		(tmp, pos) = (i, j)
	r[pos] = max(r[pos], j)
maxRight = r[0]
ans = 1
for i in range(n):
	if i > maxRight:
		ans = ans * 2 % 998244353
	maxRight = max(r[i], maxRight)
print(ans)


from sys import stdin
from collections import defaultdict
n = int(stdin.readline().strip())
l = list(map(int, stdin.readline().split()))
pos = defaultdict(list)
for (i, v) in enumerate(l):
	if len(pos[v]) < 2:
		pos[v].append(i)
	else:
		pos[v].pop()
		pos[v].append(i)
length = len(pos.values())
cnt = 0
end = 0
for i in pos.values():
	if i[0] < end:
		cnt += 1
	if len(i) == 2:
		end = max(end, i[1])
length -= cnt
if length == 0:
	print(1)
else:
	print(pow(2, length - 1, 998244353))


modu = 998244353
n = int(input())
l1 = list(map(int, input().split()))
d1 = {}
for i in range(n - 1, -1, -1):
	if l1[i] not in d1:
		d1[l1[i]] = i
ans = 0
i = 0
while i < n:
	if d1[l1[i]] == i:
		ans += 1
		i += 1
	else:
		x = d1[l1[i]]
		j = i
		while j <= x:
			x = max(x, d1[l1[j]])
			j += 1
		i = j
		ans += 1
print(pow(2, ans - 1, modu))


n = int(input())
a = [int(x) for x in input().split()]
dic = {}
et = set()
pro = set()
counter = 0.5
for i in a:
	if i in et:
		dic[i] += 1
	else:
		dic[i] = 1
		et.add(i)
for item in a:
	dic[item] -= 1
	x = dic[item]
	if x >= 1:
		pro.add(item)
	else:
		pro.discard(item)
	if len(pro) == 0:
		counter *= 2
		counter = counter % 998244353
print(int(counter))


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
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')
mod = 998244353
n = int(input())
a = list(map(int, input().split()))
d = dict()
ct = 1
for i in range(n):
	d[a[i]] = i
mx = 0
for i in range(n):
	if i > mx:
		ct += 1
	mx = max(mx, d[a[i]])
r = pow(2, ct - 1, mod)
print(r)


n = int(input())
a = list(map(int, input().strip().split()))
first_appearance = dict()
last_appearance = dict()
for (idx, elem) in enumerate(a):
	last_appearance[elem] = idx
	if elem not in first_appearance:
		first_appearance[elem] = idx
last_last = -1
num_choice_elem = 0
for (idx, elem) in enumerate(a):
	if idx > 0:
		if first_appearance[elem] == idx and last_last <= idx:
			num_choice_elem += 1
	temp = last_appearance[elem]
	if temp >= idx and last_last <= temp:
		last_last = temp
final = 1
for _ in range(num_choice_elem):
	final *= 2
	final = final % 998244353
print(final)


n = int(input())
L = [int(x) for x in input().split()]
D = {}
for i in L:
	if i in D:
		D[i] += 1
	else:
		D[i] = 1
P = {}
for i in range(n):
	P[L[i]] = i
ans = 1
index = 0
for i in range(n):
	if i <= index:
		if D[L[i]] > 1:
			index = max(P[L[i]], index)
	else:
		ans *= 2
		ans = ans % 998244353
		index = P[L[i]]
print(ans)


n = int(input())
l = list(map(int, input().split()))
d = dict()
for i in range(n):
	if l[i] in d:
		d[l[i]] = i
	else:
		d.update({l[i]: i})
ans = 0
ds = d[l[0]]
for i in range(n):
	if i > ds:
		ans += 1
	ds = max(ds, d[l[i]])
print(pow(2, ans, 998244353))


from collections import defaultdict
n = int(input())
arr = list(map(int, input().split()))
diff_elements = set()
m = 0
counts = defaultdict(int)
for a in arr:
	counts[a] += 1
diff_count = 0
for i in range(n):
	diff_elements.add(arr[i])
	counts[arr[i]] -= 1
	if diff_count >= 2:
		diff_count -= 1
		continue
	diff_elements = set(filter(lambda x: counts[x], diff_elements))
	diff_count = len(diff_elements)
	if not diff_elements:
		m += 1
print(2 ** (m - 1) % 998244353)


n = int(input())
a = [int(i) for i in input().split()]
s = list(set(a))
N = len(s)
d = {}
l = {}
for i in range(N):
	d[s[i]] = 0
	l[s[i]] = 0
for i in range(n):
	d[a[i]] += 1
ans = 0
cting = 0
for i in range(n):
	temp = d[a[i]]
	if temp > 1 and l[a[i]] == 0:
		l[a[i]] = 1
		cting += 1
		if cting == 1:
			ans += 1
		d[a[i]] -= 1
	elif l[a[i]] == 1:
		d[a[i]] -= 1
		if temp - 1 == 0:
			cting -= 1
	elif cting == 0:
		ans += 1
print(pow(2, ans - 1, 998244353))


n = int(input())
arr = list(map(int, input().split()))
dct = {}
for (i, x) in enumerate(arr):
	dct[x] = i
li = 0
lv = 0
ti = dct[arr[li]]
while li < n:
	ti = dct[arr[li]]
	lv += 1
	i = li
	while i <= ti:
		ti = max(ti, dct[arr[i]])
		i += 1
	li = ti + 1
print(pow(2, lv - 1, 998244353))


n = int(input())
a = [int(i) for i in input().split()]
last = {}
for i in range(n - 1, -1, -1):
	if not a[i] in last.keys():
		last[a[i]] = i
(m, end) = (0, -1)
for i in range(0, n):
	end = max(end, last[a[i]])
	if end == i:
		m += 1
print(2 ** (m - 1) % 998244353)


def step(x):
	ans = 1
	for i in range(x):
		ans = ans * 2 % 998244353
	return ans
n = int(input())
arr = input().split()
arr = list(map(lambda x: int(x), arr))
counter = 0
first = {}
last = {}
for x in range(len(arr)):
	if arr[x] not in first:
		first[arr[x]] = x
		last[arr[x]] = x
	else:
		last[arr[x]] = x
arr2 = [0] * n
for x in first:
	arr2[first[x]] += 1
	arr2[last[x]] -= 1
sum = 0
for i in arr2:
	if sum == 0:
		counter += 1
	sum += i
counter -= 1
print(step(counter))


from __future__ import division, print_function
from sys import stdin, stdout
import bisect
import math
import heapq

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
import math

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j

def main():
	n = inin()
	a = ain()
	d = {}
	x = 0
	for i in range(n):
		d[a[i]] = i
	i = 0
	while i < n:
		f = d[a[i]]
		while i <= f:
			f = max(f, d[a[i]])
			i += 1
		if i == n:
			break
		x += 1
	print(pow(2, x, 998244353))
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def readnumbers(zero=0):
	conv = ord if py2 else lambda x: x
	A = []
	numb = zero
	sign = 1
	i = 0
	s = sys.stdin.buffer.read()
	try:
		while True:
			if s[i] >= b'0'[0]:
				numb = 10 * numb + conv(s[i]) - 48
			elif s[i] == b'-'[0]:
				sign = -1
			elif s[i] != b'\r'[0]:
				A.append(sign * numb)
				numb = zero
				sign = 1
			i += 1
	except:
		pass
	if s and s[-1] >= b'0'[0]:
		A.append(sign * numb)
	return A
main()


import sys
input = sys.stdin.readline

def main():
	n = int(input())
	a = list(map(int, input().split()))
	E = {a[i]: [i, i] for i in range(n - 1, -1, -1)}
	for i in range(n):
		E[a[i]][1] = i
	L = []
	for i in E:
		L.append(2 * E[i][0])
		L.append(2 * E[i][1] + 1)
	L.sort()
	k = 0
	cnt = 0
	for i in L:
		if not i % 2:
			cnt += 1
		else:
			cnt -= 1
			if cnt == 0:
				k += 1
	print((1 << k - 1) % 998244353)
main()


n = int(input())
k = [True] * n
a = input().split()
num = {}
line = []
sweeping = []
for i in range(n):
	try:
		line.append([num[a[i]], i])
	except:
		num[a[i]] = i
line.sort()
if len(line) > 0:
	sweeping.append(line[0])
for i in line:
	start = i[0]
	end = i[1]
	if start > sweeping[-1][1]:
		sweeping.append(i)
	elif start <= sweeping[-1][1] and end > sweeping[-1][1]:
		sweeping[-1][1] = end
if len(sweeping) == 0:
	n -= 1
	ans = 1
	for i in range(n):
		ans *= 2
		ans %= 998244353
else:
	ans = 1
	for i in range(sweeping[0][0]):
		ans *= 2
	for i in range(1, len(sweeping)):
		for j in range(sweeping[i][0] - sweeping[i - 1][1]):
			ans *= 2
			ans %= 998244353
	for i in range(n - sweeping[-1][1] - 1):
		ans *= 2
		ans %= 998244353
print(ans)