Language: C++

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

public class Main {


    
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        String s = sc.next();
        int    K = sc.nextInt();
        PriorityQueue<String> q = new PriorityQueue<>();
        HashMap<String,Boolean> m = new HashMap<>();
        for(int i = 0; i < s.length(); i++) {
            for(int j = 1; j <= 5; j++) {
                if(i + j > s.length()) break;
                String t = s.substring(i,i+j);
                if(m.containsKey(t)) continue;
                m.put(t,true);
                q.add(s.substring(i,i+j));
            }
        }
        for(int i = 0; i < K-1; i++) {
            q.poll();
        }
        System.out.println(q.poll());


    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        if (!hasNext()) throw new NoSuchElementException();
        int n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
}


Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.util.*;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:2:1: error: 'import' does not name a type
    2 | import java.io.*;
      | ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:1: error: expected unqualified-id before 'public'
    4 | public class Main {
      | ^~~~~~
a.cc:33:12: error: expected ':' before 'final'
   33 |     private final InputStream in = System.in;
      |            ^~~~~~
      |            :
a.cc:33:13: error: 'final' does not name a type
   33 |     private final InputStream in = System.in;
      |             ^~~~~
a.cc:34:12: error: expected ':' before 'final'
   34 |     private final byte[] buffer = new byte[1024];
      |            ^~~~~~
      |            :
a.cc:34:13: error: 'final' does not name a type
   34 |     private final byte[] buffer = new byte[1024];
      |             ^~~~~
a.cc:35:12: error: expected ':' before 'int'
   35 |     private int ptr = 0;
      |            ^~~~
      |            :
a.cc:36:12: error: expected ':' before 'int'
   36 |     private int buflen = 0;
      |            ^~~~
      |            :
a.cc:37:12: error: expected ':' before 'boolean'
   37 |     private boolean hasNextByte() {
      |            ^~~~~~~~
      |            :
a.cc:37:13: error: 'boolean' does not name a type; did you mean 'bool'?
   37 |     private boolean hasNextByte() {
      |             ^~~~~~~
      |             bool
a.cc:53:12: error: expected ':' before 'int'
   53 |     private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
      |            ^~~~
      |            :
a.cc:54:12: error: expected ':' before 'static'
   54 |     private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
      |            ^~~~~~~
      |            :
a.cc:54:20: error: 'boolean' does not name a type; did you mean 'bool'?
   54 |     private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
      |                    ^~~~~~~
      |                    bool
a.cc:55:12: error: expected ':' before 'void'
   55 |     private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
      |            ^~~~~
      |            :
a.cc:56:11: error: expected ':' before 'boolean'
   56 |     public boolean hasNext() { skipUnprintable(); return hasNextByte();}
      |           ^~~~~~~~
      |           :
a.cc:56:12: error: 'boolean' does not name a type; did you mean 'bool'?
   56 |     public boolean hasNext() { skipUnprintable(); return hasNextByte();}
      |            ^~~~~~~
      |            bool
a.cc:57:11: error: expected ':' before 'String'
   57 |     public String next() {
      |           ^~~~~~~
      |           :
a.cc:57:12: error: 'String' does not name a type
   57 |     public String next() {
      |            ^~~~~~
a.cc:67:11: error: expected ':' before 'long'
   67 |     public long nextLong() {
      |           ^~~~~
      |           :
a.cc:92:11: error: expected ':' before 'int'
   92 |     public int nextInt() {
      |           ^~~~
      |           :
a.cc:116:2: error: expected ';' after class definition
  116 | }
      |  ^
      |  ;
a.cc: In member function 'int FastScanner::readByte()':
a.cc:53:34: error: 'hasNextByte' was not declared in this scope
   53 |     private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
      |                                  ^~~~~~~~~~~
a.cc:53:56: error: 'buffer' was not declared in this scope; did you mean 'buflen'?
   53 |     private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
      |                                                        ^~~~~~
      |                                                        buflen
a.cc: In member function 'void FastScanner::skipUnprintable()':
a.cc:55:44: error: 'hasNextByte' was not declared in this scope
   55 |     private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
      |                                            ^~~~~~~~~~~
a.cc:55:78: error: 'buffer' was not declared in this scope; did you mean 'buflen'?
   55 |     private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
      |                                                                              ^~~~~~
      |                                                                              buflen
a.cc:55:62: error: 'isPrintableChar' was not declared in this scope
   55 |     private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
      |                                                              ^~~~~~~~~~~~~~~
a.cc: In member function 'long int FastScanner::nextLong()':
a.cc:68:14: error: 'hasNext' was not declared in this scope
   68 |         if (!hasNext()) throw new NoSuchElementException();
      |              ^~~~~~~
a.cc:68:35: error: expected type-specifier before 'NoSuchElementException'
   68 |         if (!hasNext()) throw new NoSuchElementException();
      |                                   ^~~~~~~~~~~~~~~~~~~~~~
a.cc:70:9: error: 'boolean' was not declared in this scope; did you mean 'bool'?
   70 |         boolean minus = false;
      |         ^~~~~~~
      |         bool
a.cc:73:13: error: 'minus' was not declared in this scope
   73 |             minus = true;
      |             ^~~~~
a.cc:77:23: error: expected type-specifier before 'NumberFormatException'
   77 |             throw new NumberFormatException();
      |                       ^~~~~~~~~~~~~~~~~~~~~
a.cc:83:34: error: 'isPrintableChar' was not declared in this scope
   83 |             }else if(b == -1 || !isPrintableChar(b)){
      |                                  ^~~~~~~~~~~~~~~
a.cc:84:24: error: 'minus' was not declared in this scope
   84 |                 return minus ? -n : n;
      |                        ^~~~~
a.cc:86:27: error: expected type-specifier before 'NumberFormatException'
   86 |                 throw new NumberFormatException();
      |                           ^~~~~~~~~~~~~~~~~~~~~
a.cc: In member function 'int FastScanner::nextInt()':
a.cc:93:14: error: 'hasNext' was not declared in this scope
   93 |         if (!hasNext()) throw new NoSuchElementException();
      |              ^~~~~~~
a.cc:93:35: error: expected type-specifier before 'NoSuchElementException'
   93 |         if (!hasNext()) throw new NoSuchElementException();
      |                                   ^~~~~~~~~~~~~~~~~~~~~~
a.cc:95:9: error: 'boolean' was not declared in this scope; did you mean 'bool'?
   95 |         boolean minus = false;
      |         ^~~~~~~
      |         bool
a.cc:98:13: error: 'minus' was not declared in this scope
   98 |             minus = true;
      |             ^~~~~
a.cc:102:23: error: expected type-specifier before 'NumberFormatException'
  102 |             throw new NumberFormatException();
      |                       ^~~~~~~~~~~~~~~~~~~~~
a.cc:108:34: error: 'isPrintableChar' was not declared in this scope
  108 |             }else if(b == -1 || !isPrintableChar(b)){
      |                                  ^~~~~~~~~~~~~~~
a.cc:109:24: error: 'minus' was not declared in this scope
  109 |                 return minus ? -n : n;
      |                        ^~~~~
a.cc:111:27: error: expected type-specifier before 'NumberFormatException'
  111 |                 throw new NumberFormatException();
      |                           ^~~~~~~~~~~~~~~~~~~~~