You are given three strings A, B and C. Check whether they form a word chain.

More formally, determine whether both of the following are true:

* The last character in A and the initial character in B are the same.
* The last character in B and the initial character in C are the same.



If both are true, print `YES`. Otherwise, print `NO`.

Constraints

* A, B and C are all composed of lowercase English letters (`a` - `z`).
* 1 ≤ |A|, |B|, |C| ≤ 10, where |A|, |B| and |C| are the lengths of A, B and C, respectively.

Input

Input is given from Standard Input in the following format:


A B C


Output

Print `YES` or `NO`.

Examples

Input

rng gorilla apple


Output

YES


Input

yakiniku unagi sushi


Output

NO


Input

a a a


Output

YES


Input

aaaaaaaaab aaaaaaaaaa aaaaaaaaab


Output

NO
#include <bits/stdc++.h>
using namespace std;
struct Object {
  int w;
  int v;
  bool operator<(const Object& x) const {
    if (w == x.w) {
      return v > x.v;
    }
    return w < x.w;
  }
};
class SimpleKnapsack {
 private:
  int n;
  int max_w;
  vector<Object> objs;
  unordered_map<int, vector<int> > w_imos;
  int min_w;

 public:
  SimpleKnapsack() {
    cin >> n >> max_w;
    for (int i = 0; i < n; ++i) {
      Object tmp;
      cin >> tmp.w >> tmp.v;
      objs.push_back(tmp);
    }
    min_w = objs[0].w;
    sort(objs.begin(), objs.end());
  }
  void exec() {
    for (int i = 0; i < n; ++i) {
      w_imos[objs[i].w].push_back(objs[i].v);
    }
    for (auto itr = w_imos.begin(); itr != w_imos.end(); ++itr) {
      vector<int> arr = itr->second;
      for (int i = 1; i < arr.size(); ++i) {
        arr[i] += arr[i - 1];
      }
      for (int i = arr.size(); i <= n; ++i) {
        arr.push_back(0);
      }
      arr.insert(arr.begin(), 0);
      itr->second = arr;
    }
    long long ans = 0;
    int size_i = w_imos.find(min_w) == w_imos.end() ? 0 : w_imos[min_w].size();
    int size_j =
        w_imos.find(min_w + 1) == w_imos.end() ? 0 : w_imos[min_w + 1].size();
    int size_k =
        w_imos.find(min_w + 2) == w_imos.end() ? 0 : w_imos[min_w + 2].size();
    int size_l =
        w_imos.find(min_w + 3) == w_imos.end() ? 0 : w_imos[min_w + 3].size();
    for (int i = 0; i <= size_i; ++i) {
      for (int j = 0; j <= size_j; ++j) {
        for (int k = 0; k <= size_k; ++k) {
          for (int l = 0; l <= size_l; ++l) {
            if (min_w * i + (min_w + 1) * j + (min_w + 2) * k +
                    (min_w + 3) * l <=
                max_w) {
              long long val_i =
                  w_imos.find(min_w) == w_imos.end() ? 0 : w_imos[min_w][i];
              long long val_j = w_imos.find(min_w + 1) == w_imos.end()
                                    ? 0
                                    : w_imos[min_w + 1][j];
              long long val_w = w_imos.find(min_w + 2) == w_imos.end()
                                    ? 0
                                    : w_imos[min_w + 2][k];
              long long val_l = w_imos.find(min_w + 3) == w_imos.end()
                                    ? 0
                                    : w_imos[min_w + 3][l];
              ans = max(ans, val_i + val_j + val_w + val_l);
            }
          }
        }
      }
    }
    cout << ans << endl;
  }
};
int main() {
  SimpleKnapsack sk = SimpleKnapsack();
  sk.exec();
}
