Language: C++

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll N, K, T, W, H, M, C;

const int MAX = 5100000;
const ll MOD = 1e9 + 7;

const double PI=3.14159265358979323846;


long long fac[MAX], finv[MAX], inv[MAX];

vector<double> cx, cy, c;
 ll MM = 1e12;

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll modinv(ll a) {
    ll b = MOD, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return u;
}

ll modpow(ll x, ll n) {
  ll ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= MOD;
    (x *= x) %= MOD;
    n >>= 1;
  }
  return ret;
}

struct Eratos {
    vector<int> primes;
    vector<bool> isprime;
    vector<int> min_factor;

    Eratos(int MAX) : primes(),
                      isprime(MAX+1, true),
                      min_factor(MAX+1, -1) {
        isprime[0] = isprime[1] = false;
        min_factor[0] = 0, min_factor[1] = 1;
        for (int i = 2; i <= MAX; ++i) {
            if (!isprime[i]) continue;
            primes.push_back(i);
            min_factor[i] = i;
            for (int j = i*2; j <= MAX; j += i) {
                isprime[j] = false;
                if (min_factor[j] == -1) min_factor[j] = i;
            }
        }
    }

    // prime factorization
    vector<pair<int,int>> prime_factorize(int n) {
        vector<pair<int,int> > res;
        while (n != 1) {
            int prime = min_factor[n];
            int exp = 0;
            while (min_factor[n] == prime) {
                ++exp;
                n /= prime;
            }
            res.push_back(make_pair(prime, exp));
        }
        return res;
    }
};

ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

ll lcm(ll a, ll b)
{
   return a * b / gcd(a, b);
}

  
int main(){
    int Q;
    cin >> N >> M >> Q;
    vector<int> al(Q), b(Q) ,c(Q), d(Q);
    REP(i, Q) cin >> al[i] >> b[i] >> c[i] >> d[i];
    vector<int> a(N);
    int ans = 0;
    REP(i1,M) {
        FOR(i2, M){
            FOR(i3,i2, M){
                FOR(i4, i3, M){
                    FOR(i5, i4, M){
                        FOR(i6, i5, M){      
                            FOR(i7, i6, M){        
                                FOR(i8, i7, M){                         
                                    FOR(i9, i8, M){                                 
                                        FOR(i10, i9, M){
                                            vector<int> a = {i1,i2,i3,i4,i5,i6,i7,i8,i9,i10};
                                            int cnd = 0;
                                            for(int i = 0; i < Q; ++i){
                                                if(a[b[i]-1] - a[al[i]-1] == c[i]) cnd += d[i]; 
                                            }
                                            ans = max(ans, cnd);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    cout << ans;
    return 0;
}


Compiler output:
a.cc:122:18: error: macro "FOR" requires 3 arguments, but only 2 given
  122 |         FOR(i2, M){
      |                  ^
a.cc:4:9: note: macro "FOR" defined here
    4 | #define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
      |         ^~~
a.cc: In function 'int main()':
a.cc:122:9: error: 'FOR' was not declared in this scope
  122 |         FOR(i2, M){
      |         ^~~