Buggy python submission (verdict: Time Limit Exceeded):
def grundy(N, K):
    if N < K:
        return 0
    while N % K:
        hi = N
        lo = 1
        while hi - lo > 1:
            mid = (hi + lo) / 2
            M = N - mid * (N/ K + 1)
            if M / K == N / K:
                lo = mid
            else:
                hi = mid
        m = N / K + 1
        N -= m * lo
    return N / K

N = input()
ans = 0
for i in xrange(N):
    a, k = map(int, raw_input().split())
    ans ^= grundy(a, k)
print "Takahashi" if ans else "Aoki"


Fixed submission:
def grundy(N, K):
    if N < K:
        return 0
    while N % K:
        hi = N / (N / K + 1) 
        lo = 1
        while hi - lo > 1:
            mid = (hi + lo) / 2
            M = N - mid * (N/ K + 1)
            if M / K == N / K:
                lo = mid
            else:
                hi = mid
        m = N / K + 1
        N -= m * lo
    return N / K

N = input()
ans = 0
for i in xrange(N):
    a, k = map(int, raw_input().split())
    ans ^= grundy(a, k)
print "Takahashi" if ans else "Aoki"

Buggy python submission (verdict: Time Limit Exceeded):
def grundy(N, K):
    if N < K:
        return 0
    while N % K:
        m = N / K + 1
        N -= m
    return N / K

N = input()
ans = 0
for i in xrange(N):
    a, k = map(int, raw_input().split())
    ans ^= grundy(a, k)
print "Takahashi" if ans else "Aoki"


Fixed submission:
def grundy(N, K):
    if N < K:
        return 0
    while N % K:
        hi = N / (N / K + 1) 
        lo = 1
        while hi - lo > 1:
            mid = (hi + lo) / 2
            M = N - mid * (N/ K + 1)
            if M / K == N / K:
                lo = mid
            else:
                hi = mid
        m = N / K + 1
        N -= m * lo
    return N / K

N = input()
ans = 0
for i in xrange(N):
    a, k = map(int, raw_input().split())
    ans ^= grundy(a, k)
print "Takahashi" if ans else "Aoki"

Buggy python submission (verdict: Time Limit Exceeded):
def grundy(N, K):
    if N < K:
        return 0
    while N % K:
        m = N / K + 1
        N -= m
    return N / K

N = input()
ans = 0
for i in xrange(N):
    a, k = map(int, raw_input().split())
    ans ^= grundy(a, k)
print "Takahashi" if ans else "Aoki"


Fixed submission:
def grundy(N, K):
    if N < K:
        return 0
    while N % K:
        hi = N / (N / K + 1) 
        lo = 1
        while hi - lo > 1:
            mid = (hi + lo) / 2
            M = N - mid * (N/ K + 1)
            if M / K == N / K:
                lo = mid
            else:
                hi = mid
        m = N / K + 1
        N -= m * lo
    return N / K

N = input()
ans = 0
for i in xrange(N):
    a, k = map(int, raw_input().split())
    ans ^= grundy(a, k)
print "Takahashi" if ans else "Aoki"

Buggy python submission (verdict: Time Limit Exceeded):
def grundy(N, K):
    while N % K:
        m = N / K + 1
        N -= m
    return N / K

N = input()
ans = 0
for i in xrange(N):
    a, k = map(int, raw_input().split())
    ans ^= grundy(a, k)
print "Takahashi" if ans else "Aoki"

Fixed submission:
def grundy(N, K):
    if N < K:
        return 0
    while N % K:
        hi = N / (N / K + 1) 
        lo = 1
        while hi - lo > 1:
            mid = (hi + lo) / 2
            M = N - mid * (N/ K + 1)
            if M / K == N / K:
                lo = mid
            else:
                hi = mid
        m = N / K + 1
        N -= m * lo
    return N / K

N = input()
ans = 0
for i in xrange(N):
    a, k = map(int, raw_input().split())
    ans ^= grundy(a, k)
print "Takahashi" if ans else "Aoki"