[Question]
  [
Given a list of integers find the "trajectory" that results from indefinitely moving the instructed steps to the right (left if negative), wrapping if necessary, starting at the first element.
A "trajectory", here, is defined as a list containing the elements that are visited only one time, in the order they are visited, and a list containing those visited repeatedly, also in order i.e.:
```
[first, second, ...], [first_of_loop, second_of_loop, ...]
```
Note that:
* Multiple elements may have the same value, yet these are distinct from each other when considering if they have been visited.
* The empty list need not be handled (given an empty list your code may error).
#### Example
Given
```
[6, 0, -6, 2, -9 , 5, 3]
```
we
* start at the first element, the `6`
* step right \$6\$ to the `3`,
* step right \$3\$ to the `-6`,
* step left \$6\$ to the `2`,
* step right \$2\$ to the `5`,
* step right \$5\$ back to the `2`.
Thus the trajectory is
```
[6, 3, -6], [2, 5]
```
...where the second list shows the final loop (we first encounter `2`, then `5`, then loop forever).
#### Test Cases
```
                                  in  out
                                 [0]  [], [0]
                                 [3]  [], [3]
                             [-1, 2]  [-1], [2]
               [5, 2, 4, 6, 7, 3, 1]  [], [5, 3, 2, 6, 4, 1]
             [6, 0, -6, 2, -9 ,5 ,3]  [6, 3, -6], [2, 5]
              [4, 5, 2, 6, -2, 7, 8]  [4], [-2, 2]
           [6, 10, 10, 0, -9, -4, 6]  [6, 6], [-4, 10, -9, 10]
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]  [], [9, 9, 9, 9]
```
  
[Answer]
# Haskell + [hgl](https://gitlab.com/WheatWizard/haskell-golfing-library), ~~61~~ ~~60~~ 58 bytes
```
(i:y)#x|i?>y=m(x!)&@sp(/=i)(rv y)|u<-(i+x!i)%l x:i:y=u#x
([0]#)
```
[hgl](https://gitlab.com/WheatWizard/haskell-golfing-library) is an experimental golfing library I am developing for Haskell. I started a few days ago and this is my first answer, and it's proof there is still a lot of room for improvement.
From this post I've learned that:
* I should probably make a dedicated function for `m.(!)`, since it is likely to come up more than just here.
* I need versions of `sp` (`span`) and `bk` (`break`) that include the element that matches / doesn't match the predicate in the first part. I had to use a hack with `rv`, which is costly and only works in this specific scenario.
* ~~I should make an infix version of `e` (`elem`). It would have saved me at least a byte here.~~ Turns out I had already done this (`(?>)`). Maybe what I actually need is better documentation that makes it easier to find this stuff.
* ~~I should make an infix version of `jB`. It would have saved me at least 2 bytes here.~~ This also existed and I didn't realize (`(&@)`). There might be a pattern here.
* It might be a good idea to make an infix of `sp`. It could have saved me a byte here if I hadn't made an infix of `jB`.
* I have probably overall underestimated the usefulness of infixes and I should in general just make more of them.
### But here's how it actually works:
Vocab:
* `(?>)`: checks if a list contains an element (`elem`)
* `m`: map (`fmap`)
* `(!)`: index a list (sort of `(!!)`)
* `(&@)`: maps function across both parts of a tuple.
* `sp`: splits a list at the first element that matches a predicate (`span`)
* `rv`: reverses a list (`reverse`)
* `(%)`: modulo infix (`mod`, yes Haskell does not have a modulo infix)
So this builds up a list of indices, when a index is added that is already in the list it stops and splits at the last occurrence of that index, and converts the indices to their values.
[Answer]
# [J](http://jsoftware.com/), 53 48 bytes
*-5 thanks to Jonah!*
```
(_2{.{~</.~]+./\@e.r)(]~.@,r=.(#@[|]+{~){:)^:_&0
```
[Try it online!](https://tio.run/##bY4xC8IwEIX3/oqHgmlojWlao00tFAQnJ1etGaStuAhdI/nrMRWii9wdPN777riHmzHSo1YgSMGh/CwZ9qfjwcVaGGbsbsVsm7DVpenYSOPWsiYdaxbPm/OrTYylRtGr0gvuaDR4vyKKVD2Nutv9iQE8iDwInUEEvYZAAYkNcmTBlP4JLX2iSw9894oPLaGFx7c/OONT84nW/lYIyv8VuTc "J ‚Äì Try It Online")
* `r=.(#@[|]+{~){:` take the last index (starting with 0 `&0`), get the corresponding value, add it to the index and take the mod.
* `]~.@, ‚Ä¶ ^:_` append the new value to the indices list and repeat that process until the list does not change after removing duplicates
* `]+./\@e.r` the next index is a duplicate, so we find it in the indices list and have a bitmask: 0 for visited once, 1 for loops.
* `_2{.{~</.~` group the values based on the indices. Because there might be no items that are visited once, we can pad the output with taking the last two items `_2{.`
Another approach would be to not build a list, but just repeat the index-shift-mod-loop `<@#` times, keeping the results, and then search for the loop. But I didn't get it shorter than this.
[Answer]
# JavaScript (ES6), 92 bytes
```
a=>[(g=p=>a=1/(i=g[p%=w=a.length])?[]:[q=a[p],...g(p+q+w*q*q,g[p]=k++)])(k=0).splice(0,i),a]
```
[Try it online!](https://tio.run/##lVHbboQgEH3vV8xLE1gHFG/tNmH7IYQHYl1r1yjWTffzLdDamDTRLGEe5sycM2fgw3yZqfps7ZX1w1s9n@Vs5EmRRlp5MlLEpJWNso/yJg3v6r65vmv6qvSLGqVRViPnvCE2GqPbYTyM6Hq1vEQR1ZRcZEL5ZLu2qkmCLUWj52rop6GreTc05Exg76hEUwpxDEqjTx7u5WdrfnYXXzGBkC58JrxCuqOgCkdByBFKhCeEDEGsHRQBSkM597UtOeWaEgRWBgY7AhaAfwuVQYqVwRZCse1MuWnFMpmlwdzzIpV7DQ9urecHiuQnvKujC7/nyk/w4kHx2yD@/Zhy6M5dv9cKnb8B "JavaScript (Node.js) ‚Äì Try It Online")
### Commented
```
a => [                 // a[] = input array
  ( g = p =>           // g is a recursive function taking a position p
                       // the underlying object of g is also used to keep
                       // track of the positions that are visited
    a =                // update a[]
      1 / (            //
        i = g[         // reduce the position modulo the length w of the
          p %= w =     // array and load g[p] into i
            a.length   //
        ]              //
      ) ?              // if i is defined:
        []             //   we've found the loop: stop the recursion
      :                // else:
        [              //   update the output array:
          q = a[p],    //     load a[p] into q
          ...g(        //     do a recursive call:
            p + q +    //       add q to p
            w * q * q, //       also add w*q¬≤ to make sure it's >= 0
            g[p] = k++ //       save the index k into g[p] and increment k
          )            //     end of recursive call
        ]              //   end of array update
  )(k = 0)             // initial call to g with p = k = 0
  .splice(0, i),       // extract the non-looping part
  a                    // append the looping part
]                      //
```
[Answer]
# [Pip](https://github.com/dloscutoff/pip) -xp, 32 bytes
```
^:iT(Yy+a@y%:#a)NiiPBya@i^@:i@?y
```
Takes the list (formatted like so: `[1;2;-3]`) as a command-line argument, and outputs a list of two lists. [Try it here!](https://replit.com/@dloscutoff/pip) Or, [verify all test cases](https://tio.run/##K8gs@F8dZpVoHe7@P84qM0QjslI70aFS1Uo5UdMvMzPAqTLRITPOwSrTwb7yf62Cr0L6/2iDWK5oYyDWNbRWMALSpkDKWsHEWsHMWsHcWsHYWsEQKArkGFgr6JqBJXUtrRVMFaxBuoDqIBqAMrpGYB0WEOWGBhBsAFGvCzIRKANkEkCx/3WLAgA "Pip ‚Äì Try It Online") at TIO.
### Explanation
```
^:iT(Yy+a@y%:#a)NiiPBya@i^@:i@?y
                                  a is cmdline input, eval'd (-x flag);
                                  i is 0, y is "" (implicit)
^:i                               Split i and assign back to i: i is now [0]
   T                              Loop until
      y                            current index
       +a@y                        plus number at current index
           %:                      mod
             #a                    length of list
     Y                             (yank into y, making this the new index)
    (          )Ni                 is already in the list of indices traversed:
                  iPBy              Push the new index onto the list of indices
                                  After the loop, we have the list of unique
                                  indices traversed in i and the first repeated
                                  index in y
                      a@i         Values from a at each index in i
                         ^@:      split at
                            i@?y  the index of y in i
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 42 bytes
```
‚âî‚Å∞Œ∂Ôº∑¬¨‚ÑñœÖŒ∂¬´‚äûœÖŒ∂‚âîÔπ™‚Å∫Œ∂¬ßŒ∏Œ∂Ôº¨Œ∏Œ∂¬ª‚âî‚åïœÖŒ∂Œ∂ÔºµÔº≠œÖ¬ßŒ∏ŒπÔº©‚ü¶‚Ä¶œÖŒ∂‚úÇœÖŒ∂
```
[Try it online!](https://tio.run/##TY/NCsIwEITP9ily3EIKoihITyUgCFYKHksPoQ1NIE20SfzFZ4@pUfC0OzP7Lbstp2OrqfS@MEb0CuYYPdI8uXIhGYKDtkC0Uxbc5KcpeiazyhkedZ7MvlipOyc1VNIZeGBU2J3q2A3OHwqjPVO95XCe@gl7JV9uK1QXd8WgpCeih4FG92@NSENajSKcQqixUJN7Kxnh@vTDj1K0LIomDHtf12uMwj9ZKItQNhitMFo2jc8u8g0 "Charcoal ‚Äì Try It Online") Link is to verbose version of code. Explanation:
```
‚âî‚Å∞Œ∂
```
Start at index 0.
```
Ôº∑¬¨‚ÑñœÖŒ∂¬´
```
Repeat until a duplicate index is found.
```
‚äûœÖŒ∂
```
Save the current index.
```
‚âîÔπ™‚Å∫Œ∂¬ßŒ∏Œ∂Ôº¨Œ∏Œ∂
```
Calculate the new index.
```
¬ª‚âî‚åïœÖŒ∂Œ∂
```
Find the position of the repeat.
```
ÔºµÔº≠œÖ¬ßŒ∏Œπ
```
Replace the indices with the values.
```
Ôº©‚ü¶‚Ä¶œÖŒ∂‚úÇœÖŒ∂
```
Output the values before and after the repeat as separate arrays.
[Answer]
# [Ruby](https://www.ruby-lang.org/), 91 bytes
```
->l{*r=a=b=0;r<<a until b=r.index(a=(a+l[a])%l.size);[z=r[0,b],r-z].map{|x|l.values_at *x}}
```
[Try it online!](https://tio.run/##DcXRCoIwFADQX7kvgdrdGEVB6O1Hxog7miAskeliTf325Xk5Idpf6amIp1@bQEyWVBu6jiGOy@DBUpDD@HapYqr47DWb@uTlPGRXtzpT0AqtwSCykR@e1i1tXn7ZRze/eIEm7XuZoAet7wgKQRxdjh6AcEO4GlP@ "Ruby ‚Äì Try It Online")
[Answer]
# [C (clang)](http://clang.llvm.org/), 137 bytes
```
a,i,j;
#define f(l,z){int t[z]={i=j=0},h[z];for(;!(a=t[i]);i=(z+i+l[i]%z)%z)h[j]=l[i],t[i]=++j;for(i=0;i<j;)printf("! %d"+!!--a,h[i++]);}
```
[Try it online!](https://tio.run/##hZHtaoMwFIb/exXRUVA8oUn8mmS5kpAf0tU10rnSOhgWr92dpMWu3WAayDnvefKefGzoZt/0b/PcgIVOBk@v29b2W9LGexiTs@0HMujRqLNVnWIT7DCR7ccxlmHcqEFbk0ir4jG16R6T1Zjg2OnOKJeCA1Sadn6JVUzal04mhyP6tnEUktVrlIYhpQ0a2zRFs2l2Pd8b25M4OQfE72B7GjTuoQTCgFCcBE41AVIAySZ5pZhj2JJyl96qwqWUg1iUzCmFN8uBoGuFbkD4AhQOyH0X4QEqPPS8EOV1W5wBDga0BppDudQrV6@B/DOQD/DKB3RJDp/DKY6iRHqF/1IEiAclg@qmrNegC8hAQAk5cOMJvL@fjNeK@1U6N0C0O6C4rCkf6iWUBjSejvtjcnbBKuDivnsN/jfBNOu/X8wErsCBuOtG4QsjF2JnzVzs8cxF@OEDcPMN "C (clang) ‚Äì Try It Online")
```
l : list , z : length 
int t[z] : kinda sieve, every step sets the visited item to step number
h[z] : save the trajectory values in order for output
for(;!(a=t[i]) : we iterate until we find a visited item, saving in a the first already visited
;i=(z+i+l[i]%z)%z) : modulo hack 
at each iteration :
h[j]=l[i] : add item to output list
,t[i]=++j; : and update sieve
Output
for(i=0;i&ltj) : j is the number of items visited
printf("! %d"+!!--a,h[i++]) 
a is the beginning of loop so we 
put a separator by including '!' in format string 
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), ~~32~~ ~~29~~ ~~25~~ 23 bytes
*Edit: -2 bytes thanks to Razetime*
```
‚Ä†!¬πG-¬ßeoU·π†-UUm‚Üê¬°S·πôo!¬π‚Üê≈Ä
```
[Try it online!](https://tio.run/##yygtzv7//1HDAsVDO911Dy1PzQ99uHOBbmho7qO2CYcWBj/cOTMfKAXkHG34//9/tJmOgY6umY6Rjq6ljqmOcSwA "Husk ‚Äì Try It Online")
Outputs loop first, then first-visited.
**Piece by piece:**
Make an infinite list of lists of indices by repeatedly shifting by the input value indexed by the first element:
```
¬°S·πôo!¬π‚Üê≈Ä
```
And get the first element of each of these: this is the list of indices:
```
m‚Üê
```
Now, get the longest non-repeating prefix (this includes one copy of the repeating elements):
```
U
```
And get the repeating indices:
```
oU·π†-U
```
Join these together into a list of 2 lists:
```
¬ße
```
And remove the first (the repeating indices) from the second (the prefix):
```
G-
```
Finally, use these to index into the original input:
```
‚Ä†!¬π
```
[Answer]
# [Python 3](https://docs.python.org/3/), 116 bytes
```
f=lambda a,i=0,k=[]:i in k and[[a[q]for q in x]for x in[k[:k.index(i)],k[k.index(i):]]]or f(a,(i+a[i])%len(a),k+[i])
```
[Try it online!](https://tio.run/##hZBNb4JAEIbP@ismJk1262D4EFpJOFkOXhrT2KbJZg9rxLgBESm29tfTna3EfhwgLDvz7DvzDlt9NrtDGbTtNinUfr1RoFAnLuaJkLEGXUIOqtwIocRRbg81HImdbXg2ochFnE90ucnOTHOJubhmsZTSyLZMIdNjJbTkN0VWMsUxH1PWfux0kcGqPmXxcKAQ1pDAXlUse1cFmu7VqWF88tbUuqK9KnTDRgAjzoeDqtalyRaPy@dVPEJQV5a@LtP5Kn0gfLu@8qd0ni5eLtyMxXkLfY9wpflIpGDYrw46ddCjFo6H4EsbkN7/pxehESBMESKEO4QAweu6hzb17dGU@O9iYbCL4ERW48wAQ0A7WmQLnchaIoR/XYXpFnadHd8a31PhlCoI/B6UGnru9yLHmVk08cXL@hDwLoeeuUVh9p63@88f5As "Python 3 ‚Äì Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 26 bytes
```
L‚Äò0·ªã+·ªã¬•%L}…ó∆¨…ó∆¨%L·∏ä·∏£2fQ,·∏ü ã/·ªã
```
[Try it online!](https://tio.run/##y0rNyan8/9/nUcMMg4e7u7WB@NBSVZ/ak9OPrQFhVZ@HO7oe7lhslBao83DH/FPd@kAV/w@3P9y5T4XrcPujpjWR//9Hc0UbxOpwRRuDCF1DHQUjEMMUSOsomOgomOkomOsoGOsoGIKEgTwDHQVdM7CsrqWOAlAdWKMJmGkEVq9rBNZjAdVgaADBBhAduiBDQVJANgEUyxULAA "Jelly ‚Äì Try It Online")
A monadic link taking a list of integers and returning two lists of integers, with the looped integers first.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 22 bytes
```
0¬∏Œî¬§DIs√®+Ig%¬©¬™√ô}D¬ÆQ√Ö¬°√®
```
[Try it online!](https://tio.run/##yy9OTMpM/f/f4NCOc1MOLXHxLD68QtszXfXQykOrDs@sdTm0LvBw66GFh1f8/x9tpqNgaADBQKRrCcQmOgpmsQA "05AB1E ‚Äì Try It Online")
[Answer]
# [PowerShell Core](https://github.com/PowerShell/PowerShell), ~~156~~ 145 bytes
```
for($v=@();!(($s=$v.IndexOf($i))+1);$i%=$l){$v+=,+$i
$t+=,($u=$args[+$i])
$i+=$u+($l=$args.Count)}if(--$l*$s){$t[$s..$l],$t[0..--$s]}else{$t,@()}
```
[Try it online!](https://tio.run/##fZJfa9swFMXf9Snuwt0qzZLrP4m3EASG0sGeWtbHEIbnyquHWmeWnXVk/uzZlZ0mfRhDxtx7zu@eK7C3zS/TugdjrSqb1hyw0vtD1bQcdzrnYvWGc3Qad@Hnp3vzfFNxrIUIYrHC@q1GK/a4C7QMsGbYUcGx11i0392apI1gWAca@4CjneTwqumfOjHUFVcK7Xt0lNCt0YUh2o2kMgpDctxmMNYZ8iTdYjgMjOWcMWou4BKiCwkRiJc2pTbnqTgqKiYtIU3FMjlTC0ghgQzmEJO3kImcy0x@kKmMj1BGhMr8MCwIyWQkVUacWsqFTI/QnHyVjPlz6VMyqRKK@XgK8QmKtkSglvQek@LIP5GPUrT2fKvldAhayn8eQpmAP/Cpaa@L8kHdfPthyg72jAGged5SY@4loK1dBxrwq9dt02xJ69rCw037m5x3WEHuKT@5vr276l3XPE5xm3xPIsBdX5bGOV9qmL2ev5xCZ6DMz/Pe1Th1W7TFo@noPxqntqd2NvlfjOttB/9JnbjrY@rInXaQRV9/YIe/ "PowerShell Core ‚Äì Try It Online")
Takes a list as parameter.
Returns two lists: loop first then trajectory
Saved:
* 2 bytes by swapping the loop / trajectory in the result
* 2 bytes by reusing `$args[$i]` as `$u`
* 1 byte by merging the declaration and first usage of `$l`
* 3 bytes by not initialising `$i` anymore
* 3 bytes thanks to *mazzy*!
#### Not golfed:
```
$index = 0
$length = $args.Count
for ($indices = @(); ($truncateAt = $indices.IndexOf($index)) -eq -1) {
    $indices += , $index
    $trajectory += , $args[$index]
    $index = ($index + $args[$index] + $length) % $length
}
if (--$length -and $truncateAt) {
    ($trajectory[0..--$truncateAt] -join ','), ($trajectory[++$truncateAt..$length] -join ',')
}
else {
    '', ($trajectory -join ',')
}
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~¬†23¬†~~ 22 [bytes](https://github.com/DennisMitchell/jelly/iki/Code-page)
Quite possibly still beatable...
```
ƒñU·πôF·∏¢∆ä∆¨·∏¢‚Ç¨‚Å∫J≈ì·πñ‚Ç¨$¬ß·π™·ªç…ó∆áL·π™
```
A monadic Link that accepts the list and yields a list of lists.
**[Try it online!](https://tio.run/##y0rNyan8///ItNCHO2e6Pdyx6FjXsTVA6lHTmkeNu7yOTn64cxqQrXJo@cOdqx7u7j05/Vi7D5D5/3A7UPjopIc7ZwDpyP//o6MNYrl0oo1BhK6hjoIRiGEKpHUUTHQUzHQUzHUUjHUUDEHCQJ6BjoKuGVhW11JBx1RBB6wRqBKiBSilawTWYwHVYGgAwSCNlkAMMhQkBWQTQLFcsQA "Jelly ‚Äì Try It Online")**
### How?
```
ƒñU·πôF·∏¢∆ä∆¨·∏¢‚Ç¨‚Å∫J≈ì·πñ‚Ç¨$¬ß·π™·ªç…ó∆áL·π™ - Link: list of integers A=[a,b,...,x,y,...]
ƒñ                      - enumerate -> [[1,a],[2,b],...,[n,x],[m,y],...]
 U                     - upend     -> [[a,1],[b,2],...,[x,n],[y,m],...]
      ∆¨                - collect until a repeat under:
     ∆ä                 -   last three links as a monad, f(current=[[x,n],[y,m],...]):
   F                   -   flatten (current) -> [x,n,y,m,...]
  ·πô                    -   rotate (current) left by (each of [x,n,y,m,...])
    ·∏¢                  -   head -> rotation by x
       ·∏¢‚Ç¨              - head each -> leftmost of each, [[a,1],...,[x,n],...]
         ‚Å∫             - repeat ·∏¢‚Ç¨ -> visited elements in order, [a,...,x,...,last_of_loop]
              $        - last two links as a monad, f(V=[a,...,x,...,last_of_loop]):
          J            -   range of length -> [1,2,...,length(V)]
           ≈ì·πñ‚Ç¨         -   partition (V) before each (of those) indices
                   ∆á   - filter (all of these 2-partitions) keeping if:
                    L  -   use length (of A) on the right of...
                  …ó    -   last three links as a dyad, f(partition, length(A)):
               ¬ß       -     sums
                ·π™      -     tail -> length of the potential loop
                 ·ªç     -     how many times is that divisible by length(A)?
                             (positive (truthy) if an actual loop, else 0 (falsey))
                     ·π™ - tail
```
[Answer]
# [R](https://www.r-project.org/), ~~121~~ ~~118~~ ~~108~~ ~~102~~ ~~101~~ 99 bytes
*-10 bytes and another -6 thanks to [@Dominic van Essen](https://codegolf.stackexchange.com/users/95126/dominic-van-essen)*
```
function(a,t=1){while(!(t=(t+a[t]-1)%%sum(a|1)+1)%in%T)T=c(T,t)
split(a[T],cut(cumsum(T==t),-1:1))}
```
[Try it online!](https://tio.run/?fbclid=IwAR1DVml-S6X2G9FaLKvkNJy0r39FC1Pqq2Fi0Lp4mvQZ1e1Megiil4wdFSM##hY3NCoMwDMfvPkV3EBJMwfqxzUHfojfxIGUyQd2YKTtse3bXqvdBvn//JM@l00vnJsv9fYKWWCt8v279cIUDsAZO2pobqTCOZzdC@1GY@KafYoNGWzDEGM2PoWdoa9OQdQzWjUFrtGYkqS4K8bt0YOFIIiUhfcp8qgSJkkSOGHWQhiDzEC1IRRluZblqCxJ@6eTFJNROinU7W4nMVnrekZ@odPPwr/IeLuzUt38McfkB "R ‚Äì Try It Online")
The outputted lists have weird names (two intervals), but it I hope it's ok.
[Answer]
# [jq](https://stedolan.github.io/jq/), 146 bytes
```
length as$l|def x:((.[0]+.[1][-1])%$l+$l)%$l;def n:x as$x|.[1]|index($x);. as$i|[0,[],[]]|until(n;[$i[x],.[1]+[x],.[2]+[$i[x]]])|.[2][:n],.[2][n:]
```
[Try it online!](https://tio.run/##hU3basMwDH3vV@jBg4TIIU7Xbk0@ReihtGnnYdyNZuAHf/s8Kf6AgQ46Ohf787tQCUu8rx9wfpqQr8sN0tQ0PQ3c9eSYrOP2xYTOBF2zBuKUNJ2yBrKP1yU1JrVzr6rPNCCxDOefuPrQxJmMp8So8a6SUcgmMrdZT5pi1SlOXLjI/zvaC6xDGGUfZCG8IhwR3hD2CE5UOQYEe9xMewI8AGpLcrUgjh23xnuNu6FCayeBviiO0H@Gd7@Pr9U/4rPYyx8 "jq ‚Äì Try It Online")
[Answer]
# [BQN](https://mlochbaum.github.io/BQN/), 39 bytes[SBCS](https://github.com/mlochbaum/BQN/blob/master/commentary/sbcs.bqn)
```
‚Üï‚àò‚â†‚ä∏{‚äè‚üúùï©¬®2‚Üë‚äí‚ä∏/‚ä∏(+`‚äë‚ä∏=)‚ä∏‚äî0‚àæ‚äëÀú‚çüùï®‚üú‚äë‚â†‚ä∏|ùï®+ùï©}
```
[Try it here](https://mlochbaum.github.io/BQN/try.html#code=RiDihpAg4oaV4oiY4omg4oq4e+KKj+KfnPCdlanCqDLihpHiipLiirgv4oq4KCtg4oqR4oq4PSniirjiipQw4oi+4oqRy5zijZ/wnZWo4p+c4oqR4omg4oq4fPCdlagr8J2VqX0KCkbCqOKfqDDin6nigL/in6gz4p+p4oC/4p+owq8xLCAy4p+p4oC/4p+oNSwgMiwgNCwgNiwgNywgMywgMeKfqeKAv+KfqDYsIDAsIMKvNiwgMiwgwq85ICw1ICwz4p+p4oC/4p+oNCwgNSwgMiwgNiwgwq8yLCA3LCA44p+p4oC/4p+oNiwgMTAsIDEwLCAwLCDCrzksIMKvNCwgNuKfqeKAv+KfqDksIDksIDksIDksIDksIDksIDksIDksIDksIDksIDksIDnin6kK).
```
‚Üï‚àò‚â†‚ä∏{‚äè‚üúùï©¬®2‚Üë‚äí‚ä∏/‚ä∏(+`‚äë‚ä∏=)‚ä∏‚äî0‚àæ‚äëÀú‚çüùï®‚üú‚äë‚â†‚ä∏|ùï®+ùï©} # ùï© is input, ùï® is indices 0,1,..,length-1
‚Üï‚àò‚â†‚ä∏{                                 } # pass indices into the main function as ùï®
                                ‚â†‚ä∏|ùï®+ùï©  # add indices to the input mod the length
                          ‚äëÀú‚çüùï®‚üú‚äë        # traverse from the first element a number
                                        #  of steps equal to the length,
                                        #  accumulating results
                        0‚àæ              # prepend 0
           ‚äí‚ä∏/‚ä∏(+`‚äë‚ä∏=)‚ä∏‚äî                # find the first value to repeat and
                                        #  partition by occurrences
         2‚Üë                             # take the first 2 groups
     ‚äè‚üúùï©¬®                               # and use them to index into the input
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~115~~ 131 bytes
```
f(r,n,o,l,j)int*r,**o,*l;{int*t=malloc(4*n);for(*l=j=0;j+=o[0][(t[j]=++*l)-1]=r[j],!t[j=(j%n+n)%n];);*l-=l[1]=t[j]-1;o[1]=*o+l[1];}
```
[Try it online!](https://tio.run/##fZHbbtswDIavq6dgDWSQZGmwnDRtp/lJDF0Enj3IUKVAcYFiRZ49I@UMS7dhPgAk9ZH8SQ36@zBcLhPPKqqkgpqFj4vMSsqkZLDv5C3dyyGENPCdjMJOKXMZurlr7Fx3qW9cz5d@dl1dyyC0cV1GT91jrOPzJtZRbKKzwsqgu9DjOdHa2ES2TDXF7PlyzNjrkDOnloCGArQgjFG8s7tyOvGqr4Rld6gBiAOPKvxXZKyvawG/qM23jfx8qhRW6b1TvjbEqApK9vF1OfHKkX1mLwcfOXagatGy03CIpUClPuGwjKa1ELW2AlAGUdJHBUGB5Ol16VsnFIlEA0vfpgfq5SN0cF1fkCf/Y0wTKRd0SPmN@w/w55zrlDdNcEW1LyS/qsKaRU8Z9LoOwMfHLzT9zZYVhSHcgsc8Tv7tI7iKXGc07mPZkNLxb9pc6cb93vZ6bXkcsbGwUKy1crmF8@WJGdbgv2Ut0wZa9sgeoIUd7OERtmDQ30MDeo9B/QwPsMXIDojZg24ReiqIaehriNGYzEzLnuGf708 "C (gcc) ‚Äì Try It Online")
Outputs `[prefix, loop]` into `o` and `[len(loop), len(prefix)]` into `l`. Expects these to have allocated enough memory to fit the output (though `o[1]` is discarded).
]