#include <bits/stdc++.h>
using namespace std;
string code, s, t;
int m[1001][51][51];
vector<int> p_s, p_t;
int mat_s[51][26], mat_t[51][26];
void pd() {
  for (int i = 0; i < code.size() + 1; i++) {
    for (int j = 0; j < s.size() + 1; j++) {
      for (int k = 0; k < t.size() + 1; k++) {
        m[i][j][k] = -0x3f3f3f3f;
      }
    }
  }
  m[0][0][0] = 0;
  for (int i = 0; i < code.size(); i++) {
    for (int j = 0; j < s.size() + 1; j++) {
      for (int k = 0; k < t.size() + 1; k++) {
        for (char c = 'a'; c <= 'z'; c++) {
          if (code[i] == '*' || code[i] == c) {
            int ms = mat_s[j][c - 'a'];
            int mt = mat_t[k][c - 'a'];
            int aux = m[i][j][k];
            if (ms == s.size()) aux++;
            if (mt == t.size()) aux--;
            m[i + 1][ms][mt] = max(m[i + 1][ms][mt], aux);
          }
        }
      }
    }
  }
}
vector<int> pi(string s) {
  vector<int> p(s.size());
  for (int i = 1, j = 0; i < s.size(); i++) {
    while (j and s[j] != s[i]) j = p[j - 1];
    if (s[j] == s[i]) j++;
    p[i] = j;
  }
  return p;
}
void matching_chars(string& s, vector<int> p, int mat[51][26]) {
  vector<int> match;
  for (int i = 0; i < s.size() + 1; i++) {
    for (char c = 'a'; c <= 'z'; c++) {
      int j = i;
      while (j and s[j] != c) j = p[j - 1];
      if (s[j] == c) j++;
      mat[i][c - 'a'] = j;
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> code;
  cin >> s;
  cin >> t;
  p_s = pi(s + '$');
  p_t = pi(t + '$');
  matching_chars(s, p_s, mat_s);
  matching_chars(t, p_t, mat_t);
  pd();
  int max_diff = -0x3f3f3f3f;
  for (int j = 0; j < s.size() + 1; j++) {
    for (int k = 0; k < t.size() + 1; k++) {
      max_diff = max(max_diff, m[code.size()][j][k]);
    }
  }
  cout << max_diff << '\n';
  return 0;
}
