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

C. Good Array

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

题意:

给你一个整数n , 下面一行包含 n 个数 , 

要求你删去其中一个数 , 使得剩下的数字满足 a = b + c +..+ d;问满足这种要求的有几个 , 并且输出删去的数字的下标

比如

4

8 3 5 2

去掉 8 有 5 = 3 + 2;

去掉 2 有 8 = 3 + 5;

故答案是2 , 下标为1 , 4;

思路:

在输入的同时就将所有数字相加 ,并且将输入的数字用map存一下 , 记录这个数字记录的次数 。

再将所有数循环一遍 , 一个一个减去 , 判断减去的这个数除2的数是否被标记过

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e6+8;
int a[maxn] , b[maxn];
map<long long,int>vis;
int main()
{
	int n , ret = 0;
	long long sum = 0;
	scanf("%d" , &n);
	for(int i = 1 ;  i <= n ; i++)
	{
		scanf("%d" , &a[i]);
		vis[a[i]]++;
		sum += a[i];
	}
//	cout << "3333="<<vis[2]<<endl;
	for(int i = 1 ; i <= n ;i++)
	{
		if((sum-a[i])%2 == 1)
		{
			continue;
		}
		if(vis[(sum-a[i])/2] != 0)
		{
			
			if(vis[a[i]]-1 == 0 && sum == 3 * a[i])
			{
				continue;
			}
			b[ret++] = i;
		}
		
	}
	printf("%d\n" , ret);
	for(int j = 0 ; j < ret ; j++)
	{
		printf("%d " , b[j]);
	}
	return 0;
}

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值