C# 56ms Using Semaphore
\nusing System;\nusing System.Threading;\n\npublic class FooBar {\n    private int n;\n    private Semaphore semFoo;\n    private Semaphore semBar;\n        \n\
```\nusing System;\nusing System.Threading;\n\npublic class FooBar {\n    private int n;\n    private Semaphore semFoo;\n    private Semaphore semBar;\n        \n\n    public FooBar(int n) {\n        this.n = n;\n        this.semFoo = new Semaphore(initialCount: 0, maximumCount: 1);\n        this.semBar = new Semaphore(initialCount: 1, maximumCount: 1);\n    }\n\n    public void Foo(Action printFoo) {\n        for (int i = 0; i < n; i++) {\n           \n        \t// printFoo() outputs "foo". Do not change or remove this line.\n            semBar.WaitOne();\n        \tprintFoo();\n            semFoo.Release(1);\n        }\n    }\n\n    public void Bar(Action printBar) {\n        \n        for (int i = 0; i < n; i++) {\n            \n            // printBar() outputs "bar". Do not change or remove this line.\n            semFoo.WaitOne();\n        \tprintBar();\n            semBar.Release(1);\n        }\n    }\n}\n```
[]