eolymp
bolt
Try our new interface for solving problems
Problems

LinkedList Simulate Sum of Odd Elements

LinkedList Simulate Sum of Odd Elements

An empty Linked List is given initially. Simulate the next operations:

  • push front x: add element x to the front of a Linked List;
  • push back x: add element x to the back of a Linked List;
  • pop front: remove element from the front of a Linked List;
  • pop back: remove element from the back of a Linked List;

Let L = (a1, a2, ...., an) be the resulting Linked List. Find the sum of all its odd elements.

Input

Each line contains one of the operations described above. It is known that x is a nonnegative integer, no more than 1000. Final Linked List (after simulation) contains no more than 1000 elements.

Output

Print the sum of all odd elements of the resulting Linked List.

Example

After simulation the list will have the next form:

prb10467.gif

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

Time limit 1 second
Memory limit 128 MiB
Input example #1
push back 7
push back 5
pop front
push front 2
push back 1
Output example #1
6
Author Michael Medvediev