#include <iostream>
#include <vector>
#include <boost/utility/string_ref.hpp>

using StringVec = std::vector<std::string>;

bool isConcatable(const StringVec& l, boost::string_ref s) {
  if(s.empty())
    return true;

  for(auto& item : l) {
    if(s.starts_with(item)) {
      if(isConcatable(l, s.substr(item.length()))) {
        return true;
      }
    }
  }
  return false;
}

int main(int argc, char *argv[]) {
  StringVec l = {"ca", "at"};
  std::string s = "caat";

  std::cout << isConcatable(l,s);
  return 0;
}
