Guy-Manuel and Thomas have an array a of n integers [a1,a2,…,an]. In one step they can add 1 to any element of the array. Formally, in one step they can choose any integer index i (1≤i≤n) and do ai:=ai+1.If either the sum or the product of all elements in the array is equal to zero, Guy-Manuel and Thomas do not mind to do this operation one more time.What is the minimum number of steps they need to do to make both the sum and the product of all elements in the array different from zero? Formally, find the minimum number of steps to make a1+a2+ … +an≠0 and a1⋅a2⋅ … ⋅an≠0.

Input

Each test contains multiple test cases.The first line contains the number of test cases t (1≤t≤103). The description of the test cases follows.The first line of each test case contains an integer n (1≤n≤100) — the size of the array.The second line of each test case contains n integers a1,a2,…,an (−100≤ai≤100) — elements of the array .

Output

For each test case, output the minimum number of steps required to make both sum and product of all elements in the array different from zero.

Example
input

4
3
2 -1 -1
4
-1 0 0 1
2
-1 2
3
0 -2 1

output

1
2
0
2

Note

In the first test case, the sum is 0. If we add 1 to the first element, the array will be [3,−1,−1], the sum will be equal to 1 and the product will be equal to 3.In the second test case, both product and sum are 0. If we add 1 to the second and the third element, the array will be [−1,1,1,1], the sum will be equal to 2 and the product will be equal to −1. It can be shown that fewer steps can't be enough.In the third test case, both sum and product are non-zero, we don't need to do anything.In the fourth test case, after adding 1 twice to the first element the array will be [2,−2,1], the sum will be 1 and the product will be −4.

这个题是说通过最小的修改次数,是数列和不能为0,乘积不能为0;
那么也即数列中不存在0,如果存在0的一定要改,存在0的只能变成1,那我们考虑变成1之后,的和是否等于0,如果等于,就在修改1个,即cnt+1。

#include<bits/stdc++.h>
using namespace std;
const int N=5e5;
#define read(a) scanf("%d",&a);
int  a[N];
int main()
{int t;read(t);while(t--){int n;read(n);long long sum=0;int cnt=0;for(int i=1;i<=n;i++){cin>>a[i];sum+=(long long)a[i];if(a[i]==0) cnt++;}if(cnt==0){if(sum!=0) cout<<0<<endl;else cout<<1<<endl;}else {if(cnt+sum==0) cout<<cnt+1<<endl;else cout<<cnt<<endl;}}
}

Codeforces Round #618 (Div. 2)-Non-zero相关推荐

  1. Codeforces Round #618 (Div. 1)-----A. Anu Has a Function

    提示: Codeforces Round #618 (Div. 1)-----A. Anu Has a Function 题意: 定义一个函数f(x , y) = f(x | y) - y 给定一个长 ...

  2. 贪心 ---- Codeforces Round #618 (Div. 2)B. Assigning to Classes+贪心[证明过程]

    题目链接 题目大意:给你2∗n2*n2∗n个数,将这些数分成2个集合使得两个集合中位数的差值最小 解题思路:我懵了一个结论就是排序之后取中间的两个数然后就ac了 我们先对这些数字从小到大排序 证明:1 ...

  3. Codeforces Round #618 (Div. 2)-C. Anu Has a Function

    Anu has created her own function f: f(x,y)=(x|y)−y where | denotes the bitwise OR operation. For exa ...

  4. Codeforces Round #618 (Div. 2)-B. Assigning to Classes

    Reminder: the median of the array [a1,a2,-,a2k+1] of odd number of elements is defined as follows: l ...

  5. 【Codeforces Round#618 (Div. 2)】C. Anu Has a Function 题解

    题目链接:C. Anu Has a Function 题目 Anu has created her own function f: f(x,y)=(x|y)−y where | denotes the ...

  6. 寒假刷题13: Anu Has a Function Codeforces Round #618 (Div. 2) C

    题目链接: Anu Has a Function 题目解析: 观察函数f(x,y)定义:(x|y)-y 即 取出来x里是1但是y里不是1的地方 也就是 x&(~y) (也可以列真值表) 因此题 ...

  7. Codeforces Round #618 (Div. 2)C、Anu Has a Function

    C. Anu Has a Function time limit per test1 second memory limit per test256 megabytes inputstandard i ...

  8. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  9. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

最新文章

  1. 1微秒等于多少皮秒_注册汽油贸易公司分享1升汽油等于多少公斤?
  2. 维基百科创始人:将欧盟隐私规定推至全球将带来灾难
  3. 在C#中如何在客户端接收信件
  4. zuul filter
  5. comsol线圈不能加电流激励_为什么电压互感器不能短路,电流互感器不得开路?...
  6. jquery selector 使用方法
  7. VTK:图片之ResizeImage
  8. leetcode 687. Longest Univalue Path | 687. 最长同值路径(树形dp)
  9. matlab逆变换法产生随机数_matlab数值积分方法(一)
  10. 界面设计方法(2)— 5.功能按钮设计(新增,查询)
  11. 使用Flash Builder 4.5进行多平台游戏开发
  12. 震惊!99%的人不知道的Linux权限问题细节
  13. java_eclipse中添加外部动态链接库(dll文件)的三种方式
  14. Tomcat 访问manager app报403 解决方案(虚拟机可以正常使用,外面访问报错)
  15. (转载)你的个人信息是如何被盗走的?MySQL脱库,脱库的原理,怎么脱库,脱库的步骤,一库三表六字段
  16. arduinouno的地是相连的吗_垫圈锁紧,靠谱吗?
  17. 服务器上删掉的数据如何找回,在服务器数据丢失情况下如何恢复数据
  18. 贝叶斯估计理论——引子
  19. (转)50本书总结的50句话
  20. C语言爱心代码大全集—会Ctrl+C就可以表白了

热门文章

  1. java数据库的优化_用Java向数据库中插入大量数据时的优化
  2. mac上安装MySQL
  3. java并发中的延迟初始化
  4. java位宽_Java的数据类型
  5. 核心技术靠化缘是要不来的——自己动手写ORM框架
  6. 【Redis】redis开机自启动、设置守护进程、密码设置、访问权限控制等安全设置(redis默认端口6379)...
  7. GNU C中x++是原子操作吗?
  8. Linux下OpenSSL的安装与使用
  9. 第三篇——第二部分——第一文 SQL Server镜像简介
  10. Mysql基本用法-01