@@ -0,0 +1,1552 @@
+import java.io.*;%0Aimport java.util.*;%0Aimport java.text.*;%0Aimport java.math.*;%0Aimport java.util.regex.*;%0A%0Apublic class MarkAndToys %7B%0A    static int%5B%5D merge(int%5B%5D a,int lo,int mid,int hi)%7B%0A      int n=a.length;%0A        int aux%5B%5D=new int%5Bn%5D;%0A        for (int k = lo; k %3C= hi; k++)%0A    aux%5Bk%5D = a%5Bk%5D;%0Aint i = lo, j = mid+1;%0Afor (int k = lo; k %3C= hi; k++)%0A%7B%0Aif (i %3E mid) a%5Bk%5D = aux%5Bj++%5D;%0Aelse if (j %3E hi) a%5Bk%5D = aux%5Bi++%5D;%0Aelse if (aux%5Bj%5D%3C aux%5Bi%5D) a%5Bk%5D = aux%5Bj++%5D;%0Aelse a%5Bk%5D = aux%5Bi++%5D;%0A%7D%0A        return a;%0A    %7D%0A    static int%5B%5D mergeSort(int%5B%5D p,int l,int h)%7B%0A        if (h%3C=l) return p;%0A        int m=l+(h-l)/2;%0A        p=mergeSort(p,l,m);%0A        p=mergeSort(p,m+1,h);%0A        p=merge(p,l,m,h);%0A        return p;%0A    %7D%0A    static int compute(int x,int%5B%5D p)%7B%0A        int n=p.length;%0A        p=mergeSort(p,0,n-1);%0A       %0A        /*for(int i=0;i%3Cn;i++)%7B%0A            System.out.print(p%5Bi%5D+%22 %22);%0A        %7D*/%0A        int count=0;%0A        long sum=0;%0A        for(int i=0;i%3Cp.length&&sum%3Cx&&p%5Bi%5D%3C=x;i++,count++)%7B%0A            sum+=p%5Bi%5D;%0A           //System.out.println(%22with %22+p%5Bi%5D+%22 sum is %22+sum);%0A        %7D%0A        if(sum%3Ex)return count-1;%0A        else%0A            return count;%0A    %7D%0A    public static void main(String%5B%5D args) %7B%0A        Scanner stdin=new Scanner(System.in);%0A        int n=stdin.nextInt(),k=stdin.nextInt();%0A        int prices%5B%5D=new int%5Bn%5D;%0A        for(int i=0;i%3Cn;i++) prices%5Bi%5D=stdin.nextInt();%0A        %0A        int answer = compute(k,prices);%0A        // Compute the final answer from n,k,prices %0A        System.out.println(answer);%0A    %7D%0A%7D%0A

Create MarkAndToys.java