Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
ll INF = 4001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<tuple<ll,ll,ll>>>;

// MOD確認

ll N,M,Q,ans = 0;
ll a[60],b[60],c[60],d[60];
ll A[60];

void dfs(ll *B,ll n){
    if(n - 1 == N){
        ll res = 0;
        rep(i,Q){
            if(B[b[i]] - B[a[i]] == c[i]) res += d[i];
        }
        ans = max(ans,res);
    }else{
        FOR(i,B[n-1],M){
            B[n] = i;
            dfs(B,n+1);
        }
    }
    return ;
}

int main(){
    cin >> N >> M >> Q;
    rep(i,Q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    dfs(A,1);
    cout << ans << endl;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
ll INF = 4001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<tuple<ll,ll,ll>>>;

// MOD確認

ll N,M,Q,ans = 0;
ll a[60],b[60],c[60],d[60];
ll A[60];

void dfs(ll *B,ll n){
    if(n - 1 == N){
        ll res = 0;
        rep(i,Q){
            if(B[b[i]] - B[a[i]] == c[i]) res += d[i];
        }
        ans = max(ans,res);
    }else{
        FOR(i,B[n-1],M){
            B[n] = i;
            dfs(B,n+1);
        }
    }
    return ;
}

int main(){
    cin >> N >> M >> Q;
    rep(i,Q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    dfs(A,1);
    cout << ans << endl;
}


Compiler output:
a.cc:61:14: error: redefinition of 'constexpr const ll MOD'
   61 | constexpr ll MOD = 1000000007;
      |              ^~~
a.cc:10:14: note: 'constexpr const ll MOD' previously defined here
   10 | constexpr ll MOD = 1000000007;
      |              ^~~
a.cc:63:4: error: redefinition of 'll INF'
   63 | ll INF = 4001001001001001001;
      |    ^~~
a.cc:12:4: note: 'll INF' previously defined here
   12 | ll INF = 4001001001001001001;
      |    ^~~
a.cc:64:13: error: redefinition of 'long double EPS'
   64 | long double EPS = 1e-9;
      |             ^~~
a.cc:13:13: note: 'long double EPS' previously defined here
   13 | long double EPS = 1e-9;
      |             ^~~
a.cc:65:13: error: redefinition of 'long double PI'
   65 | long double PI = 3.141592653589793238;
      |             ^~
a.cc:14:13: note: 'long double PI' previously defined here
   14 | long double PI = 3.141592653589793238;
      |             ^~
a.cc:67:6: error: redefinition of 'template<class T> void remove(std::vector<_Tp>&, unsigned int)'
   67 | void remove(std::vector<T>& vector, unsigned int index){
      |      ^~~~~~
a.cc:16:6: note: 'template<class T> void remove(std::vector<_Tp>&, unsigned int)' previously declared here
   16 | void remove(std::vector<T>& vector, unsigned int index){
      |      ^~~~~~
a.cc:75:4: error: redefinition of 'll N'
   75 | ll N,M,Q,ans = 0;
      |    ^
a.cc:24:4: note: 'll N' previously declared here
   24 | ll N,M,Q,ans = 0;
      |    ^
a.cc:75:6: error: redefinition of 'll M'
   75 | ll N,M,Q,ans = 0;
      |      ^
a.cc:24:6: note: 'll M' previously declared here
   24 | ll N,M,Q,ans = 0;
      |      ^
a.cc:75:8: error: redefinition of 'll Q'
   75 | ll N,M,Q,ans = 0;
      |        ^
a.cc:24:8: note: 'll Q' previously declared here
   24 | ll N,M,Q,ans = 0;
      |        ^
a.cc:75:10: error: redefinition of 'll ans'
   75 | ll N,M,Q,ans = 0;
      |          ^~~
a.cc:24:10: note: 'll ans' previously defined here
   24 | ll N,M,Q,ans = 0;
      |          ^~~
a.cc:76:4: error: redefinition of 'll a [60]'
   76 | ll a[60],b[60],c[60],d[60];
      |    ^
a.cc:25:4: note: 'll a [60]' previously declared here
   25 | ll a[60],b[60],c[60],d[60];
      |    ^
a.cc:76:10: error: redefinition of 'll b [60]'
   76 | ll a[60],b[60],c[60],d[60];
      |          ^
a.cc:25:10: note: 'll b [60]' previously declared here
   25 | ll a[60],b[60],c[60],d[60];
      |          ^
a.cc:76:16: error: redefinition of 'll c [60]'
   76 | ll a[60],b[60],c[60],d[60];
      |                ^
a.cc:25:16: note: 'll c [60]' previously declared here
   25 | ll a[60],b[60],c[60],d[60];
      |                ^
a.cc:76:22: error: redefinition of 'll d [60]'
   76 | ll a[60],b[60],c[60],d[60];
      |                      ^
a.cc:25:22: note: 'll d [60]' previously declared here
   25 | ll a[60],b[60],c[60],d[60];
      |                      ^
a.cc:77:4: error: redefinition of 'll A [60]'
   77 | ll A[60];
      |    ^
a.cc:26:4: note: 'll A [60]' previously declared here
   26 | ll A[60];
      |    ^
a.cc:79:6: error: redefinition of 'void dfs(ll*, ll)'
   79 | void dfs(ll *B,ll n){
      |      ^~~
a.cc:28:6: note: 'void dfs(ll*, ll)' previously defined here
   28 | void dfs(ll *B,ll n){
      |      ^~~
a.cc:95:5: error: redefinition of 'int main()'
   95 | int main(){
      |     ^~~~
a.cc:44:5: note: 'int main()' previously defined here
   44 | int main(){
      |     ^~~~