Python Fast Input Output Using Buffer Competitive Programming
Question: I have seen people using buffer in different languages for fast input/output
in Online Judges. For example this <http://www.spoj.pl/problems/INTEST/> is
done with C like this:

    
    
    #include <stdio.h>
    #define size 50000
    
    int main (void){
    unsigned int n=0,k,t;
    char buff[size];
    unsigned int divisible=0;
    int block_read=0;
    int j;
    t=0;
    scanf("%lu %lu\n",&t,&k);
    
    while(t){
        block_read =fread(buff,1,size,stdin);
        for(j=0;j<block_read;j++){
            if(buff[j]=='\n'){
                t--;
                if(n%k==0){
                    divisible++;
                }
                n=0;
            }
            else{
                n = n*10 + (buff[j] - '0');
            }
        }
    }
    
    printf("%d",divisible);
    return 0;
    

How can this be done with python?


Answer: 
    import sys
    file = sys.stdin
    size = 50000
    t = 0
    while(t != 0)
        block_read = file.read(size)
        ...
    ...
    

Most probably this will not increase performance though – Python is
interpreted language, so you basically want to spend as much time in native
code (standard library input/parsing routines in this case) as possible.

TL;DR either use built-in routines to parse integers or get some sort of 3rd
party library which is optimized for speed.

