let mat_mul a b n =
  let c = Array.make (n * n) 0 in
  for i = 0 to n - 1 do
    for j = 0 to n - 1 do
      for k = 0 to n - 1 do
        c.(i * n + j) <- c.(i * n + j) + a.(i * n + k) * b.(k * n + j)
      done
    done
  done;
  c

;;

let n = 3 in
let a = Array.of_list [1;2;3; 4;5;6; 7;8;9] in
let b = Array.of_list [9;8;7; 6;5;4; 3;2;1] in
let c = mat_mul a b n in
Array.fold_left (+) 0 c
