This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.

Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.

As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.

The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?

Polycarp can throw his fire ball into an archer if the latter is already killed.

Input

The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.

Output

In the first line print t — the required minimum amount of fire balls.

In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.

Examples

Input

3 2 1
2 2 2


Output

3
2 2 2 

Input

4 3 1
1 4 1 1


Output

4
2 2 3 3

Difficulty: VERY_HARD
Tags: Dynamic programming

Complete search
Skill types: Dynamic programming

Complete search

Starter code:

Solutions:
(n, a, b) = list(map(int, input().split(' ')))
h = list(map(lambda x: int(x) + 1, input().split(' ')))
dp = [[[-1] * 17 for j in range(17)] for i in range(n)]
num = [[[0] * 17 for j in range(17)] for i in range(n)]
health = [[[0] * 17 for j in range(17)] for i in range(n)]
result = []

def recursion(i, j, k):
	if i == n - 1:
		return float('inf') if j > 0 else 0
	if dp[i][j][k] != -1:
		return dp[i][j][k]
	dp[i][j][k] = float('inf')
	for s in range(17):
		if j <= s * b:
			bt = s + recursion(i + 1, max(0, h[i] - k * b - s * a), s)
			if bt < dp[i][j][k]:
				dp[i][j][k] = bt
				num[i][j][k] = s
				health[i][j][k] = max(0, h[i] - k * b - s * a)
	return dp[i][j][k]

def compute(i, j, k):
	global result
	if i == n - 1:
		return
	result += [str(i + 1)] * num[i][j][k]
	compute(i + 1, health[i][j][k], num[i][j][k])
while h[0] > 0:
	h[0] = max(h[0] - b, 0)
	h[1] = max(h[1] - a, 0)
	h[2] = max(h[2] - b, 0)
	result.append(str(2))
while h[n - 1] > 0:
	h[n - 1] = max(h[n - 1] - b, 0)
	h[n - 2] = max(h[n - 2] - a, 0)
	h[n - 3] = max(h[n - 3] - b, 0)
	result.append(str(n - 1))
recursion(1, 0, 0)
compute(1, 0, 0)
print(len(result))
print(' '.join(result))


(n, a, b) = map(int, input().split())
f = list(map(int, input().split()))
mn = 1 << 64
hit = None

def dfs(p, ans, hit2):
	global mn
	if ans >= mn:
		return
	if p == n - 1:
		if ans < mn:
			global hit
			hit = hit2.copy()
			mn = ans
		return
	if f[p - 1] < 0:
		dfs(p + 1, ans, hit2)
	t = max(f[p - 1] // b + 1, f[p] // a + 1)
	for i in range(t + 1):
		if f[p - 1] < b * i:
			f[p - 1] -= b * i
			f[p] -= a * i
			f[p + 1] -= b * i
			for j in range(i):
				hit2.append(p)
			dfs(p + 1, ans + i, hit2)
			f[p - 1] += b * i
			f[p] += a * i
			f[p + 1] += b * i
			for j in range(i):
				hit2.pop()
	return
hit2 = []
a1 = f[0] // b + 1
f[0] -= b * a1
f[1] -= a * a1
f[2] -= b * a1
ret = a1
for i in range(a1):
	hit2.append(1)
if f[n - 1] >= 0:
	a1 = f[n - 1] // b + 1
	f[n - 1] -= b * a1
	f[n - 2] -= a * a1
	f[n - 3] -= b * a1
	for i in range(a1):
		hit2.append(n - 2)
	ret += a1
dfs(1, 0, hit2)
mn += ret
print(mn)
for i in range(mn):
	print(hit[i] + 1, end=' ')
print('')


import sys

def main():
	(n, a, b) = map(int, sys.stdin.readline().strip().split())
	archers = list(map(int, sys.stdin.readline().strip().split()))
	temp = [0] * n
	shots = []
	shots_first = archers[0] // b + 1
	archers[0] -= shots_first * b
	archers[1] -= shots_first * a
	archers[2] -= shots_first * b
	shots_last = archers[n - 1] // b + 1
	archers[n - 1] -= shots_last * b
	archers[n - 2] -= shots_last * a
	archers[n - 3] -= shots_last * b
	min_shots = 10000

	def kill(current_archer, life_current, life_left):
		nonlocal temp, shots, min_shots
		next_archer = current_archer + 1
		min_shots_kill_left = life_left // b + 1 if life_left >= 0 else 0
		min_shots_kill_current = life_current // a + 1 if life_current >= 0 else 0
		min_shots_kill_right = archers[next_archer] // b + 1 if archers[next_archer] >= 0 else 0
		min_shots_kill_trio = max(min_shots_kill_left, min_shots_kill_current, min_shots_kill_right)
		accum_shots = sum(temp[:current_archer])
		if current_archer == n - 2:
			temp[n - 2] = min_shots_kill_trio
			accum_shots += min_shots_kill_trio
			if min_shots > accum_shots:
				min_shots = accum_shots
				shots = temp.copy()
			return
		life = life_current - min_shots_kill_left * a
		if (life // a + 1 if life >= 0 else 0) == (life // b + 1 if life >= 0 else 0):
			temp[current_archer] = min_shots_kill_left
			kill(next_archer, archers[next_archer] - min_shots_kill_left * b, life)
		else:
			for j in range(min_shots_kill_left, min_shots_kill_trio + 1):
				if accum_shots + j >= min_shots:
					break
				temp[current_archer] = j
				kill(next_archer, archers[next_archer] - j * b, life_current - j * a)
	kill(1, archers[1], archers[0])
	shots[1] += shots_first
	shots[n - 2] += shots_last
	min_shots += shots_first + shots_last
	sys.stdout.write(str(min_shots) + '\n')
	sys.stdout.write(' '.join((str(pos) for (pos, s) in enumerate(shots, start=1) for _ in range(s))) + '\n')
main()


def dfs(step, left, mx):
	if step == 0:
		for i in range(0, n):
			if h[i] >= 0:
				return False
		return True
	else:
		if h[left - 1] < 0 and h[left] < 0 and (left + 2 != n):
			if dfs(step, left + 1, mx):
				return True
		else:
			if left >= mx:
				h[left - 1] -= b
				h[left] -= a
				h[left + 1] -= b
				ans[step] = left
				if dfs(step - 1, left, left):
					return True
				h[left - 1] += b
				h[left] += a
				h[left + 1] += b
			if left + 1 >= mx and left + 1 < n - 1:
				h[left] -= b
				h[left + 1] -= a
				h[left + 2] -= b
				ans[step] = left + 1
				if dfs(step - 1, left, left + 1):
					return True
				h[left] += b
				h[left + 1] += a
				h[left + 2] += b
		return False
(n, a, b) = input().split()
n = int(n)
a = int(a)
b = int(b)
h = list(map(int, input().split()))
ans = list(range(0, 200))
for i in range(0, 200):
	if dfs(i, 1, 1):
		print(i)
		for j in range(1, i):
			print(ans[j] + 1, end=' ')
		print(ans[i] + 1)
		break


(N, a, b) = [int(_) for _ in input().split()]
h = [int(_) for _ in input().split()]
t = h[-1] // b + 1
h[-1] -= t * b
h[-2] -= t * a
h[-3] -= t * b
import sys
res = [sys.maxsize, None]
cnt = [0] * N

def search(idx, cur):
	if idx == N - 1:
		y = h[idx - 1] // a + 1 if h[idx - 1] >= 0 else 0
		if cur + y < res[0]:
			res[0] = cur + y
			cnt[N - 2] += t + y
			res[1] = cnt[:]
		return
	x = h[idx - 1] // b + 1 if h[idx - 1] >= 0 else 0
	while cur + x < res[0]:
		h[idx - 1] -= x * b
		h[idx] -= x * a
		h[idx + 1] -= x * b
		cnt[idx] = x
		search(idx + 1, cur + x)
		h[idx - 1] += x * b
		h[idx] += x * a
		h[idx + 1] += x * b
		x += 1
search(1, t)
print(res[0])
s = []
for i in range(N):
	for _ in range(res[1][i]):
		s.append(str(i + 1))
print(' '.join(s))


(n, a, b) = map(int, input().split())
h = list(map(int, input().split()))
t = h[-1] // b + 1
h[-1] -= t * b
h[-2] -= t * a
h[-3] -= t * b
import sys
res = [sys.maxsize, None]
c = [0] * n

def search(i, cur):
	if i == n - 1:
		res[0] = cur
		c[n - 2] += t
		res[1] = c[:]
		return
	if h[i - 1] >= 0:
		x = h[i - 1] // b + 1
	else:
		x = 0
	while cur + x < res[0]:
		h[i - 1] -= x * b
		h[i] -= x * a
		h[i + 1] -= x * b
		c[i] = x
		search(i + 1, cur + x)
		h[i - 1] += x * b
		h[i] += x * a
		h[i + 1] += x * b
		x += 1
search(1, t)
print(res[0])
s = []
for i in range(n):
	for j in range(res[1][i]):
		s.append(str(i + 1))
print(' '.join(s))


import math
steps = 0

def base_gen(b, l):
	n = [0] * l
	yield n[:]
	while not all((ne == b - 1 for ne in n)):
		p = l - 1
		while n[p] == b - 1:
			n[p] = 0
			p -= 1
		n[p] += 1
		yield n[:]

def deplete(pos, val, n, a, b, gs):
	gs[pos - 1] -= b * val
	gs[pos] -= a * val
	gs[pos + 1] -= b * val

def fill_gaps(s, n, a, b, hs):
	gs = hs[:]
	for i in range(2, len(s) - 1, 2):
		deplete(i, s[i], n, a, b, gs)
	for i in range(1, len(s) - 1, 2):
		val = max([0] + [math.ceil(x) for x in [gs[i - 1] / b, gs[i] / a]])
		s[i] = val
		deplete(i, s[i], n, a, b, gs)
	val = max(0, math.ceil(gs[-1] / b))
	s[-2] += val
	deplete(len(s) - 2, val, n, a, b, gs)
	return (s, gs)

def merged_base(bs, n):
	st = [0] * n
	for (bi, be) in enumerate(bs):
		st[2 + bi * 2] = be
	return st
(n, a, b) = [int(x) for x in input().split()]
hs = [int(x) for x in input().split()]
hs = [hse + 1 for hse in hs]
min_final_state = []
min_score = float('inf')
for bs in base_gen(math.ceil(max(hs) / min(a, b)) + 1, (n - 2) // 2):
	st = merged_base(bs, n)
	(final_state, remained_health) = fill_gaps(st, n, a, b, hs)
	assert all((rh <= 0 for rh in remained_health))
	if sum(final_state) < min_score:
		min_score = sum(final_state)
		min_final_state = final_state
print(sum(min_final_state))
res = []
for (i, v) in enumerate(min_final_state):
	res += [i + 1] * v
print(*res)


res = 10000
path = []
(n, a, b) = map(int, input().split())

def solve(cnt, idx, arc, p):
	global res
	global path
	if idx == n - 1:
		if res > cnt:
			res = cnt
			path = p.copy()
		return
	if cnt > res:
		return
	if arc[idx] < 0 and arc[idx - 1] < 0:
		solve(cnt, idx + 1, arc, p)
	else:
		(min_t, max_t) = (arc[idx - 1] // b + 1, arc[idx] + 2 // a + 1)
		min_t = max(min_t, 0)
		max_t = max(min_t, max_t)
		for i in range(min_t, max_t + 1):
			arc[idx - 1] -= i * b
			arc[idx] -= i * a
			arc[idx + 1] -= i * b
			p.extend([idx + 1] * i)
			solve(cnt + i, idx + 1, arc, p)
			for _ in range(i):
				p.pop()
			arc[idx - 1] += i * b
			arc[idx] += i * a
			arc[idx + 1] += i * b
h = list(map(int, input().split()))
t = h[n - 1] // b + 1
h[n - 1] -= t * b
h[n - 2] -= t * a
h[n - 3] -= t * b
tmp = []
tmp.extend([n - 1] * t)
solve(t, 1, h, tmp)
print(res)
print(' '.join((str(i) for i in path)))


__author__ = 'Darren'

def solve():
	(n, a, b) = map(int, input().split())
	h = [0]
	h.extend(map(int, input().split()))
	fires = []
	count = h[1] // b + 1 if h[1] >= 0 else 0
	fires.extend([2 for i in range(count)])
	h[1] -= b * count
	h[2] -= a * count
	h[3] -= b * count
	count = h[n] // b + 1 if h[n] >= 0 else 0
	fires.extend([n - 1 for i in range(count)])
	h[n] -= b * count
	h[n - 1] -= a * count
	h[n - 2] -= b * count
	temp = fires.copy()
	for i in range(2, n):
		count = h[i] // a + 1
		fires.extend([i for j in range(count)])

	def search(pos):
		nonlocal n, a, b, h, fires, temp
		if pos == n and h[pos - 1] < 0:
			if len(fires) > len(temp):
				fires = temp.copy()
			return
		balls = 0
		count = h[pos - 1] // b + 1 if h[pos - 1] >= 0 else 0
		temp.extend([pos for i in range(count)])
		h[pos - 1] -= b * count
		h[pos] -= a * count
		h[pos + 1] -= b * count
		balls += count
		while h[pos] >= 0:
			search(pos + 1)
			temp.append(pos)
			h[pos - 1] -= b
			h[pos] -= a
			h[pos + 1] -= b
			balls += 1
		search(pos + 1)
		h[pos - 1] += b * balls
		h[pos] += a * balls
		h[pos + 1] += b * balls
		for i in range(balls):
			temp.pop()
	search(2)
	print(len(fires))
	print(' '.join(map(str, fires)))
solve()


def main():
	(n, a, b) = map(int, input().split())
	health = [0]
	health.extend(map(int, input().split()))
	target = [0] * len(health)

	def need(t, d):
		nonlocal health
		p = health[t]
		return p // d + 1 if p >= 0 else 0
	least_target = []
	least_thrown = sum(health)
	last_need = max(need(n - 1, a), need(n, b))

	def beat(left, sofar):
		nonlocal health, target, n, a, b, need
		nonlocal least_thrown, least_target, last_need
		if sofar >= least_thrown:
			return
		center = left + 1
		right = center + 1
		if right == n:
			m = max(need(left, b), last_need)
			thrown = sofar + m
			if thrown < least_thrown:
				least_thrown = thrown
				least_target = target[:]
				least_target[center] += m
			return
		must = need(left, b)
		for m in range(must, max(must, need(center, a)) + 1):
			ma = m * a
			mb = m * b
			health[left] -= mb
			health[center] -= ma
			health[right] -= mb
			target[center] += m
			beat(center, sofar + m)
			target[center] -= m
			health[right] += mb
			health[center] += ma
			health[left] += mb
	beat(1, 0)

	def target_sequence(targets):
		for (t, k) in enumerate(targets):
			if k:
				s = str(t)
				yield from (s for _ in range(k))
	if least_target:
		print(least_thrown)
		print(' '.join(target_sequence(least_target)))
	else:
		print(0)
		print()
main()


import math
(n, a, b) = map(int, input().split())
arr = list(map(int, input().split()))
res = []

def helper(idx, arr, path, memo):
	global res
	if len(res) != 0 and len(path) >= len(res):
		return
	if idx == len(arr) - 1:
		if len(res) == 0 or len(path) < len(res):
			res = path.copy()
		return
	status = str(idx) + ' '
	for val in arr:
		status += str(val) + ' '
	if status in memo:
		return
	else:
		memo.add(status)
	if idx == len(arr) - 2:
		cnt = max(arr[idx - 1] // b + 1, arr[idx] // a + 1, arr[idx + 1] // b + 1)
		path.extend([idx] * cnt)
		helper(idx + 1, arr, path, memo)
		if cnt > 0:
			del path[-cnt:]
	else:
		cnt = arr[idx - 1] // b + 1
		if cnt < 0:
			cnt = 0
		path.extend([idx] * cnt)
		arr[idx] -= cnt * a
		arr[idx - 1] -= cnt * b
		arr[idx + 1] -= cnt * b
		helper(idx + 1, arr, path, memo)
		while arr[idx] >= 0:
			arr[idx] -= a
			arr[idx - 1] -= b
			arr[idx + 1] -= b
			path.append(idx)
			cnt += 1
			helper(idx + 1, arr, path, memo)
		if cnt > 0:
			del path[-cnt:]
		arr[idx] += cnt * a
		arr[idx - 1] += cnt * b
		arr[idx + 1] += cnt * b
	return
memo = set()
helper(1, arr, [], memo)
ret = [x + 1 for x in res]
print(len(ret))
print(' '.join(map(str, ret)))