Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int n,m,q;  
vector<int[4]>Q;

int dfs(vector<int> &A, int ptr = 1){
    static int ans = 0;
    if(ptr == n){
        rep(i, q){
            int a = A[Q[i][0]];
            int b = A[Q[i][1]];
            if(b-a == Q[i][2])  ans += Q[i][3];
        }
        if(A[0] == m)   return ans;
    }else{
        for(int i = A[ptr-1]; i <= m; i++){
            A[ptr] = i;
            dfs(A, ptr+1);
        }
    }
}

int main(){
    cin >> n >> m >> q;
    Q.resize(q);
    rep(i, q){
        int a,b,c,d;    cin >> a >> b >> c >> d;
        a--;    b--;
        Q[i][0] = a;
        Q[i][1] = b;
        Q[i][2] = c;
        Q[i][3] = d;
    }
    vector<int> A(n);
    cout << dfs(A) << endl;
}


Compiler output:
In file included from /usr/include/c++/14/vector:65,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_uninitialized.h: In instantiation of 'constexpr bool std::__check_constructible() [with _ValueType = int [4]; _Tp = int (&&)[4]]':
/usr/include/c++/14/bits/stl_uninitialized.h:182:4:   required from '_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = move_iterator<int (*)[4]>; _ForwardIterator = int (*)[4]]'
  182 |         = _GLIBCXX_USE_ASSIGN_FOR_INIT(_ValueType2, _From);
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_uninitialized.h:373:37:   required from '_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, allocator<_Tp>&) [with _InputIterator = move_iterator<int (*)[4]>; _ForwardIterator = int (*)[4]; _Tp = int [4]]'
  373 |       return std::uninitialized_copy(__first, __last, __result);
      |              ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_uninitialized.h:399:2:   required from '_ForwardIterator std::__uninitialized_move_if_noexcept_a(_InputIterator, _InputIterator, _ForwardIterator, _Allocator&) [with _InputIterator = int (*)[4]; _ForwardIterator = int (*)[4]; _Allocator = allocator<int [4]>]'
  398 |       return std::__uninitialized_copy_a
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  399 |         (_GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(__first),
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  400 |          _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(__last), __result, __alloc);
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:894:46:   required from 'void std::vector<_Tp, _Alloc>::_M_default_append(size_type) [with _Tp = int [4]; _Alloc = std::allocator<int [4]>; size_type = long unsigned int]'
  894 |                     std::__uninitialized_move_if_noexcept_a(
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
  895 |                       __old_start, __old_finish, __new_start,
      |                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  896 |                       _M_get_Tp_allocator());
      |                       ~~~~~~~~~~~~~~~~~~~~~~                
/usr/include/c++/14/bits/stl_vector.h:1016:4:   required from 'void std::vector<_Tp, _Alloc>::resize(size_type) [with _Tp = int [4]; _Alloc = std::allocator<int [4]>; size_type = long unsigned int]'
 1016 |           _M_default_append(__new_size - size());
      |           ^~~~~~~~~~~~~~~~~
a.cc:31:13:   required from here
   31 |     Q.resize(q);
      |     ~~~~~~~~^~~
/usr/include/c++/14/bits/stl_uninitialized.h:90:56: error: static assertion failed: result type must be constructible from input type
   90 |       static_assert(is_constructible<_ValueType, _Tp>::value,
      |                                                        ^~~~~
/usr/include/c++/14/bits/stl_uninitialized.h:90:56: note: 'std::integral_constant<bool, false>::value' evaluates to false
a.cc: In function 'int dfs(std::vector<int>&, int)':
a.cc:27:1: warning: control reaches end of non-void function [-Wreturn-type]
   27 | }
      | ^