CF1102D.Balanced Ternary String

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a string ss consisting of exactly nn characters, and each character is either '0', '1' or '2'. Such strings are called ternary strings.

Your task is to replace minimum number of characters in this string with other characters to obtain a balanced ternary string (balanced ternary string is a ternary string such that the number of characters '0' in this string is equal to the number of characters '1', and the number of characters '1' (and '0' obviously) is equal to the number of characters '2').

Among all possible balanced ternary strings you have to obtain the lexicographically (alphabetically) smallest.

Note that you can neither remove characters from the string nor add characters to the string. Also note that you can replace the given characters only with characters '0', '1' and '2'.

It is guaranteed that the answer exists.

输入格式

The first line of the input contains one integer nn ( 3n31053 \le n \le 3 \cdot 10^5 , nn is divisible by 33 ) — the number of characters in ss .

The second line contains the string ss consisting of exactly nn characters '0', '1' and '2'.

输出格式

Print one string — the lexicographically (alphabetically) smallest balanced ternary string which can be obtained from the given one with minimum number of replacements.

Because nn is divisible by 33 it is obvious that the answer exists. And it is obvious that there is only one possible answer.

输入输出样例

  • 输入#1

    3
    121
    

    输出#1

    021
    
  • 输入#2

    6
    000000
    

    输出#2

    001122
    
  • 输入#3

    6
    211200
    

    输出#3

    211200
    
  • 输入#4

    6
    120110
    

    输出#4

    120120
    
首页