Skip to content

Instantly share code, notes, and snippets.

@viniru
Created July 5, 2018 11:56
Show Gist options
  • Save viniru/a4715aa7ad0d4bfc76ba10a10ecfa3fa to your computer and use it in GitHub Desktop.
Save viniru/a4715aa7ad0d4bfc76ba10a10ecfa3fa to your computer and use it in GitHub Desktop.
dqqw
import java.util.*;
public class Sum
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
TreeSet<Long> ts = new TreeSet<>();
ArrayList<Long> al1 = new ArrayList<>();
ArrayList<Long> al2 = new ArrayList<>();
HashSet<Long> hs = new HashSet<>();
long x=0;long duplicate=0;
while(sc.hasNextInt())
{
x = sc.nextInt();
if(hs.contains(x) == false)
{
al1.add(-10000-x);
al2.add(10000-x);
ts.add(x);
hs.add(x);
}
else duplicate++;
}
long size = 0;
for(int i=0;i<al1.size();i++)
{
long a = al1.get(i);
long b = al2.get(i);
size += ts.subSet(a,true,b,true).size();
}
System.out.println(size - duplicate);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment