Simple Java Solution with two Semaphores, beat 100%
\nclass FooBar {\n    private int n;\n    \n    private Semaphore fooSem;\n    \n    private Semaphore barSem;\n\n    public FooBar(int n) {\n        this.n = n
```\nclass FooBar {\n    private int n;\n    \n    private Semaphore fooSem;\n    \n    private Semaphore barSem;\n\n    public FooBar(int n) {\n        this.n = n;\n        this.fooSem = new Semaphore(1);\n        this.barSem = new Semaphore(0);\n    }\n\n    public void foo(Runnable printFoo) throws InterruptedException {\n        \n        for (int i = 0; i < n; i++) {\n            this.fooSem.acquire();\n        \t// printFoo.run() outputs "foo". Do not change or remove this line.\n        \tprintFoo.run();\n            this.barSem.release();\n        }\n    }\n\n    public void bar(Runnable printBar) throws InterruptedException {\n        \n        for (int i = 0; i < n; i++) {\n            this.barSem.acquire();\n            // printBar.run() outputs "bar". Do not change or remove this line.\n        \tprintBar.run();\n            this.fooSem.release();\n        }\n    }\n}\n```
[]