#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


int main(){cout<<fixed<<setprecision(10);
		   string s[3];
           rep(i,0,3)cin>>s[i];
           YES(s[0][s[0].size()-1]==s[1][0]&&s[1][s[1].size()-1]==s[2][0]);
          }
#include<bits/stdc++.h>
#include<string.h>

using namespace std;

int main()
{
    char line[50];
    cin.getline(line,50);
    char a,b,c,d;
    int count=0;
    for(int i=0;i<strlen(line);i++)
    {
        if(line[i]==' ')
        {
            if(count==0)
            {
            a=line[i-1];
            b=line[i+1];
            count=1;
            }
            else
            {
              c=line[i-1];
              d=line[i+1];
            }
        }
    }
    if(a==b && c==d)
    {
        cout<<"YES";
    }
    else{
        cout<<"NO";
    }
    return 0;
}

