Sequences without Stammers

No attempts yetTime limit3sMemory limit128 MB

Problem

We work with sequences of letters. A sequence x1,x2,,xnx_1, x_2, \dots, x_n contains a stammer if some block of consecutive letters is immediately followed by an identical block. Formally, there exist indices ii and jj with 1i<j1 \le i < j and 2ji1n2j - i - 1 \le n such that

xi=xj,  xi+1=xj+1,  ,  xj1=x2ji1.x_{i} = x_{j},\; x_{i+1} = x_{j+1},\; \dots,\; x_{j-1} = x_{2j-i-1}.

Equivalently, the sequence contains a square: a factor of the form wwww for some non-empty word ww. A sequence with no such repeated block is called stammer-free.

We want to build a stammer-free sequence of length nn using as few distinct letters as possible.

Some observations:

  • With a single letter, the only stammer-free sequences have length 11, because aaaa is already a stammer.
  • With two letters, say aa and bb, the longest stammer-free sequences have length 33: exactly abaaba and babbab. For example, bababbabab is not stammer-free (the block baba and the block abab each repeat).
  • With three letters, a stammer-free sequence exists for every length; for instance abcababcab is a stammer-free sequence of length 55.

Determine the minimal number of different letters needed.

Input

The first line of standard input contains one positive integer nn (1n10,000,0001 \le n \le 10{,}000{,}000) — the desired length of the sequence.

Output

Print a single positive integer kk: the minimal number of distinct letters that must appear in any stammer-free sequence of length nn.