ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
#define LOCAL
#ifdef LOCAL
#if __has_include("C:\Users\HP\Desktop\Codeforces\template.cpp")
#include "C:\Users\HP\Desktop\Codeforces\template.cpp"
#else
#pragma message("template.cpp not found. Proceeding without it.")
#endif
#else
#define debug(...)
#endif
using namespace std;
#define out(x) cout<<x<<endl
#define in(x)  cin>>x
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define int long long
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define deb(x) cout<<"#"<<x<<endl
#define deb2(x) cout<<"^"<<x<<endl
#define rep(i,x,y) for(int i=x;i<y;i++)
#define nxt cout<<endl;
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vc vector<char>

void solve(){
int n,m;
cin>>n>>m;
vi a(n);
rep(i,0,n){
    in(a[i]);
}
vi b(m);
map<int,int>mp;
map<int,int>mp2;
rep(i,0,m){
    in(b[i]);
    mp[b[i]]++;
    mp2[b[i]]++;
}
if(n==m){
    sort(all(a));
    sort(all(b));
    for(int i=0;i<n;i++){
        if(a[i]!=b[i]){
            no;
            return;
        }
    }
    yes;
    return;
}
sort(all(a));
sort(all(b));
multiset<int>ms;
set<int>ind;
// debug(mp2);
for(int i=0;i<n;i++){
    ms.insert(a[i]);
}
vi a2=a;
sort(all(a2));
// debug(a);
for(int i=0;i<a2.size()-1;i++){
    if(mp2.find(a2[i])!=mp2.end() && mp2[a2[i]]>0){
        mp2[a2[i]]--;
        continue;
    }
    if(abs(a2[i+1]-a2[i])<=1){
        // deb(a[i]);
        // deb2(a[i+1]);
        int x = a2[i+1]+a2[i];
        // deb2(x);
        if(mp2.find(x)!=mp2.end() && mp2[x]>0){
            mp2[x]--;
            // deb(a[i]);
            // deb2(a[i+1]);
            auto it = ms.find(a2[i]);
            ms.erase(it);
            ms.erase(ms.find(a2[i+1]));
            ms.insert(x);
            // deb(x);
            i++;
        }else{
            ms.erase(ms.find(a2[i]));
            ms.erase(ms.find(a2[i+1]));
            ms.insert(x);
            a2[i+1]= x;
        }
    }
    // debug(a);
    // debug(ms);
}

int z=0;
if(ms.size()>b.size() || ms.size()<b.size()){
    no;
    return;
}
for(auto it:ms){
    if(it!=b[z]){
        no;
        return;
    }
    z++;
}
yes;

}

signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin>>t;
while(t--){
solve();
}
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<int> arr(n);
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        int sum=accumulate(arr.begin(),arr.end(),0);
        while(arr.size()>1){
            vector<int> diff;
            int sum=0;
            for(int i=0;i<arr.size()-1;i++){
                int d=arr[i + 1]-arr[i];
                diff.push_back(d);
                sum += d;
            }
            if(sum>=0){
                arr=diff;  // Keep forward differences
                sum=max(sum,(int)accumulate(arr.begin(),arr.end(),0));   
            } 
            else{
                for(int &x:diff) x=-x;  // Invert differences
                reverse(diff.begin(),diff.end());
                arr=diff;
                sum=max(sum,(int)accumulate(arr.begin(),arr.end(),0));
            }
        }
        cout<<max(sum,arr[0])<<endl;
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<int> arr(n);
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        int sum=accumulate(arr.begin(),arr.end(),0);
        while(arr.size()>1){
            vector<int> diff;
            int sum=0;
            for(int i=0;i<arr.size()-1;i++){
                int d=arr[i + 1]-arr[i];
                diff.push_back(d);
                sum += d;
            }
            if(sum>=0){
                arr=diff;  // Keep forward differences
                sum=max(sum,(int)accumulate(arr.begin(),arr.end(),0));   
            } 
            else{
                for(int &x:diff) x=-x;  // Invert differences
                reverse(diff.begin(),diff.end());
                arr=diff;
                sum=max(sum,(int)accumulate(arr.begin(),arr.end(),0));
            }
        }
        cout<<max(sum,arr[0])<<endl;
    }
    return 0;
}


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<int> arr(n);
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        int tsum=accumulate(arr.begin(),arr.end(),0);
        while(arr.size()>1){
            vector<int> diff;
            int sum=0;
            for(int i=0;i<arr.size()-1;i++){
                int d=arr[i + 1]-arr[i];
                diff.push_back(d);
                sum += d;
            }
            if(sum>=0){
                arr=diff;  // Keep forward differences
                tsum=max(tsum,(int)accumulate(arr.begin(),arr.end(),0));   
            } 
            else{
                for(int &x:diff) x=-x;  // Invert differences
                reverse(diff.begin(),diff.end());
                arr=diff;
                tsum=max(tsum,(int)accumulate(arr.begin(),arr.end(),0));
            }
        }
        cout<<max(tsum,arr[0])<<endl;
    }
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<int> arr(n);
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        int tsum=accumulate(arr.begin(),arr.end(),0);
        while(arr.size()>1){
            vector<int> diff;
            int sum=0;
            for(int i=0;i<arr.size()-1;i++){
                int d=arr[i + 1]-arr[i];
                diff.push_back(d);
                sum += d;
            }
            if(sum>0){
                // arr=diff;  // Keep forward differences
                tsum=max(tsum,(int)accumulate(arr.begin(),arr.end(),0));   
            } 
                for(int &x:diff) x=-x;  // Invert differences
                reverse(diff.begin(),diff.end());
                arr=diff;
                tsum=max(tsum,(int)accumulate(arr.begin(),arr.end(),0));
        }
        cout<<max(tsum,arr[0])<<endl;
    }
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<int> arr(n);
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        int tsum=0;
        for(int i=0;i<n;i++){
            tsum+=arr[i];
        }
        int ans=tsum;
        while(arr.size()>1){
            vector<int> nxt;
            for(int j=0;j<arr.size()-1;j++){
                nxt.push_back(arr[j+1]-arr[j]);
            }
            int s=0;
            for(int x:nxt){
                s+=x;
            }
            tsum=max(tsum,(int)abs(s));
            arr=nxt;
        }
        cout<<tsum<<endl;
    }
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<int> arr(n);
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        int tsum=accumulate(arr.begin(),arr.end(),0);
        while(arr.size()>1){
            vector<int> diff;
            int sum=0;
            for(int i=0;i<arr.size()-1;i++){
                int d=arr[i + 1]-arr[i];
                diff.push_back(d);
                sum += d;
            }
            if(sum>=0){
                arr=diff;  // Keep forward differences
                tsum=max(tsum,(int)accumulate(arr.begin(),arr.end(),0));   
            } 
            else{
                for(int &x:diff) x=-x;  // Invert differences
                reverse(diff.begin(),diff.end());
                arr=diff;
                tsum=max(tsum,(int)accumulate(arr.begin(),arr.end(),0));
            }
        }
        cout<<max(tsum,arr[0])<<endl;
    }
}


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<int> arr(n);
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        int tsum=accumulate(arr.begin(),arr.end(),0);
        while(arr.size()>1){
            vector<int> diff;
            int sum=0;
            for(int i=0;i<arr.size()-1;i++){
                int d=arr[i + 1]-arr[i];
                diff.push_back(d);
                sum += d;
            }
            if(sum>0){
                // arr=diff;  // Keep forward differences
                tsum=max(tsum,(int)accumulate(arr.begin(),arr.end(),0));   
            } 
                for(int &x:diff) x=-x;  // Invert differences
                reverse(diff.begin(),diff.end());
                arr=diff;
                tsum=max(tsum,(int)accumulate(arr.begin(),arr.end(),0));
        }
        cout<<max(tsum,arr[0])<<endl;
    }
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
/* This was created by Ravinder Dathak.
 * Codeforces id by name of Mahadeva.
 * On 04-04-2024.
 * As proof that the following code is my own and authenticate.
*/

#include <bits/stdc++.h>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

using namespace std;

//Uncomment during contest.
#define int long long int
#define double long double float

#define input(n) for(int i=0;i<(int)n;i++)

//uncomment during practice. Plz take care of int and long long int.
//typedef long long int ll;
//typedef long double ld;

const int Mod= 1e9+7;

//uncomment to use AutoCp and before any submission.
//  #define ONLINE_JUDGE

void solve(){
    int l,r;
    cin>>l>>r;
    if(l==0){
        cout<<l<<' '<<r-1<<' '<<r<<endl;
        return ;
    }
    int ans=0;
    for(int i=log2(r);i>log2(l);i--){
        if(!((r>>i)&1))ans+=(1<<i);
    }
    if(ans==0)ans=l+1;
    cout<<l<<' '<<ans<<' '<<r<<endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifndef ONLINE_JUDGE
    freopen("cmake-build-debug/input.txt","r",stdin);
    freopen("cmake-build-debug/output.txt","w",stdout);
#endif
    int t=1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Submission (verdict: Wrong answer on test 1):
/* This was created by Ravinder Dathak.
 * Codeforces id by name of Mahadeva.
 * On 04-04-2024.
 * As proof that the following code is my own and authenticate.
*/

#include <bits/stdc++.h>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

using namespace std;

//Uncomment during contest.
#define int long long int
#define double long double float

#define input(n) for(int i=0;i<(int)n;i++)

//uncomment during practice. Plz take care of int and long long int.
//typedef long long int ll;
//typedef long double ld;

const int Mod= 1e9+7;

//uncomment to use AutoCp and before any submission.
//  #define ONLINE_JUDGE

void solve(){
    int l,r;
    cin>>l>>r;
    if(l==0){
        cout<<l<<' '<<r-1<<' '<<r<<endl;
        return ;
    }
    int ans=0;
    for(int i=log2(r)-1;i>=0;i--){
        if( ((r>>i)&1) == 0 )ans+=(1<<i);
    }
    if(ans==0 || ans<=l)ans=l+1;
    cout<<l<<' '<<ans<<' '<<r<<endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifndef ONLINE_JUDGE
    freopen("cmake-build-debug/input.txt","r",stdin);
    freopen("cmake-build-debug/output.txt","w",stdout);
#endif
    int t=1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 1):
/* This was created by Ravinder Dathak.
 * Codeforces id by name of Mahadeva.
 * On 04-04-2024.
 * As proof that the following code is my own and authenticate.
*/

#include <bits/stdc++.h>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

using namespace std;

//Uncomment during contest.
#define int long long int
#define double long double float

#define input(n) for(int i=0;i<(int)n;i++)

//uncomment during practice. Plz take care of int and long long int.
//typedef long long int ll;
//typedef long double ld;

const int Mod= 1e9+7;

//uncomment to use AutoCp and before any submission.
//  #define ONLINE_JUDGE

void solve(){
    int l,r;
    cin>>l>>r;
    if(l==0){
        cout<<l<<' '<<r-1<<' '<<r<<endl;
        return ;
    }
    int ans=0;
    for(int i=log2(r);i>log2(l);i--){
        if(!((r>>i)&1))ans+=(1<<i);
    }
    if(ans==0)ans=l+1;
    cout<<l<<' '<<ans<<' '<<r<<endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifndef ONLINE_JUDGE
    freopen("cmake-build-debug/input.txt","r",stdin);
    freopen("cmake-build-debug/output.txt","w",stdout);
#endif
    int t=1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
/* This was created by Ravinder Dathak.
 * Codeforces id by name of Mahadeva.
 * On 04-04-2024.
 * As proof that the following code is my own and authenticate.
*/

#include <bits/stdc++.h>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

using namespace std;

//Uncomment during contest.
#define int long long int
#define double long double float

#define input(n) for(int i=0;i<(int)n;i++)

//uncomment during practice. Plz take care of int and long long int.
//typedef long long int ll;
//typedef long double ld;

const int Mod= 1e9+7;

//uncomment to use AutoCp and before any submission.
//  #define ONLINE_JUDGE

void solve(){
    int l,r;
    cin>>l>>r;
    if(l==0){
        cout<<l<<' '<<r-1<<' '<<r<<endl;
        return ;
    }
    int ans=0;
    for(int i=log2(r)-1;i>=0;i--){
        if( ((r>>i)&1) == 0 )ans+=(1<<i);
    }
    if(ans==0 || ans<=l)ans=l+1;
    cout<<l<<' '<<ans<<' '<<r<<endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifndef ONLINE_JUDGE
    freopen("cmake-build-debug/input.txt","r",stdin);
    freopen("cmake-build-debug/output.txt","w",stdout);
#endif
    int t=1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Submission (verdict: Accepted):
/* This was created by Ravinder Dathak.
 * Codeforces id by name of Mahadeva.
 * On 04-04-2024.
 * As proof that the following code is my own and authenticate.
*/

#include <bits/stdc++.h>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

using namespace std;

//Uncomment during contest.
#define int long long int
#define double long double float

#define input(n) for(int i=0;i<(int)n;i++)

//uncomment during practice. Plz take care of int and long long int.
//typedef long long int ll;
//typedef long double ld;

const int Mod= 1e9+7;

//uncomment to use AutoCp and before any submission.
//  #define ONLINE_JUDGE

void solve(){
    int l,r;
    cin>>l>>r;
    int k;
    for(int i=30;i>=0;i--){
        if((l>>i)^(r>>i)){
            k=i;
            break;
        }
    }
    int a=l|((1<<k)-1),b=a+1,c=(a==l)?r:l;
    cout<<a<<' '<<b<<' '<<c<<endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifndef ONLINE_JUDGE
    freopen("cmake-build-debug/input.txt","r",stdin);
    freopen("cmake-build-debug/output.txt","w",stdout);
#endif
    int t=1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2049B - pspspsps
Language: C++17 (GCC 7-32)

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

using namespace std;

int main()

{

    int t;

    cin >> t;

    while (t--)

    {

        int n;

        cin >> n;

        string s;

        cin >> s;





        if (s[0] == 's')

            s[0] = '.';

        if (s[n - 1] == 'p')

            s[n - 1] = '.';

        bool fp=0, fs=0;

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

        {

            if (s[i]=='s')

            {

                fs=1;

            }

            if(s[i] == 'p')

            {

                fp=1;

            }

        }

        if (fs==1 && fp==1)

            cout << "NO" << endl;

        else

            cout << "YES" << endl;

    }

    return 0;

}

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

using namespace std;

int main()

{

    int t;

    cin >> t;

    while (t--)

    {

        int n;

        cin >> n;

        string s;

        cin >> s;





        if (s[0] == 's')

            s[0] = '.';

        if (s[n - 1] == 'p')

            s[n - 1] = '.';

        bool fp=0, fs=0;

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

        {

            if (s[i]=='s')

            {

                fs=1;

            }

            if(s[i] == 'p')

            {

                fp=1;

            }

        }

        if (fs==1 && fp==1)

            cout << "NO" << endl;

        else

            cout << "YES" << endl;

    }

    return 0;

}
Problem: 2049B - pspspsps
Language: C++17 (GCC 7-32)


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

using namespace std;

int main()

{

    int t;

    cin >> t;

    while (t--)

    {

        int n;

        cin >> n;

        string s;

        cin >> s;

        int lasts = -1, lastp = -1;

        bool ans = true;

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

        {

            if (s[i] == 's')

                lasts = i;

            else if (s[i] == 'p')

                lastp = i;



            if (lasts != -1 && lastp != -1)

            {

                if (lasts > lastp)

                {

                    ans = false;

                    break;

                }

                else if (lastp > lasts && lastp != n - 1)

                {

                    ans = false;

                    break;

                }

            }

        }

        if(ans==1)

        cout<<"YES"<<endl;

        else 

        cout<<"NO"<<endl;



    }

    return 0;

}
Problem: 2049B - pspspsps
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>

using namespace std;

int main()

{

    int t;

    cin >> t;

    while (t--)

    {

        int n;

        cin >> n;

        string s;

        cin >> s;

        int lasts = -1, lastp = -1;

        bool ans = true;

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

        {

            if (s[i] == 's')

                lasts = i;

            else if (s[i] == 'p')

                lastp = i;



            if (lasts != -1 && lastp != -1)

            {

                if (lasts > lastp)

                {

                    ans = false;

                    break;

                }

                else if (lastp > lasts && lastp != n - 1)

                {

                    ans = false;

                    break;

                }

            }

        }

        if(ans==1)

        cout<<"YES"<<endl;

        else 

        cout<<"NO"<<endl;



    }

    return 0;

}

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

using namespace std;

int main()

{

    int t;

    cin >> t;

    while (t--)

    {

        int n;

        cin >> n;

        string s;

        cin >> s;





        if (s[0] == 's')

            s[0] = '.';

        if (s[n - 1] == 'p')

            s[n - 1] = '.';

        bool fp=0, fs=0;

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

        {

            if (s[i]=='s')

            {

                fs=1;

            }

            if(s[i] == 'p')

            {

                fp=1;

            }

        }

        if (fs==1 && fp==1)

            cout << "NO" << endl;

        else

            cout << "YES" << endl;

    }

    return 0;

}
Problem: 2060D - Subtract Min Sort
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 2):
for _ in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    
    if l[0]>=l[1]:
        print("NO")
    else:
        f=1
        for i in range(1,n-1):
            
            if l[i]<=l[i-1]:
                f=0
                break
        
            if l[i+1]<=l[i]:
                l[i]=l[i]-l[i-1]
                
                
                
            
        if f:
            print("YES")
        else:
            print("NO")

Submission (verdict: Wrong answer on test 2):
for _ in range(int(input())):

    n=int(input())

    l=list(map(int,input().split()))

    

    if l[0]>l[1]:

        print("NO")

    else:

        f=1

        for i in range(1,n-1):

            

            if l[i]<l[i-1]:

                f=0

                break

        

            if l[i+1]<l[i]:

                l[i]=l[i]-l[i-1]

                

                

                

            

        if f:

            print("YES")

        else:

            print("NO")
Problem: 2060D - Subtract Min Sort
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 2):
for _ in range(int(input())):

    n=int(input())

    l=list(map(int,input().split()))

    

    if l[0]>l[1]:

        print("NO")

    else:

        f=1

        for i in range(1,n):

            

            if l[i]<l[i-1]:

                f=0

                break

        

            if i+1<n and l[i+1]<l[i]:

                l[i]=l[i]-l[i-1]

                

                

                

            

        if f:

            print("YES")

        else:

            print("NO")

Submission (verdict: Accepted):
for _ in range(int(input())):

    n=int(input())

    l=list(map(int,input().split()))

    



    f=1

    for i in range(n-1):

        

        if l[i]>l[i+1]:

            f=0

            break

    

        l[i+1]-=l[i]

        

                

                

                

        

    if f:

        print("YES")

    else:

        print("NO")
Problem: 2060D - Subtract Min Sort
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 2):
for _ in range(int(input())):

    n=int(input())

    l=list(map(int,input().split()))

    

    if l[0]>l[1]:

        print("NO")

    else:

        f=1

        for i in range(1,n-1):

            

            if l[i]<l[i-1]:

                f=0

                break

        

            if l[i+1]<l[i]:

                l[i]=l[i]-l[i-1]

                

                

                

            

        if f:

            print("YES")

        else:

            print("NO")

Submission (verdict: Wrong answer on test 2):
for _ in range(int(input())):

    n=int(input())

    l=list(map(int,input().split()))

    

    if l[0]>l[1]:

        print("NO")

    else:

        f=1

        for i in range(1,n):

            

            if l[i]<l[i-1]:

                f=0

                break

        

            if i+1<n and l[i+1]<l[i]:

                l[i]=l[i]-l[i-1]

                

                

                

            

        if f:

            print("YES")

        else:

            print("NO")