For example the array with n=10 elements:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
gets cyclicly left-shifted by 3 so the first number is f=3 to produce the array:
[3, 4, 5, 6, 7, 8, 9, 0, 1, 2]
From i=8 to j=1 there are d=3 steps, that is the left-to-right distance d. From i=8 to j=3 there are d=5 steps, because after 2 it cyclicly jumps to 3 (think of it as a ring). How does one generally calculate the distance d between two numbers i,j, when n and f are known, assuming the array always contains cyclicly left-shifted consecutive integers initially starting from 0?