NSEZ and TLE error in Enormous Input Test

Sir/Mam,here is my solution for the problem Enormous Input Test.The link for the problem is as given http://www.codechef.com/problems/INTEST

n,k =map(int,input().split(" "))
j=0
for i in range(n):
    if((int)(input()))%k==0:
        j=j+1
print(j)

The code works well in my system but on submitting it I get a TLE error in Python 3.1.2 . On submitting in python 2.7.2 it gave nsez error.I tried using

import sys
sys.exit(0)

but in vain.Please help.

It gave TLE in 3.1 because 3.1 is very slow for this question even though code is correct. Nothing you can do.

For version 2.7.2 you will need to replace the input() by raw_input() since input() is used to input only numbers and not strings. raw_input() is used for strings.

import sys
n,k =map(int,raw_input().split(" "))
j=0
for i in range(n):
if((int)(input()))%k==0:
j=j+1
print j
sys.exit(0)

Sir I submitted the code as above but I am still getting a TLE in python 2…Please help.

the method he told ou is the correct way to take input in python 2.7 and earlier versions. he has mentioned in answer that this cant not be solved in python. try it in C or C++ (using scanf and printf) python I/O is very slow so its not solvable in python.

1 Like

i just chekd the accepted codes and there are a few in python. so it s solvable but using some faster I/O methods. ur code is correct but for it to pas in time limit it requires some tricks.see this one http://www.codechef.com/viewsolution/3950420

1 Like

but stil there will be a few questions in some contests where the time limit will be strict and a python code will never be ale to get AC even with the most efficient algo. so better use C or C++ in contests.

1 Like

As @redd said go for faster I/O methods.

1 Like

Sir the code that you suggested
http://www.codechef.com/viewsolution/3950420

Submitted successfully on the site but when I ran it on my system it gave the following error:

Traceback (most recent call last):
File “C:/Users/hp/Desktop/pythonfile/enormousInputTestSolution.py”, line 8, in
nums = stdin.buffer.read( ).splitlines( )
AttributeError: ‘PseudoInputFile’ object has no attribute ‘buffer’

Please explain

@akshitha007 It is because the Python installed on your system is version 2.7 and not 3.1 as you think. I tested both the codes above on ideone.com and here are the links:

Version 2.7 : link Shows the same error as yours.

Version 3.1 : link 2 Runs successfully.

I would recommend you keep using 2.7 only as it is more widely used and is faster compared to 3.Python 3.1 is new but has not been widely adopted.

Also 1 request. Please try not address any one on the forum as Sir/Madam. We are just normal students like you trying to help others.

1 Like

Thanks a lot.
Actually I was running the code on 3.3.2 and I thought that it must be the same as 3.1.
In that case please let me know how to take faster input and output in python 2.7…as I come across many problems that run well on my system but I get a TLE or NSEZ on the site.