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.*;
import static x30_pkg.x30_util.DynamicObject;
class main {
static void forEachWithPosition(Matrix m, IVF3 f) {
if (m == null || f == null) return;
int w = m.getWidth(), h = m.getHeight();
for (int y = 0; y < h; y++)
for (int x = 0; x < w; x++)
f.get(x, y, m.get(x, y));
}
interface Matrix {
public int getWidth();
public int getHeight();
public A get(int x, int y);
public void set(int x, int y, A a);
default Pt size() { return pt(getWidth(), getHeight()); }
default int nCells() { return getWidth()*getHeight(); }
default List getLine(int y) {
return new RandomAccessAbstractList() {
public int size() { return getWidth(); }
public A get(int x) {
return Matrix.this.get(x, y);
}
public A set(int x, A val) {
A old = Matrix.this.get(x, y);
Matrix.this.set(x, y, val);
return old;
}
};
}
}
static interface IVF3 {
void get(A a, B b, C c);
}
static class Pt implements Comparable {
int x, y;
Pt() {}
Pt(Point p) {
x = p.x;
y = p.y;
}
Pt(int x, int y) {
this.y = y;
this.x = x;}
Point getPoint() {
return new Point(x, y);
}
public boolean equals(Object o) {
return o instanceof Pt && x == ((Pt) o).x && y == ((Pt) o).y;
}
public int hashCode() {
return boostHashCombine(x, y);
}
// compare in scan order
public int compareTo(Pt p) {
if (y != p.y) return cmp(y, p.y);
return cmp(x, p.x);
}
public String toString() {
return x + ", " + y;
}
}
abstract static class RandomAccessAbstractList extends AbstractList implements RandomAccess {
}
static Pt pt(int x, int y) {
return new Pt(x, y);
}
static Pt pt(int x) {
return new Pt(x, x);
}
static int getWidth(Component c) {
return c == null ? 0 : (int) swingCall(c, "getWidth");
}
static int getHeight(Component c) {
return c == null ? 0 : (int) swingCall(c, "getHeight");
}
// lineNr starts at 1
static String getLine(String s, int lineNr) {
return safeGet(toLines(s), lineNr-1);
}
static int boostHashCombine(int a, int b) {
return a ^ (b + 0x9e3779b9 + (a << 6) + (a >> 2));
}
static int cmp(Number a, Number b) {
return a == null ? b == null ? 0 : -1 : cmp(a.doubleValue(), b.doubleValue());
}
static int cmp(double a, double b) {
return a < b ? -1 : a == b ? 0 : 1;
}
static int cmp(int a, int b) {
return a < b ? -1 : a == b ? 0 : 1;
}
static int cmp(long a, long b) {
return a < b ? -1 : a == b ? 0 : 1;
}
static int cmp(Object a, Object b) {
if (a == null) return b == null ? 0 : -1;
if (b == null) return 1;
return ((Comparable) a).compareTo(b);
}
static Object swingCall(final Object o, final String method, final Object... args) {
return swing(new F0