Language: C++

##include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <functional>
#include <set>
#include <ctime>
#include <random>
#include <chrono>
#include <cassert>
#include <tuple>
#include <utility>
using namespace std;

namespace {
  using Integer = long long; //__int128;
  template<class T, class S> istream& operator >> (istream& is, pair<T,S>& p){return is >> p.first >> p.second;}
  template<class T> istream& operator >> (istream& is, vector<T>& vec){for(T& val: vec) is >> val; return is;}
  template<class T> istream& operator ,  (istream& is, T& val){ return is >> val;}
  template<class T, class S> ostream& operator << (ostream& os, const pair<T,S>& p){return os << p.first << " " << p.second;}
  template<class T> ostream& operator << (ostream& os, const vector<T>& vec){for(size_t i=0; i<vec.size(); i++) os << vec[i] << (i==vec.size()-1?"":" "); return os;}
  template<class T> ostream& operator ,  (ostream& os, const T& val){ return os << " " << val;}

  template<class H> void print(const H& head){ cout << head; }
  template<class H, class ... T> void print(const H& head, const T& ... tail){ cout << head << " "; print(tail...); }
  template<class ... T> void println(const T& ... values){ print(values...); cout << endl; }

  template<class H> void eprint(const H& head){ cerr << head; }
  template<class H, class ... T> void eprint(const H& head, const T& ... tail){ cerr << head << " "; eprint(tail...); }
  template<class ... T> void eprintln(const T& ... values){ eprint(values...); cerr << endl; }

  class range{ Integer start_, end_, step_; public: struct range_iterator{ Integer val, step_; range_iterator(Integer v, Integer step) : val(v), step_(step) {} Integer operator * (){return val;} void operator ++ (){val += step_;} bool operator != (range_iterator& x){return step_ > 0 ? val < x.val : val > x.val;} }; range(Integer len) : start_(0), end_(len), step_(1) {} range(Integer start, Integer end) : start_(start), end_(end), step_(1) {} range(Integer start, Integer end, Integer step) : start_(start), end_(end), step_(step) {} range_iterator begin(){ return range_iterator(start_, step_); } range_iterator   end(){ return range_iterator(  end_, step_); } };

  inline string operator "" _s (const char* str, size_t size){ return move(string(str)); }
  constexpr Integer my_pow(Integer x, Integer k, Integer z=1){return k==0 ? z : k==1 ? z*x : (k&1) ? my_pow(x*x,k>>1,z*x) : my_pow(x*x,k>>1,z);}
  constexpr Integer my_pow_mod(Integer x, Integer k, Integer M, Integer z=1){return k==0 ? z%M : k==1 ? z*x%M : (k&1) ? my_pow_mod(x*x%M,k>>1,M,z*x%M) : my_pow_mod(x*x%M,k>>1,M,z);}
  constexpr unsigned long long operator "" _ten (unsigned long long value){ return my_pow(10,value); }

  inline int k_bit(Integer x, int k){return (x>>k)&1;} //0-indexed

  mt19937 mt(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count());

  template<class T> string join(const vector<T>& v, const string& sep){ stringstream ss; for(size_t i=0; i<v.size(); i++){ if(i>0) ss << sep; ss << v[i]; } return ss.str(); }

  inline string operator * (string s, int k){ string ret; while(k){ if(k&1) ret += s; s += s; k >>= 1; } return ret; }
}
constexpr long long mod = 9_ten + 7;

class SuffixArray{
 public:
  vector<int> sa;
  vector<int> lcp;
  vector<int> rank;

  SuffixArray(const string& SS)
   : S(SS),
     len(SS.size()),
     sa(SS.size()+1),
     lcp(SS.size()+1),
     rank(SS.size()+1)
  {
    constract_sa();
    constract_lcp();
  }

  void dbg_print(){
    for(int i=0; i<=len; i++){
      cerr << S.substr(sa[i]) << " " << lcp[i] << endl;
    }
  }

 private:
  const string& S;
  int len;

  //Manber & Myers
  //O(len (logN)^2)
  void constract_sa(){
    //first character
    for(int i=0; i<=len; i++){
      sa[i] = i;
      rank[i] = (i<len) ? S[i] : -1;
    }

    vector<int> tmp(len+1);
    for(int k=1; k<=len; k *= 2){
      auto cmp_func = [&](int x, int y) -> bool{
        if(rank[x] != rank[y]) return rank[x] < rank[y];
        int l = (x+k <= len) ? rank[x+k] : -1;
        int r = (y+k <= len) ? rank[y+k] : -1;
        return l < r;
      };
      sort(sa.begin(), sa.end(), cmp_func);
      tmp[sa[0]] = 0;
      for(int i=1; i<=len; i++){
        tmp[sa[i]] = tmp[sa[i-1]] + (cmp_func(sa[i-1],sa[i])==true?1:0);
      }
      for(int i=0; i<=len; i++){
        rank[i] = tmp[i];
      }
    }
  }

  void constract_lcp(){
    for(int i=0; i<=len; i++) rank[sa[i]] = i;
    int h=0;
    lcp[0] = 0;
    for(int i=0; i<len; i++){
      int j=sa[rank[i]-1];
      if(h>0) h--;
      for(; j+h<len && i+h<len; h++){
        if(S[j+h] != S[i+h]) break;
      }
      lcp[rank[i] - 1] = h;
    }
  }
};

int main(){
  int k;
  string s;
  cin >> k,s;

  if(k==0){
    println(s);
    return 0;
  }

  int l = (s.size()+k)/(k+1); //l
  int t = s.size()%(k+1);   //cnt l

  if(t==0){
    vector<string> ss(k+1);
    for(int i=0; i<ss.size(); i++){
      ss[i] = s.substr(i*l, l);
    }
    sort(ss.rbegin(), ss.rend());
    println(*ss.begin());
    return 0;
  }

  SuffixArray sa(s);

  //sa.dbg_print();

  vector<pair<int,int>> r;
  for(int i : range(sa.rank.size()-k)){
    r.push_back({sa.rank[i], i});
  }
  sort(r.begin(), r.end());

  auto check = [&](int x){
    int u = t;
    int v = k+1-t;
    for(int i=0; i<s.size();){
      if(u && sa.rank[i] <= r[x].first){
        i += l;
        u--;
      }else{
        if(v>0){
          v--;
          i+=l-1;
        }else{
          return false;
        }
      }
    }
    return true;
  };

  long long lb = -1;
  long long ub = r.size()-1;
  while(ub-lb>1){
    long long mid = (lb+ub)/2;
    bool ok = check(mid);
    (ok? ub : lb) = mid;
  }

  println( s.substr(r[ub].second, l) );

  return 0;
}


Compiler output:
a.cc:1:1: error: stray '##' in program
    1 | ##include <iostream>
      | ^~
a.cc:1:3: error: 'include' does not name a type
    1 | ##include <iostream>
      |   ^~~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:62,
                 from /usr/include/c++/14/vector:62,
                 from a.cc:2:
/usr/include/c++/14/ext/type_traits.h:164:35: error: 'constexpr const bool __gnu_cxx::__is_null_pointer' redeclared as different kind of entity
  164 |   __is_null_pointer(std::nullptr_t)
      |                                   ^
/usr/include/c++/14/ext/type_traits.h:159:5: note: previous declaration 'template<class _Type> constexpr bool __gnu_cxx::__is_null_pointer(_Type)'
  159 |     __is_null_pointer(_Type)
      |     ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/ext/type_traits.h:164:26: error: 'nullptr_t' is not a member of 'std'
  164 |   __is_null_pointer(std::nullptr_t)
      |                          ^~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_pair.h:60,
                 from /usr/include/c++/14/bits/stl_algobase.h:64:
/usr/include/c++/14/type_traits:295:27: error: 'size_t' has not been declared
  295 |   template <typename _Tp, size_t = sizeof(_Tp)>
      |                           ^~~~~~
/usr/include/c++/14/type_traits:666:33: error: 'nullptr_t' is not a member of 'std'
  666 |     struct is_null_pointer<std::nullptr_t>
      |                                 ^~~~~~~~~
/usr/include/c++/14/type_traits:666:42: error: template argument 1 is invalid
  666 |     struct is_null_pointer<std::nullptr_t>
      |                                          ^
/usr/include/c++/14/type_traits:670:48: error: template argument 1 is invalid
  670 |     struct is_null_pointer<const std::nullptr_t>
      |                                                ^
/usr/include/c++/14/type_traits:674:51: error: template argument 1 is invalid
  674 |     struct is_null_pointer<volatile std::nullptr_t>
      |                                                   ^
/usr/include/c++/14/type_traits:678:57: error: template argument 1 is invalid
  678 |     struct is_null_pointer<const volatile std::nullptr_t>
      |                                                         ^
/usr/include/c++/14/type_traits:984:26: error: 'size_t' has not been declared
  984 |   template<typename _Tp, size_t _Size>
      |                          ^~~~~~
/usr/include/c++/14/type_traits:985:40: error: '_Size' was not declared in this scope
  985 |     struct __is_array_known_bounds<_Tp[_Size]>
      |                                        ^~~~~
/usr/include/c++/14/type_traits:985:46: error: template argument 1 is invalid
  985 |     struct __is_array_known_bounds<_Tp[_Size]>
      |                                              ^
/usr/include/c++/14/type_traits:1429:37: error: 'size_t' is not a member of 'std'
 1429 |     : public integral_constant<std::size_t, alignof(_Tp)>
      |                                     ^~~~~~
/usr/include/c++/14/type_traits:1429:57: error: template argument 1 is invalid
 1429 |     : public integral_constant<std::size_t, alignof(_Tp)>
      |                                                         ^
/usr/include/c++/14/type_traits:1429:57: note: invalid template non-type parameter
/usr/include/c++/14/type_traits:1438:37: error: 'size_t' is not a member of 'std'
 1438 |     : public integral_constant<std::size_t, 0> { };
      |                                     ^~~~~~
/usr/include/c++/14/type_traits:1438:46: error: template argument 1 is invalid
 1438 |     : public integral_constant<std::size_t, 0> { };
      |                                              ^
/usr/include/c++/14/type_traits:1438:46: note: invalid template non-type parameter
/usr/include/c++/14/type_traits:1440:26: error: 'std::size_t' has not been declared
 1440 |   template<typename _Tp, std::size_t _Size>
      |                          ^~~
/usr/include/c++/14/type_traits:1441:21: error: '_Size' was not declared in this scope
 1441 |     struct rank<_Tp[_Size]>
      |                     ^~~~~
/usr/include/c++/14/type_traits:1441:27: error: template argument 1 is invalid
 1441 |     struct rank<_Tp[_Size]>
      |                           ^
/usr/include/c++/14/type_traits:1442:37: error: 'size_t' is not a member of 'std'
 1442 |     : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
      |                                     ^~~~~~
/usr/include/c++/14/type_traits:1442:65: error: template argument 1 is invalid
 1442 |     : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
      |                                                                 ^
/usr/include/c++/14/type_traits:1442:65: note: invalid template non-type parameter
/usr/include/c++/14/type_traits:1446:37: error: 'size_t' is not a member of 'std'
 1446 |     : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
      |                                     ^~~~~~
/usr/include/c++/14/type_traits:1446:65: error: template argument 1 is invalid
 1446 |     : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
      |                                                                 ^
/usr/include/c++/14/type_traits:1446:65: note: invalid template non-type parameter
/usr/include/c++/14/type_traits:1451:32: error: 'size_t' was not declared in this scope
 1451 |     : public integral_constant<size_t, 0> { };
      |                                ^~~~~~
/usr/include/c++/14/type_traits:64:1: note: 'size_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
   63 | #include <bits/version.h>
  +++ |+#include <cstddef>
   64 | 
/usr/include/c++/14/type_traits:1451:41: error: template argument 1 is invalid
 1451 |     : public integral_constant<size_t, 0> { };
      |                                         ^
/usr/include/c++/14/type_traits:1451:41: note: invalid template non-type parameter
/usr/include/c++/14/type_traits:1453:26: error: 'size_t' has not been declared
 1453 |   template<typename _Tp, size_t _Size>
      |                          ^~~~~~
/usr/include/c++/14/type_traits:1454:23: error: '_Size' was not declared in this scope
 1454 |     struct extent<_Tp[_Size], 0>
      |                       ^~~~~
/usr/include/c++/14/type_traits:1454:32: error: template argument 1 is invalid
 1454 |     struct extent<_Tp[_Size], 0>
      |                                ^
/usr/include/c++/14/type_traits:1455:32: error: 'size_t' was not declared in this scope
 1455 |     : public integral_constant<size_t, _Size> { };
      |                                ^~~~~~
/usr/include/c++/14/type_traits:1455:32: note: 'size_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
/usr/include/c++/14/type_traits:1455:40: error: '_Size' was not declared in this scope
 1455 |     : public integral_constant<size_t, _Size> { };
      |                                        ^~~~~
/usr/include/c++/14/type_traits:1455:45: error: template argument 1 is invalid
 1455 |     : public integral_constant<size_t, _Size> { };
      |                                             ^
/usr/include/c++/14/type_traits:1455:45: error: template argument 2 is invalid
/usr/include/c++/14/type_traits:1457:42: error: 'size_t' has not been declared
 1457 |   template<typename _Tp, unsigned _Uint, size_t _Size>
      |                                          ^~~~~~
/usr/include/c++/14/type_traits:1458:23: error: '_Size' was not declared in this scope
 1458 |     struct extent<_Tp[_Size], _Uint>
      |                       ^~~~~
/usr/include/c++/14/type_traits:1458:36: error: template argument 1 is invalid
 1458 |     struct extent<_Tp[_Size], _Uint>
      |                                    ^
/usr/include/c++/14/type_traits:1463:32: error: 'size_t' was not declared in this scope
 1463 |     : public integral_constant<size_t, 0> { };
      |                                ^~~~~~
/usr/include/c++/14/type_traits:1463:32: note: 'size_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
/usr/include/c++/14/type_traits:1463:41: error: template argument 1 is invalid
 1463 |     : public integral_constant<size_t, 0> { };
      |                                         ^
/usr/include/c++/14/type_traits:1463:41: note: invalid template non-type parameter
/usr/include/c++/14/type_traits:1857:26: error: 'size_t' does not name a type
 1857 |       { static constexpr size_t __size = sizeof(_Tp); };
      |                          ^~~~~~
/usr/include/c++/14/type_traits:1857:26: note: 'size_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
/usr/include/c++/14/type_traits:1859:14: error: 'size_t' has not been declared
 1859 |     template<size_t _Sz, typename _Tp, bool = (_Sz <= _Tp::__size)>
      |              ^~~~~~
/usr/include/c++/14/type_traits:1859:48: error: '_Sz' was not declared in this scope
 1859 |     template<size_t _Sz, typename _Tp, bool = (_Sz <= _Tp::__size)>
      |                                                ^~~
/usr/include/c++/14/type_traits:1860:14: error: no default argument for '_Tp'
 1860 |       struct __select;
      |              ^~~~~~~~
/usr/include/c++/14/type_traits:1862:14: error: 'size_t' has not been declared
 1862 |     template<size_t _Sz, typename _Uint, typename... _UInts>
      |              ^~~~~~
/usr/include/c++/14/type_traits:1863:23: error: '_Sz' was not declared in this scope
 1863 |       struct __select<_Sz, _List<_Uint, _UInts...>, true>
      |                       ^~~
/usr/include/c++/14/type_traits:1863:57: error: template argument 1 is invalid
 1863 |       struct __select<_Sz, _List<_Uint, _UInts...>, true>
      |                                                         ^
/usr/include/c++/14/type_traits:1866:14: error: 'size_t' has not been declared
 1866 |     template<size_t _Sz, typename _Uint, typename... _UInts>
      |              ^~~~~~
/usr/include/c++/14/type_traits:1867:23: error: '_Sz' was not declared in this scope
 1867 |       struct __select<_Sz, _List<_Uint, _UInts...>, false>
      |                       ^~~
/usr/include/c++/14/type_traits:1867:58: error: template argument 1 is