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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <map>
#include <cstdio>
#include <iomanip>
#include <sstream>
#include <iostream>
#include <cstring>
#define REP(i,x,v)for(int i=x;i<=v;i++)
#define REPD(i,x,v)for(int i=x;i>=v;i--)
#define FOR(i,v)for(int i=0;i<v;i++)
#define FORE(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define REMIN(x,y) (x)=min((x),(y))
#define REMAX(x,y) (x)=max((x),(y))
#define pb push_back
#define sz size()
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define IN(x,y) ((y).find((x))!=(y).end())
#define un(v) v.erase(unique(ALL(v)),v.end())
#define LOLDBG
#ifdef LOLDBG
#define DBG(vari) cerr<<#vari<<" = "<<vari<<endl;
#define DBG2(v1,v2) cerr<<(v1)<<" - "<<(v2)<<endl;
#else
#define DBG(vari)
#define DBG2(v1,v2)
#endif
#define CZ(x) scanf("%d",&(x));
#define CZ2(x,y) scanf("%d%d",&(x),&(y));
#define CZ3(x,y,z) scanf("%d%d%d",&(x),&(y),&(z));
#define ALL(x) (x).begin(),(x).end()
#define tests int dsdsf;cin>>dsdsf;while(dsdsf--)
#define testss int dsdsf;CZ(dsdsf);while(dsdsf--)
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
template<typename T,typename TT> ostream &operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
template<typename T> ostream &operator<<(ostream &s,vector<T> t){s<<"{";FOR(i,t.size())s<<t[i]<<(i==t.size()-1?"":",");return s<<"}"<<endl; }
typedef unsigned int uint;
#include "message.h"


char a[120003],b[120003];
int A,B;
int D;


pii lewo[11111];
pii prawo[11111];
pii gora[11111];
pii dol[11111];
pii Wyn;
bool swapped;

inline int pyt(int i,int j)
{
    if (a[i]==b[j]) return 0;
    if (swapped)
	{
		if (a[i]<b[j]) return 1;
		else return -1;
	}
	if (a[i]<b[j]) return -1;
	else return 1;
}

void wal(int a0,int b0)
{
    prawo[0]=gora[D];
    int as=(a0-1)*D;
    int bs=(b0-1)*D;
    REP(i,1,D)
    {
        dol[0]=lewo[i];
        REP(j,1,D)
        {
            if (a[as+i]==b[bs+j]) dol[j]=gora[j-1];
            else
            {
                if (pyt(as+i,bs+j)==-1) dol[j]=mp(gora[j-1].fi+1,gora[j-1].se+1);
                else dol[j]=mp(gora[j-1].fi+1,gora[j-1].se);
            }
            REMIN(dol[j],mp(gora[j].fi+1,gora[j].se));
			REMIN(dol[j],mp(dol[j-1].fi+1,dol[j-1].se));
			if (as+i==A && bs+j==B) printf("%d %d\n",dol[j].fi,dol[j].se);
        }
        prawo[i]=dol[D];
        REP(j,0,D) gora[j]=dol[j];
    }
}

int main()
{
    CZ2(A,B);
    scanf("%s",a+1);
    scanf("%s",b+1);
    /*A=100000;
    B=210;
    FOR(i,A+1) a[i]='a'+rand()%5;
    FOR(i,B+1) b[i]='a'+rand()%5;
    */
	swapped=0;
	int m=NumberOfNodes();
	int myid=MyNodeId();
	if (A>B)
	{
		swapped=1;
		swap(A,B);
		FOR(i,max(A,B)+10) swap(a[i],b[i]);
	}
	D=(A/m)+1;
	D=max(D,211);
    int ma=(myid)*D;
    if (ma>=A) return 0;
    int j=1;
    while(1)
	{
		int mb=(j-1)*D;
		if (mb>=B) break;
		if (j==1)
		{
            REP(i1,0,D) lewo[i1]=mp(ma+i1,0);
		}
		else
		{
            REP(i1,0,D) lewo[i1]=prawo[i1];
		}
		if (myid==0)
		{
            REP(j1,0,D) gora[j1]=mp(mb+j1,0);
		}
		else
		{
            Receive(myid-1);
            REP(j1,0,D)
            {
                gora[j1].fi=GetInt(myid-1);
                gora[j1].se=GetInt(myid-1);
            }
		}
		wal(myid+1,j);
		if (ma+D<A)
		{
            REP(j1,0,D)
            {
                PutInt(myid+1,dol[j1].fi);
                PutInt(myid+1,dol[j1].se);
            }
            Send(myid+1);
		}

		j++;
	}
    return 0;
}