L - MaratonIME doesn't like odd numbers

简介: L - MaratonIME doesn't like odd numbers

Statements

Estrela is known for defending tolerance time in delay tolerance. When he was attending to his MAC101 classes, there was a 15 minutes tolerance for delays and once he got 19 minutes late to the class. Estrela lost 7 points in his grade because of this even after he tried to explain how big the line for the Hot-Dog truck was. Later that day, he was talking about this situation during a training day for MaratonIME when Yan noticed a something odd: there was a 15 minutes delay tolerance, Estrela was 19 minutes late and lost 7 points. He said: "Estrela, can't you see? These are all odd numbers!".

The observation startled them and they realized that many of MaratonIME's catchphrases had a odd number of alphanumeric characters: "Oh, Fox!", "7", "Wubalubbadubdub", among others. That could not be a coincidence! They also realized that in their own names: Estrela and Yan.

Sena, whose name doesn't fit the observations, wants people to stop worrying about this kind of nonsense and focus on their training but he's busy trying to contain the great ruckus caused by the "7 Theory".

You agree with Sena and believe that if you create a super catchphrase with even length, people won't believe this crazy theory anymore. A super catchphrase is the concatenation of some (possibly none) catchphrases, as an example, "Da Matta is big." (12 alphanumeric characters) and "What a man!" (8 alphanumeric characters) can be used to make the super catchphrase "Da Matta is big. What a man!" (22 alphanumeric characters).

Since MaratonIME has a gigantic amount of catchphrases, you have to make a program that will determine the size of the greatest even length possible for a super catchphrase that is the concatenation of some (possibly none) of MaratonIME catchphrases. Note that if no super catchphrase with even length can be created the answer is 0.

Input

On the first line there will be an integer n, the amount of catchphrases and, on the second line, n integers, the i-th integer, ai, is the amount of alphanumerics on the i-th catchphrase.

Limits

  • 1 ≤ n ≤ 105.
  • 1 ≤ ai ≤ 104.

Output

Print the largest even size of a super catchphrase.

Examples

Input

3

1 2 4


Output

6

Input

6

4 8 15 16 23 42


Output

108

题目大意及思路:给你几个数相加,判断是不是偶数,是偶数的话,直接输出,不是偶数的话,减去最小的奇数。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void paixu(int a[], int l, int r);
int main()
{
    int n, a[100010], i, sum;
    sum = 0;
    scanf("%d", &n);
    for(i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
        sum = sum + a[i];
    }
    paixu(a,1,n);
    if(sum % 2 == 0)
    {
        printf("%d\n", sum);
    }
    else
    {
        for(i = 1; i <= n; i++)
        {
            if(a[i] % 2 != 0)
            {
                break;
            }
        }
        if(i > n)
        {
            printf("0\n");
        }
        else
        {
            printf("%d\n", sum - a[i]);
        }
    }
    return 0;
}
void paixu(int a[], int l, int r)
{
    int i = l, j = r;
    int x = a[i];
    if(i >= j)
    {
        return;
    }
    else
    {
        while(i < j)
        {
            while(i < j && a[j] >= x)
            {
                j--;
            }
            a[i] = a[j];
            while(i < j && a[i] <= x)
            {
                i++;
            }
            a[j] = a[i];
        }
        a[i] = x;
        paixu(a,l,i-1);
        paixu(a,i+1,r);
    }
}


相关文章
|
存储 算法 搜索推荐
Leetcode 347.Top K Frequent Elements
一句话理解题意:输出数组中出现次数对多的k个数。 在如果用C语言来写这个题目,思路就是先按数的大小排序,然后再用一个结构体数组保存每个数的出现次次数。 因为数组已经有序了,所以只需要遍历一次数组就可以获得每个数的出现次数了。
52 3
LeetCode 241. Different Ways to Add Parentheses
给定一个含有数字和运算符的字符串,为表达式添加括号,改变其运算优先级以求出不同的结果。你需要给出所有可能的组合的结果。有效的运算符号包含 +, - 以及 * 。
83 0
LeetCode 241. Different Ways to Add Parentheses
|
API
LeetCode 374. Guess Number Higher or Lower
我们正在玩一个猜数字游戏。 游戏规则如下: 我从 1 到 n 选择一个数字。 你需要猜我选择了哪个数字。 每次你猜错了,我会告诉你这个数字是大了还是小了。
77 0
LeetCode 374. Guess Number Higher or Lower
|
API
LeetCode 375. Guess Number Higher or Lower II
我们正在玩一个猜数游戏,游戏规则如下: 我从 1 到 n 之间选择一个数字,你来猜我选了哪个数字。 每次你猜错了,我都会告诉你,我选的数字比你的大了或者小了。 然而,当你猜了数字 x 并且猜错了的时候,你需要支付金额为 x 的现金。直到你猜到我选的数字,你才算赢得了这个游戏。
111 0
LeetCode 375. Guess Number Higher or Lower II
|
机器学习/深度学习 算法
LeetCode 347. Top K Frequent Elements
给定一个非空的整数数组,返回其中出现频率前 k 高的元素。
46 0
LeetCode 347. Top K Frequent Elements
LeetCode 263. Ugly Number
编写一个程序判断给定的数是否为丑数。 丑数就是只包含质因数 2, 3, 5 的正整数。
93 0
LeetCode 263. Ugly Number
LeetCode 264. Ugly Number II
编写一个程序,找出第 n 个丑数。 丑数就是只包含质因数 2, 3, 5 的正整数。
73 0
LeetCode 264. Ugly Number II
|
人工智能 C++
Longest Valid Parentheses
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.
775 0
|
机器学习/深度学习 Java
HDOJ 2095 find your present (2)
HDOJ 2095 find your present (2)
110 0
HDOJ 2095 find your present (2)
|
程序员
Uncaught ReferenceError: Invalid left-hand side in assignment
Uncaught ReferenceError: Invalid left-hand side in assignment
395 0