var n, x, y;

fun append (x, y) {
    case x of
      Nil         ->  y
    | Cons (h, t) ->  Cons (h, append (t, y))
    esac
}

fun printList (x) {
    case x of
      Nil         -> skip
    | Cons (h, t) -> write (h); printList (t)
    esac
}

n := read ();

x := Cons (1, Cons (2, Nil));
y := Cons (3, Cons (4, Nil));

printList (x);
printList (y);
printList (append (x, y));
printList (append (y, x))
