First Last Last First Challenge

The task is simple. Given an array and a first and last value: Return the first of the last after the first, and the last of the first before the last.



Or simply: Given an array, var1, var2.

Example Array:

[ var2, , var1, , var2, , var2, var1, var2, ]

Return:


The index of the first var2 on the right side of the first var1 that appears in the array.


[ var2, , first var1, , first var2, , second var2, var1, third var2, ]


The index of the first var1 on the left side of the last var2 that appears in the array.


[ var2, , second var1, , var2, , var2, first var1,last var2, ]

Input

Two distinct positive integers

Array of positive integers

Output

Index of answers, in order

Rules

The array will contain at least one of each variable (minimum size of 2)

Assume inputs work


  Example: 0, 1 [1, 0] or similar would fail


IO is flexible

Examples

Input
First = 2; Last = 4; [0, 2, 4, 2, 3, 1, 4, 0, 1, 2, 4, 9]

Output
2, 9




Input
First = 4; Last = 2; [0, 2, 4, 2, 3, 1, 4, 0, 1, 2, 4, 9]

Output
3, 6




Input
First = 0; Last = 1; [0, 1]

Output
1, 0
JavaScript (ES6), 63 bytes



(x,y,a)=&gt;a.map(P=(v,i)=&gt;v-y?v-x?0:a=i:1/(p=a)?P=+P||i:0)&amp;&amp;[P,p]


Try it online!

Commented

(x, y, a) =&gt;          // given the two integers x, y and the array a[]
  a.map(P =           // initialize P to a non-numeric value
            (v, i) =&gt; // for each value v at position i in a[]:
    v - y ?           //   if v is not equal to y:
      v - x ?         //     if v is not equal to x:
        0             //       do nothing
      :               //     else (v = x):
        a = i         //       save the current position in a
    :                 //   else (v = y):
      1 / (p = a) ?   //     update p to a (last position of x); if p is numeric (&gt;= 0):
        P = +P || i   //       unless P is also already numeric, update it to i
                      //       (if P is numeric, it's necessarily greater than 0 because
                      //       we've also seen x before; that's why +P works)
      :               //     else:
        0             //       do nothing
  )                   // end of map()
  &amp;&amp; [P, p]           // return [P, p]


Alternate versions

Using JS built-ins, a more straightforward answer is 79 bytes:

(x,y,a)=&gt;[a.indexOf(y,a.indexOf(x)),a.slice(0,a.lastIndexOf(y)).lastIndexOf(x)]


which can be slightly compressed to 75 bytes:

(x,y,a)=&gt;[a.indexOf(y,a.indexOf(x)),a.slice(0,a[L='lastIndexOf'](y))[L](x)]


Try it online!

Edit: @Neil managed to reduce it to a very nice 67-byte:

(x,y,a,f=s=&gt;a[z=y,y=x,x=z,s+=`ndexOf`](x,a[s](y)))=&gt;[f`i`,f`lastI`]


Try it online!