Language: C

struct Read<R: std::io::BufRead> {
    stdin: R,
    v: Vec<String>,
    i: usize,
}
impl<R:std::io::BufRead> Read<R> {
    pub fn new(stdin: R) -> Self {
        Read{
            stdin: stdin,
            v: Vec::new(),
            i: 0,
        }
    }
    pub fn read_line(&mut self) {
        self.i = 0; self.v.clear();
        let mut buf = String::new();
        self.stdin.read_line(&mut buf).unwrap();
        let buf = buf.trim().to_owned();
        let mut ws = buf.split_whitespace();
        loop {
            let x = ws.next();
            if x.is_none() {break;}
            let x = x.unwrap().to_owned();
            self.v.push(x);
        }
    }
    #[allow(dead_code)]
    pub fn read_t<T: std::str::FromStr>(&mut self) -> T {
        if self.i == self.v.len() {self.read_line();}
        let elem = &self.v[self.i];
        self.i += 1;
        elem.parse().unwrap_or_else(|_| panic!())
    }
    
    #[allow(dead_code)]
    pub fn read_i32(&mut self) -> i32 {
        if self.i == self.v.len() {self.read_line();}
        let elem = self.v[self.i].parse().unwrap();
        self.i += 1;
        elem
    }
    #[allow(dead_code)]
    pub fn read_usize(&mut self) -> usize {
        if self.i == self.v.len() {self.read_line();}
        let elem = self.v[self.i].parse().unwrap();
        self.i += 1;
        elem
    }
    #[allow(dead_code)]
    pub fn read_u64(&mut self) -> u64 {
        if self.i == self.v.len() {self.read_line();}
        let elem = self.v[self.i].parse().unwrap();
        self.i += 1;
        elem
    }
    #[allow(dead_code)]
    pub fn read_string(&mut self) -> String {
        if self.i == self.v.len() {self.read_line();}
        let elem = &self.v[self.i];
        self.i += 1;
        elem.to_owned()
    }
}

fn main() {
    use std::io;
    let stdin = io::stdin();
    let stdin = io::BufReader::new(stdin.lock());
    let read = Read::new(stdin);
    solve(read);
}


fn solve<R: std::io::BufRead>(mut r: Read<R>) {
    let n = r.read_i32();
    let m = r.read_i32();
    let q = r.read_i32();
    let mut a:Vec<i32> = Vec::new();
    let mut b:Vec<i32> = Vec::new();
    let mut c:Vec<i32> = Vec::new();
    let mut d:Vec<i32> = Vec::new();
    for _i in 0..q {
        a.push(r.read_i32());
        b.push(r.read_i32());
        c.push(r.read_i32());
        d.push(r.read_i32());
    }
    let mut x:Vec<i32> = Vec::new();
    for _i in 0..n {
        x.push(1);
    }
    let mut ans:i32 = 0;
    loop {
        let mut sum:i32 = 0;
        for i in 0..q as usize {
            if x[b[i] as usize - 1] - x[a[i] as usize - 1] == c[i] {
                sum += d[i];
            }
        }
        ans = if sum > ans {
            sum
        }else{
            ans
        };
        if make_indexes(&mut x, &m) {
            break;
        }
    }

    println!("{}", ans);
}

fn make_indexes(a: &mut Vec<i32>, m: &i32) -> bool{
    for i in (0..a.len()).rev() {
        if a[i] < *m {
            a[i] += 1;
            for j in (i+1)..a.len() {
                a[j] = a[i];
            }
            return false;
        }
    }

    true
}

Compiler output:
main.c:1:12: error: expected identifier or '(' before '<' token
    1 | struct Read<R: std::io::BufRead> {
      |            ^
main.c:6:5: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
    6 | impl<R:std::io::BufRead> Read<R> {
      |     ^
main.c:27:6: error: invalid preprocessing directive #[
   27 |     #[allow(dead_code)]
      |      ^
main.c:35:6: error: invalid preprocessing directive #[
   35 |     #[allow(dead_code)]
      |      ^
main.c:42:6: error: invalid preprocessing directive #[
   42 |     #[allow(dead_code)]
      |      ^
main.c:49:6: error: invalid preprocessing directive #[
   49 |     #[allow(dead_code)]
      |      ^
main.c:56:6: error: invalid preprocessing directive #[
   56 |     #[allow(dead_code)]
      |      ^
main.c:65:1: error: unknown type name 'fn'
   65 | fn main() {
      | ^~
main.c: In function 'main':
main.c:66:5: error: unknown type name 'use'
   66 |     use std::io;
      |     ^~~
main.c:66:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before '::' token
   66 |     use std::io;
      |            ^~
main.c:67:5: error: unknown type name 'let'
   67 |     let stdin = io::stdin();
      |     ^~~
main.c:67:17: error: 'io' undeclared (first use in this function)
   67 |     let stdin = io::stdin();
      |                 ^~
main.c:67:17: note: each undeclared identifier is reported only once for each function it appears in
main.c:67:19: error: expected ',' or ';' before '::' token
   67 |     let stdin = io::stdin();
      |                   ^~
main.c:68:5: error: unknown type name 'let'
   68 |     let stdin = io::BufReader::new(stdin.lock());
      |     ^~~
main.c:68:9: error: redefinition of 'stdin'
   68 |     let stdin = io::BufReader::new(stdin.lock());
      |         ^~~~~
main.c:67:9: note: previous definition of 'stdin' with type 'int'
   67 |     let stdin = io::stdin();
      |         ^~~~~
main.c:68:19: error: expected ',' or ';' before '::' token
   68 |     let stdin = io::BufReader::new(stdin.lock());
      |                   ^~
main.c:69:5: error: unknown type name 'let'
   69 |     let read = Read::new(stdin);
      |     ^~~
main.c:69:16: error: 'Read' undeclared (first use in this function)
   69 |     let read = Read::new(stdin);
      |                ^~~~
main.c:69:20: error: expected ',' or ';' before '::' token
   69 |     let read = Read::new(stdin);
      |                    ^~
main.c:70:5: error: implicit declaration of function 'solve' [-Wimplicit-function-declaration]
   70 |     solve(read);
      |     ^~~~~
main.c: At top level:
main.c:74:1: error: unknown type name 'fn'
   74 | fn solve<R: std::io::BufRead>(mut r: Read<R>) {
      | ^~
main.c:74:9: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
   74 | fn solve<R: std::io::BufRead>(mut r: Read<R>) {
      |         ^
main.c:82:15: error: too many decimal points in number
   82 |     for _i in 0..q {
      |               ^~~~
main.c:89:15: error: too many decimal points in number
   89 |     for _i in 0..n {
      |               ^~~~
main.c:95:18: error: too many decimal points in number
   95 |         for i in 0..q as usize {
      |                  ^~~~
main.c:113:1: error: unknown type name 'fn'
  113 | fn make_indexes(a: &mut Vec<i32>, m: &i32) -> bool{
      | ^~
main.c:113:18: error: expected ')' before ':' token
  113 | fn make_indexes(a: &mut Vec<i32>, m: &i32) -> bool{
      |                  ^
      |                  )
main.c:114:15: error: too many decimal points in number
  114 |     for i in (0..a.len()).rev() {
      |               ^~~~~~~~