#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
struct autKMP {
  vector<vector<int> > nxt;
  vector<int> p;
  void process(string& second) {
    for (int i = 1; i < second.size(); i++) {
      int j = p[i - 1];
      while (j > 0 && second[i] != second[j]) {
        j = p[j - 1];
      }
      if (second[i] == second[j]) {
        j++;
      }
      p[i] = j;
    }
  }
  autKMP(string second)
      : nxt(26, vector<int>(second.size() + 1)), p(second.size() + 1) {
    second += '#';
    process(second);
    for (int c = 0; c < 26; c++) {
      for (int i = 0; i < second.size(); i++) {
        if (i > 0 && (c + 'a') != second[i]) {
          nxt[c][i] = nxt[c][p[i - 1]];
        } else {
          nxt[c][i] = i + ((c + 'a') == second[i]);
        }
      }
    }
  }
};
autKMP* autS;
autKMP* autT;
string second, t;
string code;
int dp[1001][51][51];
bool vis[1001][51][51];
int solve(int posAt, int posAutomatoS, int posAutomatoT) {
  int modificador = 0;
  if (posAutomatoS == second.size()) {
    modificador++;
  }
  if (posAutomatoT == t.size()) {
    modificador--;
  }
  if (posAt == code.size()) {
    return modificador;
  }
  if (vis[posAt][posAutomatoS][posAutomatoT]) {
    return dp[posAt][posAutomatoS][posAutomatoT];
  }
  char cAt = code[posAt];
  if (cAt != '*') {
    int ret = modificador + solve(posAt + 1, autS->nxt[cAt - 'a'][posAutomatoS],
                                  autT->nxt[cAt - 'a'][posAutomatoT]);
    vis[posAt][posAutomatoS][posAutomatoT] = true;
    return dp[posAt][posAutomatoS][posAutomatoT] = ret;
  } else {
    int ret = -INF;
    for (int prox = 0; prox < 26; prox++) {
      ret =
          max(ret, modificador + solve(posAt + 1, autS->nxt[prox][posAutomatoS],
                                       autT->nxt[prox][posAutomatoT]));
    }
    vis[posAt][posAutomatoS][posAutomatoT] = true;
    return dp[posAt][posAutomatoS][posAutomatoT] = ret;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> code;
  cin >> second >> t;
  memset(vis, 0, sizeof(vis));
  autS = new autKMP(second);
  autT = new autKMP(t);
  cout << solve(0, 0, 0) << '\n';
  return 0;
}
