Under construction

Still being built. Things may change

Naming the Computer

Time limit2sMemory limit512 MB

Summary
Given a string S and integer K, find the shortest string that contains S as a substring at least K times, and output its length.
Level

Hard8 of 10

Topics
String matching, Dynamic programming, String, Greedy
Solved
No attempts yet

Problem

Ukje is naming the computer he just bought.

The name of the new computer must contain SS, Ukje's favorite string, as a substring at least KK times. If several names are possible, the name must have the shortest length.

Given SS and KK, find the length of the name of Ukje's new computer.

Input

The first line gives SS and KK. SS consists only of lowercase English letters and has length at most 500,000. KK is a positive integer at most 1,000,000.

Output

Print the length of the name of Ukje's new computer on the first line.

Examples5

  1. Example 1

    Input
    ada 3
    
    Expected output
    7
    
  2. Example 2

    Input
    abc 2
    
    Expected output
    6
    
  3. Example 3

    Input
    r 7
    
    Expected output
    7
    
  4. Example 4

    Input
    rr 5
    
    Expected output
    6
    
  5. Example 5

    Input
    abbababbbbababababba 2
    
    Expected output
    36