Problem F. Formatting function

Author:A. Klenin   Time limit:2 sec
Input file:input.txt   Memory limit:8 Mb
Output file:output.txt  

Statement

Text formatting functions (Format, sprintf, etc) are very common between programming languages. Your task is to implement a simplified one.

Formatting function receives format string and several arguments. Argument values are processed one by one and inserted into format string at positions designated by format specifiers. The following format specifiers must be implemented:

Formatting error is generated if:

Input file format

Input file contains format string followed by arguments, one per line.

Output file format

Output file must contain a single string — either formatted text or ERROR in case of any formatting error.

Constraints

Number of arguments is not greater than 1000, length of each line is not greater than 50000 characters.

Sample tests

No. Input file (input.txt) Output file (output.txt)
1
%d x %d %s %d
2
02
=
4
2 x 2 = 4
2
%s
ERROR
3
%d
2a
ERROR

0.066s 0.012s 13