Codeforces 768A Oath of the Night's Watch

来源:互联网 发布:js 当前页面url 编辑:程序博客网 时间:2024/05/23 21:46

A. Oath of the Night's Watch
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I pledge my life and honor to the Night's Watch, for this night and all the nights to come." — The Night's Watch oath.

With that begins the watch of Jon Snow. He is assigned the task to support the stewards.

This time he has n stewards with him whom he has to provide support. Each steward has his own strength. Jon Snow likes to support a steward only if there exists at least one steward who has strength strictly less than him and at least one steward who has strength strictly greater than him.

Can you find how many stewards will Jon support?

Input

First line consists of a single integer n (1 ≤ n ≤ 105) — the number of stewards with Jon Snow.

Second line consists of n space separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) representing the values assigned to the stewards.

Output

Output a single integer representing the number of stewards which Jon will feed.

Examples
input
21 5
output
0
input
31 2 5
output
1
Note

In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.

In the second sample, Jon Snow can support steward with strength 2 because there are stewards with strength less than 2 and greater than 2.


——————————————————————————————————————

题目的意思是给出n个数,输出不是最大也不是最小的数的个数

排序,找出最大数个数最小数个数,总数减去就好,注意都是一样的情况



#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <queue>#include <stack>#include <string>#include <set>#include <map>using namespace std;int a[100005];int n;int main(){    while(~scanf("%d",&n))    {        for(int i=0;i<n;i++)            scanf("%d",&a[i]);        sort(a,a+n);        if(a[0]==a[n-1])            printf("0\n");        else        {            int cnt=2;            for(int i=1;i<n;i++)            {                if(a[i]==a[i-1])                    cnt++;                else                    break;            }            for(int i=n-2;i>0;i--)            {                if(a[i]==a[i+1])                    cnt++;                else                break;            }             printf("%d\n",n-cnt);        }    }    return 0;}




0 0
原创粉丝点击