ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2052A - Adrenaline Rush
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 4):
from sys import stdin

input = lambda: stdin.readline().strip()



n = int(input())

a = list(map(int, input().split()))

cur = list(range(1, n + 1))

pos = list(range(-1, n))

ans = []

vis = set()



for r in range(n - 1, -1, -1):

    p = pos[a[r]]

    fl = False

    for i in range(p + 1, r + 1):

        # print("swap",i - 1, i)

        ans.append((cur[i], cur[i - 1]))

        vis.add((cur[i], cur[i - 1]))

        pos[cur[i - 1]], pos[cur[i]] = pos[cur[i]], pos[cur[i - 1]]

        cur[i - 1], cur[i] = cur[i], cur[i - 1]

    if p + 1 < n:

        if ((cur[p + 1], cur[p]) in vis) or ((cur[p], cur[p + 1]) in vis):

            continue

        ans.append((cur[p + 1], cur[p]))

        ans.append((cur[p], cur[p + 1]))

        vis.add((cur[p + 1], cur[p]))

        vis.add((cur[p], cur[p + 1]))



    # print(pos)



print(len(ans))

for x, y in ans:

    print(f'{x} {y}')

Submission (verdict: Accepted):
from sys import stdin

input = lambda: stdin.readline().strip()



n = int(input())

a = list(map(int, input().split()))

ans = []



for _ in range(n):

    for i in range(n - 1):

        if a[i] < a[i + 1]:

            ans.append((a[i], a[i + 1]))

            a[i], a[i + 1] = a[i + 1], a[i]

for _ in range(n):

    for i in range(n - 1):

        if a[i] > a[i + 1]:

            ans.append((a[i], a[i + 1]))

            a[i], a[i + 1] = a[i + 1], a[i]

ans.reverse()

print(len(ans))

for x, y in ans:

    print(f'{x} {y}')
Problem: 2052A - Adrenaline Rush
Language: PyPy 3-64


Submission (verdict: Wrong answer on test 4):
from sys import stdin

input = lambda: stdin.readline().strip()



n = int(input())

a = list(map(int, input().split()))

cur = list(range(1, n + 1))

pos = list(range(-1, n))

ans = []



for r in range(n - 1, -1, -1):

    p = pos[a[r]]

    fl = False

    for i in range(p + 1, r + 1):

        # print("swap",i - 1, i)

        fl = True

        ans.append((cur[i], cur[i - 1]))

        pos[cur[i - 1]], pos[cur[i]] = pos[cur[i]], pos[cur[i - 1]]

        cur[i - 1], cur[i] = cur[i], cur[i - 1]

    if not fl and p + 1 < n:

        if not ans or (ans[-1] != (cur[p + 1], cur[p]) and ans[-1] != (cur[p], cur[p + 1])):

            ans.append((cur[p + 1], cur[p]))

            ans.append((cur[p], cur[p + 1]))

    # print(pos)



print(len(ans))

for x, y in ans:

    print(f'{x} {y}')
Problem: 2052A - Adrenaline Rush
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 4):
from sys import stdin

input = lambda: stdin.readline().strip()



n = int(input())

a = list(map(int, input().split()))

cur = list(range(1, n + 1))

pos = list(range(-1, n))

ans = []



for r in range(n - 1, -1, -1):

    p = pos[a[r]]

    fl = False

    for i in range(p + 1, r + 1):

        # print("swap",i - 1, i)

        fl = True

        ans.append((cur[i], cur[i - 1]))

        pos[cur[i - 1]], pos[cur[i]] = pos[cur[i]], pos[cur[i - 1]]

        cur[i - 1], cur[i] = cur[i], cur[i - 1]

    if not fl and p + 1 < n:

        if not ans or (ans[-1] != (cur[p + 1], cur[p]) and ans[-1] != (cur[p], cur[p + 1])):

            ans.append((cur[p + 1], cur[p]))

            ans.append((cur[p], cur[p + 1]))

    # print(pos)



print(len(ans))

for x, y in ans:

    print(f'{x} {y}')

Submission (verdict: Wrong answer on test 4):
from sys import stdin

input = lambda: stdin.readline().strip()



n = int(input())

a = list(map(int, input().split()))

cur = list(range(1, n + 1))

pos = list(range(-1, n))

ans = []

vis = set()



for r in range(n - 1, -1, -1):

    p = pos[a[r]]

    fl = False

    for i in range(p + 1, r + 1):

        # print("swap",i - 1, i)

        ans.append((cur[i], cur[i - 1]))

        vis.add((cur[i], cur[i - 1]))

        pos[cur[i - 1]], pos[cur[i]] = pos[cur[i]], pos[cur[i - 1]]

        cur[i - 1], cur[i] = cur[i], cur[i - 1]

    if p + 1 < n:

        if ((cur[p + 1], cur[p]) in vis) or ((cur[p], cur[p + 1]) in vis):

            continue

        ans.append((cur[p + 1], cur[p]))

        ans.append((cur[p], cur[p + 1]))

        vis.add((cur[p + 1], cur[p]))

        vis.add((cur[p], cur[p + 1]))



    # print(pos)



print(len(ans))

for x, y in ans:

    print(f'{x} {y}')
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

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



using namespace std;



void solve()

{



int n;

cin>>n;

vector<int> arr(n);



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

cin>>arr[i];

}

int i = 1;



while( i< n){



if( arr[i-1] > arr[i] && i <n-1&& arr[i] > arr[i+1]){

cout<<"No"<<endl;

return;

}

i++;

}



cout<<"Yes"<<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()

{



int n;

cin>>n;

vector<int> arr(n);



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

cin>>arr[i];

}

int i = 1;

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

cout<<"No"<<endl;

return;

}

while( i< n){

if(arr[i-1] > arr[i] && i == n-1) {

cout<<"No"<<endl;

return;

}



if( arr[i-1] > arr[i] && i <n-1&& arr[i] > arr[i+1]){

cout<<"No"<<endl;

return;

}

i++;

}



cout<<"Yes"<<endl;



}



int main()



{

int t;

cin >> t;

while (t--)

{

solve();

}

return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)


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



using namespace std;



void solve()

{



int n;

cin>>n;

vector<int> arr(n);



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

cin>>arr[i];

}

int i = 1;



while( i< n){



if( arr[i-1] > arr[i] && i <n-1&& arr[i] > arr[i+1]){

cout<<"No"<<endl;

return;

}

i++;

}



cout<<"Yes"<<endl;



}



int main()



{

int t;

cin >> t;

while (t--)

{

solve();

}

return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

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



using namespace std;



void solve()

{



int n;

cin>>n;

vector<int> arr(n);



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

cin>>arr[i];

}

int i = 1;

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

cout<<"No"<<endl;

return;

}

while( i< n){

if(arr[i-1] > arr[i] && i == n-1) {

cout<<"No"<<endl;

return;

}



if( arr[i-1] > arr[i] && i <n-1&& arr[i] > arr[i+1]){

cout<<"No"<<endl;

return;

}

i++;

}



cout<<"Yes"<<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()

{



int n;

cin>>n;

vector<int> arr(n);



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

cin>>arr[i];

}

int i = 1;

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

cout<<"No"<<endl;

return;

}

while( i< n){

// if(arr[i-1] > arr[i] && i == n-1) {

//     cout<<"No"<<endl;

//     return;

// }



if( arr[i-1] > arr[i] && i <n-1&& arr[i] > arr[i+1]){

cout<<"No"<<endl;

return;

}

i++;

}



cout<<"Yes"<<endl;



}



int main()



{

int t;

cin >> t;

while (t--)

{

solve();

}

return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

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



using namespace std;



void solve()

{



int n;

cin>>n;

vector<int> arr(n);



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

cin>>arr[i];

}

int i = 1;

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

cout<<"No"<<endl;

return;

}

while( i< n){

// if(arr[i-1] > arr[i] && i == n-1) {

//     cout<<"No"<<endl;

//     return;

// }



if( arr[i-1] > arr[i] && i <n-1&& arr[i] > arr[i+1]){

cout<<"No"<<endl;

return;

}

i++;

}



cout<<"Yes"<<endl;



}



int main()



{

int t;

cin >> t;

while (t--)

{

solve();

}

return 0;

}



Submission (verdict: Accepted):
#include <iostream>

#include <vector>

#include <algorithm>



using namespace std;



typedef long long ll;



void processTestCase() {

ll n;

cin >> n;

vector<ll> numbers(n);



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

cin >> numbers[i];

}



ll breakPoint = 0;

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

if (numbers[i - 1] > numbers[i]) {

breakPoint = i;

}

}



if (breakPoint == 0) {

cout << "YES" << endl;

return;

}



for (ll i = 0; i < breakPoint; i++) {

ll minValue;

if (numbers[i] < numbers[i + 1]) {

minValue = numbers[i];

} else {

minValue = numbers[i + 1];

}

numbers[i] = numbers[i] - minValue;

numbers[i + 1] = numbers[i + 1] - minValue;

}



bool isSorted = true;

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

if (numbers[i - 1] > numbers[i]) {

isSorted = false;

break;

}

}



if (isSorted) {

cout << "YES" << endl;

} else {

cout << "NO" << endl;

}

}



int main() {

ios::sync_with_stdio(false);

cin.tie(nullptr);



ll testCases;

cin >> testCases;



while (testCases > 0) {

processTestCase();

testCases = testCases - 1;

}



return 0;

}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)

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

#define int long long

// DFS function to check the color consistency
bool dfs(map<int, vector<int>>& mpp, int in, int parent, int x, vector<int>& c) {
    bool ans = true;

    for (auto it : mpp[in]) {
        if (it == parent || it == x) 
            continue;
        else 
            ans &= (c[it] == c[in]) & dfs(mpp, it, in, x, c);
    }

    return ans;
}

void testcase() {
    int a,b;
    cin>>a>>b;
    int x=log2(b);
    int y=log2(a);
    int ans=x;
    int a1=pow(2,x);
    int b1=a1-1;
    int c1=0;
    cout<<a1<<" "<<b1<<" "<<a<<endl;
   
}

int32_t main() {
    int t = 1;
cin>>t;
    for (int i = 0; i < t; i++) {
        testcase();
    }

    return 0;
}


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

#define int long long

// DFS function to check the color consistency
bool dfs(map<int, vector<int>>& mpp, int in, int parent, int x, vector<int>& c) {
    bool ans = true;

    for (auto it : mpp[in]) {
        if (it == parent || it == x) 
            continue;
        else 
            ans &= (c[it] == c[in]) & dfs(mpp, it, in, x, c);
    }

    return ans;
}

void testcase() {
    int a,b;
    cin>>a>>b;
    int x=log2(b);
    int y=log2(a);
    int ans=x;
    int a1=pow(2,x);
    int b1=a1-1;
    int c1=0;
    if(a!=b1)
    cout<<a1<<" "<<b1<<" "<<a<<endl;
else
    cout<<a1<<" "<<b1<<" "<<a1+1<<endl;
   
}

int32_t main() {
    int t = 1;
cin>>t;
    for (int i = 0; i < t; i++) {
        testcase();
    }

    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)


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

#define int long long

// DFS function to check the color consistency
bool dfs(map<int, vector<int>>& mpp, int in, int parent, int x, vector<int>& c) {
    bool ans = true;

    for (auto it : mpp[in]) {
        if (it == parent || it == x) 
            continue;
        else 
            ans &= (c[it] == c[in]) & dfs(mpp, it, in, x, c);
    }

    return ans;
}

void testcase() {
    int a,b;
    cin>>a>>b;
    int x=log2(b);
    int y=log2(a);
    int ans=x;
    int a1=pow(2,x);
    int b1=a1-1;
    int c1=0;
    cout<<a1<<" "<<b1<<" "<<a<<endl;
   
}

int32_t main() {
    int t = 1;
cin>>t;
    for (int i = 0; i < t; i++) {
        testcase();
    }

    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)

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

#define int long long

// DFS function to check the color consistency
bool dfs(map<int, vector<int>>& mpp, int in, int parent, int x, vector<int>& c) {
    bool ans = true;

    for (auto it : mpp[in]) {
        if (it == parent || it == x) 
            continue;
        else 
            ans &= (c[it] == c[in]) & dfs(mpp, it, in, x, c);
    }

    return ans;
}

void testcase() {
    int a,b;
    cin>>a>>b;
    int x=log2(b);
    int y=log2(a);
    int ans=x;
    int a1=pow(2,x);
    int b1=a1-1;
    int c1=0;
    if(a!=b1)
    cout<<a1<<" "<<b1<<" "<<a<<endl;
else
    cout<<a1<<" "<<b1<<" "<<a1+1<<endl;
   
}

int32_t main() {
    int t = 1;
cin>>t;
    for (int i = 0; i < t; i++) {
        testcase();
    }

    return 0;
}


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

#define int long long

// DFS function to check the color consistency
bool dfs(map<int, vector<int>>& mpp, int in, int parent, int x, vector<int>& c) {
    bool ans = true;

    for (auto it : mpp[in]) {
        if (it == parent || it == x) 
            continue;
        else 
            ans &= (c[it] == c[in]) & dfs(mpp, it, in, x, c);
    }

    return ans;
}

void testcase() {
    int a,b;
    cin>>a>>b;
    int x=log2(b);
    int y=0;
    if(a>=2)
     y=log2(a);
    int ans=x;
    int a1=pow(2,x);
    int b1=a1-1;
    int c1=0;
    if(a1!=b)
    cout<<a1<<" "<<b1<<" "<<b<<endl;
else
    cout<<a1<<" "<<b1<<" "<<a1-2<<endl;
   
}

int32_t main() {
    int t = 1;
cin>>t;
    for (int i = 0; i < t; i++) {
        testcase();
    }

    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)

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

#define int long long

// DFS function to check the color consistency
bool dfs(map<int, vector<int>>& mpp, int in, int parent, int x, vector<int>& c) {
    bool ans = true;

    for (auto it : mpp[in]) {
        if (it == parent || it == x) 
            continue;
        else 
            ans &= (c[it] == c[in]) & dfs(mpp, it, in, x, c);
    }

    return ans;
}

void testcase() {
    int a,b;
    cin>>a>>b;
    int x=log2(b);
    int y=0;
    if(a>=2)
     y=log2(a);
    int ans=x;
    int a1=pow(2,x);
    int b1=a1-1;
    int c1=0;
    if(a1!=b)
    cout<<a1<<" "<<b1<<" "<<b<<endl;
else
    cout<<a1<<" "<<b1<<" "<<a1-2<<endl;
   
}

int32_t main() {
    int t = 1;
cin>>t;
    for (int i = 0; i < t; i++) {
        testcase();
    }

    return 0;
}


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

#define int long long

// DFS function to check the color consistency
bool dfs(map<int, vector<int>>& mpp, int in, int parent, int x, vector<int>& c) {
    bool ans = true;

    for (auto it : mpp[in]) {
        if (it == parent || it == x) 
            continue;
        else 
            ans &= (c[it] == c[in]) & dfs(mpp, it, in, x, c);
    }

    return ans;
}

void testcase() {
    int L, R;
    cin >> L >> R;
 
    int X = (L ^ R);

    int a = L | (1 << __lg(X)) - 1;
    int b = a + 1;
    int c = (a == L ? R : L);
 
    cout << a << " " << b << " " << c << endl;
   
}

int32_t main() {
    int t = 1;
cin>>t;
    for (int i = 0; i < t; i++) {
        testcase();
    }

    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 2):
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

    while(t --)
    {
        int n,m;

        unordered_map<ll,ll> cnt;
        vector<pair<ll,ll>> s;

        cin >> n >> m;
        int idx = 0;
        for(int i = 0;i<n;i++)
        {
            int a;
            cin >> a;
            if(cnt[a] == 0)
            {
                cnt[a] = idx+1;
                s.push_back({0,a});
                idx ++;
            }
            s[cnt[a] - 1].first ++;
        }

        sort(s.begin(),s.begin()+idx);


        int idx2 = 0;

        int ans = 0;
        while(idx2 < idx && m > 0)
        {
            if(m >= s[idx2].first)
            {
                m -= s[idx2].first;
                s[idx2 ++].first = 0;
            }
        }
        
        for(int i = 0;i<idx;i++)
        {
            if(s[i].first != 0) ans ++;
        }

        cout << max(ans,1) << "\n";

    }
    
    return 0;
}

Submission (verdict: Time limit exceeded on test 2):
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

    while(t --)
    {
        int n,m;

        unordered_map<ll,ll> cnt;
        vector<pair<ll,ll>> s;

        cin >> n >> m;
        int idx = 0;

        for(int i = 0;i<n;i++)
        {
            ll a;
            cin >> a;
            if(cnt[a] == 0)
            {
                cnt[a] = idx+1;
                s.push_back({0,a});
                idx ++;
            }
            s[cnt[a] - 1].first ++;
        }

        sort(s.begin(),s.begin()+idx);


        int idx2 = 0;

        int ans = 0;
        while(idx2 < idx && m > 0)
        {
            if(m >= s[idx2].first)
            {
                m -= s[idx2].first;
                s[idx2 ++].first = 0;
            }
        }
        
        for(int i = 0;i<idx;i++)
        {
            if(s[i].first != 0) ans ++;
        }

        cout << max(ans,1) << "\n";

    }
    
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 2):
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

    while(t --)
    {
        int n,m;

        unordered_map<ll,ll> cnt;
        vector<pair<ll,ll>> s;

        cin >> n >> m;
        int idx = 0;

        for(int i = 0;i<n;i++)
        {
            ll a;
            cin >> a;
            if(cnt[a] == 0)
            {
                cnt[a] = idx+1;
                s.push_back({0,a});
                idx ++;
            }
            s[cnt[a] - 1].first ++;
        }

        sort(s.begin(),s.begin()+idx);


        int idx2 = 0;

        int ans = 0;
        while(idx2 < idx && m > 0)
        {
            if(m >= s[idx2].first)
            {
                m -= s[idx2].first;
                s[idx2 ++].first = 0;
            }
        }
        
        for(int i = 0;i<idx;i++)
        {
            if(s[i].first != 0) ans ++;
        }

        cout << max(ans,1) << "\n";

    }
    
    return 0;
}

Submission (verdict: Time limit exceeded on test 11):
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

    while(t --)
    {
        int n,m;

        unordered_map<ll,ll> cnt;
        vector<pair<ll,ll>> s;

        cin >> n >> m;
        int idx = 0;

        for(int i = 0;i<n;i++)
        {
            ll a;
            cin >> a;
            if(cnt[a] == 0)
            {
                cnt[a] = idx+1;
                s.push_back({0,a});
                idx ++;
            }
            s[cnt[a] - 1].first ++;
        }

        sort(s.begin(),s.end());
        int idx2 = 0;

        int ans = 0;
        while(idx2 < idx && m > 0)
        {
            if(m >= s[idx2].first)
            {
                m -= s[idx2].first;
                s[idx2].first = 0;
            }
            idx2 ++;
        }
        
        for(int i = 0;i<idx;i++)
        {
            if(s[i].first != 0) ans ++;
        }

        cout << max(ans,1) << "\n";

    }
    
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)


Submission (verdict: Time limit exceeded on test 2):
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

    while(t --)
    {
        int n,m;

        unordered_map<ll,ll> cnt;
        vector<pair<ll,ll>> s;

        cin >> n >> m;
        int idx = 0;
        for(int i = 0;i<n;i++)
        {
            int a;
            cin >> a;
            if(cnt[a] == 0)
            {
                cnt[a] = idx+1;
                s.push_back({0,a});
                idx ++;
            }
            s[cnt[a] - 1].first ++;
        }

        sort(s.begin(),s.begin()+idx);


        int idx2 = 0;

        int ans = 0;
        while(idx2 < idx && m > 0)
        {
            if(m >= s[idx2].first)
            {
                m -= s[idx2].first;
                s[idx2 ++].first = 0;
            }
        }
        
        for(int i = 0;i<idx;i++)
        {
            if(s[i].first != 0) ans ++;
        }

        cout << max(ans,1) << "\n";

    }
    
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 11):
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

    while(t --)
    {
        int n,m;

        unordered_map<ll,ll> cnt;
        vector<pair<ll,ll>> s;

        cin >> n >> m;
        int idx = 0;

        for(int i = 0;i<n;i++)
        {
            ll a;
            cin >> a;
            if(cnt[a] == 0)
            {
                cnt[a] = idx+1;
                s.push_back({0,a});
                idx ++;
            }
            s[cnt[a] - 1].first ++;
        }

        sort(s.begin(),s.end());
        int idx2 = 0;

        int ans = 0;
        while(idx2 < idx && m > 0)
        {
            if(m >= s[idx2].first)
            {
                m -= s[idx2].first;
                s[idx2].first = 0;
            }
            idx2 ++;
        }
        
        for(int i = 0;i<idx;i++)
        {
            if(s[i].first != 0) ans ++;
        }

        cout << max(ans,1) << "\n";

    }
    
    return 0;
}

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

using namespace std;
using ll = long long;

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

    while(t --)
    {
        int n,m;

        map<ll,ll> cnt;
        vector<pair<ll,ll>> s;

        cin >> n >> m;
        int idx = 0;

        for(int i = 0;i<n;i++)
        {
            ll a;
            cin >> a;
            if(cnt[a] == 0)
            {
                cnt[a] = idx+1;
                s.push_back({0,a});
                idx ++;
            }
            s[cnt[a] - 1].first ++;
        }

        sort(s.begin(),s.end());
        int idx2 = 0;

        int ans = 0;
        while(idx2 < idx && m > 0)
        {
            if(m >= s[idx2].first)
            {
                m -= s[idx2].first;
                s[idx2].first = 0;
            }
            idx2 ++;
        }
        
        for(int i = 0;i<idx;i++)
        {
            if(s[i].first != 0) ans ++;
        }

        cout << max(ans,1) << "\n";

    }
    
    return 0;
}