[Question]
  [
### Input:
Two strings without newlines or whitespaces.
### Output:
Both input strings on separate lines, with spaces where necessary† for one of the two strings. And a third line with the characters `A`, `R`, `M` and , representing *added*, *removed*, *modified*, and *unchanged*.
† We add spaces to either the top ***or*** bottom input string (if we have to). The goal of this challenge is to output with the least amount of changes (`ARM`) possible, also known as the [Levenshtein distance](https://people.cs.pitt.edu/~kirk/cs1501/Pruhs/Spring2006/assignments/editdistance/Levenshtein%20Distance.htm).
### Example:
Let's say the input strings are `ABCDEF` and `AFBECD`, then the output would be this:
```
A B CDEF
AFBECD  
 A A  RR
```
Here are some other possible invalid outputs as example (and there are a lot more):
```
ABCDEF
AFBECD
 MMMMM
A BCDEF
AFBECD 
 A MMMR
AB CDEF
AFBECD 
 MAMMMR
ABC DEF
AFBECD 
 MMAMMR
ABC  DEF
AFBECD  
 MMAA RR
ABCDEF 
AFB ECD
 MMR MA
 AB CDEF   // This doesn't make much sense,
AFBECD     // but it's to show leading spaces are also allowed
AM A  RR
```
None of these have only four changes however, so only `A B CDEF\nAFBECD \n A A RR` is a valid output for this challenge.
### Challenge rules:
* You can assume the input strings won't contain any new-lines or spaces.
* The two input strings can be of different lengths.
* One of the two input strings should remain as is, except for optional leading/trailing spaces.
* If your languages doesn't support anything besides ASCII, you can assume the input will only contain printable ASCII characters.
* The input and output format are flexible. You can have three separate Strings, a String array, a single String with new-lines, 2D character array, etc.
* You are allowed to use something else instead of `ARM`, but state what you've used (i.e. `123`, or `abc.`, etc.)
* If more than one valid output is possible with the same amount of changes (`ARM`), you can choose whether to output one of the possible outputs or all of them.
* Leading and trailing spaces are optional:
```
A B CDEF
AFBECD
 A A  RR
```
or
```
"A B CDEF\nAFBECD\n A A  RR"
                 ^
                 Note there are no spaces here
```
### General rules:
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest answer in bytes wins.  
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
* [Standard rules apply](https://codegolf.meta.stackexchange.com/questions/2419/default-for-code-golf-program-function-or-snippet/2422#2422) for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters, full programs. Your call.
* [Default Loopholes](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) are forbidden.
* If possible, please add a link with a test for your code.
* Also, please add an explanation if necessary.
### Test cases:
```
In: "ABCDEF" & "AFBECD"
Output (4 changes):
A B CDEF
AFBECD  
 A A  RR                  
In: "This_is_an_example_text" & "This_is_a_test_as_example"
Possible output (13 changes):
This_is_an       _example_text
This_is_a_test_as_example     
         MAAAAAAA        RRRRR
In: "AaAaABBbBBcCcCc" & "abcABCabcABC"
Possible output (10 changes):
AaAaABBbBBcCcCc
 abcABCab cABC 
R MM  MMMR MM R
In: "intf(){longr=java.util.concurrent.ThreadLocalRandom.current().nextLong(10000000000L);returnr>0?r%2:2;}" & "intf(){intr=(int)(Math.random()*10);returnr>0?r%2:2;}"
Possible output (60 changes):
intf(){longr=java.util.concurrent.ThreadLocalRandom.current().nextLong(10000000000L);returnr>0?r%2:2;}
intf(){i ntr=(      i    n      t)(M  ath.r   andom        ()*         10          );returnr>0?r%2:2;}
       MR M  MRRRRRR RRRR RRRRRR MMMRR MMMMRRR     RRRRRRRR  MRRRRRRRRR  RRRRRRRRRR 
In: "ABCDEF" & "XABCDF"
Output (2 changes):
 ABCDEF
XABCD F 
A    R 
In: "abC" & "ABC"
Output (2 changes):
abC
ABC
MM 
```
  
[Answer]
# JavaScript (ES6), ~~413~~ ... ~~343~~ 342 bytes
*Saved 5 bytes by tweaking the loop indices, as suggested by @KevinCruijssen*
Takes input as 2 strings in currying syntax. Returns an array of 3 strings.
```
b=>a=>{m=[];x=a.length;y=b.length;for(i=j=0,c=d='';i<=y;c+=R='R')m[i]=[[c,i++]];for(;j++<x;)m[i=0][j]=[d+=A='A',j];for(;i<y;i++)for(j=0;j<x;)[C]=m[[X,S]=m[i][j],[Y,I]=m[i+1][j],[Z,D]=m[i][++j],Q=[Z+R,D+1],i+1][j]=b[i]==a[j-1]?[X+' ',S]:S<I?D<S?Q:[X+'M',S+1]:D<I?Q:[Y+A,I+1];return[(g=s=>C.replace(/./g,c=>c==s?' ':b[i++],i=0))(A),g(R,b=a),C]}
```
### Test cases
```
let f =
b=>a=>{m=[];x=a.length;y=b.length;for(i=j=0,c=d='';i<=y;c+=R='R')m[i]=[[c,i++]];for(;j++<x;)m[i=0][j]=[d+=A='A',j];for(;i<y;i++)for(j=0;j<x;)[C]=m[[X,S]=m[i][j],[Y,I]=m[i+1][j],[Z,D]=m[i][++j],Q=[Z+R,D+1],i+1][j]=b[i]==a[j-1]?[X+' ',S]:S<I?D<S?Q:[X+'M',S+1]:D<I?Q:[Y+A,I+1];return[(g=s=>C.replace(/./g,c=>c==s?' ':b[i++],i=0))(A),g(R,b=a),C]}
console.log(f('ABCDEF')('AFBECD').join`\n`);
console.log(f('This_is_an       _example_text')('This_is_a_test_as_example').join`\n`);
console.log(f('AaAaABBbBBcCcCc')('abcABCabcABC').join`\n`);
console.log(f("intf(){longr=java.util.concurrent.ThreadLocalRandom.current().nextLong(10000000000L);returnr>0?r%2:2;}")("intf(){intr=(int)(Math.random()*10);returnr>0?r%2:2;}").join`\n`);
console.log(f('ABCDEF')('XABCDF').join`\n`);
```
### Less golfed
```
b => a => {
  m = []; x = a.length; y = b.length;
  // initialize the leftmost column and the topmost row
  for(i = j = 0, c = d = ''; i <= y; c += R = 'R')
    m[i] = [[c, i++]];
  for(; j++ < x;)
    m[i = 0][j] = [d += A = 'A', j];
  // walk through the Levenshtein matrix
  for(; i < y; i++)
    for(j = 0; j < x;)
      [C] = m[                                // C = current string, once updated
        [X, S] = m[i][j],                     // substitution
        [Y, I] = m[i + 1][j],                 // insertion
        [Z, D] = m[i][++j],                   // deletion
        Q = [Z + R, D + 1],                   // precomputed update for deletion
        i + 1
      ][j] =
        b[i] == a[j - 1] ?
          [X + ' ', S]                        // unchanged character
        :
          S < I ?
            D < S ? Q : [X + 'M', S + 1]      // deletion or substitution
          :
            D < I ? Q : [Y + A, I + 1];       // deletion or insertion
  return [
    // g = helper function to format the output strings by inserting spaces
    (g = s => C.replace(/./g, c => c == s ? ' ' : b[i++], i = 0))(A),
    g(R, b = a),
    // final modification string, picked from the last visited cell
    C
  ]
}
```
### Example
Below is the initial matrix for ***b = "foo"*** and ***a = "ok"***:
```
//                     'o'           'k'
[ [ [ '',    0 ], [ 'A',   1 ], [ 'AA',  2 ] ],
  [ [ 'R',   1 ],  (undefined),  (undefined) ],  // 'f'
  [ [ 'RR',  2 ],  (undefined),  (undefined) ],  // 'o'
  [ [ 'RRR', 3 ],  (undefined),  (undefined) ] ] // 'o'
```
and here is the final matrix after all iterations:
```
//                     'o'           'k'
[ [ [ '',    0 ], [ 'A',   1 ], [ 'AA',  2 ] ],
  [ [ 'R',   1 ], [ 'M',   1 ], [ 'MA',  2 ] ],  // 'f'
  [ [ 'RR',  2 ], [ 'R ',  1 ], [ 'R A', 2 ] ],  // 'o'
  [ [ 'RRR', 3 ], [ 'RR ', 2 ], [ 'R M', 2 ] ] ] // 'o'
```
The final modification string along with the Levenshtein distance are stored in the bottom-right cell.
[Answer]
# [Haskell](https://www.haskell.org/), ~~192~~ ~~181~~ ~~174~~ ~~161~~ ~~158~~ ~~150~~ ~~147~~ ~~143~~ 1581 bytes
```
e@(a:r)&f@(b:s)=snd$maximum[([1|' '<-s!!2],s)|s<-z(z(:))[a:" R",' ':b:"A",a:b:last("M":[" "|a==b])][r&f,e&s,r&s]]
x&y=[x,y,"RA"!!(0^length x)<$x++y]
z=zipWith
```
[Try it online!](https://tio.run/##jVBRa4NADH7Pr8iOYpXqWMuejlqqtsJgsuEeNhAfztauMrXFU7Cu@@3urBVa2rIl3CWQL1/yZc34VxjHdR1OZUYzRVpN5YByRefpspewMkqKxJO94b6P/bHG7@5GvsqVPR9rlVzJVFE8Rgm6RBV1GlBiEJWJGDOey8Qh1CNI9kzXA1/xvUxaqaHE1Uzivg@ltNO9Ut2p5WCwm0yIS3yo9Cravkf5uk5YlKKOyw0Cbov8Lc@eU7zHIo2jNOTYQ2KY1mxuE5REaptza0ZA025hmXDTDExzYQk/NLFgISjan/xjyEeT2zeRLLDaXRo2@NbgKaVXl3wpcsGA8iMu1iz9DLlCwUATGyC0IBSiDeHounhhcGT@U9LrhvMoiEPcHCcOH05HnvcDds3YBAQXHQfFcw6JCxd6unt0ekYn5Nji4IBBG4VAYW63@9mtrvULAIgiiMmg/dS/ "Haskell – Try It Online") Example usage: `"ABCDEF" & "AFBECD"`. Returns a list of three strings. This is an extension of my recursive solution to the ordinary [Levenshtein distance question](https://codegolf.stackexchange.com/a/142370/56433).
### Explanation:
To compute the minimal modifications to get from `"xyz"` to `"yw"`, we focus on the first character of both strings. There are three possibilities:
* *Remove:* Drop `x` from the first string and recursively compute the modifications to get from `"yz"` to `"yw"`. This yields the three lines `["yz","yw"," M"]`. Add `x` to the first one, a space to the second one and `R` to the third one. We get 
```
xyz
yw
R M
```
* *Add:* Drop `y` from the second string and compute `"xyz" & "w"`, which returns the result `["xyz","w","MRR"]`. We need to add a space on the first line, `y` to the second and `A` to the third line: 
```
 xyz
yw
AMRR
```
* *Modified/Unchanged:* We can combine those two cases because both require to drop the first character of both strings and compute the minimal modifications between the remaining strings: `"yz" & "w"`. To the result `["yz","w","MR"]`, we add `x` on he first and `y` on the second line. Only for the last line we need to differentiate whether the initial characters are the same. If they are the same, a space is added to the third line, otherwise (as in this case because `x \= y`) an `M` is added: 
```
xyz
yw
MMR
```
From those three candidates, we need to find the one with the fewest modifications. This is equivalent to having the most spaces on the third line. Therefore we convert each candidate `s` (a list of three strings) to a tuple `([1|' '<-s!!2],s)`, where `s` appears as second component and the first component is a list with as many elements as there are spaces in the third line of `s` (`s!!2` because of 0-indexing). As list element `1` is used, but the actual element is irrelevant as long as it is the same for all candidates.
Altogether, this yields the list of tuples 
```
[([1],["xyz"," yw","R M"]),([],[" xyz","yw","AMRR"]),([],["xyz","yw","MMR"])]
```
The build-in `maximum` selects the largest element of this list, where tuples are compared lexicographically, that is component-wise from left to right. As `[1]` is larger than `[]`, the first tuple is selected, and `snd` returns the second of component, that is the list of lines, of the tuple.
---
1 +15 bytes to fix a bug where `A`-changes at the end of a string would be displayed as `R`-changes
[Answer]
# [Python 2](https://docs.python.org/2/), ~~548~~ ~~536~~ ~~484~~ ~~5001~~ ~~488~~ ~~447~~ ~~3812~~ ~~373~~ ~~371~~ ~~357~~ 350 bytes
```
s,t=input()
n,m=len(s),len(t)
r=range
L=[[(j,'RA'[i<1]*j)for j in r(i,m-~i)]for i in r(n+1)]
for i in r(n):
 for j in r(m):M,R=L[i][j:j+2];A=L[i+1][j];v,V=min(A,R,M);x=('AR'[v in R],'M_'[s[i]==t[j]])[v in M];_=M;X=eval(x)[1]+x;L[i+1][j+1]=v+(x<'_'),X
for i in r(len(X)):s=s[:i]+' '*('B'>X[i])+s[i:];t=t[:i]+' '*('R'==X[i])+t[i:]
print s+'\n'+t+'\n'+X
```
[Try it online!](https://tio.run/##bVBbb5swFH7nV6BIk32Ch0K0J6g7Qdo@hRdUTZGohVziNkZgIuNETNP217PD6CUPw@gc@bucz/bxpzv0Zn2p@73idrFYXAbmuDbHk6PgGdbxVhk6AJuaA89yK82r8ra8LGnDSJGSUt9EYtnAS2/9xtfGt1Sz7usfDWKC9AyZIALhXQMQe/6Vp4M4ZwXfllqUTdwEa5Gk0y6IcC@SM/vBO21oygqWQzJyStKClOfJXAhG8oqUA3o5dygXMDO5SCqeJzuuzrKlI5SRCMbkfSoWfg7oeEMqAmx3fbrpujuAeOBDGWsREJ8sKcnI7Q4zIMCkWCQOsz7JgnA@s25ivaPVxvlDQJ4MCdzcdpcZxYf2PDWq2p8efvntQtJsc3f/QBhJH7L7zR3xyONBDxX@0lRqlN2xVZVTo0PJB4PA4Co5vAvQlUpcWfacZfUGF6rlc43D54oCjH@h8KvtzavljTzL8OR0G9a9qU/WKuPCx4NVcr/ta9kW0uz7LnxjKIQGT7BFK41WH98WEqvcyRp7u/puv6zjdfIbc9@CsFlOsQLNpTuE9t9ICsto9T/fXw "Python 2 – Try It Online")
Uses `'ARM_'` instead of `'ARM '`
Works by building up the Levenshtein matrix, ~~and then traversing backwards to find the operations~~. Now builds the operation-string at the same time as the Levenshtein matrix, as in [Arnauld's JS answer](https://codegolf.stackexchange.com/a/144482/38592)
1: More bytes, as it did not work if the first string was a single character.
2: Switched to building the combinations in the Levenshtein matrix.
[Answer]
# [Python 2](https://docs.python.org/2/), 310 bytes
```
from difflib import*
a,b=input()
U,j=[],' '
for g,s,t,x,y in SequenceMatcher(0,a,b).get_opcodes():
	g,Y,T=g[0],y-x,t-s
	z,A,B=Y-T,a[s:t],b[x:y]
	if'q'<g:U+=[A+z*j,B+j*-z,'M'*min(T,Y)+'A'*z+'R'*-z]
	if'e'==g:U+=[A,B,j*Y]
	if'i'==g:U+=[j*Y,B,'A'*Y]
	if'e'>g:U+=[A,j*T,'R'*T]
for e in[0,1,2]:print''.join(U[e::3])
```
[Try it online!](https://tio.run/##RY@xboMwEIbn8BQoy4E5orTdrLpSsmdpyYAsC5HEEKNgE@xIwMtTp2la6abvv@9Ofze6s9Gv81z1pg1Pqqou6hCqtjO9I0GJB6Z0d3NRHOyxYVwghBBUpg9rtOhwwDFUOvyS15vUR7kr3fEs@2iN3oxXtXSF6Y7mJG0U02BRY44Zq/la4JgO6FIbLCbc4JblaYYlt9QJPPCBjiJYqAqu8F7TfcL4JplIg9ukIemEsAPSKh1lmMcJbIBMCXyCTx6SBMZ@LdxiQ/IHVn/YIx/cxfxpfDyFhmR4P5aJn5LSl@NrfMFXQbteaQewaoz/veeS0jcRz/MyOytb@Cl1IYey7S6ycHJwS/xPPLCuKO1zYfkN "Python 2 – Try It Online")
Using `difflib.SequenceMatcher` that computes an alignment between two strings 
[Answer]
# Mathematica, 250 ~~256~~ ~~259~~ ~~384~~ bytes
~0.00035 seconds for the java code case.
```
(i=o=p="";a=Array;r=StringLength;If[Length@#>0,g=#&@@#;h=#[[2]];u=r@g;v=r@h;i=i<>g;o=o<>h;w=Abs[v-u];k=a[" "&,w];If[u<v,i=i<>k,o=o<>k];p=p<>a["M"&,u~Min~v];p=p<>a[If[u>v,"R","A"]&,w],i=i<>#;o=o<>#;p=p<>a[" "&,r@#]]&/@SequenceAlignment[#,#2];{i,o,p})&
```
Usage: `f["ABCDE", "ABCDF"]`
[Try it online!](https://tio.run/##PY/LasMwEEV/pUhgWlApZCuPkfMihQRKsxSzUFJZFq5lR5EdSml@3ZUSyOYuhnPPzLQq1LpVwR7VVMH0bIEQ3qXoUygovVc/3MM@eOvMVjsTav5eyY1WX4ICwNaeAzNAMyEor4FKOUPkA3hh@Biz5hZsXpho7fKi5hcoD2c5vg7IG1CSPJGMXTAph3xkN7ZhN7bBeESfFxHaRWi47qy7jo9hahQjI5@EkZJgstzr9L6KPtpphRcUMXsTe30atDvq8tsa12oXJGV0hvzXso71fy/Z9BEfDbKSpJwvlqt1sq/nq8WSIE7/ "Wolfram Language (Mathematica) – Try It Online")
The code is based on a fact that `SequenceAlignment` works by default on 
> 
> With the default setting SimilarityRules->Automatic, each match
>  between two elements contributes 1 to the total similarity score,
>  while each mismatch, insertion, or deletion contributes -1.
> 
> 
> 
Namely, the scoring is calculated by `M`, `A` and `R`, accordingly.
Example:
[![example](https://i.stack.imgur.com/Wak6u.png)](https://i.stack.imgur.com/Wak6u.png)
[Answer]
# [D](https://dlang.org/), ~~351~~ 345 bytes
-6 bytes thanx to KevinCruijssen 
```
string f(string a,string b){import std.algorithm;string x,y,z;size_t i,j,k;foreach(c;levenshteinDistanceAndPath(a,b)[1]){final switch(c)with(EditOp){case none:x~=a[i++];y~=b[j++];z~=" ";break;case substitute:x~=a[i++];y~=b[j++];z~="M";break;case insert:x~=" ";y~=b[j++];z~="A";break;case remove:x~=a[i++];y~=" ";z~="R";}}return x~"\n"~y~"\n"~z;}
```
[Try it online!](https://tio.run/##dVJdb5swFH3fr0BIk@wVoaSPtdgE@XhKtanqw6SsigyY4BSuI9ukJBH89fSS0KpZiw2@V77nHNvHTk8nY7WEtZORPuFen8T0KMut0tYxNvV5sVZa2rxkfbn29t6BGXkQK@tIb@M9s0xpwZOcJKwQOwEmt0LCVBrLIREhpH@4zQn3YrocP9FjJoEXjnmRtqNQjDmZpdL@3tJjwo1wQIG4q9uAL@XNzRPbt0G83HTZoQ1cx2UxrvbMzlBTxcZKW9lhwv0VQYIR2nbgTukaGV4htSjV7j/ZjtMhH1zWNFrYSoNTt@4/cNv9JRxYc9opmToll0Do8ZuD7YOd@EvFzrMvaKsogGTEDaPJdDZ3PTecR7PJ1KVnMfoJ95hLs8KPw0rUvNwWeAeitkh8r@CEsStu3gCDWiHHHkVxFCUT7KjB4wQ3chkHaRJshucqFKx1sOE77ldWFn6iIKm0FmD9xxxNTBcq4cUDh1SVfl8h1Afc7QKpZDx6bwvKLlbqn6Nf@vvt3S1rcDf9Qhh0QHCk5B6fka/PkoT@GI@@4g2e9s3hv102H8TxeNJdw0cDmtMr "D – Try It Online")
]