Make it Zigzag

AtCoder
IDagc058_a
Time2000ms
Memory256MB
Difficulty
You are given a permutation $P=(P_1,P_2,\cdots,P_{2N})$ of $(1,2,\cdots,2N)$. The following operation may be performed between $0$ and $N$ times (inclusive). * Choose an integer $x$ ($1 \leq x \leq 2N-1$). Swap the values of $P_x$ and $P_{x+1}$. Present a sequence of operations that make $P$ satisfy the following conditions. * $P_i<P_{i+1}$ for each $i=1,3,5,\cdots,2N-1$; * $P_i>P_{i+1}$ for each $i=2,4,6,\cdots,2N-2$. It can be proved that such a sequence of operations always exists. ## Constraints * $1 \leq N \leq 10^5$ * $(P_1,P_2,\cdots,P_{2N})$ is a permutation of $(1,2,\cdots,{2N})$. * All values in input are integers. ## Input Input is given from Standard Input in the following format: $N$ $P_1$ $P_2$ $\cdots$ $P_{2N}$ [samples]
Samples
Input #1
2
4 3 2 1
Output #1
2
1 3

These operations make $P=(3,4,1,2)$, which satisfies the conditions.
Input #2
1
1 2
Output #2
0
API Response (JSON)
{
  "problem": {
    "name": "Make it Zigzag",
    "description": {
      "content": "You are given a permutation $P=(P_1,P_2,\\cdots,P_{2N})$ of $(1,2,\\cdots,2N)$. The following operation may be performed between $0$ and $N$ times (inclusive). *   Choose an integer $x$ ($1 \\leq x \\leq",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "agc058_a"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given a permutation $P=(P_1,P_2,\\cdots,P_{2N})$ of $(1,2,\\cdots,2N)$.\nThe following operation may be performed between $0$ and $N$ times (inclusive).\n\n*   Choose an integer $x$ ($1 \\leq x \\leq...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments