B - Xor of Sequences Editorial by en_translator

Since \(1 ≤ A_i, B_i ≤ 10^3\), one can check for each of \(1, 2, \dots, 10^3\) if it appears in \(A\) and if it appears in \(B\), and output the result accordingly, in order to solve the problem.
Also, one can utilize the features of each language to solve it easier.

Sample Code (C++)

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> A(N), B(M);
    for(int& i : A) cin >> i;
    for(int& i : B) cin >> i;
    vector<int> C;
    set_symmetric_difference(A.begin(), A.end(), B.begin(), B.end(), back_inserter(C));
    for(int i : C) cout << i << ' ';

Sample Code (Python)

A = set(map(int, input().split()))
B = set(map(int, input().split()))
print(*sorted(A ^ B))

last update: