Boxes in a Line

You have n boxes in a line on the table numbered 1 . . . n from left to right. Your task is to simulate 4 kinds of commands: • 1 X Y: moveboxX tothelefttoY (ignorethisifX isalreadytheleftofY) • 2 X Y: moveboxX totherighttoY (ignorethisifX isalreadytherightofY) • 3 X Y : swap box X and Y • 4: reverse the whole line. Commands are guaranteed to be valid, i.e. X will be not equal to Y . For example, if n = 6, after executing 1 1 4, the line becomes 2 3 1 4 5 6. Then after executing 2 3 5,thelinebecomes2 1 4 5 3 6. Thenafterexecuting3 1 6,thelinebecomes2 6 4 5 3 1. Then after executing 4, then line becomes 1 3 5 4 6 2 Input There will be at most 10 test cases. Each test case begins with a line containing 2 integers n, m (1 ≤ n, m ≤ 100, 000). Each of the following m lines contain a command. Output For each test case, print the sum of numbers at odd-indexed positions. Positions are numbered 1 to n from left to right. Sample Input 64 114 235 316 4 63 114 235 316 100000 1 4 Sample Output Case 1: 12 Case 2: 9 Case 3: 2500050000