CF1633E Spanning Tree Queries

Description

You are given a connected weighted undirected graph, consisting of $ n $ vertices and $ m $ edges. You are asked $ k $ queries about it. Each query consists of a single integer $ x $ . For each query, you select a spanning tree in the graph. Let the weights of its edges be $ w_1, w_2, \dots, w_{n-1} $ . The cost of a spanning tree is $ \sum \limits_{i=1}^{n-1} |w_i - x| $ (the sum of absolute differences between the weights and $ x $ ). The answer to a query is the lowest cost of a spanning tree. The queries are given in a compressed format. The first $ p $ $ (1 \le p \le k) $ queries $ q_1, q_2, \dots, q_p $ are provided explicitly. For queries from $ p+1 $ to $ k $ , $ q_j = (q_{j-1} \cdot a + b) \mod c $ . Print the xor of answers to all queries.

Input Format

N/A

Output Format

N/A

Explanation/Hint

The queries in the first example are $ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 $ . The answers are $ 11, 9, 7, 3, 1, 5, 8, 7, 5, 7, 11 $ . ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1633E/cc44ec2a2f7074b3d4db31716a40d840e49d6671.png)The queries in the second example are $ 3, 0, 2, 1, 6, 0, 3, 5, 4, 1 $ . The answers are $ 14, 19, 15, 16, 11, 19, 14, 12, 13, 16 $ . ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1633E/8c952d1a0cb110f0d7bc671856ab3b11fe089a16.png)The queries in the third example are $ 75, 0, 0, \dots $ . The answers are $ 50, 150, 150, \dots $ . ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1633E/0df04a7e4050b5f60aca076480a18740ebab3d6b.png)