import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.function.Consumer;
import java.util.stream.Stream;

class Ideone {
	public static void main(final String[] args) throws java.lang.Exception {
		Leaf.main(args);
	}

	public static class Leaf {
	  public static void main(final String[] args) throws ExecutionException, InterruptedException {
	    leaf(new CompletableFuture<Runnable>(), Leaf::main).get().run();
	  }
	
	  private void yes(final CompletableFuture<Runnable> future) {
	    future.complete(() -> {});
	    future.thenRun(() -> {
	      Thread.dumpStack();
	      System.out.println("Hello, world!");
	    });
	  }
	
	  public static void main(final CompletableFuture<Runnable> future) {
	    leaf(() -> leaf(future, new Leaf()::leaf));
	  }
	
	  private void leaf(final CompletableFuture<Runnable> future) {
	    leaf(() -> new $().leaf(future));
	  }
	
	  class $ {
	    private void leaf(final CompletableFuture<Runnable> future) {
	      Leaf.leaf(() -> new $$().leaf(future, x -> Leaf.this.yes(future)));
	    }
	  }
	
	  class $$ {
	    private void leaf(final CompletableFuture<Runnable> future, final Consumer<CompletableFuture<Runnable>> runnable) {
	      Leaf.leaf(() -> Leaf.leaf(future, runnable));
	    }
	  }
	
	  private static <T> CompletableFuture<T> leaf(final CompletableFuture<T> future, final Consumer<CompletableFuture<T>> runnable) {
	    Stream.of(runnable).forEach(task -> task.accept(future));
	    return future;
	  }
	
	  private static void leaf(final Runnable runnable) {
	    final CompletableFuture<Runnable> future = new CompletableFuture<>();
	    future.complete(() -> {});
	    future.thenRun(runnable);
	  }
	}
}