ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050B - Transfusion
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>

using namespace std;

void solve(){

    int n;

    cin>>n;

    vector<int>arr(n);

    long long sum =0;

    for(int i=0;i<n;i++){

        cin>>arr[i];

        sum +=arr[i];

    }

    if(n==1){

        cout<<"YES\n";

        return;

    }

    if(n==2){

        if(arr[0]==arr[1]){

            cout<<"YES\n";



        }

        else{

            cout<<"NO\n";

        }

        return ;

    }

    if(sum%n!=0){

        cout<<"NO\n";

        return ;

    }

    bool flag1 = true;

    bool flag2 = true;

    // try to made it from starting

    vector<int>temp = arr;

    long long element = sum/n;

    for(int i=1;i<n-1;i++){

        long long s = arr[i-1]+arr[i+1];

        if(s<element){

            flag1= false;

            break;

        }

        else{

            arr[i+1] = s-element;

        }

    }

    if(arr[n-2]!=element){

        flag1 = false;

    }

    if(flag1){

        cout<<"YES\n";

        return ;

    }

    for(int i=n-2;i>0;i--){

        long long s = temp[i+1]+temp[i-1];

        if(s<element){

            flag2 =false;

            break;

        }

        else{

            temp[i-1] = s-element;

        }

    }

    if(temp[0]!=element){

        flag2= false;

    }

    if(flag1|| flag2){

        cout<<"YES\n";

    }

    else{

        cout<<"NO\n";

    }





    

}



int main(){

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    

    int t;

    cin >> t;

    while (t--) solve();

}

Submission (verdict: Accepted):
#include<bits/stdc++.h>

using namespace std;

void solve(){

    int n;

    cin>>n;

    long long odd_sum =0;

    long long even_sum =0;

    long long c1=0,c2=0;

    for(int i=1;i<=n;i++){

        long long x;cin>>x;

        if(i&1){

            odd_sum+=x;

            c1++;

        }

        else{

            even_sum +=x;

            c2++;

        }

    }

    if(odd_sum%c1==0 && even_sum%c2==0){

        if(odd_sum/c1 == even_sum/c2){

            cout<<"YES\n";

        }

        else{

            cout<<"NO\n";

        }

    }

    else{

        cout<<"NO\n";

    }

    

}



int main(){

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    

    int t;

    cin >> t;

    while (t--) solve();

}
Problem: 2050B - Transfusion
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>

using namespace std;

void solve(){

    int n;

    cin>>n;

    vector<int>arr(n);

    long long sum =0;

    for(int i=0;i<n;i++){

        cin>>arr[i];

        sum +=arr[i];

    }

    if(n==1){

        cout<<"YES\n";

        return;

    }

    if(n==2){

        if(arr[0]==arr[1]){

            cout<<"YES\n";



        }

        else{

            cout<<"NO\n";

        }

        return ;

    }

    if(sum%n!=0){

        cout<<"NO\n";

        return ;

    }

    bool flag1 = true;

    bool flag2 = true;

    // try to made it from starting

    vector<int>temp = arr;

    long long element = sum/n;

    for(int i=1;i<n-1;i++){

        long long s = arr[i-1]+arr[i+1];

        if(s<element){

            flag1= false;

            break;

        }

        else{

            arr[i+1] = s-element;

        }

    }

    if(arr[n-2]!=element){

        flag1 = false;

    }

    if(flag1){

        cout<<"YES\n";

        return ;

    }

    for(int i=n-2;i>0;i--){

        long long s = temp[i+1]+temp[i-1];

        if(s<element){

            flag2 =false;

            break;

        }

        else{

            temp[i+1] = s-element;

        }

    }

    if(temp[0]!=element){

        flag2= false;

    }

    if(flag1|| flag2){

        cout<<"YES\n";

    }

    else{

        cout<<"NO\n";

    }





    

}



int main(){

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    

    int t;

    cin >> t;

    while (t--) solve();

}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>
#define ll long long
using namespace std;

vector<bool> digitchanges(9);
 //track the digits already searched

bool searchchanges(int curmod9, int remaining2s, int remaining3s){
    if(curmod9 == 0){
        return true;
    }
    // 1 2 3 4 5 6 7 8 0
    /*
    if(digitchanges[curmod9] == true){
        cout << curmod9 << "\n";
        return false;
    }
    */
    if(remaining2s == 0 && remaining3s == 0){
       // cout << remaining2s << " " << remaining3s << "\n";
        return false;
    }
    digitchanges[curmod9] = true;
    bool true2 = false;
    bool true3 = false;
    if(remaining2s > 0){
        int newmod9 = (2 + curmod9) % 9;
        true2 = searchchanges(newmod9, remaining2s-1, remaining3s);
    }
    if(remaining3s > 0){
        int newmod9 = (6+curmod9) % 9;
        true3 = searchchanges(newmod9, remaining2s, remaining3s-1);
    }
    if(true2 == true || true3 == true){
        return true;
    }
    return false;
}

void solve() {
    int n[2]; //only store twos and threes
    n[0] = 0; //count of 2s
    n[1] = 0; //count of 3s
    int totalmod9 = 0;
    string s;
    cin >> s;
    int len = s.length();
    for(int i = 0; i < len; i++){
        if(s[i] == '3'){
            n[1]++;
        }
        if(s[i] == '2'){
            n[0]++;
        }
        int digit = s[i] - '0';
        totalmod9 += digit;
        totalmod9 = totalmod9 % 9;
    }
    
    if(n[0] > 10){
        cout << "YES";
    } else if(n[0]>5&&n[1]>5){
        cout << "YES";
    }else if(searchchanges(totalmod9, n[0], n[1]) == true){
        cout << "YES";
    } else{
        cout << "NO";
    }
    return;
}

int main() {
    int TESTS; cin >> TESTS;
    while (TESTS --> 0) {
        solve();
        cout << '\n';
    }
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;

  if (n == 1) {
    cout << 0 << "\n";
    return 0;
  }

  vector<int> racers(n);
  for (int i = 0; i < n; ++i) {
    cin >> racers[i];
  }

  vector<pair<int, int>> results;
  for (int i = 0; i < n-1; ++i) {
    if (racers[i+1] > racers[i]) {
      results.push_back({racers[i], racers[i+1]});
      results.push_back({racers[i+1], racers[i]});
    }
  }

  bool flag = false;
  while (flag == false) {
    flag = true;
    for (int i = 0; i < n-1; ++i) {
      if (racers[i+1] < racers[i]) {
        iter_swap(racers.begin() + i, racers.begin() + i+1);
        results.push_back({racers[i+1], racers[i]});
        flag = false;
      }
    }
  }

  cout << results.size();
  for (auto it = results.rbegin(); it != results.rend(); ++it) {
    cout << it->first << " " << it->second << "\n";
  }
}


Submission (verdict: Wrong answer on test 4):
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;

  if (n == 1) {
    cout << 0 << "\n";
    return 0;
  }

  vector<int> racers(n);
  for (int i = 0; i < n; ++i) {
    cin >> racers[i];
  }

  vector<pair<int, int>> results;
  for (int i = 0; i < n-1; ++i) {
    if (racers[i+1] > racers[i]) {
      results.push_back({racers[i], racers[i+1]});
      results.push_back({racers[i+1], racers[i]});
    }
  }

  bool flag = false;
  while (flag == false) {
    flag = true;
    for (int i = 0; i < n-1; ++i) {
      if (racers[i+1] < racers[i]) {
        iter_swap(racers.begin() + i, racers.begin() + i+1);
        results.push_back({racers[i+1], racers[i]});
        flag = false;
      }
    }
  }

  cout << results.size() << "\n";
  for (auto it = results.rbegin(); it != results.rend(); ++it) {
    cout << it->first << " " << it->second << "\n";
  }
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;

  if (n == 1) {
    cout << 0 << "\n";
    return 0;
  }

  vector<int> racers(n);
  for (int i = 0; i < n; ++i) {
    cin >> racers[i];
  }

  vector<pair<int, int>> results;
  for (int i = 0; i < n-1; ++i) {
    if (racers[i+1] > racers[i]) {
      results.push_back({racers[i], racers[i+1]});
      results.push_back({racers[i+1], racers[i]});
    }
  }

  bool flag = false;
  while (flag == false) {
    flag = true;
    for (int i = 0; i < n-1; ++i) {
      if (racers[i+1] < racers[i]) {
        iter_swap(racers.begin() + i, racers.begin() + i+1);
        results.push_back({racers[i+1], racers[i]});
        flag = false;
      }
    }
  }

  cout << results.size();
  for (auto it = results.rbegin(); it != results.rend(); ++it) {
    cout << it->first << " " << it->second << "\n";
  }
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 4):
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;

  if (n == 1) {
    cout << 0 << "\n";
    return 0;
  }

  vector<int> racers(n);
  for (int i = 0; i < n; ++i) {
    cin >> racers[i];
  }

  vector<pair<int, int>> results;
  for (int i = 0; i < n-1; ++i) {
    if (racers[i+1] > racers[i]) {
      results.push_back({racers[i], racers[i+1]});
      results.push_back({racers[i+1], racers[i]});
    }
  }

  bool flag = false;
  while (flag == false) {
    flag = true;
    for (int i = 0; i < n-1; ++i) {
      if (racers[i+1] < racers[i]) {
        iter_swap(racers.begin() + i, racers.begin() + i+1);
        results.push_back({racers[i+1], racers[i]});
        flag = false;
      }
    }
  }

  cout << results.size() << "\n";
  for (auto it = results.rbegin(); it != results.rend(); ++it) {
    cout << it->first << " " << it->second << "\n";
  }
}


Submission (verdict: Accepted):
#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;

  if (n == 1) {
    cout << 0 << "\n";
    return 0;
  }

  vector<int> racers(n);
  for (int i = 0; i < n; ++i) {
    cin >> racers[i];
  }

  reverse(racers.begin(), racers.end());
  vector<int> sim(n);
  for (int i = 0; i < n; ++i) {
    sim[i] = n-i;
  }

  vector<pair<int, int>> overtakes;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n-1; ++j) {
      if (sim[j] == racers[i]) {
        overtakes.push_back({sim[j], sim[j+1]});
        swap(sim[j], sim[j+1]);
      }
    }

    for (int j = n-1; j > i; --j) {
      overtakes.push_back({sim[j-1], sim[j]});
      swap(sim[j-1], sim[j]);
    }
  }

  cout << overtakes.size() << "\n";
  for (auto &[a, b] : overtakes) {
    cout << a << " " << b << "\n";
  }
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using  namespace std;

void solve() {
    long long n;
    cin >> n;
    vector<long long> a(n);
    for (long long i = 0;i <n ; i++) {cin >> a[i];}
    if (n == 1){ cout << a[0] << endl; return; }

    long long sum1 = 0;
    long long ans = 0;

    for (long long i = 0; i<n ; i++) {ans += a[i];}

    long long start = 0;
    long long len = n;
    while (len > 0) {
        for (long long j = n-1; j >= start+1; j--) {
            a[j] -= a[j-1];
        }
        sum1 = 0;
        for (long long i = start; i<n ; i++) {sum1 += a[i];}
        ans = max(ans, abs(sum1));
        start++; len--;
    }
    // ans = max(abs(a[start] - a[start+1]), max(abs(a[start+1] - a[start]) , sum1));
    cout << ans << endl;
}

int main() {
    long long t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using  namespace std;

void solve() {
    long long n;
    cin >> n;
    vector<long long> a(n);
    for (long long i = 0;i <n ; i++) {cin >> a[i];}
    if (n == 1){ cout << a[0] << endl; return; }

    long long sum1 = 0;
    long long ans = 0;

    for (long long i = 0; i<n ; i++) {ans += a[i];}

    long long start = 0;
    long long len = n;
    while (len > 1) {
        for (long long j = n-1; j >= start+1; j--) {
            a[j] -= a[j-1];
        }
        sum1 = 0;
        start++;
        for (long long i = start; i<n ; i++) {sum1 += a[i];}
        ans = max(ans, abs(sum1));
         len--;
    }
    // ans = max(abs(a[start] - a[start+1]), max(abs(a[start+1] - a[start]) , sum1));
    cout << ans << endl;
}

int main() {
    long long t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using  namespace std;

void solve() {
    long long n;
    cin >> n;
    vector<long long> a(n);
    for (long long i = 0;i <n ; i++) {cin >> a[i];}
    if (n == 1){ cout << a[0] << endl; return; }

    long long sum1 = 0;
    for (long long i = 0; i<n ; i++) {sum1 += a[i];}

    long long start = 0;
    long long len = n;
    long long ans = 0;
    while (len > 2) {
        for (long long j = n-1; j >= start+1; j--) {
            a[j] -= a[j-1];
        } start++; len--;
    }
    ans = max(a[start] - a[start+1], max(a[start+1] - a[start] , sum1));
    cout << ans << endl;
}

int main() {
    long long t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using  namespace std;

void solve() {
    long long n;
    cin >> n;
    vector<long long> a(n);
    for (long long i = 0;i <n ; i++) {cin >> a[i];}
    if (n == 1){ cout << a[0] << endl; return; }

    long long sum1 = 0;
    for (long long i = 0; i<n ; i++) {sum1 += a[i];}

    long long start = 0;
    long long len = n;
    long long ans = 0;
    while (len > 2) {
        for (long long j = n-1; j >= start+1; j--) {
            a[j] -= a[j-1];
        } start++; len--;
    }
    ans = max(abs(a[start] - a[start+1]), max(abs(a[start+1] - a[start]) , sum1));
    cout << ans << endl;
}

int main() {
    long long t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using  namespace std;

void solve() {
    long long n;
    cin >> n;
    vector<long long> a(n);
    for (long long i = 0;i <n ; i++) {cin >> a[i];}
    if (n == 1){ cout << a[0] << endl; return; }

    long long sum1 = 0;
    for (long long i = 0; i<n ; i++) {sum1 += a[i];}

    long long start = 0;
    long long len = n;
    long long ans = 0;
    while (len > 2) {
        for (long long j = n-1; j >= start+1; j--) {
            a[j] -= a[j-1];
        } start++; len--;
    }
    ans = max(abs(a[start] - a[start+1]), max(abs(a[start+1] - a[start]) , sum1));
    cout << ans << endl;
}

int main() {
    long long t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using  namespace std;

void solve() {
    long long n;
    cin >> n;
    vector<long long> a(n);
    for (long long i = 0;i <n ; i++) {cin >> a[i];}
    if (n == 1){ cout << a[0] << endl; return; }

    long long sum1 = 0;
    long long ans = 0;

    for (long long i = 0; i<n ; i++) {ans += a[i];}

    long long start = 0;
    long long len = n;
    while (len > 0) {
        for (long long j = n-1; j >= start+1; j--) {
            a[j] -= a[j-1];
        }
        sum1 = 0;
        for (long long i = start; i<n ; i++) {sum1 += a[i];}
        ans = max(ans, abs(sum1));
        start++; len--;
    }
    // ans = max(abs(a[start] - a[start+1]), max(abs(a[start+1] - a[start]) , sum1));
    cout << ans << endl;
}

int main() {
    long long t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using  namespace std;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0;i <n ; i++) {cin >> a[i];}
    if (n == 1){ cout << a[0] << endl; return; }

    int sum1 = 0;
    for (int i = 0; i<n ; i++) {sum1 += a[i];}

    int start = 0;
    int len = n;
    int ans = 0;
    while (len > 2) {
        for (int j = n-1; j >= start+1; j--) {
            a[j] -= a[j-1];
        } start++; len--;
    }
    ans = max(a[start] - a[start+1], max(a[start+1] - a[start] , sum1));
    cout << ans << endl;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using  namespace std;

void solve() {
    long long n;
    cin >> n;
    vector<long long> a(n);
    for (long long i = 0;i <n ; i++) {cin >> a[i];}
    if (n == 1){ cout << a[0] << endl; return; }

    long long sum1 = 0;
    for (long long i = 0; i<n ; i++) {sum1 += a[i];}

    long long start = 0;
    long long len = n;
    long long ans = 0;
    while (len > 2) {
        for (long long j = n-1; j >= start+1; j--) {
            a[j] -= a[j-1];
        } start++; len--;
    }
    ans = max(a[start] - a[start+1], max(a[start+1] - a[start] , sum1));
    cout << ans << endl;
}

int main() {
    long long t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using  namespace std;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0;i <n ; i++) {cin >> a[i];}
    if (n == 1){ cout << a[0] << endl; return; }

    int sum1 = 0;
    for (int i = 0; i<n ; i++) {sum1 += a[i];}

    int start = 0;
    int len = n;
    int ans = 0;
    while (len > 2) {
        for (int j = n-1; j >= start+1; j--) {
            a[j] -= a[j-1];
        } start++; len--;
    }
    ans = max(a[start] - a[start+1], max(a[start+1] - a[start] , sum1));
    cout << ans << endl;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 8):
#include <bits/stdc++.h>
using namespace std;

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n, l, r;
        cin >> n >> l >> r;
        vector<int> a(n);
        for (int i = 0; i < n; i++) cin >> a[i];

        vector<int> b = a, c = a;
        sort(b.begin() + l - 1, b.end());
        sort(c.begin(), c.begin() + r, greater<int>());

        int sum_b = accumulate(b.begin() + l - 1, b.begin() + r, 0);
        int sum_c = accumulate(c.begin() + l - 1, c.begin() + r, 0);

        cout << min(sum_b, sum_c) << endl;
    }
    return 0;
}


Submission (verdict: Wrong answer on test 8):
#include <bits/stdc++.h>
using namespace std;

int main() {
    long long  t;
    cin >> t;
    while (t--) {
        long long n, l, r;
        cin >> n >> l >> r;
        vector<long long> a(n);
        for (long long i = 0; i < n; i++) cin >> a[i];

        vector<long long> b = a, c = a;
        sort(b.begin() + l - 1, b.end());
        sort(c.begin(), c.begin() + r, greater<long long>());

        long long sum_b = accumulate(b.begin() + l - 1, b.begin() + r, 0);
        long long sum_c = accumulate(c.begin() + l - 1, c.begin() + r, 0);

        cout << min(sum_b, sum_c) << endl;
    }
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 8):
#include <bits/stdc++.h>
using namespace std;

int main() {
    long long  t;
    cin >> t;
    while (t--) {
        long long n, l, r;
        cin >> n >> l >> r;
        vector<long long> a(n);
        for (long long i = 0; i < n; i++) cin >> a[i];

        vector<long long> b = a, c = a;
        sort(b.begin() + l - 1, b.end());
        sort(c.begin(), c.begin() + r, greater<long long>());

        long long sum_b = accumulate(b.begin() + l - 1, b.begin() + r, 0);
        long long sum_c = accumulate(c.begin() + l - 1, c.begin() + r, 0);

        cout << min(sum_b, sum_c) << endl;
    }
    return 0;
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;

int main() {
    long long  t;
    cin >> t;
    while (t--) {
        long long n, l, r;
        cin >> n >> l >> r;
        vector<long long> a(n);
        for (long long i = 0; i < n; i++) cin >> a[i];

        vector<long long> b = a, c = a;
        sort(b.begin() + l - 1, b.end());
        sort(c.begin(), c.begin() + r, greater<long long>());

        long long sum_b = accumulate(b.begin() + l - 1, b.begin() + r, 0ll);
        long long sum_c = accumulate(c.begin() + l - 1, c.begin() + r, 0ll);

        cout << min(sum_b, sum_c) << endl;
    }
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 8):
#include <bits/stdc++.h>
using namespace std;

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n, l, r;
        cin >> n >> l >> r;
        vector<int> a(n);
        for (int i = 0; i < n; i++) cin >> a[i];

        vector<int> b = a, c = a;
        sort(b.begin() + l - 1, b.end());
        sort(c.begin(), c.begin() + r, greater<int>());

        int sum_b = accumulate(b.begin() + l - 1, b.begin() + r, 0);
        int sum_c = accumulate(c.begin() + l - 1, c.begin() + r, 0);

        cout << min(sum_b, sum_c) << endl;
    }
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: PyPy 3-64


Submission (verdict: Wrong answer on test 1):

t = int(input())

for x in range(t):
    n = int(input())
    edges = []
    adj_list = []

    for y in range(n+1):
        adj_list.append([])

    for e in range(n-1):
        a,b = list(map(int, input().split(" ")))
        
        adj_list[a].append(b)
        adj_list[b].append(a)


    for i in range(2):
        most_edges = 0
        most_edges_node = 1
        for node in range(1, n+1):
            if adj_list[node] != None:
                if len(adj_list[node]) >= most_edges:
                    most_edges = len(adj_list[node])
                    most_edges_node = node

        for node in adj_list[most_edges_node]:
            adj_list[node].remove(most_edges_node)

        adj_list[most_edges_node] = None

    count_cc = 0
    connected = {}
    v = 1
    for node in range(1, n+1):
        print(node, adj_list[node])
        if adj_list[node] != None and not node in connected:
            queue = [node]

            while len(queue) > 0:
                curr = queue.pop()
                connected[curr] = count_cc
                for adj_node in adj_list[curr]:
                    if not adj_node in connected:
                        queue.append(adj_node)
                        connected[adj_node] = count_cc

            count_cc += 1

    print(count_cc)