
#include "validator.h"
#include <bits/stdc++.h>
using namespace std;

bool nonincr(int i, vector<int> &a)
{
    if (i > 0 && a[i-1] < a[i]) return false;
    if (i + 1 < (int) a.size() && a[i] < a[i+1]) return false;
    return true;
}

void run() {
    int maxn = toml<int>("MAXN");
    int maxq = toml<int>("MAXQ");
    int mina = toml<int>("MINA");
    int maxa = toml<int>("MAXA");
    int bias = toml<int>("BIAS");
    string mode = toml<string>("MODE");

    int n = Int(2, maxn);
    Space();
    int q = Int(0, maxq);
    Endl();
    vector<int> a = SpacedInts(n, 1, maxa);
    if (mode == "nonincreasing")
    {
        for (int i = 0; i < n; i++)
        {
            if (!nonincr(i, a))
            {
                die_line("initial array not non-incr");
            }
        }
    }

    int changeIndex, previousValue;
    for (int i = 0; i < q; i++) {
        int p = Int(0, n-1);
        Space();
        int x = Int(mina, maxa);
        Endl();

        if (mode == "restoring") {
            if (i % 2 == 0) {
                changeIndex = p;
                previousValue = a[p];
            } else if (changeIndex != p || x != previousValue) {
                die_line("test case didn't restore after query " + to_string(i));
            }
        }

        a[p] = x;

        if (mode == "nonincreasing" && !nonincr(p, a))
        {
            string sp = to_string(p);
            string sx = to_string(x);
            string arr = "... " + to_string(p == 0 ? 50 : a[p - 1]) +
                            " " + to_string(a[p]) +
                            " " + to_string(p + 1 == n ? 1 : a[p + 1]) + "...";
            die_line("after query array not non-incr: " + to_string(p) + " : " + arr);
        }

    }

    Eof();
    return;
}
