Instagram
youtube
Facebook
Twitter

Python Dividing Stamps Program Codechef Solution

           Python Dividing Stamps Program Codechef Solution

Problem

Are you fond of collecting some kind of stuff? Mike is crazy about collecting stamps. He is an active member of the Stamp Collecting Community (SCC).

SCC consists of N members which are fond of philately. A few days ago Mike argued with the others from SCC. Mike told them that all stamps of the members could be divided in such a way that each member would get two postage stamps. Now Mike wants to know if he was right. The next SCC meeting is tomorrow. Mike still has no answer.

So, help Mike! There are N members in the SCC, and each member has Ci stamps in his collection. Your task is to determine if it is possible to redistribute C1 + C2 +... + Cn stamps among the members of SCC, so that each member would get i stamps.

Input

The first line contains one integer, N, denoting the number of members of the SCC.

The second line contains N integers Ci, denoting the numbers of the stamps in the collection of i'th member.

Output

The first line should contain yes if we can obtain the required division; otherwise, no.

Constraints

1 ≤ N ≤ 100 000;

1 ≤ Ci ≤ 10^9.

Sample Input 1:

7 4 1 1 2

Sample Output 1:

Yes

Sample Input 2:

1 1 1 1 1

Sample Output 2:

No

Solution:

n = int(input(“Enter the number of members of SCC: “ ))

c = list(map(int,input(“Enter the numbers of the stamp).split()))

count = 0

for i in c:

    count = count + i

#print(count)

if count==n*(n+1)//2:

    print("YES")

else:

    print("NO")

Steps to solve this problem:

  1. Ask the user to enter the number of members of the SCC.
  2. Ask the user to enter the numbers of the stamp, and using the map() function, get iterator objects, convert them to a list, and store them in c.
  3. Initialise the count variable with 0.
  4. In the loop, add i to the value of count iteratively.
  5. Check if count is equal to n*(n+1)/2, then print "yes." Otherwise, print "no."