import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
	PrintWriter out = new PrintWriter(System.out);
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tok = new StringTokenizer("");
    String next() throws IOException {
        if (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); }
        return tok.nextToken();
    }
    int ni() throws IOException { return Integer.parseInt(next()); }
    long nl() throws IOException { return Long.parseLong(next()); }
  
    void solve() throws IOException {
        int n=ni();
        int a=0,b=0,p=1;
        while (true) {
            int c=ni();
            if (c==p) {
                p++; 
                if (p>n) break;
                continue;
            }
            a=p;
            b=c;
            p++;
            break;
        }
        if (a==0) {System.out.println("YES"); return;}
        
        while (true) {
            int c=ni();
            if (c==p) {
                p++; 
                if (p>n) { System.out.println("NO"); return; }
                continue;
            }
            if (c==a && p==b) {p++; break;}
            System.out.println("NO");
            return;
        }
        
        while (p<=n) {
            if (ni()==p) {p++; continue;}
            System.out.println("NO");
            return;
        }
        System.out.println("YES");
    }
    
    public static void main(String[] args) throws IOException {
        new Main().solve();
    }
} import java.util.*; util.* java import java.lang.*; lang.* java import java.io.*; io.* java public class Main
{
	PrintWriter out = new PrintWriter(System.out);
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tok = new StringTokenizer("");
    String next() throws IOException {
        if (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); }
        return tok.nextToken();
    }
    int ni() throws IOException { return Integer.parseInt(next()); }
    long nl() throws IOException { return Long.parseLong(next()); }
  
    void solve() throws IOException {
        int n=ni();
        int a=0,b=0,p=1;
        while (true) {
            int c=ni();
            if (c==p) {
                p++; 
                if (p>n) break;
                continue;
            }
            a=p;
            b=c;
            p++;
            break;
        }
        if (a==0) {System.out.println("YES"); return;}
        
        while (true) {
            int c=ni();
            if (c==p) {
                p++; 
                if (p>n) { System.out.println("NO"); return; }
                continue;
            }
            if (c==a && p==b) {p++; break;}
            System.out.println("NO");
            return;
        }
        
        while (p<=n) {
            if (ni()==p) {p++; continue;}
            System.out.println("NO");
            return;
        }
        System.out.println("YES");
    }
    
    public static void main(String[] args) throws IOException {
        new Main().solve();
    }
} Main PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); in new BufferedReader(new InputStreamReader(System.in)) StringTokenizer tok = new StringTokenizer(""); tok new StringTokenizer("") String next() throws IOException {
        if (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); }
        return tok.nextToken();
    } next {
        if (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); }
        return tok.nextToken();
    } if (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); } !tok.hasMoreTokens() tok.hasMoreTokens() tok.hasMoreTokens tok { tok = new StringTokenizer(in.readLine()); } tok = new StringTokenizer(in.readLine()) tok new StringTokenizer(in.readLine()) return tok.nextToken(); tok.nextToken() tok.nextToken tok int ni() throws IOException { return Integer.parseInt(next()); } ni { return Integer.parseInt(next()); } return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next long nl() throws IOException { return Long.parseLong(next()); } nl { return Long.parseLong(next()); } return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next void solve() throws IOException {
        int n=ni();
        int a=0,b=0,p=1;
        while (true) {
            int c=ni();
            if (c==p) {
                p++; 
                if (p>n) break;
                continue;
            }
            a=p;
            b=c;
            p++;
            break;
        }
        if (a==0) {System.out.println("YES"); return;}
        
        while (true) {
            int c=ni();
            if (c==p) {
                p++; 
                if (p>n) { System.out.println("NO"); return; }
                continue;
            }
            if (c==a && p==b) {p++; break;}
            System.out.println("NO");
            return;
        }
        
        while (p<=n) {
            if (ni()==p) {p++; continue;}
            System.out.println("NO");
            return;
        }
        System.out.println("YES");
    } solve {
        int n=ni();
        int a=0,b=0,p=1;
        while (true) {
            int c=ni();
            if (c==p) {
                p++; 
                if (p>n) break;
                continue;
            }
            a=p;
            b=c;
            p++;
            break;
        }
        if (a==0) {System.out.println("YES"); return;}
        
        while (true) {
            int c=ni();
            if (c==p) {
                p++; 
                if (p>n) { System.out.println("NO"); return; }
                continue;
            }
            if (c==a && p==b) {p++; break;}
            System.out.println("NO");
            return;
        }
        
        while (p<=n) {
            if (ni()==p) {p++; continue;}
            System.out.println("NO");
            return;
        }
        System.out.println("YES");
    } int n=ni(); n ni() ni int a=0 a 0 b=0 b 0 p=1; p 1 while (true) {
            int c=ni();
            if (c==p) {
                p++; 
                if (p>n) break;
                continue;
            }
            a=p;
            b=c;
            p++;
            break;
        } true {
            int c=ni();
            if (c==p) {
                p++; 
                if (p>n) break;
                continue;
            }
            a=p;
            b=c;
            p++;
            break;
        } int c=ni(); c ni() ni if (c==p) {
                p++; 
                if (p>n) break;
                continue;
            } c==p c p {
                p++; 
                if (p>n) break;
                continue;
            } p++ p if (p>n) break; p>n p n break; continue; a=p a p b=c b c p++ p break; if (a==0) {System.out.println("YES"); return;} a==0 a 0 {System.out.println("YES"); return;} System.out.println("YES") System.out.println System.out System System.out "YES" return; while (true) {
            int c=ni();
            if (c==p) {
                p++; 
                if (p>n) { System.out.println("NO"); return; }
                continue;
            }
            if (c==a && p==b) {p++; break;}
            System.out.println("NO");
            return;
        } true {
            int c=ni();
            if (c==p) {
                p++; 
                if (p>n) { System.out.println("NO"); return; }
                continue;
            }
            if (c==a && p==b) {p++; break;}
            System.out.println("NO");
            return;
        } int c=ni(); c ni() ni if (c==p) {
                p++; 
                if (p>n) { System.out.println("NO"); return; }
                continue;
            } c==p c p {
                p++; 
                if (p>n) { System.out.println("NO"); return; }
                continue;
            } p++ p if (p>n) { System.out.println("NO"); return; } p>n p n { System.out.println("NO"); return; } System.out.println("NO") System.out.println System.out System System.out "NO" return; continue; if (c==a && p==b) {p++; break;} c==a && p==b c==a c a p==b p b {p++; break;} p++ p break; System.out.println("NO") System.out.println System.out System System.out "NO" return; while (p<=n) {
            if (ni()==p) {p++; continue;}
            System.out.println("NO");
            return;
        } p<=n p n {
            if (ni()==p) {p++; continue;}
            System.out.println("NO");
            return;
        } if (ni()==p) {p++; continue;} ni()==p ni() ni p {p++; continue;} p++ p continue; System.out.println("NO") System.out.println System.out System System.out "NO" return; System.out.println("YES") System.out.println System.out System System.out "YES" public static void main(String[] args) throws IOException {
        new Main().solve();
    } main {
        new Main().solve();
    } new Main().solve() new Main().solve new Main() String[] args args public class Main
{
	PrintWriter out = new PrintWriter(System.out);
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tok = new StringTokenizer("");
    String next() throws IOException {
        if (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); }
        return tok.nextToken();
    }
    int ni() throws IOException { return Integer.parseInt(next()); }
    long nl() throws IOException { return Long.parseLong(next()); }
  
    void solve() throws IOException {
        int n=ni();
        int a=0,b=0,p=1;
        while (true) {
            int c=ni();
            if (c==p) {
                p++; 
                if (p>n) break;
                continue;
            }
            a=p;
            b=c;
            p++;
            break;
        }
        if (a==0) {System.out.println("YES"); return;}
        
        while (true) {
            int c=ni();
            if (c==p) {
                p++; 
                if (p>n) { System.out.println("NO"); return; }
                continue;
            }
            if (c==a && p==b) {p++; break;}
            System.out.println("NO");
            return;
        }
        
        while (p<=n) {
            if (ni()==p) {p++; continue;}
            System.out.println("NO");
            return;
        }
        System.out.println("YES");
    }
    
    public static void main(String[] args) throws IOException {
        new Main().solve();
    }
} public class Main
{
	PrintWriter out = new PrintWriter(System.out);
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tok = new StringTokenizer("");
    String next() throws IOException {
        if (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); }
        return tok.nextToken();
    }
    int ni() throws IOException { return Integer.parseInt(next()); }
    long nl() throws IOException { return Long.parseLong(next()); }
  
    void solve() throws IOException {
        int n=ni();
        int a=0,b=0,p=1;
        while (true) {
            int c=ni();
            if (c==p) {
                p++; 
                if (p>n) break;
                continue;
            }
            a=p;
            b=c;
            p++;
            break;
        }
        if (a==0) {System.out.println("YES"); return;}
        
        while (true) {
            int c=ni();
            if (c==p) {
                p++; 
                if (p>n) { System.out.println("NO"); return; }
                continue;
            }
            if (c==a && p==b) {p++; break;}
            System.out.println("NO");
            return;
        }
        
        while (p<=n) {
            if (ni()==p) {p++; continue;}
            System.out.println("NO");
            return;
        }
        System.out.println("YES");
    }
    
    public static void main(String[] args) throws IOException {
        new Main().solve();
    }
} Main
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
	PrintWriter out = new PrintWriter(System.out);
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tok = new StringTokenizer("");
    String next() throws IOException {
        if (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); }
        return tok.nextToken();
    }
    int ni() throws IOException { return Integer.parseInt(next()); }
    long nl() throws IOException { return Long.parseLong(next()); }
  
    void solve() throws IOException {
        int n=ni();
        int a=0,b=0,p=1;
        while (true) {
            int c=ni();
            if (c==p) {
                p++; 
                if (p>n) break;
                continue;
            }
            a=p;
            b=c;
            p++;
            break;
        }
        if (a==0) {System.out.println("YES"); return;}
        
        while (true) {
            int c=ni();
            if (c==p) {
                p++; 
                if (p>n) { System.out.println("NO"); return; }
                continue;
            }
            if (c==a && p==b) {p++; break;}
            System.out.println("NO");
            return;
        }
        
        while (p<=n) {
            if (ni()==p) {p++; continue;}
            System.out.println("NO");
            return;
        }
        System.out.println("YES");
    }
    
    public static void main(String[] args) throws IOException {
        new Main().solve();
    }
}