python3: 40ms 86.64% Faster 100% Less memory, using threading.Lock
\nfrom threading import Lock\nclass FooBar:\n    def __init__(self, n):\n        self.n = n\n        self.foo_lock = Lock()\n        self.bar_lock = Lock()\n   
```\nfrom threading import Lock\nclass FooBar:\n    def __init__(self, n):\n        self.n = n\n        self.foo_lock = Lock()\n        self.bar_lock = Lock()\n        self.bar_lock.acquire()\n\n\n    def foo(self, printFoo: \'Callable[[], None]\') -> None:\n        for i in range(self.n):\n            self.foo_lock.acquire()\n            # printFoo() outputs "foo". Do not change or remove this line.\n            printFoo()\n            self.bar_lock.release()\n\n\n    def bar(self, printBar: \'Callable[[], None]\') -> None:\n        for i in range(self.n):\n            self.bar_lock.acquire()\n            # printBar() outputs "bar". Do not change or remove this line.\n            printBar()\n            self.foo_lock.release()\n```
['Python', 'Python3']