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 class TimeCollector { long count, totalNanos; void addNanos(long nanos) { ++count; totalNanos += nanos; } public String toString() { return count == 0 ? "Empty time collector" : "Average time: " + formatElapsedTimeWithAppropriateUnit(nanosToSeconds(doubleRatio(totalNanos, count))) + " (n=" + count + ")"; } } static String formatElapsedTimeWithAppropriateUnit(double seconds) { if (seconds >= 1) return formatDouble(seconds, 3) + " s"; double ms = seconds*1000; if (ms >= 1) return formatDouble(ms, 3) + " ms"; double us = ms*1000; if (us >= 1) return formatDouble(us, 3) + " µs"; double ns = us*1000; return formatDouble(ns, 3) + " ns"; } static double nanosToSeconds(double nanos) { return nanoSecondsToSeconds(nanos); } static double doubleRatio(double x, double y) { return y == 0 ? 0 : x/y; } static String formatDouble(double d, int digits) { String format = digits <= 0 ? "0" : "0." + rep(digits, '#'); return decimalFormatEnglish(format, d); } static double nanoSecondsToSeconds(double nanos) { return nanos*1e-9; } static String rep(int n, char c) { return repeat(c, n); } static String rep(char c, int n) { return repeat(c, n); } static List rep(A a, int n) { return repeat(a, n); } static List rep(int n, A a) { return repeat(n, a); } static String decimalFormatEnglish(String format, double d) { return new java.text.DecimalFormat(format, new java.text.DecimalFormatSymbols(Locale.ENGLISH)).format(d); } static String repeat(char c, int n) { n = Math.max(n, 0); char[] chars = new char[n]; for (int i = 0; i < n; i++) chars[i] = c; return new String(chars); } static List repeat(A a, int n) { n = Math.max(n, 0); List l = new ArrayList(n); for (int i = 0; i < n; i++) l.add(a); return l; } static List repeat(int n, A a) { return repeat(a, n); } }