LinkedList Simulation: Sum at Odd Indices#10467

LinkedList Simulation: Sum at Odd Indices

1 second
128 megabytes
Easy

An empty linked list is given initially. Simulate the following operations:

  1. push front : add element to the front of the linked list;

  2. push back : add element to the back of the linked list;

  3. pop front: remove the element from the front of the linked list;

  4. pop back: remove the element from the back of the linked list.

Let L = (a_1, a_2, \ldots, a_n) be the resulting linked list. Find the sum of all odd elements.

Input

Each line contains one of the operations described above. It is known that is a nonnegative integer, no more than . The final linked list (after simulation) contains no more than elements.

Output

Print the sum of all elements at odd indices of the resulting linked list.

Examples

After simulation, the list will have the following form:

The sum of odd elements is 5 + 1 = 6.

Example 1

Loading
Loading