Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- //#include <ext/pb_ds/assoc_container.hpp> // Общий файл.
- //#include <ext/pb_ds/tree_policy.hpp> // Содержит класс tree_order_statistics_node_update
- #define ll long long
- #define ull unsigned long long
- #define ld long double
- #define len(v) (int)v.size()
- #define all(v) v.begin(), v.end()
- #define rall(v) v.rbegin(), v.rend()
- #define pii pair<int, int>
- #define vi vector<int>
- #define vii vector<vector<int>>
- #define vpii vector<pair<int, int>>
- #define dcout cout << setprecision(7)
- #define mkp make_pair
- #define in(v) for (auto& i : v) cin >> i;
- #define out(v) for (auto& i : v) cout << i << ' ';
- //#define int long long
- //#define ll ull
- const int maxn = 3e5 + 10;
- const int C = 20;
- const int logn = 20;
- const int inf = 1e9;
- const ll mod = 1e9 + 7;
- //const int M = 1e9;
- const ull M2 = 998244353;
- const ld eps = 1e-9;
- using namespace std;
- //using namespace __gnu_pbds;
- //typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
- // random
- //std::mt19937_64 gen(std::chrono::steady_clock::now().time_since_epoch().count());
- int gcd(int a, int b) {
- return b ? gcd(b, a % b) : a;
- }
- ll binpow(ll a, ll p, ll m) {
- if (p == 0) return 1ll;
- else if (p % 2)
- return (binpow(a, p - 1, m) * a) % m;
- else {
- ll d = binpow(a, p / 2, m);
- return (int)((d * d) % m);
- }
- }
- ll binsqrt(ll x) {
- ll l = 0;
- ll r = 1000000;
- for (int i = 0; i < 200; ++i) {
- ll m = (l + r) / 2;
- if (m * m < x) l = m;
- else r = m;
- }
- return r;
- }
- int gcd_ext(int a, int b, int& x, int& y) {
- if (b == 0) {
- x = 1;
- y = 0;
- return a;
- }
- int xx, yy, d;
- d = gcd_ext(b, a % b, xx, yy);
- x = yy;
- y = xx - (a / b) * yy;
- return d;
- }
- ll phi(ll n) {
- ll res = n;
- for (int i = 2; i * i <= n; ++i) {
- if (n % i == 0) {
- while (n % i == 0)
- n /= i;
- res -= res / i;
- }
- }
- if (n > 1)
- res -= res / n;
- return res;
- }
- void solve() {
- int n, l = -1; cin >> n;
- vi c(n); in(c);
- for (int i = 0; i < n; ++i) {
- if (c[i] == 0) {
- if (l == -1) {
- l = i;
- continue;
- } else {
- cout << "NO";
- return;
- }
- }
- if (c[i] == 2) {
- if (l == -1) {
- l = i;
- continue;
- } else if (i - l != 2) {
- cout << "NO";
- return;
- }
- }
- }
- vi a;
- for (int i = l; i < n; ++i)
- a.push_back(c[i]);
- for (int i = 0; i < l; ++i)
- a.push_back(c[i]);
- //out(a);
- for (int i = 0; i < n; ++i) {
- int cur = i + 1;
- if (abs(a[i] - cur) != 1) {
- cout << "NO";
- return;
- }
- a[i] += (a[i] > cur ? -1 : 1);
- }
- for (int i = 1; i <= n; ++i) {
- if (i != a[i - 1]) {
- cout << "NO";
- return;
- }
- }
- cout << "YES\n" << l + 1;
- }
- signed main() {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int T = 1;
- //cin >> T;
- while (T--) {
- solve();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment