PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000070. Chuỗi đong nước tiết kiệm nhất (Water Containers Moves)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Chuỗi đong nước tiết kiệm nhất (Water Containers Moves)

Water Containers Moves

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

Two containers A and B have capacities a and b and start empty. You may fill, empty, or pour between them until the source becomes empty or the destination becomes full. Every operation must actually move a positive amount of water. Find a sequence ending with exactly x units in A that minimizes the total amount of water moved, including filling and emptying. Output the number of operations and the total moved amount, followed by the operations FILL A, FILL B, EMPTY A, EMPTY B, MOVE A B, or MOVE B A. Print -1 if impossible.

Input

Three positive integers a b x.

Output

Either -1, or a first line containing n m followed by n valid operation lines, with minimum possible total moved amount m.

Subtasks

  • Subtask 1 (20 points): 1≤a,b,x≤201\le a,b,x\le 20.
  • Subtask 2 (30 points): 1≤a,b,x≤2001\le a,b,x\le 200.
  • Subtask 3 (50 points): 1≤a,b,x≤10001\le a,b,x\le 1000.

Examples

Input

5 3 4

Output

6 19
FILL A
MOVE A B
EMPTY B
MOVE A B
FILL A
MOVE A B

Explanation

The example moves lead to state (4,3) with moved amounts 5+3+3+2+5+1=19, which is minimal.