This page is still under construction.

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

Odd Subsequence

Time limit3sMemory limit512 MB

Summary
Count the distinct multisets chosen as subsequences whose element sum has an odd number of odd digits (1, 3, 5, 7, 9 in the decimal representation).
Level

Medium7 of 10

Topics
Combinatorics, Array, Math, Implementation
Solved
No attempts yet

Problem

For an array AA of nn nonnegative integers, a "subsequence" is any array obtained by deleting zero or more elements.

A subsequence SS of AA is called an "odd subsequence" of AA if it satisfies the following condition:

  • The number of odd digits in the sum of the elements of SS is odd.

Given an array AA of nonnegative integers, output the number of distinct odd subsequences of AA. Two subsequences are considered the same if sorting their elements yields the same result.

For A=[3,3,6,8,6]A = [3, 3, 6, 8, 6], the answer is 8.

  • Odd subsequences of length 0: none
  • Odd subsequences of length 1: [3][3]
    • The sum is 3, and the only odd digit is 3
  • Odd subsequences of length 2: [3,6][3, 6], [6,6][6, 6], [6,8][6, 8]
    • The sums are 9, 12, 14, each with exactly one odd digit: 9, 1, 1
  • Odd subsequences of length 3: [3,3,6][3, 3, 6], [3,3,8][3, 3, 8]
  • Odd subsequences of length 4: [3,3,6,6][3, 3, 6, 6], [3,6,6,8][3, 6, 6, 8]
  • Odd subsequences of length 5: none

Input

The first line contains the number of test cases TT (1≤T≤101 \le T \le 10).

For each test case, the first line contains the length nn of AA. The second line contains nn nonnegative integers separated by spaces. Each element of AA is between 0 and 2,000 inclusive.

Output

For each test case, print the number of odd subsequences on one line.

Hint

  • Test case 1: there are three odd subsequences: {3}\{3\}, {3,6}\{3, 6\}, {3,3,6}\{3, 3, 6\}.
  • Test case 2: there are eight odd subsequences: {1}\{1\}, {3}\{3\}, {0,1}\{0, 1\}, {0,3}\{0, 3\}, {1,2}\{1, 2\}, {2,3}\{2, 3\}, {0,1,2}\{0, 1, 2\}, {0,2,3}\{0, 2, 3\}.
  • Test case 3: as described in the problem, there are eight odd subsequences.

Examples1

  1. Example 1

    Input
    3
    3
    3 3 6
    4
    0 1 2 3
    5
    3 3 6 8 6
    
    Expected output
    3
    8
    8