← All problemsSign in

Modular Circular Permutations

CodeChefRating 2723Open on judge ↗

You are given an array $A = [A_1, A_2, \ldots, A_N]$ containing **distinct positive** integers. Let $B$ be a [permutation](https://en.wikipedia.org/wiki/Permutation) of $A$. Define the *value* of $B$ to be $$\sum_{i=1}^N (B_i \bmod{B_{i+1}})$$ where $B_{N+1}$ is treated to be $B_1$. Find the **maximum** *value* across all permutations of $A$. ### Input - The first line of input contains a sing

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start