Python Solution
The key is that zero() determines if even() or odd() should run next. Treat (even, zero) and (odd, zero) as two separate pairs. For each pair, the two functions
The key is that zero() determines if even() or odd() should run next. Treat (even, zero) and (odd, zero) as two separate pairs. For each pair, the two functions should run alternatively. Make sure only zero() could run at first.\n```import threading\nclass ZeroEvenOdd(object):\n    def __init__(self, n):\n        self.n = n\n        self.zero_lock = threading.Lock()\n        self.even_lock = threading.Lock()\n        self.odd_lock = threading.Lock()\n        self.odd_lock.acquire()\n        self.even_lock.acquire()\n        \n        \n\t# printNumber(x) outputs "x", where x is an integer.\n    def zero(self, printNumber):\n        """\n        :type printNumber: method\n        :rtype: void\n        """\n        #determine if odd()/even() goes next\n        for i in range(1, self.n+1):\n            self.zero_lock.acquire()\n            printNumber(0)\n            if (i % 2 == 1):\n                self.odd_lock.release()\n            else:\n                self.even_lock.release()\n            \n        \n        \n    def even(self, printNumber):\n        """\n        :type printNumber: method\n        :rtype: void\n        """\n        for i in range(2, self.n+1, 2):\n            self.even_lock.acquire()\n            printNumber(i)\n            self.zero_lock.release()\n        \n        \n        \n    def odd(self, printNumber):\n        """\n        :type printNumber: method\n        :rtype: void\n        """\n        for i in range(1, self.n+1, 2):\n            self.odd_lock.acquire()\n            printNumber(i)\n            self.zero_lock.release()
['Python']