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

#GD0000033. Số ghép lớn nhất (Largest Number)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Số ghép lớn nhất (Largest Number)

Largest Number

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Given nn non-negative integers, arrange them and concatenate their decimal representations to form the largest possible number.

Input

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

Output

Print the largest number as a string. If all values are zero, print a single 0.

Constraints

  • 1≤n≤1051\le n\le 10^5.
  • 0≤ai≤1090\le a_i\le 10^9 for 1≤i≤n1\le i\le n.

Subtasks

  • Subtask 1 (20 points): n≤8n\le 8.
  • Subtask 2 (30 points): n≤30n\le 30.
  • Subtask 3 (50 points): Full constraints.

Examples

Input

5
3 30 34 5 9

Output

9534330

Explanation

The sample follows the ordering rule described in the Vietnamese explanation and produces the shown optimum.