output_description: Print the K-th lexicographically smallest substring of K.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      s
      K
attempt: import numpy as np
  
  N, M = list(map(int, input().split()))
  p = list(map(int, input().split()))
  x = []
  y = []
  for _ in range(M):
      xi, yi = list(map(int, input().split()))
      x.append(xi - 1)
      y.append(yi - 1)
  
  
  def count(l):
      out = 0
      for i, v in enumerate(l):
          if i + 1 == v:
              out += 1
      return out
  
  
  def swap(l, a, b):
      va = l[a]
      vb = l[b]
      l1 = l.copy()
      l1[a] = vb
      l1[b] = va
      return l1
  
  
  depth = 0
  max_count = count(p)
  max_d = M**5
  children = [p]
  next_children = []
  while depth <= max_d:
      for child in children:
          for i in range(M):
              pi = swap(child, x[i], y[i])
              ci = count(pi)
              if ci > max_count:
                  max_count = ci
              if not pi in next_children:
                  next_children.append(pi)
      depth += 1
      children = next_children
      next_chldren = []
      if max_count == len(p):
          break
  
  print(max_count)
  
problem_description: Statement
  
  You are given a string s. Among the **different** substrings of s, print the
  K-th lexicographically smallest one.
  
  A substring of s is a string obtained by taking out a non-empty contiguous
  part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings
  of s, while `ac`, `z` and an empty string are not. Also, we say that
  substrings are different when they are different as strings.
  
  Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings.
  X is lexicographically larger than Y if and only if Y is a prefix of X or
  x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.
samples: [{"input": "aba\n    4", "output": "b\n    \n\ns has five substrings: `a`, `b`, `ab`, `ba` and `aba`. Among them, we should\nprint the fourth smallest one, `b`. Note that we do not count `a` twice.\n\n* * *"}, {"input": "atcoderandatcodeer\n    5", "output": "andat\n    \n\n* * *"}, {"input": "z\n    1", "output": "z"}]