Language: C++

struct Pair {
    int a, b, c, d;
};

static int N, M, Q;
static int max;
static std::vector<Pair> pairs;

void count(std::vector<int> vals) {
    int sum = 0;
    for (auto && pair : pairs) {
        if (vals[pair.b - 1] - vals[pair.a - 1] == pair.c) {
            sum += pair.d;
        }
    }
    if (max < sum) {
        max = sum;
    }
}

void combination() {
    std::vector<int> indices(N);
    int start_index = 1;
    int size = 0;

    while (size >= 0) {
        for (int i = start_index; i <= M;) {
            indices[size++] = i;
            if (size == N) {
                count(indices);
                break;
            }
        }
        size--;
        start_index = indices[size] + 1;
    }
}


int main() {
    std::cin >> N >> M >> Q;

    pairs = std::vector<Pair>(Q);
    max = 0;

    for (int i = 0; i < Q; i++) {
        std::cin >> pairs[i].a >> pairs[i].b >> pairs[i].c >> pairs[i].d;
    }

    combination();

    std::cout << max << std::endl;
}


Compiler output:
a.cc:7:13: error: 'vector' in namespace 'std' does not name a template type
    7 | static std::vector<Pair> pairs;
      |             ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | struct Pair {
a.cc:9:6: error: variable or field 'count' declared void
    9 | void count(std::vector<int> vals) {
      |      ^~~~~
a.cc:9:17: error: 'vector' is not a member of 'std'
    9 | void count(std::vector<int> vals) {
      |                 ^~~~~~
a.cc:9:17: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:9:24: error: expected primary-expression before 'int'
    9 | void count(std::vector<int> vals) {
      |                        ^~~
a.cc: In function 'void combination()':
a.cc:22:10: error: 'vector' is not a member of 'std'
   22 |     std::vector<int> indices(N);
      |          ^~~~~~
a.cc:22:10: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:22:17: error: expected primary-expression before 'int'
   22 |     std::vector<int> indices(N);
      |                 ^~~
a.cc:28:13: error: 'indices' was not declared in this scope
   28 |             indices[size++] = i;
      |             ^~~~~~~
a.cc:30:17: error: 'count' was not declared in this scope
   30 |                 count(indices);
      |                 ^~~~~
a.cc:35:23: error: 'indices' was not declared in this scope
   35 |         start_index = indices[size] + 1;
      |                       ^~~~~~~
a.cc: In function 'int main()':
a.cc:41:10: error: 'cin' is not a member of 'std'
   41 |     std::cin >> N >> M >> Q;
      |          ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | struct Pair {
a.cc:43:5: error: 'pairs' was not declared in this scope
   43 |     pairs = std::vector<Pair>(Q);
      |     ^~~~~
a.cc:43:18: error: 'vector' is not a member of 'std'
   43 |     pairs = std::vector<Pair>(Q);
      |                  ^~~~~~
a.cc:43:18: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:43:29: error: expected primary-expression before '>' token
   43 |     pairs = std::vector<Pair>(Q);
      |                             ^
a.cc:47:14: error: 'cin' is not a member of 'std'
   47 |         std::cin >> pairs[i].a >> pairs[i].b >> pairs[i].c >> pairs[i].d;
      |              ^~~
a.cc:47:14: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:52:10: error: 'cout' is not a member of 'std'
   52 |     std::cout << max << std::endl;
      |          ^~~~
a.cc:52:10: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:52:30: error: 'endl' is not a member of 'std'
   52 |     std::cout << max << std::endl;
      |                              ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 | struct Pair {