import java.io.*
import java.util.*

class InputReader(val stream: InputStream) {
    val buf = ByteArray(1024)
    var curChar: Int = 0
    var numChars: Int = 0

    fun read(): Char {
        if (numChars == -1)
            throw InputMismatchException()
        if (curChar >= numChars) {
            curChar = 0
            try {
                numChars = stream.read(buf)
            } catch (e: IOException) {
                throw InputMismatchException()
            }
            if (numChars <= 0)
                return '\uFFFF'
        }
        return buf[curChar++].toChar()
    }

    fun nextInt(): Int {
        var c = read()
        while (isSpaceChar(c))
            c = read()
        var sgn = 1
        if (c == '-') {
            sgn = -1
            c = read()
        }
        var res = 0
        do {
            if (c < '0' || c > '9')
                throw InputMismatchException()
            res *= 10
            res += c.toInt() and 15
            c = read()
        } while (!isSpaceChar(c))
        return res * sgn
    }

    fun nextLong(): Long {
        var c = read()
        while (isSpaceChar(c))
            c = read()
        var sgn = 1
        if (c == '-') {
            sgn = -1
            c = read()
        }
        var res = 0L
        do {
            if (c < '0' || c > '9')
                throw InputMismatchException()
            res *= 10
            res += c.toInt() and 15
            c = read()
        } while (!isSpaceChar(c))
        return res * sgn
    }

    fun nextString(): String {
        var c = read()
        while (isSpaceChar(c))
            c = read()
        val res = StringBuilder()
        do {
            res.append(c)
            c = read()
        } while (!isSpaceChar(c))
        return res.toString()
    }

    fun isSpaceChar(c: Char): Boolean {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == '\uFFFF'
    }
}

class OutputWriter(val stream: OutputStream) {
    val buf = ByteArray(65536)
    var curPos: Int = 0

    fun write(c: Char) {
        if (buf.size - curPos < 1) flush()
        buf[curPos++] = c.toByte()
    }

    fun write(s: String) {
        if (buf.size - curPos < s.length) flush()
        var idx = 0
        if (s.length > buf.size) {
            var remaining = s.length
            while (remaining > buf.size) {
                while (curPos < buf.size) buf[curPos++] = s[idx++].toByte()
                flush()
                remaining -= buf.size
            }
        }
        while (idx < s.length) buf[curPos++] = s[idx++].toByte()
    }

    fun flush() {
        stream.write(buf, 0, curPos)
        curPos = 0
    }
}

inline fun <T> ArrayList<T>.swap(ia: Int, ib: Int) {
    val tmp = this[ia]
    this[ia] = this[ib]
    this[ib] = tmp
}

inline fun ArrayList<Char>.toStr(): String {
    val builder = StringBuilder(this.size)
    for (c in this) {
        builder.append(c)
    }
    return builder.toString()
}

fun main(args: Array<String>) {
    if (args.isNotEmpty()) System.setIn(FileInputStream(args[0]))
    val ir = InputReader(System.`in`)
    val ow = OutputWriter(System.out)

    val lst = mutableListOf<Long>()
    for (i in 2 .. 10 step 2) {
        val ca = ArrayList<Char>()
        for (j in 1 .. i / 2) {
            ca.add('4')
        }
        for (j in 1 .. i / 2) {
            ca.add('7')
        }
        while (true) {
            lst.add(ca.toStr().toLong())
            var swapped = false
            for (j in ca.size - 2 downTo 0) {
                if (ca[j] == '4' && ca[j + 1] == '7') {
                    ca.swap(j, j + 1)
                    swapped = true
                    ca.subList(j + 1, ca.size).sort()
                    break
                }
            }
            if (!swapped) break
        }
    }

    val n = ir.nextInt()
    var lo = 0; var hi = lst.lastIndex
    while (lo <= hi) {
        val mid = (lo + hi) ushr 1
        if (n <= lst[mid]) hi = mid - 1  // <= to < for lower-bound to upper-bound
        else lo = mid + 1
    }
    val answer = lo

    ow.write("${lst[answer]}\n")
    ow.flush()
}


import java.io.*
import kotlin.concurrent.thread
import java.io.IOException
import java.io.BufferedReader
import java.io.InputStream
import kotlin.*
import java.*
import java.io.OutputStream
import java.io.PrintWriter
import java.lang.ArithmeticException
import java.lang.Exception
import java.math.BigInteger
import java.security.cert.TrustAnchor
import java.util.*
import kotlin.collections.ArrayList
import kotlin.system.exitProcess

fun main() {
    val inputStream = System.`in`
    val outputStream = System.out
    val `in` = InputReader(inputStream)
    val out = PrintWriter(outputStream)

    val n = `in`.nextLong()+2
    var t = `in`.nextLong()

    if (t and t - 1 > 0) {
        out.println(0)
    } else {
        var kol = 1
        var ans=0L
        if (t==1L)
            --ans
        while (t % 2 == 0L) {
            ++kol
            t /= 2
        }

        fun C(b:Int,m:Int):Long {
            if (b<m)
                return 0
            if (m<0)
                return 0
            var x = BigInteger.ONE
            for (i in 1..b)
                x=x.multiply(BigInteger(i.toString()))
            for (i in 1..m)
                x=x.divide(BigInteger(i.toString()))
            for (i in 1..b-m)
                x=x.divide(BigInteger(i.toString()))
            return x.toLong()
        }

        for (i in 60 downTo 0)
        {
            if ((1L shl i).and(n)>0) {
                ans += C(i, kol)
                --kol
            }
        }

        out.println(ans)
    }

    out.close()

}

internal class InputReader(stream: InputStream) {
    var reader: BufferedReader
    var tokenizer: StringTokenizer? = null

    init {
        reader = BufferedReader(InputStreamReader(stream), 32768)
        tokenizer = null
    }

    operator fun next(): String {
        while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
            try {
                tokenizer = StringTokenizer(reader.readLine())
            } catch (e: IOException) {
                throw RuntimeException(e)
            }

        }
        return tokenizer!!.nextToken()
    }

    fun nextInt(): Int {
        return Integer.parseInt(next())
    }

    fun nextLong(): Long {
        return next().toLong()
    }

}


import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

val MOD = 1_000_000_007L

class Solver(stream: InputStream, private val out: java.io.PrintWriter) {
  fun solve() {
    val N = ni()
    val A = ni() - 1
    val B = ni() - 1
    val K = ni()
    val dp = Array(K + 1){LongArray(N + 10)}
    dp[0][A] = 1
    for (i in 1 .. K) {
      for (j in 0 until N) {
        val d = abs(B - j) - 1
        val t = min(N - 1, j + d)
        val b = max(0, j - d)
        val v = dp[i - 1][j]
        dp[i][b] = (dp[i][b] + v) % MOD
        dp[i][j] = (MOD + dp[i][j] - v) % MOD
        if (j + 1 <= t + 1) {
          dp[i][j + 1] = (dp[i][j + 1] + v) % MOD
          dp[i][t + 1] = (MOD + dp[i][t + 1] - v) % MOD
        }
      }
      for (j in 1 until N) {
        dp[i][j] = (dp[i][j] + dp[i][j - 1]) % MOD
      }
      debug(dp[i])
    }
    out.println(dp[K].take(N).sum() % MOD)
  }

  private val isDebug = try {
    // なんか本番でエラーでる
    System.getenv("MY_DEBUG") != null
  } catch (t: Throwable) {
    false
  }

  private var tokenizer: StringTokenizer? = null
  private val reader = BufferedReader(InputStreamReader(stream), 32768)
  private fun next(): String {
    while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
      tokenizer = StringTokenizer(reader.readLine())
    }
    return tokenizer!!.nextToken()
  }

  private fun ni() = next().toInt()
  private fun nl() = next().toLong()
  private fun ns() = next()
  private fun na(n: Int, offset: Int = 0): IntArray {
    return map(n) { ni() + offset }
  }
  private fun nal(n: Int, offset: Int = 0): LongArray {
    val res = LongArray(n)
    for (i in 0 until n) {
      res[i] = nl() + offset
    }
    return res
  }

  private fun na2(n: Int, offset: Int = 0): Array<IntArray> {
    val a  = Array(2){IntArray(n)}
    for (i in 0 until n) {
      for (e in a) {
        e[i] = ni() + offset
      }
    }
    return a
  }

  private inline fun map(n: Int, f: (Int) -> Int): IntArray {
    val res = IntArray(n)
    for (i in 0 until n) {
      res[i] = f(i)
    }
    return res
  }

  private inline fun debug(msg: () -> String) {
    if (isDebug) System.err.println(msg())
  }

  private fun debug(a: LongArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: IntArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: BooleanArray) {
    debug { a.map { if (it) 1 else 0 }.joinToString("") }
  }

  private fun debugDim(A: Array<IntArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }

  /**
   * 勝手にimport消されるのを防ぎたい
   */
  private fun hoge() {
    min(1, 2)
    max(1, 2)
    abs(-10)
  }
}

fun main() {
  val out = java.io.PrintWriter(System.out)
  Solver(System.`in`, out).solve()
  out.flush()
}