function main(input) {
    var args = input.trim().split(/\r\n|\n/);
    var N = Number(args[0].trim());
    var Ps = args[1].trim().split(" ").map(v => Number(v.trim()));

    var targets = [];
    for(var i = 0; Ps.length > i; i++) {
        if (i + 1 !== Ps[i]) {
            targets.push(Ps[i - 1]);
        }

        if (targets.length > 2) {
            console.log("NO");
            return;
        };
    }
    console.log("YES");
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));