Source Code
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n,k,m;
    cin>>n>>k>>m;

    ll sum=0;
    int difs=0,same=0;

    for(int i=0;i<n;i++){
        int x,y;
        cin>>x>>y;
        difs+=x%2!=y%2;
        same+=x%2==y%2;
        sum+=x;
    }

    if(!difs&&same){
        if(m==sum%2) cout<<1;
        else cout<<2;
    } else if(!same&&difs){
        if(k%2){
            if(m==sum%2) cout<<2;
            else cout<<1;
        } else {
            if(m==sum%2) cout<<1;
            else cout<<2;
        }
    } else {
        cout<<(k%2==0)+1;
    }
}
Copy
Cliffs of Dover Mohamedmaher
GNU G++17
174 ms
1.0 MB
Accepted