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>
const int INF = 1e9;
const long long INFLL = 1e18;
const int NMAX = 120;
const int MMAX = 100005;
const int KMAX = 1005;
const int MOD = 1e9 + 7;
using namespace std;
static const int di[] = {-1, 0, 1, -1, 1, -1, 0, 1};
static const int dj[] = {-1, -1, -1, 0, 0, 1, 1, 1};
struct edge {
  int to, cost;
};
void debug(const char *format, ...) {}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}
long long BSearch(long long _begin, long long _end, bool (*f)(int)) {
  long long mid;
  while (_end - _begin > 1LL) {
    mid = (_begin + _end) / 2LL;
    if (f(mid)) {
      debug("BSearch: f(%d) == true\n", mid);
      _end = mid;
    } else {
      debug("BSearch: f(%d) == false\n", mid);
      _begin = mid;
    }
  }
  return _end;
}
long long N, M, K, A[NMAX], B[NMAX], C, D, E;
long long dp[NMAX][3 * NMAX][NMAX];
string S;
vector<int> v;
long long ans = 0;
void solve() {
  dp[0][0][0] = 0;
  for (long long i = 0; i < N; ++i) {
    for (long long j = 0; j <= i * 3; ++j) {
      for (long long k = 0; k <= i; ++k) {
        if (dp[i][j][k] != -1) {
          dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][j][k]);
          long long jj = j + A[i] - A[0];
          dp[i + 1][jj][k + 1] =
              max(dp[i + 1][jj][k + 1], dp[i][j][k] + (long long)B[i]);
        }
      }
    }
  }
  for (long long i = 0; i <= N; ++i) {
    for (long long j = 0; j + A[0] * i <= M; ++j) {
      ans = max(ans, dp[N][j][i]);
    }
  }
}
void debug() {
  for (int i = 0; i <= N; ++i) {
    do {
    } while (0);
    for (int j = 0; j <= 3 * i; ++j) {
      for (int k = 0; k <= i; ++k) {
        cout << dp[i][j][k] << " ";
      }
      cout << endl;
    }
  }
}
void answer() { cout << ans << endl; }
int main(int argc, char const *argv[]) {
  Fill(dp, -1);
  cin >> N >> M;
  for (int i = 0; i < N; ++i) {
    scanf("%lld%lld", &A[i], &B[i]);
  }
  solve();
  answer();
  return 0;
}
