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

#QHD0000011. Bài tập của Người Nhện (Spiderman's Workout)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Bài tập của Người Nhện (Spiderman's Workout)

Spiderman's Workout

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

Spiderman completes MM consecutive climbing stages. During stage ii, he must move vertically by exactly did_i metres, either up (U) or down (D). The stages must be performed in their given order.

He starts at height 00 and must finish at height 00, and his height must never become negative.

Among all legal routes, find a sequence of directions that minimizes the maximum height reached. If no legal route exists, print IMPOSSIBLE.

Input

The first line contains MM, the number of climbing stages.

The second line contains MM positive integers d1,d2,…,dMd_1,d_2,\ldots,d_M, the stage lengths in order.

Output

Print a string of exactly MM characters U or D describing an optimal legal route. Any optimal route is accepted. If no legal route exists, print IMPOSSIBLE.

Subtasks

  • Subtask 1 (20 points): 1≤M≤121\le M\le 12; 1≤di≤10001\le d_i\le 1000 (1≤i≤M1\le i\le M); 1≤∑i=1Mdi≤801\le \sum_{i=1}^{M}d_i\le 80.
  • Subtask 2 (30 points): 1≤M≤261\le M\le 26; 1≤di≤10001\le d_i\le 1000 (1≤i≤M1\le i\le M); 1≤∑i=1Mdi≤4001\le \sum_{i=1}^{M}d_i\le 400.
  • Subtask 3 (50 points): 1≤M≤401\le M\le 40; 1≤di≤10001\le d_i\le 1000 (1≤i≤M1\le i\le M); 1≤∑i=1Mdi≤10001\le \sum_{i=1}^{M}d_i\le 1000.

Examples

Input

4
20 20 20 20

Output

UDUD

Explanation

The route UDUD reaches heights 20,0,20,020,0,20,0. Its peak is 2020; any legal solution must climb 2020 in its first stage, so this peak is optimal.