B. increase and decrease

Source: Internet
Author: User
Time limit per test

2 seconds

Memory limit per test

256 megabytes

Input

Standard Input

Output

Standard output

Polycarpus has an array, consistingNIntegersA1, bytes,A2, middle..., middle ,...,AN.
Polycarpus likes it when numbers in an array match. That's why he wants the array to have as your equal numbers as possible. For that polycarpus performs the following Operation multiple times:

  • He chooses two elements of the arrayAI,AJ(I  =J);
  • He simultaneously increases numberAIBy 1 and
    Decreases numberAJBy 1,
    That is, executesAISignature = SignatureAIBetween + between 1 andAJSignature = SignatureAJAccept-encoding 1.

The given operation changes exactly two distinct array elements. polycarpus can apply the described operation an infinite number of times.

Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help polycarpus.

Input

The first line contains integerN(1 digit ≤ DigitNLimit ≤ limit 105)
-The array size. The second line contains space-separated IntegersA1, bytes,A2, middle..., middle ,...,AN(|AI| Limit ≤ limit 104)
-The original array.

Output

Print a single integer-the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.

Sample test (s) Input
22 1
Output
1
Input
31 4 1
Output
3

Explanation: considering that the addition and subtraction operations are actually the conversion of numbers, you only need to determine whether the sum of all numbers can be divisible by N. If the sum of all numbers can be divisible, n is output, when division is not allowed, we can use the remainder as a separate number. At this time, there are n-1 identical numbers, and N-1 is output.

#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <string>#include <algorithm>using namespace std;int main() {int n,i,a;int sum;sum=0;scanf("%d",&n);for(i=0;i<n;i++){scanf("%d",&a);sum+=a;}if(sum%n==0){printf("%d\n",n);}else{printf("%d\n",n-1);}return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.