A. Oath of the Night's Watch

Codeforces
IDCF768A
Time2000ms
Memory256MB
Difficulty
constructive algorithmssortings
English · Original
Chinese · Translation
Formal · Original
_"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 _a_1, _a_2, ..., _a__n_ (0 ≤ _a__i_ ≤ 109) representing the values assigned to the stewards. ## Output Output a single integer representing the number of stewards which Jon will feed. [samples] ## 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.
_"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 #cf_span[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? First line consists of a single integer #cf_span[n] (#cf_span[1 ≤ n ≤ 105]) — the number of stewards with Jon Snow. Second line consists of #cf_span[n] space separated integers #cf_span[a1, a2, ..., an] (#cf_span[0 ≤ ai ≤ 109]) representing the values assigned to the stewards. Output a single integer representing the number of stewards which Jon will feed. In the first sample, Jon Snow cannot support steward with strength #cf_span[1] because there is no steward with strength less than #cf_span[1] and he cannot support steward with strength #cf_span[5] because there is no steward with strength greater than #cf_span[5]. In the second sample, Jon Snow can support steward with strength #cf_span[2] because there are stewards with strength less than #cf_span[2] and greater than #cf_span[2]. ## Input 第一行包含一个整数 #cf_span[n] (#cf_span[1 ≤ n ≤ 105]) —— 与琼·雪诺在一起的管家数量。 第二行包含 #cf_span[n] 个用空格分隔的整数 #cf_span[a1, a2, ..., an] (#cf_span[0 ≤ ai ≤ 109]),表示分配给各管家的数值。 ## Output 输出一个整数,表示琼将支持的管家数量。 [samples] ## Note 在第一个测试用例中,琼·雪诺无法支持强度为 #cf_span[1] 的管家,因为不存在强度小于 #cf_span[1] 的管家;他也无法支持强度为 #cf_span[5] 的管家,因为不存在强度大于 #cf_span[5] 的管家。 在第二个测试用例中,琼·雪诺可以支持强度为 #cf_span[2] 的管家,因为存在强度小于 #cf_span[2] 和大于 #cf_span[2] 的管家。
**Definitions** Let $ n \in \mathbb{Z} $ be the number of stewards. Let $ A = (a_1, a_2, \dots, a_n) $ be a sequence of non-negative integers representing the strengths of the stewards. **Constraints** 1. $ 1 \leq n \leq 10^5 $ 2. $ 0 \leq a_i \leq 10^9 $ for all $ i \in \{1, \dots, n\} $ **Objective** Count the number of stewards $ a_i \in A $ such that: $$ \exists\, a_j, a_k \in A \text{ with } a_j < a_i < a_k $$ That is, $ a_i $ is neither the minimum nor the maximum of $ A $.
Samples
Input #1
2
1 5
Output #1
0
Input #2
3
1 2 5
Output #2
1
API Response (JSON)
{
  "problem": {
    "name": "A. Oath of the Night's Watch",
    "description": {
      "content": "_\"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 ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF768A"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "_\"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 ...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "_\"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 ...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z} $ be the number of stewards.  \nLet $ A = (a_1, a_2, \\dots, a_n) $ be a sequence of non-negative integers representing the strengths of the stewards.\n\n**Constra...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments