#K36137. Generate N-grams

    ID: 25688 Type: Default 1000ms 256MiB

Generate N-grams

Generate N-grams

Given a string \( S \) consisting of lowercase English letters and an integer \( n \), generate all contiguous substrings of length \( n \) (also known as n-grams) from \( S \). For each index \( i \) such that \( 0 \leq i \leq |S|-n \), the substring \( S[i:i+n] \) forms an n-gram.

In mathematical terms, the task is to compute:

\[ \{ S[i:i+n] : 0 \leq i \leq |S|-n \}\]

The input is provided from standard input and the output should be printed to standard output with each n-gram on a separate line.

inputFormat

The input consists of two lines:

  • The first line contains the string \( S \) composed of lowercase English letters.
  • The second line contains an integer \( n \) where \( 1 \leq n \leq |S| \).

outputFormat

Print each n-gram on a new line in the order they appear in \( S \).

## sample
hello
2
he

el ll lo

</p>