Codeforces Round #651 (Div. 2)(A,B,C,D,E)


#include
using namespace std;
#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)
#define fi first                                  
#define se second
#define mk(x,y) make_pair(x,y)
const int mod=1e9+7;
const int maxn=5e4+10;
const int maxm=5e5+10;
const ll INF=1e18;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){
    if(y==0) return x;
    return gcd(y,x%y);
}
/*
A 
*/
int t,n;
int main(){
    ios::sync_with_stdio(false);/*
    freopen("d://in.txt","r",stdin);
    freopen("d://out.txt","w",stdout);*/
    cin>>t;
    while(t--){
        cin>>n;
        cout<
#include
using namespace std;
#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)
#define fi first                                  
#define se second
#define mk(x,y) make_pair(x,y)
const int mod=1e9+7;
const int maxn=2100;
const int maxm=5e5+10;
const ll INF=1e18;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){
    if(y==0) return x;
    return gcd(y,x%y);
}
/*
B 
*/
int t,n,a[maxn],cnt[2];
pii p[maxn];
int main(){
    ios::sync_with_stdio(false);/*
    freopen("d://in.txt","r",stdin);
    freopen("d://out.txt","w",stdout);*/
    cin>>t;
    while(t--){
        mst(cnt,0);
        cin>>n;
        rep(i,1,2*n+1){
            cin>>a[i];
            a[i]%=2;
            cnt[a[i]]++;
            p[i]=mk(a[i],i);
        }
        sort(p+1,p+2*n+1);
        if(cnt[1]&1){
            for(int i=1;i<=2*n;i+=2){
                if(p[i].fi^p[i+1].fi) continue;
                cout<

#include
using namespace std;
#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)
#define fi first                                  
#define se second
#define mk(x,y) make_pair(x,y)
const int mod=1e9+7;
const int maxn=5e4+10;
const int maxm=5e5+10;
const ll INF=1e18;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){
    if(y==0) return x;
    return gcd(y,x%y);
}
/*
C 
*/
int t;
ll n;
int main(){
    ios::sync_with_stdio(false);/*
    freopen("d://in.txt","r",stdin);
    freopen("d://out.txt","w",stdout);*/
    cin>>t;
    while(t--){
        cin>>n;

        if(n==1) {cout<
#include
using namespace std;
#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)
#define fi first                                  
#define se second
#define mk(x,y) make_pair(x,y)
const int mod=1e9+7;
const int maxn=2e5+10;
const int maxm=5e5+10;
const ll INF=1e18;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){
    if(y==0) return x;
    return gcd(y,x%y);
}
/*
D 
*/
int n,k,a[maxn],b[maxn];
int judge(int x){
    int cnt1=0,cnt0=0;
    rep(i,1,n+1){
        if(a[i]<=x){
            cnt1++;
            if(i+1<=n) cnt0++,i++;
        }
    }
    if(cnt0>=k/2&&cnt1>=(k+1)/2) return 1;
    cnt1=1,cnt0=0;
    rep(i,2,n+1){
        if(a[i]<=x){
            cnt0++;
            if(i+1<=n) cnt1++,i++;
        }
    }
    if(cnt1>=(k+1)/2&&cnt0>=k/2) return 1;
    return 0;
}
int main(){
    ios::sync_with_stdio(false);/*
    freopen("d://in.txt","r",stdin);
    freopen("d://out.txt","w",stdout);*/
    cin>>n>>k;
    rep(i,1,n+1){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b+1,b+1+n);
    int cnt=unique(b+1,b+1+n)-b-1;
    int l=1,r=cnt,ans;
    while(l<=r){
        int mid=l+r>>1;
        if(judge(b[mid])){
            r=mid-1,ans=mid;
        }else{
            l=mid+1;
        }
    }
    cout<
#include
using namespace std;
#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)
#define fi first                                  
#define se second
#define mk(x,y) make_pair(x,y)
const int mod=1e9+7;
const int maxn=1e6+10;
const int maxm=5e5+10;
const ll INF=1e18;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){
    if(y==0) return x;
    return gcd(y,x%y);
}
/*
E 
*/
int n,cnt0=0,cnt1=0,ret=0,cur;
int sk[maxn],idx=0,l1=0,l2=0;
string s,t;
int main(){
    ios::sync_with_stdio(false);/*
    freopen("d://in.txt","r",stdin);
    freopen("d://out.txt","w",stdout);*/
    cin>>n;ret=0;
    cin>>s>>t;
    rep(i,0,n) if(s[i]^t[i]){
        if(s[i]=='0'){
            cnt0++,cur=0;
        }else{
            cnt1++,cur=1;
        }
        if(idx==0) sk[idx++]=cur;
        else{
            if(sk[idx-1]^cur) idx--;
            else sk[idx++]=cur;
        }
        if(idx){
            if(sk[idx-1]) l1=max(l1,idx);
            else l2=max(l2,idx);
        }
    }
    if(cnt0^cnt1) cout<