Language: C++

#include<bits/stdc++.h>
using namespace std;
const int maxn=100005;
struct SHIT
{
    int one,two;
    bool operator<(const SHIT  &b)const {
        if(this->one!=b.one) return (this->one<b.one);
        return (this->two<b.two);
    }
}shit[maxn];
bool cmp(SHIT a,SHIT b)
{
    if(a.one+a.two!=b.one+b.two)
    return a.one+a.two<b.one+b.two;
    return a.one<b.one;
}
map<SHIT,bool>mp;
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d",&shit[i].one,&shit[i].two);
    }
    if(!(shit[1].one==shit[2].two&&shit[1].one==0&&shit[1].two!=0)){
        puts("-1");
        return 0;
    }
    int mn=shit[1].two;
    int ans=0;
    if(mn==1)
        ans++;
    if(n==2){
        if(mn==1){
            puts("1");
        }
        else{
            puts("-1");
        }
        return 0;
    }
    for(int i=3;i<=n;i++)
    {
        if(shit[i].one==0||shit[i].two==0||shit[i].one+shit[i].two<mn){
            puts("-1");
            return 0;
        }
    }
    sort(shit+3,shit+n+1,cmp);
    mp.clear();
    mp[shit[1]]=1;
    mp[shit[2]]=1;
    for(int i=3;i<=n;)
    {
        int j=i+1;
        while(j<=n&&shit[j].one+shit[j].two==shit[i].one+shit[i].two)
            j++;
        for(int k=i;k<j;k++)
            mp[shit[k]]=1;
        if(shit[i].one+shit[i].two==mn){
            for(int k=i;k<j;k++)
            {
                SHIT tmp1,tmp2;
                tmp1.one=shit[k].one-1;
                tmp1.two=shit[k].two+1;
                tmp2.one=shit[k].one+1;
                tmp2.two=shit[k].two-1;
                //printf("%d %d\n",mp.count(tmp1),mp.count(tmp2));
                if(mp.count(tmp1)&&mp.count(tmp2)){
                    continue;
                }
                else{
                    puts("-1");
                    return 0;
                }
            }
            ans=ans+(j-i-mn+1)*2+mn;
        }
        else{
            for(int k=i;k<j;k++)
            {
                SHIT tmp1,tmp2;
                tmp1.one=shit[k].one-1;
                tmp1.two=shit[k].two-1;
                if(mp.count(tmp1)){
                    ans++;
                    continue;
                }
                if(shit[k].one==shit[k-1].one&&shit[k].two==shit[k-1].two){
                    ans+=2;
                    continue;
                }
                bool one=0,two=0;
                tmp1.one=shit[k].one-1;
                tmp1.two=shit[k].two+1;
                tmp2.one=shit[k].one+1;
                tmp2.two=shit[k].two-1;

                if(mp.count(tmp1)&&mp.count(tmp2)&&tmp1.one==shit[k-1].one&&tmp1.two=shit[k-1].two){
                    ans=ans+1;
                    continue;
                }
                one=one|mp.count(tmp1);
                tmp1.two--;
                one=one|mp.count(tmp1);

                two=two|mp.count(tmp2);
                tmp2.one--;
                two=two|mp.count(tmp2);
                if(one&&two){
                    ans+=2;continue;
                }
                puts("-1");
                return 0;
            }
        }
        i=j;
    }
    printf("%d\n",ans);
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:101:75: error: lvalue required as left operand of assignment
  101 |                 if(mp.count(tmp1)&&mp.count(tmp2)&&tmp1.one==shit[k-1].one&&tmp1.two=shit[k-1].two){
      |                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~