Problem:
Score : 1000 points

Problem Statement

You are given a string S consisting of digits between 1 and 9, inclusive.
You will insert at most K commas (,) into this string to separate it into multiple numbers.

Your task is to minimize the maximum number among those produced by inserting commas. Find minimum possible such value.

Constraints

0 ≦ K < |S| ≦ 100,000

S consists of digits between 1 and 9, inclusive.

Partial Scores

In the test set worth 100 points, |S| ≦ 2.

In the test set worth another 100 points, |S| ≦ 16.

In the test set worth another 200 points, |S| ≦ 100.

In the test set worth another 200 points, |S| ≦ 2,000.

Input

The input is given from Standard Input in the following format:

K
S

Output

Print the minimum possible value.

Sample Input 1

2
15267315

Sample Output 1

315

When the string is separated into 152, 67 and 315, the maximum among these is 315, which is the minimum possible value.

Sample Input 2

0
12456174517653111

Sample Output 2

12456174517653111

12456174517653111 itself is the answer.

Sample Input 3

8
127356176351764127645176543176531763517635176531278461856198765816581726586715987216581

Sample Output 3

5317635176

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
using ii = pair<int,int>;
ii mods = {1'000'000'007, 1'000'000'009};
ii base = {313, 419};
int add(int a, int b, int mod){
	a += b;
	if(a >= mod) a -= mod;
	return a;
}
int mul(long long a, long long b, int mod){
	return a * b % mod;
}
ii operator + (ii a, ii b){
	return make_pair(add(a.first, b.first, mods.first), add(a.second, b.second, mods.second));
}
ii operator - (ii a, ii b){
	return make_pair(add(a.first, mods.first - b.first, mods.first), add(a.second, mods.first - b.second, mods.second));
}
ii operator * (ii a, ii b){
	return make_pair(mul(a.first, b.first, mods.first), add(a.second, b.second, mods.second));
}
ii text[maxn], pattern[maxn], pwrs[maxn];
ii get_text(int l, int r){
	return text[r + 1] - pwrs[r - l + 1] * text[l];
}
ii get_pattern(int l, int r){
	return pattern[r + 1] - pwrs[r - l + 1] * pattern[l];
}
int main(){
	pwrs[0] = {1, 1};
	for(int i = 1; i < maxn; i++) pwrs[i] = pwrs[i - 1] * base;
	text[0] = {0, 0};
	pattern[0] = {0, 0};
	int k; string s; cin >> k >> s;
	int n = s.length(); k++;
	for(int i = 0; i < n; i++){
		text[i + 1] = text[i] * base + make_pair(s[i], s[i]);
	}
	int rn = (n + k - 1) / k;
	string ans(rn, '9');
	for(int i = 0; i < rn; i++){
		for(int v = '1'; v <= '9'; v++){
			ans[i] = v;
			pattern[i + 1] = pattern[i] * base + make_pair(v, v);
			int blocks = 0;
			bool bad = false;
			for(int j = 0; j < n; ){
				int lo = 0, hi = min(i, n - j - 1), pos = -1;
				while(lo <= hi){
					int mid = (lo+hi)>>1;
					if(get_text(j, j + mid) == get_pattern(0, mid)){
						pos = mid;
						lo = mid + 1;
					} else {
						hi = mid - 1;
					}
				}
				if(pos == min(i, n - j - 1) || s[j + pos + 1] < ans[pos + 1]) j += rn;
				else {
					if(rn == 1){
						bad = true;
						break;
					}
					j += rn - 1;
				}
				blocks++;
			}
			if(!bad && blocks <= k) break;
		}
	}
	cout << ans << endl;
	return 0;
}