L - Distance Graph

Languages: C, C++, Java, Python, Kotlin
Time & Memory limits: (details)

Input

Output

Sample test(s)

Input
6 2 1 2
--- Showing first 30 lines (click "Copy" to get full content) ---
Output
9
--- Showing first 30 lines (click "Copy" to get full content) ---
Input
10 4 1 2 3 4
--- Showing first 30 lines (click "Copy" to get full content) ---
Output
-1
--- Showing first 30 lines (click "Copy" to get full content) ---
Input
11 4 1 2 3 4
--- Showing first 30 lines (click "Copy" to get full content) ---
Output
21
--- Showing first 30 lines (click "Copy" to get full content) ---
Input
15 4 1 2 3 4
--- Showing first 30 lines (click "Copy" to get full content) ---
Output
46
--- Showing first 30 lines (click "Copy" to get full content) ---

Notes