import java.util.*;
public class Find_muti
{
public static int[] findMuti(int[] x)
{
int N = x.length;
int[] a = new int[N];
int[] b = new int[N + 1];
for (int i = 0; i < N; i++)
a[i] = x[i];
Arrays.sort(a);
int t = a[0];
int flag = 0;
int cnt = 1;
for (int i = 1; i < N; )
{
if (t == a[i])
{
if (i == N-1)
{
b[cnt++] = a[i];
break;
}
flag = 1;
i++;
}
else if (t != a[i])
{
if (flag == 1)
b[cnt++] = t;
t = a[i];
flag = 0;
i++;
}
else
{
}
}
b[0] = cnt - 1;
return b;
}
public static int[] findSingle(int[] x)
{
int N = x.length;
int[] a = new int[N];
int[] b = new int[N + 1];
for (int i = 0; i < N; i++)
a[i] = x[i];
Arrays.sort(a);
int t = a[0];
int flag = 1;
int cnt = 1;
for (int i = 1; i < N; )
{
if (t == a[i])
{
flag = 0;
i++;
}
else if (t != a[i])
{
if (flag == 1)
b[cnt++] = t;
if (i == N-1)
b[cnt++] = a[i];
t = a[i];
flag = 1;
i++;
}
else
{
}
}
b[0] = cnt - 1;
return b;
}
public static void main(String[] args)
{
int[] a = {1,2,2,3,4,4,5,6,7,7,8,8,8,9,9};
int[] b = findMuti(a);
int[] c = findSingle(a);
System.out.println(Arrays.toString(b));
System.out.println(Arrays.toString(c));
}