Buggy python submission (verdict: Runtime Error):
#???????????£?????§????????????????±???¨????????¢?????´?????????

def partition(data, l, r, pivotIndex, key):
    pivotValue = key(data[pivotIndex])
    data[pivotIndex], data[r] = data[r], data[pivotIndex]
    storeIndex = l
    for i in range(l, r):
        if key(data[i]) < pivotValue:
            data[storeIndex], data[i] = data[i], data[storeIndex]
            storeIndex += 1
    data[r], data[storeIndex] = data[storeIndex], data[r]
    return storeIndex

from random import randint

# partition()??§data[pivot]???m????????§???????????¨????±???????
# n != m ????????°pivot???????????????????????????????????°?????????
# pivot?????????????????????????????´????????????O(nlog(n))????????????????????§???????????????????????????
def select(data, l, r, n, key):
    while True:
        pivot = randint(l, r)
        m = partition(data, l, r, pivot, key)
        if n == m:
             return data[n]
        elif n < m:
            r = m - 1
        else:
            l = m + 1

import math
class twodtree:
    def __init__(self, data):
        self.data = [None] * (1 << (int(math.log(len(data), 2)) + 1))
    
        self.update(data,(0, 1),0,len(data)-1)
        
    def update(self, data, k, l, r, i=1):
        if l > r:
            return
        if l == r:
            self.data[i] = data[l]
            return
        
        m = (l + r) // 2
        self.data[i] = select(data, l, r, m, itemgetter(*k))

        k = (k[0],k[1])
        self.update(data,k,l,m - 1,2 * i)
        self.update(data,k,m + 1,r,2 * i + 1)
        
    def find(self, s, t, k=0, i=1):
        ret = []
        if len(self.data) <= i or self.data[i] is None:
            return ret
        if s[0] <= self.data[i][0] <= t[0] and s[1] <= self.data[i][1] <= t[1]:
            ret.append(self.data[i][2])
        
        if s[k] <= self.data[i][k]:
            ret.extend(self.find(s, t, k^1, 2 * i))
        if self.data[i][k] <= t[k]:
            ret.extend(self.find(s, t, k^1, 2 * i + 1))

        return ret

from sys import stdin
readline = stdin.readline

n = int(readline())
xyi = [list(map(int, readline().split())) + [i] for i in range(n)]


two = twodtree(xyi)
print
q = int(readline())
for sx, tx, sy, ty in [map(int, readline().split()) for _ in range(q)]:
    id = two.find((sx,sy),(tx,ty))
    id.sort()
    print('\n'.join(map(str, id)))
    print()

Fixed submission:
from sys import stdin
import math
from operator import itemgetter
from bisect import bisect_left, bisect_right
readline = stdin.readline

def main():
    xy = [tuple(map(int, readline().split())) + (i,) for i in range(int(readline()))]
    xy.sort()
    root = int(math.sqrt(len(xy)))

    low = [x for x, y, i in xy[::root]]
    high = [x for x, y, i in xy[root - 1::root]] + [float('inf')]

    xy = [sorted(xy[i:i+root], key=itemgetter(1)) for i in range(0,len(xy),root)]
    xy = [([y for x, y, i in xyi], xyi) for xyi in xy]
    for sx, tx, sy, ty in (map(int, readline().split()) for _ in range(int(readline()))):
        ret = []
        for i in range(bisect_left(high, sx), bisect_right(low, tx)):
            k, v = xy[i]
            for i in range(bisect_left(k, sy), bisect_right(k, ty)):
                if sx <= v[i][0] <=tx:
                    ret.append(v[i][2])
        if ret:
            ret.sort()
            print('\n'.join(map(str,ret)))
        print()
main()

Buggy python submission (verdict: Time Limit Exceeded):
#???????????£?????§????????????????±???¨????????¢?????´?????????

def partition(data, l, r, pivotIndex, key):
    pivotValue = key(data[pivotIndex])
    data[pivotIndex], data[r] = data[r], data[pivotIndex]
    storeIndex = l
    for i in range(l, r):
        if key(data[i]) < pivotValue:
            data[storeIndex], data[i] = data[i], data[storeIndex]
            storeIndex += 1
    data[r], data[storeIndex] = data[storeIndex], data[r]
    return storeIndex

from random import randint

# partition()??§data[pivot]???m????????§???????????¨????±???????
# n != m ????????°pivot???????????????????????????????????°?????????
# pivot?????????????????????????????´????????????O(nlog(n))????????????????????§???????????????????????????
def select(data, l, r, n, key):
    while True:
        pivot = randint(l, r)
        m = partition(data, l, r, pivot, key)
        if n == m:
             return data[n]
        elif n < m:
            r = m - 1
        else:
            l = m + 1

import math

from operator import itemgetter
class twodtree:
    def __init__(self, data):
        self.data = [None] * (1 << (int(math.log(len(data), 2)) + 1))
    
        self.update(data,(0, 1),0,len(data)-1)
        
    def update(self, data, k, l, r, i=1):
        if l > r:
            return
        if l == r:
            self.data[i] = data[l]
            return
        
        m = (l + r) // 2
        self.data[i] = select(data, l, r, m, itemgetter(*k))

        k = (k[1],k[0])
        self.update(data,k,l,m - 1,2 * i)
        self.update(data,k,m + 1,r,2 * i + 1)
        
    def find(self, s, t, k=0, i=1):
        ret = []
        if len(self.data) <= i or self.data[i] is None:
            return ret
        if s[0] <= self.data[i][0] <= t[0] and s[1] <= self.data[i][1] <= t[1]:
            ret.append(self.data[i][2])
        
        if s[k] <= self.data[i][k]:
            ret.extend(self.find(s, t, k^1, 2 * i))
        if self.data[i][k] <= t[k]:
            ret.extend(self.find(s, t, k^1, 2 * i + 1))

        return ret

from sys import stdin
readline = stdin.readline

n = int(readline())
xyi = [list(map(int, readline().split())) + [i] for i in range(n)]


two = twodtree(xyi)
print
q = int(readline())
for sx, tx, sy, ty in [map(int, readline().split()) for _ in range(q)]:
    id = two.find((sx,sy),(tx,ty))
    if len(id):
        id.sort()
        print('\n'.join(map(str, id)))
    print()

Fixed submission:
from sys import stdin
import math
from operator import itemgetter
from bisect import bisect_left, bisect_right
readline = stdin.readline

def main():
    xy = [tuple(map(int, readline().split())) + (i,) for i in range(int(readline()))]
    xy.sort()
    root = int(math.sqrt(len(xy)))

    low = [x for x, y, i in xy[::root]]
    high = [x for x, y, i in xy[root - 1::root]] + [float('inf')]

    xy = [sorted(xy[i:i+root], key=itemgetter(1)) for i in range(0,len(xy),root)]
    xy = [([y for x, y, i in xyi], xyi) for xyi in xy]
    for sx, tx, sy, ty in (map(int, readline().split()) for _ in range(int(readline()))):
        ret = []
        for i in range(bisect_left(high, sx), bisect_right(low, tx)):
            k, v = xy[i]
            for i in range(bisect_left(k, sy), bisect_right(k, ty)):
                if sx <= v[i][0] <=tx:
                    ret.append(v[i][2])
        if ret:
            ret.sort()
            print('\n'.join(map(str,ret)))
        print()
main()

Buggy python submission (verdict: Time Limit Exceeded):
import math
from collections import deque 
from operator import itemgetter

class twodtree:
    #@profile
    def __init__(self, data):
        self.data = [None] * (1 << (int(math.log(len(data), 2)) + 1))

        que = deque([(0,0,len(data) - 1,1)])
        key = itemgetter(0,1),itemgetter(1,0)
        while len(que):
            k, l, r, i = que.popleft()
            if l > r:continue
            if l == r:
                self.data[i] = data[l]
                continue

            m = (l + r) // 2
            
            que.append((k^1,l,m - 1,2 * i))
            que.append((k^1,m + 1,r,2 * i + 1))
            
            while True:
                # ?????? pertition inline?±????
                index = (l + r) // 2
                value = key[k](data[index])
                data[index], data[r] = data[r], data[index]
                n = l
                for j in range(l, r):
                    if key[k](data[j]) < value:
                        data[n], data[j] = data[j], data[n]
                        n += 1
                data[r], data[n] = data[n], data[r]
                # ?????? pertition inline?±????

                if m == n:
                    break
                elif m <  n:
                    r = n - 1
                else:
                    l = n + 1
            self.data[i] = data[m]

    def find(self, s, t, k=0, i=1):
        ret = []
        if len(self.data) <= i or self.data[i] is None:
            return ret
        if s[0] <= self.data[i][0] <= t[0] and s[1] <= self.data[i][1] <= t[1]:
            ret.append(self.data[i][2])
         
        if s[k] <= self.data[i][k]:
            ret.extend(self.find(s, t, k^1, 2 * i))
        if self.data[i][k] <= t[k]:
            ret.extend(self.find(s, t, k^1, 2 * i + 1))
 
        return ret
 
from sys import stdin
readline = stdin.readline

def main(): 
    n = int(readline())
    xyi = [tuple(map(int, readline().split())) + (i,) for i in range(n)]
 
    two = twodtree(xyi)
    q = int(readline())
    for sx, tx, sy, ty in [map(int, readline().split()) for _ in range(q)]:
        id = two.find((sx,sy),(tx,ty))
        if len(id):
            id.sort()
            print('\n'.join(map(str, id)))
        print()

main()

Fixed submission:
from sys import stdin
import math
from operator import itemgetter
from bisect import bisect_left, bisect_right
readline = stdin.readline

def main():
    xy = [tuple(map(int, readline().split())) + (i,) for i in range(int(readline()))]
    xy.sort()
    root = int(math.sqrt(len(xy)))

    low = [x for x, y, i in xy[::root]]
    high = [x for x, y, i in xy[root - 1::root]] + [float('inf')]

    xy = [sorted(xy[i:i+root], key=itemgetter(1)) for i in range(0,len(xy),root)]
    xy = [([y for x, y, i in xyi], xyi) for xyi in xy]
    for sx, tx, sy, ty in (map(int, readline().split()) for _ in range(int(readline()))):
        ret = []
        for i in range(bisect_left(high, sx), bisect_right(low, tx)):
            k, v = xy[i]
            for i in range(bisect_left(k, sy), bisect_right(k, ty)):
                if sx <= v[i][0] <=tx:
                    ret.append(v[i][2])
        if ret:
            ret.sort()
            print('\n'.join(map(str,ret)))
        print()
main()

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import math
from operator import itemgetter
readline = stdin.readline

def main():
    xy = [tuple(map(int, readline().split())) + (i,) for i in range(int(readline()))]
    xy.sort()
    root = int(math.sqrt(len(xy)))
        
    index = [(s[0], t[0]) for s,t in zip(xy[::root], xy[root - 1::root] + [(float('inf'),float('inf'))])]
    
    xy = [sorted(xy[i:i+root], key=itemgetter(1,0)) for i in range(0,len(xy),root)]
    for sx, tx, sy, ty in (map(int, readline().split()) for _ in range(int(readline()))):
        ret = []
        for i, (s, t) in enumerate(index):
            if sx <= t and s <= tx:
                for xyi in xy[i]:
                    if sy <= xyi[1] <= ty and sx <= xyi[0] <=tx:
                        ret.append(xyi[2])
        if ret:
            ret.sort()
            print('\n'.join(map(str,ret)))
        print()
main()

Fixed submission:
from sys import stdin
import math
from operator import itemgetter
from bisect import bisect_left, bisect_right
readline = stdin.readline

def main():
    xy = [tuple(map(int, readline().split())) + (i,) for i in range(int(readline()))]
    xy.sort()
    root = int(math.sqrt(len(xy)))

    low = [x for x, y, i in xy[::root]]
    high = [x for x, y, i in xy[root - 1::root]] + [float('inf')]

    xy = [sorted(xy[i:i+root], key=itemgetter(1)) for i in range(0,len(xy),root)]
    xy = [([y for x, y, i in xyi], xyi) for xyi in xy]
    for sx, tx, sy, ty in (map(int, readline().split()) for _ in range(int(readline()))):
        ret = []
        for i in range(bisect_left(high, sx), bisect_right(low, tx)):
            k, v = xy[i]
            for i in range(bisect_left(k, sy), bisect_right(k, ty)):
                if sx <= v[i][0] <=tx:
                    ret.append(v[i][2])
        if ret:
            ret.sort()
            print('\n'.join(map(str,ret)))
        print()
main()