This page is still under construction.

Parts of this page are still being built. What you see may change.

A Really Odd Sequence

Interview

Time limit6sMemory limit512 MB

Summary
Given a sequence of integers, find the maximum sum of a contiguous subarray whose length is odd.
Level

Medium5 of 10

Topics
Array, Dynamic programming, Prefix sum, Greedy
Solved
No attempts yet

Problem

Following our long-established tradition, the best statements are those kept short.

Given a sequence of integers, find the largest sum of a consecutive subsequence of odd length.

Input

The first line of input contains the number of test cases zz. The descriptions of the test cases follow.

The first line of each test case contains the length of the sequence nn (1≤n≤1 000 0001 \leq n \leq 1\,000\,000).

The next line contains nn integers a_1,a_2,…,a_na\_1, a\_2, \ldots, a\_n (−109≤a_i≤109-10^9 \leq a\_i \leq 10^9), the elements of the sequence.

The total length of all sequences in all test cases does not exceed 5 000 0005\,000\,000.

Output

For each test case, output the largest sum on a separate line.

Examples1

  1. Example 1

    Input
    1
    4
    8 -7 9 1
    
    Expected output
    10