Champernowne Subsequence

시간 제한2초메모리 제한2048 MB

요약
숫자 문자열이 주어질 때, 1부터 k까지 이어 붙인 문자열의 부분 수열이 되는 가장 작은 k를 구한다.
난이도

어려움10점 중 8점

유형
그리디, 수학, 문자열 매칭, 구현
정답자
아직 제출이 없습니다

문제

The kthk^{\text{th}} Champernowne word is obtained by writing down the first kk positive integers and concatenating them together. For example, the 10th10^{\text{th}} Champernowne word is 1234567891012345678910.

It can be proven that, for any finite string of digits, there exists some integer kk such that the finite string of digits will appear as a subsequence in the kthk^{\text{th}} Champernowne word.

String ss is a subsequence of string tt if it is possible to delete some (possibly zero) characters from tt to get ss.

Given a string of digits, compute the smallest integer kk such that the given string of digits is a subsequence of the kthk^{\text{th}} Champernowne word.

입력

The first line of input contains a single integer nn (1≤n≤105)(1 \leq n \leq 10^5), the length of the string of digits.

The second line of input contains a string of nn digits.

출력

Output a single integer kk, the minimum integer such that the given string is a subsequence of the kthk^{\text{th}} Champernowne word.

예제2

  1. 예제 1

    입력
    2
    90
    
    예상 출력
    10
    
  2. 예제 2

    입력
    2
    00
    
    예상 출력
    20