Solution (source code)

= Solution

Save the last entry and shift in decreasing index order, so no source is overwritten before being used:
``
PROCEDURE RightOne;
VAR saved: T; i: INTEGER;
BEGIN
  saved := a[N-1]; i := N-1;
  WHILE i > 0 DO
    a[i] := a[i-1]; i := i-1
  END;
  a[0] := saved
END RightOne;
``
The <loop invariant> is `saved = A[N-1]`, $a[j]=A[j]$ for $0\leq j\leq i$, and $a[j]=A[j-1]$ for $i<j<N$. The decreasing <loop variant> is $i$. At exit the untouched saved value fills index zero. \b[The result is $a[j]=A[(j-1)\bmod N]$], again with $N$ reads, $N$ writes, and one extra value of type `T`. Applying this after part (b) restores every original entry.