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;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n, w, wi, vi, first_w;
  while (cin >> n >> w) {
    vector<long long> a;
    vector<long long> b;
    vector<long long> c;
    vector<long long> d;
    for (int i = 0; i < n; i++) {
      cin >> wi >> vi;
      if (i == 0) first_w = wi;
      if (wi == first_w) a.push_back(vi);
      if (wi == first_w + 1) b.push_back(vi);
      if (wi == first_w + 2) c.push_back(vi);
      if (wi == first_w + 3) d.push_back(vi);
    }
    sort(a.rbegin(), a.rend());
    sort(b.rbegin(), b.rend());
    sort(c.rbegin(), c.rend());
    sort(d.rbegin(), d.rend());
    a.insert(a.begin(), 0ll);
    b.insert(b.begin(), 0ll);
    c.insert(c.begin(), 0ll);
    d.insert(d.begin(), 0ll);
    for (int i = 1; i < a.size(); i++) a[i] += a[i - 1];
    for (int i = 1; i < b.size(); i++) b[i] += b[i - 1];
    for (int i = 1; i < c.size(); i++) c[i] += c[i - 1];
    for (int i = 1; i < d.size(); i++) d[i] += d[i - 1];
    long long ans = 0;
    for (int i = 0; i < a.size(); i++) {
      for (int j = 0; j < b.size(); j++) {
        for (int k = 0; k < c.size(); k++) {
          for (int l = 0; l < d.size(); l++) {
            int x = (first_w * i) + ((first_w + 1) * j) + ((first_w + 2) * k) +
                    ((first_w + 3) * l);
            if (x > w) continue;
            ans = max(ans, a[i] + b[j] + c[k] + d[l]);
          }
        }
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
