The only difference between easy and hard versions is a number of elements in the array.

You are given an array $a$ consisting of $n$ integers. The value of the $i$-th element of the array is $a_i$.

You are also given a set of $m$ segments. The $j$-th segment is $[l_j; r_j]$, where $1 \le l_j \le r_j \le n$.

You can choose some subset of the given set of segments and decrease values on each of the chosen segments by one (independently). For example, if the initial array $a = [0, 0, 0, 0, 0]$ and the given segments are $[1; 3]$ and $[2; 4]$ then you can choose both of them and the array will become $b = [-1, -2, -2, -1, 0]$.

You have to choose some subset of the given segments (each segment can be chosen at most once) in such a way that if you apply this subset of segments to the array $a$ and obtain the array $b$ then the value $\max\limits_{i=1}^{n}b_i - \min\limits_{i=1}^{n}b_i$ will be maximum possible.

Note that you can choose the empty set.

If there are multiple answers, you can print any.

If you are Python programmer, consider using PyPy instead of Python when you submit your code.


-----Input-----

The first line of the input contains two integers $n$ and $m$ ($1 \le n \le 300, 0 \le m \le 300$) — the length of the array $a$ and the number of segments, respectively.

The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^6 \le a_i \le 10^6$), where $a_i$ is the value of the $i$-th element of the array $a$.

The next $m$ lines are contain two integers each. The $j$-th of them contains two integers $l_j$ and $r_j$ ($1 \le l_j \le r_j \le n$), where $l_j$ and $r_j$ are the ends of the $j$-th segment.


-----Output-----

In the first line of the output print one integer $d$ — the maximum possible value $\max\limits_{i=1}^{n}b_i - \min\limits_{i=1}^{n}b_i$ if $b$ is the array obtained by applying some subset of the given segments to the array $a$.

In the second line of the output print one integer $q$ ($0 \le q \le m$) — the number of segments you apply.

In the third line print $q$ distinct integers $c_1, c_2, \dots, c_q$ in any order ($1 \le c_k \le m$) — indices of segments you apply to the array $a$ in such a way that the value $\max\limits_{i=1}^{n}b_i - \min\limits_{i=1}^{n}b_i$ of the obtained array $b$ is maximum possible.

If there are multiple answers, you can print any.


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

Output
6
2
1 4 

Input
5 4
2 -2 3 1 4
3 5
3 4
2 4
2 5

Output
7
2
3 2 

Input
1 0
1000000

Output
0
0




-----Note-----

In the first example the obtained array $b$ will be $[0, -4, 1, 1, 2]$ so the answer is $6$.

In the second example the obtained array $b$ will be $[2, -3, 1, -1, 4]$ so the answer is $7$.

In the third example you cannot do anything so the answer is $0$.

Difficulty: MEDIUM_HARD
Tags: Complete search

Implementation

Greedy algorithms
Skill types: Complete search

Greedy algorithms

Starter code:

Solutions:
(n, m) = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
queries = []
for i in range(m):
	(l, r) = [int(x) for x in input().split()]
	queries.append([l, r])
if True:
	B = A[:]
	bestans = 0
	bestq = []
	for mnind in range(n):
		qans = []
		B = A[:]
		for i in range(m):
			if queries[i][0] - 1 > mnind or mnind > queries[i][1] - 1:
				qans.append(i)
				for j in range(queries[i][0] - 1, queries[i][1]):
					B[j] -= 1
		if max(B) - min(B) > bestans:
			bestans = max(B) - min(B)
			bestq = qans[:]
	print(bestans)
	print(len(bestq))
	for i in bestq:
		print(i + 1, end=' ')
	print()

def brute():
	res = 0
	resq = []
	for i in range(1 << m):
		ans = 0
		qs = []
		tmp = A[:]
		for j in range(m):
			if 1 << j & i:
				qs.append(j + 1)
				for k in range(queries[j][0] - 1, queries[j][1]):
					tmp[k] -= 1
		ans = max(tmp) - min(tmp)
		print(qs, ans)
		res = max(res, ans)
		if res == ans:
			resq = qs[:]
	print('Final', res, resq)


import sys
from math import *
from copy import copy
(n, m) = input().split()
n = int(n)
m = int(m)
dat = [int(i) for i in input().split()]
otr = []
for i in range(m):
	(l, r) = input().split()
	l = int(l)
	r = int(r)
	otr.append((l - 1, r - 1))
best = 0
otrBest = []
for i in range(n):
	iDat = copy(dat)
	iBest = 0
	iOtrBest = []
	kosInd = 0
	for ii in otr:
		if ii[0] <= i and i <= ii[1]:
			kosInd += 1
			continue
		else:
			iOtrBest.append(kosInd)
			for iii in range(ii[0], ii[1] + 1):
				iDat[iii] -= 1
		kosInd += 1
	iBest = max(iDat) - min(iDat)
	if iBest > best:
		otrBest = iOtrBest
		best = iBest
print(best)
print(len(otrBest))
for l in otrBest:
	print(l + 1, end=' ')


(n, m) = list(map(int, input().split()))
A = [int(a) for a in input().split()]
L = [0] * m
R = [0] * m
for i in range(m):
	(l, r) = list(map(int, input().split()))
	L[i] = l - 1
	R[i] = r - 1
ma = -1
mai = -1
for i in range(n):
	B = [a for a in A]
	for j in range(m):
		if L[j] > i or R[j] < i:
			for k in range(L[j], R[j] + 1):
				B[k] -= 1
	d = B[i] - min(B)
	if d > ma:
		ma = d
		mai = i
print(ma)
B = [a for a in A]
X = []
for j in range(m):
	if L[j] > mai or R[j] < mai:
		X.append(str(j + 1))
print(len(X))
print(' '.join(X))


def read_nums():
	return [int(x) for x in input().split()]

def calculate_diff(i1, i2, nums, all_segments):
	cur_diff = nums[i2] - nums[i1]
	used_segments = []
	for (index, segment) in enumerate(all_segments):
		(left, right) = segment
		if left <= i1 <= right and (not left <= i2 <= right):
			used_segments.append(index)
			cur_diff += 1
	return (cur_diff, used_segments)

def main():
	(n, m) = read_nums()
	nums = read_nums()
	segments = [[x - 1 for x in read_nums()] for _ in range(m)]
	if n == 1:
		print(0)
		print(0)
		return
	candidates = []
	for (i1, num1) in enumerate(nums):
		for (i2, num2) in enumerate(nums):
			if i1 == i2:
				continue
			(diff, used_segments) = calculate_diff(i1, i2, nums, segments)
			candidates.append((diff, used_segments))
	(res_diff, segment_indexes) = max(candidates, key=lambda x: x[0])
	print(res_diff)
	print(len(segment_indexes))
	if len(segment_indexes) > 0:
		print(' '.join([str(x + 1) for x in segment_indexes]))

def __starting_point():
	main()
__starting_point()


(n, m) = [int(x) for x in input().split()]
L = [int(x) for x in input().split()]
large = max(L)
R = []
used = 0
Pairs = []
best = 0
lol = []
for i in range(n):
	if L[i] == large:
		R.append(i)
for T in range(m):
	(l, j) = [int(x) for x in input().split()]
	Pairs.append((l, j))
for j in range(0, n):
	S = L[:]
	tu = 0
	tuu = []
	for i in range(m):
		if Pairs[i][0] - 1 > j or Pairs[i][1] <= j:
			tu += 1
			tuu.append(i + 1)
			for k in range(Pairs[i][0] - 1, Pairs[i][1]):
				S[k] -= 1
	t = max(S) - min(S)
	if t > best:
		best = t
		used = tu
		lol = tuu
print(best)
print(used)
print(' '.join((str(i) for i in lol)))


import os
import sys
from io import BytesIO, IOBase

def main():
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	left = [[] for _ in range(n)]
	right = [[] for _ in range(n)]
	seg = []
	for _ in range(m):
		(l, r) = map(int, input().split())
		l -= 1
		r -= 1
		left[r].append(l)
		right[l].append(r)
		seg.append((l, r))
	dff = [0] * n
	ans = [-10 ** 10] * n
	mm = arr[0]
	for i in range(n):
		ans[i] = max(ans[i], arr[i] - mm)
		for l in left[i]:
			for j in range(l, i + 1):
				dff[j] -= 1
				mm = min(mm, arr[j] + dff[j])
		mm = min(mm, arr[i] + dff[i])
	dff = [0] * n
	mm = arr[n - 1]
	for i in range(n - 1, -1, -1):
		ans[i] = max(ans[i], arr[i] - mm)
		for r in right[i]:
			for j in range(i, r + 1):
				dff[j] -= 1
				mm = min(mm, arr[j] + dff[j])
		mm = min(mm, arr[i] + dff[i])
	final = max(ans)
	idx = ans.index(final)
	que = []
	for (i, item) in enumerate(seg):
		(l, r) = item
		if l <= idx <= r:
			continue
		que.append(i + 1)
	print(final)
	print(len(que))
	print(*que)
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()


import sys
big = 10 ** 9

class super_seg:

	def __init__(self, data):
		n = len(data)
		m = 1
		while m < n:
			m *= 2
		self.n = n
		self.m = m
		self.data = [big] * (2 * m)
		for i in range(n):
			self.data[i + m] = data[i]
		for i in reversed(range(m)):
			self.data[i] = min(self.data[2 * i], self.data[2 * i + 1])
		self.query = [0] * (2 * m)

	def push(self, seg_ind):
		q = self.query[seg_ind]
		self.query[2 * seg_ind] += q
		self.query[2 * seg_ind + 1] += q
		self.data[2 * seg_ind] += q
		self.data[2 * seg_ind + 1] += q
		self.data[seg_ind] = min(self.data[2 * seg_ind], self.data[2 * seg_ind + 1])
		self.query[seg_ind] = 0

	def update(self, seg_ind):
		seg_ind //= 2
		inds = []
		while seg_ind > 0:
			inds.append(seg_ind)
			seg_ind //= 2
		for ind in reversed(inds):
			self.push(ind)

	def build(self, seg_ind):
		seg_ind //= 2
		while seg_ind > 0:
			self.data[seg_ind] = min(self.data[2 * seg_ind], self.data[2 * seg_ind + 1]) + self.query[seg_ind]
			seg_ind //= 2

	def add(self, l, r, value):
		l += self.m
		r += self.m
		l0 = l
		r0 = r
		while l < r:
			if l % 2 == 1:
				self.query[l] += value
				self.data[l] += value
				l += 1
			if r % 2 == 1:
				r -= 1
				self.query[r] += value
				self.data[r] += value
			l //= 2
			r //= 2
		self.build(l0)
		self.build(r0 - 1)

	def min(self, l, r):
		l += self.m
		r += self.m
		self.update(l)
		self.update(r - 1)
		segs = []
		while l < r:
			if l % 2 == 1:
				segs.append(l)
				l += 1
			if r % 2 == 1:
				r -= 1
				segs.append(r)
			l //= 2
			r //= 2
		return min((self.data[ind] for ind in segs))

	def find_min(self, l, r):
		l += self.m
		r += self.m
		self.update(l)
		self.update(r - 1)
		segs = []
		while l < r:
			if l % 2 == 1:
				segs.append(l)
				l += 1
			if r % 2 == 1:
				r -= 1
				segs.append(r)
			l //= 2
			r //= 2
		ind = min(segs, key=lambda i: self.data[i])
		mini = self.data[ind]
		while ind < self.m:
			self.push(ind)
			if self.data[2 * ind] == mini:
				ind *= 2
			else:
				ind = 2 * ind + 1
		return (ind - self.m, mini)
(n, m) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
inter = []
update = [[] for _ in range(n + 1)]
for _ in range(m):
	(l, r) = [int(x) for x in input().split()]
	l -= 1
	inter.append((l, r))
	update[l].append((l, r))
	update[r].append((l, r))
Aneg = super_seg([-a for a in A])
besta = -1
besta_ind = -1
active_intervals = 0
for i in range(n):
	for (l, r) in update[i]:
		Aneg.add(l, r, 1 if l == i else -1)
		active_intervals += 1 if l == i else -1
	Amax = -Aneg.data[1]
	Ai = A[i] - active_intervals
	if Amax - Ai > besta:
		besta = Amax - Ai
		besta_ind = i
ints = [i for i in range(m) if inter[i][0] <= besta_ind < inter[i][1]]
print(besta)
print(len(ints))
print(*[x + 1 for x in ints])


(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = [list(map(int, input().split())) for i in range(m)]
gl_ans = -1
gl_mas = []
for num_i in range(n):
	ma = -10000000.0
	ans_m = []
	o = []
	for i in range(m):
		if b[i][0] - 1 > num_i or b[i][1] - 1 < num_i:
			o.append([b[i][0] - 1, -1])
			o.append([b[i][1], 0])
			ans_m.append(i + 1)
	for i in range(n):
		o.append([i, 1])
	o.sort()
	cnt = 0
	mi = 10000000.0
	for u in range(len(o)):
		if o[u][1] == -1:
			cnt -= 1
		elif o[u][1] == 0:
			cnt += 1
		elif a[o[u][0]] + cnt < mi:
			mi = a[o[u][0]] + cnt
	ma = a[num_i]
	if ma - mi > gl_ans:
		gl_ans = ma - mi
		gl_mas = ans_m
print(gl_ans)
print(len(gl_mas))
print(*gl_mas)


(n, m) = map(int, input().split())
mas = list(map(int, input().split()))
otmas = []
for i in range(m):
	otmas.append(list(map(int, input().split())))
for i in range(m):
	otmas[i][0] -= 1
	otmas[i][1] -= 1
ans = -1
masotv = []
for i in range(n):
	mascop = mas.copy()
	masotvizc = []
	for j in range(m):
		if not (i >= otmas[j][0] and i <= otmas[j][1]):
			masotvizc.append(j + 1)
			for k in range(otmas[j][0], otmas[j][1] + 1):
				mascop[k] -= 1
	if max(mascop) - min(mascop) > ans:
		masotv = masotvizc
	ans = max(ans, max(mascop) - min(mascop))
print(ans)
print(len(masotv))
print(*masotv)


from sys import stdin, stdout

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())
(n, m) = listIn()
a = [0] + listIn()
arr = {}
segments = [(0, 0)]
for i in range(m):
	(l, r) = listIn()
	segments.append((l, r))
	for j in range(l, r + 1):
		e = (a[j], j)
		if e not in arr:
			arr[e] = [0]
		arr[e].append(i + 1)
for i in range(1, n + 1):
	e = (a[i], i)
	if e not in arr:
		arr[e] = [0]
maxx = max(a[1:]) - min(a[1:])
minn = float('inf')
for ele in arr:
	e = arr[ele]
	e[0] = ele[0] - (len(e) - 1)
ans = []
for e1 in arr:
	s1 = set(arr[e1][1:])
	for e2 in arr:
		if e1 != e2:
			s2 = set(arr[e2][1:])
			s3 = s2 - s1
			s4 = s1 - s2
			b1 = e1[0] - (e2[0] - len(s3))
			b2 = e2[0] - (e1[0] - len(s4))
			b = max(b1, b2)
			if b > maxx:
				maxx = b
				if b == b1:
					ans = s3
				else:
					ans = s4
print(maxx)
print(len(ans))
print(*list(ans))


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
lr = [list(map(int, input().split())) for i in range(m)]
max_d = -1
ans_use = []
for i in range(n):
	use = []
	c = [a[i] for i in range(n)]
	for j in range(m):
		(l, r) = lr[j]
		if l <= i + 1 <= r:
			use.append(j + 1)
			for k in range(l, r + 1):
				c[k - 1] -= 1
	dd = max(c) - min(c)
	if dd > max_d:
		ans_use = use
		max_d = dd
print(max_d)
print(len(ans_use))
print(*ans_use)


(n, m) = map(int, input().split())
a = [int(k) for k in input().split()]
ans = max(a) - min(a)
p = []
an = []
for i in range(m):
	p.append(list(map(int, input().split())))
for i in range(n):
	b = a.copy()
	tmp = []
	for j in range(m):
		if i not in range(p[j][0] - 1, p[j][1]):
			for k in range(p[j][0] - 1, p[j][1]):
				b[k] -= 1
			tmp.append(j + 1)
	if ans < max(b) - min(b):
		ans = max(b) - min(b)
		an = tmp
print(ans)
print(len(an))
print(*an)


from sys import stdin, stdout
from collections import defaultdict
import math
I = stdin.readline
P = stdout.write
(n, m) = map(int, I().split())
arr = [int(x) for x in I().split()]
indi = defaultdict(lambda : set())
for j in range(m):
	(l, r) = map(int, I().split())
	for i in range(l - 1, r):
		indi[i].add(j + 1)
ans = 0
(a, b) = (0, 0)
inter = set()
for i in range(n):
	for j in range(n):
		nowint = indi[j].intersection(indi[i])
		now = arr[i] - arr[j] + len(indi[j]) - len(nowint)
		if now > ans:
			ans = now
			a = i
			b = j
			inter = nowint
print(ans)
print(len(indi[b]))
for i in indi[b]:
	print(i, end=' ')


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inara():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
(n, m) = invr()
a = inara()
seg = []
for i in range(m):
	(l, r) = invr()
	l -= 1
	r -= 1
	seg.append([l, r])
maxi = max(a) - min(a)
moves = []
for i in range(n):
	for j in range(n):
		curr = a[i] - a[j]
		temp = []
		for k in range(m):
			l = seg[k][0]
			r = seg[k][1]
			if j >= l and j <= r:
				temp.append(k + 1)
				if i < l or i > r:
					curr += 1
		if curr > maxi:
			maxi = curr
			moves = temp
print(maxi)
print(len(moves))
print(*moves)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
ma = max(a) - min(a)
rec = []
(L, R) = ([], [])
for i in range(m):
	(l, r) = map(int, input().split())
	(l, r) = (l - 1, r - 1)
	L.append(l)
	R.append(r)
for k in range(n):
	c = a.copy()
	tmp = []
	for i in range(m):
		(l, r) = (L[i], R[i])
		if l <= k <= r:
			tmp.append(i + 1)
			for j in range(l, r + 1):
				c[j] -= 1
	mac = max(c) - min(c)
	if ma < mac:
		ma = mac
		rec = tmp
print(ma)
print(len(rec))
print(' '.join(map(str, rec)))


dat = list(map(int, input().split()))
l = list(map(int, input().split()))
d = {}
i = 1
while i < dat[1] + 1:
	inter = list(map(int, input().split()))
	j = inter[0]
	while j < inter[1] + 1:
		if j not in d:
			d[j] = set()
		d[j].add(i)
		j += 1
	i += 1
max_res = -1
ans = None
i = 0
while i < len(l):
	j = 0
	while j < len(l):
		ii = i + 1
		jj = j + 1
		res_i = l[i]
		res_j = l[j]
		if ii in d:
			res_i = l[i] - len(d[ii])
			if jj in d:
				for dd in d[ii]:
					if dd in d[jj]:
						res_j -= 1
		res = res_j - res_i
		if res > max_res:
			max_res = res
			ans = ii
		j += 1
	i += 1
if max_res == -1:
	print(0)
	print(0)
else:
	print(max_res)
	if ans in d:
		print(len(d[ans]))
		print(' '.join(map(str, d[ans])))
	else:
		print(0)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
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, m) = map(int, input().split())
a = [int(x) for x in input().split()]
res = max(a) - min(a)
l = []
for i in range(m):
	l.append(list(map(int, input().split())))
cur = []
for i in range(n):
	c = a.copy()
	h = []
	for j in range(m):
		if i not in range(l[j][0] - 1, l[j][1]):
			for k in range(l[j][0] - 1, l[j][1]):
				c[k] -= 1
			h.append(j + 1)
	if res < max(c) - min(c):
		res = max(c) - min(c)
		cur = h
print(res)
print(len(cur))
print(*cur)


(lambda N, M: (lambda n, m, d, dM, dm: [[[(lambda a, b: [[0 if k[0] <= i <= k[1] else b.__setitem__(0, b[0] - 1) for k in m if not k[0] <= i <= k[1] and k[0] <= j <= k[1]], d[0] < a[0] - b[0] and [d.__setitem__(0, a[0] - b[0]), dM.__setitem__(0, i), dm.__setitem__(0, j)]])([n[i - 1]], [n[j - 1]]) for j in range(1, N + 1)] for i in range(1, N + 1)], (lambda p: [print(d[0]), print(len(p)), print(*p)])([k + 1 for k in range(M) if not m[k][0] <= dM[0] <= m[k][1] and m[k][0] <= dm[0] <= m[k][1]])])(list(map(int, input().split())), [list(map(int, input().split())) for i in range(M)], [-1], [0], [0]))(*map(int, input().split()))


def __starting_point():
	(n, subset) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	f = []
	t = []
	for i in range(subset):
		(x, y) = map(int, input().split(' '))
		f.append(x - 1)
		t.append(y - 1)
	diff = 0
	answer = []
	for ma in range(n):
		for mi in range(n):
			inside = 0
			cur_answer = []
			for sub in range(subset):
				if f[sub] <= mi <= t[sub] and (not f[sub] <= ma <= t[sub]):
					inside += 1
					cur_answer.append(sub)
			if a[ma] - (a[mi] - inside) > diff:
				diff = a[ma] - (a[mi] - inside)
				answer = cur_answer
	print(diff)
	print(len(answer))
	print(' '.join((str(x + 1) for x in answer)))
__starting_point()


def main():
	(n, m) = map(int, input().split())
	aa = list(map(int, input().split()))
	res = max(aa) - min(aa)
	(ll, rr) = ([999], [999])
	segments = res_segments = [False] * (m + 1)
	for _ in range(m):
		(l, r) = map(int, input().split())
		ll.append(l - 1)
		rr.append(r - 1)
	(il, ir) = (sorted(range(m + 1), key=xx.__getitem__, reverse=True) for xx in (ll, rr))
	for i in range(n):
		while True:
			k = il[-1]
			if ll[k] > i:
				break
			segments[k] = True
			for j in range(ll[k], rr[k] + 1):
				aa[j] -= 1
			del il[-1]
		x = max(aa) - min(aa)
		if res < x:
			res = x
			res_segments = segments[:]
		while True:
			k = ir[-1]
			if rr[k] > i:
				break
			segments[k] = False
			for j in range(ll[k], rr[k] + 1):
				aa[j] += 1
			del ir[-1]
	print(res)
	segments = [i for (i, f) in enumerate(res_segments) if f]
	print(len(segments))
	print(*segments)
main()


(n, m) = map(int, input().split())
arr = [int(x) for x in input().split()]
seg = []
el = []
el2 = []
h = []

def cont(a, b, c):
	return a <= c <= b

def count_delta():
	return max(h) - min(h)

def decrement(l, r):
	for i in range(l - 1, r):
		h[i] -= 1
for i in range(m):
	seg.append([int(x) for x in input().split()])
for i in range(len(arr)):
	h = arr[:]
	tmp = []
	for j in range(len(seg)):
		if cont(seg[j][0], seg[j][1], i + 1):
			decrement(seg[j][0], seg[j][1])
			tmp.append(j + 1)
	el.append(count_delta())
	el2.append(tmp)
print(max(el))
k = el.index(max(el))
print(len(el2[k]))
print(*el2[k])


(n, m) = list(map(int, input().split()))
A = list(map(int, input().split()))
lst = []
for i in range(m):
	(a, b) = list(map(int, input().split()))
	lst.append([a, b])
answer = 0
answer_1 = []
for i in range(n):
	B = A.copy()
	kek = []
	for j in range(m):
		(a, b) = (lst[j][0], lst[j][1])
		if a <= i + 1 <= b:
			kek.append(j + 1)
			for q in range(a - 1, b):
				B[q] -= 1
	elem = max(B)
	if answer < elem - B[i]:
		answer = elem - B[i]
		answer_1 = kek.copy()
print(answer)
print(len(answer_1))
print(' '.join(map(str, answer_1)))


import sys
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))
(n, m) = inpl()
a = inpl()
mx = max(a)
a = [-(x - mx) for x in a]
s = [inpl() for _ in range(m)]
res = 0
Q = []
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		q = []
		for (k, (l, r)) in enumerate(s):
			if l - 1 <= i <= r - 1 and (not l - 1 <= j <= r - 1):
				q.append(k + 1)
		ans = a[i] - a[j] + len(q)
		if ans > res:
			res = ans
			Q = q[:]
print(res)
print(len(Q))
print(*Q)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
i = 0
l1 = []
l2 = []
while i < m:
	(e, f) = map(int, input().split())
	l1.append(e)
	l2.append(f)
	i += 1
i = 0
j = 0
ans = -1
s = []
while i < n:
	j = 0
	while j < n:
		k = 0
		l = a[j] - a[i]
		m1 = []
		while k < m:
			if l1[k] <= i + 1 and l2[k] >= i + 1:
				if l1[k] > j + 1 or l2[k] < j + 1:
					l += 1
					m1.append(k + 1)
			k += 1
		if l > ans:
			s = m1
			ans = l
		j += 1
	i += 1
print(ans)
print(len(s))
for i in s:
	print(i, end=' ')


(n, m) = list(map(int, input().split()))
lst = list(map(int, input().split()))
segments = [list(map(int, input().split())) for i in range(m)]
max_diff = max(lst) - min(lst)
final_inds_segments = []
for (ind_max, est_max) in enumerate(lst):
	est_final_list = lst.copy()
	est_inds_segments = []
	for (segm_pair_ind, segment) in enumerate(segments):
		if not segment[0] - 1 <= ind_max <= segment[1] - 1:
			est_inds_segments.append(segm_pair_ind + 1)
			for segm_ind in range(segment[0] - 1, segment[1]):
				est_final_list[segm_ind] += -1
	est_max_diff = max(est_final_list) - min(est_final_list)
	if est_max_diff > max_diff:
		max_diff = est_max_diff
		final_inds_segments = est_inds_segments
print(max_diff)
if final_inds_segments:
	print(len(final_inds_segments))
	print(' '.join(map(str, final_inds_segments)))
else:
	print(0)


(n, m) = map(int, input().split())
A = list(map(int, input().split()))
Lf = [[] for _ in range(n)]
Rb = [[] for _ in range(n)]
LR = []
for i in range(m):
	(l, r) = map(int, input().split())
	(l, r) = (l - 1, r - 1)
	Lf[r].append(l)
	Rb[l].append(r)
	LR.append((l, r))
minus = [0] * n
INF = 10 ** 18
ans = [-INF] * n
mn = A[0]
for i in range(n):
	ans[i] = max(ans[i], A[i] - mn)
	for l in Lf[i]:
		for j in range(l, i + 1):
			minus[j] -= 1
			mn = min(mn, A[j] + minus[j])
	mn = min(mn, A[i] + minus[i])
minus = [0] * n
mn = A[n - 1]
for i in reversed(range(n)):
	ans[i] = max(ans[i], A[i] - mn)
	for r in Rb[i]:
		for j in range(i, r + 1):
			minus[j] -= 1
			mn = min(mn, A[j] + minus[j])
	mn = min(mn, A[i] + minus[i])
ans_ = max(ans)
res = []
for i in range(n):
	if ans[i] == ans_:
		for j in range(m):
			(l, r) = LR[j]
			if not (l <= i and i <= r):
				res.append(j + 1)
		break
print(ans_)
print(len(res))
print(*res)


(n, m) = map(int, input().split())
a = [*map(int, input().split())]
seg = [[*map(int, input().split())] for _ in range(m)]
ans = max(a) - min(a)
ansv = []
for i in range(n):
	b = [*a]
	temp = []
	for j in range(m):
		if i + 1 >= seg[j][0] and i + 1 <= seg[j][1]:
			continue
		for k in range(seg[j][0] - 1, seg[j][1]):
			b[k] -= 1
		temp.append(j + 1)
	if max(b) - min(b) > ans:
		ans = max(b) - min(b)
		ansv = [*temp]
print(ans)
print(len(ansv))
print(*ansv)


(n, m) = map(int, input().split())
a = [*map(int, input().split())]
i = 0
c = []
d = []
while i < m:
	(e, f) = map(int, input().split())
	c.append(e)
	d.append(f)
	i += 1
i = 0
j = 0
ans = -1
s = []
while i < n:
	j = 0
	while j < n:
		k = 0
		l = a[j] - a[i]
		ma = []
		while k < m:
			if c[k] <= i + 1 and d[k] >= i + 1:
				if c[k] > j + 1 or d[k] < j + 1:
					l += 1
					ma.append(k + 1)
			k += 1
		if l > ans:
			s = ma
			ans = l
		j += 1
	i += 1
print(ans)
print(len(s))
print(*s, sep=' ')


def f(a, b):
	b = sorted(b, key=lambda s: s[1] - s[0])
	t = {}
	for i in range(len(a)):
		l = []
		for j in b:
			if i in range(j[0], j[1] + 1):
				l.append(j)
		t[i] = l
	t = dict(sorted(t.items(), key=lambda s: a[s[0]]))
	t = dict(sorted(t.items(), key=lambda s: len(s[1]) - a[s[0]], reverse=True))
	mn = list(t.items())[0]
	curr = max(a) - min(a)
	bigans = 0
	bigd = []
	for mn in t.items():
		s = a.copy()
		ans = []
		a2 = []
		for i in mn[1]:
			l = i[0]
			r = i[1]
			for j in range(l, r + 1):
				s[j] -= 1
			tempans = max(s) - min(s)
			if tempans >= curr:
				a2.append(i[2] + 1)
				ans += a2
				a2 = []
			else:
				a2.append(i[2] + 1)
			curr = max(curr, tempans)
		if bigans < curr:
			bigans = curr
			bigd = ans
		else:
			break
	return (bigd, bigans)
(a, b) = map(int, input().strip().split())
blacnk = []
lst = list(map(int, input().strip().split()))
for i in range(b):
	(l, r) = map(int, input().strip().split())
	blacnk.append([l - 1, r - 1, i])
x = f(lst, blacnk)
print(x[1])
print(len(x[0]))
print(*x[0])


def main():
	(n, m) = map(int, input().split())
	aa = list(map(int, input().split()))
	res = max(aa) - min(aa)
	(ll, rr) = ([n + 1], [n + 1])
	segments = res_segments = [False] * (m + 1)
	bounds = {0, n, n + 1}
	for _ in range(m):
		(l, r) = map(int, input().split())
		l -= 1
		ll.append(l)
		rr.append(r)
		bounds.add(l)
		bounds.add(r)
	xlat = sorted(bounds)
	(mi, ma) = ([], [])
	for (l, r) in zip(xlat, xlat[1:-1]):
		t = aa[l:r]
		mi.append(min(t))
		ma.append(max(t))
	bounds = {x: i for (i, x) in enumerate(xlat)}
	for xx in (ll, rr):
		for (i, x) in enumerate(xx):
			xx[i] = bounds[x]
	(il, ir) = (sorted(range(m + 1), key=xx.__getitem__, reverse=True) for xx in (ll, rr))
	for i in range(len(xlat) - 1):
		while True:
			k = il[-1]
			lo = ll[k]
			if lo > i:
				break
			segments[k] = True
			for j in range(lo, rr[k]):
				mi[j] -= 1
				ma[j] -= 1
			del il[-1]
		x = max(ma) - min(mi)
		if res < x:
			res = x
			res_segments = segments[:]
		while True:
			k = ir[-1]
			hi = rr[k]
			if hi > i:
				break
			segments[k] = False
			for j in range(ll[k], hi):
				mi[j] += 1
				ma[j] += 1
			del ir[-1]
	print(res)
	segments = [i for (i, f) in enumerate(res_segments) if f]
	print(len(segments))
	print(*segments)
main()


(n, m) = map(int, input().split())
lis = list(map(int, input().split()))
res = max(lis) - min(lis)
seg = []
cur = []
pre = [0] * n
for i in range(m):
	(a, b) = map(int, input().split())
	seg.append([a - 1, b - 1])
for i in range(n):
	c = lis[:]
	ans = []
	for j in range(m):
		(aa, bb) = (seg[j][0], seg[j][1])
		if i not in range(aa, bb + 1):
			for k in range(aa, bb + 1):
				c[k] -= 1
			ans.append(j + 1)
		if res < max(c) - min(c):
			res = max(c) - min(c)
			cur = ans
print(res)
print(len(cur))
print(*cur)


(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = []
for i in range(m):
	b.append(list(map(int, input().split())))
ans = -1000000000
for i in range(n):
	ac = a.copy()
	for j in range(m):
		if i + 1 < b[j][0] or i + 1 > b[j][1]:
			for k in range(b[j][0] - 1, b[j][1]):
				ac[k] -= 1
	if a[i] - min(ac) > ans:
		ans = a[i] - min(ac)
		ansi = i
ansh = []
i = ansi
ac = a.copy()
q = 0
for j in range(m):
	if i + 1 < b[j][0] or i + 1 > b[j][1]:
		q += 1
		ansh.append(j + 1)
print(ans)
print(q)
print(*ansh)


import sys
from atexit import register
from io import FileIO, StringIO
sys.stdin = StringIO(FileIO(0).read().decode())
input = lambda : sys.stdin.readline().rstrip('\r\n')
sys.stdout = StringIO()
register(lambda : FileIO(1, 'w').write(sys.stdout.getvalue().encode()))

def main():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	segments = list((list(map(int, input().split())) for _ in range(m)))
	best = 0
	cnt = 0
	ans = []
	for i in range(n):
		case = a[:]
		res = []
		for j in range(m):
			if segments[j][0] <= i + 1 <= segments[j][1]:
				res.append(j + 1)
				for k in range(segments[j][0] - 1, segments[j][1]):
					case[k] -= 1
		tmp = max(case) - min(case)
		if tmp > best:
			best = tmp
			cnt = len(res)
			ans = res
	print(best)
	print(cnt)
	print(*ans)
main()


(n, m) = map(int, input().split())
a = [int(x) for x in input().split()]
res = max(a) - min(a)
l = []
for i in range(m):
	l.append(list(map(int, input().split())))
cur = []
for i in range(n):
	c = a.copy()
	h = []
	for j in range(m):
		if i not in range(l[j][0] - 1, l[j][1]):
			for k in range(l[j][0] - 1, l[j][1]):
				c[k] -= 1
			h.append(j + 1)
	if res < max(c) - min(c):
		res = max(c) - min(c)
		cur = h
print(res)
print(len(cur))
print(*cur)


(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
d = []
for i in range(m):
	d.append(list(map(int, input().split())))
par = []
g = []
for i in range(n):
	g.append(0)
for i in range(n):
	par.append(g.copy())
mas = []
for i in range(n):
	mas.append([])
for i in range(m):
	for k in range(max(0, d[i][0] - 1), min(n, d[i][1])):
		mas[k].append(i)
		for c in range(max(0, d[i][0] - 1), min(n, d[i][1])):
			par[c][k] += 1
max = -100000000
for i in range(n):
	for j in range(n):
		c = a[j] - a[i] + len(mas[i]) - par[i][j]
		if c > max:
			max = c
			count = len(mas[i])
			ans = mas[i]
print(max)
print(count)
for i in ans:
	print(i + 1, end=' ')
print()


from __future__ import division, print_function
import bisect
import math
import itertools
import sys
from atexit import register
if sys.version_info[0] < 3:
	from io import BytesIO as stream
else:
	from io import StringIO as stream
if sys.version_info[0] < 3:

	class dict(dict):

		def items(self):
			return dict.iteritems(self)

		def keys(self):
			return dict.iterkeys(self)

		def values(self):
			return dict.itervalues(self)
	input = raw_input
	range = xrange
	filter = itertools.ifilter
	map = itertools.imap
	zip = itertools.izip

def sync_with_stdio(sync=True):
	global input, flush
	if sync:
		flush = sys.stdout.flush
	else:
		sys.stdin = stream(sys.stdin.read())
		input = lambda : sys.stdin.readline().rstrip('\r\n')
		sys.stdout = stream()
		register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))

def update(D, l, r, x):
	D[l] += x
	D[r + 1] -= x

def main():
	(n, k) = map(int, input().split())
	l1 = list(map(int, input().split()))
	l2 = []
	for i in range(0, k):
		(l, r) = map(int, input().split())
		l2.append([l - 1, r - 1])
	li = []
	m = max(l1) - min(l1)
	for i in range(0, n):
		l3 = l1.copy()
		l4 = []
		D = [0] * (n + 1)
		for k in range(0, len(l2)):
			if i >= l2[k][0] and i <= l2[k][1]:
				l4.append(k + 1)
				update(D, l2[k][0], l2[k][1], -1)
		for i in range(0, n):
			if i == 0:
				D[i] = D[i]
			else:
				D[i] = D[i] + D[i - 1]
			l3[i] = l3[i] + D[i]
		f = max(l3) - min(l3)
		if f > m:
			li = l4
			m = f
	print(m)
	print(len(li))
	print(' '.join((str(x) for x in li)))
sync_with_stdio(False)
main()


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
ans = []
pair = []
for i in range(m):
	x = list(map(int, input().split()))
	pair.append(x)
for i in range(n):
	for j in range(n):
		d = []
		b = 0
		for k in range(m):
			if j + 1 >= pair[k][0] and j + 1 <= pair[k][1] and (i + 1 < pair[k][0] or i + 1 > pair[k][1]):
				b += 1
				d.append(k + 1)
		d = [a[i] - a[j] + b] + d
		ans.append(d)
ans.sort()
print(ans[-1][0])
sz = len(ans[-1]) - 1
print(sz)
print(*ans[-1][1:])


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
segments = []
for i in range(m):
	(l, r) = map(int, input().split())
	segments.append([l, r])
ans = 0
flag = 0
for i in range(n):
	for j in range(i, n):
		ai = a[i]
		aj = a[j]
		seglist1 = []
		seglist2 = []
		for k in range(m):
			if segments[k][0] - 1 <= i <= segments[k][1] - 1 and segments[k][1] - 1 < j:
				ai -= 1
				seglist1.append(k + 1)
			if segments[k][0] - 1 > i and segments[k][0] - 1 <= j <= segments[k][1] - 1:
				aj -= 1
				seglist2.append(k + 1)
		if ans < a[j] - ai:
			anslist = seglist1
			ans = a[j] - ai
			flag = 1
		if ans < a[i] - aj:
			anslist = seglist2
			ans = a[i] - aj
			flag = 1
if flag == 1 and len(anslist) >= 1:
	ansseg = str(anslist[0])
	for i in range(1, len(anslist)):
		ansseg += ' ' + str(anslist[i])
else:
	anslist = []
	ansseg = ''
print(ans)
print(len(anslist))
print(ansseg)


import math
(n, m) = list(map(int, input().split()))
arr = list(map(int, input().split()))
rs = [None] * m
for i in range(m):
	rs[i] = list(map(lambda x: int(x) - 1, input().split()))
maxdiff = 0
maxdiff_used_rs = []
for i in range(n):
	used_rs = []
	app = [0] * n
	curmax = arr[i]
	for j in range(m):
		if rs[j][0] <= i <= rs[j][1]:
			continue
		app[rs[j][0]] -= 1
		if rs[j][1] + 1 < n:
			app[rs[j][1] + 1] += 1
		used_rs.append(j + 1)
	curmin = math.inf
	curapp = 0
	for j in range(n):
		curapp += app[j]
		curmin = min(curmin, arr[j] + curapp)
	diff = curmax - curmin
	if diff > maxdiff:
		maxdiff = diff
		maxdiff_used_rs = used_rs
print(maxdiff)
print(len(maxdiff_used_rs))
print(*maxdiff_used_rs, sep=' ')


from copy import deepcopy
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = [list(map(int, input().split())) for i in range(m)]
best1 = -1
best2 = -1
best3 = []
for i in range(n):
	tmp = 0
	tmp2 = 0
	tmp3 = []
	c = deepcopy(a)
	for j in range(m):
		(x, y) = b[j]
		x -= 1
		y -= 1
		if x <= i and i <= y:
			continue
		for k in range(x, y + 1):
			c[k] -= 1
		tmp3.append(j + 1)
		tmp2 += 1
	kon = max(c) - min(c)
	if best1 < kon:
		best1 = kon
		best2 = tmp2
		best3 = tmp3
print(best1)
print(best2)
print(*best3)


(n, m) = map(int, input().split())
x = list(map(int, input().split()))
q = [0] * m
for i in range(m):
	q[i] = list(map(int, input().split()))
ans = 0
ansNum = 0
ansS = ''
for i in range(n):
	maxVal = x[i]
	maxIndex = i + 1
	temp = [0] * n
	tempNum = 0
	tempS = ''
	for k in range(n):
		temp[k] = x[k]
	for js in range(len(q)):
		j = q[js]
		if not j[0] <= maxIndex <= j[1]:
			tempNum += 1
			tempS += ' ' + str(js + 1)
			for l in range(j[0] - 1, j[1]):
				temp[l] -= 1
	tempAns = maxVal - min(temp)
	if tempAns > ans:
		ans = tempAns
		ansNum = tempNum
		ansS = tempS
print(ans)
print(ansNum)
print(ansS[1:])


(n, m) = map(int, input().split())
b = list(map(int, input().split()))
se = []
for i in range(m):
	se.append(list(map(int, input().split())))
k = max(b) - min(b)
ans = []
for i in range(n):
	l = []
	r = b[:]
	for j in range(m):
		(c, d) = (se[j][0], se[j][1])
		if i not in range(c - 1, d):
			for x in range(c - 1, d):
				r[x] -= 1
			l.append(j + 1)
	x = max(r) - min(r)
	if x > k:
		k = x
		ans = l
print(k)
print(len(ans))
print(*ans)


def solve(n, m, values, segments):
	if n < 2:
		return (0, 0, [])

	def find_min_max(max_value_index):
		values_updated = values[:]
		max_value = values[max_value_index]
		(min_value_index, min_value) = (None, None)
		segment_indexes = []
		for seg_index in range(m):
			(start, end) = segments[seg_index]
			if max_value_index < start - 1 or max_value_index > end - 1:
				for val_index in range(start - 1, end):
					values_updated[val_index] -= 1
				segment_indexes.append(str(seg_index + 1))
		for index in range(n):
			if index != max_value_index and (min_value_index is None or values_updated[index] < min_value):
				min_value_index = index
				min_value = values_updated[index]
		return (min_value, max_value, segment_indexes)
	(d, segment_indexes) = (None, None)
	for index in range(n):
		(min_value, max_value, indexes) = find_min_max(index)
		if min_value is None:
			continue
		if d is None or max_value - min_value > d:
			d = max_value - min_value
			segment_indexes = indexes
	if d is None:
		return (0, 0, [])
	return (d, len(segment_indexes), segment_indexes)
(n, m) = map(int, input().strip().split(' '))
values = list(map(int, input().strip().split(' ')))
segments = []
for i in range(m):
	(a, b) = map(int, input().strip().split(' '))
	segments.append((a, b))
(d, q, segment_indexes) = solve(n, m, values, segments)
print(d)
print(q)
print(' '.join(segment_indexes))


R = lambda : map(int, input().split())
(n, m) = R()
l = list(R())
d = max(l) - min(l)
s = []
qc = []
for i in range(m):
	s.append(list(R()))
for i in range(1, n + 1):
	str = l.copy()
	c = []
	for j in range(m):
		if i not in range(s[j][0], s[j][1] + 1):
			c.append(j + 1)
			for t in range(s[j][0] - 1, s[j][1]):
				str[t] -= 1
			distance = max(str) - min(str)
			if distance > d:
				d = distance
				qc = c
print(d, len(qc), sep='\n')
print(*qc)


from bisect import bisect_left as bl
from bisect import bisect_right as br
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
it = []
for i in range(m):
	(l, r) = map(int, input().split())
	it.append((l - 1, r - 1, i + 1))
it1 = it
it1.sort()
it2 = it
it2.sort(key=lambda x: x[1])
iit1 = [i[0] for i in it1]
iit2 = [i[1] for i in it2]

def inc(rr):
	(l, r) = (rr[0], rr[1])
	for i in range(l, r + 1):
		st[i] -= 1
an = []
ans = max(a) - min(a)
for i in range(n):
	st = [c for c in a]
	aa = []
	for j in range(m):
		if it[j][0] <= i and i <= it[j][1]:
			inc(it[j])
			aa.append(it[j][2])
	if ans < max(st) - min(st):
		ans = max(st) - min(st)
		an = aa
print(ans)
print(len(an))
print(*an)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
l = []
v = []
for _ in range(m):
	l.append(list(map(int, input().split())))
ans = max(a) - min(a)
c = a.copy()
for _ in range(n):
	for __ in range(n):
		a = c.copy()
		cur = []
		if _ == __:
			continue
		for ___ in range(m):
			if __ in range(l[___][0] - 1, l[___][1]) and _ not in range(l[___][0] - 1, l[___][1]):
				a[__] -= 1
				cur.append(___ + 1)
		ans = max(ans, a[_] - a[__])
		if ans == a[_] - a[__]:
			v = cur.copy()
print(int(ans))
print(len(v))
for _ in v:
	print(_, end=' ')


import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
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
(n, m) = map(int, input().split())
l = list(map(int, input().split()))
ma = max(l)
ind = []
tot = []
seg = []
for i in range(m):
	seg.append(list(map(int, input().split())))
ans = ma - min(l)
for i in range(n):
	l1 = [0] * (n + 1)
	e = []
	s = ma
	for j in range(m):
		if seg[j][0] <= i + 1 <= seg[j][1]:
			continue
		l1[seg[j][0] - 1] -= 1
		l1[seg[j][1]] += 1
		e.append(j + 1)
	for j in range(1, n + 1):
		l1[j] += l1[j - 1]
	for j in range(n):
		s = min(s, l[j] + l1[j])
	ans = max(ans, l[i] - s)
	if l[i] - s == ans:
		tot = e
print(ans)
print(len(tot))
print(*tot)


from sys import stdin
(n, m) = map(int, input().split())
l = list(map(int, stdin.readline().split()))
segment = [tuple(map(int, inp.split())) for inp in stdin.read().splitlines()]
ans = 0
chosen = []
for i in range(n):
	temp = l.copy()
	curpair = []
	for j in range(m):
		(left, right) = segment[j]
		if i not in range(left - 1, right):
			for k in range(left - 1, right):
				temp[k] -= 1
			curpair.append(j + 1)
	cur = max(temp) - min(temp)
	if cur > ans:
		ans = cur
		chosen = curpair.copy()
print(ans)
print(len(chosen))
print(*chosen)


(n, m) = list(map(int, input().split()))
A = list(map(int, input().split()))
if n > 300:
	lst = []
	for i in range(m):
		(a, b) = list(map(int, input().split()))
		lst.append([a, b])
	answer = 0
	answer_1 = []
	m300 = [[-1, -10 ** 6]]
	for i in range(max(0, m - 1)):
		m300.append([-1, -10 ** 6])
	for u in range(n):
		if A[u] > min(m300)[1]:
			m300[m300.index(min(m300))] = [u, A[u]]
	for (i, mi) in m300:
		B = A.copy()
		kek = []
		for j in range(m):
			(a, b) = (lst[j][0], lst[j][1])
			if a <= i + 1 <= b:
				kek.append(j + 1)
				for q in range(a - 1, b):
					B[q] -= 1
		elem = max(B)
		if answer < elem - mi:
			answer = elem - mi
			answer_1 = kek.copy()
	print(answer)
	print(len(answer_1))
	print(' '.join(map(str, answer_1)))
else:
	lst = []
	for i in range(m):
		(a, b) = list(map(int, input().split()))
		lst.append([a, b])
	answer = 0
	answer_1 = []
	for i in range(n):
		B = A.copy()
		kek = []
		for j in range(m):
			(a, b) = (lst[j][0], lst[j][1])
			if a <= i + 1 <= b:
				kek.append(j + 1)
				for q in range(a - 1, b):
					B[q] -= 1
		elem = max(B)
		if answer < elem - B[i]:
			answer = elem - B[i]
			answer_1 = kek.copy()
	print(answer)
	print(len(answer_1))
	print(' '.join(map(str, answer_1)))


(n, m) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
q = []
for i in range(m):
	(l, r) = [int(c) for c in input().split()]
	q.append([l, r, i + 1])
fin = []
fin_val = 0
for i in range(n):
	mx = a[i]
	copy = a[:]
	ans = []
	for j in range(m):
		(l, r) = (q[j][0], q[j][1])
		if i >= l - 1 and i <= r - 1:
			continue
		for k in range(l - 1, r):
			copy[k] -= 1
		ans.append(q[j][2])
	val = mx - min(copy)
	if val > fin_val:
		fin = ans[:]
		fin_val = val
print(fin_val)
print(len(fin))
print(*fin)


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
b = []
for i in range(m):
	(l, r) = map(int, input().split())
	b.append([l, r])
ans = 0
rt = []
for i in range(1, n + 1):
	brr = arr[:]
	temp = []
	for j in range(m):
		if i >= b[j][0] and i <= b[j][1]:
			continue
		temp.append(j)
		for k in range(b[j][0] - 1, b[j][1]):
			brr[k] -= 1
	mx = max(brr)
	mi = min(brr)
	if mx - mi > ans:
		rt = temp[:]
	ans = max(ans, mx - mi)
print(ans)
print(len(rt))
for i in rt:
	print(i + 1, end=' ')
print()


(aLen, numOfSeg) = map(int, input().split(' '))
aList = list(map(int, input().split(' ')))
segList = []
for x in range(numOfSeg):
	(s, e) = map(int, input().split(' '))
	segList.append((s, e))
res = max(aList) - min(aList)
hList = []
for x in range(0, len(aList)):
	ele = aList[x]
	c = aList[:]
	h = []
	for y in range(numOfSeg):
		if x not in range(segList[y][0] - 1, segList[y][1]):
			h.append(str(y + 1))
			for z in range(segList[y][0] - 1, segList[y][1]):
				c[z] -= 1
	lres = max(c) - min(c)
	if lres > res:
		res = lres
		hList = h
print(res)
print(len(hList))
print(' '.join(hList))


import sys

class super_seg:

	def __init__(self, data):
		n = len(data)
		m = 1
		while m < n:
			m *= 2
		self.n = n
		self.m = m
		self.data = [0] * (2 * m)
		for i in range(n):
			self.data[i + m] = data[i]
		for i in reversed(range(m)):
			self.data[i] = min(self.data[2 * i], self.data[2 * i + 1])
		self.query = [0] * (2 * m)

	def push(self, seg_ind):
		q = self.query[seg_ind]
		self.query[2 * seg_ind] += q
		self.query[2 * seg_ind + 1] += q
		self.data[2 * seg_ind] += q
		self.data[2 * seg_ind + 1] += q
		self.data[seg_ind] = min(self.data[2 * seg_ind], self.data[2 * seg_ind + 1])
		self.query[seg_ind] = 0

	def update(self, seg_ind):
		seg_ind //= 2
		inds = []
		while seg_ind > 0:
			inds.append(seg_ind)
			seg_ind //= 2
		for ind in reversed(inds):
			self.push(ind)

	def build(self, seg_ind):
		seg_ind //= 2
		while seg_ind > 0:
			self.data[seg_ind] = min(self.data[2 * seg_ind], self.data[2 * seg_ind + 1]) + self.query[seg_ind]
			seg_ind //= 2

	def add(self, l, r, value):
		l += self.m
		r += self.m
		l0 = l
		r0 = r
		while l < r:
			if l % 2 == 1:
				self.query[l] += value
				self.data[l] += value
				l += 1
			if r % 2 == 1:
				r -= 1
				self.query[r] += value
				self.data[r] += value
			l //= 2
			r //= 2
		self.build(l0)
		self.build(r0 - 1)

	def min(self, l, r):
		l += self.m
		r += self.m
		self.update(l)
		self.update(r - 1)
		segs = []
		while l < r:
			if l % 2 == 1:
				segs.append(l)
				l += 1
			if r % 2 == 1:
				r -= 1
				segs.append(r)
			l //= 2
			r //= 2
		return min((self.data[ind] for ind in segs))

	def find_min(self, l, r):
		l += self.m
		r += self.m
		self.update(l)
		self.update(r - 1)
		segs = []
		while l < r:
			if l % 2 == 1:
				segs.append(l)
				l += 1
			if r % 2 == 1:
				r -= 1
				segs.append(r)
			l //= 2
			r //= 2
		ind = min(segs, key=lambda i: self.data[i])
		mini = self.data[ind]
		while ind < self.m:
			self.push(ind)
			if self.data[2 * ind] == mini:
				ind *= 2
			else:
				ind = 2 * ind + 1
		return (ind - self.m, mini)
(n, m) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
inter = []
inter2 = []
for _ in range(m):
	(l, r) = [int(x) for x in input().split()]
	l -= 1
	inter.append((l, r))
	inter2.append((r, l))
inter_copy = inter[:]
inter.sort()
inter2.sort()
Aneg = super_seg([-a for a in A])
besta = -1
besta_ind = -1
j1 = 0
j2 = 0
for i in range(n):
	while j1 < m and inter[j1][0] <= i:
		(l, r) = inter[j1]
		Aneg.add(l, r, 1)
		j1 += 1
	while j2 < m and inter2[j2][0] <= i:
		(r, l) = inter2[j2]
		Aneg.add(l, r, -1)
		j2 += 1
	Amax = -Aneg.min(0, n)
	Ai = -Aneg.min(i, i + 1)
	if Amax - Ai > besta:
		besta = Amax - Ai
		besta_ind = i
ints = [j for j in range(m) if inter_copy[j][0] <= besta_ind < inter_copy[j][1]]
print(besta)
print(len(ints))
print(*[x + 1 for x in ints])


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
seg = []
for i in range(m):
	(a, b) = map(int, input().split())
	seg.append((a - 1, b - 1))
ans = max(l) - min(l)
minind = 0
maxind = 0
for i in range(n):
	for j in range(n):
		temp1 = l[i]
		temp2 = l[j]
		for k in seg:
			if j >= k[0] and j <= k[1] and (i < k[0] or i > k[1]):
				temp2 -= 1
		c = temp1 - temp2
		if c > ans:
			ans = c
			minind = j
			maxind = i
ansl = []
for i in range(m):
	t = seg[i]
	if t[0] <= minind and t[1] >= minind and (t[0] > maxind or t[1] < maxind):
		ansl.append(i + 1)
print(ans)
print(len(ansl))
print(*ansl)


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
x = [*map(int, input().split())]
seg = []
for i in range(m):
	a = [*map(int, input().split())]
	seg.append(a)
ans = -1
ansi = []
for i in range(len(x)):
	tx = x[:]
	oi = []
	for (n, j) in enumerate(seg):
		(a, b) = j
		if not a - 1 <= i <= b - 1:
			oi.append(n + 1)
			for k in range(a - 1, b):
				tx[k] -= 1
	m = max(tx) - min(tx)
	if m > ans:
		ans = m
		ansi = oi[:]
print(ans)
print(len(ansi))
for i in ansi:
	print(i, end=' ')


from __future__ import division, print_function

def main():

	def f(a, b):
		b = sorted(b, key=lambda s: s[1] - s[0])
		t = {}
		for i in range(len(a)):
			l = []
			for j in b:
				if i in range(j[0], j[1] + 1):
					l.append(j)
			t[i] = l
		t = dict(sorted(t.items(), key=lambda s: a[s[0]]))
		t = dict(sorted(t.items(), key=lambda s: len(s[1]) - a[s[0]], reverse=True))
		mn = list(t.items())[0]
		curr = max(a) - min(a)
		bigans = 0
		bigd = []
		for mn in t.items():
			s = a.copy()
			ans = []
			a2 = []
			for i in mn[1]:
				l = i[0]
				r = i[1]
				for j in range(l, r + 1):
					s[j] -= 1
				tempans = max(s) - min(s)
				if tempans >= curr:
					a2.append(i[2] + 1)
					ans += a2
					a2 = []
				else:
					a2.append(i[2] + 1)
				curr = max(curr, tempans)
			if bigans < curr:
				bigans = curr
				bigd = ans
			else:
				break
		return (bigd, bigans)
	(a, b) = map(int, input().strip().split())
	blacnk = []
	lst = list(map(int, input().strip().split()))
	for i in range(b):
		(l, r) = map(int, input().strip().split())
		blacnk.append([l - 1, r - 1, i])
	x = f(lst, blacnk)
	print(x[1])
	print(len(x[0]))
	print(*x[0])
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
(n, m) = map(int, input().split())
A = list(map(int, input().split()))
LR = [list(map(int, input().split())) for i in range(m)]

def MINUS(A, B):
	MIN = float('inf')
	MAX = -float('inf')
	for i in range(len(A)):
		if MIN > A[i] - B[i]:
			MIN = A[i] - B[i]
		if MAX < A[i] - B[i]:
			MAX = A[i] - B[i]
	return MAX - MIN
MINUSLIST = [[0] * n for i in range(n)]
for (l, r) in LR:
	for j in range(l - 1, r):
		for k in range(l - 1, r):
			MINUSLIST[j][k] += 1
ANSLIST = [0] * n
for i in range(n):
	ANSLIST[i] = MINUS(A, MINUSLIST[i])
print(max(ANSLIST))
x = ANSLIST.index(max(ANSLIST))
AN = []
for i in range(m):
	(z, w) = LR[i]
	if z <= x + 1 <= w:
		AN.append(i + 1)
print(len(AN))
for a in AN:
	print(a, end=' ')


(n, m) = map(int, input().split())
A = list(map(int, input().split()))
LR = []
for i in range(m):
	(l, r) = map(int, input().split())
	(l, r) = (l - 1, r - 1)
	LR.append((l, r))
from itertools import accumulate
ans = -float('inf')
subs = -1
for i in range(n):
	a = A[i]
	imos = [0] * (n + 1)
	s = []
	for j in range(m):
		(l, r) = LR[j]
		if l <= i and i <= r:
			continue
		else:
			imos[l] += 1
			imos[r + 1] -= 1
			s.append(j + 1)
	imos = list(accumulate(imos))
	B = [0] * n
	for k in range(n):
		B[k] = A[k] - imos[k]
	min_ = min(B)
	temp = max(B) - min_
	if temp >= ans:
		ans = temp
		subs = tuple(s)
print(ans)
print(len(subs))
print(*subs)


import sys
inn = lambda : input().strip()
(N, M) = map(int, inn().split(' '))
array = list(map(int, inn().split(' ')))
segment = []
for _ in range(M):
	(l, r) = tuple(map(int, inn().split(' ')))
	segment.append((l - 1, r - 1))
answer = -1
selectedSeg = []
for (i, a) in enumerate(array):
	array_temp = array.copy()
	selectedSeg_temp = []
	for (segI, (l, r)) in enumerate(segment):
		if i >= l and i <= r:
			selectedSeg_temp.append(segI + 1)
			for decrease in range(l, r + 1):
				array_temp[decrease] -= 1
	interval = max(array_temp) - min(array_temp)
	if answer < interval:
		answer = interval
		selectedSeg = list(map(str, selectedSeg_temp))
print(answer)
print(len(selectedSeg))
print(' '.join(selectedSeg))


(horizon, num_blocks) = [int(x) for x in input().split()]
c = 0
terrain = []
for x in input().split():
	terrain.append([int(x), c])
	c += 1
ori_shallow = max(terrain)
ori_deep = min(terrain)
record = abs(ori_deep[0] - ori_shallow[0])
if num_blocks == 0 or horizon == 1:
	print(record)
	print(0)
	exit()
record_index = ''
blocks = []
c = 0
new_terrain = [list(x) for x in terrain]
for x in range(num_blocks):
	new_block = [int(j) - 1 for j in input().split()]
	blocks.append([new_block, c])
	c += 1
	for y in range(new_block[0], new_block[1] + 1):
		new_terrain[y][0] -= 1
blocks.sort()
landscape = sorted(new_terrain)
new_shallow = landscape[-1]
used_blocks_index = ''
for y in range(horizon):
	if abs(ori_shallow[0] - landscape[y][0]) <= record:
		break
	else:
		used_blocks_index = ''
		present_index = landscape[y][1]
		new_terrain = [list(s) for s in terrain]
		for t in range(num_blocks):
			if blocks[t][0][0] > present_index:
				break
			if blocks[t][0][1] < present_index:
				continue
			for x in range(blocks[t][0][0], blocks[t][0][1] + 1):
				new_terrain[x][0] -= 1
			used_blocks_index += ' ' + str(blocks[t][1])
		new_shallow = max(new_terrain)[0]
		gap = abs(new_shallow - landscape[y][0])
		if gap > record:
			record = gap
			record_index = used_blocks_index
print(record)
ans_index = [int(x) + 1 for x in record_index.split()]
print(len(ans_index))
print(' '.join([str(x) for x in ans_index]))


import os
import sys
from io import BytesIO, IOBase
from math import inf

def check(x, v):
	return v >= x[0] and v <= x[1]

def main():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	c = [list(map(int, input().split())) for _ in range(m)]
	(gma, ans1) = (-inf, [])
	for ma in range(1, n + 1):
		b = [0] * (n + 1)
		ans = []
		for j in range(1, m + 1):
			i = c[j - 1]
			if not check(i, ma):
				b[i[0] - 1] -= 1
				b[i[1]] += 1
				ans.append(j)
		for j in range(1, n + 1):
			b[j] += b[j - 1]
		(maa, mii) = (-inf, inf)
		for j in range(n):
			maa = max(maa, a[j] + b[j])
			mii = min(mii, a[j] + b[j])
		if gma < maa - mii:
			gma = maa - mii
			ans1 = ans
	print(gma)
	print(len(ans1))
	print(*ans1)
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, q) = map(int, input().split())
l = [int(i) for i in input().split()]
eff = [0] * (n + 5)
qry = []
for i in range(q):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	qry.append([a, b])
maxi = 0
res = []
for ans in range(n):
	l1 = l[:]
	now = l[ans]
	apply = []
	for j in range(q):
		a = qry[j][0]
		b = qry[j][1]
		if a <= ans <= b:
			pass
		else:
			apply.append(j)
			for i in range(a, b + 1):
				l1[i] -= 1
	if now - min(l1) > maxi:
		maxi = now - min(l1)
		res = apply
print(maxi)
print(len(res))
if not res:
	exit()
for i in res:
	print(i + 1, end=' ')


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = []
for i in range(m):
	b.append(list(map(int, input().split())))
ans = max(a) - min(a)
temp = []
for i in range(n):
	c = a[:]
	l = []
	for j in range(m):
		if i not in range(b[j][0] - 1, b[j][1]):
			for k in range(b[j][0] - 1, b[j][1]):
				c[k] -= 1
			l.append(j + 1)
	if ans < max(c) - min(c):
		ans = max(c) - min(c)
		temp = l
print(ans)
print(len(temp))
print(*temp)


import collections
import functools
import math
import random
import sys
import bisect
input = sys.stdin.readline

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

def arrsegez():
	(n, m) = In()
	l = list(In())
	segs = [set() for _ in range(n)]
	for i in range(m):
		(le, r) = In()
		for x in range(le - 1, r):
			segs[x].add(i + 1)
	maxc = -math.inf
	ansseg = {}
	for i in range(n):
		for i1 in range(i + 1, n):
			c = l[i] - l[i1]
			seg = segs[i1] - segs[i]
			c += len(seg)
			if maxc < c:
				ansseg = seg
				maxc = c
			c = l[i1] - l[i]
			seg = segs[i] - segs[i1]
			c += len(seg)
			if maxc < c:
				ansseg = seg
				maxc = c
	print(maxc if maxc != -math.inf else 0)
	print(len(ansseg))
	print(*ansseg)
arrsegez()


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')
from collections import Counter
import heapq
from collections import Counter
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
seg = []
an = []
for i in range(k):
	(u, v) = map(int, input().split())
	seg.append((u, v))
ans = max(arr) - min(arr)
for i in range(n):
	ls = arr.copy()
	temp = []
	for j in range(k):
		if i not in range(seg[j][0] - 1, seg[j][1]):
			for m in range(seg[j][0] - 1, seg[j][1]):
				ls[m] -= 1
			temp.append(j + 1)
	if ans < max(ls) - min(ls):
		ans = max(ls) - min(ls)
		an = temp
print(ans)
print(len(an))
print(*an)


(n, m) = map(int, input().strip().split())
lst = list(map(int, input().strip().split()))
vidr = []
for i in range(m):
	(a, b) = map(int, input().strip().split())
	vidr.append([a - 1, b - 1])
dif = max(lst) - min(lst)
used = []
for i in range(n):
	new_vidr = []
	new_lst = lst.copy()
	for v in range(m):
		if vidr[v][0] > i or vidr[v][1] < i:
			new_vidr.append(v + 1)
			for j in range(vidr[v][0], vidr[v][1] + 1):
				new_lst[j] -= 1
	d = max(new_lst) - min(new_lst)
	if dif < d:
		dif = d
		used = new_vidr
	dif = max(dif, max(new_lst) - min(new_lst))
print(dif)
print(len(used))
for i in used:
	print(i, end=' ')
print()


import math
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
lr = [None] * m
for i in range(m):
	(l, r) = map(int, input().split())
	lr[i] = [l - 1, r - 1]
saved = []
diff = -math.inf
for cand in range(n):
	used = [False] * m
	for i in range(m):
		if lr[i][0] <= cand <= lr[i][1]:
			used[i] = True
	b = a.copy()
	for i in range(m):
		if used[i]:
			for pos in range(lr[i][0], lr[i][1] + 1):
				b[pos] -= 1
	mx = -math.inf
	mn = math.inf
	for i in range(n):
		mx = max(mx, b[i])
		mn = min(mn, b[i])
	if mx - mn > diff:
		saved.clear()
		diff = mx - mn
		for i in range(m):
			if used[i]:
				saved.append(i + 1)
print(diff)
print(len(saved))
print(' '.join(map(str, saved)))


import collections, atexit, math, sys, bisect
sys.setrecursionlimit(1000000)

def getIntList():
	return list(map(int, input().split()))
try:
	import numpy

	def dprint(*args, **kwargs):
		print(*args, file=sys.stderr)
	dprint('debug mode')
except Exception:

	def dprint(*args, **kwargs):
		pass
inId = 0
outId = 0
if inId > 0:
	dprint('use input', inId)
	try:
		f = open('input' + str(inId) + '.txt', 'r')
		sys.stdin = f
	except Exception:
		dprint('invalid input file')
if outId > 0:
	dprint('use output', outId)
	try:
		f = open('stdout' + str(outId) + '.txt', 'w')
		sys.stdout = f
	except Exception:
		dprint('invalid output file')
	atexit.register(lambda : sys.stdout.close())
(N, M) = getIntList()
za = getIntList()
omin = min(za)
sg = [0 for i in range(N * 4)]
de = sg.copy()

def built_sg(root, left, right):
	if left == right:
		sg[root] = za[left]
		return sg[root]
	mid = (left + right) // 2
	a = built_sg(root * 2 + 1, left, mid)
	b = built_sg(root * 2 + 2, mid + 1, right)
	sg[root] = min(a, b)
	return sg[root]

def update(root, left, right, qleft, qright, dif):
	if qright < left or right < qleft:
		return sg[root]
	if qleft <= left and right <= qright:
		de[root] += dif
		sg[root] += dif
		return sg[root]
	if de[root] != 0:
		t = de[root]
		sg[root * 2 + 1] += t
		sg[root * 2 + 2] += t
		de[root * 2 + 1] += t
		de[root * 2 + 2] += t
		de[root] = 0
	mid = (left + right) // 2
	a = update(root * 2 + 1, left, mid, qleft, qright, dif)
	b = update(root * 2 + 2, mid + 1, right, qleft, qright, dif)
	sg[root] = min(a, b)
	return sg[root]
built_sg(0, 0, N - 1)
zm = []
zz = [0, N]
for i in range(M):
	(l, r) = getIntList()
	l -= 1
	r -= 1
	zm.append((l, r))
	zz.append(l)
	zz.append(r + 1)
zz.sort()
r = max(za) - sg[0]
zr = []
for i in range(len(zz) - 1):
	a = zz[i]
	b = zz[i + 1]
	if a == b:
		continue
	t = max(za[a:b])
	tzr = []
	for j in range(M):
		x = zm[j]
		if x[0] <= a <= x[1]:
			continue
		tzr.append(j + 1)
		update(0, 0, N - 1, x[0], x[1], -1)
	t1 = sg[0]
	if r < t - t1:
		r = t - t1
		zr = tzr
	for x in zm:
		if x[0] <= a <= x[1]:
			continue
		update(0, 0, N - 1, x[0], x[1], 1)
	assert omin == sg[0]
print(r)
print(len(zr))
for x in zr:
	print(x, end=' ')


import math
menor = 10 ** 6 + 1
maior = -(10 ** 6 + 1)
indmenor = -1
indmaior = -1
(n, m) = map(int, input().split())
array = list(map(int, input().split()))
arrayOri = []
for j in range(0, n):
	arrayOri.append(array[j])
for x in range(0, n):
	if array[x] > maior:
		maior = array[x]
	if array[x] < menor:
		menor = array[x]
lista = [[] for x in range(m)]
for x in range(0, m):
	(a, b) = map(int, input().split())
	lista[x].append(a)
	lista[x].append(b)
contresp = 0
resp = []
respfinal = []
cont = 0
diff = maior - menor
for x in range(0, n):
	maior = array[x]
	indmaior = x + 1
	for y in range(0, m):
		if indmaior < lista[y][0] or indmaior > lista[y][1]:
			resp.append(y + 1)
			cont += 1
			for p in range(lista[y][0] - 1, lista[y][1]):
				array[p] -= 1
	menor = 10 ** 6 + 1
	maior = -(10 ** 6 + 1)
	for x in range(0, n):
		if array[x] > maior:
			maior = array[x]
		if array[x] < menor:
			menor = array[x]
	if maior - menor > diff:
		diff = maior - menor
		contresp = cont
		respfinal = resp
	resp = []
	cont = 0
	for j in range(0, n):
		array[j] = arrayOri[j]
print(diff)
print(contresp)
if respfinal:
	for h in respfinal:
		print(h, end=' ')


import os
import sys
from io import BytesIO, IOBase

def main():
	(n, m) = map(int, input().split())
	arr = [0] + list(map(int, input().split()))
	seg = []
	for _ in range(m):
		seg.append(list(map(int, input().split())))
	ans = -float('inf')
	z = 0
	zz = []
	for i in range(1, n + 1):
		mx = arr[i]
		temp = arr.copy()
		flag = 0
		temp1 = []
		for (k, item) in enumerate(seg):
			(l, r) = item
			if l <= i <= r:
				continue
			flag += 1
			for j in range(l, r + 1):
				temp[j] -= 1
			temp1.append(k + 1)
		mm = min(temp[1:])
		if ans < mx - mm:
			ans = mx - mm
			zz = temp1.copy()
			z = flag
	print(ans)
	print(z)
	print(*zz)
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, m) = map(int, input().split())
a = [*map(int, input().split())]
i = 0
c = []
d = []
while i < m:
	(e, f) = map(int, input().split())
	c.append(e)
	d.append(f)
	i += 1
i = 0
j = 0
ans = max(a) - min(a)
ii = 0
jj = 0
while i < n:
	j = 0
	while j < n:
		k = 0
		l = a[j] - a[i]
		if l + m <= ans:
			k = m + 1
		while k < m:
			if l + m - k <= ans:
				k = m - 1
			if c[k] <= i + 1 and d[k] >= i + 1:
				if c[k] > j + 1 or d[k] < j + 1:
					l += 1
			k += 1
		if l > ans:
			ii = i
			jj = j
			ans = l
		j += 1
	i += 1
k = 0
j = jj
i = ii
l = a[j] - a[i]
s = []
while k < m:
	if c[k] <= i + 1 and d[k] >= i + 1:
		if c[k] > j + 1 or d[k] < j + 1:
			s.append(k + 1)
	k += 1
print(ans)
print(len(s))
print(*s, sep=' ')


(n, m) = map(int, input().split())
inputList = [0] + list(map(int, input().split())) + [0]
inputIntervals = []
for _ in range(m):
	inputIntervals.append(tuple(map(int, input().split())))

def wynik(in1, in2):
	intervals = [[] for _ in range(n + 1)]
	for (nr, (a, b)) in enumerate(in2):
		intervals[b] += [(a, nr + 1)]
	wyn = (0, [])
	minek = in1[1]
	numerki = []
	for i in range(2, n + 1):
		minek = min(minek, in1[i - 1])
		for (j, ind) in intervals[i - 1]:
			for k in range(j, i):
				in1[k] -= 1
				minek = min(minek, in1[k])
			numerki += [ind]
		wyn = max(wyn, (in1[i] - minek, list(numerki)))
	return wyn
odp = max(wynik(list(reversed(inputList)), list(map(lambda x: (n - x[1] + 1, n - x[0] + 1), inputIntervals))), wynik(inputList, inputIntervals))
print(odp[0], len(odp[1]), sep='\n')
print(*odp[1])


import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict, deque, Counter, OrderedDict
import threading
from heapq import *

def main():
	(n, m) = map(int, input().split())
	D = [*map(int, input().split())]
	seg = []
	for i in range(m):
		seg.append([*map(int, input().split())])
		seg[i][0] -= 1
		seg[i][1] -= 1
	if n == 1:
		print(0)
		print(0)
		print()
		exit()
	val = [[] for _ in range(n)]
	for i in range(m):
		(x, y) = seg[i]
		for j in range(x, y + 1):
			val[j].append(i + 1)
	ans = [-1, -1]
	for i in range(n):
		change = D + []
		for j in val[i]:
			(x, y) = seg[j - 1]
			for k in range(x, y + 1):
				change[k] -= 1
		(a, b) = (max(change), min(change))
		if ans[1] < abs(a - b):
			ans = [i, abs(a - b)]
	print(ans[1])
	print(len(val[ans[0]]))
	print(*val[ans[0]])
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()


import math
import collections
import bisect
import heapq
import time
import itertools
import sys
(N, M) = map(int, input().split())
A = [int(x) for x in input().split()]
S = []
for i in range(M):
	(l, r) = map(int, input().split())
	S.append((l - 1, r - 1))
maxdiff = 0
ans = []
for i in range(N):
	a = [a for a in A]
	b = []
	for (si, s) in enumerate(S):
		if s[0] <= i <= s[1]:
			b.append(si + 1)
			for j in range(s[0], s[1] + 1):
				a[j] -= 1
	d = max(a) - min(a)
	if d > maxdiff:
		maxdiff = d
		ans = b
print(maxdiff)
print(len(ans))
print(' '.join(map(str, ans)))


class Segments:

	def __init__(self, segments):
		self.segments = segments

	def all(self):
		return [i for i in range(len(self.segments))]

	def at_point(self, point, included=None, excluded=None):
		if included is None:
			included = self.all()
		if excluded is None:
			excluded = []
		segments = []
		for i in range(len(self.segments)):
			if i not in excluded and i in included:
				if self.segments[i][0] <= point <= self.segments[i][1]:
					segments.append(i)
		return segments
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
ends = []
for i in range(m):
	(l, r) = map(int, input().split())
	l -= 1
	r -= 1
	ends.append((l, r))
s = Segments(ends)
delta = max(a) - min(a)
c = []
segment_cache = [s.at_point(i) for i in range(len(a))]
for i in range(len(a)):
	prev_segments = []
	my_segments = []
	for j in range(len(a)):
		if j != i:
			his_segments = segment_cache[j]
			if his_segments != prev_segments:
				my_segments = s.at_point(i, included=his_segments)
			local_max = a[i] - len(my_segments)
			local_min = a[j] - len(his_segments)
			if local_max - local_min > delta:
				delta = local_max - local_min
				c = set(my_segments + his_segments)
			prev_segments = his_segments
print(delta)
print(len(c))
for c_ in c:
	print(c_ + 1, end=' ')


(n, m) = map(int, input().split())
a = [int(i) for i in input().split()]
b = []
for i in range(m):
	(x, y) = map(int, input().split())
	b.append((x, y))
seg = []
ma = -1000002
for i in range(len(a)):
	for j in range(len(a)):
		seg.clear()
		if i == j:
			continue
		cnt = 0
		for idx in range(len(b)):
			(l, r) = b[idx]
			if i >= l - 1 and i < r:
				if j < l - 1 or j >= r:
					cnt += 1
					seg.append(idx + 1)
		if a[j] - a[i] + cnt > ma:
			(pos1, pos2) = (i, j)
			ma = a[j] - a[i] + cnt
			seg2 = seg.copy()
if len(a) == 1:
	print(0)
	print(0)
	print()
else:
	print(ma)
	print(len(seg2))
	for l in seg2:
		print(l, end=' ')


import sys, os, io
from sys import stdin
import math
from collections import defaultdict
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
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')
alphabets = list('abcdefghijklmnopqrstuvwxyz')
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

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 primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def sieveForSmallestPrimeFactor():
	MAXN = 100001
	spf = [0 for i in range(MAXN)]
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, math.ceil(math.sqrt(MAXN))):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
	return spf

def getPrimeFactorizationLOGN(x):
	spf = sieveForSmallestPrimeFactor()
	ret = list()
	while x != 1:
		ret.append(spf[x])
		x = x // spf[x]
	return ret

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

def si():
	return input()

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')

def solve():
	(n, m) = li()
	a = li()
	seg = []
	for i in range(m):
		seg.append(li())
	ans = max(a) - min(a)
	temp = []
	for minn in range(n):
		for maxx in range(n):
			res = []
			cur = 0
			for i in range(m):
				(l, r) = seg[i]
				l -= 1
				r -= 1
				if l <= minn <= r and (maxx > r or maxx < l):
					cur += 1
					res.append(i + 1)
			cur += a[maxx] - a[minn]
			if ans < cur:
				temp = res[:]
			ans = max(ans, cur)
	print(ans)
	print(len(temp))
	print(*temp)
t = 1
for _ in range(t):
	solve()


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
arr = [set() for i in range(n)]
for i in range(m):
	(l, r) = map(int, input().split())
	l -= 1
	for j in range(l, r):
		arr[j].add(i)
maxi = 0
(b, s) = (0, 0)
d = 0
ans = []
f_ans = []
for i in range(n):
	for j in range(n):
		d = 0
		ans = []
		for k in range(300):
			if k in arr[i] and k not in arr[j]:
				d += 1
				ans.append(k + 1)
		if maxi < a[j] - a[i] + d:
			maxi = a[j] - a[i] + d
			f_ans = ans
print(maxi)
print(len(f_ans))
print(*f_ans)


(n, m) = map(int, input().split())
b = list(map(int, input().split()))
segs = [list(map(int, input().split())) for _ in range(m)]
a = []
d = []
for i in range(n):
	w = [i for i in b]
	x = [0] * (n + 1)
	t = []
	for j in range(m):
		(left, right) = (segs[j][0], segs[j][1])
		if i >= left - 1 and i <= right - 1:
			x[left - 1] -= 1
			x[right] += 1
			t.append(j + 1)
	d.append(t)
	for j in range(1, n + 1):
		x[j] += x[j - 1]
	for j in range(n):
		w[j] += x[j]
	if m > 0:
		l = min(w)
		h = max(w)
		a.append(h - l)
if a != []:
	f = a.index(max(a))
	if max(b) - min(b) > max(a):
		print(max(b) - min(b))
		print(0)
		print()
	else:
		print(max(a))
		print(len(d[f]))
		print(*d[f])
else:
	print(max(b) - min(b))
	print(0)
	print()


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
lr = [list(map(int, input().split())) for _ in range(m)]
for i in range(m):
	lr[i][0] -= 1
inf = 1145141919
d = -inf
for i in range(n):
	for j in range(n):
		b = [0] * (n + 1)
		c0 = []
		for k in range(m):
			(l, r) = lr[k]
			if l <= i < r and (not l <= j < r):
				b[l] -= 1
				b[r] += 1
				c0.append(k + 1)
		(mi, ma) = (inf, -inf)
		s = 0
		for k in range(n):
			s += b[k]
			ak = s + a[k]
			mi = min(mi, ak)
			ma = max(ma, ak)
		if d < ma - mi:
			d = ma - mi
			c = c0
q = len(c)
print(d)
print(q)
print(*c)


(n, m) = map(int, input().split())
ls = list(map(int, input().split()))
segs = [None for _ in range(m)]
maxdiv = 0
maxsegs = set()
for i in range(m):
	(l, r) = map(int, input().split())
	segs[i] = (l - 1, r - 1)
for maxi in range(n):
	currarr = [0 for _ in range(n + 1)]
	usegs = set()
	for (ind, seg) in enumerate(segs):
		if maxi < seg[0] or maxi > seg[1]:
			currarr[seg[0]] -= 1
			currarr[seg[1] + 1] += 1
			usegs.add(ind)
	cnt = 0
	minv = 10000000
	for j in range(n):
		cnt += currarr[j]
		v = ls[j] + cnt
		if v < minv:
			minv = v
	v = ls[maxi] - minv
	if maxdiv < v:
		maxdiv = v
		maxsegs = usegs
print(maxdiv)
print(len(maxsegs))
print(' '.join([str(v + 1) for v in maxsegs]))


(n, m) = map(int, input().split())
mass = list(map(int, input().split()))
lr = []
for t in range(m):
	(l, r) = map(int, input().split())
	lr.append([l, r])
mq = 0
mdel = []
mitog = 0
for a in range(len(mass)):
	ma = mass[a]
	for b in range(len(mass)):
		mb = mass[b]
		q = 0
		delete = []
		itog = 0
		for x in range(len(lr)):
			(l, r) = (lr[x][0], lr[x][1])
			if l <= b + 1 <= r and (a + 1 < l or a + 1 > r):
				q += 1
				delete.append(x + 1)
		itog = ma + q - mb
		if mitog < itog:
			mitog = itog
			mq = q
			mdel = delete
print(mitog)
print(mq)
if len(mdel):
	print(' '.join(list(map(str, mdel))))
else:
	print('')


import sys
import copy
input = sys.stdin.readline
(n, m) = map(int, input().split())
A = list(map(int, input().split()))
LR = [list(map(int, input().split())) for i in range(m)]
MLIST = []
for (l, r) in LR:
	MLIST.append(l)
	MLIST.append(r)
MLIST = list(set(MLIST))
MLIST.sort()
MLIST.append(10 ** 9)
MDICT = dict()
MLEN = len(MLIST)
for i in range(MLEN):
	MDICT[MLIST[i]] = i
MINUSLIST = [[0] * (MLEN * 2 - 1) for i in range(MLEN)]
for (l, r) in LR:
	for j in range(MDICT[l], MDICT[r] + 1):
		for k in range(MDICT[l] * 2 + 1, MDICT[r] * 2 + 2):
			MINUSLIST[j][k] += 1
A_m = [[float('inf'), -float('inf')] for i in range(MLEN * 2 - 1)]
if MLIST[0] != 1:
	A_m[0] = [min(A[:MLIST[0] - 1]), max(A[:MLIST[0] - 1])]
for i in range(MLEN - 1):
	x = MLIST[i] - 1
	y = MLIST[i + 1] - 1
	A_m[2 * i + 1] = [A[x], A[x]]
	if x + 1 != y and x != n - 1:
		A_m[2 * i + 2] = [min(A[x + 1:y]), max(A[x + 1:y])]

def MINUS(A, B):
	MIN = float('inf')
	MAX = -float('inf')
	for i in range(MLEN * 2 - 1):
		if MIN > A[i][0] - B[i]:
			MIN = A[i][0] - B[i]
		if MAX < A[i][1] - B[i]:
			MAX = A[i][1] - B[i]
	return MAX - MIN
ANSLIST = [0] * MLEN
for i in range(MLEN):
	ANSLIST[i] = MINUS(A_m, MINUSLIST[i])
print(max(ANSLIST))
target = MLIST[ANSLIST.index(max(ANSLIST))]
AN = []
for i in range(m):
	(z, w) = LR[i]
	if z <= target <= w:
		AN.append(i + 1)
print(len(AN))
for a in AN:
	print(a, end=' ')