Header Ads Widget

Odd one Out

 Problem:-

Alice and Bob are getting bored so they decided to play a game.

Alice has n cards having the first n odd numbers written on them. He removes one of the cards at random and hands the remaining n-1 cards to Bob. Help Bob to find the value of the card Alice has removed.

Input

The first line contains n the numbers of cards Alice has.

The second line contains n-1 space-separated integers representing the values of cards that Bob got.

Output

Print the value of card Alice removed.

Constraints

1n4000000

 

Sample Input
5
3 1 9 5
Sample Output
7
Time Limit: 1
Memory Limit: 512
Source Limit:
Explanation

The first 5 odd numbers are 1, 3, 5, 7 and 9 out of which 7 is missing.

Code (c++):-

#include<iostream>
using namespace std;
int main()
{
    // these three lines only for decrease the time
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long long n,sum=0,a;
    cin>>n;
    for(long long i=0;i<n-1;i++)
    {
        cin>>a;
        sum=sum+a;
    }
    cout<<n*n-sum;
    return 0;
}

Code (c):-


#include <stdio.h>
int main(){
long n,d;
scanf("%ld", &n);
long tot=n*n,sum=0;
for (int i=0;i<n-1;i++)
{
scanf("%ld",&d);
sum+=d;
}
printf("%ld\n",tot - sum);
}