{"problem":{"name":"Constant Sum Subsequence","description":{"content":"We have a sequence of positive integers of length $N^2$, $A=(A_1,\\ A_2,\\ \\dots,\\ A_{N^2})$, and a positive integer $S$. For this sequence of positive integers, $A_i=A_{i+N}$ holds for positive integer","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":5000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"arc150_f"},"statements":[{"statement_type":"Markdown","content":"We have a sequence of positive integers of length $N^2$, $A=(A_1,\\ A_2,\\ \\dots,\\ A_{N^2})$, and a positive integer $S$. For this sequence of positive integers, $A_i=A_{i+N}$ holds for positive integers $i\\ (1\\leq i \\leq N^2-N)$, and only $A_1,\\ A_2,\\ \\dots,\\ A_N$ are given as the input.\nFind the minimum integer $L$ such that every sequence $B$ of positive integers totaling $S$ is a (not necessarily contiguous) subsequence of the sequence $(A_1,\\ A_2,\\ \\dots,\\ A_L)$ of positive integers.\nIt can be shown that at least one such $L$ exists under the Constraints of this problem.\n\n## Constraints\n\n*   $1 \\leq N \\leq 1.5 \\times 10^6$\n*   $1 \\leq S \\leq \\min(N,2 \\times 10^5)$\n*   $1 \\leq A_i \\leq S$\n*   For every positive integer $x\\ (1\\leq x \\leq S)$, $(A_1,\\ A_2,\\ \\dots,\\ A_N)$ contains at least one occurrence of $x$.\n*   All values in the input are integers.\n\n## Input\n\nThe input is given from Standard Input in the following format:\n\n$N$ $S$\n$A_1$ $A_2$ $\\dots$ $A_N$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"arc150_f","tags":[],"sample_group":[["6 4\n1 1 2 1 4 3","9\n\nThere are eight sequences $B$ to consider: $B=(1,\\ 1,\\ 1,\\ 1),\\ (1,\\ 1,\\ 2),\\ (1,\\ 2,\\ 1),\\ (1,\\ 3),\\ (2,\\ 1,\\ 1),\\ (2,\\ 2),\\ (3,\\ 1),\\ (4)$.\nFor $L=8$, for instance, $B=(2,\\ 2)$ is not a subsequence of $(A_1,A_2,\\ \\dots,\\ A_8)=(1,\\ 1,\\ 2,\\ 1,\\ 4,\\ 3,\\ 1,\\ 1)$.\nFor $L=9$, on the other hand, every $B$ is a subsequence of $(A_1,A_2,\\ \\dots,\\ A_9)=(1,\\ 1,\\ 2,\\ 1,\\ 4,\\ 3,\\ 1,\\ 1,\\ 2)$."],["14 5\n1 1 1 2 3 1 2 4 5 1 1 2 3 1","11"],["19 10\n1 6 2 7 4 8 5 9 1 10 4 1 3 1 3 2 2 2 1","39"]],"created_at":"2026-03-03 11:01:14"}}