Java Semaphore solution
\nclass Foo {\n    \n    private final Semaphore second = new Semaphore(0);\n    private final Semaphore third = new Semaphore(0);\n\n    public void first(Runn
```\nclass Foo {\n    \n    private final Semaphore second = new Semaphore(0);\n    private final Semaphore third = new Semaphore(0);\n\n    public void first(Runnable printFirst) throws InterruptedException {\n        // printFirst.run() outputs "first". Do not change or remove this line.\n        printFirst.run();\n        \n        second.release();\n    }\n\n    public void second(Runnable printSecond) throws InterruptedException {\n        second.acquire();\n        \n        // printSecond.run() outputs "second". Do not change or remove this line.\n        printSecond.run();\n        \n        third.release();\n    }\n\n    public void third(Runnable printThird) throws InterruptedException {\n        third.acquire();\n        \n        // printThird.run() outputs "third". Do not change or remove this line.\n        printThird.run();\n    }\n}\n```
['Java']