import java.util.*;
interface function<T> { public void func (T x); }
abstract class Foo { int n; abstract int foo(); }
class Bar extends Foo { Bar (int x) { n = x; } int foo() { return n + 1; } }
class Baz extends Foo { Baz (int x) { n = x; } int foo() { return n * 2; } }
class Main
{
public static void runClosure (function<Integer> f) {
for (int i = 0; i < 100; i++) { f.func(i); }
}
public static void main
(String args
[]) { final Foo[] x = new Bar[]{ new Bar(0) };
runClosure(new function<Integer>() {
System.
out.
println(x
[0].
foo()); x[0] = n % 2 == 0 ? new Bar(x[0].foo()) : new Baz(x[0].foo());
}
});
}
}
aW1wb3J0IGphdmEudXRpbC4qOwoKaW50ZXJmYWNlIGZ1bmN0aW9uPFQ+IHsgcHVibGljIHZvaWQgZnVuYyAoVCB4KTsgfQoKYWJzdHJhY3QgY2xhc3MgRm9vIHsgaW50IG47IGFic3RyYWN0IGludCBmb28oKTsgfQpjbGFzcyBCYXIgZXh0ZW5kcyBGb28geyBCYXIgKGludCB4KSB7IG4gPSB4OyB9IGludCBmb28oKSB7IHJldHVybiBuICsgMTsgfSB9CmNsYXNzIEJheiBleHRlbmRzIEZvbyB7IEJheiAoaW50IHgpIHsgbiA9IHg7IH0gaW50IGZvbygpIHsgcmV0dXJuIG4gKiAyOyB9IH0KCmNsYXNzIE1haW4KewogICAgcHVibGljIHN0YXRpYyB2b2lkIHJ1bkNsb3N1cmUgKGZ1bmN0aW9uPEludGVnZXI+IGYpIHsKICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IDEwMDsgaSsrKSB7IGYuZnVuYyhpKTsgfQogICAgfQogICAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4gKFN0cmluZyBhcmdzW10pIHsKICAgICAgICBmaW5hbCBGb29bXSB4ID0gbmV3IEJhcltdeyBuZXcgQmFyKDApIH07CiAgICAgICAgcnVuQ2xvc3VyZShuZXcgZnVuY3Rpb248SW50ZWdlcj4oKSB7CiAgICAgICAgICAgIHB1YmxpYyB2b2lkIGZ1bmMoSW50ZWdlciBuKSB7CiAgICAgICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oeFswXS5mb28oKSk7CiAgICAgICAgICAgICAgICB4WzBdID0gbiAlIDIgPT0gMCA/IG5ldyBCYXIoeFswXS5mb28oKSkgOiBuZXcgQmF6KHhbMF0uZm9vKCkpOwogICAgICAgICAgICB9CiAgICAgICAgfSk7CiAgICB9Cn0=