# Create list and add 1 to list values from index [I,R].Print the Occurence of a specific number

def add(a,b):
for i in xrange(a-1,b):
box[i]+=1
def count(k):
if box.count(k)!=0:
box.index(k)
return len(box)-box.index(k)
else:
return 0
from sys import stdin,stdout
box=[0]*int(stdin.readline()) #input the number of boxes of chocolate
for i in xrange(int(stdin.readline())):  #loops for M days
a,b = stdin.readline().split()  #gets the starting and ending index.
box.sort()
print count(int(stdin.readline()))  #prints the number of boxes of chocolates greater than equal to the input number


For small values the program works but fails for large value.Suggest any faster method/algorithm.

Constraints: 1 <= N <= 100000

1 <= M <= 1000

1 <= l <= r <= N

1 <= Q <= 100000

1 <= K <= N

• Hello, and welcome to code review. Could I please check what you mean by "fails for large values?" Is it giving the wrong answer, or just taking too long to give any answer at all? – Josiah Jul 18 '18 at 6:46
• fails for large values means Time Limit is Exceeded – AYUSH SINGHAL Jul 18 '18 at 7:12
• The comments in the code feels like this is a coding challenge. Do you mind adding the description of the challenge into the question, please? – Mathias Ettinger Jul 18 '18 at 8:32
• I also removed the python-3.x tag as xrange doesn't exist anymore and print as a keyword is not valid syntax. – Mathias Ettinger Jul 18 '18 at 8:37
• I've removed the Python 2.6 tag. You'd initially tagged this question with all Python tags but the code is written in Python 2.7. If this code HAS to run on Python 2.6, please state so explicitly in the question. The 2.7 tag will eventually be renamed to 2.x. – Mast Jul 30 '18 at 7:00