#include "message.h"
#include <algorithm>
#include <iostream>
#include <cassert>
#include <sstream>
using namespace std;
#define make(type, x) type x; cin>>x;
#define make2(type, x, y) type x, y; cin>>x>>y;
#define make3(type, x, y, z) type x, y, z; cin>>x>>y>>z;
#define MP make_pair
template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
typedef pair<int, int> PII;
const int N = 1e5 + 5;
const int H = 1e4 + 5;
const int W = 1e2 + 5;
char a[N], b[N];
pair<int, int> dp[H][W];
int main() {
make2(int, row, col);
int inst_num = min(NumberOfNodes(), row);
long long start_row = 1 + MyNodeId() * row / inst_num;
long long end_row = ((MyNodeId() + 1) * row) / inst_num;
if (MyNodeId() >= inst_num) {
return 0;
}
for (int i = 1; i <= row; i++) {
cin>>a[i];
}
for (int i = 1; i <= col; i++) {
cin>>b[i];
}
int computed_cols = 0;
int cols_in_package = 102;
while (computed_cols < col) {
int my_hei = end_row - start_row + 1;
for (int i = 0; i <= my_hei; i++) {
if (computed_cols == 0) {
dp[i][0] = MP(i + start_row - 1, 0);
} else {
dp[i][0] = dp[i][cols_in_package];
}
}
int inst = MyNodeId();
int new_cols = min(cols_in_package, col - computed_cols);
if (inst > 0) {
Receive(inst - 1);
}
for (int c = 1; c <= new_cols; c++) {
if (inst > 0) {
int fir = GetInt(inst - 1);
int sec = GetInt(inst - 1);
dp[0][c] = MP(fir, sec);
} else {
dp[0][c] = MP(computed_cols + c, 0);
}
for (int r = 1; r <= my_hei; r++) {
int i = r - 1 + start_row;
int j = computed_cols + c;
PII left = dp[r][c - 1];
left.first++;
PII right = dp[r - 1][c];
right.first++;
PII diag = dp[r - 1][c - 1];
if (a[i] != b[j]) {
diag.first++;
}
if (a[i] < b[j]) {
diag.second++;
}
dp[r][c] = min(min(left, right), diag);
if (i == row && j == col) {
cout<<dp[r][c].first<<" "<<dp[r][c].second<<endl;
}
}
if (inst < inst_num - 1) {
PutInt(inst + 1, dp[my_hei][c].first);
PutInt(inst + 1, dp[my_hei][c].second);
}
}
computed_cols += new_cols;
if (inst < inst_num - 1) {
Send(inst + 1);
}
}
return 0;
}
I2luY2x1ZGUgIm1lc3NhZ2UuaCIKI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y2Fzc2VydD4KI2luY2x1ZGUgPHNzdHJlYW0+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgbWFrZSh0eXBlLCB4KSB0eXBlIHg7IGNpbj4+eDsKI2RlZmluZSBtYWtlMih0eXBlLCB4LCB5KSB0eXBlIHgsIHk7IGNpbj4+eD4+eTsKI2RlZmluZSBtYWtlMyh0eXBlLCB4LCB5LCB6KSB0eXBlIHgsIHksIHo7IGNpbj4+eD4+eT4+ejsKI2RlZmluZSBNUCBtYWtlX3BhaXIKdGVtcGxhdGU8Y2xhc3MgQz4gdm9pZCBtaW5pKEMmYTQsIEMgYjQpe2E0PW1pbihhNCwgYjQpOyB9CnRlbXBsYXRlPGNsYXNzIEM+IHZvaWQgbWF4aShDJmE0LCBDIGI0KXthND1tYXgoYTQsIGI0KTsgfQp0ZW1wbGF0ZTxjbGFzcyBUMSwgY2xhc3MgVDI+Cm9zdHJlYW0mIG9wZXJhdG9yPDwgKG9zdHJlYW0gJm91dCwgcGFpcjxUMSwgVDI+IHBhaXIpIHsgcmV0dXJuIG91dCA8PCAiKCIgPDwgcGFpci5maXJzdCA8PCAiLCAiIDw8IHBhaXIuc2Vjb25kIDw8ICIpIjt9CnR5cGVkZWYgcGFpcjxpbnQsIGludD4gUElJOwpjb25zdCBpbnQgTiA9IDFlNSArIDU7CmNvbnN0IGludCBIID0gMWU0ICsgNTsKY29uc3QgaW50IFcgPSAxZTIgKyA1OwpjaGFyIGFbTl0sIGJbTl07CgpwYWlyPGludCwgaW50PiB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7IGMgPD0gbmV3X2NvbHM7IGMrKykgewogICAgICBpZiAoaW5zdCA+IDApIHsKICAgICAgICBpbnQgZmlyID0gR2V0SW50KGluc3QgLSAxKTsKICAgICAgICBpbnQgc2VjID0gR2V0SW50KGluc3QgLSAxKTsKICAgICAgICBkcFswXVtjXSA9IE1QKGZpciwgc2VjKTsKICAgICAgfSBlbHNlIHsKICAgICAgICBkcFswXVtjXSA9IE1QKGNvbXB1dGVkX2NvbHMgKyBjLCAwKTsKICAgICAgfQogICAgICBmb3IgKGludCByID0gMTsgciA8PSBteV9oZWk7IHIrKykgewogICAgICAgIGludCBpID0gciAtIDEgKyBzdGFydF9yb3c7CiAgICAgICAgaW50IGogPSBjb21wdXRlZF9jb2xzICsgYzsKICAgICAgICAKICAgICAgICBQSUkgbGVmdCA9IGRwW3JdW2MgLSAxXTsKICAgICAgICBsZWZ0LmZpcnN0Kys7CiAgICAgICAgUElJIHJpZ2h0ID0gZHBbciAtIDFdW2NdOwogICAgICAgIHJpZ2h0LmZpcnN0Kys7CiAgICAgICAgUElJIGRpYWcgPSBkcFtyIC0gMV1bYyAtIDFdOwogICAgICAgIGlmIChhW2ldICE9IGJbal0pIHsgCiAgICAgICAgICBkaWFnLmZpcnN0Kys7CiAgICAgICAgfQogICAgICAgIGlmIChhW2ldIDwgYltqXSkgewogICAgICAgICAgZGlhZy5zZWNvbmQrKzsKICAgICAgICB9CiAgICAgICAgZHBbcl1bY10gPSBtaW4obWluKGxlZnQsIHJpZ2h0KSwgZGlhZyk7CiAgICAgICAgaWYgKGkgPT0gcm93ICYmIGogPT0gY29sKSB7CiAgICAgICAgICBjb3V0PDxkcFtyXVtjXS5maXJzdDw8IiAiPDxkcFtyXVtjXS5zZWNvbmQ8PGVuZGw7CiAgICAgICAgfQogICAgICB9CiAgICAgIGlmIChpbnN0IDwgaW5zdF9udW0gLSAxKSB7CiAgICAgICAgUHV0SW50KGluc3QgKyAxLCBkcFtteV9oZWldW2NdLmZpcnN0KTsKICAgICAgICBQdXRJbnQoaW5zdCArIDEsIGRwW215X2hlaV1bY10uc2Vjb25kKTsKICAgICAgfQogICAgfQogICAgY29tcHV0ZWRfY29scyArPSBuZXdfY29sczsKICAgIGlmIChpbnN0IDwgaW5zdF9udW0gLSAxKSB7CiAgICAgIFNlbmQoaW5zdCArIDEpOwogICAgfQogIH0KICAgICAgCiAgICAgIAogIHJldHVybiAwOwp9Cg==