Problem:
Score : 300 points

Problem Statement

There is a staircase with N steps. Takahashi is now standing at the foot of the stairs, that is, on the 0-th step.
He can climb up one or two steps at a time.

However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are broken, so it is dangerous to set foot on those steps.

How many are there to climb up to the top step, that is, the N-th step, without setting foot on the broken steps?
Find the count modulo 1\ 000\ 000\ 007.

Constraints

1 \leq N \leq 10^5

0 \leq M \leq N-1

1 \leq a_1 < a_2 < ... < a_M \leq N-1

Input

Input is given from Standard Input in the following format:

N M
a_1
a_2
.
.
.
a_M

Output

Print the number of ways to climb up the stairs under the condition, modulo 1\ 000\ 000\ 007.

Sample Input 1

6 1
3

Sample Output 1

4

There are four ways to climb up the stairs, as follows:

0 \to 1 \to 2 \to 4 \to 5 \to 6

0 \to 1 \to 2 \to 4 \to 6

0 \to 2 \to 4 \to 5 \to 6

0 \to 2 \to 4 \to 6

Sample Input 2

10 2
4
5

Sample Output 2

0

There may be no way to climb up the stairs without setting foot on the broken steps.

Sample Input 3

100 5
1
23
45
67
89

Sample Output 3

608200469

Be sure to print the count modulo 1\ 000\ 000\ 007.

Solution in Kotlin (1.0.0) (judge verdict: Time Limit Exceeded)

import java.lang.Math.*
import kotlin.comparisons.compareByDescending

const val MOD = 1000000007L
const val INF = 1000000007L

fun main(args: Array<String>) {
    val (n, m) = readIntList()

    val a = Array(n + 1) {
        return@Array true
    }
    m.rep {
        val t = readInt()
        a[t] = false
    }

    val memo = Array(n + 1) {
        return@Array 0L
    }

    fun dfs(now: Int): Long {
        if (now == n) {
            return 1
        }
        
        if (memo[now] > 0L) {
            return memo[now]
        }

        var ret = 0L
        if (now + 1 < n + 1 && a[now + 1]) {
            ret += dfs(now + 1)
        }
        if (now + 2 < n + 1 && a[now + 2]) {
            ret += dfs(now + 2)
        }
        memo[now] = ret % MOD
        return memo[now]
    }

    println(dfs(0))

}

fun readList() = readLine()!!.split(' ')
fun readInt() = readLine()!!.split(' ').map(String::toInt).first()
fun readIntList() = readList().map(String::toInt)
fun readLongList() = readList().map(String::toLong)
fun readDoubleList() = readList().map(String::toDouble)

fun readPair(): Pair<String, String> {
    val splite = readLine()!!.split(' ')
    return Pair(splite[0], splite[1])
}

fun <T> List<T>.copy() = this.map { it }

inline fun <reified T> dualArray(h: Int, w: Int, init: (Int, Int) -> T) {
    Array(h) { i ->
        return@Array Array(w) { j ->
            return@Array init(i, j)
        }
    }
}

// 速度のためforEachは避ける
inline fun Int.rep(start: Int = 0, shiftLast: Boolean = false, body: (Int) -> Unit) {
    for (i in start until if (shiftLast) this + start else this) {
        body(i)
    }
}

inline fun Long.rep(start: Long = 0, shiftLast: Boolean = false, body: (Long) -> Unit) {
    for (i in start until if (shiftLast) this + start else this) {
        body(i)
    }
}

// 約数のList
fun divisor(value: Long): List<Long> {
    val max = sqrt(value.toDouble()).toLong()
    val former = mutableListOf<Long>()
    val latter = mutableListOf<Long>()
    (1..max).filter { value % it == 0L }
        .forEach {
            former.add(it)
            latter.add(value / it)
        }
    former.addAll(latter.reversed())
    return former
}

// 範囲内の素数を取得
// fromだけ指定すると戻り値の個数で素数判定ができる
fun prime(from: Long, to: Long = from): List<Long> {
    return (from..to).filter { i ->
        val max = Math.sqrt(i.toDouble()).toLong()
        (2..max).all { j -> i % j != 0L }
    }
}

// 素因数分解
fun decom(value: Long): List<Long> {
    if (value == 1L) return listOf(1)
    val max = Math.sqrt(value.toDouble()).toLong()
    return prime(2, max).filter { value % it == 0L }
}

// 最大公約数
fun gcd(a: Long, b: Long): Long {
    return if (a % b == 0L) b else gcd(b, a % b)
}

// 文字列を入れ替え
fun swap(base: String, a: String, b: String): String {
    return base.map {
        when (it) {
            a.toCharArray()[0] -> b
            b.toCharArray()[0] -> a
            else -> it.toString()
        }
    }.joinToString()
}

// 二分探索
fun List<Long>.binarySearch(target: Long, _start: Int = 0, _end: Int = this.size): Int {
    var start = (_start - 1).toLong()
    var end = _end.toLong()
    while (end - start > 1) {
        val mid = (start + end) / 2
        if (this[mid.toInt()] < target) {
            start = mid
        } else {
            end = mid
        }
    }
    return end.toInt()
}

// bit全探索
inline fun Int.bitAllSearch(body: (Array<Int>) -> Unit) {
    for (bit in 0 until (1 shl this)) {
        val s = mutableListOf<Int>()
        for (i in 0 until this) {
            if ((bit and (1 shl i)) shr i == 1) { // i が bit に入るかどうか
                s.add(i)
            }
        }
        body(s.toTypedArray())
    }
}