1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <algorithm>
//#include <iostream>
#include <numeric>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
//#include <cmath>
#include <set>
#include <map>
using namespace std;

#include "message.h"

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
typedef vector<PII> VPII;

#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b);i>=(e);--i)

#define PB push_back
#define ALL(V) (V).begin(),(V).end()
#define SIZE(V) ((int)(V).size())

#define MP make_pair
#define ST first
#define ND second

#define DBG

#ifdef DBG
	#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
	#define debug(...)
#endif

int __stmp;
#define scanf __stmp=scanf


const int INF = 1000000001;
const int MAX = 100010;
const int MSG_LIMIT = 1000;

char A[MAX], B[MAX];
int n, m;
PII dp[2][MAX];

int main(int argc, char *argv[]) {
	scanf("%d %d", &n, &m);
	scanf("%s %s", A+1, B+1);
	int nodes = NumberOfNodes();
	int id = MyNodeId();
	int stepn = n/nodes + (n % nodes < id);
	int startc = n/nodes * id + min(n % nodes, id);
	int stopc = n/nodes * (id+1) + min(n % nodes, id+1);
	if(startc == n) return 0;
	for(int c=startc;c<=stopc;c++)
		dp[0][c] = PII(c, 0);
	int next_receive_r = 1;
	int denom = 2 * nodes;
	int add = m % denom;
	if(!id) {
		for(int r=1;r<=m;r++)
		{
			bool b = r&1;
			if(r == next_receive_r) {
				next_receive_r += m/denom;
				if(add) {
					next_receive_r++;
					add--;
				}
			}
			dp[b][0] = PII(r, 0);
			for(int c=startc+1;c<=stopc;c++)
			{
				dp[b][c] = min(dp[!b][c], dp[b][c-1]);
				dp[b][c].ST++;
				if(A[c] == B[r]) {
					dp[b][c] = min(dp[b][c], dp[!b][c-1]);
				} else {
					PII t = dp[!b][c-1];
					t.ST++;
					if(A[c] < B[r]) t.ND++;
					dp[b][c] = min(dp[b][c], t);
				}
			}
			if(stopc < n) {
				PutLL(id+1, (((LL)dp[b][stopc].ST)<<32) | dp[b][stopc].ND);
				if(r+1 == next_receive_r) {
					Send(id+1);
				}
			}
		}
	} else {
		for(int r=1;r<=m;r++)
		{
			bool b = r&1;
			if(r == next_receive_r) {
				Receive(id-1);
				next_receive_r += m/denom;
				if(add) {
					next_receive_r++;
					add--;
				}
			}
			LL msg = GetLL(id-1);
			dp[b][startc] = PII(msg>>32, msg&0xffffffffLL);
			for(int c=startc+1;c<=stopc;c++)
			{
				dp[b][c] = min(dp[!b][c], dp[b][c-1]);
				dp[b][c].ST++;
				if(A[c] == B[r]) {
					dp[b][c] = min(dp[b][c], dp[!b][c-1]);
				} else {
					PII t = dp[!b][c-1];
					t.ST++;
					if(A[c] < B[r]) t.ND++;
					dp[b][c] = min(dp[b][c], t);
				}
			}
			if(stopc < n) {
				PutLL(id+1, (((LL)dp[b][stopc].ST)<<32) | dp[b][stopc].ND);
				if(r+1 == next_receive_r) {
					Send(id+1);
				}
			}
		}
	}
	if(stopc == n) {
		printf("%d %d\n", dp[m&1][n].ST, dp[m&1][n].ND);
	}
	return 0;
}