PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#PS0000183. Dãy ký tự X liên tiếp dài nhất (Longest X)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Dãy ký tự X liên tiếp dài nhất (Longest X)

Longest X

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

A string SS consists of X and .. One operation changes a dot into X. You may perform any number of operations from zero to KK. Find the greatest possible length of a consecutive run of X after the changes, or zero if no X can be obtained.

Input

The first line contains SS. The second contains integer KK.

Output

Print the maximum possible length.

Subtasks

  • Subtask 1 (20 points): 1≤∣S∣≤5001\le |S|\le 500; 0≤K≤2000000\le K\le200000; the string contains only X and ..
  • Subtask 2 (30 points): 1≤∣S∣≤2000001\le |S|\le 200000; 0≤K≤2000000\le K\le200000; the string contains only X and .; K=0K=0.
  • Subtask 3 (50 points): 1≤∣S∣≤2000001\le |S|\le 200000; 0≤K≤2000000\le K\le200000; the string contains only X and ..

Example 1

Input

XX...X.X.X.
2

Output

5

Explanation

Change the dots at positions 7 and 9 (1-based), obtaining a run from 6 through 10. Each length-six window contains at least three dots.

Example 2

Input

XXXX
200000

Output

4

Explanation

All four characters are already X; no change is needed.