#include #if __has_include() #include using namespace atcoder; using mint = modint998244353; // using mint = modint1000000007; #endif #pragma GCC target("avx2") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; inline void scan(int &a) { cin >> a; } inline void scan(unsigned int &a) { cin >> a; } inline void scan(long long &a) { cin >> a; } inline void scan(unsigned long long &a) { cin >> a; } inline void scan(float &a) { cin >> a; } inline void scan(double &a) { cin >> a; } inline void scan(long double &a) { cin >> a; } inline void scan(char &a) { cin >> a; } inline void scan(string &a) { cin >> a; } inline void scan(vector &vec) { for (int i = 0; i < int(vec.size()); i++) { int a; scan(a); vec[i] = a; } } template inline void scan(vector &vec); template inline void scan(array &vec); template inline void scan(deque &deq); template inline void scan(pair &p); template inline void scan(vector &vec) { for (auto &i : vec) scan(i); } template inline void scan(array &vec) { for (auto &i : vec) scan(i); } template inline void scan(deque &deq) { for (auto &i : deq) scan(i); } template inline void scan(pair &p) { scan(p.first); scan(p.second); } template inline void scan(T &a) { cin >> a; } inline void read() { } template inline void read(T &a, U &...b) { scan(a); read(b...); } inline void write(const int &a) { cout << a; } inline void write(const unsigned int &a) { cout << a; } inline void write(const long long &a) { cout << a; } inline void write(const unsigned long long &a) { cout << a; } inline void write(const float &a) { cout << a; } inline void write(const double &a) { cout << a; } inline void write(const long double &a) { cout << a; } inline void write(const char &a) { cout << a; } inline void write(const string &a) { cout << a; } template inline void write(const vector &vec); template inline void write(const array &vec); template inline void write(const deque &deq); template inline void write(const pair &p); template inline void write(const vector &vec) { for (int i = 0; i < int(vec.size()); i++) { if (i) write(' '); write(vec[i]); } } template inline void write(const array &vec) { for (int i = 0; i < int(vec.size()); i++) { if (i) write(' '); write(vec[i]); } } template inline void write(const deque &deq) { for (int i = 0; i < int(deq.size()); i++) { if (i) write(' '); write(deq[i]); } } template inline void write(const pair &p) { write(p.first); write(' '); write(p.second); } template inline void write(const T &a) { cout << a; } inline void print() { cout << '\n'; } template inline void print(const T &a) { write(a); cout << '\n'; } template inline void print(const T &a, const U &...b) { write(a); ((cout << ' ', write(b)), ...); write('\n'); } template inline void debug_impl(const char *name, const T &value) { cerr << name << " = "; write(value); cerr << '\n'; } template inline void debug_impl(const char *names, const T &value, const U &...values) { const char *comma = strchr(names, ','); cerr.write(names, comma - names); cerr << " = "; write(value); cerr << ", "; while (*++comma == ' '); debug_impl(comma, values...); } using ll = long long; using ld = long double; using ull = unsigned long long; using pii = pair; using pll = pair; template using pq = priority_queue; template using pq_g = priority_queue, greater>; #define overload3(a, b, c, d, ...) d #define overload4(a, b, c, d, e, ...) e #define rep1(n) for (ll i = 0; i < (n); i++) #define rep2(i, n) for (ll i = 0; i < (n); i++) #define rep3(i, a, b) for (ll i = (a); i < (b); i++) #define rep4(i, a, b, c) for (ll i = (a); i < (b); i += (c)) #define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__) #define rrep1(n) for (ll i = (n) - 1; i >= 0; i--) #define rrep2(i, n) for (ll i = (n) - 1; i >= 0; i--) #define rrep3(i, a, b) for (ll i = (b) - 1; i >= (a); i--) #define rrep4(i, a, b, c) for (ll i = (a) + ((b) - (a) - 1) / (c) * (c); i >= (a); i -= (c)) #define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__) #define all1(v) (v).begin(), (v).end() #define all2(v, n) (v).begin(), (v).begin() + (n) #define all3(v, a, b) (v).begin() + (a), (v).begin() + (b) #define all(...) overload3(__VA_ARGS__, all3, all2, all1)(__VA_ARGS__) #define rall(v) (v).rbegin(), (v).rend() #define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end()) #define NP next_permutation #define endl '\n' #define INT(...) int __VA_ARGS__; read(__VA_ARGS__); #define LL(...) long long __VA_ARGS__; read(__VA_ARGS__); #define ULL(...) unsigned long long __VA_ARGS__; read(__VA_ARGS__); #define STR(...) string __VA_ARGS__; read(__VA_ARGS__); #define CHAR(...) char __VA_ARGS__; read(__VA_ARGS__); #define LD(...) long double __VA_ARGS__; read(__VA_ARGS__); #define VEC(type, name, size) vector name(size); read(name); #define VV(type, name, h, w) vector> name(h, vector(w)); read(name); #ifdef LOCAL #define debug(...) debug_impl(#__VA_ARGS__, __VA_ARGS__) #else #define debug(...) ((void)0) #endif inline void Yes(bool a = true) { cout << (a ? "Yes" : "No") << endl; } inline void No(bool a = true) { cout << (a ? "No" : "Yes") << endl; } inline void YES(bool a = true) { cout << (a ? "YES" : "NO") << endl; } inline void NO(bool a = true) { cout << (a ? "NO" : "YES") << endl; } inline void Takahashi(bool a = true) { cout << (a ? "Takahashi" : "Aoki") << endl; } inline void Alice(bool a = true) { cout << (a ? "Alice" : "Bob") << endl; } inline void Possible(bool a = true) { cout << (a ? "Possible" : "Impossible") << endl; } constexpr int INF = 1001001001; constexpr ll LINF = 4004004004004004004LL; constexpr ld pi = 3.14159265358979323846; constexpr ld eps = 1e-9; constexpr int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 }; constexpr int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 }; ll modPow(ll a, ll n, ll mod = LINF) { ll ret = 1; ll x = a % mod; while (n) { if (n & 1) ret = ret * x % mod; x = x * x % mod; n >>= 1; } return ret; } int topbit(int x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); } int topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); } int lowbit(int x) { return (x == 0 ? -1 : __builtin_ctz(x)); } int lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctz(x)); } int popcount(int x) { return __builtin_popcount(x); } ll popcount(ll x) { return __builtin_popcountll(x); } ll isqrt(ll x) { ll n = sqrtl(x); while ((n + 1) * (n + 1) <= x) n++; while (n * n > x) n--; return n; } template T floor(T a, T b) { return a / b - (a % b && (a ^ b) < 0); } template T ceil(T a, T b) { return floor(a + b - 1, b); } template T bmod(T a, T b) { return a - b * floor(a, b); } template pair divmod(T a, T b) { return { floor(a, b), a - b * floor(a, b) }; } template auto MIN(const vector &a) { return *min_element(all(a)); } template auto MAX(const vector &a) { return *max_element(all(a)); } template auto SUM(const vector &a) { return accumulate(all(a), T(0)); } template bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } void cincout() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); } #include using namespace std; namespace HashMapImpl { using u32 = uint32_t; using u64 = uint64_t; template struct HashMapBase; template struct itrB : iterator { using base = iterator; using ptr = typename base::pointer; using ref = typename base::reference; u32 i; HashMapBase* p; explicit constexpr itrB() : i(0), p(nullptr) {} explicit constexpr itrB(u32 _i, HashMapBase* _p) : i(_i), p(_p) {} explicit constexpr itrB(u32 _i, const HashMapBase* _p) : i(_i), p(const_cast*>(_p)) {} friend void swap(itrB& l, itrB& r) { swap(l.i, r.i), swap(l.p, r.p); } friend bool operator==(const itrB& l, const itrB& r) { return l.i == r.i; } friend bool operator!=(const itrB& l, const itrB& r) { return l.i != r.i; } const ref operator*() const { return const_cast*>(p)->data[i]; } ref operator*() { return p->data[i]; } ptr operator->() const { return &(p->data[i]); } itrB& operator++() { assert(i != p->cap && "itr::operator++()"); do { i++; if (i == p->cap) break; if (p->occupied_flag[i] && !p->deleted_flag[i]) break; } while (true); return (*this); } itrB operator++(int) { itrB it(*this); ++(*this); return it; } itrB& operator--() { do { i--; if (p->occupied_flag[i] && !p->deleted_flag[i]) break; assert(i != 0 && "itr::operator--()"); } while (true); return (*this); } itrB operator--(int) { itrB it(*this); --(*this); return it; } }; template struct HashMapBase { using u32 = uint32_t; using u64 = uint64_t; using iterator = itrB; using itr = iterator; protected: template inline u64 randomized(const K& key) const { return u64(key) ^ r; } template ::value, nullptr_t> = nullptr, enable_if_t::value, nullptr_t> = nullptr> inline u32 inner_hash(const K& key) const { return (randomized(key) * 11995408973635179863ULL) >> shift; } template < typename K, enable_if_t::value, nullptr_t> = nullptr, enable_if_t::value, nullptr_t> = nullptr, enable_if_t::value, nullptr_t> = nullptr> inline u32 inner_hash(const K& key) const { u64 a = randomized(key.first), b = randomized(key.second); a *= 11995408973635179863ULL; b *= 10150724397891781847ULL; return (a + b) >> shift; } template ::value, nullptr_t> = nullptr, enable_if_t::value, nullptr_t> = nullptr> inline u32 inner_hash(const K& key) const { static constexpr u64 mod = (1LL << 61) - 1; static constexpr u64 base = 950699498548472943ULL; u64 res = 0; for (auto& elem : key) { __uint128_t x = __uint128_t(res) * base + (randomized(elem) & mod); res = (x & mod) + (x >> 61); } __uint128_t x = __uint128_t(res) * base; res = (x & mod) + (x >> 61); if (res >= mod) res -= mod; return res >> (shift - 3); } template ::value, nullptr_t> = nullptr> inline u32 hash(const D& dat) const { return inner_hash(dat); } template < typename D = Data, enable_if_t::value, nullptr_t> = nullptr> inline u32 hash(const D& dat) const { return inner_hash(dat.first); } template ::value, nullptr_t> = nullptr> inline Key data_to_key(const D& dat) const { return dat; } template < typename D = Data, enable_if_t::value, nullptr_t> = nullptr> inline Key data_to_key(const D& dat) const { return dat.first; } void reallocate(u32 ncap) { vector ndata(ncap); vector nf(ncap); shift = 64 - __lg(ncap); for (u32 i = 0; i < cap; i++) { if (occupied_flag[i] && !deleted_flag[i]) { u32 h = hash(data[i]); while (nf[h]) h = (h + 1) & (ncap - 1); ndata[h] = move(data[i]); nf[h] = true; } } data.swap(ndata); occupied_flag.swap(nf); cap = ncap; occupied = s; deleted_flag.resize(cap); fill(std::begin(deleted_flag), std::end(deleted_flag), false); } inline bool extend_rate(u32 x) const { return x * 2 >= cap; } inline bool shrink_rate(u32 x) const { return HASHMAP_DEFAULT_SIZE < cap && x * 10 <= cap; } inline void extend() { reallocate(cap << 1); } inline void shrink() { reallocate(cap >> 1); } public: u32 cap, s, occupied; vector data; vector occupied_flag, deleted_flag; u32 shift; static u64 r; static constexpr uint32_t HASHMAP_DEFAULT_SIZE = 4; explicit HashMapBase() : cap(HASHMAP_DEFAULT_SIZE), s(0), occupied(0), data(cap), occupied_flag(cap), deleted_flag(cap), shift(64 - __lg(cap)) {} itr begin() const { u32 h = 0; while (h != cap) { if (occupied_flag[h] && !deleted_flag[h]) break; h++; } return itr(h, this); } itr end() const { return itr(this->cap, this); } friend itr begin(const HashMapBase& h) { return h.begin(); } friend itr end(const HashMapBase& h) { return h.end(); } itr find(const Key& key) const { u32 h = inner_hash(key); while (true) { if (occupied_flag[h] == false) return this->end(); if (data_to_key(data[h]) == key) { if (deleted_flag[h] == true) return this->end(); return itr(h, this); } h = (h + 1) & (cap - 1); } } bool contain(const Key& key) const { return find(key) != this->end(); } itr insert(const Data& d) { u32 h = hash(d); while (true) { if (occupied_flag[h] == false) { if (extend_rate(occupied + 1)) { extend(); h = hash(d); continue; } data[h] = d; occupied_flag[h] = true; ++occupied, ++s; return itr(h, this); } if (data_to_key(data[h]) == data_to_key(d)) { if (deleted_flag[h] == true) { data[h] = d; deleted_flag[h] = false; ++s; } return itr(h, this); } h = (h + 1) & (cap - 1); } } // tips for speed up : // if return value is unnecessary, make argument_2 false. itr erase(itr it, bool get_next = true) { if (it == this->end()) return this->end(); s--; if (!get_next) { this->deleted_flag[it.i] = true; if (shrink_rate(s)) shrink(); return this->end(); } itr nxt = it; nxt++; this->deleted_flag[it.i] = true; if (shrink_rate(s)) { Data d = data[nxt.i]; shrink(); it = find(data_to_key(d)); } return nxt; } itr erase(const Key& key) { return erase(find(key)); } int count(const Key& key) { return find(key) == end() ? 0 : 1; } bool empty() const { return s == 0; } int size() const { return s; } void clear() { fill(std::begin(occupied_flag), std::end(occupied_flag), false); fill(std::begin(deleted_flag), std::end(deleted_flag), false); s = occupied = 0; } void reserve(int n) { if (n <= 0) return; n = 1 << min(23, __lg(n) + 2); if (cap < u32(n)) reallocate(n); } }; template uint64_t HashMapBase::r = chrono::duration_cast( chrono::high_resolution_clock::now().time_since_epoch()) .count(); } // namespace HashMapImpl /** * @brief Hash Map(base) (ハッシュマップ・基底クラス) */ template struct HashSet : HashMapImpl::HashMapBase { using HashMapImpl::HashMapBase::HashMapBase; }; int dp[101][100001]; void solve() { INT(N, M); VEC(int, U, N); VEC(int, V, M); const int X = SUM(V) + 1; dp[0][0] = true; for (int i = 0; i < M; i++) for (int j = 0; j <= X; j++) { if (!dp[i][j]) continue; dp[i + 1][j] = true; dp[i + 1][j + V[i]] = true; } HashSet s; for (int j = 0; j <= X; j++) { if (dp[M][j]) { for (int i = 0; i < N; i++) s.insert(U[i] + j); } } print(s.size()); } int main() { cincout(); int t = 1; // cin >> t; while (t--) solve(); return 0; }