QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#148294#2325. CornsmifafaAC ✓203ms50200kbC++2311.7kb2023-08-23 15:41:042023-08-23 20:21:31

Judging History

This is the latest submission verdict.

  • [2023-08-23 20:21:31]
  • Judged
  • Verdict: AC
  • Time: 203ms
  • Memory: 50200kb
  • [2023-08-23 15:41:04]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int inf = 0x3f3f3f3f3f3f3f3f;

const int mod = 998244353;

inline void add(int &x, int y) {
    x += y;
    if (x >= mod) {
        x -= mod;
    }
}

inline void sub(int &x, int y) {
    x -= y;
    if (x < 0) {
        x += mod;
    }
}

inline int mul(int x, int y) {
    return (long long) x * y % mod;
}

inline int power(int x, int y) {
    int res = 1;
    for (; y; y >>= 1, x = mul(x, x)) {
        if (y & 1) {
            res = mul(res, x);
        }
    }
    return res;
}

inline int inv(int a) {
    a %= mod;
    if (a < 0) {
        a += mod;
    }
    int b = mod, u = 0, v = 1;
    while (a) {
        int t = b / a;
        b -= t * a;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    if (u < 0) {
        u += mod;
    }
    return u;
}

namespace ntt {
    int base = 1, root = -1, max_base = -1;
    vector<int> rev = {0, 1}, roots = {0, 1};

    void init() {
        int temp = mod - 1;
        max_base = 0;
        while (temp % 2 == 0) {
            temp >>= 1;
            ++max_base;
        }
        root = 2;
        while (true) {
            if (power(root, 1 << max_base) == 1 && power(root, 1 << (max_base - 1)) != 1) {
                break;
            }
            ++root;
        }
    }

    void ensure_base(int nbase) {
        if (max_base == -1) {
            init();
        }
        if (nbase <= base) {
            return;
        }
        assert(nbase <= max_base);
        rev.resize(1 << nbase);
        for (int i = 0; i < 1 << nbase; ++i) {
            rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (nbase - 1));
        }
        roots.resize(1 << nbase);
        while (base < nbase) {
            int z = power(root, 1 << (max_base - 1 - base));
            for (int i = 1 << (base - 1); i < 1 << base; ++i) {
                roots[i << 1] = roots[i];
                roots[i << 1 | 1] = mul(roots[i], z);
            }
            ++base;
        }
    }

    void dft(vector<int> &a) {
        int n = a.size(), zeros = __builtin_ctz(n);
        ensure_base(zeros);
        int shift = base - zeros;
        for (int i = 0; i < n; ++i) {
            if (i < rev[i] >> shift) {
                swap(a[i], a[rev[i] >> shift]);
            }
        }
        for (int i = 1; i < n; i <<= 1) {
            for (int j = 0; j < n; j += i << 1) {
                for (int k = 0; k < i; ++k) {
                    int x = a[j + k], y = mul(a[j + k + i], roots[i + k]);
                    a[j + k] = (x + y) % mod > 0;
                    a[j + k + i] = (x + mod - y) % mod > 0;
                }
            }
        }
    }

    vector<int> multiply(vector<int> a, vector<int> b) {
        int need = a.size() + b.size() - 1, nbase = 0;
        while (1 << nbase < need) {
            ++nbase;
        }
        ensure_base(nbase);
        int sz = 1 << nbase;
        a.resize(sz);
        b.resize(sz);
        bool equal = a == b;
        dft(a);
        if (equal) {
            b = a;
        } else {
            dft(b);
        }
        int inv_sz = inv(sz);
        for (int i = 0; i < sz; ++i) {
            a[i] = mul(mul(a[i], b[i]), inv_sz) > 0;
        }
        reverse(a.begin() + 1, a.end());
        dft(a);
        a.resize(need);
        return a;
    }

    vector<int> inverse(vector<int> a) {
        int n = a.size(), m = (n + 1) >> 1;
        if (n == 1) {
            return vector<int>(1, inv(a[0]));
        } else {
            vector<int> b = inverse(vector<int>(a.begin(), a.begin() + m));
            int need = n << 1, nbase = 0;
            while (1 << nbase < need) {
                ++nbase;
            }
            ensure_base(nbase);
            int sz = 1 << nbase;
            a.resize(sz);
            b.resize(sz);
            dft(a);
            dft(b);
            int inv_sz = inv(sz);
            for (int i = 0; i < sz; ++i) {
                a[i] = mul(mul(mod + 2 - mul(a[i], b[i]), b[i]), inv_sz);
            }
            reverse(a.begin() + 1, a.end());
            dft(a);
            a.resize(n);
            return a;
        }
    }
}

using ntt::multiply;
using ntt::inverse;

vector<int> &operator += (vector<int> &a, const vector<int> &b) {
    if (a.size() < b.size()) {
        a.resize(b.size());
    }
    for (int i = 0; i < b.size(); ++i) {
        add(a[i], b[i]);
    }
    return a;
}

vector<int> operator + (const vector<int> &a, const vector<int> &b) {
    vector<int> c = a;
    return c += b;
}

vector<int> &operator -= (vector<int> &a, const vector<int> &b) {
    if (a.size() < b.size()) {
        a.resize(b.size());
    }
    for (int i = 0; i < b.size(); ++i) {
        sub(a[i], b[i]);
    }
    return a;
}

vector<int> operator - (const vector<int> &a, const vector<int> &b) {
    vector<int> c = a;
    return c -= b;
}

vector<int> &operator *= (vector<int> &a, const vector<int> &b) {
    if (min(a.size(), b.size()) < 128) {
        vector<int> c = a;
        a.assign(a.size() + b.size() - 1, 0);
        for (int i = 0; i < c.size(); ++i) {
            for (int j = 0; j < b.size(); ++j) {
                add(a[i + j], mul(c[i], b[j]));
            }
        }
    } else {
        a = multiply(a, b);
    }
    return a;
}

vector<int> operator * (const vector<int> &a, const vector<int> &b) {
    vector<int> c = a;
    return c *= b;
}

vector<int> &operator /= (vector<int> &a, const vector<int> &b) {
    int n = a.size(), m = b.size();
    if (n < m) {
        a.clear();
    } else {
        vector<int> c = b;
        reverse(a.begin(), a.end());
        reverse(c.begin(), c.end());
        c.resize(n - m + 1);
        a *= inverse(c);
        a.erase(a.begin() + n - m + 1, a.end());
        reverse(a.begin(), a.end());
    }
    return a;
}

vector<int> operator / (const vector<int> &a, const vector<int> &b) {
    vector<int> c = a;
    return c /= b;
}

vector<int> &operator %= (vector<int> &a, const vector<int> &b) {
    int n = a.size(), m = b.size();
    if (n >= m) {
        vector<int> c = (a / b) * b;
        a.resize(m - 1);
        for (int i = 0; i < m - 1; ++i) {
            sub(a[i], c[i]);
        }
    }
    return a;
}

vector<int> operator % (const vector<int> &a, const vector<int> &b) {
    vector<int> c = a;
    return c %= b;
}

vector<int> derivative(const vector<int> &a) {
    int n = a.size();
    vector<int> b(n - 1);
    for (int i = 1; i < n; ++i) {
        b[i - 1] = mul(a[i], i);
    }
    return b;
}

vector<int> primitive(const vector<int> &a) {
    int n = a.size();
    vector<int> b(n + 1), invs(n + 1);
    for (int i = 1; i <= n; ++i) {
        invs[i] = i == 1 ? 1 : mul(mod - mod / i, invs[mod % i]);
        b[i] = mul(a[i - 1], invs[i]);
    }
    return b;
}

vector<int> logarithm(const vector<int> &a) {
    vector<int> b = primitive(derivative(a) * inverse(a));
    b.resize(a.size());
    return b;
}

vector<int> exponent(const vector<int> &a) {
    vector<int> b(1, 1);
    while (b.size() < a.size()) {
        vector<int> c(a.begin(), a.begin() + min(a.size(), b.size() << 1));
        add(c[0], 1);
        vector<int> old_b = b;
        b.resize(b.size() << 1);
        c -= logarithm(b);
        c *= old_b;
        for (int i = b.size() >> 1; i < b.size(); ++i) {
            b[i] = c[i];
        }
    }
    b.resize(a.size());
    return b;
}

vector<int> power(vector<int> a, int m) {
    int n = a.size(), p = -1;
    vector<int> b(n);
    for (int i = 0; i < n; ++i) {
        if (a[i]) {
            p = i;
            break;
        }
    }
    if (p == -1) {
        b[0] = !m;
        return b;
    }
    if ((long long) m * p >= n) {
        return b;
    }
    int mu = power(a[p], m), di = inv(a[p]);
    vector<int> c(n - m * p);
    for (int i = 0; i < n - m * p; ++i) {
        c[i] = mul(a[i + p], di);
    }
    c = logarithm(c);
    for (int i = 0; i < n - m * p; ++i) {
        c[i] = mul(c[i], m);
    }
    c = exponent(c);
    for (int i = 0; i < n - m * p; ++i) {
        b[i + m * p] = mul(c[i], mu);
    }
    return b;
}

vector<int> sqrt(const vector<int> &a) {
    vector<int> b(1, 1);
    while (b.size() < a.size()) {
        vector<int> c(a.begin(), a.begin() + min(a.size(), b.size() << 1));
        vector<int> old_b = b;
        b.resize(b.size() << 1);
        c *= inverse(b);
        for (int i = b.size() >> 1; i < b.size(); ++i) {
            b[i] = mul(c[i], (mod + 1) >> 1);
        }
    }
    b.resize(a.size());
    return b;
}

vector<int> multiply_all(int l, int r, vector<vector<int>> &all) {
    if (l > r) {
        return vector<int>();
    } else if (l == r) {
        return all[l];
    } else {
        int y = (l + r) >> 1;
        return multiply_all(l, y, all) * multiply_all(y + 1, r, all);
    }
}

vector<int> evaluate(const vector<int> &f, const vector<int> &x) {
    int n = x.size();
    if (!n) {
        return vector<int>();
    }
    vector<vector<int>> up(n * 2);
    for (int i = 0; i < n; ++i) {
        up[i + n] = vector<int> {(mod - x[i]) % mod, 1};
    }
    for (int i = n - 1; i; --i) {
        up[i] = up[i << 1] * up[i << 1 | 1];
    }
    vector<vector<int>> down(n * 2);
    down[1] = f % up[1];
    for (int i = 2; i < n * 2; ++i) {
        down[i] = down[i >> 1] % up[i];
    }
    vector<int> y(n);
    for (int i = 0; i < n; ++i) {
        y[i] = down[i + n][0];
    }
    return y;
}

vector<int> interpolate(const vector<int> &x, const vector<int> &y) {
    int n = x.size();
    vector<vector<int>> up(n * 2);
    for (int i = 0; i < n; ++i) {
        up[i + n] = vector<int> {(mod - x[i]) % mod, 1};
    }
    for (int i = n - 1; i; --i) {
        up[i] = up[i << 1] * up[i << 1 | 1];
    }
    vector<int> a = evaluate(derivative(up[1]), x);
    for (int i = 0; i < n; ++i) {
        a[i] = mul(y[i], inv(a[i]));
    }
    vector<vector<int>> down(n * 2);
    for (int i = 0; i < n; ++i) {
        down[i + n] = vector<int>(1, a[i]);
    }
    for (int i = n - 1; i; --i) {
        down[i] = down[i << 1] * up[i << 1 | 1] + down[i << 1 | 1] * up[i << 1];
    }
    return down[1];
}

const int N = 2e6 + 10;
int fac[N + 10], fnv[N + 10];

int powmod(int a, int b) {
    int ret = 1;
    a %= mod;
    for (; b; b >>= 1) {
        if(b & 1) ret = ret * a % mod;
        a = a * a % mod;
    }
    return ret;
}

int binom(int n, int m) {
    if (m < 0 || m > n) return 0;
    return fac[n] * fnv[m] % mod * fnv[n - m] % mod;
}

void init() {
    fac[0] = 1;
    for (int i = 1; i <= N; i++) fac[i] = fac[i - 1] * i % mod;
    fnv[N] = powmod(fac[N], mod - 2);
    for (int i = N; i >= 1; i--) fnv[i - 1] = fnv[i] * i % mod;
    // fnv[1] = 1;
    // for(int i = 2; i <= N; i++) fnv[i] = (mod - mod / i) * fnv[mod % i] % mod;
    assert(fnv[0] == 1);
}

int cnt[N];

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, w;
    cin >> n >> w;
    init();

    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        cnt[x]++;
    }

    vector<vector<int>> polys;
    for (int i = 1; i <= 2e5; i++) {
        if (!cnt[i]) continue;
        vector<int> a(i * cnt[i] + 1, 0);

        for (int j = 0; j <= cnt[i]; j++) {
            a[i * j] = binom(cnt[i], j) > 0;
        }

        polys.push_back(a);
    }

    auto f = multiply_all(0, polys.size() - 1, polys);
    
    int ans = 0;

    for (int i = 0; i <= w && i < f.size(); i++) {
        // cout << f[i] << endl;
    	if (f[i] != 0) ans = max(ans, i);
    }

    cout << ans << "\n";

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 18ms
memory: 36128kb

input:

3 10
1
1
11

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 22ms
memory: 34888kb

input:

4 10
3
5
3
4

output:

10

result:

ok single line: '10'

Test #3:

score: 0
Accepted
time: 44ms
memory: 49572kb

input:

30669 199323
7
6
7
7
7
7
6
7
7
7
7
6
7
6
6
7
7
7
7
6
6
7
7
7
6
6
6
7
7
7
6
6
7
7
6
6
7
6
7
6
7
6
6
6
6
6
7
7
7
6
6
6
6
6
6
6
7
7
6
6
7
6
6
7
6
6
6
6
6
7
7
7
7
6
7
7
6
6
7
6
7
6
6
6
6
7
6
7
6
7
6
7
6
7
7
7
7
6
7
7
6
6
6
6
7
6
7
7
7
7
6
7
7
7
7
7
7
6
6
6
7
7
7
6
7
7
7
7
6
7
7
6
6
6
6
7
6
7
7
7
6
6
7
7...

output:

199318

result:

ok single line: '199318'

Test #4:

score: 0
Accepted
time: 52ms
memory: 49460kb

input:

22122 199097
9
8
8
10
9
8
10
9
9
9
8
9
8
9
10
8
9
10
10
10
10
10
9
9
10
10
10
10
10
9
8
8
8
10
9
8
9
9
8
10
9
10
10
10
9
8
8
9
10
10
8
9
9
10
9
10
9
9
9
9
9
10
9
8
9
10
9
9
10
10
8
10
8
8
9
10
8
10
10
8
8
9
8
9
8
10
10
10
10
8
8
8
10
9
8
9
8
9
10
9
8
8
10
9
8
10
10
8
9
10
8
10
9
8
10
9
8
9
8
9
9
8
9...

output:

199089

result:

ok single line: '199089'

Test #5:

score: 0
Accepted
time: 55ms
memory: 48984kb

input:

120000 200000
1
2
1
1
1
2
1
2
2
1
1
1
1
1
1
2
1
1
2
2
1
2
1
2
1
1
2
1
2
1
2
2
1
1
1
1
1
2
2
2
2
2
1
1
2
2
2
2
2
1
1
1
1
1
2
2
2
2
1
1
1
2
2
2
1
1
2
1
2
2
1
1
2
2
2
2
2
2
1
2
1
1
2
1
2
1
2
2
1
2
1
1
2
2
1
1
1
1
1
1
2
1
1
2
1
1
1
1
2
2
1
2
1
1
1
1
1
1
1
2
2
1
1
1
1
2
2
2
1
1
2
1
2
1
2
1
2
1
2
2
1
2
1
...

output:

180055

result:

ok single line: '180055'

Test #6:

score: 0
Accepted
time: 182ms
memory: 47740kb

input:

1243 152688
41
47
45
47
50
37
33
911
42
510
46
33
753
46
47
31
37
50
47
31
39
45
182
48
49
42
40
31
48
807
37
30
38
48
865
43
46
31
42
40
42
46
30
44
31
39
42
45
38
47
47
299
46
598
43
480
40
34
638
37
38
47
210
37
32
38
38
36
50
32
49
494
461
37
34
31
47
42
825
46
44
35
40
225
36
44
231
43
38
40
40...

output:

152688

result:

ok single line: '152688'

Test #7:

score: 0
Accepted
time: 172ms
memory: 49676kb

input:

1241 158399
30
47
914
37
37
31
258
539
31
865
50
47
49
41
107
39
40
704
39
195
30
48
591
557
37
48
32
45
32
31
39
979
42
975
49
32
35
50
38
565
41
34
47
48
30
34
868
993
50
41
50
270
42
535
35
43
36
35
48
72
34
49
45
46
44
48
36
50
48
34
40
972
48
33
730
34
44
30
50
48
35
35
523
668
48
43
48
32
46
3...

output:

158399

result:

ok single line: '158399'

Test #8:

score: 0
Accepted
time: 173ms
memory: 48192kb

input:

1243 157456
31
32
41
37
42
45
42
841
728
46
31
34
43
50
49
48
33
35
39
589
38
39
31
45
754
771
32
687
35
41
46
3
49
37
35
40
36
38
49
733
37
49
849
50
43
34
42
30
31
44
41
39
188
45
194
103
48
33
44
35
36
34
36
44
41
591
40
32
41
36
96
44
49
31
37
46
46
39
37
573
35
63
49
36
34
46
39
46
41
971
38
32...

output:

157456

result:

ok single line: '157456'

Test #9:

score: 0
Accepted
time: 178ms
memory: 48788kb

input:

1244 154207
48
45
36
43
46
49
49
38
871
43
685
38
44
294
38
49
33
35
627
48
564
48
30
32
46
453
43
30
33
46
36
47
440
44
44
37
48
38
34
48
44
37
50
46
37
49
43
115
43
39
419
774
46
45
38
43
35
50
224
832
157
31
34
50
101
46
35
33
49
754
41
39
42
34
49
44
23
626
32
38
39
45
44
33
39
48
48
46
43
46
38...

output:

154207

result:

ok single line: '154207'

Test #10:

score: 0
Accepted
time: 180ms
memory: 47612kb

input:

1244 157697
42
37
159
40
50
31
42
50
899
950
30
41
48
43
37
43
37
36
50
47
41
31
49
35
137
30
144
40
50
38
30
38
38
90
32
49
825
38
32
49
50
31
45
217
40
43
42
43
40
46
42
285
31
977
36
35
34
40
968
47
34
49
39
34
49
270
35
37
60
988
32
35
50
631
33
35
49
521
32
32
33
48
560
803
593
982
49
40
43
41
...

output:

157697

result:

ok single line: '157697'

Test #11:

score: 0
Accepted
time: 167ms
memory: 49384kb

input:

7060 171395
46
9
7
17
30
48
50
17
7
17
17
18
20
9
31
2
41
17
15
11
11
80
9
3
30
18
3
5
7
7
37
4
17
44
18
14
8
5
1
71
39
19
19
3
20
20
9
17
10
10
34
18
37
10
30
9
43
3
18
8
14
15
37
13
4
19
17
15
11
15
4
11
6
18
5
17
4
13
20
50
14
2
65
5
15
18
5
3
9
9
12
8
4
42
37
62
13
16
10
46
15
17
79
7
14
14
20
3...

output:

171395

result:

ok single line: '171395'

Test #12:

score: 0
Accepted
time: 183ms
memory: 49200kb

input:

7058 172240
99
6
45
20
8
44
12
7
13
18
46
15
14
10
50
37
37
1
12
7
7
3
12
7
13
48
30
6
5
11
68
46
2
20
10
58
3
17
36
7
86
8
57
17
17
4
12
4
59
4
48
37
42
8
7
11
36
5
14
12
15
6
9
74
4
8
19
11
5
19
8
15
20
2
2
4
17
62
16
17
6
14
15
11
50
1
15
14
37
17
4
45
12
8
60
4
46
18
6
18
11
3
19
7
17
35
7
2
52
...

output:

172240

result:

ok single line: '172240'

Test #13:

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

input:

1 1
1

output:

1

result:

ok single line: '1'

Test #14:

score: 0
Accepted
time: 174ms
memory: 48964kb

input:

7052 171344
3
17
36
19
11
15
34
3
91
17
16
18
93
15
7
1
2
5
7
61
4
6
8
10
3
7
3
2
35
10
82
39
88
4
6
15
40
8
96
17
15
20
98
43
18
11
39
13
58
13
16
49
3
49
15
9
18
10
12
5
10
12
6
3
77
4
71
45
16
3
1
77
2
38
31
13
44
4
13
20
19
10
92
20
17
87
7
64
4
39
81
63
8
52
5
3
6
5
14
2
52
20
4
16
20
13
4
2
13...

output:

171344

result:

ok single line: '171344'

Test #15:

score: 0
Accepted
time: 160ms
memory: 49692kb

input:

7065 171538
8
9
13
92
8
15
4
16
30
12
10
69
68
15
57
16
4
83
5
81
15
67
6
2
40
18
8
9
4
16
19
17
14
16
53
20
7
20
48
91
13
40
14
19
10
13
10
33
88
32
9
100
14
33
64
83
12
78
9
7
9
20
93
8
11
11
11
1
16
8
1
16
9
5
5
17
12
1
5
10
49
14
16
17
8
19
70
35
18
8
17
10
5
5
86
11
19
2
6
48
5
13
12
6
20
20
68...

output:

171538

result:

ok single line: '171538'

Test #16:

score: 0
Accepted
time: 187ms
memory: 48680kb

input:

7063 170730
19
18
3
72
10
19
3
50
5
3
100
2
71
11
6
9
13
52
32
2
69
14
6
2
13
33
13
5
19
4
9
17
1
37
42
40
50
30
19
87
16
12
81
7
20
19
19
17
17
31
12
11
45
46
18
8
2
8
9
34
5
8
74
18
84
46
58
8
15
11
76
17
84
17
7
38
72
11
17
20
20
4
14
5
20
4
5
14
11
13
47
6
1
10
20
85
8
11
7
17
20
13
31
4
10
18
1...

output:

170730

result:

ok single line: '170730'

Test #17:

score: 0
Accepted
time: 178ms
memory: 48268kb

input:

7061 171010
7
5
19
69
15
74
8
18
67
10
18
20
11
16
16
65
13
40
60
38
15
13
12
95
85
42
19
17
5
16
76
1
61
4
9
85
19
1
17
8
15
11
1
13
14
93
6
15
8
16
15
18
7
12
10
15
10
6
1
58
7
6
13
3
20
66
13
8
17
13
11
6
10
10
19
4
7
33
13
11
18
13
18
12
6
57
7
18
9
20
65
7
19
13
14
9
7
18
6
16
1
43
50
7
10
8
12...

output:

171010

result:

ok single line: '171010'

Test #18:

score: 0
Accepted
time: 160ms
memory: 48360kb

input:

7062 171278
97
20
20
68
32
61
10
1
14
1
7
69
42
17
8
7
1
74
18
14
5
2
9
14
47
5
5
13
80
38
2
6
7
31
10
11
33
1
13
11
14
16
9
45
67
6
8
1
11
4
19
78
82
58
65
12
17
98
15
47
19
49
19
11
76
12
11
30
2
60
16
99
12
18
77
2
64
17
71
20
19
3
7
20
3
19
91
18
12
13
31
16
18
30
48
1
75
2
14
16
14
15
6
19
19
1...

output:

171278

result:

ok single line: '171278'

Test #19:

score: 0
Accepted
time: 199ms
memory: 49060kb

input:

32142 191489
6
5
4
7
4
7
11
3
4
4
14
3
13
7
4
3
6
7
4
3
7
6
6
7
5
10
7
5
6
6
7
8
4
4
4
6
12
7
7
5
7
7
5
4
10
5
5
3
7
4
4
15
3
12
3
4
6
6
7
6
7
4
3
7
4
4
3
6
4
10
7
5
5
14
7
7
3
3
5
6
8
3
6
3
5
6
4
7
15
7
7
4
3
4
5
6
7
7
7
11
3
14
3
10
7
4
14
5
7
4
5
5
5
6
6
5
7
7
7
5
11
5
4
13
5
6
6
3
13
3
4
6
5
7
3...

output:

191489

result:

ok single line: '191489'

Test #20:

score: 0
Accepted
time: 197ms
memory: 50200kb

input:

32112 191429
3
6
6
6
6
11
6
3
7
6
6
3
8
4
4
4
3
7
4
7
7
12
7
5
4
7
4
7
5
6
7
3
6
7
12
7
7
4
6
12
5
4
7
5
7
3
5
3
3
5
4
6
7
6
7
5
7
4
5
5
6
4
3
4
5
5
7
6
5
5
13
11
7
4
5
3
4
15
5
5
4
5
5
7
3
3
6
6
11
5
7
12
6
11
7
5
7
4
4
3
4
6
5
7
5
3
5
12
5
6
6
5
3
5
4
6
4
6
3
7
4
7
7
6
6
7
5
7
5
5
10
7
4
4
6
3
4
3...

output:

191429

result:

ok single line: '191429'

Test #21:

score: 0
Accepted
time: 203ms
memory: 50184kb

input:

32107 192846
5
3
7
5
7
3
9
6
3
7
6
7
7
10
4
7
7
6
5
7
7
6
6
12
3
7
7
3
4
13
5
7
5
7
6
6
7
4
6
6
4
5
7
16
5
7
4
4
5
4
4
6
6
10
11
7
7
4
4
7
4
4
5
4
8
6
3
4
5
4
3
3
4
3
3
6
7
6
4
5
12
6
3
11
7
6
7
3
6
7
3
7
6
6
5
7
7
6
6
14
7
12
7
6
3
6
7
6
10
5
3
4
4
3
5
4
7
7
8
7
3
7
6
3
4
5
3
7
4
6
3
3
6
7
5
5
4
4
...

output:

192846

result:

ok single line: '192846'

Test #22:

score: 0
Accepted
time: 192ms
memory: 49788kb

input:

32136 191995
14
7
3
6
4
4
3
4
3
4
4
14
7
3
3
6
4
5
3
7
6
4
5
4
7
7
4
4
7
3
6
4
8
8
4
7
15
13
4
10
4
7
6
4
7
3
3
6
11
10
6
7
7
5
6
10
4
7
4
5
12
7
7
3
4
6
3
6
3
3
7
4
7
5
3
11
5
7
4
13
7
5
6
6
4
5
5
7
3
4
6
5
4
7
5
3
6
15
4
3
15
4
6
7
5
10
5
7
10
4
5
5
4
5
7
4
4
6
7
3
3
5
5
12
13
3
5
5
7
10
7
5
4
6
7...

output:

191995

result:

ok single line: '191995'

Test #23:

score: 0
Accepted
time: 198ms
memory: 49200kb

input:

32162 192563
6
3
6
4
7
5
4
10
7
7
5
5
3
6
12
5
5
4
6
7
6
5
5
5
5
3
4
5
3
5
13
4
7
5
5
5
4
3
3
4
10
6
3
15
4
3
6
4
5
7
3
5
4
8
5
4
3
11
7
5
7
12
8
10
3
3
5
6
3
3
7
13
7
4
3
3
10
4
3
10
4
5
6
6
3
3
10
6
3
5
4
5
6
4
4
4
7
6
5
3
6
5
5
5
4
4
4
5
3
6
3
6
4
3
5
4
5
3
9
4
8
6
5
13
6
5
5
5
3
5
6
4
4
4
5
4
4
...

output:

192563

result:

ok single line: '192563'

Test #24:

score: 0
Accepted
time: 18ms
memory: 40048kb

input:

1 1
200000

output:

0

result:

ok single line: '0'

Test #25:

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

input:

3 10
2
3
6

output:

9

result:

ok single line: '9'

Test #26:

score: 0
Accepted
time: 23ms
memory: 36244kb

input:

10 500
1
2
3
4
5
6
400
491
412
492

output:

500

result:

ok single line: '500'

Test #27:

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

input:

2 200000
100000
100000

output:

200000

result:

ok single line: '200000'

Test #28:

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

input:

200000 200000
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:

200000

result:

ok single line: '200000'

Test #29:

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

input:

100000 100000
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
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:

100000

result:

ok single line: '100000'

Test #30:

score: 0
Accepted
time: 55ms
memory: 50160kb

input:

49900 199570
3
3
3
4
4
5
3
3
5
3
4
5
3
5
5
3
3
3
5
3
3
5
4
4
3
5
3
4
3
5
4
4
3
4
5
5
5
4
3
4
5
4
4
5
4
5
5
4
3
3
5
3
4
4
3
3
3
3
4
5
4
4
5
3
4
4
5
5
3
4
3
4
3
5
3
4
5
3
4
4
3
4
4
4
4
3
5
3
3
5
3
3
3
5
3
4
4
4
5
3
4
4
5
4
5
4
4
4
5
3
5
4
3
5
3
3
5
5
3
3
4
3
4
5
5
4
4
3
4
4
5
3
3
3
3
5
5
4
5
4
3
4
4
3...

output:

199568

result:

ok single line: '199568'