Language: C++

 #include<bits/stdc++.h>
 #include <ext/pb_ds/tree_policy.hpp>
 #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
 using namespace std;
 using namespace std::chrono;      
 using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
#define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          1000000007
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        2e18
 #define sm         -1e9
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;

#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update> 
  
void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
   
    #endif
}



int a[11],b[11],c[11],d[11],n,m,q,an=-1;


void recur(int cur,int rm,vii vc)
{
  if(cur>m && rm!=0) return ;
  if(rm==0)
  {
    int cur=0;
    
    
    forf(j,0,q)
    {
      int f = a[j]-1 ,s = b[j]-1 ;
     if(vc[s]-vc[f]==c[j]) cur+=d[j];
    }

    an = max(an,cur);
    return ;
  }
  recur(cur+1,rm,vc);
  vc.pb(cur);
  recur(cur+1,rm-1,vc);
  recur(cur,rm-1,vc);
}

void solve()
{
  
  
  cin >> n >> m >> q;

  forf(i,0,q)
  {
    cin >> a[i] >> b[i] >> c[i] >> d[i];

  }
 vii emp;
 recur(1,n,emp);
 cout<<an<<endl;

}

int32_t main()
{
  pr_init();
  fastio;
  
  auto start = high_resolution_clock::now(); 
 
  solve(); #include<bits/stdc++.h>
 #include <ext/pb_ds/tree_policy.hpp>
 #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
 using namespace std;
 using namespace std::chrono;      
 using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
#define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          1000000007
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        2e18
 #define sm         -1e9
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;

#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update> 
  
void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
   
    #endif
}



int a[11],b[11],c[11],d[11],n,m,q,an=-1;


void recur(int cur,int rm,vii vc)
{
  if(cur>m && rm!=0) return ;
  if(rm==0)
  {
    int cur=0;
    
    
    forf(j,0,q)
    {
      int f = a[j]-1 ,s = b[j]-1 ;
     if(vc[s]-vc[f]==c[j]) cur+=d[j];
    }

    an = max(an,cur);
    return ;
  }
  recur(cur+1,rm,vc);
  vc.pb(cur);
  recur(cur+1,rm-1,vc);
  recur(cur,rm-1,vc);
}

void solve()
{
  
  
  cin >> n >> m >> q;

  forf(i,0,q)
  {
    cin >> a[i] >> b[i] >> c[i] >> d[i];

  }
 vii emp;
 recur(1,n,emp);
 cout<<an<<endl;

}

int32_t main()
{
  pr_init();
  fastio;
  
  auto start = high_resolution_clock::now(); 
 
  solve();
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
  
    // cout << "Time taken by function: "
    //      << duration.count() << " microseconds" << endl; 

 }

  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
  
    // cout << "Time taken by function: "
    //      << duration.count() << " microseconds" << endl; 

 }


Compiler output:
a.cc:100:12: error: stray '#' in program
  100 |   solve(); #include<bits/stdc++.h>
      |            ^
a.cc: In function 'int32_t main()':
a.cc:100:13: error: 'include' was not declared in this scope
  100 |   solve(); #include<bits/stdc++.h>
      |             ^~~~~~~
a.cc:100:21: error: 'bits' was not declared in this scope
  100 |   solve(); #include<bits/stdc++.h>
      |                     ^~~~
a.cc:100:26: error: 'stdc' was not declared in this scope; did you mean 'std'?
  100 |   solve(); #include<bits/stdc++.h>
      |                          ^~~~
      |                          std
a.cc:104:2: error: expected primary-expression before 'using'
  104 |  using namespace std;
      |  ^~~~~
a.cc:138:1: error: a function-definition is not allowed here before '{' token
  138 | {
      | ^
a.cc:153:1: error: a function-definition is not allowed here before '{' token
  153 | {
      | ^
a.cc:176:1: error: a function-definition is not allowed here before '{' token
  176 | {
      | ^
a.cc:192:13: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
  192 | int32_t main()
      |             ^~
a.cc:192:13: note: remove parentheses to default-initialize a variable
  192 | int32_t main()
      |             ^~
      |             --
a.cc:192:13: note: or replace parentheses with braces to value-initialize a variable
a.cc:193:1: error: a function-definition is not allowed here before '{' token
  193 | {
      | ^