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 Java8 (OpenJDK 1.8.0) (judge verdict: Wrong Answer)

import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        Task task = new Task(in, out);
        task.solve();
        out.close();
    }

    static class Task {
        
        private InputReader in;
        private PrintWriter out;

        public Task(InputReader in, PrintWriter out) {
            this.in = in;
            this.out = out;
        }

        public void solve() {
            int K = in.nextInt();
            String S = in.next();
            int ssl = S.length() / (K+1);
            int sslp1 = S.length() - (K+1) * ssl;
            String[][] T = new String[S.length()][sslp1+1];
            T[ssl-1][0] = S.substring(0, ssl);
            if (sslp1 > 0)
                T[ssl][1] = S.substring(0, ssl+1);
            for (int j = ssl+1; j < S.length(); j++) {
                // T[j][k] = best splitting of chars from 0-j in k strings of length sslp1
                for (int k = 0; k <= sslp1; k++) {
                    // cut j-(j-sslp1)
                    if (k > 0 && j-ssl >= 0)
                        T[j][k] = max(S.substring(j-ssl, j+1), table(T, j-ssl-1, k-1));
                    // cut j-(j-sslp1+1)
                    if (j-ssl+1 >= 0)
                        T[j][k] = min(T[j][k], max(S.substring(j-ssl+1, j+1), table(T, j-ssl, k)));
                }
            }
            out.println(T[S.length() - 1][sslp1]);
        }

        private String table(String[][] T, int j, int k) {
            if (j < 0 || k < 0)
                return null;
            return T[j][k];
        }

        private String min(String a, String b) {
            if (a == null) return b;
            if (b == null) return a;
            if (a.length() < b.length())
                return a;
            if (a.length() > b.length())
                return b;
            return a.compareTo(b) < 0 ? a : b;
        }

        private String max(String a, String b) {
            if (a == null || b == null)
                return null;
            if (a.length() < b.length())
                return b;
            if (a.length() > b.length())
                return a;
            return a.compareTo(b) > 0 ? a : b;
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
    
}