efficient algorithm for creating multibyte sequences