//g++ 2.cpp -std=c++14 -O2 -I . #include using namespace std; #include using namespace atcoder; using ll = long long; using ld = long double; using vi = vector; using vvi = vector; using vll = vector; using vvll = vector; using vld = vector; using vvld = vector; using vst = vector; using vvst = vector; #define fi first #define se second #define pb push_back #define eb emplace_back #define pq_big(T) priority_queue,less> #define pq_small(T) priority_queue,greater> #define all(a) a.begin(),a.end() #define rep(i,start,end) for(ll i=start;i<(ll)(end);i++) #define per(i,start,end) for(ll i=start;i>=(ll)(end);i--) #define uniq(a) sort(all(a));a.erase(unique(all(a)),a.end()) //https://atcoder.jp/contests/arc122/submissions/24436348 //https://judge.yosupo.jp/submission/53811 //https://yukicoder.me/submissions/680896 //https://atcoder.jp/contests/abc180/submissions/24436784 #include #include #include #include #include #include std::mt19937_64 mt{std::random_device{}()}; long long rnd(long long n) { return std::uniform_int_distribution(0, n-1)(mt); } bool is_prime(long long x){ using u128=__uint128_t; if(x==2||x==3||x==5||x==7)return true; if(x%2==0||x%3==0||x%5==0||x%7==0)return false; if(x<121){ return x>1; } long long d = (x-1) >> __builtin_ctzll(x-1); long long one=1,minus_one=x-1; auto pow = [](long long x,long long n,long long mod){ u128 res; x%=mod; if(n==0){ res=1;return res; } res=1; u128 now=x; for(;n;n>>=1,now=(now*now)%mod){ if(n&1){ res=res*now%mod; } } return res; }; auto ok = [&](long long a){ auto y=pow(a,d,x); long long t=d; while(y!=one&&y!=minus_one&&t!=x-1){ y=y*y%x; t<<=1; } if(y!=minus_one&&t%2==0)return false; return true; }; if(x<(1ull<<32)){ for(long long a:{2,7,61}){ if(!ok(a))return false; } } else{ for(long long a:{2,325,9375,28178,450775,9780504,1795265022}){ if(x<=a)return true; if(!ok(a))return false; } } return true; } long long GCD(long long a,long long b){ if(b==0){ return a; } else{ return GCD(b,(a%b)); } } long long rho(long long n,long long c){ using u128=__uint128_t; assert(n>1); long long cc=c; auto f = [&](long long x){ long long res; res=(((u128)x)*x+cc)%n; return res; }; long long x=1,y=2,z=1,q=1; long long g=1; long long m= 1LL<<((64-__builtin_ctzll(n))/5); for(long long r=1;g==1;r<<=1){ x=y; for(int i=0;i1); if(is_prime(n)) return n; for(int i=0;i<100;i++){ long long m=rho(n,rnd(n)); if(is_prime(m))return m; n=m; } std::cerr<<"failed\n"; assert(false); return -1; } //nを素因数分解 {素因数,個数} で管理 (1は空配列) std::vector> factor(long long n){ static std::vector> res; res.clear(); for(long long i=2;i<=100&&i*i<=n;++i){ if(n%i==0){ int cnt=0; do{ cnt++; n/=i; }while(n%i==0); res.emplace_back(i,cnt); } } while(n>1){ long long p=prime_factor(n); int cnt=0; do{ cnt++; n/=p; }while(n%p==0); res.emplace_back(p,cnt); } std::sort(res.begin(),res.end()); return res; } //nの約数配列(昇順) 引数はfactor(n) std::vector divisor(std::vector> &fac){ int sz=fac.size(); //n=1の時 if(sz==0){ return {1}; } std::vector> x(sz); for(int i=0;i> res(sz); res[0]=x[0]; for(int i=1;i>n; vvi p(n,vi(2)); rep(i,0,n){ cin>>p[i][0]>>p[i][1]; } two_sat ts(n); // 0 S-T 1 T-S rep(i,0,n){ rep(j,0,n){ if(i==j){ rep(k,0,2){ string s=to_string(p[i][k])+to_string(p[i][k^1]); int z=stoi(s); if(is_prime(z)){ ts.add_clause(i,k,i,k); } } continue; } rep(k,0,2){ rep(l,0,2){ string s; int z1,z2; s=to_string(p[i][k])+to_string(p[j][l^1]); z1=stoi(s); s=to_string(p[j][l])+to_string(p[i][k^1]); z2=stoi(s); if(is_prime(z1)||is_prime(z2)){ ts.add_clause(i,k,j,l); } } } } } if(ts.satisfiable()){ cout<<"Yes\n"; return 0; } cout<<"No\n"; }