# Index sum

Problem Statement:

Given an array a of n integers. Find the maximum value of (i + j) such that 1 ≤ i < j ≤ n and a\[i] = a\[j]. Input The First line of the input contains n. The next line contains n space-separated integers.

Constraints 1 ≤ n ≤ 105 1 ≤ a\[i] ≤ n Output Output a single integer denoting maximum sum. Example Input: 6 2 3 1 2 3 5

Output: 7

Explanation: for 2 => i = 1, j = 4 => i+j = 5 for 3 => i = 2, j = 5 => i+j = 7

link:<https://my.newtonschool.co/playground/code/m1lw3ytpn7mt/>

````java
```java
import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework

// don't change the name of this class
// you can add inner classes if needed
class Main {
    public static void main (String[] args) {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int max=0;
    HashMap<Integer,Integer>hm=new HashMap<>();
    for(int i=0;i<n;i++){
        int a=sc.nextInt();
        if(hm.containsKey(a)){
        max=Math.max(max,i+hm.get(a)+2);
        hm.remove(a);
        hm.put(a,i);
        }else{
            hm.put(a,i);
        }
    }
    System.out.println(max);
    }
}
```
````


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://anand-aryan.gitbook.io/placecom-asssignment/index-sum.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
