Subtask 1. For a=b=1,c=n, there always is a solution. It's enough to take p=(1,2,…,n) and q=r=(n,n−1,…,1).
Subtask 2. Let's notice the simple property:
Let a,b be any sequences of length n co