1. Abridged Problem Statement  
Vasya has n distinct coins with values a₁…aₙ, and needs to pay exactly x using a subset of them (no change is given). Among all subsets summing to x, find those coin denominations that appear in every such subset. Output the count and list of these “necessary” coins in any order.

2. Detailed Editorial  

Goal  
We want all coins that are present in every possible subset of {a₁…aₙ} whose sum is exactly x. Equivalently, a coin with value aᵢ is “non‐necessary” if there exists at least one valid subset summing to x that does not include it; otherwise it is “necessary.”

Brute Force Is Too Slow  
Checking for each coin i by running a fresh subset‐sum DP on the other n–1 coins would cost O(n·x) per coin, for O(n²·x) total. With n up to 200 and x up to 10⁴, that can be ~4·10⁸ operations—too large.

Prefix‐Suffix DP Trick  
We construct two DP tables:  
- dp_pref[i][s] = whether sum s is achievable using coins a₁…aᵢ  
- dp_suf[i][s] = whether sum s is achievable using coins aᵢ…aₙ  

Then for coin i we ask: can we partition x into s + t = x where s is formed by some subset of coins before i (1…i–1) and t by some subset after i (i+1…n)? If yes, we can pay x without coin i, so it’s non‐necessary. Otherwise it’s necessary.

Implementation with Bitsets  
Since x≤10⁴, we use bitset<MAX> to represent a boolean array of length MAX.  
- dp_pref[i] = dp_pref[i–1] | (dp_pref[i–1] << aᵢ)  
- dp_suf[i] = dp_suf[i+1] | (dp_suf[i+1] << aᵢ)  
Shift and OR propagate all sums that include coin i.

Answer Extraction  
For each i from 1…n, check for any j in [0..x] if dp_pref[i–1][j] and dp_suf[i+1][x−j] are both true. If none such j exists, coin i is necessary.

Time Complexity  
Building both DP arrays: O(n * (x/word_size)) with bitsets. Checking each coin costs O(x). Total is O(n·x/word_size + n·x) which passes under given limits.

3. Provided C++ Solution with Detailed Comments

#include <bits/stdc++.h>
using namespace std;

// Overload output for pair<T1,T2>
template<typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &x) {
    return out << x.first << ' ' << x.second;
}

// Overload input for pair<T1,T2>
template<typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &x) {
    return in >> x.first >> x.second;
}

// Overload input for vector<T>
template<typename T>
istream &operator>>(istream &in, vector<T> &a) {
    for(auto &x: a) {
        in >> x;
    }
    return in;
}

// Overload output for vector<T>
template<typename T>
ostream &operator<<(ostream &out, const vector<T> &a) {
    for(auto x: a) {
        out << x << ' ';
    }
    return out;
}

int n, x;           // n = number of coins, x = target sum
vector<int> a;      // coin values

// Read input
void read() {
    cin >> n >> x;
    a.resize(n);
    cin >> a;       // read all coin values
}

// Maximum bitset length (covers x up to 1e4)
const int MAXLEN = (int)1e4 + 42;

// Recursive template to pick a bitset size >= x+1
template<int bit_len = 1>
void solve(int _x) {
    // If our current template bit length is too small, double it
    if(_x > bit_len) {
        solve< min(bit_len * 2, MAXLEN) >(_x);
        return;
    }

    // dp_prev[i] will hold reachable sums using first i coins
    // dp_suff[i] will hold reachable sums using coins i..n
    vector< bitset<bit_len> > dp_prev(n + 2), dp_suff(n + 2);

    // Base cases: sum 0 is always reachable with no coins
    dp_prev[0][0] = 1;
    dp_suff[n+1][0] = 1;

    // Build prefix DP
    for(int i = 1; i <= n; i++) {
        // carry forward previous reachable sums
        dp_prev[i] = dp_prev[i - 1]
                   // add coin a[i-1] by shifting bits left by that amount
                   | (dp_prev[i - 1] << a[i - 1]);
    }

    // Build suffix DP in reverse
    for(int i = n; i >= 1; i--) {
        dp_suff[i] = dp_suff[i + 1]
                   | (dp_suff[i + 1] << a[i - 1]);
    }

    vector<int> ans;  // store necessary coins

    // For each coin i, test if we can form x without it
    for(int i = 1; i <= n; i++) {
        bool can_skip = false;
        // try every split j + (x-j) = x
        for(int j = 0; j <= x; j++) {
            if(dp_prev[i - 1][j] && dp_suff[i + 1][x - j]) {
                // We can pay x by taking some coins before i summing to j
                // and some after i summing to x-j
                can_skip = true;
                break;
            }
        }
        if(!can_skip) {
            // No way to pay x without coin i => it's necessary
            ans.push_back(a[i - 1]);
        }
    }

    // Output result
    cout << ans.size() << '\n';
    cout << ans << '\n';
}

// Entry point to solve with correct template parameter
void solve() {
    solve<x>(x);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    // Single test case
    read();
    solve();
    return 0;
}

4. Python Solution with Detailed Comments

# Python implementation using integers as bitsets
import sys
def main():
    data = sys.stdin.read().split()
    it = iter(data)
    n = int(next(it))
    x = int(next(it))
    a = [int(next(it)) for _ in range(n)]

    # dp_pref[i] : bitmask of achievable sums using a[0..i-1]
    dp_pref = [0] * (n + 2)
    dp_suf  = [0] * (n + 2)

    # sum=0 is always achievable
    dp_pref[0] = 1 << 0
    dp_suf[n+1] = 1 << 0

    full_mask = (1 << (x + 1)) - 1  # to trim bits > x

    # Build prefix dp
    for i in range(1, n+1):
        prev = dp_pref[i-1]
        shift = (prev << a[i-1]) & full_mask
        dp_pref[i] = prev | shift

    # Build suffix dp
    for i in range(n, 0, -1):
        nxt = dp_suf[i+1]
        shift = (nxt << a[i-1]) & full_mask
        dp_suf[i] = nxt | shift

    necessary = []
    # Check each coin
    for i in range(1, n+1):
        can_skip = False
        # Try all splits j + (x-j) = x
        pref = dp_pref[i-1]
        suf  = dp_suf[i+1]
        # Iterate j=0..x
        for j in range(x+1):
            if (pref >> j) & 1 and (suf >> (x - j)) & 1:
                can_skip = True
                break
        if not can_skip:
            necessary.append(a[i-1])

    # Output
    out = []
    out.append(str(len(necessary)))
    out.append(" ".join(map(str, necessary)))
    sys.stdout.write("\n".join(out))

if __name__ == "__main__":
    main()

5. Compressed Editorial  
Compute two bitset-based subset-sum DPs: one forward (prefix) over coins 1…i, one backward (suffix) over coins i…n. A coin i is necessary if and only if there is no split j+(x−j)=x such that sum j is reachable before i and sum x−j is reachable after i.