This page is still under construction.

Parts of this page are still being built. What you see may change.

Protocols

Interview

Time limit3sMemory limit128 MB

Summary
Count the length-m strings over k symbols with no run of l equal symbols, then output floor((n/m) * log2(count)).
Level

Medium5 of 10

Topics
Dynamic programming, Combinatorics, Math, Implementation
Solved
No attempts yet

Problem

A telecommunications company is designing a protocol to send data between two computers over a new cable. The cable can carry signals at kk different voltage levels, but the voltage may change only every 1/n1/n of a second. Such a 1/n1/n-second interval, during which the voltage stays constant, is called an impulse.

Data are sent in packets of mm consecutive impulses, so transmitting one packet takes m/nm/n seconds.

For technical reasons the voltage may not stay constant for too long inside a packet: a packet may not contain ll consecutive impulses at the same voltage level.

If a protocol can send xx different packets, then each packet carries log⁡2x\log_2 x bits of information. The task is to find how many bits of information can be sent in one second.

For example, suppose the cable offers 22 voltage levels (k=2k = 2), written 00 and 11. Let the voltage change 2020 times per second (n=20n = 20), let each packet contain 44 impulses (m=4m = 4), and let no 33 consecutive impulses share the same level (l=3l = 3). Then the packets 00000000, 00010001, 10001000, 11111111, 11101110 and 01110111 cannot be sent, while 00100010, 00110011, 01000100, 01100110, 01010101, 11011101, 11001100, 10111011, 10011001 and 10101010 can. Since 1010 different packets are available, each packet carries log⁡210\log_2 10 bits. In one second 20/4=520/4 = 5 packets are sent, giving 5⋅log⁡210≈16.60965 \cdot \log_2 10 \approx 16.6096 bits of information.

Write a program that reads the integers kk, nn, mm and ll describing the protocol, computes the maximum number of bits of information that can be sent in one second, and prints that number rounded down to the nearest integer.

Input

The first line contains four integers separated by single spaces:

  • the number of voltage levels kk (2≤k≤102 \le k \le 10),
  • the impulse frequency nn (1≤n≤10001 \le n \le 1000),
  • the packet size mm (1≤m≤1001 \le m \le 100),
  • the forbidden run length ll (2≤l≤m2 \le l \le m): a packet may not contain ll consecutive impulses at the same voltage level.

It is guaranteed that n/mn/m is an integer not greater than 1010.

Output

Print a single integer: the maximum number of bits of information that can be sent in one second, rounded down to the nearest integer.

Examples1

  1. Example 1

    Input
    2 20 4 3
    
    Expected output
    16