Under construction

Still being built. Things may change

Card Pairs

Time limit1sMemory limit1024 MB

Summary
Given counts of n card types, find the maximum number of trades where two cards of one type are swapped for one card of a different type.
Level

Medium6 of 10

Topics
Greedy, Sorting, Math
Solved
No attempts yet

Problem

You have a hand of cards, and each card has one of nn types. For each ii from 11 to nn, you have aia_i cards of type ii, and the bank has an unlimited supply of cards of every type.

You can trade with the bank any number of times. In each trade, choose two cards of the same type from your hand and exchange them for one card from the bank. The new card may have any type from 11 to nn except the type of the two cards you gave up. The bank has no cards of other types, so you cannot receive them.

The image below shows a valid sequence of trades on the first sample case.

What is the maximum number of trades you can perform?

Input

The first line contains a single integer tt (1≤t≤1051 \le t \le 10^5), the number of test cases. Each test case starts with a line containing nn (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5), the number of card types. The next line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤1090 \le a_i \le 10^9), where aia_i is the number of cards of type ii you currently have. The sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

Output

For each test case, print the maximum number of trades you can perform on its own line.

Hint

The image above shows an optimal sequence of trades in the first test case.

In the fourth test case, you have no pair of cards with the same type, so no trade is possible and the answer is 00.

Examples1

  1. Example 1

    Input
    9
    4
    2 0 0 1
    2
    5 2
    6
    1 5 0 6 7 1
    4
    1 1 0 1
    2
    4 2
    7
    1 2 4 8 4 2 1
    2
    1 1
    4
    0 0 0 0
    3
    1000000000 1000000000 1000000000
    
    Expected output
    2
    5
    19
    0
    5
    21
    0
    0
    2999999999