B - Who is Missing?
Source: atcoder
Difficulty: 200

Problem Statement
You are given a sequence of
M
integers
A = (A_1, A_2, \dots, A_M)
.
Each element of
A
is an integer between
1
and
N
, inclusive, and all elements are distinct.
List all integers between
1
and
N
that do not appear in
A
in ascending order.
Constraints
All input values are integers.
1 \le M \le N \le 1000
1 \le A_i \le N
The elements of
A
are distinct.
Input
The input is given from Standard Input in the following format:
N
M
A_1
A_2
\dots
A_M
Output
Let
(X_1, X_2, \dots, X_C)
be the sequence of all integers between
1
and
N
, inclusive, that do not appear in
A
, listed in ascending order.
The output should be in the following format:
C
X_1
X_2
\dots
X_C
Sample Input 1
10 3
3 9 2
Sample Output 1
7
1 4 5 6 7 8 10
Here,
A=(3,9,2)
.
The integers between
1
and
10
that do not appear in
A
, listed in ascending order, are
1,4,5,6,7,8,10
.
Sample Input 2
6 6
1 3 5 2 4 6
Sample Output 2
0
No integer between
1
and
6
is missing from
A
.
In this case, print
0
on the first line and leave the second line empty.
Sample Input 3
9 1
9
Sample Output 3
8
1 2 3 4 5 6 7 8

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




// -------# Short Code Defines #-----------------

#define endl '\n'

#define ll long long
#define ld long double

#define all(a) (a).begin(), (a).end()



// -------# Constants #---------------------------

#define PI 3.1415926535897932384626433832795l 
#define mod 1000000007

const int N2 = 1e2 + 5;
const int N3 = 1e3 + 5;
const int N5 = 1e5 + 5;
const int N6 = 1e6 + 5;
const int INF = 1e9 + 5;
const ll INFLL = 1e18 + 5;

const int NCRN = 1e1 + 5;
const int SIEVEN = 1e1 + 5;

vector<pair<int, int> > directions_8 {{-1, -1}, {1, 1}, {1, -1}, {-1, 1}, {0, 1}, {0, -1}, {-1, 0}, {1, 0}};
vector<pair<int, int> >directions_4 {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};




// ------# Useful Function #-----------

ll min(ll a,int b) { if (a<b) return a; return b; }
ll min(int a,ll b) { if (a<b) return a; return b; }
ll max(ll a,int b) { if (a>b) return a; return b; }
ll max(int a,ll b) { if (a>b) return a; return b; }

string to_upper(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A'; return a; }
string to_lower(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A'; return a; }



// -----------# Print Functions #--------------

void yes() { cout<<"YES\n"; }
void no() { cout<<"NO\n"; }

#define printv(a) {for (auto u: a) cout << u << " "; cout << endl; }




// ---------------# Debug #---------------------


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif




// ----------# Modular Arithmetic #-------------

int mul(int a, int b) { return (1ll * a * b) % mod; };
int add(int a, int b) { return (a + b) % mod; };
int sub(int a, int b) { return ((ll)a - (ll)b + (ll)mod) % mod; }
int binExp(int a, int b) { int answer = 1; while(b) { if(b & 1) answer = mul(answer, a);b >>= 1; a = mul(a, a);} return answer; };
int divi(int a, int b) { return (mul(a, binExp(b, mod - 2))); };




// ----------# Number Theory #--------------------

ll gcd(ll a, ll b) { return(b ? __gcd(a,b) : a); };
ll lcm(ll a,ll b) { return (a / gcd(a,b) * b); };



// -------------# Prime Sieve #-------------------



// -------------# Combinatorics #-----------------


int FACT[NCRN];
int IFACT[NCRN];

void ncrInit() {
    FACT[0] = 1;
    for(int i = 1; i < NCRN; i ++) FACT[i] = mul(i, FACT[i - 1]);
    IFACT[NCRN - 1] = binExp(FACT[NCRN - 1], mod - 2);
    for(int i = NCRN - 2; i >= 0; i --) IFACT[i] = mul(IFACT[i + 1], i + 1);
    return;    
}

int ncr(int n, int r) { if(r > n) return 0; return (mul(FACT[n], mul(IFACT[n - r], IFACT[r]))); };
ll ncrll(ll n, ll r) { if(r > n) return 0; if(r == 0) return 1; r = min(r, n - r); ll a = 1, b = 1; while(r) { a = a * n; b = b * r; ll int g = gcd(a, b); a /= g; b /= g; n --; r --; } return a; }

int npr(int n, int r) { if(r > n) return 0; return (mul(FACT[n], IFACT[n - r])); };
ll nprll(ll n, ll r) { if(r > n) return 0; r = min(r, n - r); if(r == 0) return 1; ll ans = 1;while(r) { ans = ans * n; n --; r --; }; return ans; }



// ----------------------------------------------

// ---------------- Precomputation ---------------




void init() {
    
    
    
    
    return;
}

// -----------------------------------------------











void solve() {
    
    int n, m;
    cin >> n >> m;

    set<int> appearing;
    while(m --) {
        int val;
        cin >> val;

        appearing.insert(val);
    }

    vector<int> answer;
    for(int i = 1; i <= n; i ++) {
        if(appearing.find(i) != appearing.end()) continue;
        answer.push_back(i);
    }

    cout << answer.size() << endl;

    for(int i = 0; i < answer.size(); i ++) {
        cout << answer[i] << " ";
    }
    cout << endl;
    
    return; 
}



int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    
    init();

    int t = 1;
    // cin >> t;
    
    int currCase = 1;
    
    while(t --) {
        // cout << "-------# test : " << currCase << " #-------------" << endl;
        
        
        solve();
        
        currCase ++;
    }



return 0;
}

Go solution:
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	sc = bufio.NewScanner(os.Stdin)
)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 256*1024), 1024*1024)
}

func scanInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func main() {
	N, M := scanInt(), scanInt()
	count := make([]int, N)
	for i := 0; i < M; i++ {
		count[scanInt()-1]++
	}

	fmt.Println(N - M)
	ans := make([]string, 0)
	for i, v := range count {
		if v == 0 {
			ans = append(ans, strconv.Itoa(i+1))
		}
	}
	fmt.Println(strings.Join(ans, " "))
}

Java solution:
import java.io.*;
import java.util.*;

public class Main {
    static class MyScanner {
        static BufferedReader r;
        static StringTokenizer st;
        public MyScanner() {
            r = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                while (st == null || !st.hasMoreTokens()) {
                    st = new StringTokenizer(r.readLine());
                }
                return st.nextToken();
            } catch (Exception e) {
                return null;
            }
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
    static class Pair <K, V> {
        K X;
        V Y;

        public Pair(K x, V y) {
            X = x;
            Y = y;
        }

        public Pair() {}

        @Override
        public String toString() {
            return "Pair{" + "X=" + X + ", Y=" + Y + '}';
        }
    }
    static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
    static MyScanner sc = new MyScanner();
    static int N, M;
    static final int MAXN = 200010;
    public static void main(String[] args) throws IOException {
        N = sc.nextInt();
        M = sc.nextInt();
        HashSet<Integer> s = new HashSet<>();
        for (int i = 1; i <= M; i++) {
            s.add(sc.nextInt());
        }
        ArrayList<Integer> ans = new ArrayList<>();
        for (int i = 1; i <= N; i++) if (!s.contains(i)) {
            ans.add(i);
        }
        bw.write(ans.size() + "\n");
        for (var x : ans) {
            bw.write(x + " ");
        }
        bw.flush();
    }
}

JavaScript solution:
function Main(input) {
  const inputs = input.split("\n")
  const [N, M] = inputs[0].split(" ").map((x)=>Number(x))
  const arr_a = inputs[1].split(" ").map((x)=>Number(x))
  const hash ={}
  for (const am of arr_a) {
    hash[am] = true 
  }
  const ans = []
  for (let i=1; i<N+1;i++) {
    if (!(i in hash) ) ans.push(i)
  }
  console.log(ans.length)
  console.log(ans.join(" "))
}

Main(require("fs").readFileSync(0) + "")
// Main(`10 3
// 3 9 2
// `)
// Main(`6 6
// 1 3 5 2 4 6
// `)
// Main(`9 1
// 9
// `)

Python solution:
N,M=map(int,input().split())

A=set(map(int,input().split()))

res=set((i) for i in range(1,N+1))

ans=sorted(res-A)
if not ans:
    print(0)
    print("")
else:
    print(len(ans))
    print(" ".join(map(str,ans)))

Ruby solution:
n, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

all_to_n = (1..n).to_a
ans = (all_to_n - a).sort

puts ans.size
puts ans.join(' ')