C# faster than 90.67%, less then 100% Mem
Runtime: 52 ms\nMemory Usage: 16.8 MB\n```\npublic class FooBar {\n    private int n;\n\n    private System.Threading.AutoResetEvent fooReady;\n    private Syst
Runtime: 52 ms\nMemory Usage: 16.8 MB\n```\npublic class FooBar {\n    private int n;\n\n    private System.Threading.AutoResetEvent fooReady;\n    private System.Threading.AutoResetEvent barReady;\n    \n    public FooBar(int n) {\n        this.n = n;\n        fooReady = new System.Threading.AutoResetEvent(true);\n        barReady = new System.Threading.AutoResetEvent(false);\n    }\n\n    public void Foo(Action printFoo) {\n        \n        for (int i = 0; i < n; i++) {\n            fooReady.WaitOne();\n        \t// printFoo() outputs "foo". Do not change or remove this line.\n        \tprintFoo();\n            barReady.Set();\n        }\n    }\n\n    public void Bar(Action printBar) {\n        \n        for (int i = 0; i < n; i++) {\n            barReady.WaitOne();\n            // printBar() outputs "bar". Do not change or remove this line.\n        \tprintBar();\n            fooReady.Set();\n        }\n    }\n    \n    ~FooBar()\n    {\n        try\n        {\n            fooReady.Dispose();\n            barReady.Dispose();\n        } catch(Exception ex) {}\n    }
[]