#K42857. FlexiFibonacci Sequence

    ID: 27180 Type: Default 1000ms 256MiB

FlexiFibonacci Sequence

FlexiFibonacci Sequence

In this problem, you are given two starting integers a and b, an integer k (which represents the number of previous terms to sum), and an integer n that specifies the length of the sequence to generate. The sequence, called the FlexiFibonacci sequence, is defined as follows:

\(a_0 = a, \quad a_1 = b,\)

and for each \(i\ge2\),

\(a_i = \sum_{j=\max(0, i-k)}^{i-1} a_j\).

Your task is to compute and print the first n elements of this sequence, with the elements separated by spaces.

inputFormat

The input consists of a single line with four space-separated integers:

  • a: the first term of the sequence.
  • b: the second term of the sequence.
  • k: the number of previous terms to sum to obtain the next term.
  • n: the total number of terms in the sequence to generate.

You may assume that n is at least 1.

outputFormat

Output the FlexiFibonacci sequence of length n as space-separated integers in a single line.

## sample
0 1 2 6
0 1 1 2 3 5