object Match extends App {
	val (s0, s1) = (readLine, readLine)

	def shortest (s : String) : Array[Int] = {
		val (buf, ans) = (Array.fill(s.length + 1)(0), Array.fill(s.length)(0))
		for (i <- s.length - 1 to 0 by -1) {
			for (j <- 0 until s.length) {
				if (s(i) == s(j) && i != j) {
					buf(j) = buf(j + 1) + 1
					ans(i) = math.max(ans(i), buf(j))
				} else buf(j) = 0
			}
		}
		ans
	}

	val (m0, m1) = (shortest(s0), shortest(s1))
	val (buf, inf) = (Array.fill(s1.length + 1)(0), 123456)
	var ans = inf
	for (i <- s0.length - 1 to 0 by -1) {
		for (j <- 0 until s1.length) {
			if (s0(i) == s1(j)) {
				buf(j) = buf(j + 1) + 1
				if (buf(j) > m0(i) && buf(j) > m1(j)) {
					ans = math.min(ans, 1 + math.max(m0(i), m1(j)))
				}
			} else buf(j) = 0
		}
	}

	print(if (ans < inf) ans else -1)
}

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val S1, S2 = ns()
    val S = S1 + "$" + S2

    val sa = suffixArray(S)
    val (lcp, rank) = longestCommonPrefix(S, sa)

    /**
      * これ以上の長さの部分文字列じゃないと重複が存在する
      */
    def limits(s: String) = {
      val sa = suffixArray(s)
      val (lcp, _) = longestCommonPrefix(s, sa)
      val res = Array.ofDim[Int](s.length + 1)
      val n = lcp.length
      REP(n) { i =>
        if (i == n - 1) {
          res(sa(i)) = lcp(i)
        } else {
          res(sa(i)) = max(lcp(i), lcp(i + 1))
        }
      }
      res
    }

    val limit1 = limits(S1)
    val limit2 = limits(S2)

    val INF = 1e6.toInt
    var ans = INF

    // debug
//    REP(sa.length) { i =>
//      System.err.println(s"$i ${S.substring(sa(i))}")
//    }

    REP(lcp.length) { i =>
      if (lcp(i) > 0) {
        val p1 = min(sa(i), sa(i - 1))
        val p2 = max(sa(i), sa(i - 1))

        // p1がS1に, p2がS2に含まれる
        if (p1 < S1.length && p2 > S1.length) {
          val p2OnS2 = p2 - S1.length - 1
          val mxLim = max(limit1(p1), limit2(p2OnS2))

          // p1, p2ともに重複制限に引っかからない最短の文字列
          val len = mxLim + 1

          // lcpがlenを作れる程に十分長い
          if (len <= lcp(i)) {
            // p1+lelnがS1を超えない
            if (p1 + len <= S1.length) {
              // debug
//              System.err.println(s"$i ${S.substring(p1, p1 + len)}")
              ans = min(ans, len)
            }
          }
        }
      }
    }

    if (ans == INF) ans = -1
    out.println(ans)
  }

  /**
    * LCPには一個手前の文字との共通の文字数が入っている
    * @return (LCP, 文字列の位置 => 辞書順の位)
    */
  def longestCommonPrefix(s: String, sa: Array[Int]): (Array[Int], Array[Int]) = {
    val n = s.length
    val lcp = Array.ofDim[Int](n + 1)
    val rank = Array.ofDim[Int](n + 1)
    REP(n + 1) { i =>
      rank(sa(i)) = i
    }
    var h = 0
    REP(n) { i =>
      val j = sa(rank(i) - 1) // sa上で１個前
      h = max(0, h - 1)
      while(i + h < n && j + h < n && s(i + h) == s(j + h)) {
        h += 1
      }
      lcp(rank(i)) = h
    }
    (lcp, rank)
  }

  /**
    * 大文字小文字が混ざってる場合はうまくいかないので注意
    * @return 辞書順 => 文字列の位置
    */
  def suffixArray(s: String): Array[Int] = {
    val n = s.length

    val sa = Array.iterate(0, n + 1)(_ + 1)
    val rank, tmp = Array.ofDim[Int](n + 1)
    REP(n) { i =>
      rank(i) = s(i)
    }
    rank(n) = -1

    def lt(len: Int)(i: Int, j: Int): Boolean = {
      if (rank(i) != rank(j)) rank(i) < rank(j)
      else {
        // 長さが足りないってことは文字がないてことなので、辞書順で先になる
        val ri = if (i + len <= n) rank(i + len) else -1
        val rj = if (j + len <= n) rank(j + len) else -1
        ri < rj
      }
    }

    var len = 1
    while(len <= n) {
      // 今のランクとダブリングをつかってlen*2までの長さで並び替える
      Sorting.quickSort[Int](sa)(Ordering.fromLessThan(lt(len)))

      // 次のlen*2の長さで並び替えたsaからrankの値を計算する
      tmp(sa(0)) = 0
      REP(n, 1) { i =>
        tmp(sa(i)) = tmp(sa(i - 1)) + (if (lt(len)(sa(i - 1), sa(i))) 1 else 0) // 前の順位のものより大きい場合は+1する
      }

      Array.copy(tmp, 0, rank, 0, n + 1)
      len *= 2
    }
    sa
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val S1, S2 = ns()
    val S = S1 + S2

    val sa = suffixArray(S)
    val (lcp, rank) = longestCommonPrefix(S, sa)

    /**
      * これ以上の長さの部分文字列じゃないと重複が存在する
      */
    def limits(s: String) = {
      val sa = suffixArray(s)
      val (lcp, _) = longestCommonPrefix(s, sa)
      val res = Array.ofDim[Int](s.length + 1)
      val n = lcp.length
      REP(n) { i =>
        if (i == n - 1) {
          res(sa(i)) = lcp(i)
        } else {
          res(sa(i)) = max(lcp(i), lcp(i + 1))
        }
      }
      res
    }

    val limit1 = limits(S1)
    val limit2 = limits(S2)

    val INF = 1e6.toInt
    var ans = INF

    // debug
//    REP(sa.length) { i =>
//      System.err.println(s"$i ${S.substring(sa(i))}")
//    }

    REP(lcp.length) { i =>
      if (lcp(i) > 0) {
        val p1 = min(sa(i), sa(i - 1))
        val p2 = max(sa(i), sa(i - 1))

        // p1がS1に, p2がS2に含まれる
        if (p1 <= S1.length && p2 >= S1.length) {
          val p2OnS2 = p2 - S1.length
          val mxLim = max(limit1(p1), limit2(p2OnS2))
          val len = mxLim + 1
          // p1, p2ともに重複制限に引っかからない程の長い文字列
          if (len <= lcp(i)) {
            // p1+lがS1を超えない
            if (p1 + len <= S1.length) {
              // debug
//              System.err.println(s"$i ${S.substring(p1, p1 + len)}")
              ans = min(ans, len) // 引っかからない最短の文字列
            }
          }
        }
      }
    }

    if (ans == INF) ans = -1
    out.println(ans)
  }

  /**
    * LCPには一個手前の文字との共通の文字数が入っている
    * @return (LCP, 文字列の位置 => 辞書順の位)
    */
  def longestCommonPrefix(s: String, sa: Array[Int]): (Array[Int], Array[Int]) = {
    val n = s.length
    val lcp = Array.ofDim[Int](n + 1)
    val rank = Array.ofDim[Int](n + 1)
    REP(n + 1) { i =>
      rank(sa(i)) = i
    }
    var h = 0
    REP(n) { i =>
      val j = sa(rank(i) - 1) // sa上で１個前
      h = max(0, h - 1)
      while(i + h < n && j + h < n && s(i + h) == s(j + h)) {
        h += 1
      }
      lcp(rank(i)) = h
    }
    (lcp, rank)
  }

  /**
    * 大文字小文字が混ざってる場合はうまくいかないので注意
    * @return 辞書順 => 文字列の位置
    */
  def suffixArray(s: String): Array[Int] = {
    val n = s.length

    val sa = Array.iterate(0, n + 1)(_ + 1)
    val rank, tmp = Array.ofDim[Int](n + 1)
    REP(n) { i =>
      rank(i) = s(i)
    }
    rank(n) = -1

    def lt(len: Int)(i: Int, j: Int): Boolean = {
      if (rank(i) != rank(j)) rank(i) < rank(j)
      else {
        // 長さが足りないってことは文字がないてことなので、辞書順で先になる
        val ri = if (i + len <= n) rank(i + len) else -1
        val rj = if (j + len <= n) rank(j + len) else -1
        ri < rj
      }
    }

    var len = 1
    while(len <= n) {
      // 今のランクとダブリングをつかってlen*2までの長さで並び替える
      Sorting.quickSort[Int](sa)(Ordering.fromLessThan(lt(len)))

      // 次のlen*2の長さで並び替えたsaからrankの値を計算する
      tmp(sa(0)) = 0
      REP(n, 1) { i =>
        tmp(sa(i)) = tmp(sa(i - 1)) + (if (lt(len)(sa(i - 1), sa(i))) 1 else 0) // 前の順位のものより大きい場合は+1する
      }

      Array.copy(tmp, 0, rank, 0, n + 1)
      len *= 2
    }
    sa
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val S1, S2 = ns()
    val S = S1 + S2

    val sa = suffixArray(S)
    val (lcp, rank) = longestCommonPrefix(S, sa)

    /**
      * これ以上の長さの部分文字列じゃないと重複が存在する
      */
    def limits(s: String) = {
      val sa = suffixArray(s)
      val (lcp, _) = longestCommonPrefix(s, sa)
      val res = Array.ofDim[Int](s.length + 1)
      val n = lcp.length
      REP(n) { i =>
        if (i == n - 1) {
          res(sa(i)) = lcp(i)
        } else {
          res(sa(i)) = max(lcp(i), lcp(i + 1))
        }
      }
      res
    }

    val limit1 = limits(S1)
    val limit2 = limits(S2)

    val INF = 1e6.toInt
    var ans = INF

//    REP(sa.length) { i =>
//      System.err.println(s"$i ${S.substring(sa(i))}")
//    }

    REP(lcp.length) { i =>
      if (lcp(i) > 0) {
        val p1 = min(sa(i), sa(i - 1))
        val p2 = max(sa(i), sa(i - 1))

        // p1がS1に, p2がS2に含まれる
        if (p1 <= S1.length && p2 >= S1.length) {
          val p2OnS2 = p2 - S1.length
          val mxLim = max(limit1(p1), limit2(p2OnS2))
          // p1, p2ともに重複制限に引っかからない程の長い文字列
          if (mxLim < lcp(i)) {
            val len = mxLim + 1
            // p1+lがS1を超えない
//            if (len <= S.length) {
              ans = min(ans, len) // 引っかからない最短の文字列
//            }
          }
        }
      }
    }

    if (ans == INF) ans = -1
    out.println(ans)
  }

  /**
    * LCPには一個手前の文字との共通の文字数が入っている
    * @return (LCP, 文字列の位置 => 辞書順の位)
    */
  def longestCommonPrefix(s: String, sa: Array[Int]): (Array[Int], Array[Int]) = {
    val n = s.length
    val lcp = Array.ofDim[Int](n + 1)
    val rank = Array.ofDim[Int](n + 1)
    REP(n + 1) { i =>
      rank(sa(i)) = i
    }
    var h = 0
    REP(n) { i =>
      val j = sa(rank(i) - 1) // sa上で１個前
      h = max(0, h - 1)
      while(i + h < n && j + h < n && s(i + h) == s(j + h)) {
        h += 1
      }
      lcp(rank(i)) = h
    }
    (lcp, rank)
  }

  /**
    * 大文字小文字が混ざってる場合はうまくいかないので注意
    * @return 辞書順 => 文字列の位置
    */
  def suffixArray(s: String): Array[Int] = {
    val n = s.length

    val sa = Array.iterate(0, n + 1)(_ + 1)
    val rank, tmp = Array.ofDim[Int](n + 1)
    REP(n) { i =>
      rank(i) = s(i)
    }
    rank(n) = -1

    def lt(len: Int)(i: Int, j: Int): Boolean = {
      if (rank(i) != rank(j)) rank(i) < rank(j)
      else {
        // 長さが足りないってことは文字がないてことなので、辞書順で先になる
        val ri = if (i + len <= n) rank(i + len) else -1
        val rj = if (j + len <= n) rank(j + len) else -1
        ri < rj
      }
    }

    var len = 1
    while(len <= n) {
      // 今のランクとダブリングをつかってlen*2までの長さで並び替える
      Sorting.quickSort[Int](sa)(Ordering.fromLessThan(lt(len)))

      // 次のlen*2の長さで並び替えたsaからrankの値を計算する
      tmp(sa(0)) = 0
      REP(n, 1) { i =>
        tmp(sa(i)) = tmp(sa(i - 1)) + (if (lt(len)(sa(i - 1), sa(i))) 1 else 0) // 前の順位のものより大きい場合は+1する
      }

      Array.copy(tmp, 0, rank, 0, n + 1)
      len *= 2
    }
    sa
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val S1, S2 = ns()
    val S = S1 + S2

    val sa = suffixArray(S)
    val (lcp, rank) = longestCommonPrefix(S, sa)

    /**
      * これ以上の長さの部分文字列じゃないと重複が存在する
      */
    def limits(s: String) = {
      val sa = suffixArray(s)
      val (lcp, _) = longestCommonPrefix(s, sa)
      val res = Array.ofDim[Int](s.length + 1)
      val n = lcp.length
      REP(n) { i =>
        if (i == n - 1) {
          res(sa(i)) = lcp(i)
        } else {
          res(sa(i)) = max(lcp(i), lcp(i + 1))
        }
      }
      res
    }

    val limit1 = limits(S1)
    val limit2 = limits(S2)

    val INF = 1e6.toInt
    var ans = INF

    // debug
//    REP(sa.length) { i =>
//      System.err.println(s"$i ${S.substring(sa(i))}")
//    }

    REP(lcp.length) { i =>
      if (lcp(i) > 0) {
        val p1 = min(sa(i), sa(i - 1))
        val p2 = max(sa(i), sa(i - 1))

        // p1がS1に, p2がS2に含まれる
        if (p1 < S1.length && p2 >= S1.length) {
          val p2OnS2 = p2 - S1.length
          val mxLim = max(limit1(p1), limit2(p2OnS2))

          // p1, p2ともに重複制限に引っかからない最短の文字列
          val len = mxLim + 1

          // lcpがlenを作れる程に十分長い
          if (len <= lcp(i)) {
            // p1+lelnがS1を超えない
            if (p1 + len <= S1.length) {
              // debug
//              System.err.println(s"$i ${S.substring(p1, p1 + len)}")
              ans = min(ans, len)
            }
          }
        }
      }
    }

    if (ans == INF) ans = -1
    out.println(ans)
  }

  /**
    * LCPには一個手前の文字との共通の文字数が入っている
    * @return (LCP, 文字列の位置 => 辞書順の位)
    */
  def longestCommonPrefix(s: String, sa: Array[Int]): (Array[Int], Array[Int]) = {
    val n = s.length
    val lcp = Array.ofDim[Int](n + 1)
    val rank = Array.ofDim[Int](n + 1)
    REP(n + 1) { i =>
      rank(sa(i)) = i
    }
    var h = 0
    REP(n) { i =>
      val j = sa(rank(i) - 1) // sa上で１個前
      h = max(0, h - 1)
      while(i + h < n && j + h < n && s(i + h) == s(j + h)) {
        h += 1
      }
      lcp(rank(i)) = h
    }
    (lcp, rank)
  }

  /**
    * 大文字小文字が混ざってる場合はうまくいかないので注意
    * @return 辞書順 => 文字列の位置
    */
  def suffixArray(s: String): Array[Int] = {
    val n = s.length

    val sa = Array.iterate(0, n + 1)(_ + 1)
    val rank, tmp = Array.ofDim[Int](n + 1)
    REP(n) { i =>
      rank(i) = s(i)
    }
    rank(n) = -1

    def lt(len: Int)(i: Int, j: Int): Boolean = {
      if (rank(i) != rank(j)) rank(i) < rank(j)
      else {
        // 長さが足りないってことは文字がないてことなので、辞書順で先になる
        val ri = if (i + len <= n) rank(i + len) else -1
        val rj = if (j + len <= n) rank(j + len) else -1
        ri < rj
      }
    }

    var len = 1
    while(len <= n) {
      // 今のランクとダブリングをつかってlen*2までの長さで並び替える
      Sorting.quickSort[Int](sa)(Ordering.fromLessThan(lt(len)))

      // 次のlen*2の長さで並び替えたsaからrankの値を計算する
      tmp(sa(0)) = 0
      REP(n, 1) { i =>
        tmp(sa(i)) = tmp(sa(i - 1)) + (if (lt(len)(sa(i - 1), sa(i))) 1 else 0) // 前の順位のものより大きい場合は+1する
      }

      Array.copy(tmp, 0, rank, 0, n + 1)
      len *= 2
    }
    sa
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val S1, S2 = ns()
    val S = S1 + S2

    val sa = suffixArray(S)
    val (lcp, rank) = longestCommonPrefix(S, sa)

    /**
      * これ以上の長さの部分文字列じゃないと重複が存在する
      */
    def limits(s: String) = {
      val sa = suffixArray(s)
      val (lcp, _) = longestCommonPrefix(s, sa)
      val res = Array.ofDim[Int](s.length + 1)
      val n = lcp.length
      REP(n) { i =>
        if (i == n - 1) {
          res(sa(i)) = lcp(i)
        } else {
          res(sa(i)) = max(lcp(i), lcp(i + 1))
        }
      }
      res
    }

    val limit1 = limits(S1)
    val limit2 = limits(S2)

    val INF = 1e6.toInt
    var ans = INF

//    REP(sa.length) { i =>
//      System.err.println(s"$i ${S.substring(sa(i))}")
//    }

    REP(lcp.length) { i =>
      val len = lcp(i)
      if (len > 0) {
        val p1 = min(sa(i), sa(i - 1))
        val p2 = max(sa(i), sa(i - 1))

        // [p1, p1+len]がS1に, [p2, p2+len]がS2に含まれる
        if (p1 + len <= S1.length && p2 >= S1.length) {
          val p2OnS2 = p2 - S1.length
          val mxLim = max(limit1(p1), limit2(p2OnS2))
          // p1, p2ともに重複制限に引っかからない程の長い文字列
          if (mxLim < len) {
            ans = min(ans, mxLim + 1) // 引っかからない最短の文字列
          }
        }
      }
    }

    if (ans == INF) ans = -1
    out.println(ans)
  }

  /**
    * LCPには一個手前の文字との共通の文字数が入っている
    * @return (LCP, 文字列の位置 => 辞書順の位)
    */
  def longestCommonPrefix(s: String, sa: Array[Int]): (Array[Int], Array[Int]) = {
    val n = s.length
    val lcp = Array.ofDim[Int](n + 1)
    val rank = Array.ofDim[Int](n + 1)
    REP(n + 1) { i =>
      rank(sa(i)) = i
    }
    var h = 0
    REP(n) { i =>
      val j = sa(rank(i) - 1) // sa上で１個前
      h = max(0, h - 1)
      while(i + h < n && j + h < n && s(i + h) == s(j + h)) {
        h += 1
      }
      lcp(rank(i)) = h
    }
    (lcp, rank)
  }

  /**
    * 大文字小文字が混ざってる場合はうまくいかないので注意
    * @return 辞書順 => 文字列の位置
    */
  def suffixArray(s: String): Array[Int] = {
    val n = s.length

    val sa = Array.iterate(0, n + 1)(_ + 1)
    val rank, tmp = Array.ofDim[Int](n + 1)
    REP(n) { i =>
      rank(i) = s(i)
    }
    rank(n) = -1

    def lt(len: Int)(i: Int, j: Int): Boolean = {
      if (rank(i) != rank(j)) rank(i) < rank(j)
      else {
        // 長さが足りないってことは文字がないてことなので、辞書順で先になる
        val ri = if (i + len <= n) rank(i + len) else -1
        val rj = if (j + len <= n) rank(j + len) else -1
        ri < rj
      }
    }

    var len = 1
    while(len <= n) {
      // 今のランクとダブリングをつかってlen*2までの長さで並び替える
      Sorting.quickSort[Int](sa)(Ordering.fromLessThan(lt(len)))

      // 次のlen*2の長さで並び替えたsaからrankの値を計算する
      tmp(sa(0)) = 0
      REP(n, 1) { i =>
        tmp(sa(i)) = tmp(sa(i - 1)) + (if (lt(len)(sa(i - 1), sa(i))) 1 else 0) // 前の順位のものより大きい場合は+1する
      }

      Array.copy(tmp, 0, rank, 0, n + 1)
      len *= 2
    }
    sa
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}


import java.io._
import java.util.StringTokenizer
import scala.collection.mutable
import scala.collection.mutable._
import scala.collection.immutable._
import scala.util.Sorting.quickSort
import scala.math._

object sample extends App {
    val writer =  new PrintWriter(System.out, false)
    val reader = new BufferedReader(new InputStreamReader(System.in))
    var st = new StringTokenizer("")
    def next(): String = {while (!st.hasMoreTokens) {st = new StringTokenizer(reader.readLine())};st.nextToken()}
    def readInt(): Int = next().toInt
    def readLong(): Long = next().toLong
    def readString(): String = next()

    case class myType(var social: Int, var cp:  Int, var ind: Int)extends Ordered[myType] {
        override def compare(that: myType): Int = {
            if (social < that.social)
                return -1
            else if (social == that.social)
                return 0
            else
                return 1
        }
    }

    val t = readInt()
    for (tt <- 1 to t) {
        val n = readInt()
        var h = readInt()
        var tmp = 0
        var mx1 = 0
        var mx2 = 0
        for (i <- 0 until n) {
            tmp = readInt()
            if (tmp > mx2)
                mx2 = tmp
            if (mx2 > mx1){
                tmp = mx1
                mx1 = mx2
                mx2 = tmp
            }
        }
        var cnt = 2 * (h/(mx1+mx2)).toInt
        if (h %(mx1+mx2)!= 0)
            cnt += 1
        if (h%(mx1+mx2)> mx1)
            cnt += 1
        writer.println(cnt)
    }
    writer.flush()
}

object A extends App {

  def gamerHemose(an: Array[Int], h: Int): Int = {
    val Array(a1, a2, _*) = an.sorted(Ordering[Int].reverse)

    (h / (a1 + a2), h % (a1 + a2)) match {
      case (i, 0)            => 2 * i
      case (i, j) if j <= a1 => 2 * i + 1
      case (i, _)            => 2 * i + 2
    }
  }

  import InOut._

  val t = nextInt()

  (0 until t).foreach { _ =>
    val n  = nextInt()
    val h  = nextInt()
    val an = nextInts(n)

    out.println(gamerHemose(an, h))
  }

  out.flush()

  final object InOut {
    val in  = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)

    def nextInt()        = Integer.parseInt(nextToken())
    def nextInts(n: Int) = Array.fill(n)(nextInt())

    def nextLong()        = java.lang.Long.parseLong(nextToken())
    def nextLongs(n: Int) = Array.fill(n)(nextLong())

    def nextBig()        = BigInt(nextToken())
    def nextBigs(n: Int) = Array.fill(n)(nextBig())

    def nextLine() = in.readLine()

    private[this] var tokenizer: java.util.StringTokenizer = _

    def nextToken(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens())
        tokenizer = new java.util.StringTokenizer(in.readLine())
      tokenizer.nextToken()
    }
  }

}

object A extends App {

  def gamerHemose(an: Array[Int], h: Int): Int = {
    val Array(a1, a2, _*) = an.sorted(Ordering[Int].reverse)

    val (i, j) = (h / (a1 + a2), h % (a1 + a2))

    j match {
      case 0            => 2 * i
      case j if j <= a1 => 2 * i + 1
      case _            => 2 * i + 2
    }
  }

  import InOut._

  val t = nextInt()

  (0 until t).foreach { _ =>
    val n  = nextInt()
    val h  = nextInt()
    val an = nextInts(n)

    out.println(gamerHemose(an, h))
  }

  out.flush()

  final object InOut {
    val in  = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)

    def nextInt()        = Integer.parseInt(nextToken())
    def nextInts(n: Int) = Array.fill(n)(nextInt())

    def nextLong()        = java.lang.Long.parseLong(nextToken())
    def nextLongs(n: Int) = Array.fill(n)(nextLong())

    def nextBig()        = BigInt(nextToken())
    def nextBigs(n: Int) = Array.fill(n)(nextBig())

    def nextLine() = in.readLine()

    private[this] var tokenizer: java.util.StringTokenizer = _

    def nextToken(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens())
        tokenizer = new java.util.StringTokenizer(in.readLine())
      tokenizer.nextToken()
    }
  }

}

import java.io._
import java.util.StringTokenizer
import scala.collection.mutable
import scala.collection.mutable._
import scala.collection.immutable._
import scala.util.Sorting.quickSort
import scala.math._

object sample extends App {
    val writer =  new PrintWriter(System.out, false)
    val reader = new BufferedReader(new InputStreamReader(System.in))
    var st = new StringTokenizer("")
    def next(): String = {while (!st.hasMoreTokens) {st = new StringTokenizer(reader.readLine())};st.nextToken()}
    def readInt(): Int = next().toInt
    def readLong(): Long = next().toLong
    def readString(): String = next()

    case class myType(var social: Int, var cp:  Int, var ind: Int)extends Ordered[myType] {
        override def compare(that: myType): Int = {
            if (social < that.social)
                return -1
            else if (social == that.social)
                return 0
            else
                return 1
        }
    }

    val t = readInt()
    for (tt <- 1 to t) {
        val n = readInt()
        var h = readInt()
        var tmp = 0
        var mx1 = 0
        var mx2 = 0
        for (i <- 0 until n) {
            tmp = readInt()
            if (tmp > mx2)
                mx2 = tmp
            if (mx2 > mx1){
                tmp = mx1
                mx1 = mx2
                mx2 = tmp
            }
        }
        var cnt = (2 * h/(mx1+mx2)).toInt
        if (h %(mx1+mx2)!= 0)
            cnt += 1
        if (h%(mx1+mx2)> mx1)
            cnt += 1
        writer.println(cnt)
    }
    writer.flush()
}

import java.io._
import java.util.StringTokenizer
import scala.collection.mutable
import scala.collection.mutable._
import scala.collection.immutable._
import scala.util.Sorting.quickSort
import scala.math._

object sample extends App {
    val writer =  new PrintWriter(System.out, false)
    val reader = new BufferedReader(new InputStreamReader(System.in))
    var st = new StringTokenizer("")
    def next(): String = {while (!st.hasMoreTokens) {st = new StringTokenizer(reader.readLine())};st.nextToken()}
    def readInt(): Int = next().toInt
    def readLong(): Long = next().toLong
    def readString(): String = next()

    case class myType(var social: Int, var cp:  Int, var ind: Int)extends Ordered[myType] {
        override def compare(that: myType): Int = {
            if (social < that.social)
                return -1
            else if (social == that.social)
                return 0
            else
                return 1
        }
    }

    val t = readInt()
    for (tt <- 1 to t) {
        var n = readInt()
        var h = readInt()
        val arr = new Array[Int](n)
        for (i <- 0 until n)
            arr(i) = readInt()
        quickSort(arr)
        var cnt = 0
        while (h > 0 && n > 0) {
            cnt += 1
            h -= arr(n-1)
            n -= 1
        }
        writer.println(cnt)
    }
    writer.flush()
}

object A extends App {

  def gamerHemose(an: Array[Int], h: Int): Int = {
    val Array(a1, a2, _*) = an.sorted(Ordering[Int].reverse)
    h / (a1 + a2) * 2 + (if (h % (a1 + a2) == 0) 0 else 1)
  }

  import InOut._

  val t = nextInt()

  (0 until t).foreach { _ =>
    val n  = nextInt()
    val h  = nextInt()
    val an = nextInts(n)

    out.println(gamerHemose(an, h))
  }

  out.flush()

  final object InOut {
    val in  = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)

    def nextInt()        = Integer.parseInt(nextToken())
    def nextInts(n: Int) = Array.fill(n)(nextInt())

    def nextLong()        = java.lang.Long.parseLong(nextToken())
    def nextLongs(n: Int) = Array.fill(n)(nextLong())

    def nextBig()        = BigInt(nextToken())
    def nextBigs(n: Int) = Array.fill(n)(nextBig())

    def nextLine() = in.readLine()

    private[this] var tokenizer: java.util.StringTokenizer = _

    def nextToken(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens())
        tokenizer = new java.util.StringTokenizer(in.readLine())
      tokenizer.nextToken()
    }
  }

}


object Main {
    import java.io.File
    import java.util.Scanner
    import java.io.PrintWriter

    val in = new Scanner(System.in)
    val out = new PrintWriter(System.out)

    val pat = "hard"

    def main(args: Array[String]) {
        val n = in.nextInt
        in.nextLine
        val str = in.nextLine
        val a = (for (i <- 0 until n) yield in.nextInt).toArray
        val f = new Array[Long]((n + 1) * 4)
        for (i <- 1 until n + 1; j <- 0 until 4)
            f(i * 4 + j) = {
                if (str(i - 1) == pat(j)) {
                    if (j == 0 || f((i - 1) * 4 + j) + a(i - 1) < f((i - 1) * 4 + j - 1))
                        f((i - 1) * 4 + j) + a(i - 1)
                    else f((i - 1) * 4 + j - 1)
                }
                else f((i - 1) * 4 + j)
            }
        out.println(f(n * 4 + 3))
        in.close
        out.close
    }
}

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N = ni()
    val S = ns(N).map {
      case 'h' => 1
      case 'a' => 2
      case 'r' => 3
      case 'd' => 4
      case _ => -1
    }

    val A = nal(N)

    val INF = 1e17.toLong
    val dp = Array.fill[Long](5)(INF)
    dp(0) = 0

    REP(N) { i =>
      val s = S(i)
      if (s != -1) {
        if (dp(s - 1) != INF) dp(s) = min(dp(s), dp(s - 1))
        if (dp(s - 1) != INF) dp(s - 1) += A(i)
      }
    }

    val ans = map(4) { i =>
      dp(i)
    }.min

    if (dp(4) != INF) out.println(ans)
    else out.println(0)
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Int](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }

  def debug(as: Array[Long], delimiter: String = " "): Unit = {
    debug(as.mkString(delimiter))
  }

  def debug(s: String): Unit = {
    System.err.println(s)
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N = ni()
    val S = ns(N).map {
      case 'h' => 1
      case 'a' => 2
      case 'r' => 3
      case 'd' => 4
      case _ => -1
    }

    val A = nal(N)

    val INF = 1e17.toLong
    val dp = Array.fill[Long](5)(INF)
    dp(0) = 0

    REP(N) { i =>
      val s = S(i)
      if (s != -1) {
        if (dp(s - 1) != INF) dp(s) = min(dp(s), dp(s - 1))
        if (dp(s - 1) != INF) dp(s - 1) += A(i)
      }
//      debug(dp)
    }

//    debug(dp)

    val ans = map(4) { i =>
      dp(i)
    }.min

    out.println(ans)
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Int](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }

  def debug(as: Array[Long], delimiter: String = " "): Unit = {
    debug(as.mkString(delimiter))
  }

  def debug(s: String): Unit = {
    System.err.println(s)
  }
}


object _1729B extends CodeForcesApp {
  override def solve() = repeat() {
    val _ = nextInt()
    val s = nextStr().toList.map(_ - '0')
    out.println(parse(s))
  }

  val table = Seq.tabulate(27)(i => ('a' - 1 + i).toChar)

  def parse(chars: List[Int]): String = chars match {
    case Nil => ""
    case 0 :: _ => illegal()
    case x :: (r1 @ (y :: 0 :: r2)) if 10*x + y < table.length =>
      try {
        table(10*x + y) + parse(r2)
      } catch {
        case _: Throwable => table(x) + parse(r1)
      }
    case x :: rest => table(x) + parse(rest)
  }
}
/**************************** [Ignore Template Below] **************************************/
trait CodeForcesApp {
  import java.io._
  var in = new BufferedReader(new InputStreamReader(System.in))
  var out = new PrintWriter(System.out)

  val tokens = Iterator.continually(nextLine()).takeWhile(_ != null).flatMap(_.split(' '))

  def nextLine(): String = in.readLine()
  def nextStr(): String = tokens.next()
  def nextInt(): Int = nextStr().toInt
  def nextLong(): Long = nextStr().toLong
  def nextDouble(): Double = nextStr().toDouble
  def nextN[A](r: => A): Iterator[A] = Iterator.fill(nextInt())(r)
  def repeat[U](n: Int = nextInt())(f: => U): Unit = (1 to n).foreach(_ => f)
  def query[A](query: String, res: => A): A = {out.println(query); out.flush(); res}

  def debug(x: => Any): Unit = if (!sys.props.contains("ONLINE_JUDGE")) println(s">>> DEBUG: $x")
  def illegal(msg: String = "can't happen") = throw new IllegalStateException(msg)

  def main(args: Array[String]): Unit = try solve() finally out.flush()
  def solve(): Any
}

import scala.util.Try

object _1729B extends CodeForcesApp {
  override def solve() = repeat() {
    val _ = nextInt()
    val s = nextStr().toList.map(_ - '0')
    printLine(parse(s))
  }

  val table = Seq.tabulate(27)(i => ('a' - 1 + i).toChar)

  def parse(chars: List[Int]): String = chars match {
    case Nil => ""
    case 0 :: _ => throw new IllegalStateException()
    case x :: (r1 @ (y :: 0 :: r2)) if 10*x + y < table.length =>
      Try(table(10*x + y) + parse(r2)).getOrElse(table(x) + parse(r1))
    case x :: rest => table(x) + parse(rest)
  }
}
/**************************** [Ignore Template Below] **************************************/
trait CodeForcesApp {
  import java.io._
  var in = new BufferedReader(new InputStreamReader(System.in))
  var out = new PrintWriter(System.out)

  val tokens = Iterator.continually(nextLine()).takeWhile(_ != null).flatMap(_.split(' '))

  def nextLine(): String = in.readLine()
  def nextStr(): String = tokens.next()
  def nextInt(): Int = nextStr().toInt
  def nextLong(): Long = nextStr().toLong
  def nextDouble(): Double = nextStr().toDouble
  def nextN[A](r: => A): Iterator[A] = Iterator.fill(nextInt())(r)
  def repeat[U](n: Int = nextInt())(f: => U): Unit = (1 to n).foreach(_ => f)
  def query[A](query: String)(res: => A): A = {printLine(query); out.flush(); res}

  def print(xs: Any*): Unit = out.print(xs.mkString(" "))
  def printLine(xs: Any*): Unit = if (xs.isEmpty) out.println() else xs.foreach(out.println)
  def debug(x: => Any): Unit = if (!sys.props.contains("ONLINE_JUDGE")) println(s">>> DEBUG: $x")

  def main(args: Array[String]): Unit = try solve() finally out.flush()
  def solve(): Any
}


object D extends App {
  val t = scala.io.StdIn.readInt()

  (0 until t).foreach { _ =>
    val Array(n, k) = scala.io.StdIn.readLine().split(" ").map(_.toLong)

    val ans = n / math
      .sqrt(n)
      .toLong
      .to(1, -1)
      .collect {
        case x if n % x == 0 => List(x, n / x).filter(_ <= k)
      }
      .flatten
      .max

    println(ans)
  }
}

import java.io._
import java.util.StringTokenizer

import scala.reflect.ClassTag

object Main {
  def main(args: Array[String]): Unit = {
    try {
      val (in, out) =
        if (isOnlineJudge) {
          (
            new FastScanner(new InputStreamReader(System.in)),
            new PrintWriter(System.out)
          )
        } else {
          (
            new FastScanner(new FileReader(new File("src/resource/problem.in"))),
            new PrintWriter(new File("src/resource/problem.out"))
          )
        }
      new CF644(in, out).solve()
      out.flush()
      out.close()
    } catch {
      case e: IOException => e.printStackTrace()
    }
  }

  private[this] val isOnlineJudge = true

  class FastScanner(val streamReader: InputStreamReader) {
    private[this] val reader = new BufferedReader(streamReader, 32768)
    private[this] var tokenizer: StringTokenizer = _

    @inline private[this] final def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = Integer.parseInt(next())

    def nextLong(): Long = java.lang.Long.parseLong(next())

    def nextChar(): Char = next().charAt(0)

    def ni(): Int = nextInt()

    def nl(): Long = nextLong()

    def nc(): Char = nextChar()

    def ns(): String = next()

    def ns(n: Int): Array[Char] = ns().toCharArray

    def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)

    def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
      val A1, A2 = Array.ofDim[Int](n)
      REP(n) { i =>
        A1(i) = ni() + offset
        A2(i) = ni() + offset
      }
      (A1, A2)
    }

    def nm(n: Int, m: Int): Array[Array[Int]] = {
      val A = Array.ofDim[Int](n, m)
      REP(n) { i =>
        REP(m) { j =>
          A(i)(j) = ni()
        }
      }
      A
    }

    def nal(n: Int): Array[Long] = map(n)(_ => nl())

    def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n)(_ => ns(m))
  }

  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while (i < N) {
      f(i);
      i += 1
    }
  }

  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while (i >= offset) {
      f(i);
      i -= 1
    }
  }

  def TO(from: Int, to: Int)(f: Int => Unit): Unit = {
    REP(to - from + 1, from)(f)
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]): Array[Long] = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

class CF644(fScanner: Main.FastScanner, out: java.io.PrintWriter) {

  import Main._
  import fScanner._

  def solve(): Unit = {
    val t = ni()
    REP(t) { _ =>
      val n = ni()
      val k = ni()

      if(k >= n) {
        out.println(1)
      } else {
        val l = math.ceil(math.sqrt(n.toDouble)).toInt
        var ans = n
        2 to l by 1 foreach { f =>
          if(n % f == 0) {
            val u = n / f
            if(u <= k) ans = math.min(ans, f)
            if(f <= k) ans = math.min(ans, u)
          }
        }
        out.println(ans)
      }
    }
  }
}

object D extends App {
  val t = scala.io.StdIn.readInt()

  (0 until t).foreach { _ =>
    val Array(n, k) = scala.io.StdIn.readLine().split(" ").map(_.toLong)

    def x(n: Long): Long =
      if (n <= k) 1
      else if (n % k == 0) n / k
      else if (n % 2 == 0) 2 * x(n / 2)
      else n

    val ans = x(n)

    println(ans)
  }
}

object D extends App {
  val t = scala.io.StdIn.readInt()

  (0 until t).foreach { _ =>
    val Array(n, k) = scala.io.StdIn.readLine().split(" ").map(_.toLong)

    val ans =
      if (n <= k) 1
      else
        k.min(math.sqrt(n).toLong)
          .until(1, -1)
          .find(n % _ == 0)
          .map(x => List(x, n / x).filter(_ <= k).max)
          .getOrElse(n)

    println(ans)
  }
}

object D extends App {
  val t = scala.io.StdIn.readInt()

  (0 until t).foreach { _ =>
    val Array(n, k) = scala.io.StdIn.readLine().split(" ").map(_.toLong)

    def x(n: Long): Long =
      if (n <= k) 1
      else if (n % 2 == 0) 2 * x(n / 2)
      else n

    val ans = x(n)

    println(ans)
  }
}

object D extends App {
  val t = scala.io.StdIn.readInt()

  (0 until t).foreach { _ =>
    val Array(n, k) = scala.io.StdIn.readLine().split(" ").map(_.toLong)

    val ans =
      if (n <= k) 1
      else k.min(math.sqrt(n).toLong).until(1, -1).find(n % _ == 0).getOrElse(n)

    println(ans)
  }
}

object D extends App {
  val t = scala.io.StdIn.readInt()

  (0 until t).foreach { _ =>
    val Array(n, k) = scala.io.StdIn.readLine().split(" ").map(_.toLong)

    val ans =
      if (n <= k) 1
      else
        k.min(math.sqrt(n).toLong).until(1, -1).find(n % _ == 0).map(n / _).getOrElse(n)

    println(ans)
  }
}


object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N, K = ni()
    val S = nl()
    val L = N - 1
    val minK = (S - 1) / L + 1
    val maxK = S
    if (K < minK || K > maxK) {
      out.println("NO")
    } else {
      out.println("YES")
      var cur = 1
      var direction = 1

      val ans = ArrayBuffer[Int]()

      def move(dist: Int): Unit = {
        val to = cur + direction * dist
        ans += to
        cur = to
        if (to == 1) direction = 1
        else if (to == N) direction = -1
      }

      val s = S - K
      val l = L - 1
      if (l == 0) {
        REP(K) { _ => move(1)}
      } else {
        val a = s / l
        val b = K - (s / l + (if (s % l > 0) 1 else 0))
        REP(a.toInt) { _ => move(L) }
        val r = s % l
        if (r > 0) move((r + 1).toInt)
        REP(b.toInt) { _ => move(1) }
      }

      out.println(ans.mkString(" "))
    }
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Int](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

import java.util

object CF501D extends App {

  import java.io.PrintWriter
  import java.util.Scanner

  val in = new Scanner(System.in)
  val out = new PrintWriter(System.out)

  def solve = {
    val n = in.nextInt
    val k = in.nextInt
    val s = in.nextLong

    if (s > (n.toLong-1)*k.toLong || s < k) {
      out.println("NO")
    } else {
      val moves = new util.LinkedList[Long]()

      var distByMove = s/k
      var remainder = s%k

      var currentPos: Long = 1
      var shifted = false
      for (i <- 0 until k) {
        if (currentPos == 1) {
          currentPos = 1 + distByMove
          // add 1 in the "remainder" last steps
          // or 1 step before if k is even xor remainder is even
          if (!shifted || i != k-1) {
            if (k-i <= remainder) {
              currentPos += 1
            } else if (remainder != 0 && k-i <= remainder + 1 && (k%2 == 0 ^ remainder%2 == 0)) {
              currentPos += 1
              shifted = true
            }
          }
        } else {
          if (remainder != 0 && i == k-1 && (k%2 == 0 ^ remainder%2 == 0))
            currentPos = 2
          else
            currentPos = 1
        }
        moves.add(currentPos)
      }

      out.println("YES")
      out.println(moves.toArray.mkString(" "))
    }
  }

  solve
  out.flush
  out.close
}

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N, K = ni()
    val S = nl()
    val L = N - 1
    val minK = (S - 1) / L + 1
    val maxK = S
    if (K < minK || K > maxK) {
      out.println("NO")
    } else {
      out.println("YES")
      var cur = 1
      var direction = 1
      var k = K
      var s = S

      val ans = ArrayBuffer[Int]()

      def move(dist: Int): Unit = {
        val to = cur + direction * dist
        ans += to
        cur = to
        if (to == 1) direction = 1
        else if (to == N) direction = -1
        k -= 1
        s -= dist
      }

      while(s - k >= L) {
        move(L)
      }

      if (s - k + 1 > 0) move((s - k + 1).toInt)
      REP(k) { _ => move(1) }

      out.println(ans.mkString(" "))
    }
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int): Array[Int] = map(n)(_ => ni())
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Int](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

object Main {
  import java.io._

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import scala.collection.mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N = sc.nextInt()
    val N1 = N - 1
    val K, S = sc.nextLong()
    val ok = K <= S && S <= (N - 1) * K
    if (!ok) out.println("NO")
    else {
      val m = N - 2
      val (a, b, r) = if ((S - K) % m == 0) {
        val a = ((S - K) / m).toInt
        (a, (K - a).toInt, 0)
      } else {
        val r0 = (S - K + 1) % m
        val r = if (r0 == 0) m else r0
        val a = (S - K + 1) / m - (if (r == 8) 1 else 0)
        val b = K - a - 1
        (a.toInt, b.toInt, r.toInt)
      }

      var pos = 1
      val moves = ArrayBuffer[Int]()
      rep(a) { _ =>
        pos = pos match {
          case 1 => N
          case N => 1
        }
        moves += pos
      }
      rep(b) { _ =>
        pos = pos match {
          case 1 => 2
          case 2 => 1
          case N => N1
          case N1 => N
        }
        moves += pos
      }

      if (r > 0) {
        pos = pos match {
          case 1 => r + 1
          case 2 => r + 2
          case N => N - r
          case N1 => N1 - r
        }
        moves += pos
      }

      println("YES")
      println(moves.mkString(" "))
    }
  }

  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }

  class InputReader(val stream: InputStream) {

    import java.util.StringTokenizer

    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    // todo Orderingだとboxing発生するので自作Orderを用意したい
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      rep(as.length)(i => map.getOrElseUpdate(f(as(i)), ArrayBuffer()) += as(i))
      map
    }

    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      var sum = num.zero
      rep(as.length)(i => sum = num.plus(sum, f(as(i))))
      sum
    }

    def minByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.lt)
    }

    def maxByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.gt)
    }

    private def limit[B](f: A => B, ixRange: Range)(cmp: (B, B) => Boolean): (A, B) = {
      var limA = as(ixRange.head)
      var limB = f(limA)

      for (i <- ixRange.tail) {
        val a = as(i)
        val b = f(a)
        if (cmp(b, limB)) {
          limA = a
          limB = b
        }
      }
      (limA, limB)
    }
  }

  implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N, K = ni()
    val S = nl()
    val L = N - 1
    val minK = (S - 1) / L + 1
    val maxK = S
    if (K < minK || K > maxK) {
      out.println("NO")
    } else {
      out.println("YES")
      var cur = 1
      var direction = 1

      val ans = ArrayBuffer[Int]()

      def move(dist: Int): Unit = {
        val to = cur + direction * dist
        ans += to
        cur = to
        if (to == 1) direction = 1
        else if (to == N) direction = -1
      }

      val s = S - K
      val l = L - 1
      REP((s / l).toInt) { _ => move(L) }
      val r = s % l
      if (r > 0) move((r + 1).toInt)
      REP((K - ((s + 1) / l + 1)).toInt) { _ => move(1) }

      out.println(ans.mkString(" "))
    }
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Int](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

object Main {
  import java.io._

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import scala.collection.mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N, K = sc.nextInt()
    val N1 = N - 1
    val S = sc.nextLong()
    val ok = K <= S && S <= (N - 1) * K
    if (!ok) out.println("NO")
    else {
      val m = N - 2
      val (a, b, r) = if ((S - K) % m == 0) {
        val a = ((S - K) / m).toInt
        (a, K - a, 0)
      } else {
        val r0 = (S - K + 1) % m
        val r = if (r0 == 0) m else r0
        val a = (S - K + 1) / m - (if (r == m) 1 else 0)
        val b = K - a - 1
        (a.toInt, b.toInt, r.toInt)
      }

      var pos = 1
      val moves = ArrayBuffer[Int]()
      rep(a) { _ =>
        pos = pos match {
          case 1 => N
          case N => 1
        }
        moves += pos
      }
      rep(b) { _ =>
        pos = pos match {
          case 1 => 2
          case 2 => 1
          case N => N1
          case N1 => N
        }
        moves += pos
      }

      if (r > 0) {
        pos = pos match {
          case 1 => r + 1
          case 2 => r + 2
          case N => N - r
          case N1 => N1 - r
        }
        moves += pos
      }

      println("YES")
      println(moves.mkString(" "))
    }
  }

  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }

  class InputReader(val stream: InputStream) {

    import java.util.StringTokenizer

    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    // todo Orderingだとboxing発生するので自作Orderを用意したい
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      rep(as.length)(i => map.getOrElseUpdate(f(as(i)), ArrayBuffer()) += as(i))
      map
    }

    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      var sum = num.zero
      rep(as.length)(i => sum = num.plus(sum, f(as(i))))
      sum
    }

    def minByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.lt)
    }

    def maxByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.gt)
    }

    private def limit[B](f: A => B, ixRange: Range)(cmp: (B, B) => Boolean): (A, B) = {
      var limA = as(ixRange.head)
      var limB = f(limA)

      for (i <- ixRange.tail) {
        val a = as(i)
        val b = f(a)
        if (cmp(b, limB)) {
          limA = a
          limB = b
        }
      }
      (limA, limB)
    }
  }

  implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }
  }
}

object Main {
  import java.io._

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import scala.collection.mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N, K = sc.nextInt()
    val N1 = N - 1
    val S = sc.nextLong()
    val ok = K <= S && S <= (N - 1) * K
    if (!ok) out.println("NO")
    else {
      val m = N - 2
      val (a, b, r) = if ((S - K) % m == 0) {
        val a = ((S - K) / m).toInt
        (a, K - a, 0)
      } else {
        val r0 = (S - K + 1) % m
        val r = if (r0 == 0) m else r0
        val a = (S - K + 1) / m - (if (r0 == 0) 1 else 0)
        val b = K - a - 1
        (a.toInt, b.toInt, r.toInt)
      }

      var pos = 1
      val moves = ArrayBuffer[Int]()
      rep(a) { _ =>
        pos = pos match {
          case 1 => N
          case N => 1
        }
        moves += pos
      }
      rep(b) { _ =>
        pos = pos match {
          case 1 => 2
          case 2 => 1
          case N => N1
          case N1 => N
        }
        moves += pos
      }

      if (r > 0) {
        pos = pos match {
          case 1 => r + 1
          case 2 => r + 2
          case N => N - r
          case N1 => N1 - r
        }
        moves += pos
      }

      println("YES")
      println(moves.mkString(" "))
    }
  }

  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }

  class InputReader(val stream: InputStream) {

    import java.util.StringTokenizer

    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    // todo Orderingだとboxing発生するので自作Orderを用意したい
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      rep(as.length)(i => map.getOrElseUpdate(f(as(i)), ArrayBuffer()) += as(i))
      map
    }

    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      var sum = num.zero
      rep(as.length)(i => sum = num.plus(sum, f(as(i))))
      sum
    }

    def minByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.lt)
    }

    def maxByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.gt)
    }

    private def limit[B](f: A => B, ixRange: Range)(cmp: (B, B) => Boolean): (A, B) = {
      var limA = as(ixRange.head)
      var limB = f(limA)

      for (i <- ixRange.tail) {
        val a = as(i)
        val b = f(a)
        if (cmp(b, limB)) {
          limA = a
          limB = b
        }
      }
      (limA, limB)
    }
  }

  implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }
  }
}

object Main {
  import java.io._

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import scala.collection.mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N = sc.nextInt()
    val N1 = N - 1
    val K, S = sc.nextLong()
    val ok = K <= S && S <= (N - 1) * K
    if (!ok) out.println("NO")
    else {
      val m = N - 2
      val (a, b, r) = if ((S - K) % m == 0) {
        (((S - K) / m).toInt, 0, 0)
      } else {
        val r0 = (S - K + 1) % m
        val r = if (r0 == 0) m else r0
        val a = (S - K + 1) / m - (if (r == 8) 1 else 0)
        val b = K - a - 1
        (a.toInt, b.toInt, r.toInt)
      }

      var pos = 1
      val moves = ArrayBuffer[Int]()
      rep(a) { _ =>
        pos = pos match {
          case 1 => N
          case N => 1
        }
        moves += pos
      }
      rep(b) { _ =>
        pos = pos match {
          case 1 => 2
          case 2 => 1
          case N => N1
          case N1 => N
        }
        moves += pos
      }

      if (r > 0) {
        pos = pos match {
          case 1 => r + 1
          case 2 => r + 2
          case N => N - r
          case N1 => N1 - r
        }
        moves += pos
      }

      println("YES")
      println(moves.mkString(" "))
    }
  }

  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }

  class InputReader(val stream: InputStream) {

    import java.util.StringTokenizer

    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    // todo Orderingだとboxing発生するので自作Orderを用意したい
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      rep(as.length)(i => map.getOrElseUpdate(f(as(i)), ArrayBuffer()) += as(i))
      map
    }

    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      var sum = num.zero
      rep(as.length)(i => sum = num.plus(sum, f(as(i))))
      sum
    }

    def minByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.lt)
    }

    def maxByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.gt)
    }

    private def limit[B](f: A => B, ixRange: Range)(cmp: (B, B) => Boolean): (A, B) = {
      var limA = as(ixRange.head)
      var limB = f(limA)

      for (i <- ixRange.tail) {
        val a = as(i)
        val b = f(a)
        if (cmp(b, limB)) {
          limA = a
          limB = b
        }
      }
      (limA, limB)
    }
  }

  implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N, K = ni()
    val S = nl()
    val L = N - 1
    val minK = (S - 1) / L + 1
    val maxK = S
    if (K < minK || K > maxK) {
      out.println("NO")
    } else {
      out.println("YES")
      var cur = 1
      var direction = 1
      var k = K
      var s = S

      val ans = ArrayBuffer[Int]()

      def move(dist: Int): Unit = {
        val to = cur + direction * dist
        ans += to
        cur = to
        if (to == 1) direction = 1
        else if (to == N) direction = -1
        k -= 1
        s -= dist
      }

      while(s - k >= L) {
        move(L)
      }

      REP(k - 1) { _ => move(1) }
      move(s.toInt)

      out.println(ans.mkString(" "))
    }
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int): Array[Int] = map(n)(_ => ni())
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Int](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N, K = ni()
    val S = nl()
    val L = N - 1
    val minK = (S - 1) / L + 1
    val maxK = S
    if (K < minK || K > maxK) {
      out.println("NO")
    } else {
      out.println("YES")
      var cur = 1
      var direction = 1

      val ans = ArrayBuffer[Int]()

      def move(dist: Int): Unit = {
        val to = cur + direction * dist
        ans += to
        cur = to
        if (to == 1) direction = 1
        else if (to == N) direction = -1
      }

      REP(((S - K) / (L - 1)).toInt) { _ => move(L) }
      val r = (S - K) % (L - 1)
      if (r > 0) move((r + 1).toInt)
      REP((K - minK).toInt) { _ => move(1) }

      out.println(ans.mkString(" "))
    }
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Int](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

object Main {
  import java.io._

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import scala.collection.mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N = sc.nextInt()
    val N1 = N - 1
    val K, S = sc.nextLong()
    val ok = K <= S && S <= (N - 1) * K
    if (!ok) out.println("NO")
    else {
      val m = N - 2
      val (a, b, r) = if ((S - K) % m == 0) {
        (((S - K) / m).toInt, 0, 0)
      } else {
        val r = (S - K + 1) % m
        val a = (S - K + 1) / m
        val b = K - a - (if (r == 0) 0 else 1)
        (a.toInt, b.toInt, r.toInt)
      }

      var pos = 1
      val moves = ArrayBuffer[Int]()
      rep(a) { _ =>
        pos = pos match {
          case 1 => N
          case N => 1
        }
        moves += pos
      }
      rep(b) { _ =>
        pos = pos match {
          case 1 => 2
          case 2 => 1
          case N => N1
          case N1 => N
        }
        moves += pos
      }

      if (r > 0) {
        pos = pos match {
          case 1 => r + 1
          case 2 => r + 2
          case N => N - r
          case N1 => N1 - r
        }
        moves += pos
      }

      println("YES")
      println(moves.mkString(" "))
    }
  }

  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }

  class InputReader(val stream: InputStream) {

    import java.util.StringTokenizer

    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    // todo Orderingだとboxing発生するので自作Orderを用意したい
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      rep(as.length)(i => map.getOrElseUpdate(f(as(i)), ArrayBuffer()) += as(i))
      map
    }

    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      var sum = num.zero
      rep(as.length)(i => sum = num.plus(sum, f(as(i))))
      sum
    }

    def minByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.lt)
    }

    def maxByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.gt)
    }

    private def limit[B](f: A => B, ixRange: Range)(cmp: (B, B) => Boolean): (A, B) = {
      var limA = as(ixRange.head)
      var limB = f(limA)

      for (i <- ixRange.tail) {
        val a = as(i)
        val b = f(a)
        if (cmp(b, limB)) {
          limA = a
          limB = b
        }
      }
      (limA, limB)
    }
  }

  implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }
  }
}

object Main {
  import java.io._

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import scala.collection.mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N, K, S = sc.nextLong()
    val ok = K <= S && S <= (N - 1) * K
    if (!ok) out.println("NO")
    else {
      val m = N - 2
      val (a, b, r) = if ((S - K) % m == 0) {
        (((S - K) / m).toInt, 0, 0)
      } else {
        val r = (S - K + 1) % m
        val a = (S - K + 1) / m
        val b = K - a - (if (r == 0) 0 else 1)
        (a.toInt, b.toInt, r.toInt)
      }

      val moves = ArrayBuffer[Int]()
      rep(a.toInt / 2) { _ =>
        moves += N.toInt
        moves += 1
      }
      if (a % 2 == 0) {
        rep(b.toInt / 2) { _ =>
          moves += 2
          moves += 1
        }
        if (b % 2 == 0) {
          moves += r.toInt + 1
        } else {
          moves += 2
          moves += r.toInt + 2
        }
      } else {
        moves += N.toInt
        rep(b.toInt / 2) { _ =>
          moves += N.toInt
          moves += N.toInt - 1
        }
        if (b % 2 == 0) {
          moves += (N - r).toInt
        } else {
          moves += N.toInt - 1
          moves += (N - r - 1).toInt
        }
      }

      println("YES")
      println(moves.mkString(" "))
    }
  }

  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }

  class InputReader(val stream: InputStream) {

    import java.util.StringTokenizer

    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    // todo Orderingだとboxing発生するので自作Orderを用意したい
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      rep(as.length)(i => map.getOrElseUpdate(f(as(i)), ArrayBuffer()) += as(i))
      map
    }

    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      var sum = num.zero
      rep(as.length)(i => sum = num.plus(sum, f(as(i))))
      sum
    }

    def minByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.lt)
    }

    def maxByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.gt)
    }

    private def limit[B](f: A => B, ixRange: Range)(cmp: (B, B) => Boolean): (A, B) = {
      var limA = as(ixRange.head)
      var limB = f(limA)

      for (i <- ixRange.tail) {
        val a = as(i)
        val b = f(a)
        if (cmp(b, limB)) {
          limA = a
          limB = b
        }
      }
      (limA, limB)
    }
  }

  implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }
  }
}

import java.util

object CF501D extends App {

  import java.io.PrintWriter
  import java.util.Scanner

  val in = new Scanner(System.in)
  val out = new PrintWriter(System.out)

  def solve = {
    val n = in.nextInt
    val k = in.nextInt
    val s = in.nextLong

    if (s > (n-1)*k || s < k) {
      out.println("NO")
    } else {
      val moves = new util.LinkedList[Long]()

      var distByMove = s/k
      var remainder = s%k

      var currentPos: Long = 1
      for (i <- 0 until k) {
        if (currentPos == 1) {
          currentPos = 1 + distByMove
          // add 1 in the "remainder" last steps
          // or 1 step before if k is even xor remainder is even
          if (k-i <= remainder || (remainder != 0 && k-i <= remainder + 1 && (k%2 == 0 ^ remainder%2 == 0))) currentPos += 1
        } else {
          if (remainder != 0 && i == k-1 && (k%2 == 0 ^ remainder%2 == 0))
            currentPos = 2
          else
            currentPos = 1
        }
        moves.add(currentPos)
      }

      out.println("YES")
      out.println(moves.toArray.mkString(" "))
    }
  }

  solve
  out.flush
  out.close
}

import java.util

object CF501D extends App {

  import java.io.PrintWriter
  import java.util.Scanner

  val in = new Scanner(System.in)
  val out = new PrintWriter(System.out)

  def solve = {
    val n = in.nextInt
    val k = in.nextInt
    val s = in.nextLong

    if (s > (n.toLong-1)*k.toLong || s < k) {
      out.println("NO")
    } else {
      val moves = new util.LinkedList[Long]()

      var distByMove = s/k
      var remainder = s%k

      var currentPos: Long = 1
      for (i <- 0 until k) {
        if (currentPos == 1) {
          currentPos = 1 + distByMove
          // add 1 in the "remainder" last steps
          // or 1 step before if k is even xor remainder is even
          if (k-i <= remainder || (remainder != 0 && k-i <= remainder + 1 && (k%2 == 0 ^ remainder%2 == 0))) currentPos += 1
        } else {
          if (remainder != 0 && i == k-1 && (k%2 == 0 ^ remainder%2 == 0))
            currentPos = 2
          else
            currentPos = 1
        }
        moves.add(currentPos)
      }

      out.println("YES")
      out.println(moves.toArray.mkString(" "))
    }
  }

  solve
  out.flush
  out.close
}