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 static x30_pkg.x30_util.DynamicObject;
import java.awt.geom.*;
import java.text.*;
import java.text.NumberFormat;
import java.util.TimeZone;
class main {
abstract static class AbstractMatrix implements Matrix {
AbstractMatrix() {}
int w, h;
AbstractMatrix(int w, int h) {
this.h = h;
this.w = w;}
public int getWidth() { return w; }
public int getHeight() { return h; }
public String toString() {
return flexLines(
roundBracket(w+"x"+h),
countIteratorToList(y -> str(getLine(y)), getHeight()));
}
public void set(int x, int y, A a) { unimplemented(); }
}
static String flexLines(Object... l) {
return lines(flattenIterablesAndArrays(ll(l)));
}
static String roundBracket(String s) {
return "(" + s + ")";
}
static String roundBracket(Object s) {
return roundBracket(str(s));
}
static List countIteratorToList(int b) { return countIteratorToList(0, b); }
static List countIteratorToList(int a, int b) {
return asList(countIterator(a, b));
}
static List countIteratorToList(int b, IF1 f) { return countIteratorToList(0, b, f); }
static List countIteratorToList(int a, int b, IF1 f) {
return asList(countIterator(a, b, f));
}
static List countIteratorToList(int a, int b, int step) {
return asList(countIterator(a, b, step));
}
static List countIteratorToList(double a, double b, double step, IF1 f) {
return asList(countIterator(a, b, step, f));
}
static List countIteratorToList(double a, double b, double step) {
return asList(countIterator(a, b, step));
}
static List countIteratorToList(IF1 f, double a, double b, double step) {
return asList(countIterator(f, a, b, step));
}
static List countIteratorToList(IF1 f, int b) { return countIteratorToList(f, 0, b); }
static List countIteratorToList(IF1 f, int a, int b) {
return asList(countIterator(f, a, b));
}
static String str(Object o) {
return o == null ? "null" : o.toString();
}
static String str(char[] c) {
return new String(c);
}
static String str(char[] c, int offset, int count) {
return new String(c, offset, count);
}
// lineNr starts at 1
static String getLine(String s, int lineNr) {
return safeGet(toLines(s), lineNr-1);
}
static int getHeight(Component c) {
return c == null ? 0 : (int) swingCall(c, "getHeight");
}
static RuntimeException unimplemented() {
throw fail("TODO");
}
static RuntimeException unimplemented(String msg) {
throw fail("TODO: " + msg);
}
static RuntimeException unimplemented(Object obj) {
throw fail("TODO: implement method in " + className(obj));
}
static String lines(Iterable lines) { return fromLines(lines); }
static String lines(Object[] lines) { return fromLines(asList(lines)); }
static List lines(String s) { return toLines(s); }
// convenience map call
static String lines(Iterable l, IF1 f) {
return mapToLines(l, f);
}
static List flattenIterablesAndArrays(Iterable a) {
List l = new ArrayList();
for (Object x : a)
if (x instanceof Iterable)
l.addAll(flattenIterablesAndArrays((Iterable) x));
else if (x instanceof Iterator)
l.addAll(flattenIterablesAndArrays(asList((Iterator) x)));
else if (x instanceof Object[])
l.addAll(flattenIterablesAndArrays(asList((Object[]) x)));
else
l.add(x);
return l;
}
static List ll(A... a) {
ArrayList l = new ArrayList(a.length);
if (a != null) for (A x : a) l.add(x);
return l;
}
// unclear semantics as to whether return null on null
static ArrayList asList(A[] a) {
return a == null ? new ArrayList() : new ArrayList(Arrays.asList(a));
}
static ArrayList asList(int[] a) {
if (a == null) return null;
ArrayList l = emptyList(a.length);
for (int i : a) l.add(i);
return l;
}
static ArrayList asList(long[] a) {
if (a == null) return null;
ArrayList l = emptyList(a.length);
for (long i : a) l.add(i);
return l;
}
static ArrayList asList(float[] a) {
if (a == null) return null;
ArrayList l = emptyList(a.length);
for (float i : a) l.add(i);
return l;
}
static ArrayList asList(double[] a) {
if (a == null) return null;
ArrayList l = emptyList(a.length);
for (double i : a) l.add(i);
return l;
}
static ArrayList asList(short[] a) {
if (a == null) return null;
ArrayList l = emptyList(a.length);
for (short i : a) l.add(i);
return l;
}
static ArrayList asList(Iterator it) {
ArrayList l = new ArrayList();
if (it != null)
while (it.hasNext())
l.add(it.next());
return l;
}
// disambiguation
static ArrayList asList(IterableIterator s) {
return asList((Iterator) s);
}
static ArrayList asList(Iterable s) {
if (s instanceof ArrayList) return (ArrayList) s;
ArrayList l = new ArrayList();
if (s != null)
for (A a : s)
l.add(a);
return l;
}
static ArrayList asList(Enumeration e) {
ArrayList l = new ArrayList();
if (e != null)
while (e.hasMoreElements())
l.add(e.nextElement());
return l;
}
static ArrayList asList(ReverseChain c) {
return c == null ? emptyList() : c.toList();
}
static List asList(Pair p) {
return p == null ? null : ll(p.a, p.b);
}
static IterableIterator countIterator(int b) { return countIterator(0, b); }
static IterableIterator countIterator(int a, int b) {
return countIterator_exclusive(a, b);
}
static IterableIterator countIterator(int b, IF1 f) { return countIterator(0, b, f); }
static IterableIterator countIterator(int a, int b, IF1 f) {
return countIterator_exclusive(a, b, f);
}
static IterableIterator countIterator(int a, int b, int step) {
return countIterator_exclusive_step(a, b, step);
}
static IterableIterator countIterator(double a, double b, double step, IF1 f) {
return countIterator_exclusive_step(a, b, step, f);
}
static IterableIterator countIterator(double a, double b, double step) {
return countIterator_exclusive_step(a, b, step);
}
static IterableIterator countIterator(IF1 f, double a, double b, double step) {
return countIterator(a, b, step, f);
}
static IterableIterator countIterator(IF1 f, int b) { return countIterator(f, 0, b); }
static IterableIterator countIterator(IF1 f, int a, int b) {
return countIterator_exclusive(a, b, f);
}
static IterableIterator countIterator(List l) {
return countIterator(l(l));
}
static A safeGet(List l, int i) {
return i >= 0 && i < l(l) ? l.get(i) : null;
}
static IterableIterator toLines(File f) {
return linesFromFile(f);
}
static List toLines(String s) {
List lines = new ArrayList();
if (s == null) return lines;
int start = 0;
while (true) {
int i = toLines_nextLineBreak(s, start);
if (i < 0) {
if (s.length() > start) lines.add(s.substring(start));
break;
}
lines.add(s.substring(start, i));
if (s.charAt(i) == '\r' && i+1 < s.length() && s.charAt(i+1) == '\n')
i += 2;
else
++i;
start = i;
}
return lines;
}
static int toLines_nextLineBreak(String s, int start) {
int n = s.length();
for (int i = start; i < n; i++) {
char c = s.charAt(i);
if (c == '\r' || c == '\n')
return i;
}
return -1;
}
static Object swingCall(final Object o, final String method, final Object... args) {
return swing(new F0