Language: C++

#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
// #define fore(i,a) for(auto &i:a)
// #define all(x) (x).begin(),(x).end()
// #pragma GCC optimize ("-O3")
// using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
// typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
// template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
// template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

using namespace std;

template <typename Tlist, typename Tfunc>
void __combination(
    Tlist const& list, typename Tlist::size_type const n, Tfunc const& func,
    Tlist& tmp, typename Tlist::size_type const i, typename Tlist::size_type const j)
{
    if (i == n)
    {
        func(tmp);
        return;
    }

    for (typename Tlist::size_type k = j; k < list.size(); ++k)
    {
        tmp[i] = list[k];
        __combination(list, n, func, tmp, i + 1, k);
    }
}

template <typename Tlist, typename Tfunc>
void combination(
    Tlist const& list, typename Tlist::size_type const n, Tfunc const& func)
{
    Tlist tmp(n);
    __combination(list, n, func, tmp, 0, 0);
}

int main()
{
  int N,M,Q;
  cin>>N>>M>>Q;
  vector<vector<int>> x;
  x.resize(Q);
  rep(i,0,Q){
    x[i].resize(4);
    cin>>x[i][0]>>x[i][1]>>x[i][2]>>x[i][3];
  }
  
  std::vector<unsigned int>::size_type m = M, n = N;
  std::vector<unsigned int> list(m);
  for (unsigned int i = 0; i < m; ++i)
  {
      list[i] = i + 1;
  }

  vector<vector<unsigned int>> Aall;
  vector<unsigned int> A;
  combination(
    list, n, [](std::vector<unsigned int> const& a) {
      for (auto i(a.begin()); i != a.end(); ++i){
        int c=(int)(*i);
        A.push_back(c);
      }
      Aall.push_back(A);
  });
  
  long int MAX=0;
  rep(i,0,Aall.size()){
    long int max=0;
    rep(j,0,Q){
      if(Aall[i][x[j][1]]-Aall[i][x[j][0]]==x[j][2]) max+=x[j][3];
    }
    if(MAX<max) MAX=max;
  }
  
  cout<<MAX<<endl;
}

Compiler output:
a.cc: In lambda function:
a.cc:64:9: error: 'A' is not captured
   64 |         A.push_back(c);
      |         ^
a.cc:61:15: note: the lambda has no capture-default
   61 |     list, n, [](std::vector<unsigned int> const& a) {
      |               ^
a.cc:59:24: note: 'std::vector<unsigned int> A' declared here
   59 |   vector<unsigned int> A;
      |                        ^
a.cc:66:7: error: 'Aall' is not captured
   66 |       Aall.push_back(A);
      |       ^~~~
a.cc:61:15: note: the lambda has no capture-default
   61 |     list, n, [](std::vector<unsigned int> const& a) {
      |               ^
a.cc:58:32: note: 'std::vector<std::vector<unsigned int> > Aall' declared here
   58 |   vector<vector<unsigned int>> Aall;
      |                                ^~~~
a.cc:66:22: error: 'A' is not captured
   66 |       Aall.push_back(A);
      |                      ^
a.cc:61:15: note: the lambda has no capture-default
   61 |     list, n, [](std::vector<unsigned int> const& a) {
      |               ^
a.cc:59:24: note: 'std::vector<unsigned int> A' declared here
   59 |   vector<unsigned int> A;
      |                        ^