Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

struct data{int a, b, c, d;};
int n, m, q;

int dfs(int v, int id, vint &x) {
    if (id == n) {
        int sum = 0;
        rep(i,q) {
            if (x[Q[i].b]-x[Q[i].a] == Q[i].c) sum += Q[i].d;
        }
        return sum;
    }
    int res = 0;
    x[id] = v;
    for (int i = v; i <= m; i++) {
        res = max(dfs(i,id+1,x),res);
    }
    return res;
}

int main() {
    cin >> n >> m >> q;
    vector<data> Q(q);
    vint x(n);
    rep(i,q) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        a--; b--;
        Q[i] = data{a,b,c,d};
    }
    int ans = 0;
    for (int i = 1; i <= m; i++) {
        ans = max(dfs(i,0,x),ans);
    }
    cout << ans << endl;
}

Compiler output:
a.cc: In function 'int dfs(int, int, vint&)':
a.cc:27:19: error: 'Q' was not declared in this scope
   27 |             if (x[Q[i].b]-x[Q[i].a] == Q[i].c) sum += Q[i].d;
      |                   ^
a.cc: In function 'int main()':
a.cc:41:16: error: template argument 1 is invalid
   41 |     vector<data> Q(q);
      |                ^
a.cc:41:16: error: template argument 2 is invalid
a.cc:47:10: error: invalid types 'int[int]' for array subscript
   47 |         Q[i] = data{a,b,c,d};
      |          ^
a.cc:47:16: error: reference to 'data' is ambiguous
   47 |         Q[i] = data{a,b,c,d};
      |                ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:20:8: note:                 'struct data'
   20 | struct data{int a, b, c, d;};
      |        ^~~~