Under construction

Still being built. Things may change

Dirigent

Interview

Time limit1sMemory limit1024 MB

Summary
After each swap in a circle of n students, decide whether cutting one neighbouring pair leaves the labels in sorted order.
Level

Medium5 of 10

Topics
Array, Implementation
Solved
No attempts yet

Problem

Winter school of informatics ends with a traditional dance. There are nn students who participate. Each of them has a unique label between 11 and nn.

First, conductor Krešo orders the students to form a circle such that each student holds hands with two other students.

Alenka is wondering if it is possible to break the circle by making exactly one pair of neighbouring students stop holding hands and that the newly formed sequence of students is sorted by their labels. For example, if their order is 3 4 1 2, then the circle can be broken between students with labels 4 and 1. If their order is 2 1 4 3, then there is no way to break the circle in such a way.

During the night Krešo is going to give qq instructions. In each of them, he orders two students to swap places. After each swap, you need to help Alenka answer her question.

Input

The first line contains two integers nn and qq (1≤n,q≤3000001 ≤ n, q ≤ 300000), the number of students and the number of swaps.

The second line contains nn integers aia_i (1≤ai≤n1 ≤ a_i ≤ n), describing the initial placement of students in the circle.

In each of the next qq lines there are two integers xix_i, yiy_i (1≤xi,yi≤n1 ≤ x_i, y_i ≤ n, xi≠yix_i ≠ y_i), describing Krešo's ii-th instruction. Students with labels xix_i and yiy_i swap places.

Output

In the ii-th of the qq lines, output the answer after the first ii swaps have been carried out. Print DA if the answer is yes, otherwise print NE.

Hint

Clarification of the second example: the students at the beginning, after the first swap, and after the second swap.

Examples3

  1. Example 1

    Input
    5 2
    2 3 4 5 1
    1 3
    3 1
    
    Expected output
    NE
    DA
    
  2. Example 2

    Input
    4 2
    2 3 1 4
    4 2
    3 4
    
    Expected output
    NE
    DA
    
  3. Example 3

    Input
    6 5
    2 1 5 6 3 4
    3 1
    3 4
    3 2
    4 5
    5 4
    
    Expected output
    NE
    NE
    DA
    NE
    DA