fork download
  1. import sys
  2.  
  3. lines_to_repeat = [5, 6, 7]
  4.  
  5. memory = []
  6. for i, line in enumerate(sys.stdin, 1):
  7. if i in lines_to_repeat:
  8. memory.append(line)
  9. elif memory:
  10. sys.stdout.write(''.join(memory))
  11. memory = []
  12. sys.stdout.write(line)
Success #stdin #stdout 0.01s 7200KB
stdin
 Heading 
 Heading2 
    
 Heading3 
    
 Line1
 Line2
    
 Line3
 Line4
stdout
 Heading 
 Heading2 
    
 Heading3 
    
 Line1
 Line2
    
 Line1
 Line2
    
 Line3
 Line4