#include using namespace std; typedef long long ll; #define REP(i, n) for(int(i)=0;(i)<(n);++(i)) const int MOD = 1000000007; int N, a[51], b[51]; bool dfs(int i){ if(i == N) return true; if(b[i] >= 0){ int j = b[i]; if(b[j] >= 0){ if(a[i] != b[j]) return false; if(dfs(i+1)) return true; } else { b[j] = a[i]; if(dfs(i+1)) return true; b[j] = -1; } } else { REP(j,N){ b[i] = j; if(b[j] >= 0){ if(a[i] != b[j]) continue; if(dfs(i+1)) return true; } else { b[j] = a[i]; if(dfs(i+1)) return true; b[j] = -1; } } b[i] = -1; } return false; } int main(){ cin >> N; REP(i,N){ cin >> a[i]; a[i]--; b[i] = -1; } cout << (dfs(0)?"Yes":"No") << endl; return 0; }