'''
keys: 
Solutions:
Similar: 
T:
S:
'''
from typing import List
import collections

'''
implement read(outputbuf, n) by calling read4, write output to outputbuf, 
modify outputbuf inplace and return the final read count.
'''


class Solution:
    def read(self, buf, n):
        """
        :type buf: Destination buffer (List[str])
        :type n: Number of characters to read (int)
        :rtype: The number of actual characters read (int)
        """
        idx = 0
        while n > 0:
            # read file to buf4 (buf of read4)
            buf4 = [""] * 4
            ct = read4(buf4) # ct: number of chars read by read4
            # if no more char in file, return
            if not ct:
                return idx
            # write buf4 into buf directly
            for i in range(min(ct, n)):
                buf[idx] = buf4[i]
                idx += 1
                n -= 1
        return idx