Help me in solving TIES problem

My issue

I got the gist of the problem and can solve it but am not able to write the code

My code

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
	public static void main (String[] args) throws java.lang.Exception
		// your code goes here

Problem Link: TIES Problem - CodeChef

there is no benefit for you in me writing a solution. You can find Java solutions to your problem here: CodeChef: Practical coding for everyone

Even if you don’t know how to write it down yet, you can split the task of writing code in subproblems. In fact, you need to do that always. A good split would be:

Input / Logic / Output
(Note: sometimes you need to mix Input and Logic. Or Logic and Output)

you can split them up further. Input can be split into all Input Variables. The testcases first, then n and the array.

Try to write something. If you really can’t, take code from someone else and try to adjust it. If that is too much as well, you should probably try an even easier Problem.

AIs are prone to errors, but may be helpful as well. It can guide you through a solution from someone else and explain it to you. Just be aware that while AIs are mostly accurate when it comes to easy problems, it can happen that they lie like crazy.

feel free to use my Input:
(And really be aware that the AI often lies. In this case, it answered the question nicely)