func_code_string: #include <bits/stdc++.h>   const int maxn = 1e5 + 10;   using namespace std;   long long gcd(long long p, long long q) { return q == 0 ? p : gcd(q, p % q); }   long long qpow(long long p, long long q) {     long long f = 1;     while (q) {       if (q & 1) f = f * p;       p = p * p;       q >>= 1;     }     return f;   }   inline long long read() {     long long x = 0;     int f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n, m, k, t, c[21][21], vis[21][21], num[4];   struct node {     int cnt, id;     bool operator<(const node& p) const { return cnt > p.cnt; }   } ca[25];   bool flag;   bool solve(int a, int b) {     int d[21][21];     int i, j;     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++) d[i][j] = c[i][j];     for (i = 1; i <= n; i++) swap(d[i][a], d[i][b]);     for (i = 1; i <= n; i++) {       int now = 0;       for (j = 1; j <= m; j++)         if (d[i][j] != j) now++;       if (now > 2) return false;     }     return true;   }   int main() {     int i, j;     scanf( %d%d , &n, &m);     for (i = 1; i <= n; i++) ca[i].id = i;     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++) {         scanf( %d , &c[i][j]);         if (c[i][j] != j) ca[i].cnt++;       }     sort(ca + 1, ca + n + 1);     if (ca[1].cnt <= 2)       puts( YES );     else if (ca[1].cnt > 4)       puts( NO );     else {       j = 0;       int pos = ca[1].id;       for (i = 1; i <= m; i++)         if (c[pos][i] != i) num[j++] = i;       for (i = 0; i <= 3; i++)         for (j = i + 1; j <= 3; j++) {           if (solve(num[i], num[j])) return 0 * puts( YES );         }       puts( NO );     }     return 0;   }   