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

#CCBCHBAHAI0000076. Xóa mọi số 0, giữ thứ tự (Remove All Zeros While Preserving Order)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Xóa mọi số 0, giữ thứ tự (Remove All Zeros While Preserving Order)

Remove All Zeros While Preserving Order

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem

Given a0,a1,…,an−1a_0,a_1,\ldots,a_{n-1}, remove every zero while preserving the relative order of all nonzero elements.

Let

$$J=\{i\mid0\le i<n,\ a_i\ne0\}=\{j_0<\cdots<j_{m-1}\}.$$

The result has length m=∣J∣m=|J| and bk=ajkb_k=a_{j_k} for 0≤k<m0\le k<m. If all elements are zero, then m=0m=0 and the result is empty.

Input

The first line contains nn. The second line contains nn integers aia_i.

Output

Print mm on the first line. If m>0m>0, print b0,…,bm−1b_0,\ldots,b_{m-1} on the second line; otherwise the second line is empty.

Subtask

Subtask 1 (20 points): 1≤n≤101\le n\le 10, ∣ai∣≤103|a_i|\le 10^3.

Subtask 2 (30 points): 1≤n≤50001\le n\le 5000, ∣ai∣≤106|a_i|\le 10^6.

Subtask 3 (50 points): 1≤n≤2⋅1051\le n\le 2\cdot 10^5, ∣ai∣≤109|a_i|\le 10^9.

Example

Input

8
0 5 0 -2 7 0 0 4

Output

4
5 -2 7 4

Explanation

The output follows directly from the mathematical definition above.