<p>You are participating in an online chess tournament. There is a chess round that starts every <code>15</code> minutes. The first round of the day starts at <code>00:00</code>, and after every <code>15</code> minutes, a new round starts.</p>

<ul>
	<li>For example, the second round starts at <code>00:15</code>, the fourth round starts at <code>00:45</code>, and the seventh round starts at <code>01:30</code>.</li>
</ul>

<p>You are given two strings <code>loginTime</code> and <code>logoutTime</code> where:</p>

<ul>
	<li><code>loginTime</code> is the time you will login to the game, and</li>
	<li><code>logoutTime</code> is the time you will logout from the game.</li>
</ul>

<p>If <code>logoutTime</code> is <strong>earlier</strong> than <code>loginTime</code>, this means you have played from <code>loginTime</code> to midnight and from midnight to <code>logoutTime</code>.</p>

<p>Return <em>the number of full chess rounds you have played in the tournament</em>.</p>

<p><strong>Note:</strong>&nbsp;All the given times follow the 24-hour clock. That means the first round of the day starts at <code>00:00</code> and the last round of the day starts at <code>23:45</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> loginTime = &quot;09:31&quot;, logoutTime = &quot;10:14&quot;
<strong>Output:</strong> 1
<strong>Explanation:</strong> You played one full round from 09:45 to 10:00.
You did not play the full round from 09:30 to 09:45 because you logged in at 09:31 after it began.
You did not play the full round from 10:00 to 10:15 because you logged out at 10:14 before it ended.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> loginTime = &quot;21:30&quot;, logoutTime = &quot;03:00&quot;
<strong>Output:</strong> 22
<strong>Explanation:</strong> You played 10 full rounds from 21:30 to 00:00 and 12 full rounds from 00:00 to 03:00.
10 + 12 = 22.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>loginTime</code> and <code>logoutTime</code> are in the format <code>hh:mm</code>.</li>
	<li><code>00 &lt;= hh &lt;= 23</code></li>
	<li><code>00 &lt;= mm &lt;= 59</code></li>
	<li><code>loginTime</code> and <code>logoutTime</code> are not equal.</li>
</ul>

class Solution:
    def numberOfRounds(self, loginTime: str, logoutTime: str) -> int:

        valid = [00, 15, 30, 45]

        if loginTime[:3] == logoutTime[:3]:
            if 0 <= (int(logoutTime[3:]) - int(loginTime[3:])) < 15:
                return 0 
        
        def formatLoginTime(timev):
            last_two = int(timev[::-1][:2][::-1])
            if last_two not in valid:
                if last_two > 45:
                    if int(timev[:2]) == 23:
                        timev = '00' + ':' + '00'
                    else:
                        if int(timev[:2]) < 9:
                            timev = '0' + str(int(timev[:2]) + 1) + ':' + '00'
                        else:
                            timev = str(int(timev[:2]) + 1) + ':' + '00'
                elif last_two > 30:
                    timev = timev[:3] + '45'
                elif last_two > 15:
                    timev = timev[:3] + '30'
                elif last_two > 00:
                    timev = timev[:3] + '15'
            return timev 


        def formatLogoutTime(timev):
            last_two = int(timev[::-1][:2][::-1])
            if last_two not in valid:
                if last_two > 45:
                    timev = timev[:3] + '45'
                elif last_two > 30:
                    timev = timev[:3] + '30'
                elif last_two > 15:
                    timev = timev[:3] + '15'
                elif last_two > 00:
                    timev = timev[:3] + '00'
            return timev 

        litime = formatLoginTime(loginTime)
        lotime = formatLogoutTime(logoutTime)
        ans = 0

        while litime != lotime:
            ans += 1 
            print('litime', litime)
            h, m = litime.split(':')
            h, m = int(h), int(m)
            if m in [00, 15, 30]:
                m += 15 
                m = str(m)
                if h <= 9:
                    h = '0' + str(h)
                litime = str(h) + ':' + m 
            elif m == 45:
                if h != 23:
                    h += 1
                    m = '00'
                    if h <= 9:
                        h = '0' + str(h)
                    h = str(h)
                else:
                    h = '00'
                    m = '00'
                litime = h + ':' + m

        return ans 
        
34