-
-
Save viniru/a4715aa7ad0d4bfc76ba10a10ecfa3fa to your computer and use it in GitHub Desktop.
dqqw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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