#include <bits/stdc++.h>
using namespace std;
long long func(long long, long long, long long), mem[1005][55][55], lps1[55],
    lps2[55], ret1[55][30], ret2[55][30];
char str[1005], a[55], b[55];
long long as, bs, n;
long long func1(long long, char), func2(long long, char);
void comp();
int main() {
  cin >> str >> a >> b;
  n = strlen(str);
  as = strlen(a);
  bs = strlen(b);
  comp();
  for (int i = n; i >= 0; i--)
    for (int j = 0; j <= as; j++)
      for (int k = 0; k <= bs; k++) {
        if (i == n)
          mem[i][j][k] = 0;
        else if ('a' <= str[i] && str[i] <= 'z') {
          long long ai = 0, bi = 0;
          ai = func1(j, str[i]);
          bi = func2(k, str[i]);
          mem[i][j][k] = mem[i + 1][ai][bi] + (ai / as) - (bi / bs);
        } else {
          mem[i][j][k] = -10000000000LL;
          for (int l = 0; l < 26; l++) {
            long long ai = 0, bi = 0;
            ai = func1(j, l + 'a');
            bi = func2(k, l + 'a');
            mem[i][j][k] =
                max(mem[i + 1][ai][bi] + (ai / as) - (bi / bs), mem[i][j][k]);
          }
        }
      }
  cout << mem[0][0][0];
  return 0;
}
void comp() {
  lps1[0] = lps2[0] = 0;
  long long len = 0, i = 1;
  while (i < as) {
    if (a[i] == a[len]) {
      len++;
      lps1[i] = len;
      i++;
    } else {
      if (len != 0) {
        len = lps1[len - 1];
      } else {
        lps1[i] = 0;
        i++;
      }
    }
  }
  i = 1, len = 0;
  while (i < bs) {
    if (b[i] == b[len]) {
      len++;
      lps2[i] = len;
      i++;
    } else {
      if (len != 0) {
        len = lps2[len - 1];
      } else {
        lps2[i] = 0;
        i++;
      }
    }
  }
  for (int i = 0; i < as + 1; i++)
    for (int j = 0; j < 26; j++) {
      ret1[i][j] = func1(i, j + 'a');
    }
  for (int i = 0; i < bs + 1; i++)
    for (int j = 0; j < 26; j++) {
      ret2[i][j] = func2(i, j + 'a');
    }
}
long long func(long long idx, long long a_, long long b_) {
  if (idx == n) return 0;
  if (mem[idx][a_][b_] != -1) return mem[idx][a_][b_];
  if ('a' <= str[idx] && str[idx] <= 'z') {
    long long ai = 0, bi = 0;
    ai = ret1[a_][str[idx] - 'a'];
    bi = ret2[b_][str[idx] - 'a'];
    return mem[idx][a_][b_] = func(idx + 1, ai, bi) + (ai) / as - (bi) / bs;
  }
  long long ans = -1000000;
  for (int i = 0; i < 26; i++) {
    long long ai = 0, bi = 0;
    ai = ret1[a_][i];
    bi = ret2[b_][i];
    ans = max(func(idx + 1, ai, bi) + (ai) / as - (bi) / bs, ans);
  }
  return mem[idx][a_][b_] = ans;
}
long long func1(long long a_, char c) {
  if (a_ == as) a_ = lps1[as - 1];
  while (1) {
    if (a[a_] == c) return a_ + 1;
    if (a_ != 0)
      a_ = lps1[a_ - 1];
    else if (a_ == 0)
      return 0;
  }
}
long long func2(long long a_, char c) {
  if (a_ == bs) a_ = lps2[bs - 1];
  while (1) {
    if (b[a_] == c) return a_ + 1;
    if (a_ != 0)
      a_ = lps2[a_ - 1];
    else if (a_ == 0)
      return 0;
  }
}
