import java.util.*;
class Ideone {
public static class Sprite {
public static List<Sprite> sprites = null;
public int age = 0;
private boolean removed = false;
public Sprite() {
sprites.add(this);
}
public boolean render() {
if (removed)
return false;
age++;
if (age > 30)
dispose();
return true;
}
public void dispose() {
removed = true;
}
}
private static List
<Sprite
> sprites
= Collections.
synchronizedList(new ArrayList
<Sprite
>());
public static void main
(String[] args
) { Sprite.sprites = sprites;
new Sprite();
new Sprite();
for (int i = 0; i < 60; i++)
render();
}
public static void render() {
synchronized(sprites) {
Iterator<Sprite> iterator = sprites.iterator();
while (iterator.hasNext())
if (!iterator.next().render())
iterator.remove();
}
}
}
aW1wb3J0IGphdmEudXRpbC4qOwoKY2xhc3MgSWRlb25lIHsKICAgIAogICAgcHVibGljIHN0YXRpYyBjbGFzcyBTcHJpdGUgewogICAgICAgIHB1YmxpYyBzdGF0aWMgTGlzdDxTcHJpdGU+IHNwcml0ZXMgPSBudWxsOwogICAgICAgIHB1YmxpYyBpbnQgYWdlID0gMDsKICAgICAgICAKICAgICAgICBwcml2YXRlIGJvb2xlYW4gcmVtb3ZlZCA9IGZhbHNlOwogICAgICAgIAogICAgICAgIHB1YmxpYyBTcHJpdGUoKSB7CiAgICAgICAgICAgIHNwcml0ZXMuYWRkKHRoaXMpOwogICAgICAgIH0KICAgICAgICAKICAgICAgICBwdWJsaWMgYm9vbGVhbiByZW5kZXIoKSB7CiAgICAgICAgCWlmIChyZW1vdmVkKQogICAgICAgIAkgICAgcmV0dXJuIGZhbHNlOwogICAgICAgICAgICBhZ2UrKzsKICAgICAgICAgICAgaWYgKGFnZSA+IDMwKQogICAgICAgICAgICAgICAgZGlzcG9zZSgpOwogICAgICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgICB9CiAgICAgICAgCiAgICAgICAgcHVibGljIHZvaWQgZGlzcG9zZSgpIHsKICAgICAgICAgICAgcmVtb3ZlZCA9IHRydWU7CiAgICAgICAgfQogICAgfQogICAgCiAgICBwcml2YXRlIHN0YXRpYyBMaXN0PFNwcml0ZT4gc3ByaXRlcyA9IENvbGxlY3Rpb25zLnN5bmNocm9uaXplZExpc3QobmV3IEFycmF5TGlzdDxTcHJpdGU+KCkpOwoKICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHsKICAgICAgICBTcHJpdGUuc3ByaXRlcyA9IHNwcml0ZXM7CiAgICAgICAgCiAgICAgICAgbmV3IFNwcml0ZSgpOwogICAgICAgIG5ldyBTcHJpdGUoKTsKICAgICAgICAKICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IDYwOyBpKyspCiAgICAgICAgICAgIHJlbmRlcigpOwogICAgICAgIAogICAgfQogICAgCiAgICBwdWJsaWMgc3RhdGljIHZvaWQgcmVuZGVyKCkgewogICAgICAgIHN5bmNocm9uaXplZChzcHJpdGVzKSB7CiAgICAgICAgICAgIEl0ZXJhdG9yPFNwcml0ZT4gaXRlcmF0b3IgPSBzcHJpdGVzLml0ZXJhdG9yKCk7CiAgICAgICAgICAgIHdoaWxlIChpdGVyYXRvci5oYXNOZXh0KCkpCiAgICAgICAgICAgICAgICBpZiAoIWl0ZXJhdG9yLm5leHQoKS5yZW5kZXIoKSkKICAgICAgICAgICAgICAgICAgICBpdGVyYXRvci5yZW1vdmUoKTsKICAgICAgICB9CiAgICB9Cn0K