Baby Ehab Partitions Again

Baby Ehab was toying around with arrays. He has an array aa of length nn. He defines an array to be good if there's no way to partition it into 22 subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in aa so that it becomes a good array. Can you help him?

A sequence bb is a subsequence of an array aa if bb can be obtained from aa by deleting some (possibly zero or all) elements. A partitioning of an array is a way to divide it into 22 subsequences such that every element belongs to exactly one subsequence, so you must use all the elements, and you can't share any elements.

Input

The first line contains an integer nn (2≤n≤1002≤n≤100) — the length of the array aa.

The second line contains nn integers a1a1, a2a2, ……, anan (1≤ai≤20001≤ai≤2000) — the elements of the array aa.

Output

The first line should contain the minimum number of elements you need to remove.

The second line should contain the indices of the elements you're removing, separated by spaces.

We can show that an answer always exists. If there are multiple solutions, you can print any.

Examples

input

4
6 3 9 12

output

1
2

input

2
1 2

output

0

Note

In the first example, you can partition the array into [6,9][6,9] and [3,12][3,12], so you must remove at least 11 element. Removing 33 is sufficient.

In the second example, the array is already good, so you don't need to remove any elements.

如果sum是奇数,那就直接是好的。

其次, 首先用受限制的背包找到sum/2是否能被构造出来,如果不可以,那这个数组也是好的。

以上答案都是0,其次。

就是如果有一个数是奇数,那把奇数抽出,剩余的是奇数,一定不能构造。

比如:1、2、2、1把1抽出,就只剩下2、2、1,一定不能平分。

我们剩余还有一种情况,那就是全都是偶数的情况,我们设想把1、2、2、1全部 * 4,最后变成了4、8、8、4这就是全部都是偶数了,就等同于我们拿4次1、2、2、1中的一个数,且四次都是同一个数,很自然的我们会拿那个奇数,也就是1。所以4、8、8、4最后拿的数是4。

受此启示,我们只需要拿到所有数的最大公约数,把所有数除以最大公约数,数组就会存在奇数。我们把那个数删去就行。

其实问题就转变为,找到最大公约数,然后,若某个数除以此数是奇数。那删去此数就行。

#include<bits/stdc++.h>
#define int long long
#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define per(i, a, b) for(int i = a; i >= b; i --)
using namespace std;
const int N = 110;
int a[N];
int sum = 0;
bool f[200010];
bool st[N];


signed main(){

	int n; cin >> n;
	int tot = -1;
	rep(i,1,n){
		cin >> a[i];
		sum += a[i];
		if(a[i]&1) tot = i;
	} 
	
	if((sum & 1)){
		cout << 0 << endl;
		return 0;
	}
	f[0] = 1;
	rep(i,1,n){
		per(j,sum,a[i]) f[j] = (f[j-a[i]] || f[j]);
	}

	if(!f[sum/2]){
		cout << 0 << endl;
	}else{
		if(tot == -1){
			sort(a+1,a+n+1);
			cout << "1\n" << a[1];
		}else{
			cout << "1\n" << tot << endl;
		}
	}
    return 0;
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值