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

#QHD0000052. Xếp xe lên phà (Ferry Loading)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Xếp xe lên phà (Ferry Loading)

Ferry Loading

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

A ferry has two separate lanes, port and starboard. Each lane can hold cars of total length at most LL metres. There are nn cars in a single ordered queue; car ii is aia_i centimetres long.

Cars must be loaded in their given order. A car may be assigned to either lane if there is sufficient remaining room. You may not skip a car in order to load a later car. Maximize the number of cars in the longest loadable prefix, and print any valid assignment of those cars to the two lanes. Notice the difference between metres and centimetres.

Input

The first line contains L,nL,n. The next nn lines each contain a car length aia_i in centimetres.

Output

Print the maximum number kk of loaded cars, followed by kk lines in queue order, each port or starboard. Any valid optimal assignment is accepted.

Subtasks

Scoring groups are independent. All constraints listed for a group apply simultaneously.

  • Subtask 1 (20%): 1≤L≤101\le L\le 10 (metres), 1≤n≤121\le n\le12, 100≤ai≤1000100\le a_i\le1000 (cm).
  • Subtask 2 (30%): 1≤L≤501\le L\le50 (metres), 1≤n≤801\le n\le80, 100≤ai≤3000100\le a_i\le3000 (cm).
  • Subtask 3 (50%): 1≤L≤1001\le L\le100 (metres), 1≤n≤2001\le n\le200, 100≤ai≤3000100\le a_i\le3000 (cm).

Examples

Input

5 4
300
200
300
200

Output

4
port
port
starboard
starboard

Explanation

Each lane has capacity 500500 cm. Put cars 1 and 2 on port (300+200=500300+200=500), and cars 3 and 4 on starboard (300+200=500300+200=500), so all four cars fit.