Problem p00040 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
int main() {
  string thth[2] = {"this", "that"};
  string ths[2][26][26];
  for (int i = 0; i < 2; i++) {
    for (int ia = 0; ia < 26; ia++) {
      for (int ib = 0; ib < 26; ib++) {
        ths[i][ia][ib] = "    ";
      }
    }
  }
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 2; j++) {
      thth[j][i] -= 'a';
    }
  }
  for (int ia = 0; ia < 26; ia++) {
    for (int ib = 0; ib < 26; ib++) {
      for (int j = 0; j < 4; j++) {
        for (int k = 0; k < 2; k++) {
          ths[k][ia][ib][j] = (thth[k][j] * ia + ib) % 26;
        }
      }
    }
  }
  int n;
  cin >> n;
  string line, ins;
  getline(cin, line);
  for (int ii = 0; ii < n; ii++) {
    int aa = 0, bb = 0;
    vector<string> strs;
    getline(cin, line);
    stringstream ss(line);
    while (ss >> ins) {
      strs.push_back(ins);
    }
    for (int i = 0; i < strs.size(); i++) {
      for (int j = 0; j < strs[i].size(); j++) {
        strs[i][j] -= 'a';
      }
    }
    for (int i = 0; i < strs.size(); i++) {
      if (strs[i].size() == 4) {
        for (int ia = 0; ia < 26; ia++) {
          for (int ib = 0; ib < 26; ib++) {
            for (int j = 0; j < 2; j++) {
              if (strs[i] == ths[j][ia][ib]) {
                aa = ia;
                bb = ib;
                goto TO;
              }
            }
          }
        }
      }
    }
  TO:
    char cry[26];
    for (int i = 0; i < 26; i++) {
      cry[(i * aa + bb) % 26] = i;
    }
    for (int i = 0; i < strs.size(); i++) {
      for (int j = 0; j < strs[i].size(); j++) {
        strs[i][j] = cry[strs[i][j]] + 'a';
      }
    }
    for (int i = 0; i < strs.size() - 1; i++) {
      cout << strs[i] << ' ';
    }
    cout << strs[strs.size() - 1] << endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  string thth[2] = {"this", "that"};
  string ths[2][26][26];
  for (int i = 0; i < 2; i++) {
    for (int ia = 0; ia < 26; ia++) {
      for (int ib = 0; ib < 26; ib++) {
        ths[i][ia][ib] = "    ";
      }
    }
  }
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 2; j++) {
      thth[j][i] -= 'a';
    }
  }
  for (int ia = 0; ia < 26; ia++) {
    for (int ib = 0; ib < 26; ib++) {
      for (int j = 0; j < 4; j++) {
        for (int k = 0; k < 2; k++) {
          ths[k][ia][ib][j] = (thth[k][j] * ia + ib) % 26;
        }
      }
    }
  }
  int aa = 0, bb = 0;
  for (int ii = 0; ii < n; ii++) {
    vector<string> strs;
    string ins;
    while (cin >> ins) {
      strs.push_back(ins);
    }
    for (int i = 0; i < strs.size(); i++) {
      for (int j = 0; j < strs[i].size(); j++) {
        strs[i][j] -= 'a';
      }
    }
    for (int i = 0; i < strs.size(); i++) {
      if (strs[i].size() == 4) {
        for (int ia = 0; ia < 26; ia++) {
          for (int ib = 0; ib < 26; ib++) {
            for (int j = 0; j < 2; j++) {
              if (strs[i] == ths[j][ia][ib]) {
                aa = ia;
                bb = ib;
                goto TO;
              }
            }
          }
        }
      }
    }
  TO:
    char cry[26];
    for (int i = 0; i < 26; i++) {
      cry[(i * aa + bb) % 26] = i;
    }
    for (int i = 0; i < strs.size(); i++) {
      for (int j = 0; j < strs[i].size(); j++) {
        strs[i][j] = cry[strs[i][j]] + 'a';
      }
    }
    for (int i = 0; i < strs.size() - 1; i++) {
      cout << strs[i] << ' ';
    }
    cout << strs[strs.size() - 1] << endl;
  }
}