code:
package boj_february;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class BOJ_17135_teacher {
	private static int R, C, D;
	private static int [][] map;
	private static int MAX = Integer.MIN_VALUE;

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		scanner = new Scanner(src);
		R = scanner.nextInt();
		C = scanner.nextInt();
		D = scanner.nextInt();

		map = new int[R][C];
		for(int r=0; r<R; r++) {
			for(int c=0; c<C; c++) {
				map[r][c]=scanner.nextInt();
			}
		}

		combination(0, new int[3], 0, 0);

		System.out.println(MAX);
	}

	public static void attack(int [] positions) {

		List<Enemy> enemies = new ArrayList<>();
		for(int r=0; r<R; r++) {
			for(int c=0; c<C; c++) {
				if(map[r][c]==1) {
					enemies.add(new Enemy(r, c));
				}
			}
		}

		int deadMan = 0;
		while(true) {

			for(int i=0; i<positions.length; i++) {
				int archer = positions[i];
				PriorityQueue<Enemy> targetedEnemies = new PriorityQueue<>();

				for(int e=0; e<enemies.size(); e++) {
					Enemy enemy = enemies.get(e);

					enemy.d = Math.abs(archer - enemy.c) + Math.abs(enemy.r - R);

					if(enemy.d <=D) {
						targetedEnemies.offer(enemy);
					}
				}

				if(!targetedEnemies.isEmpty()) {
					targetedEnemies.poll().isTargeted = true;
				}
			}

			for(int e=0; e<enemies.size(); e++) {
				Enemy enemy = enemies.get(e);
				if(enemy.isTargeted) {
					enemies.remove(e--);
					deadMan++;
				}else if(enemy.r==R-1){
					enemies.remove(e--);
				}else {
					enemy.r++;
				}
			}

			if(enemies.size()==0) {
				break;
			}
		}
		MAX = Integer.max(MAX, deadMan);
	}

	public static void combination(int r, int [] temp, int ti, int si) {
		if(r==3) {

			attack(temp);
			return;
		}
		for(int i=si; i<C; i++) {
			temp[ti] = i;
			combination(r+1, temp, ti+1, i+1);
		}
	}

	static class Enemy implements Comparable<Enemy>{
		Integer r, c, d;
		boolean isTargeted;
		public Enemy(Integer r, Integer c) {
			super();
			this.r = r;
			this.c = c;
		}

		public int compareTo(Enemy o) {
			if(this.d.equals(o.d)) {
				return this.c.compareTo(o.c);
			}else {
				return this.d.compareTo(o.d);
			}
		}

		@Override
		public String toString() {
			return "[r=" + r + ", c=" + c + "]";
		}
	}

	private static String src = "5 5 2\r\n" +
			"0 0 0 0 0\r\n" +
			"0 0 0 0 0\r\n" +
			"0 0 0 0 0\r\n" +
			"1 1 1 1 1\r\n" +
			"0 0 0 0 0";
}

entry_point: attack


code:
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void compFunc(String[] args) throws IOException {

        Scanner in = new Scanner(System.in);

        while (in.hasNext()) {
            int n = in.nextInt();
            int g = in.nextInt();

            int[] results = new int[n];
            int points = 0;

            for (int i = 0; i < n; i++) {
                byte s = in.nextByte();
                byte r = in.nextByte();

                results[i] = s - r;
            }

            Arrays.sort(results);

            for (int i = n - 1; i > -1; i--) {
                if (results[i] > 0) {
                    points += 3;
                } else if (results[i] == 0) {
                    if (g > 0) {
                        g--;
                        points += 3;
                    } else {
                        points += 1;
                    }
                } else {
                    int result = g + results[i];

                    if (g > 0) {
                        if (result == 0) {
                            points += 1;
                            break;
                        } else if (result > 0) {
                            points += 3;
                            g += results[i] - 1;
                        } else {
                            break;
                        }
                    } else {
                        break;
                    }
                }
            }

            System.out.println(points);
        }

        in.close();
    }

}

entry_point: compFunc


code:
import java.util.*;
public class Main implements Comparator< Integer> {
  static class Edge{
   int e,c;
   Edge next;
   Edge rev;
  public void dec(int f){
   c-=f;
   rev.c+=f;
  }
 }

 int n,m,src,tag;
 final Edge[] g=new Edge[200];
 final int[] h=new int[200];  final int[] ex=new int[200];
 final Scanner sc=new Scanner(System.in);
 final PriorityQueue< Integer> pq=new PriorityQueue< Integer>(200,this);

 boolean init(){
   if(!sc.hasNext()) return false;
   m=sc.nextInt();
   n=sc.nextInt();
   src=0;   tag=n-1;
  for(int i=0;i!=n;++i){
   g[i]=null;
   h[i]=0;
   ex[i]=0;
   }

  h[src]=n;
  for(int i=0;i!=m;++i){
   int a=sc.nextInt()-1,b=sc.nextInt()-1,c=sc.nextInt();
   Edge e0=addEdge(a, b, c),e1=addEdge(b,a,0);
   e0.rev=e1;e1.rev=e0;
  }    return true;
 }

  private Edge addEdge(int s, int e, int c) {
   Edge n=new Edge();
   n.c=c;
   n.e=e;
   n.next=g[s];
   g[s]=n;
  return n;
  }

  int work(){
   for(Edge e=g[src];e!=null;e=e.next){
    ex[e.e]+=e.c;
    e.dec(e.c);
    if(e.e!=src&&e.e!=tag){
     pq.add(e.e);
   }
  }
  while(pq.size()>0){
   int v=pq.poll();
   int exv=ex[v],hv=h[v];
   for(Edge e=g[v]; exv>0&&e!=null; e=e.next){
      if(e.c<=0 || hv !=h[e.e]+ 1 ) continue;
    int f=Math.min( exv , e.c);
    ex[e.e]+=f;
    exv-=f;
    e.dec(f);
    if(ex[e.e]==f&&e.e!=tag&&e.e!=src){
     pq.add(e.e);
    }
   }
   if(exv>0){
    for(Edge e=g[v];e!=null;e=e.next){
     if(e.c > 0 && hv>h[e.e]){
      hv=h[e.e];
     }
    }
    ++hv;
    pq.add(v);
   }
   ex[v]=exv;
   h[v]=hv;
  }
  return ex[tag];
 }

  void go(){     while(init()){
    System.out.println( work());
  }
  }

  public static void main(String[] args) {
    new Main().go();
  }

  public int compare(Integer o1, Integer o2) {
   return h[o2]-h[o1];
  }
}

entry_point: work


code:
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

    public static void compFunc(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        ArrayList<Integer[]> alist = new ArrayList<Integer[]>();

        for(int i = 0; i < n; i++) {
            int no_of_ele = scanner.nextInt();

            Integer [] intarr = new Integer[no_of_ele];

            for(int j = 0; j < no_of_ele; j++) {
                int ele = scanner.nextInt();
                intarr[j] = ele;
            }
            alist.add(intarr);

        }

        int q = scanner.nextInt();
        int [][] qarr = new int [q][2];

        for(int i = 0; i < q; i++) {
            for(int j = 0; j < 2; j++) {
                qarr[i][j] = scanner.nextInt();
            }
        }

        for(int i = 0; i < q; i++) {
            int index = qarr[i][0] - 1;
            int pos = qarr[i][1] - 1;

            Integer [] arr = alist.get(index);
            if((arr.length == 0) || (pos >= arr.length)) {
                System.out.println("ERROR!");
                continue;
            }
            int retrieveEle = arr[pos];
            System.out.println(retrieveEle);
        }

    }
}


code:
package gcj.y2016.round2;
import java.io.*;
import java.util.*;
import java.util.concurrent.*;

public class C {
	static final String NO = "IMPOSSIBLE";

	int hei, wid, p;
	int[] a;

	String solve() {
		int[] bx = new int[p];
		int[] by = new int[p];
		for (int i = 0; i < wid; i++) {
			bx[i] = 2 * i + 1;
			by[i] = 0;
			bx[hei + wid + i] = 2 * wid - 2 * i - 1;
			by[hei + wid + i] = 2 * hei;
		}
		for (int i = 0; i < hei; i++) {
			bx[wid + i] = 2 * wid;
			by[wid + i] = 2 * i + 1;
			bx[hei + 2 * wid + i] = 0;
			by[hei + 2 * wid + i] = 2 * hei - 2 * i - 1;
		}
		char[][] ans = new char[hei][wid];
		boolean[] connected = new boolean[p];
		int[] pair = new int[p];
		for (int i = 0; i < p; i += 2) {
			a[i]--;
			a[i + 1]--;
			pair[a[i]] = a[i + 1];
			pair[a[i + 1]] = a[i];
		}
		for (int turn = 0; turn < p / 2; turn++) {
			int from = -1, to = -1;
			for (int i = 0; i < p; i++) {
				if (connected[i]) {
					continue;
				}
				int j = i;
				for (;;) {
					j = (j + 1) % p;
					if (connected[j]) {
						continue;
					}
					break;
				}
				if (j == pair[i]) {
					from = i;
					to = j;
					break;
				}
			}
			if (from == -1) {
				return NO;
			}
			connected[from] = connected[to] = true;
			int x = bx[from];
			int y = by[from];
			int dx, dy;
			if (x == 0) {
				dx = dy = -1;
			} else if (y == 0) {
				dx = 1; dy = -1;
			} else if (x == 2 * wid) {
				dx = dy = 1;
			} else {
				dx = -1; dy = 1;
			}
			while (x != bx[to] || y != by[to]) {
				boolean ok = false;
				for (int t = 0; t <= 2; t++) {
					int dxNew = -dy;
					int dyNew = dx;
					dx = dxNew;
					dy = dyNew;
					if (x + dx < 0 || x + dx > 2 * wid || y + dy < 0 || y + dy > 2 * hei) {
						continue;
					}
					int x2 = Math.min(x, x + dx) / 2;
					int y2 = Math.min(y, y + dy) / 2;
					char drawn = (dx == dy) ? '\\' : '/';
					if (ans[y2][x2] == drawn || ans[y2][x2] == 0) {
						ans[y2][x2] = drawn;
						ok = true;
						break;
					}
				}
				if (!ok) {
					return NO;
				}
				x += dx;
				y += dy;
				dx *= -1;
				dy *= -1;
			}
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < hei; i++) {
			sb.append(new String(ans[i]).replace((char) 0, '/')).append("\n");
		}
		return sb.toString().trim();
	}

	public C(Scanner in) {
		hei = in.nextInt();
		wid = in.nextInt();
		p = 2 * (hei + wid);
		a = new int[p];
		for (int i = 0; i < p; i++) {
			a[i] = in.nextInt();
		}
	}

	public static void main(String[] args) throws Exception {
		int nThreads = 1;

		String fileNameSuffix = "";
		String formatOut = "Case #%2$d:\n%1$s";
		String formatSystemOut = formatOut;

		String fileName = C.class.getSimpleName().replaceFirst("_.*", "").toLowerCase() + fileNameSuffix;
		String inputFileName = fileName + ".in";
		String outputFileName = fileName + ".out";

		Locale.setDefault(Locale.US);
		Scanner in = new Scanner(new File(inputFileName));
		PrintWriter out = new PrintWriter(outputFileName);
		int tests = in.nextInt(); in.nextLine();
		nThreads = Math.min(nThreads, tests);
		@SuppressWarnings("unchecked")
		Callable<String>[] callables = new Callable[tests];
		for (int t = 0; t < tests; t++) {
			final C testCase = new C(in);
			final int testCaseNumber = t + 1;
			callables[t] = new Callable<String>() {
				@Override
				public String call() {
					String answer = testCase.solve();
					System.out.println(String.format(formatSystemOut, answer, testCaseNumber));
					return String.format(formatOut, answer, testCaseNumber);
				}
			};
		}
		try {
			if (nThreads > 1) {
				ExecutorService executor = Executors.newFixedThreadPool(4);
				@SuppressWarnings("unchecked")
				Future<String>[] outputs = new Future[tests];
				for (int t = 0; t < tests; t++) {
					outputs[t] = executor.submit(callables[t]);
				}
				for (int t = 0; t < tests; t++) {
					out.println(outputs[t].get());
				}
				executor.shutdown();
			} else {
				for (int t = 0; t < tests; t++) {
					out.println(callables[t].call());
				}
			}
		} catch (Exception e) {
			System.out.flush();
			System.err.flush();
			e.printStackTrace();
			System.exit(1);
		}
		System.out.println("COMPLETE");
		in.close();
		out.close();
	}
}

entry_point: solve


code:
package com.elfefe.fonctionne.mathengine.special;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;

public final class Primes {
	public static List<Long> distinctPrimeFactors(long n) {

		List<Long> factors = primeFactors(n);
		LinkedHashSet<Long> distinct = new LinkedHashSet<>(factors);

		return new ArrayList<Long>(distinct);
	}

	public static boolean isPrime(long n) {
		n = Math.abs(n);

		boolean prime = true;
		for (long i = 3; i <= Math.sqrt(n); i += 2) {

			if (n % i == 0) {
				prime = false;
				break;
			}
		}

		if ((n % 2 != 0 && prime && n > 2) || n == 2) {
			return true;
		} else {
			return false;
		}
	}

	public static long nextPrime(long n) {
		n++;
		if (n % 2 == 0) {
			n++;
		}

		long result = n;

		while (!isPrime(result)) {
			result += 2;
		}

		return result;
	}

	public static long previousPrime(long n) {
		n--;
		if (n % 2 == 0) {
			n--;
		}

		long result = n;
		while (!isPrime(result)) {
			result -= 2;
		}

		return result;
	}

	public static List<Long> primeFactors(long n) {
		long num = Math.abs(n);

		List<Long> factors = new ArrayList<Long>();

		if (num == 1) {
			factors.add(num);
		}

		for (long i = 2; i <= num / i; i++) {
			while (num % i == 0){
				factors.add(i);
				num /= i;
			}
		}

		if (num >= 0 && num != 1) {
			factors.add(num);
		}

		if (n < 0 && factors.size() != 0) {
			long first = factors.get(0);

			for (int i = 0; i < factors.size(); i++) {
				long current = factors.get(i);

				if (current == first)
					factors.set(i, -current);
				else
					break;
			}
		}

		return factors;
	}
}

entry_point: primeFactors


code:
package subArraySum;
import java.util.Arrays;

public class subArraySum {

    public static void subArraySumGreed(int[] arr, int k) {
        for (int i = 0; i < arr.length; i += 1) {
            int sum = 0;
            for (int j = i; j < arr.length; j += 1) {
                sum += arr[j];
                if (sum == k) {
                    System.out.println(Arrays.toString(Arrays.copyOfRange(arr, i, j + 1)));
                }
            }
        }
    }

    public static int subArraySumKadane(int[] arr, int k) {
        int best = 0;
        int current = 0;
        for (int i = 0; i < arr.length; i += 1) {
            current = Math.max(0, current + arr[i]);
            best = Math.max(current, best);
        }
        return best;
    }

    public static int[] subArraySumKadaneK(int[] arr, int k) {
        int current = arr[0];
        int i = 0;
        int j = 0;
        while (j < arr.length) {
            if (current == k) {
                return Arrays.copyOfRange(arr, i, j + 1);
            }
            if (current < k) {
                j += 1;
                if (j < arr.length) {
                    current += arr[j];
                }
            } else {
                current = current - arr[i];
                i += 1;
            }
        }
        return Arrays.copyOfRange(arr, i, j);
    }

    public static void main(String[] args) {
        subArraySumGreed(new int[] { 1, 2, 3, 4, 1, 7 }, 12);
        System.out.println(Arrays.toString(subArraySumKadaneK(new int[] { 2, 4, 17, 9, 6, 3 }, 18)));
        System.out.println(subArraySumKadane(new int[] { 1, 2, 3, 4, 1, 7 }, 12));
    }
}

entry_point: subArraySumKadaneK


code:
package net.wastl.webmail.misc;

import java.util.Properties;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.util.Set;
import java.util.HashSet;
import java.util.Enumeration;

public class ExpandableProperties extends Properties {
    static final long serialVersionUID = -6501669686410348173L;

    Pattern propVarPattern = Pattern.compile("\\Q${\\E([^}]+?)\\Q}");
    private boolean permitUnset = false;
    private boolean namesToo = false;
    private boolean sysToo = true;

    public void expand(Properties inExp, boolean permitUnset,
            boolean namesToo, boolean sysToo) {
        Properties exp = (sysToo ? (new Properties(System.getProperties()))
                                 : (new Properties()));
        exp.putAll(inExp);
        Properties additions = new Properties();
        Set<String> zaps = new HashSet<String>();

        Enumeration e = propertyNames();
        String pk, pv;
        String newKey, newVal;
        Matcher m;
        while (e.hasMoreElements()) {
            pk = (String) e.nextElement();
            pv = getProperty(pk);
            newKey = null;
            if (namesToo) {
                m = propVarPattern.matcher(pk);
                if (m.find()) newKey = subst(m, pk, exp, permitUnset);
            }
            m = propVarPattern.matcher(pv);
            newVal = (m.find() ? subst(m, pv, exp, permitUnset) : null);
            if (newKey != null) zaps.add(pk);
            if (newKey != null || newVal != null)
                additions.setProperty(((newKey == null) ? pk : newKey),
                    ((newVal == null) ? pv : newVal));
        }
        for (String k : zaps) remove(k);
        putAll(additions);
    }

    protected String subst(Matcher m, String origVal,
            Properties exp, boolean permitUnset) {
        int afterLast = 0;
        String substVal;
        StringBuilder sb = new StringBuilder();
        do {
            substVal = exp.getProperty(m.group(1));
            if (substVal == null) {
                if (permitUnset) continue;
                throw new IllegalStateException(
                        "Undefined property '" + m.group(1) + "'");
            }
            sb.append(origVal.substring(afterLast, m.start())
                    + substVal);
            afterLast = m.end();
        } while (m.find());
        sb.append(origVal.substring(afterLast));
        if (origVal.equals(sb.toString())) return null;

        return sb.toString();
    }
}

entry_point: expand


code:
package practice.slidingwindow;

import java.util.ArrayList;
import java.util.List;

public class FindFirstNegative {

  public List<Integer> findFirstNegative(int[] arr, int k) {
    List<Integer> output = new ArrayList<>();
    int i = 0, j = 0;
    List<Integer> negativeList = new ArrayList<>();
    while (j < arr.length) {
      if (arr[j] < 0) {
        negativeList.add(arr[j]);
      }
      if (j - i + 1 < k) {
        j++;
      } else if (j - i + 1 == k) {
        if (negativeList.isEmpty()) {
          output.add(0);
        } else {
          output.add(negativeList.get(0));
          if (arr[i] == negativeList.get(0)) {
            negativeList.remove(0);
          }
        }
        i++;
        j++;
      }
    }
    return output;
  }

  public static void main(String[] args) {
    FindFirstNegative findMax = new FindFirstNegative();
    int[] arr = new int[]{2, -1, -7, 8, -15, 30, 9, 1};
    int k = 3;
    findMax.findFirstNegative(arr, k).forEach(System.out::println);
  }
}

entry_point: findFirstNegative


code:
package stats;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;

public class WilcoxonSignedRanksTest {

    private double MIN=-1.0;

    public WilcoxonSignedRanksTest()
    {

    }

    public void test()
    {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
       String s;
       int i=0;
       double values1[] = new double[6];
       double values2[] = new double[6];

        try {
            while ((s = in.readLine()) != null && s.length() != 0){
               String values[] = s.split("\\s+");

               values1[i] = Double.parseDouble(values[0]);
               values2[i] = Double.parseDouble(values[1]);

               i++;

            }

            performTest(values1, values2);
        } catch (IOException ex) {
            Logger.getLogger(WilcoxonSignedRanksTest.class.getName()).log(Level.SEVERE, null, ex);
        }
   }

    public int [] nextMinIndexes(double []acc,double min)
    {
	int [] ids=new int[acc.length];
	int j=0;
	double m=1.0;

	for(int i=0;i<acc.length;i++)
	    acc[i] = Math.abs(acc[i]);

	for(int i=0;i<acc.length;i++)
	    if(acc[i]>min && m>acc[i])
		m = acc[i];

	for(int i=0;i<acc.length;i++)
	    if(Math.abs(acc[i])==m)
	    {
		ids[j]=i;
		j++;
	    }

	int [] rids = new int[j];
	for(int i=0;i<j;i++)
	{
	    rids[i] = ids[i];
	}
	MIN = acc[rids[0]];

	return rids;
    }

    public double [] performTest(double [] m1, double [] m2)
    {
	int l = m1.length;
	int l2 = m2.length;

	if(l != l2)
	{
	    System.out.println("The tables are not equalsized");
	    System.exit(0);
	}

	int max_rank = l;
	int rank=1;
	int [] ids = new int[l];

	double mean_rank;
	double [] dif = new double[l];
	double [] ranks = new double[l];

	for(int i=0;i<l;i++)
	    dif[i] = m1[i]-m2[i];

	while(rank<=max_rank)
	{
	    ids = nextMinIndexes(dif.clone(),MIN);

	    mean_rank = 0.0;

	    for(int j=0;j<ids.length;j++)
	    {
		mean_rank = mean_rank + rank;
		rank+=1;
	    }
	    mean_rank/=ids.length;

	    for(int j=0;j<ids.length;j++)
	    {
		mean_rank = Math.round(mean_rank*1000)/1000.0;
		ranks[ids[j]]=mean_rank;
	    }

	}

	double rminus=0.0;
	double rpos = 0.0;
	double rzero = 0.0;
	double rankzero = 0;
	int countzeros=0;

	for(int i=0;i<l;i++)
	{
	    if(dif[i]<0.0)
		rminus+=ranks[i];
	    else if(dif[i]>0.0)
		rpos+=ranks[i];
	    else
	    {
		rankzero = ranks[i];
		rzero += ranks[i];
		countzeros+=1;
	    }
	}

	if(countzeros%2!=0)
	    rzero-=rankzero;

	rpos+=rzero/2.0;
	rminus+=rzero/2.0;

	System.out.println("R+: "+rpos+" R-: "+rminus);
	System.out.println("T = "+Math.min(rpos,rminus));

	return ranks;
    }

    public static void main(String args[])
    {
        WilcoxonSignedRanksTest stest = new WilcoxonSignedRanksTest();
        stest.test();
    }
}

entry_point: nextMinIndexes


code:
package dsf.algorithm.leetcode.weekly.c174;

import java.util.PriorityQueue;

public class P1 {

    public int[] kWeakestRows(int[][] mat, int k) {

        PriorityQueue<Node> queue = new PriorityQueue<>((n1, n2) -> {
            if (n1.n < n2.n)
                return -1;
            if (n1.n > n2.n)
                return 1;
            return Integer.compare(n1.i, n2.i);
        });

        for (int i=0; i<mat.length; i++) {
            int n = 0;
            int[] arr = mat[i];
            for (; n<arr.length && arr[n] == 1; n++) {}
            queue.add(new Node(i, n));
        }

        int[] ans = new int[k];
        for (int i=0; i<k; i++) {
            ans[i] = queue.poll().i;
        }
        return ans;
    }

    static class Node {
        int i, n;

        public Node(int i, int n) {
            this.i = i;
            this.n = n;
        }
    }
}

entry_point: kWeakestRows


code:
package array_matrix_sorting;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class SmallestRangeCoveringElementsFromKLists {

    public int[] smallestRange(List<List<Integer>> nums) {
        List<int[]> list = new ArrayList<>();
        for (int i = 0; i < nums.size(); i++) {
            for (int num : nums.get(i)) {
                list.add(new int[]{num, i});
            }
        }
        Collections.sort(list, (a, b) -> (a[0] - b[0]));
        int[] res = new int[]{list.get(0)[0], list.get(list.size() - 1)[0]};
        int start = 0;
        int end = 0;
        int[] count = new int[nums.size()];
        int total = 0;
        while (end < list.size()) {
            int[] pair = list.get(end);
            int index = pair[1];
            if (count[index] == 0) {
                total++;
            }
            count[index]++;
            end++;
            while (start < end && total == nums.size()) {
                if (res[1] - res[0] > list.get(end - 1)[0] - list.get(start)[0]) {
                    res[0] = list.get(start)[0];
                    res[1] = list.get(end - 1)[0];
                }
                int[] prev = list.get(start);
                int prevIndex = prev[1];
                count[prevIndex]--;
                if (count[prevIndex] == 0) {
                    total--;
                }
                start++;
            }
        }
        return res;
    }
}

entry_point: smallestRange


code:
package com.github.zmzhoustar;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class AdjacentArray {

	private static final String REGEX = "[\\s,]+";

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		System.out.println("请输入矩阵的大小 N ：");
		while (!"".equals(line = br.readLine().trim())) {
			int n = Integer.parseInt(line);
			String[][] input = new String[n][n];
			System.out.println("请输入N*N矩阵：");
			for (int i = 0; i < input.length; i++) {
				input[i] = br.readLine().trim().split(REGEX);
			}
			System.out.println("请输入长度为M的数组(M > N)：");
			String mStr;
			while (!"".equals(mStr = br.readLine().trim())) {
				String[] m = mStr.split(REGEX);
				System.out.println("是否为相邻数组判断结果为：" + adjacentArray(input, m));
				System.out.println("请输入长度为M的数组：");
			}
			System.exit(0);
		}
	}

	private static boolean adjacentArray(String[][] input, String[] m) {
		Map<String, List<int[]>> map = new LinkedHashMap<>(m.length);
		for (String s : m) {
			map.put(s, new ArrayList<>());
		}
		for (int i = 0; i < input.length; i++) {
			String[] str = input[i];
			for (int j = 0; j < str.length; j++) {
				if (map.containsKey(input[i][j])) {
					int[] point = new int[]{i, j};
					List<int[]> value = map.get(input[i][j]);
					if (!value.isEmpty() && value.contains(point)) {
						continue;
					}
					value.add(point);
				}
			}
		}

		List<int[]> pointer = map.get(m[0]);

		if (pointer.isEmpty()) {
			return false;
		}

		List<int[]> router = new LinkedList<>();
		for (int i = 1; i < m.length; i++) {
			final List<int[]> next = map.get(m[i]);
			for (int[] p : pointer) {
				for (int[] n : next) {
					boolean requirement =

							(n[0] - p[0] == 1 && n[1] == p[1]) ||

							(n[0] == p[0] && n[1] - p[1] == 1) ||

							(n[0] == p[0] && n[1] - p[1] == -1) ||

							(n[0] - p[0] == -1 && n[1] == p[1]);
					if (requirement && addRouter(router, p, n)) {

						pointer = next;
					}
				}
			}
		}
		return router.size() == m.length;
	}

	private static boolean addRouter(List<int[]> router, int[] p, int[] n) {

		if (router.isEmpty()) {
			router.add(p);
		}

		if (!router.contains(n) && Arrays.equals(router.get(router.size() - 1), p)) {
			router.add(n);
			return true;
		}
		return false;
	}

}

entry_point: adjacentArray


code:
import java.lang.*;
import java.util.Arrays;

public class BeadSort {

    int[] sort(int[] arr) {
        int max = 0;
        for (int i = 0; i < arr.length; i++)
            if (arr[i] > max)
                max = arr[i];

        char[][] grid = new char[arr.length][max];
        int[] counter = new int[max];
        for (int i = 0; i < max; i++) {
            counter[i] = 0;
            for (int j = 0; j < arr.length; j++)
                grid[j][i] = '_';
        }

        for (int i = 0; i < arr.length; i++) {
            int num = arr[i];
            for (int j = 0; num > 0; j++) {
                grid[counter[j]++][j] = '*';
                num--;
            }

        }

        System.out.println();

        int[] sortingArray = new int[arr.length];
        for (int i = 0; i < arr.length; i++) {
            int putt = 0;
            for (int j = 0; j < max && grid[arr.length - 1 - i][j] == '*'; j++)
                putt++;
            sortingArray[i] = putt;
        }

        return sortingArray;
    }

    void display1D(int[] arr) {

        for (int i = 0; i < arr.length; i++)
            System.out.print(arr[i] + " ");

    }

    void display1D(char[] arr) {

        for (int i = 0; i < arr.length; i++)
            System.out.print(arr[i] + " ");

    }

    void display2D(char[][] arr) {

        for (int i = 0; i < arr.length; i++)
            display1D(arr[i]);

    }

}

entry_point: sort


code:
package org.hibnet.webpipes.css;

import java.util.ArrayList;
import java.util.List;

public class CssSpliter {

    public List<String> split(String content) throws Exception {
        List<String> result = new ArrayList<>();

        StringBuilder current = null;
        int count = 0;
        int multiplier = 1;
        boolean inRule = false;
        for (int i = 0; i < content.length(); i++) {
            char c = content.charAt(i);
            if (c == '{') {
                inRule = true;
            }
            if (c == ',' && !inRule) {
                multiplier++;
            }
            if (c == '}') {
                count += multiplier;
                multiplier = 1;
                inRule = false;
            }
            if (count >= 4000 || current == null) {

                if (current != null) {
                    result.add(current.toString());
                }
                current = new StringBuilder();
                count = 0;
            }
            current.append(c);
        }

        return result;
    }
}

entry_point: split


code:
package com.mohadian;

import java.util.*;

public class ThreeSum {

    private static ArrayList<Integer[]> threeSums(int[] input) {
        ArrayList<Integer[]> result = new ArrayList<>();
        Arrays.sort(input);

        int length = input.length;
        for (int i = 0; i < length - 3; i++) {
            if (i == 0 || input[i] > input[i - 1]) {
                int current = input[i];
                int lower = i + 1;
                int upper = length - 1;
                while (lower <= upper) {
                    int diff = input[upper] + input[lower];
                    if (diff == -1 * current) {
                        System.out.println("" + current + " " + input[lower] + " " + input[upper]);
                        result.add(new Integer[]{current, input[lower], input[upper]});
                        break;
                    } else if (diff < -1 * current) {
                        do {
                            lower++;
                        } while (lower + 1 < length && input[lower] == input[lower + 1]);
                        if (lower == upper) break;
                    } else if (diff > -1 * current) {
                        do {
                            upper--;
                        } while (upper > i && input[upper] == input[upper - 1]);
                        if (upper == lower) break;
                    }
                }
            }
        }

        return result;
    }

    private static Set<Integer[]> findThreeSums(int[] input) {
        Map<Integer, Integer> elements = new HashMap<>();
        int length = input.length;
        Set<Integer[]> result = new HashSet<>();

        Arrays.sort(input);

        for (int i = 0; i < length; i++) {
            elements.put(input[i], i);
        }

        for (int i = 0; i < length; i++) {
            int current = input[i];
            int complement = -1 * current;

            for (int j = i + 1; j < length; j++) {
                int second = input[j];
                if (elements.containsKey(complement - second)) {
                    if (elements.get(complement - second) != j) {
                        System.out.println("" + current + " " + second + " " + (complement - second));
                        result.add(new Integer[]{current, second, (complement - second)});

                    }
                }
            }
        }

        return result;
    }

    public static void main(String[] args) {
        int[] input = new int[]{-1, 0, 1, 2, -1, -1};

        Set<Integer[]> result = findThreeSums(input);
        Iterator<Integer[]> iterator = result.iterator();
        while (iterator.hasNext()) {
            System.out.println(Arrays.toString(iterator.next()));
        }

        threeSums(input);
    }
}

entry_point: threeSums


code:
package com.ywh.problem.leetcode.medium;

public class LeetCode43 {

    private static String mul(String num1, String num2) {
        String sum = "0";
        for (int i = num2.length() - 1; i >= 0; i--) {
            int k = num2.length() - 1 - i, p = 1;
            while (k > 0) {
                p *= 10;
                k--;
            }

            String cur = "0";
            for (int j = 0; j < p; j++) {
                cur = add(cur, num1);
            }
            String tmp = cur;
            for (int j = 0; j < (num2.charAt(i) - '0') - 1; j++) {
                cur = add(cur, tmp);
            }
            sum = add(sum, cur);
        }
        return sum;
    }

    private static String add(String num1, String num2) {
        StringBuilder sb = new StringBuilder();
        for (int i = num1.length() - 1, j = num2.length() - 1, carry = 0; i >= 0 || j >= 0 || carry > 0;) {
            int sum = carry;
            if (i >= 0) {
                sum += num1.charAt(i--) - '0';
            }
            if (j >= 0) {
                sum += num2.charAt(j--) - '0';
            }
            sb.append(sum % 10);
            carry = sum / 10;
        }
        return sb.reverse().toString();
    }

    public String multiply(String num1, String num2) {
        String ret = "0";
        if ("0".equals(num1) || "0".equals(num2)) {
            return ret;
        }
        for (int i = num2.length() - 1; i >= 0; i--) {

            int a = num2.charAt(i) - '0';
            StringBuilder sb = new StringBuilder();
            for (int j = num1.length() - 1, k = 1, carry = 0;
                 j >= 0 || carry != 0;
                 j--, k *= 10
            ) {
                int s = carry;
                if (j >= 0) {
                    s += a * (num1.charAt(j) - '0');
                }
                sb.append(s % 10);
                carry = s / 10;
            }
            sb.reverse();
            for (int k = i; k < num2.length() - 1; k++) {
                sb.append("0");
            }
            String cur = sb.toString();
            sb.delete(0, sb.length());

            for (int p1 = ret.length() - 1, p2 = cur.length() - 1, carry = 0; p1 >= 0 || p2 >= 0 || carry != 0; ) {
                int sum = carry;
                if (p1 >= 0) {
                    sum += ret.charAt(p1) - '0';
                    p1--;
                }
                if (p2 >= 0) {
                    sum += cur.charAt(p2) - '0';
                    p2--;
                }
                sb.append(sum % 10);
                carry = sum / 10;
            }
            ret = sb.reverse().toString();
        }
        return ret;
    }

}

entry_point: multiply


code:
package com.ssynhtn.medium;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Map;
import java.util.TreeMap;

public class HandofStraights {

    public boolean isNStraightHandSortedSet(int[] hand, int W) {
        int n = hand.length;
        if (n % W != 0) return false;
        TreeMap<Integer, Integer> counts = new TreeMap<>();
        for (int x : hand) {
            counts.merge(x, 1, Integer::sum);
        }

        while (!counts.isEmpty()) {
            Map.Entry<Integer, Integer> first = counts.pollFirstEntry();
            int min = first.getKey();
            int d = first.getValue();

            for (int i = min + 1; i < min + W; i++) {
                Integer c = counts.get(i);
                if (c == null) return false;
                if (c < d) return false;
                if (c == d) {
                    counts.remove(i);
                } else {
                    counts.put(i, c - d);
                }
            }
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println(new HandofStraights().isNStraightHandSortedSet(new int[]{1,2,3,6,2,3,4,7,8}, 3));
    }
}

entry_point: isNStraightHand


code:
package leetcode.weekly_contests.weekly_96;

import java.util.Arrays;
import java.util.PriorityQueue;

public class P_882 {

    public int reachableNodes(int[][] edges, int maxMoves, int n) {
        final int[][] g = new int[n][n];
        final boolean[] visited = new boolean[n];
        for (int i = 0; i < n; i++) {
            Arrays.fill(g[i], -1);
        }
        for (int[] edge : edges) {
            g[edge[0]][edge[1]] = edge[2];
            g[edge[1]][edge[0]] = edge[2];
        }
        int res = 0;
        final PriorityQueue<int[]> pq = new PriorityQueue<>((a, b) -> Integer.compare(b[1], a[1]));
        pq.offer(new int[] { 0, maxMoves });
        while (!pq.isEmpty()) {
            final int[] curr = pq.poll();
            final int u = curr[0];
            final int move = curr[1];
            if (visited[u]) {
                continue;
            }
            visited[u] = true;
            res++;
            for (int v = 0; v < n; v++) {
                if (g[u][v] > -1) {
                    if (move > g[u][v] && !visited[v]) {
                        pq.offer(new int[] { v, move - g[u][v] - 1 });
                    }
                    g[v][u] -= Math.min(move, g[u][v]);
                    res += Math.min(move, g[u][v]);
                }
            }
        }
        return res;
    }
}

entry_point: reachableNodes


code:
package math;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Boj2904 {
    private static ArrayList<Integer> primes = new ArrayList<>();
    private static boolean[] prime = new boolean[1_000_001];
    private static HashMap<Integer, Integer> count = new HashMap<>();

    private static final String SPACE = " ";

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());

        eratosthenes();
        int[] value = new int[N];
        int size = primes.size();

        StringTokenizer st = new StringTokenizer(br.readLine());
        for(int i = 0; i < N; i++) {
            value[i] = Integer.parseInt(st.nextToken());
            int loop = value[i];

            if(prime[loop]) {
                adder(loop);
                continue;
            }
            int idx = 0;

            while(idx < size && loop > 0) {
                int current = primes.get(idx++);

                while(loop % current == 0){
                    adder(current);
                    loop /= current;
                }
            }
        }

        System.out.println(finding(N, value));
    }

    private static void adder (int p) {
        if(count.containsKey(p)) count.put(p, count.get(p) + 1);
        else count.put(p, 1);
    }

    private static void eratosthenes() {
        Arrays.fill(prime, true);
        prime[0] = prime[1] = false;

        int loop = 1_001;

        for(int i = 2; i < loop; i++) {
            if(!prime[i]) continue;

            for(int j = i + i; j < prime.length; j += i) {
                prime[j] = false;
            }
        }

        for(int i = 0; i < prime.length; i++) {
            if(prime[i]) primes.add(i);
        }
    }

    private static String finding(int n, int[] value) {
        HashMap<Integer, Integer> p = new HashMap<>();
        int gcd = 1;

        for(int key: count.keySet()) {
            int dup = count.get(key) / n;
            if(dup == 0) continue;

            if(p.containsKey(key)) p.put(key, p.get(key) + dup);
            else p.put(key, dup);

            gcd *= Math.pow(key, dup);
        }

        int result = 0;
        for(int i = 0; i < n; i++) {
            for(int key: p.keySet()) {
                if(key == 1) continue;

                int cnt = 0;
                int loop = value[i];

                while(loop % key == 0) {
                    cnt++;
                    loop /= key;
                }

                if(cnt < p.get(key)) result += p.get(key) - cnt;
            }
        }

        StringBuilder sb = new StringBuilder();
        return sb.append(gcd).append(SPACE).append(result).toString();
    }
}

entry_point: finding