QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#814839#9876. Self Checkoutthinking (Fedor Romashov, Alexey Mikhnenko, Gimran Abdullin)#AC ✓33ms28004kbC++2312.0kb2024-12-14 21:17:012024-12-14 21:17:06

Judging History

This is the latest submission verdict.

  • [2024-12-14 21:17:06]
  • Judged
  • Verdict: AC
  • Time: 33ms
  • Memory: 28004kb
  • [2024-12-14 21:17:01]
  • Submitted

answer

#pragma GCC optimize("Ofast")

#include "bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define ar array

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;

using vi = vector<int>;
using vl = vector<ll>;
using vpi = vector<pair<int, int>>;
using vvi = vector<vi>;

int Bit(int mask, int b) { return (mask >> b) & 1; }

template<class T>
bool ckmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool ckmax(T &a, const T &b) {
    if (b > a) {
        a = b;
        return true;
    }
    return false;
}

// [l, r)
template<typename T, typename F>
T FindFirstTrue(T l, T r, const F &predicat) {
    --l;
    while (r - l > 1) {
        T mid = l + (r - l) / 2;
        if (predicat(mid)) {
            r = mid;
        } else {
            l = mid;
        }
    }
    return r;
}


template<typename T, typename F>
T FindLastFalse(T l, T r, const F &predicat) {
    return FindFirstTrue(l, r, predicat) - 1;
}

const int INFi = 2e9;
const ll INF = 2e18;

/*
 ! WARNING: MOD must be prime if you use division or .inv().
 ! WARNING: 2 * (MOD - 1) must be smaller than INT_MAX
 * Use .value to get the stored value.
 */
template<typename T>
int normalize(T value, int mod) {
    if (value < -mod || value >= 2 * mod) value %= mod;
    if (value < 0) value += mod;
    if (value >= mod) value -= mod;
    return value;
}

template<int mod>
struct static_modular_int {
    static_assert(mod - 2 <= std::numeric_limits<int>::max() - mod, "2(mod - 1) <= INT_MAX");
    using mint = static_modular_int<mod>;

    int value;

    static_modular_int() : value(0) {}
    static_modular_int(const mint &x) : value(x.value) {}

    template<typename T, typename U = std::enable_if_t<std::is_integral<T>::value>>
    static_modular_int(T value) : value(normalize(value, mod)) {}

    static constexpr int get_mod() {
        return mod;
    }

    template<typename T>
    mint power(T degree) const {
        mint prod = 1, a = *this;
        for (; degree > 0; degree >>= 1, a *= a)
            if (degree & 1)
                prod *= a;

        return prod;
    }

    mint inv() const {
        return power(mod - 2);
    }

    mint& operator=(const mint &x) {
        value = x.value;
        return *this;
    }

    mint& operator+=(const mint &x) {
        value += x.value;
        if (value >= mod) value -= mod;
        return *this;
    }

    mint& operator-=(const mint &x) {
        value -= x.value;
        if (value < 0) value += mod;
        return *this;
    }

    mint& operator*=(const mint &x) {
        value = int64_t(value) * x.value % mod;
        return *this;
    }

    mint& operator/=(const mint &x) {
        return *this *= x.inv();
    }

    friend mint operator+(const mint &x, const mint &y) {
        return mint(x) += y;
    }

    friend mint operator-(const mint &x, const mint &y) {
        return mint(x) -= y;
    }

    friend mint operator*(const mint &x, const mint &y) {
        return mint(x) *= y;
    }

    friend mint operator/(const mint &x, const mint &y) {
        return mint(x) /= y;
    }

    mint& operator++() {
        ++value;
        if (value == mod) value = 0;
        return *this;
    }

    mint& operator--() {
        --value;
        if (value == -1) value = mod - 1;
        return *this;
    }

    mint operator++(int) {
        mint prev = *this;
        value++;
        if (value == mod) value = 0;
        return prev;
    }

    mint operator--(int) {
        mint prev = *this;
        value--;
        if (value == -1) value = mod - 1;
        return prev;
    }

    mint operator-() const {
        return mint(0) - *this;
    }

    bool operator==(const mint &x) const {
        return value == x.value;
    }

    bool operator!=(const mint &x) const {
        return value != x.value;
    }

    bool operator<(const mint &x) const {
        return value < x.value;
    }

    template<typename T>
    explicit operator T() {
        return value;
    }

    friend std::istream& operator>>(std::istream &in, mint &x) {
        std::string s;
        in >> s;
        x = 0;
        bool neg = s[0] == '-';
        for (const auto c : s)
            if (c != '-')
                x = x * 10 + (c - '0');

        if (neg)
            x *= -1;

        return in;
    }

    friend std::ostream& operator<<(std::ostream &out, const mint &x) {
        return out << x.value;
    }

    static int primitive_root() {
        if constexpr (mod == 1'000'000'007)
            return 5;
        if constexpr (mod == 998'244'353)
            return 3;
        if constexpr (mod == 786433)
            return 10;

        static int root = -1;
        if (root != -1)
            return root;

        std::vector<int> primes;
        int value = mod - 1;
        for (int i = 2; i * i <= value; i++)
            if (value % i == 0) {
                primes.push_back(i);
                while (value % i == 0)
                    value /= i;
            }

        if (value != 1)
            primes.push_back(value);

        for (int r = 2;; r++) {
            bool ok = true;
            for (auto p : primes)
                if ((mint(r).power((mod - 1) / p)).value == 1) {
                    ok = false;
                    break;
                }

            if (ok)
                return root = r;
        }
    }
};

// constexpr int MOD = 1'000'000'007;
 constexpr int MOD = 998'244'353;
using mint = static_modular_int<MOD>;

/*
 ! WARNING: MOD must be prime.
 * Define modular int class above it.
 * No need to run any init function, it dynamically resizes the data.
 */
namespace combinatorics {
    std::vector<mint> fact_, ifact_, inv_;

    void resize_data(int size) {
        if (fact_.empty()) {
            fact_ = {mint(1), mint(1)};
            ifact_ = {mint(1), mint(1)};
            inv_ = {mint(0), mint(1)};
        }
        for (int pos = fact_.size(); pos <= size; pos++) {
            fact_.push_back(fact_.back() * mint(pos));
            inv_.push_back(-inv_[MOD % pos] * mint(MOD / pos));
            ifact_.push_back(ifact_.back() * inv_[pos]);
        }
    }

    struct combinatorics_info {
        std::vector<mint> &data;

        combinatorics_info(std::vector<mint> &data) : data(data) {}

        mint operator[](int pos) {
            if (pos >= static_cast<int>(data.size())) {
                resize_data(pos);
            }
            return data[pos];
        }
    } fact(fact_), ifact(ifact_), inv(inv_);

    // From n choose k.
    // O(max(n)) in total.
    mint choose(int n, int k) {
        if (n < k || k < 0 || n < 0) {
            return mint(0);
        }
        return fact[n] * ifact[k] * ifact[n - k];
    }

    // From n choose k.
    // O(min(k, n - k)).
    mint choose_slow(int64_t n, int64_t k) {
        if (n < k || k < 0 || n < 0) {
            return mint(0);
        }
        k = std::min(k, n - k);
        mint result = 1;
        for (int i = k; i >= 1; i--) {
            result *= (n - i + 1);
            result *= inv[i];
        }
        return result;
    }

    // Number of balanced bracket sequences with n open and m closing brackets.
    mint catalan(int n, int m) {
        if (m > n || m < 0) {
            return mint(0);
        }
        return choose(n + m, m) - choose(n + m, m - 1);
    }

    // Number of balanced bracket sequences with n open and closing brackets.
    mint catalan(int n) {
        return catalan(n, n);
    }
} // namespace combinatorics

using namespace combinatorics;


namespace ext_combinatorics {
    // distribute n equal elements into k groups
    mint distribute(int n, int k) {
        return choose(n + k - 1, n);
    }

    // count number of seqs with n '(' and m ')' and bal always >= 0
    mint catalan_nm(int n, int m) {
        assert(n >= m);
        return choose(m + n, m) - choose(m + n, m - 1);
    }

    mint catalan(int n) {
        return catalan_nm(n, n);
    }

    // count number of bracket seqs, bal always >= 0
    mint catalan_bal(int n, int start_balance = 0, int end_balance = 0) {
        if ((n + start_balance + end_balance) % 2 != 0) return 0;
        if (start_balance < 0 || end_balance < 0) return 0;
        return choose(n, (n + end_balance - start_balance) / 2) - choose(n, (n - end_balance - start_balance - 2) / 2);
    }

    // from (0, 0) to (x, y)
    mint grid_path(int x, int y) {
        return choose(x + y, x);
    }

    // from (0, 0) to (x, y) not touch low y=x+b
    mint grid_path_low(int x, int y, int b) {
        if (b >= 0) return 0;
        return grid_path(x, y) - grid_path(y - b, x + b);
    }

    // from (0, 0) to (x, y) not touch up y=x+b
    // O((x + y) / |b2 - b1|)
    mint grid_path_up(int x, int y, int b) {
        if (b <= 0) return 0;
        return grid_path(x, y) - grid_path(y - b, x + b);
    }

    // from (0, 0) to (x, y) touch L -LU +LUL -LULU ....
    // O((x + y) / |b2 - b1|)
    mint grid_calc_LUL(int x, int y, int b1, int b2) {
        swap(x, y);
        x -= b1;
        y += b1;
        if (x < 0 || y < 0) return 0;
        return grid_path(x, y) - grid_calc_LUL(y, x, -b2, -b1);
    }

    // from (0, 0) to (x, y) not touch low y=x+b1, up y=x+b2
    // O((x + y) / |b2 - b1|)
    mint grid_path_2(int x, int y, int b1, int b2) {
        return grid_path(x, y) - grid_calc_LUL(x, y, b1, b2) - grid_calc_LUL(y, x, -b2, -b1);
    }

    // probability what we end in L+R after infinity random walk, if we start at L, and absorbing points is 0, L+R.
    mint gambler_ruin_right(int L, int R, mint p_right) {
        assert(L >= 1 && R >= 1);
        if (p_right * 2 == 1) return mint(L) / mint(L + R);
        if (p_right == 1) return 1;
        if (p_right == 0) return 0;
        mint v = (1 - p_right) / p_right;
        return (1 - v.power(L)) / (1 - v.power(L + R));
    }

    mint gambler_ruin_left(int L, int R, mint p_left) {
        return 1 - gambler_ruin_right(L, R, 1 - p_left);
    }
} // namespace ext_combinatorics

using ext_combinatorics::grid_path_low;

void solve() {
    int n; cin >> n;
    vector<char> s(n);
    rep(i, n) cin >> s[i];

    int m = n;
    map<int, mint> dp;
    if (s.back() == '1') {
        if (count(all(s), '1') != 1) {
            cout << "0\n";
            return;
        }
        m--;
        dp[0] = 1;
    } else {
        if (count(all(s), '1') != 0) {
            cout << "0\n";
            return;
        }
        int cnt = 0;
        while (cnt < n && s[n - 1 - cnt] == '2') cnt++;
        if (!cnt) {
            dp[0] = 1;
        } else {

            m = n - cnt;
            dp[0] = cnt;
            dp[cnt] = 1;
        }
    }

    mint ans = 0;

    while (m != 0) {
        int cnt = 0;
        while (cnt < m && s[m - 1 - cnt] == '3') cnt++;

        map<int, mint> dp2;
        if (cnt < m) {
            assert(s[m - 1 - cnt] == '2');
            for(auto &[bal, ways] : dp) {
                dp2[0] += grid_path_low(cnt, cnt + bal + 1, -1) * ways;
            }
            swap(dp, dp2);
            m -= cnt;
            m--;
        } else {
            for(auto &[bal, ways] : dp) {
                ans += ways * grid_path_low(cnt, cnt + 1 + bal, -1);
            }
            swap(dp, dp2);
            m -= cnt;
        }
    }
    for(auto &[bal, ways] : dp) ans += ways;
    cout << ans << '\n';
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(8) << fixed;
    int t = 1;
//    cin >> t;
    rep(i, t) {
        solve();
    }
    return 0;
}

/*
 * 3
7 1 14 3 9 4 8 2 6 5 5 13 8 2 3
1
2 4 8

 */

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3512kb

input:

2
3 2

output:

5

result:

ok "5"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

6
3 2 2 3 2 1

output:

4

result:

ok "4"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3824kb

input:

5
3 2 1 3 2

output:

0

result:

ok "0"

Test #4:

score: 0
Accepted
time: 4ms
memory: 4268kb

input:

1000000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

0

result:

ok "0"

Test #5:

score: 0
Accepted
time: 7ms
memory: 3876kb

input:

743956
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

0

result:

ok "0"

Test #6:

score: 0
Accepted
time: 32ms
memory: 28004kb

input:

1000000
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ...

output:

686017352

result:

ok "686017352"

Test #7:

score: 0
Accepted
time: 31ms
memory: 27600kb

input:

1000000
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ...

output:

40768340

result:

ok "40768340"

Test #8:

score: 0
Accepted
time: 29ms
memory: 4100kb

input:

1000000
3 2 3 2 3 2 2 2 2 3 2 2 3 3 2 3 3 3 3 2 2 2 3 2 2 3 3 3 3 3 3 2 2 2 2 3 2 3 2 3 2 3 3 3 3 2 2 3 3 2 2 2 2 3 2 3 2 3 2 3 2 2 2 3 2 2 3 2 3 3 2 2 2 3 3 3 3 2 2 3 3 3 3 3 3 3 2 3 2 2 2 3 3 2 2 2 2 2 3 3 3 3 2 3 3 2 3 2 2 3 3 3 2 2 2 3 2 2 3 2 3 3 3 2 3 3 2 2 3 2 3 3 2 2 2 2 3 2 3 3 2 2 3 3 3 2 ...

output:

524330066

result:

ok "524330066"

Test #9:

score: 0
Accepted
time: 25ms
memory: 4200kb

input:

1000000
3 2 3 3 2 3 2 3 3 3 3 3 3 3 3 3 2 2 3 2 2 3 2 2 3 3 2 3 3 2 3 2 2 3 3 3 3 3 2 2 2 2 3 2 2 2 2 3 2 3 3 2 2 2 3 3 3 3 3 2 2 3 3 3 3 3 2 3 2 3 2 3 2 2 3 3 2 3 2 3 3 3 3 2 2 3 2 2 3 3 3 3 3 2 2 2 3 3 3 3 3 3 3 3 2 2 2 3 2 3 2 2 2 3 2 2 3 2 2 2 3 2 3 2 3 3 2 2 2 2 2 3 2 3 2 3 2 3 2 2 2 2 2 2 2 3 ...

output:

759933131

result:

ok "759933131"

Test #10:

score: 0
Accepted
time: 30ms
memory: 4124kb

input:

1000000
3 3 3 2 3 3 2 2 3 3 3 2 2 2 3 3 2 3 3 2 3 2 2 3 3 3 2 2 3 3 3 2 3 2 2 3 3 3 3 3 3 2 2 3 3 3 3 2 2 2 2 3 2 2 3 3 3 3 3 2 3 2 3 3 3 3 2 2 3 3 2 2 2 3 2 2 2 3 3 2 2 2 2 3 2 3 3 2 2 3 2 3 3 3 2 2 3 3 3 3 2 3 2 3 2 3 2 2 2 3 3 2 2 2 2 3 3 3 3 2 2 3 2 3 3 3 3 3 3 3 3 2 2 3 3 3 3 2 2 2 2 3 3 2 2 3 ...

output:

7146987

result:

ok "7146987"

Test #11:

score: 0
Accepted
time: 29ms
memory: 4144kb

input:

1000000
3 3 3 2 2 2 2 3 3 3 3 3 2 3 2 2 3 2 2 2 2 3 3 3 3 3 2 2 2 2 3 2 3 3 2 2 2 3 2 2 3 3 2 2 2 2 2 2 2 2 3 3 2 3 3 3 2 3 2 2 3 2 2 2 3 2 3 3 2 3 2 2 2 2 3 2 3 3 2 2 2 3 2 2 2 3 2 3 3 2 2 2 3 3 2 2 2 3 2 3 2 2 3 3 2 3 3 3 2 2 2 2 2 3 2 2 2 3 3 2 2 2 2 3 2 2 3 2 3 3 3 3 2 2 2 3 2 3 2 3 2 3 2 2 3 2 ...

output:

683068701

result:

ok "683068701"

Test #12:

score: 0
Accepted
time: 29ms
memory: 4272kb

input:

1000000
2 2 2 2 3 3 2 3 3 3 3 3 3 2 3 2 2 2 2 2 3 2 2 2 3 2 2 2 3 2 3 2 3 2 2 2 2 2 3 2 3 3 3 2 2 3 3 2 2 2 2 2 3 3 3 3 2 2 3 2 2 2 2 2 3 2 2 3 3 2 2 2 3 3 2 3 3 3 3 2 3 2 3 3 2 3 3 3 2 2 2 2 2 2 2 2 3 3 3 2 3 2 3 2 2 2 3 2 2 3 2 2 3 3 2 2 3 2 3 2 2 2 3 3 2 3 2 3 3 2 2 2 2 3 3 3 2 2 2 3 3 3 2 2 3 3 ...

output:

2294624

result:

ok "2294624"

Test #13:

score: 0
Accepted
time: 19ms
memory: 3840kb

input:

637586
2 2 2 2 2 2 3 2 2 2 3 3 2 2 3 3 2 2 2 3 3 3 2 3 2 2 3 3 3 2 3 3 3 3 3 2 3 2 3 3 3 2 3 2 2 3 3 2 3 2 3 2 2 2 3 3 3 2 3 3 2 3 2 2 3 2 2 2 2 3 3 2 2 3 3 3 2 2 3 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 2 3 3 2 2 2 3 3 3 2 3 2 3 3 3 2 2 2 3 2 2 3 2 3 3 3 3 2 3 2 3 2 3 2 3 3 2 2 3 2 3 2 2 3 2 2 3 3 2 3...

output:

710149533

result:

ok "710149533"

Test #14:

score: 0
Accepted
time: 21ms
memory: 3832kb

input:

731846
3 3 2 2 2 3 2 2 2 2 3 3 3 2 3 3 2 2 3 3 3 3 2 3 2 3 2 2 2 2 3 3 3 3 2 3 3 2 3 3 3 2 3 3 3 3 3 3 2 2 3 2 3 2 2 2 2 3 3 2 3 3 3 3 2 3 3 3 2 3 2 3 3 3 3 2 3 2 2 2 2 3 3 2 2 2 3 2 3 3 3 3 2 2 3 2 3 3 3 3 3 3 2 3 3 2 3 3 2 2 2 2 3 3 2 3 2 2 2 3 3 2 2 3 3 3 2 2 2 3 3 2 2 2 3 2 2 3 3 2 2 3 2 2 3 3 2...

output:

175239255

result:

ok "175239255"

Test #15:

score: 0
Accepted
time: 7ms
memory: 3520kb

input:

234456
3 2 2 3 2 2 3 3 2 2 3 2 2 3 2 3 2 3 3 2 3 2 2 3 2 2 3 2 2 3 3 2 2 2 2 3 3 2 2 3 3 2 2 2 2 3 2 3 2 3 2 2 2 2 2 3 3 2 2 3 2 3 2 2 2 2 3 2 2 3 2 3 2 3 2 3 2 3 2 2 2 3 3 3 3 2 2 2 2 2 2 3 3 2 3 3 3 3 3 2 2 3 3 3 2 2 2 3 3 3 2 2 3 3 2 2 3 3 3 2 3 3 2 2 3 2 2 2 3 2 2 3 2 3 2 2 3 2 3 3 3 3 2 3 3 2 3...

output:

178259636

result:

ok "178259636"

Test #16:

score: 0
Accepted
time: 15ms
memory: 3600kb

input:

614641
3 2 3 2 2 2 2 2 3 2 2 2 2 3 2 2 3 3 3 3 2 2 3 3 2 2 2 2 2 2 3 2 3 2 3 2 3 3 3 3 3 3 3 3 2 2 2 2 3 3 3 3 2 3 2 2 2 3 3 2 2 3 3 2 3 2 2 2 3 2 2 2 3 2 2 2 2 3 3 3 3 2 3 3 3 2 3 2 2 3 2 3 2 3 3 3 3 2 3 2 3 3 3 3 3 3 3 3 3 3 2 2 3 3 2 3 3 2 2 2 2 3 3 2 2 3 2 3 3 3 2 2 2 2 2 3 2 3 3 3 3 3 2 2 3 2 3...

output:

590475478

result:

ok "590475478"

Test #17:

score: 0
Accepted
time: 16ms
memory: 3852kb

input:

550862
3 3 3 2 2 2 2 2 3 2 3 2 3 3 3 3 2 3 2 3 2 3 3 3 2 3 3 2 3 2 3 2 3 3 3 2 3 2 3 3 3 2 2 2 3 2 3 2 2 2 2 3 2 3 3 3 2 2 3 2 3 2 2 2 3 2 3 3 3 3 3 3 2 2 2 3 3 3 2 3 3 3 2 2 3 3 3 3 2 3 3 3 2 3 2 3 3 2 2 2 3 3 2 2 2 3 2 2 3 2 3 2 3 3 2 2 3 3 3 3 3 2 2 3 2 2 3 2 2 2 3 2 3 2 3 2 3 2 2 2 2 3 2 3 3 2 3...

output:

496316643

result:

ok "496316643"

Test #18:

score: 0
Accepted
time: 4ms
memory: 4124kb

input:

1000000
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...

output:

1000001

result:

ok "1000001"

Test #19:

score: 0
Accepted
time: 1ms
memory: 3744kb

input:

108766
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2...

output:

108767

result:

ok "108767"

Test #20:

score: 0
Accepted
time: 14ms
memory: 15252kb

input:

1000000
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ...

output:

403803660

result:

ok "403803660"

Test #21:

score: 0
Accepted
time: 19ms
memory: 10288kb

input:

1000000
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ...

output:

207755525

result:

ok "207755525"

Test #22:

score: 0
Accepted
time: 6ms
memory: 4168kb

input:

1000000
3 2 2 2 2 2 3 2 3 3 2 3 2 2 2 3 3 3 2 3 3 3 2 3 2 3 2 2 3 3 3 3 3 2 3 3 2 3 3 3 2 3 2 2 2 3 2 2 2 2 2 3 2 3 3 3 3 2 3 2 2 3 3 2 3 3 3 2 2 3 2 3 3 3 3 2 2 3 2 3 2 3 2 3 2 3 2 2 2 2 3 3 2 2 2 2 3 2 2 3 2 2 2 3 2 2 3 2 2 3 3 2 3 3 3 2 2 3 3 2 3 2 3 3 2 2 3 3 2 2 2 2 2 2 3 2 3 2 2 3 3 3 3 2 2 3 ...

output:

0

result:

ok "0"

Test #23:

score: 0
Accepted
time: 6ms
memory: 4100kb

input:

1000000
2 2 3 2 3 3 3 2 2 2 2 3 2 3 3 3 2 2 3 3 2 2 2 3 3 2 3 3 2 3 3 2 2 3 2 2 2 2 2 2 2 3 3 3 2 2 3 2 2 3 2 3 3 3 2 3 2 2 3 3 3 2 3 3 3 3 3 2 2 3 2 2 3 3 3 3 2 2 3 3 3 3 3 3 2 3 3 2 2 2 3 3 3 2 2 3 2 2 2 2 2 3 2 3 2 3 2 3 2 2 3 2 3 2 2 3 3 3 3 3 3 3 3 3 3 2 2 3 3 3 2 2 3 2 2 3 2 3 3 2 3 3 2 3 2 2 ...

output:

0

result:

ok "0"

Test #24:

score: 0
Accepted
time: 6ms
memory: 4188kb

input:

1000000
3 2 2 3 3 2 2 2 3 3 3 2 3 3 2 3 3 3 3 2 2 2 3 3 3 2 2 3 3 2 2 2 2 2 2 2 2 2 2 3 2 2 3 2 2 3 2 3 3 3 3 3 3 3 3 2 3 3 3 3 2 3 2 3 2 3 3 2 2 3 2 3 3 2 3 3 3 3 3 2 3 2 3 3 2 2 2 2 2 2 3 2 2 3 2 2 2 2 3 2 3 3 2 3 2 2 3 2 2 3 3 3 2 2 2 2 2 3 3 3 2 2 2 2 3 3 3 2 3 2 3 3 2 2 2 2 3 2 3 2 2 2 3 2 2 3 ...

output:

0

result:

ok "0"

Test #25:

score: 0
Accepted
time: 6ms
memory: 4252kb

input:

1000000
3 3 2 2 2 2 2 2 2 3 2 2 2 2 3 3 2 3 2 2 3 2 3 2 2 3 2 3 3 3 2 2 3 2 3 2 2 2 2 2 2 3 2 3 3 3 3 3 2 2 3 3 2 2 3 2 2 3 2 2 3 2 3 3 2 3 3 2 3 2 3 3 3 2 2 3 3 3 2 3 2 2 2 3 3 2 2 2 2 2 3 2 3 3 2 3 3 2 2 2 3 2 2 3 3 2 3 2 2 2 3 2 3 3 3 2 3 2 2 3 2 3 2 2 3 3 2 3 3 2 2 2 3 2 2 3 2 3 3 2 2 3 2 2 3 2 ...

output:

0

result:

ok "0"

Test #26:

score: 0
Accepted
time: 9ms
memory: 4148kb

input:

1000000
3 3 2 3 2 2 2 2 3 2 2 2 3 2 2 3 3 2 3 2 3 3 2 2 2 3 2 3 3 3 2 2 3 2 3 3 3 2 2 3 3 3 2 3 2 3 2 2 2 3 2 3 3 3 2 2 3 3 3 2 3 2 2 2 3 3 3 2 3 2 2 3 3 2 2 2 3 2 2 2 2 2 3 2 2 2 3 2 2 2 3 2 2 2 2 3 2 3 3 3 3 3 3 3 2 3 3 2 3 2 2 3 3 3 2 3 2 3 2 3 3 3 3 3 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 2 2 3 2 3 2 2 ...

output:

0

result:

ok "0"

Test #27:

score: 0
Accepted
time: 5ms
memory: 3596kb

input:

511376
3 2 2 2 2 2 3 3 2 3 2 2 2 3 2 3 3 3 2 2 3 3 3 2 2 2 2 3 3 2 2 3 2 3 3 3 3 3 2 3 2 3 2 3 2 3 2 2 3 3 3 3 3 2 3 2 3 2 3 3 3 3 3 3 3 3 3 2 2 3 2 2 3 2 3 3 2 2 2 3 2 3 2 3 2 2 2 2 2 2 3 3 2 2 3 3 3 2 2 2 3 3 3 2 2 2 2 3 2 2 2 3 3 2 2 2 3 3 2 2 3 2 2 3 3 3 3 3 3 3 3 3 2 3 2 2 3 3 2 2 2 2 2 2 3 3 3...

output:

0

result:

ok "0"

Test #28:

score: 0
Accepted
time: 1ms
memory: 3768kb

input:

104296
3 3 2 3 3 2 3 3 3 3 2 3 3 2 3 2 3 3 2 2 2 2 3 3 3 3 2 3 3 3 3 3 3 2 2 3 2 3 2 2 2 3 3 2 2 3 3 3 2 3 3 2 3 2 3 2 2 2 2 3 3 3 2 2 3 2 3 2 2 3 3 2 2 2 2 3 2 3 3 3 2 3 2 2 2 2 2 2 2 3 3 3 2 3 3 2 2 3 3 3 2 3 2 2 3 2 3 3 2 2 2 2 3 2 2 2 2 2 2 2 2 3 3 3 3 2 2 3 2 2 3 2 3 3 3 3 3 2 2 3 3 2 2 3 2 3 2...

output:

0

result:

ok "0"

Test #29:

score: 0
Accepted
time: 1ms
memory: 3784kb

input:

119245
2 2 2 3 2 2 2 3 2 2 3 2 3 3 3 2 3 2 2 2 3 2 3 2 2 3 2 2 2 2 3 3 2 3 3 3 2 3 3 2 2 3 2 3 3 3 3 2 3 3 2 2 3 3 2 2 3 3 3 3 3 2 2 2 3 2 2 2 3 3 2 3 3 2 3 3 2 2 2 2 3 2 3 2 2 2 2 3 2 2 3 2 2 2 3 3 3 3 3 3 2 3 3 2 3 2 2 3 2 3 3 3 3 3 2 3 2 3 3 3 2 2 2 3 2 2 3 2 3 2 3 2 2 2 2 3 2 3 3 2 2 3 3 3 2 2 3...

output:

0

result:

ok "0"

Test #30:

score: 0
Accepted
time: 5ms
memory: 3864kb

input:

499896
2 3 3 3 2 2 3 3 3 2 2 3 3 3 2 3 2 3 2 3 3 3 2 3 3 3 2 3 3 3 3 3 2 3 2 2 2 3 3 3 2 3 3 3 2 2 3 2 3 2 3 2 2 2 3 3 3 3 2 3 3 3 2 3 3 2 3 3 3 2 2 2 2 2 3 2 2 3 2 2 2 2 3 3 3 2 2 3 3 2 2 3 3 3 2 3 3 3 2 3 3 3 2 3 3 2 3 2 3 3 2 3 2 3 2 2 3 3 3 3 2 3 3 2 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 2 3 3 3 3 3 2 2...

output:

0

result:

ok "0"

Test #31:

score: 0
Accepted
time: 4ms
memory: 3852kb

input:

870424
3 3 3 3 3 2 3 3 2 3 2 3 2 2 3 2 3 2 2 3 3 2 3 2 3 3 2 2 3 2 3 3 3 3 3 3 3 3 3 3 3 2 2 3 3 3 3 3 2 3 2 2 2 3 2 2 3 2 2 2 3 2 2 2 2 2 3 2 2 2 2 3 3 3 3 3 3 3 2 2 2 2 3 2 2 3 3 3 2 3 2 3 3 2 2 2 2 3 3 2 3 2 3 2 3 3 3 2 3 3 3 3 2 3 3 2 3 2 2 3 2 2 2 3 3 2 3 3 2 2 2 3 2 3 2 2 2 3 2 2 2 2 3 2 3 2 3...

output:

0

result:

ok "0"

Test #32:

score: 0
Accepted
time: 32ms
memory: 27564kb

input:

1000000
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ...

output:

686017352

result:

ok "686017352"

Test #33:

score: 0
Accepted
time: 0ms
memory: 6112kb

input:

100432
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3...

output:

848135413

result:

ok "848135413"

Test #34:

score: 0
Accepted
time: 10ms
memory: 4120kb

input:

1000000
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ...

output:

481078003

result:

ok "481078003"

Test #35:

score: 0
Accepted
time: 10ms
memory: 4140kb

input:

1000000
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ...

output:

429280846

result:

ok "429280846"

Test #36:

score: 0
Accepted
time: 6ms
memory: 4140kb

input:

1000000
2 2 3 2 3 3 2 2 1 3 2 2 3 2 1 3 2 1 2 1 3 1 1 2 1 3 3 1 2 2 1 2 2 1 2 2 2 2 1 3 3 1 2 3 2 1 2 1 3 1 2 2 2 2 2 3 1 2 2 3 2 2 1 3 3 2 3 2 3 2 1 1 2 3 1 1 3 2 3 1 1 2 1 2 1 2 2 3 2 3 1 2 1 3 2 3 1 1 2 3 1 2 3 1 3 2 2 2 3 1 2 2 2 3 2 3 1 3 3 2 2 2 2 3 3 3 2 2 1 3 1 3 1 1 3 2 1 3 2 1 1 3 1 2 1 1 ...

output:

0

result:

ok "0"

Test #37:

score: 0
Accepted
time: 10ms
memory: 4128kb

input:

1000000
2 3 2 1 2 2 1 1 2 3 3 2 2 3 1 3 3 3 2 2 3 1 3 3 2 1 1 1 1 3 2 1 2 2 2 3 1 3 2 2 2 3 2 2 2 2 1 2 2 1 1 1 1 1 1 1 1 3 1 1 3 1 2 2 1 1 2 1 1 3 3 2 3 3 2 2 2 2 3 1 2 1 1 2 1 1 3 3 3 2 2 1 3 3 1 3 2 2 2 2 3 3 3 1 2 3 2 2 1 1 2 2 2 3 2 3 1 3 2 3 2 1 2 1 1 3 3 1 2 1 2 1 2 2 2 3 2 3 3 2 1 2 1 2 1 2 ...

output:

0

result:

ok "0"

Test #38:

score: 0
Accepted
time: 9ms
memory: 4200kb

input:

1000000
3 1 3 1 1 1 1 2 2 2 1 3 3 2 2 3 2 3 3 2 3 3 3 2 2 1 3 3 3 3 3 2 3 2 3 1 1 1 2 2 1 1 3 2 3 1 3 3 1 2 3 3 2 2 1 3 1 1 1 2 3 2 1 1 3 2 2 3 3 3 2 3 1 3 3 2 3 2 1 1 2 2 3 1 1 2 3 2 2 3 1 3 2 3 2 2 2 1 3 3 1 2 3 1 3 3 1 2 2 2 1 3 2 3 3 2 2 3 1 3 3 3 3 3 3 1 1 2 1 1 3 2 1 1 1 1 1 3 2 3 1 3 3 3 3 2 ...

output:

0

result:

ok "0"

Test #39:

score: 0
Accepted
time: 9ms
memory: 4140kb

input:

1000000
2 2 2 2 3 2 1 2 2 1 1 2 3 1 1 1 2 2 3 3 2 1 3 3 2 1 3 3 1 2 2 2 2 1 1 2 2 1 3 1 3 1 3 3 1 2 3 2 2 3 1 2 3 2 3 3 3 1 3 2 1 2 2 3 2 1 3 3 3 3 1 1 2 2 3 1 3 1 2 1 2 3 3 3 2 3 1 2 2 2 2 2 3 3 2 2 3 2 1 1 2 3 1 1 2 1 2 1 3 2 3 2 2 2 2 1 1 3 1 2 1 3 2 1 2 1 2 3 3 1 2 2 3 1 3 3 3 2 1 1 2 3 1 3 1 2 ...

output:

0

result:

ok "0"

Test #40:

score: 0
Accepted
time: 9ms
memory: 4104kb

input:

1000000
2 1 2 1 3 3 2 2 1 1 1 3 2 3 3 2 2 2 1 3 2 1 3 2 2 2 3 3 1 1 2 2 2 2 3 2 2 1 1 2 2 2 1 2 2 1 1 2 2 2 2 2 2 3 2 1 1 1 1 1 1 3 1 2 1 3 3 3 2 3 1 3 2 3 2 1 1 2 3 3 3 3 2 1 2 3 2 2 1 1 1 3 2 1 1 1 2 1 1 1 2 1 2 2 3 2 1 3 2 3 1 1 2 1 2 3 1 3 1 3 3 1 2 2 3 1 1 2 3 1 1 1 3 2 2 3 3 3 2 2 2 2 2 3 1 2 ...

output:

0

result:

ok "0"

Test #41:

score: 0
Accepted
time: 4ms
memory: 4116kb

input:

897920
2 2 1 1 3 1 1 2 1 2 2 2 2 3 2 1 3 3 3 3 1 1 3 3 3 3 3 1 2 1 2 1 2 3 1 2 2 2 3 2 2 1 2 2 1 2 2 1 2 1 3 1 3 3 1 1 3 2 3 3 3 3 1 3 1 1 2 2 1 1 2 1 3 3 2 3 3 1 3 2 3 1 2 2 2 3 1 2 2 1 3 2 3 3 3 1 2 1 1 1 3 1 2 3 3 1 1 2 1 2 2 2 2 2 1 1 3 3 3 3 2 1 1 3 1 1 2 1 1 1 1 3 3 3 3 3 2 1 1 1 3 1 1 3 2 1 1...

output:

0

result:

ok "0"

Test #42:

score: 0
Accepted
time: 6ms
memory: 3836kb

input:

685690
1 2 3 2 3 3 2 1 3 2 3 3 3 2 1 2 1 3 2 3 2 1 2 3 3 2 2 2 1 1 1 1 2 1 3 1 1 3 1 1 3 3 1 1 2 1 2 3 1 3 2 2 2 1 1 3 2 1 2 2 3 2 3 3 3 2 3 3 2 2 2 3 2 1 3 1 2 1 1 1 3 2 3 1 3 2 1 3 2 1 1 2 3 2 2 1 2 3 2 1 2 3 2 3 3 3 2 1 2 3 2 3 2 1 2 3 1 1 1 2 1 3 3 2 1 3 3 2 2 3 3 1 3 2 2 1 3 1 2 3 2 3 1 1 2 2 2...

output:

0

result:

ok "0"

Test #43:

score: 0
Accepted
time: 6ms
memory: 4016kb

input:

664461
3 3 3 3 1 2 1 1 3 1 3 3 1 2 2 3 3 3 2 3 1 2 1 3 1 1 3 1 1 2 1 1 1 1 3 1 1 3 3 1 3 2 3 3 3 2 2 2 1 3 1 1 2 1 1 3 1 3 2 2 3 3 3 1 2 3 3 3 3 2 2 1 3 1 2 1 3 1 2 3 1 3 1 3 1 1 1 3 3 2 1 3 2 2 1 2 3 1 2 1 2 1 1 2 2 2 1 1 1 1 1 1 2 1 3 1 1 2 1 1 1 2 3 3 2 3 2 2 1 1 1 2 1 1 3 1 2 2 2 1 1 3 3 3 1 1 3...

output:

0

result:

ok "0"

Test #44:

score: 0
Accepted
time: 9ms
memory: 4168kb

input:

900750
2 3 2 3 1 1 1 2 1 3 2 2 1 1 1 3 2 2 2 3 1 3 1 1 3 2 3 2 2 3 3 1 2 2 2 2 2 3 1 2 1 1 2 2 1 2 1 2 1 3 2 3 2 3 1 1 3 3 1 2 3 3 1 1 3 3 1 2 2 2 2 3 1 1 3 1 3 2 2 1 2 1 3 1 2 3 1 3 1 1 1 3 2 2 1 3 3 1 3 3 3 1 3 3 3 2 2 3 2 3 3 1 3 2 3 1 2 3 2 3 2 2 1 1 3 3 2 3 2 1 1 2 1 1 1 1 2 1 1 2 3 2 3 2 3 2 3...

output:

0

result:

ok "0"

Test #45:

score: 0
Accepted
time: 2ms
memory: 3632kb

input:

190397
3 1 3 2 3 2 1 1 1 3 2 2 1 1 2 3 1 2 1 1 2 2 1 2 2 3 3 2 2 3 1 2 3 1 1 3 1 3 3 1 1 3 1 2 2 1 1 3 3 2 1 3 1 3 3 3 2 1 2 3 2 3 2 2 1 3 3 3 1 2 2 3 1 3 2 2 3 1 2 2 2 1 2 2 2 3 1 2 1 1 2 3 1 1 3 1 2 1 3 3 1 3 1 1 1 2 1 3 3 3 2 2 2 3 2 3 1 1 3 3 3 2 3 3 2 2 2 3 2 1 2 3 2 3 3 2 3 3 1 2 3 1 2 1 3 2 2...

output:

0

result:

ok "0"

Test #46:

score: 0
Accepted
time: 27ms
memory: 27020kb

input:

1000000
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ...

output:

831727446

result:

ok "831727446"

Test #47:

score: 0
Accepted
time: 33ms
memory: 15908kb

input:

1000000
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ...

output:

122657581

result:

ok "122657581"

Test #48:

score: 0
Accepted
time: 4ms
memory: 4140kb

input:

1000000
1 2 2 1 1 1 2 1 3 2 1 3 1 3 2 3 1 1 1 2 2 2 3 2 1 3 1 2 2 3 2 3 1 2 2 1 1 3 3 3 2 3 1 2 1 1 2 1 3 3 3 1 2 3 3 3 1 1 2 1 3 1 2 1 1 1 1 2 2 1 3 3 1 2 1 1 3 3 3 2 3 3 1 2 2 2 1 3 2 3 3 2 2 1 1 2 3 2 1 1 3 2 2 3 1 1 3 1 2 1 1 2 2 2 1 2 2 3 3 2 2 2 2 1 3 1 3 3 2 1 3 1 3 3 2 1 3 2 2 3 2 1 1 2 3 3 ...

output:

0

result:

ok "0"

Test #49:

score: 0
Accepted
time: 9ms
memory: 4164kb

input:

1000000
2 2 3 2 2 2 1 2 1 2 1 2 3 1 3 1 3 2 1 3 3 3 3 1 1 1 2 1 3 3 3 2 2 2 1 1 3 3 1 2 2 1 3 3 1 2 3 2 3 1 3 2 3 2 2 3 2 1 3 3 1 3 3 3 3 1 1 1 3 2 3 2 2 2 1 3 1 2 3 2 3 2 1 1 2 2 3 2 1 3 3 2 2 2 3 2 1 1 1 3 2 2 1 3 3 3 3 3 1 3 2 2 1 1 3 3 2 1 2 2 2 1 2 2 2 3 3 3 3 1 1 1 3 2 1 2 2 1 2 2 3 2 3 1 2 1 ...

output:

0

result:

ok "0"

Test #50:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

8
2 2 1 1 2 1 2 2

output:

0

result:

ok "0"

Test #51:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

4
1 2 1 2

output:

0

result:

ok "0"

Test #52:

score: 0
Accepted
time: 28ms
memory: 17684kb

input:

1000000
3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...

output:

2999999

result:

ok "2999999"

Test #53:

score: 0
Accepted
time: 31ms
memory: 4096kb

input:

1000000
3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...

output:

2

result:

ok "2"

Test #54:

score: 0
Accepted
time: 30ms
memory: 4204kb

input:

1000000
2 3 3 2 3 2 3 3 2 3 2 2 3 3 3 2 3 2 2 3 3 2 2 3 3 2 3 3 2 2 2 3 2 3 2 3 3 3 2 2 2 3 2 2 2 2 3 2 3 2 3 2 2 2 3 3 3 3 3 2 3 3 3 2 2 2 3 3 3 2 3 2 3 3 3 3 3 3 2 2 2 2 3 3 3 2 3 2 3 3 2 2 3 2 2 3 2 2 3 3 2 2 2 2 2 3 3 2 3 2 3 3 2 3 3 3 2 2 2 2 3 2 2 2 3 3 2 2 2 2 2 3 3 3 3 3 3 3 3 2 2 3 2 3 2 3 ...

output:

820447236

result:

ok "820447236"

Test #55:

score: 0
Accepted
time: 26ms
memory: 4200kb

input:

1000000
2 2 3 3 3 3 3 3 3 3 2 2 3 3 2 2 2 3 3 3 2 2 3 2 2 3 3 3 3 3 3 2 2 3 3 3 3 3 3 3 3 3 3 2 3 3 2 2 2 3 2 3 2 2 2 3 3 3 2 3 3 3 2 2 2 3 3 2 2 2 2 2 2 3 3 2 3 2 3 2 3 3 2 3 3 3 2 3 2 3 2 2 3 2 2 3 3 2 3 2 2 3 3 2 2 2 2 3 3 3 2 3 2 3 3 3 2 3 3 3 3 3 2 3 3 2 3 2 3 3 3 3 3 3 3 3 3 2 2 2 3 2 2 3 3 3 ...

output:

748187707

result:

ok "748187707"

Test #56:

score: 0
Accepted
time: 29ms
memory: 4120kb

input:

1000000
3 2 2 2 2 2 3 2 2 2 3 3 3 3 3 2 2 2 3 3 2 3 2 3 2 3 2 2 3 3 2 2 3 2 3 2 2 2 2 2 2 2 2 2 2 2 3 3 2 2 2 2 3 2 2 2 2 2 3 2 2 3 2 2 3 3 3 2 2 3 2 2 2 2 2 2 3 2 3 3 3 3 2 3 2 2 3 2 3 2 3 3 2 2 3 2 3 2 3 2 2 2 3 3 2 3 2 2 2 2 2 2 2 2 2 3 3 3 2 2 3 3 2 3 3 2 2 2 2 2 2 2 2 3 3 3 2 2 2 3 3 3 2 2 3 2 ...

output:

232126478

result:

ok "232126478"

Test #57:

score: 0
Accepted
time: 29ms
memory: 4124kb

input:

1000000
2 3 2 2 3 2 3 3 2 2 3 2 2 2 2 3 3 2 2 3 2 3 2 3 2 3 2 3 3 3 3 2 3 3 2 2 3 2 2 2 2 3 3 3 2 3 3 2 2 2 2 2 2 3 3 3 3 2 3 2 3 2 3 2 2 2 2 3 3 2 2 3 3 3 3 2 3 2 3 2 3 2 3 3 3 2 3 3 2 3 2 2 3 3 3 2 2 2 2 3 3 2 2 2 2 2 2 2 3 2 3 3 3 2 2 3 3 3 3 3 2 2 2 2 3 2 2 3 2 3 3 2 2 2 3 3 3 2 3 3 2 3 2 2 2 3 ...

output:

766356020

result:

ok "766356020"

Test #58:

score: 0
Accepted
time: 30ms
memory: 4172kb

input:

1000000
2 3 3 2 2 2 2 2 2 2 3 2 2 3 3 2 2 3 2 3 2 2 3 2 3 2 2 3 2 3 2 2 2 2 2 2 2 2 2 3 3 2 3 3 2 3 3 2 2 3 2 2 3 2 3 3 2 2 2 2 2 3 3 3 3 2 3 3 3 3 2 3 2 2 3 3 3 2 2 2 2 2 3 3 2 2 2 2 2 3 2 3 2 3 2 3 3 2 2 3 2 3 2 2 2 2 3 3 2 3 3 2 2 2 2 2 3 3 3 2 2 2 2 2 2 2 2 3 3 3 2 3 2 3 3 3 2 3 3 2 3 3 3 2 3 2 ...

output:

667015541

result:

ok "667015541"

Test #59:

score: 0
Accepted
time: 9ms
memory: 3564kb

input:

287217
3 3 3 2 2 2 2 3 2 2 2 2 3 2 2 3 3 3 3 3 3 3 2 2 2 2 3 2 2 3 3 2 2 2 3 3 3 2 2 3 2 2 3 2 3 3 2 2 2 3 3 2 2 2 3 2 3 3 2 2 2 2 2 2 3 3 2 2 2 2 3 3 3 3 2 3 3 2 2 2 2 2 3 2 3 2 2 2 2 3 3 2 2 3 3 3 2 3 3 3 2 2 3 3 3 3 2 3 2 2 3 3 2 3 2 2 2 3 3 2 2 2 2 3 2 3 2 3 2 3 3 3 2 2 3 3 3 3 2 2 2 2 3 3 2 3 2...

output:

331407254

result:

ok "331407254"

Test #60:

score: 0
Accepted
time: 5ms
memory: 3516kb

input:

155307
3 2 2 2 3 3 3 2 2 3 3 2 2 3 3 3 3 3 3 2 2 3 3 2 2 3 2 2 3 2 3 2 2 3 2 3 3 3 2 2 3 3 2 3 2 2 3 3 2 2 2 3 2 3 2 2 2 3 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 3 2 2 2 3 3 2 3 3 2 2 3 3 3 2 3 2 2 2 2 3 2 2 3 3 2 3 3 3 2 3 2 3 2 3 3 3 3 2 2 2 3 2 3 2 2 2 3 3 3 3 3 2 3 3 2 2 3 3 2 3 3 2 3 3 2 2 3 3 3 2 2...

output:

869312595

result:

ok "869312595"

Test #61:

score: 0
Accepted
time: 5ms
memory: 3604kb

input:

167271
2 3 3 3 3 3 3 2 3 3 3 3 2 3 2 2 3 3 2 3 2 2 3 2 3 3 2 3 2 3 3 3 3 3 2 2 3 3 2 3 2 2 3 2 2 2 2 2 2 2 3 2 2 2 2 3 3 2 2 3 2 2 3 2 3 3 3 3 3 2 2 2 2 2 2 3 2 3 3 3 2 2 3 2 3 2 3 3 3 3 3 3 3 2 3 2 3 3 2 2 2 2 2 2 2 3 2 3 2 2 3 2 3 3 2 2 2 3 3 3 2 3 3 2 2 3 3 3 3 3 3 2 2 2 3 2 2 3 2 3 2 2 3 3 2 2 3...

output:

922488383

result:

ok "922488383"

Test #62:

score: 0
Accepted
time: 21ms
memory: 4252kb

input:

1000000
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...

output:

513338050

result:

ok "513338050"

Test #63:

score: 0
Accepted
time: 24ms
memory: 4140kb

input:

1000000
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...

output:

182405174

result:

ok "182405174"

Test #64:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

3
1 2 3

output:

0

result:

ok "0"

Test #65:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

3
1 3 2

output:

0

result:

ok "0"

Test #66:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

3
2 1 3

output:

0

result:

ok "0"

Test #67:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

3
2 3 1

output:

2

result:

ok "2"

Test #68:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

3
3 1 2

output:

0

result:

ok "0"

Test #69:

score: 0
Accepted
time: 0ms
memory: 3572kb

input:

3
3 2 1

output:

2

result:

ok "2"

Extra Test:

score: 0
Extra Test Passed