QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#678586#9523. Marble RaceThe Raspberry Candies (Takuki Kurokawa, Kei Chinen, Keisuke Katayama)#AC ✓871ms5376kbC++2317.8kb2024-10-26 15:27:272024-10-26 15:27:28

Judging History

This is the latest submission verdict.

  • [2024-10-26 15:27:28]
  • Judged
  • Verdict: AC
  • Time: 871ms
  • Memory: 5376kb
  • [2024-10-26 15:27:27]
  • Submitted

answer

#include <bits/stdc++.h>
#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void(0)
#endif

template <class T> std::istream& operator>>(std::istream& is, std::vector<T>& v) {
    for (auto& e : v) {
        is >> e;
    }
    return is;
}

template <class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
    for (std::string_view sep = ""; const auto& e : v) {
        os << std::exchange(sep, " ") << e;
    }
    return os;
}

template <class T, class U = T> bool chmin(T& x, U&& y) {
    return y < x and (x = std::forward<U>(y), true);
}

template <class T, class U = T> bool chmax(T& x, U&& y) {
    return x < y and (x = std::forward<U>(y), true);
}

template <class T> void mkuni(std::vector<T>& v) {
    std::ranges::sort(v);
    auto result = std::ranges::unique(v);
    v.erase(result.begin(), result.end());
}

template <class T> int lwb(const std::vector<T>& v, const T& x) {
    return std::distance(v.begin(), std::ranges::lower_bound(v, x));
}

#include <type_traits>

#ifdef _MSC_VER
#include <intrin.h>
#endif

#ifdef _MSC_VER
#include <intrin.h>
#endif

namespace atcoder {

namespace internal {

// @param m `1 <= m`
// @return x mod m
constexpr long long safe_mod(long long x, long long m) {
    x %= m;
    if (x < 0) x += m;
    return x;
}

// Fast modular multiplication by barrett reduction
// Reference: https://en.wikipedia.org/wiki/Barrett_reduction
// NOTE: reconsider after Ice Lake
struct barrett {
    unsigned int _m;
    unsigned long long im;

    // @param m `1 <= m < 2^31`
    explicit barrett(unsigned int m) : _m(m), im((unsigned long long)(-1) / m + 1) {}

    // @return m
    unsigned int umod() const { return _m; }

    // @param a `0 <= a < m`
    // @param b `0 <= b < m`
    // @return `a * b % m`
    unsigned int mul(unsigned int a, unsigned int b) const {
        // [1] m = 1
        // a = b = im = 0, so okay

        // [2] m >= 2
        // im = ceil(2^64 / m)
        // -> im * m = 2^64 + r (0 <= r < m)
        // let z = a*b = c*m + d (0 <= c, d < m)
        // a*b * im = (c*m + d) * im = c*(im*m) + d*im = c*2^64 + c*r + d*im
        // c*r + d*im < m * m + m * im < m * m + 2^64 + m <= 2^64 + m * (m + 1) < 2^64 * 2
        // ((ab * im) >> 64) == c or c + 1
        unsigned long long z = a;
        z *= b;
#ifdef _MSC_VER
        unsigned long long x;
        _umul128(z, im, &x);
#else
        unsigned long long x =
            (unsigned long long)(((unsigned __int128)(z)*im) >> 64);
#endif
        unsigned int v = (unsigned int)(z - x * _m);
        if (_m <= v) v += _m;
        return v;
    }
};

// @param n `0 <= n`
// @param m `1 <= m`
// @return `(x ** n) % m`
constexpr long long pow_mod_constexpr(long long x, long long n, int m) {
    if (m == 1) return 0;
    unsigned int _m = (unsigned int)(m);
    unsigned long long r = 1;
    unsigned long long y = safe_mod(x, m);
    while (n) {
        if (n & 1) r = (r * y) % _m;
        y = (y * y) % _m;
        n >>= 1;
    }
    return r;
}

// Reference:
// M. Forisek and J. Jancina,
// Fast Primality Testing for Integers That Fit into a Machine Word
// @param n `0 <= n`
constexpr bool is_prime_constexpr(int n) {
    if (n <= 1) return false;
    if (n == 2 || n == 7 || n == 61) return true;
    if (n % 2 == 0) return false;
    long long d = n - 1;
    while (d % 2 == 0) d /= 2;
    constexpr long long bases[3] = {2, 7, 61};
    for (long long a : bases) {
        long long t = d;
        long long y = pow_mod_constexpr(a, t, n);
        while (t != n - 1 && y != 1 && y != n - 1) {
            y = y * y % n;
            t <<= 1;
        }
        if (y != n - 1 && t % 2 == 0) {
            return false;
        }
    }
    return true;
}
template <int n> constexpr bool is_prime = is_prime_constexpr(n);

// @param b `1 <= b`
// @return pair(g, x) s.t. g = gcd(a, b), xa = g (mod b), 0 <= x < b/g
constexpr std::pair<long long, long long> inv_gcd(long long a, long long b) {
    a = safe_mod(a, b);
    if (a == 0) return {b, 0};

    // Contracts:
    // [1] s - m0 * a = 0 (mod b)
    // [2] t - m1 * a = 0 (mod b)
    // [3] s * |m1| + t * |m0| <= b
    long long s = b, t = a;
    long long m0 = 0, m1 = 1;

    while (t) {
        long long u = s / t;
        s -= t * u;
        m0 -= m1 * u;  // |m1 * u| <= |m1| * s <= b

        // [3]:
        // (s - t * u) * |m1| + t * |m0 - m1 * u|
        // <= s * |m1| - t * u * |m1| + t * (|m0| + |m1| * u)
        // = s * |m1| + t * |m0| <= b

        auto tmp = s;
        s = t;
        t = tmp;
        tmp = m0;
        m0 = m1;
        m1 = tmp;
    }
    // by [3]: |m0| <= b/g
    // by g != b: |m0| < b/g
    if (m0 < 0) m0 += b / s;
    return {s, m0};
}

// Compile time primitive root
// @param m must be prime
// @return primitive root (and minimum in now)
constexpr int primitive_root_constexpr(int m) {
    if (m == 2) return 1;
    if (m == 167772161) return 3;
    if (m == 469762049) return 3;
    if (m == 754974721) return 11;
    if (m == 998244353) return 3;
    int divs[20] = {};
    divs[0] = 2;
    int cnt = 1;
    int x = (m - 1) / 2;
    while (x % 2 == 0) x /= 2;
    for (int i = 3; (long long)(i)*i <= x; i += 2) {
        if (x % i == 0) {
            divs[cnt++] = i;
            while (x % i == 0) {
                x /= i;
            }
        }
    }
    if (x > 1) {
        divs[cnt++] = x;
    }
    for (int g = 2;; g++) {
        bool ok = true;
        for (int i = 0; i < cnt; i++) {
            if (pow_mod_constexpr(g, (m - 1) / divs[i], m) == 1) {
                ok = false;
                break;
            }
        }
        if (ok) return g;
    }
}
template <int m> constexpr int primitive_root = primitive_root_constexpr(m);

// @param n `n < 2^32`
// @param m `1 <= m < 2^32`
// @return sum_{i=0}^{n-1} floor((ai + b) / m) (mod 2^64)
unsigned long long floor_sum_unsigned(unsigned long long n,
                                      unsigned long long m,
                                      unsigned long long a,
                                      unsigned long long b) {
    unsigned long long ans = 0;
    while (true) {
        if (a >= m) {
            ans += n * (n - 1) / 2 * (a / m);
            a %= m;
        }
        if (b >= m) {
            ans += n * (b / m);
            b %= m;
        }

        unsigned long long y_max = a * n + b;
        if (y_max < m) break;
        // y_max < m * (n + 1)
        // floor(y_max / m) <= n
        n = (unsigned long long)(y_max / m);
        b = (unsigned long long)(y_max % m);
        std::swap(m, a);
    }
    return ans;
}

}  // namespace internal

}  // namespace atcoder

namespace atcoder {

namespace internal {

#ifndef _MSC_VER
template <class T>
using is_signed_int128 =
    typename std::conditional<std::is_same<T, __int128_t>::value ||
                                  std::is_same<T, __int128>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using is_unsigned_int128 =
    typename std::conditional<std::is_same<T, __uint128_t>::value ||
                                  std::is_same<T, unsigned __int128>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using make_unsigned_int128 =
    typename std::conditional<std::is_same<T, __int128_t>::value,
                              __uint128_t,
                              unsigned __int128>;

template <class T>
using is_integral = typename std::conditional<std::is_integral<T>::value ||
                                                  is_signed_int128<T>::value ||
                                                  is_unsigned_int128<T>::value,
                                              std::true_type,
                                              std::false_type>::type;

template <class T>
using is_signed_int = typename std::conditional<(is_integral<T>::value &&
                                                 std::is_signed<T>::value) ||
                                                    is_signed_int128<T>::value,
                                                std::true_type,
                                                std::false_type>::type;

template <class T>
using is_unsigned_int =
    typename std::conditional<(is_integral<T>::value &&
                               std::is_unsigned<T>::value) ||
                                  is_unsigned_int128<T>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using to_unsigned = typename std::conditional<
    is_signed_int128<T>::value,
    make_unsigned_int128<T>,
    typename std::conditional<std::is_signed<T>::value,
                              std::make_unsigned<T>,
                              std::common_type<T>>::type>::type;

#else

template <class T> using is_integral = typename std::is_integral<T>;

template <class T>
using is_signed_int =
    typename std::conditional<is_integral<T>::value && std::is_signed<T>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using is_unsigned_int =
    typename std::conditional<is_integral<T>::value &&
                                  std::is_unsigned<T>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using to_unsigned = typename std::conditional<is_signed_int<T>::value,
                                              std::make_unsigned<T>,
                                              std::common_type<T>>::type;

#endif

template <class T>
using is_signed_int_t = std::enable_if_t<is_signed_int<T>::value>;

template <class T>
using is_unsigned_int_t = std::enable_if_t<is_unsigned_int<T>::value>;

template <class T> using to_unsigned_t = typename to_unsigned<T>::type;

}  // namespace internal

}  // namespace atcoder

namespace atcoder {

namespace internal {

struct modint_base {};
struct static_modint_base : modint_base {};

template <class T> using is_modint = std::is_base_of<modint_base, T>;
template <class T> using is_modint_t = std::enable_if_t<is_modint<T>::value>;

}  // namespace internal

template <int m, std::enable_if_t<(1 <= m)>* = nullptr>
struct static_modint : internal::static_modint_base {
    using mint = static_modint;

  public:
    static constexpr int mod() { return m; }
    static mint raw(int v) {
        mint x;
        x._v = v;
        return x;
    }

    static_modint() : _v(0) {}
    template <class T, internal::is_signed_int_t<T>* = nullptr>
    static_modint(T v) {
        long long x = (long long)(v % (long long)(umod()));
        if (x < 0) x += umod();
        _v = (unsigned int)(x);
    }
    template <class T, internal::is_unsigned_int_t<T>* = nullptr>
    static_modint(T v) {
        _v = (unsigned int)(v % umod());
    }

    unsigned int val() const { return _v; }

    mint& operator++() {
        _v++;
        if (_v == umod()) _v = 0;
        return *this;
    }
    mint& operator--() {
        if (_v == 0) _v = umod();
        _v--;
        return *this;
    }
    mint operator++(int) {
        mint result = *this;
        ++*this;
        return result;
    }
    mint operator--(int) {
        mint result = *this;
        --*this;
        return result;
    }

    mint& operator+=(const mint& rhs) {
        _v += rhs._v;
        if (_v >= umod()) _v -= umod();
        return *this;
    }
    mint& operator-=(const mint& rhs) {
        _v -= rhs._v;
        if (_v >= umod()) _v += umod();
        return *this;
    }
    mint& operator*=(const mint& rhs) {
        unsigned long long z = _v;
        z *= rhs._v;
        _v = (unsigned int)(z % umod());
        return *this;
    }
    mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); }

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

    mint pow(long long n) const {
        assert(0 <= n);
        mint x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    mint inv() const {
        if (prime) {
            assert(_v);
            return pow(umod() - 2);
        } else {
            auto eg = internal::inv_gcd(_v, m);
            assert(eg.first == 1);
            return eg.second;
        }
    }

    friend mint operator+(const mint& lhs, const mint& rhs) {
        return mint(lhs) += rhs;
    }
    friend mint operator-(const mint& lhs, const mint& rhs) {
        return mint(lhs) -= rhs;
    }
    friend mint operator*(const mint& lhs, const mint& rhs) {
        return mint(lhs) *= rhs;
    }
    friend mint operator/(const mint& lhs, const mint& rhs) {
        return mint(lhs) /= rhs;
    }
    friend bool operator==(const mint& lhs, const mint& rhs) {
        return lhs._v == rhs._v;
    }
    friend bool operator!=(const mint& lhs, const mint& rhs) {
        return lhs._v != rhs._v;
    }

  private:
    unsigned int _v;
    static constexpr unsigned int umod() { return m; }
    static constexpr bool prime = internal::is_prime<m>;
};

template <int id> struct dynamic_modint : internal::modint_base {
    using mint = dynamic_modint;

  public:
    static int mod() { return (int)(bt.umod()); }
    static void set_mod(int m) {
        assert(1 <= m);
        bt = internal::barrett(m);
    }
    static mint raw(int v) {
        mint x;
        x._v = v;
        return x;
    }

    dynamic_modint() : _v(0) {}
    template <class T, internal::is_signed_int_t<T>* = nullptr>
    dynamic_modint(T v) {
        long long x = (long long)(v % (long long)(mod()));
        if (x < 0) x += mod();
        _v = (unsigned int)(x);
    }
    template <class T, internal::is_unsigned_int_t<T>* = nullptr>
    dynamic_modint(T v) {
        _v = (unsigned int)(v % mod());
    }

    unsigned int val() const { return _v; }

    mint& operator++() {
        _v++;
        if (_v == umod()) _v = 0;
        return *this;
    }
    mint& operator--() {
        if (_v == 0) _v = umod();
        _v--;
        return *this;
    }
    mint operator++(int) {
        mint result = *this;
        ++*this;
        return result;
    }
    mint operator--(int) {
        mint result = *this;
        --*this;
        return result;
    }

    mint& operator+=(const mint& rhs) {
        _v += rhs._v;
        if (_v >= umod()) _v -= umod();
        return *this;
    }
    mint& operator-=(const mint& rhs) {
        _v += mod() - rhs._v;
        if (_v >= umod()) _v -= umod();
        return *this;
    }
    mint& operator*=(const mint& rhs) {
        _v = bt.mul(_v, rhs._v);
        return *this;
    }
    mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); }

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

    mint pow(long long n) const {
        assert(0 <= n);
        mint x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    mint inv() const {
        auto eg = internal::inv_gcd(_v, mod());
        assert(eg.first == 1);
        return eg.second;
    }

    friend mint operator+(const mint& lhs, const mint& rhs) {
        return mint(lhs) += rhs;
    }
    friend mint operator-(const mint& lhs, const mint& rhs) {
        return mint(lhs) -= rhs;
    }
    friend mint operator*(const mint& lhs, const mint& rhs) {
        return mint(lhs) *= rhs;
    }
    friend mint operator/(const mint& lhs, const mint& rhs) {
        return mint(lhs) /= rhs;
    }
    friend bool operator==(const mint& lhs, const mint& rhs) {
        return lhs._v == rhs._v;
    }
    friend bool operator!=(const mint& lhs, const mint& rhs) {
        return lhs._v != rhs._v;
    }

  private:
    unsigned int _v;
    static internal::barrett bt;
    static unsigned int umod() { return bt.umod(); }
};
template <int id> internal::barrett dynamic_modint<id>::bt(998244353);

using modint998244353 = static_modint<998244353>;
using modint1000000007 = static_modint<1000000007>;
using modint = dynamic_modint<-1>;

namespace internal {

template <class T>
using is_static_modint = std::is_base_of<internal::static_modint_base, T>;

template <class T>
using is_static_modint_t = std::enable_if_t<is_static_modint<T>::value>;

template <class> struct is_dynamic_modint : public std::false_type {};
template <int id>
struct is_dynamic_modint<dynamic_modint<id>> : public std::true_type {};

template <class T>
using is_dynamic_modint_t = std::enable_if_t<is_dynamic_modint<T>::value>;

}  // namespace internal

}  // namespace atcoder

using namespace std;

using ll = long long;

using mint = atcoder::modint1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    int n, m;
    cin >> n >> m;
    vector<ll> x(n), v(m);
    cin >> x >> v;

    vector<pair<int, int>> ord;
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) {
            ord.emplace_back(i, j);
        }
    }
    ranges::sort(ord, [&](auto p, auto q) {
        ll L = x[p.second] * v[q.first], R = x[q.second] * v[p.first];
        return L > R;
    });
    mint ans = 0;
    int half = m / 2;
    vector<mint> dp(half + 1, 0);
    dp[0] = 1;
    vector<mint> cnt(m, 0);

    for (auto [i, j] : ord) {
        if (cnt[i] != 0) {
            auto a = cnt[i] / n, b = 1 - a;  // ax + b
            mint inv = mint(b).inv();
            for (int k = 0; k <= half; k++) {
                if (dp[k] == 0) continue;
                dp[k] *= inv;
                if (k + 1 <= half) dp[k + 1] -= dp[k] * a;
            }
        }
        ans += dp[m / 2] * (-x[j]) / v[i];
        cnt[i]++;
        {
            auto a = cnt[i] / n, b = 1 - a;
            for (int k = half; k >= 0; k--) {
                if (dp[k] == 0) continue;
                if (k + 1 <= half) dp[k + 1] += dp[k] * a;
                dp[k] *= b;
            }
        }
    }
    ans /= n;

    cout << ans.val() << "\n";
    return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 3
-4 -5
1 2 3

output:

250000004

result:

ok single line: '250000004'

Test #2:

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

input:

3 3
-4 -5 -6
1 2 3

output:

500000006

result:

ok single line: '500000006'

Test #3:

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

input:

5 5
-4 -5 -6 -10 -2
1 2 3 2 4

output:

434986672

result:

ok single line: '434986672'

Test #4:

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

input:

1 1
-1000000000
1000000000

output:

1

result:

ok single line: '1'

Test #5:

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

input:

1 1
-1
1000000000

output:

857142863

result:

ok single line: '857142863'

Test #6:

score: 0
Accepted
time: 871ms
memory: 5204kb

input:

500 499
-99999989 -99999971 -99999959 -99999941 -99999931 -99999847 -99999839 -99999827 -99999821 -99999787 -99999773 -99999721 -99999703 -99999677 -99999643 -99999623 -99999617 -99999611 -99999589 -99999587 -99999563 -99999551 -99999547 -99999541 -99999539 -99999517 -99999509 -99999481 -99999439 -9...

output:

799064702

result:

ok single line: '799064702'

Test #7:

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

input:

3 5
-16 -3 -95
2 45 28 73 42

output:

434596897

result:

ok single line: '434596897'

Test #8:

score: 0
Accepted
time: 813ms
memory: 5184kb

input:

495 495
-56840 -9237 -60089 -44275 -46467 -64675 -21377 -17888 -93998 -40048 -76558 -77291 -61902 -18270 -79113 -93227 -80460 -51700 -19773 -22360 -54041 -34077 -46332 -36368 -34148 -63946 -76248 -35988 -16198 -63916 -82091 -79432 -17655 -22619 -96368 -4918 -15925 -11410 -67847 -12556 -83748 -50256 ...

output:

178310831

result:

ok single line: '178310831'

Test #9:

score: 0
Accepted
time: 789ms
memory: 5188kb

input:

499 493
-40336 -95406 -37496 -20002 -22729 -581 -50775 -25098 -49638 -27716 -8861 -90393 -28538 -93691 -25957 -79160 -31047 -99345 -45180 -67081 -95687 -34815 -69670 -16093 -775 -69106 -44730 -44606 -22759 -32493 -57473 -18439 -99899 -50277 -28826 -27910 -25101 -99363 -57465 -96417 -50744 -90086 -19...

output:

989986453

result:

ok single line: '989986453'

Test #10:

score: 0
Accepted
time: 810ms
memory: 5224kb

input:

495 497
-12600 -35662 -4701 -26272 -28214 -52664 -70349 -77540 -51620 -30771 -45113 -66807 -21028 -19308 -79396 -60440 -36826 -74484 -98164 -67210 -76461 -48736 -60083 -39957 -98666 -41802 -77296 -14531 -68225 -75086 -41372 -324 -25606 -15822 -70638 -34123 -45585 -75119 -91039 -43758 -70334 -79546 -...

output:

73594750

result:

ok single line: '73594750'

Test #11:

score: 0
Accepted
time: 816ms
memory: 5244kb

input:

496 495
-19457 -75919 -4611 -91327 -57891 -4747 -22626 -73086 -20898 -90722 -81364 -19029 -80815 -44925 -65539 -50232 -42605 -49623 -40747 -67340 -33043 -5762 -17792 -96525 -72365 -4098 -75270 -51752 -80987 -84976 -68375 -14914 -27121 -15960 -36641 -48847 -31478 -83579 -33125 -47995 -48709 -27790 -4...

output:

155618967

result:

ok single line: '155618967'

Test #12:

score: 0
Accepted
time: 795ms
memory: 5148kb

input:

496 495
-31103 -8414 -77086 -58518 -21191 -58160 -27790 -12251 -12555 -54099 -29345 -99147 -16802 -17132 -32848 -18460 -14952 -87427 -67835 -57963 -15645 -84167 -96866 -96982 -16518 -76936 -48941 -29312 -80779 -93275 -31525 -9329 -78071 -32058 -78520 -691 -40156 -26625 -99897 -75702 -53260 -85586 -1...

output:

237106967

result:

ok single line: '237106967'

Test #13:

score: 0
Accepted
time: 795ms
memory: 5228kb

input:

495 495
-84317 -84140 -53347 -27127 -9373 -32667 -50726 -99919 -12154 -34497 -71789 -74568 -39454 -27257 -91947 -33401 -73063 -40660 -9481 -58700 -71688 -63892 -96197 -2143 -17704 -77043 -31310 -97890 -80353 -32282 -13769 -36987 -77826 -65450 -87695 -88645 -97070 -86294 -56492 -80940 -5051 -54343 -4...

output:

75990388

result:

ok single line: '75990388'

Test #14:

score: 0
Accepted
time: 796ms
memory: 5188kb

input:

498 495
-51523 -90411 -83024 -79210 -37459 -60917 -52708 -35678 -48405 -86719 -64279 -8697 -25597 -84345 -97726 -8540 -82942 -40790 -66063 -48430 -62101 -20460 -61384 -64438 -50270 -79672 -44072 -40483 -40060 -38359 -47988 -2533 -19637 -4366 -8180 -97105 -39156 -90532 -10675 -29184 -57766 -55522 -88...

output:

782279106

result:

ok single line: '782279106'

Test #15:

score: 0
Accepted
time: 805ms
memory: 5224kb

input:

493 495
-75624 -55466 -88509 -7101 -89736 -80654 -21986 -30221 -84657 -63133 -80962 -34314 -79036 -74137 -36209 -83680 -68630 -97815 -46837 -62352 -19810 -44324 -91979 -37134 -15540 -49597 -13731 -83076 -23959 -52949 -49503 -35374 -85641 -10579 -94072 -5565 -72730 -5169 -97561 -85940 -77777 -80894 -...

output:

213759565

result:

ok single line: '213759565'

Test #16:

score: 0
Accepted
time: 800ms
memory: 5376kb

input:

495 495
-120197258 -907881619 -376753724 -223789518 -675894450 -176097971 -608625300 -221589720 -739630578 -626611518 -163283045 -81372446 -418769779 -534823144 -116695351 -322804616 -817482049 -148861930 -179261882 -672981184 -258783948 -538547330 -899502656 -499003830 -124548968 -396443505 -492886...

output:

197323734

result:

ok single line: '197323734'

Test #17:

score: 0
Accepted
time: 820ms
memory: 5312kb

input:

498 495
-170117768 -772233153 -115062689 -518658128 -34848040 -624172478 -893605132 -889934284 -85530177 -186724620 -311349681 -50023675 -390016623 -782333269 -376078642 -539652261 -167364352 -107473947 -170070825 -76981921 -615248502 -195202863 -334701986 -159641694 -630484745 -463919419 -73492895 ...

output:

959117392

result:

ok single line: '959117392'

Test #18:

score: 0
Accepted
time: 788ms
memory: 5256kb

input:

496 493
-232317678 -892630912 -188059662 -295986018 -606376125 -469924920 -725207114 -745637339 -793242237 -566576842 -501274875 -533181996 -662670062 -912023061 -662984421 -959227400 -143650040 -625239484 -257327407 -752695843 -506097699 -828226727 -218867174 -212271286 -64650015 -44722048 -5293836...

output:

768539431

result:

ok single line: '768539431'

Test #19:

score: 0
Accepted
time: 780ms
memory: 5172kb

input:

497 495
-294517588 -572837183 -525897851 -218538101 -618095699 -465420466 -706552200 -601340394 -646178488 -91653256 -426358854 -311307613 -640356205 -631647445 -949890199 -378802539 -119935727 -732939614 -489808181 -283185572 -661788112 -166283295 -367873577 -119676686 -498815286 -920491973 -327351...

output:

82799455

result:

ok single line: '82799455'

Test #20:

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

input:

96 95
-74761 -67660 -68148 -38791 -97903 -59994 -50056 -60407 -20011 -28158 -76935 -4150 -72881 -97434 -53960 -49046 -24121 -42834 -20292 -53968 -94047 -21809 -7194 -38333 -4132 -59619 -88652 -54333 -78059 -18425 -23425 -75092 -81725 -81352 -95137 -74568 -17062 -38538 -5596 -51589 -50645 -85307 -205...

output:

944433669

result:

ok single line: '944433669'

Test #21:

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

input:

99 95
-44975 -47436 -93882 -63895 -29133 -93102 -75206 -4275 -35489 -16221 -6333 -53095 -2021 -72139 -56142 -95593 -15261 -73197 -48620 -21872 -29484 -25533 -15149 -39608 -95037 -42139 -25453 -39201 -26107 -11144 -30348 -9392 -84216 -44617 -2284 -13357 -84138 -28106 -10324 -59204 -49897 -4984 -57136...

output:

517770827

result:

ok single line: '517770827'

Test #22:

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

input:

97 97
-84535 -20396 -93791 -70166 -34618 -53697 -94780 -56716 -37471 -51981 -18393 -5317 -94512 -97756 -9581 -52681 -21040 -81040 -91203 -22001 -10258 -47967 -64346 -96176 -36032 -71731 -90724 -9126 -38869 -86441 -46951 -23982 -42627 -77459 -44095 -19570 -70031 -3862 -52410 -6545 -36784 -53228 -9850...

output:

397948133

result:

ok single line: '397948133'

Test #23:

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

input:

99 95
-39162 -2930 -52713 -86540 -17166 -67976 -53803 -76169 -45636 -48254 -40324 -86823 -67457 -72951 -85021 -9595 -80878 -94843 -75137 -45695 -9212 -86132 -99554 -58063 -28922 -52178 -10802 -92333 -22113 -88935 -4107 -24958 -44137 -44812 -79656 -27819 -77905 -41466 -99497 -10753 -6363 -79410 -3829...

output:

780569056

result:

ok single line: '780569056'

Test #24:

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

input:

95 97
-73407 -28033 -59752 -95457 -33805 -11843 -69281 -88424 -42330 -97199 -69465 -85720 -2343 -10986 -43457 -39957 -694 -95451 -10575 -82123 -84463 -20111 -90459 -7880 -98427 -4342 -91554 -85052 -53228 -47428 -30791 -31328 -83987 -50897 -46733 -17388 -82633 -81785 -66046 -30430 -86023 -86653 -7741...

output:

864507241

result:

ok single line: '864507241'

Test #25:

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

input:

97 95
-40613 -34304 -56725 -47540 -61890 -72797 -38558 -24183 -54390 -82125 -61955 -11337 -23078 -777 -81940 -90905 -19086 -95581 -24052 -39149 -99067 -43975 -55646 -37471 -30994 -74267 -71613 -19134 -45639 -62017 -32306 -96873 -49991 -89813 -32625 -25848 -92015 -96423 -85636 -44083 -95634 -87833 -1...

output:

618328141

result:

ok single line: '618328141'

Test #26:

score: 0
Accepted
time: 11ms
memory: 3660kb

input:

97 99
-16372613 -434584647 -66962055 -390284836 -503614617 -387407787 -436984017 -783077830 -699230955 -416438377 -685850920 -436827418 -817911922 -387478963 -649771716 -223428454 -803572168 -933560834 -591669185 -30901620 -905977514 -340049295 -524605343 -235664911 -627628668 -494094555 -527272387 ...

output:

526504944

result:

ok single line: '526504944'

Test #27:

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

input:

99 97
-615706858 -274409750 -518936390 -139326457 -272839767 -226551654 -352766791 -621322789 -686036162 -976795834 -732280061 -334393611 -286946809 -750525510 -55430152 -139458817 -828900496 -101761442 -288804622 -417305344 -293852765 -181826378 -97096248 -541147431 -881865469 -42779423 -933120435 ...

output:

623480952

result:

ok single line: '623480952'

Test #28:

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

input:

95 93
-677906768 -394807509 -296966067 -61878540 -844367853 -72304096 -184368773 -477025844 -538972413 -796839544 -217172551 -672327740 -559600248 -320406790 -342335931 -708777060 -805186183 -209461571 -521285396 -947795074 -744510474 -519882946 -836037243 -888744319 -316030739 -918549348 -207533198...

output:

585910673

result:

ok single line: '585910673'

Test #29:

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

input:

8 5
-34 -11437 -50741 -11651 -8757 -3788 -90502 -96093
29605 21399 25048 97749 43910

output:

397491239

result:

ok single line: '397491239'

Test #30:

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

input:

9 3
-49027 -30756 -41587 -49117 -99978 -12167 -89480 -34923 -76073
48874 27241 41726

output:

200471110

result:

ok single line: '200471110'

Test #31:

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

input:

8 7
-21754 -75789 -63567 -6142 -57612 -70958 -30693 -36706
559461045 787850364 98787162 462848465 847196706 998165849 963086182

output:

19131642

result:

ok single line: '19131642'

Test #32:

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

input:

8 5
-45305 -13255 -30596 -81817 -13486 -18299 -77160 -21077
45663238 739218533 309380317 996252523 67640780

output:

69088620

result:

ok single line: '69088620'

Test #33:

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

input:

6 5
-888287910 -483857506 -267440205 -681604438 -522130871 -551510769
60907 71071 46364 40487 97757

output:

241557038

result:

ok single line: '241557038'

Test #34:

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

input:

6 5
-467446052 -264329564 -685207234 -300112817 -954919449 -1382303
7375 98546 57069 8656 58208

output:

324676237

result:

ok single line: '324676237'

Extra Test:

score: 0
Extra Test Passed