@jit(nopython=True, cache=True)
def next_k_array(a):
 k = len(a)
 if (k == 0):
  return a
 x = 0
 for i in range(k):
  x += (1 << a[i])
 x = next_k_combination(x)
 pos = 0
 for i in range(k):
  while ((x & 1) == 0):
   x = (x >> 1)
   pos += 1
  a[i] = pos
  x = (x >> 1)
  pos += 1
 return a

@ jit ( nopython = True , cache = True ) def next_k_array ( a ) : k = len ( a ) if ( k == 0 ) : return a x = 0 for i in range ( k ) : x += ( 1 << a [ i ] ) x = next_k_combination ( x ) pos = 0 for i in range ( k ) : while ( ( x & 1 ) == 0 ) : x = ( x >> 1 ) pos += 1 a [ i ] = pos x = ( x >> 1 ) pos += 1 return a
given an array a of k distinct nonnegative integers .