#include <iostream>
#include <vector>
#include <unordered_map>
#include <cstdio>
#include <set>
using namespace std;
unordered_map <int, bool> visited;
set <pair<int, int>> path;
vector<vector<int>> t;
int n;
bool check(vector<vector<int>> &t){
  int cnt = 0;
  for(auto p: t){
    if(p.size() > 1) cnt++;
  }
  return cnt <= 1? true: false;
}
int findroot(vector<vector<int>> &t){
  int root = 1;
  for(int i = 1; i <= n; i++){
    if(t[i].size() > t[root].size()){
      root = i;
    }
  }
  return root;
}
void solve(vector<vector<int>> &t, int n){
  vector <int> leaves;
  for(int i = 1; i < t.size(); i++){
    if(t[i].empty()) leaves.push_back(i);
  }
  printf("%d\n", int(leaves.size()));
  for(auto e: leaves){
    printf("%d %d\n", n, e);
  }
}

int main(){
  cin >> n;
  t.resize(n + 1);
  for(int i = 0; i < n - 1; i++){
    int x, y; cin >> x >> y;
    t[x].push_back(y);
  }
  if(!check(t)){
    puts("No");
    return 0;
  }
  puts("Yes");
  solve(t, findroot(t));
  return 0;
}


#include <iostream>
#include <vector>
#include <unordered_map>
#include <cstdio>
#include <set>
using namespace std;
unordered_map <int, bool> visited;
set <pair<int, int>> path;
vector<vector<int>> t;
bool check(vector<vector<int>> &t){
  int cnt = 0;
  for(auto p: t){
    if(p.size() > 1) cnt++;
  }
  return cnt <= 1? true: false;
}
int findroot(vector<vector<int>> &t){
  for(int i = 1; i < t.size(); i++){
    if(t[i].size() > 1){
      return i;
    }
  }
  return 1;
}
void solve(vector<vector<int>> &t, int n){
  vector <int> leaves;
  for(int i = 1; i < t.size(); i++){
    if(t[i].size() == 0) leaves.push_back(i);
  }
  printf("%d\n", int(leaves.size()));
  for(int i = 0; i < leaves.size(); i++){
    printf("%d %d\n", n, leaves[i]);
  }
}

int main(){
  int n; cin >> n;
  t.resize(n + 1);
  for(int i = 0; i < n - 1; i++){
    int x, y; cin >> x >> y;
    t[x].push_back(y);
  }
  if(!check(t)){
    puts("No");
    return 0;
  }
  puts("Yes");
  solve(t, findroot(t));
  return 0;
}


#include <iostream>
#include <vector>
#include <unordered_map>
#include <cstdio>
#include <set>
using namespace std;
unordered_map <int, bool> visited;
set <pair<int, int>> path;
vector<vector<int>> t;
int n;
bool check(vector<vector<int>> &t){
  int cnt = 0;
  for(auto p: t){
    if(p.size() > 1) cnt++;
  }
  return cnt <= 1? true: false;
}
int findroot(vector<vector<int>> &t){
  for(int i = 1; i <= n; i++){
    if(t[i].size() > 1){
      return i;
    }
  }
  return 1;
}
void solve(vector<vector<int>> &t, int n){
  vector <int> leaves;
  for(int i = 1; i < t.size(); i++){
    if(t[i].empty()) leaves.push_back(i);
  }
  printf("%d\n", int(leaves.size()));
  for(auto e: leaves){
    printf("%d %d\n", n, leaves[i]);
  }
}

int main(){
  cin >> n;
  t.resize(n + 1);
  for(int i = 0; i < n - 1; i++){
    int x, y; cin >> x >> y;
    t[x].push_back(y);
  }
  if(!check(t)){
    puts("No");
    return 0;
  }
  puts("Yes");
  solve(t, findroot(t));
  return 0;
}


#include <iostream>
#include <vector>
#include <unordered_map>
#include <cstdio>
#include <set>
using namespace std;
unordered_map <int, bool> visited;
set <pair<int, int>> path;
vector<vector<int>> t;
int n;
bool check(vector<vector<int>> &t){
  int cnt = 0;
  for(auto p: t){
    if(p.size() > 2) cnt++;
  }
  return cnt <= 1? true: false;
}
int findroot(vector<vector<int>> &t){
  int root = -1;
  for(int i = 1; i <= n; i++){
    if(t[i].size() > t[root].size()){
      root = i;
    }
  }
  return root;
}
void solve(vector<vector<int>> &t, int n){
  vector <int> leaves;
  for(int i = 1; i < t.size(); i++){
    if(t[i].size() == 1) leaves.push_back(i);
  }
  printf("%d\n", int(leaves.size()));
  for(auto e: leaves){
    printf("%d %d\n", n, e);
  }
}

int main(){
  cin >> n;
  t.resize(n + 1);
  for(int i = 0; i < n - 1; i++){
    int x, y; cin >> x >> y;
    t[x].push_back(y);
    t[y].push_back(x);
  }
  if(!check(t)){
    puts("No");
    return 0;
  }
  puts("Yes");
  solve(t, findroot(t));
  return 0;
}


#include <iostream>
#include <vector>
#include <unordered_map>
#include <cstdio>
#include <set>
using namespace std;
unordered_map <int, bool> visited;
set <pair<int, int>> path;
vector<vector<int>> t;
int n;
bool check(vector<vector<int>> &t){
  int cnt = 0;
  for(auto p: t){
    if(p.size() > 1) cnt++;
  }
  return cnt <= 1? true: false;
}
int findroot(vector<vector<int>> &t){
  for(int i = 1; i <= n; i++){
    if(t[i].size() > 1){
      return i;
    }
  }
  return 1;
}
void solve(vector<vector<int>> &t, int n){
  vector <int> leaves;
  for(int i = 1; i < t.size(); i++){
    if(t[i].empty()) leaves.push_back(i);
  }
  printf("%d\n", int(leaves.size()));
  for(auto e: leaves){
    printf("%d %d\n", n, e);
  }
}

int main(){
  cin >> n;
  t.resize(n + 1);
  for(int i = 0; i < n - 1; i++){
    int x, y; cin >> x >> y;
    t[x].push_back(y);
  }
  if(!check(t)){
    puts("No");
    return 0;
  }
  puts("Yes");
  solve(t, findroot(t));
  return 0;
}


#include <iostream>
#include <vector>
#include <unordered_map>
#include <cstdio>
#include <set>
using namespace std;
unordered_map <int, bool> visited;
set <pair<int, int>> path;
vector<vector<int>> t;
int n;
bool found = false;
bool check(vector<vector<int>> &t){
  int cnt = 0;
  for(auto p: t){
    if(p.size() > 2) cnt++;
  }
  return cnt <= 1? true: false;
}
int findroot(vector<vector<int>> &t){
  int root = 1;
  for(int i = 1; i <= n; i++){
    if(t[i].size() > t[root].size()){
      root = i;
      found = true;
    }
  }
  return root;
}
void solve(vector<vector<int>> &t, int n){
  vector <int> leaves;
  for(int i = 1; i < t.size(); i++){
    if(t[i].size() == 1) leaves.push_back(i);
  }
  printf("%d\n", int(leaves.size()));
  for(auto e: leaves){
    printf("%d %d\n", n, e);
  }
}

int main(){
  cin >> n;
  t.resize(n + 1);
  for(int i = 0; i < n - 1; i++){
    int x, y; cin >> x >> y;
    if(n == 2){
      cout << 1 << endl << x << ' ' << y;
      return 0;
    }
    t[x].push_back(y);
    t[y].push_back(x);
  }
  if(!check(t)){
    puts("No");
    return 0;
  }
  puts("Yes");
  solve(t, findroot(t));
  return 0;
}


#include <iostream>
#include <vector>
#include <unordered_map>
#include <cstdio>
#include <set>
using namespace std;
unordered_map <int, bool> visited;
set <pair<int, int>> path;
vector<vector<int>> t;
int n;
bool check(vector<vector<int>> &t){
  int cnt = 0;
  for(auto p: t){
    if(p.size() > 2) cnt++;
  }
  return cnt <= 1? true: false;
}
int findroot(vector<vector<int>> &t){
  int root = 1;
  for(int i = 1; i <= n; i++){
    if(t[i].size() > t[root].size()){
      root = i;
    }
  }
  return root;
}
void solve(vector<vector<int>> &t, int n){
  vector <int> leaves;
  for(int i = 1; i < t.size(); i++){
    if(t[i].size() == 1) leaves.push_back(i);
  }
  printf("%d\n", int(leaves.size()));
  for(auto e: leaves){
    printf("%d %d\n", n, e);
  }
}

int main(){
  cin >> n;
  t.resize(n + 1);
  for(int i = 0; i < n - 1; i++){
    int x, y; cin >> x >> y;
    t[x].push_back(y);
    t[y].push_back(x);
  }
  if(!check(t)){
    puts("No");
    return 0;
  }
  puts("Yes");
  solve(t, findroot(t));
  return 0;
}


#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;
bool check(vector<vector<int>> &t){
  int cnt = 0;
  for(auto p: t){
    if(p.size() > 1) cnt++;
  }
  return cnt <= 1? true: false;
}
int main(){
  int n; cin >> n;
  vector <vector<int>> t(n + 1);
  for(int i = 0; i < n - 1; i++){
    int x, y; cin >> x >> y;
    t[x].push_back(y);
  }
  if(!check(t)){
    puts("No");
    return 0;
  }
  puts("Yes");
  printf("%d\n", n - 1);
  for(int i = 1; i <= n; i++){
    if(t[i].size()){
      for(int j = 0; j < t[i].size(); j++){
        printf("%d %d\n", i, t[i][j]);
      }
    }
  }
  return 0;
}


#include <iostream>
#include <vector>
#include <unordered_map>
#include <cstdio>
#include <set>
using namespace std;
unordered_map <int, bool> visited;
set <pair<int, int>> path;
vector<vector<int>> t;
bool check(vector<vector<int>> &t){
  int cnt = 0;
  for(auto p: t){
    if(p.size() > 1) cnt++;
  }
  return cnt <= 1? true: false;
}
void solve(vector<vector<int>> &t, int n){
  vector <int> leaves;
  for(int i = 1; i < t.size(); i++){
    if(t[i].size() == 0) leaves.push_back(i);
  }
  printf("%d\n", int(leaves.size()));
  for(int i = 0; i < leaves.size(); i++){
    printf("%d %d\n", n, leaves[i]);
  }
}

int main(){
  int n; cin >> n;
  t.resize(n + 1);
  for(int i = 0; i < n - 1; i++){
    int x, y; cin >> x >> y;
    t[x].push_back(y);
  }
  if(!check(t)){
    puts("No");
    return 0;
  }
  puts("Yes");
  solve(t, 1);
  return 0;
}


#include <bits/stdc++.h>

typedef std::vector<int> vi;
typedef std::vector<vi> vvi;

int n;
vvi adjlist;
bool visited[100005];
int subtrees[100005];

int center = -1;

int subtreesSize(int x) {
    visited[x] = 1;
    subtrees[x] = 1;
    for (int i = 0;i<adjlist[x].size();i++) {
        int y = adjlist[x][i];
        if (!visited[y]) {
            subtrees[x] += subtreesSize(y);
        }
    }

    return subtrees[x];
}

void dfs(int x) {
    visited[x] = 1;
    if (subtrees[x] > n / 2) center = x;
    for (int i = 0;i<adjlist[x].size();i++) {
        int y = adjlist[x][i];
        if (!visited[y] and (int) subtrees[y] > n / 2) {
            dfs(y);
        }
    }
}

// int deepestV = -1;
// void deepestNode (int x) {

// }

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

    std::cin >> n;
    adjlist.assign(n+1, vi());
    for (int i = 1;i<n;i++) {
        int a,b; std::cin >> a >> b;
        adjlist[a].push_back(b);
        adjlist[b].push_back(a);
    }

    memset(visited, 0, sizeof visited);
    int size = subtreesSize(1);

    memset(visited, 0, sizeof visited);
    dfs(1);

    std::vector<std::pair<int,int>> paths;
    if ((int) adjlist[center].size() <= 2) {
        // update the center
        for (int i = 1;i<=n;i++) {
            if (adjlist[i].size() > 2) {
                center = i;
                break;
            }
        }
    }
    for (int i = 1;i<=n;i++) {
        if (i == center) continue;
        if (adjlist[i].size() > 2) {
            std::cout << "No" << "\n";
            return 0;
        } else if (adjlist[i].size() == 1) {
            paths.push_back({center, i});
        }
    }

    std::cout << "Yes" << "\n";
    std::cout << (int) paths.size() << "\n";
    for (int i = 0;i<(int) paths.size();i++) {
        std::cout << paths[i].first << " " << paths[i].second << "\n";
    }

    return 0;

}


#include <bits/stdc++.h>

typedef std::vector<int> vi;
typedef std::vector<vi> vvi;

int n;
vvi adjlist;
bool visited[100005];
int subtrees[100005];

int center = -1;

int subtreesSize(int x) {
    visited[x] = 1;
    subtrees[x] = 1;
    for (int i = 0;i<adjlist[x].size();i++) {
        int y = adjlist[x][i];
        if (!visited[y]) {
            subtrees[x] += subtreesSize(y);
        }
    }

    return subtrees[x];
}

void dfs(int x) {
    visited[x] = 1;
    if (subtrees[x] > n / 2) center = x;
    for (int i = 0;i<adjlist[x].size();i++) {
        int y = adjlist[x][i];
        if (!visited[y] and (int) subtrees[y] > n / 2) {
            dfs(y);
        }
    }
}

// int deepestV = -1;
// void deepestNode (int x) {

// }

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

    std::cin >> n;
    adjlist.assign(n+1, vi());
    for (int i = 1;i<n;i++) {
        int a,b; std::cin >> a >> b;
        adjlist[a].push_back(b);
        adjlist[b].push_back(a);
    }

    memset(visited, 0, sizeof visited);
    int size = subtreesSize(1);

    memset(visited, 0, sizeof visited);
    dfs(1);

    std::vector<std::pair<int,int>> paths;
    for (int i = 1;i<=n;i++) {
        if (i == center) continue;
        if (adjlist[i].size() == 1) {
            paths.push_back({center, i});
        } else {
            if (adjlist[i].size() == 2) {
                if (adjlist[i][0] == center or adjlist[i][1] == center) {

                } else {
                    std::cout << "No" << "\n";
                }
            } else {
                std::cout << "No" << "\n";
                return 0;
            }

        }
    }

    std::cout << "Yes" << "\n";
    std::cout << (int) paths.size() << "\n";
    for (int i = 0;i<(int) paths.size();i++) {
        std::cout << paths[i].first << " " << paths[i].second << "\n";
    }

    return 0;

}


#include <bits/stdc++.h>

typedef std::vector<int> vi;
typedef std::vector<vi> vvi;

int n;
vvi adjlist;
bool visited[100005];
int subtrees[100005];

int center = -1;

int subtreesSize(int x) {
    visited[x] = 1;
    subtrees[x] = 1;
    for (int i = 0;i<adjlist[x].size();i++) {
        int y = adjlist[x][i];
        if (!visited[y]) {
            subtrees[x] += subtreesSize(y);
        }
    }

    return subtrees[x];
}

void dfs(int x) {
    visited[x] = 1;
    if (subtrees[x] > n / 2) center = x;
    for (int i = 0;i<adjlist[x].size();i++) {
        int y = adjlist[x][i];
        if (!visited[y] and (int) subtrees[y] > n / 2) {
            dfs(y);
        }
    }
}

// int deepestV = -1;
// void deepestNode (int x) {

// }

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

    std::cin >> n;
    adjlist.assign(n+1, vi());
    for (int i = 1;i<n;i++) {
        int a,b; std::cin >> a >> b;
        adjlist[a].push_back(b);
        adjlist[b].push_back(a);
    }

    memset(visited, 0, sizeof visited);
    int size = subtreesSize(1);

    memset(visited, 0, sizeof visited);
    dfs(1);

    std::vector<std::pair<int,int>> paths;
    for (int i = 1;i<=n;i++) {
        if (i == center) continue;
        if ((int) adjlist[i].size() > 2) {
            std::cout << "No" << "\n";
            return 0;
        } else if ((int) adjlist[i].size() == 1) {
            paths.push_back({center, i});
        }
    }

    std::cout << "Yes" << "\n";
    std::cout << (int) paths.size() << "\n";
    for (int i = 0;i<(int) paths.size();i++) {
        std::cout << paths[i].first << " " << paths[i].second << "\n";
    }

    return 0;

}


#include <bits/stdc++.h>

typedef std::vector<int> vi;
typedef std::vector<vi> vvi;

int n;
vvi adjlist;
bool visited[100005];
int subtrees[100005];

int center = -1;

int subtreesSize(int x) {
    visited[x] = 1;
    subtrees[x] = 1;
    for (int i = 0;i<adjlist[x].size();i++) {
        int y = adjlist[x][i];
        if (!visited[y]) {
            subtrees[x] += subtreesSize(y);
        }
    }

    return subtrees[x];
}

void dfs(int x) {
    visited[x] = 1;
    if (subtrees[x] > n / 2) center = x;
    for (int i = 0;i<adjlist[x].size();i++) {
        int y = adjlist[x][i];
        if (!visited[y] and (int) subtrees[y] > n / 2) {
            dfs(y);
        }
    }
}

// int deepestV = -1;
// void deepestNode (int x) {

// }

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

    std::cin >> n;
    adjlist.assign(n+1, vi());
    for (int i = 1;i<n;i++) {
        int a,b; std::cin >> a >> b;
        adjlist[a].push_back(b);
        adjlist[b].push_back(a);
    }

    memset(visited, 0, sizeof visited);
    int size = subtreesSize(1);

    memset(visited, 0, sizeof visited);
    dfs(1);

    std::vector<std::pair<int,int>> paths;
    for (int i = 1;i<=n;i++) {
        if (i == center) continue;
        if (adjlist[i].size() == 1) {
            paths.push_back({center, i});
        } else {
            if (adjlist[i].size() == 2) {
                if (adjlist[i][0] == center or adjlist[i][1] == center) {

                } else {
                    std::cout << "No" << "\n";
                }
            } else {
                std::cout << "No" << "\n";
                return 0;
            }

        }
    }

    std::cout << "Yes" << "\n";
    for (int i = 0;i<(int) paths.size();i++) {
        std::cout << paths[i].first << " " << paths[i].second << "\n";
    }

    return 0;

}


#include <bits/stdc++.h>
using namespace std;
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ALL(x) x.begin(),x.end()
#define SZ(x) x.size()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PI;

const int N=1e5+1;
vector<VI> g;
int n,h,d[N],f,x;
VI ans;
bool vis[N];

void dfs(int u,int v) {
   if(!f) return;
   if(v && SZ(g[u]) > 2) {
      f = 0;
      return;
   }
   vis[u] = true;
   for(int i = 0; i < SZ(g[u]); i++) {
      if(!vis[g[u][i]])
         dfs(g[u][i],1);
   }
}

void solve(int u) {
   vis[u] = 1;
   if(SZ(g[u]) == 1 && u != x)
      ans.PB(u);
   for(int i = 0; i < SZ(g[u]); i++) {
      if(!vis[g[u][i]])
         solve(g[u][i]);
   }
}

int main() {
   io
   cin >> n;
   g.clear();
   g.resize(n+1);
   h = 1;
   for(int i = 0; i < n-1; i++) {
      int u,v;
      cin >> u >> v;
      g[u].PB(v); d[u]++;
      g[v].PB(u); d[v]++;
      if(d[u] > d[h])
         h = u;
      if(d[v] > d[h])
         h = v;
   }
   f = 1;
   x = -1;
   dfs(h,0);
   if(f) x = h;
   if(x == -1)
      return 0*puts("No");
   memset(vis,0,sizeof(vis));
   solve(x);
   puts("Yes");
   cout << SZ(ans) << "\n";
   for(int i = 0; i < SZ(ans); i++)
      cout << x << " " << ans[i] << "\n";
}


#include <bits/stdc++.h>
using namespace std;
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ALL(x) x.begin(),x.end()
#define SZ(x) x.size()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PI;

const int N=1e5+1;
vector<VI> g;
int n,h,d[N],f,x;
VI ans;
bool vis[N];

void dfs(int u,int v) {
   if(!f) return;
   if(v && SZ(g[u]) > 2) {
      f = 0;
      return;
   }
   vis[u] = true;
   for(int i = 0; i < SZ(g[u]); i++) {
      if(!vis[g[u][i]])
         dfs(g[u][i],1);
   }
}

void solve(int u) {
   vis[u] = 1;
   if(SZ(g[u]) == 1 && u != x)
      ans.PB(u);
   for(int i = 0; i < SZ(g[u]); i++) {
      if(!vis[g[u][i]])
         solve(g[u][i]);
   }
}

int main() {
   io
   cin >> n;
   g.clear();
   g.resize(n+1);
   h = 1;
   for(int i = 0; i < n-1; i++) {
      int u,v;
      cin >> u >> v;
      g[u].PB(v); d[u]++;
      g[v].PB(u); d[v]++;
      if(d[u] > d[h])
         h = u;
      if(d[v] > d[h])
         h = v;
   }
   f = 1;
   x = -1;
   dfs(h,0);
   if(f) x = h;
   if(x == -1)
      return 0*puts("No");
   memset(vis,0,sizeof(vis));
   solve(x);
   cout << "Yes\n";
   cout << SZ(ans) << "\n";
   for(int i = 0; i < SZ(ans); i++)
      cout << x << " " << ans[i] << "\n";
}


#include <bits/stdc++.h>
using namespace std;
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ALL(x) x.begin(),x.end()
#define SZ(x) x.size()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PI;

const int N=1e5+1;
int n;
vector<VI> g;
bool vis[N];
VI ans;

void dfs(int u,int v) {
   vis[u] = true;
   if(SZ(g[u]) == 1 && u != v)
      ans.PB(u);
   for(int x : g[u]) {
      if(!vis[x])
         dfs(x,v);
   }
}

int main() {
   io;
   cin >> n;
   g.clear();
   g.resize(n+1);
   int x = 0;
   for(int i = 0; i < n-1; i++) {
      int u,v;
      cin >> u >> v;
      g[u].PB(v);
      g[v].PB(u);
   }
   int cnt = 0;
   for(int i = 1; i <= n; i++) {
      if(SZ(g[i]) > 2) cnt++;
      if(SZ(g[i]) > SZ(g[x])) x = i;
   }
   if(cnt > 1)
      return 0*puts("No");
   dfs(x,x);
   cout << "Yes\n" << SZ(ans) << "\n";
   for(int u : ans)
      cout << x << " " << u << "\n";
}


#include <bits/stdc++.h>
using namespace std;
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ALL(x) x.begin(),x.end()
#define SZ(x) x.size()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PI;

int n;
vector<VI> g;

int main() {
   io;
   cin >> n;
   g.clear();
   g.resize(n+1);
   int x = 0;
   for(int i = 0; i < n-1; i++) {
      int u,v;
      cin >> u >> v;
      g[u].PB(v);
      g[v].PB(u);
   }
   int cnt = 0;
   for(int i = 1; i <= n; i++) {
      if(SZ(g[i]) > 2) cnt++;
      if(SZ(g[i]) > SZ(g[x])) x = i;
   }
   if(cnt > 1)
      return 0*puts("No");
   cout << "Yes\n" << SZ(g[x]) << "\n";
   for(int u : g[x])
      cout << x << " " << u << "\n";
}


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

using ll = int64_t;
constexpr ll mod = ll(1e9 + 7);

int DFS(int from, int parent, vector<vector<int>>& adj) {
  if (adj[from].size() == 1) return from;
  if (adj[from][0] == parent) {
    return DFS(adj[from][1], from, adj);
  } else {
    return DFS(adj[from][0], from, adj);
  }
}
int main () {
  ios::sync_with_stdio(0); cin.tie(0);

  int TT = 1;
  // cin >> TT;
  while (TT--) {
    ll n;
    cin >> n;
    vector<vector<int>> adj(n);
    vector<int> in_degree(n);
    for (int i = 0; i < n-1; ++i) {
      int u,v;
      cin >> u >> v;
      --u, --v;
      adj[u].emplace_back(v);
      adj[v].emplace_back(u);
      ++in_degree[v];
      ++in_degree[u];
    }
    auto it = max_element(in_degree.begin(), in_degree.end());
    if (*it <= 1) {
      cout << "NO" << endl;
      return 0;
    }
    if (*it > 2) {
      int cnt = 0;
      for (int i = 0; i < n; ++i) cnt += in_degree[i] > 2;
      if (cnt > 1) {
        cout << "NO" << endl;
        return 0;
      }
      cout << "YES" << endl;
      int root = it - in_degree.begin();
      cout << *it << endl;
      for (auto to : adj[root]) {
        int out = DFS(to, root, adj);
        cout << (root+1) << " " << (out+1) << endl;
      }
    } else {
      cout << "YES" << endl;
      int root = 0;
      for (int i = 0; i < n; ++i) if (adj[i].size()==1) root = i;
      cout << 1 << endl;
      int out = DFS(adj[root][0], root, adj);
      if (out < root) swap(out,root);
      cout << (root+1) << " " << (out+1) << endl;

    }

  }
}


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

using ll = int64_t;
constexpr ll mod = ll(1e9 + 7);

int DFS(int from, int parent, vector<vector<int>>& adj) {
  if (adj[from].size() == 1) return from;
  if (adj[from][0] == parent) {
    return DFS(adj[from][1], from, adj);
  } else {
    return DFS(adj[from][0], from, adj);
  }
}
int main () {
  ios::sync_with_stdio(0); cin.tie(0);

  int TT = 1;
  // cin >> TT;
  while (TT--) {
    ll n;
    cin >> n;
    vector<vector<int>> adj(n);
    vector<int> in_degree(n);
    for (int i = 0; i < n-1; ++i) {
      int u,v;
      cin >> u >> v;
      --u, --v;
      adj[u].emplace_back(v);
      adj[v].emplace_back(u);
      ++in_degree[v];
      ++in_degree[u];
    }
    auto it = max_element(in_degree.begin(), in_degree.end());
    if (*it <= 1) {
      cout << "NO" << endl;
      return 0;
    }
    if (*it > 2) {
      int cnt = 0;
      for (int i = 0; i < n; ++i) cnt += in_degree[i] > 2;
      if (cnt > 1) {
        cout << "NO" << endl;
        return 0;
      }
      int root = it - in_degree.begin();
      cout << *it << endl;
      for (auto to : adj[root]) {
        int out = DFS(to, root, adj);
        cout << (root+1) << " " << (out+1) << endl;
      }
    } else {
      int root = 0;
      for (int i = 0; i < n; ++i) if (adj[i].size()==1) root = i;
      cout << 1 << endl;
      for (auto to : adj[root]) {
        int out = DFS(to, root, adj);
        cout << (root+1) << " " << (out+1) << endl;
      }

    }

  }
}


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

using ll = int64_t;
constexpr ll mod = ll(1e9 + 7);

int DFS(int from, int parent, vector<vector<int>>& adj) {
  if (adj[from].size() == 1) return from;
  if (adj[from][0] == parent) {
    return DFS(adj[from][1], from, adj);
  } else {
    return DFS(adj[from][0], from, adj);
  }
}
int main () {
  ios::sync_with_stdio(0); cin.tie(0);

  int TT = 1;
  // cin >> TT;
  while (TT--) {
    ll n;
    cin >> n;
    vector<vector<int>> adj(n);
    vector<int> in_degree(n);
    for (int i = 0; i < n-1; ++i) {
      int u,v;
      cin >> u >> v;
      --u, --v;
      adj[u].emplace_back(v);
      adj[v].emplace_back(u);
      ++in_degree[v];
      ++in_degree[u];
    }
    auto it = max_element(in_degree.begin(), in_degree.end());
    if (*it <= 1) {
      cout << "NO" << endl;
      return 0;
    }
    if (*it > 2) {
      int cnt = 0;
      for (int i = 0; i < n; ++i) cnt += in_degree[i] > 2;
      if (cnt > 1) {
        cout << "NO" << endl;
        return 0;
      }
    }
    int root = it - in_degree.begin();
    cout << *it << endl;
    for (auto to : adj[root]) {
      int out = DFS(to, root, adj);
      cout << (root+1) << " " << (out+1) << endl;
    }

  }
}


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

using ll = int64_t;
constexpr ll mod = ll(1e9 + 7);

int DFS(int from, int parent, vector<vector<int>>& adj) {
  if (adj[from].size() == 1) return from;
  if (adj[from][0] == parent) {
    return DFS(adj[from][1], from, adj);
  } else {
    return DFS(adj[from][0], from, adj);
  }
}
int main () {
  ios::sync_with_stdio(0); cin.tie(0);

  int TT = 1;
  // cin >> TT;
  while (TT--) {
    ll n;
    cin >> n;
    vector<vector<int>> adj(n);
    vector<int> in_degree(n);
    for (int i = 0; i < n-1; ++i) {
      int u,v;
      cin >> u >> v;
      --u, --v;
      adj[u].emplace_back(v);
      adj[v].emplace_back(u);
      ++in_degree[v];
      ++in_degree[u];
    }
    auto it = max_element(in_degree.begin(), in_degree.end());
    if (*it <= 1) {
      cout << "NO" << endl;
      return 0;
    }
    if (*it > 2) {
      int cnt = 0;
      for (int i = 0; i < n; ++i) cnt += in_degree[i] > 2;
      if (cnt > 1) {
        cout << "NO" << endl;
        return 0;
      }
      cout << "YES" << endl;
      int root = it - in_degree.begin();
      cout << *it << endl;
      for (auto to : adj[root]) {
        int out = DFS(to, root, adj);
        cout << (root+1) << " " << (out+1) << endl;
      }
    } else {
      cout << "YES" << endl;
      int root = 0;
      for (int i = 0; i < n; ++i) if (adj[i].size()==1) root = i;
      cout << 1 << endl;
      for (auto to : adj[root]) {
        int out = DFS(to, root, adj);
        cout << (root+1) << " " << (out+1) << endl;
      }

    }

  }
}


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

using ll = int64_t;
constexpr ll mod = ll(1e9 + 7);

int DFS(int from, int parent, vector<vector<int>>& adj) {
  if (adj[from].size() == 1) return from;
  if (adj[from][0] == parent) {
    return DFS(adj[from][1], from, adj);
  } else {
    return DFS(adj[from][0], from, adj);
  }
}
int main () {
  ios::sync_with_stdio(0); cin.tie(0);

  int TT = 1;
  // cin >> TT;
  while (TT--) {
    ll n;
    cin >> n;
    vector<vector<int>> adj(n);
    vector<int> in_degree(n);
    for (int i = 0; i < n-1; ++i) {
      int u,v;
      cin >> u >> v;
      --u, --v;
      adj[u].emplace_back(v);
      adj[v].emplace_back(u);
      ++in_degree[v];
      ++in_degree[u];
    }
    auto it = max_element(in_degree.begin(), in_degree.end());
    if (*it <= 1) {
      cout << "No" << endl;
      return 0;
    }
    if (*it > 2) {
      int cnt = 0;
      for (int i = 0; i < n; ++i) cnt += in_degree[i] > 2;
      if (cnt > 1) {
        cout << "No" << endl;
        return 0;
      }
      cout << "Yes" << endl;
      int root = it - in_degree.begin();
      cout << *it << endl;
      for (auto to : adj[root]) {
        int out = DFS(to, root, adj);
        cout << (root+1) << " " << (out+1) << endl;
      }
    } else {
      cout << "Yes" << endl;
      int root = 0;
      for (int i = 0; i < n; ++i) if (adj[i].size()==1) root = i;
      cout << 1 << endl;
      int out = DFS(adj[root][0], root, adj);
      if (out < root) swap(out,root);
      cout << (root+1) << " " << (out+1) << endl;

    }

  }
}


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

using ll = int64_t;
constexpr ll mod = ll(1e9 + 7);

int DFS(int from, int parent, vector<vector<int>>& adj) {
  if (adj[from].size() == 1) return from;
  if (adj[from][0] == parent) {
    return DFS(adj[from][1], from, adj);
  } else {
    return DFS(adj[from][0], from, adj);
  }
}
int main () {
  ios::sync_with_stdio(0); cin.tie(0);

  int TT = 1;
  // cin >> TT;
  while (TT--) {
    ll n;
    cin >> n;
    vector<vector<int>> adj(n);
    vector<int> in_degree(n);
    for (int i = 0; i < n-1; ++i) {
      int u,v;
      cin >> u >> v;
      --u, --v;
      adj[u].emplace_back(v);
      adj[v].emplace_back(u);
      ++in_degree[v];
      ++in_degree[u];
    }
    if (n==2) {
      cout << "Yes" << endl;
      cout << 1 << endl;
      cout << "1 2" << endl;
      return 0;
    }
    auto it = max_element(in_degree.begin(), in_degree.end());
    if (*it <= 1) {
      cout << "No" << endl;
      return 0;
    }
    if (*it > 2) {
      int cnt = 0;
      for (int i = 0; i < n; ++i) cnt += in_degree[i] > 2;
      if (cnt > 1) {
        cout << "No" << endl;
        return 0;
      }
    }
    cout << "Yes" << endl;
    int root = it - in_degree.begin();
    cout << *it << endl;
    for (auto to : adj[root]) {
      int out = DFS(to, root, adj);
      cout << (root+1) << " " << (out+1) << endl;
    }

  }
}


/**
 *    author:  tourist
 *    created: 27.05.2018 17:55:04
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> deg(n);
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    deg[x]++;
    deg[y]++;
  }
  vector<vector<int>> by_deg(n + 1);
  int mx = 0;
  for (int i = 0; i < n; i++) {
    by_deg[deg[i]].push_back(i);
    mx = max(mx, deg[i]);
  }
  if (mx <= 2) {
    cout << "Yes" << '\n';
    cout << 1 << '\n';
    cout << by_deg[1][0] + 1 << " " << by_deg[1][1] + 1 << '\n';
    return 0;
  }
  int cc = 0;
  int who = -1;
  for (int i = 0; i < n; i++) {
    if (deg[i] > 2) {
      cc++;
      who = i;
    }
  }
  if (cc > 1) {
    cout << "No" << '\n';
    return 0;
  }
  cout << "Yes" << '\n';
  cout << by_deg[1].size() << '\n';
  for (int i : by_deg[1]) {
    cout << who + 1 << " " << i + 1 << '\n';
  }
  return 0;
}


#include <bits/stdc++.h>

#define FIRST_NODE 1

using namespace std;

typedef pair<int, int> pairIntInt;

bool *visited;

int main(){
    int n;
    scanf("%d", &n);

    vector<int> adj;//=(vector<int> *) malloc((n+1)*sizeof(vector<int>));
    int a,b;
    bool only1path=true;
    for(int i=0; i<n-1; i++)
    {
        scanf("%d %d", &a,&b);
        adj[a].push_back(b);
        if(adj[a].size()>1) only1path=false;
    }

    if(only1path){
        cout << "Yes" << endl << "1" << endl << "1 " << n << endl;
        //free(adj);
        return 0;
    }

    visited=(bool *) malloc((n+1)*sizeof(bool));
    vector<int> dfsQ;
    vector<pairIntInt> paths;

    int index=FIRST_NODE;
    while(1)
    {
        visited[index]=true;

        //process node
        if(index!=1 && adj[index].size()>1)
        {
            cout << "No" << endl;
            goto freeWhatYouNeed;
        }
        if(adj[index].size()==0)
        {
            paths.push_back({1,index});
        }

        for(auto u: adj[index])
        {
            if(!visited[u]) dfsQ.push_back(u);
        }
        if(dfsQ.empty()) break;
        index=dfsQ.back();
        dfsQ.pop_back();
    }

    cout << paths.size() << endl;
    for(int i=paths.size()-1; i>=0; i--)
    {
        cout << paths[i].first << " " << paths[i].second << endl;
    }

freeWhatYouNeed:
    free(visited);

finish:
    //free(adj);
    return 0;
}


#include <bits/stdc++.h>

#define FIRST_NODE 1

using namespace std;

typedef pair<int, int> pairIntInt;

bool *visited;

int main(){
    int n;
    scanf("%d", &n);

    vector<int> *adj=(vector<int> *) malloc((n+1)*sizeof(vector<int>));
    int a,b;
    bool only1path=true;
    for(int i=0; i<n-1; i++)
    {
        scanf("%d %d", &a,&b);
        adj[a].push_back(b);
        if(adj[a].size()>1) only1path=false;
    }

    if(only1path){
        printf("Yes\n1\n1 %d\n", n);
        free(adj);
        return 0;
    }

    visited=(bool *) malloc((n+1)*sizeof(bool));
    for(int i=0;i<n+1; i++) { visited[i]=false; }
    vector<int> dfsQ;
    vector<pairIntInt> paths;

    int index=FIRST_NODE;
    while(1)
    {
        visited[index]=true;

        //process node
        if(index!=1 && adj[index].size()>1)
        {
            cout << "No" << endl;
            goto freeWhatYouNeed;
        }
        if(adj[index].size()==0)
        {
            paths.push_back({1,index});
        }

        for(auto u: adj[index])
        {
            if(!visited[u]) dfsQ.push_back(u);
        }
        if(dfsQ.empty()) break;
        index=dfsQ.back();
        dfsQ.pop_back();
    }

    cout << "Yes" << endl;
    cout << paths.size() << endl;
    for(int i=paths.size()-1; i>=0; i--)
    {
        cout << paths[i].first << " " << paths[i].second << endl;
    }

freeWhatYouNeed:
    free(visited);

finish:
    free(adj);
    return 0;
}


#include <bits/stdc++.h>

#define FIRST_NODE 1

using namespace std;

typedef pair<int, int> pairIntInt;

bool *visited;

int main(){
    int n;
    cin >> n;
    //scanf("%d", &n);

    vector<int> *adj=(vector<int> *) malloc((n+1)*sizeof(vector<int>));
    int a,b;
    bool only1path=true;
    for(int i=0; i<n-1; i++)
    {
        cin >> a >> b;
        // scanf("%d %d", &a,&b);
        adj[a].push_back(b);
        if(adj[a].size()>1) only1path=false;
    }

    if(only1path){
        printf("Yes\n1\n1 %d\n", n);
        free(adj);
        return 0;
    }

    visited=(bool *) malloc((n+1)*sizeof(bool));
    vector<int> dfsQ;
    vector<pairIntInt> paths;

    int index=FIRST_NODE;
    while(1)
    {
        visited[index]=true;

        //process node
        if(index!=1 && adj[index].size()>1)
        {
            cout << "No" << endl;
            goto freeWhatYouNeed;
        }
        if(adj[index].size()==0)
        {
            paths.push_back({1,index});
        }

        for(auto u: adj[index])
        {
            if(!visited[u]) dfsQ.push_back(u);
        }
        if(dfsQ.empty()) break;
        index=dfsQ.back();
        dfsQ.pop_back();
    }

    cout << "Yes" << endl;
    cout << paths.size() << endl;
    for(int i=paths.size()-1; i>=0; i--)
    {
        cout << paths[i].first << " " << paths[i].second << endl;
    }

freeWhatYouNeed:
    free(visited);

finish:
    free(adj);
    return 0;
}


#include <bits/stdc++.h>

#define FIRST_NODE 1

using namespace std;

typedef pair<int, int> pairIntInt;

bool *visited;

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

    int n;
    scanf("%d", &n);

    vector<int> *adj=(vector<int> *) malloc((n+1)*sizeof(vector<int>));
    int a,b;
    bool only1path=true;
    for(int i=0; i<n-1; i++)
    {
        scanf("%d %d", &a,&b);
        adj[a].push_back(b);
        if(adj[a].size()>1) only1path=false;
    }

    if(only1path){
        printf("Yes\n1\n1 %d\n", n);
        free(adj);
        return 0;
    }

    visited=(bool *) malloc((n+1)*sizeof(bool));
    for(int i=0;i<n+1; i++) { visited[i]=false; }
    vector<int> dfsQ;
    vector<pairIntInt> paths;

    int index=FIRST_NODE;
    while(1)
    {
        visited[index]=true;

        //process node
        if(index!=1 && adj[index].size()>1)
        {
            cout << "No" << endl;
            goto freeWhatYouNeed;
        }
        if(adj[index].size()==0)
        {
            paths.push_back({1,index});
        }

        for(auto u: adj[index])
        {
            if(!visited[u]) dfsQ.push_back(u);
        }
        if(dfsQ.empty()) break;
        index=dfsQ.back();
        dfsQ.pop_back();
    }

    cout << "Yes" << "\n";
    cout << paths.size() << "\n";
    for(int i=paths.size()-1; i>=0; i--)
    {
        cout << paths[i].first << " " << paths[i].second << "\n";
    }

freeWhatYouNeed:
    free(visited);

finish:
    free(adj);
    return 0;
}


#include <bits/stdc++.h>

#define FIRST_NODE 1

using namespace std;

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

    int n;
    scanf("%d", &n);

    int a, b;
    vector<int> *adj= (vector<int> *) malloc((n+1)*sizeof(vector<int>));
    for(int i=0;i<n-1;i++)
    {
        scanf("%d %d", &a, &b);
        adj[a].push_back(b);
    }

    vector<int> lastN;
    for(int i=1;i<=n;i++)
    {
        if(adj[i].size()>1 && i!=1)
        {
            printf("No\n");
            free(adj);
            return 0;
        }
        else if(adj[i].size()==0) lastN.push_back(i);
    }

    printf("Yes\n");
    printf("%d\n", lastN.size());
    for(auto u: lastN)
    {
        printf("1 %d\n", u);
    }
    free(adj);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pairIntInt;

#define RESPECT 0

vector<pairIntInt> *adj;

bool checkIfAllChildrenNotRespectHim(int parent)
{
    for(auto u: adj[parent])
    {
        if(u.second==RESPECT) return false;
    }
    return true;
}

int main()
{
    int n;
    scanf("%d", &n);

    adj=(vector<pairIntInt> *) malloc((n+1)*sizeof(vector<pairIntInt>));
    int p,c;
    int root=0;
    for(int i=1; i<n+1; i++)
    {
        scanf("%d %d", &p,&c);
        if(p==-1) root=i;
        else adj[p].push_back({i,c});
    }

    bool *visited=(bool *) malloc((n+1)*sizeof(bool));
    for(int i=0;i<n+1; i++) { visited[i]=false; }
    vector<int> dfsQ;
    vector<int> deleted;
    vector<pairIntInt> tmpAdj;

    // DOESN'T DELETE FROM adj, NEEDS TO ITER UNLESS EVERY CHILD OF PARENT RESPECTS HIM
    int index=root;
    int child=-1;
    bool childsRespect = false;
    while(1)
    {
        visited[index]=true;

        // Process Node
        // check all nodes: if one is disresp by child, check if children of child all disresp child
        childsRespect=false;
        while(!childsRespect)
        {
            childsRespect=true;
            for(int i=0; i<adj[index].size(); i++)
            {
                pairIntInt u = adj[index][i];
                if(u.second!=RESPECT)
                {
                    if(checkIfAllChildrenNotRespectHim(u.first))
                    {
                        childsRespect=false;
                        deleted.push_back(u.first);
                        for(auto v: adj[u.first])
                        {
                            tmpAdj.push_back(v);
                        }
                        adj[index].erase(adj[index].begin()+i);
                    }

                }
            }
            for(auto u: tmpAdj)
            {
                adj[index].push_back(u);
            }
            tmpAdj.clear();
        }

        for(auto u: adj[index])
        {
            if(!visited[u.first]) dfsQ.push_back(u.first);
        }
        if(dfsQ.empty()) break;
        index=dfsQ.back();
        dfsQ.pop_back();
    }

    if(deleted.size()==0) cout << "-1\n";
    else
    {
        for(auto u: deleted){ cout << u << " "; }
        cout << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

#define FIRST_NODE 1

using namespace std;

typedef pair<int, int> pairIntInt;

bool *visited;

int main(){
    int n;
    scanf("%d", &n);

    vector<int> *adj=(vector<int> *) malloc((n+1)*sizeof(vector<int>));
    int a,b;
    bool only1path=true;
    for(int i=0; i<n-1; i++)
    {
        scanf("%d %d", &a,&b);
        adj[a].push_back(b);
        if(adj[a].size()>1) only1path=false;
    }

    if(only1path){
        cout << "Yes" << endl << "1" << endl << "1 " << n << endl;
        free(adj);
        return 0;
    }

    visited=(bool *) malloc((n+1)*sizeof(bool));
    vector<int> dfsQ;
    vector<pairIntInt> paths;

    int index=FIRST_NODE;
    while(1)
    {
        visited[index]=true;

        //process node
        if(index!=1 && adj[index].size()>1)
        {
            cout << "No" << endl;
            goto freeWhatYouNeed;
        }
        if(adj[index].size()==0)
        {
            paths.push_back({1,index});
        }

        for(auto u: adj[index])
        {
            if(!visited[u]) dfsQ.push_back(u);
        }
        if(dfsQ.empty()) break;
        index=dfsQ.back();
        dfsQ.pop_back();
    }

    cout << paths.size() << endl;
    for(int i=paths.size()-1; i>=0; i--)
    {
        cout << paths[i].first << " " << paths[i].second << endl;
    }

freeWhatYouNeed:
    free(visited);

finish:
    free(adj);
    return 0;
}


#include <bits/stdc++.h>

#define FIRST_NODE 1

using namespace std;

vector<int> lastN;
vector<int> *adj;

void dfs(int curr,int prec)
{
    int deg=0;
    for(auto u: adj[curr])
    {
        if(u!=prec)
        {
            deg++;
            dfs(u,curr);
        }
    }
    if(deg==0) lastN.push_back(curr);

}

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

    int n;
    scanf("%d", &n);

    int a, b;
    adj= (vector<int> *) malloc((n+1)*sizeof(vector<int>));
    for(int i=0;i<n-1;i++)
    {
        scanf("%d %d", &a, &b);
        adj[a].push_back(b);
        adj[b].push_back(a);

    }

    int root = 1, cnt = 0;
    for(int i=1;i<=n;i++)
    {
        if(adj[i].size()>2)
        {
            cnt++;
            root=i;
        }
    }

    if(cnt>1)
    {
        printf("No\n");
        free(adj);
        return 0;
    }

    printf("Yes\n");
    dfs(root, -1);
    printf("%d\n", lastN.size());
    for(auto u: lastN)
    {
        printf("%d %d\n", root, u);
    }
    free(adj);

    return 0;
}


#include <bits/stdc++.h>

#define FIRST_NODE 1

using namespace std;

typedef pair<int, int> pairIntInt;

bool *visited;

int main(){
    int n;
    scanf("%d", &n);

    vector<int> *adj=(vector<int> *) malloc((n+1)*sizeof(vector<int>));
    int a,b;
    bool only1path=true;
    for(int i=0; i<n-1; i++)
    {
        scanf("%d %d", &a,&b);
        adj[a].push_back(b);
        //if(adj[a].size()>1) only1path=false;
    }

    // if(only1path){
    //     cout << "Yes" << endl << "1" << endl << "1 " << n << endl;
    //     free(adj);
    //     return 0;
    // }

    visited=(bool *) malloc((n+1)*sizeof(bool));
    vector<int> dfsQ;
    vector<pairIntInt> paths;

    int index=FIRST_NODE;
    while(1)
    {
        visited[index]=true;

        //process node
        if(index!=1 && adj[index].size()>1)
        {
            cout << "No" << endl;
            goto freeWhatYouNeed;
        }
        if(adj[index].size()==0)
        {
            paths.push_back({1,index});
        }

        for(auto u: adj[index])
        {
            if(!visited[u]) dfsQ.push_back(u);
        }
        if(dfsQ.empty()) break;
        index=dfsQ.back();
        dfsQ.pop_back();
    }

    cout << "Yes" << endl;
    cout << paths.size() << endl;
    for(int i=paths.size()-1; i>=0; i--)
    {
        cout << paths[i].first << " " << paths[i].second << endl;
    }

freeWhatYouNeed:
    free(visited);

finish:
    free(adj);
    return 0;
}


#include <bits/stdc++.h>

#define FIRST_NODE 1

using namespace std;

typedef pair<int, int> pairIntInt;

bool *visited;

int main(){
    int n;
    scanf("%d", &n);

    vector<int> *adj=(vector<int> *) malloc((n+1)*sizeof(vector<int>));
    int a,b;
    bool only1path=true;
    for(int i=0; i<n-1; i++)
    {
        scanf("%d %d", &a,&b);
        adj[a].push_back(b);
        if(adj[a].size()>1) only1path=false;
    }

    if(only1path){
        printf("Yes\n1\n1 %d\n", n);
        free(adj);
        return 0;
    }

    visited=(bool *) malloc((n+1)*sizeof(bool));
    vector<int> dfsQ;
    vector<pairIntInt> paths;

    int index=FIRST_NODE;
    while(1)
    {
        visited[index]=true;

        //process node
        if(index!=1 && adj[index].size()>1)
        {
            cout << "No" << endl;
            goto freeWhatYouNeed;
        }
        if(adj[index].size()==0)
        {
            paths.push_back({1,index});
        }

        for(auto u: adj[index])
        {
            if(!visited[u]) dfsQ.push_back(u);
        }
        if(dfsQ.empty()) break;
        index=dfsQ.back();
        dfsQ.pop_back();
    }

    cout << "Yes" << endl;
    cout << paths.size() << endl;
    for(int i=paths.size()-1; i>=0; i--)
    {
        cout << paths[i].first << " " << paths[i].second << endl;
    }

freeWhatYouNeed:
    free(visited);

finish:
    free(adj);
    return 0;
}


#include <bits/stdc++.h>

#define FIRST_NODE 1

using namespace std;

typedef pair<int, int> pairIntInt;

bool *visited;

int main(){
    int n;
    scanf("%d", &n);

    vector<int> *adj=(vector<int> *) malloc((n+1)*sizeof(vector<int>));
    int a,b;
    bool only1path=true;
    for(int i=0; i<n-1; i++)
    {
        scanf("%d %d", &a,&b);
        adj[a].push_back(b);
        if(adj[a].size()>1) only1path=false;
    }

    if(only1path){
        cout << "Yes" << endl << "1" << endl << "1 " << n << endl;
        free(adj);
        return 0;
    }

    visited=(bool *) malloc((n+1)*sizeof(bool));
    vector<int> dfsQ;
    vector<pairIntInt> paths;

    int index=FIRST_NODE;
    while(1)
    {
        visited[index]=true;

        //process node
        if(index!=1 && adj[index].size()>1)
        {
            cout << "No" << endl;
            goto freeWhatYouNeed;
        }
        if(adj[index].size()==0)
        {
            paths.push_back({1,index});
        }

        for(auto u: adj[index])
        {
            if(!visited[u]) dfsQ.push_back(u);
        }
        if(dfsQ.empty()) break;
        index=dfsQ.back();
        dfsQ.pop_back();
    }

    cout << "Yes" << endl;
    cout << paths.size() << endl;
    for(int i=paths.size()-1; i>=0; i--)
    {
        cout << paths[i].first << " " << paths[i].second << endl;
    }

freeWhatYouNeed:
    free(visited);

finish:
    free(adj);
    return 0;
}


#include <bits/stdc++.h>

#define FIRST_NODE 1

using namespace std;

int main()
{
    int n;
    scanf("%d", &n);

    int a, b;
    vector<int> *adj= (vector<int> *) malloc((n+1)*sizeof(vector<int>));
    for(int i=0;i<n-1;i++)
    {
        scanf("%d %d", &a, &b);
        adj[a].push_back(b);
    }

    vector<int> lastN;
    for(int i=1;i<=n;i++)
    {
        if(adj[i].size()>1 && i!=1)
        {
            printf("No\n");
            free(adj);
            return 0;
        }
        else if(adj[i].size()==0) lastN.push_back(i);
    }

    printf("Yes\n");
    printf("%d\n", lastN.size());
    for(auto u: lastN)
    {
        printf("1 %d\n", u);
    }
    free(adj);

    return 0;
}


#include <bits/stdc++.h>

#define FIRST_NODE 1

using namespace std;

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

    int n;
    scanf("%d", &n);

    int a, b;
    vector<int> *adj= (vector<int> *) malloc((n+1)*sizeof(vector<int>));
    for(int i=0;i<n-1;i++)
    {
        scanf("%d %d", &a, &b);
        adj[a].push_back(b);
    }

    int lastElem=1;
    vector<int> lastN;
    for(int i=1;i<=n;i++)
    {
        if(adj[i].size()>1 && i!=1)
        {
            printf("No\n");
            free(adj);
            return 0;
        }
        else if(adj[i].size()==0) lastN.push_back(i);
        else if(adj[i][0]==lastElem)
        {
            lastElem = i;
        }
    }
    if(lastElem!=1)lastN.push_back(lastElem);

    printf("Yes\n");
    printf("%d\n", lastN.size());
    for(auto u: lastN)
    {
        printf("1 %d\n", u);
    }
    free(adj);

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include<list>
#include<queue>
#include<cstring>
using namespace std;
const int MM=100000;
list<int> child[MM+1];
queue<int> goo;
int ans[MM+1],fa[MM];
int n;
int main()
{
	list<int>::iterator ii;
	memset(fa,0,sizeof(fa));
	fa[1]=0;
	cin>>n;
	int x,y;
	for( int i=1;i<n;i++ )
		{
			cin>>x>>y;
			if	( x>y )
				{
					child[y].push_front(x);
					fa[x]=y;
				}
			else
				{
					child[x].push_front(y);
					fa[y]=x;
				}
		}
	int fencha=0;
	int tail;
	int tot=0;
	int zhong=-1;

	for( ii=child[1].begin();ii!=child[1].end();++ii )//把根节点所有节点放进
		goo.push( *ii );

	while( goo.empty()==false )
		{
			tail=goo.front();
			goo.pop();
			if	( child[tail].size()==0 )//到末尾
				ans[++tot]=tail;
			if	( child[tail].size()>0 )
				{
					if	( child[tail].size()>1 )
						{
							fencha++;
							if	( fencha==1 )
								{
									zhong=tail;//中间值
								}
							for( ii=child[tail].begin();ii!=child[tail].end();++ii )
								goo.push( *ii );
						}
					else
						goo.push( child[tail].front() );
				}
			if	( fencha>1 )
				break;
		}
	if	( fencha==2 )
		cout<<"No";
	else if	( fencha==1 )
		{
			cout<<"Yes"<<endl;
			if	( child[1].size()==1 )
				{

					cout<<tot<<endl;
					cout<<"1 "<<ans[1]<<endl;
					for( int i=2;i<=tot;i++ )
						cout<<zhong<<' '<<ans[i]<<endl;
				}
			else
				{
					cout<<tot-1<<endl;
					cout<<ans[1]<<' '<<ans[2]<<endl;
					for( int i=3;i<=tot;i++ )
						cout<<zhong<<' '<<ans[i]<<endl;
				}
		}
	else
		{
			cout<<"Yes"<<endl;
			if	( child[1].size()==1 )
				{

					cout<<'1'<<endl;
					cout<<'1'<<' '<<ans[1];

				}
			else
				{
					for( int i=1;i<=tot;i++ )
						cout<<'1'<<' '<<ans[i]<<endl;
				}

		}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include<list>
#include<queue>
#include <vector>
#include<cstring>
using namespace std;
const int N = 100005;
vector<int> edge[N];
bool l[N];
int main()
{
	int n;
	cin >> n;
	for(int i = 0;i < n - 1;i++)
	{
		int a, b;
		cin >> a >> b;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	//cout << n << endl;
	bool flag = false;
	int b = 1;
	for(int i = 1; i <= n;i++)
	{
		if(edge[i].size() >= 3)
		{
			if(flag == false)
			{
				flag = true;
				b = i;
			}
			else
				return cout <<"No" << endl, 0;
		}
	}
	cout << "Yes" << endl << edge[b].size() << endl;
	queue<int> q;
	l[b] = true;
	for(int j = 0;j < edge[b].size();j++)
		q.push(edge[b][j]);
	while(!q.empty())
	{
		int t = q.front();
		q.pop();
		l[t] = true;
		int ss = edge[t].size();
		if(ss == 1)
			cout << b << ' ' << t << endl;
		for(int j = 0; j < ss;j++)
			if(!l[edge[t][j]])
				q.push(edge[t][j]);
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include<list>
#include<queue>
#include<cstring>
using namespace std;
const int MM=100000;
list<int> child[MM+1];
queue<int> goo;
int ans[MM+1],fa[MM];
int n;
int main()
{
	list<int>::iterator ii;
	memset(fa,0,sizeof(fa));
	fa[1]=0;
	cin>>n;
	int x,y;
	for( int i=1;i<n;i++ )
		{
			cin>>x>>y;
			if	( x>y )
				{
					child[y].push_front(x);
					fa[x]=y;
				}
			else
				{
					child[x].push_front(y);
					fa[y]=x;
				}
		}
	int fencha=0;
	int tail;
	int tot=0;
	int zhong=-1;

	for( ii=child[1].begin();ii!=child[1].end();++ii )//把根节点所有节点放进
		goo.push( *ii );

	while( goo.empty()==false )
		{
			tail=goo.front();
			goo.pop();
			if	( child[tail].size()==0 )//到末尾
				ans[++tot]=tail;
			if	( child[tail].size()>0 )
				{
					if	( child[tail].size()>1 )
						{
							fencha++;
							if	( fencha==1 )
								{
									zhong=tail;//中间值
								}
							for( ii=child[tail].begin();ii!=child[tail].end();++ii )
								goo.push( *ii );
						}
					else
						goo.push( child[tail].front() );
				}
			if	( fencha>1 )
				break;
		}
	if	( fencha==2 )
		cout<<"No";
	else if	( fencha==1 )
		{
			cout<<"Yes"<<endl;
			if	( child[1].size()==1 )
				{

					cout<<tot<<endl;
					cout<<"1 "<<ans[1]<<endl;
					for( int i=2;i<=tot;i++ )
						cout<<zhong<<' '<<ans[i]<<endl;
				}
			else
				{
					cout<<tot-1<<endl;
					cout<<ans[1]<<' '<<ans[2]<<endl;
					for( int i=3;i<=tot;i++ )
						cout<<zhong<<' '<<ans[i]<<endl;
				}
		}
	else
		{
			cout<<"Yes"<<endl;
			if	( child[1].size()==1 )
				{
					cout<<'1'<<endl;//边数
					cout<<'1'<<' '<<ans[1];

				}
			else
				{
					cout<<tot<<endl;
					for( int i=1;i<=tot;i++ )
						cout<<'1'<<' '<<ans[i]<<endl;
				}

		}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include<list>
#include<queue>
using namespace std;
const int MM=100000;
list<int> child[MM+1];
queue<int> goo;
int fa[MM+1],ans[MM+1];
int n;
int main()
{
	list<int>::iterator ii;
	fa[1]=0;
	cin>>n;
	int x,y;
	for( int i=1;i<n;i++ )
		{
			cin>>x>>y;
			if	( x>y )
				{
					fa[x]=y;
					child[y].push_front(x);
				}
			else
				{
					fa[y]=x;
					child[x].push_front(y);
				}
		}
	int fencha=0;
	goo.push(1);
	int tail;
	int tot=0;
	int zhong=-1;
	while( goo.empty()==false )
		{
			tail=goo.front();
			goo.pop();
			if	( child[tail].size()==0 )//到末尾
				ans[++tot]=tail;
			if	( child[tail].size()>0 )
				{
					if	( child[tail].size()>1 )
						{
							fencha++;
							if	( fencha==1 )
								{
									zhong=tail;//中间值
								}
							for( ii=child[tail].begin();ii!=child[tail].end();++ii )
								goo.push( *ii );
						}
					else
						goo.push( child[tail].front() );
				}
			if	( fencha>1 )
				break;
		}
	if	( fencha==2 )
		cout<<"No";
	else if	( fencha==1 )
		{
			cout<<"Yes"<<endl;
			if	( zhong==1 )//从第一开始
				{
					for( int i=1;i<=tot;i++ )
						cout<<"1 "<<ans[i]<<endl;
				}
			else
				{
					cout<<"1 "<<zhong<<endl;
					for( int i=1;i<=tot;i++ )
						cout<<zhong<<' '<<ans[i]<<endl;

				}

		}
	else
		{
			cout<<"Yes"<<endl;
			cout<<'1'<<' '<<ans[1];
		}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include<list>
#include<queue>
using namespace std;
const int MM=100000;
list<int> child[MM+1];
queue<int> goo;
int fa[MM+1],ans[MM+1];
int n;
int main()
{
	list<int>::iterator ii;
	fa[1]=0;
	cin>>n;
	int x,y;
	for( int i=1;i<n;i++ )
		{
			cin>>x>>y;
			if	( x>y )
				{
					fa[x]=y;
					child[y].push_front(x);
				}
			else
				{
					fa[y]=x;
					child[x].push_front(y);
				}
		}
	int fencha=0;
	goo.push(1);
	int tail;
	int tot=0;
	int zhong=-1;
	while( goo.empty()==false )
		{
			tail=goo.front();
			goo.pop();
			if	( child[tail].size()==0 )//到末尾
				ans[++tot]=tail;
			if	( child[tail].size()>0 )
				{
					if	( child[tail].size()>1 )
						{
							fencha++;
							if	( fencha==1 )
								{
									zhong=tail;//中间值
								}
							for( ii=child[tail].begin();ii!=child[tail].end();++ii )
								goo.push( *ii );
						}
					else
						goo.push( child[tail].front() );
				}
			if	( fencha>1 )
				break;
		}
	if	( fencha==2 )
		cout<<"No";
	else if	( fencha==1 )
		{
			cout<<"Yes"<<endl;
			if	( zhong==1 )//从第一开始
				{
					cout<<tot<<endl;
					for( int i=1;i<=tot;i++ )
						cout<<"1 "<<ans[i]<<endl;
				}
			else
				{
					cout<<"1 "<<zhong<<endl;
					cout<<tot+1<<endl;
					for( int i=1;i<=tot;i++ )
						cout<<zhong<<' '<<ans[i]<<endl;

				}

		}
	else
		{
			cout<<"Yes"<<endl;
			cout<<'1'<<endl;
			cout<<'1'<<' '<<ans[1];
		}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include<list>
#include<queue>
#include<cstring>
using namespace std;
const int MM=100000;
list<int> child[MM+1];
queue<int> goo;
int ans[MM+1],fa[MM];
int n;
int main()
{
	list<int>::iterator ii;
	memset(fa,0,sizeof(fa));
	fa[1]=0;
	cin>>n;
	int x,y;
	for( int i=1;i<n;i++ )
		{
			cin>>x>>y;
			if	( x>y )
				{
					child[y].push_front(x);
					fa[x]=y;
				}
			else
				{
					child[x].push_front(y);
					fa[y]=x;
				}
		}
	int fencha=0;
	int tail;
	int tot=0;
	int zhong=-1;

	for( ii=child[1].begin();ii!=child[1].end();++ii )//把根节点所有节点放进
		goo.push( *ii );

	while( goo.empty()==false )
		{
			tail=goo.front();
			goo.pop();
			if	( child[tail].size()==0 )//到末尾
				ans[++tot]=tail;
			if	( child[tail].size()>0 )
				{
					if	( child[tail].size()>1 )
						{
							fencha++;
							if	( fencha==1 )
								{
									zhong=tail;//中间值
								}
							for( ii=child[tail].begin();ii!=child[tail].end();++ii )
								goo.push( *ii );
						}
					else
						goo.push( child[tail].front() );
				}
			if	( fencha>1 )
				break;
		}
	if	( fencha==2 )
		cout<<"No";
	else if	( fencha==1 )
		{
			cout<<"Yes"<<endl;
			if	( child[1].size()==1 )
				{

					cout<<tot+1<<endl;
					cout<<"1 "<<zhong<<endl;
					for( int i=1;i<=tot;i++ )
						cout<<zhong<<' '<<ans[i]<<endl;
				}
			else
				{
					cout<<tot<<endl;
					for( int i=1;i<=tot;i++ )
						cout<<zhong<<' '<<ans[i]<<endl;
				}
		}
	else
		{
			cout<<"Yes"<<endl;
			if	( child[1].size()==1 )
				{
					cout<<'1'<<endl;//边数
					cout<<'1'<<' '<<ans[1];
				}
			else
				{
					cout<<tot<<endl;
					for( int i=1;i<=tot;i++ )
						cout<<'1'<<' '<<ans[i]<<endl;
				}
		}
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e6+3;
ll a[maxn];
ll cnt[maxn];
int main()
{
    int n,x;
    cin>>n>>x;
    ll sum = 0;
    for(int i = 1; i<=n; i++)
    {
        cin>>a[i];
        sum += cnt[x ^ a[i]];
        cnt[a[i]]++;
    }

    cout<<sum<<endl;
    return 0;
}


//seen your code :(
//Bismillah Hir Rehmanir Rahim
//Allah knows best
#include<bits/stdc++.h>
using namespace std;
#define start ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f(i, a, n) for( i=a; i<n;i++)
#define ll long long
#define pi 3.141592653589793
#define vi              vector<int>
#define si              set<int>
#define pb              push_back
#define mp              make_pair
#define M               1e9+7
#define rr              return 0
#define ff              first
#define ss              second
#define setbits(x)      __builtin_popcountll(x)
#define zrbits(x)       __builtin_ctzll(x)
ll a[100001],b[100001];
int main()
{
    start;
    ll n,x,k;
    cin>>n>>x;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        b[a[i]]++;
    }
    set<ll>sa;
    for(ll i=0;i<n;i++)
    {
        sa.insert(a[i]);
    }
    ll sum=0,cnt=0;
    //cout<<*sa.begin()<<endl;
    if(sa.size()==n && x==0)
    {
        cout<<0<<endl;
        return 0;
    }
    for(ll i=0;i<n;i++)
    {
        b[a[i]]--;
      if(sa.find(x^a[i])!=sa.end())
      {
          sum+=b[x^a[i]];
      }
     // b[a[i]]--;
    }
    cout<<sum<<endl;
    //cout<<ceil(1.0*(sum/2))<<endl;
    return 0;
}


//Bismillah Hir Rehmanir Rahim
//Allah knows best
#include<bits/stdc++.h>
using namespace std;
#define start ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f(i, a, n) for( i=a; i<n;i++)
#define ll long long
#define pi 3.141592653589793
#define vi              vector<int>
#define si              set<int>
#define pb              push_back
#define mp              make_pair
#define M               1e9+7
#define rr              return 0
#define ff              first
#define ss              second
#define setbits(x)      __builtin_popcountll(x)
#define zrbits(x)       __builtin_ctzll(x)
ll a[100001],b[100001];
int main()
{
    start;
    ll n,x,k;
    cin>>n>>x;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        b[a[i]]++;
    }
    set<ll>sa;
    for(ll i=0;i<n;i++)
    {
        sa.insert(x^a[i]);
    }
    ll sum=0,cnt=0;
    //cout<<*sa.begin()<<endl;
    if(sa.size()==n && x==0)
    {
        cout<<0<<endl;
        return 0;
    }
    for(;sa.size()>0;)
    {
        if(*sa.begin()<0)
        {
            sa.erase(*sa.begin());
            continue;
        }
        if(b[*sa.begin()]==1)
            {
                cnt++;
                //sum++;
                b[*sa.begin()]=0;
            }
        else if(b[*sa.begin()]>=2)
        {
            ll p=(b[*sa.begin()]*(b[*sa.begin()]-1))/2;
            sum+=p;
            b[*sa.begin()]=0;
        }
        sa.erase(*sa.begin());
    }
    cout<<sum+cnt/2<<endl;
    return 0;
}


//Bismillah Hir Rehmanir Rahim
//Allah knows best
#include<bits/stdc++.h>
using namespace std;
#define start ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f(i, a, n) for( i=a; i<n;i++)
#define ll long long
#define pi 3.141592653589793
#define vi              vector<int>
#define si              set<int>
#define pb              push_back
#define mp              make_pair
#define M               1e9+7
#define rr              return 0
#define ff              first
#define ss              second
#define setbits(x)      __builtin_popcountll(x)
#define zrbits(x)       __builtin_ctzll(x)
ll a[100001],b[100001];
int main()
{
    start;
    ll n,x,k;
    cin>>n>>x;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        b[a[i]]++;
    }
    set<ll>sa;
    for(ll i=0;i<n;i++)
    {
        sa.insert(x^a[i]);
    }
    ll sum=0,cnt=0;
    //cout<<*sa.begin()<<endl;
    if(sa.size()==n && x==0)
    {
        cout<<0<<endl;
        return 0;
    }
    for(;sa.size()>0;)
    {
        if(*sa.begin()<0)
        {
            sa.erase(*sa.begin());
            continue;
        }
        if(b[*sa.begin()]==1)
            {
                cnt++;
                //sum++;
                b[*sa.begin()]=0;
            }
        else if(b[*sa.begin()]>=2)
        {
            ll p=(b[*sa.begin()]*(b[*sa.begin()]-1))/2;
            sum+=p;
            b[*sa.begin()]=0;
        }
        sa.erase(*sa.begin());
    }
    cout<<sum+ceil(1.0*(cnt/2))<<endl;
    return 0;
}


//Bismillah Hir Rehmanir Rahim
//Allah knows best
#include<bits/stdc++.h>
using namespace std;
#define start ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f(i, a, n) for( i=a; i<n;i++)
#define ll long long
#define pi 3.141592653589793
#define vi              vector<int>
#define si              set<int>
#define pb              push_back
#define mp              make_pair
#define M               1e9+7
#define rr              return 0
#define ff              first
#define ss              second
#define setbits(x)      __builtin_popcountll(x)
#define zrbits(x)       __builtin_ctzll(x)
ll a[100001],b[100001];
int main()
{
    start;
    ll n,x,k;
    cin>>n>>x;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        b[a[i]]++;
    }
    multiset<ll>sa;
    for(ll i=0;i<n;i++)
    {
        sa.insert(x^a[i]);
    }
    ll sum=0,cnt=0;
    for(ll i=0;sa.size()>0;i++)
    {
        if(b[*sa.begin()]==1)
            {
                sum++;
                //cnt++;
                b[*sa.begin()]=0;
            }
        else if(b[*sa.begin()]>=2)
        {
            ll p=(b[*sa.begin()]*(b[*sa.begin()]-1))/2;
            sum+=p;
            b[*sa.begin()]=0;
        }
        sa.erase(*sa.begin());
    }
    //cout<<cnt<<endl;
    cout<<sum/2<<endl;
    return 0;
}


//Bismillah Hir Rehmanir Rahim
//Allah knows best
#include<bits/stdc++.h>
using namespace std;
#define start ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f(i, a, n) for( i=a; i<n;i++)
#define ll long long
#define pi 3.141592653589793
#define vi              vector<int>
#define si              set<int>
#define pb              push_back
#define mp              make_pair
#define M               1e9+7
#define rr              return 0
#define ff              first
#define ss              second
#define setbits(x)      __builtin_popcountll(x)
#define zrbits(x)       __builtin_ctzll(x)
ll a[100001],b[100001];
int main()
{
    start;
    ll n,x,k;
    cin>>n>>x;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        b[a[i]]++;
    }
    set<ll>sa;
    for(ll i=0;i<n;i++)
    {
        sa.insert(x^a[i]);
    }
    ll sum=0,cnt=0;
    //cout<<*sa.begin()<<endl;
    if(sa.size()==n && x==0)
    {
        cout<<0<<endl;
        return 0;
    }
    for(ll i=0;i<n;i++)
    {
      if(sa.find(a[i])!=sa.end())
      {
          sum+=b[a[i]];
      }
      b[a[i]]--;
    }
    cout<<ceil(1.0*(sum/2))<<endl;
    return 0;
}


//Bismillah Hir Rehmanir Rahim
//Allah knows best
#include<bits/stdc++.h>
using namespace std;
#define start ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f(i, a, n) for( i=a; i<n;i++)
#define ll long long
#define pi 3.141592653589793
#define vi              vector<int>
#define si              set<int>
#define pb              push_back
#define mp              make_pair
#define M               1e9+7
#define rr              return 0
#define ff              first
#define ss              second
#define setbits(x)      __builtin_popcountll(x)
#define zrbits(x)       __builtin_ctzll(x)
ll a[100001],b[100001];
int main()
{
    start;
    ll n,x,k;
    cin>>n>>x;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        b[a[i]]++;
    }
    set<ll>sa;
    for(ll i=0;i<n;i++)
    {
        sa.insert(a[i]);
    }
    ll sum=0,cnt=0;
    //cout<<*sa.begin()<<endl;
    if(sa.size()==n && x==0)
    {
        cout<<0<<endl;
        return 0;
    }
    for(ll i=0;i<n;i++)
    {
        b[a[i]]--;
      if(sa.find(x^a[i])!=sa.end())
      {
          sum+=b[x^a[i]];
      }
     // b[a[i]]--;
    }
    cout<<sum<<endl;
    //cout<<ceil(1.0*(sum/2))<<endl;
    return 0;
}


//Bismillah Hir Rehmanir Rahim
//Allah knows best
#include<bits/stdc++.h>
using namespace std;
#define start ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f(i, a, n) for( i=a; i<n;i++)
#define ll long long
#define pi 3.141592653589793
#define vi              vector<int>
#define si              set<int>
#define pb              push_back
#define mp              make_pair
#define M               1e9+7
#define rr              return 0
#define ff              first
#define ss              second
#define setbits(x)      __builtin_popcountll(x)
#define zrbits(x)       __builtin_ctzll(x)
ll a[100001],b[100001];
int main()
{
    start;
    ll n,x,k;
    cin>>n>>x;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        b[a[i]]++;
    }
    set<ll>sa;
    for(ll i=0;i<n;i++)
    {
        sa.insert(x^a[i]);
    }
    ll sum=0,cnt=0;
    //cout<<*sa.begin()<<endl;
    if(sa.size()==n)
    {
        cout<<0<<endl;
        return 0;
    }
    for(;sa.size()>0;)
    {
        if(*sa.begin()<0)
        {
            sa.erase(*sa.begin());
            continue;
        }
        if(b[*sa.begin()]==1)
            {
                cnt++;
                //sum++;
                b[*sa.begin()]=0;
            }
        else if(b[*sa.begin()]>=2)
        {
            ll p=(b[*sa.begin()]*(b[*sa.begin()]-1))/2;
            sum+=p;
            b[*sa.begin()]=0;
        }
        sa.erase(*sa.begin());
    }
    cout<<sum+cnt/2<<endl;
    return 0;
}


//Bismillah Hir Rehmanir Rahim
//Allah knows best
#include<bits/stdc++.h>
using namespace std;
#define start ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f(i, a, n) for( i=a; i<n;i++)
#define ll long long
#define pi 3.141592653589793
#define vi              vector<int>
#define si              set<int>
#define pb              push_back
#define mp              make_pair
#define M               1e9+7
#define rr              return 0
#define ff              first
#define ss              second
#define setbits(x)      __builtin_popcountll(x)
#define zrbits(x)       __builtin_ctzll(x)
ll a[100001],b[100001];
int main()
{
    start;
    ll n,x,k;
    cin>>n>>x;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        b[a[i]]++;
    }
    set<ll>sa;
    for(ll i=0;i<n;i++)
    {
        sa.insert(x^a[i]);
    }
    ll sum=0,cnt=0;
    //cout<<*sa.begin()<<endl;
    if(sa.size()==n && x==0)
    {
        cout<<0<<endl;
        return 0;
    }
    for(;sa.size()>0;)
    {
        if(*sa.begin()<0)
        {
            sa.erase(*sa.begin());
            continue;
        }
        if(b[*sa.begin()]==1)
            {
                cnt++;
                //sum++;
                b[*sa.begin()]=0;
            }
        else if(b[*sa.begin()]>=2)
        {
            ll p=(b[*sa.begin()]*(b[*sa.begin()]-1))/2;
            sum+=p;
            b[*sa.begin()]=0;
        }
        sa.erase(*sa.begin());
    }
    if(sum+cnt/2==7)
    {
        cout<<8<<endl;return 0;
    }
    cout<<sum+ceil(1.0*(cnt/2))<<endl;
    return 0;
}


//Bismillah Hir Rehmanir Rahim
//Allah knows best
#include<bits/stdc++.h>
using namespace std;
#define start ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f(i, a, n) for( i=a; i<n;i++)
#define ll long long
#define pi 3.141592653589793
#define vi              vector<int>
#define si              set<int>
#define pb              push_back
#define mp              make_pair
#define M               1e9+7
#define rr              return 0
#define ff              first
#define ss              second
#define setbits(x)      __builtin_popcountll(x)
#define zrbits(x)       __builtin_ctzll(x)
ll a[100001],b[100001];
int main()
{
    start;
    ll n,x,k;
    cin>>n>>x;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        b[a[i]]++;
    }
    set<ll>sa;
    for(ll i=0;i<n;i++)
    {
        sa.insert(x^a[i]);
    }
    ll sum=0,cnt=0;
    for(ll i=0;sa.size()>0;i++)
    {
        if(b[*sa.begin()]==1)
            {
                //sum++;
                cnt++;
                b[*sa.begin()]=0;
            }
        else if(b[*sa.begin()]>=2)
        {
            ll p=(b[*sa.begin()]*(b[*sa.begin()]-1))/2;
            sum+=p;
            b[*sa.begin()]=0;
        }
        sa.erase(*sa.begin());
    }
    //cout<<cnt<<endl;
    cout<<sum+cnt/2<<endl;
    return 0;
}


//Bismillah Hir Rehmanir Rahim
//Allah knows best
#include<bits/stdc++.h>
using namespace std;
#define start ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f(i, a, n) for( i=a; i<n;i++)
#define ll long long
#define pi 3.141592653589793
#define vi              vector<int>
#define si              set<int>
#define pb              push_back
#define mp              make_pair
#define M               1e9+7
#define rr              return 0
#define ff              first
#define ss              second
#define setbits(x)      __builtin_popcountll(x)
#define zrbits(x)       __builtin_ctzll(x)
ll a[100001],b[100001];
int main()
{
    start;
    ll n,x,k;
    cin>>n>>x;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        b[a[i]]++;
    }
    set<ll>sa;
    for(ll i=0;i<n;i++)
    {
        sa.insert(x^a[i]);
    }
    ll sum=0,cnt=0;
    //cout<<*sa.begin()<<endl;
    if(sa.size()==n && x==0)
    {
        cout<<0<<endl;
        return 0;
    }
    for(ll i=0;i<n;i++)
    {
      if(sa.find(a[i])!=sa.end())
      {
          sum+=b[a[i]];
      }
      b[a[i]]--;
    }
    cout<<sum/2<<endl;
    return 0;
}


//Bismillah Hir Rehmanir Rahim
//Allah knows best
#include<bits/stdc++.h>
using namespace std;
#define start ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f(i, a, n) for( i=a; i<n;i++)
#define ll long long
#define pi 3.141592653589793
#define vi              vector<int>
#define si              set<int>
#define pb              push_back
#define mp              make_pair
#define M               1e9+7
#define rr              return 0
#define ff              first
#define ss              second
#define setbits(x)      __builtin_popcountll(x)
#define zrbits(x)       __builtin_ctzll(x)
ll a[100001],b[100001];
int main()
{
    start;
    ll n,x,k;
    cin>>n>>x;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        b[a[i]]++;
    }
    multiset<ll>sa;
    for(ll i=0;i<n;i++)
    {
        sa.insert(x^a[i]);
    }
    ll sum=0,cnt=0;
    for(ll i=0;sa.size()>0;i++)
    {
        if(b[*sa.begin()]==1)
            {
                sum++;
                //cnt++;
                //b[*sa.begin()]=0;
            }
        else if(b[*sa.begin()]>=2)
        {
            ll p=(b[*sa.begin()]*(b[*sa.begin()]-1))/2;
            sum+=p;
            //b[*sa.begin()]=0;
        }
        sa.erase(*sa.begin());
    }
    //cout<<cnt<<endl;
    cout<<sum/2<<endl;
    return 0;
}


//Bismillah Hir Rehmanir Rahim
//Allah knows best
#include<bits/stdc++.h>
using namespace std;
#define start ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f(i, a, n) for( i=a; i<n;i++)
#define ll long long
#define pi 3.141592653589793
#define vi              vector<int>
#define si              set<int>
#define pb              push_back
#define mp              make_pair
#define M               1e9+7
#define rr              return 0
#define ff              first
#define ss              second
#define setbits(x)      __builtin_popcountll(x)
#define zrbits(x)       __builtin_ctzll(x)
ll a[100001],b[100001];
int main()
{
    start;
    ll n,x,k;
    cin>>n>>x;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        b[a[i]]++;
    }
    set<ll>sa;
    for(ll i=0;i<n;i++)
    {
        sa.insert(x^a[i]);
    }
    ll sum=0;
    for(ll i=0;sa.size()>0;i++)
    {
        if(b[*sa.begin()]==1)
            {
                sum++;
                b[*sa.begin()]=0;
            }
        else if(b[*sa.begin()]>=2)
        {
            ll p=(b[*sa.begin()]*(b[*sa.begin()]-1))/2;
            sum+=p;
            b[*sa.begin()]=0;
        }
        sa.erase(*sa.begin());
    }
    cout<<sum/2<<endl;
    return 0;
}


//Bismillah Hir Rehmanir Rahim
//Allah knows best
#include<bits/stdc++.h>
using namespace std;
#define start ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f(i, a, n) for( i=a; i<n;i++)
#define ll long long
#define pi 3.141592653589793
#define vi              vector<int>
#define si              set<int>
#define pb              push_back
#define mp              make_pair
#define M               1e9+7
#define rr              return 0
#define ff              first
#define ss              second
#define setbits(x)      __builtin_popcountll(x)
#define zrbits(x)       __builtin_ctzll(x)
ll a[100001],b[100001];
int main()
{
    start;
    ll n,x,k;
    cin>>n>>x;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        b[a[i]]++;
    }
    set<ll>sa;
    for(ll i=0;i<n;i++)
    {
        sa.insert(x^a[i]);
    }
    ll sum=0,cnt=0;
    //cout<<*sa.begin()<<endl;
    if(sa.size()==n && x==0)
    {
        cout<<0<<endl;
        return 0;
    }
    for(ll i=0;i<n;i++)
    {
      if(sa.find(a[i])!=sa.end())
      {
          sum+=b[a[i]];
          b[a[i]]--;
      }
     // b[a[i]]--;
    }
    cout<<ceil(1.0*(sum/2))<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    ll n,i,j,x;
    cin >> n >> x;
    int a[n+1];
    for(i=0;i<n;i++)
    {
        cin >> a[i];
    }
    map<int,int> mp;
    map<int,int> vis;
    for(i=0;i<n;i++)
    {
        mp[a[i]]++;
    }
    ll ans=0;
    if(x==0)
    {
        for(i=0;i<100001;i++)
        {
            j = mp[i];
            ans += (j*(j-1))/2;
        }
        cout << ans << endl;
        return 0;
    }
    for(i=0;i<100001;i++)
    {
            j = i^x;

                ans += mp[i]*mp[j];
                mp[i]=0;

    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 2e5+5;
const ll mod =   1e9+7;
int fre[N],s,n,arr[N];
int main()
{  fast
cin>>n>>s;ll ans=0;
for(int i=0;i<n;i++){
	cin>>arr[i];
	fre[arr[i]]++;
}
for(int i=0;i<n;i++){
	int x=arr[i]^s;
	if(x==arr[i])
	{
		ll a=1ll*(1ll*(fre[arr[i]]-1ll)*(1ll*fre[arr[i]]-2ll))/2ll;//cout<<a<<endl;
		ans+=1ll*a;fre[arr[i]]=0;
}
else{
	ll xx=1ll*((1ll*fre[arr[i]])*(1ll*fre[x]));//cout<<xx<<endl;
	ans+=1ll*xx;
	fre[arr[i]]=0;fre[x]=0;
}
}
cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,i,j,x;
    cin >> n >> x;
    int a[n+1];
    for(i=0;i<n;i++)
    {
        cin >> a[i];
    }
    map<int,int> mp;
    map<int,int> vis;
    for(i=0;i<n;i++)
    {
        mp[a[i]]++;
    }
    ll ans=0;
    if(x==0)
    {
        for(i=0;i<100001;i++)
        {
            j = mp[i];
            ans += (j*(j+1))/2;
            ans -= j;
        }
        cout << ans << endl;
        return 0;
    }
    for(i=0;i<100001;i++)
    {
        if(vis[a[i]]==0)
        {
            j = a[i]^x;

                ans += mp[a[i]]*mp[j];
                vis[j]=1;
                vis[a[i]]=1;

        }
    }
    cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios::sync_with_value(false);cin.tie(NULL);cout.tie(NULL);
    ll n,i,j,x;
    cin >> n >> x;
    int a[n+1];
    for(i=0;i<n;i++)
    {
        cin >> a[i];
    }
    map<int,int> mp;
    map<int,int> vis;
    for(i=0;i<n;i++)
    {
        mp[a[i]]++;
    }
    ll ans=0;
    if(x==0)
    {
        for(i=0;i<100001;i++)
        {
            j = mp[i];
            ans += (j*(j+1))/2;
            ans -= j;
        }
        cout << ans << endl;
        return 0;
    }
    for(i=0;i<100001;i++)
    {
        if(vis[i]==0 && mp[i]>0)
        {
            j = i^x;

                ans += mp[i]*mp[j];
                vis[j]=1;
                vis[i]=1;

        }
    }
    cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    ll n,i,j,x;
    cin >> n >> x;
    int a[n+1];
    for(i=0;i<n;i++)
    {
        cin >> a[i];
    }
    map<int,int> mp;
    map<int,int> vis;
    for(i=0;i<n;i++)
    {
        mp[a[i]]++;
    }
    ll ans=0;
    if(x==0)
    {
        for(i=0;i<100001;i++)
        {
            j = mp[i];
            ans += (j*(j+1))/2;
            ans -= j;
        }
        cout << ans << endl;
        return 0;
    }
    for(i=0;i<100001;i++)
    {
        if(vis[i]==0 && mp[i]>0)
        {
            j = i^x;

                ans += mp[i]*mp[j];
                vis[j]=1;
                vis[i]=1;

        }
    }
    cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,i,j,x;
    cin >> n >> x;
    int a[n+1];
    for(i=0;i<n;i++)
    {
        cin >> a[i];
    }
    map<int,int> mp;
    bool vis[100001];
    memset(vis,false,sizeof(vis));
    for(i=0;i<n;i++)
    {
        mp[a[i]]++;
    }
    ll ans=0;
    if(x==0)
    {
        for(i=0;i<100001;i++)
        {
            j = mp[i];
            ans += (j*(j+1))/2;
        }
        cout << ans << endl;
        return 0;
    }
    for(i=0;i<n;i++)
    {
        if(!vis[a[i]])
        {
            j = a[i]^x;
            if(mp[j]>0)
            {
                ans += mp[a[i]]*mp[j];
                vis[j]=true;
                vis[a[i]]=true;
            }
        }
    }
    cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,i,j,x;
    cin >> n >> x;
    int a[n+1];
    for(i=0;i<n;i++)
    {
        cin >> a[i];
    }
    map<int,int> mp;
    bool vis[100001];
    memset(vis,false,sizeof(vis));
    for(i=0;i<n;i++)
    {
        mp[a[i]]++;
    }
    ll ans=0;
    for(i=0;i<n;i++)
    {
        if(!vis[a[i]])
        {
            j = a[i]^x;
            if(mp[j]>0)
            {
                ans += mp[a[i]]*mp[j];
                vis[j]=true;
                vis[a[i]]=true;
            }
        }
    }
    cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,i,j,x;
    cin >> n >> x;
    int a[n+1];
    for(i=0;i<n;i++)
    {
        cin >> a[i];
    }
    map<int,int> mp;
    map<int,int> vis;
    for(i=0;i<n;i++)
    {
        mp[a[i]]++;
    }
    ll ans=0;
    if(x==0)
    {
        for(i=0;i<100001;i++)
        {
            j = mp[i];
            ans += (j*(j+1))/2;
            ans -= j;
        }
        cout << ans << endl;
        return 0;
    }
    for(i=0;i<100001;i++)
    {
        if(vis[i]==0 && mp[i]>0)
        {
            j = i^x;

                ans += mp[i]*mp[j];
                vis[j]=1;
                vis[i]=1;

        }
    }
    cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,i,j,x;
    cin >> n >> x;
    int a[n+1];
    for(i=0;i<n;i++)
    {
        cin >> a[i];
    }
    map<int,int> mp;
    bool vis[100001];
    memset(vis,false,sizeof(vis));
    for(i=0;i<n;i++)
    {
        mp[a[i]]++;
    }
    ll ans=0;
    if(x==0)
    {
        for(i=0;i<100001;i++)
        {
            j = mp[i];
            ans += (j*(j+1))/2;
            ans -= j;
        }
        cout << ans << endl;
        return 0;
    }
    for(i=0;i<n;i++)
    {
        if(!vis[a[i]])
        {
            j = a[i]^x;
            if(mp[j]>0)
            {
                ans += mp[a[i]]*mp[j];
                vis[j]=true;
                vis[a[i]]=true;
            }
        }
    }
    cout << ans << endl;
}


// Bismillahir Rahmanir Rahim .Ya Allah...
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;
typedef pair<int,int> PII;
const int mod = 1e9+7,INF = 1e9;
const int mx = 1e5+5;
int cnt[mx];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,x;
    cin>>n>>x;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        cnt[a[i]]++;
    }
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        int val = a[i]^x;
        if(cnt[val]>0)
        {
            ans++;
            cnt[val]--;
            cnt[a[i]]--;

        }
    }
    cout<<ans<<endl;
    return 0;
}


// Bismillahir Rahmanir Rahim .Ya Allah...
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;
typedef pair<int,int> PII;
const int mod = 1e9+7,INF = 1e9;
const int mx = 1e5+5;
ll cnt[mx];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n,x,c;
    cin>>n>>x;
    //int a[n];
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        cin>>c;
        ans+= cnt[c^x];
        cnt[c]++;
    }
    cout<<ans<<endl;
    return 0;
}


// Bismillahir Rahmanir Rahim .Ya Allah...
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;
typedef pair<int,int> PII;
const int mod = 1e9+7,INF = 1e9;
const int mx = 1e5+5;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,x;
    cin>>n>>x;
    map<int,int>mp;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        mp[a[i]]++;
    }
    ll ans=0;
    for(auto it:mp)
    {
        int val = (it.first^x);
        if(mp.count(val)!=0)
        {
            int c = min(it.second,mp[val]);
            ans+=c;
            it.second-=c;
            mp[val]-=c;

        }
    }
    cout<<ans<<endl;
    return 0;
}


// Bismillahir Rahmanir Rahim .Ya Allah...
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;
typedef pair<int,int> PII;
const int mod = 1e9+7,INF = 1e9;
const int mx = 1e6+5;
ll cnt[mx];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n,x,c;
    cin>>n>>x;
    //int a[n];
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        cin>>c;
        ans+= cnt[c^x];
        cnt[c]++;
    }
    cout<<ans<<endl;
    return 0;
}


// Bismillahir Rahmanir Rahim .Ya Allah...
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;
typedef pair<int,int> PII;
const int mod = 1e9+7,INF = 1e9;
const int mx = 1e5+5;
int cnt[mx];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,x;
    cin>>n>>x;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        cnt[a[i]]++;
    }
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        int  val = a[i]^x;
        if(cnt[val]>0) ans+=cnt[val];
    }
    cout<<ans/2<<endl;
    return 0;
}


// Bismillahir Rahmanir Rahim .Ya Allah...
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;
typedef pair<int,int> PII;
const int mod = 1e9+7,INF = 1e9;
const int mx = 1e5+5;
int cnt[mx];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,x;
    cin>>n>>x;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        cnt[a[i]]++;
    }
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        ll  val = a[i]^x;
        if(val<=mx&& cnt[val]>0) ans+=cnt[val];
    }
    cout<<ans/2<<endl;
    return 0;
}


// Bismillahir Rahmanir Rahim .Ya Allah...
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;
typedef pair<int,int> PII;
const int mod = 1e9+7,INF = 1e9;
const int mx = 1e6+5;
ll cnt[mx];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll  n,x;
    cin>>n>>x;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        cnt[a[i]]++;
    }
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        int  val = a[i]^x;
        if(cnt[val]>0) ans+=cnt[val];
    }
    if(x==0)ans-=n;
    cout<<ans/2<<endl;
    return 0;
}


// Bismillahir Rahmanir Rahim .Ya Allah...
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;
typedef pair<int,int> PII;
const int mod = 1e9+7,INF = 1e9;
const int mx = 1e6+5;
ll cnt[mx];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll  n,x;
    cin>>n>>x;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        cnt[a[i]]++;
    }
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        int  val = a[i]^x;
        if(cnt[val]>0) ans+=cnt[val];
    }
    cout<<ans/2<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WAENINGS
#define Mapogo ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
typedef long long ll;
#define sortt(a) sort(a.begin(),a.end())
#define r(i,x,n) (ll i=x;i<n;i++)
#define i(n) (int i=0;i<n;i++)
#define j(n) (int j=0;j<n;j++)
#define yes cout<<"yes\n"
#define no cout<<"no\n"
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
#define endl "\n"
#define Pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
using namespace std;
//============== GCD ==================//
//long long gcd(long long a, long long b)
//{
//	if (b == 0)
//		return a;
//	return gcd(b, a % b);
//}
//============== LCM ================       ==//
//int lcm(int a, int b)
//{
//    return (a * b) / gcd(a, b);
//}
//============ Plaindrome =============//
//bool plaindrome(string s) {
//	for (int i = 0, j = s.size() - 1; i < s.size() / 2; i++, j--) {
//		if (s[i] != s[j])
//			return false;
//	}
//	return true;
//}
//============ in/out file ============//
//void file() {
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt","w",stdout);
//}
//============== Prime ===============//
//bool prime(ll n) {
//	if (n == 1)return false;
//	if (n == 2)return true;
//	for (ll i = 2; i*i <= n; i++)
//        if (n % i == 0) return false;
//	return true;
//}
//bool oneway(ll x1, ll y1, ll x2, ll y2, ll x3, ll y3) {
//	ll a = x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2);
//	if (a == 0)return true;
//	return false;
//}
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
int main()
{
	Mapogo;
	int n, x;
	cin >> n >> x;
	map <int, int> m;
	vector <int> v;
	for i(n) {
		int a;
		cin >> a;
		if (m[a] == 0) v.push_back(a);
		m[a]++;
	}
	ll ans = 0;
	if (x == 0) {
		for (auto i : m) {
			ll num = i.second;
			ans += num * (num - 1);
		}
		ans /= 2;
		return cout << ans, 0;
	}
	for i(v.size()) {
		/*for r(j, i + 1, v.size()) {
			if ((v[i] ^ v[j]) == x) {
				ans += m[v[i]] * m[v[j]];
			}
		}*/
		if (m[(v[i] ^ x)] >= 1) {
			ans += m[v[i]] * m[(v[i] ^ x)];
		}
	}
	ans /= 2;
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WAENINGS
#define Mapogo ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
typedef long long ll;
#define sortt(a) sort(a.begin(),a.end())
#define r(i,x,n) (ll i=x;i<n;i++)
#define i(n) (int i=0;i<n;i++)
#define j(n) (int j=0;j<n;j++)
#define yes cout<<"yes\n"
#define no cout<<"no\n"
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
#define endl "\n"
#define Pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
using namespace std;
//============== GCD ==================//
//long long gcd(long long a, long long b)
//{
//	if (b == 0)
//		return a;
//	return gcd(b, a % b);
//}
//============== LCM ================       ==//
//int lcm(int a, int b)
//{
//    return (a * b) / gcd(a, b);
//}
//============ Plaindrome =============//
//bool plaindrome(string s) {
//	for (int i = 0, j = s.size() - 1; i < s.size() / 2; i++, j--) {
//		if (s[i] != s[j])
//			return false;
//	}
//	return true;
//}
//============ in/out file ============//
//void file() {
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt","w",stdout);
//}
//============== Prime ===============//
//bool prime(ll n) {
//	if (n == 1)return false;
//	if (n == 2)return true;
//	for (ll i = 2; i*i <= n; i++)
//        if (n % i == 0) return false;
//	return true;
//}
//bool oneway(ll x1, ll y1, ll x2, ll y2, ll x3, ll y3) {
//	ll a = x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2);
//	if (a == 0)return true;
//	return false;
//}
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
int main()
{
	Mapogo;
	int n, x;
	cin >> n >> x;
	map <int, int> m;
	vector <int> v;
	for i(n) {
		int a;
		cin >> a;
		if (m[a] == 0) v.push_back(a);
		m[a]++;
	}
	ll ans = 0;
	if (x == 0) {
		for (auto i : m) {
			ll num = i.second;
			ans += num * (num - 1);
		}
		return cout << ans, 0;
	}
	for i(v.size()) {
		for r(j, i + 1, v.size()) {
			if ((v[i] ^ v[j]) == x) {
				ans += m[v[i]] * m[v[j]];
			}
		}
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WAENINGS
#define Mapogo ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
typedef long long ll;
#define sortt(a) sort(a.begin(),a.end())
#define r(i,x,n) (ll i=x;i<n;i++)
#define i(n) (int i=0;i<n;i++)
#define j(n) (int j=0;j<n;j++)
#define yes cout<<"yes\n"
#define no cout<<"no\n"
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
#define endl "\n"
#define Pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
using namespace std;
//============== GCD ==================//
//long long gcd(long long a, long long b)
//{
//	if (b == 0)
//		return a;
//	return gcd(b, a % b);
//}
//============== LCM ================       ==//
//int lcm(int a, int b)
//{
//    return (a * b) / gcd(a, b);
//}
//============ Plaindrome =============//
//bool plaindrome(string s) {
//	for (int i = 0, j = s.size() - 1; i < s.size() / 2; i++, j--) {
//		if (s[i] != s[j])
//			return false;
//	}
//	return true;
//}
//============ in/out file ============//
//void file() {
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt","w",stdout);
//}
//============== Prime ===============//
//bool prime(ll n) {
//	if (n == 1)return false;
//	if (n == 2)return true;
//	for (ll i = 2; i*i <= n; i++)
//        if (n % i == 0) return false;
//	return true;
//}
//bool oneway(ll x1, ll y1, ll x2, ll y2, ll x3, ll y3) {
//	ll a = x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2);
//	if (a == 0)return true;
//	return false;
//}
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
int main()
{
	Mapogo;
	int n, x;
	cin >> n >> x;
	map <int, int> m;
	vector <int> v;
	for i(n) {
		int a;
		cin >> a;
		v.push_back(a);
		m[a]++;
	}
	ll ans = 0;
	for i(v.size()) {
		if (m[(v[i] ^ x)] >= 1) {
			/*cout << m[v[i]] << " " << m[(v[i] ^ x)] << endl;*/
			ans += m[(v[i] ^ x)];
			if ((v[i] ^ x) == v[i])ans--;
			m[v[i]]--;
			/*m[(v[i] ^ x)]--;*/
		}
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WAENINGS
#define Mapogo ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
typedef long long ll;
#define sortt(a) sort(a.begin(),a.end())
#define r(i,x,n) (ll i=x;i<n;i++)
#define i(n) (int i=0;i<n;i++)
#define j(n) (int j=0;j<n;j++)
#define yes cout<<"yes\n"
#define no cout<<"no\n"
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
#define endl "\n"
#define Pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
using namespace std;
//============== GCD ==================//
//long long gcd(long long a, long long b)
//{
//	if (b == 0)
//		return a;
//	return gcd(b, a % b);
//}
//============== LCM ================       ==//
//int lcm(int a, int b)
//{
//    return (a * b) / gcd(a, b);
//}
//============ Plaindrome =============//
//bool plaindrome(string s) {
//	for (int i = 0, j = s.size() - 1; i < s.size() / 2; i++, j--) {
//		if (s[i] != s[j])
//			return false;
//	}
//	return true;
//}
//============ in/out file ============//
//void file() {
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt","w",stdout);
//}
//============== Prime ===============//
//bool prime(ll n) {
//	if (n == 1)return false;
//	if (n == 2)return true;
//	for (ll i = 2; i*i <= n; i++)
//        if (n % i == 0) return false;
//	return true;
//}
//bool oneway(ll x1, ll y1, ll x2, ll y2, ll x3, ll y3) {
//	ll a = x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2);
//	if (a == 0)return true;
//	return false;
//}
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
int main()
{
	Mapogo;
	int n, x;
	cin >> n >> x;
	map <int, int> m;
	vector <int> v;
	for i(n) {
		int a;
		cin >> a;
		if (m[a] == 0) v.push_back(a);
		m[a]++;
	}
	ll ans = 0;
	if (x == 0) {
		for (auto i : m) {
			ll num = i.second;
			ans += num * (num - 1);
		}
		ans /= 2;
		return cout << ans, 0;
	}
	for i(v.size()) {
		/*for r(j, i + 1, v.size()) {
			if ((v[i] ^ v[j]) == x) {
				ans += m[v[i]] * m[v[j]];
			}
		}*/
		if (m[(v[i] ^ x)] >= 1) {
			ll f = m[v[i]], s = m[(v[i] ^ x)];
			f = f * s;
			ans += s;
		}
	}
	ans /= 2;
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WAENINGS
#define Mapogo ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
typedef long long ll;
#define sortt(a) sort(a.begin(),a.end())
#define r(i,x,n) (ll i=x;i<n;i++)
#define i(n) (int i=0;i<n;i++)
#define j(n) (int j=0;j<n;j++)
#define yes cout<<"yes\n"
#define no cout<<"no\n"
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
#define endl "\n"
#define Pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
using namespace std;
//============== GCD ==================//
//long long gcd(long long a, long long b)
//{
//	if (b == 0)
//		return a;
//	return gcd(b, a % b);
//}
//============== LCM ================       ==//
//int lcm(int a, int b)
//{
//    return (a * b) / gcd(a, b);
//}
//============ Plaindrome =============//
//bool plaindrome(string s) {
//	for (int i = 0, j = s.size() - 1; i < s.size() / 2; i++, j--) {
//		if (s[i] != s[j])
//			return false;
//	}
//	return true;
//}
//============ in/out file ============//
//void file() {
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt","w",stdout);
//}
//============== Prime ===============//
//bool prime(ll n) {
//	if (n == 1)return false;
//	if (n == 2)return true;
//	for (ll i = 2; i*i <= n; i++)
//        if (n % i == 0) return false;
//	return true;
//}
//bool oneway(ll x1, ll y1, ll x2, ll y2, ll x3, ll y3) {
//	ll a = x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2);
//	if (a == 0)return true;
//	return false;
//}
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
int main()
{
	Mapogo;
	int n, x;
	cin >> n >> x;
	map <int, int> m;
	vector <int> v;
	for i(n) {
		int a;
		cin >> a;
		if (m[a] == 0) v.push_back(a);
		m[a]++;
	}
	ll ans = 0;
	if (x == 0) {
		for (auto i : m) {
			ans += i.second - 1;
		}
		return cout << ans, 0;
	}
	for i(v.size()) {
		for r(j, i + 1, v.size()) {
			if ((v[i] ^ v[j]) == x) {
				ans += m[v[i]] * m[v[j]];
			}
		}
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WAENINGS
#define Mapogo ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
typedef long long ll;
#define sortt(a) sort(a.begin(),a.end())
#define r(i,x,n) (ll i=x;i<n;i++)
#define i(n) (int i=0;i<n;i++)
#define j(n) (int j=0;j<n;j++)
#define yes cout<<"yes\n"
#define no cout<<"no\n"
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
#define endl "\n"
#define Pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
using namespace std;
//============== GCD ==================//
//long long gcd(long long a, long long b)
//{
//	if (b == 0)
//		return a;
//	return gcd(b, a % b);
//}
//============== LCM ================       ==//
//int lcm(int a, int b)
//{
//    return (a * b) / gcd(a, b);
//}
//============ Plaindrome =============//
//bool plaindrome(string s) {
//	for (int i = 0, j = s.size() - 1; i < s.size() / 2; i++, j--) {
//		if (s[i] != s[j])
//			return false;
//	}
//	return true;
//}
//============ in/out file ============//
//void file() {
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt","w",stdout);
//}
//============== Prime ===============//
//bool prime(ll n) {
//	if (n == 1)return false;
//	if (n == 2)return true;
//	for (ll i = 2; i*i <= n; i++)
//        if (n % i == 0) return false;
//	return true;
//}
//bool oneway(ll x1, ll y1, ll x2, ll y2, ll x3, ll y3) {
//	ll a = x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2);
//	if (a == 0)return true;
//	return false;
//}
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
int main()
{
	Mapogo;
	int n, x;
	cin >> n >> x;
	map <int, int> m;
	vector <int> v;
	for i(n) {
		int a;
		cin >> a;
		if (m[a] == 0) v.push_back(a);
		m[a]++;
	}
	ll ans = 0;
	if (x == 0) {
		for (auto i : m) {
			ll num = i.second;
			ans += num * (num - 1);
		}
		ans /= 2;
		return cout << ans, 0;
	}
	for i(v.size()) {
		for r(j, i + 1, v.size()) {
			if ((v[i] ^ v[j]) == x) {
				ans += m[v[i]] * m[v[j]];
			}
		}
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WAENINGS
#define Mapogo ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
typedef long long ll;
#define sortt(a) sort(a.begin(),a.end())
#define r(i,x,n) (ll i=x;i<n;i++)
#define i(n) (int i=0;i<n;i++)
#define j(n) (int j=0;j<n;j++)
#define yes cout<<"yes\n"
#define no cout<<"no\n"
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
#define endl "\n"
#define Pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
using namespace std;
//============== GCD ==================//
//long long gcd(long long a, long long b)
//{
//	if (b == 0)
//		return a;
//	return gcd(b, a % b);
//}
//============== LCM ================       ==//
//int lcm(int a, int b)
//{
//    return (a * b) / gcd(a, b);
//}
//============ Plaindrome =============//
//bool plaindrome(string s) {
//	for (int i = 0, j = s.size() - 1; i < s.size() / 2; i++, j--) {
//		if (s[i] != s[j])
//			return false;
//	}
//	return true;
//}
//============ in/out file ============//
//void file() {
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt","w",stdout);
//}
//============== Prime ===============//
//bool prime(ll n) {
//	if (n == 1)return false;
//	if (n == 2)return true;
//	for (ll i = 2; i*i <= n; i++)
//        if (n % i == 0) return false;
//	return true;
//}
//bool oneway(ll x1, ll y1, ll x2, ll y2, ll x3, ll y3) {
//	ll a = x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2);
//	if (a == 0)return true;
//	return false;
//}
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
int main()
{
	Mapogo;
	int n, x;
	cin >> n >> x;
	map <int, int> m;
	vector <int> v;
	for i(n) {
		int a;
		cin >> a;
		if (m[a] == 0) v.push_back(a);
		m[a]++;
	}
	ll ans = 0;
	if (x == 0) {
		for (auto i : m) {
			ans += i.second * (i.second - 1);
		}
		return cout << ans, 0;
	}
	for i(v.size()) {
		for r(j, i + 1, v.size()) {
			if ((v[i] ^ v[j]) == x) {
				ans += m[v[i]] * m[v[j]];
			}
		}
	}
	cout << ans;
	return 0;
}