Language: C++



# define _SCL_SECURE_NO_WARNINGS

# include <iostream>
# include <string>
# include <iomanip>
# include <stdio.h>
# include <array>
# include <numeric>
# include <algorithm>
# include <vector>
# include <functional>
# include <fstream>
# include <cmath>

namespace
{

    using Ull = unsigned long long;
    using Ll = long long;

    namespace mine
    {

        template<typename T>
        std::istream& operator >> (std::istream& is, std::vector<T>& vec)
        {
            for (T& x : vec) is >> x;
            return is;
        }

        template<typename T>
        std::string to_string(const std::vector<T>& vec, std::string sep = " ")
        {
            std::string result;
            for (T& x : vec) result += std::to_string(x) + sep;
            result.erase(result.size() - sep.length());

            return result;
        }

        template<>
        std::string to_string(const std::vector<std::string>& vec, std::string sep)
        {
            std::string result;
            for (auto str : vec) result += str + sep;
            result.erase(result.size() - sep.length());

            return result;
        }

        template<typename T, size_t L>
        std::string to_string(T(&ary)[L], std::string sep = " ", size_t size = L)
        {
            std::string result;
            for (int i = 0; i < size; ++i) result += std::to_string(ary[i]);
            result.erase(result.size() - sep.length());

            return result;
        }

        template<typename T, size_t L, typename Function>
        void for_each(T(&ary)[L], Function lambda)
        {
            for (size_t i{}; i < L; ++i)
                lambda(static_cast<T&>(ary[i]));
        }

        template<typename T>
        void SetAll(T container, typename T::value_type value = typename T::value_type{})
        {
            for (typename T::reference content : container)
                content = value;
        }

        template<typename T, size_t L>
        void SetAll(T(&ary)[L], T value = T{})
        {
            for (size_t i{}; i < L; ++i)
                ary[i] = value;
        }

        template<typename T, size_t L>
        std::array<T, L> AsContainer(T(&ary)[L], bool isSwap = true)
        {
            std::array<T, L> result;

            if (isSwap)
            {
                for (size_t i{}; i < L; ++i)
                    std::swap(result[i], ary[i]);
            }
            else
            {
                for (size_t i{}; i < L; ++i)
                    result[i] = ary[i];
            }

            return result;
        }

        template<size_t length>
        constexpr std::array<size_t, length> range()
        {
            std::array<size_t, length> range{};

            for (size_t i{}; i < length; ++i)
                range[i] = i;

            return range;
        }

        template<typename T>
        const std::vector<T> range(const T length)
        {
            std::vector<T> range(length);

            for (T i{}; i < length; ++i)
                range[i] = i;

            return range;
        }

        template<typename T>
        const std::vector<T> range(const T start, const T end)
        {
            if (start == end) return std::vector<T>{};

            else if (start > end)
            {
                std::vector<T> range(start - end);

                for (T i{start}; i > end; --i)
                    range[start - i] = i;

                return range;
            }
            else
            {
                std::vector<T> range(end - start);

                for (T i{start}; i < end; ++i)
                    range[i - start] = i;

                return range;
            }
        }

        bool IsPrime(const Ull n)
        {
            switch (n)
            {
            case 0: case 1:
                return false;
            case 2:
                return true;
            default:

                if (n % 2 == 0) return false;

                for (Ull i{3}; i * i <= n; i += 2)
                {
                    if (n % i == 0) return false;
                }
            }

            return true;
        }
    }
    using namespace mine;


    void Solve();

}

//namespace 
//{
int main()
{
    Solve();

    return 0;
}
//}

namespace
{
    void Solve()
    {
        std::string str;
        int pos;
        std::vector<std::string> subStrs{};
        std::cin >> str;
        std::cin >> pos;

        for (auto length : range(1u, str.length() + 1))
        {
            for (auto pos : range(str.length() - length + 1))
            {
                subStrs.push_back(str.substr(pos, length));
            }
        }

        std::sort(subStrs.begin(), subStrs.end());
        subStrs.erase(std::unique(subStrs.begin(), subStrs.end()), subStrs.end());

        std::sort(subStrs.begin(), subStrs.end(), [](const std::string& left, const std::string& right) 
        {
            for (int i : range(std::min(left.length(), right.length())))
                if (left[i] != right[i]) return left[i] < right[i];

            return left.length() < right.length();
        });

        //std::cout << to_string(subStrs) << std::endl;
        std::cout << subStrs[pos - 1];

    }
}

Compiler output:
a.cc: In function 'void {anonymous}::Solve()':
a.cc:198:33: error: no matching function for call to 'range(unsigned int, std::__cxx11::basic_string<char>::size_type)'
  198 |         for (auto length : range(1u, str.length() + 1))
      |                            ~~~~~^~~~~~~~~~~~~~~~~~~~~~
a.cc:104:46: note: candidate: 'template<long unsigned int length> constexpr std::array<long unsigned int, length> {anonymous}::mine::range()'
  104 |         constexpr std::array<size_t, length> range()
      |                                              ^~~~~
a.cc:104:46: note:   candidate expects 0 arguments, 2 provided
a.cc:115:30: note: candidate: 'template<class T> const std::vector<T> {anonymous}::mine::range(T)'
  115 |         const std::vector<T> range(const T length)
      |                              ^~~~~
a.cc:115:30: note:   candidate expects 1 argument, 2 provided
a.cc:126:30: note: candidate: 'template<class T> const std::vector<T> {anonymous}::mine::range(T, T)'
  126 |         const std::vector<T> range(const T start, const T end)
      |                              ^~~~~
a.cc:126:30: note:   template argument deduction/substitution failed:
a.cc:198:33: note:   deduced conflicting types for parameter 'T' ('unsigned int' and 'long unsigned int')
  198 |         for (auto length : range(1u, str.length() + 1))
      |                            ~~~~~^~~~~~~~~~~~~~~~~~~~~~