#include <bits/stdc++.h>
using namespace std;
int KthSmallest(vector<int>& arr, int k) {
sort(arr.begin(), arr.end());
int uniqueCount = 0;
int lastUnique = INT_MIN;
for (int i = 0; i < arr.size(); ++i) {
if (arr[i] != lastUnique) {
uniqueCount++;
lastUnique = arr[i];
}
if (uniqueCount == k) {
return arr[i];
}
}
return -1;
}
int main() {
vector<int> arr = {10, 20, 7, 8, 7, 7, 6} ;
int ans = KthSmallest(arr, 3);
cout<<ans<<endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgS3RoU21hbGxlc3QodmVjdG9yPGludD4mIGFyciwgaW50IGspIHsKICAgIHNvcnQoYXJyLmJlZ2luKCksIGFyci5lbmQoKSk7CgogICAgaW50IHVuaXF1ZUNvdW50ID0gMDsKICAgIGludCBsYXN0VW5pcXVlID0gSU5UX01JTjsKCiAgICBmb3IgKGludCBpID0gMDsgaSA8IGFyci5zaXplKCk7ICsraSkgewogICAgICAgIGlmIChhcnJbaV0gIT0gbGFzdFVuaXF1ZSkgewogICAgICAgICAgICB1bmlxdWVDb3VudCsrOwogICAgICAgICAgICBsYXN0VW5pcXVlID0gYXJyW2ldOwogICAgICAgIH0KICAgICAgICBpZiAodW5pcXVlQ291bnQgPT0gaykgewogICAgICAgICAgICByZXR1cm4gYXJyW2ldOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiAtMTsgCn0KCiAgICAKaW50IG1haW4oKSB7CiAgICAKICAgIHZlY3RvcjxpbnQ+IGFyciA9IHsxMCwgMjAsIDcsIDgsIDcsIDcsIDZ9IDsKICAgIGludCBhbnMgPSBLdGhTbWFsbGVzdChhcnIsIDMpOwogICAgY291dDw8YW5zPDxlbmRsOwogICAgCiAgICByZXR1cm4gMDsKfQ==