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 java.util.function.*;
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 java.awt.geom.*;
import javax.imageio.*;
import java.math.*;
import java.time.Duration;
import java.lang.invoke.VarHandle;
import java.lang.invoke.MethodHandles;
import static x30_pkg.x30_util.DynamicObject;
import java.awt.geom.*;
import java.text.*;
import java.text.NumberFormat;
import java.util.TimeZone;
class main {
static PatchworkImage patchworkBufferedImagesHorizontally(List> imagesAndValues, Object... __) {
if (empty(imagesAndValues)) return null;
int spacing = optPar("spacing", __, imageMergeSpacing());
var images = pairsA(imagesAndValues);
int w = intSum(mapMethod("getWidth", images))+(l(images)-1)*spacing;
int h = intMax(mapMethod("getHeight", images));
PatchworkImage < A > out = new PatchworkImage<>(w, h);
int x = 0;
for (var imageAndValue : imagesAndValues) {
BufferedImage img = imageAndValue.a;
int y = (h-img.getHeight())/2;
out.addPatch(img, x, y, imageAndValue.b);
x += img.getWidth() + spacing;
}
return out;
}
static boolean empty(Collection c) { return c == null || c.isEmpty(); }
static boolean empty(Iterable c) { return c == null || !c.iterator().hasNext(); }
static boolean empty(CharSequence s) { return s == null || s.length() == 0; }
static boolean empty(Map map) { return map == null || map.isEmpty(); }
static boolean empty(Object[] o) { return o == null || o.length == 0; }
static boolean empty(BitSet bs) { return bs == null || bs.isEmpty(); }
static boolean empty(Object o) {
if (o instanceof Collection) return empty((Collection) o);
if (o instanceof String) return empty((String) o);
if (o instanceof Map) return empty((Map) o);
if (o instanceof Object[]) return empty((Object[]) o);
if (o instanceof byte[]) return empty((byte[]) o);
if (o == null) return true;
throw fail("unknown type for 'empty': " + getType(o));
}
static boolean empty(Iterator i) { return i == null || !i.hasNext(); }
static boolean empty(double[] a) { return a == null || a.length == 0; }
static boolean empty(float[] a) { return a == null || a.length == 0; }
static boolean empty(int[] a) { return a == null || a.length == 0; }
static boolean empty(long[] a) { return a == null || a.length == 0; }
static boolean empty(byte[] a) { return a == null || a.length == 0; }
static boolean empty(short[] a) { return a == null || a.length == 0; }
static boolean empty(IMultiMap mm) { return mm == null || mm.size() == 0; }
static boolean empty(File f) { return getFileSize(f) == 0; }
static boolean empty(Rect r) { return !(r != null && r.w != 0 && r.h != 0); }
static boolean empty(Chain c) { return c == null; }
static boolean empty(AppendableChain c) { return c == null; }
static A optPar(ThreadLocal tl, A defaultValue) {
A a = tl.get();
if (a != null) {
tl.set(null);
return a;
}
return defaultValue;
}
static A optPar(ThreadLocal tl) {
return optPar(tl, null);
}
static Object optPar(Object[] params, String name) {
return optParam(params, name);
}
static Object optPar(String name, Object[] params) {
return optParam(params, name);
}
static Object optPar(String name, Map params) {
return optParam(name, params);
}
static A optPar(Object[] params, String name, A defaultValue) {
return optParam(params, name, defaultValue);
}
static A optPar(String name, Object[] params, A defaultValue) {
return optParam(params, name, defaultValue);
}
static int imageMergeSpacing = 5;
static int imageMergeSpacing() {
return imageMergeSpacing;
}
static void imageMergeSpacing(int pixels) {
imageMergeSpacing = pixels;
}
static List pairsA(Collection> l) {
return firstOfPairs(l);
}
static int intSum(Collection c, String field) {
int sum = 0;
for (Object o : unnull(c))
sum += toInt(getOpt(o, field));
return sum;
}
static int intSum(Iterable l) {
int sum = 0;
for (Integer i : unnull(l))
if (i != null) sum += i;
return sum;
}
static int intSum(int... l) {
int sum = 0;
for (int i : unnull(l))
sum += i;
return sum;
}
static List mapMethod(Object[] l, final String methodName) {
return map(l, new F1