#K64487. Reformat List

    ID: 31986 Type: Default 1000ms 256MiB

Reformat List

Reformat List

You are given a list of tokens, where each token is a single character. These characters can be digits (0-9), alphabetical letters (a-z or A-Z), or special symbols (such as @, #, $, etc.). Your task is to reformat the list such that all the digits appear first (in their original order), followed by all the alphabetical letters (in their original order), and finally followed by all the special symbols (again, preserving their original order).

In other words, if the input list is represented by \(L = [l_1, l_2, \dots, l_n]\), partition \(L\) into three parts \(D, A, S\) where:

  • \(D\) contains all digits from \(L\) in the order they appear,
  • \(A\) contains all alphabetical letters from \(L\) in order, and
  • \(S\) contains the remaining special symbols in order.

The final formatted list should be \(D \oplus A \oplus S\) where \(\oplus\) denotes list concatenation.

inputFormat

The input is read from standard input (stdin) and has the following format:

  1. The first line contains a single integer \(n\) representing the number of elements in the list.
  2. The second line contains \(n\) space-separated tokens (each token is a single character): digits, alphabetical letters, or special symbols.

outputFormat

Print the reformatted list to standard output (stdout) as a single line where the tokens are space-separated.

## sample
10
4 a 5 b * & 6 c % $
4 5 6 a b c * & % $

</p>