What causes the NZEC (Non Zero Exit Code) error in my Sums in a Triangle solution?
Question: I was doing [this practice problem](http://www.codechef.com/problems/SUMTRIAN)
on codechef. I have already [solved this in
C](http://www.codechef.com/status/SUMTRIAN,anshbansal) and was trying to do
the same in Python 2.7. I am getting NZEC error on codechef judge which is
"Non Zero Exit Code". I don't understand why this could be happening. The
program is working fine on my computer. What kind of corner case can be giving
this problem?

    
    
    import sys
    from itertools import islice
    
    def p(): 
        cases = int(sys.stdin.readline())
        for case in xrange(cases):
            height = int(sys.stdin.readline())
            triangle = [map(int, i.split()) for i in islice(sys.stdin,height)]
    
            prev_row = triangle[0]
            for i in xrange(1, height):
                cur_row = triangle[i]
    
                cur_row[0] += prev_row[0]
                cur_row[len(cur_row) - 1] += prev_row[len(prev_row) - 1]
    
                for j in xrange(1, len(cur_row) - 1):
                    if(prev_row[j - 1] > prev_row[j]):
                        cur_row[j] += prev_row[j - 1]
                    else:
                        cur_row[j] += prev_row[j]
    
                prev_row = cur_row
    
            print max(prev_row)
    
    p()
    


Answer: change this line:

    
    
    triangle = [map(int, i.split()) for i in islice(sys.stdin,height)]
    

to this:

    
    
    triangle = [map(int, sys.stdin.readline().split()) for _ in xrange(height)]
    

From the [docs](http://docs.python.org/2/library/stdtypes.html#file.next):

> As a consequence of using a read-ahead buffer, combining `next()` with other
> file methods (like `readline()`) does not work right.
    
    
    #so.py
    import sys
    from itertools import islice
    print list(islice(sys.stdin,3))
    print sys.stdin.readline()
    

Demo:

    
    
    $ python so.py <abc
    ['2\n', '3\n', '1\n']
    Traceback (most recent call last):
      File "so.py", line 4, in <module>
        print sys.stdin.readline()
    ValueError: Mixing iteration and read methods would lose data
    

