Java solution with synchronized methods
Code with a runtime of 10ms :\n\n\nclass Foo {\n    public int count;\n    \n    public Foo() {\n        this.count = 1;\n    }\n\n    synchronized public void 
Code with a runtime of 10ms :\n\n```\nclass Foo {\n    public int count;\n    \n    public Foo() {\n        this.count = 1;\n    }\n\n    synchronized public void first(Runnable printFirst) throws InterruptedException {\n        while(count != 1) wait();\n        \n        // printFirst.run() outputs "first". Do not change or remove this line.\n        printFirst.run();\n        this.count++;\n        notifyAll();\n    }\n\n    synchronized public void second(Runnable printSecond) throws InterruptedException {\n        while(this.count != 2) wait();\n        \n        // printSecond.run() outputs "second". Do not change or remove this line.\n        printSecond.run();\n        this.count++;\n        notifyAll();\n    }\n\n    synchronized public void third(Runnable printThird) throws InterruptedException {\n        while(this.count != 3) wait();\n        \n        // printThird.run() outputs "third". Do not change or remove this line.\n        printThird.run();\n        this.count++;\n        notifyAll();\n    }\n}\n```
['Java']