`{"id":"071629c1-b941-4156-ab01-3531bc0715d7","name":" No Max No Min","description":"You have an array with n elements. you have to create all subsequences of this array with length K. For each subsequence, you have to write down the product of k-2 integers, all elements of this sequence except the minimum and maximum element.\r\nyour work will be considered done if you will be able to write down all these numbers and tell PepBoss their product mod 10^9+7.","inputFormat":"The first line contains integer N (length of array) and K.\r\nThe second line contains N space separated integers.","outputFormat":"Print a single line containing one integer - the product of all numbers written down by you modulo 10^9+7.","constraints":"1&lt;= N &lt;= 5000\r\n3 &lt;= K &lt;= N\r\n1 &lt;= arr[i] &lt;= 10000","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.util.Arrays;\r\nimport java.util.Scanner;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n\r\n int n = scn.nextInt();\r\n int k = scn.nextInt();\r\n\r\n long[] arr = new long[n];\r\n for (int z = 0; z < n; z++) {\r\n arr[z] = scn.nextInt();\r\n }\r\n }\r\n\r\n}\r\n"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"hard","sampleInput":"4 3 \r\n1 2 3 4","sampleOutput":"36\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"086949fa-3c5e-40c6-8a9c-f9be4b400318","name":"Number Theory For Experts","slug":"number-theory-for-experts","type":0},{"id":"7bbe3fe7-4b6b-43bc-a1c8-4a53e4484e5f","name":" No Max No Min","slug":"no-max-no-min","type":1}],"next":{"id":"7a0addd3-431f-49f2-9130-83ccdd374ccf","name":"Prime Factors Using Sieve","type":1,"slug":"prime-factors-using-sieve"},"prev":{"id":"910daa87-1899-4fb1-8e06-38ea272e0bd4","name":"Modular C(n,r)","type":1,"slug":"modular-c-n-r"}}}`

No Max No Min

You have an array with n elements. you have to create all subsequences of this array with length K. For each subsequence, you have to write down the product of k-2 integers, all elements of this sequence except the minimum and maximum element. your work will be considered done if you will be able to write down all these numbers and tell PepBoss their product mod 10^9+7.

`{"id":"071629c1-b941-4156-ab01-3531bc0715d7","name":" No Max No Min","description":"You have an array with n elements. you have to create all subsequences of this array with length K. For each subsequence, you have to write down the product of k-2 integers, all elements of this sequence except the minimum and maximum element.\r\nyour work will be considered done if you will be able to write down all these numbers and tell PepBoss their product mod 10^9+7.","inputFormat":"The first line contains integer N (length of array) and K.\r\nThe second line contains N space separated integers.","outputFormat":"Print a single line containing one integer - the product of all numbers written down by you modulo 10^9+7.","constraints":"1&lt;= N &lt;= 5000\r\n3 &lt;= K &lt;= N\r\n1 &lt;= arr[i] &lt;= 10000","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.util.Arrays;\r\nimport java.util.Scanner;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n\r\n int n = scn.nextInt();\r\n int k = scn.nextInt();\r\n\r\n long[] arr = new long[n];\r\n for (int z = 0; z < n; z++) {\r\n arr[z] = scn.nextInt();\r\n }\r\n }\r\n\r\n}\r\n"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"hard","sampleInput":"4 3 \r\n1 2 3 4","sampleOutput":"36\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"086949fa-3c5e-40c6-8a9c-f9be4b400318","name":"Number Theory For Experts","slug":"number-theory-for-experts","type":0},{"id":"7bbe3fe7-4b6b-43bc-a1c8-4a53e4484e5f","name":" No Max No Min","slug":"no-max-no-min","type":1}],"next":{"id":"7a0addd3-431f-49f2-9130-83ccdd374ccf","name":"Prime Factors Using Sieve","type":1,"slug":"prime-factors-using-sieve"},"prev":{"id":"910daa87-1899-4fb1-8e06-38ea272e0bd4","name":"Modular C(n,r)","type":1,"slug":"modular-c-n-r"}}}`

Editor

No Max No Min

hard

You have an array with n elements. you have to create all subsequences of this array with length K. For each subsequence, you have to write down the product of k-2 integers, all elements of this sequence except the minimum and maximum element. your work will be considered done if you will be able to write down all these numbers and tell PepBoss their product mod 10^9+7.

Constraints

1<= N <= 5000 3 <= K <= N 1 <= arr[i] <= 10000

Format

Input

The first line contains integer N (length of array) and K. The second line contains N space separated integers.

Output

Print a single line containing one integer - the product of all numbers written down by you modulo 10^9+7.

Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}4 3 1 2 3 4```

Sample Output

```.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}36 ```

Discussions

Show Discussion

Related Resources