{"raw_statement":[{"iden":"statement","content":"You are given a set of _n_ elements indexed from 1 to _n_. The weight of _i_\\-th element is _w__i_. The weight of some subset of a given set is denoted as . The weight of some partition _R_ of a given set into _k_ subsets is (recall that a partition of a given set is a set of its subsets such that every element of the given set belongs to exactly one subset in partition).\n\nCalculate the sum of weights of all partitions of a given set into exactly _k_ **non-empty** subsets, and print it modulo 109 + 7. Two partitions are considered different iff there exist two elements _x_ and _y_ such that they belong to the same set in one of the partitions, and to different sets in another partition."},{"iden":"input","content":"The first line contains two integers _n_ and _k_ (1 ≤ _k_ ≤ _n_ ≤ 2·105) — the number of elements and the number of subsets in each partition, respectively.\n\nThe second line contains _n_ integers _w__i_ (1 ≤ _w__i_ ≤ 109)— weights of elements of the set."},{"iden":"output","content":"Print one integer — the sum of weights of all partitions of a given set into _k_ **non-empty** subsets, taken modulo 109 + 7."},{"iden":"examples","content":"Input\n\n4 2\n2 3 2 3\n\nOutput\n\n160\n\nInput\n\n5 2\n1 2 3 4 5\n\nOutput\n\n645"},{"iden":"note","content":"Possible partitions in the first sample:\n\n1.  {{1, 2, 3}, {4}}, _W_(_R_) = 3·(_w_1 + _w_2 + _w_3) + 1·_w_4 = 24;\n2.  {{1, 2, 4}, {3}}, _W_(_R_) = 26;\n3.  {{1, 3, 4}, {2}}, _W_(_R_) = 24;\n4.  {{1, 2}, {3, 4}}, _W_(_R_) = 2·(_w_1 + _w_2) + 2·(_w_3 + _w_4) = 20;\n5.  {{1, 3}, {2, 4}}, _W_(_R_) = 20;\n6.  {{1, 4}, {2, 3}}, _W_(_R_) = 20;\n7.  {{1}, {2, 3, 4}}, _W_(_R_) = 26;\n\nPossible partitions in the second sample:\n\n1.  {{1, 2, 3, 4}, {5}}, _W_(_R_) = 45;\n2.  {{1, 2, 3, 5}, {4}}, _W_(_R_) = 48;\n3.  {{1, 2, 4, 5}, {3}}, _W_(_R_) = 51;\n4.  {{1, 3, 4, 5}, {2}}, _W_(_R_) = 54;\n5.  {{2, 3, 4, 5}, {1}}, _W_(_R_) = 57;\n6.  {{1, 2, 3}, {4, 5}}, _W_(_R_) = 36;\n7.  {{1, 2, 4}, {3, 5}}, _W_(_R_) = 37;\n8.  {{1, 2, 5}, {3, 4}}, _W_(_R_) = 38;\n9.  {{1, 3, 4}, {2, 5}}, _W_(_R_) = 38;\n10.  {{1, 3, 5}, {2, 4}}, _W_(_R_) = 39;\n11.  {{1, 4, 5}, {2, 3}}, _W_(_R_) = 40;\n12.  {{2, 3, 4}, {1, 5}}, _W_(_R_) = 39;\n13.  {{2, 3, 5}, {1, 4}}, _W_(_R_) = 40;\n14.  {{2, 4, 5}, {1, 3}}, _W_(_R_) = 41;\n15.  {{3, 4, 5}, {1, 2}}, _W_(_R_) = 42."}],"translated_statement":[{"iden":"statement","content":"你被给定一个包含 #cf_span[n] 个元素的集合，元素编号从 #cf_span[1] 到 #cf_span[n]。第 #cf_span[i] 个元素的权重为 #cf_span[wi]。一个子集的权重定义为该子集中所有元素权重之和。一个将给定集合划分为 #cf_span[k] 个子集的划分 #cf_span[R] 的权重定义为  （回忆：一个划分是原集合的若干子集的集合，满足原集合中的每个元素恰好属于其中一个子集）。\n\n计算将给定集合划分为恰好 #cf_span[k] 个 *非空* 子集的所有划分的权重之和，并对 #cf_span[109 + 7] 取模输出。两个划分被认为是不同的，当且仅当存在两个元素 #cf_span[x] 和 #cf_span[y]，使得它们在其中一个划分中属于同一个子集，而在另一个划分中属于不同的子集。\n\n第一行包含两个整数 #cf_span[n] 和 #cf_span[k]（#cf_span[1 ≤ k ≤ n ≤ 2·105]）——元素个数和每个划分中的子集个数。\n\n第二行包含 #cf_span[n] 个整数 #cf_span[wi]（#cf_span[1 ≤ wi ≤ 109]）——集合中各元素的权重。\n\n输出一个整数——将给定集合划分为 #cf_span[k] 个 *非空* 子集的所有划分的权重之和，对 #cf_span[109 + 7] 取模。"},{"iden":"input","content":"第一行包含两个整数 #cf_span[n] 和 #cf_span[k]（#cf_span[1 ≤ k ≤ n ≤ 2·105]）——元素个数和每个划分中的子集个数。第二行包含 #cf_span[n] 个整数 #cf_span[wi]（#cf_span[1 ≤ wi ≤ 109]）——集合中各元素的权重。"},{"iden":"output","content":"输出一个整数——将给定集合划分为 #cf_span[k] 个 *非空* 子集的所有划分的权重之和，对 #cf_span[109 + 7] 取模。"},{"iden":"examples","content":"输入\n4 2\n2 3 2 3\n输出\n160\n\n输入\n5 2\n1 2 3 4 5\n输出\n645"},{"iden":"note","content":"第一个样例的可能划分：  #cf_span[{{1, 2, 3}, {4}}], #cf_span[W(R) = 3·(w1 + w2 + w3) + 1·w4 = 24];  #cf_span[{{1, 2, 4}, {3}}], #cf_span[W(R) = 26];  #cf_span[{{1, 3, 4}, {2}}], #cf_span[W(R) = 24];  #cf_span[{{1, 2}, {3, 4}}], #cf_span[W(R) = 2·(w1 + w2) + 2·(w3 + w4) = 20];  #cf_span[{{1, 3}, {2, 4}}], #cf_span[W(R) = 20];  #cf_span[{{1, 4}, {2, 3}}], #cf_span[W(R) = 20];  #cf_span[{{1}, {2, 3, 4}}], #cf_span[W(R) = 26]; 第二个样例的可能划分：  #cf_span[{{1, 2, 3, 4}, {5}}], #cf_span[W(R) = 45];  #cf_span[{{1, 2, 3, 5}, {4}}], #cf_span[W(R) = 48];  #cf_span[{{1, 2, 4, 5}, {3}}], #cf_span[W(R) = 51];  #cf_span[{{1, 3, 4, 5}, {2}}], #cf_span[W(R) = 54];  #cf_span[{{2, 3, 4, 5}, {1}}], #cf_span[W(R) = 57];  #cf_span[{{1, 2, 3}, {4, 5}}], #cf_span[W(R) = 36];  #cf_span[{{1, 2, 4}, {3, 5}}], #cf_span[W(R) = 37];  #cf_span[{{1, 2, 5}, {3, 4}}], #cf_span[W(R) = 38];  #cf_span[{{1, 3, 4}, {2, 5}}], #cf_span[W(R) = 38];  #cf_span[{{1, 3, 5}, {2, 4}}], #cf_span[W(R) = 39];  #cf_span[{{1, 4, 5}, {2, 3}}], #cf_span[W(R) = 40];  #cf_span[{{2, 3, 4}, {1, 5}}], #cf_span[W(R) = 39];  #cf_span[{{2, 3, 5}, {1, 4}}], #cf_span[W(R) = 40];  #cf_span[{{2, 4, 5}, {1, 3}}], #cf_span[W(R) = 41];  #cf_span[{{3, 4, 5}, {1, 2}}], #cf_span[W(R) = 42]. "}],"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ n, k \\in \\mathbb{Z}^+ $ with $ 1 \\leq k \\leq n \\leq 2 \\cdot 10^5 $.  \nLet $ W = (w_1, w_2, \\dots, w_n) $ be a sequence of positive integers representing the weights of $ n $ elements.  \nLet $ \\mathcal{P}_{n,k} $ denote the set of all partitions of the set $ [n] = \\{1, 2, \\dots, n\\} $ into exactly $ k $ non-empty, unlabeled subsets.  \n\nFor a partition $ R \\in \\mathcal{P}_{n,k} $, define its weight as:  \n$$\n\\text{weight}(R) = \\sum_{S \\in R} \\left( \\sum_{i \\in S} w_i \\right)\n$$\n\n**Constraints**  \n1. $ 1 \\leq k \\leq n \\leq 2 \\cdot 10^5 $  \n2. $ 1 \\leq w_i \\leq 10^9 $ for all $ i \\in [n] $\n\n**Objective**  \nCompute:  \n$$\n\\sum_{R \\in \\mathcal{P}_{n,k}} \\text{weight}(R) \\mod (10^9 + 7)\n$$","simple_statement":null,"has_page_source":false}