func_code_string: #include <bits/stdc++.h>   using namespace std;   long long int mod = 1e9 + 7;   long long int inf = 9 * 1e18;   const long long maxn = 2e5 + 100;   long long pow(long long a, long long b) {     if (b < 0) return 0LL;     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a;       a = a * a;       b >>= 1;     }     return ans;   }   long long binpow(long long a, long long b, long long m) {     if (b < 0) return 0LL;     if (a <= 0) return 0LL;     a %= m;     long long ans = 1LL;     while (b) {       if (b & 1) ans = ans * a % m;       a = a * a % m;       b >>= 1;     }     return ans;   }   long long modinv(long long n) { return binpow(n, mod - 2, mod); }   int gcdExtended(int a, int b, int *x, int *y) {     if (a == 0) {       *x = 0, *y = 1;       return b;     }     int x1, y1;     int gcd = gcdExtended(b % a, a, &x1, &y1);     *x = y1 - (b / a) * x1;     *y = x1;     return gcd;   }   void modInverse(int a, int m) {     int x, y;     int g = gcdExtended(a, m, &x, &y);     if (g != 1)       cout <<  Inverse doesn t exist ;     else {       int res = (x % m + m) % m;       cout <<  Modular multiplicative inverse is   << res;     }   }   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second < b.second);   }   const long long N = 1e7 + 5;   long long sp[N];   void sieve(long long N) {     for (long long i = 1; i < N; i++) sp[i] = i;     for (long long i = 2; i < N; i++) {       if (sp[i] == i) {         for (long long j = i * i; j < N; j += i) {           if (sp[j] == j) sp[j] = i;         }       }     }   }   void solve() {     string s1;     cin >> s1;     long long k;     cin >> k;     long long n = s1.size();     map<char, char> ma;     for (int i = 0; i < k; i++) {       char u, x;       cin >> u >> x;       ma[u] = x;       ma[x] = u;     }     long long c1 = 0, c2 = 0;     long long ans = 0;     long long j = 0;     for (int i = 0; i < n; i++) {       c1 = 1;       c2 = 0;       char a = s1[i];       char b = ma[a];       for (j = i + 1; j < n; j++) {         if (s1[j] == a)           c1++;         else if (s1[j] == b)           c2++;         else           break;       }       ans += min(c1, c2);       i = j - 1;     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int t;     t = 1;     while (t--) {       solve();     }     return 0;   }   