ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
void dfs(int node , vector<vector<int>>& adj , vector<int>& vis , int del1 , int del2){
    vis[node]=1;
    for(auto it : adj[node]){
        if(!vis[it] && it!=del1 && it!=del2){
            dfs(it,adj,vis,del1,del2);
        }
    }
}
void solve() {
    int n;
    cin>>n;
    vector<vector<int>> adj(n+1);
    vector<int> deg(n+1,0);
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        adj[a].push_back(b);
        deg[b]++;
        deg[a]++;
    }
    int maxDeg = 0;
    int node = 1;
    // for(auto it : deg) cout<<it<<" ";
    // cout<<endl;
    priority_queue<pair<int,int>> q; 
    for(int i=1;i<=n;i++){
            q.push({deg[i],i});
        if(maxDeg<=deg[i]){
            node = i;
            maxDeg=deg[i];
        }
    }
    // cout<<maxDeg<<" ";
    // cout<<"size="<<q.size()<<" ";
    int node2;
    while(!q.empty()){
        int nod = q.top().second;
        // cout<<nod<<" ";
        q.pop();
        if(nod==node) continue;
        node2= nod;
        bool flag = 0;
        for(auto it : adj[nod]){
            if(it==node){
                flag = 1;
                continue;
            }
        }
        if(flag) continue;
        for(auto it : adj[node]){
            if(it==nod){
                flag = 1;
                continue;
            }
        }
        if(flag) continue;
        node2 = nod;
        break;
    }
    // cout<<endl;
    // deg[node]=0;
    // maxDeg=0;
    // for(int i=1;i<=n;i++){
    //     if(maxDeg<=deg[i] && i!=node){
    //         node2 = i;
    //         maxDeg=deg[i];
    //     }
    // }
    // cout<<node<<" "<<node2<<endl;
    vector<int> vis(n+1,0);
    int ans = 0;
    for(int i=1;i<=n;i++){
        if(!vis[i] && i!=node && i!=node2){
            ans++;
            dfs(i,adj,vis,node,node2);
        }
    }
    cout<<ans<<endl;
    
}

int main()
{
    ios_base::sync_with_stdio(false);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cin.tie(NULL);
 
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
 
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
}
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;

typedef long long ll;
typedef vector<ll> vll;
const int mod = 1e9 + 7;
const int inf = INT_MAX;
const ll infl = LLONG_MAX;
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) x.rbegin(), x.rend()

ll expo(ll a, ll b, ll m)
{
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = (res * a) % m;
        a = (a * a) % m;
        b = b >> 1;
    }
    return res;
}

ll mod_inv(ll a, ll m) { return expo(a, m - 2, m); }

ll gcd(ll a, ll b)
{
    while (b != 0)
    {
        ll t = b;
        b = a % b;
        a = t;
    }
    return a;
}

void solve(){
ll l,r;
cin>>l>>r;
int k;
for(int i=30;i>=0;i--){
    if(((1<<i)&l)!=((1<<i)&r)){
        k = i;
        break;
    }
}
cout<<(1<<k)<<" "<<(1<<k)-1<<" "<<r<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t = 1;
    cin >> t;
    while(t--){
        solve();
    }
    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;

typedef long long ll;
typedef vector<ll> vll;
const int mod = 1e9 + 7;
const int inf = INT_MAX;
const ll infl = LLONG_MAX;
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) x.rbegin(), x.rend()

ll expo(ll a, ll b, ll m)
{
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = (res * a) % m;
        a = (a * a) % m;
        b = b >> 1;
    }
    return res;
}

ll mod_inv(ll a, ll m) { return expo(a, m - 2, m); }

ll gcd(ll a, ll b)
{
    while (b != 0)
    {
        ll t = b;
        b = a % b;
        a = t;
    }
    return a;
}

void solve(){
ll l,r;
cin>>l>>r;
int k;
for(int i=30;i>=0;i--){
    if(((1<<i)&l)!=((1<<i)&r)){
        k = i;
        break;
    }
}
ll a = 1<<k;
cout<<a<<" "<<a-1<<" "<<((a==r || a-1==r)?l:r)<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t = 1;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

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

typedef long long ll;
typedef vector<ll> vll;
const int mod = 1e9 + 7;
const int inf = INT_MAX;
const ll infl = LLONG_MAX;
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) x.rbegin(), x.rend()

ll expo(ll a, ll b, ll m)
{
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = (res * a) % m;
        a = (a * a) % m;
        b = b >> 1;
    }
    return res;
}

ll mod_inv(ll a, ll m) { return expo(a, m - 2, m); }

ll gcd(ll a, ll b)
{
    while (b != 0)
    {
        ll t = b;
        b = a % b;
        a = t;
    }
    return a;
}

void solve(){
ll l,r;
cin>>l>>r;
int k;
for(int i=30;i>=0;i--){
    if(((1<<i)&l)!=((1<<i)&r)){
        k = i;
        break;
    }
}
ll a = l|((1<<k)-1);
cout<<a<<" "<<a+1<<" "<<((a==r || a+1==r)?l:r)<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t = 1;
    cin >> t;
    while(t--){
        solve();
    }
    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;

typedef long long ll;
typedef vector<ll> vll;
const int mod = 1e9 + 7;
const int inf = INT_MAX;
const ll infl = LLONG_MAX;
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) x.rbegin(), x.rend()

ll expo(ll a, ll b, ll m)
{
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = (res * a) % m;
        a = (a * a) % m;
        b = b >> 1;
    }
    return res;
}

ll mod_inv(ll a, ll m) { return expo(a, m - 2, m); }

ll gcd(ll a, ll b)
{
    while (b != 0)
    {
        ll t = b;
        b = a % b;
        a = t;
    }
    return a;
}

void solve(){
ll l,r;
cin>>l>>r;
int k;
for(int i=30;i>=0;i--){
    if(((1<<i)&l)!=((1<<i)&r)){
        k = i;
        break;
    }
}
cout<<(1<<k)<<" "<<(1<<k)-1<<" "<<r<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t = 1;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

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

typedef long long ll;
typedef vector<ll> vll;
const int mod = 1e9 + 7;
const int inf = INT_MAX;
const ll infl = LLONG_MAX;
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) x.rbegin(), x.rend()

ll expo(ll a, ll b, ll m)
{
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = (res * a) % m;
        a = (a * a) % m;
        b = b >> 1;
    }
    return res;
}

ll mod_inv(ll a, ll m) { return expo(a, m - 2, m); }

ll gcd(ll a, ll b)
{
    while (b != 0)
    {
        ll t = b;
        b = a % b;
        a = t;
    }
    return a;
}

void solve(){
ll l,r;
cin>>l>>r;
int k;
for(int i=30;i>=0;i--){
    if(((1<<i)&l)!=((1<<i)&r)){
        k = i;
        break;
    }
}
ll a = 1<<k;
cout<<a<<" "<<a-1<<" "<<((a==r || a-1==r)?l:r)<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t = 1;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: Python 3

Previous submission (verdict: Time limit exceeded on test 6):
def f(a, b, c, i, j):
    if i == 0 and j == 0 :
        return 0
    if i == 0:
        return sum(1 for k in range(j) if b[k] != c[k])
    if j == 0:
        return sum(1 for k in range(i) if a[k] != c[k])
    indx = i + j - 1
    ans = float("inf")
    if i > 0 and c[indx] == a[i - 1]:
        ans = min(ans, f(a, b, c, i - 1, j))
    if j > 0 and c[indx] == b[j - 1]:
        ans = min(ans, f(a, b, c, i, j - 1))
    if i > 0 and c[indx] != a[i - 1]:
        ans = min(ans, f(a, b, c, i - 1, j) + 1)
    if j > 0 and c[indx] != b[j - 1]:
        ans = min(ans, f(a, b, c, i, j - 1) + 1)
    return ans
n = int(input())
for _ in range(n):
    a = input()
    b = input()
    c = input()
    i = len(a)
    j = len(b)
    res = f(a, b, c, i, j)
    print(res)


Submission (verdict: Runtime error on test 16):
def f(a, b, c, i, j, dp):
    if i == 0 and j == 0:
        return 0
    if i == 0:
        return sum(1 for k in range(j) if b[k] != c[k])
    if j == 0:
        return sum(1 for k in range(i) if a[k] != c[k])
    if dp[i][j] != -1:
        return dp[i][j]
    indx = i + j - 1
    ans = float("inf")
    if i > 0 and c[indx] == a[i - 1]:
        ans = min(ans, f(a, b, c, i - 1, j, dp))
    if j > 0 and c[indx] == b[j - 1]:
        ans = min(ans, f(a, b, c, i, j - 1, dp))
    if i > 0 and c[indx] != a[i - 1]:
        ans = min(ans, f(a, b, c, i - 1, j, dp) + 1)
    if j > 0 and c[indx] != b[j - 1]:
        ans = min(ans, f(a, b, c, i, j - 1, dp) + 1)
    dp[i][j] = ans
    return ans
n = int(input())
for _ in range(n):
    a = input()
    b = input()
    c = input()
    i = len(a)
    j = len(b)
    dp = [[-1] * (j + 1) for _ in range(i + 1)]
    res = f(a, b, c, i, j, dp)
    print(res)
Problem: 2050E - Three Strings
Language: Python 3

Previous submission (verdict: Runtime error on test 16):
def f(a, b, c, i, j, dp):
    if i == 0 and j == 0:
        return 0
    if i == 0:
        return sum(1 for k in range(j) if b[k] != c[k])
    if j == 0:
        return sum(1 for k in range(i) if a[k] != c[k])
    if dp[i][j] != -1:
        return dp[i][j]
    indx = i + j - 1
    ans = float("inf")
    if i > 0 and c[indx] == a[i - 1]:
        ans = min(ans, f(a, b, c, i - 1, j, dp))
    if j > 0 and c[indx] == b[j - 1]:
        ans = min(ans, f(a, b, c, i, j - 1, dp))
    if i > 0 and c[indx] != a[i - 1]:
        ans = min(ans, f(a, b, c, i - 1, j, dp) + 1)
    if j > 0 and c[indx] != b[j - 1]:
        ans = min(ans, f(a, b, c, i, j - 1, dp) + 1)
    dp[i][j] = ans
    return ans
n = int(input())
for _ in range(n):
    a = input()
    b = input()
    c = input()
    i = len(a)
    j = len(b)
    dp = [[-1] * (j + 1) for _ in range(i + 1)]
    res = f(a, b, c, i, j, dp)
    print(res)


Submission (verdict: Time limit exceeded on test 2):
def f(a, b, c, i, j, dp):
    if i == 0 and j == 0:
        return 0
    if i == 0:
        return sum(1 for k in range(j) if b[k] != c[k])
    if j == 0:
        return sum(1 for k in range(i) if a[k] != c[k])
    if dp[i][j] != -1:
        return dp[i][j]
    indx = i + j - 1
    ans = float("inf")
    if i > 0 and c[indx] == a[i - 1]:
        ans = min(ans, f(a, b, c, i - 1, j, dp))
    if j > 0 and c[indx] == b[j - 1]:
        ans = min(ans, f(a, b, c, i, j - 1, dp))
    if i > 0 and c[indx] != a[i - 1]:
        ans = min(ans, f(a, b, c, i - 1, j, dp) + 1)
    if j > 0 and c[indx] != b[j - 1]:
        ans = min(ans, f(a, b, c, i, j - 1, dp) + 1)
    dp[i][j] = ans
    return ans
n = int(input())
for _ in range(n):
    a = input()
    b = input()
    c = input()
    i = len(a)
    j = len(b)
    dp = [[-1] * (1000) for _ in range(1000)]
    res = f(a, b, c, i, j, dp)
    print(res)
Problem: 2050E - Three Strings
Language: Python 3


Submission (verdict: Time limit exceeded on test 6):
def f(a, b, c, i, j):
    if i == 0 and j == 0 :
        return 0
    if i == 0:
        return sum(1 for k in range(j) if b[k] != c[k])
    if j == 0:
        return sum(1 for k in range(i) if a[k] != c[k])
    indx = i + j - 1
    ans = float("inf")
    if i > 0 and c[indx] == a[i - 1]:
        ans = min(ans, f(a, b, c, i - 1, j))
    if j > 0 and c[indx] == b[j - 1]:
        ans = min(ans, f(a, b, c, i, j - 1))
    if i > 0 and c[indx] != a[i - 1]:
        ans = min(ans, f(a, b, c, i - 1, j) + 1)
    if j > 0 and c[indx] != b[j - 1]:
        ans = min(ans, f(a, b, c, i, j - 1) + 1)
    return ans
n = int(input())
for _ in range(n):
    a = input()
    b = input()
    c = input()
    i = len(a)
    j = len(b)
    res = f(a, b, c, i, j)
    print(res)
Problem: 2050E - Three Strings
Language: Python 3

Previous submission (verdict: Runtime error on test 16):
def f(a, b, c, i, j, dp):
    if i == 0 and j == 0:
        return 0
    if i == 0:
        tempu = sum(1 for k in range(j) if b[k] != c[k])
        dp[i][j] = tempu
        return dp[i][j]
    if j == 0:
        tempu = sum(1 for k in range(i) if a[k] != c[k])
        dp[i][j] = tempu
        return dp[i][j]
    if dp[i][j] != -1:
        return dp[i][j]
    
    indx = i + j - 1
    ans = float("inf")
    if i > 0 and c[indx] == a[i - 1]:
        ans = min(ans, f(a, b, c, i - 1, j, dp))
    if j > 0 and c[indx] == b[j - 1]:
        ans = min(ans, f(a, b, c, i, j - 1, dp))
    if i > 0 and c[indx] != a[i - 1]:
        ans = min(ans, f(a, b, c, i - 1, j, dp) + 1)
    if j > 0 and c[indx] != b[j - 1]:
        ans = min(ans, f(a, b, c, i, j - 1, dp) + 1)
    dp[i][j] = ans
    return ans

n = int(input())
for _ in range(n):
    a = input()
    b = input()
    c = input()
    i = len(a)
    j = len(b)
    # Re-initialize `dp` for each test case
    dp = [[-1] * (j + 1) for _ in range(i + 1)]
    res = f(a, b, c, i, j, dp)
    print(res)


Submission (verdict: Accepted):
def f(a,b,c,p,q,dp):
    dp[0][0] = 0
    for i in range(p+1):
        for j in range(q+1):
            if i > 0 :
                val = int(a[i-1] != c[i+j-1])
                dp[i][j] = min(dp[i][j],dp[i-1][j]+val)
            if j > 0 :
                val = int(b[j-1] != c[i+j-1])
                dp[i][j] = min(dp[i][j] , dp[i][j-1]+val)
    return dp[p][q]
                

n = int(input())
for _ in range(n):
    a = input()
    b = input()
    c = input()
    i = len(a)
    j = len(b)
    dp = [[float('inf')] * (j+1) for _ in range(i+1)]
    res = f(a, b, c, i, j, dp)
    print(res)
Problem: 2050E - Three Strings
Language: Python 3

Previous submission (verdict: Time limit exceeded on test 2):
def f(a, b, c, i, j, dp):
    if i == 0 and j == 0:
        return 0
    if i == 0:
        return sum(1 for k in range(j) if b[k] != c[k])
    if j == 0:
        return sum(1 for k in range(i) if a[k] != c[k])
    if dp[i][j] != -1:
        return dp[i][j]
    indx = i + j - 1
    ans = float("inf")
    if i > 0 and c[indx] == a[i - 1]:
        ans = min(ans, f(a, b, c, i - 1, j, dp))
    if j > 0 and c[indx] == b[j - 1]:
        ans = min(ans, f(a, b, c, i, j - 1, dp))
    if i > 0 and c[indx] != a[i - 1]:
        ans = min(ans, f(a, b, c, i - 1, j, dp) + 1)
    if j > 0 and c[indx] != b[j - 1]:
        ans = min(ans, f(a, b, c, i, j - 1, dp) + 1)
    dp[i][j] = ans
    return ans
n = int(input())
for _ in range(n):
    a = input()
    b = input()
    c = input()
    i = len(a)
    j = len(b)
    dp = [[-1] * (1000) for _ in range(1000)]
    res = f(a, b, c, i, j, dp)
    print(res)


Submission (verdict: Runtime error on test 16):
def f(a, b, c, i, j, dp):
    if i == 0 and j == 0:
        return 0
    if i == 0:
        tempu = sum(1 for k in range(j) if b[k] != c[k])
        dp[i][j] = tempu
        return dp[i][j]
    if j == 0:
        tempu = sum(1 for k in range(i) if a[k] != c[k])
        dp[i][j] = tempu
        return dp[i][j]
    if dp[i][j] != -1:
        return dp[i][j]
    
    indx = i + j - 1
    ans = float("inf")
    if i > 0 and c[indx] == a[i - 1]:
        ans = min(ans, f(a, b, c, i - 1, j, dp))
    if j > 0 and c[indx] == b[j - 1]:
        ans = min(ans, f(a, b, c, i, j - 1, dp))
    if i > 0 and c[indx] != a[i - 1]:
        ans = min(ans, f(a, b, c, i - 1, j, dp) + 1)
    if j > 0 and c[indx] != b[j - 1]:
        ans = min(ans, f(a, b, c, i, j - 1, dp) + 1)
    dp[i][j] = ans
    return ans

n = int(input())
for _ in range(n):
    a = input()
    b = input()
    c = input()
    i = len(a)
    j = len(b)
    # Re-initialize `dp` for each test case
    dp = [[-1] * (j + 1) for _ in range(i + 1)]
    res = f(a, b, c, i, j, dp)
    print(res)
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

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

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    vector<int> arr(n);
    
    for(int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    
    vector<int> brr = arr;
    sort(brr.begin(), brr.begin() + r);
   
    int p = r - l + 1;
    //   for(int i=0;i<p;i++)cout<<brr[i]<<" ";
    //   cout<<endl;
    int ans = INT_MAX;
    int current_sum = 0;

    for(int i = 0; i < p; i++) {
        current_sum += brr[i];
    }
ans = min(ans,current_sum);
    sort(arr.begin() + (l - 1), arr.end());
    //  for(int i=l-1;i<p;i++)cout<<arr[i]<<" ";
    //   cout<<endl;
 current_sum=0;
    for(int i = l - 1; i < l+p-1; i++) { 
        current_sum += arr[i];
    }

    ans = min(ans, current_sum);
    cout << ans << endl;
}

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


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

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    vector<int> arr(n);
    
    for(int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    
    vector<int> brr = arr;
    sort(brr.begin(), brr.begin() + r);
   
    int p = r - l + 1;
    int ans = INT_MAX;
    long long current_sum = 0;

    for(int i = 0; i < p; i++) {
        current_sum += brr[i];
    }
    ans = min(ans, current_sum);
    sort(arr.begin() + (l - 1), arr.end());
    current_sum = 0;
    for(int i = l - 1; i < l + p - 1; i++) { 
        current_sum += arr[i];
    }
    ans = min(ans, current_sum);
    cout << ans << endl;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

Previous submission (verdict: Compilation error):
#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    vector<int> arr(n);
    
    for(int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    
    vector<int> brr = arr;
    sort(brr.begin(), brr.begin() + r);
   
    int p = r - l + 1;
    int ans = INT_MAX;
    long long current_sum = 0;

    for(int i = 0; i < p; i++) {
        current_sum += brr[i];
    }
    ans = min(ans, current_sum);
    sort(arr.begin() + (l - 1), arr.end());
    current_sum = 0;
    for(int i = l - 1; i < l + p - 1; i++) { 
        current_sum += arr[i];
    }
    ans = min(ans, current_sum);
    cout << ans << endl;
}

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


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

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    vector<int> arr(n);
    
    for(int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    
    vector<int> brr = arr;
    sort(brr.begin(), brr.begin() + r);
   
    int p = r - l + 1;
    long long ans = LLONG_MAX;
    long long current_sum = 0;

    for(int i = 0; i < p; i++) {
        current_sum += brr[i];
    }
    ans = min(ans, current_sum);
    sort(arr.begin() + (l - 1), arr.end());
    current_sum = 0;
    for(int i = l - 1; i < l + p - 1; i++) { 
        current_sum += arr[i];
    }
    ans = min(ans, current_sum);
    cout << ans << endl;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


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

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    vector<int> arr(n);
    
    for(int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    
    vector<int> brr = arr;
    sort(brr.begin(), brr.begin() + r);
   
    int p = r - l + 1;
    //   for(int i=0;i<p;i++)cout<<brr[i]<<" ";
    //   cout<<endl;
    int ans = INT_MAX;
    int current_sum = 0;

    for(int i = 0; i < p; i++) {
        current_sum += brr[i];
    }
ans = min(ans,current_sum);
    sort(arr.begin() + (l - 1), arr.end());
    //  for(int i=l-1;i<p;i++)cout<<arr[i]<<" ";
    //   cout<<endl;
 current_sum=0;
    for(int i = l - 1; i < l+p-1; i++) { 
        current_sum += arr[i];
    }

    ans = min(ans, current_sum);
    cout << ans << endl;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2049C - MEX Cycle
Language: C++20 (GCC 13-64)


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

// #include<ext/pb_ds/assoc_container.hpp>

// #include<ext/pb_ds/tree_policy.hpp>

using namespace std;

//using namespace __gnu_pbds;

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key

#define int long long

#define pb push_back

#define endl '\n'

#define vi vector<int>

const int Mod=1e9+7;

const int N=1e6;

#define ld long double

#define vpi vector<pair<int,int>>

const int MOD = 1e9 + 7;



#define mii map<int, int>

#define vvi vector<vi>

#define rep(i,x,y) for(int i=x; i<y; i++)



 bool primenumber(int n){

     vector<bool> prime(n+1,1);

     prime[0]=0;

     prime[1]=0;

     for(int i =2;i*i<=n;i++){

         if(prime[i]){

             for(int j =i*i;j<=n;j=j+i){

                 prime[j]=0;

                 }}}

     return prime[n];

 }



 int power(int x,int n){

     // calculating the power by binary exponentiation

     int ans=1;

     if(n==0){

         return 1;

     }

     if(n%2 == 0){

         // even power case

    ans=power(x*x,n/2);

     }

     else {

         //odd power case

       ans=x*power(x*x,n/2);

     }

     return ans;

 }



int ncr(int n,int r){

    if(r==0 || r==n) return 1;

    if(r==1) return n;

    int res=1;

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

        res*=(n-i+1);

        res/=(i);

    }

    return res;

}



// factorial

unsigned int factorial(unsigned int n)

{

    if (n == 0 || n == 1)

        return 1;

    return n * factorial(n - 1);

}





// sort the vactor pair based on second element

 bool comp(pair<int, int>& a, pair<int, int>& b){

     return a.second < b.second;

 }

// Function to calculate (base^exponent) % mod

int  modExp(int base, int  exponent, int mod) {

    int result = 1;

    while (exponent > 0) {

        if (exponent % 2 == 1) { 

            result = (result * base) % mod;

        }

        base = (base * base) % mod; 

        exponent /= 2; 

    }

    return result;

}



// Function to calculate (P * Q^-1) % MOD

int calculateModInverse(int P, int Q) {

    int Q_inv = modExp(Q, MOD - 2, MOD); 

    return (P * Q_inv) % MOD;

}



int gcd(int a, int b) {

    while (b != 0) {

        int temp = b;

        b = a % b;

        a = temp;

    }

    return a;

}

void FASTIO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); }



int32_t main(){

    FASTIO();

    cout<<setprecision(21)<<fixed;



    int t;

    cin>>t;

    while(t--){

        int n,x,y;

        cin>>n>>x>>y;

        vi ans(n,-1);

        ans[x-1]=0;

        ans[y-1]=1;



   if(ans[x%n]==-1)ans[x]=2;

   if(ans[(x-2) %n]==-1)ans[(x-2) %n]=2;

   if(ans[(y-2) %n] ==-1)ans[(y-2) %n]=0;

   if(ans[y%n]==-1)ans[y]=0;

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

    if(ans[i]==-1)ans[i]=1;

   }

   for(auto it:ans)cout<<it<<" ";

   cout<<endl;















    

    }

    return 0;

   

}