#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int getMinTransformOp(char *, int, char *, int, int **);
int /*<<< orphan*/ memset(int **, int, int);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ scanf(char *, int *, char *);
int main(void) {
  int memoTable[1000][1000];
  int lenX, lenY;
  char strX[1000 + 1], strY[1000 + 1];
  while (scanf("%d %s", &lenX, strX) > 0) {
    scanf("%d %s", &lenY, strY);
    memset(memoTable, -1, 1000 * 1000 * sizeof(int));
    printf("%d\n",
           getMinTransformOp(strX, lenX - 1, strY, lenY - 1, memoTable));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3d1100,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x3d0d10(%rbp),%rdx
lea    0xea0(%rip),%rdi
lea    -0x3d0914(%rbp),%rsi
call   1060 <scanf@plt>
cmp    $0x0,%rax
jle    11e5 <main+0xa5>
lea    -0x3d1100(%rbp),%rdx
lea    0xe7c(%rip),%rdi
lea    -0x3d0918(%rbp),%rsi
call   1060 <scanf@plt>
lea    -0x3d0910(%rbp),%rdi
mov    $0xffffffff,%esi
mov    $0x3d0900,%edx
call   1040 <memset@plt>
lea    -0x3d0d10(%rbp),%rdi
mov    -0x3d0914(%rbp),%esi
sub    $0x1,%esi
lea    -0x3d1100(%rbp),%rdx
mov    -0x3d0918(%rbp),%ecx
sub    $0x1,%ecx
lea    -0x3d0910(%rbp),%r8
call   1050 <getMinTransformOp@plt>
mov    %eax,%esi
lea    0xe2b(%rip),%rdi
call   1030 <printf@plt>
jmp    1152 <main+0x12>
xor    %eax,%eax
add    $0x3d1100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3d10f8,%rsp
lea    0xea8(%rip),%rdi
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rdx
call   1060 <scanf@plt>
test   %rax,%rax
jle    11fb <main+0xbb>
lea    0xe89(%rip),%r15
lea    0x400(%rsp),%r12
lea    0x7f0(%rsp),%r13
lea    0x10(%rsp),%rbx
lea    0xe73(%rip),%rbp
lea    0x8(%rsp),%r14
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
lea    0xc(%rsp),%rsi
mov    %r12,%rdx
call   1060 <scanf@plt>
mov    %r13,%rdi
mov    $0xffffffff,%esi
mov    $0x3d0900,%edx
call   1040 <memset@plt>
mov    0x8(%rsp),%esi
add    $0xffffffff,%esi
mov    0xc(%rsp),%ecx
add    $0xffffffff,%ecx
mov    %rbx,%rdi
mov    %r12,%rdx
mov    %r13,%r8
call   1050 <getMinTransformOp@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1060 <scanf@plt>
test   %rax,%rax
jg     11a0 <main+0x60>
xor    %eax,%eax
add    $0x3d10f8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%d %s\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1000 x [1000 x i32]]
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1001 x i8]
%6 = alloca [1001 x i8]
store i32 0, i32* %1
br label %7
7: ; preds = %11, %0
%8 = getelementptr inbounds [1001 x i8], [1001 x i8]* %5, i64 0, i64 0
%9 = call i64 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %3, i8* %8)
%10 = icmp sgt i64 %9, 0
br i1 %10, label %11, label %27
11: ; preds = %7
%12 = getelementptr inbounds [1001 x i8], [1001 x i8]* %6, i64 0, i64 0
%13 = call i64 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %4, i8* %12)
%14 = getelementptr inbounds [1000 x [1000 x i32]], [1000 x [1000 x i32]]* %2, i64 0, i64 0
%15 = bitcast [1000 x i32]* %14 to i32**
%16 = call i32 @memset(i32** %15, i32 -1, i32 4000000)
%17 = getelementptr inbounds [1001 x i8], [1001 x i8]* %5, i64 0, i64 0
%18 = load i32, i32* %3
%19 = sub nsw i32 %18, 1
%20 = getelementptr inbounds [1001 x i8], [1001 x i8]* %6, i64 0, i64 0
%21 = load i32, i32* %4
%22 = sub nsw i32 %21, 1
%23 = getelementptr inbounds [1000 x [1000 x i32]], [1000 x [1000 x i32]]* %2, i64 0, i64 0
%24 = bitcast [1000 x i32]* %23 to i32**
%25 = call i32 @getMinTransformOp(i8* %17, i32 %19, i8* %20, i32 %22, i32** %24)
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %25)
br label %7
27: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"%d %s\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca [1000 x [1000 x i32]]
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1001 x i8]
%5 = alloca [1001 x i8]
%6 = bitcast [1000 x [1000 x i32]]* %1 to i8*
%7 = bitcast i32* %2 to i8*
%8 = bitcast i32* %3 to i8*
%9 = getelementptr inbounds [1001 x i8], [1001 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [1001 x i8], [1001 x i8]* %5, i64 0, i64 0
%11 = call i64 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %2, i8* %9)
%12 = icmp sgt i64 %11, 0
br i1 %12, label %13, label %26
13: ; preds = %0
%14 = bitcast [1000 x [1000 x i32]]* %1 to i32**
br label %15
15: ; preds = %13, %15
%16 = call i64 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %3, i8* %10)
%17 = call i32 @memset(i32** %14, i32 -1, i32 4000000)
%18 = load i32, i32* %2
%19 = add nsw i32 %18, -1
%20 = load i32, i32* %3
%21 = add nsw i32 %20, -1
%22 = call i32 @getMinTransformOp(i8* %9, i32 %19, i8* %10, i32 %21, i32** %14)
%23 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = call i64 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %2, i8* %9)
%25 = icmp sgt i64 %24, 0
br i1 %25, label %15, label %26
26: ; preds = %15, %0
ret i32 0
}