Problem:
Score : 100 points

Problem Statement

There are N students in a school.

We will divide these students into some groups, and in each group they will discuss some themes.

You think that groups consisting of two or less students cannot have an effective discussion, so you want to have as many groups consisting of three or more students as possible.

Divide the students so that the number of groups consisting of three or more students is maximized.

Constraints

1 \leq N \leq 1000

All input values are integers.

Input

Input is given from Standard Input in the following format:

N

Output

If you can form at most x groups consisting of three or more students, print x.

Sample Input 1

8

Sample Output 1

2

For example, you can form a group of three students and another of five students.

Sample Input 2

2

Sample Output 2

0

Sometimes you cannot form any group consisting of three or more students, regardless of how you divide the students.

Sample Input 3

9

Sample Output 3

3

Solution in Kotlin (1.0.0) (judge verdict: Runtime Error)

operator fun Pair<Int, Int>.plus(pair: Pair<Int, Int>) = Pair(first + pair.first, second + pair.second)
operator fun Pair<Int, Int>.minus(pair: Pair<Int, Int>) = Pair(first - pair.first, second - pair.second)
fun Pair<Int, Int>.manhattanTo(pair: Pair<Int, Int>) = (this - pair).manhattanLength()
fun Pair<Int, Int>.manhattanLength() = Math.abs(first) + Math.abs(second)

private fun readStrings() = readLine()!!.split(" ")
private fun readInts() = readStrings().map { it.toInt() }

private fun List<IntRange>.zipWithIndices() =
        mapIndexed { first, range ->
            range.map { second -> Pair(first, second) }
        }.flatten()

fun main(args: Array<String>) {
    val (H, W, D) = readInts()
    val A = (0 until H).map { readInts() }

    val numberCache = {
        val result = mutableMapOf<Int, Pair<Int, Int>>()
        (0 until H).map { (0 until W) }.zipWithIndices().forEach { pair ->
            val (h, w) = pair
            result[A[h][w]] = Pair(h, w)
        }
        result
    }()

    val mpCache = {
        val result = mutableMapOf<Int, Int>()
        (1 until H * W + 1).forEach { index ->
            val prevIndex = index - D

            result[index] = result[prevIndex]?.let { previous ->
                val diff = numberCache[prevIndex]!!.manhattanTo(numberCache[index]!!)
                previous + diff
            } ?: 0
        }
        result
    }()

    val Q = readLine()!!.toInt()
    (0 until Q).forEach {
        val (L, R) = readInts()
        println(mpCache[R]!! - mpCache[L]!!)
    }
}