Rohit collects coins: he has exactly one coin for every year from 1 to n. Naturally, Rohit keeps all the coins in his collection in the order in which they were released. Once Rohit's younger brother made a change — he took all the coins whose release year dated from l to r inclusively and put them in the reverse order. That is, he took a certain segment [l, r] and reversed it. At that, the segment's endpoints did not coincide. For example, if n = 8, then initially Rohit's coins were kept in the order 1 2 3 4 5 6 7 8. If Rohit's younger brother chose the segment [2, 6], then after the reversal the coin order will change to 1 6 5 4 3 2 7 8. Rohit suspects that someone else could have spoilt the permutation after his brother. Help him to find that out. Check if the given permutation can be obtained from the permutation 1 2 … n using exactly one segment reversal. If it is possible, find the segment itself.

-----Input:-----
- The first line contains an integer N which is the number of coins in Rohit's collection. 
- The second line contains space-separated n integers which are the spoilt sequence of coins. It is guaranteed that the given sequence is a permutation, i.e. it contains only integers from 1 to n, and every number is used exactly 1 time.

-----Output:-----
If it is impossible to obtain the given permutation from the original one in exactly one action, print 0 0. Otherwise, print two numbers l, r (1 ≤ l < r ≤ n) which are the endpoints of the segment that needs to be reversed to obtain from permutation 1 2 … n the given one.

-----Constraints-----
- $1 \leq N \leq 1000$
- $1 \leq A[N] \leq 10^9$

-----Sample Input:-----
8
1 6 5 4 3 2 7 8

-----Sample Output:-----
2 6

Difficulty: UNKNOWN_DIFFICULTY

Solutions:
n = int(input())
a = list(map(int, input().split()))
(l, r) = (-1, -1)
for i in range(n):
	if a[i] != i + 1:
		l = i
		break
for i in range(n - 1, -1, -1):
	if a[i] != i + 1:
		r = i
		break
j = r + 1
for i in range(l, r + 1):
	if a[i] == j:
		j -= 1
		continue
	else:
		print(0, 0)
		return
print(l + 1, r + 1)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
sys.setrecursionlimit(100000000)
ii = lambda : int(input())
si = lambda : input()
jn = lambda x, l: x.join(map(str, l))
sl = lambda : list(map(str, input().strip()))
mi = lambda : list(map(int, input().split()))
mif = lambda : list(map(float, input().split()))
lii = lambda : list(map(int, input().split()))
ceil = lambda x: int(x) if x == int(x) else int(x) + 1
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
mod = 1000000007
try:
	n = ii()
	arr = lii()
	for i in range(1, n + 1):
		if i != arr[i - 1]:
			l = i
			break
	for i in range(n, -1, -1):
		if i != arr[i - 1]:
			r = i
			break
	temp = arr[l - 1:r]
	temp.reverse()
	srr = arr[0:l - 1]
	srr.extend(temp)
	srr.extend(arr[r:n])
	if srr == sorted(arr):
		print(l, r)
	else:
		print(0, 0)
except:
	print(0, 0)


n = int(input())
l = [int(x) for x in input().split()]
(left, right, i, num, flag) = (0, 0, 0, 0, 0)
while i < n:
	if l[i] != i + 1:
		num = l[i]
		i += 1
		left = i
		flag += 1
		while i < n and abs(l[i] - num) == 1:
			num = l[i]
			i += 1
		right = i
	else:
		i += 1
if flag == 1:
	print(left, right, sep=' ')
else:
	print('0 0')


N = int(input())
A = [0]
A += [int(x) for x in input().split()]
i = 0
while i <= N and i == A[i]:
	i += 1
j = N
while j >= i and j == A[j]:
	j -= 1
t = i
flg = True
for k in range(j, i - 1, -1):
	if A[k] != t:
		flg = False
		break
	t += 1
if i > j:
	flg = False
if flg:
	print(i, j)
else:
	print(0, 0)


n = int(input())
a = list(map(int, input().split()))
flag = 0
x = 0
y = 0
for i in range(0, n - 1):
	if flag == 0 and abs(a[i + 1] - a[i]) != 1:
		flag += 1
		x = a[i + 1]
	elif flag == 1 and abs(a[i + 1] - a[i]) != 1:
		flag += 1
		y = a[i]
	elif flag == 2 and abs(a[i + 1] - a[i]) != 1:
		flag += 1
		break
if flag == 2:
	print(y, x)
else:
	print('0 0')


n = int(input())
x = [int(x) for x in input().split()]
np = [int(np) for np in range(1, n + 1)]
l = []
for i in range(len(x)):
	if x[i] != np[i]:
		l.append(i)
if len(l) > 0:
	if ''.join(map(str, list(reversed(x[min(l):max(l) + 1])))) == ''.join(map(str, np[min(l):max(l) + 1])):
		print(min(l) + 1, max(l) + 1)
	else:
		print('0 0')
else:
	print('0 0')


try:
	n = int(input())
	a = list(map(int, input().split()))
	(l, r) = (-1, -1)
	for i in range(n):
		if a[i] != i + 1:
			l = i
			break
	for i in range(n - 1, -1, -1):
		if a[i] != i + 1:
			r = i
			break
	j = r + 1
	for i in range(l, r + 1):
		if a[i] == j:
			j -= 1
			continue
		else:
			print(0, 0)
			return
	print(l + 1, r + 1)
except EOFError as e:
	print(e)


n = int(input())
coins = list(map(int, input().split()))
start = -1
end = -1
ans = [0 for x in range(n)]
for i in range(n):
	if coins[i] != i + 1:
		if start == -1:
			start = i
			break
	ans[i] = coins[i]
for i in range(n - 1, -1, -1):
	if coins[i] != i + 1:
		if end == -1:
			end = i
			break
	ans[i] = coins[i]
mid = start + (end - start) // 2
s = start
e = end
while s <= end:
	ans[s] = coins[e]
	s += 1
	e -= 1
start += 1
end += 1
for i in range(n):
	if ans[i] != i + 1:
		start = 0
		end = 0
		break
print(start, end)


n = int(input())
l = [int(x) for x in input().split()]
fr = 0
to = 0
r = 1
for i in range(0, len(l)):
	if l[i] == r:
		r += 1
	else:
		fr = r
		to = l[i]
		break
dup = to
br = 0
for i in range(fr - 1, to):
	if l[i] == dup:
		dup -= 1
	else:
		br = 1
		break
dup = to + 1
for i in range(to, len(l)):
	if br == 1:
		break
	if l[i] == dup:
		dup += 1
	else:
		br = 1
if br == 1:
	print('0 0')
else:
	print(fr, to)


n = int(input())
l = list(map(int, input().split()))
val = 0
i = 1
(A, B) = (0, 0)
while i <= n:
	if i != l[i - 1]:
		p = l[i - 1:l[i - 1]]
		q = sorted(p, reverse=True)
		if p != q:
			val += 1
			break
		else:
			val += 1
			i = l[i - 1]
			B = l[i - 1]
			A = i
	i += 1
if val > 1:
	print(0, 0)
else:
	print(B, A)


from sys import stdin, stdout, exit
from heapq import *
try:
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	s = 0
	l = 0
	r = n
	left = right = False
	for i in range(n):
		if s + 1 == a[i]:
			s = a[i]
		else:
			l = i
			s = a[l]
			break
	for i in range(l + 1, n):
		if s - 1 == a[i]:
			s = a[i]
		else:
			s = a[i]
			r = i
			break
	arr = a[:l] + a[l:r][::-1] + a[r:]
	s = 0
	ans = True
	for i in arr:
		if s + 1 == i:
			s = i
		else:
			ans = False
			break
	if ans and l + 1 != r:
		print(l + 1, r)
	else:
		print(0, 0)
except:
	print(0, 0)


n = int(input())
l = list(map(int, input().split()))
flag = 0
for i in range(1, n + 1):
	if l[i - 1] != i:
		start = i
		flag = 1
		break
for i in range(n, 0, -1):
	if l[i - 1] != i:
		end = i
		break
if flag == 0:
	print(0, 0)
	return
for x in range(start - 1, end - 1):
	if l[x + 1] != l[x] - 1:
		print(0, 0)
		return
print(start, end)


n = int(input())
arr = list(map(int, input().split()))
brr = []
(l, r) = (0, 0)
i = 0
while i < n:
	if arr[i] != i + 1:
		(l, r) = (i + 1, arr[i])
		break
	i += 1
while i < r:
	if arr[i] != l + r - i - 1:
		(l, r) = (0, 0)
		break
	i += 1
while i < n:
	if arr[i] != i + 1:
		(l, r) = (0, 0)
		break
	i += 1
print(l, r)


(n, a) = (int(input()), [0] + list(map(int, input().split())))
(l, r) = (1, n)
while l <= n and a[l] == l:
	l += 1
while r >= 1 and a[r] == r:
	r -= 1
if l < n and a[l:r + 1] == list(range(r, l - 1, -1)):
	print(l, r)
else:
	print('0 0')


n = int(input())
arr = list(map(int, input().split()))

def solve(arr, n):
	l = n
	for i in range(n):
		if arr[i] != i + 1:
			l = i + 1
			break
	if l == n:
		return [0, 0]
	r = 1
	for i in range(n - 1, 0, -1):
		if arr[i] != i + 1:
			r = i + 1
			break
	if r == 1:
		return [0, 0]
	if arr[l - 1:r] == [i for i in range(r, l - 1, -1)]:
		return [l, r]
	else:
		return [0, 0]
print(*solve(arr, n))


n = int(input())
l = list(map(int, input().split()))
f = 0
ans = 1
(l1, l2) = (0, 0)
for i in range(1, n + 1):
	if l[i - 1] != i:
		if f == 0:
			idx = l.index(i)
			k = l[0:i - 1] + l[i - 1:idx + 1][::-1] + l[idx + 1:]
			l = k
			f = 1
			l1 = i
			l2 = idx + 1
		else:
			ans = 0
if ans == 0:
	print(0, 0)
else:
	print(l1, l2)


def __starting_point():
	n = int(input())
	arr = list(map(int, input().split()))
	l = -1
	r = -1
	for i in range(n):
		if arr[i] != i + 1:
			l = i
	for i in range(n - 1, 0, -1):
		if arr[i] != i + 1:
			r = i
	sub = arr[r:l + 1]
	newarr = arr[:r] + sub[::-1] + arr[l + 1:]
	if arr == list(range(1, n + 1)):
		print('0 0')
	elif list(range(1, n + 1)) == newarr:
		print(r + 1, l + 1)
	else:
		print('0 0')
__starting_point()


n = int(input())
arr = [int(x) for x in input().split()]
i = 0
l = []
while i < n - 1:
	if arr[i] < arr[i + 1]:
		i = i + 1
	else:
		j = i + 1
		while j < n and arr[j] < arr[j - 1]:
			j = j + 1
		l.append((i, j - 1))
		i = j
if len(l) == 1:
	ll = []
	for i in range(l[0][1] + 1, l[0][0], -1):
		ll.append(i)
	if ll == arr[l[0][0]:l[0][1] + 1]:
		print(l[0][0] + 1, l[0][1] + 1)
	else:
		print(0, 0)
else:
	print(0, 0)


n = int(input())
arr = list(map(int, input().split()))
(i, j) = (0, n - 1)
(x, y) = (-1, -1)
while i < j:
	if arr[i] == i + 1 and x < 0:
		i += 1
	else:
		x = i
	if arr[j] == j + 1 and y < 0:
		j -= 1
	else:
		y = j
	if x >= 0 and y >= 0:
		break
if arr[i:j + 1][::-1] == list(range(x + 1, y + 2)):
	print(x + 1, y + 1)
else:
	print(0, 0)