let create =
    fun l1 -> fun l2 ->
        let x = vector (l1 * l2) 0 in
        for i = 0 to l1 do
            for j = 0 to l2 do
                vector_set x ((l2 * i) + j) (j + i)
            done
        done ;
        x
in

let mult =
    fun x ->
    fun x1 -> fun x2 ->
    fun y ->
    fun y1 -> fun y2 ->
    let r = vector (y2 * x1) 0 in
    for i = 0 to x1 do
        for j = 0 to y2 do
            for k = 0 to y1 do
                vector_set r ((i * y2) + j)
                    ((vector_get r ((i * y2) + j)) +
                        (vector_get x ((i * x2) + k)) *
                        (vector_get y ((k * y2) + j)))
            done
        done
    done ;
    r
in

let size = read_int () in

let ar = size in
let ac = size in
let br = size in
let bc = size in

let a = create ar ac in
let b = create br bc in

print (vector_get (mult a ar ac b br bc) ((ar * bc) - 1))
