QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#484403#8712. Flooding WallWansur36 128ms172496kbC++239.1kb2024-07-19 18:19:232024-07-19 18:19:23

Judging History

This is the latest submission verdict.

  • [2024-07-19 18:19:23]
  • Judged
  • Verdict: 36
  • Time: 128ms
  • Memory: 172496kb
  • [2024-07-19 18:19:23]
  • Submitted

answer

#include <bits/stdc++.h>
#define ent '\n'
#define f first
#define s second

using namespace std;

template <typename T>
T inverse(T a, T m) {
    T u = 0, v = 1;
    while (a != 0) {
        T t = m / a;
        m -= t * a; swap(a, m);
        u -= t * v; swap(u, v);
    }
    assert(m == 1);
    return u;
}

template <typename T>
class Modular {
public:
    using Type = typename decay<decltype(T::value)>::type;

    constexpr Modular() : value() {}
    template <typename U>
    Modular(const U& x) {
        value = normalize(x);
    }

    template <typename U>
    static Type normalize(const U& x) {
        Type v;
        if (-mod() <= x && x < mod()) v = static_cast<Type>(x);
        else v = static_cast<Type>(x % mod());
        if (v < 0) v += mod();
        return v;
    }

    const Type& operator()() const { return value; }
    template <typename U>
    explicit operator U() const { return static_cast<U>(value); }
    constexpr static Type mod() { return T::value; }

    Modular& operator+=(const Modular& other) { if ((value += other.value) >= mod()) value -= mod(); return *this; }
    Modular& operator-=(const Modular& other) { if ((value -= other.value) < 0) value += mod(); return *this; }
    template <typename U> Modular& operator+=(const U& other) { return *this += Modular(other); }
    template <typename U> Modular& operator-=(const U& other) { return *this -= Modular(other); }
    Modular& operator++() { return *this += 1; }
    Modular& operator--() { return *this -= 1; }
    Modular operator++(int) { Modular result(*this); *this += 1; return result; }
    Modular operator--(int) { Modular result(*this); *this -= 1; return result; }
    Modular operator-() const { return Modular(-value); }

    template <typename U = T>
    typename enable_if<is_same<typename Modular<U>::Type, int>::value, Modular>::type& operator*=(const Modular& rhs) {
        value = normalize(static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value));
        return *this;
    }
    template <typename U = T>
    typename enable_if<is_same<typename Modular<U>::Type, long long>::value, Modular>::type& operator*=(const Modular& rhs) {
        long long q = static_cast<long long>(static_cast<long double>(value) * rhs.value / mod());
        value = normalize(value * rhs.value - q * mod());
        return *this;
    }
    template <typename U = T>
    typename enable_if<!is_integral<typename Modular<U>::Type>::value, Modular>::type& operator*=(const Modular& rhs) {
        value = normalize(value * rhs.value);
        return *this;
    }

    Modular& operator/=(const Modular& other) { return *this *= Modular(inverse(other.value, mod())); }

    friend const Type& abs(const Modular& x) { return x.value; }

    template <typename U>
    friend bool operator==(const Modular<U>& lhs, const Modular<U>& rhs);

    template <typename U>
    friend bool operator<(const Modular<U>& lhs, const Modular<U>& rhs);

    template <typename V, typename U>
    friend V& operator>>(V& stream, Modular<U>& number);

private:
    Type value;
};

template <typename T> bool operator==(const Modular<T>& lhs, const Modular<T>& rhs) { return lhs.value == rhs.value; }
template <typename T, typename U> bool operator==(const Modular<T>& lhs, U rhs) { return lhs == Modular<T>(rhs); }
template <typename T, typename U> bool operator==(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) == rhs; }

template <typename T> bool operator!=(const Modular<T>& lhs, const Modular<T>& rhs) { return !(lhs == rhs); }
template <typename T, typename U> bool operator!=(const Modular<T>& lhs, U rhs) { return !(lhs == rhs); }
template <typename T, typename U> bool operator!=(U lhs, const Modular<T>& rhs) { return !(lhs == rhs); }

template <typename T> bool operator<(const Modular<T>& lhs, const Modular<T>& rhs) { return lhs.value < rhs.value; }

template <typename T> Modular<T> operator+(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) += rhs; }
template <typename T, typename U> Modular<T> operator+(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) += rhs; }
template <typename T, typename U> Modular<T> operator+(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) += rhs; }

template <typename T> Modular<T> operator-(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) -= rhs; }
template <typename T, typename U> Modular<T> operator-(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) -= rhs; }
template <typename T, typename U> Modular<T> operator-(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) -= rhs; }

template <typename T> Modular<T> operator*(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) *= rhs; }
template <typename T, typename U> Modular<T> operator*(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) *= rhs; }
template <typename T, typename U> Modular<T> operator*(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) *= rhs; }

template <typename T> Modular<T> operator/(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) /= rhs; }
template <typename T, typename U> Modular<T> operator/(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) /= rhs; }
template <typename T, typename U> Modular<T> operator/(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) /= rhs; }

template<typename T, typename U>
Modular<T> power(const Modular<T>& a, const U& b) {
    assert(b >= 0);
    Modular<T> x = a, res = 1;
    U p = b;
    while (p > 0) {
        if (p & 1) res *= x;
        x *= x;
        p >>= 1;
    }
    return res;
}

template <typename T>
bool IsZero(const Modular<T>& number) {
    return number() == 0;
}

template <typename T>
string to_string(const Modular<T>& number) {
    return to_string(number());
}

// U == std::ostream? but done this way because of fastoutput
template <typename U, typename T>
U& operator<<(U& stream, const Modular<T>& number) {
    return stream << number();
}

// U == std::istream? but done this way because of fastinput
template <typename U, typename T>
U& operator>>(U& stream, Modular<T>& number) {
    typename common_type<typename Modular<T>::Type, long long>::type x;
    stream >> x;
    number.value = Modular<T>::normalize(x);
    return stream;
}

// using ModType = int;

// struct VarMod { static ModType value; };
// ModType VarMod::value;
// ModType& md = VarMod::value;
// using Mint = Modular<VarMod>;

const int md = (int)1e9 + 7;
using Mint = Modular<std::integral_constant<decay<decltype(md)>::type, md>>;
#define int long long

typedef long long ll;
const int maxn = 1e6 + 12;
const int mod = 1e9 + 7;

Mint sums[10040][1040];
Mint dps[10040][1040];
Mint sum[10400][1040];
Mint dp[10040][1040];
int a[maxn];
int b[maxn];
int n, m, s;

void solve(){
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> a[i];
    }
    for(int i=1;i<=n;i++) {
        cin >> b[i];
    }
    dp[0][0] = 1;
    sum[0][0] = 0;
    for(int i=1;i<=n;i++){
        for(int x=0;x<=1000;x++){
            if(a[i] >= x){
                dp[i][a[i]] += dp[i-1][x];
                sum[i][a[i]] += sum[i-1][x];
            }
            else{
                dp[i][x] += dp[i-1][x];
                sum[i][x] += sum[i-1][x] + dp[i-1][x] * (x - a[i]);
            }
            if(b[i] >= x){
                dp[i][b[i]] += dp[i-1][x];
                sum[i][b[i]] += sum[i-1][x];
            }
            else{
                dp[i][x] += dp[i-1][x];
                sum[i][x] += sum[i-1][x] + dp[i-1][x] * (x - b[i]);
            }
        }
    }
    dps[n+1][0] = 1;
    for(int i=n;i;i--){
        for(int x=0;x<=1000;x++){
            if(a[i] >= x){
                dps[i][a[i]] += dps[i+1][x];
                sums[i][a[i]] += sums[i+1][x];
            }
            else{
                dps[i][x] += dps[i+1][x];
                sums[i][x] += sums[i+1][x] + dps[i+1][x] * (x - a[i]);
            }
            if(b[i] >= x){
                dps[i][b[i]] += dps[i+1][x];
                sums[i][b[i]] += sums[i+1][x];
            }
            else{
                dps[i][x] += dps[i+1][x];
                sums[i][x] += sums[i+1][x] + dps[i+1][x] * (x - b[i]);
            }
        }
    }
    Mint ans = 0;
    for(int i=1;i<=n;i++){
        Mint cntl = 0, sl = 0, cntr = 0, sr = 0;
        for(int x=0;x<=a[i];x++){
            cntr += dps[i+1][x];
            sr += sums[i+1][x];
            if(x == a[i]) break;
            cntl += dp[i-1][x];
            sl += sum[i-1][x];
        }
        ans += sr * cntl + sl * cntr;
    }
    for(int i=1;i<=n;i++){
        Mint cntl = 0, sl = 0, cntr = 0, sr = 0;
        for(int x=0;x<=b[i];x++){
            cntr += dps[i+1][x];
            sr += sums[i+1][x];
            if(x == b[i]) break;
            cntl += dp[i-1][x];
            sl += sum[i-1][x];
        }
        ans += sr * cntl + sl * cntr;
    }
    cout << ans << ent;
}

signed main(){
    srand(time(0));
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 8
Accepted
time: 2ms
memory: 11868kb

input:

4
1 1 1 1
2 2 2 2

output:

6

result:

ok single line: '6'

Test #2:

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

input:

10
1 2 3 4 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1

output:

21116

result:

ok single line: '21116'

Test #3:

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

input:

1
1
2

output:

0

result:

ok single line: '0'

Test #4:

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

input:

2
1 1
2 2

output:

0

result:

ok single line: '0'

Test #5:

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

input:

3
1 1 1
2 2 2

output:

1

result:

ok single line: '1'

Test #6:

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

input:

3
1 1 1
3 2 3

output:

3

result:

ok single line: '3'

Test #7:

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

input:

3
2 1 1
3 2 3

output:

4

result:

ok single line: '4'

Test #8:

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

input:

3
1 1 2
3 2 3

output:

4

result:

ok single line: '4'

Test #9:

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

input:

4
1 1 2 2
2 2 1 1

output:

6

result:

ok single line: '6'

Test #10:

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

input:

3
1 4 4
3 1 1

output:

2

result:

ok single line: '2'

Test #11:

score: -8
Runtime Error

input:

20
801072306 297281669 94099424 745640358 822582129 579751930 776707816 425952653 529794053 256263083 615445445 401366545 990263003 967996508 788867983 916880116 837997768 346996508 623409388 122077161
141734988 448434751 822901346 825591177 388082644 468025968 260356829 1164654 537396602 730502935 ...

output:


result:


Subtask #2:

score: 17
Accepted

Test #23:

score: 17
Accepted
time: 3ms
memory: 12656kb

input:

100
948 425 211 688 416 81 356 602 712 954 117 522 797 75 281 491 662 669 78 156 939 526 929 937 916 619 166 777 48 898 449 278 298 714 668 755 679 38 389 602 195 135 672 833 655 541 473 27 596 274 351 353 598 993 837 246 950 99 179 751 481 843 550 195 964 279 806 82 330 599 124 756 649 838 513 625 ...

output:

164439470

result:

ok single line: '164439470'

Test #24:

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

input:

99
426 562 392 187 480 118 86 459 941 159 104 108 323 616 104 679 464 929 60 387 335 298 540 352 520 152 76 233 69 50 422 839 236 113 79 782 44 253 791 857 393 767 297 267 23 523 274 514 489 58 217 361 408 753 990 491 787 529 759 351 668 348 811 737 764 672 471 115 815 701 604 348 708 512 227 707 20...

output:

295469554

result:

ok single line: '295469554'

Test #25:

score: 0
Accepted
time: 3ms
memory: 12376kb

input:

100
2 1 1 2 2 2 2 1 2 2 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 1 2 1 1 2 1 2 2 1 2 2 2 1 1 1 1 2 2 2 2 2 2 2 1 2 1 1 1 1 2 2 2 2 2 2 1 2 1 2 1 2 2 1 1 2 2 1 1 2 1 2 2 2 1 1 1 1 1 1 2 2 1 2 1 1 2 1 1 1 2 1 1 2 2 1
1 2 2 1 1 1 1 2 1 1 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 2 1 2 2 1 2 1 1 2 1 1 1 2 2 2 2 1 1 1 1 1 1 1 ...

output:

865821460

result:

ok single line: '865821460'

Test #26:

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

input:

97
2 1 2 1 1 1 2 2 2 1 2 1 2 1 2 2 1 1 2 1 1 1 1 2 2 2 1 1 1 2 1 2 2 2 1 1 1 1 2 2 1 1 1 1 1 1 1 1 2 2 1 2 2 1 1 1 2 1 2 2 2 2 2 1 2 1 1 2 1 1 2 2 2 2 1 2 2 1 1 1 1 2 1 2 2 2 1 1 2 2 1 1 2 2 1 2 2
1 2 1 2 2 2 1 1 1 2 1 2 1 2 1 1 2 2 1 2 2 2 2 1 1 1 2 2 2 1 2 1 1 1 2 2 2 2 1 1 2 2 2 2 2 2 2 2 1 1 2 1...

output:

237658155

result:

ok single line: '237658155'

Test #27:

score: 0
Accepted
time: 3ms
memory: 12252kb

input:

100
2 7 7 7 10 10 5 3 8 7 4 4 3 3 9 9 3 4 10 10 2 2 8 6 8 5 8 5 6 5 9 7 9 4 9 4 2 6 4 7 8 8 1 4 2 4 5 3 6 8 2 5 6 1 4 10 10 1 8 7 4 9 2 8 9 5 7 8 9 8 3 5 4 7 6 3 3 1 9 4 1 4 9 1 10 3 3 9 10 7 7 8 5 8 4 10 8 4 1 4
6 8 5 8 9 2 9 9 7 3 10 1 4 10 7 1 4 1 6 8 5 7 7 7 9 3 2 3 1 9 7 2 6 5 7 9 10 1 8 1 2 6 ...

output:

12245240

result:

ok single line: '12245240'

Test #28:

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

input:

100
996 996 998 996 997 996 995 998 991 996 997 1000 992 1000 995 999 1000 999 998 992 995 998 994 996 994 994 995 1000 992 992 1000 994 993 999 997 997 997 1000 991 994 995 999 1000 999 994 992 997 992 999 992 992 1000 999 996 995 992 999 993 997 993 992 997 991 992 992 995 992 994 998 1000 998 100...

output:

699955927

result:

ok single line: '699955927'

Test #29:

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

input:

100
991 6 5 1 8 3 10 10 7 2 8 10 4 9 6 8 1 2 9 6 7 8 8 1 9 5 8 2 5 2 6 1 8 9 9 1 5 9 2 7 8 6 10 8 1 10 3 4 5 5 5 1 1 4 5 7 7 7 3 7 8 4 7 4 4 10 3 1 4 7 7 6 4 3 3 4 4 1 4 9 3 7 9 5 4 3 3 5 7 7 8 10 3 6 4 10 4 5 3 991
994 1 8 5 1 5 7 3 3 4 3 1 6 2 1 4 10 5 8 8 5 7 9 6 4 2 9 3 2 4 3 8 7 1 4 7 9 7 1 4 7...

output:

823274616

result:

ok single line: '823274616'

Test #30:

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

input:

95
3 1 9 8 2 3 7 1 9 9 10 1 1 10 10 9 9 2 4 9 6 7 10 2 8 8 2 4 7 4 9 4 2 10 1 6 1 8 9 5 2 4 1 9 3 1 10 4 10 4 3 7 1 7 9 2 10 2 5 5 4 8 4 7 8 8 2 7 3 3 9 3 9 10 5 3 2 7 10 3 10 9 1 1 1 9 7 10 2 6 5 7 10 7 10
5 7 4 3 9 9 9 4 10 1 6 5 7 6 9 3 10 3 3 3 9 2 5 5 10 10 7 8 2 7 5 5 6 6 6 10 5 6 5 6 4 10 2 8...

output:

39455183

result:

ok single line: '39455183'

Test #31:

score: 0
Accepted
time: 3ms
memory: 12640kb

input:

99
991 1000 999 997 991 997 991 998 993 993 991 997 998 998 993 991 995 999 1000 995 994 991 994 998 1000 995 997 995 996 998 997 994 997 997 993 993 999 993 998 997 998 994 998 999 998 992 991 996 1000 1000 995 994 997 997 1000 995 993 996 994 993 996 997 991 991 993 992 996 1000 994 1000 993 998 9...

output:

177632228

result:

ok single line: '177632228'

Test #32:

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

input:

93
998 9 4 6 6 3 7 6 6 2 3 1 1 4 3 4 3 10 1 7 6 6 7 2 1 6 2 7 5 10 10 5 3 6 9 3 7 8 2 4 2 5 8 4 9 8 9 6 6 10 9 8 5 9 6 7 8 6 10 4 3 4 2 10 3 6 6 3 3 7 1 5 8 8 2 4 3 6 5 4 4 9 2 4 4 10 10 5 3 4 6 5 998
991 3 7 1 2 7 4 4 7 4 8 3 7 7 6 6 1 8 3 8 2 4 9 7 2 1 6 8 4 6 1 9 6 2 8 8 5 1 5 1 6 1 2 8 1 7 7 10 ...

output:

19480584

result:

ok single line: '19480584'

Test #33:

score: 0
Accepted
time: 3ms
memory: 12376kb

input:

100
8 4 962 943 7 905 886 867 848 4 810 9 772 1 10 9 8 677 658 639 2 601 6 563 544 1 506 487 3 5 3 1 392 5 354 335 316 297 10 259 240 221 5 183 164 10 126 10 9 9 50 69 88 3 126 145 164 1 202 6 8 9 8 1 316 335 354 6 3 411 5 9 468 487 506 10 544 2 582 601 620 6 658 677 8 715 8 2 4 2 7 4 7 2 886 905 9 ...

output:

224554505

result:

ok single line: '224554505'

Test #34:

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

input:

97
8 980 2 940 920 900 880 8 5 820 5 2 7 740 5 700 9 8 640 4 8 8 3 540 520 500 7 460 7 420 9 380 10 3 6 300 280 7 240 220 200 180 10 140 4 3 80 60 7 60 10 1 7 140 160 5 200 4 10 2 280 1 3 10 360 5 400 7 9 1 480 7 520 8 560 9 8 620 640 5 680 700 720 6 7 780 1 9 3 4 9 8 920 940 960 7 9
1000 8 960 3 4 ...

output:

11356755

result:

ok single line: '11356755'

Subtask #3:

score: 19
Accepted

Dependency #2:

100%
Accepted

Test #35:

score: 19
Accepted
time: 109ms
memory: 169632kb

input:

10000
723 904 141 407 718 128 268 838 287 173 507 490 602 335 475 954 785 148 163 452 709 394 16 817 80 850 830 464 419 833 306 591 731 966 380 514 365 563 290 58 620 883 384 413 312 996 203 57 954 951 996 176 352 789 531 233 697 231 230 730 482 891 67 514 75 259 673 241 851 957 928 891 510 592 290 ...

output:

357364262

result:

ok single line: '357364262'

Test #36:

score: 0
Accepted
time: 99ms
memory: 169972kb

input:

9995
141 696 412 803 219 794 458 520 884 453 444 885 902 857 677 266 505 768 741 426 249 274 745 514 683 937 18 814 407 618 545 960 695 294 858 150 198 930 27 458 214 159 57 238 39 376 404 957 622 73 858 400 690 32 263 998 526 408 667 361 792 272 839 676 207 728 172 567 262 715 424 845 164 426 518 6...

output:

58777672

result:

ok single line: '58777672'

Test #37:

score: 0
Accepted
time: 112ms
memory: 168752kb

input:

10000
2 1 2 2 1 1 1 2 2 1 1 1 2 2 2 1 2 2 2 2 2 1 2 1 1 1 1 1 2 2 1 2 1 2 2 2 1 1 1 1 2 2 2 1 2 1 2 1 1 1 1 1 2 1 1 1 1 2 1 1 1 2 2 2 1 1 2 1 2 2 2 1 1 2 2 2 2 1 2 2 2 1 2 2 1 1 2 1 2 1 2 1 2 1 1 2 2 2 1 2 1 2 2 1 1 1 2 2 2 1 1 1 1 1 2 2 2 2 2 2 1 1 2 2 1 2 1 1 2 2 2 2 2 1 2 2 1 2 1 2 2 1 2 1 1 1 1 ...

output:

247779710

result:

ok single line: '247779710'

Test #38:

score: 0
Accepted
time: 96ms
memory: 169852kb

input:

9991
1 2 2 2 1 2 2 1 1 1 1 2 2 2 2 1 2 2 2 2 1 2 2 2 2 2 2 2 2 2 1 1 2 1 1 2 2 2 1 2 2 2 2 2 2 1 2 1 2 1 1 2 2 1 2 2 1 2 2 2 1 1 2 2 1 2 1 2 2 1 1 2 1 2 2 2 1 2 2 1 2 2 1 1 1 2 1 1 2 2 1 2 2 1 2 2 1 1 2 2 2 1 2 2 2 2 2 2 1 2 1 2 1 1 2 2 2 2 1 1 1 1 1 2 2 1 1 1 2 1 2 2 2 2 1 2 1 2 2 1 1 1 2 1 1 2 2 2...

output:

284526629

result:

ok single line: '284526629'

Test #39:

score: 0
Accepted
time: 97ms
memory: 168752kb

input:

10000
10 4 7 9 9 3 10 10 3 6 1 4 4 2 6 6 10 3 4 5 5 2 9 9 2 5 10 6 6 5 8 8 6 2 9 4 9 1 9 9 1 4 2 1 4 8 9 6 1 9 6 5 5 4 8 7 8 3 9 7 7 4 10 5 4 8 7 5 5 6 5 3 6 4 8 1 6 8 6 4 5 6 10 7 2 8 1 2 2 4 10 9 4 5 10 4 5 9 4 5 10 7 1 9 6 7 1 5 6 3 6 1 6 8 3 2 8 2 9 10 10 8 9 1 6 1 6 6 5 3 5 10 3 7 4 1 5 10 7 9 ...

output:

30198386

result:

ok single line: '30198386'

Test #40:

score: 0
Accepted
time: 87ms
memory: 172496kb

input:

10000
1000 998 997 995 995 998 995 994 994 998 1000 997 991 996 996 999 1000 998 991 1000 999 997 996 996 999 1000 994 993 999 994 997 994 1000 996 994 998 1000 997 992 999 1000 991 992 1000 1000 996 994 999 991 994 999 994 993 996 991 997 1000 1000 993 998 1000 998 995 993 997 992 999 998 995 992 9...

output:

592005476

result:

ok single line: '592005476'

Test #41:

score: 0
Accepted
time: 128ms
memory: 170128kb

input:

10000
995 5 2 5 9 6 10 10 3 1 9 2 4 4 5 6 6 8 4 2 9 7 5 2 2 2 8 8 1 2 10 7 6 2 10 1 6 1 6 10 5 4 7 7 8 10 10 9 4 10 8 10 6 7 7 7 1 7 3 7 9 1 9 5 5 4 8 9 5 3 4 1 7 2 7 4 8 8 1 10 4 7 8 6 6 6 10 7 3 2 4 4 10 5 4 5 2 10 4 7 10 2 10 2 9 7 2 10 9 3 6 4 5 5 2 6 5 7 7 9 3 4 2 10 3 3 1 7 8 7 2 2 2 9 6 1 9 2...

output:

782664420

result:

ok single line: '782664420'

Test #42:

score: 0
Accepted
time: 124ms
memory: 169348kb

input:

9995
9 6 6 8 7 9 6 6 1 10 5 8 6 8 10 7 9 1 5 6 4 4 9 9 8 9 2 10 8 6 6 2 8 3 7 2 7 10 3 10 1 2 5 9 4 5 9 6 1 5 7 4 10 3 9 7 4 9 3 8 3 5 3 6 5 4 1 10 10 6 7 9 4 4 10 3 8 7 9 3 9 5 2 1 7 4 9 1 8 5 7 7 6 9 4 8 2 9 8 7 6 1 3 1 8 6 3 7 1 8 1 4 6 1 6 5 7 10 2 5 2 2 2 9 2 9 9 1 4 8 8 5 9 6 6 4 8 9 7 2 7 9 4...

output:

111454521

result:

ok single line: '111454521'

Test #43:

score: 0
Accepted
time: 75ms
memory: 171780kb

input:

9995
997 998 996 993 991 991 995 998 997 991 994 993 999 998 993 999 999 999 1000 996 994 997 995 995 993 995 997 998 997 995 994 997 992 996 999 995 992 992 992 998 997 995 999 991 997 994 991 993 998 1000 998 998 991 997 996 996 993 993 998 997 993 993 999 1000 999 993 992 1000 995 993 995 995 999...

output:

2654488

result:

ok single line: '2654488'

Test #44:

score: 0
Accepted
time: 109ms
memory: 170284kb

input:

9995
993 1 1 10 5 8 9 5 8 10 4 1 3 4 8 7 2 2 1 2 7 9 7 5 8 3 3 9 7 1 9 8 6 5 2 4 9 2 1 2 9 8 1 8 6 5 3 3 3 6 1 1 9 8 3 3 4 10 5 6 7 3 1 8 4 9 7 8 4 6 5 6 3 3 4 2 1 3 6 7 5 4 4 4 6 7 8 10 3 5 3 5 3 2 4 7 9 5 6 1 1 5 3 5 7 1 7 10 8 9 1 2 10 6 3 7 10 4 3 9 1 7 2 7 10 6 6 6 9 3 10 2 8 6 2 2 9 3 2 2 8 9 ...

output:

821273565

result:

ok single line: '821273565'

Test #45:

score: 0
Accepted
time: 110ms
memory: 170216kb

input:

10000
2 1 2 2 1 2 2 1 2 2 2 1 2 1 2 1 2 2 2 2 2 1 2 1 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 2 1 1 1 2 1 1 1 1 2 1 1 1 1 1 2 2 1 2 1 2 2 2 2 1 2 2 2 2 1 2 1 1 2 2 2 2 2 2 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 2 1 1 1 2 2 1 2 1 2 2 1 1 2 1 1 2 2 1 2 1 1 1 1 1 2 1 1 2 1 1 2 1 2 2 2 1 1 2 2 2 1 1 2 2 2 2 1 1 1 1 2 2 ...

output:

247779710

result:

ok single line: '247779710'

Test #46:

score: 0
Accepted
time: 125ms
memory: 169836kb

input:

9997
2 2 1 1 1 1 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 1 2 1 2 1 1 1 2 1 2 2 2 2 2 1 1 1 1 2 2 2 1 2 2 2 1 2 2 2 2 2 2 1 2 1 2 2 1 1 2 1 2 1 1 2 2 1 1 1 1 2 2 2 1 2 1 1 2 1 1 2 2 1 1 1 1 1 1 2 2 2 2 2 1 1 2 2 1 1 1 2 1 1 2 1 1 2 1 2 1 2 1 1 1 1 2 1 2 1 1 2 2...

output:

423679003

result:

ok single line: '423679003'

Test #47:

score: 0
Accepted
time: 95ms
memory: 168816kb

input:

10000
1 6 9 4 6 6 7 8 3 2 8 7 9 5 1 7 5 5 7 3 4 6 5 2 9 5 3 8 7 9 5 8 5 9 2 7 6 1 10 1 8 4 1 7 6 1 4 3 6 3 8 9 8 5 10 2 7 3 2 6 6 1 10 5 7 3 4 5 10 8 2 2 5 9 4 6 8 3 9 4 3 2 7 7 7 1 2 7 6 8 3 2 5 9 5 2 2 8 3 5 6 1 7 10 10 2 2 6 3 1 2 5 9 4 10 5 3 4 10 3 10 7 1 9 8 7 10 3 2 4 9 2 1 1 7 5 2 10 6 3 8 3...

output:

199950642

result:

ok single line: '199950642'

Test #48:

score: 0
Accepted
time: 111ms
memory: 170376kb

input:

9991
9 1 3 5 3 6 9 2 1 4 9 8 1 7 8 10 4 9 8 6 4 9 2 2 1 4 10 8 1 3 9 9 8 4 6 7 1 5 4 3 6 10 9 1 8 8 10 3 10 5 10 4 9 1 2 1 7 5 7 7 3 8 10 10 3 2 10 9 3 1 6 3 1 3 2 9 3 6 4 1 7 3 6 10 2 8 6 9 4 5 8 1 3 2 4 4 8 9 4 2 10 7 5 7 5 6 3 2 9 2 4 2 4 7 7 7 5 8 4 8 5 1 4 5 5 7 10 6 4 7 4 9 5 4 8 5 2 3 7 2 3 4...

output:

776507969

result:

ok single line: '776507969'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Runtime Error

Test #57:

score: 0
Runtime Error

input:

500000
1 1 1 1 2 2 2 1 1 1 1 1 2 2 1 1 2 2 2 2 1 2 1 1 2 1 1 1 1 2 1 2 2 1 1 2 2 2 1 1 2 2 2 2 1 2 2 2 2 1 2 2 2 1 2 2 2 1 2 2 2 2 2 2 2 2 1 1 2 1 2 1 2 2 1 2 2 2 2 2 2 2 1 1 1 2 2 2 1 1 2 1 2 2 1 2 2 1 2 2 2 1 2 2 2 2 2 2 2 2 1 1 1 2 1 2 1 1 2 1 2 1 2 2 1 1 2 1 1 1 1 1 2 2 2 2 2 2 1 2 2 1 1 2 1 2 1...

output:


result:


Subtask #6:

score: 0
Skipped

Dependency #1:

0%