#C13358. Cumulative Sum and Palindrome Check

    ID: 42887 Type: Default 1000ms 256MiB

Cumulative Sum and Palindrome Check

Cumulative Sum and Palindrome Check

This problem requires you to implement two functionalities based on the provided operation. If the operation is sum, you are to compute the cumulative sum of a list of integers, where each element in the output is the sum of all previous elements (including the element itself). If the operation is palindrome, determine whether the given list of integers is a palindrome; that is, it reads the same forwards and backwards.

Note that an empty list should result in an empty cumulative sum and is considered a palindrome. The cumulative sum must be computed efficiently.

In mathematical terms, given a list \(a_1, a_2, \dots, a_n\), the cumulative sum produces a new list \(b_1, b_2, \dots, b_n\) where:

\(b_i = \sum_{j=1}^{i} a_j\) for \(1 \leq i \leq n\).

inputFormat

The first line of the input contains an integer T, representing the number of test cases. Each test case consists of two lines:

  1. The first line is a string which is either sum or palindrome, indicating the operation to perform.
  2. The second line contains a space-separated list of integers. This line may be empty, indicating an empty list.

outputFormat

For each test case, output a single line:

  • If the operation is sum, print the cumulative sum of the list with its elements space separated.
  • If the operation is palindrome, print True if the list is a palindrome or False otherwise.
## sample
5
sum
1 2 3 4 5
palindrome
1 2 3 2 1
sum
-1 2 -3 4 -5
palindrome
1 2 3 4 5
palindrome

1 3 6 10 15

True -1 1 -2 2 -3 False True

</p>