#K77017. Custom Sequence Generator
Custom Sequence Generator
Custom Sequence Generator
You are given an initial sequence (signature) and a transformation type. Your task is to compute the final value after performing a number of iterations. At each iteration, apply a function f to the last element of the sequence to produce a new value. The function is selected according to a given type:
- inc: f(x) = x + 1
- mul: f(x) = x * 2
- add: f(x) = x + 5
If an invalid type is provided, default to inc (i.e. f(x) = x + 1). Note that if the number of iterations is zero or negative, the sequence remains unchanged and the output is the last element of the signature. In addition, if the signature is empty, the program should raise an error or exit abnormally.
For example, if the signature is [1] and the function type is inc with 5 iterations, the sequence evolves as: 1 -> 2 -> 3 -> 4 -> 5 -> 6. Hence, the output is 6.
inputFormat
The input is read from stdin and consists of four lines:
- An integer n which represents the number of elements in the signature. (n > 0)
- n space-separated integers representing the signature.
- An integer representing the number of iterations.
- A string representing the transformation function type. It can be one of: "inc", "mul", or "add".
outputFormat
The output should be written to stdout as a single integer: the final value of the sequence after applying the transformation function the specified number of times.
## sample1
1
5
inc
6