Codeforces Round #521 (Div. 3) C. Good Array

版权声明: https://blog.csdn.net/SunPeishuai/article/details/84189342

Let's call an array good if there is an element in the array that equals to the sum of all other elements. For example, the array a=[1,3,3,7]a=[1,3,3,7] is good because there is the element a4=7a4=7 which equals to the sum 1+3+31+3+3 .

You are given an array aa consisting of nn integers. Your task is to print all indices jj of this array such that after removing the jj -th element from the array it will be good (let's call such indices nice).

For example, if a=[8,3,5,2]a=[8,3,5,2] , the nice indices are 11 and 44 :

  • if you remove a1a1 , the array will look like [3,5,2][3,5,2] and it is good;
  • if you remove a4a4 , the array will look like [8,3,5][8,3,5] and it is good.

You have to consider all removals independently, i. e. remove the element, check if the resulting array is good, and return the element into the array.

Input

The first line of the input contains one integer nn (2≤n≤2⋅1052≤n≤2⋅105 ) — the number of elements in the array aa .

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1061≤ai≤106 ) — elements of the array aa .

Output

In the first line print one integer kk — the number of indices jj of the array aa such that after removing the jj -th element from the array it will be good (i.e. print the number of the nice indices).

In the second line print kk distinct integers j1,j2,…,jkj1,j2,…,jk in any order — nice indices of the array aa .

If there are no such indices in the array aa , just print 00 in the first line and leave the second line empty or do not print it at all.

Examples

Input

Copy

5
2 5 1 2 2

Output

Copy

3
4 1 5

Input

Copy

4
8 3 5 2

Output

Copy

2
1 4 

Input

Copy

5
2 1 2 4 3

Output

Copy

0

Note

In the first example you can remove any element with the value 22 so the array will look like [5,1,2,2][5,1,2,2] . The sum of this array is 1010 and there is an element equals to the sum of remaining elements (5=1+2+25=1+2+2 ).

In the second example you can remove 88 so the array will look like [3,5,2][3,5,2] . The sum of this array is 1010 and there is an element equals to the sum of remaining elements (5=3+25=3+2 ). You can also remove 22 so the array will look like [8,3,5][8,3,5] . The sum of this array is 1616 and there is an element equals to the sum of remaining elements (8=3+58=3+5 ).

In the third example you cannot make the given array good by removing exactly one element.

(PS):忽略了数据的大小,需要用long long,被hacked了呜呜~

题意:去掉任意一个数,使剩下的数的最大值等于其他n-2个数的和,输出满足题意的去掉的数的位置,以任意顺序输出。

分析:通过pair的第一个数表示输入的数的值,第二个数 表示输入的数的位置坐标。通过sort排序(pair默认的按照第一个数升序),然后分为两种情况。①前 n-1个数,去掉任意一个数,其他数的和等于第n个数的值。②特 判最后一个数,去掉最后一个数,判断前n-2项的和是否等于第n-1项的值。

代码:

#include <utility>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include<cstdio>
using namespace std;
typedef pair<long long int, long long int> P;
const int N =200008;
pair<long long int, long long int> items[N];
long long int b[200008];
int main()
{

    long long int n,maxn=0;
    scanf("%lld",&n);
    long long int sum=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&items[i].first);
        items[i].second=i;
        sum+=items[i].first;
        maxn=max(items[i].first,maxn);
    }
    long long int j=0;
    sum-=maxn;
    sort(items,items+n+1);
    for(int i=1;i<n;i++)
    {
        if(sum-items[i].first==maxn)
        {
            b[++j]=items[i].second;
        }
    }
    if(sum==2*items[n-1].first) b[++j]=items[n].second;
    printf("%lld\n",j);
    for(int i=1;i<=j;i++)
    {
        printf("%lld ",b[i]);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/SunPeishuai/article/details/84189342