import java.util.*;
import java.util.zip.*;
import java.util.List;
import java.util.regex.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
import java.util.concurrent.locks.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.table.*;
import java.io.*;
import java.net.*;
import java.lang.reflect.*;
import java.lang.ref.*;
import java.lang.management.*;
import java.security.*;
import java.security.spec.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.imageio.*;
import java.math.*;
class main {
static void test_levenWithSwapsSubstringIC() {
testFunctionValues_twoArgs("levenWithSwapsSubstringIC",
pair("xabcdeyy", "abdce"), 1,
pair("eeeacexyz", "abcde"), 2,
pair("pppppab", "ba"), 1,
pair("ppab", "xy"), 2,
pair("aabx", "bAx"), 1,
pair("lxcb", "xbc"), 1);
}
// params = pair(inputs), output, pair(inputs), output, ...
static void testFunctionValues_twoArgs(Object function, Object... params) {
for (int i = 0; i+1 < l(params); i += 2) {
Pair in = (Pair) (params[i]);
Object expected = params[i+1];
print(function + "(" + in + ")");
assertEqualsVerbose(expected, callFWithVarArgs(function, in.a, in.b));
}
}
static int levenWithSwapsSubstringIC(String haystack, String needle) {
int m = strL(needle), n = strL(haystack);
// base cases
if (containsIgnoreCase(haystack, needle)) return 0;
int[] vx = new int[n+1], v0 = new int[n+1], v1 = new int[n+1];
for (int i = 0; i < m; i++) { // iterate over needle
v1[0] = i+1;
for (int j = 0; j < n; j++) { // iterate over haystack
int cost = neqic(needle.charAt(i), haystack.charAt(j)) ? 1 : 0;
int d = min3(v1[j]+1, // insertion
v0[j+1]+1, // deletion
v0[j]+cost); // substitution
if (i > 0 && j > 0 && equalsIgnoreCase(needle.charAt(i), haystack.charAt(j-1)) && equalsIgnoreCase(needle.charAt(i-1), haystack.charAt(j)))
d = min(d, vx[j-1] + 1); // transposition
v1[j+1] = d;
}
int[] temp = vx;
vx = v0;
v0 = v1;
v1 = temp;
}
return minOfIntArray(v0);
}
static Pair pair(A a, B b) {
return new Pair(a, b);
}
static Pair pair(A a) {
return new Pair(a, a);
}
static int l(Object[] a) { return a == null ? 0 : a.length; }
static int l(boolean[] a) { return a == null ? 0 : a.length; }
static int l(byte[] a) { return a == null ? 0 : a.length; }
static int l(short[] a) { return a == null ? 0 : a.length; }
static int l(long[] a) { return a == null ? 0 : a.length; }
static int l(int[] a) { return a == null ? 0 : a.length; }
static int l(float[] a) { return a == null ? 0 : a.length; }
static int l(double[] a) { return a == null ? 0 : a.length; }
static int l(char[] a) { return a == null ? 0 : a.length; }
static int l(Collection c) { return c == null ? 0 : c.size(); }
static int l(Iterator i) { return iteratorCount_int_close(i); } // consumes the iterator && closes it if possible
static int l(Map m) { return m == null ? 0 : m.size(); }
static int l(CharSequence s) { return s == null ? 0 : s.length(); }
static long l(File f) { return f == null ? 0 : f.length(); }
static int l(Object o) {
return o == null ? 0
: o instanceof String ? l((String) o)
: o instanceof Map ? l((Map) o)
: o instanceof Collection ? l((Collection) o)
: o instanceof Object[] ? l((Object[]) o)
: o instanceof boolean[] ? l((boolean[]) o)
: o instanceof byte[] ? l((byte[]) o)
: o instanceof char[] ? l((char[]) o)
: o instanceof short[] ? l((short[]) o)
: o instanceof int[] ? l((int[]) o)
: o instanceof float[] ? l((float[]) o)
: o instanceof double[] ? l((double[]) o)
: o instanceof long[] ? l((long[]) o)
: (Integer) call(o, "size");
}
static volatile StringBuffer local_log = new StringBuffer(); // not redirected
static volatile Appendable print_log = local_log; // might be redirected, e.g. to main bot
// in bytes - will cut to half that
static volatile int print_log_max = 1024*1024;
static volatile int local_log_max = 100*1024;
static boolean print_silent = false; // total mute if set
static Object print_byThread_lock = new Object();
static volatile ThreadLocal