SIMD12C.文件系统

传统题 时间 2000 ms 内存 256 MiB 9 尝试 11 已通过 3 标签

文件系统

Statement

Simulate a file system containing directories and ordinary files. The root path is /. Names contain lowercase letters and digits. Every operation is valid: referenced paths exist, creations do not conflict, a directory is never moved into its own subtree, and the root is never removed or moved.

Commands are MK path, TOUCH path s, RM path, MV src dst, and Q path. A query path is always a directory and asks for the number of ordinary files in its full subtree and their total size. Moving changes all paths below the moved object. Directory depth never exceeds 4040.

Input

The first line contains qq (1q2000001 \le q \le 200000). The following lines contain commands. The total length of all paths is at most 5×1065\times10^6, and file sizes are at most 10910^9.

Output

For each query, print the number of ordinary files in the directory subtree and their total size.

Samples

Sample 1

Input:

10
MK /a
MK /b
TOUCH /a/x 5
MK /a/c
TOUCH /a/c/y 7
Q /a
MV /a/c /b
Q /a
Q /b
RM /a/x

Output:

2 12
1 5
1 7

在线编程 IDE

建议全屏模式获得最佳体验