#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
string s;
struct aho_corasick {
  struct out_node {
    int keyword;
    out_node *next;
    out_node(int k, out_node *n) : keyword(k), next(n) {}
  };
  struct go_node {
    map<char, go_node *> next;
    int out;
    go_node *fail;
    go_node() {
      out = 0;
      fail = NULL;
    }
  };
  map<pair<int, go_node *>, int> mem;
  go_node *go;
  aho_corasick(vector<string> keywords) {
    go = new go_node();
    int kat = 0;
    for (auto k = (keywords).begin(); k != (keywords).end(); ++k) {
      go_node *cur = go;
      for (auto c = (*k).begin(); c != (*k).end(); ++c)
        cur = cur->next.find(*c) != cur->next.end()
                  ? cur->next[*c]
                  : (cur->next[*c] = new go_node());
      if (kat == 0)
        cur->out++;
      else
        cur->out--;
      kat++;
    }
    queue<go_node *> q;
    for (auto a = (go->next).begin(); a != (go->next).end(); ++a)
      q.push(a->second);
    while (!q.empty()) {
      go_node *r = q.front();
      q.pop();
      for (auto a = (r->next).begin(); a != (r->next).end(); ++a) {
        go_node *s = a->second;
        q.push(s);
        go_node *st = r->fail;
        while (st && st->next.find(a->first) == st->next.end()) st = st->fail;
        if (!st) st = go;
        s->fail = st->next[a->first];
        if (s->fail) {
          s->out += s->fail->out;
        }
      }
    }
  }
  int dp(int at, go_node *cur = NULL) {
    if (!cur) cur = go;
    if (at == s.size()) {
      return 0;
    }
    pair<int, go_node *> st(at, cur);
    if (mem.find(st) != mem.end()) {
      return mem[st];
    }
    int mx = -INF;
    for (char c = 'a'; c <= 'z'; c++) {
      if (s[at] != '*' && s[at] != c) continue;
      go_node *nxt = cur;
      while (nxt && nxt->next.find(c) == nxt->next.end()) nxt = nxt->fail;
      if (!nxt) nxt = go;
      nxt = nxt->next[c];
      if (!nxt) nxt = go;
      mx = max(mx, nxt->out + dp(at + 1, nxt));
    }
    return mem[st] = mx;
  }
};
int main() {
  string a, b;
  cin >> s >> a >> b;
  aho_corasick ac({a, b});
  cout << ac.dp(0) << endl;
  return 0;
}
