Problem:
Score : 200 points

Problem Statement

Print all the integers that satisfies the following in ascending order:

Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.

Constraints

1 \leq A \leq B \leq 10^9

1 \leq K \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B K

Output

Print all the integers that satisfies the condition above in ascending order.

Sample Input 1

3 8 2

Sample Output 1

3
4
7
8

3 is the first smallest integer among the integers between 3 and 8.

4 is the second smallest integer among the integers between 3 and 8.

7 is the second largest integer among the integers between 3 and 8.

8 is the first largest integer among the integers between 3 and 8.

Sample Input 2

4 8 3

Sample Output 2

4
5
6
7
8

Sample Input 3

2 9 100

Sample Output 3

2
3
4
5
6
7
8
9

Solution in Scala (2.11.7) (judge verdict: Accepted)

import scala.collection.generic.CanBuild
import scala.io.StdIn
import scala.language.higherKinds

// TODO: write well formed Docs!

case class StdInScanner[A](scan: StdIn.type => A) {
  // transform read result by "f"
  def map[B](f: A => B): StdInScanner[B] =
    StdInScanner(in => f(scan(in)))

  // run this to read A, then obtain new scanner from A using "f", then run the new scanner
  def flatMap[B](f: A => StdInScanner[B]): StdInScanner[B] =
    StdInScanner(in => f(scan(in)).scan(in))

  // run entire scanner and get result
  def run: A = scan(StdIn)
}

object StdInScanner {
  // read nothing, and return specified "a"
  def apply[A](a: A): StdInScanner[A] = StdInScanner(_ => a)
  // read nothing, and return ()
  def unit: StdInScanner[Unit] = StdInScanner(())

  // read a line
  def readLine: StdInScanner[String] = StdInScanner(s => s.readLine().trim)
  // read a line as Int
  def readLnInt: StdInScanner[Int] = StdInScanner(s => s.readInt())
  // read a line as BigInt
  def readLnBigInt: StdInScanner[BigInt] = readLine.map(BigInt(_))

  // read tokens (separated by "sep") from a line, and store them in an array
  def readTokens(sep: String): StdInScanner[Array[String]] =
    readLine.map(_.split(sep).map(_.trim))
  // read tokens (separated by "sep") from a line, and store them in a collection (type "C")
  def readTokensTo[C[_]](sep: String)(implicit cb: CanBuild[String, C[String]]): StdInScanner[C[String]] =
    readTokens(sep).map(_.to[C])


  // read "n" lines, and store them in an array
  def readLines(n: Int): StdInScanner[Array[String]] =
    StdInScanner(s => Array.fill(n)(s.readLine().trim))
  // read "n" lines, and store them in a collection "C"
  def readLinesTo[C[_]](n: Int)(implicit cb: CanBuild[String, C[String]]): StdInScanner[C[String]] =
    readLines(n).map(_.to[C])

  // read "n" ints from lines. and store them in an array
  def readInts(n: Int): StdInScanner[Array[Int]] =
    StdInScanner(s => Array.fill(n)(s.readInt()))
  // read "n" ints from lines. and store them in a collection "C"
  def readIntsTo[C[_]](n: Int)(implicit cb: CanBuild[Int, C[Int]]): StdInScanner[C[Int]] =
    readInts(n).map(_.to[C])

  // read a table of "n" rows
  def readTable(rows: Int, sep: String = " "): StdInScanner[Array[Array[String]]] =
    readLines(rows).map{ lns =>
      lns.map(ln => ln.split(sep).map(tkn => tkn.trim))
    }

  // read a 2D int matrix of "n" rows, stored in an array of arrays
  def readIntMatrix(rows: Int, sep: String = " "): StdInScanner[Array[Array[Int]]] =
    readLines(rows).map{ lns =>
      lns.map(ln => ln.split(sep).map(tkn => tkn.toInt))
    }

  // read a 2D int matrix of "n" rows, stored in a collection of collections ("C[C[Int]")
  def readIntMatrixTo[C[_]](rows: Int, sep: String = " ")(implicit cb1: CanBuild[Int, C[Int]] ,cb2: CanBuild[C[Int], C[C[Int]]]): StdInScanner[C[C[Int]]] =
    readIntMatrix(rows, sep).map { mat =>
      mat.map(row => row.to[C]).to[C]
    }
}

object Main {

  import StdInScanner._

  def main(args: Array[String]) = {
    def abk = readTokens(" ").map(_.map(_.toInt)).run
    val Array(a, b, k) = abk
    val s = scala.collection.mutable.TreeSet.empty[Int]
    for (i <- 0 until k) {
      if(a + i <= b) {
        s += (a + i)
      }
      if(b - i >= a) {
        s += (b - i)
      }
    }

    s.foreach(println)
  }
}