#include <bits/stdc++.h>
#define debug(x) cout << #x << " = " << x << endl
#define REP(i, n) for (Long i = 0; i < (Long)n; i++)
using namespace std;

typedef long long Long;

string x, y;

const int MX = 1005;
bool used[MX][MX][2][2][2];
Long dp[MX][MX][2][2][2];

const Long MOD = 998244353;
Long add(Long a, Long b) {
	if (a + b < MOD) return a + b;
	return a + b - MOD;
}

Long count(Long i, Long j, Long prev, bool left = false, bool right = false, char prevChar = '$') {
	if (i == x.size() && j == y.size()) {
		return left && right;
	}
	Long &ans = dp[i][j][prev][left][right];
	if (used[i][j][prev][left][right]) {
		return ans;
	}
	used[i][j][prev][left][right] = true;
	ans = 0;
	if (left && right) ans++;
	if (i < x.size() && x[i] != prevChar) {
		ans = add(ans, count(i + 1, j, 0, true, right , x[i]));
	}
	if (j < y.size() && y[j] != prevChar) {
		ans = add(ans, count(i, j + 1, 1, left, true, y[j]));
	}
	return ans;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> x >> y;
	
	Long ans = 0;
	for (int l1 = 0; l1 < x.size(); l1++) {
		for (int l2 = 0; l2 < y.size(); l2++) {
			ans = add(ans, count(l1, l2, 0));
		}
	}
	cout << ans << "\n";
	
	return 0;
}
